/*jslint laxbreak: true, forin: true, onevar: true, undef: true, eqeqeq: true, newcap: true, immed: true, strict: true */
"use strict";
var $ =
(function(window){
function Rocket(element){
this.element = element;
this.length = 1;
}
function Rockets(elements){
this.elements = elements;
this.length = elements.length;
}
//event handlers won't be gc'd if they're not attached to window
//can either attach these variables to window, or add an onbeforeunload to null them
//this sucks, but there are no other ways to avoid self-referencing event handlers in IE
window.ROCKET_ADDONFUNCTIONS = [];
window.ROCKET_ADDONCALLBACKS = [];
window.ROCKET_OBJECTS = [];
window.ROCKET_FUNCTIONS = [];
var //private variables and helper functions
$ //is set to this function returning this function
,document = window.document
,setTimeout = window.setTimeout
,clearTimeout = window.clearTimeout
,Array = window.Array
,Object = window.Object
,String = window.String
,Date = window.Date
,RegExp = window.RegExp
,isFinite = window.isFinite
,isNaN = window.isNaN
,parseFloat = window.parseFloat
,parseInt = window.parseInt
,encodeURIComponent = window.encodeURIComponent
,arrayPrototype = Array.prototype
,arraySlice = arrayPrototype.slice
,defaultView = document.defaultView
,documentBody = function(){ return document.getElementsByTagName("body")[0]; }
,Math = window.Math
,mathCos = Math.cos
,MathPI = Math.PI
,mathRandom = Math.random
,mathMin = Math.min
,mathMax = Math.max
,mathCosPITimes = function(arg){ return mathCos(MathPI * arg); }
,propertiesThatShouldBeInts = /px$/
,simpleHTMLTag = /<[^>]+>/g
,stringTrim = /^(?:\s|\u00A0)+|(?:\s|\u00A0)+$/g
,urlHasQuestionMark = /\/[^\/]*\?[^\/]*$/g
,dollarSignRightParenComma = /[\$\),]/g
,addedStyleRules = {}
,_framesPerSecond = 20
,millisecondsPerFrame = 1000 / _framesPerSecond
,rocketCompleteSuffix = -1
,_ajaxTimeout // = 60 * 1000
,_ajaxCacheTimeout = 60 * 1000
,reusable_XMLHttpRequest = false
,noOp = function(){return true;}
,closure =
function(obj){
var objId,funId;
window.ROCKET_OBJECTS[objId = obj.ROCKET_GUID] = obj;
if (typeof (funId = this.ROCKET_GUID) === "undefined"){
window.ROCKET_FUNCTIONS[funId = (this.ROCKET_GUID = window.ROCKET_FUNCTIONS.length)] = this;
}
obj = null;
return function(){
return window.ROCKET_FUNCTIONS[funId].apply(window.ROCKET_OBJECTS[objId], arguments);
};
}
,addClass =
function(className){
if(!this) { return; }; // JEZ: Not sure about this 8/1/2013
if(className.indexOf(" ") === -1){
if((" " + this.className + " ").indexOf(" " + className + " ") === -1){
this.className += (this.className.charAt(0) ? " " : "") + className;
}
}
else{
var classNames = className.split(" "),i = 0,len = classNames.length;
className = this.className;
for(;i < len; ++i){
if((" " + className + " ").indexOf(" " + classNames[i] + " ") === -1){
className += (className.charAt(0) ? " " : "") + classNames[i];
}
}
this.className = className;
}
return this;
}
,removeClass =
function(className){
if(!this) { return; }; // JEZ: Not sure about this 8/1/2013
if(typeof className === "undefined"){
this.className = "";
}
else if(className.indexOf(" ") === -1){
this.className = (" " + this.className + " ").replace(" " + className + " "," ").replace(stringTrim,"");
}
else{
var classNames = className.split(" "),i = 0,len = classNames.length;
className = " " + this.className + " ";
for(;i < len; ++i){
className = className.replace(" " + classNames[i] + " "," ");
}
this.className = className.replace(stringTrim,"");
}
return this;
}
,hasClass =
function(className){
return (" " + this.className + " ").indexOf(" " + className + " ") !== -1;
}
,toggleClass =
function(className){
return hasClass.call(this,className) ? removeClass.call(this,className) : addClass.call(this,className);
}
,indexOf =
(function(){
if(typeof arrayPrototype.indexOf === "function"){
return arrayPrototype.indexOf;
}
else{
return function(element,start){
if(typeof start === "undefined"){
start = 0;
}
for(var len = this.length; start < len; ++start){
if(this[start] === element){
return start;
}
}
return -1;
};
}
}())
,getPosition =
function(){
var element = this.offsetParent, left = this.offsetLeft, top = this.offsetTop;
if(element === null){
return [left,top];
}
do{
left += element.offsetLeft;
top += element.offsetTop;
}
while((element = element.offsetParent) !== null);
return [left,top];
}
,elementsByClass =
function(theClassName,self){
var ret;
if(typeof document.querySelectorAll !== "undefined"){
try{
ret = arraySlice.call(self.querySelectorAll("." + theClassName),0);
elementsByClass = function(theClassName,self){
return arraySlice.call(self.querySelectorAll("." + theClassName),0);
};
return ret;
}
catch(e){
elementsByClass = function(theClassName,self){
for(var j = 0, ret = [], elements = self.querySelectorAll("." + theClassName), len = elements.length; j < len; ++j){
ret[j] = elements[j];
}
return ret;
};
}
}
else{
if(typeof document.getElementsByClassName === "function"){
try{
ret = arraySlice.call(self.getElementsByClassName(theClassName),0);
elementsByClass = function(theClassName,self){
return arraySlice.call(self.getElementsByClassName(theClassName),0);
};
return ret;
}
catch(f){
elementsByClass = function(theClassName,self){
for(var j = 0, ret = [], elements = self.getElementsByClassName(theClassName), len = elements.length; j < len; ++j){
ret[j] = elements[j];
}
return ret;
};
}
}
else{
elementsByClass = function(theClassName,self){
theClassName = new RegExp("(?:^|\\s)" + theClassName + "(?:$|\\s)");
for(var i = 0, j = -1, documentAll = self.getElementsByTagName("*"), len = documentAll.length, current, ret = []; i < len; ++i){
current = documentAll[i];
if(theClassName.test(current.className) === true){
ret[++j] = current;
}
}
return ret;
};
}
}
return elementsByClass(theClassName,self);
}
,elementsByTag =
function(tagName){
var ret;
try{
ret = arraySlice.call(this.getElementsByTagName(tagName),0);
elementsByTag = function(tagName){
if(tagName === "body"){
return [documentBody()];
}
return arraySlice.call(this.getElementsByTagName(tagName),0);
};
return ret;
}
catch(e){
elementsByTag = function(tagName){
if(tagName === "body"){
return [documentBody()];
}
for(var j = 0, elements = this.getElementsByTagName(tagName), len = elements.length, ret = []; j < len; ++j){
ret[j] = elements[j];
}
return ret;
};
return elementsByTag.call(this,tagName);
}
}
,getChildren =
function(){
for(var i = -1, j = 0, elements = this.childNodes, len = elements.length, ret = [], thisj; j < len; ++j){
if((thisj = elements[j]).nodeType === 1){
ret[++i] = thisj;
}
}
return ret;
}
,elementsByTagDotClassName =
function(tagDotClass,dot){
var ret;
if(typeof document.querySelectorAll !== "undefined"){
try{
ret = arraySlice.call(this.querySelectorAll(tagDotClass),0);
elementsByTagDotClassName = function(tagDotClass){
return arraySlice.call(this.querySelectorAll(tagDotClass),0);
};
return ret;
}
catch(e){
elementsByTagDotClassName = function(tagDotClass){
for(var j = 0, ret = [], elements = this.querySelectorAll(tagDotClass), len = elements.length; j < len; ++j){
ret[j] = elements[j];
}
return ret;
};
}
}
else{
elementsByTagDotClassName = function(tagDotClass,dot){
for(var theElement,classNameRegExp = new RegExp("(?:^|\\s)" + tagDotClass.substr(dot + 1) + "(?:$|\\s)"), tagElements = this.getElementsByTagName(tagDotClass.substr(0,dot)), ret = [], j = 0, i = -1, len = tagElements.length; j < len; ++j){
if(classNameRegExp.test((theElement = tagElements[j]).className) === true){
ret[++i] = theElement;
}
}
return ret;
};
}
return elementsByTagDotClassName.call(this,tagDotClass,dot);
}
,elementsBySelector =
function(selector,space){
var ret;
if(typeof document.querySelectorAll !== "undefined"){
try{
ret = arraySlice.call(document.querySelectorAll(selector),0);
elementsBySelector = function(selector){
return arraySlice.call(document.querySelectorAll(selector),0);
};
return ret;
}
catch(e){
elementsBySelector = function(selector){
for(var j = 0, ret = [], elements = document.querySelectorAll(selector), len = elements.length; j < len; ++j){
ret[j] = elements[j];
}
return ret;
};
}
}
else{
elementsBySelector = function(selector,space){
var rightElements = selector.substr(space + 1), charZero = rightElements.charAt(0), testFunction, functionParam, functionSecondParam, i = 0, elementParent, theRightElement, rightElementsLength, ret = [], k = -1;
selector = selector.substr(0,space);
if(charZero === "."){
rightElements = elementsByClass(rightElements.substr(1),document);
}
else if((i = indexOf.call(rightElements,".")) !== -1){
rightElements = elementsByTagDotClassName.call(document,rightElements,i);
}
else{
rightElements = elementsByTag.call(document,rightElements);
}
rightElementsLength = rightElements.length;
if(selector.charAt(0) === "#"){
functionParam = selector.substr(1);
testFunction = function(element){ return element.id === functionParam; };
}
else if(selector.charAt(0) === "."){
functionParam = new RegExp("(?:^|\\s)" + selector.substr(1) + "(?:$|\\s)");
testFunction = function(element){ return functionParam.test(element.className) === true; };
}
else if((i = indexOf.call(selector,".")) !== -1){
functionParam = selector.substr(0,i).toUpperCase();
functionSecondParam = new RegExp("(?:^|\\s)" + selector.substr(i + 1) + "(?:$|\\s)");
testFunction = function(element){ return element.nodeName === functionParam && functionSecondParam.test(element.className) === true; };
}
else{
functionParam = selector.toUpperCase();
testFunction = function(element){ return element.nodeName === functionParam; };
}
for(i = 0; i < rightElementsLength; ++i){
theRightElement = rightElements[i];
elementParent = theRightElement.parentNode;
do{
if(testFunction(elementParent)){
ret[++k] = theRightElement;
break;
}
}
while((elementParent = elementParent.parentNode).nodeName !== "HTML");
}
return ret;
};
return elementsBySelector(selector,space);
}
}
,shallowCopy =
function(){
var ret = {}, property;
for(property in this){
ret[property] = this[property];
}
return ret;
}
,guid = -1
,addEventListenerFunction =
function(evt){
return function(e){
var self = this, i = 0, len = window.ROCKET_ADDONFUNCTIONS[self.ROCKET_GUID][evt].length, fncts = window.ROCKET_ADDONFUNCTIONS[self.ROCKET_GUID][evt],
eventCallbackFunction =
function(fnctsi){
return function(){
fnctsi.call(self,e);
};
};
for(; i < len; ++i){
fncts[i].call(this,e);
}
return setTimeout(function(){
for(i = 0, len = window.ROCKET_ADDONCALLBACKS[self.ROCKET_GUID][evt].length, fncts = window.ROCKET_ADDONCALLBACKS[self.ROCKET_GUID][evt]; i < len; ++i){
setTimeout(eventCallbackFunction(fncts[i]),0);
}
},0);
};
}
,attachEventFunction =
function(evt,self){
return function(e){
var theEvent = shallowCopy.call(e), i = 0, len = window.ROCKET_ADDONFUNCTIONS[self.ROCKET_GUID][evt].length, fncts = window.ROCKET_ADDONFUNCTIONS[self.ROCKET_GUID][evt],
eventCallbackFunction =
function(fnctsi){
return function(){
fnctsi.call(self,theEvent);
};
};
for(; i < len; ++i){
fncts[i].call(self,e);
}
return setTimeout(function(){
for(i = 0, len = window.ROCKET_ADDONCALLBACKS[self.ROCKET_GUID][evt].length, fncts = window.ROCKET_ADDONCALLBACKS[self.ROCKET_GUID][evt]; i < len; ++i){
setTimeout(eventCallbackFunction(fncts[i]),0);
}
},0);
};
}
,addOnFunction =
function(self,evt,fnct){
// if(typeof this.addEventListener === "function"){
// JEZ: not sure why I had to do this... 8/1/2013
if(typeof self.addEventListener === "function"){
addOnFunction = function(self,evt,fnct){
self.addEventListener(evt,closure.call(addEventListenerFunction(evt),self),false);
};
}
else{
addOnFunction = function(self,evt,fnct){
self.attachEvent("on" + evt,closure.call(attachEventFunction(evt,self),self));
};
}
addOnFunction(self,evt,fnct);
}
,addOn =
function(evt,fnct,addFunctionAsCallback){
var rocketAddOnFunctionsThisEvent,rocketAddOnCallbacksThisEvent,localGuid;
if(typeof this.ROCKET_GUID === "undefined"){
window.ROCKET_ADDONFUNCTIONS[localGuid = (this.ROCKET_GUID = ++guid)] = {};
window.ROCKET_ADDONCALLBACKS[localGuid] = {};
}
else{
localGuid = this.ROCKET_GUID;
}
if(typeof (rocketAddOnFunctionsThisEvent = window.ROCKET_ADDONFUNCTIONS[localGuid][(evt = evt.toLowerCase())]) !== "undefined"){
if(addFunctionAsCallback === true){
window.ROCKET_ADDONCALLBACKS[localGuid][evt].push(fnct);
}
else{
rocketAddOnFunctionsThisEvent.push(fnct);
}
}
else{
rocketAddOnFunctionsThisEvent = (window.ROCKET_ADDONFUNCTIONS[localGuid][evt] = []);
rocketAddOnCallbacksThisEvent = (window.ROCKET_ADDONCALLBACKS[localGuid][evt] = []);
if(addFunctionAsCallback === true){
rocketAddOnCallbacksThisEvent[0] = fnct;
}
else{
rocketAddOnFunctionsThisEvent[0] = fnct;
}
addOnFunction(this,evt,fnct);
}
return this;
}
,removeOn =
function(evt,fnct,functionWasCallback){
var fnctArray,fnctIndex,localGuid = this.ROCKET_GUID;
if(typeof localGuid !== "undefined"){
if(typeof evt === "undefined"){
for(fnctIndex in window.ROCKET_ADDONFUNCTIONS[localGuid]){
window.ROCKET_ADDONFUNCTIONS[localGuid][fnctIndex] = [];
window.ROCKET_ADDONCALLBACKS[localGuid][fnctIndex] = [];
}
}
else if(typeof fnct === "undefined"){
window.ROCKET_ADDONFUNCTIONS[localGuid][evt] = [];
window.ROCKET_ADDONCALLBACKS[localGuid][evt] = [];
}
else if((typeof window.ROCKET_ADDONFUNCTIONS[localGuid][evt] !== "undefined") && (fnctIndex = indexOf.call(fnctArray = (functionWasCallback === true ? window.ROCKET_ADDONCALLBACKS : window.ROCKET_ADDONFUNCTIONS)[localGuid][evt],fnct)) !== -1){
fnctArray.splice(fnctIndex,1);
}
}
return this;
}
,hyphensToCamelCase =
function(property){
if(property.indexOf("-") !== -1){
property = property.split("-");
property[0] = property[0].toLowerCase();
for(var i = 1, len = property.length, propertyi; i < len; ++i){
property[i] = (propertyi = property[i]).charAt(0).toUpperCase() + propertyi.substr(1).toLowerCase();
}
return property.join("");
}
return property;
}
,getPropertyValue =
function(property){
if(typeof defaultView !== "undefined"){
getPropertyValue = function(property){
property = defaultView.getComputedStyle(this,null)[hyphensToCamelCase(property)];
if(propertiesThatShouldBeInts.test(property) === true){
return parseInt(property,10);
}
return property;
};
}
else{
getPropertyValue = function(property){
if(property === "opacity"){
return (parseInt(this.currentStyle.filter.substr(14),10) / 100) || 1;
}
property = this.currentStyle[hyphensToCamelCase(property)];
if(propertiesThatShouldBeInts.test(property) === true){
return parseInt(property,10);
}
return property;
};
}
return getPropertyValue.call(this,property);
}
,setDefaultsOnArgObject =
function(argObject,defaults){
for(var i in defaults){
if(typeof argObject[i] === "undefined"){
argObject[i] = defaults[i];
}
}
}
,getRequest =
function(){
if(window.XMLHttpRequest){
getRequest = function(){
return new window.XMLHttpRequest();
};
reusable_XMLHttpRequest = true;
return getRequest();
}
else{
var i = 0,tryRequest,msxml =
[
'MSXML3.XMLHTTP'
,'MSXML2.XMLHTTP.6.0'
,'MSXML2.XMLHTTP.3.0'
,'MSXML2.XMLHTTP'
,'Microsoft.XMLHTTP'
]
,len = msxml.length;
//create function for internet explorer using best ActiveXObject's first
getRequest = function(){
return new window.ActiveXObject(msxml[i]);
};
for(; i < len; ++i){
try{
tryRequest = new window.ActiveXObject(msxml[i]);
break;
}
catch(e){}
}
return tryRequest;
}
}
,objectURI =
function(object){
if(typeof object === "undefined" || object === null){
return null;
}
var ret = [], i, j = -1;
for(i in object){
ret[++j] = encodeURIComponent(i) + "=" + encodeURIComponent(object[i]);
}
return ret.join("&");
}
,ajax =
function(url,method,params,callback,pause,pauseReference,cache,cacheReference,async){
var self = this, xmlhttp = getRequest(), parameters = objectURI(params.call(this)), cacheResult,
readyStateChangeFunction = function(){
if(xmlhttp.readyState === 4){
if(xmlhttp.status === 200){
if(cache === true){
cacheReference[parameters] = xmlhttp.responseText;
}
if(parameters === objectURI(params.call(self))){
callback.call(self,xmlhttp.responseText);
}
}
else if(xmlhttp.status !== 0){
window.alert("ajax:readystate complete and not ok");
}
}
};
if(cache === true){
clearTimeout(cacheReference[0]);
cacheReference[0] = setTimeout(function(){for(var i in cacheReference){delete cacheReference[i];}},_ajaxCacheTimeout);
if(typeof (cacheResult = cacheReference[parameters]) !== "undefined"){
callback.call(self,cacheResult);
return this;
}
}
if(method === "GET"){
if(parameters !== null){
if(url.indexOf("?") !== -1 && urlHasQuestionMark.test(url) === true){
url += "&" + parameters;
}
else{
url += "?" + parameters;
}
}
}
xmlhttp.open(method,url,async === false ? false : true);
if(method === "POST"){
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
}
xmlhttp.onreadystatechange = readyStateChangeFunction;
if(typeof pause === "undefined" || pause === 0 || pause === "0"){
xmlhttp.send(method === "GET" ? null : parameters);
if(async === false){
readyStateChangeFunction();
}
else{
if(typeof _ajaxTimeout !== "undefined"){
setTimeout(function(){xmlhttp.abort();},_ajaxTimeout);
}
}
}
else{
clearTimeout(pauseReference[0]);
pauseReference[0] = setTimeout(function(){
xmlhttp.send(method === "GET" ? null : parameters);
if(async === false){
readyStateChangeFunction();
}
else{
if(typeof _ajaxTimeout !== "undefined"){
setTimeout(function(){xmlhttp.abort();},_ajaxTimeout);
}
}
},pause);
}
return this;
}
,addAjaxOn =
function(event,url,method,parameters,callback,pause,asCallback,cache){
if(typeof this.AJAX_FUNCTIONS === "undefined"){
this.AJAX_FUNCTIONS = [];
}
var self = this, pauseReference = [null], cacheReference = {0:null};
return addOn.call(this,event,
this.AJAX_FUNCTIONS[event + url + method] = function(){
ajax.call(self,url,method,parameters,callback,pause,pauseReference,cache,cacheReference);
},asCallback);
}
,removeAjaxOn =
function(event,url,method,asCallback){
return removeOn.call(this,event,this.AJAX_FUNCTIONS[event + url + method],asCallback);
}
,addStyleRuleToDocument =
function(selector,rule){
if(typeof document.styleSheets[0].insertRule !== "undefined"){
addStyleRuleToDocument = function(selector,rule){
if(typeof addedStyleRules[selector+rule] === "undefined"){
document.styleSheets[0].insertRule(selector + "{" + rule + "}",0);
addedStyleRules[selector+rule] = true;
}
};
}
else{
addStyleRuleToDocument = function(selector,rule){
if(typeof addedStyleRules[selector+rule] === "undefined"){
document.styleSheets[0].addRule(selector,rule);
addedStyleRules[selector+rule] = true;
}
};
}
addStyleRuleToDocument(selector,rule);
}
,preventSelect =
function(){
return addOn.call(addOn.call(this,"selectstart",function(e){e.returnValue = false;},false),"mousedown",function(e){if(typeof e.preventDefault !== "undefined"){e.preventDefault();}});
}
,classOnHover =
function(className){
return addOn.call(addOn.call(addOn.call(addOn.call(this,
"mouseover",function(){addClass.call(this,className);}),
"mouseout",function(){removeClass.call(this,className);}),
"focus",function(){addClass.call(this,className);}),
"blur",function(){removeClass.call(this,className);});
}
,classOnActive =
function(className){
return addOn.call(addOn.call(addOn.call(addOn.call(addOn.call(addOn.call(this,
"mousedown",function(){addClass.call(this,className);}),
"mouseup",function(){removeClass.call(this,className);}),
"mouseout",function(){removeClass.call(this,className);}),
"keydown",function(e){if((e.which || e.keyCode) === 32){addClass.call(this,className);}}),
"keyup",function(e){if((e.which || e.keyCode) === 32){removeClass.call(this,className);}}),
"blur",function(){removeClass.call(this,className);});
}
,fadeStepper =
function(elementStyle,constant,difference,current,step){
var setOpacity;
if(typeof elementStyle.opacity !== "undefined"){
setOpacity = function(elementStyle,constant,difference,current){
elementStyle.opacity = constant + difference * mathCosPITimes(current);
};
}
else{
setOpacity = function(elementStyle,constant,difference,current){
elementStyle.filter = "alpha(opacity=" + (100 * (constant + difference * mathCosPITimes(current))) + ")";
};
}
fadeStepper = function(elementStyle,constant,difference,current,step){
setOpacity(elementStyle,constant,difference,(current += step));
if(current < 1){
setTimeout(function(){ fadeStepper(elementStyle,constant,difference,current,step); },millisecondsPerFrame);
}
else{
setOpacity(elementStyle,constant,difference,1);
}
};
fadeStepper(elementStyle,constant,difference,current,step);
}
,setSelection =
function(start,end){
if(typeof this.createTextRange !== "undefined"){
setSelection = function(start,end){
var range = this.createTextRange();
range.moveStart("character",start);
range.moveEnd("character",end - this.value.length );
range.select();
return this;
};
}
else{
setSelection = function(start,end){
this.setSelectionRange(start,end);
return this;
};
}
return setSelection.call(this,start,end);
}
,feedHTML =
function(url,interval,method,params){
ajax.call(this,url,method,params,function(responseText){this.innerHTML = responseText;});
if(typeof interval === "undefined"){
interval = 5000;
}
var self = this,
timeoutFunction =
function(){
ajax.call(self,url,method,params,
function(responseText){
this.innerHTML = responseText;
self.ROCKET_FEEDHTML_TIMEOUT = setTimeout(timeoutFunction,interval);
});
};
self.ROCKET_FEEDHTML_TIMEOUT = setTimeout(timeoutFunction,interval);
return this;
}
,loadHTML =
function(url,method,params){
return ajax.call(this,url,method,params,function(responseText){this.innerHTML = responseText;});
}
,stopFeed =
function(){
clearTimeout(this.ROCKET_FEEDHTML_TIMEOUT);
return this;
}
,fade =
function(toOpacity,duration){
var initial = parseFloat(getPropertyValue.call(this,"opacity"));
if(toOpacity !== initial){
fadeStepper(this.style,(initial + toOpacity) / 2,(initial - toOpacity) / 2,0,(millisecondsPerFrame / (typeof duration === "undefined" ? 1000 : duration)));
}
return this;
}
,zebra =
function(even,odd,hoverTr,hoverTd,clickTr,clickTd,skip){
if(typeof skip === "undefined"){
skip = 0;
}
var
rows = elementsByTag.call(this,'tr'),rowsLength = rows.length,hoverTdFunction,clickTdFunction,tds,ths,tdsLength,thsLength,
column,columns = [],thisColumn,nextColumn,thisRow,thisStyle = this.style,i,len,hoverTrFunction,
clickTrFunction = function(){toggleClass.call(this,clickTr);};
thisStyle.visibility = "hidden";
if(typeof even !== "undefined"){
for(i = skip; i < rowsLength; i += 2){
removeClass.call(addClass.call(rows[i],even),odd);
}
}
if(typeof odd !== "undefined"){
for(i = skip + 1; i < rowsLength; i += 2){
removeClass.call(addClass.call(rows[i],odd),even);
}
}
if(typeof this.ROCKET_ZEBRA_STRIPED === "undefined"){
if(typeof hoverTr !== "undefined"){
hoverTrFunction = function(){
if(typeof thisRow !== "undefined"){
if(thisRow === this){
return null;
}
removeClass.call(thisRow,hoverTr);
}
addClass.call((thisRow = this),hoverTr);
};
for(i = skip; i < rowsLength; ++i){
addOn.call(rows[i],"mouseover",hoverTrFunction);
}
}
if(typeof hoverTd !== "undefined"){
if(typeof tds === "undefined"){
tdsLength = (tds = elementsByTag.call(this,"td")).length;
thsLength = (ths = elementsByTag.call(this,"th")).length;
}
hoverTdFunction = function(){
if(column === (nextColumn = indexOf.call(getChildren.call(this.parentNode),this))){
return null;
}
var i = 0, thisColumn, len;
if(typeof column !== "undefined"){
for(thisColumn = columns[column], len = thisColumn.length; i < len; ++i){
removeClass.call(thisColumn[i],hoverTd);
}
}
if(typeof columns[(column = nextColumn)] === "undefined"){
thisColumn = (columns[column] = []);
for(i = 0; i < rowsLength; ++i){
thisColumn[i] = getChildren.call(rows[i])[column];
}
}
for(i = 0, thisColumn = columns[column], len = thisColumn.length; i < len; ++i){
addClass.call(thisColumn[i],hoverTd);
}
};
for(i = 0; i < tdsLength; ++i){
addOn.call(tds[i],"mouseover",hoverTdFunction);
}
for(i = 0; i < thsLength; ++i){
addOn.call(ths[i],"mouseover",hoverTdFunction);
}
}
if(typeof clickTr !== "undefined"){
for(i = 0; i < rowsLength; ++i){
addOn.call(rows[i],"click",clickTrFunction);
}
}
if(typeof clickTd !== "undefined"){
if(typeof tds === "undefined"){
tdsLength = (tds = elementsByTag.call(this,"td")).length;
thsLength = (ths = elementsByTag.call(this,"th")).length;
}
clickTdFunction = function(){
if(typeof columns[column = indexOf.call(getChildren.call(this.parentNode),this)] === "undefined"){
thisColumn = (columns[column] = []);
for(i = 0; i < rowsLength; ++i){
thisColumn[i] = getChildren.call(rows[i])[column];
}
}
for(i = 0, thisColumn = columns[column], len = thisColumn.length; i < len; ++i){
toggleClass.call(thisColumn[i],clickTd);
}
};
for(i = 0; i < tdsLength; ++i){
addOn.call(tds[i],"click",clickTdFunction);
}
for(i = 0; i < thsLength; ++i){
addOn.call(ths[i],"click",clickTdFunction);
}
}
}
thisStyle.visibility = "visible";
this.ROCKET_ZEBRA_STRIPED = true;
return this;
}
,sortable =
function(footer,callback,arrowUp,arrowDown){
var
i,sorts = [],columns = [],columnsLength,sortsLength,thisTh,
trs = elementsByTag.call(this,'tr'),trsLength = trs.length - 1,
ths = elementsByTag.call(trs[0],'th'),
thsLength = ths.length,
tbody = trs[0].parentNode,tds,copyTds,tdsLength,
tdsFunction =
function(){
tds = [];
var i = 0, k, theseTds, thisTd;
for(; i < trsLength; ++i){
theseTds = getChildren.call(trs[i]);
thisTd = (tds[i] = []);
for(k = 0; k < columnsLength; ++k){
thisTd[k] = theseTds[columns[k]].innerHTML;
}
}
copyTds = tds.slice(0);
tdsLength = tds.length;
},
sortFunction =
function(a,b){
for(var ret, i = 0, char_zero, char_one; i < sortsLength; ++i){
if((char_zero = sorts[i].charAt(0)) === "#" || (char_one = sorts[i].charAt(1)) === "#"){
if(char_zero === "-"){
if((ret = b[i] - a[i]) !== 0){
return ret;
}
}
else{
if((ret = a[i] - b[i]) !== 0){
return ret;
}
}
}
else if(char_zero === "$" || char_one === "$"){
a[i] = a[i].replace(dollarSignRightParenComma,"").replace("(","-");
b[i] = b[i].replace(dollarSignRightParenComma,"").replace("(","-");
if(char_zero === "-"){
if((ret = b[i] - a[i]) !== 0){
return ret;
}
}
else{
if((ret = a[i] - b[i]) !== 0){
return ret;
}
}
}
else{
if(char_zero === "-"){
if(a[i] > b[i]){
return -1;
}
else if(a[i] < b[i]){
return 1;
}
}
else{
if(a[i] > b[i]){
return 1;
}
else if(a[i] < b[i]){
return -1;
}
}
}
}
return 0;
},
thsFunction = function(){
var sort = this.getAttribute("sortable"), pos = indexOf.call(ths,this), columnsPos = indexOf.call(columns,pos), i = 0, index, trsIndex;
if(columnsPos === -1){
sorts.push(sort === null ? "" : sort);
columns.push(pos);
columnsLength = columns.length;
sortsLength = sorts.length;
tdsFunction();
this.innerHTML += " " + arrowUp;
}
else if(sorts[columnsPos].charAt(0) !== "-"){
sorts[columnsPos] = "-" + sorts[columnsPos];
this.innerHTML = this.innerHTML.substr(0,this.innerHTML.length - 1) + arrowDown;
}
else{
sorts.splice(columnsPos,1);
columns.splice(columnsPos,1);
this.innerHTML = this.innerHTML.substr(0,this.innerHTML.length - 7);
columnsLength = columns.length;
sortsLength = sorts.length;
tdsFunction();
}
tds.sort(sortFunction);
for(; i < tdsLength; ++i){
tbody.insertBefore(trsIndex = trs[index = indexOf.call(copyTds,tds[i],i)],trs[i]);
trs.splice(i,0,trsIndex);
trs.splice(index + 1,1);
copyTds.splice(i,0,copyTds[index]);
copyTds.splice(index + 1,1);
}
callback.call(this);
};
if(footer === true){
trs = trs.slice(1,trsLength--);
}
else{
trs = trs.slice(1);
}
if(typeof arrowUp === "undefined"){
arrowUp = "↑";
}
if(typeof arrowDown === "undefined"){
arrowDown = "↓";
}
if(typeof callback !== "function"){
callback = noOp;
}
for(i = 0; i < thsLength; ++i){
(thisTh = ths[i]).style.cursor = "pointer";
addOn.call(preventSelect.call(thisTh),"click",thsFunction);
}
return this;
}
,autoComplete =
function(argObject){
setDefaultsOnArgObject(argObject,{
"limit": "10"
,"defaultText": "type to search"
,"defaultTextStyle": "padding-left:2px"
,"onHoverColor": "#D5E2FF"
,"divBorder": "1px solid gray"
,"method": "POST"
,"pause": 0
});
if(typeof argObject.callback !== "function"){
argObject.callback = noOp;
}
if(typeof argObject.ajaxCallback !== "function"){
argObject.ajaxCallback = noOp;
}
if(typeof argObject.escapeCallback !== "function"){
argObject.escapeCallback = noOp;
}
var
pos = getPosition.call(this)
,pauseReference = [null]
,cacheReference = {0:null}
,ignoreNextFocus = false
,originalValue
,lastValue
,highlightedRow
,theDiv = preventSelect.call(addClass.call(document.createElement("div"),"ROCKET_COMPLETE_DIV"))
,theDivStyle = theDiv.style
,theTableChildren,theTableChildrenLength
,tableChildrenMouseOverFunction = function(){
if(highlightedRow !== null){
removeClass.call(highlightedRow,"ROCKET_COMPLETE_ONHOVER");
}
highlightedRow = addClass.call(this,"ROCKET_COMPLETE_ONHOVER");
}
,self = this
,tableChildrenClickFunction = function(){
var len;
if(originalValue === null){
originalValue = self.value;
}
self.value = highlightedRow.firstChild.innerHTML.replace(simpleHTMLTag,"");
ignoreNextFocus = true;
setSelection.call(self,len = self.value.length,len);
theDivStyle.visibility = "hidden";
argObject.callback.call(self,highlightedRow);
}
,onBlurFunction = function(){
theDivStyle.visibility = "hidden";
}
,divTableMouseOverFunction = function(){removeOn.call(self,"blur",onBlurFunction);}
,divTableMouseOutFunction = function(){addOn.call(self,"blur",onBlurFunction);}
,keyDownFunction =
function(e){
// tab 9 - up 38 - down 40 - enter 13 - esc 27
var sibling, key = e.which || e.keyCode, tempValue;
if((key === 9 || key === 13)
&& typeof theTableChildren !== "undefined" && typeof theTableChildren[0] === "object" && typeof theTableChildren[1] === "undefined"){
tempValue = theTableChildren[0].firstChild.innerHTML.replace(simpleHTMLTag,"");
if(tempValue.length >= this.value.length){
theDivStyle.visibility = "hidden";
highlightedRow = addClass.call(theTableChildren[0],"ROCKET_COMPLETE_ONHOVER");
this.value = tempValue;
argObject.callback.call(this,highlightedRow);
}
}
if(typeof highlightedRow !== "undefined" && this.value !== ""){
if(key === 9){
theDivStyle.visibility = "hidden";
}
else if(key === 27){
if(highlightedRow !== null){
theDivStyle.visibility = "visible";
removeClass.call(highlightedRow,"ROCKET_COMPLETE_ONHOVER");
highlightedRow = null;
this.value = originalValue;
}
else{
theDivStyle.visibility = "hidden";
}
argObject.escapeCallback.call(this);
}
else if(key === 40 || key === 38){
if(originalValue === null){
originalValue = this.value;
}
theDivStyle.visibility = "visible";
if(highlightedRow === null){
if(typeof theTableChildren[0] !== "undefined"){
if(key === 40){
highlightedRow = addClass.call(theTableChildren[0],"ROCKET_COMPLETE_ONHOVER");
}
else{
highlightedRow = addClass.call(theTableChildren[theTableChildrenLength - 1],"ROCKET_COMPLETE_ONHOVER");
}
this.value = highlightedRow.firstChild.innerHTML.replace(simpleHTMLTag,"");
argObject.callback.call(this,highlightedRow);
}
}
else{
removeClass.call(highlightedRow,"ROCKET_COMPLETE_ONHOVER");
if(key === 40){
sibling = highlightedRow.nextSibling;
}
else{
sibling = highlightedRow.previousSibling;
}
if(sibling === null){
highlightedRow = null;
return keyDownFunction.call(this,e);
}
else{
highlightedRow = addClass.call(sibling,"ROCKET_COMPLETE_ONHOVER");
this.value = highlightedRow.firstChild.innerHTML.replace(simpleHTMLTag,"");
argObject.callback.call(this,highlightedRow);
}
}
}
else if(key === 13){
if(highlightedRow !== null){
theDivStyle.visibility = "hidden";
this.value = highlightedRow.firstChild.innerHTML.replace(simpleHTMLTag,"");
argObject.callback.call(this,highlightedRow);
}
}
else{
theDivStyle.visibility = "visible";
}
}
if(this.value === ""){
theDiv.innerHTML = "" + argObject.defaultText + "";
}
if(key === 38 || key === 40 || key === 9 || key === 13 || key === 27){
return true;
}
if((typeof lastValue === "undefined" || lastValue !== this.value) && this.value !== ""){
lastValue = this.value;
}
else{
if(this.value.length === 0){
lastValue = null;
}
return true;
}
ajax.call(this,argObject.url,argObject.method,function(){return {"l":argObject.limit,"q":this.value};},function(responsetext){
theDiv.innerHTML = responsetext;
highlightedRow = null;
originalValue = null;
addOn.call(addOn.call(theDiv.firstChild,"mouseover",divTableMouseOverFunction),"mouseout",divTableMouseOutFunction);
theTableChildrenLength = (theTableChildren = elementsByTag.call(theDiv,"tr")).length;
for(var i = 0; i < theTableChildrenLength; ++i){
addOn.call(addOn.call(theTableChildren[i],"mouseover",tableChildrenMouseOverFunction),"click",tableChildrenClickFunction);
}
argObject.ajaxCallback.call(this);
},argObject.pause,pauseReference,true,cacheReference);
}
;
theDiv.id = "ROCKET_COMPLETE_DIV-" + (++rocketCompleteSuffix);
theDiv.innerHTML = "" + argObject.defaultText + "";
theDivStyle.left = pos[0] + "px";
theDivStyle.top = pos[1] + this.clientHeight + getPropertyValue.call(this,"border-top-width") + "px";
theDivStyle.width = this.clientWidth + getPropertyValue.call(this,"border-left-width") + "px";
documentBody().appendChild(theDiv);
addStyleRuleToDocument(".ROCKET_COMPLETE_DIV td","padding-left: 2px; white-space: nowrap");
addStyleRuleToDocument(".ROCKET_COMPLETE_DIV table","border: 0 none; padding: 0; border-collapse: collapse; width: 100%");
addStyleRuleToDocument(".ROCKET_COMPLETE_ONHOVER","background-color: " + argObject.onHoverColor);
addStyleRuleToDocument(".ROCKET_COMPLETE_DIV","cursor: default; background-color:white; border: " + argObject.divBorder + "; position: absolute; visibility:hidden; overflow: hidden");
return addOn.call(addOn.call(addOn.call(addOn.call(this,
"blur",onBlurFunction),
"click",function(){
theDivStyle.visibility = "visible";
}),
"focus",function(){
if(ignoreNextFocus !== true){
var pos = getPosition.call(this);
theDivStyle.left = pos[0] + "px";
theDivStyle.top = pos[1] + this.clientHeight + getPropertyValue.call(this,"border-top-width") + "px";
theDivStyle.width = this.clientWidth + getPropertyValue.call(this,"border-left-width") + "px";
theDivStyle.visibility = "visible";
}
ignoreNextFocus = false;
}),
"keydown",keyDownFunction,true);
}
,forEach =
(function(){
if(typeof arrayPrototype.forEach === "function"){
return arrayPrototype.forEach;
}
else{
return function(fnct,self){
for(var i = 0, len = this.length; i < len; ++i){
fnct.call(self,this[i],i,this);
}
};
}
}())
,rforEach =
function(fnct,self,start,end){
for(var i = start >>> 0, len = this.length - (end >> 0), thisi; i < len; ++i){
if(typeof (thisi = this[i]) !== "undefined" && thisi !== null && thisi.constructor === Array){
rforEach.call(thisi,fnct,self);
}
else{
fnct.call(self,thisi,i,this);
}
}
}
,each =
function(fnct,self){
forEach.call(this,fnct,self);
return this;
}
,reach =
function(fnct,self,start,end){
rforEach.call(this,fnct,self,start);
return this;
}
,map =
(function(){
if(typeof arrayPrototype.map === "function"){
return arrayPrototype.map;
}
else{
return function(fnct,thisp){
var reti = 0, ret = [];
forEach.call(this,function(selfi,i,self){ret[++reti] = fnct.call(thisp,selfi,i,self);});
return ret;
};
}
}())
,rmap =
function(fnct,self,start,end){
for(var ret = [],i = start >>> 0, len = this.length - (end >> 0), thisi; i < len; ++i){
if(typeof (thisi = this[i]) !== "undefined" && thisi !== null && thisi.constructor === Array){
ret[i] = rmap.call(thisi,fnct,self);
}
else{
ret[i] = fnct.call(self,thisi,i,this);
}
}
return ret;
}
,splitter =
function(start,step){
for(var ret = [], j = -1, i = start, len = this.length; i < len; i += step){
ret[++j] = this[i];
}
return ret;
}
,flatten =
function(){
for(var i = 0, len = this.length, ret = [], j = -1, thisi, recurse; i < len; ++i){
if(typeof (thisi = this[i]) !== "undefined" && thisi !== null && thisi.constructor === Array){
j += (recurse = flatten.call(thisi)).length;
ret.push.apply(ret,recurse);
}
else{
ret[++j] = thisi;
}
}
return ret;
}
,filter =
(function(){
if(typeof arrayPrototype.filter === "function"){
return arrayPrototype.filter;
}
else{
return function(fnct,self){
for(var j = -1, i = 0, len = this.length, ret = [], thisi; i < len; ++i){
if(fnct.call(self,(thisi = this[i]),i,this)){
ret[++j] = thisi;
}
}
return ret;
};
}
}())
,rfilter =
function(fnct,self,start,end){
for(var i = start >>> 0, len = this.length - (end >> 0), ret = [], j = -1, thisi; i < len; ++i){
if(typeof (thisi = this[i]) !== "undefined" && thisi !== null && thisi.constructor === Array){
ret[++j] = rfilter.call(thisi,fnct,self);
}
else{
if(fnct.call(self,thisi,i,this)){
ret[++j] = thisi;
}
}
}
return ret;
}
,every =
(function(){
if(typeof arrayPrototype.every === "function"){
return arrayPrototype.every;
}
else{
return function(fnct,self){
for(var i = 0, len = this.length; i < len; ++i){
if(!fnct.call(self,this[i],i,this)){
return false;
}
}
return true;
};
}
}())
,revery =
function(fnct,self,start,end){
for(var i = start >>> 0, len = this.length - (end >> 0), thisi; i < len; ++i){
if(typeof (thisi = this[i]) !== "undefined" && thisi !== null && thisi.constructor === Array && !revery.call(thisi,fnct,self)){
return false;
}
else{
if(!fnct.call(self,thisi,i,this)){
return false;
}
}
}
return true;
}
,some =
(function(){
if(typeof arrayPrototype.some === "function"){
return arrayPrototype.some;
}
else{
return function(fnct,self){
for(var i = 0, len = this.length; i < len; ++i){
if(fnct.call(self,this[i],i,this)){
return true;
}
}
return false;
};
}
}())
,rsome =
function(fnct,self,start,end){
for(var i = start >>> 0, len = this.length - (end >> 0), thisi; i < len; ++i){
if(typeof (thisi = this[i]) !== "undefined" && thisi !== null && thisi.constructor === Array && rsome.call(thisi,fnct,self)){
return true;
}
else{
if(fnct.call(self,thisi,i,this)){
return true;
}
}
}
return false;
}
,unique =
function(){
for(var i = 0, len = this.length, ret = [], j = -1, thisi; i < len; ++i){
if(indexOf.call(ret,thisi = this[i]) === -1){
ret[++j] = thisi;
}
}
return ret;
}
,runique =
function(){
return unique.call(flatten.call(this));
}
,union =
function(array){
var ret = unique.call(this);
ret.push.apply(ret,filter.call(array,function(arg){return indexOf.call(ret,arg) === -1;}));
return ret;
}
,intersect =
function(array){
var ret = [], i = -1;
forEach.call(unique.call(array),function(self){if(indexOf.call(this,self) !== -1){ret[++i] = self;}},this);
return ret;
}
,sortNum =
function(descending){
return descending === true ? this.sort(function(a,b){return b - a;}) : this.sort(function(a,b){return a - b;});
}
,sortRand =
function(){
return this.sort(function(){return 0.5 - mathRandom();});
}
,json_encode =
function(arg,forceObject){
var i,len,ret = [],j = -1,argConstructor = arg.constructor,argIsObject,argIsArray,argi,typeofargi;
if(typeof argConstructor === "undefined"){
return "@@@UNDEFINED_CONSTRUCTOR@@@";
}
if((argIsObject = (argConstructor === Object)) === false && (argIsArray = (argConstructor === Array)) === false){
return arg;
}
if(argIsArray){
for(i = 0, len = arg.length; i < len; ++i){
ret[++j] = ",";
if(forceObject === true){
ret[++j] = "\"" + i.replace("\\","\\\\").replace("\"","\\\"") + "\":";
}
if((argi = arg[i]) === null || (typeofargi = typeof argi) === "undefined"){
ret[++j] = "null";
}
else if(typeofargi === "number" || typeofargi === "boolean"){
ret[++j] = argi;
}
else if(typeofargi === "string"){
ret[++j] = "\"" + argi.replace("\\","\\\\").replace("\"","\\\"") + "\"";
}
else if(typeofargi === "object"){
ret[++j] = json_encode(argi,forceObject);
}
}
}
else{ //argIsObject === true
for(i in arg){
if((typeofargi = typeof (argi = arg[i])) === "function"){
continue;
}
ret[++j] = ",";
if(argIsObject === true || forceObject === true){
ret[++j] = "\"" + i.replace("\\","\\\\").replace("\"","\\\"") + "\":";
}
if(argi === null || typeofargi === "undefined"){
ret[++j] = "null";
}
else if(typeofargi === "number" || typeofargi === "boolean"){
ret[++j] = argi;
}
else if(typeofargi === "string"){
ret[++j] = "\"" + argi.replace("\\","\\\\").replace("\"","\\\"") + "\"";
}
else if(typeofargi === "object"){
ret[++j] = json_encode(argi,forceObject);
}
}
}
if(argIsObject === true || forceObject === true){
ret[0] = "{";
if(j === -1){
return "{}";
}
else{
ret[++j] = "}";
}
}
else{
ret[0] = "[";
if(j === -1){
return "[]";
}
else{
ret[++j] = "]";
}
}
return ret.join("");
}
,json_parse = //json_parse from json.org, json parse without eval
(function () {
/*
http://www.JSON.org/json_parse.js
2009-05-31
Public Domain.
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
This file creates a json_parse function.
json_parse(text, reviver)
This method parses a JSON text to produce an object or array.
It can throw a SyntaxError exception.
The optional reviver parameter is a function that can filter and
transform the results. It receives each of the keys and values,
and its return value is used instead of the original value.
If it returns what it received, then the structure is not modified.
If it returns undefined then the member is deleted.
Example:
// Parse the text. Values that look like ISO date strings will
// be converted to Date objects.
myData = json_parse(text, function (key, value) {
var a;
if (typeof value === 'string') {
a =
/^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
if (a) {
return new Date(Date.UTC(+a[1], +a[2] - 1, +a[3], +a[4],
+a[5], +a[6]));
}
}
return value;
});
This is a reference implementation. You are free to copy, modify, or
redistribute.
This code should be minified before deployment.
See http://javascript.crockford.com/jsmin.html
USE YOUR OWN COPY. IT IS EXTREMELY UNWISE TO LOAD CODE FROM SERVERS YOU DO
NOT CONTROL.
*/
// This is a function that can parse a JSON text, producing a JavaScript
// data structure. It is a simple, recursive descent parser. It does not use
// eval or regular expressions, so it can be used as a model for implementing
// a JSON parser in other languages.
// We are defining the function inside of another function to avoid creating
// global variables.
var at, // The index of the current character
ch, // The current character
escapee = {
'"': '"',
'\\': '\\',
'/': '/',
b: '\b',
f: '\f',
n: '\n',
r: '\r',
t: '\t'
},
text,
error = function (m) {
// Call error when something is wrong.
throw {
name: 'SyntaxError',
message: m,
at: at,
text: text
};
},
next = function (c) {
// If a c parameter is provided, verify that it matches the current character.
if (c && c !== ch) {
error("Expected '" + c + "' instead of '" + ch + "'");
}
// Get the next character. When there are no more characters,
// return the empty string.
ch = text.charAt(at);
at += 1;
return ch;
},
number = function () {
// Parse a number value.
var number,
string = '';
if (ch === '-') {
string = '-';
next('-');
}
while (ch >= '0' && ch <= '9') {
string += ch;
next();
}
if (ch === '.') {
string += '.';
while (next() && ch >= '0' && ch <= '9') {
string += ch;
}
}
if (ch === 'e' || ch === 'E') {
string += ch;
next();
if (ch === '-' || ch === '+') {
string += ch;
next();
}
while (ch >= '0' && ch <= '9') {
string += ch;
next();
}
}
number = +string;
if (isNaN(number)) {
error("Bad number");
} else {
return number;
}
},
string = function () {
// Parse a string value.
var hex,
i,
string = '',
uffff;
// When parsing for string values, we must look for " and \ characters.
if (ch === '"') {
while (next()) {
if (ch === '"') {
next();
return string;
} else if (ch === '\\') {
next();
if (ch === 'u') {
uffff = 0;
for (i = 0; i < 4; i += 1) {
hex = parseInt(next(), 16);
if (!isFinite(hex)) {
break;
}
uffff = uffff * 16 + hex;
}
string += String.fromCharCode(uffff);
} else if (typeof escapee[ch] === 'string') {
string += escapee[ch];
} else {
break;
}
} else {
string += ch;
}
}
}
error("Bad string");
},
white = function () {
// Skip whitespace.
while (ch && ch <= ' ') {
next();
}
},
word = function () {
// true, false, or null.
switch (ch) {
case 't':
next('t');
next('r');
next('u');
next('e');
return true;
case 'f':
next('f');
next('a');
next('l');
next('s');
next('e');
return false;
case 'n':
next('n');
next('u');
next('l');
next('l');
return null;
}
error("Unexpected '" + ch + "'");
},
value, // Place holder for the value function.
array = function () {
// Parse an array value.
var array = [];
if (ch === '[') {
next('[');
white();
if (ch === ']') {
next(']');
return array; // empty array
}
while (ch) {
array.push(value());
white();
if (ch === ']') {
next(']');
return array;
}
next(',');
white();
}
}
error("Bad array");
},
object = function () {
// Parse an object value.
var key,
object = {};
if (ch === '{') {
next('{');
white();
if (ch === '}') {
next('}');
return object; // empty object
}
while (ch) {
key = string();
white();
next(':');
if (Object.hasOwnProperty.call(object, key)) {
error('Duplicate key "' + key + '"');
}
object[key] = value();
white();
if (ch === '}') {
next('}');
return object;
}
next(',');
white();
}
}
error("Bad object");
};
value = function () {
// Parse a JSON value. It could be an object, an array, a string, a number,
// or a word.
white();
switch (ch) {
case '{':
return object();
case '[':
return array();
case '"':
return string();
case '-':
return number();
default:
return ch >= '0' && ch <= '9' ? number() : word();
}
};
// Return the json_parse function. It will have access to all of the above
// functions and variables.
return function (source, reviver) {
var result;
text = source;
at = 0;
ch = ' ';
result = value();
white();
if (ch) {
error("Syntax error");
}
// If there is a reviver function, we recursively walk the new structure,
// passing each name/value pair to the reviver function for possible
// transformation, starting with a temporary root object that holds the result
// in an empty key. If there is not a reviver function, we simply return the
// result.
return typeof reviver === 'function' ? (function walk(holder, key) {
var k, v, value = holder[key];
if (value && typeof value === 'object') {
for (k in value) {
if (Object.hasOwnProperty.call(value, k)) {
v = walk(value, k);
if (v !== undefined) {
value[k] = v;
} else {
delete value[k];
}
}
}
}
return reviver.call(holder, key, value);
}({'': result}, '')) : result;
};
}())
,now =
function(){
return new Date().getTime() / 1000;
}
,loadJSON =
function(url,method,params){
var ret;
ajax(url,method,params,function(responseText){ret = responseText;},0,null,false,null,false);
return json_parse(ret);
}
,prototypeElement = {
"addClass":/**
adds a class name or a list of class names to this element
@param {String} className class name or space delimited list of class names
@return {Rocket} this element
@see removeClass
@see toggleClass
@see hasClass
@see classOnHover
@see classOnActive
safe to be called on an element that has className
*/ function(className){
addClass.call(this.element,className);
return this;
}
,"removeClass":/**
removes a class name or a list of class names from this element
@param {String} className class name or space delimited list of class names
@return {Rocket} this element
@see addClass
@see toggleClass
@see hasClass
@see classOnHover
@see classOnActive
if called with a className, will remove all classNames from this element
safe to be called on an element that doesn't have className
*/ function(className){
removeClass.call(this.element,className);
return this;
}
,"hasClass":/**
checks if this element has a class name
@param {String} className class name
@return {Boolean} true or false
@see addClass
@see removeClass
@see toggleClass
@see classOnHover
@see classOnActive
if this element has className, returns true, else returns false
*/ function(className){
return hasClass.call(this.element,className);
}
,"toggleClass":/**
toggles a class name on or off for this element
@param {String} className class name
@return {Rocket} this element
@see addClass
@see removeClass
@see hasClass
@see classOnHover
@see classOnActive
if this element has the class className, then remove the class, else add it
*/ function(className){
toggleClass.call(this.element,className);
return this;
}
,"addOn":/**
add an event handler to this element
@param {String} evt event name
@param {Function} fnct handling function
@param {Boolean} addFunctionAsCallback true or false, default false
@return {Rocket} this element
@example .addOn("click",function(){alert("hello world!");})
@example .addOn("click",function(event){alert(event);})
@example .addOn("click",function(){alert("you clicked on me and I'm a: " + this.nodeName);})
@example .addOn("keydown",function(){alert("the value of this input after you pressed down the key is: " + this.value);},true)
@see removeOn
@see addAjaxOn
@see removeAjaxOn
fnct.call(this,event) where this is this element and event is the DOM event
if addFunctionAsCallback is true, then the handler will be called imediately after all event handling functions have executed
functions added to an event are guaranteed to be processed in order if and only if addFunctionAsCallback is false
if addFunctionAsCallback is true, functions will be simultaneously asynchronously executed
*/ function(evt,fnct,addFunctionAsCallback){
addOn.call(this.element,evt,fnct,addFunctionAsCallback);
return this;
}
,"removeOn":/**
removes an event handler from this element
@param evt event name
@param {Function} fnct handling function
@param {Boolean} functionWasCallback true or false, default false
@return {Rocket} this element
@see addOn
@see addAjaxOn
@see removeAjaxOn
@see loadHTML
@see feedHTML
@example .removeOn() will remove all event handlers from this element
@example .removeOn("click") will remove all "click" event handlers from this element
if called without fnct, will remove all functions for event parameter;
if called without any parameters, will remove all functions from this element;
*/ function(evt,fnct,functionWasCallback){
removeOn.call(this.element,evt,fnct,functionWasCallback);
return this;
}
,"getPropertyValue":/**
returns a css property value for thie element
@param {String} property property name
@return {Mixed} property value
@example .getPropertyValue("border-top-width") could return (int)5
***this still needs testing the make it cross-browser identical***
*/ function(property){
return getPropertyValue.call(this.element,property);
}
,"addAjaxOn":/**
adds an ajax handler function to this element
@param {Object} argObject argument object
@return {Rocket} this element
@example .addAjaxOn({url:"example.php",event:"click",method:"POST",parameters:function(){return {foo:"bar"};},callback:function(xml){this.innerHTML = xml;}})
@see addOn
@see removeOn
@see removeAjaxOn
@see loadHTML
@see feedHTML
parameters: url, event, method, parameters, and callback are required
argObject is an object containing parameter definitions
.url
url for the ajax call
.event
event name
.method
"GET" or "POST"
.parameters
function that returns an argObject of get/post var/value pairs; this will be URI encoded
.callback
handling function for ajax response; callback.call(this,xmlhttp) where this is this element and xmlhttp is the response text
.pause
waits this many milliseconds before sending the request
if another occurrence of event happens before the request is sent, then the original request is not sent
the timer restarts, the new event/parameters then wait
.asCallback
true will add this as an event_callback, or immediately after event occurs
false will add this as a standard event
.cache
true will cache ajax responses for _ajaxCacheTimeout milliseconds
false will not cache responses
default false
*/ function(argObject){
addAjaxOn.call(this.element,argObject.event,argObject.url,argObject.method,argObject.parameters,argObject.callback,argObject.pause,argObject.asCallback,argObject.cache);
return this;
}
,"removeAjaxOn":/**
removes an ajax handler function from this element
@param {Object} argObject argument object
@return {Rocket} this element
@see addAjaxOn
@see addOn
@see removeOn
parameters: url, event, and method are required
argObject is an object containing parameter definitions
.url
url for the ajax call
.event
event name
.method
"GET" or "POST"
.asCallback
true if this was added an event_callback
false if this was added as a standard event
default false
*/ function(argObject){
removeAjaxOn.call(this.element,argObject.event,argObject.url,argObject.method,argObject.asCallback);
return this;
}
,"classOnHover":/**
toggles a class name or a list of class names to this element when mouseover'ed or focus'ed
@param {String} className class name or space delimited list of class names
@return {Rocket} this element
@see addClass
@see removeClass
@see toggleClass
@see hasClass
@see classOnActive
adds className on mouseover/focus and removes className on mouseout/blur
*/ function(className){
classOnHover.call(this.element,className);
return this;
}
,"classOnActive":/**
toggles a class name or a list of class names on this element when mousedown'ed or space'ed
@param {String} className class name or space delimited list of class names
@return {Rocket} this element
@see addClass
@see removeClass
@see toggleClass
@see hasClass
@see classOnHover
intended for <button> like behavior
adds className on mousedown or on space bar keydown
removes className on mouseup,mouseout,keyup,blur
*/ function(className){
classOnActive.call(this.element,className);
return this;
}
,"getPosition":/**
gets this element's current position
@return {Array} array of this element's current position
returns current absolute position of this element [left,top]
*/ function(){
return getPosition.call(this.element);
}
,"getChildren":/**
gets this element's children nodes
@return {Rockets} array of this element's child nodes
*/ function(){
return new Rockets(getChildren.call(this.element));
}
,"getElementsBy":/**
gets this element's descendants using a CSS selector
@param {String} selector CSS selector
@example .getElementsBy()
@example .getElementsBy(*)
@example .getElementsBy("div")
@example .getElementsBy(".class")
@example .getElementsBy("div.class")
@return {Rockets} array of elements
*/ function(selector){
var i;
if(typeof selector === "undefined" || (i = selector.charAt(0)) === '*'){
return new Rockets(elementsByTag.call(this.element,"*"));
}
if(i === "."){
return new Rockets(elementsByClass(selector,this.element));
}
if((i = selector.indexOf(".")) !== -1){
return new Rockets(elementsByTagDotClassName.call(this.element,selector,i));
}
return new Rockets(elementsByTag.call(this.element,selector));
}
,"preventSelect":/**
prevents selection of text for this element
@return {Rocket} this element
*/ function(){
preventSelect.call(this.element);
return this;
}
,"setSelection":/**
set selected text in this input element
@param {Integer} start zero based index character position
@param {Integer} end zero based index character position
@return {Rocket} this element
@see setCaret
@example .setSelection(2,4) will select "cd" from "abcdef"
*/ function(start,end){
setSelection.call(this.element,start,end);
return this;
}
,"setCaret":/**
sets the position of the caret in this input element
@param {Integer} character zero based index character position
@return {Rocket} this element
@see setSelection
@example .setCaret(2) will set the caret "ab|cd"
*/ function(character){
setSelection.call(this.element,character,character);
return this;
}
,"autoComplete":/**
sets up this input element to use an autosuggest/complete server page
@param {Object} argObject argument object
@return {Rocket} this element
@example .autoComplete({url:"example.php"})
@see addAjaxOn
parameters: url is required
argObject is an object containing parameter definitions
.url
url that returns a table takes ?q=search ?l=limit
uses first <td> child as autoComplete value
displays, but ignores, other <td>
e.g.
<table>
<tr> <td>autoComplete_value</td> [<td>.*?</td>]* </tr>
</table>
.callback
function.call(this,selected_row) when row is selected via enter, click, up arrow, down arrow
.method
"GET" or "POST"
.limit
?l= to url; ?q= to url is automatically this.value
.ajaxCallback
.call(this) when an ajax response is received
.escapeCallback
.call(this) when [escape] is pressed
.defaultText
default text that appears in div
.defaultTextStyle
style="defaultTextStyle" for default text
.onHoverColor
css background-color: highlighed/selected row color
.divBorder
border of div holding table containing rows
.pause
how long to wait before sending request between keystrokes
*/ function(argObject){
autoComplete.call(this.element,argObject);
return this;
}
,"fade":/**
fade this element to a different opacity
@param {Float} toOpacity percentage opacity
@param {Integer} duration duration in milliseconds
@return {Rocket} this element
if called on this element when this element is already set at toOpacity, then this function does nothing
this uses a cosign curve to adjust opacity
*/ function(toOpacity,duration){
fade.call(this.element,toOpacity,duration);
return this;
}
,"loadHTML":/**
puts an xmlhttp response into this element
@param {String} url for the ajax call
@param {String} method "GET" or "POST"
@param {Function} params function that returns an argObject of get/post var/value pairs; this will be URI encoded
@return {Rocket} this element
@example .loadHTML("example.php","GET",function(){return {foo:"bar"};});
@see addAjaxOn
@see removeAjaxOn
@see feedHTML
*/ function(url,method,params){
loadHTML.call(this.element,url,method,params);
return this;
}
,"feedHTML":/**
continuously puts an xmlhttp response into this element
@param {String} url for the ajax call
@param {Integer} interval in milliseconds
@param {String} method "GET" or "POST"
@param {Function} params function for ajax call
@return {Rocket} this element
@example .feedHTML("example.php",1000,"POST",function(){return {foo:"bar"};})
@see loadHTML
@see stopFeed
@see addAjaxOn
@see removeAjaxOn
this can also be used for long polling
http://en.wikipedia.org/wiki/Server_push#Long_polling
e.g.: if interval is 1000 milliseconds, it will feed the page once, wait for it to complete downloading, then wait 1000 milliseconds, then initiate another request
*/ function(url,interval,method,params){
feedHTML.call(this.element,url,interval,method,params);
return this;
}
,"stopFeed":/**
stop continuously putting an xmlhttp response into this element
@return {Rocket} this element
@see feedHTML
@see loadHTML
safe to be called on an element not currently feedHTML'ing
*/ function(){
stopFeed.call(this.element);
return this;
}
,"zebra":/**
sets up this table element to be zebra striped
@param {Object} argObject argument object
@return {Rocket} this element
@see sortable
@see addClass
@see toggleClass
parameters: all are optional
argObject is an object containing parameter definitions
.even
class name for even rows
.odd
class name for odd rows
.skip
number of rows to skip before starting to count even/odd; default is 0
.hoverTr
class name for a table row while hovering over it
.hoverTd
class name for a table column while hovering over it
.clickTr
class name for a table row that toggles on click
.clickTd
class name for a table column that toggles on click
*/ function(argObject){
zebra.call(this.element,argObject.even,argObject.odd,argObject.hoverTr,argObject.hoverTd,argObject.clickTr,argObject.clickTd,argObject.skip);
return this;
}
,"sortable":/**
sets up this table element to be sortable
@param {Boolean} footer true or false
@param {Function} callback function on sort
@param {String} arrowUp arrow up character
@param {String} arrowDown arrow down character
@return {Rocket} this element
@see zebra
adds style.cursor=pointer to all th's in the first row
makes th's in the first row clickable to sort that column, ASC->DESC->OFF->ASC...;
ignores <td> columns in first row
looks at first row's <th sortable="#" or "$"> or null for type of sort respectively: numeric, monetary, else normal;
monetary sort removes "$,)", replaces "(" with "-", then sorts the column as a float
rows are moved in the DOM, any attributes or styles will move with them;
*/ function(footer,callback,arrowUp,arrowDown){
sortable.call(this.element,footer,callback,arrowUp,arrowDown);
return this;
}
,"innerHTML":/**
reference to this.innerHTML
@param {String} innerHTML innerHTML
@return {Rocket or String} this element or string innerHTML
@exmaple .innerHTML() will return a string "this element's innerhtml"
@example .innerHTML("") will set this element's innerHTML to "" and return this element
if innerHTML is not passed, returns innerHTML value, else sets innerHTML value and returns this element
*/ function(innerHTML){
if(typeof innerHTML === "undefined"){
return this.element.innerHTML;
}
this.element.innerHTML = innerHTML;
return this;
}
,"style":/**
sets CSS property value pairs
@param {String} property CSS property
@param {String} value CSS value
@return {Rocket} this element
@example .style("border","1px solid gray")
@example .style("background-color","blue")
@example .style("backgroundColor","blue")
*/ function(property,value){
this.element.style[hyphensToCamelCase(property)] = value;
return this;
}
,"parentNode":/**
returns this element's parent node as if called by $()
@return {Rocket} element
@see firstChild
@see nextSibling
@see previousSibling
*/ function(){
return new Rocket(this.element.parentNode);
}
,"firstChild":/**
returns this element's firstChild as if called by $()
@return {Rocket} element
@see parentNode
@see nextSibling
@see previousSibling
*/ function(){
return new Rocket(this.element.firstChild);
}
,"nextSibling":/**
returns this element's nextSibling as if called by $()
@return {Rocket} element
@see parentNode
@see firstChild
@see previousSibling
*/ function(){
return new Rocket(this.element.nextSibling);
}
,"previousSibling":/**
returns this element's nextSibling as if called by $()
@return {Rocket} element
@see parentNode
@see firstChild
@see nextSibling
*/ function(){
return new Rocket(this.element.previousSibling);
}
}
,prototypeArray = {
"indexOf":/**
returns the index of element in this array or -1 if not found
@param {Mixed} element needle
@param {Integer} start zero based start position
@return {Integer} zero based position
won't redefine this prototype if it already exists
if start is passed, will start at that index
returns -1 if the element is not found in this array
use identical comparison (===) when checking return value, 0 == false, 0 is a valid return position
this mostly follows the mozdev spec at
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
*/ function(element,start){
return indexOf.call(this,element,start);
}
,"i":/**
returns the element at the given index
@param {Integer} i index position
@return {Mixed} element as position
@see i
identical to the index function
*/ function(i){
return this[i];
}
,"index":/**
returns the element at the given index
@param {Integer} i index position
@return {Mixed} element as position
@see i
identical to the i function
*/ function(i){
return this[i];
}
,"max":/**
returns the maximum numeric value of this array
@return {Numeric} maximum value
@see min
this function will return NaN, not a number, if this array contains any non-numeric values
*/ function(){
return mathMax.apply(null,this);
}
,"min":/**
returns the minimum numeric value of this array
@return {Numeric} minimum value
@see max
this function will return NaN, not a number, if this array contains any non-numeric values
*/ function(){
return mathMin.apply(null,this);
}
,"each":/**
calls a function on each element in this array, returns this array
@param {Function} fnct function called
@param {Object} self value of this within fnct
@return {Array} this array
@example [1,2,3].each(function(selfi,i,self){++self[i];}) will modifiy original array to be [2,3,4]
@see forEach
@see rforEach
@see reach
@see map
@see rmap
this function is identical to forEach except that it returns this array instead of void
*/ function(fnct,self){
return each.call(this,fnct,self);
}
,"forEach":/**
calls a function on each element in this array, returns void
@param {Function} fnct function called
@param {Object} self value of this within fnct
@return {void} returns void
@see each
@see rforEach
@see reach
@see map
@see rmap
won't redefine this prototype if it already exists
fnct is called with self parameter as this, and the arguments (this_element,this_index,this_array) or (array[i],i,array)
this mostly follows the mozdev spec at
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/forEach
*/ function(fnct,self){
forEach.call(this,fnct,self);
}
,"rforEach":/**
recursively calls a function on each element in this array
@param {Function} fnct function called
@param {Object} self value of this within fnct
@param {Integer} start position to start within each array
@param {Integer} end number of elements to skip from the end of each array
@return {void} returns void
@see each
@see forEach
@see reach
@see map
@see rmap
recursively calls fnct on each element in this array
if this element is an array, then it will call rforEach on that element with the same parameters
fnct is called with self parameter as this, and the arguments (this_element,this_index,this_array) or (array[i],i,array)
this mostly follows the mozdev spec at
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/forEach
*/ function(fnct,self,start,end){
rforEach.call(this,fnct,self,start,end);
}
,"reach":/**
recursively calls a function on each element in this array, returns this array
@param {Function} fnct function called
@param {Object} self value of this within fnct
@param {Integer} start position to start within each array
@param {Integer} end number of elements to skip from the end of each array
@return {Array} this array
@see each
@see forEach
@see rforEach
@see map
@see rmap
recursively calls fnct on each element in this array
if this element is an array, then it will call reach on that element with the same parameters
fnct is called with self parameter as this, and the arguments (this_element,this_index,this_array) or (array[i],i,array)
this function is identical to rforEach except that it returns this array instead of void
*/ function(fnct,self,start,end){
return reach.call(this,fnct,self,start);
}
,"map":/**
calls a function on each element in this array, returns array of results of function
@param {Function} fnct function called
@param {Object} self value of this within fnct
@return {Array} array of results
@example [1,2,3].map(function(arg){return arg + 1;}) will return [2,3,4]
@see each
@see forEach
@see rforEach
@see reach
@see rmap
returns array of results of fnct being called on this array
won't redefine this prototype if it already exists
fnct is called with self parameter as this, and the arguments (this_element,this_index,this_array) or (array[i],i,array)
this mostly follows the mozdev spec at
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/map
*/ function(fnct,self){
return map.call(this,fnct,self);
}
,"rmap":/**
recursively calls a function on each element in this array, returns array of results of function
@param {Function} fnct function called
@param {Object} self value of this within fnct
@param {Integer} start position to start within each array
@param {Integer} end number of elements to skip from the end of each array
@return {Array} array of results
@example [1,[3,4],2].map(function(arg){return arg + 1;}) will return [2,[4,5],3]
@see each
@see forEach
@see rforEach
@see reach
@see map
returns array of results of fnct being recursively called on this array
if this element is an array, then it will call rmap on that element with the same parameters
fnct is called with self parameter as this, and the arguments (this_element,this_index,this_array) or (array[i],i,array)
*/ function(fnct,self,start,end){
return rmap.call(this,fnct,self,start);
}
,"splitter":/**
returns array of every step'th element from start in this array
@param {Integer} start position to start within array
@param {Integer} step increment
@return {Array} array of results
@example [0,1,2,3,4,5].splitter(0,2) will return [0,2,4]
@example [0,1,2,3,4,5].splitter(1,2) will return [1,3,5]
@example [0,1,2,3,4,5].splitter(0,3) will return [0,3]
@see odd
@see even
returns every step'th element from start in this array
used to split an array into evens, odds, every third, etc.
*/ function(start,step){
return splitter.call(this,start,step);
}
,"odd":/**
returns an array of the odd elements of this array
@return {Array} array of results
@example [0,1,2,3,4,5].odd() will return [1,3,5]
@see splitter
@see even
*/ function(){
return splitter.call(this,1,2);
}
,"even":/**
returns an array of the even elements of this array
@return {Array} array of results
@example [0,1,2,3,4,5].even() will return [0,2,4]
@see splitter
@see odd
*/ function(){
return splitter.call(this,0,2);
}
,"flatten":/**
flattens an array, removes any nested arrays
@return {Array} array or results
@example [0,1,[2,[3,[4,[5]]]],6].flatten() will return [0,1,2,3,4,5,6]
*/ function(){
return flatten.call(this);
}
,"filter":/**
returns an array where filter fnct returns true
@param {Function} fnct function called
@param {Object} self value of this within fnct
@return {Array} array of results
@example [1,2,3,4,5].filter(function(arg){return arg - 3;}) will return [1,2,4,5]
@example [1,2,3,4,5].filter(function(arg){return arg > 3;}) will return [4,5]
@see rfilter
returns array of results where fnct returns == true
won't redefine this prototype if it already exists
fnct is called with self parameter as this, and the arguments (this_element,this_index,this_array) or (array[i],i,array)
this mostly follows the mozdev spec at
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/filter
*/ function(fnct,self){
return filter.call(this,fnct,self);
}
,"rfilter":/**
returns an array where filter fnct returns true
@param {Function} fnct function called
@param {Object} self value of this within fnct
@param {Integer} start position to start within each array
@param {Integer} end number of elements to skip from the end of each array
@return {Array} array or results
@example [0,1,[2,[3,[4,[5]]]],6].rfilter(function(arg){return arg - 5;} will return [0,1,[2,[3,[4,[]]]],6]
@example [0,1,[2,[3,[4,[5]]]],6].rfilter(function(arg){return arg > 5;} will return [[[[[]]]],6]
@example [1,2,3,[4,5,6]].rfilter(function(arg){return arg % 2;} will return [1,3,[5]]
@see filter
returns array of results where fnct being recursively called on this array is == true
if this element is an array, then it will call rfilter on that element with the same parameters
fnct is called with self parameter as this, and the arguments (this_element,this_index,this_array) or (array[i],i,array)
*/ function(fnct,self,start,end){ //return array with elements where filter returns true, preserves order/structure
return rfilter.call(this,fnct,self,start);
}
,"every":/**
returns true if fnct returns true for every element in this array
@param {Function} fnct function called
@param {Object} self value of this within fnct
@return {Boolean} true or false
@example [1,2,3].every(function(arg){return arg > 0;}) will return true;
@example [1,2,3].every(function(arg){return arg < 2;}) will return false;
@example [1,2,3].every(function(arg){return arg;}) will return true;
@see revery
@see some
@see rsome
returns true if fnct returns == true for every element in this array
won't redefine this prototype if it already exists
fnct is called with self parameter as this, and the arguments (this_element,this_index,this_array) or (array[i],i,array)
this mostly follows the mozdev spec at
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/every
*/ function(fnct,self){
return every.call(this,fnct,self);
}
,"revery":/**
returns true if recursively fnct returns true for every element in this array
@param {Function} fnct function called
@param {Object} self value of this within fnct
@param {Integer} start position to start within each array
@param {Integer} end number of elements to skip from the end of each array
@return {Boolean} true or false
@example [1,[4,5],2,3].every(function(arg){return arg > 0;}) will return true;
@example [2,[4,0,5],2,3].every(function(arg){return arg < 2;}) will return false;
@example [1,[4,5],2,3].every(function(arg){return arg;}) will return true;
@see every
@see some
@see rsome
returns true if fnct recursively returns == true for every element in this array
if this element is an array, then it will call revery on that element with the same parameters
fnct is called with self parameter as this, and the arguments (this_element,this_index,this_array) or (array[i],i,array)
*/ function(fnct,self,start,end){
return revery.call(this,fnct,self,start);
}
,"some":/**
returns true if any fnct returns true for any element in this array
@param {Function} fnct function called
@param {Object} self value of this within fnct
@return {Boolean} true or false
@example [1,2,3].some(function(arg){return arg == 1;}) will return true
@example [1,2,3].some(function(arg){return arg == 0;}) will return false
@example [1,2,3].some(function(arg){return arg;}) will return true
@see every
@see revery
@see rsome
returns true if fnct returns == true for any element in this array
won't redefine this prototype if it already exists
fnct is called with self parameter as this, and the arguments (this_element,this_index,this_array) or (array[i],i,array)
this mostly follows the mozdev spec at
https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some
*/ function(fnct,self){
return some.call(this,fnct,self);
}
,"rsome":/**
returns true if any recursively fnct returns true for any element in this array
@param {Function} fnct function called
@param {Object} self value of this within fnct
@return {Boolean} true or false
@example [1,2,3].some(function(arg){return arg == 1;}) will return true
@example [1,2,3].some(function(arg){return arg == 0;}) will return false
@example [1,2,3].some(function(arg){return arg;}) will return true
@see every
@see revery
@see some
returns true if recursively fnct returns == true for any element in this array
if this element is an array, then it will call rsome on that element with the same parameters
fnct is called with self parameter as this, and the arguments (this_element,this_index,this_array) or (array[i],i,array)
*/ function(fnct,self,start,end){
return rsome.call(this,fnct,self,start);
}
,"unique":/**
returns array of this array without duplicates
@return {Array} array or results
@example [1,2,3,1,2,3,4].unique() will return [1,2,3,4]
@example [1,"1","one"].unique() will return [1,"1","one"]
@see runique
returns array of this array without duplicates by checking if each element exists using indexOf
this uses the identical (===) function, the following statment is false, "1" === 1
*/ function(){
return unique.call(this);
}
,"runique":/**
returns array of this array without duplicates ignoring nesting of arrays
@return {Array} array or results
@example [1,[2,[3,[4,[5,1,2,3],4],5]]].unique() will return [1,2,3,4,5]
@see unique
this function is identical to array.flatten().unique()
returns array of this array without duplicates ignoring nesting of arrays by checking if each element exists using indexOf
this uses the identical (===) function, the following statment is false, "1" === 1
*/ function(){
return runique.call(this);
}
,"union":/**
returns array of this array union passed array
@param {Array} array array to union
@return {Array} array or results
@example [1,2,3].union([3,4,5]) will return [1,2,3,4,5]
@example [1,2].union([4,5]) will return [1,2,4,5]
@example [1].union(["1"]) will return [1,"1"]
@see intersect
returns array of this array union passed array using indexOf
this uses the identical (===) function, the following statment is false, "1" === 1
*/ function(array){ //returns this union (array)
return union.call(this,array);
}
,"intersect":/**
returns array of this array intersect passed array
@param {Array} array array to intersect
@return {Array} array or results
@example [1,2,3].intersect([3,4,5]) will return [3]
@example [1,2].intersect([4,5]) will return []
@example [1].intersect(["1"]) will return []
@see union
returns array of this array intersect passed array using indexOf
this uses the identical (===) function, the following statment is false, "1" === 1
*/ function(array){ //returns this union (array)
return intersect.call(this,array);
}
,"sortNum":/**
returns array of this array sorted numerically
@param {Boolean} descending true or false
@returns {Array} array of results
@example [1,3,2,5,4].sortNum() will return [1,2,3,4,5]
@example [1,3,2,5,4].sortNum(false) will return [1,2,3,4,5]
@example [1,3,2,5,4].sortNum(true) will return [5,4,3,2,1]
*/ function(descending){ //sort array of numbers (or strings continaing a number) numerically
return sortNum.call(this,descending);
}
,"sortRand":/**
returns array of this array sorted randomly
@returns {Array} array of results
*/ function(){ //sort array randomly
return sortRand.call(this);
}
}
,prototype$ = {
"json_encode":/**
jsonifies an object to a string
@param {Object} arg object to jsonify
@param {Boolean} forceObject return an object not an array
@return {String} returns arg represented as string
@see json_parse
@see json_decode
@example $.json_encode({a:"b"}) will return the string '{"a":"b"}'
*/ function(arg,forceObject){
return json_encode(arg,forceObject);
}
,"json_parse":/**
parses json into an object
@param {String} json string to parse
@return {Object} object represented by json
@see json_encode
@see json_decode
@example $.json_parse('{"a":"b"}') will return the object {a:"b"}
this is identical to json_decode
php calls this function json_decode
json.org calls this function json_parse
this is "json_parse.js" from
http://www.JSON.org
*/ function(json){
return json_parse(json);
}
,"json_decode":/**
parses json into an object
@param {String} json string to parse
@return {Object} object represented by json
@example $.json_parse('{"a":"b"}') will return the object {a:"b"}
@see json_encode
@see json_parse
this is identical to json_parse
php calls this function json_decode
json.org calls this function json_parse
this is "json_parse.js" from
http://www.JSON.org
*/ function(json){
return json_parse(json);
}
,"ajaxTimeout":/**
sets and gets how long to wait before forcefully killing an ajax request
@param {Integer} timeout milliseconds to wait
@return {Integer} timeout in milliseconds
@example $.ajaxTimeout(5000) sets the timeout to 5 seconds and returns 5000
@example $.ajaxTimeout() returns "undefined" milliseconds, the default
@see ajaxCacheTimeout
ajax requests are killed using the .abort() method
this is disabled by default
*/ function(timeout){
if(typeof timeout !== "undefined"){
_ajaxTimeout = timeout;
}
return _ajaxTimeout;
}
,"ajaxCacheTimeout":/**
sets and gets how long to cache ajax responses when cached
@param {Integer} timeout milliseconds to wait
@return {Integer} timeout in milliseconds
@example $.ajaxCacheTimeout(5000) sets the timeout to 5 seconds and returns 5000
@example $.ajaxCacheTimeout() returns 60 * 1000 milliseconds, or 60 seconds, the default
@see ajaxTimeout
ajax requests are cached in the equivalent of an array[element][ajaxEvent][url][parameters]
if the same paramters are sent, it will return the result without sending an xmlhttprequest
*/ function(timeout){
if(typeof timeout !== "undefined"){
_ajaxCacheTimeout = timeout;
}
return _ajaxCacheTimeout;
}
,"framesPerSecond":/**
sets frames per second attempted for graphics/transitions
@param {Integer} fps frames per second
@return {Integer} frames per second
@example $.framePerSecond(100) sets the framesPerSecond to 100 and returns 100
@example $.framePerSecond() returns 20 frames per second, the default
*/ function(fps){
if(typeof fps !== "undefined"){
_framesPerSecond = fps;
millisecondsPerFrame = 1000 / _framesPerSecond;
}
return _framesPerSecond;
}
,"now":/**
returns the current unix time
@return {Float} current browser unix time
depends upon browser/OS, but typically this will have 3 decimal places of precision
*/ function(){
return now();
}
,"addCSS":/**
add CSS styles to this document
@param {String} selector css selector
@param {String} rule css rule
@return {void} void
@example $.addCSS("div.class","color:red")
safe to be called multiple times, won't re-add added styles
*/ function(selector,rule){
addStyleRuleToDocument(selector,rule);
}
,"ajax":/**
return ROCKET's ajax function
@return {Function} ajax function
@example $.ajax() will return the ajax function
outside of development/debug purposes, there should never be a reason to use this
*/ function(){
return ajax;
}
,"trim":/**
trims a string
@param {String} string string to trim
@return {String} trimmed string
@example $.trim(" some string ") will return "some string"
removes all newlines, spaces (including non-breaking spaces), and tabs from the beginning and end of the supplied string
*/ function(string){
return string.replace(stringTrim,"");
}
,"loadJSON":/**
returns an object from an xmlhttp request
@param {String} url for the ajax call
@param {String} method "GET" or "POST"
@param {Function} params function that returns an argObject of get/post var/value pairs; this will be URI encoded
@return {Object} result object
@see addAjaxOn
@example .loadJSON("example.php","GET",function(){return {foo:"bar"};}); could return {foo:"bar'd"};
will return an object json_parse/decode'd from a url
this is a blocking ajax request, loadJSON will block/wait until the request has been received
*/ function(url,method,params){
return loadJSON(url,method,params);
}
}
;
(function(){
var i, rocketPrototype = Rocket.prototype, rocketsPrototype = Rockets.prototype,
rocketsFunctionElement = function(fnct){
return function(){
var args = arguments;
forEach.call(this.elements,function(selfi){fnct.apply({"element":selfi},args);});
return this;
};
},
rocketsFunctionArray = function(fnct){
return function(){
return fnct.apply(this.elements,arguments);
};
};
for(i in prototypeElement){
rocketPrototype[i] = prototypeElement[i];
rocketsPrototype[i] = rocketsFunctionElement(prototypeElement[i]);
}
//map prototype array functions to Array.prototype
for(i in prototypeArray){
if(typeof arrayPrototype[i] !== "function"){
arrayPrototype[i] = prototypeArray[i];
}
rocketsPrototype[i] = rocketsFunctionArray(prototypeArray[i]);
}
}());
$ = function(query){
var i, charZero, ret;
if(typeof query === "object" && query !== null){
if(query.constructor === Array){
return new Rockets(query);
}
else{
return new Rocket(query);
}
}
if(typeof query !== "string" || query === null || (charZero = query.charAt(0)) === ""){
return null;
}
if(query.indexOf(",") !== -1){
ret = [];
forEach.call(query.split(","),function(selfi){
if(selfi.charAt(0) === "#"){
ret.push($(selfi).element);
}
else{
ret.push.apply(ret,$(selfi).elements);
}
});
return new Rockets(ret);
}
else if((i = query.indexOf(" ")) !== -1){
return new Rockets(elementsBySelector(query,i));
}
else if(charZero === "#"){
return new Rocket(document.getElementById(query.substr(1)));
}
else if(charZero === "."){
return new Rockets(elementsByClass(query.substr(1),document));
}
else if((i = query.indexOf(".")) !== -1){
return new Rockets(elementsByTagDotClassName.call(document,query,i));
}
else{
return new Rockets(elementsByTag.call(document,query));
}
};
//assign functions to this returned function object, prototype$
(function(){for(var i in prototype$){$[i] = prototype$[i];}}());
return $;
}(this));