diff options
Diffstat (limited to 'sources/core/tools.js')
-rw-r--r-- | sources/core/tools.js | 167 |
1 files changed, 162 insertions, 5 deletions
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 @@ | |||
1021 | styleText = CKEDITOR.tools.normalizeHex( CKEDITOR.tools.convertRgbToHex( styleText ) ); | 1021 | styleText = CKEDITOR.tools.normalizeHex( CKEDITOR.tools.convertRgbToHex( styleText ) ); |
1022 | } | 1022 | } |
1023 | 1023 | ||
1024 | // IE will leave a single semicolon when failed to parse the style text. (#3891) | 1024 | // IE will leave a single semicolon when failed to parse the style text. (http://dev.ckeditor.com/ticket/3891) |
1025 | if ( !styleText || styleText == ';' ) | 1025 | if ( !styleText || styleText == ';' ) |
1026 | return retval; | 1026 | return retval; |
1027 | 1027 | ||
@@ -1463,6 +1463,37 @@ | |||
1463 | }, | 1463 | }, |
1464 | 1464 | ||
1465 | /** | 1465 | /** |
1466 | * Detects which mouse button generated a given DOM event. | ||
1467 | * | ||
1468 | * @since 4.7.3 | ||
1469 | * @param {CKEDITOR.dom.event} evt DOM event. | ||
1470 | * @returns {Number|Boolean} Returns a number indicating the mouse button or `false` | ||
1471 | * if the mouse button cannot be determined. | ||
1472 | */ | ||
1473 | getMouseButton: function( evt ) { | ||
1474 | var evtData = evt.data, | ||
1475 | domEvent = evtData && evtData.$; | ||
1476 | |||
1477 | if ( !( evtData && domEvent ) ) { | ||
1478 | // Added in case when there's no data available. That's the case in some unit test in built version which | ||
1479 | // mock event but doesn't put data object. | ||
1480 | return false; | ||
1481 | } | ||
1482 | |||
1483 | if ( CKEDITOR.env.ie && CKEDITOR.env.version < 9 ) { | ||
1484 | if ( domEvent.button === 4 ) { | ||
1485 | return CKEDITOR.MOUSE_BUTTON_MIDDLE; | ||
1486 | } else if ( domEvent.button === 1 ) { | ||
1487 | return CKEDITOR.MOUSE_BUTTON_LEFT; | ||
1488 | } else { | ||
1489 | return CKEDITOR.MOUSE_BUTTON_RIGHT; | ||
1490 | } | ||
1491 | } | ||
1492 | |||
1493 | return domEvent.button; | ||
1494 | }, | ||
1495 | |||
1496 | /** | ||
1466 | * A set of functions for operations on styles. | 1497 | * A set of functions for operations on styles. |
1467 | * | 1498 | * |
1468 | * @property {CKEDITOR.tools.style} | 1499 | * @property {CKEDITOR.tools.style} |
@@ -1627,6 +1658,21 @@ | |||
1627 | yellowgreen: '#9ACD32' | 1658 | yellowgreen: '#9ACD32' |
1628 | }, | 1659 | }, |
1629 | 1660 | ||
1661 | _borderStyle: [ | ||
1662 | 'none', | ||
1663 | 'hidden', | ||
1664 | 'dotted', | ||
1665 | 'dashed', | ||
1666 | 'solid', | ||
1667 | 'double', | ||
1668 | 'groove', | ||
1669 | 'ridge', | ||
1670 | 'inset', | ||
1671 | 'outset' | ||
1672 | ], | ||
1673 | |||
1674 | _widthRegExp: /^(thin|medium|thick|[\+-]?\d+(\.\d+)?[a-z%]+|[\+-]?0+(\.0+)?|\.\d+[a-z%]+)$/, | ||
1675 | |||
1630 | _rgbaRegExp: /rgba?\(\s*\d+%?\s*,\s*\d+%?\s*,\s*\d+%?\s*(?:,\s*[0-9.]+\s*)?\)/gi, | 1676 | _rgbaRegExp: /rgba?\(\s*\d+%?\s*,\s*\d+%?\s*,\s*\d+%?\s*(?:,\s*[0-9.]+\s*)?\)/gi, |
1631 | 1677 | ||
1632 | _hslaRegExp: /hsla?\(\s*[0-9.]+\s*,\s*\d+%\s*,\s*\d+%\s*(?:,\s*[0-9.]+\s*)?\)/gi, | 1678 | _hslaRegExp: /hsla?\(\s*[0-9.]+\s*,\s*\d+%\s*,\s*\d+%\s*(?:,\s*[0-9.]+\s*)?\)/gi, |
@@ -1647,10 +1693,8 @@ | |||
1647 | * @member CKEDITOR.tools.style.parse | 1693 | * @member CKEDITOR.tools.style.parse |
1648 | */ | 1694 | */ |
1649 | background: function( value ) { | 1695 | background: function( value ) { |
1650 | var ret = [], | 1696 | var ret = {}, |
1651 | colors = []; | 1697 | colors = this._findColor( value ); |
1652 | |||
1653 | colors = this._findColor( value ); | ||
1654 | 1698 | ||
1655 | if ( colors.length ) { | 1699 | if ( colors.length ) { |
1656 | ret.color = colors[ 0 ]; | 1700 | ret.color = colors[ 0 ]; |
@@ -1715,6 +1759,51 @@ | |||
1715 | }, | 1759 | }, |
1716 | 1760 | ||
1717 | /** | 1761 | /** |
1762 | * Parses the `border` CSS property shorthand format. | ||
1763 | * This CSS property does not support inheritance (https://www.w3.org/TR/css3-background/#the-border-shorthands). | ||
1764 | * | ||
1765 | * console.log( CKEDITOR.tools.style.parse.border( '3px solid #ffeedd' ) ); | ||
1766 | * // Logs: { width: "3px", style: "solid", color: "#ffeedd" } | ||
1767 | * | ||
1768 | * @param {String} value The `border` property value. | ||
1769 | * @returns {Object} | ||
1770 | * @returns {String} return.width The border-width attribute. | ||
1771 | * @returns {String} return.style The border-style attribute. | ||
1772 | * @returns {String} return.color The border-color attribute. | ||
1773 | * @member CKEDITOR.tools.style.parse | ||
1774 | */ | ||
1775 | border: function( value ) { | ||
1776 | var ret = {}, | ||
1777 | input = value.split( /\s+/ ); | ||
1778 | |||
1779 | CKEDITOR.tools.array.forEach( input, function( val ) { | ||
1780 | if ( !ret.color ) { | ||
1781 | var parseColor = CKEDITOR.tools.style.parse._findColor( val ); | ||
1782 | if ( parseColor.length ) { | ||
1783 | ret.color = parseColor[ 0 ]; | ||
1784 | return; | ||
1785 | } | ||
1786 | } | ||
1787 | |||
1788 | if ( !ret.style ) { | ||
1789 | if ( CKEDITOR.tools.indexOf( CKEDITOR.tools.style.parse._borderStyle, val ) !== -1 ) { | ||
1790 | ret.style = val; | ||
1791 | return; | ||
1792 | } | ||
1793 | } | ||
1794 | |||
1795 | if ( !ret.width ) { | ||
1796 | if ( CKEDITOR.tools.style.parse._widthRegExp.test( val ) ) { | ||
1797 | ret.width = val; | ||
1798 | return; | ||
1799 | } | ||
1800 | } | ||
1801 | |||
1802 | } ); | ||
1803 | return ret; | ||
1804 | }, | ||
1805 | |||
1806 | /** | ||
1718 | * Searches the `value` for any CSS color occurrences and returns it. | 1807 | * Searches the `value` for any CSS color occurrences and returns it. |
1719 | * | 1808 | * |
1720 | * @private | 1809 | * @private |
@@ -1846,6 +1935,39 @@ | |||
1846 | } | 1935 | } |
1847 | return acc; | 1936 | return acc; |
1848 | } | 1937 | } |
1938 | }, | ||
1939 | |||
1940 | /** | ||
1941 | * A set of object helpers. | ||
1942 | * | ||
1943 | * @property {CKEDITOR.tools.object} | ||
1944 | * @member CKEDITOR.tools | ||
1945 | */ | ||
1946 | object: { | ||
1947 | /** | ||
1948 | * Returns the first key from `obj` which has a given `value`. | ||
1949 | * | ||
1950 | * @param {Object} obj An object whose `key` is looked for. | ||
1951 | * @param {Mixed} value An object's `value` to be looked for. | ||
1952 | * @returns {String/null} Matched `key` or `null` if not found. | ||
1953 | * @member CKEDITOR.tools.object | ||
1954 | */ | ||
1955 | |||
1956 | findKey: function( obj, value ) { | ||
1957 | if ( typeof obj !== 'object' ) { | ||
1958 | return null; | ||
1959 | } | ||
1960 | |||
1961 | var key; | ||
1962 | |||
1963 | for ( key in obj ) { | ||
1964 | if ( obj[ key ] === value ) { | ||
1965 | return key; | ||
1966 | } | ||
1967 | } | ||
1968 | |||
1969 | return null; | ||
1970 | } | ||
1849 | } | 1971 | } |
1850 | }; | 1972 | }; |
1851 | 1973 | ||
@@ -1889,7 +2011,35 @@ | |||
1889 | */ | 2011 | */ |
1890 | CKEDITOR.tools.array.isArray = CKEDITOR.tools.isArray; | 2012 | CKEDITOR.tools.array.isArray = CKEDITOR.tools.isArray; |
1891 | 2013 | ||
2014 | /** | ||
2015 | * Left mouse button. | ||
2016 | * | ||
2017 | * @since 4.7.3 | ||
2018 | * @readonly | ||
2019 | * @property {Number} [=0] | ||
2020 | * @member CKEDITOR | ||
2021 | */ | ||
2022 | CKEDITOR.MOUSE_BUTTON_LEFT = 0; | ||
1892 | 2023 | ||
2024 | /** | ||
2025 | * Middle mouse button. | ||
2026 | * | ||
2027 | * @since 4.7.3 | ||
2028 | * @readonly | ||
2029 | * @property {Number} [=1] | ||
2030 | * @member CKEDITOR | ||
2031 | */ | ||
2032 | CKEDITOR.MOUSE_BUTTON_MIDDLE = 1; | ||
2033 | |||
2034 | /** | ||
2035 | * Right mouse button. | ||
2036 | * | ||
2037 | * @since 4.7.3 | ||
2038 | * @readonly | ||
2039 | * @property {Number} [=2] | ||
2040 | * @member CKEDITOR | ||
2041 | */ | ||
2042 | CKEDITOR.MOUSE_BUTTON_RIGHT = 2; | ||
1893 | 2043 | ||
1894 | /** | 2044 | /** |
1895 | * The namespace containing functions to work on CSS properties. | 2045 | * The namespace containing functions to work on CSS properties. |
@@ -1911,6 +2061,13 @@ | |||
1911 | * @since 4.6.1 | 2061 | * @since 4.6.1 |
1912 | * @class CKEDITOR.tools.array | 2062 | * @class CKEDITOR.tools.array |
1913 | */ | 2063 | */ |
2064 | |||
2065 | /** | ||
2066 | * The namespace with helper functions and polyfills for objects. | ||
2067 | * | ||
2068 | * @since 4.7.1 | ||
2069 | * @class CKEDITOR.tools.object | ||
2070 | */ | ||
1914 | } )(); | 2071 | } )(); |
1915 | 2072 | ||
1916 | // PACKAGER_RENAME( CKEDITOR.tools ) | 2073 | // PACKAGER_RENAME( CKEDITOR.tools ) |