X-Git-Url: https://jasonwoof.com/gitweb/?a=blobdiff_plain;f=_source%2Fcore%2Ftools.js;h=5d0573c40386caae1ee4834169816dc9c227fec7;hb=f0610347140239143439a511ee2bd48cb784f470;hp=80555664350599c2e471fee3284fc093e848eaed;hpb=8665a7c6c60586526e32e8941fe2896739b6ebfb;p=ckeditor.git diff --git a/_source/core/tools.js b/_source/core/tools.js index 8055566..5d0573c 100644 --- a/_source/core/tools.js +++ b/_source/core/tools.js @@ -1,5 +1,5 @@ /* -Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved. +Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ @@ -220,6 +220,10 @@ For licensing, see LICENSE.html or http://ckeditor.com/license return ( !!object && object instanceof Array ); }, + /** + * Whether the object contains no properties of it's own. + * @param object + */ isEmpty : function ( object ) { for ( var i in object ) @@ -229,6 +233,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license } return true; }, + /** * Transforms a CSS property name to its relative DOM style name. * @param {String} cssName The CSS property name. @@ -337,20 +342,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license */ htmlEncodeAttr : function( text ) { - return text.replace( /"/g, '"' ).replace( //, '>' ); - }, - - /** - * 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, '\\$&' ); + return text.replace( /"/g, '"' ).replace( //g, '>' ); }, /** @@ -372,6 +364,20 @@ For licensing, see LICENSE.html or http://ckeditor.com/license })(), /** + * Gets a unique ID for CKEditor's interface elements. It returns a + * string with the "cke_" prefix and a progressive number. + * @function + * @returns {String} A unique ID. + * @example + * alert( CKEDITOR.tools.getNextId() ); // "cke_1" (e.g.) + * alert( CKEDITOR.tools.getNextId() ); // "cke_2" + */ + getNextId : function() + { + return 'cke_' + this.getNextNumber(); + }, + + /** * Creates a function override. * @param {Function} originalFunction The function to be overridden. * @param {Function} functionBuilder A function that returns the new @@ -632,7 +638,7 @@ For licensing, see LICENSE.html or http://ckeditor.com/license { return functions.push( function() { - fn.apply( scope || this, arguments ); + return fn.apply( scope || this, arguments ); }) - 1; }, @@ -668,20 +674,62 @@ For licensing, see LICENSE.html or http://ckeditor.com/license return fn && fn.apply( window, Array.prototype.slice.call( arguments, 1 ) ); }, + /** + * Append the 'px' length unit to the size if it's missing. + * @param length + */ cssLength : (function() { - var decimalRegex = /^\d+(?:\.\d+)?$/; return function( length ) { - return length + ( decimalRegex.test( length ) ? 'px' : '' ); + return length + ( !length || isNaN( Number( length ) ) ? '' : 'px' ); }; })(), + /** + * Convert the specified CSS length value to the calculated pixel length inside this page. + * Note: Percentage based value is left intact. + * @param {String} cssLength CSS length value. + */ + convertToPx : ( function () + { + var calculator; + + return function( cssLength ) + { + if ( !calculator ) + { + calculator = CKEDITOR.dom.element.createFromHtml( + '
', CKEDITOR.document ); + CKEDITOR.document.getBody().append( calculator ); + } + + if ( !(/%$/).test( cssLength ) ) + { + calculator.setStyle( 'width', cssLength ); + return calculator.$.clientWidth; + } + + return cssLength; + }; + } )(), + + /** + * String specified by {@param str} repeats {@param times} times. + * @param str + * @param times + */ repeat : function( str, times ) { return new Array( times + 1 ).join( str ); }, + /** + * Return the first successfully executed function's return value that + * doesn't throw any exception. + */ tryThese : function() { var returnValue;