@ -147,4 +148,4 @@ var TwitterGitter = new Class({
}
});
//Compact Jsonp from http://clientcide.com/js
MooTools.More={'version':'1.2.3.1'};varLog=newClass({log:function(){Log.logger.call(this,arguments)}});Log.logged=[];Log.logger=function(){if(window.console&&console.log)console.log.apply(console,arguments);elseLog.logged.push(arguments)};Class.refactor=function(original,refactors){$each(refactors,function(item,name){varorigin=original.prototype[name];if(origin&&(origin=origin._origin)&&typeofitem=='function')original.implement(name,function(){varold=this.previous;this.previous=origin;varvalue=item.apply(this,arguments);this.previous=old;returnvalue});elseoriginal.implement(name,item)});returnoriginal};Request.JSONP=newClass({Implements:[Chain,Events,Options,Log],options:{url:'',data:{},retries:0,timeout:0,link:'ignore',callbackKey:'callback',injectScript:document.head},initialize:function(options){this.setOptions(options);this.running=false;this.requests=0;this.triesRemaining=[]},check:function(){if(!this.running)returntrue;switch(this.options.link){case'cancel':this.cancel();returntrue;case'chain':this.chain(this.caller.bind(this,arguments));returnfalse}returnfalse},send:function(options){if(!$chk(arguments[1])&&!this.check(options))returnthis;vartype=$type(options),old=this.options,index=$chk(arguments[1])?arguments[1]:this.requests++;if(type=='string'||type=='element')options={data:options};options=$extend({data:old.data,url:old.url},options);if(!$chk(this.triesRemaining[index]))this.triesRemaining[index]=this.options.retries;varremaining=this.triesRemaining[index];(function(){varscript=this.getScript(options);this.log('JSONP retrieving script with url: '+script.get('src'));this.fireEvent('request',script);this.running=true;(function(){if(remaining){this.triesRemaining[index]=remaining-1;if(script){script.destroy();this.send(options,index);this.fireEvent('retry',this.triesRemaining[index])}}elseif(script&&this.options.timeout){script.destroy();this.cancel();this.fireEvent('failure')}}).delay(this.options.timeout,this)}).delay(Browser.Engine.trident?50:0,this);returnthis},cancel:function(){if(!this.running)returnthis;this.running=false;this.fireEvent('cancel');returnthis},getScript:function(options){varindex=Request.JSONP.counter,data;Request.JSONP.counter++;switch($type(options.data)){case'element':data=document.id(options.data).toQueryString();break;case'object':case'hash':data=Hash.toQueryString(options.data)}varsrc=options.url+(options.url.test('\\?')?'&':'?')+(options.callbackKey||this.options.callbackKey)+'=Request.JSONP.request_map.request_'+index+(data?'&'+data:'');if(src.length>2083)this.log('JSONP '+src+' will fail in Internet Explorer, which enforces a 2083 bytes length limit on URIs');varscript=newElement('script',{type:'text/javascript',src:src});Request.JSONP.request_map['request_'+index]=function(data){this.success(data,script)}.bind(this);returnscript.inject(this.options.injectScript)},success:function(data,script){if(script)script.destroy();this.running=false;this.log('JSONP successfully retrieved: ',data);this.fireEvent('complete',[data]).fireEvent('success',[data]).callChain()}});Request.JSONP.counter=0;Request.JSONP.request_map={};varJsonP=Class.refactor(Request.JSONP,{initialize:function(){varparams=Array.link(arguments,{url:String.type,options:Object.type});options=(params.options||{});options.url=options.url||params.url;if(options.callBackKey)options.callbackKey=options.callBackKey;this.previous(options)},getScript:function(options){varqueryString=options.queryString||this.options.queryString;if(options.url&&queryString)options.url+=(options.url.indexOf("?")>=0?"&":"?")+queryString;varscript=this.previous(options);if($chk(options.globalFunction)){window[options.globalFunction]=function(r){JsonP.requestors[index].handleResults(r)}}returnscript},request:function(url){this.send({url:url||this.options.url})}});
MooTools.More={'version':'1.2.3.1'};varLog=newClass({log:function(){Log.logger.call(this,arguments)}});Log.logged=[];Log.logger=function(){if(window.console&&console.log)console.log.apply(console,arguments);elseLog.logged.push(arguments)};Class.refactor=function(original,refactors){$each(refactors,function(item,name){varorigin=original.prototype[name];if(origin&&(origin=origin._origin)&&typeofitem=='function')original.implement(name,function(){varold=this.previous;this.previous=origin;varvalue=item.apply(this,arguments);this.previous=old;returnvalue});elseoriginal.implement(name,item)});returnoriginal};Request.JSONP=newClass({Implements:[Chain,Events,Options,Log],options:{url:'',data:{},retries:0,timeout:0,link:'ignore',callbackKey:'callback',injectScript:document.head},initialize:function(options){this.setOptions(options);this.running=false;this.requests=0;this.triesRemaining=[]},check:function(){if(!this.running)returntrue;switch(this.options.link){case'cancel':this.cancel();returntrue;case'chain':this.chain(this.caller.bind(this,arguments));returnfalse}returnfalse},send:function(options){if(!$chk(arguments[1])&&!this.check(options))returnthis;vartype=$type(options),old=this.options,index=$chk(arguments[1])?arguments[1]:this.requests++;if(type=='string'||type=='element')options={data:options};options=$extend({data:old.data,url:old.url},options);if(!$chk(this.triesRemaining[index]))this.triesRemaining[index]=this.options.retries;varremaining=this.triesRemaining[index];(function(){varscript=this.getScript(options);this.log('JSONP retrieving script with url: '+script.get('src'));this.fireEvent('request',script);this.running=true;(function(){if(remaining){this.triesRemaining[index]=remaining-1;if(script){script.destroy();this.send(options,index);this.fireEvent('retry',this.triesRemaining[index])}}elseif(script&&this.options.timeout){script.destroy();this.cancel();this.fireEvent('failure')}}).delay(this.options.timeout,this)}).delay(Browser.Engine.trident?50:0,this);returnthis},cancel:function(){if(!this.running)returnthis;this.running=false;this.fireEvent('cancel');returnthis},getScript:function(options){varindex=Request.JSONP.counter,data;Request.JSONP.counter++;switch($type(options.data)){case'element':data=document.id(options.data).toQueryString();break;case'object':case'hash':data=Hash.toQueryString(options.data)}varsrc=options.url+(options.url.test('\\?')?'&':'?')+(options.callbackKey||this.options.callbackKey)+'=Request.JSONP.request_map.request_'+index+(data?'&'+data:'');if(src.length>2083)this.log('JSONP '+src+' will fail in Internet Explorer, which enforces a 2083 bytes length limit on URIs');varscript=newElement('script',{type:'text/javascript',src:src});Request.JSONP.request_map['request_'+index]=function(data){this.success(data,script)}.bind(this);returnscript.inject(this.options.injectScript)},success:function(data,script){if(script)script.destroy();this.running=false;this.log('JSONP successfully retrieved: ',data);this.fireEvent('complete',[data]).fireEvent('success',[data]).callChain()}});Request.JSONP.counter=0;Request.JSONP.request_map={};varJsonP=Class.refactor(Request.JSONP,{initialize:function(){varparams=Array.link(arguments,{url:String.type,options:Object.type});options=(params.options||{});options.url=options.url||params.url;if(options.callBackKey)options.callbackKey=options.callBackKey;this.previous(options)},getScript:function(options){varqueryString=options.queryString||this.options.queryString;if(options.url&&queryString)options.url+=(options.url.indexOf("?")>=0?"&":"?")+queryString;varscript=this.previous(options);if($chk(options.globalFunction)){window[options.globalFunction]=function(r){JsonP.requestors[index].handleResults(r)}}returnscript},request:function(url){this.send({url:url||this.options.url})}});