Integrate trim() into any String
Adds the trim() function to all String objects
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ""); }
Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world (or not, you can keep them private!)
String.prototype.trim = function() { return this.replace(/^\s+|\s+$/, ""); }
hide_warning = "window.setTimeout('Effect.BlindUp($(\\'flash_box\\'), {duration:.3})', #{@warning_timeout ||= 8000})"
Object.extend(Event, { _domReady : function() { if (arguments.callee.done) return; arguments.callee.done = true; if (this._timer) clearInterval(this._timer); this._readyCallbacks.each(function(f) { f() }); this._readyCallbacks = null; }, onDOMReady : function(f) { if (!this._readyCallbacks) { var domReady = this._domReady.bind(this); if (document.addEventListener) document.addEventListener("DOMContentLoaded", domReady, false); /*@cc_on @*/ /*@if (@_win32) document.write("<script id=__ie_onload defer src=javascript:void(0)><\/script>"); document.getElementById("__ie_onload").onreadystatechange = function() { if (this.readyState == "complete") domReady(); }; /*@end @*/ if (/WebKit/i.test(navigator.userAgent)) { this._timer = setInterval(function() { if (/loaded|complete/.test(document.readyState)) domReady(); }, 10); } Event.observe(window, 'load', domReady); Event._readyCallbacks = []; } Event._readyCallbacks.push(f); } });
Event.onDOMReady(function(){ alert('DOM is loaded!'); });
Position.Center = function(element, parent) { var w, h, pw, ph; var d = Element.getDimensions(element); w = d.width; h = d.height; Position.prepare(); if (!parent) { var ws = Position.GetWindowSize(); pw = ws[0]; ph = ws[1]; } else { pw = parent.offsetWidth; ph = parent.offsetHeight; } element.style.top = (ph/2) - (h/2) - Position.deltaY + "px"; element.style.left = (pw/2) - (w/2) - Position.deltaX + "px"; }
Position.GetWindowSize = function(w) { w = w ? w : window; var width = w.innerWidth || (w.document.documentElement.clientWidth || w.document.body.clientWidth); var height = w.innerHeight || (w.document.documentElement.clientHeight || w.document.body.clientHeight); return [width, height] }
function min() { return $A(arguments).min(); } function max() { return $A(arguments).max(); }
// Function.prototype.toEvent, .bindAsEventListener( args ) REM2006 for this.js Api // Important: sends event as the first argument to your function in IE also!, // event XY [Array][x,y] is passed as last arg, your passed args are in the middle :) // example: myElement.onclick= myFunc.toEvent( myArguments ); http://richard-m.blogspot.com/ // Function.prototype.toEvent = Function.prototype.bindAsEventListener= function(){ var _method= this, r=[], len=arguments.length, i=0;//alert(len) for (i;i<len;i++){ r[i+1]=arguments[i] } return function( ev ){ r[0]= ev= ev || event; var db=document.body, dd=document.documentElement; r[r.length++]=(ev.pageX)? [ev.pageX, ev.pageY] : [ev.clientX + db.scrollLeft+ dd.scrollLeft, ev.clientY + db.scrollTop + dd.scrollTop]; return _method.apply(ev.target|| ev.srcElement, r); }; };
registers: { onCreate: function() { if(Ajax.activeRequestCount>0) new Effect.Appear('indicate'); }, onComplete: function() { if(Ajax.activeRequestCount==0) new Effect.Fade('indicate', {queue: 'end'}); } } Ajax.Responders.register(Note.registers);
putCenter: function(item) { item = $(item); var xy = item.getDimensions(); var win = this.windowDimensions(); var scrol = this.scrollOffset(); item.style.left = (win[0] / 2) + scrol[0] - (xy.width / 2) + "px"; item.style.top = (win[1] / 2) + scrol[1] - (xy.height / 2) + "px"; }, fullScreen: function(item) { item = $(item); var win = this.windowDimensions(); var scrol = this.scrollOffset(); item.style.height = scrol[1] + win[1] + "px"; }, windowDimensions: function() { var x, y; if (self.innerHeight) { // all except Explorer x = self.innerWidth; y = self.innerHeight; } else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode x = document.documentElement.clientWidth; y = document.documentElement.clientHeight; } else if (document.body) { // other Explorers x = document.body.clientWidth; y = document.body.clientHeight; } if (!x) x = 0; if (!y) y = 0; arrayWindowSize = new Array(x,y); return arrayWindowSize; }, scrollOffset: function() { var x, y; if (self.pageYOffset) { // all except Explorer x = self.pageXOffset; y = self.pageYOffset; } else if (document.documentElement && document.documentElement.scrollTop) { // Explorer 6 Strict x = document.documentElement.scrollLeft; y = document.documentElement.scrollTop; } else if (document.body) { // all other Explorers x = document.body.scrollLeft; y = document.body.scrollTop; } if (!x) x = 0; if (!y) y = 0; arrayScrollOffset = new Array(x,y); return arrayScrollOffset; }
execEvent: function(el, type) { Event.observers.each(function(item,index) { if (item[0] == el && item[1] == type) { item[2](); throw $break; } }); }