X-Git-Url: https://git.immae.eu/?p=perso%2FImmae%2FProjets%2Fpackagist%2Fludivine-ckeditor-component.git;a=blobdiff_plain;f=sources%2Fcore%2Ftools.js;h=a4b736d647700bb6b59f3701a0f19b398f14dc9c;hp=7e0083f6b63384db5c759c12cf36c6e647a5a698;hb=1794320dcfdfcd19572fb1676294f9853a6bbc20;hpb=7183f6a6a21ad9124e70c997e0168459f377a9f2 diff --git a/sources/core/tools.js b/sources/core/tools.js index 7e0083f..a4b736d 100644 --- a/sources/core/tools.js +++ b/sources/core/tools.js @@ -1021,7 +1021,7 @@ styleText = CKEDITOR.tools.normalizeHex( CKEDITOR.tools.convertRgbToHex( styleText ) ); } - // IE will leave a single semicolon when failed to parse the style text. (#3891) + // IE will leave a single semicolon when failed to parse the style text. (http://dev.ckeditor.com/ticket/3891) if ( !styleText || styleText == ';' ) return retval; @@ -1462,6 +1462,37 @@ return selector; }, + /** + * Detects which mouse button generated a given DOM event. + * + * @since 4.7.3 + * @param {CKEDITOR.dom.event} evt DOM event. + * @returns {Number|Boolean} Returns a number indicating the mouse button or `false` + * if the mouse button cannot be determined. + */ + getMouseButton: function( evt ) { + var evtData = evt.data, + domEvent = evtData && evtData.$; + + if ( !( evtData && domEvent ) ) { + // Added in case when there's no data available. That's the case in some unit test in built version which + // mock event but doesn't put data object. + return false; + } + + if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 ) { + if ( domEvent.button === 4 ) { + return CKEDITOR.MOUSE_BUTTON_MIDDLE; + } else if ( domEvent.button === 1 ) { + return CKEDITOR.MOUSE_BUTTON_LEFT; + } else { + return CKEDITOR.MOUSE_BUTTON_RIGHT; + } + } + + return domEvent.button; + }, + /** * A set of functions for operations on styles. * @@ -1627,6 +1658,21 @@ yellowgreen: '#9ACD32' }, + _borderStyle: [ + 'none', + 'hidden', + 'dotted', + 'dashed', + 'solid', + 'double', + 'groove', + 'ridge', + 'inset', + 'outset' + ], + + _widthRegExp: /^(thin|medium|thick|[\+-]?\d+(\.\d+)?[a-z%]+|[\+-]?0+(\.0+)?|\.\d+[a-z%]+)$/, + _rgbaRegExp: /rgba?\(\s*\d+%?\s*,\s*\d+%?\s*,\s*\d+%?\s*(?:,\s*[0-9.]+\s*)?\)/gi, _hslaRegExp: /hsla?\(\s*[0-9.]+\s*,\s*\d+%\s*,\s*\d+%\s*(?:,\s*[0-9.]+\s*)?\)/gi, @@ -1647,10 +1693,8 @@ * @member CKEDITOR.tools.style.parse */ background: function( value ) { - var ret = [], - colors = []; - - colors = this._findColor( value ); + var ret = {}, + colors = this._findColor( value ); if ( colors.length ) { ret.color = colors[ 0 ]; @@ -1714,6 +1758,51 @@ return ret; }, + /** + * Parses the `border` CSS property shorthand format. + * This CSS property does not support inheritance (https://www.w3.org/TR/css3-background/#the-border-shorthands). + * + * console.log( CKEDITOR.tools.style.parse.border( '3px solid #ffeedd' ) ); + * // Logs: { width: "3px", style: "solid", color: "#ffeedd" } + * + * @param {String} value The `border` property value. + * @returns {Object} + * @returns {String} return.width The border-width attribute. + * @returns {String} return.style The border-style attribute. + * @returns {String} return.color The border-color attribute. + * @member CKEDITOR.tools.style.parse + */ + border: function( value ) { + var ret = {}, + input = value.split( /\s+/ ); + + CKEDITOR.tools.array.forEach( input, function( val ) { + if ( !ret.color ) { + var parseColor = CKEDITOR.tools.style.parse._findColor( val ); + if ( parseColor.length ) { + ret.color = parseColor[ 0 ]; + return; + } + } + + if ( !ret.style ) { + if ( CKEDITOR.tools.indexOf( CKEDITOR.tools.style.parse._borderStyle, val ) !== -1 ) { + ret.style = val; + return; + } + } + + if ( !ret.width ) { + if ( CKEDITOR.tools.style.parse._widthRegExp.test( val ) ) { + ret.width = val; + return; + } + } + + } ); + return ret; + }, + /** * Searches the `value` for any CSS color occurrences and returns it. * @@ -1846,6 +1935,39 @@ } return acc; } + }, + + /** + * A set of object helpers. + * + * @property {CKEDITOR.tools.object} + * @member CKEDITOR.tools + */ + object: { + /** + * Returns the first key from `obj` which has a given `value`. + * + * @param {Object} obj An object whose `key` is looked for. + * @param {Mixed} value An object's `value` to be looked for. + * @returns {String/null} Matched `key` or `null` if not found. + * @member CKEDITOR.tools.object + */ + + findKey: function( obj, value ) { + if ( typeof obj !== 'object' ) { + return null; + } + + var key; + + for ( key in obj ) { + if ( obj[ key ] === value ) { + return key; + } + } + + return null; + } } }; @@ -1889,7 +2011,35 @@ */ CKEDITOR.tools.array.isArray = CKEDITOR.tools.isArray; + /** + * Left mouse button. + * + * @since 4.7.3 + * @readonly + * @property {Number} [=0] + * @member CKEDITOR + */ + CKEDITOR.MOUSE_BUTTON_LEFT = 0; + /** + * Middle mouse button. + * + * @since 4.7.3 + * @readonly + * @property {Number} [=1] + * @member CKEDITOR + */ + CKEDITOR.MOUSE_BUTTON_MIDDLE = 1; + + /** + * Right mouse button. + * + * @since 4.7.3 + * @readonly + * @property {Number} [=2] + * @member CKEDITOR + */ + CKEDITOR.MOUSE_BUTTON_RIGHT = 2; /** * The namespace containing functions to work on CSS properties. @@ -1911,6 +2061,13 @@ * @since 4.6.1 * @class CKEDITOR.tools.array */ + + /** + * The namespace with helper functions and polyfills for objects. + * + * @since 4.7.1 + * @class CKEDITOR.tools.object + */ } )(); // PACKAGER_RENAME( CKEDITOR.tools )