Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge https://github.com/facebook/javelin

  • Loading branch information...
commit d2dd54245cc90fb5dc75e40c8266962a5f99de4f 2 parents 7519bc2 + 83aedd5
@hedgerwang hedgerwang authored
View
2  pkg/init.min.js
@@ -1 +1 @@
-(function(){if(window.JX)return;window.JX={};var c={};function f(l){if(JX[l])return;c[l]=[];JX[l]=function(){c[l].push(arguments);};}JX.flushHoldingQueue=function(n,l){for(var m=0;m<c[n].length;m++)l.apply(null,c[n][m]);c[n]={};};f('install');f('behavior');f('install-init');window.__DEV__=window.__DEV__||0;var e=false;var h=[];var g=[];var j=document.documentElement;var b=!!j.addEventListener;JX.__rawEventQueue=function(r){g.push(r);var l=JX.Stratcom;if(l&&l.ready){var p=g;g=[];for(var n=0;n<p.length;++n){var m=p[n];try{var test=m.type;}catch(s){continue;}if(!e&&m.type=='domready'){document.body&&(document.body.id=null);e=true;for(var o=0;o<h.length;o++)h[o]();}l.dispatch(m);}}else{var q=r.srcElement||r.target;if(q&&(r.type in {click:1,submit:1})&&q.getAttribute&&q.getAttribute('data-mustcapture')==='1'){r.returnValue=false;r.preventDefault&&r.preventDefault();document.body.id='event_capture';if(!add_event_listener&&document.createEventObject){g.pop();g.push(document.createEventObject(r));}return false;}}};JX.enableDispatch=function(l,m){if(l.addEventListener){l.addEventListener(m,JX.__rawEventQueue,true);}else if(l.attachEvent)l.attachEvent('on'+m,JX.__rawEventQueue);};var a=['click','change','submit','keypress','mousedown','mouseover','mouseout','mouseup','keyup','keydown','input','drop','dragenter','dragleave','dragover','paste','touchstart','touchmove','touchend','touchcancel'];if(!b)a.push('focusin','focusout');if(window.opera)a.push('focus','blur');for(var d=0;d<a.length;++d)JX.enableDispatch(j,a[d]);var k=[('onpagehide' in window)?'pagehide':'unload','resize','scroll','focus','blur','popstate','hashchange'];for(var d=0;d<k.length;++d)JX.enableDispatch(window,k[d]);JX.__simulate=function(m,event){if(!b){var l={target:m,type:event};JX.__rawEventQueue(l);if(l.returnValue===false)return false;}};if(b){document.addEventListener('DOMContentLoaded',function(){JX.__rawEventQueue({type:'domready'});},true);}else{var i="if (this.readyState == 'complete') {"+"JX.__rawEventQueue({type: 'domready'});"+"}";document.write('<script'+' defer="defer"'+' src="javascript:void(0)"'+' onreadystatechange="'+i+'"'+'><\/sc'+'ript\>');}JX.onload=function(l){if(e){l();}else h.push(l);};})();
+(function(){if(window.JX)return;window.JX={};var c={};function f(l){if(JX[l])return;c[l]=[];JX[l]=function(){c[l].push(arguments);};}JX.flushHoldingQueue=function(n,l){for(var m=0;m<c[n].length;m++)l.apply(null,c[n][m]);c[n]={};};f('install');f('behavior');f('install-init');window.__DEV__=window.__DEV__||0;var e=false;var h=[];var g=[];var j=document.documentElement;var b=!!j.addEventListener;JX.__rawEventQueue=function(r){g.push(r);var l=JX.Stratcom;if(l&&l.ready){var p=g;g=[];for(var n=0;n<p.length;++n){var m=p[n];try{var test=m.type;}catch(s){continue;}if(!e&&m.type=='domready'){document.body&&(document.body.id=null);e=true;for(var o=0;o<h.length;o++)h[o]();}l.dispatch(m);}}else{var q=r.srcElement||r.target;if(q&&(r.type in {click:1,submit:1})&&q.getAttribute&&q.getAttribute('data-mustcapture')==='1'){r.returnValue=false;r.preventDefault&&r.preventDefault();document.body.id='event_capture';if(!add_event_listener&&document.createEventObject){g.pop();g.push(document.createEventObject(r));}return false;}}};JX.enableDispatch=function(l,m){if(l.addEventListener){l.addEventListener(m,JX.__rawEventQueue,true);}else if(l.attachEvent)l.attachEvent('on'+m,JX.__rawEventQueue);};var a=['click','change','submit','keypress','mousedown','mouseover','mouseout','mouseup','keyup','keydown','input','drop','dragenter','dragleave','dragover','paste','touchstart','touchmove','touchend','touchcancel'];if(!b)a.push('focusin','focusout');if(window.opera)a.push('focus','blur');for(var d=0;d<a.length;++d)JX.enableDispatch(j,a[d]);var k=[('onpagehide' in window)?'pagehide':'unload','resize','scroll','focus','blur','popstate','hashchange'];for(var d=0;d<k.length;++d)JX.enableDispatch(window,k[d]);JX.__simulate=function(m,event){if(!b){var l={target:m,type:event};JX.__rawEventQueue(l);if(l.returnValue===false)return false;}};if(b){document.addEventListener('DOMContentLoaded',function(){JX.__rawEventQueue({type:'domready'});},true);}else{var i="if (this.readyState == 'complete') {"+"JX.__rawEventQueue({type: 'domready'});"+"}";document.write('<script'+' defer="defer"'+' src="javascript:void(0)"'+' onreadystatechange="'+i+'"'+'><\/sc'+'ript\>');}JX.onload=function(l){if(e){l();}else h.push(l);};})();
View
6 pkg/javelin.dev.js
@@ -3928,7 +3928,11 @@ JX.install('URI', {
if (JX.Stratcom.invoke('go', null, {uri: uri}).getPrevented()) {
return;
}
- (uri && (window.location = uri)) || window.location.reload(true);
+ if (!uri) {
+ // window.location.reload clears cache in Firefox.
+ uri = window.location.pathname + (window.location.query || '');
+ }
+ window.location = uri;
}
}
View
2  pkg/javelin.min.js
@@ -1 +1 @@
-JX.$E=function(c){var b=new Error(c);var a=JX.$E.caller;if(a)b.caller_fn=a.caller;throw b;};JX.$A=function(b){var c=[];for(var a=0;a<b.length;a++)c.push(b[a]);return c;};JX.$AX=function(a){return JX.isArray(a)?a:[a];};JX.isArray=Array.isArray||function(a){return Object.prototype.toString.call(a)=='[object Array]';};JX.copy=function(a,b){for(var c in b)a[c]=b[c];return a;};JX.bind=function(b,c,d){var a=JX.$A(arguments).slice(2);if(c.bind)return c.bind.apply(c,[b].concat(a));return function(){return c.apply(b||window,a.concat(JX.$A(arguments)));};};JX.bag=function(){};JX.keys=Object.keys||function(b){var c=[];for(var a in b)c.push(a);return c;};JX.id=function(a){return a;};JX.log=JX.bag;JX.now=(Date.now||function(){return new Date().getTime();});JX.install=function(f,e){if(f in JX)return;(JX.install._queue||(JX.install._queue=[])).push([f,e]);var d;do{var c;var b;d=null;for(var a=0;a<JX.install._queue.length;++a){c=JX.install._queue[a][1];if(c.extend&&!JX[c.extend])continue;d=JX.install._queue.splice(a,1)[0][0];--a;if(c.extend)c.extend=JX[c.extend];b=c.initialize;delete c.initialize;c.name='JX.'+d;JX[d]=JX.createClass(c);if(b)if(JX.Stratcom&&JX.Stratcom.ready){b.apply(null);}else JX['install-init'](b);}}while(d);};JX.createClass=function(i){var k=i.name||'';var j;var h;var a=(function(u,t){var v=function(){this.__id__='__obj__'+(++JX.install._nextObjectID);return (t.construct||t.extend||JX.bag).apply(this,arguments);};return v;})(k,i);a.__readable__=k;for(j in i.statics)a[j]=i.statics[j];var q;if(i.extend){var b=function(){};b.prototype=i.extend.prototype;q=a.prototype=new b();}else q=a.prototype={};q.__class__=a;var r=function(t){return function(u){this[t]=u;return this;};};var f=function(t){return function(u){return this[t];};};for(j in (i.properties||{})){var d=j.charAt(0).toUpperCase()+j.substr(1);var o='__auto__'+j;q[o]=i.properties[j];q['set'+d]=r(o);q['get'+d]=f(o);}for(j in i.members)q[j]=i.members[j];var e=JX.install._enumerables;if(i.members&&e){h=e.length;while(h--){var p=e[h];if(i.members[p])q[p]=i.members[p];}}var n=i.extend||{};var m=n.__events__;var l=i.events||[];var g=m||l.length;if(g){var s={};a.__events__=s;a.__name__='class:'+k;var c=n.__path__||[];a.__path__=c.concat([a.__name__]);q.invoke=function(t){return JX.Stratcom.invoke('obj:'+t,this.__class__.__path__.concat([this.__id__]),{args:JX.$A(arguments).slice(1)});};q.listen=function(u,t){return JX.Stratcom.listen('obj:'+u,this.__id__,JX.bind(this,function(v){return t.apply(this,v.getData().args);}));};a.listen=function(u,t){return JX.Stratcom.listen('obj:'+u,this.__name__,JX.bind(this,function(v){return t.apply(this,v.getData().args);}));};}return a;};JX.install._nextObjectID=0;JX.flushHoldingQueue('install',JX.install);(function(){for(var a in {toString:1})return;JX.install._enumerables=['toString','hasOwnProperty','valueOf','isPrototypeOf','propertyIsEnumerable','toLocaleString','constructor'];})();JX.install('Event',{members:{stop:function(){var a=this.getRawEvent();if(a){a.cancelBubble=true;a.stopPropagation&&a.stopPropagation();}this.setStopped(true);return this;},prevent:function(){var a=this.getRawEvent();if(a){a.returnValue=false;a.preventDefault&&a.preventDefault();}this.setPrevented(true);return this;},kill:function(){this.prevent();this.stop();return this;},getSpecialKey:function(){var a=this.getRawEvent();if(!a||a.shiftKey)return null;return JX.Event._keymap[a.keyCode]||null;},isRightButton:function(){var a=this.getRawEvent();return a.which==3||a.button==2;},getNode:function(a){return this.getNodes()[a]||null;},getNodeData:function(a){return JX.Stratcom.getData(this.getNode(a));}},statics:{_keymap:{8:'delete',9:'tab',13:'return',27:'esc',37:'left',38:'up',39:'right',40:'down',63232:'up',63233:'down',62234:'left',62235:'right'}},properties:{rawEvent:null,type:null,target:null,data:null,path:[],stopped:false,prevented:false,nodes:{},nodeDistances:{}},initialize:function(){}});JX.install('Stratcom',{statics:{ready:false,_targets:{},_handlers:[],_need:{},_auto:'*',_data:{},_execContext:[],_dataBlock:2,_dataIndex:0,invoke:function(c,b,a){b=JX.$AX(b);return this._dispatchProxy(new JX.Event().setType(c).setData(a||{}).setPath(b||[]));},listen:function(l,i,a){var c=[];l=JX.$AX(l);if(!i)i=this._auto;if(!JX.isArray(i)){i=[[i]];}else if(!JX.isArray(i[0]))i=[i];var g={_callback:a};for(var d=0;d<l.length;++d){var j=l[d];if(('onpagehide' in window)&&j=='unload')j='pagehide';if(!(j in this._targets))this._targets[j]={};var k=this._targets[j];for(var e=0;e<i.length;++e){var h=i[e];var b=this._handlers.length;this._handlers.push(g);this._need[b]=h.length;c.push(b);for(var f=0;f<h.length;++f)(k[h[f]]||(k[h[f]]=[])).push(b);}}g.remove=function(){if(g._callback){delete g._callback;for(var m=0;m<c.length;m++)delete JX.Stratcom._handlers[c[m]];}};return g;},removeCurrentListener:function(){var a=this._execContext[this._execContext.length-1];var c=a.listeners;var b=a.cursor-1;if(c[b])c[b].handler.remove();},dispatch:function(event){var h=[];var g={};var c={};var j=function(n,o,m){if(!g.hasOwnProperty(n)){g[n]=o;c[n]=m;h.push(n);}};var l=event.srcElement||event.target;if(l&&l.nodeType===3)l=l.parentNode;if(!l||!l.getAttribute)l=null;var b=1;var a=l;while(a&&a.getAttribute){j('tag:'+a.nodeName.toLowerCase(),a,b);var e=a.id;if(e)j('id:'+e,a,b);var k=a.getAttribute('data-sigil');if(k){k=k.split(' ');for(var f=0;f<k.length;f++)j(k[f],a,b);}++b;a=a.parentNode;}var d=event.type;if(d=='focusin'){d='focus';}else if(d=='focusout')d='blur';var i=new JX.Event().setRawEvent(event).setType(d).setTarget(l).setNodes(g).setNodeDistances(c).setPath(h.reverse());return this._dispatchProxy(i);},_dispatchProxy:function(n){var p=this._targets[n.getType()];if(!p)return n;var m=n.getPath();var b=n.getNodeDistances();var i=m.length;var f={};var e={};var l;var c=1e+06;for(var o=-1;o<i;++o){l=p[(o==-1)?this._auto:m[o]];if(l){var a=b[m[o]]||c;for(var g=0;g<l.length;++g){var k=l[g];f[k]=(f[k]||0)+1;e[k]=Math.min(e[k]||a,a);}}}var j=[];for(var h in f)if(f[h]==this._need[h]){var d=this._handlers[h];if(d)j.push({distance:e[h],handler:d});}j.sort(function(q,r){return q.distance-r.distance;});this._execContext.push({listeners:j,event:n,cursor:0});this.pass();this._execContext.pop();return n;},pass:function(){var a=this._execContext[this._execContext.length-1];var event=a.event;var d=a.listeners;while(a.cursor<d.length){var b=a.cursor++;if(d[b]){var c=d[b].handler;c._callback&&c._callback(event);}if(event.getStopped())break;}return event.getStopped()||event.getPrevented();},context:function(){var a=this._execContext.length;return a?this._execContext[a-1].event:null;},mergeData:function(a,b){if(this._data[a]){JX.copy(this._data[a],b);}else{this._data[a]=b;if(a===0){JX.Stratcom.ready=true;JX.flushHoldingQueue('install-init',function(c){c();});JX.__rawEventQueue({type:'start-queue'});}}},hasSigil:function(a,b){var c=a.getAttribute('data-sigil')||false;return c&&(' '+c+' ').indexOf(' '+b+' ')>-1;},addSigil:function(a,b){var c=a.getAttribute('data-sigil')||'';if(!JX.Stratcom.hasSigil(a,b))c+=' '+b;a.setAttribute('data-sigil',c);},getData:function(e){var d=(e.getAttribute('data-meta')||'').split('_');if(d[0]&&d[1]){var a=this._data[d[0]];var c=d[1];if(a&&(c in a))return a[c];}var b={};if(!this._data[1])this._data[1]={};this._data[1][this._dataIndex]=b;e.setAttribute('data-meta','1_'+(this._dataIndex++));return b;},addData:function(b,a){return JX.copy(JX.Stratcom.getData(b),a);},allocateMetadataBlock:function(){return this._dataBlock++;}}});JX.behavior=function(b,a){JX.behavior._behaviors[b]=a;JX.behavior._statics[b]={};};JX.initBehaviors=function(c){var d=[];for(var e in c){if(!(e in JX.behavior._behaviors)){d.push(e);continue;}var a=c[e];if(!a.length){if(JX.behavior._initialized.hasOwnProperty(e))continue;a=[null];}for(var b=0;b<a.length;b++)JX.behavior._behaviors[e](a[b],JX.behavior._statics[e]);JX.behavior._initialized[e]=true;}if(d.length)JX.$E('JX.initBehavior(map): behavior(s) not registered: '+d.join(', '));};JX.behavior._behaviors={};JX.behavior._statics={};JX.behavior._initialized={};JX.flushHoldingQueue('behavior',JX.behavior);JX.install('Request',{construct:function(b,a){this.setURI(b);if(a)this.listen('done',a);},events:['start','open','send','statechange','done','error','finally','uploadprogress'],members:{_xhrkey:null,_transport:null,_sent:false,_finished:false,_block:null,_data:null,_getSameOriginTransport:function(){try{try{return new XMLHttpRequest();}catch(a){return new ActiveXObject("Msxml2.XMLHTTP");}}catch(a){return new ActiveXObject("Microsoft.XMLHTTP");}},_getCORSTransport:function(){try{var xport=new XMLHttpRequest();if(!('withCredentials' in xport))if(typeof XDomainRequest!='undefined')xport=new XDomainRequest();return xport;}catch(a){return new XDomainRequest();}},getTransport:function(){if(!this._transport)this._transport=this.getCORS()?this._getCORSTransport():this._getSameOriginTransport();return this._transport;},send:function(){if(this._sent||this._finished)return;this.invoke('start',this);if(this._finished)return;var e=this.getTransport();e.onreadystatechange=JX.bind(this,this._onreadystatechange);if(e.upload)e.upload.onprogress=JX.bind(this,this._onuploadprogress);var b=this.getMethod().toUpperCase();var a=this._data||[];a.push(['__ajax__',true]);this._block=JX.Stratcom.allocateMetadataBlock();a.push(['__metablock__',this._block]);var c=(this.getDataSerializer()||JX.Request.defaultDataSerializer)(a);var d=this.getURI();if(b=='GET'||this.getFile())d+=((d.indexOf('?')===-1)?'?':'&')+c;if(this.getTimeout())this._timer=setTimeout(JX.bind(this,this._fail,JX.Request.ERROR_TIMEOUT),this.getTimeout());e.open(b,d,true);this.invoke('open',this);if(this._finished)return;this.invoke('send',this);if(this._finished)return;if(b=='POST'){if(this.getFile()){e.send(this.getFile());}else{e.setRequestHeader('Content-Type','application/x-www-form-urlencoded');e.send(c);}}else e.send(null);this._sent=true;},abort:function(){this._cleanup();},_onuploadprogress:function(a){this.invoke('uploadprogress',a);},_onreadystatechange:function(){var c=this.getTransport();var b;try{this.invoke('statechange',this);if(this._finished)return;if(c.readyState!=4)return;if(c.status!==0&&(c.status<200||c.status>=300)){this._fail();return;}b=this._extractResponse(c);if(!b)JX.$E('JX.Request("'+this.getURI()+'", ...): '+'server returned an invalid response.');}catch(a){this._fail();return;}try{this._handleResponse(b);this._cleanup();}catch(a){setTimeout(function(){throw a;},0);}},_extractResponse:function(e){var c=e.responseText;if(this.getExpectCSRFGuard())c=c.substring('for (;;);'.length);var d=this.getResponseType().toUpperCase();if(d=='TEXT'){return c;}else if(d=='JSON'||d=='JAVELIN'){return JX.JSON.parse(c);}else if(d=='XML'){var a;try{if(typeof DOMParser!='undefined'){var parser=new DOMParser();a=parser.parseFromString(c,"text/xml");}else{a=new ActiveXObject("Microsoft.XMLDOM");a.async=false;a.loadXML(e.responseText);}return a.documentElement;}catch(b){this._fail();return null;}}return null;},_fail:function(a){this._cleanup();this.invoke('error',a,this);this.invoke('finally');},_done:function(c){this._cleanup();if(c.onload)for(var a=0;a<c.onload.length;a++)(new Function(c.onload[a]))();var b;if(this.getRaw()){b=c;}else{b=c.payload;JX.Request._parseResponsePayload(b);}this.invoke('done',b,this);this.invoke('finally');},_cleanup:function(){this._finished=true;clearTimeout(this._timer);this._timer=null;if(this._transport&&this._transport.readyState!=4)this._transport.abort();},setData:function(a){this._data=null;this.addData(a);return this;},addData:function(a){if(!this._data)this._data=[];for(var b in a)this._data.push([b,a[b]]);return this;},setDataWithListOfPairs:function(a){this._data=a;return this;},_handleResponse:function(a){if(this.getResponseType().toUpperCase()=='JAVELIN'){if(a.error){this._fail(a.error);}else{JX.Stratcom.mergeData(this._block,a.javelin_metadata||{});this._done(a);JX.initBehaviors(a.javelin_behaviors||{});}}else{this._cleanup();this.invoke('done',a,this);this.invoke('finally');}}},statics:{ERROR_TIMEOUT:-9000,defaultDataSerializer:function(b){var e=[];for(var a=0;a<b.length;a++){var d=b[a];var c=encodeURIComponent(d[0]);var f=encodeURIComponent(d[1]);e.push(c+'='+f);}return e.join('&');},_parseResponsePayload:function(e,b){var f=JX.Request._parseResponsePayload;var d=(typeof b!=='undefined')?e[b]:e;if(JX.isArray(d)){for(var a=0;a<d.length;a++)f(d,a);}else if(d&&typeof d=='object')if(d.__html!=null){e[b]=JX.$H(d.__html);}else for(var c in d)f(d,c);}},properties:{URI:null,dataSerializer:null,method:'POST',file:null,raw:false,timeout:null,expectCSRFGuard:true,CORS:false,responseType:'JAVELIN'}});JX.$V=function(a,b){return new JX.Vector(a,b);};JX.install('Vector',{construct:function(a,b){if(typeof b=='undefined')return JX.Vector.getPos(a);this.x=(a===null)?null:parseFloat(a);this.y=(b===null)?null:parseFloat(b);},members:{x:null,y:null,setPos:function(a){a.style.left=(this.x===null)?'':(parseInt(this.x,10)+'px');a.style.top=(this.y===null)?'':(parseInt(this.y,10)+'px');return this;},setDim:function(a){a.style.width=(this.x===null)?'':(parseInt(this.x,10)+'px');a.style.height=(this.y===null)?'':(parseInt(this.y,10)+'px');return this;},add:function(a,b){if(a instanceof JX.Vector){b=a.y;a=a.x;}return new JX.Vector(this.x+parseFloat(a),this.y+parseFloat(b));}},statics:{_viewport:null,getPos:function(b){JX.Event&&(b instanceof JX.Event)&&(b=b.getRawEvent());if(('pageX' in b)||('clientX' in b)){var a=JX.Vector._viewport;return new JX.Vector(b.pageX||(b.clientX+a.scrollLeft),b.pageY||(b.clientY+a.scrollTop));}var c=0;var d=0;do{c+=b.offsetLeft;d+=b.offsetTop;b=b.offsetParent;}while(b&&b!=document.body);return new JX.Vector(c,d);},getDim:function(a){return new JX.Vector(a.offsetWidth,a.offsetHeight);},getScroll:function(){var a=document.body;var b=document.documentElement;return new JX.Vector(window.pageXOffset||a.scrollLeft||b.scrollLeft,window.pageYOffset||a.scrollTop||b.scrollTop);},getViewport:function(){var a=JX.Vector._viewport;return new JX.Vector(window.innerWidth||a.clientWidth||0,window.innerHeight||a.clientHeight||0);},getDocument:function(){var a=JX.Vector._viewport;return new JX.Vector(a.scrollWidth||0,a.scrollHeight||0);}},initialize:function(){JX.Vector._viewport=document.documentElement||document.body;}});JX.$=function(a){var b=document.getElementById(a);if(!b||(b.id!=a))JX.$E("JX.$('"+a+"') call matched no nodes.");return b;};JX.install('HTML',{construct:function(a){this._content=a;},members:{_content:null,getFragment:function(){var b=JX.$N('div');b.innerHTML=this._content;var a=document.createDocumentFragment();while(b.firstChild)a.appendChild(b.removeChild(b.firstChild));return a;}}});JX.$H=function(a){return new JX.HTML(a);};JX.$N=function(d,a,b){if(typeof b=='undefined'&&(typeof a!='object'||a instanceof JX.HTML)){b=a;a={};}var c=document.createElement(d);if(a.style){JX.copy(c.style,a.style);delete a.style;}if(a.sigil){JX.Stratcom.addSigil(c,a.sigil);delete a.sigil;}if(a.meta){JX.Stratcom.addData(c,a.meta);delete a.meta;}JX.copy(c,a);if(b)JX.DOM.setContent(c,b);return c;};JX.install('DOM',{statics:{_autoid:0,_metrics:{},setContent:function(b,a){while(b.firstChild)JX.DOM.remove(b.firstChild);JX.DOM.appendContent(b,a);},prependContent:function(b,a){this._insertContent(b,a,this._mechanismPrepend,true);},appendContent:function(b,a){this._insertContent(b,a,this._mechanismAppend);},_mechanismPrepend:function(b,a){b.insertBefore(a,b.firstChild);},_mechanismAppend:function(b,a){b.appendChild(a);},_insertContent:function(d,a,c,e){if(JX.isArray(a)){if(e)a=[].concat(a).reverse();for(var b=0;b<a.length;b++)JX.DOM._insertContent(d,a[b],c,e);}else{var f=typeof a;if(a instanceof JX.HTML){a=a.getFragment();}else if(f=='string'||f=='number')a=document.createTextNode(a);a&&c(d,a);}},remove:function(a){a.parentNode&&JX.DOM.replace(a,null);return a;},replace:function(b,d){var a;if(b.nextSibling){a=JX.bind(b.nextSibling,function(f,e){f.insertBefore(e,this);});}else a=this._mechanismAppend;var c=b.parentNode;c.removeChild(b);this._insertContent(c,d,a);return b;},convertFormToListOfPairs:function(c){var b=c.getElementsByTagName('*');var a=[];for(var d=0;d<b.length;++d){if(!b[d].name)continue;if(b[d].disabled)continue;var f=b[d].type;var e=b[d].tagName;if((f in {radio:1,checkbox:1}&&b[d].checked)||f in {text:1,hidden:1,password:1,email:1,tel:1,number:1}||e in {TEXTAREA:1,SELECT:1})a.push([b[d].name,b[d].value]);}return a;},convertFormToDictionary:function(b){var a={};var d=JX.DOM.convertFormToListOfPairs(b);for(var c=0;c<d.length;c++)a[d[c][0]]=d[c][1];return a;},isNode:function(a){return !!(a&&a.nodeName&&(a!==window));},isType:function(b,c){b=(''+(b.nodeName||'')).toUpperCase();c=JX.$AX(c);for(var a=0;a<c.length;++a)if(c[a].toUpperCase()==b)return true;return false;},listen:function(d,f,e,a){var b=['id:'+JX.DOM.uniqID(d)];e=JX.$AX(e||[]);if(!e.length){e=b;}else for(var c=0;c<e.length;c++)e[c]=b.concat(JX.$AX(e[c]));return JX.Stratcom.listen(f,e,a);},uniqID:function(a){if(!a.getAttribute('id'))a.setAttribute('id','autoid_'+(++JX.DOM._autoid));return a.getAttribute('id');},alterClass:function(d,b,a){var c=((' '+d.className+' ').indexOf(' '+b+' ')>-1);if(a&&!c){d.className+=' '+b;}else if(c&&!a)d.className=d.className.replace(new RegExp('(^|\\s)'+b+'(?:\\s|$)','g'),' ');},htmlize:function(a){return (''+a).replace(/&/g,'&amp;').replace(/"/g,'&quot;').replace(/</g,'&lt;').replace(/>/g,'&gt;');},show:function(){for(var a=0;a<arguments.length;++a)arguments[a].style.display='';},hide:function(){for(var a=0;a<arguments.length;++a)arguments[a].style.display='none';},textMetrics:function(c,e,f){if(!this._metrics[e]){var b=JX.$N('var',{className:e});this._metrics[e]=b;}var d=this._metrics[e];document.body.appendChild(d);d.style.width=f?(f+'px'):'';JX.DOM.setContent(d,JX.$H(JX.DOM.htmlize(c.value).replace(/\n/g,'<br />')));var a=JX.Vector.getDim(d);document.body.removeChild(d);return a;},scry:function(d,f,e){var b=d.getElementsByTagName(f);if(!e)return JX.$A(b);var c=[];for(var a=0;a<b.length;a++)if(JX.Stratcom.hasSigil(b[a],e))c.push(b[a]);return c;},find:function(b,d,c){var a=JX.DOM.scry(b,d,c);if(!a.length)JX.$E('JX.DOM.find(<node>, "'+d+'", "'+c+'"): '+'matched no nodes.');return a[0];},focus:function(b){try{b.focus();}catch(a){}},scrollTo:function(a){window.scrollTo(0,JX.$V(a).y);}}});JX.install('JSON',{statics:{parse:function(data){if(typeof data!='string')return null;if(window.JSON&&JSON.parse){var obj;try{obj=JSON.parse(data);}catch(e){}return obj||null;}return eval('('+data+')');},stringify:function(e){if(window.JSON&&JSON.stringify)return JSON.stringify(e);var c=[];if(e===null||e===true||e===false||typeof e=='number')return ''+e;if(e.push&&e.pop){var d;for(var a=0;a<e.length;a++){d=(typeof e[a]=='undefined')?null:e[a];c.push(JX.JSON.stringify(d));}return '['+c.join(',')+']';}if(typeof e=='string')return JX.JSON._esc(e);for(var b in e)c.push(JX.JSON._esc(b)+':'+JX.JSON.stringify(e[b]));return '{'+c.join(',')+'}';},_escexp:/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,_meta:{'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},_esc:function(a){JX.JSON._escexp.lastIndex=0;return JX.JSON._escexp.test(a)?'"'+a.replace(JX.JSON._escexp,JX.JSON._replace)+'"':'"'+a+'"';},_replace:function(a){if(a in JX.JSON._meta)return JX.JSON._meta[a];return '\\u'+(('0000'+a.charCodeAt(0).toString(16)).slice(-4));}}});JX.$U=function(a){return new JX.URI(a);};JX.install('URI',{statics:{_uriPattern:/(?:([^:\/?#]+):)?(?:\/\/([^:\/?#]*)(?::(\d*))?)?([^?#]*)(?:\?([^#]*))?(?:#(.*))?/,_queryPattern:/(?:^|&)([^&=]*)=?([^&]*)/g,_defaultQuerySerializer:function(c){var b=[];for(var a in c)if(c[a]!=null){var d=encodeURIComponent(c[a]);b.push(encodeURIComponent(a)+(d?'='+d:''));}return b.join('&');}},construct:function(f){this.setQueryParams({});if(f){var e=JX.URI._uriPattern.exec(f);this.setProtocol(e[1]||undefined);this.setDomain(e[2]||undefined);this.setPort(e[3]||undefined);var b=e[4];var c=e[5];this.setFragment(e[6]||undefined);this.setPath(b.charAt(0)=='/'?b:'/'+b);if(c){var d={};var a;while((a=JX.URI._queryPattern.exec(c))!=null)d[decodeURIComponent(a[1].replace(/\+/g,' '))]=decodeURIComponent(a[2].replace(/\+/g,' '));this.setQueryParams(d);}}},properties:{protocol:undefined,port:undefined,path:undefined,queryParams:undefined,fragment:undefined,querySerializer:undefined},members:{_domain:undefined,addQueryParams:function(a){JX.copy(this.getQueryParams(),a);return this;},setQueryParam:function(a,c){var b={};b[a]=c;return this.addQueryParams(b);},setDomain:function(a){var b=new RegExp('[\\x00-\\x2c\\x2f\\x3b-\\x40\\x5c\\x5e\\x60\\x7b-\\x7f'+'\\uFDD0-\\uFDEF\\uFFF0-\\uFFFF'+'\\u2047\\u2048\\uFE56\\uFE5F\\uFF03\\uFF0F\\uFF1F]');if(b.test(a))JX.$E('JX.URI.setDomain(...): invalid domain specified.');this._domain=a;return this;},getDomain:function(){return this._domain;},toString:function(){var a='';if(this.getProtocol())a+=this.getProtocol()+'://';a+=this.getDomain()||'';a+=this.getPath()||(a?'/':'');a+=this._getQueryString();if(this.getFragment())a+='#'+this.getFragment();return a;},_getQueryString:function(){var a=(this.getQuerySerializer()||JX.URI._defaultQuerySerializer)(this.getQueryParams());return a?'?'+a:'';},go:function(){var a=this.toString();if(JX.Stratcom.invoke('go',null,{uri:a}).getPrevented())return;(a&&(window.location=a))||window.location.reload(true);}}});
+JX.$E=function(c){var b=new Error(c);var a=JX.$E.caller;if(a)b.caller_fn=a.caller;throw b;};JX.$A=function(b){var c=[];for(var a=0;a<b.length;a++)c.push(b[a]);return c;};JX.$AX=function(a){return JX.isArray(a)?a:[a];};JX.isArray=Array.isArray||function(a){return Object.prototype.toString.call(a)=='[object Array]';};JX.copy=function(a,b){for(var c in b)a[c]=b[c];return a;};JX.bind=function(b,c,d){var a=JX.$A(arguments).slice(2);if(c.bind)return c.bind.apply(c,[b].concat(a));return function(){return c.apply(b||window,a.concat(JX.$A(arguments)));};};JX.bag=function(){};JX.keys=Object.keys||function(b){var c=[];for(var a in b)c.push(a);return c;};JX.id=function(a){return a;};JX.log=JX.bag;JX.now=(Date.now||function(){return new Date().getTime();});JX.install=function(f,e){if(f in JX)return;(JX.install._queue||(JX.install._queue=[])).push([f,e]);var d;do{var c;var b;d=null;for(var a=0;a<JX.install._queue.length;++a){c=JX.install._queue[a][1];if(c.extend&&!JX[c.extend])continue;d=JX.install._queue.splice(a,1)[0][0];--a;if(c.extend)c.extend=JX[c.extend];b=c.initialize;delete c.initialize;c.name='JX.'+d;JX[d]=JX.createClass(c);if(b)if(JX.Stratcom&&JX.Stratcom.ready){b.apply(null);}else JX['install-init'](b);}}while(d);};JX.createClass=function(i){var k=i.name||'';var j;var h;var a=(function(u,t){var v=function(){this.__id__='__obj__'+(++JX.install._nextObjectID);return (t.construct||t.extend||JX.bag).apply(this,arguments);};return v;})(k,i);a.__readable__=k;for(j in i.statics)a[j]=i.statics[j];var q;if(i.extend){var b=function(){};b.prototype=i.extend.prototype;q=a.prototype=new b();}else q=a.prototype={};q.__class__=a;var r=function(t){return function(u){this[t]=u;return this;};};var f=function(t){return function(u){return this[t];};};for(j in (i.properties||{})){var d=j.charAt(0).toUpperCase()+j.substr(1);var o='__auto__'+j;q[o]=i.properties[j];q['set'+d]=r(o);q['get'+d]=f(o);}for(j in i.members)q[j]=i.members[j];var e=JX.install._enumerables;if(i.members&&e){h=e.length;while(h--){var p=e[h];if(i.members[p])q[p]=i.members[p];}}var n=i.extend||{};var m=n.__events__;var l=i.events||[];var g=m||l.length;if(g){var s={};a.__events__=s;a.__name__='class:'+k;var c=n.__path__||[];a.__path__=c.concat([a.__name__]);q.invoke=function(t){return JX.Stratcom.invoke('obj:'+t,this.__class__.__path__.concat([this.__id__]),{args:JX.$A(arguments).slice(1)});};q.listen=function(u,t){return JX.Stratcom.listen('obj:'+u,this.__id__,JX.bind(this,function(v){return t.apply(this,v.getData().args);}));};a.listen=function(u,t){return JX.Stratcom.listen('obj:'+u,this.__name__,JX.bind(this,function(v){return t.apply(this,v.getData().args);}));};}return a;};JX.install._nextObjectID=0;JX.flushHoldingQueue('install',JX.install);(function(){for(var a in {toString:1})return;JX.install._enumerables=['toString','hasOwnProperty','valueOf','isPrototypeOf','propertyIsEnumerable','toLocaleString','constructor'];})();JX.install('Event',{members:{stop:function(){var a=this.getRawEvent();if(a){a.cancelBubble=true;a.stopPropagation&&a.stopPropagation();}this.setStopped(true);return this;},prevent:function(){var a=this.getRawEvent();if(a){a.returnValue=false;a.preventDefault&&a.preventDefault();}this.setPrevented(true);return this;},kill:function(){this.prevent();this.stop();return this;},getSpecialKey:function(){var a=this.getRawEvent();if(!a||a.shiftKey)return null;return JX.Event._keymap[a.keyCode]||null;},isRightButton:function(){var a=this.getRawEvent();return a.which==3||a.button==2;},getNode:function(a){return this.getNodes()[a]||null;},getNodeData:function(a){return JX.Stratcom.getData(this.getNode(a));}},statics:{_keymap:{8:'delete',9:'tab',13:'return',27:'esc',37:'left',38:'up',39:'right',40:'down',63232:'up',63233:'down',62234:'left',62235:'right'}},properties:{rawEvent:null,type:null,target:null,data:null,path:[],stopped:false,prevented:false,nodes:{},nodeDistances:{}},initialize:function(){}});JX.install('Stratcom',{statics:{ready:false,_targets:{},_handlers:[],_need:{},_auto:'*',_data:{},_execContext:[],_dataBlock:2,_dataIndex:0,invoke:function(c,b,a){b=JX.$AX(b);return this._dispatchProxy(new JX.Event().setType(c).setData(a||{}).setPath(b||[]));},listen:function(l,i,a){var c=[];l=JX.$AX(l);if(!i)i=this._auto;if(!JX.isArray(i)){i=[[i]];}else if(!JX.isArray(i[0]))i=[i];var g={_callback:a};for(var d=0;d<l.length;++d){var j=l[d];if(('onpagehide' in window)&&j=='unload')j='pagehide';if(!(j in this._targets))this._targets[j]={};var k=this._targets[j];for(var e=0;e<i.length;++e){var h=i[e];var b=this._handlers.length;this._handlers.push(g);this._need[b]=h.length;c.push(b);for(var f=0;f<h.length;++f)(k[h[f]]||(k[h[f]]=[])).push(b);}}g.remove=function(){if(g._callback){delete g._callback;for(var m=0;m<c.length;m++)delete JX.Stratcom._handlers[c[m]];}};return g;},removeCurrentListener:function(){var a=this._execContext[this._execContext.length-1];var c=a.listeners;var b=a.cursor-1;if(c[b])c[b].handler.remove();},dispatch:function(event){var h=[];var g={};var c={};var j=function(n,o,m){if(!g.hasOwnProperty(n)){g[n]=o;c[n]=m;h.push(n);}};var l=event.srcElement||event.target;if(l&&l.nodeType===3)l=l.parentNode;if(!l||!l.getAttribute)l=null;var b=1;var a=l;while(a&&a.getAttribute){j('tag:'+a.nodeName.toLowerCase(),a,b);var e=a.id;if(e)j('id:'+e,a,b);var k=a.getAttribute('data-sigil');if(k){k=k.split(' ');for(var f=0;f<k.length;f++)j(k[f],a,b);}++b;a=a.parentNode;}var d=event.type;if(d=='focusin'){d='focus';}else if(d=='focusout')d='blur';var i=new JX.Event().setRawEvent(event).setType(d).setTarget(l).setNodes(g).setNodeDistances(c).setPath(h.reverse());return this._dispatchProxy(i);},_dispatchProxy:function(n){var p=this._targets[n.getType()];if(!p)return n;var m=n.getPath();var b=n.getNodeDistances();var i=m.length;var f={};var e={};var l;var c=1e+06;for(var o=-1;o<i;++o){l=p[(o==-1)?this._auto:m[o]];if(l){var a=b[m[o]]||c;for(var g=0;g<l.length;++g){var k=l[g];f[k]=(f[k]||0)+1;e[k]=Math.min(e[k]||a,a);}}}var j=[];for(var h in f)if(f[h]==this._need[h]){var d=this._handlers[h];if(d)j.push({distance:e[h],handler:d});}j.sort(function(q,r){return q.distance-r.distance;});this._execContext.push({listeners:j,event:n,cursor:0});this.pass();this._execContext.pop();return n;},pass:function(){var a=this._execContext[this._execContext.length-1];var event=a.event;var d=a.listeners;while(a.cursor<d.length){var b=a.cursor++;if(d[b]){var c=d[b].handler;c._callback&&c._callback(event);}if(event.getStopped())break;}return event.getStopped()||event.getPrevented();},context:function(){var a=this._execContext.length;return a?this._execContext[a-1].event:null;},mergeData:function(a,b){if(this._data[a]){JX.copy(this._data[a],b);}else{this._data[a]=b;if(a===0){JX.Stratcom.ready=true;JX.flushHoldingQueue('install-init',function(c){c();});JX.__rawEventQueue({type:'start-queue'});}}},hasSigil:function(a,b){var c=a.getAttribute('data-sigil')||false;return c&&(' '+c+' ').indexOf(' '+b+' ')>-1;},addSigil:function(a,b){var c=a.getAttribute('data-sigil')||'';if(!JX.Stratcom.hasSigil(a,b))c+=' '+b;a.setAttribute('data-sigil',c);},getData:function(e){var d=(e.getAttribute('data-meta')||'').split('_');if(d[0]&&d[1]){var a=this._data[d[0]];var c=d[1];if(a&&(c in a))return a[c];}var b={};if(!this._data[1])this._data[1]={};this._data[1][this._dataIndex]=b;e.setAttribute('data-meta','1_'+(this._dataIndex++));return b;},addData:function(b,a){return JX.copy(JX.Stratcom.getData(b),a);},allocateMetadataBlock:function(){return this._dataBlock++;}}});JX.behavior=function(b,a){JX.behavior._behaviors[b]=a;JX.behavior._statics[b]={};};JX.initBehaviors=function(c){var d=[];for(var e in c){if(!(e in JX.behavior._behaviors)){d.push(e);continue;}var a=c[e];if(!a.length){if(JX.behavior._initialized.hasOwnProperty(e))continue;a=[null];}for(var b=0;b<a.length;b++)JX.behavior._behaviors[e](a[b],JX.behavior._statics[e]);JX.behavior._initialized[e]=true;}if(d.length)JX.$E('JX.initBehavior(map): behavior(s) not registered: '+d.join(', '));};JX.behavior._behaviors={};JX.behavior._statics={};JX.behavior._initialized={};JX.flushHoldingQueue('behavior',JX.behavior);JX.install('Request',{construct:function(b,a){this.setURI(b);if(a)this.listen('done',a);},events:['start','open','send','statechange','done','error','finally','uploadprogress'],members:{_xhrkey:null,_transport:null,_sent:false,_finished:false,_block:null,_data:null,_getSameOriginTransport:function(){try{try{return new XMLHttpRequest();}catch(a){return new ActiveXObject("Msxml2.XMLHTTP");}}catch(a){return new ActiveXObject("Microsoft.XMLHTTP");}},_getCORSTransport:function(){try{var xport=new XMLHttpRequest();if(!('withCredentials' in xport))if(typeof XDomainRequest!='undefined')xport=new XDomainRequest();return xport;}catch(a){return new XDomainRequest();}},getTransport:function(){if(!this._transport)this._transport=this.getCORS()?this._getCORSTransport():this._getSameOriginTransport();return this._transport;},send:function(){if(this._sent||this._finished)return;this.invoke('start',this);if(this._finished)return;var e=this.getTransport();e.onreadystatechange=JX.bind(this,this._onreadystatechange);if(e.upload)e.upload.onprogress=JX.bind(this,this._onuploadprogress);var b=this.getMethod().toUpperCase();var a=this._data||[];a.push(['__ajax__',true]);this._block=JX.Stratcom.allocateMetadataBlock();a.push(['__metablock__',this._block]);var c=(this.getDataSerializer()||JX.Request.defaultDataSerializer)(a);var d=this.getURI();if(b=='GET'||this.getFile())d+=((d.indexOf('?')===-1)?'?':'&')+c;if(this.getTimeout())this._timer=setTimeout(JX.bind(this,this._fail,JX.Request.ERROR_TIMEOUT),this.getTimeout());e.open(b,d,true);this.invoke('open',this);if(this._finished)return;this.invoke('send',this);if(this._finished)return;if(b=='POST'){if(this.getFile()){e.send(this.getFile());}else{e.setRequestHeader('Content-Type','application/x-www-form-urlencoded');e.send(c);}}else e.send(null);this._sent=true;},abort:function(){this._cleanup();},_onuploadprogress:function(a){this.invoke('uploadprogress',a);},_onreadystatechange:function(){var c=this.getTransport();var b;try{this.invoke('statechange',this);if(this._finished)return;if(c.readyState!=4)return;if(c.status!==0&&(c.status<200||c.status>=300)){this._fail();return;}b=this._extractResponse(c);if(!b)JX.$E('JX.Request("'+this.getURI()+'", ...): '+'server returned an invalid response.');}catch(a){this._fail();return;}try{this._handleResponse(b);this._cleanup();}catch(a){setTimeout(function(){throw a;},0);}},_extractResponse:function(e){var c=e.responseText;if(this.getExpectCSRFGuard())c=c.substring('for (;;);'.length);var d=this.getResponseType().toUpperCase();if(d=='TEXT'){return c;}else if(d=='JSON'||d=='JAVELIN'){return JX.JSON.parse(c);}else if(d=='XML'){var a;try{if(typeof DOMParser!='undefined'){var parser=new DOMParser();a=parser.parseFromString(c,"text/xml");}else{a=new ActiveXObject("Microsoft.XMLDOM");a.async=false;a.loadXML(e.responseText);}return a.documentElement;}catch(b){this._fail();return null;}}return null;},_fail:function(a){this._cleanup();this.invoke('error',a,this);this.invoke('finally');},_done:function(c){this._cleanup();if(c.onload)for(var a=0;a<c.onload.length;a++)(new Function(c.onload[a]))();var b;if(this.getRaw()){b=c;}else{b=c.payload;JX.Request._parseResponsePayload(b);}this.invoke('done',b,this);this.invoke('finally');},_cleanup:function(){this._finished=true;clearTimeout(this._timer);this._timer=null;if(this._transport&&this._transport.readyState!=4)this._transport.abort();},setData:function(a){this._data=null;this.addData(a);return this;},addData:function(a){if(!this._data)this._data=[];for(var b in a)this._data.push([b,a[b]]);return this;},setDataWithListOfPairs:function(a){this._data=a;return this;},_handleResponse:function(a){if(this.getResponseType().toUpperCase()=='JAVELIN'){if(a.error){this._fail(a.error);}else{JX.Stratcom.mergeData(this._block,a.javelin_metadata||{});this._done(a);JX.initBehaviors(a.javelin_behaviors||{});}}else{this._cleanup();this.invoke('done',a,this);this.invoke('finally');}}},statics:{ERROR_TIMEOUT:-9000,defaultDataSerializer:function(b){var e=[];for(var a=0;a<b.length;a++){var d=b[a];var c=encodeURIComponent(d[0]);var f=encodeURIComponent(d[1]);e.push(c+'='+f);}return e.join('&');},_parseResponsePayload:function(e,b){var f=JX.Request._parseResponsePayload;var d=(typeof b!=='undefined')?e[b]:e;if(JX.isArray(d)){for(var a=0;a<d.length;a++)f(d,a);}else if(d&&typeof d=='object')if(d.__html!=null){e[b]=JX.$H(d.__html);}else for(var c in d)f(d,c);}},properties:{URI:null,dataSerializer:null,method:'POST',file:null,raw:false,timeout:null,expectCSRFGuard:true,CORS:false,responseType:'JAVELIN'}});JX.$V=function(a,b){return new JX.Vector(a,b);};JX.install('Vector',{construct:function(a,b){if(typeof b=='undefined')return JX.Vector.getPos(a);this.x=(a===null)?null:parseFloat(a);this.y=(b===null)?null:parseFloat(b);},members:{x:null,y:null,setPos:function(a){a.style.left=(this.x===null)?'':(parseInt(this.x,10)+'px');a.style.top=(this.y===null)?'':(parseInt(this.y,10)+'px');return this;},setDim:function(a){a.style.width=(this.x===null)?'':(parseInt(this.x,10)+'px');a.style.height=(this.y===null)?'':(parseInt(this.y,10)+'px');return this;},add:function(a,b){if(a instanceof JX.Vector){b=a.y;a=a.x;}return new JX.Vector(this.x+parseFloat(a),this.y+parseFloat(b));}},statics:{_viewport:null,getPos:function(b){JX.Event&&(b instanceof JX.Event)&&(b=b.getRawEvent());if(('pageX' in b)||('clientX' in b)){var a=JX.Vector._viewport;return new JX.Vector(b.pageX||(b.clientX+a.scrollLeft),b.pageY||(b.clientY+a.scrollTop));}var c=0;var d=0;do{c+=b.offsetLeft;d+=b.offsetTop;b=b.offsetParent;}while(b&&b!=document.body);return new JX.Vector(c,d);},getDim:function(a){return new JX.Vector(a.offsetWidth,a.offsetHeight);},getScroll:function(){var a=document.body;var b=document.documentElement;return new JX.Vector(window.pageXOffset||a.scrollLeft||b.scrollLeft,window.pageYOffset||a.scrollTop||b.scrollTop);},getViewport:function(){var a=JX.Vector._viewport;return new JX.Vector(window.innerWidth||a.clientWidth||0,window.innerHeight||a.clientHeight||0);},getDocument:function(){var a=JX.Vector._viewport;return new JX.Vector(a.scrollWidth||0,a.scrollHeight||0);}},initialize:function(){JX.Vector._viewport=document.documentElement||document.body;}});JX.$=function(a){var b=document.getElementById(a);if(!b||(b.id!=a))JX.$E("JX.$('"+a+"') call matched no nodes.");return b;};JX.install('HTML',{construct:function(a){this._content=a;},members:{_content:null,getFragment:function(){var b=JX.$N('div');b.innerHTML=this._content;var a=document.createDocumentFragment();while(b.firstChild)a.appendChild(b.removeChild(b.firstChild));return a;}}});JX.$H=function(a){return new JX.HTML(a);};JX.$N=function(d,a,b){if(typeof b=='undefined'&&(typeof a!='object'||a instanceof JX.HTML)){b=a;a={};}var c=document.createElement(d);if(a.style){JX.copy(c.style,a.style);delete a.style;}if(a.sigil){JX.Stratcom.addSigil(c,a.sigil);delete a.sigil;}if(a.meta){JX.Stratcom.addData(c,a.meta);delete a.meta;}JX.copy(c,a);if(b)JX.DOM.setContent(c,b);return c;};JX.install('DOM',{statics:{_autoid:0,_metrics:{},setContent:function(b,a){while(b.firstChild)JX.DOM.remove(b.firstChild);JX.DOM.appendContent(b,a);},prependContent:function(b,a){this._insertContent(b,a,this._mechanismPrepend,true);},appendContent:function(b,a){this._insertContent(b,a,this._mechanismAppend);},_mechanismPrepend:function(b,a){b.insertBefore(a,b.firstChild);},_mechanismAppend:function(b,a){b.appendChild(a);},_insertContent:function(d,a,c,e){if(JX.isArray(a)){if(e)a=[].concat(a).reverse();for(var b=0;b<a.length;b++)JX.DOM._insertContent(d,a[b],c,e);}else{var f=typeof a;if(a instanceof JX.HTML){a=a.getFragment();}else if(f=='string'||f=='number')a=document.createTextNode(a);a&&c(d,a);}},remove:function(a){a.parentNode&&JX.DOM.replace(a,null);return a;},replace:function(b,d){var a;if(b.nextSibling){a=JX.bind(b.nextSibling,function(f,e){f.insertBefore(e,this);});}else a=this._mechanismAppend;var c=b.parentNode;c.removeChild(b);this._insertContent(c,d,a);return b;},convertFormToListOfPairs:function(c){var b=c.getElementsByTagName('*');var a=[];for(var d=0;d<b.length;++d){if(!b[d].name)continue;if(b[d].disabled)continue;var f=b[d].type;var e=b[d].tagName;if((f in {radio:1,checkbox:1}&&b[d].checked)||f in {text:1,hidden:1,password:1,email:1,tel:1,number:1}||e in {TEXTAREA:1,SELECT:1})a.push([b[d].name,b[d].value]);}return a;},convertFormToDictionary:function(b){var a={};var d=JX.DOM.convertFormToListOfPairs(b);for(var c=0;c<d.length;c++)a[d[c][0]]=d[c][1];return a;},isNode:function(a){return !!(a&&a.nodeName&&(a!==window));},isType:function(b,c){b=(''+(b.nodeName||'')).toUpperCase();c=JX.$AX(c);for(var a=0;a<c.length;++a)if(c[a].toUpperCase()==b)return true;return false;},listen:function(d,f,e,a){var b=['id:'+JX.DOM.uniqID(d)];e=JX.$AX(e||[]);if(!e.length){e=b;}else for(var c=0;c<e.length;c++)e[c]=b.concat(JX.$AX(e[c]));return JX.Stratcom.listen(f,e,a);},uniqID:function(a){if(!a.getAttribute('id'))a.setAttribute('id','autoid_'+(++JX.DOM._autoid));return a.getAttribute('id');},alterClass:function(d,b,a){var c=((' '+d.className+' ').indexOf(' '+b+' ')>-1);if(a&&!c){d.className+=' '+b;}else if(c&&!a)d.className=d.className.replace(new RegExp('(^|\\s)'+b+'(?:\\s|$)','g'),' ');},htmlize:function(a){return (''+a).replace(/&/g,'&amp;').replace(/"/g,'&quot;').replace(/</g,'&lt;').replace(/>/g,'&gt;');},show:function(){for(var a=0;a<arguments.length;++a)arguments[a].style.display='';},hide:function(){for(var a=0;a<arguments.length;++a)arguments[a].style.display='none';},textMetrics:function(c,e,f){if(!this._metrics[e]){var b=JX.$N('var',{className:e});this._metrics[e]=b;}var d=this._metrics[e];document.body.appendChild(d);d.style.width=f?(f+'px'):'';JX.DOM.setContent(d,JX.$H(JX.DOM.htmlize(c.value).replace(/\n/g,'<br />')));var a=JX.Vector.getDim(d);document.body.removeChild(d);return a;},scry:function(d,f,e){var b=d.getElementsByTagName(f);if(!e)return JX.$A(b);var c=[];for(var a=0;a<b.length;a++)if(JX.Stratcom.hasSigil(b[a],e))c.push(b[a]);return c;},find:function(b,d,c){var a=JX.DOM.scry(b,d,c);if(!a.length)JX.$E('JX.DOM.find(<node>, "'+d+'", "'+c+'"): '+'matched no nodes.');return a[0];},focus:function(b){try{b.focus();}catch(a){}},scrollTo:function(a){window.scrollTo(0,JX.$V(a).y);}}});JX.install('JSON',{statics:{parse:function(data){if(typeof data!='string')return null;if(window.JSON&&JSON.parse){var obj;try{obj=JSON.parse(data);}catch(e){}return obj||null;}return eval('('+data+')');},stringify:function(e){if(window.JSON&&JSON.stringify)return JSON.stringify(e);var c=[];if(e===null||e===true||e===false||typeof e=='number')return ''+e;if(e.push&&e.pop){var d;for(var a=0;a<e.length;a++){d=(typeof e[a]=='undefined')?null:e[a];c.push(JX.JSON.stringify(d));}return '['+c.join(',')+']';}if(typeof e=='string')return JX.JSON._esc(e);for(var b in e)c.push(JX.JSON._esc(b)+':'+JX.JSON.stringify(e[b]));return '{'+c.join(',')+'}';},_escexp:/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,_meta:{'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},_esc:function(a){JX.JSON._escexp.lastIndex=0;return JX.JSON._escexp.test(a)?'"'+a.replace(JX.JSON._escexp,JX.JSON._replace)+'"':'"'+a+'"';},_replace:function(a){if(a in JX.JSON._meta)return JX.JSON._meta[a];return '\\u'+(('0000'+a.charCodeAt(0).toString(16)).slice(-4));}}});JX.$U=function(a){return new JX.URI(a);};JX.install('URI',{statics:{_uriPattern:/(?:([^:\/?#]+):)?(?:\/\/([^:\/?#]*)(?::(\d*))?)?([^?#]*)(?:\?([^#]*))?(?:#(.*))?/,_queryPattern:/(?:^|&)([^&=]*)=?([^&]*)/g,_defaultQuerySerializer:function(c){var b=[];for(var a in c)if(c[a]!=null){var d=encodeURIComponent(c[a]);b.push(encodeURIComponent(a)+(d?'='+d:''));}return b.join('&');}},construct:function(f){this.setQueryParams({});if(f){var e=JX.URI._uriPattern.exec(f);this.setProtocol(e[1]||undefined);this.setDomain(e[2]||undefined);this.setPort(e[3]||undefined);var b=e[4];var c=e[5];this.setFragment(e[6]||undefined);this.setPath(b.charAt(0)=='/'?b:'/'+b);if(c){var d={};var a;while((a=JX.URI._queryPattern.exec(c))!=null)d[decodeURIComponent(a[1].replace(/\+/g,' '))]=decodeURIComponent(a[2].replace(/\+/g,' '));this.setQueryParams(d);}}},properties:{protocol:undefined,port:undefined,path:undefined,queryParams:undefined,fragment:undefined,querySerializer:undefined},members:{_domain:undefined,addQueryParams:function(a){JX.copy(this.getQueryParams(),a);return this;},setQueryParam:function(a,c){var b={};b[a]=c;return this.addQueryParams(b);},setDomain:function(a){var b=new RegExp('[\\x00-\\x2c\\x2f\\x3b-\\x40\\x5c\\x5e\\x60\\x7b-\\x7f'+'\\uFDD0-\\uFDEF\\uFFF0-\\uFFFF'+'\\u2047\\u2048\\uFE56\\uFE5F\\uFF03\\uFF0F\\uFF1F]');if(b.test(a))JX.$E('JX.URI.setDomain(...): invalid domain specified.');this._domain=a;return this;},getDomain:function(){return this._domain;},toString:function(){var a='';if(this.getProtocol())a+=this.getProtocol()+'://';a+=this.getDomain()||'';a+=this.getPath()||(a?'/':'');a+=this._getQueryString();if(this.getFragment())a+='#'+this.getFragment();return a;},_getQueryString:function(){var a=(this.getQuerySerializer()||JX.URI._defaultQuerySerializer)(this.getQueryParams());return a?'?'+a:'';},go:function(){var a=this.toString();if(JX.Stratcom.invoke('go',null,{uri:a}).getPrevented())return;if(!a)a=window.location.pathname+(window.location.query||'');window.location=a;}}});
View
66 pkg/typeahead.dev.js
@@ -122,6 +122,8 @@ JX.install('Typeahead', {
_placeholder : null,
_display : null,
_datasource : null,
+ _waitingListener : null,
+ _readyListener : null,
/**
* Activate your properly configured typeahead. It won't do anything until
@@ -154,19 +156,27 @@ JX.install('Typeahead', {
* draw from.
*/
setDatasource : function(datasource) {
- if (__DEV__) {
- if (this._datasource) {
- throw new Error(
- "JX.Typeahead.setDatasource(): " +
- "Typeahead already has a datasource.");
- }
+ if (this._datasource) {
+ this._datasource.unbindFromTypeahead();
+ this._waitingListener.remove();
+ this._readyListener.remove();
}
- datasource.listen('waiting', JX.bind(this, this.waitForResults));
- datasource.listen('resultsready', JX.bind(this, this.showResults));
+ this._waitingListener = datasource.listen(
+ 'waiting',
+ JX.bind(this, this.waitForResults)
+ );
+ this._readyListener = datasource.listen(
+ 'resultsready',
+ JX.bind(this, this.showResults)
+ );
datasource.bindToTypeahead(this);
this._datasource = datasource;
},
+ getDatasource : function() {
+ return this._datasource;
+ },
+
/**
* Override the <input /> selected in the constructor with some other input.
* This is primarily useful when building a control on top of the typeahead,
@@ -302,6 +312,7 @@ JX.install('Typeahead', {
*/
clear : function() {
this._control.value = '';
+ this._value = '';
this.hide();
},
@@ -630,10 +641,23 @@ JX.install('TypeaheadSource', {
_raw : null,
_lookup : null,
_excludeIDs : null,
+ _changeListener : null,
+ _startListener : null,
bindToTypeahead : function(typeahead) {
- typeahead.listen('change', JX.bind(this, this.didChange));
- typeahead.listen('start', JX.bind(this, this.didStart));
+ this._changeListener = typeahead.listen(
+ 'change',
+ JX.bind(this, this.didChange)
+ );
+ this._startListener = typeahead.listen(
+ 'start',
+ JX.bind(this, this.didStart)
+ );
+ },
+
+ unbindFromTypeahead : function() {
+ this._changeListener.remove();
+ this._startListener.remove();
},
didChange : function(value) {
@@ -664,10 +688,6 @@ JX.install('TypeaheadSource', {
addResult : function(obj) {
obj = (this.getTransformer() || this._defaultTransformer)(obj);
- if (obj && obj.id && this._excludeIDs[obj.id]) {
- return;
- }
-
if (obj.id in this._raw) {
// We're already aware of this result. This will happen if someone
// searches for "zeb" and then for "zebra" with a
@@ -699,6 +719,20 @@ JX.install('TypeaheadSource', {
return this;
},
+
+ /**
+ * Get the raw state of a result by its ID. A number of other events and
+ * mechanisms give a list of result IDs and limited additional data; if you
+ * need to act on the full result data you can look it up here.
+ *
+ * @param scalar Result ID.
+ * @return dict Corresponding raw result.
+ */
+ getResult : function(id) {
+ return this._raw[id];
+ },
+
+
matchResults : function(value) {
// This table keeps track of the number of tokens each potential match
@@ -758,7 +792,7 @@ JX.install('TypeaheadSource', {
var hits = [];
for (var k in match_count) {
- if (match_count[k] == t.length) {
+ if (match_count[k] == t.length && !this._excludeIDs[k]) {
hits.push(k);
}
}
@@ -1143,7 +1177,7 @@ JX.install('Tokenizer', {
if (this.shouldHideResultsOnChoose()) {
this._typeahead.hide();
}
- this._focus.value = '';
+ this._typeahead.clear();
this._redraw();
this.focus();
}
View
2  pkg/typeahead.min.js
@@ -1 +1 @@
-JX.install('Typeahead',{construct:function(b,a){this._hardpoint=b;this._control=a||JX.DOM.find(b,'input');this._root=JX.$N('div',{className:'jx-typeahead-results'});this._display=[];this._listener=JX.DOM.listen(this._control,['focus','blur','keypress','keydown','input'],null,JX.bind(this,this.handleEvent));JX.DOM.listen(this._root,['mouseover','mouseout'],null,JX.bind(this,this._onmouse));JX.DOM.listen(this._root,'mousedown','tag:a',JX.bind(this,function(c){if(!c.isRightButton())this._choose(c.getNode('tag:a'));}));},events:['choose','query','start','change','show'],properties:{allowNullSelection:true},members:{_root:null,_control:null,_hardpoint:null,_listener:null,_value:null,_stop:false,_focus:-1,_focused:false,_placeholderVisible:false,_placeholder:null,_display:null,_datasource:null,start:function(){this.invoke('start');this.updatePlaceholder();},setDatasource:function(a){a.listen('waiting',JX.bind(this,this.waitForResults));a.listen('resultsready',JX.bind(this,this.showResults));a.bindToTypeahead(this);this._datasource=a;},setInputNode:function(a){this._control=a;return this;},hide:function(){this._changeFocus(Number.NEGATIVE_INFINITY);this._display=[];this._moused=false;JX.DOM.hide(this._root);},showResults:function(d){var c={show:d};var b=this.invoke('show',c);this._display=c.show;if(this._display.length&&!b.getPrevented()){JX.DOM.setContent(this._root,this._display);this._changeFocus(Number.NEGATIVE_INFINITY);var a=JX.Vector.getDim(this._hardpoint);a.x=0;a.setPos(this._root);if(this._root.parentNode!==this._hardpoint)this._hardpoint.appendChild(this._root);JX.DOM.show(this._root);}else this.hide();},refresh:function(){if(this._stop)return;this._value=this._control.value;this.invoke('change',this._value);},waitForResults:function(){this.hide();},_onmouse:function(event){this._moused=(event.getType()=='mouseover');this._drawFocus();},_changeFocus:function(a){var b=Math.min(Math.max(-1,this._focus+a),this._display.length-1);if(!this.getAllowNullSelection())b=Math.max(0,b);if(this._focus>=0&&this._focus<this._display.length)JX.DOM.alterClass(this._display[this._focus],'focused',false);this._focus=b;this._drawFocus();return true;},_drawFocus:function(){var a=this._display[this._focus];if(a)JX.DOM.alterClass(a,'focused',!this._moused);},_choose:function(b){var a=this.invoke('choose',b);if(a.getPrevented())return;this._control.value=b.name;this.hide();},clear:function(){this._control.value='';this.hide();},disable:function(){this._control.blur();this._control.disabled=true;this._stop=true;},submit:function(){if(this._focus>=0&&this._display[this._focus]){this._choose(this._display[this._focus]);return true;}else{result=this.invoke('query',this._control.value);if(result.getPrevented())return true;}return false;},setValue:function(a){this._control.value=a;},getValue:function(){return this._control.value;},_update:function(event){if(event.getType()=='focus'){this._focused=true;this.updatePlaceholder();}var a=event.getSpecialKey();if(a&&event.getType()=='keydown')switch(a){case 'up':if(this._display.length&&this._changeFocus(-1))event.prevent();break;case 'down':if(this._display.length&&this._changeFocus(1))event.prevent();break;case 'return':if(this.submit()){event.prevent();return;}break;case 'esc':if(this._display.length&&this.getAllowNullSelection()){this.hide();event.prevent();}break;case 'tab':return;}setTimeout(JX.bind(this,function(){if(this._value==this._control.value)return;this.refresh();}),0);},handleEvent:function(a){if(this._stop||a.getPrevented())return;var b=a.getType();if(b=='blur'){this._focused=false;this.updatePlaceholder();this.hide();}else this._update(a);},removeListener:function(){if(this._listener)this._listener.remove();},setPlaceholder:function(a){this._placeholder=a;this.updatePlaceholder();return this;},updatePlaceholder:function(){if(this._placeholderVisible){if(this._focused||!this._placeholder){this._placeholderVisible=false;this._control.value='';}}else if(!this._focused)if(this._placeholder&&!this._control.value)this._placeholderVisible=true;if(this._placeholderVisible)this._control.value=this._placeholder;JX.DOM.alterClass(this._control,'jx-typeahead-placeholder',this._placeholderVisible);}}});JX.install('TypeaheadNormalizer',{statics:{normalize:function(a){return (''+a).toLocaleLowerCase().replace(/[\.,-\/#!$%\^&\*;:{}=\-_`~()]/g,'').replace(/ +/g,' ').replace(/^\s*|\s*$/g,'');}}});JX.install('TypeaheadSource',{construct:function(){this._raw={};this._lookup={};this.setNormalizer(JX.TypeaheadNormalizer.normalize);this._excludeIDs={};},events:['waiting','resultsready','complete'],properties:{normalizer:null,queryExtractor:null,transformer:null,maximumResultCount:5,sortHandler:null},members:{_raw:null,_lookup:null,_excludeIDs:null,bindToTypeahead:function(a){a.listen('change',JX.bind(this,this.didChange));a.listen('start',JX.bind(this,this.didStart));},didChange:function(a){return;},didStart:function(){return;},clearCache:function(){this._raw={};this._lookup={};},addExcludeID:function(a){if(a)this._excludeIDs[a]=true;},removeExcludeID:function(a){if(a)delete this._excludeIDs[a];},addResult:function(b){b=(this.getTransformer()||this._defaultTransformer)(b);if(b&&b.id&&this._excludeIDs[b.id])return;if(b.id in this._raw)return;this._raw[b.id]=b;var c=this.tokenize(b.tokenizable||b.name);for(var a=0;a<c.length;++a){this._lookup[c[a]]=this._lookup[c[a]]||[];this._lookup[c[a]].push(b.id);}},waitForResults:function(){this.invoke('waiting');return this;},matchResults:function(p){var g={};var h={};var j={};var n={};var m=this.getQueryExtractor();if(m)p=m(p);var o=this.tokenize(p);o.sort(function(q,r){return r.length-q.length;});for(var c=0;c<o.length;++c){if(o[c] in n){o.splice(c--,1);continue;}n[o[c]]=true;var a=o[c];for(var k in this._lookup)if(k.substr(0,a.length)===a){if(!(k in j)){j[k]=true;}else continue;var f=this._lookup[k];for(var d=0;d<f.length;++d){var i=f[d];if(!h[i])h[i]={};if(!(a in h[i])){h[i][a]=true;g[i]=(g[i]||0)+1;}}}}var b=[];for(var e in g)if(g[e]==o.length)b.push(e);this.sortHits(p,b);var l=this.renderNodes(p,b);this.invoke('resultsready',l);this.invoke('complete');},sortHits:function(f,c){var e=[];for(var d=0;d<c.length;d++)e.push(this._raw[c[d]]);var a=function(i,j){var g=i.sort||i.name;var h=j.sort||j.name;return g.localeCompare(h);};var b=this.getSortHandler()||function(i,h,g){h.sort(g);};b(f,e,a);c.splice(0,c.length);for(var d=0;d<e.length;d++)c.push(e[d].id);},renderNodes:function(e,a){var c=Math.min(this.getMaximumResultCount(),a.length);var d=[];for(var b=0;b<c;b++)d.push(this.createNode(this._raw[a[b]]));return d;},createNode:function(a){return JX.$N('a',{href:a.uri,name:a.name,rel:a.id,className:'jx-result'},a.display);},normalize:function(a){return this.getNormalizer()(a);},tokenize:function(a){a=this.normalize(a);if(!a.length)return [];return a.split(/\s/g);},_defaultTransformer:function(a){return {name:a[0],display:a[0],uri:a[1],id:a[2]};}}});JX.install('TypeaheadPreloadedSource',{extend:'TypeaheadSource',construct:function(a){JX.TypeaheadSource.call(this);this.uri=a;},members:{ready:false,uri:null,lastValue:null,didChange:function(a){if(this.ready){this.matchResults(a);}else{this.lastValue=a;this.waitForResults();}},didStart:function(){var a=new JX.Request(this.uri,JX.bind(this,this.ondata));a.setMethod('GET');a.send();},ondata:function(b){for(var a=0;a<b.length;++a)this.addResult(b[a]);if(this.lastValue!==null)this.matchResults(this.lastValue);this.ready=true;}}});JX.install('TypeaheadOnDemandSource',{extend:'TypeaheadSource',construct:function(a){JX.TypeaheadSource.call(this);this.uri=a;this.haveData={'':true};},properties:{queryDelay:125,auxiliaryData:{}},members:{uri:null,lastChange:null,haveData:null,didChange:function(a){this.lastChange=JX.now();a=this.normalize(a);if(this.haveData[a]){this.matchResults(a);}else{this.waitForResults();setTimeout(JX.bind(this,this.sendRequest,this.lastChange,a),this.getQueryDelay());}},sendRequest:function(c,b){if(c!=this.lastChange)return;var a=new JX.Request(this.uri,JX.bind(this,this.ondata,this.lastChange,b));a.setMethod('GET');a.setData(JX.copy(this.getAuxiliaryData(),{q:b}));a.send();},ondata:function(d,c,b){if(b)for(var a=0;a<b.length;a++)this.addResult(b[a]);this.haveData[c]=true;if(d!=this.lastChange)return;this.matchResults(c);}}});JX.install('Tokenizer',{construct:function(a){this._containerNode=a;},events:['change'],properties:{limit:null,nextInput:null},members:{_containerNode:null,_root:null,_focus:null,_orig:null,_typeahead:null,_tokenid:0,_tokens:null,_tokenMap:null,_initialValue:null,_seq:0,_lastvalue:null,_placeholder:null,start:function(){this._orig=JX.DOM.find(this._containerNode,'input','tokenizer-input');this._tokens=[];this._tokenMap={};var a=this.buildInput(this._orig.value);this._focus=a;var b=JX.DOM.scry(this._containerNode,'div','tokenizer-input-container');b=b[0]||this._containerNode;JX.DOM.listen(a,['click','focus','blur','keydown','keypress'],null,JX.bind(this,this.handleEvent));JX.DOM.listen(b,'click',null,JX.bind(this,function(e){if(e.getNode('remove')){this._remove(e.getNodeData('token').key);}else if(e.getTarget()==this._root)this.focus();}));var c=JX.$N('div');c.id=this._orig.id;JX.DOM.alterClass(c,'jx-tokenizer',true);c.style.cursor='text';this._root=c;c.appendChild(a);var d=this._typeahead;d.setInputNode(this._focus);d.start();setTimeout(JX.bind(this,function(){var e=this._orig.parentNode;JX.DOM.setContent(e,c);var g=this._initialValue||{};for(var f in g)this.addToken(f,g[f]);JX.DOM.appendContent(c,JX.$N('div',{style:{clear:'both'}}));this._redraw();}),0);},setInitialValue:function(a){this._initialValue=a;return this;},setTypeahead:function(a){a.setAllowNullSelection(false);a.removeListener();a.listen('choose',JX.bind(this,function(b){JX.Stratcom.context().prevent();if(this.addToken(b.rel,b.name)){if(this.shouldHideResultsOnChoose())this._typeahead.hide();this._focus.value='';this._redraw();this.focus();}}));a.listen('query',JX.bind(this,function(b){if(b.length)JX.Stratcom.context().prevent();}));this._typeahead=a;return this;},shouldHideResultsOnChoose:function(){return true;},handleEvent:function(a){this._typeahead.handleEvent(a);if(a.getPrevented())return;if(a.getType()=='click'){if(a.getTarget()==this._root){this.focus();a.prevent();return;}}else if(a.getType()=='keydown'){this._onkeydown(a);}else if(a.getType()=='blur'){this._focus.value='';this._redraw();this._typeahead.updatePlaceholder();}},refresh:function(){this._redraw(true);return this;},_redraw:function(b){if(JX.keys(this._tokenMap).length){this._typeahead.setPlaceholder(null);}else this._typeahead.setPlaceholder(this._placeholder);var a=this._focus;if(a.value===this._lastvalue&&!b)return;this._lastvalue=a.value;var d=this._root;var c=JX.DOM.textMetrics(this._focus,'jx-tokenizer-metrics');c.y=null;c.x+=24;c.setDim(a);a.value=a.value;},setPlaceholder:function(a){this._placeholder=a;return this;},addToken:function(b,e){if(b in this._tokenMap)return false;var a=this._focus;var c=this._root;var d=this.buildToken(b,e);this._tokenMap[b]={value:e,key:b,node:d};this._tokens.push(b);c.insertBefore(d,a);this.invoke('change',this);return true;},buildInput:function(a){return JX.$N('input',{className:'jx-tokenizer-input',type:'text',autocomplete:'off',value:a});},buildToken:function(b,d){var a=JX.$N('input',{type:'hidden',value:b,name:this._orig.name+'['+(this._seq++)+']'});var c=JX.$N('a',{className:'jx-tokenizer-x',sigil:'remove'},'\u00d7');return JX.$N('a',{className:'jx-tokenizer-token',sigil:'token',meta:{key:b}},[d,a,c]);},getTokens:function(){var b={};for(var a in this._tokenMap)b[a]=this._tokenMap[a].value;return b;},_onkeydown:function(b){var c=this._focus;var d=this._root;switch(b.getSpecialKey()){case 'tab':var a=this._typeahead.submit();if(this.getNextInput()){if(!a)this._focus.value='';setTimeout(JX.bind(this,function(){this.getNextInput().focus();}),0);}break;case 'delete':if(!this._focus.value.length){var e;while(e=this._tokens.pop())if(this._remove(e))break;}break;case 'return':break;default:if(this.getLimit()&&JX.keys(this._tokenMap).length==this.getLimit())b.prevent();setTimeout(JX.bind(this,this._redraw),0);break;}},_remove:function(a){if(!this._tokenMap[a])return false;JX.DOM.remove(this._tokenMap[a].node);delete this._tokenMap[a];this._redraw(true);this.focus();this.invoke('change',this);return true;},focus:function(){var a=this._focus;JX.DOM.show(a);setTimeout(function(){JX.DOM.focus(a);},0);}}});
+JX.install('Typeahead',{construct:function(b,a){this._hardpoint=b;this._control=a||JX.DOM.find(b,'input');this._root=JX.$N('div',{className:'jx-typeahead-results'});this._display=[];this._listener=JX.DOM.listen(this._control,['focus','blur','keypress','keydown','input'],null,JX.bind(this,this.handleEvent));JX.DOM.listen(this._root,['mouseover','mouseout'],null,JX.bind(this,this._onmouse));JX.DOM.listen(this._root,'mousedown','tag:a',JX.bind(this,function(c){if(!c.isRightButton())this._choose(c.getNode('tag:a'));}));},events:['choose','query','start','change','show'],properties:{allowNullSelection:true},members:{_root:null,_control:null,_hardpoint:null,_listener:null,_value:null,_stop:false,_focus:-1,_focused:false,_placeholderVisible:false,_placeholder:null,_display:null,_datasource:null,_waitingListener:null,_readyListener:null,start:function(){this.invoke('start');this.updatePlaceholder();},setDatasource:function(a){if(this._datasource){this._datasource.unbindFromTypeahead();this._waitingListener.remove();this._readyListener.remove();}this._waitingListener=a.listen('waiting',JX.bind(this,this.waitForResults));this._readyListener=a.listen('resultsready',JX.bind(this,this.showResults));a.bindToTypeahead(this);this._datasource=a;},getDatasource:function(){return this._datasource;},setInputNode:function(a){this._control=a;return this;},hide:function(){this._changeFocus(Number.NEGATIVE_INFINITY);this._display=[];this._moused=false;JX.DOM.hide(this._root);},showResults:function(d){var c={show:d};var b=this.invoke('show',c);this._display=c.show;if(this._display.length&&!b.getPrevented()){JX.DOM.setContent(this._root,this._display);this._changeFocus(Number.NEGATIVE_INFINITY);var a=JX.Vector.getDim(this._hardpoint);a.x=0;a.setPos(this._root);if(this._root.parentNode!==this._hardpoint)this._hardpoint.appendChild(this._root);JX.DOM.show(this._root);}else this.hide();},refresh:function(){if(this._stop)return;this._value=this._control.value;this.invoke('change',this._value);},waitForResults:function(){this.hide();},_onmouse:function(event){this._moused=(event.getType()=='mouseover');this._drawFocus();},_changeFocus:function(a){var b=Math.min(Math.max(-1,this._focus+a),this._display.length-1);if(!this.getAllowNullSelection())b=Math.max(0,b);if(this._focus>=0&&this._focus<this._display.length)JX.DOM.alterClass(this._display[this._focus],'focused',false);this._focus=b;this._drawFocus();return true;},_drawFocus:function(){var a=this._display[this._focus];if(a)JX.DOM.alterClass(a,'focused',!this._moused);},_choose:function(b){var a=this.invoke('choose',b);if(a.getPrevented())return;this._control.value=b.name;this.hide();},clear:function(){this._control.value='';this._value='';this.hide();},disable:function(){this._control.blur();this._control.disabled=true;this._stop=true;},submit:function(){if(this._focus>=0&&this._display[this._focus]){this._choose(this._display[this._focus]);return true;}else{result=this.invoke('query',this._control.value);if(result.getPrevented())return true;}return false;},setValue:function(a){this._control.value=a;},getValue:function(){return this._control.value;},_update:function(event){if(event.getType()=='focus'){this._focused=true;this.updatePlaceholder();}var a=event.getSpecialKey();if(a&&event.getType()=='keydown')switch(a){case 'up':if(this._display.length&&this._changeFocus(-1))event.prevent();break;case 'down':if(this._display.length&&this._changeFocus(1))event.prevent();break;case 'return':if(this.submit()){event.prevent();return;}break;case 'esc':if(this._display.length&&this.getAllowNullSelection()){this.hide();event.prevent();}break;case 'tab':return;}setTimeout(JX.bind(this,function(){if(this._value==this._control.value)return;this.refresh();}),0);},handleEvent:function(a){if(this._stop||a.getPrevented())return;var b=a.getType();if(b=='blur'){this._focused=false;this.updatePlaceholder();this.hide();}else this._update(a);},removeListener:function(){if(this._listener)this._listener.remove();},setPlaceholder:function(a){this._placeholder=a;this.updatePlaceholder();return this;},updatePlaceholder:function(){if(this._placeholderVisible){if(this._focused||!this._placeholder){this._placeholderVisible=false;this._control.value='';}}else if(!this._focused)if(this._placeholder&&!this._control.value)this._placeholderVisible=true;if(this._placeholderVisible)this._control.value=this._placeholder;JX.DOM.alterClass(this._control,'jx-typeahead-placeholder',this._placeholderVisible);}}});JX.install('TypeaheadNormalizer',{statics:{normalize:function(a){return (''+a).toLocaleLowerCase().replace(/[\.,-\/#!$%\^&\*;:{}=\-_`~()]/g,'').replace(/ +/g,' ').replace(/^\s*|\s*$/g,'');}}});JX.install('TypeaheadSource',{construct:function(){this._raw={};this._lookup={};this.setNormalizer(JX.TypeaheadNormalizer.normalize);this._excludeIDs={};},events:['waiting','resultsready','complete'],properties:{normalizer:null,queryExtractor:null,transformer:null,maximumResultCount:5,sortHandler:null},members:{_raw:null,_lookup:null,_excludeIDs:null,_changeListener:null,_startListener:null,bindToTypeahead:function(a){this._changeListener=a.listen('change',JX.bind(this,this.didChange));this._startListener=a.listen('start',JX.bind(this,this.didStart));},unbindFromTypeahead:function(){this._changeListener.remove();this._startListener.remove();},didChange:function(a){return;},didStart:function(){return;},clearCache:function(){this._raw={};this._lookup={};},addExcludeID:function(a){if(a)this._excludeIDs[a]=true;},removeExcludeID:function(a){if(a)delete this._excludeIDs[a];},addResult:function(b){b=(this.getTransformer()||this._defaultTransformer)(b);if(b.id in this._raw)return;this._raw[b.id]=b;var c=this.tokenize(b.tokenizable||b.name);for(var a=0;a<c.length;++a){this._lookup[c[a]]=this._lookup[c[a]]||[];this._lookup[c[a]].push(b.id);}},waitForResults:function(){this.invoke('waiting');return this;},getResult:function(a){return this._raw[a];},matchResults:function(p){var g={};var h={};var j={};var n={};var m=this.getQueryExtractor();if(m)p=m(p);var o=this.tokenize(p);o.sort(function(q,r){return r.length-q.length;});for(var c=0;c<o.length;++c){if(o[c] in n){o.splice(c--,1);continue;}n[o[c]]=true;var a=o[c];for(var k in this._lookup)if(k.substr(0,a.length)===a){if(!(k in j)){j[k]=true;}else continue;var f=this._lookup[k];for(var d=0;d<f.length;++d){var i=f[d];if(!h[i])h[i]={};if(!(a in h[i])){h[i][a]=true;g[i]=(g[i]||0)+1;}}}}var b=[];for(var e in g)if(g[e]==o.length&&!this._excludeIDs[e])b.push(e);this.sortHits(p,b);var l=this.renderNodes(p,b);this.invoke('resultsready',l);this.invoke('complete');},sortHits:function(f,c){var e=[];for(var d=0;d<c.length;d++)e.push(this._raw[c[d]]);var a=function(i,j){var g=i.sort||i.name;var h=j.sort||j.name;return g.localeCompare(h);};var b=this.getSortHandler()||function(i,h,g){h.sort(g);};b(f,e,a);c.splice(0,c.length);for(var d=0;d<e.length;d++)c.push(e[d].id);},renderNodes:function(e,a){var c=Math.min(this.getMaximumResultCount(),a.length);var d=[];for(var b=0;b<c;b++)d.push(this.createNode(this._raw[a[b]]));return d;},createNode:function(a){return JX.$N('a',{href:a.uri,name:a.name,rel:a.id,className:'jx-result'},a.display);},normalize:function(a){return this.getNormalizer()(a);},tokenize:function(a){a=this.normalize(a);if(!a.length)return [];return a.split(/\s/g);},_defaultTransformer:function(a){return {name:a[0],display:a[0],uri:a[1],id:a[2]};}}});JX.install('TypeaheadPreloadedSource',{extend:'TypeaheadSource',construct:function(a){JX.TypeaheadSource.call(this);this.uri=a;},members:{ready:false,uri:null,lastValue:null,didChange:function(a){if(this.ready){this.matchResults(a);}else{this.lastValue=a;this.waitForResults();}},didStart:function(){var a=new JX.Request(this.uri,JX.bind(this,this.ondata));a.setMethod('GET');a.send();},ondata:function(b){for(var a=0;a<b.length;++a)this.addResult(b[a]);if(this.lastValue!==null)this.matchResults(this.lastValue);this.ready=true;}}});JX.install('TypeaheadOnDemandSource',{extend:'TypeaheadSource',construct:function(a){JX.TypeaheadSource.call(this);this.uri=a;this.haveData={'':true};},properties:{queryDelay:125,auxiliaryData:{}},members:{uri:null,lastChange:null,haveData:null,didChange:function(a){this.lastChange=JX.now();a=this.normalize(a);if(this.haveData[a]){this.matchResults(a);}else{this.waitForResults();setTimeout(JX.bind(this,this.sendRequest,this.lastChange,a),this.getQueryDelay());}},sendRequest:function(c,b){if(c!=this.lastChange)return;var a=new JX.Request(this.uri,JX.bind(this,this.ondata,this.lastChange,b));a.setMethod('GET');a.setData(JX.copy(this.getAuxiliaryData(),{q:b}));a.send();},ondata:function(d,c,b){if(b)for(var a=0;a<b.length;a++)this.addResult(b[a]);this.haveData[c]=true;if(d!=this.lastChange)return;this.matchResults(c);}}});JX.install('Tokenizer',{construct:function(a){this._containerNode=a;},events:['change'],properties:{limit:null,nextInput:null},members:{_containerNode:null,_root:null,_focus:null,_orig:null,_typeahead:null,_tokenid:0,_tokens:null,_tokenMap:null,_initialValue:null,_seq:0,_lastvalue:null,_placeholder:null,start:function(){this._orig=JX.DOM.find(this._containerNode,'input','tokenizer-input');this._tokens=[];this._tokenMap={};var a=this.buildInput(this._orig.value);this._focus=a;var b=JX.DOM.scry(this._containerNode,'div','tokenizer-input-container');b=b[0]||this._containerNode;JX.DOM.listen(a,['click','focus','blur','keydown','keypress'],null,JX.bind(this,this.handleEvent));JX.DOM.listen(b,'click',null,JX.bind(this,function(e){if(e.getNode('remove')){this._remove(e.getNodeData('token').key);}else if(e.getTarget()==this._root)this.focus();}));var c=JX.$N('div');c.id=this._orig.id;JX.DOM.alterClass(c,'jx-tokenizer',true);c.style.cursor='text';this._root=c;c.appendChild(a);var d=this._typeahead;d.setInputNode(this._focus);d.start();setTimeout(JX.bind(this,function(){var e=this._orig.parentNode;JX.DOM.setContent(e,c);var g=this._initialValue||{};for(var f in g)this.addToken(f,g[f]);JX.DOM.appendContent(c,JX.$N('div',{style:{clear:'both'}}));this._redraw();}),0);},setInitialValue:function(a){this._initialValue=a;return this;},setTypeahead:function(a){a.setAllowNullSelection(false);a.removeListener();a.listen('choose',JX.bind(this,function(b){JX.Stratcom.context().prevent();if(this.addToken(b.rel,b.name)){if(this.shouldHideResultsOnChoose())this._typeahead.hide();this._typeahead.clear();this._redraw();this.focus();}}));a.listen('query',JX.bind(this,function(b){if(b.length)JX.Stratcom.context().prevent();}));this._typeahead=a;return this;},shouldHideResultsOnChoose:function(){return true;},handleEvent:function(a){this._typeahead.handleEvent(a);if(a.getPrevented())return;if(a.getType()=='click'){if(a.getTarget()==this._root){this.focus();a.prevent();return;}}else if(a.getType()=='keydown'){this._onkeydown(a);}else if(a.getType()=='blur'){this._focus.value='';this._redraw();this._typeahead.updatePlaceholder();}},refresh:function(){this._redraw(true);return this;},_redraw:function(b){if(JX.keys(this._tokenMap).length){this._typeahead.setPlaceholder(null);}else this._typeahead.setPlaceholder(this._placeholder);var a=this._focus;if(a.value===this._lastvalue&&!b)return;this._lastvalue=a.value;var d=this._root;var c=JX.DOM.textMetrics(this._focus,'jx-tokenizer-metrics');c.y=null;c.x+=24;c.setDim(a);a.value=a.value;},setPlaceholder:function(a){this._placeholder=a;return this;},addToken:function(b,e){if(b in this._tokenMap)return false;var a=this._focus;var c=this._root;var d=this.buildToken(b,e);this._tokenMap[b]={value:e,key:b,node:d};this._tokens.push(b);c.insertBefore(d,a);this.invoke('change',this);return true;},buildInput:function(a){return JX.$N('input',{className:'jx-tokenizer-input',type:'text',autocomplete:'off',value:a});},buildToken:function(b,d){var a=JX.$N('input',{type:'hidden',value:b,name:this._orig.name+'['+(this._seq++)+']'});var c=JX.$N('a',{className:'jx-tokenizer-x',sigil:'remove'},'\u00d7');return JX.$N('a',{className:'jx-tokenizer-token',sigil:'token',meta:{key:b}},[d,a,c]);},getTokens:function(){var b={};for(var a in this._tokenMap)b[a]=this._tokenMap[a].value;return b;},_onkeydown:function(b){var c=this._focus;var d=this._root;switch(b.getSpecialKey()){case 'tab':var a=this._typeahead.submit();if(this.getNextInput()){if(!a)this._focus.value='';setTimeout(JX.bind(this,function(){this.getNextInput().focus();}),0);}break;case 'delete':if(!this._focus.value.length){var e;while(e=this._tokens.pop())if(this._remove(e))break;}break;case 'return':break;default:if(this.getLimit()&&JX.keys(this._tokenMap).length==this.getLimit())b.prevent();setTimeout(JX.bind(this,this._redraw),0);break;}},_remove:function(a){if(!this._tokenMap[a])return false;JX.DOM.remove(this._tokenMap[a].node);delete this._tokenMap[a];this._redraw(true);this.focus();this.invoke('change',this);return true;},focus:function(){var a=this._focus;JX.DOM.show(a);setTimeout(function(){JX.DOM.focus(a);},0);}}});
View
2  src/lib/Resource.js
@@ -81,7 +81,7 @@ JX.install('Resource', {
script.onreadystatechange = function() {
var state = this.readyState;
if (state == 'complete' || state == 'loaded') {
- callback();
+ load_callback();
}
};
document.getElementsByTagName('head')[0].appendChild(script);
Please sign in to comment.
Something went wrong with that request. Please try again.