X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=_source%2Fcore%2Ftools.js;h=6fb417b8ed66fd956aa0123cb31eb01c515df9c5;hb=941b0a9ba4e673e292510d80a5a86806994b8ea6;hp=6f9542869acf7288049bcb804fe2f28143eaecaf;hpb=8761695d9b70afe75905deaac88f78c1f8aeb32d;p=ckeditor.git diff --git a/_source/core/tools.js b/_source/core/tools.js index 6f95428..6fb417b 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. @@ -220,6 +255,27 @@ For licensing, see LICENSE.html or http://ckeditor.com/license } )(), /** + * Build the HTML snippet of a set of '); + else + retval.push(''); + } + return retval.join( '' ); + }, + + /** * Replace special HTML characters in a string with their relative HTML * entity values. * @param {String} text The string to be encoded. @@ -267,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 @@ -439,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 ); }; @@ -450,11 +537,11 @@ For licensing, see LICENSE.html or http://ckeditor.com/license *