Subversion Repositories Applications.papyrus

Rev

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

Rev Author Line No. Line
431 ddelon 1
/*
2
 * FCKeditor - The text editor for internet
3
 * Copyright (C) 2003-2005 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
 * File Name: fckcoreextensions.js
12
 * 	Some extensions to the Javascript Core.
13
 *
14
 * File Authors:
15
 * 		Frederico Caldeira Knabben (fredck@fckeditor.net)
16
 */
17
 
18
// Extends the Array object, creating a "addItem" method on it.
19
Array.prototype.addItem = function( item )
20
{
21
	var i = this.length ;
22
	this[ i ] = item ;
23
	return i ;
24
}
25
 
26
Array.prototype.indexOf = function( value )
27
{
28
	for ( var i = 0 ; i < this.length ; i++ )
29
	{
30
		if ( this[i] == value )
31
			return i ;
32
	}
33
	return -1 ;
34
}
35
 
36
String.prototype.startsWith = function( value )
37
{
38
	return ( this.substr( 0, value.length ) == value ) ;
39
}
40
 
41
// Extends the String object, creating a "endsWith" method on it.
42
String.prototype.endsWith = function( value, ignoreCase )
43
{
44
	var L1 = this.length ;
45
	var L2 = value.length ;
46
 
47
	if ( L2 > L1 )
48
		return false ;
49
 
50
	if ( ignoreCase )
51
	{
52
		var oRegex = new RegExp( value + '$' , 'i' ) ;
53
		return oRegex.test( this ) ;
54
	}
55
	else
56
		return ( L2 == 0 || this.substr( L1 - L2, L2 ) == value ) ;
57
}
58
 
59
String.prototype.remove = function( start, length )
60
{
61
	var s = '' ;
62
 
63
	if ( start > 0 )
64
		s = this.substring( 0, start ) ;
65
 
66
	if ( start + length < this.length )
67
		s += this.substring( start + length , this.length ) ;
68
 
69
	return s ;
70
}
71
 
72
String.prototype.trim = function()
73
{
74
	return this.replace( /(^\s*)|(\s*$)/g, '' ) ;
75
}
76
 
77
String.prototype.ltrim = function()
78
{
79
	return this.replace( /^\s*/g, '' ) ;
80
}
81
 
82
String.prototype.rtrim = function()
83
{
84
	return this.replace( /\s*$/g, '' ) ;
85
}
86
 
87
String.prototype.replaceNewLineChars = function( replacement )
88
{
89
	return this.replace( /\n/g, replacement ) ;
90
}