source: extensions/FCKEditor/editor/_source/fckjscoreextensions.js @ 3295

Last change on this file since 3295 was 3295, checked in by patdenice, 15 years ago

New extension added:
FCK Editor (2.0.a)

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