import rt 3.8.7
[freeside.git] / rt / share / html / NoAuth / RichText / FCKeditor / editor / _source / fckjscoreextensions.js
1 /*\r
2  * FCKeditor - The text editor for Internet - http://www.fckeditor.net\r
3  * Copyright (C) 2003-2009 Frederico Caldeira Knabben\r
4  *\r
5  * == BEGIN LICENSE ==\r
6  *\r
7  * Licensed under the terms of any of the following licenses at your\r
8  * choice:\r
9  *\r
10  *  - GNU General Public License Version 2 or later (the "GPL")\r
11  *    http://www.gnu.org/licenses/gpl.html\r
12  *\r
13  *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")\r
14  *    http://www.gnu.org/licenses/lgpl.html\r
15  *\r
16  *  - Mozilla Public License Version 1.1 or later (the "MPL")\r
17  *    http://www.mozilla.org/MPL/MPL-1.1.html\r
18  *\r
19  * == END LICENSE ==\r
20  *\r
21  * Extensions to the JavaScript Core.\r
22  *\r
23  * All custom extensions functions are PascalCased to differ from the standard\r
24  * camelCased ones.\r
25  */\r
26 \r
27 String.prototype.Contains = function( textToCheck )\r
28 {\r
29         return ( this.indexOf( textToCheck ) > -1 ) ;\r
30 }\r
31 \r
32 String.prototype.Equals = function()\r
33 {\r
34         var aArgs = arguments ;\r
35 \r
36         // The arguments could also be a single array.\r
37         if ( aArgs.length == 1 && aArgs[0].pop )\r
38                 aArgs = aArgs[0] ;\r
39 \r
40         for ( var i = 0 ; i < aArgs.length ; i++ )\r
41         {\r
42                 if ( this == aArgs[i] )\r
43                         return true ;\r
44         }\r
45         return false ;\r
46 }\r
47 \r
48 String.prototype.IEquals = function()\r
49 {\r
50         var thisUpper = this.toUpperCase() ;\r
51 \r
52         var aArgs = arguments ;\r
53 \r
54         // The arguments could also be a single array.\r
55         if ( aArgs.length == 1 && aArgs[0].pop )\r
56                 aArgs = aArgs[0] ;\r
57 \r
58         for ( var i = 0 ; i < aArgs.length ; i++ )\r
59         {\r
60                 if ( thisUpper == aArgs[i].toUpperCase() )\r
61                         return true ;\r
62         }\r
63         return false ;\r
64 }\r
65 \r
66 String.prototype.ReplaceAll = function( searchArray, replaceArray )\r
67 {\r
68         var replaced = this ;\r
69 \r
70         for ( var i = 0 ; i < searchArray.length ; i++ )\r
71         {\r
72                 replaced = replaced.replace( searchArray[i], replaceArray[i] ) ;\r
73         }\r
74 \r
75         return replaced ;\r
76 }\r
77 \r
78 String.prototype.StartsWith = function( value )\r
79 {\r
80         return ( this.substr( 0, value.length ) == value ) ;\r
81 }\r
82 \r
83 // Extends the String object, creating a "EndsWith" method on it.\r
84 String.prototype.EndsWith = function( value, ignoreCase )\r
85 {\r
86         var L1 = this.length ;\r
87         var L2 = value.length ;\r
88 \r
89         if ( L2 > L1 )\r
90                 return false ;\r
91 \r
92         if ( ignoreCase )\r
93         {\r
94                 var oRegex = new RegExp( value + '$' , 'i' ) ;\r
95                 return oRegex.test( this ) ;\r
96         }\r
97         else\r
98                 return ( L2 == 0 || this.substr( L1 - L2, L2 ) == value ) ;\r
99 }\r
100 \r
101 String.prototype.Remove = function( start, length )\r
102 {\r
103         var s = '' ;\r
104 \r
105         if ( start > 0 )\r
106                 s = this.substring( 0, start ) ;\r
107 \r
108         if ( start + length < this.length )\r
109                 s += this.substring( start + length , this.length ) ;\r
110 \r
111         return s ;\r
112 }\r
113 \r
114 String.prototype.Trim = function()\r
115 {\r
116         // We are not using \s because we don't want "non-breaking spaces to be caught".\r
117         return this.replace( /(^[ \t\n\r]*)|([ \t\n\r]*$)/g, '' ) ;\r
118 }\r
119 \r
120 String.prototype.LTrim = function()\r
121 {\r
122         // We are not using \s because we don't want "non-breaking spaces to be caught".\r
123         return this.replace( /^[ \t\n\r]*/g, '' ) ;\r
124 }\r
125 \r
126 String.prototype.RTrim = function()\r
127 {\r
128         // We are not using \s because we don't want "non-breaking spaces to be caught".\r
129         return this.replace( /[ \t\n\r]*$/g, '' ) ;\r
130 }\r
131 \r
132 String.prototype.ReplaceNewLineChars = function( replacement )\r
133 {\r
134         return this.replace( /\n/g, replacement ) ;\r
135 }\r
136 \r
137 String.prototype.Replace = function( regExp, replacement, thisObj )\r
138 {\r
139         if ( typeof replacement == 'function' )\r
140         {\r
141                 return this.replace( regExp,\r
142                         function()\r
143                         {\r
144                                 return replacement.apply( thisObj || this, arguments ) ;\r
145                         } ) ;\r
146         }\r
147         else\r
148                 return this.replace( regExp, replacement ) ;\r
149 }\r
150 \r
151 Array.prototype.IndexOf = function( value )\r
152 {\r
153         for ( var i = 0 ; i < this.length ; i++ )\r
154         {\r
155                 if ( this[i] == value )\r
156                         return i ;\r
157         }\r
158         return -1 ;\r
159 }\r