CKEDITOR.tools
Utility functions.
Filtering
Properties
array : arrayCKEDITOR.tools#arrayA set of array helpers.
object : objectCKEDITOR.tools#objectA set of object helpers.
style : styleCKEDITOR.tools#styleA set of functions for operations on styles.
-
The data URI of a transparent image. May be used e.g. in HTML as an image source or in CSS in
url().Defaults to
'data:image/gif;base64,R0lGODlhAQABAPABAP///wAAACH5BAEKAAAALAAAAAABAAEAAAICRAEAOw==' -
Note: This regexp is deprecated, use CKEDITOR.tools.color to handle colors.
Defaults to
/hsla?\(\s*[0-9.]+\s*,\s*\d+%\s*,\s*\d+%\s*(?:,\s*[0-9.]+\s*)?\)/gi -
Note: This regexp is deprecated, use CKEDITOR.tools.color to handle colors.
Defaults to
/rgba?\(\s*\d+%?\s*,\s*\d+%?\s*,\s*\d+%?\s*(?:,\s*[0-9.]+\s*)?\)/gi
Methods
addFunction( fn, [ scope ] ) → NumberCKEDITOR.tools#addFunctionCreates a function reference that can be called later using callFunction. This approach is especially useful to make DOM attribute function calls to JavaScript-defined functions.
var ref = CKEDITOR.tools.addFunction( function() { alert( 'Hello!'); } ); CKEDITOR.tools.callFunction( ref ); // 'Hello!'Parameters
fn : FunctionThe function to be executed on call.
[ scope ] : ObjectThe object to have the context on
fnexecution.
Returns
NumberA unique reference to be used in conjuction with callFunction.
arrayCompare( arrayA, arrayB ) → BooleanCKEDITOR.tools#arrayCompareCompares the elements of two arrays.
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 ) ); // falseParameters
arrayA : ArrayAn array to be compared.
arrayB : ArrayThe other array to be compared.
Returns
Booleantrueif the arrays have the same length and their elements match.
bind( func, obj, [ args ] ) → FunctionCKEDITOR.tools#bindCreates a function that will always execute in the context of a specified object.
var obj = { text: 'My Object' }; function alertText() { alert( this.text ); } var newFunc = CKEDITOR.tools.bind( alertText, obj ); newFunc(); // Alerts 'My Object'.Since 4.13.0 additional arguments can be bound to a function.
function logData( text, number1, number2 ) { console.log( text, number1, number2 ); } var newFunc = CKEDITOR.tools.bind( logData, null, 'Foo', 1 ); newFunc(); // Logs: 'Foo', 1, undefined. newFunc( 2 ); // Logs: 'Foo', 1, 2.Parameters
func : FunctionThe function to be executed.
obj : ObjectThe object to which the execution context will be bound.
[ args ] : *Arguments provided to the bound function when invoking the target function. Available since 4.13.0.
Returns
FunctionThe function that can be used to execute the
funcfunction in the context of the specifiedobjobject.
buildStyleHtml( css ) → StringCKEDITOR.tools#buildStyleHtmlBuilds a HTML snippet from a set of
<style>/<link>.Parameters
css : String | ArrayEach of which are URLs (absolute) of a CSS file or a trunk of style text.
Returns
String
buildTableMap( table, startRow, startCell, endRow, endCell )CKEDITOR.tools#buildTableMapCreates a two-dimension array that reflects the actual layout of table cells, with cell spans, with mappings to the original
tdelements.It could also create a map for the specified fragment of the table.
Parameters
table : elementstartRow : NumberRow index from which the map should be created.
startCell : NumberCell index from which the map should be created.
endRow : NumberRow index to which the map should be created.
endCell : NumberCell index to which the map should be created.
callFunction( ref, params ) → MixedCKEDITOR.tools#callFunctionExecutes a function based on the reference created with addFunction.
var ref = CKEDITOR.tools.addFunction( function() { alert( 'Hello!'); } ); CKEDITOR.tools.callFunction( ref ); // 'Hello!'Parameters
ref : NumberThe function reference created with addFunction.
params : MixedAny number of parameters to be passed to the executed function.
Returns
MixedThe return value of the function.
capitalize( str, [ keepCase ] ) → StringCKEDITOR.tools#capitalizeTurns the first letter of a string to upper-case.
Parameters
str : String[ keepCase ] : BooleanKeep the case of 2nd to last letter.
Returns
String
since 4.4.0
checkIfAnyArrayItemMatches( arr, regexp ) → BooleanCKEDITOR.tools#checkIfAnyArrayItemMatchesChecks if any of the
arritems match the provided regular expression.Parameters
arr : ArrayThe array whose items will be checked.
regexp : RegExpThe regular expression.
Returns
BooleanReturns
truefor the first occurrence of the search pattern.
since 4.4.0
checkIfAnyObjectPropertyMatches( obj, regexp ) → BooleanCKEDITOR.tools#checkIfAnyObjectPropertyMatchesChecks if any of the
objproperties match the provided regular expression.Parameters
obj : ObjectThe object whose properties will be checked.
regexp : RegExpThe regular expression.
Returns
BooleanReturns
truefor the first occurrence of the search pattern.
clone( object ) → ObjectCKEDITOR.tools#cloneCreates a deep copy of an object.
Note: Recursive references are not supported.
var obj = { name: 'John', cars: { Mercedes: { color: 'blue' }, Porsche: { color: 'red' } } }; var clone = CKEDITOR.tools.clone( obj ); clone.name = 'Paul'; clone.cars.Porsche.color = 'silver'; alert( obj.name ); // 'John' alert( clone.name ); // 'Paul' alert( obj.cars.Porsche.color ); // 'red' alert( clone.cars.Porsche.color ); // 'silver'Parameters
object : ObjectThe object to be cloned.
Returns
ObjectThe object clone.
-
Converts an array to an object by rewriting array items to object properties.
var arr = [ 'foo', 'bar', 'foo' ]; console.log( CKEDITOR.tools.convertArrayToObject( arr ) ); // -> { foo: true, bar: true } console.log( CKEDITOR.tools.convertArrayToObject( arr, 1 ) ); // -> { foo: 1, bar: 1 }Parameters
arr : ArrayThe array to be converted to an object.
[ fillWith ] : ObjectSet each property of an object to
fillWithvalue.Defaults to
true
-
Converts a bytes array into a a Base64-encoded string.
Parameters
bytesArray : Number[]An array that stores 1 byte in each cell as an Integer number.
Returns
StringBase64-encoded string that represents input bytes.
-
Converts a hex string to an array containing 1 byte in each cell. Bytes are represented as Integer numbers.
Parameters
hexString : StringContains an input string which represents bytes, e.g.
"08A11D8ADA2B".
Returns
Number[]Bytes stored in a form of Integer numbers, e.g.
[ 8, 161, 29, 138, 218, 43 ].
convertRgbToHex( styleText ) → StringCKEDITOR.tools#convertRgbToHexFinds and converts
rgb(x,x,x)color definition into a given string to hexadecimal notation.Note: For handling RGB string only (not within text) it is recommended to use CKEDITOR.tools.color to create color instance and CKEDITOR.tools.color.getHex method to get its hexadecimal representation:
var color = new CKEDITOR.tools.color( 'rgb( 225, 225, 225 )' ); // Create color instance. console.log( color.getHex() ); // #FFFFFFParameters
styleText : StringThe style data (or just a string containing RGB colors) to be converted.
Returns
StringThe style data with RGB colors converted to hexadecimal equivalents.
convertToPx( cssLength ) → Number | StringCKEDITOR.tools#convertToPxConverts the specified CSS length value to the calculated pixel length inside this page.
Since 4.11.0 it also returns negative values.
Note: Percentage-based value is left intact.
Parameters
cssLength : StringCSS length value.
Returns
Number | StringA number representing the length in pixels or a string with a percentage value.
-
Makes fast (shallow) copy of an object. This method is faster than clone which does a deep copy of an object (including arrays).
Parameters
source : ObjectThe object to be copied.
Returns
ObjectCopy of
source.
createClass( definition ) → FunctionCKEDITOR.tools#createClassClass creation based on prototype inheritance which supports the following features:
- Static fields
- Private fields
- Public (prototype) fields
- Chainable base class constructor
Parameters
definition : ObjectThe class definition object.
Returns
FunctionA class-like JavaScript function.
cssLength( length )CKEDITOR.tools#cssLengthAppends the
pxlength unit to the size value if it is missing.var cssLength = CKEDITOR.tools.cssLength; cssLength( 42 ); // '42px' cssLength( '42' ); // '42px' cssLength( '42px' ); // '42px' cssLength( '42%' ); // '42%' cssLength( 'bold' ); // 'bold' cssLength( false ); // '' cssLength( NaN ); // ''Parameters
length : Number | String | Boolean
cssStyleToDomStyle( cssName ) → StringCKEDITOR.tools#cssStyleToDomStyleTransforms a CSS property name to its relative DOM style name.
alert( CKEDITOR.tools.cssStyleToDomStyle( 'background-color' ) ); // 'backgroundColor' alert( CKEDITOR.tools.cssStyleToDomStyle( 'float' ) ); // 'cssFloat'Parameters
cssName : StringThe CSS property name.
Returns
StringThe transformed name.
cssVendorPrefix( property, value, [ asString ] ) → Object | StringCKEDITOR.tools#cssVendorPrefixGenerates an object or a string containing vendor-specific and vendor-free CSS properties.
CKEDITOR.tools.cssVendorPrefix( 'border-radius', '0', true ); // On Firefox: '-moz-border-radius:0;border-radius:0' // On Chrome: '-webkit-border-radius:0;border-radius:0'Parameters
property : StringThe CSS property name.
value : StringThe CSS value.
[ asString ] : BooleanIf
true, then the returned value will be a CSS string.Defaults to
false
Returns
Object | StringThe object containing CSS properties or its stringified version.
-
Returns a new debounced version of the passed function that will postpone its execution until the given milliseconds have elapsed since the last time it was invoked.
Parameters
func : FunctionThe function to be executed.
[ milliseconds ] : NumberThe amount of time (in milliseconds) to wait to fire the function execution.
Defaults to
0
Returns
Function
defer( fn ) → FunctionCKEDITOR.tools#deferCreates a "deferred" function which will not run immediately, but rather runs as soon as the interpreter’s call stack is empty. Behaves much like
window.setTimeoutwith a delay.Note: The return value of the original function will be lost.
Parameters
fn : FunctionThe callee function.
Returns
FunctionThe new deferred function.
-
Enables HTML5 elements for older browsers (IE8) in the passed document.
In IE8 this method can also be executed on a document fragment.
Note: This method has to be used in the
<head>section of the document.Parameters
doc : ObjectNative
DocumentorDocumentFragmentin which the elements will be enabled.[ withAppend ] : BooleanWhether to append created elements to the
doc.
-
Returns an escaped CSS selector.
CSS.escape()is used if defined, leading digit is escaped otherwise.Parameters
selector : StringA CSS selector to escape.
Returns
StringAn escaped selector.
-
Creates an events buffer instance.
See the input method's documentation for example code listings.
Parameters
minInterval : NumberThe minimum interval between
outputcalls in milliseconds.output : FunctionThe function that will be executed as
output.[ contextObj ] : ObjectThe object used as context to the listener call (the
thisobject).
Returns
event
extend( target, source, [ overwrite ], [ properties ] ) → ObjectCKEDITOR.tools#extendCopies the properties from one object to another. By default, properties already present in the target object are not overwritten.
// Create the sample object. var myObject = { prop1: true }; // Extend the above object with two properties. CKEDITOR.tools.extend( myObject, { prop2: true, prop3: true } ); // Alert 'prop1', 'prop2' and 'prop3'. for ( var p in myObject ) alert( p );Parameters
target : ObjectThe object to be extended.
source : ObjectThe object(s) from properties will be copied. Any number of objects can be passed to this function.
[ overwrite ] : BooleanIf
trueis specified, it indicates that properties already present in the target object could be overwritten by subsequent objects.[ properties ] : ObjectOnly properties within the specified names list will be received from the source object.
Returns
ObjectThe extended object (target).
-
Tries to fix the
document.domainof the current document to match the parent window domain, avoiding "Same Origin" policy issues. This is an Internet Explorer only requirement.Returns
Booleantrueif the current domain is already good or if it has been fixed successfully.
genKey( subKey ) → StringCKEDITOR.tools#genKeyGenerates a combined key from a series of params.
var key = CKEDITOR.tools.genKey( 'key1', 'key2', 'key3' ); alert( key ); // 'key1-key2-key3'.Parameters
subKey : StringOne or more strings used as subkeys.
Returns
String
since 4.10.0
getAbsoluteRectPosition( window, rect ) → CKEDITORCKEDITOR.tools#getAbsoluteRectPositionConverts relative positions inside a DOM rectangle into absolute ones using the given window as context. "Absolute" here means in relation to the upper-left corner of the topmost viewport.
Parameters
window : CKEDITORThe window containing an element for which the rectangle is passed.
rect : CKEDITORA rectangle with a relative position.
Returns
CKEDITORA rectangle with an absolute position.
-
Returns the value of the cookie with a given name or
nullif the cookie is not found.Parameters
name : String
Returns
String
-
Returns the CSRF token value. The value is a hash stored in
document.cookieunder theckCsrfTokenkey. The CSRF token can be used to secure the communication between the web browser and the server, i.e. for the file upload feature in the editor.Returns
String
-
Finds the index of the first element in an array for which the
compareFunctionreturnstrue.CKEDITOR.tools.getIndex( [ 1, 2, 4, 3, 5 ], function( el ) { return el >= 3; } ); // 2Parameters
array : ArrayArray to search in.
compareFunction : FunctionCompare function.
Returns
NumberThe index of the first matching element or
-1if none matches.
-
Detects which mouse button generated a given DOM event.
Parameters
evt : event | EventDOM event. Since 4.11.3 a native
MouseEventinstance can be passed.
Returns
BooleanReturns a number indicating the mouse button or
falseif the mouse button cannot be determined.
getNextId() → StringCKEDITOR.tools#getNextIdGets a unique ID for CKEditor interface elements. It returns a string with the "cke_" prefix and a consecutive number.
alert( CKEDITOR.tools.getNextId() ); // (e.g.) 'cke_1' alert( CKEDITOR.tools.getNextId() ); // 'cke_2'Returns
StringA unique ID.
getNextNumber() → NumberCKEDITOR.tools#getNextNumberGets a unique number for this CKEDITOR execution session. It returns consecutive numbers starting from 1.
alert( CKEDITOR.tools.getNextNumber() ); // (e.g.) 1 alert( CKEDITOR.tools.getNextNumber() ); // 2Returns
NumberA unique number.
-
Finds all span elements styled with the given property in the editor contents.
Parameters
property : StringCSS property which will be used in query.
source : elementThe element to be searched.
Returns
ArrayReturns an array of CKEDITOR.dom.elements.
getUniqueId() → StringCKEDITOR.tools#getUniqueIdGets a universally unique ID. It returns a random string compliant with ISO/IEC 11578:1996, without dashes, with the "e" prefix to make sure that the ID does not start with a number.
Returns
StringA global unique ID.
htmlDecode( The ) → StringCKEDITOR.tools#htmlDecodeDecodes HTML entities that browsers tend to encode when used in text nodes.
alert( CKEDITOR.tools.htmlDecode( '<a & b >' ) ); // '<a & b >'Read more about chosen entities in the research.
Parameters
The : Stringstring to be decoded.
Returns
StringThe decoded string.
htmlDecodeAttr( text ) → StringCKEDITOR.tools#htmlDecodeAttrDecodes HTML entities that browsers tend to encode when used in attributes.
alert( CKEDITOR.tools.htmlDecodeAttr( '<a " b>' ) ); // '<a " b>'Since CKEditor 4.5.0 this method simply executes htmlDecode which covers all necessary entities.
Parameters
text : StringThe text to be decoded.
Returns
StringThe decoded text.
htmlEncode( text ) → StringCKEDITOR.tools#htmlEncodeReplaces special HTML characters in a string with their relative HTML entity values.
alert( CKEDITOR.tools.htmlEncode( 'A > B & C < D' ) ); // 'A > B & C < D'Parameters
text : StringThe string to be encoded.
Returns
StringThe encoded string.
htmlEncodeAttr( The ) → StringCKEDITOR.tools#htmlEncodeAttrReplaces special HTML characters in HTMLElement attribute with their relative HTML entity values.
alert( CKEDITOR.tools.htmlEncodeAttr( '<a " b >' ) ); // '<a " b >'Parameters
The : Stringattribute value to be encoded.
Returns
StringThe encoded value.
indexOf( array, value ) → NumberCKEDITOR.tools#indexOfReturns the index of an element in an array.
var letters = [ 'a', 'b', 0, 'c', false ]; alert( CKEDITOR.tools.indexOf( letters, '0' ) ); // -1 because 0 !== '0' alert( CKEDITOR.tools.indexOf( letters, false ) ); // 4 because 0 !== falseParameters
array : ArrayThe array to be searched.
value : Object | FunctionThe element to be found. This can be an evaluation function which receives a single parameter call for each entry in the array, returning
trueif the entry matches.
Returns
NumberThe (zero-based) index of the first entry that matches the entry, or
-1if not found.
isArray( object ) → BooleanCKEDITOR.tools#isArrayChecks if an object is an Array.
alert( CKEDITOR.tools.isArray( [] ) ); // true alert( CKEDITOR.tools.isArray( 'Test' ) ); // falseParameters
object : ObjectThe object to be checked.
Returns
Booleantrueif the object is an Array, otherwisefalse.
isEmpty( object ) → BooleanCKEDITOR.tools#isEmptyWhether the object contains no properties of its own.
Parameters
object : Object
Returns
Boolean
-
Converts a keystroke to its string representation.
var lang = editor.lang.common.keyboard; var shortcut = CKEDITOR.tools.keystrokeToArray( lang, CKEDITOR.CTRL + 88 ); console.log( shortcut.display ); // [ 'CTRL', 'X' ], on Mac [ '⌘', 'X' ]. console.log( shortcut.aria ); // [ 'CTRL', 'X' ], on Mac [ 'COMMAND', 'X' ].Parameters
lang : ObjectA language object with the key name translation.
keystroke : NumberThe keystroke to convert.
Returns
Object- Properties
display : String[]An array of strings that should be used for visible labels. For Mac devices it uses
⌥for Alt,⇧for Shift and⌘for Command.aria : String[]An array of strings that should be used for ARIA descriptions. It does not use special characters such as
⌥,⇧or⌘.
-
Converts a keystroke to its string representation. Returns exactly the same members as keystrokeToArray, but the returned object contains strings of keys joined with "+" rather than an array of keystrokes.
var lang = editor.lang.common.keyboard; var shortcut = CKEDITOR.tools.keystrokeToString( lang, CKEDITOR.CTRL + 88 ); console.log( shortcut.display ); // 'Ctrl + X', on Mac '⌘ + X'. console.log( shortcut.aria ); // 'Ctrl + X', on Mac 'Cmd + X'.Parameters
lang : ObjectA language object with the key name translation.
keystroke : NumberThe keystroke to convert.
Returns
ObjectSee keystrokeToArray.
Propertiesdisplay : Stringaria : String
ltrim( str ) → StringCKEDITOR.tools#ltrimRemoves spaces from the start (left) of a string. The following characters are removed: space, tab, line break, line feed.
alert( CKEDITOR.tools.ltrim( ' example ' ); // 'example 'Parameters
str : StringThe text from which the spaces will be removed.
Returns
StringThe modified string excluding the removed spaces.
normalizeCssText( styleText, [ nativeNormalize ] ) → StringCKEDITOR.tools#normalizeCssTextNormalizes CSS data in order to avoid differences in the style attribute.
Parameters
styleText : StringThe style data to be normalized.
[ nativeNormalize ] : BooleanParse the data using the browser.
Defaults to
false
Returns
StringThe normalized value.
-
Normalizes hexadecimal notation so that the color string is always 6 characters long and lowercase.
Note: This method is deprecated, instead use CKEDITOR.tools.color to create color and CKEDITOR.tools.color.getHex method to get its hexadecimal representation. Since it returns uppercase string, use
toLowerCase()to get lowercase representation:var color = new CKEDITOR.tools.color( '#FFF' ); // Create color instance. console.log( color.getHex().toLowerCase() ); // #ffffffParameters
styleText : StringThe style data (or just a string containing hex colors) to be converted.
Returns
StringThe style data with hex colors normalized.
-
Normalizes mouse buttons across browsers.
Only Internet Explorer 8 and Internet Explorer 9 in Quirks Mode or Compatibility View have different button mappings than other browsers:
+--------------+--------------------------+----------------+ | Mouse button | IE 8 / IE 9 CM / IE 9 QM | Other browsers | +--------------+--------------------------+----------------+ | Left | 1 | 0 | +--------------+--------------------------+----------------+ | Middle | 4 | 1 | +--------------+--------------------------+----------------+ | Right | 2 | 2 | +--------------+--------------------------+----------------+The normalization is conducted only in browsers that use non-standard button mappings, returning the passed parameter in every other browser. Therefore values for IE < 9 are mapped to values used in the rest of the browsers. For example, the code below will return the following results in IE8:
console.log( CKEDITOR.tools.normalizeMouseButton( 1 ) ); // 0 console.log( CKEDITOR.tools.normalizeMouseButton( 4 ) ); // 1 console.log( CKEDITOR.tools.normalizeMouseButton( 2 ) ); // 2In other browsers it will simply return the passed values.
With the
reversedparameter set totrue, values from the rest of the browsers are mapped to IE < 9 values in IE < 9 browsers. This means that IE8 will return the following results:console.log( CKEDITOR.tools.normalizeMouseButton( 0, true ) ); // 1 console.log( CKEDITOR.tools.normalizeMouseButton( 1, true ) ); // 4 console.log( CKEDITOR.tools.normalizeMouseButton( 2, true ) ); // 2In other browsers it will simply return the passed values.
Parameters
button : NumberMouse button identifier.
[ reverse ] : BooleanIf set to
true, the conversion is reversed: values returned by other browsers are converted to IE8 values.Defaults to
false
Returns
NumberNormalized mouse button identifier.
-
Compares two objects.
Note: This method performs shallow, non-strict comparison.
Parameters
left : Objectright : Object[ onlyLeft ] : BooleanCheck only the properties that are present in the
leftobject.
Returns
BooleanWhether objects are identical.
-
Returns an array of passed object keys.
console.log( CKEDITOR.tools.object.keys( { foo: 1, bar: false } ); // -> [ 'foo', 'bar' ]Parameters
obj : Object
Returns
ArrayObject's keys.
override( originalFunction, functionBuilder ) → FunctionCKEDITOR.tools#overrideCreates a function override.
var obj = { myFunction: function( name ) { alert( 'Name: ' + name ); } }; obj.myFunction = CKEDITOR.tools.override( obj.myFunction, function( myFunctionOriginal ) { return function( name ) { alert( 'Overriden name: ' + name ); myFunctionOriginal.call( this, name ); }; } );Parameters
originalFunction : FunctionThe function to be overridden.
functionBuilder : FunctionA function that returns the new function. The original function reference will be passed to this function.
Returns
FunctionThe new function.
parseCssText( styleText, [ normalize ], [ nativeNormalize ] ) → ObjectCKEDITOR.tools#parseCssTextTurns inline style text properties into one hash.
Parameters
styleText : StringThe style data to be parsed.
[ normalize ] : BooleanNormalize properties and values (e.g. trim spaces, convert to lower case).
Defaults to
false[ nativeNormalize ] : BooleanParse the data using the browser.
Defaults to
false
Returns
ObjectThe object containing parsed properties.
prototypedCopy( source ) → ObjectCKEDITOR.tools#prototypedCopyCreates an object which is an instance of a class whose prototype is a predefined object. All properties defined in the source object are automatically inherited by the resulting object, including future changes to it.
Parameters
source : ObjectThe source object to be used as the prototype for the final object.
Returns
ObjectThe resulting copy.
removeFunction( ref )CKEDITOR.tools#removeFunctionRemoves the function reference created with addFunction.
Parameters
ref : NumberThe function reference created with addFunction.
repeat( str, times ) → StringCKEDITOR.tools#repeatString specified by
strrepeatstimestimes.Parameters
str : Stringtimes : Number
Returns
String
rtrim( str ) → StringCKEDITOR.tools#rtrimRemoves spaces from the end (right) of a string. The following characters are removed: space, tab, line break, line feed.
alert( CKEDITOR.tools.ltrim( ' example ' ); // ' example'Parameters
str : StringThe text from which spaces will be removed.
Returns
StringThe modified string excluding the removed spaces.
search( array, value ) → ObjectCKEDITOR.tools#searchReturns the index of an element in an array.
var obj = { prop: true }; var letters = [ 'a', 'b', 0, obj, false ]; alert( CKEDITOR.tools.indexOf( letters, '0' ) ); // null alert( CKEDITOR.tools.indexOf( letters, function( value ) { // Return true when passed value has property 'prop'. return value && 'prop' in value; } ) ); // objParameters
array : ArrayThe array to be searched.
value : Object | FunctionThe element to be found. Can be an evaluation function which receives a single parameter call for each entry in the array, returning
trueif the entry matches.
Returns
ObjectObject The value that was found in an array.
-
setTimeout( func, [ milliseconds ], [ scope ], [ args ], [ ownerWindow ] ) → ObjectCKEDITOR.tools#setTimeoutExecutes a function after a specified delay.
CKEDITOR.tools.setTimeout( function() { alert( 'Executed after 2 seconds' ); }, 2000 );Parameters
func : FunctionThe function to be executed.
[ milliseconds ] : NumberThe amount of time (in milliseconds) to wait to fire the function execution.
Defaults to
0[ scope ] : ObjectThe object to store the function execution scope (the
thisobject).Defaults to
window[ args ] : Object | ArrayA single object, or an array of objects, to pass as argument to the function.
[ ownerWindow ] : ObjectThe window that will be used to set the timeout.
Defaults to
window
Returns
ObjectA value that can be used to cancel the function execution.
-
Creates a throttle buffer instance.
See the input method's documentation for example listings.
Parameters
minInterval : NumberThe minimum interval between
outputcalls in milliseconds.output : FunctionThe function that will be executed as
output.[ contextObj ] : ObjectThe object used as context to the listener call (the
thisobject).
Returns
throttle
since 4.5.0
transformPlainTextToHtml( text, enterMode ) → StringCKEDITOR.tools#transformPlainTextToHtmlTransforms text to valid HTML: creates paragraphs, replaces tabs with non-breaking spaces etc.
Parameters
text : StringText to transform.
enterMode : NumberEditor Enter mode.
Returns
StringHTML generated from the text.
trim( str ) → StringCKEDITOR.tools#trimRemoves spaces from the start and the end of a string. The following characters are removed: space, tab, line break, line feed.
alert( CKEDITOR.tools.trim( ' example ' ); // 'example'Parameters
str : StringThe text from which the spaces will be removed.
Returns
StringThe modified string without the boundary spaces.
tryThese( fn ) → MixedCKEDITOR.tools#tryTheseReturns the first successfully executed return value of a function that does not throw any exception.
Parameters
fn : Function
Returns
Mixed
-
Serializes the
style name => valuehash to a style text.var styleObj = CKEDITOR.tools.parseCssText( 'color: red; border: none' ); console.log( styleObj.color ); // -> 'red' CKEDITOR.tools.writeCssText( styleObj ); // -> 'color:red; border:none' CKEDITOR.tools.writeCssText( styleObj, true ); // -> 'border:none; color:red'Parameters
styles : ObjectThe object contaning style properties.
[ sort ] : BooleanWhether to sort CSS properties.
Returns
StringThe serialized style text.
since 4.15.1 deprecated 4.16.0 private
_isValidColorFormat( colorCode ) → BooleanCKEDITOR.tools#_isValidColorFormatValidates color string correctness. Works for:
- hexadecimal notation,
- RGB or RGBA notation,
- HSL or HSLA notation,
- HTML color name.
Note: This method is deprecated, instead use use CKEDITOR.tools.color to create color class and check if passed color string is valid.
Note: This method is intended mostly for the input validations. It performs no logical check e.g.: are the values in RGB format correct or does the passed color name actually exists?
See the examples below:
CKEDITOR.tools._isValidColorFormat( '123456' ); // true CKEDITOR.tools._isValidColorFormat( '#4A2' ); // true CKEDITOR.tools._isValidColorFormat( 'rgb( 40, 40, 150 )' ); // true CKEDITOR.tools._isValidColorFormat( 'hsla( 180, 50%, 50%, 0.2 )' ); // true CKEDITOR.tools._isValidColorFormat( '333333;' ); // false CKEDITOR.tools._isValidColorFormat( '<833AF2>' ); // false // But also: CKEDITOR.tools._isValidColorFormat( 'ckeditor' ); // true CKEDITOR.tools._isValidColorFormat( '1234' ); // true CKEDITOR.tools._isValidColorFormat( 'hsrgb( 100 )' ); // trueParameters
colorCode : StringString to be validated.
Returns
BooleanWhether the input string contains only allowed characters.