X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fcore%2Ftools.js;h=0fd703f9ea6a1df91566395d2e5f928bb49ca715;hb=refs%2Ftags%2Fv3.2;hp=29b34b4bfb27e1b5197664511b47e54a20a59b7d;hpb=ea7e3453c7b0f023b050aca6d9f83ab372860d91;p=ckeditor.git diff --git a/_source/core/tools.js b/_source/core/tools.js index 29b34b4..0fd703f 100644 --- a/_source/core/tools.js +++ b/_source/core/tools.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -19,6 +19,22 @@ For licensing, see LICENSE.html or http://ckeditor.com/license */ CKEDITOR.tools = { + /** + * Compare the elements of two arrays. + * @param {Array} arrayA An array to be compared. + * @param {Array} arrayB The other array to be compared. + * @returns {Boolean} "true" is the arrays have the same lenght and + * their elements match. + * @example + * var a = [ 1, 'a', 3 ]; + * var b = [ 1, 3, 'a' ]; + * var c = [ 1, 'a', 3 ]; + * var d = [ 1, 'a', 3, 4 ]; + * + * alert( CKEDITOR.tools.arrayCompare( a, b ) ); // false + * alert( CKEDITOR.tools.arrayCompare( a, c ) ); // true + * alert( CKEDITOR.tools.arrayCompare( a, d ) ); // false + */ arrayCompare : function( arrayA, arrayB ) { if ( !arrayA && !arrayB ) @@ -80,7 +96,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license || ( obj instanceof String ) || ( obj instanceof Number ) || ( obj instanceof Boolean ) - || ( obj instanceof Date ) ) + || ( obj instanceof Date ) + || ( obj instanceof RegExp) ) { return obj; } @@ -98,6 +115,15 @@ For licensing, see LICENSE.html or http://ckeditor.com/license }, /** + * Turn the first letter of string to upper-case. + * @param {String} str + */ + capitalize: function( str ) + { + return str.charAt( 0 ).toUpperCase() + str.substring( 1 ).toLowerCase(); + }, + + /** * Copy the properties from one object to another. By default, properties * already present in the target object are not overwritten. * @param {Object} target The object to be extended. @@ -189,6 +215,15 @@ For licensing, see LICENSE.html or http://ckeditor.com/license return ( !!object && object instanceof Array ); }, + isEmpty : function ( object ) + { + for ( var i in object ) + { + if ( object.hasOwnProperty( i ) ) + return false; + } + return true; + }, /** * Transforms a CSS property name to its relative DOM style name. * @param {String} cssName The CSS property name. @@ -197,17 +232,47 @@ For licensing, see LICENSE.html or http://ckeditor.com/license * alert( CKEDITOR.tools.cssStyleToDomStyle( 'background-color' ) ); // "backgroundColor" * alert( CKEDITOR.tools.cssStyleToDomStyle( 'float' ) ); // "cssFloat" */ - cssStyleToDomStyle : function( cssName ) + cssStyleToDomStyle : ( function() + { + var test = document.createElement( 'div' ).style; + + var cssFloat = ( typeof test.cssFloat != 'undefined' ) ? 'cssFloat' + : ( typeof test.styleFloat != 'undefined' ) ? 'styleFloat' + : 'float'; + + return function( cssName ) + { + if ( cssName == 'float' ) + return cssFloat; + else + { + return cssName.replace( /-./g, function( match ) + { + return match.substr( 1 ).toUpperCase(); + }); + } + }; + } )(), + + /** + * Build the HTML snippet of a set of '); + else + retval.push(''); } + return retval.join( '' ); }, /** @@ -258,6 +323,19 @@ For licensing, see LICENSE.html or http://ckeditor.com/license }, /** + * Replace characters can't be represented through CSS Selectors string + * by CSS Escape Notation where the character escape sequence consists + * of a backslash character (\) followed by the orginal characters. + * Ref: http://www.w3.org/TR/css3-selectors/#grammar + * @param cssSelectText + * @return the escaped selector text. + */ + escapeCssSelector : function( cssSelectText ) + { + return cssSelectText.replace( /[\s#:.,$*^\[\]()~=+>]/g, '\\$&' ); + }, + + /** * Gets a unique number for this CKEDITOR execution session. It returns * progressive numbers starting at 1. * @function @@ -430,6 +508,24 @@ For licensing, see LICENSE.html or http://ckeditor.com/license return -1; }, + /** + * Creates a function that will always execute in the context of a + * specified object. + * @param {Function} func The function to be executed. + * @param {Object} obj The object to which bind the execution context. + * @returns {Function} The function that can be used to execute the + * "func" function in the context of "obj". + * @example + * var obj = { text : 'My Object' }; + * + * function alertText() + * { + * alert( this.text ); + * } + * + * var newFunc = CKEDITOR.tools.bind( alertText, obj ); + * newFunc(); // Alerts "My Object". + */ bind : function( func, obj ) { return function() { return func.apply( obj, arguments ); }; @@ -441,11 +537,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license *