diff options
| author | Christophe Matthieu <chm@odoo.com> | 2014-12-10 15:59:48 +0100 |
|---|---|---|
| committer | Christophe Matthieu <chm@odoo.com> | 2015-01-05 10:17:10 +0100 |
| commit | 1596e45e8174cd736d4f7c78f85ec76a8e34888d (patch) | |
| tree | 4ff318ee78bccc6c0bb6253670e85977f8f5a643 /addons/website/static/lib/summernote/src/js/editing/Style.js | |
| parent | f9a7ed6b9406d657fda33ec55c4e237576b77a42 (diff) | |
[IMP] website: add summernote lib
Diffstat (limited to 'addons/website/static/lib/summernote/src/js/editing/Style.js')
| -rw-r--r-- | addons/website/static/lib/summernote/src/js/editing/Style.js | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/addons/website/static/lib/summernote/src/js/editing/Style.js b/addons/website/static/lib/summernote/src/js/editing/Style.js new file mode 100644 index 00000000000..ec0260c0317 --- /dev/null +++ b/addons/website/static/lib/summernote/src/js/editing/Style.js @@ -0,0 +1,93 @@ +define([ + 'summernote/core/agent', + 'summernote/core/dom' +], function (agent, dom) { + /** + * Style + * @class + */ + var Style = function () { + /** + * passing an array of style properties to .css() + * will result in an object of property-value pairs. + * (compability with version < 1.9) + * + * @param {jQuery} $obj + * @param {Array} propertyNames - An array of one or more CSS properties. + * @returns {Object} + */ + var jQueryCSS = function ($obj, propertyNames) { + if (agent.jqueryVersion < 1.9) { + var result = {}; + $.each(propertyNames, function (idx, propertyName) { + result[propertyName] = $obj.css(propertyName); + }); + return result; + } + return $obj.css.call($obj, propertyNames); + }; + + /** + * paragraph level style + * + * @param {WrappedRange} rng + * @param {Object} styleInfo + */ + this.stylePara = function (rng, styleInfo) { + $.each(rng.nodes(dom.isPara, { + includeAncestor: true + }), function (idx, para) { + $(para).css(styleInfo); + }); + }; + + /** + * get current style on cursor + * + * @param {WrappedRange} rng + * @param {Node} target - target element on event + * @return {Object} - object contains style properties. + */ + this.current = function (rng, target) { + var $cont = $(dom.isText(rng.sc) ? rng.sc.parentNode : rng.sc); + var properties = ['font-family', 'font-size', 'text-align', 'list-style-type', 'line-height']; + var styleInfo = jQueryCSS($cont, properties) || {}; + + styleInfo['font-size'] = parseInt(styleInfo['font-size'], 10); + + // document.queryCommandState for toggle state + styleInfo['font-bold'] = document.queryCommandState('bold') ? 'bold' : 'normal'; + styleInfo['font-italic'] = document.queryCommandState('italic') ? 'italic' : 'normal'; + styleInfo['font-underline'] = document.queryCommandState('underline') ? 'underline' : 'normal'; + styleInfo['font-strikethrough'] = document.queryCommandState('strikeThrough') ? 'strikethrough' : 'normal'; + styleInfo['font-superscript'] = document.queryCommandState('superscript') ? 'superscript' : 'normal'; + styleInfo['font-subscript'] = document.queryCommandState('subscript') ? 'subscript' : 'normal'; + + // list-style-type to list-style(unordered, ordered) + if (!rng.isOnList()) { + styleInfo['list-style'] = 'none'; + } else { + var aOrderedType = ['circle', 'disc', 'disc-leading-zero', 'square']; + var isUnordered = $.inArray(styleInfo['list-style-type'], aOrderedType) > -1; + styleInfo['list-style'] = isUnordered ? 'unordered' : 'ordered'; + } + + var para = dom.ancestor(rng.sc, dom.isPara); + if (para && para.style['line-height']) { + styleInfo['line-height'] = para.style.lineHeight; + } else { + var lineHeight = parseInt(styleInfo['line-height'], 10) / parseInt(styleInfo['font-size'], 10); + styleInfo['line-height'] = lineHeight.toFixed(1); + } + + styleInfo.image = dom.isImg(target) && target; + styleInfo.anchor = rng.isOnAnchor() && dom.ancestor(rng.sc, dom.isAnchor); + styleInfo.ancestors = dom.listAncestor(rng.sc, dom.isEditable); + styleInfo.range = rng; + + return styleInfo; + }; + }; + + return Style; +}); |
