Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1075 ddelon 1
/*
2
 * FCKeditor - The text editor for internet
3
 * Copyright (C) 2003-2006 Frederico Caldeira Knabben
4
 *
5
 * Licensed under the terms of the GNU Lesser General Public License:
6
 * 		http://www.opensource.org/licenses/lgpl-license.php
7
 *
8
 * For further information visit:
9
 * 		http://www.fckeditor.net/
10
 *
11
 * "Support Open Source software. What about a donation today?"
12
 *
13
 * File Name: fckjscoreextensions.js
14
 * 	Extensions to the JavaScript Core.
15
 *
16
 * 	All custom extentions functions are PascalCased to differ from the standard
17
 * 	camelCased ones.
18
 *
19
 * File Authors:
20
 * 		Frederico Caldeira Knabben (fredck@fckeditor.net)
21
 */
22
 
23
String.prototype.Contains = function( textToCheck )
24
{
25
	return ( this.indexOf( textToCheck ) > -1 ) ;
26
}
27
 
28
String.prototype.Equals = function()
29
{
30
	for ( var i = 0 ; i < arguments.length ; i++ )
31
		if ( this == arguments[i] )
32
			return true ;
33
 
34
	return false ;
35
}
36
 
37
String.prototype.ReplaceAll = function( searchArray, replaceArray )
38
{
39
	var replaced = this ;
40
 
41
	for ( var i = 0 ; i < searchArray.length ; i++ )
42
	{
43
		replaced = replaced.replace( searchArray[i], replaceArray[i] ) ;
44
	}
45
 
46
	return replaced ;
47
}
48
 
49
Array.prototype.AddItem = function( item )
50
{
51
	var i = this.length ;
52
	this[ i ] = item ;
53
	return i ;
54
}
55
 
56
Array.prototype.indexOf = function( value )
57
{
58
	for ( var i = 0 ; i < this.length ; i++ )
59
	{
60
		if ( this[i] == value )
61
			return i ;
62
	}
63
	return -1 ;
64
}
65
 
66
String.prototype.startsWith = function( value )
67
{
68
	return ( this.substr( 0, value.length ) == value ) ;
69
}
70
 
71
// Extends the String object, creating a "endsWith" method on it.
72
String.prototype.endsWith = function( value, ignoreCase )
73
{
74
	var L1 = this.length ;
75
	var L2 = value.length ;
76
 
77
	if ( L2 > L1 )
78
		return false ;
79
 
80
	if ( ignoreCase )
81
	{
82
		var oRegex = new RegExp( value + '$' , 'i' ) ;
83
		return oRegex.test( this ) ;
84
	}
85
	else
86
		return ( L2 == 0 || this.substr( L1 - L2, L2 ) == value ) ;
87
}
88
 
89
String.prototype.remove = function( start, length )
90
{
91
	var s = '' ;
92
 
93
	if ( start > 0 )
94
		s = this.substring( 0, start ) ;
95
 
96
	if ( start + length < this.length )
97
		s += this.substring( start + length , this.length ) ;
98
 
99
	return s ;
100
}
101
 
102
String.prototype.trim = function()
103
{
104
	return this.replace( /(^\s*)|(\s*$)/g, '' ) ;
105
}
106
 
107
String.prototype.ltrim = function()
108
{
109
	return this.replace( /^\s*/g, '' ) ;
110
}
111
 
112
String.prototype.rtrim = function()
113
{
114
	return this.replace( /\s*$/g, '' ) ;
115
}
116
 
117
String.prototype.replaceNewLineChars = function( replacement )
118
{
119
	return this.replace( /\n/g, replacement ) ;
120
}