JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
vanilla ckeditor-3.1
[ckeditor.git] / _source / core / tools.js
index c9d9877..6fb417b 100644 (file)
@@ -1,5 +1,5 @@
 /*\r
-Copyright (c) 2003-2009, CKSource - Frederico Knabben. All rights reserved.\r
+Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.\r
 For licensing, see LICENSE.html or http://ckeditor.com/license\r
 */\r
 \r
@@ -96,7 +96,8 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                                || ( obj instanceof String )\r
                                || ( obj instanceof Number )\r
                                || ( obj instanceof Boolean )\r
-                               || ( obj instanceof Date ) )\r
+                               || ( obj instanceof Date )\r
+                               || ( obj instanceof RegExp) )\r
                        {\r
                                return obj;\r
                        }\r
@@ -114,6 +115,15 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                },\r
 \r
                /**\r
+                * Turn the first letter of string to upper-case.\r
+                * @param {String} str\r
+                */\r
+               capitalize: function( str )\r
+               {\r
+                       return str.charAt( 0 ).toUpperCase() + str.substring( 1 ).toLowerCase();\r
+               },\r
+\r
+               /**\r
                 * Copy the properties from one object to another. By default, properties\r
                 * already present in the target object <strong>are not</strong> overwritten.\r
                 * @param {Object} target The object to be extended.\r
@@ -245,6 +255,27 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                } )(),\r
 \r
                /**\r
+                * Build the HTML snippet of a set of <style>/<link>.\r
+                * @param css {String|Array} Each of which are url (absolute) of a CSS file or\r
+                * a trunk of style text.\r
+                */\r
+               buildStyleHtml : function ( css )\r
+               {\r
+                       css = [].concat( css );\r
+                       var item, retval = [];\r
+                       for ( var i = 0; i < css.length; i++ )\r
+                       {\r
+                               item = css[ i ];\r
+                               // Is CSS style text ?\r
+                               if ( /@import|[{}]/.test(item) )\r
+                                       retval.push('<style>' + item + '</style>');\r
+                               else\r
+                                       retval.push('<link type="text/css" rel=stylesheet href="' + item + '">');\r
+                       }\r
+                       return retval.join( '' );\r
+               },\r
+\r
+               /**\r
                 * Replace special HTML characters in a string with their relative HTML\r
                 * entity values.\r
                 * @param {String} text The string to be encoded.\r
@@ -621,6 +652,22 @@ For licensing, see LICENSE.html or http://ckeditor.com/license
                repeat : function( str, times )\r
                {\r
                        return new Array( times + 1 ).join( str );\r
+               },\r
+\r
+               tryThese : function()\r
+               {\r
+                       var returnValue;\r
+                       for ( var i = 0, length = arguments.length; i < length; i++ )\r
+                       {\r
+                               var lambda = arguments[i];\r
+                               try\r
+                               {\r
+                                       returnValue = lambda();\r
+                                       break;\r
+                               }\r
+                               catch (e) {}\r
+                       }\r
+                       return returnValue;\r
                }\r
        };\r
 })();\r