]> git.immae.eu Git - perso/Immae/Projets/packagist/ludivine-ckeditor-component.git/blobdiff - sources/core/tools.js
Update to 4.7.3
[perso/Immae/Projets/packagist/ludivine-ckeditor-component.git] / sources / core / tools.js
index 7e0083f6b63384db5c759c12cf36c6e647a5a698..a4b736d647700bb6b59f3701a0f19b398f14dc9c 100644 (file)
                                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;
 
                        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.
                 *
                                        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,
                                 * @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 ];
                                        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.
                                 *
                                }
                                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;
+                       }
                }
        };
 
         */
        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.
         * @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 )