17659 lines
798 KiB
JavaScript
17659 lines
798 KiB
JavaScript
/*! jQuery v1.7.2 jquery.com | jquery.org/license */
|
|
|
|
(function(a,b){function cy(a){return f.isWindow(a)?a:a.nodeType===9?a.defaultView||a.parentWindow:!1}function cu(a){if(!cj[a]){var b=c.body,d=f("<"+a+">").appendTo(b),e=d.css("display");d.remove();if(e==="none"||e===""){ck||(ck=c.createElement("iframe"),ck.frameBorder=ck.width=ck.height=0),b.appendChild(ck);if(!cl||!ck.createElement)cl=(ck.contentWindow||ck.contentDocument).document,cl.write((f.support.boxModel?"<!doctype html>":"")+"<html><body>"),cl.close();d=cl.createElement(a),cl.body.appendChild(d),e=f.css(d,"display"),b.removeChild(ck)}cj[a]=e}return cj[a]}function ct(a,b){var c={};f.each(cp.concat.apply([],cp.slice(0,b)),function(){c[this]=a});return c}function cs(){cq=b}function cr(){setTimeout(cs,0);return cq=f.now()}function ci(){try{return new a.ActiveXObject("Microsoft.XMLHTTP")}catch(b){}}function ch(){try{return new a.XMLHttpRequest}catch(b){}}function cb(a,c){a.dataFilter&&(c=a.dataFilter(c,a.dataType));var d=a.dataTypes,e={},g,h,i=d.length,j,k=d[0],l,m,n,o,p;for(g=1;g<i;g++){if(g===1)for(h in a.converters)typeof h=="string"&&(e[h.toLowerCase()]=a.converters[h]);l=k,k=d[g];if(k==="*")k=l;else if(l!=="*"&&l!==k){m=l+" "+k,n=e[m]||e["* "+k];if(!n){p=b;for(o in e){j=o.split(" ");if(j[0]===l||j[0]==="*"){p=e[j[1]+" "+k];if(p){o=e[o],o===!0?n=p:p===!0&&(n=o);break}}}}!n&&!p&&f.error("No conversion from "+m.replace(" "," to ")),n!==!0&&(c=n?n(c):p(o(c)))}}return c}function ca(a,c,d){var e=a.contents,f=a.dataTypes,g=a.responseFields,h,i,j,k;for(i in g)i in d&&(c[g[i]]=d[i]);while(f[0]==="*")f.shift(),h===b&&(h=a.mimeType||c.getResponseHeader("content-type"));if(h)for(i in e)if(e[i]&&e[i].test(h)){f.unshift(i);break}if(f[0]in d)j=f[0];else{for(i in d){if(!f[0]||a.converters[i+" "+f[0]]){j=i;break}k||(k=i)}j=j||k}if(j){j!==f[0]&&f.unshift(j);return d[j]}}function b_(a,b,c,d){if(f.isArray(b))f.each(b,function(b,e){c||bD.test(a)?d(a,e):b_(a+"["+(typeof e=="object"?b:"")+"]",e,c,d)});else if(!c&&f.type(b)==="object")for(var e in b)b_(a+"["+e+"]",b[e],c,d);else d(a,b)}function b$(a,c){var d,e,g=f.ajaxSettings.flatOptions||{};for(d in c)c[d]!==b&&((g[d]?a:e||(e={}))[d]=c[d]);e&&f.extend(!0,a,e)}function bZ(a,c,d,e,f,g){f=f||c.dataTypes[0],g=g||{},g[f]=!0;var h=a[f],i=0,j=h?h.length:0,k=a===bS,l;for(;i<j&&(k||!l);i++)l=h[i](c,d,e),typeof l=="string"&&(!k||g[l]?l=b:(c.dataTypes.unshift(l),l=bZ(a,c,d,e,l,g)));(k||!l)&&!g["*"]&&(l=bZ(a,c,d,e,"*",g));return l}function bY(a){return function(b,c){typeof b!="string"&&(c=b,b="*");if(f.isFunction(c)){var d=b.toLowerCase().split(bO),e=0,g=d.length,h,i,j;for(;e<g;e++)h=d[e],j=/^\+/.test(h),j&&(h=h.substr(1)||"*"),i=a[h]=a[h]||[],i[j?"unshift":"push"](c)}}}function bB(a,b,c){var d=b==="width"?a.offsetWidth:a.offsetHeight,e=b==="width"?1:0,g=4;if(d>0){if(c!=="border")for(;e<g;e+=2)c||(d-=parseFloat(f.css(a,"padding"+bx[e]))||0),c==="margin"?d+=parseFloat(f.css(a,c+bx[e]))||0:d-=parseFloat(f.css(a,"border"+bx[e]+"Width"))||0;return d+"px"}d=by(a,b);if(d<0||d==null)d=a.style[b];if(bt.test(d))return d;d=parseFloat(d)||0;if(c)for(;e<g;e+=2)d+=parseFloat(f.css(a,"padding"+bx[e]))||0,c!=="padding"&&(d+=parseFloat(f.css(a,"border"+bx[e]+"Width"))||0),c==="margin"&&(d+=parseFloat(f.css(a,c+bx[e]))||0);return d+"px"}function bo(a){var b=c.createElement("div");bh.appendChild(b),b.innerHTML=a.outerHTML;return b.firstChild}function bn(a){var b=(a.nodeName||"").toLowerCase();b==="input"?bm(a):b!=="script"&&typeof a.getElementsByTagName!="undefined"&&f.grep(a.getElementsByTagName("input"),bm)}function bm(a){if(a.type==="checkbox"||a.type==="radio")a.defaultChecked=a.checked}function bl(a){return typeof a.getElementsByTagName!="undefined"?a.getElementsByTagName("*"):typeof a.querySelectorAll!="undefined"?a.querySelectorAll("*"):[]}function bk(a,b){var c;b.nodeType===1&&(b.clearAttributes&&b.clearAttributes(),b.mergeAttributes&&b.mergeAttributes(a),c=b.nodeName.toLowerCase(),c==="object"?b.outerHTML=a.outerHTML:c!=="input"||a.type!=="checkbox"&&a.type!=="radio"?c==="option"?b.selected=a.defaultSelected:c==="input"||c==="textarea"?b.defaultValue=a.defaultValue:c==="script"&&b.text!==a.text&&(b.text=a.text):(a.checked&&(b.defaultChecked=b.checked=a.checked),b.value!==a.value&&(b.value=a.value)),b.removeAttribute(f.expando),b.removeAttribute("_submit_attached"),b.removeAttribute("_change_attached"))}function bj(a,b){if(b.nodeType===1&&!!f.hasData(a)){var c,d,e,g=f._data(a),h=f._data(b,g),i=g.events;if(i){delete h.handle,h.events={};for(c in i)for(d=0,e=i[c].length;d<e;d++)f.event.add(b,c,i[c][d])}h.data&&(h.data=f.extend({},h.data))}}function bi(a,b){return f.nodeName(a,"table")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function U(a){var b=V.split("|"),c=a.createDocumentFragment();if(c.createElement)while(b.length)c.createElement(b.pop());return c}function T(a,b,c){b=b||0;if(f.isFunction(b))return f.grep(a,function(a,d){var e=!!b.call(a,d,a);return e===c});if(b.nodeType)return f.grep(a,function(a,d){return a===b===c});if(typeof b=="string"){var d=f.grep(a,function(a){return a.nodeType===1});if(O.test(b))return f.filter(b,d,!c);b=f.filter(b,d)}return f.grep(a,function(a,d){return f.inArray(a,b)>=0===c})}function S(a){return!a||!a.parentNode||a.parentNode.nodeType===11}function K(){return!0}function J(){return!1}function n(a,b,c){var d=b+"defer",e=b+"queue",g=b+"mark",h=f._data(a,d);h&&(c==="queue"||!f._data(a,e))&&(c==="mark"||!f._data(a,g))&&setTimeout(function(){!f._data(a,e)&&!f._data(a,g)&&(f.removeData(a,d,!0),h.fire())},0)}function m(a){for(var b in a){if(b==="data"&&f.isEmptyObject(a[b]))continue;if(b!=="toJSON")return!1}return!0}function l(a,c,d){if(d===b&&a.nodeType===1){var e="data-"+c.replace(k,"-$1").toLowerCase();d=a.getAttribute(e);if(typeof d=="string"){try{d=d==="true"?!0:d==="false"?!1:d==="null"?null:f.isNumeric(d)?+d:j.test(d)?f.parseJSON(d):d}catch(g){}f.data(a,c,d)}else d=b}return d}function h(a){var b=g[a]={},c,d;a=a.split(/\s+/);for(c=0,d=a.length;c<d;c++)b[a[c]]=!0;return b}var c=a.document,d=a.navigator,e=a.location,f=function(){function J(){if(!e.isReady){try{c.documentElement.doScroll("left")}catch(a){setTimeout(J,1);return}e.ready()}}var e=function(a,b){return new e.fn.init(a,b,h)},f=a.jQuery,g=a.$,h,i=/^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,j=/\S/,k=/^\s+/,l=/\s+$/,m=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,n=/^[\],:{}\s]*$/,o=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,p=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,q=/(?:^|:|,)(?:\s*\[)+/g,r=/(webkit)[ \/]([\w.]+)/,s=/(opera)(?:.*version)?[ \/]([\w.]+)/,t=/(msie) ([\w.]+)/,u=/(mozilla)(?:.*? rv:([\w.]+))?/,v=/-([a-z]|[0-9])/ig,w=/^-ms-/,x=function(a,b){return(b+"").toUpperCase()},y=d.userAgent,z,A,B,C=Object.prototype.toString,D=Object.prototype.hasOwnProperty,E=Array.prototype.push,F=Array.prototype.slice,G=String.prototype.trim,H=Array.prototype.indexOf,I={};e.fn=e.prototype={constructor:e,init:function(a,d,f){var g,h,j,k;if(!a)return this;if(a.nodeType){this.context=this[0]=a,this.length=1;return this}if(a==="body"&&!d&&c.body){this.context=c,this[0]=c.body,this.selector=a,this.length=1;return this}if(typeof a=="string"){a.charAt(0)!=="<"||a.charAt(a.length-1)!==">"||a.length<3?g=i.exec(a):g=[null,a,null];if(g&&(g[1]||!d)){if(g[1]){d=d instanceof e?d[0]:d,k=d?d.ownerDocument||d:c,j=m.exec(a),j?e.isPlainObject(d)?(a=[c.createElement(j[1])],e.fn.attr.call(a,d,!0)):a=[k.createElement(j[1])]:(j=e.buildFragment([g[1]],[k]),a=(j.cacheable?e.clone(j.fragment):j.fragment).childNodes);return e.merge(this,a)}h=c.getElementById(g[2]);if(h&&h.parentNode){if(h.id!==g[2])return f.find(a);this.length=1,this[0]=h}this.context=c,this.selector=a;return this}return!d||d.jquery?(d||f).find(a):this.constructor(d).find(a)}if(e.isFunction(a))return f.ready(a);a.selector!==b&&(this.selector=a.selector,this.context=a.context);return e.makeArray(a,this)},selector:"",jquery:"1.7.2",length:0,size:function(){return this.length},toArray:function(){return F.call(this,0)},get:function(a){return a==null?this.toArray():a<0?this[this.length+a]:this[a]},pushStack:function(a,b,c){var d=this.constructor();e.isArray(a)?E.apply(d,a):e.merge(d,a),d.prevObject=this,d.context=this.context,b==="find"?d.selector=this.selector+(this.selector?" ":"")+c:b&&(d.selector=this.selector+"."+b+"("+c+")");return d},each:function(a,b){return e.each(this,a,b)},ready:function(a){e.bindReady(),A.add(a);return this},eq:function(a){a=+a;return a===-1?this.slice(a):this.slice(a,a+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(F.apply(this,arguments),"slice",F.call(arguments).join(","))},map:function(a){return this.pushStack(e.map(this,function(b,c){return a.call(b,c,b)}))},end:function(){return this.prevObject||this.constructor(null)},push:E,sort:[].sort,splice:[].splice},e.fn.init.prototype=e.fn,e.extend=e.fn.extend=function(){var a,c,d,f,g,h,i=arguments[0]||{},j=1,k=arguments.length,l=!1;typeof i=="boolean"&&(l=i,i=arguments[1]||{},j=2),typeof i!="object"&&!e.isFunction(i)&&(i={}),k===j&&(i=this,--j);for(;j<k;j++)if((a=arguments[j])!=null)for(c in a){d=i[c],f=a[c];if(i===f)continue;l&&f&&(e.isPlainObject(f)||(g=e.isArray(f)))?(g?(g=!1,h=d&&e.isArray(d)?d:[]):h=d&&e.isPlainObject(d)?d:{},i[c]=e.extend(l,h,f)):f!==b&&(i[c]=f)}return i},e.extend({noConflict:function(b){a.$===e&&(a.$=g),b&&a.jQuery===e&&(a.jQuery=f);return e},isReady:!1,readyWait:1,holdReady:function(a){a?e.readyWait++:e.ready(!0)},ready:function(a){if(a===!0&&!--e.readyWait||a!==!0&&!e.isReady){if(!c.body)return setTimeout(e.ready,1);e.isReady=!0;if(a!==!0&&--e.readyWait>0)return;A.fireWith(c,[e]),e.fn.trigger&&e(c).trigger("ready").off("ready")}},bindReady:function(){if(!A){A=e.Callbacks("once memory");if(c.readyState==="complete")return setTimeout(e.ready,1);if(c.addEventListener)c.addEventListener("DOMContentLoaded",B,!1),a.addEventListener("load",e.ready,!1);else if(c.attachEvent){c.attachEvent("onreadystatechange",B),a.attachEvent("onload",e.ready);var b=!1;try{b=a.frameElement==null}catch(d){}c.documentElement.doScroll&&b&&J()}}},isFunction:function(a){return e.type(a)==="function"},isArray:Array.isArray||function(a){return e.type(a)==="array"},isWindow:function(a){return a!=null&&a==a.window},isNumeric:function(a){return!isNaN(parseFloat(a))&&isFinite(a)},type:function(a){return a==null?String(a):I[C.call(a)]||"object"},isPlainObject:function(a){if(!a||e.type(a)!=="object"||a.nodeType||e.isWindow(a))return!1;try{if(a.constructor&&!D.call(a,"constructor")&&!D.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(c){return!1}var d;for(d in a);return d===b||D.call(a,d)},isEmptyObject:function(a){for(var b in a)return!1;return!0},error:function(a){throw new Error(a)},parseJSON:function(b){if(typeof b!="string"||!b)return null;b=e.trim(b);if(a.JSON&&a.JSON.parse)return a.JSON.parse(b);if(n.test(b.replace(o,"@").replace(p,"]").replace(q,"")))return(new Function("return "+b))();e.error("Invalid JSON: "+b)},parseXML:function(c){if(typeof c!="string"||!c)return null;var d,f;try{a.DOMParser?(f=new DOMParser,d=f.parseFromString(c,"text/xml")):(d=new ActiveXObject("Microsoft.XMLDOM"),d.async="false",d.loadXML(c))}catch(g){d=b}(!d||!d.documentElement||d.getElementsByTagName("parsererror").length)&&e.error("Invalid XML: "+c);return d},noop:function(){},globalEval:function(b){b&&j.test(b)&&(a.execScript||function(b){a.eval.call(a,b)})(b)},camelCase:function(a){return a.replace(w,"ms-").replace(v,x)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toUpperCase()===b.toUpperCase()},each:function(a,c,d){var f,g=0,h=a.length,i=h===b||e.isFunction(a);if(d){if(i){for(f in a)if(c.apply(a[f],d)===!1)break}else for(;g<h;)if(c.apply(a[g++],d)===!1)break}else if(i){for(f in a)if(c.call(a[f],f,a[f])===!1)break}else for(;g<h;)if(c.call(a[g],g,a[g++])===!1)break;return a},trim:G?function(a){return a==null?"":G.call(a)}:function(a){return a==null?"":(a+"").replace(k,"").replace(l,"")},makeArray:function(a,b){var c=b||[];if(a!=null){var d=e.type(a);a.length==null||d==="string"||d==="function"||d==="regexp"||e.isWindow(a)?E.call(c,a):e.merge(c,a)}return c},inArray:function(a,b,c){var d;if(b){if(H)return H.call(b,a,c);d=b.length,c=c?c<0?Math.max(0,d+c):c:0;for(;c<d;c++)if(c in b&&b[c]===a)return c}return-1},merge:function(a,c){var d=a.length,e=0;if(typeof c.length=="number")for(var f=c.length;e<f;e++)a[d++]=c[e];else while(c[e]!==b)a[d++]=c[e++];a.length=d;return a},grep:function(a,b,c){var d=[],e;c=!!c;for(var f=0,g=a.length;f<g;f++)e=!!b(a[f],f),c!==e&&d.push(a[f]);return d},map:function(a,c,d){var f,g,h=[],i=0,j=a.length,k=a instanceof e||j!==b&&typeof j=="number"&&(j>0&&a[0]&&a[j-1]||j===0||e.isArray(a));if(k)for(;i<j;i++)f=c(a[i],i,d),f!=null&&(h[h.length]=f);else for(g in a)f=c(a[g],g,d),f!=null&&(h[h.length]=f);return h.concat.apply([],h)},guid:1,proxy:function(a,c){if(typeof c=="string"){var d=a[c];c=a,a=d}if(!e.isFunction(a))return b;var f=F.call(arguments,2),g=function(){return a.apply(c,f.concat(F.call(arguments)))};g.guid=a.guid=a.guid||g.guid||e.guid++;return g},access:function(a,c,d,f,g,h,i){var j,k=d==null,l=0,m=a.length;if(d&&typeof d=="object"){for(l in d)e.access(a,c,l,d[l],1,h,f);g=1}else if(f!==b){j=i===b&&e.isFunction(f),k&&(j?(j=c,c=function(a,b,c){return j.call(e(a),c)}):(c.call(a,f),c=null));if(c)for(;l<m;l++)c(a[l],d,j?f.call(a[l],l,c(a[l],d)):f,i);g=1}return g?a:k?c.call(a):m?c(a[0],d):h},now:function(){return(new Date).getTime()},uaMatch:function(a){a=a.toLowerCase();var b=r.exec(a)||s.exec(a)||t.exec(a)||a.indexOf("compatible")<0&&u.exec(a)||[];return{browser:b[1]||"",version:b[2]||"0"}},sub:function(){function a(b,c){return new a.fn.init(b,c)}e.extend(!0,a,this),a.superclass=this,a.fn=a.prototype=this(),a.fn.constructor=a,a.sub=this.sub,a.fn.init=function(d,f){f&&f instanceof e&&!(f instanceof a)&&(f=a(f));return e.fn.init.call(this,d,f,b)},a.fn.init.prototype=a.fn;var b=a(c);return a},browser:{}}),e.each("Boolean Number String Function Array Date RegExp Object".split(" "),function(a,b){I["[object "+b+"]"]=b.toLowerCase()}),z=e.uaMatch(y),z.browser&&(e.browser[z.browser]=!0,e.browser.version=z.version),e.browser.webkit&&(e.browser.safari=!0),j.test("Â ")&&(k=/^[\s\xA0]+/,l=/[\s\xA0]+$/),h=e(c),c.addEventListener?B=function(){c.removeEventListener("DOMContentLoaded",B,!1),e.ready()}:c.attachEvent&&(B=function(){c.readyState==="complete"&&(c.detachEvent("onreadystatechange",B),e.ready())});return e}(),g={};f.Callbacks=function(a){a=a?g[a]||h(a):{};var c=[],d=[],e,i,j,k,l,m,n=function(b){var d,e,g,h,i;for(d=0,e=b.length;d<e;d++)g=b[d],h=f.type(g),h==="array"?n(g):h==="function"&&(!a.unique||!p.has(g))&&c.push(g)},o=function(b,f){f=f||[],e=!a.memory||[b,f],i=!0,j=!0,m=k||0,k=0,l=c.length;for(;c&&m<l;m++)if(c[m].apply(b,f)===!1&&a.stopOnFalse){e=!0;break}j=!1,c&&(a.once?e===!0?p.disable():c=[]:d&&d.length&&(e=d.shift(),p.fireWith(e[0],e[1])))},p={add:function(){if(c){var a=c.length;n(arguments),j?l=c.length:e&&e!==!0&&(k=a,o(e[0],e[1]))}return this},remove:function(){if(c){var b=arguments,d=0,e=b.length;for(;d<e;d++)for(var f=0;f<c.length;f++)if(b[d]===c[f]){j&&f<=l&&(l--,f<=m&&m--),c.splice(f--,1);if(a.unique)break}}return this},has:function(a){if(c){var b=0,d=c.length;for(;b<d;b++)if(a===c[b])return!0}return!1},empty:function(){c=[];return this},disable:function(){c=d=e=b;return this},disabled:function(){return!c},lock:function(){d=b,(!e||e===!0)&&p.disable();return this},locked:function(){return!d},fireWith:function(b,c){d&&(j?a.once||d.push([b,c]):(!a.once||!e)&&o(b,c));return this},fire:function(){p.fireWith(this,arguments);return this},fired:function(){return!!i}};return p};var i=[].slice;f.extend({Deferred:function(a){var b=f.Callbacks("once memory"),c=f.Callbacks("once memory"),d=f.Callbacks("memory"),e="pending",g={resolve:b,reject:c,notify:d},h={done:b.add,fail:c.add,progress:d.add,state:function(){return e},isResolved:b.fired,isRejected:c.fired,then:function(a,b,c){i.done(a).fail(b).progress(c);return this},always:function(){i.done.apply(i,arguments).fail.apply(i,arguments);return this},pipe:function(a,b,c){return f.Deferred(function(d){f.each({done:[a,"resolve"],fail:[b,"reject"],progress:[c,"notify"]},function(a,b){var c=b[0],e=b[1],g;f.isFunction(c)?i[a](function(){g=c.apply(this,arguments),g&&f.isFunction(g.promise)?g.promise().then(d.resolve,d.reject,d.notify):d[e+"With"](this===i?d:this,[g])}):i[a](d[e])})}).promise()},promise:function(a){if(a==null)a=h;else for(var b in h)a[b]=h[b];return a}},i=h.promise({}),j;for(j in g)i[j]=g[j].fire,i[j+"With"]=g[j].fireWith;i.done(function(){e="resolved"},c.disable,d.lock).fail(function(){e="rejected"},b.disable,d.lock),a&&a.call(i,i);return i},when:function(a){function m(a){return function(b){e[a]=arguments.length>1?i.call(arguments,0):b,j.notifyWith(k,e)}}function l(a){return function(c){b[a]=arguments.length>1?i.call(arguments,0):c,--g||j.resolveWith(j,b)}}var b=i.call(arguments,0),c=0,d=b.length,e=Array(d),g=d,h=d,j=d<=1&&a&&f.isFunction(a.promise)?a:f.Deferred(),k=j.promise();if(d>1){for(;c<d;c++)b[c]&&b[c].promise&&f.isFunction(b[c].promise)?b[c].promise().then(l(c),j.reject,m(c)):--g;g||j.resolveWith(j,b)}else j!==a&&j.resolveWith(j,d?[a]:[]);return k}}),f.support=function(){var b,d,e,g,h,i,j,k,l,m,n,o,p=c.createElement("div"),q=c.documentElement;p.setAttribute("className","t"),p.innerHTML=" <link/><table></table><a href='/a' style='top:1px;float:left;opacity:.55;'>a</a><input type='checkbox'/>",d=p.getElementsByTagName("*"),e=p.getElementsByTagName("a")[0];if(!d||!d.length||!e)return{};g=c.createElement("select"),h=g.appendChild(c.createElement("option")),i=p.getElementsByTagName("input")[0],b={leadingWhitespace:p.firstChild.nodeType===3,tbody:!p.getElementsByTagName("tbody").length,htmlSerialize:!!p.getElementsByTagName("link").length,style:/top/.test(e.getAttribute("style")),hrefNormalized:e.getAttribute("href")==="/a",opacity:/^0.55/.test(e.style.opacity),cssFloat:!!e.style.cssFloat,checkOn:i.value==="on",optSelected:h.selected,getSetAttribute:p.className!=="t",enctype:!!c.createElement("form").enctype,html5Clone:c.createElement("nav").cloneNode(!0).outerHTML!=="<:nav></:nav>",submitBubbles:!0,changeBubbles:!0,focusinBubbles:!1,deleteExpando:!0,noCloneEvent:!0,inlineBlockNeedsLayout:!1,shrinkWrapBlocks:!1,reliableMarginRight:!0,pixelMargin:!0},f.boxModel=b.boxModel=c.compatMode==="CSS1Compat",i.checked=!0,b.noCloneChecked=i.cloneNode(!0).checked,g.disabled=!0,b.optDisabled=!h.disabled;try{delete p.test}catch(r){b.deleteExpando=!1}!p.addEventListener&&p.attachEvent&&p.fireEvent&&(p.attachEvent("onclick",function(){b.noCloneEvent=!1}),p.cloneNode(!0).fireEvent("onclick")),i=c.createElement("input"),i.value="t",i.setAttribute("type","radio"),b.radioValue=i.value==="t",i.setAttribute("checked","checked"),i.setAttribute("name","t"),p.appendChild(i),j=c.createDocumentFragment(),j.appendChild(p.lastChild),b.checkClone=j.cloneNode(!0).cloneNode(!0).lastChild.checked,b.appendChecked=i.checked,j.removeChild(i),j.appendChild(p);if(p.attachEvent)for(n in{submit:1,change:1,focusin:1})m="on"+n,o=m in p,o||(p.setAttribute(m,"return;"),o=typeof p[m]=="function"),b[n+"Bubbles"]=o;j.removeChild(p),j=g=h=p=i=null,f(function(){var d,e,g,h,i,j,l,m,n,q,r,s,t,u=c.getElementsByTagName("body")[0];!u||(m=1,t="padding:0;margin:0;border:",r="position:absolute;top:0;left:0;width:1px;height:1px;",s=t+"0;visibility:hidden;",n="style='"+r+t+"5px solid #000;",q="<div "+n+"display:block;'><div style='"+t+"0;display:block;overflow:hidden;'></div></div>"+"<table "+n+"' cellpadding='0' cellspacing='0'>"+"<tr><td></td></tr></table>",d=c.createElement("div"),d.style.cssText=s+"width:0;height:0;position:static;top:0;margin-top:"+m+"px",u.insertBefore(d,u.firstChild),p=c.createElement("div"),d.appendChild(p),p.innerHTML="<table><tr><td style='"+t+"0;display:none'></td><td>t</td></tr></table>",k=p.getElementsByTagName("td"),o=k[0].offsetHeight===0,k[0].style.display="",k[1].style.display="none",b.reliableHiddenOffsets=o&&k[0].offsetHeight===0,a.getComputedStyle&&(p.innerHTML="",l=c.createElement("div"),l.style.width="0",l.style.marginRight="0",p.style.width="2px",p.appendChild(l),b.reliableMarginRight=(parseInt((a.getComputedStyle(l,null)||{marginRight:0}).marginRight,10)||0)===0),typeof p.style.zoom!="undefined"&&(p.innerHTML="",p.style.width=p.style.padding="1px",p.style.border=0,p.style.overflow="hidden",p.style.display="inline",p.style.zoom=1,b.inlineBlockNeedsLayout=p.offsetWidth===3,p.style.display="block",p.style.overflow="visible",p.innerHTML="<div style='width:5px;'></div>",b.shrinkWrapBlocks=p.offsetWidth!==3),p.style.cssText=r+s,p.innerHTML=q,e=p.firstChild,g=e.firstChild,i=e.nextSibling.firstChild.firstChild,j={doesNotAddBorder:g.offsetTop!==5,doesAddBorderForTableAndCells:i.offsetTop===5},g.style.position="fixed",g.style.top="20px",j.fixedPosition=g.offsetTop===20||g.offsetTop===15,g.style.position=g.style.top="",e.style.overflow="hidden",e.style.position="relative",j.subtractsBorderForOverflowNotVisible=g.offsetTop===-5,j.doesNotIncludeMarginInBodyOffset=u.offsetTop!==m,a.getComputedStyle&&(p.style.marginTop="1%",b.pixelMargin=(a.getComputedStyle(p,null)||{marginTop:0}).marginTop!=="1%"),typeof d.style.zoom!="undefined"&&(d.style.zoom=1),u.removeChild(d),l=p=d=null,f.extend(b,j))});return b}();var j=/^(?:\{.*\}|\[.*\])$/,k=/([A-Z])/g;f.extend({cache:{},uuid:0,expando:"jQuery"+(f.fn.jquery+Math.random()).replace(/\D/g,""),noData:{embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:!0},hasData:function(a){a=a.nodeType?f.cache[a[f.expando]]:a[f.expando];return!!a&&!m(a)},data:function(a,c,d,e){if(!!f.acceptData(a)){var g,h,i,j=f.expando,k=typeof c=="string",l=a.nodeType,m=l?f.cache:a,n=l?a[j]:a[j]&&j,o=c==="events";if((!n||!m[n]||!o&&!e&&!m[n].data)&&k&&d===b)return;n||(l?a[j]=n=++f.uuid:n=j),m[n]||(m[n]={},l||(m[n].toJSON=f.noop));if(typeof c=="object"||typeof c=="function")e?m[n]=f.extend(m[n],c):m[n].data=f.extend(m[n].data,c);g=h=m[n],e||(h.data||(h.data={}),h=h.data),d!==b&&(h[f.camelCase(c)]=d);if(o&&!h[c])return g.events;k?(i=h[c],i==null&&(i=h[f.camelCase(c)])):i=h;return i}},removeData:function(a,b,c){if(!!f.acceptData(a)){var d,e,g,h=f.expando,i=a.nodeType,j=i?f.cache:a,k=i?a[h]:h;if(!j[k])return;if(b){d=c?j[k]:j[k].data;if(d){f.isArray(b)||(b in d?b=[b]:(b=f.camelCase(b),b in d?b=[b]:b=b.split(" ")));for(e=0,g=b.length;e<g;e++)delete d[b[e]];if(!(c?m:f.isEmptyObject)(d))return}}if(!c){delete j[k].data;if(!m(j[k]))return}f.support.deleteExpando||!j.setInterval?delete j[k]:j[k]=null,i&&(f.support.deleteExpando?delete a[h]:a.removeAttribute?a.removeAttribute(h):a[h]=null)}},_data:function(a,b,c){return f.data(a,b,c,!0)},acceptData:function(a){if(a.nodeName){var b=f.noData[a.nodeName.toLowerCase()];if(b)return b!==!0&&a.getAttribute("classid")===b}return!0}}),f.fn.extend({data:function(a,c){var d,e,g,h,i,j=this[0],k=0,m=null;if(a===b){if(this.length){m=f.data(j);if(j.nodeType===1&&!f._data(j,"parsedAttrs")){g=j.attributes;for(i=g.length;k<i;k++)h=g[k].name,h.indexOf("data-")===0&&(h=f.camelCase(h.substring(5)),l(j,h,m[h]));f._data(j,"parsedAttrs",!0)}}return m}if(typeof a=="object")return this.each(function(){f.data(this,a)});d=a.split(".",2),d[1]=d[1]?"."+d[1]:"",e=d[1]+"!";return f.access(this,function(c){if(c===b){m=this.triggerHandler("getData"+e,[d[0]]),m===b&&j&&(m=f.data(j,a),m=l(j,a,m));return m===b&&d[1]?this.data(d[0]):m}d[1]=c,this.each(function(){var b=f(this);b.triggerHandler("setData"+e,d),f.data(this,a,c),b.triggerHandler("changeData"+e,d)})},null,c,arguments.length>1,null,!1)},removeData:function(a){return this.each(function(){f.removeData(this,a)})}}),f.extend({_mark:function(a,b){a&&(b=(b||"fx")+"mark",f._data(a,b,(f._data(a,b)||0)+1))},_unmark:function(a,b,c){a!==!0&&(c=b,b=a,a=!1);if(b){c=c||"fx";var d=c+"mark",e=a?0:(f._data(b,d)||1)-1;e?f._data(b,d,e):(f.removeData(b,d,!0),n(b,c,"mark"))}},queue:function(a,b,c){var d;if(a){b=(b||"fx")+"queue",d=f._data(a,b),c&&(!d||f.isArray(c)?d=f._data(a,b,f.makeArray(c)):d.push(c));return d||[]}},dequeue:function(a,b){b=b||"fx";var c=f.queue(a,b),d=c.shift(),e={};d==="inprogress"&&(d=c.shift()),d&&(b==="fx"&&c.unshift("inprogress"),f._data(a,b+".run",e),d.call(a,function(){f.dequeue(a,b)},e)),c.length||(f.removeData(a,b+"queue "+b+".run",!0),n(a,b,"queue"))}}),f.fn.extend({queue:function(a,c){var d=2;typeof a!="string"&&(c=a,a="fx",d--);if(arguments.length<d)return f.queue(this[0],a);return c===b?this:this.each(function(){var b=f.queue(this,a,c);a==="fx"&&b[0]!=="inprogress"&&f.dequeue(this,a)})},dequeue:function(a){return this.each(function(){f.dequeue(this,a)})},delay:function(a,b){a=f.fx?f.fx.speeds[a]||a:a,b=b||"fx";return this.queue(b,function(b,c){var d=setTimeout(b,a);c.stop=function(){clearTimeout(d)}})},clearQueue:function(a){return this.queue(a||"fx",[])},promise:function(a,c){function m(){--h||d.resolveWith(e,[e])}typeof a!="string"&&(c=a,a=b),a=a||"fx";var d=f.Deferred(),e=this,g=e.length,h=1,i=a+"defer",j=a+"queue",k=a+"mark",l;while(g--)if(l=f.data(e[g],i,b,!0)||(f.data(e[g],j,b,!0)||f.data(e[g],k,b,!0))&&f.data(e[g],i,f.Callbacks("once memory"),!0))h++,l.add(m);m();return d.promise(c)}});var o=/[\n\t\r]/g,p=/\s+/,q=/\r/g,r=/^(?:button|input)$/i,s=/^(?:button|input|object|select|textarea)$/i,t=/^a(?:rea)?$/i,u=/^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,v=f.support.getSetAttribute,w,x,y;f.fn.extend({attr:function(a,b){return f.access(this,f.attr,a,b,arguments.length>1)},removeAttr:function(a){return this.each(function(){f.removeAttr(this,a)})},prop:function(a,b){return f.access(this,f.prop,a,b,arguments.length>1)},removeProp:function(a){a=f.propFix[a]||a;return this.each(function(){try{this[a]=b,delete this[a]}catch(c){}})},addClass:function(a){var b,c,d,e,g,h,i;if(f.isFunction(a))return this.each(function(b){f(this).addClass(a.call(this,b,this.className))});if(a&&typeof a=="string"){b=a.split(p);for(c=0,d=this.length;c<d;c++){e=this[c];if(e.nodeType===1)if(!e.className&&b.length===1)e.className=a;else{g=" "+e.className+" ";for(h=0,i=b.length;h<i;h++)~g.indexOf(" "+b[h]+" ")||(g+=b[h]+" ");e.className=f.trim(g)}}}return this},removeClass:function(a){var c,d,e,g,h,i,j;if(f.isFunction(a))return this.each(function(b){f(this).removeClass(a.call(this,b,this.className))});if(a&&typeof a=="string"||a===b){c=(a||"").split(p);for(d=0,e=this.length;d<e;d++){g=this[d];if(g.nodeType===1&&g.className)if(a){h=(" "+g.className+" ").replace(o," ");for(i=0,j=c.length;i<j;i++)h=h.replace(" "+c[i]+" "," ");g.className=f.trim(h)}else g.className=""}}return this},toggleClass:function(a,b){var c=typeof a,d=typeof b=="boolean";if(f.isFunction(a))return this.each(function(c){f(this).toggleClass(a.call(this,c,this.className,b),b)});return this.each(function(){if(c==="string"){var e,g=0,h=f(this),i=b,j=a.split(p);while(e=j[g++])i=d?i:!h.hasClass(e),h[i?"addClass":"removeClass"](e)}else if(c==="undefined"||c==="boolean")this.className&&f._data(this,"__className__",this.className),this.className=this.className||a===!1?"":f._data(this,"__className__")||""})},hasClass:function(a){var b=" "+a+" ",c=0,d=this.length;for(;c<d;c++)if(this[c].nodeType===1&&(" "+this[c].className+" ").replace(o," ").indexOf(b)>-1)return!0;return!1},val:function(a){var c,d,e,g=this[0];{if(!!arguments.length){e=f.isFunction(a);return this.each(function(d){var g=f(this),h;if(this.nodeType===1){e?h=a.call(this,d,g.val()):h=a,h==null?h="":typeof h=="number"?h+="":f.isArray(h)&&(h=f.map(h,function(a){return a==null?"":a+""})),c=f.valHooks[this.type]||f.valHooks[this.nodeName.toLowerCase()];if(!c||!("set"in c)||c.set(this,h,"value")===b)this.value=h}})}if(g){c=f.valHooks[g.type]||f.valHooks[g.nodeName.toLowerCase()];if(c&&"get"in c&&(d=c.get(g,"value"))!==b)return d;d=g.value;return typeof d=="string"?d.replace(q,""):d==null?"":d}}}}),f.extend({valHooks:{option:{get:function(a){var b=a.attributes.value;return!b||b.specified?a.value:a.text}},select:{get:function(a){var b,c,d,e,g=a.selectedIndex,h=[],i=a.options,j=a.type==="select-one";if(g<0)return null;c=j?g:0,d=j?g+1:i.length;for(;c<d;c++){e=i[c];if(e.selected&&(f.support.optDisabled?!e.disabled:e.getAttribute("disabled")===null)&&(!e.parentNode.disabled||!f.nodeName(e.parentNode,"optgroup"))){b=f(e).val();if(j)return b;h.push(b)}}if(j&&!h.length&&i.length)return f(i[g]).val();return h},set:function(a,b){var c=f.makeArray(b);f(a).find("option").each(function(){this.selected=f.inArray(f(this).val(),c)>=0}),c.length||(a.selectedIndex=-1);return c}}},attrFn:{val:!0,css:!0,html:!0,text:!0,data:!0,width:!0,height:!0,offset:!0},attr:function(a,c,d,e){var g,h,i,j=a.nodeType;if(!!a&&j!==3&&j!==8&&j!==2){if(e&&c in f.attrFn)return f(a)[c](d);if(typeof a.getAttribute=="undefined")return f.prop(a,c,d);i=j!==1||!f.isXMLDoc(a),i&&(c=c.toLowerCase(),h=f.attrHooks[c]||(u.test(c)?x:w));if(d!==b){if(d===null){f.removeAttr(a,c);return}if(h&&"set"in h&&i&&(g=h.set(a,d,c))!==b)return g;a.setAttribute(c,""+d);return d}if(h&&"get"in h&&i&&(g=h.get(a,c))!==null)return g;g=a.getAttribute(c);return g===null?b:g}},removeAttr:function(a,b){var c,d,e,g,h,i=0;if(b&&a.nodeType===1){d=b.toLowerCase().split(p),g=d.length;for(;i<g;i++)e=d[i],e&&(c=f.propFix[e]||e,h=u.test(e),h||f.attr(a,e,""),a.removeAttribute(v?e:c),h&&c in a&&(a[c]=!1))}},attrHooks:{type:{set:function(a,b){if(r.test(a.nodeName)&&a.parentNode)f.error("type property can't be changed");else if(!f.support.radioValue&&b==="radio"&&f.nodeName(a,"input")){var c=a.value;a.setAttribute("type",b),c&&(a.value=c);return b}}},value:{get:function(a,b){if(w&&f.nodeName(a,"button"))return w.get(a,b);return b in a?a.value:null},set:function(a,b,c){if(w&&f.nodeName(a,"button"))return w.set(a,b,c);a.value=b}}},propFix:{tabindex:"tabIndex",readonly:"readOnly","for":"htmlFor","class":"className",maxlength:"maxLength",cellspacing:"cellSpacing",cellpadding:"cellPadding",rowspan:"rowSpan",colspan:"colSpan",usemap:"useMap",frameborder:"frameBorder",contenteditable:"contentEditable"},prop:function(a,c,d){var e,g,h,i=a.nodeType;if(!!a&&i!==3&&i!==8&&i!==2){h=i!==1||!f.isXMLDoc(a),h&&(c=f.propFix[c]||c,g=f.propHooks[c]);return d!==b?g&&"set"in g&&(e=g.set(a,d,c))!==b?e:a[c]=d:g&&"get"in g&&(e=g.get(a,c))!==null?e:a[c]}},propHooks:{tabIndex:{get:function(a){var c=a.getAttributeNode("tabindex");return c&&c.specified?parseInt(c.value,10):s.test(a.nodeName)||t.test(a.nodeName)&&a.href?0:b}}}}),f.attrHooks.tabindex=f.propHooks.tabIndex,x={get:function(a,c){var d,e=f.prop(a,c);return e===!0||typeof e!="boolean"&&(d=a.getAttributeNode(c))&&d.nodeValue!==!1?c.toLowerCase():b},set:function(a,b,c){var d;b===!1?f.removeAttr(a,c):(d=f.propFix[c]||c,d in a&&(a[d]=!0),a.setAttribute(c,c.toLowerCase()));return c}},v||(y={name:!0,id:!0,coords:!0},w=f.valHooks.button={get:function(a,c){var d;d=a.getAttributeNode(c);return d&&(y[c]?d.nodeValue!=="":d.specified)?d.nodeValue:b},set:function(a,b,d){var e=a.getAttributeNode(d);e||(e=c.createAttribute(d),a.setAttributeNode(e));return e.nodeValue=b+""}},f.attrHooks.tabindex.set=w.set,f.each(["width","height"],function(a,b){f.attrHooks[b]=f.extend(f.attrHooks[b],{set:function(a,c){if(c===""){a.setAttribute(b,"auto");return c}}})}),f.attrHooks.contenteditable={get:w.get,set:function(a,b,c){b===""&&(b="false"),w.set(a,b,c)}}),f.support.hrefNormalized||f.each(["href","src","width","height"],function(a,c){f.attrHooks[c]=f.extend(f.attrHooks[c],{get:function(a){var d=a.getAttribute(c,2);return d===null?b:d}})}),f.support.style||(f.attrHooks.style={get:function(a){return a.style.cssText.toLowerCase()||b},set:function(a,b){return a.style.cssText=""+b}}),f.support.optSelected||(f.propHooks.selected=f.extend(f.propHooks.selected,{get:function(a){var b=a.parentNode;b&&(b.selectedIndex,b.parentNode&&b.parentNode.selectedIndex);return null}})),f.support.enctype||(f.propFix.enctype="encoding"),f.support.checkOn||f.each(["radio","checkbox"],function(){f.valHooks[this]={get:function(a){return a.getAttribute("value")===null?"on":a.value}}}),f.each(["radio","checkbox"],function(){f.valHooks[this]=f.extend(f.valHooks[this],{set:function(a,b){if(f.isArray(b))return a.checked=f.inArray(f(a).val(),b)>=0}})});var z=/^(?:textarea|input|select)$/i,A=/^([^\.]*)?(?:\.(.+))?$/,B=/(?:^|\s)hover(\.\S+)?\b/,C=/^key/,D=/^(?:mouse|contextmenu)|click/,E=/^(?:focusinfocus|focusoutblur)$/,F=/^(\w*)(?:#([\w\-]+))?(?:\.([\w\-]+))?$/,G=function(
|
|
a){var b=F.exec(a);b&&(b[1]=(b[1]||"").toLowerCase(),b[3]=b[3]&&new RegExp("(?:^|\\s)"+b[3]+"(?:\\s|$)"));return b},H=function(a,b){var c=a.attributes||{};return(!b[1]||a.nodeName.toLowerCase()===b[1])&&(!b[2]||(c.id||{}).value===b[2])&&(!b[3]||b[3].test((c["class"]||{}).value))},I=function(a){return f.event.special.hover?a:a.replace(B,"mouseenter$1 mouseleave$1")};f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3||a.nodeType===8||!c||!d||!(h=f._data(a)))){d.handler&&(p=d,d=p.handler,g=p.selector),d.guid||(d.guid=f.guid++),j=h.events,j||(h.events=j={}),i=h.handle,i||(h.handle=i=function(a){return typeof f!="undefined"&&(!a||f.event.triggered!==a.type)?f.event.dispatch.apply(i.elem,arguments):b},i.elem=a),c=f.trim(I(c)).split(" ");for(k=0;k<c.length;k++){l=A.exec(c[k])||[],m=l[1],n=(l[2]||"").split(".").sort(),s=f.event.special[m]||{},m=(g?s.delegateType:s.bindType)||m,s=f.event.special[m]||{},o=f.extend({type:m,origType:l[1],data:e,handler:d,guid:d.guid,selector:g,quick:g&&G(g),namespace:n.join(".")},p),r=j[m];if(!r){r=j[m]=[],r.delegateCount=0;if(!s.setup||s.setup.call(a,e,n,i)===!1)a.addEventListener?a.addEventListener(m,i,!1):a.attachEvent&&a.attachEvent("on"+m,i)}s.add&&(s.add.call(a,o),o.handler.guid||(o.handler.guid=d.guid)),g?r.splice(r.delegateCount++,0,o):r.push(o),f.event.global[m]=!0}a=null}},global:{},remove:function(a,b,c,d,e){var g=f.hasData(a)&&f._data(a),h,i,j,k,l,m,n,o,p,q,r,s;if(!!g&&!!(o=g.events)){b=f.trim(I(b||"")).split(" ");for(h=0;h<b.length;h++){i=A.exec(b[h])||[],j=k=i[1],l=i[2];if(!j){for(j in o)f.event.remove(a,j+b[h],c,d,!0);continue}p=f.event.special[j]||{},j=(d?p.delegateType:p.bindType)||j,r=o[j]||[],m=r.length,l=l?new RegExp("(^|\\.)"+l.split(".").sort().join("\\.(?:.*\\.)?")+"(\\.|$)"):null;for(n=0;n<r.length;n++)s=r[n],(e||k===s.origType)&&(!c||c.guid===s.guid)&&(!l||l.test(s.namespace))&&(!d||d===s.selector||d==="**"&&s.selector)&&(r.splice(n--,1),s.selector&&r.delegateCount--,p.remove&&p.remove.call(a,s));r.length===0&&m!==r.length&&((!p.teardown||p.teardown.call(a,l)===!1)&&f.removeEvent(a,j,g.handle),delete o[j])}f.isEmptyObject(o)&&(q=g.handle,q&&(q.elem=null),f.removeData(a,["events","handle"],!0))}},customEvent:{getData:!0,setData:!0,changeData:!0},trigger:function(c,d,e,g){if(!e||e.nodeType!==3&&e.nodeType!==8){var h=c.type||c,i=[],j,k,l,m,n,o,p,q,r,s;if(E.test(h+f.event.triggered))return;h.indexOf("!")>=0&&(h=h.slice(0,-1),k=!0),h.indexOf(".")>=0&&(i=h.split("."),h=i.shift(),i.sort());if((!e||f.event.customEvent[h])&&!f.event.global[h])return;c=typeof c=="object"?c[f.expando]?c:new f.Event(h,c):new f.Event(h),c.type=h,c.isTrigger=!0,c.exclusive=k,c.namespace=i.join("."),c.namespace_re=c.namespace?new RegExp("(^|\\.)"+i.join("\\.(?:.*\\.)?")+"(\\.|$)"):null,o=h.indexOf(":")<0?"on"+h:"";if(!e){j=f.cache;for(l in j)j[l].events&&j[l].events[h]&&f.event.trigger(c,d,j[l].handle.elem,!0);return}c.result=b,c.target||(c.target=e),d=d!=null?f.makeArray(d):[],d.unshift(c),p=f.event.special[h]||{};if(p.trigger&&p.trigger.apply(e,d)===!1)return;r=[[e,p.bindType||h]];if(!g&&!p.noBubble&&!f.isWindow(e)){s=p.delegateType||h,m=E.test(s+h)?e:e.parentNode,n=null;for(;m;m=m.parentNode)r.push([m,s]),n=m;n&&n===e.ownerDocument&&r.push([n.defaultView||n.parentWindow||a,s])}for(l=0;l<r.length&&!c.isPropagationStopped();l++)m=r[l][0],c.type=r[l][1],q=(f._data(m,"events")||{})[c.type]&&f._data(m,"handle"),q&&q.apply(m,d),q=o&&m[o],q&&f.acceptData(m)&&q.apply(m,d)===!1&&c.preventDefault();c.type=h,!g&&!c.isDefaultPrevented()&&(!p._default||p._default.apply(e.ownerDocument,d)===!1)&&(h!=="click"||!f.nodeName(e,"a"))&&f.acceptData(e)&&o&&e[h]&&(h!=="focus"&&h!=="blur"||c.target.offsetWidth!==0)&&!f.isWindow(e)&&(n=e[o],n&&(e[o]=null),f.event.triggered=h,e[h](),f.event.triggered=b,n&&(e[o]=n));return c.result}},dispatch:function(c){c=f.event.fix(c||a.event);var d=(f._data(this,"events")||{})[c.type]||[],e=d.delegateCount,g=[].slice.call(arguments,0),h=!c.exclusive&&!c.namespace,i=f.event.special[c.type]||{},j=[],k,l,m,n,o,p,q,r,s,t,u;g[0]=c,c.delegateTarget=this;if(!i.preDispatch||i.preDispatch.call(this,c)!==!1){if(e&&(!c.button||c.type!=="click")){n=f(this),n.context=this.ownerDocument||this;for(m=c.target;m!=this;m=m.parentNode||this)if(m.disabled!==!0){p={},r=[],n[0]=m;for(k=0;k<e;k++)s=d[k],t=s.selector,p[t]===b&&(p[t]=s.quick?H(m,s.quick):n.is(t)),p[t]&&r.push(s);r.length&&j.push({elem:m,matches:r})}}d.length>e&&j.push({elem:this,matches:d.slice(e)});for(k=0;k<j.length&&!c.isPropagationStopped();k++){q=j[k],c.currentTarget=q.elem;for(l=0;l<q.matches.length&&!c.isImmediatePropagationStopped();l++){s=q.matches[l];if(h||!c.namespace&&!s.namespace||c.namespace_re&&c.namespace_re.test(s.namespace))c.data=s.data,c.handleObj=s,o=((f.event.special[s.origType]||{}).handle||s.handler).apply(q.elem,g),o!==b&&(c.result=o,o===!1&&(c.preventDefault(),c.stopPropagation()))}}i.postDispatch&&i.postDispatch.call(this,c);return c.result}},props:"attrChange attrName relatedNode srcElement altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),fixHooks:{},keyHooks:{props:"char charCode key keyCode".split(" "),filter:function(a,b){a.which==null&&(a.which=b.charCode!=null?b.charCode:b.keyCode);return a}},mouseHooks:{props:"button buttons clientX clientY fromElement offsetX offsetY pageX pageY screenX screenY toElement".split(" "),filter:function(a,d){var e,f,g,h=d.button,i=d.fromElement;a.pageX==null&&d.clientX!=null&&(e=a.target.ownerDocument||c,f=e.documentElement,g=e.body,a.pageX=d.clientX+(f&&f.scrollLeft||g&&g.scrollLeft||0)-(f&&f.clientLeft||g&&g.clientLeft||0),a.pageY=d.clientY+(f&&f.scrollTop||g&&g.scrollTop||0)-(f&&f.clientTop||g&&g.clientTop||0)),!a.relatedTarget&&i&&(a.relatedTarget=i===a.target?d.toElement:i),!a.which&&h!==b&&(a.which=h&1?1:h&2?3:h&4?2:0);return a}},fix:function(a){if(a[f.expando])return a;var d,e,g=a,h=f.event.fixHooks[a.type]||{},i=h.props?this.props.concat(h.props):this.props;a=f.Event(g);for(d=i.length;d;)e=i[--d],a[e]=g[e];a.target||(a.target=g.srcElement||c),a.target.nodeType===3&&(a.target=a.target.parentNode),a.metaKey===b&&(a.metaKey=a.ctrlKey);return h.filter?h.filter(a,g):a},special:{ready:{setup:f.bindReady},load:{noBubble:!0},focus:{delegateType:"focusin"},blur:{delegateType:"focusout"},beforeunload:{setup:function(a,b,c){f.isWindow(this)&&(this.onbeforeunload=c)},teardown:function(a,b){this.onbeforeunload===b&&(this.onbeforeunload=null)}}},simulate:function(a,b,c,d){var e=f.extend(new f.Event,c,{type:a,isSimulated:!0,originalEvent:{}});d?f.event.trigger(e,null,b):f.event.dispatch.call(b,e),e.isDefaultPrevented()&&c.preventDefault()}},f.event.handle=f.event.dispatch,f.removeEvent=c.removeEventListener?function(a,b,c){a.removeEventListener&&a.removeEventListener(b,c,!1)}:function(a,b,c){a.detachEvent&&a.detachEvent("on"+b,c)},f.Event=function(a,b){if(!(this instanceof f.Event))return new f.Event(a,b);a&&a.type?(this.originalEvent=a,this.type=a.type,this.isDefaultPrevented=a.defaultPrevented||a.returnValue===!1||a.getPreventDefault&&a.getPreventDefault()?K:J):this.type=a,b&&f.extend(this,b),this.timeStamp=a&&a.timeStamp||f.now(),this[f.expando]=!0},f.Event.prototype={preventDefault:function(){this.isDefaultPrevented=K;var a=this.originalEvent;!a||(a.preventDefault?a.preventDefault():a.returnValue=!1)},stopPropagation:function(){this.isPropagationStopped=K;var a=this.originalEvent;!a||(a.stopPropagation&&a.stopPropagation(),a.cancelBubble=!0)},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=K,this.stopPropagation()},isDefaultPrevented:J,isPropagationStopped:J,isImmediatePropagationStopped:J},f.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(a,b){f.event.special[a]={delegateType:b,bindType:b,handle:function(a){var c=this,d=a.relatedTarget,e=a.handleObj,g=e.selector,h;if(!d||d!==c&&!f.contains(c,d))a.type=e.origType,h=e.handler.apply(this,arguments),a.type=b;return h}}}),f.support.submitBubbles||(f.event.special.submit={setup:function(){if(f.nodeName(this,"form"))return!1;f.event.add(this,"click._submit keypress._submit",function(a){var c=a.target,d=f.nodeName(c,"input")||f.nodeName(c,"button")?c.form:b;d&&!d._submit_attached&&(f.event.add(d,"submit._submit",function(a){a._submit_bubble=!0}),d._submit_attached=!0)})},postDispatch:function(a){a._submit_bubble&&(delete a._submit_bubble,this.parentNode&&!a.isTrigger&&f.event.simulate("submit",this.parentNode,a,!0))},teardown:function(){if(f.nodeName(this,"form"))return!1;f.event.remove(this,"._submit")}}),f.support.changeBubbles||(f.event.special.change={setup:function(){if(z.test(this.nodeName)){if(this.type==="checkbox"||this.type==="radio")f.event.add(this,"propertychange._change",function(a){a.originalEvent.propertyName==="checked"&&(this._just_changed=!0)}),f.event.add(this,"click._change",function(a){this._just_changed&&!a.isTrigger&&(this._just_changed=!1,f.event.simulate("change",this,a,!0))});return!1}f.event.add(this,"beforeactivate._change",function(a){var b=a.target;z.test(b.nodeName)&&!b._change_attached&&(f.event.add(b,"change._change",function(a){this.parentNode&&!a.isSimulated&&!a.isTrigger&&f.event.simulate("change",this.parentNode,a,!0)}),b._change_attached=!0)})},handle:function(a){var b=a.target;if(this!==b||a.isSimulated||a.isTrigger||b.type!=="radio"&&b.type!=="checkbox")return a.handleObj.handler.apply(this,arguments)},teardown:function(){f.event.remove(this,"._change");return z.test(this.nodeName)}}),f.support.focusinBubbles||f.each({focus:"focusin",blur:"focusout"},function(a,b){var d=0,e=function(a){f.event.simulate(b,a.target,f.event.fix(a),!0)};f.event.special[b]={setup:function(){d++===0&&c.addEventListener(a,e,!0)},teardown:function(){--d===0&&c.removeEventListener(a,e,!0)}}}),f.fn.extend({on:function(a,c,d,e,g){var h,i;if(typeof a=="object"){typeof c!="string"&&(d=d||c,c=b);for(i in a)this.on(i,c,d,a[i],g);return this}d==null&&e==null?(e=c,d=c=b):e==null&&(typeof c=="string"?(e=d,d=b):(e=d,d=c,c=b));if(e===!1)e=J;else if(!e)return this;g===1&&(h=e,e=function(a){f().off(a);return h.apply(this,arguments)},e.guid=h.guid||(h.guid=f.guid++));return this.each(function(){f.event.add(this,a,e,d,c)})},one:function(a,b,c,d){return this.on(a,b,c,d,1)},off:function(a,c,d){if(a&&a.preventDefault&&a.handleObj){var e=a.handleObj;f(a.delegateTarget).off(e.namespace?e.origType+"."+e.namespace:e.origType,e.selector,e.handler);return this}if(typeof a=="object"){for(var g in a)this.off(g,c,a[g]);return this}if(c===!1||typeof c=="function")d=c,c=b;d===!1&&(d=J);return this.each(function(){f.event.remove(this,a,d,c)})},bind:function(a,b,c){return this.on(a,null,b,c)},unbind:function(a,b){return this.off(a,null,b)},live:function(a,b,c){f(this.context).on(a,this.selector,b,c);return this},die:function(a,b){f(this.context).off(a,this.selector||"**",b);return this},delegate:function(a,b,c,d){return this.on(b,a,c,d)},undelegate:function(a,b,c){return arguments.length==1?this.off(a,"**"):this.off(b,a,c)},trigger:function(a,b){return this.each(function(){f.event.trigger(a,b,this)})},triggerHandler:function(a,b){if(this[0])return f.event.trigger(a,b,this[0],!0)},toggle:function(a){var b=arguments,c=a.guid||f.guid++,d=0,e=function(c){var e=(f._data(this,"lastToggle"+a.guid)||0)%d;f._data(this,"lastToggle"+a.guid,e+1),c.preventDefault();return b[e].apply(this,arguments)||!1};e.guid=c;while(d<b.length)b[d++].guid=c;return this.click(e)},hover:function(a,b){return this.mouseenter(a).mouseleave(b||a)}}),f.each("blur focus focusin focusout load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup error contextmenu".split(" "),function(a,b){f.fn[b]=function(a,c){c==null&&(c=a,a=null);return arguments.length>0?this.on(b,null,a,c):this.trigger(b)},f.attrFn&&(f.attrFn[b]=!0),C.test(b)&&(f.event.fixHooks[b]=f.event.keyHooks),D.test(b)&&(f.event.fixHooks[b]=f.event.mouseHooks)}),function(){function x(a,b,c,e,f,g){for(var h=0,i=e.length;h<i;h++){var j=e[h];if(j){var k=!1;j=j[a];while(j){if(j[d]===c){k=e[j.sizset];break}if(j.nodeType===1){g||(j[d]=c,j.sizset=h);if(typeof b!="string"){if(j===b){k=!0;break}}else if(m.filter(b,[j]).length>0){k=j;break}}j=j[a]}e[h]=k}}}function w(a,b,c,e,f,g){for(var h=0,i=e.length;h<i;h++){var j=e[h];if(j){var k=!1;j=j[a];while(j){if(j[d]===c){k=e[j.sizset];break}j.nodeType===1&&!g&&(j[d]=c,j.sizset=h);if(j.nodeName.toLowerCase()===b){k=j;break}j=j[a]}e[h]=k}}}var a=/((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,d="sizcache"+(Math.random()+"").replace(".",""),e=0,g=Object.prototype.toString,h=!1,i=!0,j=/\\/g,k=/\r\n/g,l=/\W/;[0,0].sort(function(){i=!1;return 0});var m=function(b,d,e,f){e=e||[],d=d||c;var h=d;if(d.nodeType!==1&&d.nodeType!==9)return[];if(!b||typeof b!="string")return e;var i,j,k,l,n,q,r,t,u=!0,v=m.isXML(d),w=[],x=b;do{a.exec(""),i=a.exec(x);if(i){x=i[3],w.push(i[1]);if(i[2]){l=i[3];break}}}while(i);if(w.length>1&&p.exec(b))if(w.length===2&&o.relative[w[0]])j=y(w[0]+w[1],d,f);else{j=o.relative[w[0]]?[d]:m(w.shift(),d);while(w.length)b=w.shift(),o.relative[b]&&(b+=w.shift()),j=y(b,j,f)}else{!f&&w.length>1&&d.nodeType===9&&!v&&o.match.ID.test(w[0])&&!o.match.ID.test(w[w.length-1])&&(n=m.find(w.shift(),d,v),d=n.expr?m.filter(n.expr,n.set)[0]:n.set[0]);if(d){n=f?{expr:w.pop(),set:s(f)}:m.find(w.pop(),w.length===1&&(w[0]==="~"||w[0]==="+")&&d.parentNode?d.parentNode:d,v),j=n.expr?m.filter(n.expr,n.set):n.set,w.length>0?k=s(j):u=!1;while(w.length)q=w.pop(),r=q,o.relative[q]?r=w.pop():q="",r==null&&(r=d),o.relative[q](k,r,v)}else k=w=[]}k||(k=j),k||m.error(q||b);if(g.call(k)==="[object Array]")if(!u)e.push.apply(e,k);else if(d&&d.nodeType===1)for(t=0;k[t]!=null;t++)k[t]&&(k[t]===!0||k[t].nodeType===1&&m.contains(d,k[t]))&&e.push(j[t]);else for(t=0;k[t]!=null;t++)k[t]&&k[t].nodeType===1&&e.push(j[t]);else s(k,e);l&&(m(l,h,e,f),m.uniqueSort(e));return e};m.uniqueSort=function(a){if(u){h=i,a.sort(u);if(h)for(var b=1;b<a.length;b++)a[b]===a[b-1]&&a.splice(b--,1)}return a},m.matches=function(a,b){return m(a,null,null,b)},m.matchesSelector=function(a,b){return m(b,null,null,[a]).length>0},m.find=function(a,b,c){var d,e,f,g,h,i;if(!a)return[];for(e=0,f=o.order.length;e<f;e++){h=o.order[e];if(g=o.leftMatch[h].exec(a)){i=g[1],g.splice(1,1);if(i.substr(i.length-1)!=="\\"){g[1]=(g[1]||"").replace(j,""),d=o.find[h](g,b,c);if(d!=null){a=a.replace(o.match[h],"");break}}}}d||(d=typeof b.getElementsByTagName!="undefined"?b.getElementsByTagName("*"):[]);return{set:d,expr:a}},m.filter=function(a,c,d,e){var f,g,h,i,j,k,l,n,p,q=a,r=[],s=c,t=c&&c[0]&&m.isXML(c[0]);while(a&&c.length){for(h in o.filter)if((f=o.leftMatch[h].exec(a))!=null&&f[2]){k=o.filter[h],l=f[1],g=!1,f.splice(1,1);if(l.substr(l.length-1)==="\\")continue;s===r&&(r=[]);if(o.preFilter[h]){f=o.preFilter[h](f,s,d,r,e,t);if(!f)g=i=!0;else if(f===!0)continue}if(f)for(n=0;(j=s[n])!=null;n++)j&&(i=k(j,f,n,s),p=e^i,d&&i!=null?p?g=!0:s[n]=!1:p&&(r.push(j),g=!0));if(i!==b){d||(s=r),a=a.replace(o.match[h],"");if(!g)return[];break}}if(a===q)if(g==null)m.error(a);else break;q=a}return s},m.error=function(a){throw new Error("Syntax error, unrecognized expression: "+a)};var n=m.getText=function(a){var b,c,d=a.nodeType,e="";if(d){if(d===1||d===9||d===11){if(typeof a.textContent=="string")return a.textContent;if(typeof a.innerText=="string")return a.innerText.replace(k,"");for(a=a.firstChild;a;a=a.nextSibling)e+=n(a)}else if(d===3||d===4)return a.nodeValue}else for(b=0;c=a[b];b++)c.nodeType!==8&&(e+=n(c));return e},o=m.selectors={order:["ID","NAME","TAG"],match:{ID:/#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,CLASS:/\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,NAME:/\[name=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*\]/,ATTR:/\[\s*((?:[\w\u00c0-\uFFFF\-]|\\.)+)\s*(?:(\S?=)\s*(?:(['"])(.*?)\3|(#?(?:[\w\u00c0-\uFFFF\-]|\\.)*)|)|)\s*\]/,TAG:/^((?:[\w\u00c0-\uFFFF\*\-]|\\.)+)/,CHILD:/:(only|nth|last|first)-child(?:\(\s*(even|odd|(?:[+\-]?\d+|(?:[+\-]?\d*)?n\s*(?:[+\-]\s*\d+)?))\s*\))?/,POS:/:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^\-]|$)/,PSEUDO:/:((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/},leftMatch:{},attrMap:{"class":"className","for":"htmlFor"},attrHandle:{href:function(a){return a.getAttribute("href")},type:function(a){return a.getAttribute("type")}},relative:{"+":function(a,b){var c=typeof b=="string",d=c&&!l.test(b),e=c&&!d;d&&(b=b.toLowerCase());for(var f=0,g=a.length,h;f<g;f++)if(h=a[f]){while((h=h.previousSibling)&&h.nodeType!==1);a[f]=e||h&&h.nodeName.toLowerCase()===b?h||!1:h===b}e&&m.filter(b,a,!0)},">":function(a,b){var c,d=typeof b=="string",e=0,f=a.length;if(d&&!l.test(b)){b=b.toLowerCase();for(;e<f;e++){c=a[e];if(c){var g=c.parentNode;a[e]=g.nodeName.toLowerCase()===b?g:!1}}}else{for(;e<f;e++)c=a[e],c&&(a[e]=d?c.parentNode:c.parentNode===b);d&&m.filter(b,a,!0)}},"":function(a,b,c){var d,f=e++,g=x;typeof b=="string"&&!l.test(b)&&(b=b.toLowerCase(),d=b,g=w),g("parentNode",b,f,a,d,c)},"~":function(a,b,c){var d,f=e++,g=x;typeof b=="string"&&!l.test(b)&&(b=b.toLowerCase(),d=b,g=w),g("previousSibling",b,f,a,d,c)}},find:{ID:function(a,b,c){if(typeof b.getElementById!="undefined"&&!c){var d=b.getElementById(a[1]);return d&&d.parentNode?[d]:[]}},NAME:function(a,b){if(typeof b.getElementsByName!="undefined"){var c=[],d=b.getElementsByName(a[1]);for(var e=0,f=d.length;e<f;e++)d[e].getAttribute("name")===a[1]&&c.push(d[e]);return c.length===0?null:c}},TAG:function(a,b){if(typeof b.getElementsByTagName!="undefined")return b.getElementsByTagName(a[1])}},preFilter:{CLASS:function(a,b,c,d,e,f){a=" "+a[1].replace(j,"")+" ";if(f)return a;for(var g=0,h;(h=b[g])!=null;g++)h&&(e^(h.className&&(" "+h.className+" ").replace(/[\t\n\r]/g," ").indexOf(a)>=0)?c||d.push(h):c&&(b[g]=!1));return!1},ID:function(a){return a[1].replace(j,"")},TAG:function(a,b){return a[1].replace(j,"").toLowerCase()},CHILD:function(a){if(a[1]==="nth"){a[2]||m.error(a[0]),a[2]=a[2].replace(/^\+|\s*/g,"");var b=/(-?)(\d*)(?:n([+\-]?\d*))?/.exec(a[2]==="even"&&"2n"||a[2]==="odd"&&"2n+1"||!/\D/.test(a[2])&&"0n+"+a[2]||a[2]);a[2]=b[1]+(b[2]||1)-0,a[3]=b[3]-0}else a[2]&&m.error(a[0]);a[0]=e++;return a},ATTR:function(a,b,c,d,e,f){var g=a[1]=a[1].replace(j,"");!f&&o.attrMap[g]&&(a[1]=o.attrMap[g]),a[4]=(a[4]||a[5]||"").replace(j,""),a[2]==="~="&&(a[4]=" "+a[4]+" ");return a},PSEUDO:function(b,c,d,e,f){if(b[1]==="not")if((a.exec(b[3])||"").length>1||/^\w/.test(b[3]))b[3]=m(b[3],null,null,c);else{var g=m.filter(b[3],c,d,!0^f);d||e.push.apply(e,g);return!1}else if(o.match.POS.test(b[0])||o.match.CHILD.test(b[0]))return!0;return b},POS:function(a){a.unshift(!0);return a}},filters:{enabled:function(a){return a.disabled===!1&&a.type!=="hidden"},disabled:function(a){return a.disabled===!0},checked:function(a){return a.checked===!0},selected:function(a){a.parentNode&&a.parentNode.selectedIndex;return a.selected===!0},parent:function(a){return!!a.firstChild},empty:function(a){return!a.firstChild},has:function(a,b,c){return!!m(c[3],a).length},header:function(a){return/h\d/i.test(a.nodeName)},text:function(a){var b=a.getAttribute("type"),c=a.type;return a.nodeName.toLowerCase()==="input"&&"text"===c&&(b===c||b===null)},radio:function(a){return a.nodeName.toLowerCase()==="input"&&"radio"===a.type},checkbox:function(a){return a.nodeName.toLowerCase()==="input"&&"checkbox"===a.type},file:function(a){return a.nodeName.toLowerCase()==="input"&&"file"===a.type},password:function(a){return a.nodeName.toLowerCase()==="input"&&"password"===a.type},submit:function(a){var b=a.nodeName.toLowerCase();return(b==="input"||b==="button")&&"submit"===a.type},image:function(a){return a.nodeName.toLowerCase()==="input"&&"image"===a.type},reset:function(a){var b=a.nodeName.toLowerCase();return(b==="input"||b==="button")&&"reset"===a.type},button:function(a){var b=a.nodeName.toLowerCase();return b==="input"&&"button"===a.type||b==="button"},input:function(a){return/input|select|textarea|button/i.test(a.nodeName)},focus:function(a){return a===a.ownerDocument.activeElement}},setFilters:{first:function(a,b){return b===0},last:function(a,b,c,d){return b===d.length-1},even:function(a,b){return b%2===0},odd:function(a,b){return b%2===1},lt:function(a,b,c){return b<c[3]-0},gt:function(a,b,c){return b>c[3]-0},nth:function(a,b,c){return c[3]-0===b},eq:function(a,b,c){return c[3]-0===b}},filter:{PSEUDO:function(a,b,c,d){var e=b[1],f=o.filters[e];if(f)return f(a,c,b,d);if(e==="contains")return(a.textContent||a.innerText||n([a])||"").indexOf(b[3])>=0;if(e==="not"){var g=b[3];for(var h=0,i=g.length;h<i;h++)if(g[h]===a)return!1;return!0}m.error(e)},CHILD:function(a,b){var c,e,f,g,h,i,j,k=b[1],l=a;switch(k){case"only":case"first":while(l=l.previousSibling)if(l.nodeType===1)return!1;if(k==="first")return!0;l=a;case"last":while(l=l.nextSibling)if(l.nodeType===1)return!1;return!0;case"nth":c=b[2],e=b[3];if(c===1&&e===0)return!0;f=b[0],g=a.parentNode;if(g&&(g[d]!==f||!a.nodeIndex)){i=0;for(l=g.firstChild;l;l=l.nextSibling)l.nodeType===1&&(l.nodeIndex=++i);g[d]=f}j=a.nodeIndex-e;return c===0?j===0:j%c===0&&j/c>=0}},ID:function(a,b){return a.nodeType===1&&a.getAttribute("id")===b},TAG:function(a,b){return b==="*"&&a.nodeType===1||!!a.nodeName&&a.nodeName.toLowerCase()===b},CLASS:function(a,b){return(" "+(a.className||a.getAttribute("class"))+" ").indexOf(b)>-1},ATTR:function(a,b){var c=b[1],d=m.attr?m.attr(a,c):o.attrHandle[c]?o.attrHandle[c](a):a[c]!=null?a[c]:a.getAttribute(c),e=d+"",f=b[2],g=b[4];return d==null?f==="!=":!f&&m.attr?d!=null:f==="="?e===g:f==="*="?e.indexOf(g)>=0:f==="~="?(" "+e+" ").indexOf(g)>=0:g?f==="!="?e!==g:f==="^="?e.indexOf(g)===0:f==="$="?e.substr(e.length-g.length)===g:f==="|="?e===g||e.substr(0,g.length+1)===g+"-":!1:e&&d!==!1},POS:function(a,b,c,d){var e=b[2],f=o.setFilters[e];if(f)return f(a,c,b,d)}}},p=o.match.POS,q=function(a,b){return"\\"+(b-0+1)};for(var r in o.match)o.match[r]=new RegExp(o.match[r].source+/(?![^\[]*\])(?![^\(]*\))/.source),o.leftMatch[r]=new RegExp(/(^(?:.|\r|\n)*?)/.source+o.match[r].source.replace(/\\(\d+)/g,q));o.match.globalPOS=p;var s=function(a,b){a=Array.prototype.slice.call(a,0);if(b){b.push.apply(b,a);return b}return a};try{Array.prototype.slice.call(c.documentElement.childNodes,0)[0].nodeType}catch(t){s=function(a,b){var c=0,d=b||[];if(g.call(a)==="[object Array]")Array.prototype.push.apply(d,a);else if(typeof a.length=="number")for(var e=a.length;c<e;c++)d.push(a[c]);else for(;a[c];c++)d.push(a[c]);return d}}var u,v;c.documentElement.compareDocumentPosition?u=function(a,b){if(a===b){h=!0;return 0}if(!a.compareDocumentPosition||!b.compareDocumentPosition)return a.compareDocumentPosition?-1:1;return a.compareDocumentPosition(b)&4?-1:1}:(u=function(a,b){if(a===b){h=!0;return 0}if(a.sourceIndex&&b.sourceIndex)return a.sourceIndex-b.sourceIndex;var c,d,e=[],f=[],g=a.parentNode,i=b.parentNode,j=g;if(g===i)return v(a,b);if(!g)return-1;if(!i)return 1;while(j)e.unshift(j),j=j.parentNode;j=i;while(j)f.unshift(j),j=j.parentNode;c=e.length,d=f.length;for(var k=0;k<c&&k<d;k++)if(e[k]!==f[k])return v(e[k],f[k]);return k===c?v(a,f[k],-1):v(e[k],b,1)},v=function(a,b,c){if(a===b)return c;var d=a.nextSibling;while(d){if(d===b)return-1;d=d.nextSibling}return 1}),function(){var a=c.createElement("div"),d="script"+(new Date).getTime(),e=c.documentElement;a.innerHTML="<a name='"+d+"'/>",e.insertBefore(a,e.firstChild),c.getElementById(d)&&(o.find.ID=function(a,c,d){if(typeof c.getElementById!="undefined"&&!d){var e=c.getElementById(a[1]);return e?e.id===a[1]||typeof e.getAttributeNode!="undefined"&&e.getAttributeNode("id").nodeValue===a[1]?[e]:b:[]}},o.filter.ID=function(a,b){var c=typeof a.getAttributeNode!="undefined"&&a.getAttributeNode("id");return a.nodeType===1&&c&&c.nodeValue===b}),e.removeChild(a),e=a=null}(),function(){var a=c.createElement("div");a.appendChild(c.createComment("")),a.getElementsByTagName("*").length>0&&(o.find.TAG=function(a,b){var c=b.getElementsByTagName(a[1]);if(a[1]==="*"){var d=[];for(var e=0;c[e];e++)c[e].nodeType===1&&d.push(c[e]);c=d}return c}),a.innerHTML="<a href='#'></a>",a.firstChild&&typeof a.firstChild.getAttribute!="undefined"&&a.firstChild.getAttribute("href")!=="#"&&(o.attrHandle.href=function(a){return a.getAttribute("href",2)}),a=null}(),c.querySelectorAll&&function(){var a=m,b=c.createElement("div"),d="__sizzle__";b.innerHTML="<p class='TEST'></p>";if(!b.querySelectorAll||b.querySelectorAll(".TEST").length!==0){m=function(b,e,f,g){e=e||c;if(!g&&!m.isXML(e)){var h=/^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec(b);if(h&&(e.nodeType===1||e.nodeType===9)){if(h[1])return s(e.getElementsByTagName(b),f);if(h[2]&&o.find.CLASS&&e.getElementsByClassName)return s(e.getElementsByClassName(h[2]),f)}if(e.nodeType===9){if(b==="body"&&e.body)return s([e.body],f);if(h&&h[3]){var i=e.getElementById(h[3]);if(!i||!i.parentNode)return s([],f);if(i.id===h[3])return s([i],f)}try{return s(e.querySelectorAll(b),f)}catch(j){}}else if(e.nodeType===1&&e.nodeName.toLowerCase()!=="object"){var k=e,l=e.getAttribute("id"),n=l||d,p=e.parentNode,q=/^\s*[+~]/.test(b);l?n=n.replace(/'/g,"\\$&"):e.setAttribute("id",n),q&&p&&(e=e.parentNode);try{if(!q||p)return s(e.querySelectorAll("[id='"+n+"'] "+b),f)}catch(r){}finally{l||k.removeAttribute("id")}}}return a(b,e,f,g)};for(var e in a)m[e]=a[e];b=null}}(),function(){var a=c.documentElement,b=a.matchesSelector||a.mozMatchesSelector||a.webkitMatchesSelector||a.msMatchesSelector;if(b){var d=!b.call(c.createElement("div"),"div"),e=!1;try{b.call(c.documentElement,"[test!='']:sizzle")}catch(f){e=!0}m.matchesSelector=function(a,c){c=c.replace(/\=\s*([^'"\]]*)\s*\]/g,"='$1']");if(!m.isXML(a))try{if(e||!o.match.PSEUDO.test(c)&&!/!=/.test(c)){var f=b.call(a,c);if(f||!d||a.document&&a.document.nodeType!==11)return f}}catch(g){}return m(c,null,null,[a]).length>0}}}(),function(){var a=c.createElement("div");a.innerHTML="<div class='test e'></div><div class='test'></div>";if(!!a.getElementsByClassName&&a.getElementsByClassName("e").length!==0){a.lastChild.className="e";if(a.getElementsByClassName("e").length===1)return;o.order.splice(1,0,"CLASS"),o.find.CLASS=function(a,b,c){if(typeof b.getElementsByClassName!="undefined"&&!c)return b.getElementsByClassName(a[1])},a=null}}(),c.documentElement.contains?m.contains=function(a,b){return a!==b&&(a.contains?a.contains(b):!0)}:c.documentElement.compareDocumentPosition?m.contains=function(a,b){return!!(a.compareDocumentPosition(b)&16)}:m.contains=function(){return!1},m.isXML=function(a){var b=(a?a.ownerDocument||a:0).documentElement;return b?b.nodeName!=="HTML":!1};var y=function(a,b,c){var d,e=[],f="",g=b.nodeType?[b]:b;while(d=o.match.PSEUDO.exec(a))f+=d[0],a=a.replace(o.match.PSEUDO,"");a=o.relative[a]?a+"*":a;for(var h=0,i=g.length;h<i;h++)m(a,g[h],e,c);return m.filter(f,e)};m.attr=f.attr,m.selectors.attrMap={},f.find=m,f.expr=m.selectors,f.expr[":"]=f.expr.filters,f.unique=m.uniqueSort,f.text=m.getText,f.isXMLDoc=m.isXML,f.contains=m.contains}();var L=/Until$/,M=/^(?:parents|prevUntil|prevAll)/,N=/,/,O=/^.[^:#\[\.,]*$/,P=Array.prototype.slice,Q=f.expr.match.globalPOS,R={children:!0,contents:!0,next:!0,prev:!0};f.fn.extend({find:function(a){var b=this,c,d;if(typeof a!="string")return f(a).filter(function(){for(c=0,d=b.length;c<d;c++)if(f.contains(b[c],this))return!0});var e=this.pushStack("","find",a),g,h,i;for(c=0,d=this.length;c<d;c++){g=e.length,f.find(a,this[c],e);if(c>0)for(h=g;h<e.length;h++)for(i=0;i<g;i++)if(e[i]===e[h]){e.splice(h--,1);break}}return e},has:function(a){var b=f(a);return this.filter(function(){for(var a=0,c=b.length;a<c;a++)if(f.contains(this,b[a]))return!0})},not:function(a){return this.pushStack(T(this,a,!1),"not",a)},filter:function(a){return this.pushStack(T(this,a,!0),"filter",a)},is:function(a){return!!a&&(typeof a=="string"?Q.test(a)?f(a,this.context).index(this[0])>=0:f.filter(a,this).length>0:this.filter(a).length>0)},closest:function(a,b){var c=[],d,e,g=this[0];if(f.isArray(a)){var h=1;while(g&&g.ownerDocument&&g!==b){for(d=0;d<a.length;d++)f(g).is(a[d])&&c.push({selector:a[d],elem:g,level:h});g=g.parentNode,h++}return c}var i=Q.test(a)||typeof a!="string"?f(a,b||this.context):0;for(d=0,e=this.length;d<e;d++){g=this[d];while(g){if(i?i.index(g)>-1:f.find.matchesSelector(g,a)){c.push(g);break}g=g.parentNode;if(!g||!g.ownerDocument||g===b||g.nodeType===11)break}}c=c.length>1?f.unique(c):c;return this.pushStack(c,"closest",a)},index:function(a){if(!a)return this[0]&&this[0].parentNode?this.prevAll().length:-1;if(typeof a=="string")return f.inArray(this[0],f(a));return f.inArray(a.jquery?a[0]:a,this)},add:function(a,b){var c=typeof a=="string"?f(a,b):f.makeArray(a&&a.nodeType?[a]:a),d=f.merge(this.get(),c);return this.pushStack(S(c[0])||S(d[0])?d:f.unique(d))},andSelf:function(){return this.add(this.prevObject)}}),f.each({parent:function(a){var b=a.parentNode;return b&&b.nodeType!==11?b:null},parents:function(a){return f.dir(a,"parentNode")},parentsUntil:function(a,b,c){return f.dir(a,"parentNode",c)},next:function(a){return f.nth(a,2,"nextSibling")},prev:function(a){return f.nth(a,2,"previousSibling")},nextAll:function(a){return f.dir(a,"nextSibling")},prevAll:function(a){return f.dir(a,"previousSibling")},nextUntil:function(a,b,c){return f.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return f.dir(a,"previousSibling",c)},siblings:function(a){return f.sibling((a.parentNode||{}).firstChild,a)},children:function(a){return f.sibling(a.firstChild)},contents:function(a){return f.nodeName(a,"iframe")?a.contentDocument||a.contentWindow.document:f.makeArray(a.childNodes)}},function(a,b){f.fn[a]=function(c,d){var e=f.map(this,b,c);L.test(a)||(d=c),d&&typeof d=="string"&&(e=f.filter(d,e)),e=this.length>1&&!R[a]?f.unique(e):e,(this.length>1||N.test(d))&&M.test(a)&&(e=e.reverse());return this.pushStack(e,a,P.call(arguments).join(","))}}),f.extend({filter:function(a,b,c){c&&(a=":not("+a+")");return b.length===1?f.find.matchesSelector(b[0],a)?[b[0]]:[]:f.find.matches(a,b)},dir:function(a,c,d){var e=[],g=a[c];while(g&&g.nodeType!==9&&(d===b||g.nodeType!==1||!f(g).is(d)))g.nodeType===1&&e.push(g),g=g[c];return e},nth:function(a,b,c,d){b=b||1;var e=0;for(;a;a=a[c])if(a.nodeType===1&&++e===b)break;return a},sibling:function(a,b){var c=[];for(;a;a=a.nextSibling)a.nodeType===1&&a!==b&&c.push(a);return c}});var V="abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",W=/ jQuery\d+="(?:\d+|null)"/g,X=/^\s+/,Y=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,Z=/<([\w:]+)/,$=/<tbody/i,_=/<|&#?\w+;/,ba=/<(?:script|style)/i,bb=/<(?:script|object|embed|option|style)/i,bc=new RegExp("<(?:"+V+")[\\s/>]","i"),bd=/checked\s*(?:[^=]|=\s*.checked.)/i,be=/\/(java|ecma)script/i,bf=/^\s*<!(?:\[CDATA\[|\-\-)/,bg={option:[1,"<select multiple='multiple'>","</select>"],legend:[1,"<fieldset>","</fieldset>"],thead:[1,"<table>","</table>"],tr:[2,"<table><tbody>","</tbody></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],area:[1,"<map>","</map>"],_default:[0,"",""]},bh=U(c);bg.optgroup=bg.option,bg.tbody=bg.tfoot=bg.colgroup=bg.caption=bg.thead,bg.th=bg.td,f.support.htmlSerialize||(bg._default=[1,"div<div>","</div>"]),f.fn.extend({text:function(a){return f.access(this,function(a){return a===b?f.text(this):this.empty().append((this[0]&&this[0].ownerDocument||c).createTextNode(a))},null,a,arguments.length)},wrapAll:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapAll(a.call(this,b))});if(this[0]){var b=f(a,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&b.insertBefore(this[0]),b.map(function(){var a=this;while(a.firstChild&&a.firstChild.nodeType===1)a=a.firstChild;return a}).append(this)}return this},wrapInner:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapInner(a.call(this,b))});return this.each(function(){var b=f(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){var b=f.isFunction(a);return this.each(function(c){f(this).wrapAll(b?a.call(this,c):a)})},unwrap:function(){return this.parent().each(function(){f.nodeName(this,"body")||f(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.appendChild(a)})},prepend:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.insertBefore(a,this.firstChild)})},before:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this)});if(arguments.length){var a=f
|
|
.clean(arguments);a.push.apply(a,this.toArray());return this.pushStack(a,"before",arguments)}},after:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this.nextSibling)});if(arguments.length){var a=this.pushStack(this,"after",arguments);a.push.apply(a,f.clean(arguments));return a}},remove:function(a,b){for(var c=0,d;(d=this[c])!=null;c++)if(!a||f.filter(a,[d]).length)!b&&d.nodeType===1&&(f.cleanData(d.getElementsByTagName("*")),f.cleanData([d])),d.parentNode&&d.parentNode.removeChild(d);return this},empty:function(){for(var a=0,b;(b=this[a])!=null;a++){b.nodeType===1&&f.cleanData(b.getElementsByTagName("*"));while(b.firstChild)b.removeChild(b.firstChild)}return this},clone:function(a,b){a=a==null?!1:a,b=b==null?a:b;return this.map(function(){return f.clone(this,a,b)})},html:function(a){return f.access(this,function(a){var c=this[0]||{},d=0,e=this.length;if(a===b)return c.nodeType===1?c.innerHTML.replace(W,""):null;if(typeof a=="string"&&!ba.test(a)&&(f.support.leadingWhitespace||!X.test(a))&&!bg[(Z.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(Y,"<$1></$2>");try{for(;d<e;d++)c=this[d]||{},c.nodeType===1&&(f.cleanData(c.getElementsByTagName("*")),c.innerHTML=a);c=0}catch(g){}}c&&this.empty().append(a)},null,a,arguments.length)},replaceWith:function(a){if(this[0]&&this[0].parentNode){if(f.isFunction(a))return this.each(function(b){var c=f(this),d=c.html();c.replaceWith(a.call(this,b,d))});typeof a!="string"&&(a=f(a).detach());return this.each(function(){var b=this.nextSibling,c=this.parentNode;f(this).remove(),b?f(b).before(a):f(c).append(a)})}return this.length?this.pushStack(f(f.isFunction(a)?a():a),"replaceWith",a):this},detach:function(a){return this.remove(a,!0)},domManip:function(a,c,d){var e,g,h,i,j=a[0],k=[];if(!f.support.checkClone&&arguments.length===3&&typeof j=="string"&&bd.test(j))return this.each(function(){f(this).domManip(a,c,d,!0)});if(f.isFunction(j))return this.each(function(e){var g=f(this);a[0]=j.call(this,e,c?g.html():b),g.domManip(a,c,d)});if(this[0]){i=j&&j.parentNode,f.support.parentNode&&i&&i.nodeType===11&&i.childNodes.length===this.length?e={fragment:i}:e=f.buildFragment(a,this,k),h=e.fragment,h.childNodes.length===1?g=h=h.firstChild:g=h.firstChild;if(g){c=c&&f.nodeName(g,"tr");for(var l=0,m=this.length,n=m-1;l<m;l++)d.call(c?bi(this[l],g):this[l],e.cacheable||m>1&&l<n?f.clone(h,!0,!0):h)}k.length&&f.each(k,function(a,b){b.src?f.ajax({type:"GET",global:!1,url:b.src,async:!1,dataType:"script"}):f.globalEval((b.text||b.textContent||b.innerHTML||"").replace(bf,"/*$0*/")),b.parentNode&&b.parentNode.removeChild(b)})}return this}}),f.buildFragment=function(a,b,d){var e,g,h,i,j=a[0];b&&b[0]&&(i=b[0].ownerDocument||b[0]),i.createDocumentFragment||(i=c),a.length===1&&typeof j=="string"&&j.length<512&&i===c&&j.charAt(0)==="<"&&!bb.test(j)&&(f.support.checkClone||!bd.test(j))&&(f.support.html5Clone||!bc.test(j))&&(g=!0,h=f.fragments[j],h&&h!==1&&(e=h)),e||(e=i.createDocumentFragment(),f.clean(a,i,e,d)),g&&(f.fragments[j]=h?e:1);return{fragment:e,cacheable:g}},f.fragments={},f.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){f.fn[a]=function(c){var d=[],e=f(c),g=this.length===1&&this[0].parentNode;if(g&&g.nodeType===11&&g.childNodes.length===1&&e.length===1){e[b](this[0]);return this}for(var h=0,i=e.length;h<i;h++){var j=(h>0?this.clone(!0):this).get();f(e[h])[b](j),d=d.concat(j)}return this.pushStack(d,a,e.selector)}}),f.extend({clone:function(a,b,c){var d,e,g,h=f.support.html5Clone||f.isXMLDoc(a)||!bc.test("<"+a.nodeName+">")?a.cloneNode(!0):bo(a);if((!f.support.noCloneEvent||!f.support.noCloneChecked)&&(a.nodeType===1||a.nodeType===11)&&!f.isXMLDoc(a)){bk(a,h),d=bl(a),e=bl(h);for(g=0;d[g];++g)e[g]&&bk(d[g],e[g])}if(b){bj(a,h);if(c){d=bl(a),e=bl(h);for(g=0;d[g];++g)bj(d[g],e[g])}}d=e=null;return h},clean:function(a,b,d,e){var g,h,i,j=[];b=b||c,typeof b.createElement=="undefined"&&(b=b.ownerDocument||b[0]&&b[0].ownerDocument||c);for(var k=0,l;(l=a[k])!=null;k++){typeof l=="number"&&(l+="");if(!l)continue;if(typeof l=="string")if(!_.test(l))l=b.createTextNode(l);else{l=l.replace(Y,"<$1></$2>");var m=(Z.exec(l)||["",""])[1].toLowerCase(),n=bg[m]||bg._default,o=n[0],p=b.createElement("div"),q=bh.childNodes,r;b===c?bh.appendChild(p):U(b).appendChild(p),p.innerHTML=n[1]+l+n[2];while(o--)p=p.lastChild;if(!f.support.tbody){var s=$.test(l),t=m==="table"&&!s?p.firstChild&&p.firstChild.childNodes:n[1]==="<table>"&&!s?p.childNodes:[];for(i=t.length-1;i>=0;--i)f.nodeName(t[i],"tbody")&&!t[i].childNodes.length&&t[i].parentNode.removeChild(t[i])}!f.support.leadingWhitespace&&X.test(l)&&p.insertBefore(b.createTextNode(X.exec(l)[0]),p.firstChild),l=p.childNodes,p&&(p.parentNode.removeChild(p),q.length>0&&(r=q[q.length-1],r&&r.parentNode&&r.parentNode.removeChild(r)))}var u;if(!f.support.appendChecked)if(l[0]&&typeof (u=l.length)=="number")for(i=0;i<u;i++)bn(l[i]);else bn(l);l.nodeType?j.push(l):j=f.merge(j,l)}if(d){g=function(a){return!a.type||be.test(a.type)};for(k=0;j[k];k++){h=j[k];if(e&&f.nodeName(h,"script")&&(!h.type||be.test(h.type)))e.push(h.parentNode?h.parentNode.removeChild(h):h);else{if(h.nodeType===1){var v=f.grep(h.getElementsByTagName("script"),g);j.splice.apply(j,[k+1,0].concat(v))}d.appendChild(h)}}}return j},cleanData:function(a){var b,c,d=f.cache,e=f.event.special,g=f.support.deleteExpando;for(var h=0,i;(i=a[h])!=null;h++){if(i.nodeName&&f.noData[i.nodeName.toLowerCase()])continue;c=i[f.expando];if(c){b=d[c];if(b&&b.events){for(var j in b.events)e[j]?f.event.remove(i,j):f.removeEvent(i,j,b.handle);b.handle&&(b.handle.elem=null)}g?delete i[f.expando]:i.removeAttribute&&i.removeAttribute(f.expando),delete d[c]}}}});var bp=/alpha\([^)]*\)/i,bq=/opacity=([^)]*)/,br=/([A-Z]|^ms)/g,bs=/^[\-+]?(?:\d*\.)?\d+$/i,bt=/^-?(?:\d*\.)?\d+(?!px)[^\d\s]+$/i,bu=/^([\-+])=([\-+.\de]+)/,bv=/^margin/,bw={position:"absolute",visibility:"hidden",display:"block"},bx=["Top","Right","Bottom","Left"],by,bz,bA;f.fn.css=function(a,c){return f.access(this,function(a,c,d){return d!==b?f.style(a,c,d):f.css(a,c)},a,c,arguments.length>1)},f.extend({cssHooks:{opacity:{get:function(a,b){if(b){var c=by(a,"opacity");return c===""?"1":c}return a.style.opacity}}},cssNumber:{fillOpacity:!0,fontWeight:!0,lineHeight:!0,opacity:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":f.support.cssFloat?"cssFloat":"styleFloat"},style:function(a,c,d,e){if(!!a&&a.nodeType!==3&&a.nodeType!==8&&!!a.style){var g,h,i=f.camelCase(c),j=a.style,k=f.cssHooks[i];c=f.cssProps[i]||i;if(d===b){if(k&&"get"in k&&(g=k.get(a,!1,e))!==b)return g;return j[c]}h=typeof d,h==="string"&&(g=bu.exec(d))&&(d=+(g[1]+1)*+g[2]+parseFloat(f.css(a,c)),h="number");if(d==null||h==="number"&&isNaN(d))return;h==="number"&&!f.cssNumber[i]&&(d+="px");if(!k||!("set"in k)||(d=k.set(a,d))!==b)try{j[c]=d}catch(l){}}},css:function(a,c,d){var e,g;c=f.camelCase(c),g=f.cssHooks[c],c=f.cssProps[c]||c,c==="cssFloat"&&(c="float");if(g&&"get"in g&&(e=g.get(a,!0,d))!==b)return e;if(by)return by(a,c)},swap:function(a,b,c){var d={},e,f;for(f in b)d[f]=a.style[f],a.style[f]=b[f];e=c.call(a);for(f in b)a.style[f]=d[f];return e}}),f.curCSS=f.css,c.defaultView&&c.defaultView.getComputedStyle&&(bz=function(a,b){var c,d,e,g,h=a.style;b=b.replace(br,"-$1").toLowerCase(),(d=a.ownerDocument.defaultView)&&(e=d.getComputedStyle(a,null))&&(c=e.getPropertyValue(b),c===""&&!f.contains(a.ownerDocument.documentElement,a)&&(c=f.style(a,b))),!f.support.pixelMargin&&e&&bv.test(b)&&bt.test(c)&&(g=h.width,h.width=c,c=e.width,h.width=g);return c}),c.documentElement.currentStyle&&(bA=function(a,b){var c,d,e,f=a.currentStyle&&a.currentStyle[b],g=a.style;f==null&&g&&(e=g[b])&&(f=e),bt.test(f)&&(c=g.left,d=a.runtimeStyle&&a.runtimeStyle.left,d&&(a.runtimeStyle.left=a.currentStyle.left),g.left=b==="fontSize"?"1em":f,f=g.pixelLeft+"px",g.left=c,d&&(a.runtimeStyle.left=d));return f===""?"auto":f}),by=bz||bA,f.each(["height","width"],function(a,b){f.cssHooks[b]={get:function(a,c,d){if(c)return a.offsetWidth!==0?bB(a,b,d):f.swap(a,bw,function(){return bB(a,b,d)})},set:function(a,b){return bs.test(b)?b+"px":b}}}),f.support.opacity||(f.cssHooks.opacity={get:function(a,b){return bq.test((b&&a.currentStyle?a.currentStyle.filter:a.style.filter)||"")?parseFloat(RegExp.$1)/100+"":b?"1":""},set:function(a,b){var c=a.style,d=a.currentStyle,e=f.isNumeric(b)?"alpha(opacity="+b*100+")":"",g=d&&d.filter||c.filter||"";c.zoom=1;if(b>=1&&f.trim(g.replace(bp,""))===""){c.removeAttribute("filter");if(d&&!d.filter)return}c.filter=bp.test(g)?g.replace(bp,e):g+" "+e}}),f(function(){f.support.reliableMarginRight||(f.cssHooks.marginRight={get:function(a,b){return f.swap(a,{display:"inline-block"},function(){return b?by(a,"margin-right"):a.style.marginRight})}})}),f.expr&&f.expr.filters&&(f.expr.filters.hidden=function(a){var b=a.offsetWidth,c=a.offsetHeight;return b===0&&c===0||!f.support.reliableHiddenOffsets&&(a.style&&a.style.display||f.css(a,"display"))==="none"},f.expr.filters.visible=function(a){return!f.expr.filters.hidden(a)}),f.each({margin:"",padding:"",border:"Width"},function(a,b){f.cssHooks[a+b]={expand:function(c){var d,e=typeof c=="string"?c.split(" "):[c],f={};for(d=0;d<4;d++)f[a+bx[d]+b]=e[d]||e[d-2]||e[0];return f}}});var bC=/%20/g,bD=/\[\]$/,bE=/\r?\n/g,bF=/#.*$/,bG=/^(.*?):[ \t]*([^\r\n]*)\r?$/mg,bH=/^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,bI=/^(?:about|app|app\-storage|.+\-extension|file|res|widget):$/,bJ=/^(?:GET|HEAD)$/,bK=/^\/\//,bL=/\?/,bM=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,bN=/^(?:select|textarea)/i,bO=/\s+/,bP=/([?&])_=[^&]*/,bQ=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,bR=f.fn.load,bS={},bT={},bU,bV,bW=["*/"]+["*"];try{bU=e.href}catch(bX){bU=c.createElement("a"),bU.href="",bU=bU.href}bV=bQ.exec(bU.toLowerCase())||[],f.fn.extend({load:function(a,c,d){if(typeof a!="string"&&bR)return bR.apply(this,arguments);if(!this.length)return this;var e=a.indexOf(" ");if(e>=0){var g=a.slice(e,a.length);a=a.slice(0,e)}var h="GET";c&&(f.isFunction(c)?(d=c,c=b):typeof c=="object"&&(c=f.param(c,f.ajaxSettings.traditional),h="POST"));var i=this;f.ajax({url:a,type:h,dataType:"html",data:c,complete:function(a,b,c){c=a.responseText,a.isResolved()&&(a.done(function(a){c=a}),i.html(g?f("<div>").append(c.replace(bM,"")).find(g):c)),d&&i.each(d,[c,b,a])}});return this},serialize:function(){return f.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?f.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||bN.test(this.nodeName)||bH.test(this.type))}).map(function(a,b){var c=f(this).val();return c==null?null:f.isArray(c)?f.map(c,function(a,c){return{name:b.name,value:a.replace(bE,"\r\n")}}):{name:b.name,value:c.replace(bE,"\r\n")}}).get()}}),f.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),function(a,b){f.fn[b]=function(a){return this.on(b,a)}}),f.each(["get","post"],function(a,c){f[c]=function(a,d,e,g){f.isFunction(d)&&(g=g||e,e=d,d=b);return f.ajax({type:c,url:a,data:d,success:e,dataType:g})}}),f.extend({getScript:function(a,c){return f.get(a,b,c,"script")},getJSON:function(a,b,c){return f.get(a,b,c,"json")},ajaxSetup:function(a,b){b?b$(a,f.ajaxSettings):(b=a,a=f.ajaxSettings),b$(a,b);return a},ajaxSettings:{url:bU,isLocal:bI.test(bV[1]),global:!0,type:"GET",contentType:"application/x-www-form-urlencoded; charset=UTF-8",processData:!0,async:!0,accepts:{xml:"application/xml, text/xml",html:"text/html",text:"text/plain",json:"application/json, text/javascript","*":bW},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText"},converters:{"* text":a.String,"text html":!0,"text json":f.parseJSON,"text xml":f.parseXML},flatOptions:{context:!0,url:!0}},ajaxPrefilter:bY(bS),ajaxTransport:bY(bT),ajax:function(a,c){function w(a,c,l,m){if(s!==2){s=2,q&&clearTimeout(q),p=b,n=m||"",v.readyState=a>0?4:0;var o,r,u,w=c,x=l?ca(d,v,l):b,y,z;if(a>=200&&a<300||a===304){if(d.ifModified){if(y=v.getResponseHeader("Last-Modified"))f.lastModified[k]=y;if(z=v.getResponseHeader("Etag"))f.etag[k]=z}if(a===304)w="notmodified",o=!0;else try{r=cb(d,x),w="success",o=!0}catch(A){w="parsererror",u=A}}else{u=w;if(!w||a)w="error",a<0&&(a=0)}v.status=a,v.statusText=""+(c||w),o?h.resolveWith(e,[r,w,v]):h.rejectWith(e,[v,w,u]),v.statusCode(j),j=b,t&&g.trigger("ajax"+(o?"Success":"Error"),[v,d,o?r:u]),i.fireWith(e,[v,w]),t&&(g.trigger("ajaxComplete",[v,d]),--f.active||f.event.trigger("ajaxStop"))}}typeof a=="object"&&(c=a,a=b),c=c||{};var d=f.ajaxSetup({},c),e=d.context||d,g=e!==d&&(e.nodeType||e instanceof f)?f(e):f.event,h=f.Deferred(),i=f.Callbacks("once memory"),j=d.statusCode||{},k,l={},m={},n,o,p,q,r,s=0,t,u,v={readyState:0,setRequestHeader:function(a,b){if(!s){var c=a.toLowerCase();a=m[c]=m[c]||a,l[a]=b}return this},getAllResponseHeaders:function(){return s===2?n:null},getResponseHeader:function(a){var c;if(s===2){if(!o){o={};while(c=bG.exec(n))o[c[1].toLowerCase()]=c[2]}c=o[a.toLowerCase()]}return c===b?null:c},overrideMimeType:function(a){s||(d.mimeType=a);return this},abort:function(a){a=a||"abort",p&&p.abort(a),w(0,a);return this}};h.promise(v),v.success=v.done,v.error=v.fail,v.complete=i.add,v.statusCode=function(a){if(a){var b;if(s<2)for(b in a)j[b]=[j[b],a[b]];else b=a[v.status],v.then(b,b)}return this},d.url=((a||d.url)+"").replace(bF,"").replace(bK,bV[1]+"//"),d.dataTypes=f.trim(d.dataType||"*").toLowerCase().split(bO),d.crossDomain==null&&(r=bQ.exec(d.url.toLowerCase()),d.crossDomain=!(!r||r[1]==bV[1]&&r[2]==bV[2]&&(r[3]||(r[1]==="http:"?80:443))==(bV[3]||(bV[1]==="http:"?80:443)))),d.data&&d.processData&&typeof d.data!="string"&&(d.data=f.param(d.data,d.traditional)),bZ(bS,d,c,v);if(s===2)return!1;t=d.global,d.type=d.type.toUpperCase(),d.hasContent=!bJ.test(d.type),t&&f.active++===0&&f.event.trigger("ajaxStart");if(!d.hasContent){d.data&&(d.url+=(bL.test(d.url)?"&":"?")+d.data,delete d.data),k=d.url;if(d.cache===!1){var x=f.now(),y=d.url.replace(bP,"$1_="+x);d.url=y+(y===d.url?(bL.test(d.url)?"&":"?")+"_="+x:"")}}(d.data&&d.hasContent&&d.contentType!==!1||c.contentType)&&v.setRequestHeader("Content-Type",d.contentType),d.ifModified&&(k=k||d.url,f.lastModified[k]&&v.setRequestHeader("If-Modified-Since",f.lastModified[k]),f.etag[k]&&v.setRequestHeader("If-None-Match",f.etag[k])),v.setRequestHeader("Accept",d.dataTypes[0]&&d.accepts[d.dataTypes[0]]?d.accepts[d.dataTypes[0]]+(d.dataTypes[0]!=="*"?", "+bW+"; q=0.01":""):d.accepts["*"]);for(u in d.headers)v.setRequestHeader(u,d.headers[u]);if(d.beforeSend&&(d.beforeSend.call(e,v,d)===!1||s===2)){v.abort();return!1}for(u in{success:1,error:1,complete:1})v[u](d[u]);p=bZ(bT,d,c,v);if(!p)w(-1,"No Transport");else{v.readyState=1,t&&g.trigger("ajaxSend",[v,d]),d.async&&d.timeout>0&&(q=setTimeout(function(){v.abort("timeout")},d.timeout));try{s=1,p.send(l,w)}catch(z){if(s<2)w(-1,z);else throw z}}return v},param:function(a,c){var d=[],e=function(a,b){b=f.isFunction(b)?b():b,d[d.length]=encodeURIComponent(a)+"="+encodeURIComponent(b)};c===b&&(c=f.ajaxSettings.traditional);if(f.isArray(a)||a.jquery&&!f.isPlainObject(a))f.each(a,function(){e(this.name,this.value)});else for(var g in a)b_(g,a[g],c,e);return d.join("&").replace(bC,"+")}}),f.extend({active:0,lastModified:{},etag:{}});var cc=f.now(),cd=/(\=)\?(&|$)|\?\?/i;f.ajaxSetup({jsonp:"callback",jsonpCallback:function(){return f.expando+"_"+cc++}}),f.ajaxPrefilter("json jsonp",function(b,c,d){var e=typeof b.data=="string"&&/^application\/x\-www\-form\-urlencoded/.test(b.contentType);if(b.dataTypes[0]==="jsonp"||b.jsonp!==!1&&(cd.test(b.url)||e&&cd.test(b.data))){var g,h=b.jsonpCallback=f.isFunction(b.jsonpCallback)?b.jsonpCallback():b.jsonpCallback,i=a[h],j=b.url,k=b.data,l="$1"+h+"$2";b.jsonp!==!1&&(j=j.replace(cd,l),b.url===j&&(e&&(k=k.replace(cd,l)),b.data===k&&(j+=(/\?/.test(j)?"&":"?")+b.jsonp+"="+h))),b.url=j,b.data=k,a[h]=function(a){g=[a]},d.always(function(){a[h]=i,g&&f.isFunction(i)&&a[h](g[0])}),b.converters["script json"]=function(){g||f.error(h+" was not called");return g[0]},b.dataTypes[0]="json";return"script"}}),f.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/javascript|ecmascript/},converters:{"text script":function(a){f.globalEval(a);return a}}}),f.ajaxPrefilter("script",function(a){a.cache===b&&(a.cache=!1),a.crossDomain&&(a.type="GET",a.global=!1)}),f.ajaxTransport("script",function(a){if(a.crossDomain){var d,e=c.head||c.getElementsByTagName("head")[0]||c.documentElement;return{send:function(f,g){d=c.createElement("script"),d.async="async",a.scriptCharset&&(d.charset=a.scriptCharset),d.src=a.url,d.onload=d.onreadystatechange=function(a,c){if(c||!d.readyState||/loaded|complete/.test(d.readyState))d.onload=d.onreadystatechange=null,e&&d.parentNode&&e.removeChild(d),d=b,c||g(200,"success")},e.insertBefore(d,e.firstChild)},abort:function(){d&&d.onload(0,1)}}}});var ce=a.ActiveXObject?function(){for(var a in cg)cg[a](0,1)}:!1,cf=0,cg;f.ajaxSettings.xhr=a.ActiveXObject?function(){return!this.isLocal&&ch()||ci()}:ch,function(a){f.extend(f.support,{ajax:!!a,cors:!!a&&"withCredentials"in a})}(f.ajaxSettings.xhr()),f.support.ajax&&f.ajaxTransport(function(c){if(!c.crossDomain||f.support.cors){var d;return{send:function(e,g){var h=c.xhr(),i,j;c.username?h.open(c.type,c.url,c.async,c.username,c.password):h.open(c.type,c.url,c.async);if(c.xhrFields)for(j in c.xhrFields)h[j]=c.xhrFields[j];c.mimeType&&h.overrideMimeType&&h.overrideMimeType(c.mimeType),!c.crossDomain&&!e["X-Requested-With"]&&(e["X-Requested-With"]="XMLHttpRequest");try{for(j in e)h.setRequestHeader(j,e[j])}catch(k){}h.send(c.hasContent&&c.data||null),d=function(a,e){var j,k,l,m,n;try{if(d&&(e||h.readyState===4)){d=b,i&&(h.onreadystatechange=f.noop,ce&&delete cg[i]);if(e)h.readyState!==4&&h.abort();else{j=h.status,l=h.getAllResponseHeaders(),m={},n=h.responseXML,n&&n.documentElement&&(m.xml=n);try{m.text=h.responseText}catch(a){}try{k=h.statusText}catch(o){k=""}!j&&c.isLocal&&!c.crossDomain?j=m.text?200:404:j===1223&&(j=204)}}}catch(p){e||g(-1,p)}m&&g(j,k,m,l)},!c.async||h.readyState===4?d():(i=++cf,ce&&(cg||(cg={},f(a).unload(ce)),cg[i]=d),h.onreadystatechange=d)},abort:function(){d&&d(0,1)}}}});var cj={},ck,cl,cm=/^(?:toggle|show|hide)$/,cn=/^([+\-]=)?([\d+.\-]+)([a-z%]*)$/i,co,cp=[["height","marginTop","marginBottom","paddingTop","paddingBottom"],["width","marginLeft","marginRight","paddingLeft","paddingRight"],["opacity"]],cq;f.fn.extend({show:function(a,b,c){var d,e;if(a||a===0)return this.animate(ct("show",3),a,b,c);for(var g=0,h=this.length;g<h;g++)d=this[g],d.style&&(e=d.style.display,!f._data(d,"olddisplay")&&e==="none"&&(e=d.style.display=""),(e===""&&f.css(d,"display")==="none"||!f.contains(d.ownerDocument.documentElement,d))&&f._data(d,"olddisplay",cu(d.nodeName)));for(g=0;g<h;g++){d=this[g];if(d.style){e=d.style.display;if(e===""||e==="none")d.style.display=f._data(d,"olddisplay")||""}}return this},hide:function(a,b,c){if(a||a===0)return this.animate(ct("hide",3),a,b,c);var d,e,g=0,h=this.length;for(;g<h;g++)d=this[g],d.style&&(e=f.css(d,"display"),e!=="none"&&!f._data(d,"olddisplay")&&f._data(d,"olddisplay",e));for(g=0;g<h;g++)this[g].style&&(this[g].style.display="none");return this},_toggle:f.fn.toggle,toggle:function(a,b,c){var d=typeof a=="boolean";f.isFunction(a)&&f.isFunction(b)?this._toggle.apply(this,arguments):a==null||d?this.each(function(){var b=d?a:f(this).is(":hidden");f(this)[b?"show":"hide"]()}):this.animate(ct("toggle",3),a,b,c);return this},fadeTo:function(a,b,c,d){return this.filter(":hidden").css("opacity",0).show().end().animate({opacity:b},a,c,d)},animate:function(a,b,c,d){function g(){e.queue===!1&&f._mark(this);var b=f.extend({},e),c=this.nodeType===1,d=c&&f(this).is(":hidden"),g,h,i,j,k,l,m,n,o,p,q;b.animatedProperties={};for(i in a){g=f.camelCase(i),i!==g&&(a[g]=a[i],delete a[i]);if((k=f.cssHooks[g])&&"expand"in k){l=k.expand(a[g]),delete a[g];for(i in l)i in a||(a[i]=l[i])}}for(g in a){h=a[g],f.isArray(h)?(b.animatedProperties[g]=h[1],h=a[g]=h[0]):b.animatedProperties[g]=b.specialEasing&&b.specialEasing[g]||b.easing||"swing";if(h==="hide"&&d||h==="show"&&!d)return b.complete.call(this);c&&(g==="height"||g==="width")&&(b.overflow=[this.style.overflow,this.style.overflowX,this.style.overflowY],f.css(this,"display")==="inline"&&f.css(this,"float")==="none"&&(!f.support.inlineBlockNeedsLayout||cu(this.nodeName)==="inline"?this.style.display="inline-block":this.style.zoom=1))}b.overflow!=null&&(this.style.overflow="hidden");for(i in a)j=new f.fx(this,b,i),h=a[i],cm.test(h)?(q=f._data(this,"toggle"+i)||(h==="toggle"?d?"show":"hide":0),q?(f._data(this,"toggle"+i,q==="show"?"hide":"show"),j[q]()):j[h]()):(m=cn.exec(h),n=j.cur(),m?(o=parseFloat(m[2]),p=m[3]||(f.cssNumber[i]?"":"px"),p!=="px"&&(f.style(this,i,(o||1)+p),n=(o||1)/j.cur()*n,f.style(this,i,n+p)),m[1]&&(o=(m[1]==="-="?-1:1)*o+n),j.custom(n,o,p)):j.custom(n,h,""));return!0}var e=f.speed(b,c,d);if(f.isEmptyObject(a))return this.each(e.complete,[!1]);a=f.extend({},a);return e.queue===!1?this.each(g):this.queue(e.queue,g)},stop:function(a,c,d){typeof a!="string"&&(d=c,c=a,a=b),c&&a!==!1&&this.queue(a||"fx",[]);return this.each(function(){function h(a,b,c){var e=b[c];f.removeData(a,c,!0),e.stop(d)}var b,c=!1,e=f.timers,g=f._data(this);d||f._unmark(!0,this);if(a==null)for(b in g)g[b]&&g[b].stop&&b.indexOf(".run")===b.length-4&&h(this,g,b);else g[b=a+".run"]&&g[b].stop&&h(this,g,b);for(b=e.length;b--;)e[b].elem===this&&(a==null||e[b].queue===a)&&(d?e[b](!0):e[b].saveState(),c=!0,e.splice(b,1));(!d||!c)&&f.dequeue(this,a)})}}),f.each({slideDown:ct("show",1),slideUp:ct("hide",1),slideToggle:ct("toggle",1),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(a,b){f.fn[a]=function(a,c,d){return this.animate(b,a,c,d)}}),f.extend({speed:function(a,b,c){var d=a&&typeof a=="object"?f.extend({},a):{complete:c||!c&&b||f.isFunction(a)&&a,duration:a,easing:c&&b||b&&!f.isFunction(b)&&b};d.duration=f.fx.off?0:typeof d.duration=="number"?d.duration:d.duration in f.fx.speeds?f.fx.speeds[d.duration]:f.fx.speeds._default;if(d.queue==null||d.queue===!0)d.queue="fx";d.old=d.complete,d.complete=function(a){f.isFunction(d.old)&&d.old.call(this),d.queue?f.dequeue(this,d.queue):a!==!1&&f._unmark(this)};return d},easing:{linear:function(a){return a},swing:function(a){return-Math.cos(a*Math.PI)/2+.5}},timers:[],fx:function(a,b,c){this.options=b,this.elem=a,this.prop=c,b.orig=b.orig||{}}}),f.fx.prototype={update:function(){this.options.step&&this.options.step.call(this.elem,this.now,this),(f.fx.step[this.prop]||f.fx.step._default)(this)},cur:function(){if(this.elem[this.prop]!=null&&(!this.elem.style||this.elem.style[this.prop]==null))return this.elem[this.prop];var a,b=f.css(this.elem,this.prop);return isNaN(a=parseFloat(b))?!b||b==="auto"?0:b:a},custom:function(a,c,d){function h(a){return e.step(a)}var e=this,g=f.fx;this.startTime=cq||cr(),this.end=c,this.now=this.start=a,this.pos=this.state=0,this.unit=d||this.unit||(f.cssNumber[this.prop]?"":"px"),h.queue=this.options.queue,h.elem=this.elem,h.saveState=function(){f._data(e.elem,"fxshow"+e.prop)===b&&(e.options.hide?f._data(e.elem,"fxshow"+e.prop,e.start):e.options.show&&f._data(e.elem,"fxshow"+e.prop,e.end))},h()&&f.timers.push(h)&&!co&&(co=setInterval(g.tick,g.interval))},show:function(){var a=f._data(this.elem,"fxshow"+this.prop);this.options.orig[this.prop]=a||f.style(this.elem,this.prop),this.options.show=!0,a!==b?this.custom(this.cur(),a):this.custom(this.prop==="width"||this.prop==="height"?1:0,this.cur()),f(this.elem).show()},hide:function(){this.options.orig[this.prop]=f._data(this.elem,"fxshow"+this.prop)||f.style(this.elem,this.prop),this.options.hide=!0,this.custom(this.cur(),0)},step:function(a){var b,c,d,e=cq||cr(),g=!0,h=this.elem,i=this.options;if(a||e>=i.duration+this.startTime){this.now=this.end,this.pos=this.state=1,this.update(),i.animatedProperties[this.prop]=!0;for(b in i.animatedProperties)i.animatedProperties[b]!==!0&&(g=!1);if(g){i.overflow!=null&&!f.support.shrinkWrapBlocks&&f.each(["","X","Y"],function(a,b){h.style["overflow"+b]=i.overflow[a]}),i.hide&&f(h).hide();if(i.hide||i.show)for(b in i.animatedProperties)f.style(h,b,i.orig[b]),f.removeData(h,"fxshow"+b,!0),f.removeData(h,"toggle"+b,!0);d=i.complete,d&&(i.complete=!1,d.call(h))}return!1}i.duration==Infinity?this.now=e:(c=e-this.startTime,this.state=c/i.duration,this.pos=f.easing[i.animatedProperties[this.prop]](this.state,c,0,1,i.duration),this.now=this.start+(this.end-this.start)*this.pos),this.update();return!0}},f.extend(f.fx,{tick:function(){var a,b=f.timers,c=0;for(;c<b.length;c++)a=b[c],!a()&&b[c]===a&&b.splice(c--,1);b.length||f.fx.stop()},interval:13,stop:function(){clearInterval(co),co=null},speeds:{slow:600,fast:200,_default:400},step:{opacity:function(a){f.style(a.elem,"opacity",a.now)},_default:function(a){a.elem.style&&a.elem.style[a.prop]!=null?a.elem.style[a.prop]=a.now+a.unit:a.elem[a.prop]=a.now}}}),f.each(cp.concat.apply([],cp),function(a,b){b.indexOf("margin")&&(f.fx.step[b]=function(a){f.style(a.elem,b,Math.max(0,a.now)+a.unit)})}),f.expr&&f.expr.filters&&(f.expr.filters.animated=function(a){return f.grep(f.timers,function(b){return a===b.elem}).length});var cv,cw=/^t(?:able|d|h)$/i,cx=/^(?:body|html)$/i;"getBoundingClientRect"in c.documentElement?cv=function(a,b,c,d){try{d=a.getBoundingClientRect()}catch(e){}if(!d||!f.contains(c,a))return d?{top:d.top,left:d.left}:{top:0,left:0};var g=b.body,h=cy(b),i=c.clientTop||g.clientTop||0,j=c.clientLeft||g.clientLeft||0,k=h.pageYOffset||f.support.boxModel&&c.scrollTop||g.scrollTop,l=h.pageXOffset||f.support.boxModel&&c.scrollLeft||g.scrollLeft,m=d.top+k-i,n=d.left+l-j;return{top:m,left:n}}:cv=function(a,b,c){var d,e=a.offsetParent,g=a,h=b.body,i=b.defaultView,j=i?i.getComputedStyle(a,null):a.currentStyle,k=a.offsetTop,l=a.offsetLeft;while((a=a.parentNode)&&a!==h&&a!==c){if(f.support.fixedPosition&&j.position==="fixed")break;d=i?i.getComputedStyle(a,null):a.currentStyle,k-=a.scrollTop,l-=a.scrollLeft,a===e&&(k+=a.offsetTop,l+=a.offsetLeft,f.support.doesNotAddBorder&&(!f.support.doesAddBorderForTableAndCells||!cw.test(a.nodeName))&&(k+=parseFloat(d.borderTopWidth)||0,l+=parseFloat(d.borderLeftWidth)||0),g=e,e=a.offsetParent),f.support.subtractsBorderForOverflowNotVisible&&d.overflow!=="visible"&&(k+=parseFloat(d.borderTopWidth)||0,l+=parseFloat(d.borderLeftWidth)||0),j=d}if(j.position==="relative"||j.position==="static")k+=h.offsetTop,l+=h.offsetLeft;f.support.fixedPosition&&j.position==="fixed"&&(k+=Math.max(c.scrollTop,h.scrollTop),l+=Math.max(c.scrollLeft,h.scrollLeft));return{top:k,left:l}},f.fn.offset=function(a){if(arguments.length)return a===b?this:this.each(function(b){f.offset.setOffset(this,a,b)});var c=this[0],d=c&&c.ownerDocument;if(!d)return null;if(c===d.body)return f.offset.bodyOffset(c);return cv(c,d,d.documentElement)},f.offset={bodyOffset:function(a){var b=a.offsetTop,c=a.offsetLeft;f.support.doesNotIncludeMarginInBodyOffset&&(b+=parseFloat(f.css(a,"marginTop"))||0,c+=parseFloat(f.css(a,"marginLeft"))||0);return{top:b,left:c}},setOffset:function(a,b,c){var d=f.css(a,"position");d==="static"&&(a.style.position="relative");var e=f(a),g=e.offset(),h=f.css(a,"top"),i=f.css(a,"left"),j=(d==="absolute"||d==="fixed")&&f.inArray("auto",[h,i])>-1,k={},l={},m,n;j?(l=e.position(),m=l.top,n=l.left):(m=parseFloat(h)||0,n=parseFloat(i)||0),f.isFunction(b)&&(b=b.call(a,c,g)),b.top!=null&&(k.top=b.top-g.top+m),b.left!=null&&(k.left=b.left-g.left+n),"using"in b?b.using.call(a,k):e.css(k)}},f.fn.extend({position:function(){if(!this[0])return null;var a=this[0],b=this.offsetParent(),c=this.offset(),d=cx.test(b[0].nodeName)?{top:0,left:0}:b.offset();c.top-=parseFloat(f.css(a,"marginTop"))||0,c.left-=parseFloat(f.css(a,"marginLeft"))||0,d.top+=parseFloat(f.css(b[0],"borderTopWidth"))||0,d.left+=parseFloat(f.css(b[0],"borderLeftWidth"))||0;return{top:c.top-d.top,left:c.left-d.left}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||c.body;while(a&&!cx.test(a.nodeName)&&f.css(a,"position")==="static")a=a.offsetParent;return a})}}),f.each({scrollLeft:"pageXOffset",scrollTop:"pageYOffset"},function(a,c){var d=/Y/.test(c);f.fn[a]=function(e){return f.access(this,function(a,e,g){var h=cy(a);if(g===b)return h?c in h?h[c]:f.support.boxModel&&h.document.documentElement[e]||h.document.body[e]:a[e];h?h.scrollTo(d?f(h).scrollLeft():g,d?g:f(h).scrollTop()):a[e]=g},a,e,arguments.length,null)}}),f.each({Height:"height",Width:"width"},function(a,c){var d="client"+a,e="scroll"+a,g="offset"+a;f.fn["inner"+a]=function(){var a=this[0];return a?a.style?parseFloat(f.css(a,c,"padding")):this[c]():null},f.fn["outer"+a]=function(a){var b=this[0];return b?b.style?parseFloat(f.css(b,c,a?"margin":"border")):this[c]():null},f.fn[c]=function(a){return f.access(this,function(a,c,h){var i,j,k,l;if(f.isWindow(a)){i=a.document,j=i.documentElement[d];return f.support.boxModel&&j||i.body&&i.body[d]||j}if(a.nodeType===9){i=a.documentElement;if(i[d]>=i[e])return i[d];return Math.max(a.body[e],i[e],a.body[g],i[g])}if(h===b){k=f.css(a,c),l=parseFloat(k);return f.isNumeric(l)?l:k}f(a).css(c,h)},c,a,arguments.length,null)}}),a.jQuery=a.$=f,typeof define=="function"&&define.amd&&define.amd.jQuery&&define("jquery",[],function(){return f})})(window);
|
|
// vim: ts=4 sts=4 sw=4 expandtab
|
|
// -- kriskowal Kris Kowal Copyright (C) 2009-2011 MIT License
|
|
// -- tlrobinson Tom Robinson Copyright (C) 2009-2010 MIT License (Narwhal Project)
|
|
// -- dantman Daniel Friesen Copyright (C) 2010 XXX TODO License or CLA
|
|
// -- fschaefer Florian Schäfer Copyright (C) 2010 MIT License
|
|
// -- Gozala Irakli Gozalishvili Copyright (C) 2010 MIT License
|
|
// -- kitcambridge Kit Cambridge Copyright (C) 2011 MIT License
|
|
// -- kossnocorp Sasha Koss XXX TODO License or CLA
|
|
// -- bryanforbes Bryan Forbes XXX TODO License or CLA
|
|
// -- killdream Quildreen Motta Copyright (C) 2011 MIT Licence
|
|
// -- michaelficarra Michael Ficarra Copyright (C) 2011 3-clause BSD License
|
|
// -- sharkbrainguy Gerard Paapu Copyright (C) 2011 MIT License
|
|
// -- bbqsrc Brendan Molloy XXX TODO License or CLA
|
|
// -- iwyg XXX TODO License or CLA
|
|
// -- DomenicDenicola Domenic Denicola XXX TODO License or CLA
|
|
// -- xavierm02 Montillet Xavier XXX TODO License or CLA
|
|
// -- Raynos Raynos XXX TODO License or CLA
|
|
// -- samsonjs Sami Samhuri XXX TODO License or CLA
|
|
// -- rwldrn Rick Waldron Copyright (C) 2011 MIT License
|
|
// -- lexer Alexey Zakharov XXX TODO License or CLA
|
|
|
|
/*!
|
|
Copyright (c) 2009, 280 North Inc. http://280north.com/
|
|
MIT License. http://github.com/280north/narwhal/blob/master/README.md
|
|
*/
|
|
|
|
// Module systems magic dance
|
|
(function (definition) {
|
|
// RequireJS
|
|
if (typeof define == "function") {
|
|
define(definition);
|
|
// CommonJS and <script>
|
|
} else {
|
|
definition();
|
|
}
|
|
})(function () {
|
|
|
|
/**
|
|
* Brings an environment as close to ECMAScript 5 compliance
|
|
* as is possible with the facilities of erstwhile engines.
|
|
*
|
|
* ES5 Draft
|
|
* http://www.ecma-international.org/publications/files/drafts/tc39-2009-050.pdf
|
|
*
|
|
* NOTE: this is a draft, and as such, the URL is subject to change. If the
|
|
* link is broken, check in the parent directory for the latest TC39 PDF.
|
|
* http://www.ecma-international.org/publications/files/drafts/
|
|
*
|
|
* Previous ES5 Draft
|
|
* http://www.ecma-international.org/publications/files/drafts/tc39-2009-025.pdf
|
|
* This is a broken link to the previous draft of ES5 on which most of the
|
|
* numbered specification references and quotes herein were taken. Updating
|
|
* these references and quotes to reflect the new document would be a welcome
|
|
* volunteer project.
|
|
*
|
|
* @module
|
|
*/
|
|
|
|
/*whatsupdoc*/
|
|
|
|
//
|
|
// Function
|
|
// ========
|
|
//
|
|
|
|
// ES-5 15.3.4.5
|
|
// http://www.ecma-international.org/publications/files/drafts/tc39-2009-025.pdf
|
|
|
|
if (!Function.prototype.bind) {
|
|
Function.prototype.bind = function bind(that) { // .length is 1
|
|
// 1. Let Target be the this value.
|
|
var target = this;
|
|
// 2. If IsCallable(Target) is false, throw a TypeError exception.
|
|
if (typeof target != "function")
|
|
throw new TypeError(); // TODO message
|
|
// 3. Let A be a new (possibly empty) internal list of all of the
|
|
// argument values provided after thisArg (arg1, arg2 etc), in order.
|
|
// XXX slicedArgs will stand in for "A" if used
|
|
var args = slice.call(arguments, 1); // for normal call
|
|
// 4. Let F be a new native ECMAScript object.
|
|
// 9. Set the [[Prototype]] internal property of F to the standard
|
|
// built-in Function prototype object as specified in 15.3.3.1.
|
|
// 10. Set the [[Call]] internal property of F as described in
|
|
// 15.3.4.5.1.
|
|
// 11. Set the [[Construct]] internal property of F as described in
|
|
// 15.3.4.5.2.
|
|
// 12. Set the [[HasInstance]] internal property of F as described in
|
|
// 15.3.4.5.3.
|
|
// 13. The [[Scope]] internal property of F is unused and need not
|
|
// exist.
|
|
var bound = function () {
|
|
|
|
if (this instanceof bound) {
|
|
// 15.3.4.5.2 [[Construct]]
|
|
// When the [[Construct]] internal method of a function object,
|
|
// F that was created using the bind function is called with a
|
|
// list of arguments ExtraArgs the following steps are taken:
|
|
// 1. Let target be the value of F's [[TargetFunction]]
|
|
// internal property.
|
|
// 2. If target has no [[Construct]] internal method, a
|
|
// TypeError exception is thrown.
|
|
// 3. Let boundArgs be the value of F's [[BoundArgs]] internal
|
|
// property.
|
|
// 4. Let args be a new list containing the same values as the
|
|
// list boundArgs in the same order followed by the same
|
|
// values as the list ExtraArgs in the same order.
|
|
|
|
var F = function(){};
|
|
F.prototype = target.prototype;
|
|
var self = new F;
|
|
|
|
var result = target.apply(
|
|
self,
|
|
args.concat(slice.call(arguments))
|
|
);
|
|
if (result !== null && Object(result) === result)
|
|
return result;
|
|
return self;
|
|
|
|
} else {
|
|
// 15.3.4.5.1 [[Call]]
|
|
// When the [[Call]] internal method of a function object, F,
|
|
// which was created using the bind function is called with a
|
|
// this value and a list of arguments ExtraArgs the following
|
|
// steps are taken:
|
|
// 1. Let boundArgs be the value of F's [[BoundArgs]] internal
|
|
// property.
|
|
// 2. Let boundThis be the value of F's [[BoundThis]] internal
|
|
// property.
|
|
// 3. Let target be the value of F's [[TargetFunction]] internal
|
|
// property.
|
|
// 4. Let args be a new list containing the same values as the list
|
|
// boundArgs in the same order followed by the same values as
|
|
// the list ExtraArgs in the same order. 5. Return the
|
|
// result of calling the [[Call]] internal method of target
|
|
// providing boundThis as the this value and providing args
|
|
// as the arguments.
|
|
|
|
// equiv: target.call(this, ...boundArgs, ...args)
|
|
return target.apply(
|
|
that,
|
|
args.concat(slice.call(arguments))
|
|
);
|
|
|
|
}
|
|
|
|
};
|
|
// XXX bound.length is never writable, so don't even try
|
|
//
|
|
// 16. The length own property of F is given attributes as specified in
|
|
// 15.3.5.1.
|
|
// TODO
|
|
// 17. Set the [[Extensible]] internal property of F to true.
|
|
// TODO
|
|
// 18. Call the [[DefineOwnProperty]] internal method of F with
|
|
// arguments "caller", PropertyDescriptor {[[Value]]: null,
|
|
// [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]:
|
|
// false}, and false.
|
|
// TODO
|
|
// 19. Call the [[DefineOwnProperty]] internal method of F with
|
|
// arguments "arguments", PropertyDescriptor {[[Value]]: null,
|
|
// [[Writable]]: false, [[Enumerable]]: false, [[Configurable]]:
|
|
// false}, and false.
|
|
// TODO
|
|
// NOTE Function objects created using Function.prototype.bind do not
|
|
// have a prototype property.
|
|
// XXX can't delete it in pure-js.
|
|
return bound;
|
|
};
|
|
}
|
|
|
|
// Shortcut to an often accessed properties, in order to avoid multiple
|
|
// dereference that costs universally.
|
|
// _Please note: Shortcuts are defined after `Function.prototype.bind` as we
|
|
// us it in defining shortcuts.
|
|
var call = Function.prototype.call;
|
|
var prototypeOfArray = Array.prototype;
|
|
var prototypeOfObject = Object.prototype;
|
|
var slice = prototypeOfArray.slice;
|
|
var toString = call.bind(prototypeOfObject.toString);
|
|
var owns = call.bind(prototypeOfObject.hasOwnProperty);
|
|
|
|
// If JS engine supports accessors creating shortcuts.
|
|
var defineGetter;
|
|
var defineSetter;
|
|
var lookupGetter;
|
|
var lookupSetter;
|
|
var supportsAccessors;
|
|
if ((supportsAccessors = owns(prototypeOfObject, "__defineGetter__"))) {
|
|
defineGetter = call.bind(prototypeOfObject.__defineGetter__);
|
|
defineSetter = call.bind(prototypeOfObject.__defineSetter__);
|
|
lookupGetter = call.bind(prototypeOfObject.__lookupGetter__);
|
|
lookupSetter = call.bind(prototypeOfObject.__lookupSetter__);
|
|
}
|
|
|
|
//
|
|
// Array
|
|
// =====
|
|
//
|
|
|
|
// ES5 15.4.3.2
|
|
if (!Array.isArray) {
|
|
Array.isArray = function isArray(obj) {
|
|
return toString(obj) == "[object Array]";
|
|
};
|
|
}
|
|
|
|
// The IsCallable() check in the Array functions
|
|
// has been replaced with a strict check on the
|
|
// internal class of the object to trap cases where
|
|
// the provided function was actually a regular
|
|
// expression literal, which in V8 and
|
|
// JavaScriptCore is a typeof "function". Only in
|
|
// V8 are regular expression literals permitted as
|
|
// reduce parameters, so it is desirable in the
|
|
// general case for the shim to match the more
|
|
// strict and common behavior of rejecting regular
|
|
// expressions.
|
|
|
|
// ES5 15.4.4.18
|
|
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/array/foreach
|
|
if (!Array.prototype.forEach) {
|
|
Array.prototype.forEach = function forEach(fun /*, thisp*/) {
|
|
var self = toObject(this),
|
|
thisp = arguments[1],
|
|
i = 0,
|
|
length = self.length >>> 0;
|
|
|
|
// If no callback function or if callback is not a callable function
|
|
if (toString(fun) != "[object Function]") {
|
|
throw new TypeError(); // TODO message
|
|
}
|
|
|
|
while (i < length) {
|
|
if (i in self) {
|
|
// Invoke the callback function with call, passing arguments:
|
|
// context, property value, property key, thisArg object context
|
|
fun.call(thisp, self[i], i, self);
|
|
}
|
|
i++;
|
|
}
|
|
};
|
|
}
|
|
|
|
// ES5 15.4.4.19
|
|
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/map
|
|
if (!Array.prototype.map) {
|
|
Array.prototype.map = function map(fun /*, thisp*/) {
|
|
var self = toObject(this),
|
|
length = self.length >>> 0,
|
|
result = Array(length),
|
|
thisp = arguments[1];
|
|
|
|
// If no callback function or if callback is not a callable function
|
|
if (toString(fun) != "[object Function]") {
|
|
throw new TypeError(); // TODO message
|
|
}
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
if (i in self)
|
|
result[i] = fun.call(thisp, self[i], i, self);
|
|
}
|
|
return result;
|
|
};
|
|
}
|
|
|
|
// ES5 15.4.4.20
|
|
if (!Array.prototype.filter) {
|
|
Array.prototype.filter = function filter(fun /*, thisp */) {
|
|
var self = toObject(this),
|
|
length = self.length >>> 0,
|
|
result = [],
|
|
thisp = arguments[1];
|
|
|
|
// If no callback function or if callback is not a callable function
|
|
if (toString(fun) != "[object Function]") {
|
|
throw new TypeError(); // TODO message
|
|
}
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
if (i in self && fun.call(thisp, self[i], i, self))
|
|
result.push(self[i]);
|
|
}
|
|
return result;
|
|
};
|
|
}
|
|
|
|
// ES5 15.4.4.16
|
|
if (!Array.prototype.every) {
|
|
Array.prototype.every = function every(fun /*, thisp */) {
|
|
var self = toObject(this),
|
|
length = self.length >>> 0,
|
|
thisp = arguments[1];
|
|
|
|
// If no callback function or if callback is not a callable function
|
|
if (toString(fun) != "[object Function]") {
|
|
throw new TypeError(); // TODO message
|
|
}
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
if (i in self && !fun.call(thisp, self[i], i, self))
|
|
return false;
|
|
}
|
|
return true;
|
|
};
|
|
}
|
|
|
|
// ES5 15.4.4.17
|
|
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/some
|
|
if (!Array.prototype.some) {
|
|
Array.prototype.some = function some(fun /*, thisp */) {
|
|
var self = toObject(this),
|
|
length = self.length >>> 0,
|
|
thisp = arguments[1];
|
|
|
|
// If no callback function or if callback is not a callable function
|
|
if (toString(fun) != "[object Function]") {
|
|
throw new TypeError(); // TODO message
|
|
}
|
|
|
|
for (var i = 0; i < length; i++) {
|
|
if (i in self && fun.call(thisp, self[i], i, self))
|
|
return true;
|
|
}
|
|
return false;
|
|
};
|
|
}
|
|
|
|
// ES5 15.4.4.21
|
|
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduce
|
|
if (!Array.prototype.reduce) {
|
|
Array.prototype.reduce = function reduce(fun /*, initial*/) {
|
|
var self = toObject(this),
|
|
length = self.length >>> 0;
|
|
|
|
// If no callback function or if callback is not a callable function
|
|
if (toString(fun) != "[object Function]") {
|
|
throw new TypeError(); // TODO message
|
|
}
|
|
|
|
// no value to return if no initial value and an empty array
|
|
if (!length && arguments.length == 1)
|
|
throw new TypeError(); // TODO message
|
|
|
|
var i = 0;
|
|
var result;
|
|
if (arguments.length >= 2) {
|
|
result = arguments[1];
|
|
} else {
|
|
do {
|
|
if (i in self) {
|
|
result = self[i++];
|
|
break;
|
|
}
|
|
|
|
// if array contains no values, no initial value to return
|
|
if (++i >= length)
|
|
throw new TypeError(); // TODO message
|
|
} while (true);
|
|
}
|
|
|
|
for (; i < length; i++) {
|
|
if (i in self)
|
|
result = fun.call(void 0, result, self[i], i, self);
|
|
}
|
|
|
|
return result;
|
|
};
|
|
}
|
|
|
|
// ES5 15.4.4.22
|
|
// https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Objects/Array/reduceRight
|
|
if (!Array.prototype.reduceRight) {
|
|
Array.prototype.reduceRight = function reduceRight(fun /*, initial*/) {
|
|
var self = toObject(this),
|
|
length = self.length >>> 0;
|
|
|
|
// If no callback function or if callback is not a callable function
|
|
if (toString(fun) != "[object Function]") {
|
|
throw new TypeError(); // TODO message
|
|
}
|
|
|
|
// no value to return if no initial value, empty array
|
|
if (!length && arguments.length == 1)
|
|
throw new TypeError(); // TODO message
|
|
|
|
var result, i = length - 1;
|
|
if (arguments.length >= 2) {
|
|
result = arguments[1];
|
|
} else {
|
|
do {
|
|
if (i in self) {
|
|
result = self[i--];
|
|
break;
|
|
}
|
|
|
|
// if array contains no values, no initial value to return
|
|
if (--i < 0)
|
|
throw new TypeError(); // TODO message
|
|
} while (true);
|
|
}
|
|
|
|
do {
|
|
if (i in this)
|
|
result = fun.call(void 0, result, self[i], i, self);
|
|
} while (i--);
|
|
|
|
return result;
|
|
};
|
|
}
|
|
|
|
// ES5 15.4.4.14
|
|
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf
|
|
if (!Array.prototype.indexOf) {
|
|
Array.prototype.indexOf = function indexOf(sought /*, fromIndex */ ) {
|
|
var self = toObject(this),
|
|
length = self.length >>> 0;
|
|
|
|
if (!length)
|
|
return -1;
|
|
|
|
var i = 0;
|
|
if (arguments.length > 1)
|
|
i = toInteger(arguments[1]);
|
|
|
|
// handle negative indices
|
|
i = i >= 0 ? i : length - Math.abs(i);
|
|
for (; i < length; i++) {
|
|
if (i in self && self[i] === sought) {
|
|
return i;
|
|
}
|
|
}
|
|
return -1;
|
|
};
|
|
}
|
|
|
|
// ES5 15.4.4.15
|
|
if (!Array.prototype.lastIndexOf) {
|
|
Array.prototype.lastIndexOf = function lastIndexOf(sought /*, fromIndex */) {
|
|
var self = toObject(this),
|
|
length = self.length >>> 0;
|
|
|
|
if (!length)
|
|
return -1;
|
|
var i = length - 1;
|
|
if (arguments.length > 1)
|
|
i = toInteger(arguments[1]);
|
|
// handle negative indices
|
|
i = i >= 0 ? i : length - Math.abs(i);
|
|
for (; i >= 0; i--) {
|
|
if (i in self && sought === self[i])
|
|
return i;
|
|
}
|
|
return -1;
|
|
};
|
|
}
|
|
|
|
//
|
|
// Object
|
|
// ======
|
|
//
|
|
|
|
// ES5 15.2.3.2
|
|
if (!Object.getPrototypeOf) {
|
|
// https://github.com/kriskowal/es5-shim/issues#issue/2
|
|
// http://ejohn.org/blog/objectgetprototypeof/
|
|
// recommended by fschaefer on github
|
|
Object.getPrototypeOf = function getPrototypeOf(object) {
|
|
return object.__proto__ || (
|
|
object.constructor ?
|
|
object.constructor.prototype :
|
|
prototypeOfObject
|
|
);
|
|
};
|
|
}
|
|
|
|
// ES5 15.2.3.3
|
|
if (!Object.getOwnPropertyDescriptor) {
|
|
var ERR_NON_OBJECT = "Object.getOwnPropertyDescriptor called on a " +
|
|
"non-object: ";
|
|
Object.getOwnPropertyDescriptor = function getOwnPropertyDescriptor(object, property) {
|
|
if ((typeof object != "object" && typeof object != "function") || object === null)
|
|
throw new TypeError(ERR_NON_OBJECT + object);
|
|
// If object does not owns property return undefined immediately.
|
|
if (!owns(object, property))
|
|
return;
|
|
|
|
var descriptor, getter, setter;
|
|
|
|
// If object has a property then it's for sure both `enumerable` and
|
|
// `configurable`.
|
|
descriptor = { enumerable: true, configurable: true };
|
|
|
|
// If JS engine supports accessor properties then property may be a
|
|
// getter or setter.
|
|
if (supportsAccessors) {
|
|
// Unfortunately `__lookupGetter__` will return a getter even
|
|
// if object has own non getter property along with a same named
|
|
// inherited getter. To avoid misbehavior we temporary remove
|
|
// `__proto__` so that `__lookupGetter__` will return getter only
|
|
// if it's owned by an object.
|
|
var prototype = object.__proto__;
|
|
object.__proto__ = prototypeOfObject;
|
|
|
|
var getter = lookupGetter(object, property);
|
|
var setter = lookupSetter(object, property);
|
|
|
|
// Once we have getter and setter we can put values back.
|
|
object.__proto__ = prototype;
|
|
|
|
if (getter || setter) {
|
|
if (getter) descriptor.get = getter;
|
|
if (setter) descriptor.set = setter;
|
|
|
|
// If it was accessor property we're done and return here
|
|
// in order to avoid adding `value` to the descriptor.
|
|
return descriptor;
|
|
}
|
|
}
|
|
|
|
// If we got this far we know that object has an own property that is
|
|
// not an accessor so we set it as a value and return descriptor.
|
|
descriptor.value = object[property];
|
|
return descriptor;
|
|
};
|
|
}
|
|
|
|
// ES5 15.2.3.4
|
|
if (!Object.getOwnPropertyNames) {
|
|
Object.getOwnPropertyNames = function getOwnPropertyNames(object) {
|
|
return Object.keys(object);
|
|
};
|
|
}
|
|
|
|
// ES5 15.2.3.5
|
|
if (!Object.create) {
|
|
Object.create = function create(prototype, properties) {
|
|
var object;
|
|
if (prototype === null) {
|
|
object = { "__proto__": null };
|
|
} else {
|
|
if (typeof prototype != "object")
|
|
throw new TypeError("typeof prototype["+(typeof prototype)+"] != 'object'");
|
|
var Type = function () {};
|
|
Type.prototype = prototype;
|
|
object = new Type();
|
|
// IE has no built-in implementation of `Object.getPrototypeOf`
|
|
// neither `__proto__`, but this manually setting `__proto__` will
|
|
// guarantee that `Object.getPrototypeOf` will work as expected with
|
|
// objects created using `Object.create`
|
|
object.__proto__ = prototype;
|
|
}
|
|
if (properties !== void 0)
|
|
Object.defineProperties(object, properties);
|
|
return object;
|
|
};
|
|
}
|
|
|
|
// ES5 15.2.3.6
|
|
|
|
// Patch for WebKit and IE8 standard mode
|
|
// Designed by hax <hax.github.com>
|
|
// related issue: https://github.com/kriskowal/es5-shim/issues#issue/5
|
|
// IE8 Reference:
|
|
// http://msdn.microsoft.com/en-us/library/dd282900.aspx
|
|
// http://msdn.microsoft.com/en-us/library/dd229916.aspx
|
|
// WebKit Bugs:
|
|
// https://bugs.webkit.org/show_bug.cgi?id=36423
|
|
|
|
function doesDefinePropertyWork(object) {
|
|
try {
|
|
Object.defineProperty(object, "sentinel", {});
|
|
return "sentinel" in object;
|
|
} catch (exception) {
|
|
// returns falsy
|
|
}
|
|
}
|
|
|
|
// check whether defineProperty works if it's given. Otherwise,
|
|
// shim partially.
|
|
if (Object.defineProperty) {
|
|
var definePropertyWorksOnObject = doesDefinePropertyWork({});
|
|
var definePropertyWorksOnDom = typeof document == "undefined" ||
|
|
doesDefinePropertyWork(document.createElement("div"));
|
|
if (!definePropertyWorksOnObject || !definePropertyWorksOnDom) {
|
|
var definePropertyFallback = Object.defineProperty;
|
|
}
|
|
}
|
|
|
|
if (!Object.defineProperty || definePropertyFallback) {
|
|
var ERR_NON_OBJECT_DESCRIPTOR = "Property description must be an object: ";
|
|
var ERR_NON_OBJECT_TARGET = "Object.defineProperty called on non-object: "
|
|
var ERR_ACCESSORS_NOT_SUPPORTED = "getters & setters can not be defined " +
|
|
"on this javascript engine";
|
|
|
|
Object.defineProperty = function defineProperty(object, property, descriptor) {
|
|
if ((typeof object != "object" && typeof object != "function") || object === null)
|
|
throw new TypeError(ERR_NON_OBJECT_TARGET + object);
|
|
if ((typeof descriptor != "object" && typeof descriptor != "function") || descriptor === null)
|
|
throw new TypeError(ERR_NON_OBJECT_DESCRIPTOR + descriptor);
|
|
|
|
// make a valiant attempt to use the real defineProperty
|
|
// for I8's DOM elements.
|
|
if (definePropertyFallback) {
|
|
try {
|
|
return definePropertyFallback.call(Object, object, property, descriptor);
|
|
} catch (exception) {
|
|
// try the shim if the real one doesn't work
|
|
}
|
|
}
|
|
|
|
// If it's a data property.
|
|
if (owns(descriptor, "value")) {
|
|
// fail silently if "writable", "enumerable", or "configurable"
|
|
// are requested but not supported
|
|
/*
|
|
// alternate approach:
|
|
if ( // can't implement these features; allow false but not true
|
|
!(owns(descriptor, "writable") ? descriptor.writable : true) ||
|
|
!(owns(descriptor, "enumerable") ? descriptor.enumerable : true) ||
|
|
!(owns(descriptor, "configurable") ? descriptor.configurable : true)
|
|
)
|
|
throw new RangeError(
|
|
"This implementation of Object.defineProperty does not " +
|
|
"support configurable, enumerable, or writable."
|
|
);
|
|
*/
|
|
|
|
if (supportsAccessors && (lookupGetter(object, property) ||
|
|
lookupSetter(object, property)))
|
|
{
|
|
// As accessors are supported only on engines implementing
|
|
// `__proto__` we can safely override `__proto__` while defining
|
|
// a property to make sure that we don't hit an inherited
|
|
// accessor.
|
|
var prototype = object.__proto__;
|
|
object.__proto__ = prototypeOfObject;
|
|
// Deleting a property anyway since getter / setter may be
|
|
// defined on object itself.
|
|
delete object[property];
|
|
object[property] = descriptor.value;
|
|
// Setting original `__proto__` back now.
|
|
object.__proto__ = prototype;
|
|
} else {
|
|
object[property] = descriptor.value;
|
|
}
|
|
} else {
|
|
if (!supportsAccessors)
|
|
throw new TypeError(ERR_ACCESSORS_NOT_SUPPORTED);
|
|
// If we got that far then getters and setters can be defined !!
|
|
if (owns(descriptor, "get"))
|
|
defineGetter(object, property, descriptor.get);
|
|
if (owns(descriptor, "set"))
|
|
defineSetter(object, property, descriptor.set);
|
|
}
|
|
|
|
return object;
|
|
};
|
|
}
|
|
|
|
// ES5 15.2.3.7
|
|
if (!Object.defineProperties) {
|
|
Object.defineProperties = function defineProperties(object, properties) {
|
|
for (var property in properties) {
|
|
if (owns(properties, property))
|
|
Object.defineProperty(object, property, properties[property]);
|
|
}
|
|
return object;
|
|
};
|
|
}
|
|
|
|
// ES5 15.2.3.8
|
|
if (!Object.seal) {
|
|
Object.seal = function seal(object) {
|
|
// this is misleading and breaks feature-detection, but
|
|
// allows "securable" code to "gracefully" degrade to working
|
|
// but insecure code.
|
|
return object;
|
|
};
|
|
}
|
|
|
|
// ES5 15.2.3.9
|
|
if (!Object.freeze) {
|
|
Object.freeze = function freeze(object) {
|
|
// this is misleading and breaks feature-detection, but
|
|
// allows "securable" code to "gracefully" degrade to working
|
|
// but insecure code.
|
|
return object;
|
|
};
|
|
}
|
|
|
|
// detect a Rhino bug and patch it
|
|
try {
|
|
Object.freeze(function () {});
|
|
} catch (exception) {
|
|
Object.freeze = (function freeze(freezeObject) {
|
|
return function freeze(object) {
|
|
if (typeof object == "function") {
|
|
return object;
|
|
} else {
|
|
return freezeObject(object);
|
|
}
|
|
};
|
|
})(Object.freeze);
|
|
}
|
|
|
|
// ES5 15.2.3.10
|
|
if (!Object.preventExtensions) {
|
|
Object.preventExtensions = function preventExtensions(object) {
|
|
// this is misleading and breaks feature-detection, but
|
|
// allows "securable" code to "gracefully" degrade to working
|
|
// but insecure code.
|
|
return object;
|
|
};
|
|
}
|
|
|
|
// ES5 15.2.3.11
|
|
if (!Object.isSealed) {
|
|
Object.isSealed = function isSealed(object) {
|
|
return false;
|
|
};
|
|
}
|
|
|
|
// ES5 15.2.3.12
|
|
if (!Object.isFrozen) {
|
|
Object.isFrozen = function isFrozen(object) {
|
|
return false;
|
|
};
|
|
}
|
|
|
|
// ES5 15.2.3.13
|
|
if (!Object.isExtensible) {
|
|
Object.isExtensible = function isExtensible(object) {
|
|
// 1. If Type(O) is not Object throw a TypeError exception.
|
|
if (Object(object) === object) {
|
|
throw new TypeError(); // TODO message
|
|
}
|
|
// 2. Return the Boolean value of the [[Extensible]] internal property of O.
|
|
var name = '';
|
|
while (owns(object, name)) {
|
|
name += '?';
|
|
}
|
|
object[name] = true;
|
|
var returnValue = owns(object, name);
|
|
delete object[name];
|
|
return returnValue;
|
|
};
|
|
}
|
|
|
|
// ES5 15.2.3.14
|
|
// http://whattheheadsaid.com/2010/10/a-safer-object-keys-compatibility-implementation
|
|
if (!Object.keys) {
|
|
|
|
var hasDontEnumBug = true,
|
|
dontEnums = [
|
|
"toString",
|
|
"toLocaleString",
|
|
"valueOf",
|
|
"hasOwnProperty",
|
|
"isPrototypeOf",
|
|
"propertyIsEnumerable",
|
|
"constructor"
|
|
],
|
|
dontEnumsLength = dontEnums.length;
|
|
|
|
for (var key in {"toString": null})
|
|
hasDontEnumBug = false;
|
|
|
|
Object.keys = function keys(object) {
|
|
|
|
if ((typeof object != "object" && typeof object != "function") || object === null)
|
|
throw new TypeError("Object.keys called on a non-object");
|
|
|
|
var keys = [];
|
|
for (var name in object) {
|
|
if (owns(object, name)) {
|
|
keys.push(name);
|
|
}
|
|
}
|
|
|
|
if (hasDontEnumBug) {
|
|
for (var i = 0, ii = dontEnumsLength; i < ii; i++) {
|
|
var dontEnum = dontEnums[i];
|
|
if (owns(object, dontEnum)) {
|
|
keys.push(dontEnum);
|
|
}
|
|
}
|
|
}
|
|
|
|
return keys;
|
|
};
|
|
|
|
}
|
|
|
|
//
|
|
// Date
|
|
// ====
|
|
//
|
|
|
|
// ES5 15.9.5.43
|
|
// Format a Date object as a string according to a simplified subset of the ISO 8601
|
|
// standard as defined in 15.9.1.15.
|
|
if (!Date.prototype.toISOString) {
|
|
Date.prototype.toISOString = function toISOString() {
|
|
var result, length, value;
|
|
if (!isFinite(this))
|
|
throw new RangeError;
|
|
|
|
// the date time string format is specified in 15.9.1.15.
|
|
result = [this.getUTCFullYear(), this.getUTCMonth() + 1, this.getUTCDate(),
|
|
this.getUTCHours(), this.getUTCMinutes(), this.getUTCSeconds()];
|
|
|
|
length = result.length;
|
|
while (length--) {
|
|
value = result[length];
|
|
// pad months, days, hours, minutes, and seconds to have two digits.
|
|
if (value < 10)
|
|
result[length] = "0" + value;
|
|
}
|
|
// pad milliseconds to have three digits.
|
|
return result.slice(0, 3).join("-") + "T" + result.slice(3).join(":") + "." +
|
|
("000" + this.getUTCMilliseconds()).slice(-3) + "Z";
|
|
}
|
|
}
|
|
|
|
// ES5 15.9.4.4
|
|
if (!Date.now) {
|
|
Date.now = function now() {
|
|
return new Date().getTime();
|
|
};
|
|
}
|
|
|
|
// ES5 15.9.5.44
|
|
if (!Date.prototype.toJSON) {
|
|
Date.prototype.toJSON = function toJSON(key) {
|
|
// This function provides a String representation of a Date object for
|
|
// use by JSON.stringify (15.12.3). When the toJSON method is called
|
|
// with argument key, the following steps are taken:
|
|
|
|
// 1. Let O be the result of calling ToObject, giving it the this
|
|
// value as its argument.
|
|
// 2. Let tv be ToPrimitive(O, hint Number).
|
|
// 3. If tv is a Number and is not finite, return null.
|
|
// XXX
|
|
// 4. Let toISO be the result of calling the [[Get]] internal method of
|
|
// O with argument "toISOString".
|
|
// 5. If IsCallable(toISO) is false, throw a TypeError exception.
|
|
if (typeof this.toISOString != "function")
|
|
throw new TypeError(); // TODO message
|
|
// 6. Return the result of calling the [[Call]] internal method of
|
|
// toISO with O as the this value and an empty argument list.
|
|
return this.toISOString();
|
|
|
|
// NOTE 1 The argument is ignored.
|
|
|
|
// NOTE 2 The toJSON function is intentionally generic; it does not
|
|
// require that its this value be a Date object. Therefore, it can be
|
|
// transferred to other kinds of objects for use as a method. However,
|
|
// it does require that any such object have a toISOString method. An
|
|
// object is free to use the argument key to filter its
|
|
// stringification.
|
|
};
|
|
}
|
|
|
|
// 15.9.4.2 Date.parse (string)
|
|
// 15.9.1.15 Date Time String Format
|
|
// Date.parse
|
|
// based on work shared by Daniel Friesen (dantman)
|
|
// http://gist.github.com/303249
|
|
if (isNaN(Date.parse("2011-06-15T21:40:05+06:00"))) {
|
|
// XXX global assignment won't work in embeddings that use
|
|
// an alternate object for the context.
|
|
Date = (function(NativeDate) {
|
|
|
|
// Date.length === 7
|
|
var Date = function Date(Y, M, D, h, m, s, ms) {
|
|
var length = arguments.length;
|
|
if (this instanceof NativeDate) {
|
|
var date = length == 1 && String(Y) === Y ? // isString(Y)
|
|
// We explicitly pass it through parse:
|
|
new NativeDate(Date.parse(Y)) :
|
|
// We have to manually make calls depending on argument
|
|
// length here
|
|
length >= 7 ? new NativeDate(Y, M, D, h, m, s, ms) :
|
|
length >= 6 ? new NativeDate(Y, M, D, h, m, s) :
|
|
length >= 5 ? new NativeDate(Y, M, D, h, m) :
|
|
length >= 4 ? new NativeDate(Y, M, D, h) :
|
|
length >= 3 ? new NativeDate(Y, M, D) :
|
|
length >= 2 ? new NativeDate(Y, M) :
|
|
length >= 1 ? new NativeDate(Y) :
|
|
new NativeDate();
|
|
// Prevent mixups with unfixed Date object
|
|
date.constructor = Date;
|
|
return date;
|
|
}
|
|
return NativeDate.apply(this, arguments);
|
|
};
|
|
|
|
// 15.9.1.15 Date Time String Format. This pattern does not implement
|
|
// extended years (15.9.1.15.1), as `Date.UTC` cannot parse them.
|
|
var isoDateExpression = new RegExp("^" +
|
|
"(\\d{4})" + // four-digit year capture
|
|
"(?:-(\\d{2})" + // optional month capture
|
|
"(?:-(\\d{2})" + // optional day capture
|
|
"(?:" + // capture hours:minutes:seconds.milliseconds
|
|
"T(\\d{2})" + // hours capture
|
|
":(\\d{2})" + // minutes capture
|
|
"(?:" + // optional :seconds.milliseconds
|
|
":(\\d{2})" + // seconds capture
|
|
"(?:\\.(\\d{3}))?" + // milliseconds capture
|
|
")?" +
|
|
"(?:" + // capture UTC offset component
|
|
"Z|" + // UTC capture
|
|
"(?:" + // offset specifier +/-hours:minutes
|
|
"([-+])" + // sign capture
|
|
"(\\d{2})" + // hours offset capture
|
|
":(\\d{2})" + // minutes offset capture
|
|
")" +
|
|
")?)?)?)?" +
|
|
"$");
|
|
|
|
// Copy any custom methods a 3rd party library may have added
|
|
for (var key in NativeDate)
|
|
Date[key] = NativeDate[key];
|
|
|
|
// Copy "native" methods explicitly; they may be non-enumerable
|
|
Date.now = NativeDate.now;
|
|
Date.UTC = NativeDate.UTC;
|
|
Date.prototype = NativeDate.prototype;
|
|
Date.prototype.constructor = Date;
|
|
|
|
// Upgrade Date.parse to handle simplified ISO 8601 strings
|
|
Date.parse = function parse(string) {
|
|
var match = isoDateExpression.exec(string);
|
|
if (match) {
|
|
match.shift(); // kill match[0], the full match
|
|
// parse months, days, hours, minutes, seconds, and milliseconds
|
|
for (var i = 1; i < 7; i++) {
|
|
// provide default values if necessary
|
|
match[i] = +(match[i] || (i < 3 ? 1 : 0));
|
|
// match[1] is the month. Months are 0-11 in JavaScript
|
|
// `Date` objects, but 1-12 in ISO notation, so we
|
|
// decrement.
|
|
if (i == 1)
|
|
match[i]--;
|
|
}
|
|
|
|
// parse the UTC offset component
|
|
var minuteOffset = +match.pop(), hourOffset = +match.pop(), sign = match.pop();
|
|
|
|
// compute the explicit time zone offset if specified
|
|
var offset = 0;
|
|
if (sign) {
|
|
// detect invalid offsets and return early
|
|
if (hourOffset > 23 || minuteOffset > 59)
|
|
return NaN;
|
|
|
|
// express the provided time zone offset in minutes. The offset is
|
|
// negative for time zones west of UTC; positive otherwise.
|
|
offset = (hourOffset * 60 + minuteOffset) * 6e4 * (sign == "+" ? -1 : 1);
|
|
}
|
|
|
|
// compute a new UTC date value, accounting for the optional offset
|
|
return NativeDate.UTC.apply(this, match) + offset;
|
|
}
|
|
return NativeDate.parse.apply(this, arguments);
|
|
};
|
|
|
|
return Date;
|
|
})(Date);
|
|
}
|
|
|
|
//
|
|
// String
|
|
// ======
|
|
//
|
|
|
|
// ES5 15.5.4.20
|
|
var ws = "\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003" +
|
|
"\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028" +
|
|
"\u2029\uFEFF";
|
|
if (!String.prototype.trim || ws.trim()) {
|
|
// http://blog.stevenlevithan.com/archives/faster-trim-javascript
|
|
// http://perfectionkills.com/whitespace-deviations/
|
|
ws = "[" + ws + "]";
|
|
var trimBeginRegexp = new RegExp("^" + ws + ws + "*"),
|
|
trimEndRegexp = new RegExp(ws + ws + "*$");
|
|
String.prototype.trim = function trim() {
|
|
return String(this).replace(trimBeginRegexp, "").replace(trimEndRegexp, "");
|
|
};
|
|
}
|
|
|
|
//
|
|
// Util
|
|
// ======
|
|
//
|
|
|
|
// http://jsperf.com/to-integer
|
|
var toInteger = function (n) {
|
|
n = +n;
|
|
if (n !== n) // isNaN
|
|
n = -1;
|
|
else if (n !== 0 && n !== (1/0) && n !== -(1/0))
|
|
n = (n > 0 || -1) * Math.floor(Math.abs(n));
|
|
return n;
|
|
};
|
|
|
|
var prepareString = "a"[0] != "a",
|
|
// ES5 9.9
|
|
toObject = function (o) {
|
|
if (o == null) { // this matches both null and undefined
|
|
throw new TypeError(); // TODO message
|
|
}
|
|
// If the implementation doesn't support by-index access of
|
|
// string characters (ex. IE < 7), split the string
|
|
if (prepareString && typeof o == "string" && o) {
|
|
return o.split("");
|
|
}
|
|
return Object(o);
|
|
};
|
|
});
|
|
(function() {
|
|
var Batman,
|
|
__slice = [].slice;
|
|
|
|
Batman = function() {
|
|
var mixins;
|
|
mixins = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
return (function(func, args, ctor) {
|
|
ctor.prototype = func.prototype;
|
|
var child = new ctor, result = func.apply(child, args), t = typeof result;
|
|
return t == "object" || t == "function" ? result || child : child;
|
|
})(Batman.Object, mixins, function(){});
|
|
};
|
|
|
|
Batman.version = '0.13.0';
|
|
|
|
Batman.config = {
|
|
pathPrefix: '/',
|
|
viewPrefix: 'views',
|
|
fetchRemoteViews: true,
|
|
usePushState: false,
|
|
minificationErrors: true
|
|
};
|
|
|
|
(Batman.container = (function() {
|
|
return this;
|
|
})()).Batman = Batman;
|
|
|
|
if (typeof define === 'function') {
|
|
define('batman', [], function() {
|
|
return Batman;
|
|
});
|
|
}
|
|
|
|
Batman.exportHelpers = function(onto) {
|
|
var k, _i, _len, _ref;
|
|
_ref = ['mixin', 'extend', 'unmixin', 'redirect', 'typeOf', 'redirect', 'setImmediate', 'clearImmediate'];
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
k = _ref[_i];
|
|
onto["$" + k] = Batman[k];
|
|
}
|
|
return onto;
|
|
};
|
|
|
|
Batman.exportGlobals = function() {
|
|
return Batman.exportHelpers(Batman.container);
|
|
};
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var _implementImmediates, _objectToString,
|
|
__slice = [].slice,
|
|
__hasProp = {}.hasOwnProperty,
|
|
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
|
|
|
Batman.typeOf = function(object) {
|
|
if (typeof object === 'undefined') {
|
|
return "Undefined";
|
|
}
|
|
return _objectToString.call(object).slice(8, -1);
|
|
};
|
|
|
|
_objectToString = Object.prototype.toString;
|
|
|
|
Batman.extend = function() {
|
|
var key, object, objects, to, value, _i, _len;
|
|
to = arguments[0], objects = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
|
for (_i = 0, _len = objects.length; _i < _len; _i++) {
|
|
object = objects[_i];
|
|
for (key in object) {
|
|
value = object[key];
|
|
to[key] = value;
|
|
}
|
|
}
|
|
return to;
|
|
};
|
|
|
|
Batman.mixin = function() {
|
|
var hasSet, key, mixin, mixins, to, value, _i, _len;
|
|
to = arguments[0], mixins = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
|
hasSet = typeof to.set === 'function';
|
|
for (_i = 0, _len = mixins.length; _i < _len; _i++) {
|
|
mixin = mixins[_i];
|
|
if (Batman.typeOf(mixin) !== 'Object') {
|
|
continue;
|
|
}
|
|
for (key in mixin) {
|
|
if (!__hasProp.call(mixin, key)) continue;
|
|
value = mixin[key];
|
|
if (key === 'initialize' || key === 'uninitialize' || key === 'prototype') {
|
|
continue;
|
|
}
|
|
if (hasSet) {
|
|
to.set(key, value);
|
|
} else if (to.nodeName != null) {
|
|
Batman.data(to, key, value);
|
|
} else {
|
|
to[key] = value;
|
|
}
|
|
}
|
|
if (typeof mixin.initialize === 'function') {
|
|
mixin.initialize.call(to);
|
|
}
|
|
}
|
|
return to;
|
|
};
|
|
|
|
Batman.unmixin = function() {
|
|
var from, key, mixin, mixins, _i, _len;
|
|
from = arguments[0], mixins = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
|
for (_i = 0, _len = mixins.length; _i < _len; _i++) {
|
|
mixin = mixins[_i];
|
|
for (key in mixin) {
|
|
if (key === 'initialize' || key === 'uninitialize') {
|
|
continue;
|
|
}
|
|
delete from[key];
|
|
}
|
|
if (typeof mixin.uninitialize === 'function') {
|
|
mixin.uninitialize.call(from);
|
|
}
|
|
}
|
|
return from;
|
|
};
|
|
|
|
Batman._functionName = Batman.functionName = function(f) {
|
|
var _ref;
|
|
if (f.__name__) {
|
|
return f.__name__;
|
|
}
|
|
if (f.name) {
|
|
return f.name;
|
|
}
|
|
return (_ref = f.toString().match(/\W*function\s+([\w\$]+)\(/)) != null ? _ref[1] : void 0;
|
|
};
|
|
|
|
Batman._isChildOf = Batman.isChildOf = function(parentNode, childNode) {
|
|
var node;
|
|
node = childNode.parentNode;
|
|
while (node) {
|
|
if (node === parentNode) {
|
|
return true;
|
|
}
|
|
node = node.parentNode;
|
|
}
|
|
return false;
|
|
};
|
|
|
|
Batman.setImmediate = Batman.clearImmediate = null;
|
|
|
|
_implementImmediates = function(container) {
|
|
var canUsePostMessage, count, functions, getHandle, handler, prefix, tasks;
|
|
canUsePostMessage = function() {
|
|
var async, oldMessage;
|
|
if (!container.postMessage) {
|
|
return false;
|
|
}
|
|
async = true;
|
|
oldMessage = container.onmessage;
|
|
container.onmessage = function() {
|
|
return async = false;
|
|
};
|
|
container.postMessage("", "*");
|
|
container.onmessage = oldMessage;
|
|
return async;
|
|
};
|
|
tasks = new Batman.SimpleHash;
|
|
count = 0;
|
|
getHandle = function() {
|
|
return "go" + (++count);
|
|
};
|
|
if (container.setImmediate) {
|
|
Batman.setImmediate = container.setImmediate;
|
|
Batman.clearImmediate = container.clearImmediate;
|
|
} else if (container.msSetImmediate) {
|
|
Batman.setImmediate = msSetImmediate;
|
|
Batman.clearImmediate = msClearImmediate;
|
|
} else if (canUsePostMessage()) {
|
|
prefix = 'com.batman.';
|
|
functions = new Batman.SimpleHash;
|
|
handler = function(e) {
|
|
var handle, _base;
|
|
if (!~e.data.search(prefix)) {
|
|
return;
|
|
}
|
|
handle = e.data.substring(prefix.length);
|
|
return typeof (_base = tasks.unset(handle)) === "function" ? _base() : void 0;
|
|
};
|
|
if (container.addEventListener) {
|
|
container.addEventListener('message', handler, false);
|
|
} else {
|
|
container.attachEvent('onmessage', handler);
|
|
}
|
|
Batman.setImmediate = function(f) {
|
|
var handle;
|
|
tasks.set(handle = getHandle(), f);
|
|
container.postMessage(prefix + handle, "*");
|
|
return handle;
|
|
};
|
|
Batman.clearImmediate = function(handle) {
|
|
return tasks.unset(handle);
|
|
};
|
|
} else if (typeof document !== 'undefined' && __indexOf.call(document.createElement("script"), "onreadystatechange") >= 0) {
|
|
Batman.setImmediate = function(f) {
|
|
var handle, script;
|
|
handle = getHandle();
|
|
script = document.createElement("script");
|
|
script.onreadystatechange = function() {
|
|
var _base;
|
|
if (typeof (_base = tasks.get(handle)) === "function") {
|
|
_base();
|
|
}
|
|
script.onreadystatechange = null;
|
|
script.parentNode.removeChild(script);
|
|
return script = null;
|
|
};
|
|
document.documentElement.appendChild(script);
|
|
return handle;
|
|
};
|
|
Batman.clearImmediate = function(handle) {
|
|
return tasks.unset(handle);
|
|
};
|
|
} else if (typeof process !== "undefined" && process !== null ? process.nextTick : void 0) {
|
|
functions = {};
|
|
Batman.setImmediate = function(f) {
|
|
var handle;
|
|
handle = getHandle();
|
|
functions[handle] = f;
|
|
process.nextTick(function() {
|
|
if (typeof functions[handle] === "function") {
|
|
functions[handle]();
|
|
}
|
|
return delete functions[handle];
|
|
});
|
|
return handle;
|
|
};
|
|
Batman.clearImmediate = function(handle) {
|
|
return delete functions[handle];
|
|
};
|
|
} else {
|
|
Batman.setImmediate = function(f) {
|
|
return setTimeout(f, 0);
|
|
};
|
|
Batman.clearImmediate = function(handle) {
|
|
return clearTimeout(handle);
|
|
};
|
|
}
|
|
Batman.setImmediate = Batman.setImmediate;
|
|
return Batman.clearImmediate = Batman.clearImmediate;
|
|
};
|
|
|
|
Batman.setImmediate = function() {
|
|
_implementImmediates(Batman.container);
|
|
return Batman.setImmediate.apply(this, arguments);
|
|
};
|
|
|
|
Batman.clearImmediate = function() {
|
|
_implementImmediates(Batman.container);
|
|
return Batman.clearImmediate.apply(this, arguments);
|
|
};
|
|
|
|
Batman.forEach = function(container, iterator, ctx) {
|
|
var e, i, k, v, _i, _len, _results, _results1;
|
|
if (container.forEach) {
|
|
return container.forEach(iterator, ctx);
|
|
} else if (container.indexOf) {
|
|
_results = [];
|
|
for (i = _i = 0, _len = container.length; _i < _len; i = ++_i) {
|
|
e = container[i];
|
|
_results.push(iterator.call(ctx, e, i, container));
|
|
}
|
|
return _results;
|
|
} else {
|
|
_results1 = [];
|
|
for (k in container) {
|
|
v = container[k];
|
|
_results1.push(iterator.call(ctx, k, v, container));
|
|
}
|
|
return _results1;
|
|
}
|
|
};
|
|
|
|
Batman.objectHasKey = function(object, key) {
|
|
if (typeof object.hasKey === 'function') {
|
|
return object.hasKey(key);
|
|
} else {
|
|
return key in object;
|
|
}
|
|
};
|
|
|
|
Batman.contains = function(container, item) {
|
|
if (container.indexOf) {
|
|
return __indexOf.call(container, item) >= 0;
|
|
} else if (typeof container.has === 'function') {
|
|
return container.has(item);
|
|
} else {
|
|
return Batman.objectHasKey(container, item);
|
|
}
|
|
};
|
|
|
|
Batman.get = function(base, key) {
|
|
if (typeof base.get === 'function') {
|
|
return base.get(key);
|
|
} else {
|
|
return Batman.Property.forBaseAndKey(base, key).getValue();
|
|
}
|
|
};
|
|
|
|
Batman.getPath = function(base, segments) {
|
|
var segment, _i, _len;
|
|
for (_i = 0, _len = segments.length; _i < _len; _i++) {
|
|
segment = segments[_i];
|
|
if (base != null) {
|
|
base = Batman.get(base, segment);
|
|
if (base == null) {
|
|
return base;
|
|
}
|
|
} else {
|
|
return void 0;
|
|
}
|
|
}
|
|
return base;
|
|
};
|
|
|
|
Batman.escapeHTML = (function() {
|
|
var replacements;
|
|
replacements = {
|
|
"&": "&",
|
|
"<": "<",
|
|
">": ">",
|
|
"\"": """,
|
|
"'": "'"
|
|
};
|
|
return function(s) {
|
|
return ("" + s).replace(/[&<>'"]/g, function(c) {
|
|
return replacements[c];
|
|
});
|
|
};
|
|
})();
|
|
|
|
Batman.translate = function(x, values) {
|
|
if (values == null) {
|
|
values = {};
|
|
}
|
|
return Batman.helpers.interpolate(Batman.get(Batman.translate.messages, x), values);
|
|
};
|
|
|
|
Batman.translate.messages = {};
|
|
|
|
Batman.t = function() {
|
|
return Batman.translate.apply(Batman, arguments);
|
|
};
|
|
|
|
Batman.redirect = function(url) {
|
|
var _ref;
|
|
return (_ref = Batman.navigator) != null ? _ref.redirect(url) : void 0;
|
|
};
|
|
|
|
Batman.initializeObject = function(object) {
|
|
if (object._batman != null) {
|
|
return object._batman.check(object);
|
|
} else {
|
|
return object._batman = new Batman._Batman(object);
|
|
}
|
|
};
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __slice = [].slice,
|
|
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
|
|
|
Batman.Inflector = (function() {
|
|
|
|
Inflector.prototype.plural = function(regex, replacement) {
|
|
return this._plural.unshift([regex, replacement]);
|
|
};
|
|
|
|
Inflector.prototype.singular = function(regex, replacement) {
|
|
return this._singular.unshift([regex, replacement]);
|
|
};
|
|
|
|
Inflector.prototype.human = function(regex, replacement) {
|
|
return this._human.unshift([regex, replacement]);
|
|
};
|
|
|
|
Inflector.prototype.uncountable = function() {
|
|
var strings;
|
|
strings = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
return this._uncountable = this._uncountable.concat(strings.map(function(x) {
|
|
return new RegExp("" + x + "$", 'i');
|
|
}));
|
|
};
|
|
|
|
Inflector.prototype.irregular = function(singular, plural) {
|
|
if (singular.charAt(0) === plural.charAt(0)) {
|
|
this.plural(new RegExp("(" + (singular.charAt(0)) + ")" + (singular.slice(1)) + "$", "i"), "$1" + plural.slice(1));
|
|
this.plural(new RegExp("(" + (singular.charAt(0)) + ")" + (plural.slice(1)) + "$", "i"), "$1" + plural.slice(1));
|
|
return this.singular(new RegExp("(" + (plural.charAt(0)) + ")" + (plural.slice(1)) + "$", "i"), "$1" + singular.slice(1));
|
|
} else {
|
|
this.plural(new RegExp("" + singular + "$", 'i'), plural);
|
|
this.plural(new RegExp("" + plural + "$", 'i'), plural);
|
|
return this.singular(new RegExp("" + plural + "$", 'i'), singular);
|
|
}
|
|
};
|
|
|
|
function Inflector() {
|
|
this._plural = [];
|
|
this._singular = [];
|
|
this._uncountable = [];
|
|
this._human = [];
|
|
}
|
|
|
|
Inflector.prototype.ordinalize = function(number) {
|
|
var absNumber, _ref;
|
|
absNumber = Math.abs(parseInt(number));
|
|
if (_ref = absNumber % 100, __indexOf.call([11, 12, 13], _ref) >= 0) {
|
|
return number + "th";
|
|
} else {
|
|
switch (absNumber % 10) {
|
|
case 1:
|
|
return number + "st";
|
|
case 2:
|
|
return number + "nd";
|
|
case 3:
|
|
return number + "rd";
|
|
default:
|
|
return number + "th";
|
|
}
|
|
}
|
|
};
|
|
|
|
Inflector.prototype.pluralize = function(word) {
|
|
var regex, replace_string, uncountableRegex, _i, _j, _len, _len1, _ref, _ref1, _ref2;
|
|
_ref = this._uncountable;
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
uncountableRegex = _ref[_i];
|
|
if (uncountableRegex.test(word)) {
|
|
return word;
|
|
}
|
|
}
|
|
_ref1 = this._plural;
|
|
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
|
_ref2 = _ref1[_j], regex = _ref2[0], replace_string = _ref2[1];
|
|
if (regex.test(word)) {
|
|
return word.replace(regex, replace_string);
|
|
}
|
|
}
|
|
return word;
|
|
};
|
|
|
|
Inflector.prototype.singularize = function(word) {
|
|
var regex, replace_string, uncountableRegex, _i, _j, _len, _len1, _ref, _ref1, _ref2;
|
|
_ref = this._uncountable;
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
uncountableRegex = _ref[_i];
|
|
if (uncountableRegex.test(word)) {
|
|
return word;
|
|
}
|
|
}
|
|
_ref1 = this._singular;
|
|
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
|
_ref2 = _ref1[_j], regex = _ref2[0], replace_string = _ref2[1];
|
|
if (regex.test(word)) {
|
|
return word.replace(regex, replace_string);
|
|
}
|
|
}
|
|
return word;
|
|
};
|
|
|
|
Inflector.prototype.humanize = function(word) {
|
|
var regex, replace_string, _i, _len, _ref, _ref1;
|
|
_ref = this._human;
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
_ref1 = _ref[_i], regex = _ref1[0], replace_string = _ref1[1];
|
|
if (regex.test(word)) {
|
|
return word.replace(regex, replace_string);
|
|
}
|
|
}
|
|
return word;
|
|
};
|
|
|
|
return Inflector;
|
|
|
|
})();
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var Inflector, camelize_rx, capitalize_rx, humanize_rx1, humanize_rx2, humanize_rx3, underscore_rx1, underscore_rx2;
|
|
|
|
camelize_rx = /(?:^|_|\-)(.)/g;
|
|
|
|
capitalize_rx = /(^|\s)([a-z])/g;
|
|
|
|
underscore_rx1 = /([A-Z]+)([A-Z][a-z])/g;
|
|
|
|
underscore_rx2 = /([a-z\d])([A-Z])/g;
|
|
|
|
humanize_rx1 = /_id$/;
|
|
|
|
humanize_rx2 = /_|-/g;
|
|
|
|
humanize_rx3 = /^\w/g;
|
|
|
|
Batman.helpers = {
|
|
ordinalize: function() {
|
|
return Batman.helpers.inflector.ordinalize.apply(Batman.helpers.inflector, arguments);
|
|
},
|
|
singularize: function() {
|
|
return Batman.helpers.inflector.singularize.apply(Batman.helpers.inflector, arguments);
|
|
},
|
|
pluralize: function(count, singular, plural, includeCount) {
|
|
var result;
|
|
if (includeCount == null) {
|
|
includeCount = true;
|
|
}
|
|
if (arguments.length < 2) {
|
|
return Batman.helpers.inflector.pluralize(count);
|
|
} else {
|
|
result = +count === 1 ? singular : plural || Batman.helpers.inflector.pluralize(singular);
|
|
if (includeCount) {
|
|
result = ("" + (count || 0) + " ") + result;
|
|
}
|
|
return result;
|
|
}
|
|
},
|
|
camelize: function(string, firstLetterLower) {
|
|
string = string.replace(camelize_rx, function(str, p1) {
|
|
return p1.toUpperCase();
|
|
});
|
|
if (firstLetterLower) {
|
|
return string.substr(0, 1).toLowerCase() + string.substr(1);
|
|
} else {
|
|
return string;
|
|
}
|
|
},
|
|
underscore: function(string) {
|
|
return string.replace(underscore_rx1, '$1_$2').replace(underscore_rx2, '$1_$2').replace('-', '_').toLowerCase();
|
|
},
|
|
capitalize: function(string) {
|
|
return string.replace(capitalize_rx, function(m, p1, p2) {
|
|
return p1 + p2.toUpperCase();
|
|
});
|
|
},
|
|
trim: function(string) {
|
|
if (string) {
|
|
return string.trim();
|
|
} else {
|
|
return "";
|
|
}
|
|
},
|
|
interpolate: function(stringOrObject, keys) {
|
|
var key, string, value;
|
|
if (typeof stringOrObject === 'object') {
|
|
string = stringOrObject[keys.count];
|
|
if (!string) {
|
|
string = stringOrObject['other'];
|
|
}
|
|
} else {
|
|
string = stringOrObject;
|
|
}
|
|
for (key in keys) {
|
|
value = keys[key];
|
|
string = string.replace(new RegExp("%\\{" + key + "\\}", "g"), value);
|
|
}
|
|
return string;
|
|
},
|
|
humanize: function(string) {
|
|
string = Batman.helpers.underscore(string);
|
|
string = Batman.helpers.inflector.humanize(string);
|
|
return string.replace(humanize_rx1, '').replace(humanize_rx2, ' ').replace(humanize_rx3, function(match) {
|
|
return match.toUpperCase();
|
|
});
|
|
}
|
|
};
|
|
|
|
Inflector = new Batman.Inflector;
|
|
|
|
Batman.helpers.inflector = Inflector;
|
|
|
|
Inflector.plural(/$/, 's');
|
|
|
|
Inflector.plural(/s$/i, 's');
|
|
|
|
Inflector.plural(/(ax|test)is$/i, '$1es');
|
|
|
|
Inflector.plural(/(octop|vir)us$/i, '$1i');
|
|
|
|
Inflector.plural(/(octop|vir)i$/i, '$1i');
|
|
|
|
Inflector.plural(/(alias|status)$/i, '$1es');
|
|
|
|
Inflector.plural(/(bu)s$/i, '$1ses');
|
|
|
|
Inflector.plural(/(buffal|tomat)o$/i, '$1oes');
|
|
|
|
Inflector.plural(/([ti])um$/i, '$1a');
|
|
|
|
Inflector.plural(/([ti])a$/i, '$1a');
|
|
|
|
Inflector.plural(/sis$/i, 'ses');
|
|
|
|
Inflector.plural(/(?:([^f])fe|([lr])f)$/i, '$1$2ves');
|
|
|
|
Inflector.plural(/(hive)$/i, '$1s');
|
|
|
|
Inflector.plural(/([^aeiouy]|qu)y$/i, '$1ies');
|
|
|
|
Inflector.plural(/(x|ch|ss|sh)$/i, '$1es');
|
|
|
|
Inflector.plural(/(matr|vert|ind)(?:ix|ex)$/i, '$1ices');
|
|
|
|
Inflector.plural(/([m|l])ouse$/i, '$1ice');
|
|
|
|
Inflector.plural(/([m|l])ice$/i, '$1ice');
|
|
|
|
Inflector.plural(/^(ox)$/i, '$1en');
|
|
|
|
Inflector.plural(/^(oxen)$/i, '$1');
|
|
|
|
Inflector.plural(/(quiz)$/i, '$1zes');
|
|
|
|
Inflector.singular(/s$/i, '');
|
|
|
|
Inflector.singular(/(n)ews$/i, '$1ews');
|
|
|
|
Inflector.singular(/([ti])a$/i, '$1um');
|
|
|
|
Inflector.singular(/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i, '$1$2sis');
|
|
|
|
Inflector.singular(/(^analy)ses$/i, '$1sis');
|
|
|
|
Inflector.singular(/([^f])ves$/i, '$1fe');
|
|
|
|
Inflector.singular(/(hive)s$/i, '$1');
|
|
|
|
Inflector.singular(/(tive)s$/i, '$1');
|
|
|
|
Inflector.singular(/([lr])ves$/i, '$1f');
|
|
|
|
Inflector.singular(/([^aeiouy]|qu)ies$/i, '$1y');
|
|
|
|
Inflector.singular(/(s)eries$/i, '$1eries');
|
|
|
|
Inflector.singular(/(m)ovies$/i, '$1ovie');
|
|
|
|
Inflector.singular(/(x|ch|ss|sh)es$/i, '$1');
|
|
|
|
Inflector.singular(/([m|l])ice$/i, '$1ouse');
|
|
|
|
Inflector.singular(/(bus)es$/i, '$1');
|
|
|
|
Inflector.singular(/(o)es$/i, '$1');
|
|
|
|
Inflector.singular(/(shoe)s$/i, '$1');
|
|
|
|
Inflector.singular(/(cris|ax|test)es$/i, '$1is');
|
|
|
|
Inflector.singular(/(octop|vir)i$/i, '$1us');
|
|
|
|
Inflector.singular(/(alias|status)es$/i, '$1');
|
|
|
|
Inflector.singular(/^(ox)en/i, '$1');
|
|
|
|
Inflector.singular(/(vert|ind)ices$/i, '$1ex');
|
|
|
|
Inflector.singular(/(matr)ices$/i, '$1ix');
|
|
|
|
Inflector.singular(/(quiz)zes$/i, '$1');
|
|
|
|
Inflector.singular(/(database)s$/i, '$1');
|
|
|
|
Inflector.irregular('person', 'people');
|
|
|
|
Inflector.irregular('man', 'men');
|
|
|
|
Inflector.irregular('child', 'children');
|
|
|
|
Inflector.irregular('sex', 'sexes');
|
|
|
|
Inflector.irregular('move', 'moves');
|
|
|
|
Inflector.irregular('cow', 'kine');
|
|
|
|
Inflector.irregular('zombie', 'zombies');
|
|
|
|
Inflector.uncountable('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep', 'jeans');
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var developer;
|
|
|
|
Batman.developer = {
|
|
suppressed: false,
|
|
DevelopmentError: (function() {
|
|
var DevelopmentError;
|
|
DevelopmentError = function(message) {
|
|
this.message = message;
|
|
return this.name = "DevelopmentError";
|
|
};
|
|
DevelopmentError.prototype = Error.prototype;
|
|
return DevelopmentError;
|
|
})(),
|
|
_ie_console: function(f, args) {
|
|
var arg, _i, _len, _results;
|
|
if (args.length !== 1) {
|
|
if (typeof console !== "undefined" && console !== null) {
|
|
console[f]("..." + f + " of " + args.length + " items...");
|
|
}
|
|
}
|
|
_results = [];
|
|
for (_i = 0, _len = args.length; _i < _len; _i++) {
|
|
arg = args[_i];
|
|
_results.push(typeof console !== "undefined" && console !== null ? console[f](arg) : void 0);
|
|
}
|
|
return _results;
|
|
},
|
|
suppress: function(f) {
|
|
developer.suppressed = true;
|
|
if (f) {
|
|
f();
|
|
return developer.suppressed = false;
|
|
}
|
|
},
|
|
unsuppress: function() {
|
|
return developer.suppressed = false;
|
|
},
|
|
log: function() {
|
|
if (developer.suppressed || !((typeof console !== "undefined" && console !== null ? console.log : void 0) != null)) {
|
|
return;
|
|
}
|
|
if (console.log.apply) {
|
|
return console.log.apply(console, arguments);
|
|
} else {
|
|
return developer._ie_console("log", arguments);
|
|
}
|
|
},
|
|
warn: function() {
|
|
if (developer.suppressed || !((typeof console !== "undefined" && console !== null ? console.warn : void 0) != null)) {
|
|
return;
|
|
}
|
|
if (console.warn.apply) {
|
|
return console.warn.apply(console, arguments);
|
|
} else {
|
|
return developer._ie_console("warn", arguments);
|
|
}
|
|
},
|
|
error: function(message) {
|
|
throw new developer.DevelopmentError(message);
|
|
},
|
|
assert: function(result, message) {
|
|
if (!result) {
|
|
return developer.error(message);
|
|
}
|
|
},
|
|
"do": function(f) {
|
|
if (!developer.suppressed) {
|
|
return f();
|
|
}
|
|
},
|
|
addFilters: function() {
|
|
return Batman.extend(Batman.Filters, {
|
|
log: function(value, key) {
|
|
if (typeof console !== "undefined" && console !== null) {
|
|
if (typeof console.log === "function") {
|
|
console.log(arguments);
|
|
}
|
|
}
|
|
return value;
|
|
},
|
|
logStack: function(value) {
|
|
if (typeof console !== "undefined" && console !== null) {
|
|
if (typeof console.log === "function") {
|
|
console.log(developer.currentFilterStack);
|
|
}
|
|
}
|
|
return value;
|
|
}
|
|
});
|
|
}
|
|
};
|
|
|
|
developer = Batman.developer;
|
|
|
|
Batman.developer.assert((function() {}).bind, "Error! Batman needs Function.bind to work! Please shim it using something like es5-shim or augmentjs!");
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var _Batman;
|
|
|
|
Batman._Batman = _Batman = (function() {
|
|
|
|
function _Batman(object) {
|
|
this.object = object;
|
|
}
|
|
|
|
_Batman.prototype.check = function(object) {
|
|
if (object !== this.object) {
|
|
object._batman = new Batman._Batman(object);
|
|
return false;
|
|
}
|
|
return true;
|
|
};
|
|
|
|
_Batman.prototype.get = function(key) {
|
|
var reduction, results;
|
|
results = this.getAll(key);
|
|
switch (results.length) {
|
|
case 0:
|
|
return void 0;
|
|
case 1:
|
|
return results[0];
|
|
default:
|
|
reduction = results[0].concat != null ? function(a, b) {
|
|
return a.concat(b);
|
|
} : results[0].merge != null ? function(a, b) {
|
|
return a.merge(b);
|
|
} : results.every(function(x) {
|
|
return typeof x === 'object';
|
|
}) ? (results.unshift({}), function(a, b) {
|
|
return Batman.extend(a, b);
|
|
}) : void 0;
|
|
if (reduction) {
|
|
return results.reduceRight(reduction);
|
|
} else {
|
|
return results;
|
|
}
|
|
}
|
|
};
|
|
|
|
_Batman.prototype.getFirst = function(key) {
|
|
var results;
|
|
results = this.getAll(key);
|
|
return results[0];
|
|
};
|
|
|
|
_Batman.prototype.getAll = function(keyOrGetter) {
|
|
var getter, results, val;
|
|
if (typeof keyOrGetter === 'function') {
|
|
getter = keyOrGetter;
|
|
} else {
|
|
getter = function(ancestor) {
|
|
var _ref;
|
|
return (_ref = ancestor._batman) != null ? _ref[keyOrGetter] : void 0;
|
|
};
|
|
}
|
|
results = this.ancestors(getter);
|
|
if (val = getter(this.object)) {
|
|
results.unshift(val);
|
|
}
|
|
return results;
|
|
};
|
|
|
|
_Batman.prototype.ancestors = function(getter) {
|
|
var isClass, parent, proto, results, val, _ref, _ref1;
|
|
if (getter == null) {
|
|
getter = function(x) {
|
|
return x;
|
|
};
|
|
}
|
|
results = [];
|
|
isClass = !!this.object.prototype;
|
|
parent = isClass ? (_ref = this.object.__super__) != null ? _ref.constructor : void 0 : (proto = Object.getPrototypeOf(this.object)) === this.object ? this.object.constructor.__super__ : proto;
|
|
if (parent != null) {
|
|
if ((_ref1 = parent._batman) != null) {
|
|
_ref1.check(parent);
|
|
}
|
|
val = getter(parent);
|
|
if (val != null) {
|
|
results.push(val);
|
|
}
|
|
if (parent._batman != null) {
|
|
results = results.concat(parent._batman.ancestors(getter));
|
|
}
|
|
}
|
|
return results;
|
|
};
|
|
|
|
_Batman.prototype.set = function(key, value) {
|
|
return this[key] = value;
|
|
};
|
|
|
|
return _Batman;
|
|
|
|
})();
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
|
|
Batman.Event = (function() {
|
|
|
|
Event.forBaseAndKey = function(base, key) {
|
|
if (base.isEventEmitter) {
|
|
return base.event(key);
|
|
} else {
|
|
return new Batman.Event(base, key);
|
|
}
|
|
};
|
|
|
|
function Event(base, key) {
|
|
this.base = base;
|
|
this.key = key;
|
|
this.handlers = [];
|
|
this._preventCount = 0;
|
|
}
|
|
|
|
Event.prototype.isEvent = true;
|
|
|
|
Event.prototype.isEqual = function(other) {
|
|
return this.constructor === other.constructor && this.base === other.base && this.key === other.key;
|
|
};
|
|
|
|
Event.prototype.hashKey = function() {
|
|
var key;
|
|
this.hashKey = function() {
|
|
return key;
|
|
};
|
|
return key = "<Batman.Event base: " + (Batman.Hash.prototype.hashKeyFor(this.base)) + ", key: \"" + (Batman.Hash.prototype.hashKeyFor(this.key)) + "\">";
|
|
};
|
|
|
|
Event.prototype.addHandler = function(handler) {
|
|
if (this.handlers.indexOf(handler) === -1) {
|
|
this.handlers.push(handler);
|
|
}
|
|
if (this.oneShot) {
|
|
this.autofireHandler(handler);
|
|
}
|
|
return this;
|
|
};
|
|
|
|
Event.prototype.removeHandler = function(handler) {
|
|
var index;
|
|
if ((index = this.handlers.indexOf(handler)) !== -1) {
|
|
this.handlers.splice(index, 1);
|
|
}
|
|
return this;
|
|
};
|
|
|
|
Event.prototype.eachHandler = function(iterator) {
|
|
var key, _ref, _ref1;
|
|
this.handlers.slice().forEach(iterator);
|
|
if ((_ref = this.base) != null ? _ref.isEventEmitter : void 0) {
|
|
key = this.key;
|
|
return (_ref1 = this.base._batman) != null ? _ref1.ancestors(function(ancestor) {
|
|
var handlers, _ref2, _ref3;
|
|
if (ancestor.isEventEmitter && ((_ref2 = ancestor._batman) != null ? (_ref3 = _ref2.events) != null ? _ref3.hasOwnProperty(key) : void 0 : void 0)) {
|
|
handlers = ancestor.event(key).handlers;
|
|
return handlers.slice().forEach(iterator);
|
|
}
|
|
}) : void 0;
|
|
}
|
|
};
|
|
|
|
Event.prototype.clearHandlers = function() {
|
|
return this.handlers = [];
|
|
};
|
|
|
|
Event.prototype.handlerContext = function() {
|
|
return this.base;
|
|
};
|
|
|
|
Event.prototype.prevent = function() {
|
|
return ++this._preventCount;
|
|
};
|
|
|
|
Event.prototype.allow = function() {
|
|
if (this._preventCount) {
|
|
--this._preventCount;
|
|
}
|
|
return this._preventCount;
|
|
};
|
|
|
|
Event.prototype.isPrevented = function() {
|
|
return this._preventCount > 0;
|
|
};
|
|
|
|
Event.prototype.autofireHandler = function(handler) {
|
|
if (this._oneShotFired && (this._oneShotArgs != null)) {
|
|
return handler.apply(this.handlerContext(), this._oneShotArgs);
|
|
}
|
|
};
|
|
|
|
Event.prototype.resetOneShot = function() {
|
|
this._oneShotFired = false;
|
|
return this._oneShotArgs = null;
|
|
};
|
|
|
|
Event.prototype.fire = function() {
|
|
var args, context;
|
|
if (this.isPrevented() || this._oneShotFired) {
|
|
return false;
|
|
}
|
|
context = this.handlerContext();
|
|
args = arguments;
|
|
if (this.oneShot) {
|
|
this._oneShotFired = true;
|
|
this._oneShotArgs = arguments;
|
|
}
|
|
return this.eachHandler(function(handler) {
|
|
return handler.apply(context, args);
|
|
});
|
|
};
|
|
|
|
Event.prototype.allowAndFire = function() {
|
|
this.allow();
|
|
return this.fire.apply(this, arguments);
|
|
};
|
|
|
|
return Event;
|
|
|
|
})();
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.PropertyEvent = (function(_super) {
|
|
|
|
__extends(PropertyEvent, _super);
|
|
|
|
function PropertyEvent() {
|
|
return PropertyEvent.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
PropertyEvent.prototype.eachHandler = function(iterator) {
|
|
return this.base.eachObserver(iterator);
|
|
};
|
|
|
|
PropertyEvent.prototype.handlerContext = function() {
|
|
return this.base.base;
|
|
};
|
|
|
|
return PropertyEvent;
|
|
|
|
})(Batman.Event);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __slice = [].slice;
|
|
|
|
Batman.EventEmitter = {
|
|
isEventEmitter: true,
|
|
hasEvent: function(key) {
|
|
var _ref, _ref1;
|
|
return (_ref = this._batman) != null ? typeof _ref.get === "function" ? (_ref1 = _ref.get('events')) != null ? _ref1.hasOwnProperty(key) : void 0 : void 0 : void 0;
|
|
},
|
|
event: function(key) {
|
|
var eventClass, events, existingEvent, newEvent, _base;
|
|
Batman.initializeObject(this);
|
|
eventClass = this.eventClass || Batman.Event;
|
|
events = (_base = this._batman).events || (_base.events = {});
|
|
if (events.hasOwnProperty(key)) {
|
|
return existingEvent = events[key];
|
|
} else {
|
|
this._batman.ancestors(function(ancestor) {
|
|
var _ref, _ref1;
|
|
return existingEvent || (existingEvent = (_ref = ancestor._batman) != null ? (_ref1 = _ref.events) != null ? _ref1[key] : void 0 : void 0);
|
|
});
|
|
newEvent = events[key] = new eventClass(this, key);
|
|
newEvent.oneShot = existingEvent != null ? existingEvent.oneShot : void 0;
|
|
return newEvent;
|
|
}
|
|
},
|
|
on: function() {
|
|
var handler, key, keys, _i, _j, _len, _results;
|
|
keys = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), handler = arguments[_i++];
|
|
_results = [];
|
|
for (_j = 0, _len = keys.length; _j < _len; _j++) {
|
|
key = keys[_j];
|
|
_results.push(this.event(key).addHandler(handler));
|
|
}
|
|
return _results;
|
|
},
|
|
once: function(key, handler) {
|
|
var event, handlerWrapper;
|
|
event = this.event(key);
|
|
handlerWrapper = function() {
|
|
handler.apply(this, arguments);
|
|
return event.removeHandler(handlerWrapper);
|
|
};
|
|
return event.addHandler(handlerWrapper);
|
|
},
|
|
registerAsMutableSource: function() {
|
|
return Batman.Property.registerSource(this);
|
|
},
|
|
mutation: function(wrappedFunction) {
|
|
return function() {
|
|
var result;
|
|
result = wrappedFunction.apply(this, arguments);
|
|
this.event('change').fire(this, this);
|
|
return result;
|
|
};
|
|
},
|
|
prevent: function(key) {
|
|
this.event(key).prevent();
|
|
return this;
|
|
},
|
|
allow: function(key) {
|
|
this.event(key).allow();
|
|
return this;
|
|
},
|
|
isPrevented: function(key) {
|
|
return this.event(key).isPrevented();
|
|
},
|
|
fire: function() {
|
|
var args, key, _ref;
|
|
key = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
|
return (_ref = this.event(key)).fire.apply(_ref, args);
|
|
},
|
|
allowAndFire: function() {
|
|
var args, key, _ref;
|
|
key = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
|
return (_ref = this.event(key)).allowAndFire.apply(_ref, args);
|
|
}
|
|
};
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __slice = [].slice;
|
|
|
|
Batman.Enumerable = {
|
|
isEnumerable: true,
|
|
map: function(f, ctx) {
|
|
var r;
|
|
if (ctx == null) {
|
|
ctx = Batman.container;
|
|
}
|
|
r = [];
|
|
this.forEach(function() {
|
|
return r.push(f.apply(ctx, arguments));
|
|
});
|
|
return r;
|
|
},
|
|
mapToProperty: function(key) {
|
|
var r;
|
|
r = [];
|
|
this.forEach(function(item) {
|
|
return r.push(item.get(key));
|
|
});
|
|
return r;
|
|
},
|
|
every: function(f, ctx) {
|
|
var r;
|
|
if (ctx == null) {
|
|
ctx = Batman.container;
|
|
}
|
|
r = true;
|
|
this.forEach(function() {
|
|
return r = r && f.apply(ctx, arguments);
|
|
});
|
|
return r;
|
|
},
|
|
some: function(f, ctx) {
|
|
var r;
|
|
if (ctx == null) {
|
|
ctx = Batman.container;
|
|
}
|
|
r = false;
|
|
this.forEach(function() {
|
|
return r = r || f.apply(ctx, arguments);
|
|
});
|
|
return r;
|
|
},
|
|
reduce: function(f, r) {
|
|
var count, self;
|
|
count = 0;
|
|
self = this;
|
|
this.forEach(function() {
|
|
if (r != null) {
|
|
return r = f.apply(null, [r].concat(__slice.call(arguments), [count], [self]));
|
|
} else {
|
|
return r = arguments[0];
|
|
}
|
|
});
|
|
return r;
|
|
},
|
|
filter: function(f) {
|
|
var r, wrap;
|
|
r = new this.constructor;
|
|
if (r.add) {
|
|
wrap = function(r, e) {
|
|
if (f(e)) {
|
|
r.add(e);
|
|
}
|
|
return r;
|
|
};
|
|
} else if (r.set) {
|
|
wrap = function(r, k, v) {
|
|
if (f(k, v)) {
|
|
r.set(k, v);
|
|
}
|
|
return r;
|
|
};
|
|
} else {
|
|
if (!r.push) {
|
|
r = [];
|
|
}
|
|
wrap = function(r, e) {
|
|
if (f(e)) {
|
|
r.push(e);
|
|
}
|
|
return r;
|
|
};
|
|
}
|
|
return this.reduce(wrap, r);
|
|
},
|
|
inGroupsOf: function(n) {
|
|
var current, i, r;
|
|
r = [];
|
|
current = false;
|
|
i = 0;
|
|
this.forEach(function(x) {
|
|
if (i++ % n === 0) {
|
|
current = [];
|
|
r.push(current);
|
|
}
|
|
return current.push(x);
|
|
});
|
|
return r;
|
|
}
|
|
};
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __slice = [].slice;
|
|
|
|
Batman.SimpleHash = (function() {
|
|
|
|
function SimpleHash(obj) {
|
|
this._storage = {};
|
|
this.length = 0;
|
|
if (obj != null) {
|
|
this.update(obj);
|
|
}
|
|
}
|
|
|
|
Batman.extend(SimpleHash.prototype, Batman.Enumerable);
|
|
|
|
SimpleHash.prototype.propertyClass = Batman.Property;
|
|
|
|
SimpleHash.prototype.hasKey = function(key) {
|
|
var pair, pairs, _i, _len;
|
|
if (this.objectKey(key)) {
|
|
if (!this._objectStorage) {
|
|
return false;
|
|
}
|
|
if (pairs = this._objectStorage[this.hashKeyFor(key)]) {
|
|
for (_i = 0, _len = pairs.length; _i < _len; _i++) {
|
|
pair = pairs[_i];
|
|
if (this.equality(pair[0], key)) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
} else {
|
|
key = this.prefixedKey(key);
|
|
return this._storage.hasOwnProperty(key);
|
|
}
|
|
};
|
|
|
|
SimpleHash.prototype.get = function(key) {
|
|
var pair, pairs, _i, _len;
|
|
if (this.objectKey(key)) {
|
|
if (!this._objectStorage) {
|
|
return void 0;
|
|
}
|
|
if (pairs = this._objectStorage[this.hashKeyFor(key)]) {
|
|
for (_i = 0, _len = pairs.length; _i < _len; _i++) {
|
|
pair = pairs[_i];
|
|
if (this.equality(pair[0], key)) {
|
|
return pair[1];
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
return this._storage[this.prefixedKey(key)];
|
|
}
|
|
};
|
|
|
|
SimpleHash.prototype.set = function(key, val) {
|
|
var pair, pairs, _base, _i, _len, _name;
|
|
if (this.objectKey(key)) {
|
|
this._objectStorage || (this._objectStorage = {});
|
|
pairs = (_base = this._objectStorage)[_name = this.hashKeyFor(key)] || (_base[_name] = []);
|
|
for (_i = 0, _len = pairs.length; _i < _len; _i++) {
|
|
pair = pairs[_i];
|
|
if (this.equality(pair[0], key)) {
|
|
return pair[1] = val;
|
|
}
|
|
}
|
|
this.length++;
|
|
pairs.push([key, val]);
|
|
return val;
|
|
} else {
|
|
key = this.prefixedKey(key);
|
|
if (this._storage[key] == null) {
|
|
this.length++;
|
|
}
|
|
return this._storage[key] = val;
|
|
}
|
|
};
|
|
|
|
SimpleHash.prototype.unset = function(key) {
|
|
var hashKey, index, obj, pair, pairs, val, value, _i, _len, _ref;
|
|
if (this.objectKey(key)) {
|
|
if (!this._objectStorage) {
|
|
return void 0;
|
|
}
|
|
hashKey = this.hashKeyFor(key);
|
|
if (pairs = this._objectStorage[hashKey]) {
|
|
for (index = _i = 0, _len = pairs.length; _i < _len; index = ++_i) {
|
|
_ref = pairs[index], obj = _ref[0], value = _ref[1];
|
|
if (this.equality(obj, key)) {
|
|
pair = pairs.splice(index, 1);
|
|
if (!pairs.length) {
|
|
delete this._objectStorage[hashKey];
|
|
}
|
|
this.length--;
|
|
return pair[0][1];
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
key = this.prefixedKey(key);
|
|
val = this._storage[key];
|
|
if (this._storage[key] != null) {
|
|
this.length--;
|
|
delete this._storage[key];
|
|
}
|
|
return val;
|
|
}
|
|
};
|
|
|
|
SimpleHash.prototype.getOrSet = function(key, valueFunction) {
|
|
var currentValue;
|
|
currentValue = this.get(key);
|
|
if (!currentValue) {
|
|
currentValue = valueFunction();
|
|
this.set(key, currentValue);
|
|
}
|
|
return currentValue;
|
|
};
|
|
|
|
SimpleHash.prototype.prefixedKey = function(key) {
|
|
return "_" + key;
|
|
};
|
|
|
|
SimpleHash.prototype.unprefixedKey = function(key) {
|
|
return key.slice(1);
|
|
};
|
|
|
|
SimpleHash.prototype.hashKeyFor = function(obj) {
|
|
return (obj != null ? typeof obj.hashKey === "function" ? obj.hashKey() : void 0 : void 0) || obj;
|
|
};
|
|
|
|
SimpleHash.prototype.equality = function(lhs, rhs) {
|
|
if (lhs === rhs) {
|
|
return true;
|
|
}
|
|
if (lhs !== lhs && rhs !== rhs) {
|
|
return true;
|
|
}
|
|
if ((lhs != null ? typeof lhs.isEqual === "function" ? lhs.isEqual(rhs) : void 0 : void 0) && (rhs != null ? typeof rhs.isEqual === "function" ? rhs.isEqual(lhs) : void 0 : void 0)) {
|
|
return true;
|
|
}
|
|
return false;
|
|
};
|
|
|
|
SimpleHash.prototype.objectKey = function(key) {
|
|
return typeof key !== 'string';
|
|
};
|
|
|
|
SimpleHash.prototype.forEach = function(iterator, ctx) {
|
|
var key, obj, results, value, values, _i, _len, _ref, _ref1, _ref2, _ref3;
|
|
results = [];
|
|
if (this._objectStorage) {
|
|
_ref = this._objectStorage;
|
|
for (key in _ref) {
|
|
values = _ref[key];
|
|
_ref1 = values.slice();
|
|
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
|
_ref2 = _ref1[_i], obj = _ref2[0], value = _ref2[1];
|
|
results.push(iterator.call(ctx, obj, value, this));
|
|
}
|
|
}
|
|
}
|
|
_ref3 = this._storage;
|
|
for (key in _ref3) {
|
|
value = _ref3[key];
|
|
results.push(iterator.call(ctx, this.unprefixedKey(key), value, this));
|
|
}
|
|
return results;
|
|
};
|
|
|
|
SimpleHash.prototype.keys = function() {
|
|
var result;
|
|
result = [];
|
|
Batman.SimpleHash.prototype.forEach.call(this, function(key) {
|
|
return result.push(key);
|
|
});
|
|
return result;
|
|
};
|
|
|
|
SimpleHash.prototype.toArray = SimpleHash.prototype.keys;
|
|
|
|
SimpleHash.prototype.clear = function() {
|
|
this._storage = {};
|
|
delete this._objectStorage;
|
|
return this.length = 0;
|
|
};
|
|
|
|
SimpleHash.prototype.isEmpty = function() {
|
|
return this.length === 0;
|
|
};
|
|
|
|
SimpleHash.prototype.merge = function() {
|
|
var hash, merged, others, _i, _len;
|
|
others = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
merged = new this.constructor;
|
|
others.unshift(this);
|
|
for (_i = 0, _len = others.length; _i < _len; _i++) {
|
|
hash = others[_i];
|
|
hash.forEach(function(obj, value) {
|
|
return merged.set(obj, value);
|
|
});
|
|
}
|
|
return merged;
|
|
};
|
|
|
|
SimpleHash.prototype.update = function(object) {
|
|
var k, v, _results;
|
|
_results = [];
|
|
for (k in object) {
|
|
v = object[k];
|
|
_results.push(this.set(k, v));
|
|
}
|
|
return _results;
|
|
};
|
|
|
|
SimpleHash.prototype.replace = function(object) {
|
|
var _this = this;
|
|
this.forEach(function(key, value) {
|
|
if (!(key in object)) {
|
|
return _this.unset(key);
|
|
}
|
|
});
|
|
return this.update(object);
|
|
};
|
|
|
|
SimpleHash.prototype.toObject = function() {
|
|
var key, obj, pair, value, _ref, _ref1;
|
|
obj = {};
|
|
_ref = this._storage;
|
|
for (key in _ref) {
|
|
value = _ref[key];
|
|
obj[this.unprefixedKey(key)] = value;
|
|
}
|
|
if (this._objectStorage) {
|
|
_ref1 = this._objectStorage;
|
|
for (key in _ref1) {
|
|
pair = _ref1[key];
|
|
obj[key] = pair[0][1];
|
|
}
|
|
}
|
|
return obj;
|
|
};
|
|
|
|
SimpleHash.prototype.toJSON = SimpleHash.prototype.toObject;
|
|
|
|
return SimpleHash;
|
|
|
|
})();
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
__slice = [].slice;
|
|
|
|
Batman.AssociationCurator = (function(_super) {
|
|
|
|
__extends(AssociationCurator, _super);
|
|
|
|
AssociationCurator.availableAssociations = ['belongsTo', 'hasOne', 'hasMany'];
|
|
|
|
function AssociationCurator(model) {
|
|
this.model = model;
|
|
AssociationCurator.__super__.constructor.call(this);
|
|
this._byTypeStorage = new Batman.SimpleHash;
|
|
}
|
|
|
|
AssociationCurator.prototype.add = function(association) {
|
|
var associationTypeSet;
|
|
this.set(association.label, association);
|
|
if (!(associationTypeSet = this._byTypeStorage.get(association.associationType))) {
|
|
associationTypeSet = new Batman.SimpleSet;
|
|
this._byTypeStorage.set(association.associationType, associationTypeSet);
|
|
}
|
|
return associationTypeSet.add(association);
|
|
};
|
|
|
|
AssociationCurator.prototype.getByType = function(type) {
|
|
return this._byTypeStorage.get(type);
|
|
};
|
|
|
|
AssociationCurator.prototype.getByLabel = function(label) {
|
|
return this.get(label);
|
|
};
|
|
|
|
AssociationCurator.prototype.reset = function() {
|
|
this.forEach(function(label, association) {
|
|
return association.reset();
|
|
});
|
|
return true;
|
|
};
|
|
|
|
AssociationCurator.prototype.merge = function() {
|
|
var others, result;
|
|
others = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
result = AssociationCurator.__super__.merge.apply(this, arguments);
|
|
result._byTypeStorage = this._byTypeStorage.merge(others.map(function(other) {
|
|
return other._byTypeStorage;
|
|
}));
|
|
return result;
|
|
};
|
|
|
|
AssociationCurator.prototype._markDirtyAttribute = function(key, oldValue) {
|
|
var _ref;
|
|
if ((_ref = this.lifecycle.get('state')) !== 'loading' && _ref !== 'creating' && _ref !== 'saving' && _ref !== 'saved') {
|
|
if (this.lifecycle.startTransition('set')) {
|
|
return this.dirtyKeys.set(key, oldValue);
|
|
} else {
|
|
throw new Batman.StateMachine.InvalidTransitionError("Can't set while in state " + (this.lifecycle.get('state')));
|
|
}
|
|
}
|
|
};
|
|
|
|
return AssociationCurator;
|
|
|
|
})(Batman.SimpleHash);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __slice = [].slice;
|
|
|
|
Batman.SimpleSet = (function() {
|
|
|
|
function SimpleSet() {
|
|
this._storage = [];
|
|
this.length = 0;
|
|
if (arguments.length > 0) {
|
|
this.add.apply(this, arguments);
|
|
}
|
|
}
|
|
|
|
Batman.extend(SimpleSet.prototype, Batman.Enumerable);
|
|
|
|
SimpleSet.prototype.has = function(item) {
|
|
return !!(~this._indexOfItem(item));
|
|
};
|
|
|
|
SimpleSet.prototype.add = function() {
|
|
var addedItems, item, items, _i, _len;
|
|
items = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
addedItems = [];
|
|
for (_i = 0, _len = items.length; _i < _len; _i++) {
|
|
item = items[_i];
|
|
if (!(!~this._indexOfItem(item))) {
|
|
continue;
|
|
}
|
|
this._storage.push(item);
|
|
addedItems.push(item);
|
|
}
|
|
this.length = this._storage.length;
|
|
if (this.fire && addedItems.length !== 0) {
|
|
this.fire('change', this, this);
|
|
this.fire.apply(this, ['itemsWereAdded'].concat(__slice.call(addedItems)));
|
|
}
|
|
return addedItems;
|
|
};
|
|
|
|
SimpleSet.prototype.remove = function() {
|
|
var index, item, items, removedItems, _i, _len;
|
|
items = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
removedItems = [];
|
|
for (_i = 0, _len = items.length; _i < _len; _i++) {
|
|
item = items[_i];
|
|
if (!(~(index = this._indexOfItem(item)))) {
|
|
continue;
|
|
}
|
|
this._storage.splice(index, 1);
|
|
removedItems.push(item);
|
|
}
|
|
this.length = this._storage.length;
|
|
if (this.fire && removedItems.length !== 0) {
|
|
this.fire('change', this, this);
|
|
this.fire.apply(this, ['itemsWereRemoved'].concat(__slice.call(removedItems)));
|
|
}
|
|
return removedItems;
|
|
};
|
|
|
|
SimpleSet.prototype.find = function(f) {
|
|
var item, _i, _len, _ref;
|
|
_ref = this._storage;
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
item = _ref[_i];
|
|
if (f(item)) {
|
|
return item;
|
|
}
|
|
}
|
|
};
|
|
|
|
SimpleSet.prototype.forEach = function(iterator, ctx) {
|
|
var container;
|
|
container = this;
|
|
return this._storage.slice().forEach(function(key) {
|
|
return iterator.call(ctx, key, null, container);
|
|
});
|
|
};
|
|
|
|
SimpleSet.prototype.isEmpty = function() {
|
|
return this.length === 0;
|
|
};
|
|
|
|
SimpleSet.prototype.clear = function() {
|
|
var items;
|
|
items = this._storage;
|
|
this._storage = [];
|
|
this.length = 0;
|
|
if (this.fire && items.length !== 0) {
|
|
this.fire('change', this, this);
|
|
this.fire.apply(this, ['itemsWereRemoved'].concat(__slice.call(items)));
|
|
}
|
|
return items;
|
|
};
|
|
|
|
SimpleSet.prototype.replace = function(other) {
|
|
try {
|
|
if (typeof this.prevent === "function") {
|
|
this.prevent('change');
|
|
}
|
|
this.clear();
|
|
return this.add.apply(this, other.toArray());
|
|
} finally {
|
|
if (typeof this.allowAndFire === "function") {
|
|
this.allowAndFire('change', this, this);
|
|
}
|
|
}
|
|
};
|
|
|
|
SimpleSet.prototype.toArray = function() {
|
|
return this._storage.slice();
|
|
};
|
|
|
|
SimpleSet.prototype.merge = function() {
|
|
var merged, others, set, _i, _len;
|
|
others = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
merged = new this.constructor;
|
|
others.unshift(this);
|
|
for (_i = 0, _len = others.length; _i < _len; _i++) {
|
|
set = others[_i];
|
|
set.forEach(function(v) {
|
|
return merged.add(v);
|
|
});
|
|
}
|
|
return merged;
|
|
};
|
|
|
|
SimpleSet.prototype.indexedBy = function(key) {
|
|
this._indexes || (this._indexes = new Batman.SimpleHash);
|
|
return this._indexes.get(key) || this._indexes.set(key, new Batman.SetIndex(this, key));
|
|
};
|
|
|
|
SimpleSet.prototype.indexedByUnique = function(key) {
|
|
this._uniqueIndexes || (this._uniqueIndexes = new Batman.SimpleHash);
|
|
return this._uniqueIndexes.get(key) || this._uniqueIndexes.set(key, new Batman.UniqueSetIndex(this, key));
|
|
};
|
|
|
|
SimpleSet.prototype.sortedBy = function(key, order) {
|
|
var sortsForKey;
|
|
if (order == null) {
|
|
order = "asc";
|
|
}
|
|
order = order.toLowerCase() === "desc" ? "desc" : "asc";
|
|
this._sorts || (this._sorts = new Batman.SimpleHash);
|
|
sortsForKey = this._sorts.get(key) || this._sorts.set(key, new Batman.Object);
|
|
return sortsForKey.get(order) || sortsForKey.set(order, new Batman.SetSort(this, key, order));
|
|
};
|
|
|
|
SimpleSet.prototype.equality = Batman.SimpleHash.prototype.equality;
|
|
|
|
SimpleSet.prototype._indexOfItem = function(givenItem) {
|
|
var index, item, _i, _len, _ref;
|
|
_ref = this._storage;
|
|
for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) {
|
|
item = _ref[index];
|
|
if (this.equality(givenItem, item)) {
|
|
return index;
|
|
}
|
|
}
|
|
return -1;
|
|
};
|
|
|
|
return SimpleSet;
|
|
|
|
})();
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __slice = [].slice;
|
|
|
|
Batman.Property = (function() {
|
|
|
|
Batman.mixin(Property.prototype, Batman.EventEmitter);
|
|
|
|
Property._sourceTrackerStack = [];
|
|
|
|
Property.sourceTracker = function() {
|
|
var stack;
|
|
return (stack = this._sourceTrackerStack)[stack.length - 1];
|
|
};
|
|
|
|
Property.defaultAccessor = {
|
|
get: function(key) {
|
|
return this[key];
|
|
},
|
|
set: function(key, val) {
|
|
return this[key] = val;
|
|
},
|
|
unset: function(key) {
|
|
var x;
|
|
x = this[key];
|
|
delete this[key];
|
|
return x;
|
|
},
|
|
cache: false
|
|
};
|
|
|
|
Property.defaultAccessorForBase = function(base) {
|
|
var _ref;
|
|
return ((_ref = base._batman) != null ? _ref.getFirst('defaultAccessor') : void 0) || Batman.Property.defaultAccessor;
|
|
};
|
|
|
|
Property.accessorForBaseAndKey = function(base, key) {
|
|
var accessor, _bm, _ref,
|
|
_this = this;
|
|
if ((_bm = base._batman) != null) {
|
|
accessor = (_ref = _bm.keyAccessors) != null ? _ref.get(key) : void 0;
|
|
if (!accessor) {
|
|
_bm.ancestors(function(ancestor) {
|
|
var _ref1, _ref2;
|
|
return accessor || (accessor = (_ref1 = ancestor._batman) != null ? (_ref2 = _ref1.keyAccessors) != null ? _ref2.get(key) : void 0 : void 0);
|
|
});
|
|
}
|
|
}
|
|
return accessor || this.defaultAccessorForBase(base);
|
|
};
|
|
|
|
Property.forBaseAndKey = function(base, key) {
|
|
if (base.isObservable) {
|
|
return base.property(key);
|
|
} else {
|
|
return new Batman.Keypath(base, key);
|
|
}
|
|
};
|
|
|
|
Property.withoutTracking = function(block) {
|
|
return this.wrapTrackingPrevention(block)();
|
|
};
|
|
|
|
Property.wrapTrackingPrevention = function(block) {
|
|
return function() {
|
|
Batman.Property.pushDummySourceTracker();
|
|
try {
|
|
return block.apply(this, arguments);
|
|
} finally {
|
|
Batman.Property.popSourceTracker();
|
|
}
|
|
};
|
|
};
|
|
|
|
Property.registerSource = function(obj) {
|
|
var _ref;
|
|
if (!obj.isEventEmitter) {
|
|
return;
|
|
}
|
|
return (_ref = this.sourceTracker()) != null ? _ref.add(obj) : void 0;
|
|
};
|
|
|
|
Property.pushSourceTracker = function() {
|
|
return Batman.Property._sourceTrackerStack.push(new Batman.SimpleSet);
|
|
};
|
|
|
|
Property.pushDummySourceTracker = function() {
|
|
return Batman.Property._sourceTrackerStack.push(null);
|
|
};
|
|
|
|
Property.popSourceTracker = function() {
|
|
return Batman.Property._sourceTrackerStack.pop();
|
|
};
|
|
|
|
function Property(base, key) {
|
|
this.base = base;
|
|
this.key = key;
|
|
}
|
|
|
|
Property.prototype._isolationCount = 0;
|
|
|
|
Property.prototype.cached = false;
|
|
|
|
Property.prototype.value = null;
|
|
|
|
Property.prototype.sources = null;
|
|
|
|
Property.prototype.isProperty = true;
|
|
|
|
Property.prototype.isDead = false;
|
|
|
|
Property.prototype.eventClass = Batman.PropertyEvent;
|
|
|
|
Property.prototype.isEqual = function(other) {
|
|
return this.constructor === other.constructor && this.base === other.base && this.key === other.key;
|
|
};
|
|
|
|
Property.prototype.hashKey = function() {
|
|
var key;
|
|
this.hashKey = function() {
|
|
return key;
|
|
};
|
|
return key = "<Batman.Property base: " + (Batman.Hash.prototype.hashKeyFor(this.base)) + ", key: \"" + (Batman.Hash.prototype.hashKeyFor(this.key)) + "\">";
|
|
};
|
|
|
|
Property.prototype.event = function(key) {
|
|
var eventClass, _base;
|
|
eventClass = this.eventClass || Batman.Event;
|
|
this.events || (this.events = {});
|
|
(_base = this.events)[key] || (_base[key] = new eventClass(this, key));
|
|
return this.events[key];
|
|
};
|
|
|
|
Property.prototype.changeEvent = function() {
|
|
var event;
|
|
event = this.event('change');
|
|
this.changeEvent = function() {
|
|
return event;
|
|
};
|
|
return event;
|
|
};
|
|
|
|
Property.prototype.accessor = function() {
|
|
var accessor;
|
|
accessor = this.constructor.accessorForBaseAndKey(this.base, this.key);
|
|
this.accessor = function() {
|
|
return accessor;
|
|
};
|
|
return accessor;
|
|
};
|
|
|
|
Property.prototype.eachObserver = function(iterator) {
|
|
var key;
|
|
key = this.key;
|
|
this.changeEvent().handlers.slice().forEach(iterator);
|
|
if (this.base.isObservable) {
|
|
return this.base._batman.ancestors(function(ancestor) {
|
|
var handlers, property;
|
|
if (ancestor.isObservable && ancestor.hasProperty(key)) {
|
|
property = ancestor.property(key);
|
|
handlers = property.changeEvent().handlers;
|
|
return handlers.slice().forEach(iterator);
|
|
}
|
|
});
|
|
}
|
|
};
|
|
|
|
Property.prototype.observers = function() {
|
|
var results;
|
|
results = [];
|
|
this.eachObserver(function(observer) {
|
|
return results.push(observer);
|
|
});
|
|
return results;
|
|
};
|
|
|
|
Property.prototype.hasObservers = function() {
|
|
return this.observers().length > 0;
|
|
};
|
|
|
|
Property.prototype.updateSourcesFromTracker = function() {
|
|
var handler, newSources;
|
|
newSources = this.constructor.popSourceTracker();
|
|
handler = this.sourceChangeHandler();
|
|
this._eachSourceChangeEvent(function(e) {
|
|
return e.removeHandler(handler);
|
|
});
|
|
this.sources = newSources;
|
|
return this._eachSourceChangeEvent(function(e) {
|
|
return e.addHandler(handler);
|
|
});
|
|
};
|
|
|
|
Property.prototype._eachSourceChangeEvent = function(iterator) {
|
|
if (this.sources == null) {
|
|
return;
|
|
}
|
|
return this.sources.forEach(function(source) {
|
|
return iterator(source.event('change'));
|
|
});
|
|
};
|
|
|
|
Property.prototype.getValue = function() {
|
|
this.registerAsMutableSource();
|
|
if (!this.isCached()) {
|
|
this.constructor.pushSourceTracker();
|
|
try {
|
|
this.value = this.valueFromAccessor();
|
|
this.cached = true;
|
|
} finally {
|
|
this.updateSourcesFromTracker();
|
|
}
|
|
}
|
|
return this.value;
|
|
};
|
|
|
|
Property.prototype.isCachable = function() {
|
|
var cacheable;
|
|
if (this.isFinal()) {
|
|
return true;
|
|
}
|
|
cacheable = this.accessor().cache;
|
|
if (cacheable != null) {
|
|
return !!cacheable;
|
|
} else {
|
|
return true;
|
|
}
|
|
};
|
|
|
|
Property.prototype.isCached = function() {
|
|
return this.isCachable() && this.cached;
|
|
};
|
|
|
|
Property.prototype.isFinal = function() {
|
|
return !!this.accessor()['final'];
|
|
};
|
|
|
|
Property.prototype.refresh = function() {
|
|
var previousValue, value;
|
|
this.cached = false;
|
|
previousValue = this.value;
|
|
value = this.getValue();
|
|
if (value !== previousValue && !this.isIsolated()) {
|
|
this.fire(value, previousValue);
|
|
}
|
|
if (this.value !== void 0 && this.isFinal()) {
|
|
return this.lockValue();
|
|
}
|
|
};
|
|
|
|
Property.prototype.sourceChangeHandler = function() {
|
|
var handler,
|
|
_this = this;
|
|
handler = this._handleSourceChange.bind(this);
|
|
Batman.developer["do"](function() {
|
|
return handler.property = _this;
|
|
});
|
|
this.sourceChangeHandler = function() {
|
|
return handler;
|
|
};
|
|
return handler;
|
|
};
|
|
|
|
Property.prototype._handleSourceChange = function() {
|
|
if (this.isIsolated()) {
|
|
return this._needsRefresh = true;
|
|
} else if (!this.isFinal() && !this.hasObservers()) {
|
|
return this.cached = false;
|
|
} else {
|
|
return this.refresh();
|
|
}
|
|
};
|
|
|
|
Property.prototype.valueFromAccessor = function() {
|
|
var _ref;
|
|
return (_ref = this.accessor().get) != null ? _ref.call(this.base, this.key) : void 0;
|
|
};
|
|
|
|
Property.prototype.setValue = function(val) {
|
|
var set;
|
|
if (!(set = this.accessor().set)) {
|
|
return;
|
|
}
|
|
return this._changeValue(function() {
|
|
return set.call(this.base, this.key, val);
|
|
});
|
|
};
|
|
|
|
Property.prototype.unsetValue = function() {
|
|
var unset;
|
|
if (!(unset = this.accessor().unset)) {
|
|
return;
|
|
}
|
|
return this._changeValue(function() {
|
|
return unset.call(this.base, this.key);
|
|
});
|
|
};
|
|
|
|
Property.prototype._changeValue = function(block) {
|
|
var result;
|
|
this.cached = false;
|
|
this.constructor.pushDummySourceTracker();
|
|
try {
|
|
result = block.apply(this);
|
|
this.refresh();
|
|
} finally {
|
|
this.constructor.popSourceTracker();
|
|
}
|
|
if (!(this.isCached() || this.hasObservers())) {
|
|
this.die();
|
|
}
|
|
return result;
|
|
};
|
|
|
|
Property.prototype.forget = function(handler) {
|
|
if (handler != null) {
|
|
return this.changeEvent().removeHandler(handler);
|
|
} else {
|
|
return this.changeEvent().clearHandlers();
|
|
}
|
|
};
|
|
|
|
Property.prototype.observeAndFire = function(handler) {
|
|
this.observe(handler);
|
|
return handler.call(this.base, this.value, this.value, this.key);
|
|
};
|
|
|
|
Property.prototype.observe = function(handler) {
|
|
this.changeEvent().addHandler(handler);
|
|
if (this.sources == null) {
|
|
this.getValue();
|
|
}
|
|
return this;
|
|
};
|
|
|
|
Property.prototype.observeOnce = function(originalHandler) {
|
|
var event, handler;
|
|
event = this.changeEvent();
|
|
handler = function() {
|
|
originalHandler.apply(this, arguments);
|
|
return event.removeHandler(handler);
|
|
};
|
|
event.addHandler(handler);
|
|
if (this.sources == null) {
|
|
this.getValue();
|
|
}
|
|
return this;
|
|
};
|
|
|
|
Property.prototype._removeHandlers = function() {
|
|
var handler;
|
|
handler = this.sourceChangeHandler();
|
|
this._eachSourceChangeEvent(function(e) {
|
|
return e.removeHandler(handler);
|
|
});
|
|
delete this.sources;
|
|
return this.changeEvent().clearHandlers();
|
|
};
|
|
|
|
Property.prototype.lockValue = function() {
|
|
this._removeHandlers();
|
|
this.getValue = function() {
|
|
return this.value;
|
|
};
|
|
return this.setValue = this.unsetValue = this.refresh = this.observe = function() {};
|
|
};
|
|
|
|
Property.prototype.die = function() {
|
|
var _ref, _ref1;
|
|
this._removeHandlers();
|
|
if ((_ref = this.base._batman) != null) {
|
|
if ((_ref1 = _ref.properties) != null) {
|
|
_ref1.unset(this.key);
|
|
}
|
|
}
|
|
return this.isDead = true;
|
|
};
|
|
|
|
Property.prototype.fire = function() {
|
|
var _ref;
|
|
return (_ref = this.changeEvent()).fire.apply(_ref, __slice.call(arguments).concat([this.key]));
|
|
};
|
|
|
|
Property.prototype.isolate = function() {
|
|
if (this._isolationCount === 0) {
|
|
this._preIsolationValue = this.getValue();
|
|
}
|
|
return this._isolationCount++;
|
|
};
|
|
|
|
Property.prototype.expose = function() {
|
|
if (this._isolationCount === 1) {
|
|
this._isolationCount--;
|
|
if (this._needsRefresh) {
|
|
this.value = this._preIsolationValue;
|
|
this.refresh();
|
|
} else if (this.value !== this._preIsolationValue) {
|
|
this.fire(this.value, this._preIsolationValue);
|
|
}
|
|
return this._preIsolationValue = null;
|
|
} else if (this._isolationCount > 0) {
|
|
return this._isolationCount--;
|
|
}
|
|
};
|
|
|
|
Property.prototype.isIsolated = function() {
|
|
return this._isolationCount > 0;
|
|
};
|
|
|
|
return Property;
|
|
|
|
})();
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.Keypath = (function(_super) {
|
|
|
|
__extends(Keypath, _super);
|
|
|
|
function Keypath(base, key) {
|
|
if (typeof key === 'string') {
|
|
this.segments = key.split('.');
|
|
this.depth = this.segments.length;
|
|
} else {
|
|
this.segments = [key];
|
|
this.depth = 1;
|
|
}
|
|
Keypath.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
Keypath.prototype.isCachable = function() {
|
|
if (this.depth === 1) {
|
|
return Keypath.__super__.isCachable.apply(this, arguments);
|
|
} else {
|
|
return true;
|
|
}
|
|
};
|
|
|
|
Keypath.prototype.terminalProperty = function() {
|
|
var base;
|
|
base = Batman.getPath(this.base, this.segments.slice(0, -1));
|
|
if (base == null) {
|
|
return;
|
|
}
|
|
return Batman.Keypath.forBaseAndKey(base, this.segments[this.depth - 1]);
|
|
};
|
|
|
|
Keypath.prototype.valueFromAccessor = function() {
|
|
if (this.depth === 1) {
|
|
return Keypath.__super__.valueFromAccessor.apply(this, arguments);
|
|
} else {
|
|
return Batman.getPath(this.base, this.segments);
|
|
}
|
|
};
|
|
|
|
Keypath.prototype.setValue = function(val) {
|
|
var _ref;
|
|
if (this.depth === 1) {
|
|
return Keypath.__super__.setValue.apply(this, arguments);
|
|
} else {
|
|
return (_ref = this.terminalProperty()) != null ? _ref.setValue(val) : void 0;
|
|
}
|
|
};
|
|
|
|
Keypath.prototype.unsetValue = function() {
|
|
var _ref;
|
|
if (this.depth === 1) {
|
|
return Keypath.__super__.unsetValue.apply(this, arguments);
|
|
} else {
|
|
return (_ref = this.terminalProperty()) != null ? _ref.unsetValue() : void 0;
|
|
}
|
|
};
|
|
|
|
return Keypath;
|
|
|
|
})(Batman.Property);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __slice = [].slice;
|
|
|
|
Batman.Observable = {
|
|
isObservable: true,
|
|
hasProperty: function(key) {
|
|
var _ref, _ref1;
|
|
return (_ref = this._batman) != null ? (_ref1 = _ref.properties) != null ? typeof _ref1.hasKey === "function" ? _ref1.hasKey(key) : void 0 : void 0 : void 0;
|
|
},
|
|
property: function(key) {
|
|
var properties, propertyClass, _base;
|
|
Batman.initializeObject(this);
|
|
propertyClass = this.propertyClass || Batman.Keypath;
|
|
properties = (_base = this._batman).properties || (_base.properties = new Batman.SimpleHash);
|
|
return properties.get(key) || properties.set(key, new propertyClass(this, key));
|
|
},
|
|
get: function(key) {
|
|
return this.property(key).getValue();
|
|
},
|
|
set: function(key, val) {
|
|
return this.property(key).setValue(val);
|
|
},
|
|
unset: function(key) {
|
|
return this.property(key).unsetValue();
|
|
},
|
|
getOrSet: Batman.SimpleHash.prototype.getOrSet,
|
|
forget: function(key, observer) {
|
|
var _ref;
|
|
if (key) {
|
|
this.property(key).forget(observer);
|
|
} else {
|
|
if ((_ref = this._batman.properties) != null) {
|
|
_ref.forEach(function(key, property) {
|
|
return property.forget();
|
|
});
|
|
}
|
|
}
|
|
return this;
|
|
},
|
|
observe: function() {
|
|
var args, key, _ref;
|
|
key = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
|
(_ref = this.property(key)).observe.apply(_ref, args);
|
|
return this;
|
|
},
|
|
observeAndFire: function() {
|
|
var args, key, _ref;
|
|
key = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
|
(_ref = this.property(key)).observeAndFire.apply(_ref, args);
|
|
return this;
|
|
},
|
|
observeOnce: function() {
|
|
var args, key, _ref;
|
|
key = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
|
(_ref = this.property(key)).observeOnce.apply(_ref, args);
|
|
return this;
|
|
}
|
|
};
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
|
|
Batman.DOM = {
|
|
textInputTypes: ['text', 'search', 'tel', 'url', 'email', 'password'],
|
|
scrollIntoView: function(elementID) {
|
|
var _ref;
|
|
return (_ref = document.getElementById(elementID)) != null ? typeof _ref.scrollIntoView === "function" ? _ref.scrollIntoView() : void 0 : void 0;
|
|
},
|
|
partial: function(container, path, context, renderer) {
|
|
var view;
|
|
renderer.prevent('rendered');
|
|
view = new Batman.View({
|
|
source: path,
|
|
context: context
|
|
});
|
|
return view.on('ready', function() {
|
|
Batman.DOM.setInnerHTML(container, '');
|
|
Batman.DOM.appendChild(container, view.get('node'));
|
|
return renderer.allowAndFire('rendered');
|
|
});
|
|
},
|
|
propagateBindingEvent: function(binding, node) {
|
|
var current, parentBinding, parentBindings, _i, _len;
|
|
while ((current = (current || node).parentNode)) {
|
|
parentBindings = Batman._data(current, 'bindings');
|
|
if (parentBindings != null) {
|
|
for (_i = 0, _len = parentBindings.length; _i < _len; _i++) {
|
|
parentBinding = parentBindings[_i];
|
|
if (typeof parentBinding.childBindingAdded === "function") {
|
|
parentBinding.childBindingAdded(binding);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
},
|
|
propagateBindingEvents: function(newNode) {
|
|
var binding, bindings, child, _i, _j, _len, _len1, _ref;
|
|
_ref = newNode.childNodes;
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
child = _ref[_i];
|
|
Batman.DOM.propagateBindingEvents(child);
|
|
}
|
|
if (bindings = Batman._data(newNode, 'bindings')) {
|
|
for (_j = 0, _len1 = bindings.length; _j < _len1; _j++) {
|
|
binding = bindings[_j];
|
|
Batman.DOM.propagateBindingEvent(binding, newNode);
|
|
}
|
|
}
|
|
},
|
|
trackBinding: function(binding, node) {
|
|
var bindings;
|
|
if (bindings = Batman._data(node, 'bindings')) {
|
|
bindings.push(binding);
|
|
} else {
|
|
Batman._data(node, 'bindings', [binding]);
|
|
}
|
|
Batman.DOM.fire('bindingAdded', binding);
|
|
Batman.DOM.propagateBindingEvent(binding, node);
|
|
return true;
|
|
},
|
|
onParseExit: function(node, callback) {
|
|
var set;
|
|
set = Batman._data(node, 'onParseExit') || Batman._data(node, 'onParseExit', new Batman.SimpleSet);
|
|
if (callback != null) {
|
|
set.add(callback);
|
|
}
|
|
return set;
|
|
},
|
|
forgetParseExit: function(node, callback) {
|
|
return Batman.removeData(node, 'onParseExit', true);
|
|
},
|
|
defineView: function(name, node) {
|
|
var contents;
|
|
contents = node.innerHTML;
|
|
Batman.View.store.set(Batman.Navigator.normalizePath(name), contents);
|
|
return contents;
|
|
},
|
|
setStyleProperty: function(node, property, value, importance) {
|
|
if (node.style.setProperty) {
|
|
return node.style.setProperty(property, value, importance);
|
|
} else {
|
|
return node.style.setAttribute(property, value, importance);
|
|
}
|
|
},
|
|
removeOrDestroyNode: function(node) {
|
|
var view;
|
|
view = Batman._data(node, 'view');
|
|
view || (view = Batman._data(node, 'yielder'));
|
|
if ((view != null) && view.get('cached')) {
|
|
return Batman.DOM.removeNode(node);
|
|
} else {
|
|
return Batman.DOM.destroyNode(node);
|
|
}
|
|
},
|
|
insertBefore: function(parentNode, newNode, referenceNode) {
|
|
if (referenceNode == null) {
|
|
referenceNode = null;
|
|
}
|
|
if (!referenceNode || parentNode.childNodes.length <= 0) {
|
|
return Batman.DOM.appendChild(parentNode, newNode);
|
|
} else {
|
|
Batman.DOM.willInsertNode(newNode);
|
|
parentNode.insertBefore(newNode, referenceNode);
|
|
return Batman.DOM.didInsertNode(newNode);
|
|
}
|
|
},
|
|
valueForNode: function(node, value, escapeValue) {
|
|
var isSetting;
|
|
if (value == null) {
|
|
value = '';
|
|
}
|
|
if (escapeValue == null) {
|
|
escapeValue = true;
|
|
}
|
|
isSetting = arguments.length > 1;
|
|
switch (node.nodeName.toUpperCase()) {
|
|
case 'INPUT':
|
|
case 'TEXTAREA':
|
|
if (isSetting) {
|
|
return node.value = value;
|
|
} else {
|
|
return node.value;
|
|
}
|
|
break;
|
|
case 'SELECT':
|
|
if (isSetting) {
|
|
return node.value = value;
|
|
}
|
|
break;
|
|
default:
|
|
if (isSetting) {
|
|
return Batman.DOM.setInnerHTML(node, escapeValue ? Batman.escapeHTML(value) : value);
|
|
} else {
|
|
return node.innerHTML;
|
|
}
|
|
}
|
|
},
|
|
nodeIsEditable: function(node) {
|
|
var _ref;
|
|
return (_ref = node.nodeName.toUpperCase()) === 'INPUT' || _ref === 'TEXTAREA' || _ref === 'SELECT';
|
|
},
|
|
addEventListener: function(node, eventName, callback) {
|
|
var listeners;
|
|
if (!(listeners = Batman._data(node, 'listeners'))) {
|
|
listeners = Batman._data(node, 'listeners', {});
|
|
}
|
|
if (!listeners[eventName]) {
|
|
listeners[eventName] = [];
|
|
}
|
|
listeners[eventName].push(callback);
|
|
if (Batman.DOM.hasAddEventListener) {
|
|
return node.addEventListener(eventName, callback, false);
|
|
} else {
|
|
return node.attachEvent("on" + eventName, callback);
|
|
}
|
|
},
|
|
removeEventListener: function(node, eventName, callback) {
|
|
var eventListeners, index, listeners;
|
|
if (listeners = Batman._data(node, 'listeners')) {
|
|
if (eventListeners = listeners[eventName]) {
|
|
index = eventListeners.indexOf(callback);
|
|
if (index !== -1) {
|
|
eventListeners.splice(index, 1);
|
|
}
|
|
}
|
|
}
|
|
if (Batman.DOM.hasAddEventListener) {
|
|
return node.removeEventListener(eventName, callback, false);
|
|
} else {
|
|
return node.detachEvent('on' + eventName, callback);
|
|
}
|
|
},
|
|
hasAddEventListener: !!(typeof window !== "undefined" && window !== null ? window.addEventListener : void 0),
|
|
preventDefault: function(e) {
|
|
if (typeof e.preventDefault === "function") {
|
|
return e.preventDefault();
|
|
} else {
|
|
return e.returnValue = false;
|
|
}
|
|
},
|
|
stopPropagation: function(e) {
|
|
if (e.stopPropagation) {
|
|
return e.stopPropagation();
|
|
} else {
|
|
return e.cancelBubble = true;
|
|
}
|
|
},
|
|
willInsertNode: function(node) {
|
|
var child, view, _i, _len, _ref, _ref1;
|
|
view = Batman._data(node, 'view');
|
|
if (view != null) {
|
|
view.fire('beforeAppear', node);
|
|
}
|
|
if ((_ref = Batman.data(node, 'show')) != null) {
|
|
_ref.call(node);
|
|
}
|
|
_ref1 = node.childNodes;
|
|
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
|
child = _ref1[_i];
|
|
Batman.DOM.willInsertNode(child);
|
|
}
|
|
return true;
|
|
},
|
|
didInsertNode: function(node) {
|
|
var child, view, _i, _len, _ref;
|
|
view = Batman._data(node, 'view');
|
|
if (view) {
|
|
view.fire('appear', node);
|
|
view.applyYields();
|
|
}
|
|
_ref = node.childNodes;
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
child = _ref[_i];
|
|
Batman.DOM.didInsertNode(child);
|
|
}
|
|
return true;
|
|
},
|
|
willRemoveNode: function(node) {
|
|
var child, view, _i, _len, _ref, _ref1;
|
|
view = Batman._data(node, 'view');
|
|
if (view) {
|
|
view.fire('beforeDisappear', node);
|
|
}
|
|
if ((_ref = Batman.data(node, 'hide')) != null) {
|
|
_ref.call(node);
|
|
}
|
|
_ref1 = node.childNodes;
|
|
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
|
child = _ref1[_i];
|
|
Batman.DOM.willRemoveNode(child);
|
|
}
|
|
return true;
|
|
},
|
|
didRemoveNode: function(node) {
|
|
var child, view, _i, _len, _ref;
|
|
view = Batman._data(node, 'view');
|
|
if (view) {
|
|
view.retractYields();
|
|
view.fire('disappear', node);
|
|
}
|
|
_ref = node.childNodes;
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
child = _ref[_i];
|
|
Batman.DOM.didRemoveNode(child);
|
|
}
|
|
return true;
|
|
},
|
|
willDestroyNode: function(node) {
|
|
var child, view, _i, _len, _ref;
|
|
view = Batman._data(node, 'view');
|
|
if (view) {
|
|
view.fire('beforeDestroy', node);
|
|
view.get('yields').forEach(function(name, actions) {
|
|
var _i, _len, _results;
|
|
_results = [];
|
|
for (_i = 0, _len = actions.length; _i < _len; _i++) {
|
|
node = actions[_i].node;
|
|
_results.push(Batman.DOM.willDestroyNode(node));
|
|
}
|
|
return _results;
|
|
});
|
|
}
|
|
_ref = node.childNodes;
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
child = _ref[_i];
|
|
Batman.DOM.willDestroyNode(child);
|
|
}
|
|
return true;
|
|
},
|
|
didDestroyNode: function(node) {
|
|
var bindings, child, eventListeners, eventName, listeners, view, _i, _len, _ref;
|
|
view = Batman._data(node, 'view');
|
|
if (view) {
|
|
view.fire('destroy', node);
|
|
view.get('yields').forEach(function(name, actions) {
|
|
var _i, _len, _results;
|
|
_results = [];
|
|
for (_i = 0, _len = actions.length; _i < _len; _i++) {
|
|
node = actions[_i].node;
|
|
_results.push(Batman.DOM.didDestroyNode(node));
|
|
}
|
|
return _results;
|
|
});
|
|
}
|
|
if (bindings = Batman._data(node, 'bindings')) {
|
|
bindings.forEach(function(binding) {
|
|
return binding.die();
|
|
});
|
|
}
|
|
if (listeners = Batman._data(node, 'listeners')) {
|
|
for (eventName in listeners) {
|
|
eventListeners = listeners[eventName];
|
|
eventListeners.forEach(function(listener) {
|
|
return Batman.DOM.removeEventListener(node, eventName, listener);
|
|
});
|
|
}
|
|
}
|
|
Batman.removeData(node);
|
|
Batman.removeData(node, void 0, true);
|
|
_ref = node.childNodes;
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
child = _ref[_i];
|
|
Batman.DOM.didDestroyNode(child);
|
|
}
|
|
return true;
|
|
}
|
|
};
|
|
|
|
Batman.mixin(Batman.DOM, Batman.EventEmitter, Batman.Observable);
|
|
|
|
Batman.DOM.event('bindingAdded');
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __slice = [].slice;
|
|
|
|
Batman.DOM.readers = {
|
|
target: function(node, key, context, renderer) {
|
|
Batman.DOM.readers.bind(node, key, context, renderer, 'nodeChange');
|
|
return true;
|
|
},
|
|
source: function(node, key, context, renderer) {
|
|
Batman.DOM.readers.bind(node, key, context, renderer, 'dataChange');
|
|
return true;
|
|
},
|
|
bind: function(node, key, context, renderer, only) {
|
|
var bindingClass;
|
|
bindingClass = false;
|
|
switch (node.nodeName.toLowerCase()) {
|
|
case 'input':
|
|
switch (node.getAttribute('type')) {
|
|
case 'checkbox':
|
|
Batman.DOM.attrReaders.bind(node, 'checked', key, context, renderer, only);
|
|
return true;
|
|
case 'radio':
|
|
bindingClass = Batman.DOM.RadioBinding;
|
|
break;
|
|
case 'file':
|
|
bindingClass = Batman.DOM.FileBinding;
|
|
}
|
|
break;
|
|
case 'select':
|
|
bindingClass = Batman.DOM.SelectBinding;
|
|
}
|
|
bindingClass || (bindingClass = Batman.DOM.Binding);
|
|
(function(func, args, ctor) {
|
|
ctor.prototype = func.prototype;
|
|
var child = new ctor, result = func.apply(child, args), t = typeof result;
|
|
return t == "object" || t == "function" ? result || child : child;
|
|
})(bindingClass, arguments, function(){});
|
|
return true;
|
|
},
|
|
context: function(node, key, context, renderer) {
|
|
return context.descendWithKey(key);
|
|
},
|
|
mixin: function(node, key, context, renderer) {
|
|
new Batman.DOM.MixinBinding(node, key, context.descend(Batman.mixins), renderer);
|
|
return true;
|
|
},
|
|
showif: function(node, key, context, parentRenderer, invert) {
|
|
new Batman.DOM.ShowHideBinding(node, key, context, parentRenderer, false, invert);
|
|
return true;
|
|
},
|
|
hideif: function() {
|
|
var _ref;
|
|
return (_ref = Batman.DOM.readers).showif.apply(_ref, __slice.call(arguments).concat([true]));
|
|
},
|
|
insertif: function(node, key, context, parentRenderer, invert) {
|
|
new Batman.DOM.InsertionBinding(node, key, context, parentRenderer, false, invert);
|
|
return true;
|
|
},
|
|
removeif: function() {
|
|
var _ref;
|
|
return (_ref = Batman.DOM.readers).insertif.apply(_ref, __slice.call(arguments).concat([true]));
|
|
},
|
|
route: function() {
|
|
(function(func, args, ctor) {
|
|
ctor.prototype = func.prototype;
|
|
var child = new ctor, result = func.apply(child, args), t = typeof result;
|
|
return t == "object" || t == "function" ? result || child : child;
|
|
})(Batman.DOM.RouteBinding, arguments, function(){});
|
|
return true;
|
|
},
|
|
view: function() {
|
|
(function(func, args, ctor) {
|
|
ctor.prototype = func.prototype;
|
|
var child = new ctor, result = func.apply(child, args), t = typeof result;
|
|
return t == "object" || t == "function" ? result || child : child;
|
|
})(Batman.DOM.ViewBinding, arguments, function(){});
|
|
return false;
|
|
},
|
|
partial: function(node, path, context, renderer) {
|
|
Batman.DOM.partial(node, path, context, renderer);
|
|
return true;
|
|
},
|
|
defineview: function(node, name, context, renderer) {
|
|
Batman.DOM.onParseExit(node, function() {
|
|
var _ref;
|
|
return (_ref = node.parentNode) != null ? _ref.removeChild(node) : void 0;
|
|
});
|
|
Batman.DOM.defineView(name, node);
|
|
return false;
|
|
},
|
|
renderif: function(node, key, context, renderer) {
|
|
new Batman.DOM.DeferredRenderingBinding(node, key, context, renderer);
|
|
return false;
|
|
},
|
|
"yield": function(node, key) {
|
|
Batman.DOM.onParseExit(node, function() {
|
|
return Batman.DOM.Yield.withName(key).set('containerNode', node);
|
|
});
|
|
return true;
|
|
},
|
|
contentfor: function(node, key, context, renderer, action) {
|
|
if (action == null) {
|
|
action = 'append';
|
|
}
|
|
Batman.DOM.onParseExit(node, function() {
|
|
var _ref;
|
|
if ((_ref = node.parentNode) != null) {
|
|
_ref.removeChild(node);
|
|
}
|
|
return renderer.view.pushYieldAction(key, action, node);
|
|
});
|
|
return true;
|
|
},
|
|
replace: function(node, key, context, renderer) {
|
|
Batman.DOM.readers.contentfor(node, key, context, renderer, 'replace');
|
|
return true;
|
|
}
|
|
};
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __slice = [].slice,
|
|
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
|
|
|
Batman.DOM.events = {
|
|
click: function(node, callback, context, eventName) {
|
|
if (eventName == null) {
|
|
eventName = 'click';
|
|
}
|
|
Batman.DOM.addEventListener(node, eventName, function() {
|
|
var args, event;
|
|
event = arguments[0], args = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
|
if (event.metaKey || event.ctrlKey) {
|
|
return;
|
|
}
|
|
Batman.DOM.preventDefault(event);
|
|
if (!Batman.DOM.eventIsAllowed(eventName, event)) {
|
|
return;
|
|
}
|
|
return callback.apply(null, [node, event].concat(__slice.call(args), [context]));
|
|
});
|
|
if (node.nodeName.toUpperCase() === 'A' && !node.href) {
|
|
node.href = '#';
|
|
}
|
|
return node;
|
|
},
|
|
doubleclick: function(node, callback, context) {
|
|
return Batman.DOM.events.click(node, callback, context, 'dblclick');
|
|
},
|
|
change: function(node, callback, context) {
|
|
var eventName, eventNames, oldCallback, _i, _len, _results;
|
|
eventNames = (function() {
|
|
var _ref;
|
|
switch (node.nodeName.toUpperCase()) {
|
|
case 'TEXTAREA':
|
|
return ['input', 'keyup', 'change'];
|
|
case 'INPUT':
|
|
if (_ref = node.type.toLowerCase(), __indexOf.call(Batman.DOM.textInputTypes, _ref) >= 0) {
|
|
oldCallback = callback;
|
|
callback = function(node, event) {
|
|
if (event.type === 'keyup' && Batman.DOM.events.isEnter(event)) {
|
|
return;
|
|
}
|
|
return oldCallback.apply(null, arguments);
|
|
};
|
|
return ['input', 'keyup', 'change'];
|
|
} else {
|
|
return ['input', 'change'];
|
|
}
|
|
break;
|
|
default:
|
|
return ['change'];
|
|
}
|
|
})();
|
|
_results = [];
|
|
for (_i = 0, _len = eventNames.length; _i < _len; _i++) {
|
|
eventName = eventNames[_i];
|
|
_results.push(Batman.DOM.addEventListener(node, eventName, function() {
|
|
var args;
|
|
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
return callback.apply(null, [node].concat(__slice.call(args), [context]));
|
|
}));
|
|
}
|
|
return _results;
|
|
},
|
|
isEnter: function(ev) {
|
|
var _ref, _ref1;
|
|
return ((13 <= (_ref = ev.keyCode) && _ref <= 14)) || ((13 <= (_ref1 = ev.which) && _ref1 <= 14)) || ev.keyIdentifier === 'Enter' || ev.key === 'Enter';
|
|
},
|
|
submit: function(node, callback, context) {
|
|
if (Batman.DOM.nodeIsEditable(node)) {
|
|
Batman.DOM.addEventListener(node, 'keydown', function() {
|
|
var args;
|
|
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
if (Batman.DOM.events.isEnter(args[0])) {
|
|
return Batman.DOM._keyCapturingNode = node;
|
|
}
|
|
});
|
|
Batman.DOM.addEventListener(node, 'keyup', function() {
|
|
var args;
|
|
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
if (Batman.DOM.events.isEnter(args[0])) {
|
|
if (Batman.DOM._keyCapturingNode === node) {
|
|
Batman.DOM.preventDefault(args[0]);
|
|
callback.apply(null, [node].concat(__slice.call(args), [context]));
|
|
}
|
|
return Batman.DOM._keyCapturingNode = null;
|
|
}
|
|
});
|
|
} else {
|
|
Batman.DOM.addEventListener(node, 'submit', function() {
|
|
var args;
|
|
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
Batman.DOM.preventDefault(args[0]);
|
|
return callback.apply(null, [node].concat(__slice.call(args), [context]));
|
|
});
|
|
}
|
|
return node;
|
|
},
|
|
other: function(node, eventName, callback, context) {
|
|
return Batman.DOM.addEventListener(node, eventName, function() {
|
|
var args;
|
|
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
return callback.apply(null, [node].concat(__slice.call(args), [context]));
|
|
});
|
|
}
|
|
};
|
|
|
|
Batman.DOM.eventIsAllowed = function(eventName, event) {
|
|
var delegate, _ref, _ref1;
|
|
if (delegate = (_ref = Batman.currentApp) != null ? (_ref1 = _ref.shouldAllowEvent) != null ? _ref1[eventName] : void 0 : void 0) {
|
|
if (delegate(event) === false) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
};
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
|
|
Batman.DOM.attrReaders = {
|
|
_parseAttribute: function(value) {
|
|
if (value === 'false') {
|
|
value = false;
|
|
}
|
|
if (value === 'true') {
|
|
value = true;
|
|
}
|
|
return value;
|
|
},
|
|
source: function(node, attr, key, context, renderer) {
|
|
return Batman.DOM.attrReaders.bind(node, attr, key, context, renderer, 'dataChange');
|
|
},
|
|
bind: function(node, attr, key, context, renderer, only) {
|
|
var bindingClass;
|
|
bindingClass = (function() {
|
|
switch (attr) {
|
|
case 'checked':
|
|
case 'disabled':
|
|
case 'selected':
|
|
return Batman.DOM.CheckedBinding;
|
|
case 'value':
|
|
case 'href':
|
|
case 'src':
|
|
case 'size':
|
|
return Batman.DOM.NodeAttributeBinding;
|
|
case 'class':
|
|
return Batman.DOM.ClassBinding;
|
|
case 'style':
|
|
return Batman.DOM.StyleBinding;
|
|
default:
|
|
return Batman.DOM.AttributeBinding;
|
|
}
|
|
})();
|
|
(function(func, args, ctor) {
|
|
ctor.prototype = func.prototype;
|
|
var child = new ctor, result = func.apply(child, args), t = typeof result;
|
|
return t == "object" || t == "function" ? result || child : child;
|
|
})(bindingClass, arguments, function(){});
|
|
return true;
|
|
},
|
|
context: function(node, contextName, key, context) {
|
|
return context.descendWithKey(key, contextName);
|
|
},
|
|
event: function(node, eventName, key, context) {
|
|
(function(func, args, ctor) {
|
|
ctor.prototype = func.prototype;
|
|
var child = new ctor, result = func.apply(child, args), t = typeof result;
|
|
return t == "object" || t == "function" ? result || child : child;
|
|
})(Batman.DOM.EventBinding, arguments, function(){});
|
|
return true;
|
|
},
|
|
addclass: function(node, className, key, context, parentRenderer, invert) {
|
|
new Batman.DOM.AddClassBinding(node, className, key, context, parentRenderer, false, invert);
|
|
return true;
|
|
},
|
|
removeclass: function(node, className, key, context, parentRenderer) {
|
|
return Batman.DOM.attrReaders.addclass(node, className, key, context, parentRenderer, true);
|
|
},
|
|
foreach: function(node, iteratorName, key, context, parentRenderer) {
|
|
(function(func, args, ctor) {
|
|
ctor.prototype = func.prototype;
|
|
var child = new ctor, result = func.apply(child, args), t = typeof result;
|
|
return t == "object" || t == "function" ? result || child : child;
|
|
})(Batman.DOM.IteratorBinding, arguments, function(){});
|
|
return false;
|
|
},
|
|
formfor: function(node, localName, key, context) {
|
|
(function(func, args, ctor) {
|
|
ctor.prototype = func.prototype;
|
|
var child = new ctor, result = func.apply(child, args), t = typeof result;
|
|
return t == "object" || t == "function" ? result || child : child;
|
|
})(Batman.DOM.FormBinding, arguments, function(){});
|
|
return context.descendWithKey(key, localName);
|
|
}
|
|
};
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var BatmanObject, ObjectFunctions, getAccessorObject, promiseWrapper, wrapSingleAccessor,
|
|
__slice = [].slice,
|
|
__hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
getAccessorObject = function(base, accessor) {
|
|
var deprecated, _i, _len, _ref;
|
|
if (typeof accessor === 'function') {
|
|
accessor = {
|
|
get: accessor
|
|
};
|
|
}
|
|
_ref = ['cachable', 'cacheable'];
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
deprecated = _ref[_i];
|
|
if (deprecated in accessor) {
|
|
Batman.developer.warn("Property accessor option \"" + deprecated + "\" is deprecated. Use \"cache\" instead.");
|
|
if (!('cache' in accessor)) {
|
|
accessor.cache = accessor[deprecated];
|
|
}
|
|
}
|
|
}
|
|
return accessor;
|
|
};
|
|
|
|
promiseWrapper = function(fetcher) {
|
|
return function(defaultAccessor) {
|
|
return {
|
|
get: function(key) {
|
|
var asyncDeliver, existingValue, newValue, _base, _base1, _ref, _ref1,
|
|
_this = this;
|
|
if ((existingValue = defaultAccessor.get.apply(this, arguments)) != null) {
|
|
return existingValue;
|
|
}
|
|
asyncDeliver = false;
|
|
newValue = void 0;
|
|
if ((_ref = (_base = this._batman).promises) == null) {
|
|
_base.promises = {};
|
|
}
|
|
if ((_ref1 = (_base1 = this._batman.promises)[key]) == null) {
|
|
_base1[key] = (function() {
|
|
var deliver, returnValue;
|
|
deliver = function(err, result) {
|
|
if (asyncDeliver) {
|
|
_this.set(key, result);
|
|
}
|
|
return newValue = result;
|
|
};
|
|
returnValue = fetcher.call(_this, deliver, key);
|
|
if (newValue == null) {
|
|
newValue = returnValue;
|
|
}
|
|
return true;
|
|
})();
|
|
}
|
|
asyncDeliver = true;
|
|
return newValue;
|
|
},
|
|
cache: true
|
|
};
|
|
};
|
|
};
|
|
|
|
wrapSingleAccessor = function(core, wrapper) {
|
|
var k, v;
|
|
wrapper = (typeof wrapper === "function" ? wrapper(core) : void 0) || wrapper;
|
|
for (k in core) {
|
|
v = core[k];
|
|
if (!(k in wrapper)) {
|
|
wrapper[k] = v;
|
|
}
|
|
}
|
|
return wrapper;
|
|
};
|
|
|
|
ObjectFunctions = {
|
|
_defineAccessor: function() {
|
|
var accessor, key, keys, _base, _i, _j, _len, _ref, _results;
|
|
keys = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), accessor = arguments[_i++];
|
|
if (!(accessor != null)) {
|
|
return Batman.Property.defaultAccessorForBase(this);
|
|
} else if (keys.length === 0 && ((_ref = Batman.typeOf(accessor)) !== 'Object' && _ref !== 'Function')) {
|
|
return Batman.Property.accessorForBaseAndKey(this, accessor);
|
|
} else if (typeof accessor.promise === 'function') {
|
|
return this._defineWrapAccessor.apply(this, __slice.call(keys).concat([promiseWrapper(accessor.promise)]));
|
|
}
|
|
Batman.initializeObject(this);
|
|
if (keys.length === 0) {
|
|
return this._batman.defaultAccessor = getAccessorObject(this, accessor);
|
|
} else {
|
|
(_base = this._batman).keyAccessors || (_base.keyAccessors = new Batman.SimpleHash);
|
|
_results = [];
|
|
for (_j = 0, _len = keys.length; _j < _len; _j++) {
|
|
key = keys[_j];
|
|
_results.push(this._batman.keyAccessors.set(key, getAccessorObject(this, accessor)));
|
|
}
|
|
return _results;
|
|
}
|
|
},
|
|
_defineWrapAccessor: function() {
|
|
var key, keys, wrapper, _i, _j, _len, _results;
|
|
keys = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), wrapper = arguments[_i++];
|
|
Batman.initializeObject(this);
|
|
if (keys.length === 0) {
|
|
return this._defineAccessor(wrapSingleAccessor(this._defineAccessor(), wrapper));
|
|
} else {
|
|
_results = [];
|
|
for (_j = 0, _len = keys.length; _j < _len; _j++) {
|
|
key = keys[_j];
|
|
_results.push(this._defineAccessor(key, wrapSingleAccessor(this._defineAccessor(key), wrapper)));
|
|
}
|
|
return _results;
|
|
}
|
|
},
|
|
_resetPromises: function() {
|
|
var key;
|
|
if (this._batman.promises == null) {
|
|
return;
|
|
}
|
|
for (key in this._batman.promises) {
|
|
this._resetPromise(key);
|
|
}
|
|
},
|
|
_resetPromise: function(key) {
|
|
this.unset(key);
|
|
this.property(key).cached = false;
|
|
delete this._batman.promises[key];
|
|
}
|
|
};
|
|
|
|
BatmanObject = (function(_super) {
|
|
var counter;
|
|
|
|
__extends(BatmanObject, _super);
|
|
|
|
Batman.initializeObject(BatmanObject);
|
|
|
|
Batman.initializeObject(BatmanObject.prototype);
|
|
|
|
Batman.mixin(BatmanObject.prototype, ObjectFunctions, Batman.EventEmitter, Batman.Observable);
|
|
|
|
Batman.mixin(BatmanObject, ObjectFunctions, Batman.EventEmitter, Batman.Observable);
|
|
|
|
BatmanObject.classMixin = function() {
|
|
return Batman.mixin.apply(Batman, [this].concat(__slice.call(arguments)));
|
|
};
|
|
|
|
BatmanObject.mixin = function() {
|
|
return this.classMixin.apply(this.prototype, arguments);
|
|
};
|
|
|
|
BatmanObject.prototype.mixin = BatmanObject.classMixin;
|
|
|
|
BatmanObject.classAccessor = BatmanObject._defineAccessor;
|
|
|
|
BatmanObject.accessor = function() {
|
|
var _ref;
|
|
return (_ref = this.prototype)._defineAccessor.apply(_ref, arguments);
|
|
};
|
|
|
|
BatmanObject.prototype.accessor = BatmanObject._defineAccessor;
|
|
|
|
BatmanObject.wrapClassAccessor = BatmanObject._defineWrapAccessor;
|
|
|
|
BatmanObject.wrapAccessor = function() {
|
|
var _ref;
|
|
return (_ref = this.prototype)._defineWrapAccessor.apply(_ref, arguments);
|
|
};
|
|
|
|
BatmanObject.prototype.wrapAccessor = BatmanObject._defineWrapAccessor;
|
|
|
|
BatmanObject.observeAll = function() {
|
|
return this.prototype.observe.apply(this.prototype, arguments);
|
|
};
|
|
|
|
BatmanObject.singleton = function(singletonMethodName) {
|
|
if (singletonMethodName == null) {
|
|
singletonMethodName = "sharedInstance";
|
|
}
|
|
return this.classAccessor(singletonMethodName, {
|
|
get: function() {
|
|
var _name;
|
|
return this[_name = "_" + singletonMethodName] || (this[_name] = new this);
|
|
}
|
|
});
|
|
};
|
|
|
|
BatmanObject.accessor('_batmanID', function() {
|
|
return this._batmanID();
|
|
});
|
|
|
|
function BatmanObject() {
|
|
var mixins;
|
|
mixins = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
this._batman = new Batman._Batman(this);
|
|
this.mixin.apply(this, mixins);
|
|
}
|
|
|
|
counter = 0;
|
|
|
|
BatmanObject.prototype._batmanID = function() {
|
|
var _base, _ref;
|
|
this._batman.check(this);
|
|
if ((_ref = (_base = this._batman).id) == null) {
|
|
_base.id = counter++;
|
|
}
|
|
return this._batman.id;
|
|
};
|
|
|
|
BatmanObject.prototype.hashKey = function() {
|
|
var key;
|
|
if (typeof this.isEqual === 'function') {
|
|
return;
|
|
}
|
|
this.hashKey = function() {
|
|
return key;
|
|
};
|
|
return key = "<Batman.Object " + (this._batmanID()) + ">";
|
|
};
|
|
|
|
BatmanObject.prototype.toJSON = function() {
|
|
var key, obj, value;
|
|
obj = {};
|
|
for (key in this) {
|
|
if (!__hasProp.call(this, key)) continue;
|
|
value = this[key];
|
|
if (key !== "_batman" && key !== "hashKey" && key !== "_batmanID") {
|
|
obj[key] = (value != null ? value.toJSON : void 0) ? value.toJSON() : value;
|
|
}
|
|
}
|
|
return obj;
|
|
};
|
|
|
|
return BatmanObject;
|
|
|
|
})(Object);
|
|
|
|
Batman.Object = BatmanObject;
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
|
__hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.Renderer = (function(_super) {
|
|
var bindingRegexp, bindingSortOrder, bindingSortPositions, k, name, pos, _i, _j, _len, _len1, _ref;
|
|
|
|
__extends(Renderer, _super);
|
|
|
|
Renderer.prototype.deferEvery = 50;
|
|
|
|
function Renderer(node, context, view) {
|
|
this.node = node;
|
|
this.context = context;
|
|
this.view = view;
|
|
this.resume = __bind(this.resume, this);
|
|
|
|
this.start = __bind(this.start, this);
|
|
|
|
Renderer.__super__.constructor.call(this);
|
|
if (!(this.context instanceof Batman.RenderContext)) {
|
|
Batman.developer.error("Must pass a RenderContext to a renderer for rendering");
|
|
}
|
|
this.immediate = Batman.setImmediate(this.start);
|
|
}
|
|
|
|
Renderer.prototype.start = function() {
|
|
this.startTime = new Date;
|
|
this.prevent('parsed');
|
|
this.prevent('rendered');
|
|
return this.parseNode(this.node);
|
|
};
|
|
|
|
Renderer.prototype.resume = function() {
|
|
this.startTime = new Date;
|
|
return this.parseNode(this.resumeNode);
|
|
};
|
|
|
|
Renderer.prototype.finish = function() {
|
|
this.startTime = null;
|
|
this.prevent('stopped');
|
|
this.allowAndFire('parsed');
|
|
return this.allowAndFire('rendered');
|
|
};
|
|
|
|
Renderer.prototype.stop = function() {
|
|
Batman.clearImmediate(this.immediate);
|
|
return this.fire('stopped');
|
|
};
|
|
|
|
_ref = ['parsed', 'rendered', 'stopped'];
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
k = _ref[_i];
|
|
Renderer.prototype.event(k).oneShot = true;
|
|
}
|
|
|
|
bindingRegexp = /^data\-(.*)/;
|
|
|
|
bindingSortOrder = ["view", "renderif", "foreach", "formfor", "context", "bind", "source", "target"];
|
|
|
|
bindingSortPositions = {};
|
|
|
|
for (pos = _j = 0, _len1 = bindingSortOrder.length; _j < _len1; pos = ++_j) {
|
|
name = bindingSortOrder[pos];
|
|
bindingSortPositions[name] = pos;
|
|
}
|
|
|
|
Renderer.prototype._sortBindings = function(a, b) {
|
|
var aindex, bindex;
|
|
aindex = bindingSortPositions[a[0]];
|
|
bindex = bindingSortPositions[b[0]];
|
|
if (aindex == null) {
|
|
aindex = bindingSortOrder.length;
|
|
}
|
|
if (bindex == null) {
|
|
bindex = bindingSortOrder.length;
|
|
}
|
|
if (aindex > bindex) {
|
|
return 1;
|
|
} else if (bindex > aindex) {
|
|
return -1;
|
|
} else if (a[0] > b[0]) {
|
|
return 1;
|
|
} else if (b[0] > a[0]) {
|
|
return -1;
|
|
} else {
|
|
return 0;
|
|
}
|
|
};
|
|
|
|
Renderer.prototype.parseNode = function(node) {
|
|
var argument, attribute, bindings, keypath, names, nextNode, oldContext, result, skipChildren, _base, _base1, _k, _l, _len2, _len3, _ref1, _ref2, _ref3, _ref4,
|
|
_this = this;
|
|
if (this.deferEvery && (new Date - this.startTime) > this.deferEvery) {
|
|
this.resumeNode = node;
|
|
this.timeout = Batman.setImmediate(this.resume);
|
|
return;
|
|
}
|
|
if (node.getAttribute && node.attributes) {
|
|
bindings = [];
|
|
_ref1 = node.attributes;
|
|
for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
|
|
attribute = _ref1[_k];
|
|
name = (_ref2 = attribute.nodeName.match(bindingRegexp)) != null ? _ref2[1] : void 0;
|
|
if (!name) {
|
|
continue;
|
|
}
|
|
bindings.push((names = name.split('-')).length > 1 ? [names[0], names.slice(1, names.length + 1 || 9e9).join('-'), attribute.value] : [name, void 0, attribute.value]);
|
|
}
|
|
_ref3 = bindings.sort(this._sortBindings);
|
|
for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) {
|
|
_ref4 = _ref3[_l], name = _ref4[0], argument = _ref4[1], keypath = _ref4[2];
|
|
result = argument ? typeof (_base = Batman.DOM.attrReaders)[name] === "function" ? _base[name](node, argument, keypath, this.context, this) : void 0 : typeof (_base1 = Batman.DOM.readers)[name] === "function" ? _base1[name](node, keypath, this.context, this) : void 0;
|
|
if (result === false) {
|
|
skipChildren = true;
|
|
break;
|
|
} else if (result instanceof Batman.RenderContext) {
|
|
oldContext = this.context;
|
|
this.context = result;
|
|
Batman.DOM.onParseExit(node, function() {
|
|
return _this.context = oldContext;
|
|
});
|
|
}
|
|
}
|
|
}
|
|
if ((nextNode = this.nextNode(node, skipChildren))) {
|
|
return this.parseNode(nextNode);
|
|
} else {
|
|
return this.finish();
|
|
}
|
|
};
|
|
|
|
Renderer.prototype.nextNode = function(node, skipChildren) {
|
|
var children, nextParent, parentSibling, sibling, _ref1, _ref2;
|
|
if (!skipChildren) {
|
|
children = node.childNodes;
|
|
if (children != null ? children.length : void 0) {
|
|
return children[0];
|
|
}
|
|
}
|
|
sibling = node.nextSibling;
|
|
if ((_ref1 = Batman.DOM.onParseExit(node)) != null) {
|
|
_ref1.forEach(function(callback) {
|
|
return callback();
|
|
});
|
|
}
|
|
Batman.DOM.forgetParseExit(node);
|
|
if (this.node === node) {
|
|
return;
|
|
}
|
|
if (sibling) {
|
|
return sibling;
|
|
}
|
|
nextParent = node;
|
|
while (nextParent = nextParent.parentNode) {
|
|
parentSibling = nextParent.nextSibling;
|
|
if ((_ref2 = Batman.DOM.onParseExit(nextParent)) != null) {
|
|
_ref2.forEach(function(callback) {
|
|
return callback();
|
|
});
|
|
}
|
|
Batman.DOM.forgetParseExit(nextParent);
|
|
if (this.node === nextParent) {
|
|
return;
|
|
}
|
|
if (parentSibling) {
|
|
return parentSibling;
|
|
}
|
|
}
|
|
};
|
|
|
|
return Renderer;
|
|
|
|
})(Batman.Object);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
|
__hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.DOM.AbstractBinding = (function(_super) {
|
|
var get_dot_rx, get_rx, keypath_rx;
|
|
|
|
__extends(AbstractBinding, _super);
|
|
|
|
keypath_rx = /(^|,)\s*(?:(true|false)|("[^"]*")|(\{[^\}]*\})|([a-zA-Z][\w\-\.]*[\?\!]?))\s*(?=$|,)/g;
|
|
|
|
get_dot_rx = /(?:\]\.)(.+?)(?=[\[\.]|\s*\||$)/;
|
|
|
|
get_rx = /(?!^\s*)\[(.*?)\]/g;
|
|
|
|
AbstractBinding.accessor('filteredValue', {
|
|
get: function() {
|
|
var renderContext, result, self, unfilteredValue;
|
|
unfilteredValue = this.get('unfilteredValue');
|
|
self = this;
|
|
renderContext = this.get('renderContext');
|
|
if (this.filterFunctions.length > 0) {
|
|
Batman.developer.currentFilterStack = renderContext;
|
|
result = this.filterFunctions.reduce(function(value, fn, i) {
|
|
var args;
|
|
args = self.filterArguments[i].map(function(argument) {
|
|
if (argument._keypath) {
|
|
return self.renderContext.get(argument._keypath);
|
|
} else {
|
|
return argument;
|
|
}
|
|
});
|
|
args.unshift(value);
|
|
while (args.length < (fn.length - 1)) {
|
|
args.push(void 0);
|
|
}
|
|
args.push(self);
|
|
return fn.apply(renderContext, args);
|
|
}, unfilteredValue);
|
|
Batman.developer.currentFilterStack = null;
|
|
return result;
|
|
} else {
|
|
return unfilteredValue;
|
|
}
|
|
},
|
|
set: function(_, newValue) {
|
|
return this.set('unfilteredValue', newValue);
|
|
}
|
|
});
|
|
|
|
AbstractBinding.accessor('unfilteredValue', {
|
|
get: function() {
|
|
var k;
|
|
if (k = this.get('key')) {
|
|
return Batman.RenderContext.deProxy(Batman.getPath(this, ['keyContext', k]));
|
|
} else {
|
|
return this.get('value');
|
|
}
|
|
},
|
|
set: function(_, value) {
|
|
var k, keyContext, prop;
|
|
if (k = this.get('key')) {
|
|
keyContext = this.get('keyContext');
|
|
if (keyContext && keyContext !== Batman.container) {
|
|
prop = Batman.Property.forBaseAndKey(keyContext, k);
|
|
return prop.setValue(value);
|
|
}
|
|
} else {
|
|
return this.set('value', value);
|
|
}
|
|
}
|
|
});
|
|
|
|
AbstractBinding.accessor('keyContext', function() {
|
|
return this.renderContext.contextForKey(this.key);
|
|
});
|
|
|
|
AbstractBinding.prototype.bindImmediately = true;
|
|
|
|
AbstractBinding.prototype.shouldSet = true;
|
|
|
|
AbstractBinding.prototype.isInputBinding = false;
|
|
|
|
AbstractBinding.prototype.escapeValue = true;
|
|
|
|
function AbstractBinding(node, keyPath, renderContext, renderer, only) {
|
|
this.node = node;
|
|
this.keyPath = keyPath;
|
|
this.renderContext = renderContext;
|
|
this.renderer = renderer;
|
|
this.only = only != null ? only : false;
|
|
this._fireDataChange = __bind(this._fireDataChange, this);
|
|
|
|
this._fireNodeChange = __bind(this._fireNodeChange, this);
|
|
|
|
this.parseFilter();
|
|
if (this.bindImmediately) {
|
|
this.bind();
|
|
}
|
|
}
|
|
|
|
AbstractBinding.prototype.isTwoWay = function() {
|
|
return (this.key != null) && this.filterFunctions.length === 0;
|
|
};
|
|
|
|
AbstractBinding.prototype.bind = function() {
|
|
var _ref, _ref1;
|
|
if ((this.node != null) && ((_ref = this.only) === false || _ref === 'nodeChange') && Batman.DOM.nodeIsEditable(this.node)) {
|
|
Batman.DOM.events.change(this.node, this._fireNodeChange);
|
|
if (this.only === 'nodeChange') {
|
|
this._fireNodeChange();
|
|
}
|
|
}
|
|
if ((_ref1 = this.only) === false || _ref1 === 'dataChange') {
|
|
this.observeAndFire('filteredValue', this._fireDataChange);
|
|
}
|
|
if (this.node != null) {
|
|
return Batman.DOM.trackBinding(this, this.node);
|
|
}
|
|
};
|
|
|
|
AbstractBinding.prototype._fireNodeChange = function(event) {
|
|
var val;
|
|
this.shouldSet = false;
|
|
val = this.value || this.get('keyContext');
|
|
if (typeof this.nodeChange === "function") {
|
|
this.nodeChange(this.node, val, event);
|
|
}
|
|
this.fire('nodeChange', this.node, val);
|
|
return this.shouldSet = true;
|
|
};
|
|
|
|
AbstractBinding.prototype._fireDataChange = function(value) {
|
|
if (this.shouldSet) {
|
|
if (typeof this.dataChange === "function") {
|
|
this.dataChange(value, this.node);
|
|
}
|
|
return this.fire('dataChange', value, this.node);
|
|
}
|
|
};
|
|
|
|
AbstractBinding.prototype.die = function() {
|
|
var _ref;
|
|
this.forget();
|
|
if ((_ref = this._batman.properties) != null) {
|
|
_ref.forEach(function(key, property) {
|
|
return property.die();
|
|
});
|
|
}
|
|
this.fire('die');
|
|
this.dead = true;
|
|
return true;
|
|
};
|
|
|
|
AbstractBinding.prototype.parseFilter = function() {
|
|
var args, filter, filterName, filterString, filters, key, keyPath, orig, split;
|
|
this.filterFunctions = [];
|
|
this.filterArguments = [];
|
|
keyPath = this.keyPath;
|
|
while (get_dot_rx.test(keyPath)) {
|
|
keyPath = keyPath.replace(get_dot_rx, "]['$1']");
|
|
}
|
|
filters = keyPath.replace(get_rx, " | get $1 ").replace(/'/g, '"').split(/(?!")\s+\|\s+(?!")/);
|
|
try {
|
|
key = this.parseSegment(orig = filters.shift())[0];
|
|
} catch (e) {
|
|
Batman.developer.warn(e);
|
|
Batman.developer.error("Error! Couldn't parse keypath in \"" + orig + "\". Parsing error above.");
|
|
}
|
|
if (key && key._keypath) {
|
|
this.key = key._keypath;
|
|
} else {
|
|
this.value = key;
|
|
}
|
|
if (filters.length) {
|
|
while (filterString = filters.shift()) {
|
|
split = filterString.indexOf(' ');
|
|
if (split === -1) {
|
|
split = filterString.length;
|
|
}
|
|
filterName = filterString.substr(0, split);
|
|
args = filterString.substr(split);
|
|
if (!(filter = Batman.Filters[filterName])) {
|
|
return Batman.developer.error("Unrecognized filter '" + filterName + "' in key \"" + this.keyPath + "\"!");
|
|
}
|
|
this.filterFunctions.push(filter);
|
|
try {
|
|
this.filterArguments.push(this.parseSegment(args));
|
|
} catch (e) {
|
|
Batman.developer.error("Bad filter arguments \"" + args + "\"!");
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
};
|
|
|
|
AbstractBinding.prototype.parseSegment = function(segment) {
|
|
segment = segment.replace(keypath_rx, function(match, start, bool, string, object, keypath, offset) {
|
|
var replacement;
|
|
if (start == null) {
|
|
start = '';
|
|
}
|
|
replacement = keypath ? '{"_keypath": "' + keypath + '"}' : bool || string || object;
|
|
return start + replacement;
|
|
});
|
|
return JSON.parse("[" + segment + "]");
|
|
};
|
|
|
|
return AbstractBinding;
|
|
|
|
})(Batman.Object);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.DOM.ViewBinding = (function(_super) {
|
|
|
|
__extends(ViewBinding, _super);
|
|
|
|
function ViewBinding() {
|
|
ViewBinding.__super__.constructor.apply(this, arguments);
|
|
this.renderer.prevent('rendered');
|
|
this.node.removeAttribute('data-view');
|
|
}
|
|
|
|
ViewBinding.prototype.dataChange = function(viewClassOrInstance) {
|
|
var _this = this;
|
|
if (viewClassOrInstance == null) {
|
|
return;
|
|
}
|
|
if (viewClassOrInstance.isView) {
|
|
this.view = viewClassOrInstance;
|
|
this.view.set('context', this.renderContext);
|
|
this.view.set('node', this.node);
|
|
} else {
|
|
this.view = new viewClassOrInstance({
|
|
node: this.node,
|
|
context: this.renderContext,
|
|
parentView: this.renderer.view
|
|
});
|
|
}
|
|
this.view.on('ready', function() {
|
|
return _this.renderer.allowAndFire('rendered');
|
|
});
|
|
return this.die();
|
|
};
|
|
|
|
return ViewBinding;
|
|
|
|
})(Batman.DOM.AbstractBinding);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.DOM.ViewArgumentBinding = (function(_super) {
|
|
|
|
__extends(ViewArgumentBinding, _super);
|
|
|
|
function ViewArgumentBinding() {
|
|
return ViewArgumentBinding.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
return ViewArgumentBinding;
|
|
|
|
})(Batman.DOM.AbstractBinding);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.DOM.ShowHideBinding = (function(_super) {
|
|
|
|
__extends(ShowHideBinding, _super);
|
|
|
|
function ShowHideBinding(node, className, key, context, parentRenderer, invert) {
|
|
var display;
|
|
this.invert = invert != null ? invert : false;
|
|
display = node.style.display;
|
|
if (!display || display === 'none') {
|
|
display = '';
|
|
}
|
|
this.originalDisplay = display;
|
|
ShowHideBinding.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
ShowHideBinding.prototype.dataChange = function(value) {
|
|
var hide, view, _ref;
|
|
view = Batman._data(this.node, 'view');
|
|
if (!!value === !this.invert) {
|
|
if (view != null) {
|
|
view.fire('beforeAppear', this.node);
|
|
}
|
|
if ((_ref = Batman.data(this.node, 'show')) != null) {
|
|
_ref.call(this.node);
|
|
}
|
|
this.node.style.display = this.originalDisplay;
|
|
return view != null ? view.fire('appear', this.node) : void 0;
|
|
} else {
|
|
if (view != null) {
|
|
view.fire('beforeDisappear', this.node);
|
|
}
|
|
if (typeof (hide = Batman.data(this.node, 'hide')) === 'function') {
|
|
hide.call(this.node);
|
|
} else {
|
|
Batman.DOM.setStyleProperty(this.node, 'display', 'none', 'important');
|
|
}
|
|
return view != null ? view.fire('disappear', this.node) : void 0;
|
|
}
|
|
};
|
|
|
|
return ShowHideBinding;
|
|
|
|
})(Batman.DOM.AbstractBinding);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
|
__hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.DOM.SelectBinding = (function(_super) {
|
|
|
|
__extends(SelectBinding, _super);
|
|
|
|
SelectBinding.prototype.isInputBinding = true;
|
|
|
|
SelectBinding.prototype.canSetImplicitly = true;
|
|
|
|
function SelectBinding() {
|
|
this.updateOptionBindings = __bind(this.updateOptionBindings, this);
|
|
|
|
this.nodeChange = __bind(this.nodeChange, this);
|
|
|
|
this.dataChange = __bind(this.dataChange, this);
|
|
|
|
this.childBindingAdded = __bind(this.childBindingAdded, this);
|
|
this.selectedBindings = new Batman.SimpleSet;
|
|
SelectBinding.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
SelectBinding.prototype.childBindingAdded = function(binding) {
|
|
var dataChangeHandler,
|
|
_this = this;
|
|
if (binding instanceof Batman.DOM.CheckedBinding) {
|
|
binding.on('dataChange', dataChangeHandler = function() {
|
|
return _this.nodeChange();
|
|
});
|
|
binding.on('die', function() {
|
|
binding.forget('dataChange', dataChangeHandler);
|
|
return _this.selectedBindings.remove(binding);
|
|
});
|
|
this.selectedBindings.add(binding);
|
|
} else if (binding instanceof Batman.DOM.IteratorBinding) {
|
|
binding.on('nodeAdded', dataChangeHandler = function() {
|
|
return _this._fireDataChange(_this.get('filteredValue'));
|
|
});
|
|
binding.on('nodeRemoved', dataChangeHandler);
|
|
binding.on('die', function() {
|
|
binding.forget('nodeAdded', dataChangeHandler);
|
|
return binding.forget('nodeRemoved', dataChangeHandler);
|
|
});
|
|
} else {
|
|
return;
|
|
}
|
|
return this._fireDataChange(this.get('filteredValue'));
|
|
};
|
|
|
|
SelectBinding.prototype.lastKeyContext = null;
|
|
|
|
SelectBinding.prototype.dataChange = function(newValue) {
|
|
var child, matches, valueToChild, _i, _len, _name, _ref,
|
|
_this = this;
|
|
this.lastKeyContext || (this.lastKeyContext = this.get('keyContext'));
|
|
if (this.lastKeyContext !== this.get('keyContext')) {
|
|
this.canSetImplicitly = true;
|
|
this.lastKeyContext = this.get('keyContext');
|
|
}
|
|
if (newValue != null ? newValue.forEach : void 0) {
|
|
valueToChild = {};
|
|
_ref = this.node.children;
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
child = _ref[_i];
|
|
child.selected = false;
|
|
matches = valueToChild[_name = child.value] || (valueToChild[_name] = []);
|
|
matches.push(child);
|
|
}
|
|
newValue.forEach(function(value) {
|
|
var children, node, _j, _len1, _results;
|
|
if (children = valueToChild[value]) {
|
|
_results = [];
|
|
for (_j = 0, _len1 = children.length; _j < _len1; _j++) {
|
|
node = children[_j];
|
|
_results.push(node.selected = true);
|
|
}
|
|
return _results;
|
|
}
|
|
});
|
|
} else {
|
|
if (!(newValue != null) && this.canSetImplicitly) {
|
|
if (this.node.value) {
|
|
this.canSetImplicitly = false;
|
|
this.set('unfilteredValue', this.node.value);
|
|
}
|
|
} else {
|
|
this.canSetImplicitly = false;
|
|
Batman.DOM.valueForNode(this.node, newValue, this.escapeValue);
|
|
}
|
|
}
|
|
this.updateOptionBindings();
|
|
};
|
|
|
|
SelectBinding.prototype.nodeChange = function() {
|
|
var c, selections;
|
|
if (this.isTwoWay()) {
|
|
selections = this.node.multiple ? (function() {
|
|
var _i, _len, _ref, _results;
|
|
_ref = this.node.children;
|
|
_results = [];
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
c = _ref[_i];
|
|
if (c.selected) {
|
|
_results.push(c.value);
|
|
}
|
|
}
|
|
return _results;
|
|
}).call(this) : this.node.value;
|
|
if (typeof selections === Array && selections.length === 1) {
|
|
selections = selections[0];
|
|
}
|
|
this.set('unfilteredValue', selections);
|
|
this.updateOptionBindings();
|
|
}
|
|
};
|
|
|
|
SelectBinding.prototype.updateOptionBindings = function() {
|
|
return this.selectedBindings.forEach(function(binding) {
|
|
return binding._fireNodeChange();
|
|
});
|
|
};
|
|
|
|
return SelectBinding;
|
|
|
|
})(Batman.DOM.AbstractBinding);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.DOM.RouteBinding = (function(_super) {
|
|
|
|
__extends(RouteBinding, _super);
|
|
|
|
function RouteBinding() {
|
|
return RouteBinding.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
RouteBinding.prototype.onATag = false;
|
|
|
|
RouteBinding.accessor('dispatcher', function() {
|
|
return this.renderContext.get('dispatcher') || Batman.App.get('current.dispatcher');
|
|
});
|
|
|
|
RouteBinding.prototype.bind = function() {
|
|
var _this = this;
|
|
if (this.node.nodeName.toUpperCase() === 'A') {
|
|
this.onATag = true;
|
|
}
|
|
RouteBinding.__super__.bind.apply(this, arguments);
|
|
return Batman.DOM.events.click(this.node, function(node, event) {
|
|
var params;
|
|
if (event.__batmanActionTaken) {
|
|
return;
|
|
}
|
|
event.__batmanActionTaken = true;
|
|
params = _this.pathFromValue(_this.get('filteredValue'));
|
|
if (params != null) {
|
|
return Batman.redirect(params);
|
|
}
|
|
});
|
|
};
|
|
|
|
RouteBinding.prototype.dataChange = function(value) {
|
|
var path;
|
|
if (value != null) {
|
|
path = this.pathFromValue(value);
|
|
}
|
|
if (this.onATag) {
|
|
if ((path != null) && (Batman.navigator != null)) {
|
|
path = Batman.navigator.linkTo(path);
|
|
} else {
|
|
path = "#";
|
|
}
|
|
return this.node.href = path;
|
|
}
|
|
};
|
|
|
|
RouteBinding.prototype.pathFromValue = function(value) {
|
|
var _ref;
|
|
if (value != null) {
|
|
if (value.isNamedRouteQuery) {
|
|
return value.get('path');
|
|
} else {
|
|
return (_ref = this.get('dispatcher')) != null ? _ref.pathFromParams(value) : void 0;
|
|
}
|
|
}
|
|
};
|
|
|
|
return RouteBinding;
|
|
|
|
})(Batman.DOM.AbstractBinding);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.DOM.RadioBinding = (function(_super) {
|
|
|
|
__extends(RadioBinding, _super);
|
|
|
|
function RadioBinding() {
|
|
return RadioBinding.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
RadioBinding.accessor('parsedNodeValue', function() {
|
|
return Batman.DOM.attrReaders._parseAttribute(this.node.value);
|
|
});
|
|
|
|
RadioBinding.prototype.firstBind = true;
|
|
|
|
RadioBinding.prototype.dataChange = function(value) {
|
|
var boundValue;
|
|
boundValue = this.get('filteredValue');
|
|
if (boundValue != null) {
|
|
this.node.checked = boundValue === Batman.DOM.attrReaders._parseAttribute(this.node.value);
|
|
} else {
|
|
if (this.firstBind && this.node.checked) {
|
|
this.set('filteredValue', this.get('parsedNodeValue'));
|
|
}
|
|
}
|
|
return this.firstBind = false;
|
|
};
|
|
|
|
RadioBinding.prototype.nodeChange = function(node) {
|
|
if (this.isTwoWay()) {
|
|
return this.set('filteredValue', this.get('parsedNodeValue'));
|
|
}
|
|
};
|
|
|
|
return RadioBinding;
|
|
|
|
})(Batman.DOM.AbstractBinding);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.DOM.MixinBinding = (function(_super) {
|
|
|
|
__extends(MixinBinding, _super);
|
|
|
|
function MixinBinding() {
|
|
return MixinBinding.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
MixinBinding.prototype.dataChange = function(value) {
|
|
if (value != null) {
|
|
return Batman.mixin(this.node, value);
|
|
}
|
|
};
|
|
|
|
return MixinBinding;
|
|
|
|
})(Batman.DOM.AbstractBinding);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.DOM.FileBinding = (function(_super) {
|
|
|
|
__extends(FileBinding, _super);
|
|
|
|
function FileBinding() {
|
|
return FileBinding.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
FileBinding.prototype.isInputBinding = true;
|
|
|
|
FileBinding.prototype.nodeChange = function(node, subContext) {
|
|
if (!this.isTwoWay()) {
|
|
return;
|
|
}
|
|
if (node.hasAttribute('multiple')) {
|
|
return this.set('filteredValue', Array.prototype.slice.call(node.files));
|
|
} else {
|
|
return this.set('filteredValue', node.files[0]);
|
|
}
|
|
};
|
|
|
|
return FileBinding;
|
|
|
|
})(Batman.DOM.AbstractBinding);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.DOM.DeferredRenderingBinding = (function(_super) {
|
|
|
|
__extends(DeferredRenderingBinding, _super);
|
|
|
|
DeferredRenderingBinding.prototype.rendered = false;
|
|
|
|
function DeferredRenderingBinding() {
|
|
DeferredRenderingBinding.__super__.constructor.apply(this, arguments);
|
|
this.node.removeAttribute("data-renderif");
|
|
}
|
|
|
|
DeferredRenderingBinding.prototype.nodeChange = function() {};
|
|
|
|
DeferredRenderingBinding.prototype.dataChange = function(value) {
|
|
if (value && !this.rendered) {
|
|
return this.render();
|
|
}
|
|
};
|
|
|
|
DeferredRenderingBinding.prototype.render = function() {
|
|
new Batman.Renderer(this.node, this.renderContext, this.renderer.view);
|
|
return this.rendered = true;
|
|
};
|
|
|
|
return DeferredRenderingBinding;
|
|
|
|
})(Batman.DOM.AbstractBinding);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.DOM.Binding = (function(_super) {
|
|
|
|
__extends(Binding, _super);
|
|
|
|
function Binding(node) {
|
|
var _ref;
|
|
this.isInputBinding = (_ref = node.nodeName.toLowerCase()) === 'input' || _ref === 'textarea';
|
|
Binding.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
Binding.prototype.nodeChange = function(node, context) {
|
|
if (this.isTwoWay()) {
|
|
return this.set('filteredValue', this.node.value);
|
|
}
|
|
};
|
|
|
|
Binding.prototype.dataChange = function(value, node) {
|
|
return Batman.DOM.valueForNode(this.node, value, this.escapeValue);
|
|
};
|
|
|
|
return Binding;
|
|
|
|
})(Batman.DOM.AbstractBinding);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
__slice = [].slice;
|
|
|
|
Batman.DOM.AbstractAttributeBinding = (function(_super) {
|
|
|
|
__extends(AbstractAttributeBinding, _super);
|
|
|
|
function AbstractAttributeBinding() {
|
|
var args, attributeName, node;
|
|
node = arguments[0], attributeName = arguments[1], args = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
|
|
this.attributeName = attributeName;
|
|
AbstractAttributeBinding.__super__.constructor.apply(this, [node].concat(__slice.call(args)));
|
|
}
|
|
|
|
return AbstractAttributeBinding;
|
|
|
|
})(Batman.DOM.AbstractBinding);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
|
__hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.DOM.FormBinding = (function(_super) {
|
|
|
|
__extends(FormBinding, _super);
|
|
|
|
FormBinding.current = null;
|
|
|
|
FormBinding.prototype.errorClass = 'error';
|
|
|
|
FormBinding.prototype.defaultErrorsListSelector = 'div.errors';
|
|
|
|
FormBinding.accessor('errorsListSelector', function() {
|
|
return this.get('node').getAttribute('data-errors-list') || this.defaultErrorsListSelector;
|
|
});
|
|
|
|
function FormBinding(node, contextName, keyPath, renderContext, renderer, only) {
|
|
this.childBindingAdded = __bind(this.childBindingAdded, this);
|
|
FormBinding.__super__.constructor.apply(this, arguments);
|
|
this.contextName = contextName;
|
|
delete this.attributeName;
|
|
Batman.DOM.events.submit(this.get('node'), function(node, e) {
|
|
return Batman.DOM.preventDefault(e);
|
|
});
|
|
this.setupErrorsList();
|
|
}
|
|
|
|
FormBinding.prototype.childBindingAdded = function(binding) {
|
|
var field, index, node;
|
|
if (binding.isInputBinding && Batman.isChildOf(this.get('node'), binding.get('node'))) {
|
|
if (~(index = binding.get('key').indexOf(this.contextName))) {
|
|
node = binding.get('node');
|
|
field = binding.get('key').slice(index + this.contextName.length + 1);
|
|
return new Batman.DOM.AddClassBinding(node, this.errorClass, this.get('keyPath') + (" | get 'errors." + field + ".length'"), this.renderContext, this.renderer);
|
|
}
|
|
}
|
|
};
|
|
|
|
FormBinding.prototype.setupErrorsList = function() {
|
|
if (this.errorsListNode = Batman.DOM.querySelector(this.get('node'), this.get('errorsListSelector'))) {
|
|
Batman.DOM.setInnerHTML(this.errorsListNode, this.errorsListHTML());
|
|
if (!this.errorsListNode.getAttribute('data-showif')) {
|
|
return this.errorsListNode.setAttribute('data-showif', "" + this.contextName + ".errors.length");
|
|
}
|
|
}
|
|
};
|
|
|
|
FormBinding.prototype.errorsListHTML = function() {
|
|
return "<ul>\n <li data-foreach-error=\"" + this.contextName + ".errors\" data-bind=\"error.fullMessage\"></li>\n</ul>";
|
|
};
|
|
|
|
return FormBinding;
|
|
|
|
})(Batman.DOM.AbstractAttributeBinding);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.DOM.EventBinding = (function(_super) {
|
|
|
|
__extends(EventBinding, _super);
|
|
|
|
EventBinding.prototype.bindImmediately = false;
|
|
|
|
function EventBinding(node, eventName, key, context) {
|
|
var attacher, callback,
|
|
_this = this;
|
|
EventBinding.__super__.constructor.apply(this, arguments);
|
|
callback = function() {
|
|
var _ref;
|
|
return (_ref = _this.get('filteredValue')) != null ? _ref.apply(_this.get('callbackContext'), arguments) : void 0;
|
|
};
|
|
if (attacher = Batman.DOM.events[this.attributeName]) {
|
|
attacher(this.node, callback, context);
|
|
} else {
|
|
Batman.DOM.events.other(this.node, this.attributeName, callback, context);
|
|
}
|
|
this.bind();
|
|
}
|
|
|
|
EventBinding.accessor('callbackContext', function() {
|
|
var contextKeySegments;
|
|
contextKeySegments = this.key.split('.');
|
|
contextKeySegments.pop();
|
|
if (contextKeySegments.length > 0) {
|
|
return this.get('keyContext').get(contextKeySegments.join('.'));
|
|
} else {
|
|
return this.get('keyContext');
|
|
}
|
|
});
|
|
|
|
EventBinding.wrapAccessor('unfilteredValue', function(core) {
|
|
return {
|
|
get: function() {
|
|
var functionKey, k, keyContext, keys;
|
|
if (k = this.get('key')) {
|
|
keys = k.split('.');
|
|
if (keys.length > 1) {
|
|
functionKey = keys.pop();
|
|
keyContext = Batman.getPath(this, ['keyContext'].concat(keys));
|
|
keyContext = Batman.RenderContext.deProxy(keyContext);
|
|
if (keyContext != null) {
|
|
return keyContext[functionKey];
|
|
}
|
|
}
|
|
}
|
|
return core.get.apply(this, arguments);
|
|
}
|
|
};
|
|
});
|
|
|
|
return EventBinding;
|
|
|
|
})(Batman.DOM.AbstractAttributeBinding);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.DOM.NodeAttributeBinding = (function(_super) {
|
|
|
|
__extends(NodeAttributeBinding, _super);
|
|
|
|
function NodeAttributeBinding() {
|
|
return NodeAttributeBinding.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
NodeAttributeBinding.prototype.dataChange = function(value) {
|
|
if (value == null) {
|
|
value = "";
|
|
}
|
|
return this.node[this.attributeName] = value;
|
|
};
|
|
|
|
NodeAttributeBinding.prototype.nodeChange = function(node) {
|
|
if (this.isTwoWay()) {
|
|
return this.set('filteredValue', Batman.DOM.attrReaders._parseAttribute(node[this.attributeName]));
|
|
}
|
|
};
|
|
|
|
return NodeAttributeBinding;
|
|
|
|
})(Batman.DOM.AbstractAttributeBinding);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.DOM.CheckedBinding = (function(_super) {
|
|
|
|
__extends(CheckedBinding, _super);
|
|
|
|
function CheckedBinding() {
|
|
return CheckedBinding.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
CheckedBinding.prototype.isInputBinding = true;
|
|
|
|
CheckedBinding.prototype.dataChange = function(value) {
|
|
return this.node[this.attributeName] = !!value;
|
|
};
|
|
|
|
return CheckedBinding;
|
|
|
|
})(Batman.DOM.NodeAttributeBinding);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.DOM.AttributeBinding = (function(_super) {
|
|
|
|
__extends(AttributeBinding, _super);
|
|
|
|
function AttributeBinding() {
|
|
return AttributeBinding.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
AttributeBinding.prototype.dataChange = function(value) {
|
|
return this.node.setAttribute(this.attributeName, value);
|
|
};
|
|
|
|
AttributeBinding.prototype.nodeChange = function(node) {
|
|
if (this.isTwoWay()) {
|
|
return this.set('filteredValue', Batman.DOM.attrReaders._parseAttribute(node.getAttribute(this.attributeName)));
|
|
}
|
|
};
|
|
|
|
return AttributeBinding;
|
|
|
|
})(Batman.DOM.AbstractAttributeBinding);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.DOM.AddClassBinding = (function(_super) {
|
|
|
|
__extends(AddClassBinding, _super);
|
|
|
|
function AddClassBinding(node, className, keyPath, renderContext, renderer, only, invert) {
|
|
var name, names;
|
|
this.invert = invert != null ? invert : false;
|
|
names = className.split('|');
|
|
this.classes = (function() {
|
|
var _i, _len, _results;
|
|
_results = [];
|
|
for (_i = 0, _len = names.length; _i < _len; _i++) {
|
|
name = names[_i];
|
|
_results.push({
|
|
name: name,
|
|
pattern: new RegExp("(?:^|\\s)" + name + "(?:$|\\s)", 'i')
|
|
});
|
|
}
|
|
return _results;
|
|
})();
|
|
AddClassBinding.__super__.constructor.apply(this, arguments);
|
|
delete this.attributeName;
|
|
}
|
|
|
|
AddClassBinding.prototype.dataChange = function(value) {
|
|
var currentName, includesClassName, name, pattern, _i, _len, _ref, _ref1;
|
|
currentName = this.node.className;
|
|
_ref = this.classes;
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
_ref1 = _ref[_i], name = _ref1.name, pattern = _ref1.pattern;
|
|
includesClassName = pattern.test(currentName);
|
|
if (!!value === !this.invert) {
|
|
if (!includesClassName) {
|
|
this.node.className = "" + currentName + " " + name;
|
|
}
|
|
} else {
|
|
if (includesClassName) {
|
|
this.node.className = currentName.replace(pattern, ' ');
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
};
|
|
|
|
return AddClassBinding;
|
|
|
|
})(Batman.DOM.AbstractAttributeBinding);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.DOM.AbstractCollectionBinding = (function(_super) {
|
|
|
|
__extends(AbstractCollectionBinding, _super);
|
|
|
|
function AbstractCollectionBinding() {
|
|
return AbstractCollectionBinding.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
AbstractCollectionBinding.prototype.bindCollection = function(newCollection) {
|
|
var _ref;
|
|
if (newCollection instanceof Batman.Hash) {
|
|
newCollection = newCollection.meta;
|
|
}
|
|
if (newCollection === this.collection) {
|
|
return true;
|
|
} else {
|
|
this.unbindCollection();
|
|
this.collection = newCollection;
|
|
if ((_ref = this.collection) != null ? _ref.isObservable : void 0) {
|
|
this.collection.observeAndFire('toArray', this.handleArrayChanged);
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
|
|
AbstractCollectionBinding.prototype.unbindCollection = function() {
|
|
var _ref;
|
|
if ((_ref = this.collection) != null ? _ref.isObservable : void 0) {
|
|
return this.collection.forget('toArray', this.handleArrayChanged);
|
|
}
|
|
};
|
|
|
|
AbstractCollectionBinding.prototype.handleArrayChanged = function() {};
|
|
|
|
AbstractCollectionBinding.prototype.die = function() {
|
|
this.unbindCollection();
|
|
return AbstractCollectionBinding.__super__.die.apply(this, arguments);
|
|
};
|
|
|
|
return AbstractCollectionBinding;
|
|
|
|
})(Batman.DOM.AbstractAttributeBinding);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
|
__hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
__slice = [].slice;
|
|
|
|
Batman.DOM.StyleBinding = (function(_super) {
|
|
|
|
__extends(StyleBinding, _super);
|
|
|
|
StyleBinding.SingleStyleBinding = (function(_super1) {
|
|
|
|
__extends(SingleStyleBinding, _super1);
|
|
|
|
SingleStyleBinding.prototype.isTwoWay = function() {
|
|
return false;
|
|
};
|
|
|
|
function SingleStyleBinding() {
|
|
var args, parent, _i;
|
|
args = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), parent = arguments[_i++];
|
|
this.parent = parent;
|
|
SingleStyleBinding.__super__.constructor.apply(this, args);
|
|
}
|
|
|
|
SingleStyleBinding.prototype.dataChange = function(value) {
|
|
return this.parent.setStyle(this.attributeName, value);
|
|
};
|
|
|
|
return SingleStyleBinding;
|
|
|
|
})(Batman.DOM.AbstractAttributeBinding);
|
|
|
|
function StyleBinding() {
|
|
this.setStyle = __bind(this.setStyle, this);
|
|
|
|
this.handleArrayChanged = __bind(this.handleArrayChanged, this);
|
|
this.oldStyles = {};
|
|
this.styleBindings = {};
|
|
StyleBinding.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
StyleBinding.prototype.dataChange = function(value) {
|
|
var colonSplitCSSValues, cssName, key, style, _i, _len, _ref, _ref1, _results;
|
|
if (!value) {
|
|
this.resetStyles();
|
|
return;
|
|
}
|
|
this.unbindCollection();
|
|
if (typeof value === 'string') {
|
|
this.resetStyles();
|
|
_ref = value.split(';');
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
style = _ref[_i];
|
|
_ref1 = style.split(":"), cssName = _ref1[0], colonSplitCSSValues = 2 <= _ref1.length ? __slice.call(_ref1, 1) : [];
|
|
this.setStyle(cssName, colonSplitCSSValues.join(":"));
|
|
}
|
|
return;
|
|
}
|
|
if (value instanceof Batman.Hash) {
|
|
return this.bindCollection(value);
|
|
} else {
|
|
if (value instanceof Batman.Object) {
|
|
value = value.toJSON();
|
|
}
|
|
this.resetStyles();
|
|
_results = [];
|
|
for (key in value) {
|
|
if (!__hasProp.call(value, key)) continue;
|
|
_results.push(this.bindSingleAttribute(key, "" + this.keyPath + "." + key));
|
|
}
|
|
return _results;
|
|
}
|
|
};
|
|
|
|
StyleBinding.prototype.handleArrayChanged = function(array) {
|
|
var _this = this;
|
|
return this.collection.forEach(function(key, value) {
|
|
return _this.bindSingleAttribute(key, "" + _this.keyPath + "." + key);
|
|
});
|
|
};
|
|
|
|
StyleBinding.prototype.bindSingleAttribute = function(attr, keyPath) {
|
|
return this.styleBindings[attr] = new this.constructor.SingleStyleBinding(this.node, attr, keyPath, this.renderContext, this.renderer, this.only, this);
|
|
};
|
|
|
|
StyleBinding.prototype.setStyle = function(key, value) {
|
|
key = Batman.helpers.camelize(key.trim(), true);
|
|
if (this.oldStyles[key] == null) {
|
|
this.oldStyles[key] = this.node.style[key] || "";
|
|
}
|
|
if (value != null ? value.trim : void 0) {
|
|
value = value.trim();
|
|
}
|
|
if (value == null) {
|
|
value = "";
|
|
}
|
|
return this.node.style[key] = value;
|
|
};
|
|
|
|
StyleBinding.prototype.resetStyles = function() {
|
|
var cssName, cssValue, _ref, _results;
|
|
_ref = this.oldStyles;
|
|
_results = [];
|
|
for (cssName in _ref) {
|
|
if (!__hasProp.call(_ref, cssName)) continue;
|
|
cssValue = _ref[cssName];
|
|
_results.push(this.setStyle(cssName, cssValue));
|
|
}
|
|
return _results;
|
|
};
|
|
|
|
StyleBinding.prototype.resetBindings = function() {
|
|
var attribute, binding, _ref;
|
|
_ref = this.styleBindings;
|
|
for (attribute in _ref) {
|
|
binding = _ref[attribute];
|
|
binding._fireDataChange('');
|
|
binding.die();
|
|
}
|
|
return this.styleBindings = {};
|
|
};
|
|
|
|
StyleBinding.prototype.unbindCollection = function() {
|
|
this.resetBindings();
|
|
return StyleBinding.__super__.unbindCollection.apply(this, arguments);
|
|
};
|
|
|
|
return StyleBinding;
|
|
|
|
})(Batman.DOM.AbstractCollectionBinding);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
|
__hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.DOM.IteratorBinding = (function(_super) {
|
|
|
|
__extends(IteratorBinding, _super);
|
|
|
|
IteratorBinding.prototype.currentActionNumber = 0;
|
|
|
|
IteratorBinding.prototype.queuedActionNumber = 0;
|
|
|
|
IteratorBinding.prototype.bindImmediately = false;
|
|
|
|
function IteratorBinding(sourceNode, iteratorName, key, context, parentRenderer) {
|
|
var previousSiblingNode,
|
|
_this = this;
|
|
this.iteratorName = iteratorName;
|
|
this.key = key;
|
|
this.context = context;
|
|
this.parentRenderer = parentRenderer;
|
|
this.handleArrayChanged = __bind(this.handleArrayChanged, this);
|
|
|
|
this.nodeMap = new Batman.SimpleHash;
|
|
this.rendererMap = new Batman.SimpleHash;
|
|
this.fragment = document.createDocumentFragment();
|
|
this.prototypeNode = sourceNode.cloneNode(true);
|
|
this.prototypeNode.removeAttribute("data-foreach-" + this.iteratorName);
|
|
previousSiblingNode = sourceNode.nextSibling;
|
|
this.startNode = document.createComment("start " + this.iteratorName + "-" + (this.get('_batmanID')));
|
|
this.endNode = document.createComment("end " + this.iteratorName + "-" + (this.get('_batmanID')));
|
|
this.endNode[Batman.expando] = sourceNode[Batman.expando];
|
|
if (Batman.canDeleteExpando) {
|
|
delete sourceNode[Batman.expando];
|
|
}
|
|
Batman.DOM.insertBefore(sourceNode.parentNode, this.startNode, previousSiblingNode);
|
|
Batman.DOM.insertBefore(sourceNode.parentNode, this.endNode, previousSiblingNode);
|
|
this.parentRenderer.prevent('rendered');
|
|
Batman.DOM.onParseExit(sourceNode.parentNode, function() {
|
|
Batman.DOM.destroyNode(sourceNode);
|
|
_this.bind();
|
|
return _this.parentRenderer.allowAndFire('rendered');
|
|
});
|
|
IteratorBinding.__super__.constructor.call(this, this.endNode, this.iteratorName, this.key, this.context, this.parentRenderer);
|
|
}
|
|
|
|
IteratorBinding.prototype.parentNode = function() {
|
|
return this.endNode.parentNode;
|
|
};
|
|
|
|
IteratorBinding.prototype.die = function() {
|
|
this.dead = true;
|
|
return IteratorBinding.__super__.die.apply(this, arguments);
|
|
};
|
|
|
|
IteratorBinding.prototype.dataChange = function(collection) {
|
|
var items, _items;
|
|
if (collection != null) {
|
|
if (!this.bindCollection(collection)) {
|
|
items = (collection != null ? collection.forEach : void 0) ? (_items = [], collection.forEach(function(item) {
|
|
return _items.push(item);
|
|
}), _items) : Object.keys(collection);
|
|
return this.handleArrayChanged(items);
|
|
}
|
|
} else {
|
|
return this.handleArrayChanged([]);
|
|
}
|
|
};
|
|
|
|
IteratorBinding.prototype.handleArrayChanged = function(newItems) {
|
|
var existingNode, index, newItem, node, nodeAtIndex, parentNode, startIndex, unseenNodeMap, _i, _len,
|
|
_this = this;
|
|
parentNode = this.parentNode();
|
|
startIndex = this._getStartNodeIndex() + 1;
|
|
unseenNodeMap = this.nodeMap.merge();
|
|
if (newItems != null) {
|
|
for (index = _i = 0, _len = newItems.length; _i < _len; index = ++_i) {
|
|
newItem = newItems[index];
|
|
nodeAtIndex = parentNode.childNodes[startIndex + index];
|
|
if ((nodeAtIndex != null) && this._itemForNode(nodeAtIndex) === newItem) {
|
|
unseenNodeMap.unset(newItem);
|
|
continue;
|
|
} else {
|
|
node = (existingNode = this.nodeMap.get(newItem)) ? (unseenNodeMap.unset(newItem), existingNode) : this._newNodeForItem(newItem);
|
|
Batman.DOM.insertBefore(this.parentNode(), node, nodeAtIndex);
|
|
}
|
|
}
|
|
}
|
|
unseenNodeMap.forEach(function(item, node) {
|
|
return _this._removeItem(item);
|
|
});
|
|
};
|
|
|
|
IteratorBinding.prototype._itemForNode = function(node) {
|
|
return Batman._data(node, "" + this.iteratorName + "Item");
|
|
};
|
|
|
|
IteratorBinding.prototype._newNodeForItem = function(newItem) {
|
|
var newNode, renderer,
|
|
_this = this;
|
|
newNode = this.prototypeNode.cloneNode(true);
|
|
Batman._data(newNode, "" + this.iteratorName + "Item", newItem);
|
|
this.nodeMap.set(newItem, newNode);
|
|
this.parentRenderer.prevent('rendered');
|
|
renderer = new Batman.Renderer(newNode, this.renderContext.descend(newItem, this.iteratorName), this.parentRenderer.view);
|
|
renderer.on('rendered', function() {
|
|
Batman.DOM.propagateBindingEvents(newNode);
|
|
_this.fire('nodeAdded', newNode, newItem);
|
|
return _this.parentRenderer.allowAndFire('rendered');
|
|
});
|
|
return newNode;
|
|
};
|
|
|
|
IteratorBinding.prototype._getStartNodeIndex = function() {
|
|
var index, node, _i, _len, _ref;
|
|
_ref = this.parentNode().childNodes;
|
|
for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) {
|
|
node = _ref[index];
|
|
if (node === this.startNode) {
|
|
return index;
|
|
}
|
|
}
|
|
return 0;
|
|
};
|
|
|
|
IteratorBinding.prototype._removeItem = function(item) {
|
|
var node;
|
|
node = this.nodeMap.unset(item);
|
|
Batman.DOM.destroyNode(node);
|
|
return this.fire('nodeRemoved', node, item);
|
|
};
|
|
|
|
return IteratorBinding;
|
|
|
|
})(Batman.DOM.AbstractCollectionBinding);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
|
__hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.DOM.ClassBinding = (function(_super) {
|
|
|
|
__extends(ClassBinding, _super);
|
|
|
|
function ClassBinding() {
|
|
this.handleArrayChanged = __bind(this.handleArrayChanged, this);
|
|
return ClassBinding.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
ClassBinding.prototype.dataChange = function(value) {
|
|
if (value != null) {
|
|
this.unbindCollection();
|
|
if (typeof value === 'string') {
|
|
return this.node.className = value;
|
|
} else {
|
|
this.bindCollection(value);
|
|
return this.updateFromCollection();
|
|
}
|
|
}
|
|
};
|
|
|
|
ClassBinding.prototype.updateFromCollection = function() {
|
|
var array, k, v;
|
|
if (this.collection) {
|
|
array = this.collection.map ? this.collection.map(function(x) {
|
|
return x;
|
|
}) : (function() {
|
|
var _ref, _results;
|
|
_ref = this.collection;
|
|
_results = [];
|
|
for (k in _ref) {
|
|
if (!__hasProp.call(_ref, k)) continue;
|
|
v = _ref[k];
|
|
_results.push(k);
|
|
}
|
|
return _results;
|
|
}).call(this);
|
|
if (array.toArray != null) {
|
|
array = array.toArray();
|
|
}
|
|
return this.node.className = array.join(' ');
|
|
}
|
|
};
|
|
|
|
ClassBinding.prototype.handleArrayChanged = function() {
|
|
return this.updateFromCollection();
|
|
};
|
|
|
|
return ClassBinding;
|
|
|
|
})(Batman.DOM.AbstractCollectionBinding);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.ValidationError = (function(_super) {
|
|
|
|
__extends(ValidationError, _super);
|
|
|
|
ValidationError.accessor('fullMessage', function() {
|
|
return Batman.t('errors.format', {
|
|
attribute: Batman.helpers.humanize(this.attribute),
|
|
message: this.message
|
|
});
|
|
});
|
|
|
|
function ValidationError(attribute, message) {
|
|
ValidationError.__super__.constructor.call(this, {
|
|
attribute: attribute,
|
|
message: message
|
|
});
|
|
}
|
|
|
|
return ValidationError;
|
|
|
|
})(Batman.Object);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
__slice = [].slice;
|
|
|
|
Batman.StorageAdapter = (function(_super) {
|
|
|
|
__extends(StorageAdapter, _super);
|
|
|
|
StorageAdapter.StorageError = (function(_super1) {
|
|
|
|
__extends(StorageError, _super1);
|
|
|
|
StorageError.prototype.name = "StorageError";
|
|
|
|
function StorageError(message) {
|
|
StorageError.__super__.constructor.apply(this, arguments);
|
|
this.message = message;
|
|
}
|
|
|
|
return StorageError;
|
|
|
|
})(Error);
|
|
|
|
StorageAdapter.RecordExistsError = (function(_super1) {
|
|
|
|
__extends(RecordExistsError, _super1);
|
|
|
|
RecordExistsError.prototype.name = 'RecordExistsError';
|
|
|
|
function RecordExistsError(message) {
|
|
RecordExistsError.__super__.constructor.call(this, message || "Can't create this record because it already exists in the store!");
|
|
}
|
|
|
|
return RecordExistsError;
|
|
|
|
})(StorageAdapter.StorageError);
|
|
|
|
StorageAdapter.NotFoundError = (function(_super1) {
|
|
|
|
__extends(NotFoundError, _super1);
|
|
|
|
NotFoundError.prototype.name = 'NotFoundError';
|
|
|
|
function NotFoundError(message) {
|
|
NotFoundError.__super__.constructor.call(this, message || "Record couldn't be found in storage!");
|
|
}
|
|
|
|
return NotFoundError;
|
|
|
|
})(StorageAdapter.StorageError);
|
|
|
|
StorageAdapter.NotAllowedError = (function(_super1) {
|
|
|
|
__extends(NotAllowedError, _super1);
|
|
|
|
NotAllowedError.prototype.name = "NotAllowedError";
|
|
|
|
function NotAllowedError(message) {
|
|
NotAllowedError.__super__.constructor.call(this, message || "Storage operation denied access to the operation!");
|
|
}
|
|
|
|
return NotAllowedError;
|
|
|
|
})(StorageAdapter.StorageError);
|
|
|
|
StorageAdapter.NotAcceptableError = (function(_super1) {
|
|
|
|
__extends(NotAcceptableError, _super1);
|
|
|
|
NotAcceptableError.prototype.name = "NotAcceptableError";
|
|
|
|
function NotAcceptableError(message) {
|
|
NotAcceptableError.__super__.constructor.call(this, message || "Storage operation permitted but the request was malformed!");
|
|
}
|
|
|
|
return NotAcceptableError;
|
|
|
|
})(StorageAdapter.StorageError);
|
|
|
|
StorageAdapter.UnprocessableRecordError = (function(_super1) {
|
|
|
|
__extends(UnprocessableRecordError, _super1);
|
|
|
|
UnprocessableRecordError.prototype.name = "UnprocessableRecordError";
|
|
|
|
function UnprocessableRecordError(message) {
|
|
UnprocessableRecordError.__super__.constructor.call(this, message || "Storage adapter could not process the record!");
|
|
}
|
|
|
|
return UnprocessableRecordError;
|
|
|
|
})(StorageAdapter.StorageError);
|
|
|
|
StorageAdapter.InternalStorageError = (function(_super1) {
|
|
|
|
__extends(InternalStorageError, _super1);
|
|
|
|
InternalStorageError.prototype.name = "InternalStorageError";
|
|
|
|
function InternalStorageError(message) {
|
|
InternalStorageError.__super__.constructor.call(this, message || "An error occured during the storage operation!");
|
|
}
|
|
|
|
return InternalStorageError;
|
|
|
|
})(StorageAdapter.StorageError);
|
|
|
|
StorageAdapter.NotImplementedError = (function(_super1) {
|
|
|
|
__extends(NotImplementedError, _super1);
|
|
|
|
NotImplementedError.prototype.name = "NotImplementedError";
|
|
|
|
function NotImplementedError(message) {
|
|
NotImplementedError.__super__.constructor.call(this, message || "This operation is not implemented by the storage adpater!");
|
|
}
|
|
|
|
return NotImplementedError;
|
|
|
|
})(StorageAdapter.StorageError);
|
|
|
|
function StorageAdapter(model) {
|
|
var constructor;
|
|
StorageAdapter.__super__.constructor.call(this, {
|
|
model: model
|
|
});
|
|
constructor = this.constructor;
|
|
if (constructor.ModelMixin) {
|
|
Batman.extend(model, constructor.ModelMixin);
|
|
}
|
|
if (constructor.RecordMixin) {
|
|
Batman.extend(model.prototype, constructor.RecordMixin);
|
|
}
|
|
}
|
|
|
|
StorageAdapter.prototype.isStorageAdapter = true;
|
|
|
|
StorageAdapter.prototype.storageKey = function(record) {
|
|
var model;
|
|
model = (record != null ? record.constructor : void 0) || this.model;
|
|
return model.get('storageKey') || Batman.helpers.pluralize(Batman.helpers.underscore(model.get('resourceName')));
|
|
};
|
|
|
|
StorageAdapter.prototype.getRecordFromData = function(attributes, constructor) {
|
|
var record;
|
|
if (constructor == null) {
|
|
constructor = this.model;
|
|
}
|
|
record = new constructor();
|
|
record._withoutDirtyTracking(function() {
|
|
return this.fromJSON(attributes);
|
|
});
|
|
return record;
|
|
};
|
|
|
|
StorageAdapter.skipIfError = function(f) {
|
|
return function(env, next) {
|
|
if (env.error != null) {
|
|
return next();
|
|
} else {
|
|
return f.call(this, env, next);
|
|
}
|
|
};
|
|
};
|
|
|
|
StorageAdapter.prototype.before = function() {
|
|
return this._addFilter.apply(this, ['before'].concat(__slice.call(arguments)));
|
|
};
|
|
|
|
StorageAdapter.prototype.after = function() {
|
|
return this._addFilter.apply(this, ['after'].concat(__slice.call(arguments)));
|
|
};
|
|
|
|
StorageAdapter.prototype._inheritFilters = function() {
|
|
var filtersByKey, filtersList, key, oldFilters, position, _results;
|
|
if (!this._batman.check(this) || !this._batman.filters) {
|
|
oldFilters = this._batman.getFirst('filters');
|
|
this._batman.filters = {
|
|
before: {},
|
|
after: {}
|
|
};
|
|
if (oldFilters != null) {
|
|
_results = [];
|
|
for (position in oldFilters) {
|
|
filtersByKey = oldFilters[position];
|
|
_results.push((function() {
|
|
var _results1;
|
|
_results1 = [];
|
|
for (key in filtersByKey) {
|
|
filtersList = filtersByKey[key];
|
|
_results1.push(this._batman.filters[position][key] = filtersList.slice(0));
|
|
}
|
|
return _results1;
|
|
}).call(this));
|
|
}
|
|
return _results;
|
|
}
|
|
}
|
|
};
|
|
|
|
StorageAdapter.prototype._addFilter = function() {
|
|
var filter, key, keys, position, _base, _i, _j, _len;
|
|
position = arguments[0], keys = 3 <= arguments.length ? __slice.call(arguments, 1, _i = arguments.length - 1) : (_i = 1, []), filter = arguments[_i++];
|
|
this._inheritFilters();
|
|
for (_j = 0, _len = keys.length; _j < _len; _j++) {
|
|
key = keys[_j];
|
|
(_base = this._batman.filters[position])[key] || (_base[key] = []);
|
|
this._batman.filters[position][key].push(filter);
|
|
}
|
|
return true;
|
|
};
|
|
|
|
StorageAdapter.prototype.runFilter = function(position, action, env, callback) {
|
|
var actionFilters, allFilters, filters, next,
|
|
_this = this;
|
|
this._inheritFilters();
|
|
allFilters = this._batman.filters[position].all || [];
|
|
actionFilters = this._batman.filters[position][action] || [];
|
|
env.action = action;
|
|
filters = position === 'before' ? actionFilters.concat(allFilters) : allFilters.concat(actionFilters);
|
|
next = function(newEnv) {
|
|
var nextFilter;
|
|
if (newEnv != null) {
|
|
env = newEnv;
|
|
}
|
|
if ((nextFilter = filters.shift()) != null) {
|
|
return nextFilter.call(_this, env, next);
|
|
} else {
|
|
return callback.call(_this, env);
|
|
}
|
|
};
|
|
return next();
|
|
};
|
|
|
|
StorageAdapter.prototype.runBeforeFilter = function() {
|
|
return this.runFilter.apply(this, ['before'].concat(__slice.call(arguments)));
|
|
};
|
|
|
|
StorageAdapter.prototype.runAfterFilter = function(action, env, callback) {
|
|
return this.runFilter('after', action, env, this.exportResult(callback));
|
|
};
|
|
|
|
StorageAdapter.prototype.exportResult = function(callback) {
|
|
return function(env) {
|
|
return callback(env.error, env.result, env);
|
|
};
|
|
};
|
|
|
|
StorageAdapter.prototype._jsonToAttributes = function(json) {
|
|
return JSON.parse(json);
|
|
};
|
|
|
|
StorageAdapter.prototype.perform = function(key, subject, options, callback) {
|
|
var env, next,
|
|
_this = this;
|
|
options || (options = {});
|
|
env = {
|
|
options: options,
|
|
subject: subject
|
|
};
|
|
next = function(newEnv) {
|
|
if (newEnv != null) {
|
|
env = newEnv;
|
|
}
|
|
return _this.runAfterFilter(key, env, callback);
|
|
};
|
|
this.runBeforeFilter(key, env, function(env) {
|
|
return this[key](env, next);
|
|
});
|
|
return void 0;
|
|
};
|
|
|
|
return StorageAdapter;
|
|
|
|
})(Batman.Object);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
__slice = [].slice,
|
|
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
|
|
|
Batman.RestStorage = (function(_super) {
|
|
var key, _fn, _i, _len, _ref,
|
|
_this = this;
|
|
|
|
__extends(RestStorage, _super);
|
|
|
|
RestStorage.CommunicationError = (function(_super1) {
|
|
|
|
__extends(CommunicationError, _super1);
|
|
|
|
CommunicationError.prototype.name = 'CommunicationError';
|
|
|
|
function CommunicationError(message) {
|
|
CommunicationError.__super__.constructor.call(this, message || "A communication error has occurred!");
|
|
}
|
|
|
|
return CommunicationError;
|
|
|
|
})(RestStorage.StorageError);
|
|
|
|
RestStorage.JSONContentType = 'application/json';
|
|
|
|
RestStorage.PostBodyContentType = 'application/x-www-form-urlencoded';
|
|
|
|
RestStorage.BaseMixin = {
|
|
request: function(action, options, callback) {
|
|
if (!callback) {
|
|
callback = options;
|
|
options = {};
|
|
}
|
|
options.method || (options.method = 'GET');
|
|
options.action = action;
|
|
return this._doStorageOperation(options.method.toLowerCase(), options, callback);
|
|
}
|
|
};
|
|
|
|
RestStorage.ModelMixin = Batman.extend({}, RestStorage.BaseMixin, {
|
|
urlNestsUnder: function() {
|
|
var key, keys, parents, _i, _len;
|
|
keys = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
parents = {};
|
|
for (_i = 0, _len = keys.length; _i < _len; _i++) {
|
|
key = keys[_i];
|
|
parents[key + '_id'] = Batman.helpers.pluralize(key);
|
|
}
|
|
this.url = function(options) {
|
|
var childSegment, parentID, plural;
|
|
childSegment = Batman.helpers.pluralize(this.get('resourceName').toLowerCase());
|
|
for (key in parents) {
|
|
plural = parents[key];
|
|
parentID = options.data[key];
|
|
if (parentID) {
|
|
delete options.data[key];
|
|
return "" + plural + "/" + parentID + "/" + childSegment;
|
|
}
|
|
}
|
|
return childSegment;
|
|
};
|
|
return this.prototype.url = function() {
|
|
var childSegment, id, parentID, plural, url;
|
|
childSegment = Batman.helpers.pluralize(this.constructor.get('resourceName').toLowerCase());
|
|
for (key in parents) {
|
|
plural = parents[key];
|
|
parentID = this.get('dirtyKeys').get(key);
|
|
if (parentID === void 0) {
|
|
parentID = this.get(key);
|
|
}
|
|
if (parentID) {
|
|
url = "" + plural + "/" + parentID + "/" + childSegment;
|
|
break;
|
|
}
|
|
}
|
|
url || (url = childSegment);
|
|
if (id = this.get('id')) {
|
|
url += '/' + id;
|
|
}
|
|
return url;
|
|
};
|
|
}
|
|
});
|
|
|
|
RestStorage.RecordMixin = Batman.extend({}, RestStorage.BaseMixin);
|
|
|
|
RestStorage.prototype.defaultRequestOptions = {
|
|
type: 'json'
|
|
};
|
|
|
|
RestStorage.prototype._implicitActionNames = ['create', 'read', 'update', 'destroy', 'readAll'];
|
|
|
|
RestStorage.prototype.serializeAsForm = true;
|
|
|
|
function RestStorage() {
|
|
RestStorage.__super__.constructor.apply(this, arguments);
|
|
this.defaultRequestOptions = Batman.extend({}, this.defaultRequestOptions);
|
|
}
|
|
|
|
RestStorage.prototype.recordJsonNamespace = function(record) {
|
|
return Batman.helpers.singularize(this.storageKey(record));
|
|
};
|
|
|
|
RestStorage.prototype.collectionJsonNamespace = function(constructor) {
|
|
return Batman.helpers.pluralize(this.storageKey(constructor.prototype));
|
|
};
|
|
|
|
RestStorage.prototype._execWithOptions = function(object, key, options, context) {
|
|
if (context == null) {
|
|
context = object;
|
|
}
|
|
if (typeof object[key] === 'function') {
|
|
return object[key].call(context, options);
|
|
} else {
|
|
return object[key];
|
|
}
|
|
};
|
|
|
|
RestStorage.prototype._defaultCollectionUrl = function(model) {
|
|
return "" + (this.storageKey(model.prototype));
|
|
};
|
|
|
|
RestStorage.prototype._addParams = function(url, options) {
|
|
var _ref;
|
|
if (options && options.action && !(_ref = options.action, __indexOf.call(this._implicitActionNames, _ref) >= 0)) {
|
|
url += '/' + options.action.toLowerCase();
|
|
}
|
|
return url;
|
|
};
|
|
|
|
RestStorage.prototype._addUrlAffixes = function(url, subject, env) {
|
|
var prefix, segments;
|
|
segments = [url, this.urlSuffix(subject, env)];
|
|
if (url.charAt(0) !== '/') {
|
|
prefix = this.urlPrefix(subject, env);
|
|
if (prefix.charAt(prefix.length - 1) !== '/') {
|
|
segments.unshift('/');
|
|
}
|
|
segments.unshift(prefix);
|
|
}
|
|
return segments.join('');
|
|
};
|
|
|
|
RestStorage.prototype.urlPrefix = function(object, env) {
|
|
return this._execWithOptions(object, 'urlPrefix', env.options) || '';
|
|
};
|
|
|
|
RestStorage.prototype.urlSuffix = function(object, env) {
|
|
return this._execWithOptions(object, 'urlSuffix', env.options) || '';
|
|
};
|
|
|
|
RestStorage.prototype.urlForRecord = function(record, env) {
|
|
var id, url, _ref;
|
|
if ((_ref = env.options) != null ? _ref.recordUrl : void 0) {
|
|
url = this._execWithOptions(env.options, 'recordUrl', env.options, record);
|
|
} else if (record.url) {
|
|
url = this._execWithOptions(record, 'url', env.options);
|
|
} else {
|
|
url = record.constructor.url ? this._execWithOptions(record.constructor, 'url', env.options) : this._defaultCollectionUrl(record.constructor);
|
|
if (env.action !== 'create') {
|
|
if ((id = record.get('id')) != null) {
|
|
url = url + "/" + id;
|
|
} else {
|
|
throw new this.constructor.StorageError("Couldn't get/set record primary key on " + env.action + "!");
|
|
}
|
|
}
|
|
}
|
|
return this._addUrlAffixes(this._addParams(url, env.options), record, env);
|
|
};
|
|
|
|
RestStorage.prototype.urlForCollection = function(model, env) {
|
|
var url, _ref;
|
|
url = ((_ref = env.options) != null ? _ref.collectionUrl : void 0) ? this._execWithOptions(env.options, 'collectionUrl', env.options, env.options.urlContext) : model.url ? this._execWithOptions(model, 'url', env.options) : this._defaultCollectionUrl(model, env.options);
|
|
return this._addUrlAffixes(this._addParams(url, env.options), model, env);
|
|
};
|
|
|
|
RestStorage.prototype.request = function(env, next) {
|
|
var options;
|
|
options = Batman.extend(env.options, {
|
|
autosend: false,
|
|
success: function(data) {
|
|
return env.data = data;
|
|
},
|
|
error: function(error) {
|
|
return env.error = error;
|
|
},
|
|
loaded: function() {
|
|
env.response = env.request.get('response');
|
|
return next();
|
|
}
|
|
});
|
|
env.request = new Batman.Request(options);
|
|
return env.request.send();
|
|
};
|
|
|
|
RestStorage.prototype.perform = function(key, record, options, callback) {
|
|
options || (options = {});
|
|
Batman.extend(options, this.defaultRequestOptions);
|
|
return RestStorage.__super__.perform.call(this, key, record, options, callback);
|
|
};
|
|
|
|
RestStorage.prototype.before('all', RestStorage.skipIfError(function(env, next) {
|
|
if (!env.options.url) {
|
|
try {
|
|
env.options.url = env.subject.prototype ? this.urlForCollection(env.subject, env) : this.urlForRecord(env.subject, env);
|
|
} catch (error) {
|
|
env.error = error;
|
|
}
|
|
}
|
|
return next();
|
|
}));
|
|
|
|
RestStorage.prototype.before('get', 'put', 'post', 'delete', RestStorage.skipIfError(function(env, next) {
|
|
env.options.method = env.action.toUpperCase();
|
|
return next();
|
|
}));
|
|
|
|
RestStorage.prototype.before('create', 'update', RestStorage.skipIfError(function(env, next) {
|
|
var data, json, namespace;
|
|
json = env.subject.toJSON();
|
|
if (namespace = this.recordJsonNamespace(env.subject)) {
|
|
data = {};
|
|
data[namespace] = json;
|
|
} else {
|
|
data = json;
|
|
}
|
|
env.options.data = data;
|
|
return next();
|
|
}));
|
|
|
|
RestStorage.prototype.before('create', 'update', 'put', 'post', RestStorage.skipIfError(function(env, next) {
|
|
if (this.serializeAsForm) {
|
|
env.options.contentType = this.constructor.PostBodyContentType;
|
|
} else {
|
|
if (env.options.data != null) {
|
|
env.options.data = JSON.stringify(env.options.data);
|
|
env.options.contentType = this.constructor.JSONContentType;
|
|
}
|
|
}
|
|
return next();
|
|
}));
|
|
|
|
RestStorage.prototype.after('all', RestStorage.skipIfError(function(env, next) {
|
|
var json;
|
|
if (!(env.data != null)) {
|
|
return next();
|
|
}
|
|
if (typeof env.data === 'string') {
|
|
if (env.data.length > 0) {
|
|
try {
|
|
json = this._jsonToAttributes(env.data);
|
|
} catch (error) {
|
|
env.error = error;
|
|
return next();
|
|
}
|
|
}
|
|
} else if (typeof env.data === 'object') {
|
|
json = env.data;
|
|
}
|
|
if (json != null) {
|
|
env.json = json;
|
|
}
|
|
return next();
|
|
}));
|
|
|
|
RestStorage.prototype.extractFromNamespace = function(data, namespace) {
|
|
if (namespace && (data[namespace] != null)) {
|
|
return data[namespace];
|
|
} else {
|
|
return data;
|
|
}
|
|
};
|
|
|
|
RestStorage.prototype.after('create', 'read', 'update', RestStorage.skipIfError(function(env, next) {
|
|
var json;
|
|
if (env.json != null) {
|
|
json = this.extractFromNamespace(env.json, this.recordJsonNamespace(env.subject));
|
|
env.subject._withoutDirtyTracking(function() {
|
|
return this.fromJSON(json);
|
|
});
|
|
}
|
|
env.result = env.subject;
|
|
return next();
|
|
}));
|
|
|
|
RestStorage.prototype.after('readAll', RestStorage.skipIfError(function(env, next) {
|
|
var jsonRecordAttributes, namespace;
|
|
namespace = this.collectionJsonNamespace(env.subject);
|
|
env.recordsAttributes = this.extractFromNamespace(env.json, namespace);
|
|
if (Batman.typeOf(env.recordsAttributes) !== 'Array') {
|
|
namespace = this.recordJsonNamespace(env.subject.prototype);
|
|
env.recordsAttributes = [this.extractFromNamespace(env.json, namespace)];
|
|
}
|
|
env.result = env.records = (function() {
|
|
var _i, _len, _ref, _results;
|
|
_ref = env.recordsAttributes;
|
|
_results = [];
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
jsonRecordAttributes = _ref[_i];
|
|
_results.push(this.getRecordFromData(jsonRecordAttributes, env.subject));
|
|
}
|
|
return _results;
|
|
}).call(this);
|
|
return next();
|
|
}));
|
|
|
|
RestStorage.prototype.after('get', 'put', 'post', 'delete', RestStorage.skipIfError(function(env, next) {
|
|
var json, namespace;
|
|
if (env.json != null) {
|
|
json = env.json;
|
|
namespace = env.subject.prototype ? this.collectionJsonNamespace(env.subject) : this.recordJsonNamespace(env.subject);
|
|
env.result = namespace && (env.json[namespace] != null) ? env.json[namespace] : env.json;
|
|
}
|
|
return next();
|
|
}));
|
|
|
|
RestStorage.HTTPMethods = {
|
|
create: 'POST',
|
|
update: 'PUT',
|
|
read: 'GET',
|
|
readAll: 'GET',
|
|
destroy: 'DELETE'
|
|
};
|
|
|
|
_ref = ['create', 'read', 'update', 'destroy', 'readAll', 'get', 'post', 'put', 'delete'];
|
|
_fn = function(key) {
|
|
return RestStorage.prototype[key] = RestStorage.skipIfError(function(env, next) {
|
|
var _base;
|
|
(_base = env.options).method || (_base.method = this.constructor.HTTPMethods[key]);
|
|
return this.request(env, next);
|
|
});
|
|
};
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
key = _ref[_i];
|
|
_fn(key);
|
|
}
|
|
|
|
RestStorage.prototype.after('all', function(env, next) {
|
|
if (env.error) {
|
|
env.error = this._errorFor(env.error, env);
|
|
}
|
|
return next();
|
|
});
|
|
|
|
RestStorage._statusCodeErrors = {
|
|
'0': RestStorage.CommunicationError,
|
|
'403': RestStorage.NotAllowedError,
|
|
'404': RestStorage.NotFoundError,
|
|
'406': RestStorage.NotAcceptableError,
|
|
'422': RestStorage.UnprocessableRecordError,
|
|
'500': RestStorage.InternalStorageError,
|
|
'501': RestStorage.NotImplementedError
|
|
};
|
|
|
|
RestStorage.prototype._errorFor = function(error, env) {
|
|
var errorClass, request;
|
|
if (error instanceof Error || !(error.request != null)) {
|
|
return error;
|
|
}
|
|
if (errorClass = this.constructor._statusCodeErrors[error.request.status]) {
|
|
request = error.request;
|
|
error = new errorClass;
|
|
error.request = request;
|
|
error.env = env;
|
|
}
|
|
return error;
|
|
};
|
|
|
|
return RestStorage;
|
|
|
|
}).call(this, Batman.StorageAdapter);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.LocalStorage = (function(_super) {
|
|
|
|
__extends(LocalStorage, _super);
|
|
|
|
function LocalStorage() {
|
|
if (typeof window.localStorage === 'undefined') {
|
|
return null;
|
|
}
|
|
LocalStorage.__super__.constructor.apply(this, arguments);
|
|
this.storage = localStorage;
|
|
}
|
|
|
|
LocalStorage.prototype.storageRegExpForRecord = function(record) {
|
|
return new RegExp("^" + (this.storageKey(record)) + "(\\d+)$");
|
|
};
|
|
|
|
LocalStorage.prototype.nextIdForRecord = function(record) {
|
|
var nextId, re;
|
|
re = this.storageRegExpForRecord(record);
|
|
nextId = 1;
|
|
this._forAllStorageEntries(function(k, v) {
|
|
var matches;
|
|
if (matches = re.exec(k)) {
|
|
return nextId = Math.max(nextId, parseInt(matches[1], 10) + 1);
|
|
}
|
|
});
|
|
return nextId;
|
|
};
|
|
|
|
LocalStorage.prototype._forAllStorageEntries = function(iterator) {
|
|
var i, key, _i, _ref;
|
|
for (i = _i = 0, _ref = this.storage.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
|
|
key = this.storage.key(i);
|
|
iterator.call(this, key, this.storage.getItem(key));
|
|
}
|
|
return true;
|
|
};
|
|
|
|
LocalStorage.prototype._storageEntriesMatching = function(constructor, options) {
|
|
var re, records;
|
|
re = this.storageRegExpForRecord(constructor.prototype);
|
|
records = [];
|
|
this._forAllStorageEntries(function(storageKey, storageString) {
|
|
var data, keyMatches;
|
|
if (keyMatches = re.exec(storageKey)) {
|
|
data = this._jsonToAttributes(storageString);
|
|
data[constructor.primaryKey] = keyMatches[1];
|
|
if (this._dataMatches(options, data)) {
|
|
return records.push(data);
|
|
}
|
|
}
|
|
});
|
|
return records;
|
|
};
|
|
|
|
LocalStorage.prototype._dataMatches = function(conditions, data) {
|
|
var k, match, v;
|
|
match = true;
|
|
for (k in conditions) {
|
|
v = conditions[k];
|
|
if (data[k] !== v) {
|
|
match = false;
|
|
break;
|
|
}
|
|
}
|
|
return match;
|
|
};
|
|
|
|
LocalStorage.prototype.before('read', 'create', 'update', 'destroy', LocalStorage.skipIfError(function(env, next) {
|
|
var _this = this;
|
|
if (env.action === 'create') {
|
|
env.id = env.subject.get('id') || env.subject._withoutDirtyTracking(function() {
|
|
return env.subject.set('id', _this.nextIdForRecord(env.subject));
|
|
});
|
|
} else {
|
|
env.id = env.subject.get('id');
|
|
}
|
|
if (env.id == null) {
|
|
env.error = new this.constructor.StorageError("Couldn't get/set record primary key on " + env.action + "!");
|
|
} else {
|
|
env.key = this.storageKey(env.subject) + env.id;
|
|
}
|
|
return next();
|
|
}));
|
|
|
|
LocalStorage.prototype.before('create', 'update', LocalStorage.skipIfError(function(env, next) {
|
|
env.recordAttributes = JSON.stringify(env.subject);
|
|
return next();
|
|
}));
|
|
|
|
LocalStorage.prototype.after('read', LocalStorage.skipIfError(function(env, next) {
|
|
if (typeof env.recordAttributes === 'string') {
|
|
try {
|
|
env.recordAttributes = this._jsonToAttributes(env.recordAttributes);
|
|
} catch (error) {
|
|
env.error = error;
|
|
return next();
|
|
}
|
|
}
|
|
env.subject._withoutDirtyTracking(function() {
|
|
return this.fromJSON(env.recordAttributes);
|
|
});
|
|
return next();
|
|
}));
|
|
|
|
LocalStorage.prototype.after('read', 'create', 'update', 'destroy', LocalStorage.skipIfError(function(env, next) {
|
|
env.result = env.subject;
|
|
return next();
|
|
}));
|
|
|
|
LocalStorage.prototype.after('readAll', LocalStorage.skipIfError(function(env, next) {
|
|
var recordAttributes;
|
|
env.result = env.records = (function() {
|
|
var _i, _len, _ref, _results;
|
|
_ref = env.recordsAttributes;
|
|
_results = [];
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
recordAttributes = _ref[_i];
|
|
_results.push(this.getRecordFromData(recordAttributes, env.subject));
|
|
}
|
|
return _results;
|
|
}).call(this);
|
|
return next();
|
|
}));
|
|
|
|
LocalStorage.prototype.read = LocalStorage.skipIfError(function(env, next) {
|
|
env.recordAttributes = this.storage.getItem(env.key);
|
|
if (!env.recordAttributes) {
|
|
env.error = new this.constructor.NotFoundError();
|
|
}
|
|
return next();
|
|
});
|
|
|
|
LocalStorage.prototype.create = LocalStorage.skipIfError(function(_arg, next) {
|
|
var key, recordAttributes;
|
|
key = _arg.key, recordAttributes = _arg.recordAttributes;
|
|
if (this.storage.getItem(key)) {
|
|
arguments[0].error = new this.constructor.RecordExistsError;
|
|
} else {
|
|
this.storage.setItem(key, recordAttributes);
|
|
}
|
|
return next();
|
|
});
|
|
|
|
LocalStorage.prototype.update = LocalStorage.skipIfError(function(_arg, next) {
|
|
var key, recordAttributes;
|
|
key = _arg.key, recordAttributes = _arg.recordAttributes;
|
|
this.storage.setItem(key, recordAttributes);
|
|
return next();
|
|
});
|
|
|
|
LocalStorage.prototype.destroy = LocalStorage.skipIfError(function(_arg, next) {
|
|
var key;
|
|
key = _arg.key;
|
|
this.storage.removeItem(key);
|
|
return next();
|
|
});
|
|
|
|
LocalStorage.prototype.readAll = LocalStorage.skipIfError(function(env, next) {
|
|
try {
|
|
arguments[0].recordsAttributes = this._storageEntriesMatching(env.subject, env.options.data);
|
|
} catch (error) {
|
|
arguments[0].error = error;
|
|
}
|
|
return next();
|
|
});
|
|
|
|
return LocalStorage;
|
|
|
|
})(Batman.StorageAdapter);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.SessionStorage = (function(_super) {
|
|
|
|
__extends(SessionStorage, _super);
|
|
|
|
function SessionStorage() {
|
|
if (typeof window.sessionStorage === 'undefined') {
|
|
return null;
|
|
}
|
|
SessionStorage.__super__.constructor.apply(this, arguments);
|
|
this.storage = sessionStorage;
|
|
}
|
|
|
|
return SessionStorage;
|
|
|
|
})(Batman.LocalStorage);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
|
|
Batman.Encoders = new Batman.Object;
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.ParamsReplacer = (function(_super) {
|
|
|
|
__extends(ParamsReplacer, _super);
|
|
|
|
function ParamsReplacer(navigator, params) {
|
|
this.navigator = navigator;
|
|
this.params = params;
|
|
}
|
|
|
|
ParamsReplacer.prototype.redirect = function() {
|
|
return this.navigator.replace(this.toObject());
|
|
};
|
|
|
|
ParamsReplacer.prototype.replace = function(params) {
|
|
this.params.replace(params);
|
|
return this.redirect();
|
|
};
|
|
|
|
ParamsReplacer.prototype.update = function(params) {
|
|
this.params.update(params);
|
|
return this.redirect();
|
|
};
|
|
|
|
ParamsReplacer.prototype.clear = function() {
|
|
this.params.clear();
|
|
return this.redirect();
|
|
};
|
|
|
|
ParamsReplacer.prototype.toObject = function() {
|
|
return this.params.toObject();
|
|
};
|
|
|
|
ParamsReplacer.accessor({
|
|
get: function(k) {
|
|
return this.params.get(k);
|
|
},
|
|
set: function(k, v) {
|
|
var oldValue, result;
|
|
oldValue = this.params.get(k);
|
|
result = this.params.set(k, v);
|
|
if (oldValue !== v) {
|
|
this.redirect();
|
|
}
|
|
return result;
|
|
},
|
|
unset: function(k) {
|
|
var hadKey, result;
|
|
hadKey = this.params.hasKey(k);
|
|
result = this.params.unset(k);
|
|
if (hadKey) {
|
|
this.redirect();
|
|
}
|
|
return result;
|
|
}
|
|
});
|
|
|
|
return ParamsReplacer;
|
|
|
|
})(Batman.Object);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.ParamsPusher = (function(_super) {
|
|
|
|
__extends(ParamsPusher, _super);
|
|
|
|
function ParamsPusher() {
|
|
return ParamsPusher.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
ParamsPusher.prototype.redirect = function() {
|
|
return this.navigator.push(this.toObject());
|
|
};
|
|
|
|
return ParamsPusher;
|
|
|
|
})(Batman.ParamsReplacer);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.NamedRouteQuery = (function(_super) {
|
|
|
|
__extends(NamedRouteQuery, _super);
|
|
|
|
NamedRouteQuery.prototype.isNamedRouteQuery = true;
|
|
|
|
function NamedRouteQuery(routeMap, args) {
|
|
var key;
|
|
if (args == null) {
|
|
args = [];
|
|
}
|
|
NamedRouteQuery.__super__.constructor.call(this, {
|
|
routeMap: routeMap,
|
|
args: args
|
|
});
|
|
for (key in this.get('routeMap').childrenByName) {
|
|
this[key] = this._queryAccess.bind(this, key);
|
|
}
|
|
}
|
|
|
|
NamedRouteQuery.accessor('route', function() {
|
|
var collectionRoute, memberRoute, route, _i, _len, _ref, _ref1;
|
|
_ref = this.get('routeMap'), memberRoute = _ref.memberRoute, collectionRoute = _ref.collectionRoute;
|
|
_ref1 = [memberRoute, collectionRoute];
|
|
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
|
route = _ref1[_i];
|
|
if (route != null) {
|
|
if (route.namedArguments.length === this.get('args').length) {
|
|
return route;
|
|
}
|
|
}
|
|
}
|
|
return collectionRoute || memberRoute;
|
|
});
|
|
|
|
NamedRouteQuery.accessor('path', function() {
|
|
return this.path();
|
|
});
|
|
|
|
NamedRouteQuery.accessor('routeMap', 'args', 'cardinality', 'hashValue', Batman.Property.defaultAccessor);
|
|
|
|
NamedRouteQuery.accessor({
|
|
get: function(key) {
|
|
if (key == null) {
|
|
return;
|
|
}
|
|
if (typeof key === 'string') {
|
|
return this.nextQueryForName(key);
|
|
} else {
|
|
return this.nextQueryWithArgument(key);
|
|
}
|
|
},
|
|
cache: false
|
|
});
|
|
|
|
NamedRouteQuery.accessor('withHash', function() {
|
|
var _this = this;
|
|
return new Batman.Accessible(function(hashValue) {
|
|
return _this.withHash(hashValue);
|
|
});
|
|
});
|
|
|
|
NamedRouteQuery.prototype.withHash = function(hashValue) {
|
|
var clone;
|
|
clone = this.clone();
|
|
clone.set('hashValue', hashValue);
|
|
return clone;
|
|
};
|
|
|
|
NamedRouteQuery.prototype.nextQueryForName = function(key) {
|
|
var map;
|
|
if (map = this.get('routeMap').childrenByName[key]) {
|
|
return new Batman.NamedRouteQuery(map, this.args);
|
|
} else {
|
|
return Batman.developer.error("Couldn't find a route for the name " + key + "!");
|
|
}
|
|
};
|
|
|
|
NamedRouteQuery.prototype.nextQueryWithArgument = function(arg) {
|
|
var args;
|
|
args = this.args.slice(0);
|
|
args.push(arg);
|
|
return this.clone(args);
|
|
};
|
|
|
|
NamedRouteQuery.prototype.path = function() {
|
|
var argumentName, argumentValue, index, namedArguments, params, _i, _len;
|
|
params = {};
|
|
namedArguments = this.get('route.namedArguments');
|
|
for (index = _i = 0, _len = namedArguments.length; _i < _len; index = ++_i) {
|
|
argumentName = namedArguments[index];
|
|
if ((argumentValue = this.get('args')[index]) != null) {
|
|
params[argumentName] = this._toParam(argumentValue);
|
|
}
|
|
}
|
|
if (this.get('hashValue') != null) {
|
|
params['#'] = this.get('hashValue');
|
|
}
|
|
return this.get('route').pathFromParams(params);
|
|
};
|
|
|
|
NamedRouteQuery.prototype.toString = function() {
|
|
return this.path();
|
|
};
|
|
|
|
NamedRouteQuery.prototype.clone = function(args) {
|
|
if (args == null) {
|
|
args = this.args;
|
|
}
|
|
return new Batman.NamedRouteQuery(this.routeMap, args);
|
|
};
|
|
|
|
NamedRouteQuery.prototype._toParam = function(arg) {
|
|
if (arg instanceof Batman.AssociationProxy) {
|
|
arg = arg.get('target');
|
|
}
|
|
if ((arg != null ? arg.toParam : void 0) != null) {
|
|
return arg.toParam();
|
|
} else {
|
|
return arg;
|
|
}
|
|
};
|
|
|
|
NamedRouteQuery.prototype._queryAccess = function(key, arg) {
|
|
var query;
|
|
query = this.nextQueryForName(key);
|
|
if (arg != null) {
|
|
query = query.nextQueryWithArgument(arg);
|
|
}
|
|
return query;
|
|
};
|
|
|
|
return NamedRouteQuery;
|
|
|
|
})(Batman.Object);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.Dispatcher = (function(_super) {
|
|
var ControllerDirectory;
|
|
|
|
__extends(Dispatcher, _super);
|
|
|
|
Dispatcher.canInferRoute = function(argument) {
|
|
return argument instanceof Batman.Model || argument instanceof Batman.AssociationProxy || argument.prototype instanceof Batman.Model;
|
|
};
|
|
|
|
Dispatcher.paramsFromArgument = function(argument) {
|
|
var resourceNameFromModel;
|
|
resourceNameFromModel = function(model) {
|
|
return Batman.helpers.camelize(Batman.helpers.pluralize(model.get('resourceName')), true);
|
|
};
|
|
if (!this.canInferRoute(argument)) {
|
|
return argument;
|
|
}
|
|
if (argument instanceof Batman.Model || argument instanceof Batman.AssociationProxy) {
|
|
if (argument.isProxy) {
|
|
argument = argument.get('target');
|
|
}
|
|
if (argument != null) {
|
|
return {
|
|
controller: resourceNameFromModel(argument.constructor),
|
|
action: 'show',
|
|
id: argument.get('id')
|
|
};
|
|
} else {
|
|
return {};
|
|
}
|
|
} else if (argument.prototype instanceof Batman.Model) {
|
|
return {
|
|
controller: resourceNameFromModel(argument),
|
|
action: 'index'
|
|
};
|
|
} else {
|
|
return argument;
|
|
}
|
|
};
|
|
|
|
ControllerDirectory = (function(_super1) {
|
|
|
|
__extends(ControllerDirectory, _super1);
|
|
|
|
function ControllerDirectory() {
|
|
return ControllerDirectory.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
ControllerDirectory.accessor('__app', Batman.Property.defaultAccessor);
|
|
|
|
ControllerDirectory.accessor(function(key) {
|
|
return this.get("__app." + (Batman.helpers.capitalize(key)) + "Controller.sharedController");
|
|
});
|
|
|
|
return ControllerDirectory;
|
|
|
|
})(Batman.Object);
|
|
|
|
Dispatcher.accessor('controllers', function() {
|
|
return new ControllerDirectory({
|
|
__app: this.get('app')
|
|
});
|
|
});
|
|
|
|
function Dispatcher(app, routeMap) {
|
|
Dispatcher.__super__.constructor.call(this, {
|
|
app: app,
|
|
routeMap: routeMap
|
|
});
|
|
}
|
|
|
|
Dispatcher.prototype.routeForParams = function(params) {
|
|
params = this.constructor.paramsFromArgument(params);
|
|
return this.get('routeMap').routeForParams(params);
|
|
};
|
|
|
|
Dispatcher.prototype.pathFromParams = function(params) {
|
|
var _ref;
|
|
if (typeof params === 'string') {
|
|
return params;
|
|
}
|
|
params = this.constructor.paramsFromArgument(params);
|
|
return (_ref = this.routeForParams(params)) != null ? _ref.pathFromParams(params) : void 0;
|
|
};
|
|
|
|
Dispatcher.prototype.dispatch = function(params) {
|
|
var error, inferredParams, path, route, _ref, _ref1;
|
|
inferredParams = this.constructor.paramsFromArgument(params);
|
|
route = this.routeForParams(inferredParams);
|
|
if (route) {
|
|
_ref = route.pathAndParamsFromArgument(inferredParams), path = _ref[0], params = _ref[1];
|
|
this.set('app.currentRoute', route);
|
|
this.set('app.currentURL', path);
|
|
this.get('app.currentParams').replace(params || {});
|
|
route.dispatch(params);
|
|
} else {
|
|
if (Batman.typeOf(params) === 'Object' && !this.constructor.canInferRoute(params)) {
|
|
return this.get('app.currentParams').replace(params);
|
|
} else {
|
|
this.get('app.currentParams').clear();
|
|
}
|
|
error = {
|
|
type: '404',
|
|
isPrevented: false,
|
|
preventDefault: function() {
|
|
return this.isPrevented = true;
|
|
}
|
|
};
|
|
if ((_ref1 = Batman.currentApp) != null) {
|
|
_ref1.fire('error', error);
|
|
}
|
|
if (error.isPrevented) {
|
|
return params;
|
|
}
|
|
if (params !== '/404') {
|
|
return Batman.redirect('/404');
|
|
}
|
|
}
|
|
return path;
|
|
};
|
|
|
|
return Dispatcher;
|
|
|
|
}).call(this, Batman.Object);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.Route = (function(_super) {
|
|
|
|
__extends(Route, _super);
|
|
|
|
Route.regexps = {
|
|
namedParam: /:([\w\d]+)/g,
|
|
splatParam: /\*([\w\d]+)/g,
|
|
queryParam: '(?:\\?.+)?',
|
|
namedOrSplat: /[:|\*]([\w\d]+)/g,
|
|
namePrefix: '[:|\*]',
|
|
escapeRegExp: /[-[\]{}+?.,\\^$|#\s]/g,
|
|
openOptParam: /\(/g,
|
|
closeOptParam: /\)/g
|
|
};
|
|
|
|
Route.prototype.optionKeys = ['member', 'collection'];
|
|
|
|
Route.prototype.testKeys = ['controller', 'action'];
|
|
|
|
Route.prototype.isRoute = true;
|
|
|
|
function Route(templatePath, baseParams) {
|
|
var k, matches, namedArguments, pattern, properties, regexp, regexps, _i, _len, _ref;
|
|
regexps = this.constructor.regexps;
|
|
if (templatePath.indexOf('/') !== 0) {
|
|
templatePath = "/" + templatePath;
|
|
}
|
|
pattern = templatePath.replace(regexps.escapeRegExp, '\\$&');
|
|
regexp = RegExp("^" + (pattern.replace(regexps.openOptParam, '(?:').replace(regexps.closeOptParam, ')?').replace(regexps.namedParam, '([^\/]+)').replace(regexps.splatParam, '(.*?)')) + regexps.queryParam + "$");
|
|
regexps.namedOrSplat.lastIndex = 0;
|
|
namedArguments = ((function() {
|
|
var _results;
|
|
_results = [];
|
|
while (matches = regexps.namedOrSplat.exec(pattern)) {
|
|
_results.push(matches[1]);
|
|
}
|
|
return _results;
|
|
})());
|
|
properties = {
|
|
templatePath: templatePath,
|
|
pattern: pattern,
|
|
regexp: regexp,
|
|
namedArguments: namedArguments,
|
|
baseParams: baseParams
|
|
};
|
|
_ref = this.optionKeys;
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
k = _ref[_i];
|
|
properties[k] = baseParams[k];
|
|
delete baseParams[k];
|
|
}
|
|
Route.__super__.constructor.call(this, properties);
|
|
}
|
|
|
|
Route.prototype.paramsFromPath = function(pathAndQuery) {
|
|
var index, match, matches, name, namedArguments, params, uri, _i, _len;
|
|
uri = new Batman.URI(pathAndQuery);
|
|
namedArguments = this.get('namedArguments');
|
|
params = Batman.extend({
|
|
path: uri.path
|
|
}, this.get('baseParams'));
|
|
matches = this.get('regexp').exec(uri.path).slice(1);
|
|
for (index = _i = 0, _len = matches.length; _i < _len; index = ++_i) {
|
|
match = matches[index];
|
|
name = namedArguments[index];
|
|
params[name] = match;
|
|
}
|
|
return Batman.extend(params, uri.queryParams);
|
|
};
|
|
|
|
Route.prototype.pathFromParams = function(argumentParams) {
|
|
var hash, key, name, newPath, params, path, query, regexp, regexps, _i, _j, _len, _len1, _ref, _ref1;
|
|
params = Batman.extend({}, argumentParams);
|
|
path = this.get('templatePath');
|
|
regexps = this.constructor.regexps;
|
|
_ref = this.get('namedArguments');
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
name = _ref[_i];
|
|
regexp = RegExp("" + regexps.namePrefix + name);
|
|
newPath = path.replace(regexp, (params[name] != null ? params[name] : ''));
|
|
if (newPath !== path) {
|
|
delete params[name];
|
|
path = newPath;
|
|
}
|
|
}
|
|
path = path.replace(regexps.openOptParam, '').replace(regexps.closeOptParam, '').replace(/([^\/])\/+$/, '$1');
|
|
_ref1 = this.testKeys;
|
|
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
|
key = _ref1[_j];
|
|
delete params[key];
|
|
}
|
|
if (params['#']) {
|
|
hash = params['#'];
|
|
delete params['#'];
|
|
}
|
|
query = Batman.URI.queryFromParams(params);
|
|
if (query) {
|
|
path += "?" + query;
|
|
}
|
|
if (hash) {
|
|
path += "#" + hash;
|
|
}
|
|
return path;
|
|
};
|
|
|
|
Route.prototype.test = function(pathOrParams) {
|
|
var key, path, value, _i, _len, _ref;
|
|
if (typeof pathOrParams === 'string') {
|
|
path = pathOrParams;
|
|
} else if (pathOrParams.path != null) {
|
|
path = pathOrParams.path;
|
|
} else {
|
|
path = this.pathFromParams(pathOrParams);
|
|
_ref = this.testKeys;
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
key = _ref[_i];
|
|
if ((value = this.get(key)) != null) {
|
|
if (pathOrParams[key] !== value) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return this.get('regexp').test(path);
|
|
};
|
|
|
|
Route.prototype.pathAndParamsFromArgument = function(pathOrParams) {
|
|
var params, path;
|
|
if (typeof pathOrParams === 'string') {
|
|
params = this.paramsFromPath(pathOrParams);
|
|
path = pathOrParams;
|
|
} else {
|
|
params = pathOrParams;
|
|
path = this.pathFromParams(pathOrParams);
|
|
}
|
|
return [path, params];
|
|
};
|
|
|
|
Route.prototype.dispatch = function(params) {
|
|
if (!this.test(params)) {
|
|
return false;
|
|
}
|
|
return this.get('callback')(params);
|
|
};
|
|
|
|
Route.prototype.callback = function() {
|
|
throw new Batman.DevelopmentError("Override callback in a Route subclass");
|
|
};
|
|
|
|
return Route;
|
|
|
|
})(Batman.Object);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
|
__hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.ControllerActionRoute = (function(_super) {
|
|
|
|
__extends(ControllerActionRoute, _super);
|
|
|
|
ControllerActionRoute.prototype.optionKeys = ['member', 'collection', 'app', 'controller', 'action'];
|
|
|
|
function ControllerActionRoute(templatePath, options) {
|
|
this.callback = __bind(this.callback, this);
|
|
|
|
var action, controller, _ref;
|
|
if (options.signature) {
|
|
_ref = options.signature.split('#'), controller = _ref[0], action = _ref[1];
|
|
action || (action = 'index');
|
|
options.controller = controller;
|
|
options.action = action;
|
|
delete options.signature;
|
|
}
|
|
ControllerActionRoute.__super__.constructor.call(this, templatePath, options);
|
|
}
|
|
|
|
ControllerActionRoute.prototype.callback = function(params) {
|
|
var controller;
|
|
controller = this.get("app.dispatcher.controllers." + (this.get('controller')));
|
|
return controller.dispatch(this.get('action'), params);
|
|
};
|
|
|
|
return ControllerActionRoute;
|
|
|
|
})(Batman.Route);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.CallbackActionRoute = (function(_super) {
|
|
|
|
__extends(CallbackActionRoute, _super);
|
|
|
|
function CallbackActionRoute() {
|
|
return CallbackActionRoute.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
CallbackActionRoute.prototype.optionKeys = ['member', 'collection', 'callback', 'app'];
|
|
|
|
CallbackActionRoute.prototype.controller = false;
|
|
|
|
CallbackActionRoute.prototype.action = false;
|
|
|
|
return CallbackActionRoute;
|
|
|
|
})(Batman.Route);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
__slice = [].slice;
|
|
|
|
Batman.Hash = (function(_super) {
|
|
var k, _fn, _i, _j, _len, _len1, _ref, _ref1,
|
|
_this = this;
|
|
|
|
__extends(Hash, _super);
|
|
|
|
Hash.Metadata = (function(_super1) {
|
|
|
|
__extends(Metadata, _super1);
|
|
|
|
Batman.extend(Metadata.prototype, Batman.Enumerable);
|
|
|
|
function Metadata(hash) {
|
|
this.hash = hash;
|
|
}
|
|
|
|
Metadata.accessor('length', function() {
|
|
this.hash.registerAsMutableSource();
|
|
return this.hash.length;
|
|
});
|
|
|
|
Metadata.accessor('isEmpty', 'keys', 'toArray', function(key) {
|
|
this.hash.registerAsMutableSource();
|
|
return this.hash[key]();
|
|
});
|
|
|
|
Metadata.prototype.forEach = function() {
|
|
var _ref;
|
|
return (_ref = this.hash).forEach.apply(_ref, arguments);
|
|
};
|
|
|
|
return Metadata;
|
|
|
|
})(Batman.Object);
|
|
|
|
function Hash() {
|
|
this.meta = new this.constructor.Metadata(this);
|
|
Batman.SimpleHash.apply(this, arguments);
|
|
Hash.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
Batman.extend(Hash.prototype, Batman.Enumerable);
|
|
|
|
Hash.prototype.propertyClass = Batman.Property;
|
|
|
|
Hash.defaultAccessor = {
|
|
get: Batman.SimpleHash.prototype.get,
|
|
set: Hash.mutation(function(key, value) {
|
|
var result;
|
|
result = Batman.SimpleHash.prototype.set.call(this, key, value);
|
|
this.fire('itemsWereAdded', key);
|
|
return result;
|
|
}),
|
|
unset: Hash.mutation(function(key) {
|
|
var result;
|
|
result = Batman.SimpleHash.prototype.unset.call(this, key);
|
|
if (result != null) {
|
|
this.fire('itemsWereRemoved', key);
|
|
}
|
|
return result;
|
|
}),
|
|
cache: false
|
|
};
|
|
|
|
Hash.accessor(Hash.defaultAccessor);
|
|
|
|
Hash.prototype._preventMutationEvents = function(block) {
|
|
this.prevent('change');
|
|
this.prevent('itemsWereAdded');
|
|
this.prevent('itemsWereRemoved');
|
|
try {
|
|
return block.call(this);
|
|
} finally {
|
|
this.allow('change');
|
|
this.allow('itemsWereAdded');
|
|
this.allow('itemsWereRemoved');
|
|
}
|
|
};
|
|
|
|
Hash.prototype.clear = Hash.mutation(function() {
|
|
var keys, result;
|
|
keys = this.keys();
|
|
this._preventMutationEvents(function() {
|
|
var _this = this;
|
|
return this.forEach(function(k) {
|
|
return _this.unset(k);
|
|
});
|
|
});
|
|
result = Batman.SimpleHash.prototype.clear.call(this);
|
|
this.fire.apply(this, ['itemsWereRemoved'].concat(__slice.call(keys)));
|
|
return result;
|
|
});
|
|
|
|
Hash.prototype.update = Hash.mutation(function(object) {
|
|
var addedKeys;
|
|
addedKeys = [];
|
|
this._preventMutationEvents(function() {
|
|
var _this = this;
|
|
return Batman.forEach(object, function(k, v) {
|
|
if (!_this.hasKey(k)) {
|
|
addedKeys.push(k);
|
|
}
|
|
return _this.set(k, v);
|
|
});
|
|
});
|
|
if (addedKeys.length > 0) {
|
|
return this.fire.apply(this, ['itemsWereAdded'].concat(__slice.call(addedKeys)));
|
|
}
|
|
});
|
|
|
|
Hash.prototype.replace = Hash.mutation(function(object) {
|
|
var addedKeys, removedKeys;
|
|
addedKeys = [];
|
|
removedKeys = [];
|
|
this._preventMutationEvents(function() {
|
|
var _this = this;
|
|
this.forEach(function(k, _) {
|
|
if (!Batman.objectHasKey(object, k)) {
|
|
_this.unset(k);
|
|
return removedKeys.push(k);
|
|
}
|
|
});
|
|
return Batman.forEach(object, function(k, v) {
|
|
if (!_this.hasKey(k)) {
|
|
addedKeys.push(k);
|
|
}
|
|
return _this.set(k, v);
|
|
});
|
|
});
|
|
if (addedKeys.length > 0) {
|
|
this.fire.apply(this, ['itemsWereAdded'].concat(__slice.call(addedKeys)));
|
|
}
|
|
if (removedKeys.length > 0) {
|
|
return this.fire.apply(this, ['itemsWereRemoved'].concat(__slice.call(removedKeys)));
|
|
}
|
|
});
|
|
|
|
_ref = ['equality', 'hashKeyFor', 'objectKey', 'prefixedKey', 'unprefixedKey'];
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
k = _ref[_i];
|
|
Hash.prototype[k] = Batman.SimpleHash.prototype[k];
|
|
}
|
|
|
|
_ref1 = ['hasKey', 'forEach', 'isEmpty', 'keys', 'toArray', 'merge', 'toJSON', 'toObject'];
|
|
_fn = function(k) {
|
|
return Hash.prototype[k] = function() {
|
|
this.registerAsMutableSource();
|
|
return Batman.SimpleHash.prototype[k].apply(this, arguments);
|
|
};
|
|
};
|
|
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
|
k = _ref1[_j];
|
|
_fn(k);
|
|
}
|
|
|
|
return Hash;
|
|
|
|
}).call(this, Batman.Object);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.RenderCache = (function(_super) {
|
|
|
|
__extends(RenderCache, _super);
|
|
|
|
RenderCache.prototype.maximumLength = 4;
|
|
|
|
function RenderCache() {
|
|
RenderCache.__super__.constructor.apply(this, arguments);
|
|
this.keyQueue = [];
|
|
}
|
|
|
|
RenderCache.prototype.viewForOptions = function(options) {
|
|
var _this = this;
|
|
if (options.cache === false || options.viewClass.prototype.cache === false) {
|
|
return this._newViewFromOptions(options);
|
|
}
|
|
return this.getOrSet(options, function() {
|
|
return _this._newViewFromOptions(Batman.extend({}, options));
|
|
});
|
|
};
|
|
|
|
RenderCache.prototype._newViewFromOptions = function(options) {
|
|
return new options.viewClass(options);
|
|
};
|
|
|
|
RenderCache.wrapAccessor(function(core) {
|
|
return {
|
|
cache: false,
|
|
get: function(key) {
|
|
var result;
|
|
result = core.get.call(this, key);
|
|
if (result) {
|
|
this._addOrBubbleKey(key);
|
|
}
|
|
return result;
|
|
},
|
|
set: function(key, value) {
|
|
var result;
|
|
result = core.set.apply(this, arguments);
|
|
result.set('cached', true);
|
|
this._addOrBubbleKey(key);
|
|
this._evictExpiredKeys();
|
|
return result;
|
|
},
|
|
unset: function(key) {
|
|
var result;
|
|
result = core.unset.apply(this, arguments);
|
|
result.set('cached', false);
|
|
this._removeKeyFromQueue(key);
|
|
return result;
|
|
}
|
|
};
|
|
});
|
|
|
|
RenderCache.prototype.equality = function(incomingOptions, storageOptions) {
|
|
var key;
|
|
if (Object.keys(incomingOptions).length !== Object.keys(storageOptions).length) {
|
|
return false;
|
|
}
|
|
for (key in incomingOptions) {
|
|
if (!(key === 'view')) {
|
|
if (incomingOptions[key] !== storageOptions[key]) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
return true;
|
|
};
|
|
|
|
RenderCache.prototype.reset = function() {
|
|
var key, _i, _len, _ref, _results;
|
|
_ref = this.keyQueue.slice(0);
|
|
_results = [];
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
key = _ref[_i];
|
|
_results.push(this.unset(key));
|
|
}
|
|
return _results;
|
|
};
|
|
|
|
RenderCache.prototype._addOrBubbleKey = function(key) {
|
|
this._removeKeyFromQueue(key);
|
|
return this.keyQueue.unshift(key);
|
|
};
|
|
|
|
RenderCache.prototype._removeKeyFromQueue = function(key) {
|
|
var index, queuedKey, _i, _len, _ref;
|
|
_ref = this.keyQueue;
|
|
for (index = _i = 0, _len = _ref.length; _i < _len; index = ++_i) {
|
|
queuedKey = _ref[index];
|
|
if (this.equality(queuedKey, key)) {
|
|
this.keyQueue.splice(index, 1);
|
|
break;
|
|
}
|
|
}
|
|
return key;
|
|
};
|
|
|
|
RenderCache.prototype._evictExpiredKeys = function() {
|
|
var currentKeys, i, key, _i, _ref, _ref1;
|
|
if (this.length > this.maximumLength) {
|
|
currentKeys = this.keyQueue.slice(0);
|
|
for (i = _i = _ref = this.maximumLength, _ref1 = currentKeys.length; _ref <= _ref1 ? _i < _ref1 : _i > _ref1; i = _ref <= _ref1 ? ++_i : --_i) {
|
|
key = currentKeys[i];
|
|
if (!this.get(key).isInDOM()) {
|
|
this.unset(key);
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
return RenderCache;
|
|
|
|
})(Batman.Hash);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
|
__hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
__slice = [].slice,
|
|
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
|
|
|
Batman.Controller = (function(_super) {
|
|
var _optionsFromFilterArguments;
|
|
|
|
__extends(Controller, _super);
|
|
|
|
Controller.singleton('sharedController');
|
|
|
|
Controller.wrapAccessor('routingKey', function(core) {
|
|
return {
|
|
get: function() {
|
|
if (this.routingKey != null) {
|
|
return this.routingKey;
|
|
} else {
|
|
if (Batman.config.minificationErrors) {
|
|
Batman.developer.error("Please define `routingKey` on the prototype of " + (Batman.functionName(this.constructor)) + " in order for your controller to be minification safe.");
|
|
}
|
|
return Batman.functionName(this.constructor).replace(/Controller$/, '');
|
|
}
|
|
}
|
|
};
|
|
});
|
|
|
|
Controller.accessor('_renderContext', function() {
|
|
return Batman.RenderContext.root().descend(this);
|
|
});
|
|
|
|
_optionsFromFilterArguments = function(options, nameOrFunction) {
|
|
if (!nameOrFunction) {
|
|
nameOrFunction = options;
|
|
options = {};
|
|
} else {
|
|
if (typeof options === 'string') {
|
|
options = {
|
|
only: [options]
|
|
};
|
|
} else {
|
|
if (options.only && Batman.typeOf(options.only) !== 'Array') {
|
|
options.only = [options.only];
|
|
}
|
|
if (options.except && Batman.typeOf(options.except) !== 'Array') {
|
|
options.except = [options.except];
|
|
}
|
|
}
|
|
}
|
|
options.block = nameOrFunction;
|
|
return options;
|
|
};
|
|
|
|
Controller.beforeFilter = function() {
|
|
var filters, options, _base;
|
|
Batman.initializeObject(this);
|
|
options = _optionsFromFilterArguments.apply(null, arguments);
|
|
filters = (_base = this._batman).beforeFilters || (_base.beforeFilters = []);
|
|
return filters.push(options);
|
|
};
|
|
|
|
Controller.afterFilter = function() {
|
|
var filters, options, _base;
|
|
Batman.initializeObject(this);
|
|
options = _optionsFromFilterArguments.apply(null, arguments);
|
|
filters = (_base = this._batman).afterFilters || (_base.afterFilters = []);
|
|
return filters.push(options);
|
|
};
|
|
|
|
Controller.afterFilter(function(params) {
|
|
if (this.autoScrollToHash && (params['#'] != null)) {
|
|
return this.scrollToHash(params['#']);
|
|
}
|
|
});
|
|
|
|
Controller.catchError = function() {
|
|
var currentHandlers, error, errors, handlers, options, _base, _i, _j, _len, _results;
|
|
errors = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), options = arguments[_i++];
|
|
Batman.initializeObject(this);
|
|
(_base = this._batman).errorHandlers || (_base.errorHandlers = new Batman.SimpleHash);
|
|
handlers = Batman.typeOf(options["with"]) === 'Array' ? options["with"] : [options["with"]];
|
|
_results = [];
|
|
for (_j = 0, _len = errors.length; _j < _len; _j++) {
|
|
error = errors[_j];
|
|
currentHandlers = this._batman.errorHandlers.get(error) || [];
|
|
_results.push(this._batman.errorHandlers.set(error, currentHandlers.concat(handlers)));
|
|
}
|
|
return _results;
|
|
};
|
|
|
|
Controller.prototype.errorHandler = function(callback) {
|
|
var errorFrame, _ref,
|
|
_this = this;
|
|
errorFrame = (_ref = this._actionFrames) != null ? _ref[this._actionFrames.length - 1] : void 0;
|
|
return function(err, result, env) {
|
|
if (err) {
|
|
if (errorFrame != null ? errorFrame.error : void 0) {
|
|
return;
|
|
}
|
|
if (errorFrame != null) {
|
|
errorFrame.error = err;
|
|
}
|
|
if (!_this.handleError(err)) {
|
|
throw err;
|
|
}
|
|
} else {
|
|
return typeof callback === "function" ? callback(result, env) : void 0;
|
|
}
|
|
};
|
|
};
|
|
|
|
Controller.prototype.handleError = function(error) {
|
|
var handled, _ref,
|
|
_this = this;
|
|
handled = false;
|
|
if ((_ref = this.constructor._batman.getAll('errorHandlers')) != null) {
|
|
_ref.forEach(function(hash) {
|
|
return hash.forEach(function(key, value) {
|
|
var handler, _i, _len, _results;
|
|
if (error instanceof key) {
|
|
handled = true;
|
|
_results = [];
|
|
for (_i = 0, _len = value.length; _i < _len; _i++) {
|
|
handler = value[_i];
|
|
_results.push(handler.call(_this, error));
|
|
}
|
|
return _results;
|
|
}
|
|
});
|
|
});
|
|
}
|
|
return handled;
|
|
};
|
|
|
|
function Controller() {
|
|
this.redirect = __bind(this.redirect, this);
|
|
|
|
this.handleError = __bind(this.handleError, this);
|
|
|
|
this.errorHandler = __bind(this.errorHandler, this);
|
|
Controller.__super__.constructor.apply(this, arguments);
|
|
this._resetActionFrames();
|
|
}
|
|
|
|
Controller.prototype.renderCache = new Batman.RenderCache;
|
|
|
|
Controller.prototype.defaultRenderYield = 'main';
|
|
|
|
Controller.prototype.autoScrollToHash = true;
|
|
|
|
Controller.prototype.dispatch = function(action, params) {
|
|
var redirectTo;
|
|
if (params == null) {
|
|
params = {};
|
|
}
|
|
params.controller || (params.controller = this.get('routingKey'));
|
|
params.action || (params.action = action);
|
|
params.target || (params.target = this);
|
|
this._resetActionFrames();
|
|
this.set('action', action);
|
|
this.set('params', params);
|
|
Batman.DOM.Yield.cycleAll();
|
|
this.executeAction(action, params);
|
|
Batman.DOM.Yield.clearAllStale();
|
|
redirectTo = this._afterFilterRedirect;
|
|
delete this._afterFilterRedirect;
|
|
if (redirectTo) {
|
|
return Batman.redirect(redirectTo);
|
|
}
|
|
};
|
|
|
|
Controller.prototype.executeAction = function(action, params) {
|
|
var frame, oldRedirect, parentFrame, result, _ref, _ref1,
|
|
_this = this;
|
|
if (params == null) {
|
|
params = this.get('params');
|
|
}
|
|
Batman.developer.assert(this[action], "Error! Controller action " + (this.get('routingKey')) + "." + action + " couldn't be found!");
|
|
parentFrame = this._actionFrames[this._actionFrames.length - 1];
|
|
frame = new Batman.ControllerActionFrame({
|
|
parentFrame: parentFrame,
|
|
action: action
|
|
}, function() {
|
|
var _ref;
|
|
if (!_this._afterFilterRedirect) {
|
|
_this._runFilters(action, params, 'afterFilters');
|
|
}
|
|
_this._resetActionFrames();
|
|
return (_ref = Batman.navigator) != null ? _ref.redirect = oldRedirect : void 0;
|
|
});
|
|
this._actionFrames.push(frame);
|
|
frame.startOperation({
|
|
internal: true
|
|
});
|
|
oldRedirect = (_ref = Batman.navigator) != null ? _ref.redirect : void 0;
|
|
if ((_ref1 = Batman.navigator) != null) {
|
|
_ref1.redirect = this.redirect;
|
|
}
|
|
this._runFilters(action, params, 'beforeFilters');
|
|
if (!this._afterFilterRedirect) {
|
|
result = this[action](params);
|
|
}
|
|
if (!frame.operationOccurred) {
|
|
this.render();
|
|
}
|
|
frame.finishOperation();
|
|
return result;
|
|
};
|
|
|
|
Controller.prototype.redirect = function(url) {
|
|
var frame;
|
|
frame = this._actionFrames[this._actionFrames.length - 1];
|
|
if (frame) {
|
|
if (frame.operationOccurred) {
|
|
Batman.developer.warn("Warning! Trying to redirect but an action has already been taken during " + (this.get('routingKey')) + "." + (frame.action || this.get('action')));
|
|
}
|
|
frame.startAndFinishOperation();
|
|
if (this._afterFilterRedirect != null) {
|
|
return Batman.developer.warn("Warning! Multiple actions trying to redirect!");
|
|
} else {
|
|
return this._afterFilterRedirect = url;
|
|
}
|
|
} else {
|
|
if (Batman.typeOf(url) === 'Object') {
|
|
if (!url.controller) {
|
|
url.controller = this;
|
|
}
|
|
}
|
|
return Batman.redirect(url);
|
|
}
|
|
};
|
|
|
|
Controller.prototype.render = function(options) {
|
|
var action, frame, view, _ref, _ref1,
|
|
_this = this;
|
|
if (options == null) {
|
|
options = {};
|
|
}
|
|
if (frame = (_ref = this._actionFrames) != null ? _ref[this._actionFrames.length - 1] : void 0) {
|
|
frame.startOperation();
|
|
}
|
|
if (options === false) {
|
|
frame.finishOperation();
|
|
return;
|
|
}
|
|
action = (frame != null ? frame.action : void 0) || this.get('action');
|
|
if (options) {
|
|
options.into || (options.into = this.defaultRenderYield);
|
|
}
|
|
if (!options.view) {
|
|
options.viewClass || (options.viewClass = this._viewClassForAction(action));
|
|
options.context || (options.context = this.get('_renderContext'));
|
|
options.source || (options.source = Batman.helpers.underscore(this.get('routingKey') + '/' + action));
|
|
view = this.renderCache.viewForOptions(options);
|
|
} else {
|
|
view = options.view;
|
|
options.view = null;
|
|
}
|
|
if (view) {
|
|
if ((_ref1 = Batman.currentApp) != null) {
|
|
_ref1.prevent('ready');
|
|
}
|
|
view.on('ready', function() {
|
|
var _ref2;
|
|
Batman.DOM.Yield.withName(options.into).replace(view.get('node'));
|
|
if ((_ref2 = Batman.currentApp) != null) {
|
|
_ref2.allowAndFire('ready');
|
|
}
|
|
return frame != null ? frame.finishOperation() : void 0;
|
|
});
|
|
}
|
|
return view;
|
|
};
|
|
|
|
Controller.prototype.scrollToHash = function(hash) {
|
|
if (hash == null) {
|
|
hash = this.get('params')['#'];
|
|
}
|
|
return Batman.DOM.scrollIntoView(hash);
|
|
};
|
|
|
|
Controller.prototype._resetActionFrames = function() {
|
|
return this._actionFrames = [];
|
|
};
|
|
|
|
Controller.prototype._viewClassForAction = function(action) {
|
|
var classPrefix, _ref;
|
|
classPrefix = this.get('routingKey').replace('/', '_');
|
|
return ((_ref = Batman.currentApp) != null ? _ref[Batman.helpers.camelize("" + classPrefix + "_" + action + "_view")] : void 0) || Batman.View;
|
|
};
|
|
|
|
Controller.prototype._runFilters = function(action, params, filters) {
|
|
var block, options, _i, _len, _ref;
|
|
if (filters = (_ref = this.constructor._batman) != null ? _ref.get(filters) : void 0) {
|
|
for (_i = 0, _len = filters.length; _i < _len; _i++) {
|
|
options = filters[_i];
|
|
if (options.only && __indexOf.call(options.only, action) < 0) {
|
|
continue;
|
|
}
|
|
if (options.except && __indexOf.call(options.except, action) >= 0) {
|
|
continue;
|
|
}
|
|
if (this._afterFilterRedirect) {
|
|
return;
|
|
}
|
|
block = options.block;
|
|
if (typeof block === 'function') {
|
|
block.call(this, params);
|
|
} else {
|
|
if (typeof this[block] === "function") {
|
|
this[block](params);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
return Controller;
|
|
|
|
})(Batman.Object);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.Set = (function(_super) {
|
|
var k, _fn, _i, _j, _len, _len1, _ref, _ref1,
|
|
_this = this;
|
|
|
|
__extends(Set, _super);
|
|
|
|
function Set() {
|
|
Batman.SimpleSet.apply(this, arguments);
|
|
}
|
|
|
|
Batman.extend(Set.prototype, Batman.Enumerable);
|
|
|
|
Set._applySetAccessors = function(klass) {
|
|
var accessor, accessors, key, _results;
|
|
accessors = {
|
|
first: function() {
|
|
return this.toArray()[0];
|
|
},
|
|
last: function() {
|
|
return this.toArray()[this.length - 1];
|
|
},
|
|
isEmpty: function() {
|
|
return this.isEmpty();
|
|
},
|
|
toArray: function() {
|
|
return this.toArray();
|
|
},
|
|
length: function() {
|
|
this.registerAsMutableSource();
|
|
return this.length;
|
|
},
|
|
indexedBy: function() {
|
|
var _this = this;
|
|
return new Batman.TerminalAccessible(function(key) {
|
|
return _this.indexedBy(key);
|
|
});
|
|
},
|
|
indexedByUnique: function() {
|
|
var _this = this;
|
|
return new Batman.TerminalAccessible(function(key) {
|
|
return _this.indexedByUnique(key);
|
|
});
|
|
},
|
|
sortedBy: function() {
|
|
var _this = this;
|
|
return new Batman.TerminalAccessible(function(key) {
|
|
return _this.sortedBy(key);
|
|
});
|
|
},
|
|
sortedByDescending: function() {
|
|
var _this = this;
|
|
return new Batman.TerminalAccessible(function(key) {
|
|
return _this.sortedBy(key, 'desc');
|
|
});
|
|
}
|
|
};
|
|
_results = [];
|
|
for (key in accessors) {
|
|
accessor = accessors[key];
|
|
_results.push(klass.accessor(key, accessor));
|
|
}
|
|
return _results;
|
|
};
|
|
|
|
Set._applySetAccessors(Set);
|
|
|
|
_ref = ['add', 'remove', 'clear', 'replace', 'indexedBy', 'indexedByUnique', 'sortedBy', 'equality', '_indexOfItem'];
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
k = _ref[_i];
|
|
Set.prototype[k] = Batman.SimpleSet.prototype[k];
|
|
}
|
|
|
|
_ref1 = ['find', 'merge', 'forEach', 'toArray', 'isEmpty', 'has'];
|
|
_fn = function(k) {
|
|
return Set.prototype[k] = function() {
|
|
this.registerAsMutableSource();
|
|
return Batman.SimpleSet.prototype[k].apply(this, arguments);
|
|
};
|
|
};
|
|
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
|
k = _ref1[_j];
|
|
_fn(k);
|
|
}
|
|
|
|
Set.prototype.toJSON = Set.prototype.toArray;
|
|
|
|
return Set;
|
|
|
|
}).call(this, Batman.Object);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.ErrorsSet = (function(_super) {
|
|
|
|
__extends(ErrorsSet, _super);
|
|
|
|
function ErrorsSet() {
|
|
return ErrorsSet.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
ErrorsSet.accessor(function(key) {
|
|
return this.indexedBy('attribute').get(key);
|
|
});
|
|
|
|
ErrorsSet.prototype.add = function(key, error) {
|
|
return ErrorsSet.__super__.add.call(this, new Batman.ValidationError(key, error));
|
|
};
|
|
|
|
return ErrorsSet;
|
|
|
|
})(Batman.Set);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
__slice = [].slice;
|
|
|
|
Batman.SetProxy = (function(_super) {
|
|
var k, _fn, _i, _len, _ref,
|
|
_this = this;
|
|
|
|
__extends(SetProxy, _super);
|
|
|
|
function SetProxy(base) {
|
|
var _this = this;
|
|
this.base = base;
|
|
SetProxy.__super__.constructor.call(this);
|
|
this.length = this.base.length;
|
|
this.base.on('itemsWereAdded', function() {
|
|
var items;
|
|
items = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
_this.set('length', _this.base.length);
|
|
return _this.fire.apply(_this, ['itemsWereAdded'].concat(__slice.call(items)));
|
|
});
|
|
this.base.on('itemsWereRemoved', function() {
|
|
var items;
|
|
items = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
_this.set('length', _this.base.length);
|
|
return _this.fire.apply(_this, ['itemsWereRemoved'].concat(__slice.call(items)));
|
|
});
|
|
}
|
|
|
|
Batman.extend(SetProxy.prototype, Batman.Enumerable);
|
|
|
|
SetProxy.prototype.filter = function(f) {
|
|
var r;
|
|
r = new Batman.Set();
|
|
return this.reduce((function(r, e) {
|
|
if (f(e)) {
|
|
r.add(e);
|
|
}
|
|
return r;
|
|
}), r);
|
|
};
|
|
|
|
SetProxy.prototype.replace = function() {
|
|
var length, result;
|
|
length = this.property('length');
|
|
length.isolate();
|
|
result = this.base.replace.apply(this, arguments);
|
|
length.expose();
|
|
return result;
|
|
};
|
|
|
|
Batman.Set._applySetAccessors(SetProxy);
|
|
|
|
_ref = ['add', 'remove', 'find', 'clear', 'has', 'merge', 'toArray', 'isEmpty', 'indexedBy', 'indexedByUnique', 'sortedBy'];
|
|
_fn = function(k) {
|
|
return SetProxy.prototype[k] = function() {
|
|
var _ref1;
|
|
return (_ref1 = this.base)[k].apply(_ref1, arguments);
|
|
};
|
|
};
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
k = _ref[_i];
|
|
_fn(k);
|
|
}
|
|
|
|
SetProxy.accessor('length', {
|
|
get: function() {
|
|
this.registerAsMutableSource();
|
|
return this.length;
|
|
},
|
|
set: function(_, v) {
|
|
return this.length = v;
|
|
}
|
|
});
|
|
|
|
return SetProxy;
|
|
|
|
}).call(this, Batman.Object);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
|
__hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
__slice = [].slice;
|
|
|
|
Batman.BinarySetOperation = (function(_super) {
|
|
|
|
__extends(BinarySetOperation, _super);
|
|
|
|
function BinarySetOperation(left, right) {
|
|
this.left = left;
|
|
this.right = right;
|
|
this._setup = __bind(this._setup, this);
|
|
|
|
BinarySetOperation.__super__.constructor.call(this);
|
|
this._setup(this.left, this.right);
|
|
this._setup(this.right, this.left);
|
|
}
|
|
|
|
BinarySetOperation.prototype._setup = function(set, opposite) {
|
|
var _this = this;
|
|
set.on('itemsWereAdded', function() {
|
|
var items;
|
|
items = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
return _this._itemsWereAddedToSource.apply(_this, [set, opposite].concat(__slice.call(items)));
|
|
});
|
|
set.on('itemsWereRemoved', function() {
|
|
var items;
|
|
items = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
return _this._itemsWereRemovedFromSource.apply(_this, [set, opposite].concat(__slice.call(items)));
|
|
});
|
|
return this._itemsWereAddedToSource.apply(this, [set, opposite].concat(__slice.call(set.toArray())));
|
|
};
|
|
|
|
BinarySetOperation.prototype.merge = function() {
|
|
var merged, others, set, _i, _len;
|
|
others = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
merged = new Batman.Set;
|
|
others.unshift(this);
|
|
for (_i = 0, _len = others.length; _i < _len; _i++) {
|
|
set = others[_i];
|
|
set.forEach(function(v) {
|
|
return merged.add(v);
|
|
});
|
|
}
|
|
return merged;
|
|
};
|
|
|
|
BinarySetOperation.prototype.filter = Batman.SetProxy.prototype.filter;
|
|
|
|
return BinarySetOperation;
|
|
|
|
})(Batman.Set);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
__slice = [].slice;
|
|
|
|
Batman.SetUnion = (function(_super) {
|
|
|
|
__extends(SetUnion, _super);
|
|
|
|
function SetUnion() {
|
|
return SetUnion.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
SetUnion.prototype._itemsWereAddedToSource = function() {
|
|
var items, opposite, source;
|
|
source = arguments[0], opposite = arguments[1], items = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
|
|
return this.add.apply(this, items);
|
|
};
|
|
|
|
SetUnion.prototype._itemsWereRemovedFromSource = function() {
|
|
var item, items, itemsToRemove, opposite, source;
|
|
source = arguments[0], opposite = arguments[1], items = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
|
|
itemsToRemove = (function() {
|
|
var _i, _len, _results;
|
|
_results = [];
|
|
for (_i = 0, _len = items.length; _i < _len; _i++) {
|
|
item = items[_i];
|
|
if (!opposite.has(item)) {
|
|
_results.push(item);
|
|
}
|
|
}
|
|
return _results;
|
|
})();
|
|
return this.remove.apply(this, itemsToRemove);
|
|
};
|
|
|
|
return SetUnion;
|
|
|
|
})(Batman.BinarySetOperation);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
__slice = [].slice;
|
|
|
|
Batman.SetIntersection = (function(_super) {
|
|
|
|
__extends(SetIntersection, _super);
|
|
|
|
function SetIntersection() {
|
|
return SetIntersection.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
SetIntersection.prototype._itemsWereAddedToSource = function() {
|
|
var item, items, itemsToAdd, opposite, source;
|
|
source = arguments[0], opposite = arguments[1], items = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
|
|
itemsToAdd = (function() {
|
|
var _i, _len, _results;
|
|
_results = [];
|
|
for (_i = 0, _len = items.length; _i < _len; _i++) {
|
|
item = items[_i];
|
|
if (opposite.has(item)) {
|
|
_results.push(item);
|
|
}
|
|
}
|
|
return _results;
|
|
})();
|
|
return this.add.apply(this, itemsToAdd);
|
|
};
|
|
|
|
SetIntersection.prototype._itemsWereRemovedFromSource = function() {
|
|
var items, opposite, source;
|
|
source = arguments[0], opposite = arguments[1], items = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
|
|
return this.remove.apply(this, items);
|
|
};
|
|
|
|
return SetIntersection;
|
|
|
|
})(Batman.BinarySetOperation);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
__slice = [].slice;
|
|
|
|
Batman.SetComplement = (function(_super) {
|
|
|
|
__extends(SetComplement, _super);
|
|
|
|
function SetComplement() {
|
|
return SetComplement.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
SetComplement.prototype._itemsWereAddedToSource = function() {
|
|
var item, items, itemsToAdd, itemsToRemove, opposite, source;
|
|
source = arguments[0], opposite = arguments[1], items = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
|
|
if (source === this.left) {
|
|
itemsToAdd = (function() {
|
|
var _i, _len, _results;
|
|
_results = [];
|
|
for (_i = 0, _len = items.length; _i < _len; _i++) {
|
|
item = items[_i];
|
|
if (!opposite.has(item)) {
|
|
_results.push(item);
|
|
}
|
|
}
|
|
return _results;
|
|
})();
|
|
return this.add.apply(this, itemsToAdd);
|
|
} else {
|
|
itemsToRemove = (function() {
|
|
var _i, _len, _results;
|
|
_results = [];
|
|
for (_i = 0, _len = items.length; _i < _len; _i++) {
|
|
item = items[_i];
|
|
if (opposite.has(item)) {
|
|
_results.push(item);
|
|
}
|
|
}
|
|
return _results;
|
|
})();
|
|
return this.remove.apply(this, itemsToRemove);
|
|
}
|
|
};
|
|
|
|
SetComplement.prototype._itemsWereRemovedFromSource = function() {
|
|
var item, items, itemsToAdd, opposite, source;
|
|
source = arguments[0], opposite = arguments[1], items = 3 <= arguments.length ? __slice.call(arguments, 2) : [];
|
|
if (source === this.left) {
|
|
return this.remove.apply(this, items);
|
|
} else {
|
|
itemsToAdd = (function() {
|
|
var _i, _len, _results;
|
|
_results = [];
|
|
for (_i = 0, _len = items.length; _i < _len; _i++) {
|
|
item = items[_i];
|
|
if (opposite.has(item)) {
|
|
_results.push(item);
|
|
}
|
|
}
|
|
return _results;
|
|
})();
|
|
return this.add.apply(this, itemsToAdd);
|
|
}
|
|
};
|
|
|
|
SetComplement.prototype._addComplement = function(items, opposite) {
|
|
var item;
|
|
return this.add.apply(this, (function() {
|
|
var _i, _len, _results;
|
|
_results = [];
|
|
for (_i = 0, _len = items.length; _i < _len; _i++) {
|
|
item = items[_i];
|
|
if (opposite.has(item)) {
|
|
_results.push(item);
|
|
}
|
|
}
|
|
return _results;
|
|
})());
|
|
};
|
|
|
|
return SetComplement;
|
|
|
|
})(Batman.BinarySetOperation);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
__slice = [].slice;
|
|
|
|
Batman.StateMachine = (function(_super) {
|
|
|
|
__extends(StateMachine, _super);
|
|
|
|
StateMachine.InvalidTransitionError = function(message) {
|
|
this.message = message != null ? message : "";
|
|
};
|
|
|
|
StateMachine.InvalidTransitionError.prototype = new Error;
|
|
|
|
StateMachine.transitions = function(table) {
|
|
var definePredicate, fromState, k, object, predicateKeys, toState, transitions, v, _fn, _ref,
|
|
_this = this;
|
|
for (k in table) {
|
|
v = table[k];
|
|
if (!(v.from && v.to)) {
|
|
continue;
|
|
}
|
|
object = {};
|
|
if (v.from.forEach) {
|
|
v.from.forEach(function(fromKey) {
|
|
return object[fromKey] = v.to;
|
|
});
|
|
} else {
|
|
object[v.from] = v.to;
|
|
}
|
|
table[k] = object;
|
|
}
|
|
this.prototype.transitionTable = Batman.extend({}, this.prototype.transitionTable, table);
|
|
predicateKeys = [];
|
|
definePredicate = function(state) {
|
|
var key;
|
|
key = "is" + (Batman.helpers.capitalize(state));
|
|
if (_this.prototype[key] != null) {
|
|
return;
|
|
}
|
|
predicateKeys.push(key);
|
|
return _this.prototype[key] = function() {
|
|
return this.get('state') === state;
|
|
};
|
|
};
|
|
_ref = this.prototype.transitionTable;
|
|
_fn = function(k) {
|
|
return _this.prototype[k] = function() {
|
|
return this.startTransition(k);
|
|
};
|
|
};
|
|
for (k in _ref) {
|
|
transitions = _ref[k];
|
|
if (!(!this.prototype[k])) {
|
|
continue;
|
|
}
|
|
_fn(k);
|
|
for (fromState in transitions) {
|
|
toState = transitions[fromState];
|
|
definePredicate(fromState);
|
|
definePredicate(toState);
|
|
}
|
|
}
|
|
if (predicateKeys.length) {
|
|
this.accessor.apply(this, __slice.call(predicateKeys).concat([function(key) {
|
|
return this[key]();
|
|
}]));
|
|
}
|
|
return this;
|
|
};
|
|
|
|
function StateMachine(startState) {
|
|
this.nextEvents = [];
|
|
this.set('_state', startState);
|
|
}
|
|
|
|
StateMachine.accessor('state', function() {
|
|
return this.get('_state');
|
|
});
|
|
|
|
StateMachine.prototype.isTransitioning = false;
|
|
|
|
StateMachine.prototype.transitionTable = {};
|
|
|
|
StateMachine.prototype.onTransition = function(from, into, callback) {
|
|
return this.on("" + from + "->" + into, callback);
|
|
};
|
|
|
|
StateMachine.prototype.onEnter = function(into, callback) {
|
|
return this.on("enter " + into, callback);
|
|
};
|
|
|
|
StateMachine.prototype.onExit = function(from, callback) {
|
|
return this.on("exit " + from, callback);
|
|
};
|
|
|
|
StateMachine.prototype.startTransition = Batman.Property.wrapTrackingPrevention(function(event) {
|
|
var nextState, previousState;
|
|
if (this.isTransitioning) {
|
|
this.nextEvents.push(event);
|
|
return;
|
|
}
|
|
previousState = this.get('state');
|
|
nextState = this.nextStateForEvent(event);
|
|
if (!nextState) {
|
|
return false;
|
|
}
|
|
this.isTransitioning = true;
|
|
this.fire("exit " + previousState);
|
|
this.set('_state', nextState);
|
|
this.fire("" + previousState + "->" + nextState);
|
|
this.fire("enter " + nextState);
|
|
this.fire(event);
|
|
this.isTransitioning = false;
|
|
if (this.nextEvents.length > 0) {
|
|
this.startTransition(this.nextEvents.shift());
|
|
}
|
|
return true;
|
|
});
|
|
|
|
StateMachine.prototype.canStartTransition = function(event, fromState) {
|
|
if (fromState == null) {
|
|
fromState = this.get('state');
|
|
}
|
|
return !!this.nextStateForEvent(event, fromState);
|
|
};
|
|
|
|
StateMachine.prototype.nextStateForEvent = function(event, fromState) {
|
|
var _ref;
|
|
if (fromState == null) {
|
|
fromState = this.get('state');
|
|
}
|
|
return (_ref = this.transitionTable[event]) != null ? _ref[fromState] : void 0;
|
|
};
|
|
|
|
return StateMachine;
|
|
|
|
})(Batman.Object);
|
|
|
|
Batman.DelegatingStateMachine = (function(_super) {
|
|
|
|
__extends(DelegatingStateMachine, _super);
|
|
|
|
function DelegatingStateMachine(startState, base) {
|
|
this.base = base;
|
|
DelegatingStateMachine.__super__.constructor.call(this, startState);
|
|
}
|
|
|
|
DelegatingStateMachine.prototype.fire = function() {
|
|
var result, _ref;
|
|
result = DelegatingStateMachine.__super__.fire.apply(this, arguments);
|
|
(_ref = this.base).fire.apply(_ref, arguments);
|
|
return result;
|
|
};
|
|
|
|
return DelegatingStateMachine;
|
|
|
|
})(Batman.StateMachine);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
|
__hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
__slice = [].slice;
|
|
|
|
Batman.Model = (function(_super) {
|
|
var functionName, _i, _j, _len, _len1, _ref, _ref1;
|
|
|
|
__extends(Model, _super);
|
|
|
|
Model.storageKey = null;
|
|
|
|
Model.primaryKey = 'id';
|
|
|
|
Model.persist = function() {
|
|
var mechanism, options;
|
|
mechanism = arguments[0], options = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
|
Batman.initializeObject(this.prototype);
|
|
mechanism = mechanism.isStorageAdapter ? mechanism : new mechanism(this);
|
|
if (options.length > 0) {
|
|
Batman.mixin.apply(Batman, [mechanism].concat(__slice.call(options)));
|
|
}
|
|
this.prototype._batman.storage = mechanism;
|
|
return mechanism;
|
|
};
|
|
|
|
Model.storageAdapter = function() {
|
|
Batman.initializeObject(this.prototype);
|
|
return this.prototype._batman.storage;
|
|
};
|
|
|
|
Model.encode = function() {
|
|
var encoder, encoderForKey, encoderOrLastKey, key, keys, _base, _i, _j, _len;
|
|
keys = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), encoderOrLastKey = arguments[_i++];
|
|
Batman.initializeObject(this.prototype);
|
|
(_base = this.prototype._batman).encoders || (_base.encoders = new Batman.SimpleHash);
|
|
encoder = {};
|
|
switch (Batman.typeOf(encoderOrLastKey)) {
|
|
case 'String':
|
|
keys.push(encoderOrLastKey);
|
|
break;
|
|
case 'Function':
|
|
encoder.encode = encoderOrLastKey;
|
|
break;
|
|
default:
|
|
encoder = encoderOrLastKey;
|
|
}
|
|
for (_j = 0, _len = keys.length; _j < _len; _j++) {
|
|
key = keys[_j];
|
|
encoderForKey = Batman.extend({
|
|
as: key
|
|
}, this.defaultEncoder, encoder);
|
|
this.prototype._batman.encoders.set(key, encoderForKey);
|
|
}
|
|
};
|
|
|
|
Model.defaultEncoder = {
|
|
encode: function(x) {
|
|
return x;
|
|
},
|
|
decode: function(x) {
|
|
return x;
|
|
}
|
|
};
|
|
|
|
Model.observeAndFire('primaryKey', function(newPrimaryKey, oldPrimaryKey) {
|
|
this.encode(oldPrimaryKey, {
|
|
encode: false,
|
|
decode: false
|
|
});
|
|
return this.encode(newPrimaryKey, {
|
|
encode: false,
|
|
decode: this.defaultEncoder.decode
|
|
});
|
|
});
|
|
|
|
Model.validate = function() {
|
|
var keys, matches, optionsOrFunction, validatorClass, validators, _base, _i, _j, _len, _ref, _results;
|
|
keys = 2 <= arguments.length ? __slice.call(arguments, 0, _i = arguments.length - 1) : (_i = 0, []), optionsOrFunction = arguments[_i++];
|
|
Batman.initializeObject(this.prototype);
|
|
validators = (_base = this.prototype._batman).validators || (_base.validators = []);
|
|
if (typeof optionsOrFunction === 'function') {
|
|
return validators.push({
|
|
keys: keys,
|
|
callback: optionsOrFunction
|
|
});
|
|
} else {
|
|
_ref = Batman.Validators;
|
|
_results = [];
|
|
for (_j = 0, _len = _ref.length; _j < _len; _j++) {
|
|
validatorClass = _ref[_j];
|
|
if ((matches = validatorClass.matches(optionsOrFunction))) {
|
|
_results.push(validators.push({
|
|
keys: keys,
|
|
validator: new validatorClass(matches)
|
|
}));
|
|
} else {
|
|
_results.push(void 0);
|
|
}
|
|
}
|
|
return _results;
|
|
}
|
|
};
|
|
|
|
Model.classAccessor('resourceName', {
|
|
get: function() {
|
|
if (this.resourceName != null) {
|
|
return this.resourceName;
|
|
} else {
|
|
if (Batman.config.minificationErrors) {
|
|
Batman.developer.error("Please define " + (Batman.functionName(this)) + ".resourceName in order for your model to be minification safe.");
|
|
}
|
|
return Batman.helpers.underscore(Batman.functionName(this));
|
|
}
|
|
}
|
|
});
|
|
|
|
Model.classAccessor('all', {
|
|
get: function() {
|
|
this._batman.check(this);
|
|
if (this.prototype.hasStorage() && !this._batman.allLoadTriggered) {
|
|
this.load();
|
|
this._batman.allLoadTriggered = true;
|
|
}
|
|
return this.get('loaded');
|
|
},
|
|
set: function(k, v) {
|
|
return this.set('loaded', v);
|
|
}
|
|
});
|
|
|
|
Model.classAccessor('loaded', {
|
|
get: function() {
|
|
return this._loaded || (this._loaded = new Batman.Set);
|
|
},
|
|
set: function(k, v) {
|
|
return this._loaded = v;
|
|
}
|
|
});
|
|
|
|
Model.classAccessor('first', function() {
|
|
return this.get('all').toArray()[0];
|
|
});
|
|
|
|
Model.classAccessor('last', function() {
|
|
var x;
|
|
x = this.get('all').toArray();
|
|
return x[x.length - 1];
|
|
});
|
|
|
|
Model.clear = function() {
|
|
var result, _ref;
|
|
Batman.initializeObject(this);
|
|
result = this.get('loaded').clear();
|
|
if ((_ref = this._batman.get('associations')) != null) {
|
|
_ref.reset();
|
|
}
|
|
this._resetPromises();
|
|
return result;
|
|
};
|
|
|
|
Model.find = function(id, callback) {
|
|
return this.findWithOptions(id, void 0, callback);
|
|
};
|
|
|
|
Model.findWithOptions = function(id, options, callback) {
|
|
var record;
|
|
if (options == null) {
|
|
options = {};
|
|
}
|
|
Batman.developer.assert(callback, "Must call find with a callback!");
|
|
record = new this();
|
|
record._withoutDirtyTracking(function() {
|
|
return this.set('id', id);
|
|
});
|
|
record.loadWithOptions(options, callback);
|
|
return record;
|
|
};
|
|
|
|
Model.load = function(options, callback) {
|
|
var _ref;
|
|
if ((_ref = typeof options) === 'function' || _ref === 'undefined') {
|
|
callback = options;
|
|
options = {};
|
|
} else {
|
|
options = {
|
|
data: options
|
|
};
|
|
}
|
|
return this.loadWithOptions(options, callback);
|
|
};
|
|
|
|
Model.loadWithOptions = function(options, callback) {
|
|
var _this = this;
|
|
this.fire('loading', options);
|
|
return this._doStorageOperation('readAll', options, function(err, records, env) {
|
|
var mappedRecords, record;
|
|
if (err != null) {
|
|
_this.fire('error', err);
|
|
return typeof callback === "function" ? callback(err, []) : void 0;
|
|
} else {
|
|
mappedRecords = (function() {
|
|
var _i, _len, _results;
|
|
_results = [];
|
|
for (_i = 0, _len = records.length; _i < _len; _i++) {
|
|
record = records[_i];
|
|
_results.push(this._mapIdentity(record));
|
|
}
|
|
return _results;
|
|
}).call(_this);
|
|
_this.fire('loaded', mappedRecords, env);
|
|
return typeof callback === "function" ? callback(err, mappedRecords, env) : void 0;
|
|
}
|
|
});
|
|
};
|
|
|
|
Model.create = function(attrs, callback) {
|
|
var obj, _ref;
|
|
if (!callback) {
|
|
_ref = [{}, attrs], attrs = _ref[0], callback = _ref[1];
|
|
}
|
|
obj = new this(attrs);
|
|
obj.save(callback);
|
|
return obj;
|
|
};
|
|
|
|
Model.findOrCreate = function(attrs, callback) {
|
|
var foundRecord, record;
|
|
record = new this(attrs);
|
|
if (record.isNew()) {
|
|
record.save(callback);
|
|
} else {
|
|
foundRecord = this._mapIdentity(record);
|
|
callback(void 0, foundRecord);
|
|
}
|
|
return record;
|
|
};
|
|
|
|
Model.createFromJSON = function(json) {
|
|
var record;
|
|
record = new this;
|
|
record._withoutDirtyTracking(function() {
|
|
return this.fromJSON(json);
|
|
});
|
|
return this._mapIdentity(record);
|
|
};
|
|
|
|
Model._mapIdentity = function(record) {
|
|
var existing, id, _ref;
|
|
if (typeof (id = record.get('id')) === 'undefined' || id === '') {
|
|
return record;
|
|
} else {
|
|
existing = (_ref = this.get("loaded.indexedBy.id").get(id)) != null ? _ref.toArray()[0] : void 0;
|
|
if (existing) {
|
|
existing._withoutDirtyTracking(function() {
|
|
var _ref1;
|
|
return this.updateAttributes(((_ref1 = record.get('attributes')) != null ? _ref1.toObject() : void 0) || {});
|
|
});
|
|
return existing;
|
|
} else {
|
|
this.get('loaded').add(record);
|
|
return record;
|
|
}
|
|
}
|
|
};
|
|
|
|
Model._doStorageOperation = function(operation, options, callback) {
|
|
var adapter;
|
|
Batman.developer.assert(this.prototype.hasStorage(), "Can't " + operation + " model " + (Batman.functionName(this.constructor)) + " without any storage adapters!");
|
|
adapter = this.prototype._batman.get('storage');
|
|
return adapter.perform(operation, this, options, callback);
|
|
};
|
|
|
|
_ref = ['find', 'load', 'create'];
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
functionName = _ref[_i];
|
|
Model[functionName] = Batman.Property.wrapTrackingPrevention(Model[functionName]);
|
|
}
|
|
|
|
Model.InstanceLifecycleStateMachine = (function(_super1) {
|
|
|
|
__extends(InstanceLifecycleStateMachine, _super1);
|
|
|
|
function InstanceLifecycleStateMachine() {
|
|
return InstanceLifecycleStateMachine.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
InstanceLifecycleStateMachine.transitions({
|
|
load: {
|
|
from: ['dirty', 'clean'],
|
|
to: 'loading'
|
|
},
|
|
create: {
|
|
from: ['dirty', 'clean'],
|
|
to: 'creating'
|
|
},
|
|
save: {
|
|
from: ['dirty', 'clean'],
|
|
to: 'saving'
|
|
},
|
|
destroy: {
|
|
from: ['dirty', 'clean'],
|
|
to: 'destroying'
|
|
},
|
|
failedValidation: {
|
|
from: ['saving', 'creating'],
|
|
to: 'dirty'
|
|
},
|
|
loaded: {
|
|
loading: 'clean'
|
|
},
|
|
created: {
|
|
creating: 'clean'
|
|
},
|
|
saved: {
|
|
saving: 'clean'
|
|
},
|
|
destroyed: {
|
|
destroying: 'destroyed'
|
|
},
|
|
set: {
|
|
from: ['dirty', 'clean'],
|
|
to: 'dirty'
|
|
},
|
|
error: {
|
|
from: ['saving', 'creating', 'loading', 'destroying'],
|
|
to: 'error'
|
|
}
|
|
});
|
|
|
|
return InstanceLifecycleStateMachine;
|
|
|
|
})(Batman.DelegatingStateMachine);
|
|
|
|
function Model(idOrAttributes) {
|
|
if (idOrAttributes == null) {
|
|
idOrAttributes = {};
|
|
}
|
|
this.destroy = __bind(this.destroy, this);
|
|
|
|
this.save = __bind(this.save, this);
|
|
|
|
this.loadWithOptions = __bind(this.loadWithOptions, this);
|
|
|
|
this.load = __bind(this.load, this);
|
|
|
|
Batman.developer.assert(this instanceof Batman.Object, "constructors must be called with new");
|
|
if (Batman.typeOf(idOrAttributes) === 'Object') {
|
|
Model.__super__.constructor.call(this, idOrAttributes);
|
|
} else {
|
|
Model.__super__.constructor.call(this);
|
|
this.set('id', idOrAttributes);
|
|
}
|
|
}
|
|
|
|
Model.accessor('lifecycle', function() {
|
|
return this.lifecycle || (this.lifecycle = new Batman.Model.InstanceLifecycleStateMachine('clean', this));
|
|
});
|
|
|
|
Model.accessor('attributes', function() {
|
|
return this.attributes || (this.attributes = new Batman.Hash);
|
|
});
|
|
|
|
Model.accessor('dirtyKeys', function() {
|
|
return this.dirtyKeys || (this.dirtyKeys = new Batman.Hash);
|
|
});
|
|
|
|
Model.accessor('_dirtiedKeys', function() {
|
|
return this._dirtiedKeys || (this._dirtiedKeys = new Batman.SimpleSet);
|
|
});
|
|
|
|
Model.accessor('errors', function() {
|
|
return this.errors || (this.errors = new Batman.ErrorsSet);
|
|
});
|
|
|
|
Model.accessor('isNew', function() {
|
|
return this.isNew();
|
|
});
|
|
|
|
Model.accessor('isDirty', function() {
|
|
return this.isDirty();
|
|
});
|
|
|
|
Model.accessor(Model.defaultAccessor = {
|
|
get: function(k) {
|
|
return Batman.getPath(this, ['attributes', k]);
|
|
},
|
|
set: function(k, v) {
|
|
if (this._willSet(k)) {
|
|
return this.get('attributes').set(k, v);
|
|
} else {
|
|
return this.get(k);
|
|
}
|
|
},
|
|
unset: function(k) {
|
|
return this.get('attributes').unset(k);
|
|
}
|
|
});
|
|
|
|
Model.wrapAccessor('id', function(core) {
|
|
return {
|
|
get: function() {
|
|
var primaryKey;
|
|
primaryKey = this.constructor.primaryKey;
|
|
if (primaryKey === 'id') {
|
|
return core.get.apply(this, arguments);
|
|
} else {
|
|
return this.get(primaryKey);
|
|
}
|
|
},
|
|
set: function(key, value) {
|
|
var parsedValue, primaryKey;
|
|
if ((typeof value === "string") && (value.match(/[^0-9]/) === null) && (("" + (parsedValue = parseInt(value, 10))) === value)) {
|
|
value = parsedValue;
|
|
}
|
|
primaryKey = this.constructor.primaryKey;
|
|
if (primaryKey === 'id') {
|
|
this._willSet(key);
|
|
return core.set.apply(this, arguments);
|
|
} else {
|
|
return this.set(primaryKey, value);
|
|
}
|
|
}
|
|
};
|
|
});
|
|
|
|
Model.prototype.isNew = function() {
|
|
return typeof this.get('id') === 'undefined';
|
|
};
|
|
|
|
Model.prototype.isDirty = function() {
|
|
return this.get('lifecycle.state') === 'dirty';
|
|
};
|
|
|
|
Model.prototype.updateAttributes = function(attrs) {
|
|
this.mixin(attrs);
|
|
return this;
|
|
};
|
|
|
|
Model.prototype.toString = function() {
|
|
return "" + (this.constructor.get('resourceName')) + ": " + (this.get('id'));
|
|
};
|
|
|
|
Model.prototype.toParam = function() {
|
|
return this.get('id');
|
|
};
|
|
|
|
Model.prototype.toJSON = function() {
|
|
var encoders, obj,
|
|
_this = this;
|
|
obj = {};
|
|
encoders = this._batman.get('encoders');
|
|
if (!(!encoders || encoders.isEmpty())) {
|
|
encoders.forEach(function(key, encoder) {
|
|
var encodedVal, val;
|
|
if (encoder.encode) {
|
|
val = _this.get(key);
|
|
if (typeof val !== 'undefined') {
|
|
encodedVal = encoder.encode(val, key, obj, _this);
|
|
if (typeof encodedVal !== 'undefined') {
|
|
return obj[encoder.as] = encodedVal;
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
return obj;
|
|
};
|
|
|
|
Model.prototype.fromJSON = function(data) {
|
|
var encoders, key, obj, value,
|
|
_this = this;
|
|
obj = {};
|
|
encoders = this._batman.get('encoders');
|
|
if (!encoders || encoders.isEmpty() || !encoders.some(function(key, encoder) {
|
|
return encoder.decode != null;
|
|
})) {
|
|
for (key in data) {
|
|
value = data[key];
|
|
obj[key] = value;
|
|
}
|
|
} else {
|
|
encoders.forEach(function(key, encoder) {
|
|
if (encoder.decode && typeof data[encoder.as] !== 'undefined') {
|
|
return obj[key] = encoder.decode(data[encoder.as], encoder.as, data, obj, _this);
|
|
}
|
|
});
|
|
}
|
|
if (this.constructor.primaryKey !== 'id') {
|
|
obj.id = data[this.constructor.primaryKey];
|
|
}
|
|
Batman.developer["do"](function() {
|
|
if ((!encoders) || encoders.length <= 1) {
|
|
return Batman.developer.warn("Warning: Model " + (Batman.functionName(_this.constructor)) + " has suspiciously few decoders!");
|
|
}
|
|
});
|
|
return this.mixin(obj);
|
|
};
|
|
|
|
Model.prototype.hasStorage = function() {
|
|
return this._batman.get('storage') != null;
|
|
};
|
|
|
|
Model.prototype.load = function(options, callback) {
|
|
var _ref1;
|
|
if (!callback) {
|
|
_ref1 = [{}, options], options = _ref1[0], callback = _ref1[1];
|
|
} else {
|
|
options = {
|
|
data: options
|
|
};
|
|
}
|
|
return this.loadWithOptions(options, callback);
|
|
};
|
|
|
|
Model.prototype.loadWithOptions = function(options, callback) {
|
|
var callbackQueue, hasOptions, _ref1,
|
|
_this = this;
|
|
hasOptions = Object.keys(options).length !== 0;
|
|
if ((_ref1 = this.get('lifecycle.state')) === 'destroying' || _ref1 === 'destroyed') {
|
|
if (typeof callback === "function") {
|
|
callback(new Error("Can't load a destroyed record!"));
|
|
}
|
|
return;
|
|
}
|
|
if (this.get('lifecycle').load()) {
|
|
callbackQueue = [];
|
|
if (callback != null) {
|
|
callbackQueue.push(callback);
|
|
}
|
|
if (!hasOptions) {
|
|
this._currentLoad = callbackQueue;
|
|
}
|
|
return this._doStorageOperation('read', options, function(err, record, env) {
|
|
var _j, _len1;
|
|
if (!err) {
|
|
_this.get('lifecycle').loaded();
|
|
record = _this.constructor._mapIdentity(record);
|
|
} else {
|
|
_this.get('lifecycle').error();
|
|
}
|
|
if (!hasOptions) {
|
|
_this._currentLoad = null;
|
|
}
|
|
for (_j = 0, _len1 = callbackQueue.length; _j < _len1; _j++) {
|
|
callback = callbackQueue[_j];
|
|
callback(err, record, env);
|
|
}
|
|
});
|
|
} else {
|
|
if (this.get('lifecycle.state') === 'loading' && !hasOptions) {
|
|
if (callback != null) {
|
|
return this._currentLoad.push(callback);
|
|
}
|
|
} else {
|
|
return typeof callback === "function" ? callback(new Batman.StateMachine.InvalidTransitionError("Can't load while in state " + (this.get('lifecycle.state')))) : void 0;
|
|
}
|
|
}
|
|
};
|
|
|
|
Model.prototype.save = function(options, callback) {
|
|
var endState, isNew, startState, storageOperation, _ref1, _ref2,
|
|
_this = this;
|
|
if (!callback) {
|
|
_ref1 = [{}, options], options = _ref1[0], callback = _ref1[1];
|
|
}
|
|
isNew = this.isNew();
|
|
_ref2 = isNew ? ['create', 'create', 'created'] : ['save', 'update', 'saved'], startState = _ref2[0], storageOperation = _ref2[1], endState = _ref2[2];
|
|
if (this.get('lifecycle').startTransition(startState)) {
|
|
return this.validate(function(error, errors) {
|
|
var associations;
|
|
if (error || errors.length) {
|
|
_this.get('lifecycle').failedValidation();
|
|
return typeof callback === "function" ? callback(error || errors, _this) : void 0;
|
|
}
|
|
associations = _this.constructor._batman.get('associations');
|
|
_this._withoutDirtyTracking(function() {
|
|
var _ref3,
|
|
_this = this;
|
|
return associations != null ? (_ref3 = associations.getByType('belongsTo')) != null ? _ref3.forEach(function(association, label) {
|
|
return association.apply(_this);
|
|
}) : void 0 : void 0;
|
|
});
|
|
return _this._doStorageOperation(storageOperation, {
|
|
data: options
|
|
}, function(err, record, env) {
|
|
if (!err) {
|
|
_this.get('dirtyKeys').clear();
|
|
_this.get('_dirtiedKeys').clear();
|
|
if (associations) {
|
|
record._withoutDirtyTracking(function() {
|
|
var _ref3, _ref4;
|
|
if ((_ref3 = associations.getByType('hasOne')) != null) {
|
|
_ref3.forEach(function(association, label) {
|
|
return association.apply(err, record);
|
|
});
|
|
}
|
|
return (_ref4 = associations.getByType('hasMany')) != null ? _ref4.forEach(function(association, label) {
|
|
return association.apply(err, record);
|
|
}) : void 0;
|
|
});
|
|
}
|
|
record = _this.constructor._mapIdentity(record);
|
|
_this.get('lifecycle').startTransition(endState);
|
|
} else {
|
|
if (err instanceof Batman.ErrorsSet) {
|
|
_this.get('lifecycle').failedValidation();
|
|
} else {
|
|
_this.get('lifecycle').error();
|
|
}
|
|
}
|
|
return typeof callback === "function" ? callback(err, record || _this, env) : void 0;
|
|
});
|
|
});
|
|
} else {
|
|
return typeof callback === "function" ? callback(new Batman.StateMachine.InvalidTransitionError("Can't save while in state " + (this.get('lifecycle.state')))) : void 0;
|
|
}
|
|
};
|
|
|
|
Model.prototype.destroy = function(options, callback) {
|
|
var _ref1,
|
|
_this = this;
|
|
if (!callback) {
|
|
_ref1 = [{}, options], options = _ref1[0], callback = _ref1[1];
|
|
}
|
|
if (this.get('lifecycle').destroy()) {
|
|
return this._doStorageOperation('destroy', {
|
|
data: options
|
|
}, function(err, record, env) {
|
|
if (!err) {
|
|
_this.constructor.get('loaded').remove(_this);
|
|
_this.get('lifecycle').destroyed();
|
|
} else {
|
|
_this.get('lifecycle').error();
|
|
}
|
|
return typeof callback === "function" ? callback(err, record, env) : void 0;
|
|
});
|
|
} else {
|
|
return typeof callback === "function" ? callback(new Batman.StateMachine.InvalidTransitionError("Can't destroy while in state " + (this.get('lifecycle.state')))) : void 0;
|
|
}
|
|
};
|
|
|
|
Model.prototype.validate = function(callback) {
|
|
var args, count, errors, finishedValidation, key, validator, validators, _j, _k, _len1, _len2, _ref1;
|
|
errors = this.get('errors');
|
|
errors.clear();
|
|
validators = this._batman.get('validators') || [];
|
|
if (!validators || validators.length === 0) {
|
|
if (typeof callback === "function") {
|
|
callback(void 0, errors);
|
|
}
|
|
return true;
|
|
}
|
|
count = validators.reduce((function(acc, validator) {
|
|
return acc + validator.keys.length;
|
|
}), 0);
|
|
finishedValidation = function() {
|
|
if (--count === 0) {
|
|
return typeof callback === "function" ? callback(void 0, errors) : void 0;
|
|
}
|
|
};
|
|
for (_j = 0, _len1 = validators.length; _j < _len1; _j++) {
|
|
validator = validators[_j];
|
|
_ref1 = validator.keys;
|
|
for (_k = 0, _len2 = _ref1.length; _k < _len2; _k++) {
|
|
key = _ref1[_k];
|
|
args = [errors, this, key, finishedValidation];
|
|
try {
|
|
if (validator.validator) {
|
|
validator.validator.validateEach.apply(validator.validator, args);
|
|
} else {
|
|
validator.callback.apply(validator, args);
|
|
}
|
|
} catch (e) {
|
|
if (typeof callback === "function") {
|
|
callback(e, errors);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
Model.prototype.associationProxy = function(association) {
|
|
var proxies, _base, _name;
|
|
Batman.initializeObject(this);
|
|
proxies = (_base = this._batman).associationProxies || (_base.associationProxies = {});
|
|
proxies[_name = association.label] || (proxies[_name] = new association.proxyClass(association, this));
|
|
return proxies[association.label];
|
|
};
|
|
|
|
Model.prototype._willSet = function(key) {
|
|
if (this._pauseDirtyTracking) {
|
|
return true;
|
|
}
|
|
if (this.get('lifecycle').startTransition('set')) {
|
|
if (!this.get('_dirtiedKeys').has(key)) {
|
|
this.set("dirtyKeys." + key, this.get(key));
|
|
this.get('_dirtiedKeys').add(key);
|
|
}
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
};
|
|
|
|
Model.prototype._doStorageOperation = function(operation, options, callback) {
|
|
var adapter,
|
|
_this = this;
|
|
Batman.developer.assert(this.hasStorage(), "Can't " + operation + " model " + (Batman.functionName(this.constructor)) + " without any storage adapters!");
|
|
adapter = this._batman.get('storage');
|
|
return adapter.perform(operation, this, options, function() {
|
|
return callback.apply(null, arguments);
|
|
});
|
|
};
|
|
|
|
Model.prototype._withoutDirtyTracking = function(block) {
|
|
var result;
|
|
this._pauseDirtyTracking = true;
|
|
result = block.call(this);
|
|
this._pauseDirtyTracking = false;
|
|
return result;
|
|
};
|
|
|
|
_ref1 = ['load', 'save', 'validate', 'destroy'];
|
|
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
|
functionName = _ref1[_j];
|
|
Model.prototype[functionName] = Batman.Property.wrapTrackingPrevention(Model.prototype[functionName]);
|
|
}
|
|
|
|
return Model;
|
|
|
|
}).call(this, Batman.Object);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var k, _fn, _i, _len, _ref,
|
|
_this = this;
|
|
|
|
_ref = Batman.AssociationCurator.availableAssociations;
|
|
_fn = function(k) {
|
|
return Batman.Model[k] = function(label, scope) {
|
|
var collection, _base;
|
|
Batman.initializeObject(this);
|
|
collection = (_base = this._batman).associations || (_base.associations = new Batman.AssociationCurator(this));
|
|
return collection.add(new Batman["" + (Batman.helpers.capitalize(k)) + "Association"](this, label, scope));
|
|
};
|
|
};
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
k = _ref[_i];
|
|
_fn(k);
|
|
}
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.Proxy = (function(_super) {
|
|
|
|
__extends(Proxy, _super);
|
|
|
|
Proxy.prototype.isProxy = true;
|
|
|
|
function Proxy(target) {
|
|
Proxy.__super__.constructor.call(this);
|
|
if (target != null) {
|
|
this.set('target', target);
|
|
}
|
|
}
|
|
|
|
Proxy.accessor('target', Batman.Property.defaultAccessor);
|
|
|
|
Proxy.accessor({
|
|
get: function(key) {
|
|
var _ref;
|
|
return (_ref = this.get('target')) != null ? _ref.get(key) : void 0;
|
|
},
|
|
set: function(key, value) {
|
|
var _ref;
|
|
return (_ref = this.get('target')) != null ? _ref.set(key, value) : void 0;
|
|
},
|
|
unset: function(key) {
|
|
var _ref;
|
|
return (_ref = this.get('target')) != null ? _ref.unset(key) : void 0;
|
|
}
|
|
});
|
|
|
|
return Proxy;
|
|
|
|
})(Batman.Object);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.AssociationProxy = (function(_super) {
|
|
|
|
__extends(AssociationProxy, _super);
|
|
|
|
AssociationProxy.prototype.loaded = false;
|
|
|
|
function AssociationProxy(association, model) {
|
|
this.association = association;
|
|
this.model = model;
|
|
AssociationProxy.__super__.constructor.call(this);
|
|
}
|
|
|
|
AssociationProxy.prototype.toJSON = function() {
|
|
var target;
|
|
target = this.get('target');
|
|
if (target != null) {
|
|
return this.get('target').toJSON();
|
|
}
|
|
};
|
|
|
|
AssociationProxy.prototype.load = function(callback) {
|
|
var _this = this;
|
|
this.fetch(function(err, proxiedRecord) {
|
|
if (!err) {
|
|
_this._setTarget(proxiedRecord);
|
|
}
|
|
return typeof callback === "function" ? callback(err, proxiedRecord) : void 0;
|
|
});
|
|
return this.get('target');
|
|
};
|
|
|
|
AssociationProxy.prototype.loadFromLocal = function() {
|
|
var target;
|
|
if (!this._canLoad()) {
|
|
return;
|
|
}
|
|
if (target = this.fetchFromLocal()) {
|
|
this._setTarget(target);
|
|
}
|
|
return target;
|
|
};
|
|
|
|
AssociationProxy.prototype.fetch = function(callback) {
|
|
var record;
|
|
if (!this._canLoad()) {
|
|
return callback(void 0, void 0);
|
|
}
|
|
record = this.fetchFromLocal();
|
|
if (record) {
|
|
return callback(void 0, record);
|
|
} else {
|
|
return this.fetchFromRemote(callback);
|
|
}
|
|
};
|
|
|
|
AssociationProxy.accessor('loaded', Batman.Property.defaultAccessor);
|
|
|
|
AssociationProxy.accessor('target', {
|
|
get: function() {
|
|
return this.fetchFromLocal();
|
|
},
|
|
set: function(_, v) {
|
|
return v;
|
|
}
|
|
});
|
|
|
|
AssociationProxy.prototype._canLoad = function() {
|
|
return (this.get('foreignValue') || this.get('primaryValue')) != null;
|
|
};
|
|
|
|
AssociationProxy.prototype._setTarget = function(target) {
|
|
this.set('target', target);
|
|
this.set('loaded', true);
|
|
return this.fire('loaded', target);
|
|
};
|
|
|
|
return AssociationProxy;
|
|
|
|
})(Batman.Proxy);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.HasOneProxy = (function(_super) {
|
|
|
|
__extends(HasOneProxy, _super);
|
|
|
|
function HasOneProxy() {
|
|
return HasOneProxy.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
HasOneProxy.accessor('primaryValue', function() {
|
|
return this.model.get(this.association.primaryKey);
|
|
});
|
|
|
|
HasOneProxy.prototype.fetchFromLocal = function() {
|
|
return this.association.setIndex().get(this.get('primaryValue'));
|
|
};
|
|
|
|
HasOneProxy.prototype.fetchFromRemote = function(callback) {
|
|
var loadOptions,
|
|
_this = this;
|
|
loadOptions = {
|
|
data: {}
|
|
};
|
|
loadOptions.data[this.association.foreignKey] = this.get('primaryValue');
|
|
if (this.association.options.url) {
|
|
loadOptions.collectionUrl = this.association.options.url;
|
|
loadOptions.urlContext = this.model;
|
|
}
|
|
return this.association.getRelatedModel().loadWithOptions(loadOptions, function(error, loadedRecords) {
|
|
if (error) {
|
|
throw error;
|
|
}
|
|
if (!loadedRecords || loadedRecords.length <= 0) {
|
|
return callback(new Error("Couldn't find related record!"), void 0);
|
|
} else {
|
|
return callback(void 0, loadedRecords[0]);
|
|
}
|
|
});
|
|
};
|
|
|
|
return HasOneProxy;
|
|
|
|
})(Batman.AssociationProxy);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.BelongsToProxy = (function(_super) {
|
|
|
|
__extends(BelongsToProxy, _super);
|
|
|
|
function BelongsToProxy() {
|
|
return BelongsToProxy.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
BelongsToProxy.accessor('foreignValue', function() {
|
|
return this.model.get(this.association.foreignKey);
|
|
});
|
|
|
|
BelongsToProxy.prototype.fetchFromLocal = function() {
|
|
return this.association.setIndex().get(this.get('foreignValue'));
|
|
};
|
|
|
|
BelongsToProxy.prototype.fetchFromRemote = function(callback) {
|
|
var loadOptions,
|
|
_this = this;
|
|
loadOptions = {};
|
|
if (this.association.options.url) {
|
|
loadOptions.recordUrl = this.association.options.url;
|
|
}
|
|
return this.association.getRelatedModel().findWithOptions(this.get('foreignValue'), loadOptions, function(error, loadedRecord) {
|
|
if (error) {
|
|
throw error;
|
|
}
|
|
return callback(void 0, loadedRecord);
|
|
});
|
|
};
|
|
|
|
return BelongsToProxy;
|
|
|
|
})(Batman.AssociationProxy);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.PolymorphicBelongsToProxy = (function(_super) {
|
|
|
|
__extends(PolymorphicBelongsToProxy, _super);
|
|
|
|
function PolymorphicBelongsToProxy() {
|
|
return PolymorphicBelongsToProxy.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
PolymorphicBelongsToProxy.accessor('foreignTypeValue', function() {
|
|
return this.model.get(this.association.foreignTypeKey);
|
|
});
|
|
|
|
PolymorphicBelongsToProxy.prototype.fetchFromLocal = function() {
|
|
return this.association.setIndexForType(this.get('foreignTypeValue')).get(this.get('foreignValue'));
|
|
};
|
|
|
|
PolymorphicBelongsToProxy.prototype.fetchFromRemote = function(callback) {
|
|
var loadOptions,
|
|
_this = this;
|
|
loadOptions = {};
|
|
if (this.association.options.url) {
|
|
loadOptions.recordUrl = this.association.options.url;
|
|
}
|
|
return this.association.getRelatedModelForType(this.get('foreignTypeValue')).findWithOptions(this.get('foreignValue'), loadOptions, function(error, loadedRecord) {
|
|
if (error) {
|
|
throw error;
|
|
}
|
|
return callback(void 0, loadedRecord);
|
|
});
|
|
};
|
|
|
|
return PolymorphicBelongsToProxy;
|
|
|
|
})(Batman.BelongsToProxy);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.Accessible = (function(_super) {
|
|
|
|
__extends(Accessible, _super);
|
|
|
|
function Accessible() {
|
|
this.accessor.apply(this, arguments);
|
|
}
|
|
|
|
return Accessible;
|
|
|
|
})(Batman.Object);
|
|
|
|
Batman.TerminalAccessible = (function(_super) {
|
|
|
|
__extends(TerminalAccessible, _super);
|
|
|
|
function TerminalAccessible() {
|
|
return TerminalAccessible.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
TerminalAccessible.prototype.propertyClass = Batman.Property;
|
|
|
|
return TerminalAccessible;
|
|
|
|
})(Batman.Accessible);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
|
|
Batman.mixins = new Batman.Object;
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
|
|
Batman.URI = (function() {
|
|
/*
|
|
# URI parsing
|
|
*/
|
|
|
|
var attributes, childKeyMatchers, decodeQueryComponent, encodeComponent, encodeQueryComponent, keyVal, nameParser, normalizeParams, plus, queryFromParams, r20, strictParser;
|
|
|
|
strictParser = /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/;
|
|
|
|
attributes = ["source", "protocol", "authority", "userInfo", "user", "password", "hostname", "port", "relative", "path", "directory", "file", "query", "hash"];
|
|
|
|
function URI(str) {
|
|
var i, matches;
|
|
matches = strictParser.exec(str);
|
|
i = 14;
|
|
while (i--) {
|
|
this[attributes[i]] = matches[i] || '';
|
|
}
|
|
this.queryParams = this.constructor.paramsFromQuery(this.query);
|
|
delete this.authority;
|
|
delete this.userInfo;
|
|
delete this.relative;
|
|
delete this.directory;
|
|
delete this.file;
|
|
delete this.query;
|
|
}
|
|
|
|
URI.prototype.queryString = function() {
|
|
return this.constructor.queryFromParams(this.queryParams);
|
|
};
|
|
|
|
URI.prototype.toString = function() {
|
|
return [this.protocol ? "" + this.protocol + ":" : void 0, this.authority() ? "//" : void 0, this.authority(), this.relative()].join("");
|
|
};
|
|
|
|
URI.prototype.userInfo = function() {
|
|
return [this.user, this.password ? ":" + this.password : void 0].join("");
|
|
};
|
|
|
|
URI.prototype.authority = function() {
|
|
return [this.userInfo(), this.user || this.password ? "@" : void 0, this.hostname, this.port ? ":" + this.port : void 0].join("");
|
|
};
|
|
|
|
URI.prototype.relative = function() {
|
|
var query;
|
|
query = this.queryString();
|
|
return [this.path, query ? "?" + query : void 0, this.hash ? "#" + this.hash : void 0].join("");
|
|
};
|
|
|
|
URI.prototype.directory = function() {
|
|
var splitPath;
|
|
splitPath = this.path.split('/');
|
|
if (splitPath.length > 1) {
|
|
return splitPath.slice(0, splitPath.length - 1).join('/') + "/";
|
|
} else {
|
|
return "";
|
|
}
|
|
};
|
|
|
|
URI.prototype.file = function() {
|
|
var splitPath;
|
|
splitPath = this.path.split("/");
|
|
return splitPath[splitPath.length - 1];
|
|
};
|
|
|
|
/*
|
|
# query parsing
|
|
*/
|
|
|
|
|
|
URI.paramsFromQuery = function(query) {
|
|
var matches, params, segment, _i, _len, _ref;
|
|
params = {};
|
|
_ref = query.split('&');
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
segment = _ref[_i];
|
|
if (matches = segment.match(keyVal)) {
|
|
normalizeParams(params, decodeQueryComponent(matches[1]), decodeQueryComponent(matches[2]));
|
|
} else {
|
|
normalizeParams(params, decodeQueryComponent(segment), null);
|
|
}
|
|
}
|
|
return params;
|
|
};
|
|
|
|
URI.decodeQueryComponent = decodeQueryComponent = function(str) {
|
|
return decodeURIComponent(str.replace(plus, '%20'));
|
|
};
|
|
|
|
nameParser = /^[\[\]]*([^\[\]]+)\]*(.*)/;
|
|
|
|
childKeyMatchers = [/^\[\]\[([^\[\]]+)\]$/, /^\[\](.+)$/];
|
|
|
|
plus = /\+/g;
|
|
|
|
r20 = /%20/g;
|
|
|
|
keyVal = /^([^=]*)=(.*)/;
|
|
|
|
normalizeParams = function(params, name, v) {
|
|
var after, childKey, k, last, matches, _ref, _ref1, _ref2;
|
|
if (matches = name.match(nameParser)) {
|
|
k = matches[1];
|
|
after = matches[2];
|
|
} else {
|
|
return;
|
|
}
|
|
if (after === '') {
|
|
params[k] = v;
|
|
} else if (after === '[]') {
|
|
if ((_ref = params[k]) == null) {
|
|
params[k] = [];
|
|
}
|
|
if (Batman.typeOf(params[k]) !== 'Array') {
|
|
throw new Error("expected Array (got " + (Batman.typeOf(params[k])) + ") for param \"" + k + "\"");
|
|
}
|
|
params[k].push(v);
|
|
} else if (matches = after.match(childKeyMatchers[0]) || after.match(childKeyMatchers[1])) {
|
|
childKey = matches[1];
|
|
if ((_ref1 = params[k]) == null) {
|
|
params[k] = [];
|
|
}
|
|
if (Batman.typeOf(params[k]) !== 'Array') {
|
|
throw new Error("expected Array (got " + (Batman.typeOf(params[k])) + ") for param \"" + k + "\"");
|
|
}
|
|
last = params[k][params[k].length - 1];
|
|
if (Batman.typeOf(last) === 'Object' && !(childKey in last)) {
|
|
normalizeParams(last, childKey, v);
|
|
} else {
|
|
params[k].push(normalizeParams({}, childKey, v));
|
|
}
|
|
} else {
|
|
if ((_ref2 = params[k]) == null) {
|
|
params[k] = {};
|
|
}
|
|
if (Batman.typeOf(params[k]) !== 'Object') {
|
|
throw new Error("expected Object (got " + (Batman.typeOf(params[k])) + ") for param \"" + k + "\"");
|
|
}
|
|
params[k] = normalizeParams(params[k], after, v);
|
|
}
|
|
return params;
|
|
};
|
|
|
|
/*
|
|
# query building
|
|
*/
|
|
|
|
|
|
URI.queryFromParams = queryFromParams = function(value, prefix) {
|
|
var arrayResults, k, v, valueType;
|
|
if (value == null) {
|
|
return prefix;
|
|
}
|
|
valueType = Batman.typeOf(value);
|
|
if (!((prefix != null) || valueType === 'Object')) {
|
|
throw new Error("value must be an Object");
|
|
}
|
|
switch (valueType) {
|
|
case 'Array':
|
|
return ((function() {
|
|
var _i, _len;
|
|
arrayResults = [];
|
|
if (value.length === 0) {
|
|
arrayResults.push(queryFromParams(null, "" + prefix + "[]"));
|
|
} else {
|
|
for (_i = 0, _len = value.length; _i < _len; _i++) {
|
|
v = value[_i];
|
|
arrayResults.push(queryFromParams(v, "" + prefix + "[]"));
|
|
}
|
|
}
|
|
return arrayResults;
|
|
})()).join("&");
|
|
case 'Object':
|
|
return ((function() {
|
|
var _results;
|
|
_results = [];
|
|
for (k in value) {
|
|
v = value[k];
|
|
_results.push(queryFromParams(v, prefix ? "" + prefix + "[" + (encodeQueryComponent(k)) + "]" : encodeQueryComponent(k)));
|
|
}
|
|
return _results;
|
|
})()).join("&");
|
|
default:
|
|
if (prefix != null) {
|
|
return "" + prefix + "=" + (encodeQueryComponent(value));
|
|
} else {
|
|
return encodeQueryComponent(value);
|
|
}
|
|
}
|
|
};
|
|
|
|
URI.encodeComponent = encodeComponent = function(str) {
|
|
if (str != null) {
|
|
return encodeURIComponent(str);
|
|
} else {
|
|
return '';
|
|
}
|
|
};
|
|
|
|
URI.encodeQueryComponent = encodeQueryComponent = function(str) {
|
|
return encodeComponent(str).replace(r20, '+');
|
|
};
|
|
|
|
return URI;
|
|
|
|
})();
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.Request = (function(_super) {
|
|
var dataHasFileUploads;
|
|
|
|
__extends(Request, _super);
|
|
|
|
Request.objectToFormData = function(data) {
|
|
var formData, key, pairForList, val, _i, _len, _ref, _ref1;
|
|
pairForList = function(key, object, first) {
|
|
var k, list, v;
|
|
if (first == null) {
|
|
first = false;
|
|
}
|
|
if (object instanceof Batman.container.File) {
|
|
return [[key, object]];
|
|
}
|
|
return list = (function() {
|
|
switch (Batman.typeOf(object)) {
|
|
case 'Object':
|
|
list = (function() {
|
|
var _results;
|
|
_results = [];
|
|
for (k in object) {
|
|
v = object[k];
|
|
_results.push(pairForList((first ? k : "" + key + "[" + k + "]"), v));
|
|
}
|
|
return _results;
|
|
})();
|
|
return list.reduce(function(acc, list) {
|
|
return acc.concat(list);
|
|
}, []);
|
|
case 'Array':
|
|
return object.reduce(function(acc, element) {
|
|
return acc.concat(pairForList("" + key + "[]", element));
|
|
}, []);
|
|
default:
|
|
return [[key, object != null ? object : ""]];
|
|
}
|
|
})();
|
|
};
|
|
formData = new Batman.container.FormData();
|
|
_ref = pairForList("", data, true);
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
_ref1 = _ref[_i], key = _ref1[0], val = _ref1[1];
|
|
formData.append(key, val);
|
|
}
|
|
return formData;
|
|
};
|
|
|
|
Request.dataHasFileUploads = dataHasFileUploads = function(data) {
|
|
var k, type, v, _i, _len;
|
|
if ((typeof File !== "undefined" && File !== null) && data instanceof File) {
|
|
return true;
|
|
}
|
|
type = Batman.typeOf(data);
|
|
switch (type) {
|
|
case 'Object':
|
|
for (k in data) {
|
|
v = data[k];
|
|
if (dataHasFileUploads(v)) {
|
|
return true;
|
|
}
|
|
}
|
|
break;
|
|
case 'Array':
|
|
for (_i = 0, _len = data.length; _i < _len; _i++) {
|
|
v = data[_i];
|
|
if (dataHasFileUploads(v)) {
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
return false;
|
|
};
|
|
|
|
Request.wrapAccessor('method', function(core) {
|
|
return {
|
|
set: function(k, val) {
|
|
return core.set.call(this, k, val != null ? typeof val.toUpperCase === "function" ? val.toUpperCase() : void 0 : void 0);
|
|
}
|
|
};
|
|
});
|
|
|
|
Request.prototype.method = 'GET';
|
|
|
|
Request.prototype.hasFileUploads = function() {
|
|
return dataHasFileUploads(this.data);
|
|
};
|
|
|
|
Request.prototype.contentType = 'application/x-www-form-urlencoded';
|
|
|
|
Request.prototype.autosend = true;
|
|
|
|
function Request(options) {
|
|
var handler, handlers, k, _ref;
|
|
handlers = {};
|
|
for (k in options) {
|
|
handler = options[k];
|
|
if (!(k === 'success' || k === 'error' || k === 'loading' || k === 'loaded')) {
|
|
continue;
|
|
}
|
|
handlers[k] = handler;
|
|
delete options[k];
|
|
}
|
|
Request.__super__.constructor.call(this, options);
|
|
for (k in handlers) {
|
|
handler = handlers[k];
|
|
this.on(k, handler);
|
|
}
|
|
if (((_ref = this.get('url')) != null ? _ref.length : void 0) > 0) {
|
|
if (this.autosend) {
|
|
this.send();
|
|
}
|
|
} else {
|
|
this.observe('url', function(url) {
|
|
if (url != null) {
|
|
return this.send();
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
Request.prototype.send = function() {
|
|
return Batman.developer.error("Please source a dependency file for a request implementation");
|
|
};
|
|
|
|
return Request;
|
|
|
|
})(Batman.Object);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
__slice = [].slice;
|
|
|
|
Batman.SetObserver = (function(_super) {
|
|
|
|
__extends(SetObserver, _super);
|
|
|
|
function SetObserver(base) {
|
|
var _this = this;
|
|
this.base = base;
|
|
this._itemObservers = new Batman.SimpleHash;
|
|
this._setObservers = new Batman.SimpleHash;
|
|
this._setObservers.set("itemsWereAdded", function() {
|
|
return _this.fire.apply(_this, ['itemsWereAdded'].concat(__slice.call(arguments)));
|
|
});
|
|
this._setObservers.set("itemsWereRemoved", function() {
|
|
return _this.fire.apply(_this, ['itemsWereRemoved'].concat(__slice.call(arguments)));
|
|
});
|
|
this.on('itemsWereAdded', this.startObservingItems.bind(this));
|
|
this.on('itemsWereRemoved', this.stopObservingItems.bind(this));
|
|
}
|
|
|
|
SetObserver.prototype.observedItemKeys = [];
|
|
|
|
SetObserver.prototype.observerForItemAndKey = function(item, key) {};
|
|
|
|
SetObserver.prototype._getOrSetObserverForItemAndKey = function(item, key) {
|
|
var _this = this;
|
|
return this._itemObservers.getOrSet(item, function() {
|
|
var observersByKey;
|
|
observersByKey = new Batman.SimpleHash;
|
|
return observersByKey.getOrSet(key, function() {
|
|
return _this.observerForItemAndKey(item, key);
|
|
});
|
|
});
|
|
};
|
|
|
|
SetObserver.prototype.startObserving = function() {
|
|
this._manageItemObservers("observe");
|
|
return this._manageSetObservers("addHandler");
|
|
};
|
|
|
|
SetObserver.prototype.stopObserving = function() {
|
|
this._manageItemObservers("forget");
|
|
return this._manageSetObservers("removeHandler");
|
|
};
|
|
|
|
SetObserver.prototype.startObservingItems = function() {
|
|
var item, items, _i, _len, _results;
|
|
items = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
_results = [];
|
|
for (_i = 0, _len = items.length; _i < _len; _i++) {
|
|
item = items[_i];
|
|
_results.push(this._manageObserversForItem(item, "observe"));
|
|
}
|
|
return _results;
|
|
};
|
|
|
|
SetObserver.prototype.stopObservingItems = function() {
|
|
var item, items, _i, _len, _results;
|
|
items = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
_results = [];
|
|
for (_i = 0, _len = items.length; _i < _len; _i++) {
|
|
item = items[_i];
|
|
_results.push(this._manageObserversForItem(item, "forget"));
|
|
}
|
|
return _results;
|
|
};
|
|
|
|
SetObserver.prototype._manageObserversForItem = function(item, method) {
|
|
var key, _i, _len, _ref;
|
|
if (!item.isObservable) {
|
|
return;
|
|
}
|
|
_ref = this.observedItemKeys;
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
key = _ref[_i];
|
|
item[method](key, this._getOrSetObserverForItemAndKey(item, key));
|
|
}
|
|
if (method === "forget") {
|
|
return this._itemObservers.unset(item);
|
|
}
|
|
};
|
|
|
|
SetObserver.prototype._manageItemObservers = function(method) {
|
|
var _this = this;
|
|
return this.base.forEach(function(item) {
|
|
return _this._manageObserversForItem(item, method);
|
|
});
|
|
};
|
|
|
|
SetObserver.prototype._manageSetObservers = function(method) {
|
|
var _this = this;
|
|
if (!this.base.isObservable) {
|
|
return;
|
|
}
|
|
return this._setObservers.forEach(function(key, observer) {
|
|
return _this.base.event(key)[method](observer);
|
|
});
|
|
};
|
|
|
|
return SetObserver;
|
|
|
|
})(Batman.Object);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.SetSort = (function(_super) {
|
|
|
|
__extends(SetSort, _super);
|
|
|
|
function SetSort(base, key, order) {
|
|
var boundReIndex;
|
|
this.key = key;
|
|
if (order == null) {
|
|
order = "asc";
|
|
}
|
|
SetSort.__super__.constructor.call(this, base);
|
|
this.descending = order.toLowerCase() === "desc";
|
|
if (this.base.isObservable) {
|
|
this._setObserver = new Batman.SetObserver(this.base);
|
|
this._setObserver.observedItemKeys = [this.key];
|
|
boundReIndex = this._reIndex.bind(this);
|
|
this._setObserver.observerForItemAndKey = function() {
|
|
return boundReIndex;
|
|
};
|
|
this._setObserver.on('itemsWereAdded', boundReIndex);
|
|
this._setObserver.on('itemsWereRemoved', boundReIndex);
|
|
this.startObserving();
|
|
}
|
|
this._reIndex();
|
|
}
|
|
|
|
SetSort.prototype.startObserving = function() {
|
|
var _ref;
|
|
return (_ref = this._setObserver) != null ? _ref.startObserving() : void 0;
|
|
};
|
|
|
|
SetSort.prototype.stopObserving = function() {
|
|
var _ref;
|
|
return (_ref = this._setObserver) != null ? _ref.stopObserving() : void 0;
|
|
};
|
|
|
|
SetSort.prototype.toArray = function() {
|
|
return this.get('_storage');
|
|
};
|
|
|
|
SetSort.prototype.forEach = function(iterator, ctx) {
|
|
var e, i, _i, _len, _ref, _results;
|
|
_ref = this.get('_storage');
|
|
_results = [];
|
|
for (i = _i = 0, _len = _ref.length; _i < _len; i = ++_i) {
|
|
e = _ref[i];
|
|
_results.push(iterator.call(ctx, e, i, this));
|
|
}
|
|
return _results;
|
|
};
|
|
|
|
SetSort.prototype.find = function(block) {
|
|
var item, _i, _len, _ref;
|
|
this.base.registerAsMutableSource();
|
|
_ref = this.get('_storage');
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
item = _ref[_i];
|
|
if (block(item)) {
|
|
return item;
|
|
}
|
|
}
|
|
};
|
|
|
|
SetSort.prototype.merge = function(other) {
|
|
this.base.registerAsMutableSource();
|
|
return (function(func, args, ctor) {
|
|
ctor.prototype = func.prototype;
|
|
var child = new ctor, result = func.apply(child, args), t = typeof result;
|
|
return t == "object" || t == "function" ? result || child : child;
|
|
})(Batman.Set, this._storage, function(){}).merge(other).sortedBy(this.key, this.order);
|
|
};
|
|
|
|
SetSort.prototype.compare = function(a, b) {
|
|
if (a === b) {
|
|
return 0;
|
|
}
|
|
if (a === void 0) {
|
|
return 1;
|
|
}
|
|
if (b === void 0) {
|
|
return -1;
|
|
}
|
|
if (a === null) {
|
|
return 1;
|
|
}
|
|
if (b === null) {
|
|
return -1;
|
|
}
|
|
if (a === false) {
|
|
return 1;
|
|
}
|
|
if (b === false) {
|
|
return -1;
|
|
}
|
|
if (a === true) {
|
|
return 1;
|
|
}
|
|
if (b === true) {
|
|
return -1;
|
|
}
|
|
if (a !== a) {
|
|
if (b !== b) {
|
|
return 0;
|
|
} else {
|
|
return 1;
|
|
}
|
|
}
|
|
if (b !== b) {
|
|
return -1;
|
|
}
|
|
if (a > b) {
|
|
return 1;
|
|
}
|
|
if (a < b) {
|
|
return -1;
|
|
}
|
|
return 0;
|
|
};
|
|
|
|
SetSort.prototype._reIndex = function() {
|
|
var newOrder, _ref,
|
|
_this = this;
|
|
newOrder = this.base.toArray().sort(function(a, b) {
|
|
var multiple, valueA, valueB;
|
|
valueA = Batman.get(a, _this.key);
|
|
if (typeof valueA === 'function') {
|
|
valueA = valueA.call(a);
|
|
}
|
|
if (valueA != null) {
|
|
valueA = valueA.valueOf();
|
|
}
|
|
valueB = Batman.get(b, _this.key);
|
|
if (typeof valueB === 'function') {
|
|
valueB = valueB.call(b);
|
|
}
|
|
if (valueB != null) {
|
|
valueB = valueB.valueOf();
|
|
}
|
|
multiple = _this.descending ? -1 : 1;
|
|
return _this.compare.call(_this, valueA, valueB) * multiple;
|
|
});
|
|
if ((_ref = this._setObserver) != null) {
|
|
_ref.startObservingItems.apply(_ref, newOrder);
|
|
}
|
|
return this.set('_storage', newOrder);
|
|
};
|
|
|
|
return SetSort;
|
|
|
|
})(Batman.SetProxy);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.AssociationSet = (function(_super) {
|
|
|
|
__extends(AssociationSet, _super);
|
|
|
|
function AssociationSet(foreignKeyValue, association) {
|
|
var base;
|
|
this.foreignKeyValue = foreignKeyValue;
|
|
this.association = association;
|
|
base = new Batman.Set;
|
|
AssociationSet.__super__.constructor.call(this, base, '_batmanID');
|
|
}
|
|
|
|
AssociationSet.prototype.loaded = false;
|
|
|
|
AssociationSet.prototype.load = function(callback) {
|
|
var _this = this;
|
|
if (this.foreignKeyValue == null) {
|
|
return callback(void 0, this);
|
|
}
|
|
return this.association.getRelatedModel().loadWithOptions(this._getLoadOptions(), function(err, records) {
|
|
if (!err) {
|
|
_this.markAsLoaded();
|
|
}
|
|
return callback(err, _this);
|
|
});
|
|
};
|
|
|
|
AssociationSet.prototype._getLoadOptions = function() {
|
|
var loadOptions;
|
|
loadOptions = {
|
|
data: {}
|
|
};
|
|
loadOptions.data[this.association.foreignKey] = this.foreignKeyValue;
|
|
if (this.association.options.url) {
|
|
loadOptions.collectionUrl = this.association.options.url;
|
|
loadOptions.urlContext = this.association.parentSetIndex().get(this.foreignKeyValue);
|
|
}
|
|
return loadOptions;
|
|
};
|
|
|
|
AssociationSet.accessor('loaded', Batman.Property.defaultAccessor);
|
|
|
|
AssociationSet.prototype.markAsLoaded = function() {
|
|
this.set('loaded', true);
|
|
return this.fire('loaded');
|
|
};
|
|
|
|
return AssociationSet;
|
|
|
|
})(Batman.SetSort);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.PolymorphicAssociationSet = (function(_super) {
|
|
|
|
__extends(PolymorphicAssociationSet, _super);
|
|
|
|
function PolymorphicAssociationSet(foreignKeyValue, foreignTypeKeyValue, association) {
|
|
this.foreignKeyValue = foreignKeyValue;
|
|
this.foreignTypeKeyValue = foreignTypeKeyValue;
|
|
this.association = association;
|
|
PolymorphicAssociationSet.__super__.constructor.call(this, this.foreignKeyValue, this.association);
|
|
}
|
|
|
|
PolymorphicAssociationSet.prototype._getLoadOptions = function() {
|
|
var loadOptions;
|
|
loadOptions = {
|
|
data: {}
|
|
};
|
|
loadOptions.data[this.association.foreignKey] = this.foreignKeyValue;
|
|
loadOptions.data[this.association.foreignTypeKey] = this.foreignTypeKeyValue;
|
|
if (this.association.options.url) {
|
|
loadOptions.collectionUrl = this.association.options.url;
|
|
loadOptions.urlContext = this.association.parentSetIndex().get(this.foreignKeyValue);
|
|
}
|
|
return loadOptions;
|
|
};
|
|
|
|
return PolymorphicAssociationSet;
|
|
|
|
})(Batman.AssociationSet);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
__slice = [].slice;
|
|
|
|
Batman.SetIndex = (function(_super) {
|
|
|
|
__extends(SetIndex, _super);
|
|
|
|
SetIndex.accessor('toArray', function() {
|
|
return this.toArray();
|
|
});
|
|
|
|
Batman.extend(SetIndex.prototype, Batman.Enumerable);
|
|
|
|
SetIndex.prototype.propertyClass = Batman.Property;
|
|
|
|
function SetIndex(base, key) {
|
|
var _this = this;
|
|
this.base = base;
|
|
this.key = key;
|
|
SetIndex.__super__.constructor.call(this);
|
|
this._storage = new Batman.Hash;
|
|
if (this.base.isEventEmitter) {
|
|
this._setObserver = new Batman.SetObserver(this.base);
|
|
this._setObserver.observedItemKeys = [this.key];
|
|
this._setObserver.observerForItemAndKey = this.observerForItemAndKey.bind(this);
|
|
this._setObserver.on('itemsWereAdded', function() {
|
|
var item, items, _i, _len, _results;
|
|
items = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
_results = [];
|
|
for (_i = 0, _len = items.length; _i < _len; _i++) {
|
|
item = items[_i];
|
|
_results.push(_this._addItem(item));
|
|
}
|
|
return _results;
|
|
});
|
|
this._setObserver.on('itemsWereRemoved', function() {
|
|
var item, items, _i, _len, _results;
|
|
items = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
_results = [];
|
|
for (_i = 0, _len = items.length; _i < _len; _i++) {
|
|
item = items[_i];
|
|
_results.push(_this._removeItem(item));
|
|
}
|
|
return _results;
|
|
});
|
|
}
|
|
this.base.forEach(this._addItem.bind(this));
|
|
this.startObserving();
|
|
}
|
|
|
|
SetIndex.accessor(function(key) {
|
|
return this._resultSetForKey(key);
|
|
});
|
|
|
|
SetIndex.prototype.startObserving = function() {
|
|
var _ref;
|
|
return (_ref = this._setObserver) != null ? _ref.startObserving() : void 0;
|
|
};
|
|
|
|
SetIndex.prototype.stopObserving = function() {
|
|
var _ref;
|
|
return (_ref = this._setObserver) != null ? _ref.stopObserving() : void 0;
|
|
};
|
|
|
|
SetIndex.prototype.observerForItemAndKey = function(item, key) {
|
|
var _this = this;
|
|
return function(newValue, oldValue) {
|
|
_this._removeItemFromKey(item, oldValue);
|
|
return _this._addItemToKey(item, newValue);
|
|
};
|
|
};
|
|
|
|
SetIndex.prototype.forEach = function(iterator, ctx) {
|
|
var _this = this;
|
|
return this._storage.forEach(function(key, set) {
|
|
if (set.get('length') > 0) {
|
|
return iterator.call(ctx, key, set, _this);
|
|
}
|
|
});
|
|
};
|
|
|
|
SetIndex.prototype.toArray = function() {
|
|
var results;
|
|
results = [];
|
|
this._storage.forEach(function(key, set) {
|
|
if (set.get('length') > 0) {
|
|
return results.push(key);
|
|
}
|
|
});
|
|
return results;
|
|
};
|
|
|
|
SetIndex.prototype._addItem = function(item) {
|
|
return this._addItemToKey(item, this._keyForItem(item));
|
|
};
|
|
|
|
SetIndex.prototype._addItemToKey = function(item, key) {
|
|
return this._resultSetForKey(key).add(item);
|
|
};
|
|
|
|
SetIndex.prototype._removeItem = function(item) {
|
|
return this._removeItemFromKey(item, this._keyForItem(item));
|
|
};
|
|
|
|
SetIndex.prototype._removeItemFromKey = function(item, key) {
|
|
return this._resultSetForKey(key).remove(item);
|
|
};
|
|
|
|
SetIndex.prototype._resultSetForKey = function(key) {
|
|
return this._storage.getOrSet(key, function() {
|
|
return new Batman.Set;
|
|
});
|
|
};
|
|
|
|
SetIndex.prototype._keyForItem = function(item) {
|
|
return Batman.Keypath.forBaseAndKey(item, this.key).getValue();
|
|
};
|
|
|
|
return SetIndex;
|
|
|
|
})(Batman.Object);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.PolymorphicAssociationSetIndex = (function(_super) {
|
|
|
|
__extends(PolymorphicAssociationSetIndex, _super);
|
|
|
|
function PolymorphicAssociationSetIndex(association, type, key) {
|
|
this.association = association;
|
|
this.type = type;
|
|
PolymorphicAssociationSetIndex.__super__.constructor.call(this, this.association.getRelatedModelForType(type).get('loaded'), key);
|
|
}
|
|
|
|
PolymorphicAssociationSetIndex.prototype._resultSetForKey = function(key) {
|
|
var _this = this;
|
|
return this._storage.getOrSet(key, function() {
|
|
return new _this.association.proxyClass(key, _this.type, _this.association);
|
|
});
|
|
};
|
|
|
|
return PolymorphicAssociationSetIndex;
|
|
|
|
})(Batman.SetIndex);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.AssociationSetIndex = (function(_super) {
|
|
|
|
__extends(AssociationSetIndex, _super);
|
|
|
|
function AssociationSetIndex(association, key) {
|
|
this.association = association;
|
|
AssociationSetIndex.__super__.constructor.call(this, this.association.getRelatedModel().get('loaded'), key);
|
|
}
|
|
|
|
AssociationSetIndex.prototype._resultSetForKey = function(key) {
|
|
return this.association.setForKey(key);
|
|
};
|
|
|
|
AssociationSetIndex.prototype.forEach = function(iterator, ctx) {
|
|
var _this = this;
|
|
return this.association.proxies.forEach(function(record, set) {
|
|
var key;
|
|
key = _this.association.indexValueForRecord(record);
|
|
if (set.get('length') > 0) {
|
|
return iterator.call(ctx, key, set, _this);
|
|
}
|
|
});
|
|
};
|
|
|
|
AssociationSetIndex.prototype.toArray = function() {
|
|
var results;
|
|
results = [];
|
|
this.forEach(function(key) {
|
|
return results.push(key);
|
|
});
|
|
return results;
|
|
};
|
|
|
|
return AssociationSetIndex;
|
|
|
|
})(Batman.SetIndex);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.UniqueSetIndex = (function(_super) {
|
|
|
|
__extends(UniqueSetIndex, _super);
|
|
|
|
function UniqueSetIndex() {
|
|
this._uniqueIndex = new Batman.Hash;
|
|
UniqueSetIndex.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
UniqueSetIndex.accessor(function(key) {
|
|
return this._uniqueIndex.get(key);
|
|
});
|
|
|
|
UniqueSetIndex.prototype._addItemToKey = function(item, key) {
|
|
this._resultSetForKey(key).add(item);
|
|
if (!this._uniqueIndex.hasKey(key)) {
|
|
return this._uniqueIndex.set(key, item);
|
|
}
|
|
};
|
|
|
|
UniqueSetIndex.prototype._removeItemFromKey = function(item, key) {
|
|
var resultSet;
|
|
resultSet = this._resultSetForKey(key);
|
|
UniqueSetIndex.__super__._removeItemFromKey.apply(this, arguments);
|
|
if (resultSet.isEmpty()) {
|
|
return this._uniqueIndex.unset(key);
|
|
} else {
|
|
return this._uniqueIndex.set(key, resultSet.toArray()[0]);
|
|
}
|
|
};
|
|
|
|
return UniqueSetIndex;
|
|
|
|
})(Batman.SetIndex);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.UniqueAssociationSetIndex = (function(_super) {
|
|
|
|
__extends(UniqueAssociationSetIndex, _super);
|
|
|
|
function UniqueAssociationSetIndex(association, key) {
|
|
this.association = association;
|
|
UniqueAssociationSetIndex.__super__.constructor.call(this, this.association.getRelatedModel().get('loaded'), key);
|
|
}
|
|
|
|
return UniqueAssociationSetIndex;
|
|
|
|
})(Batman.UniqueSetIndex);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.PolymorphicUniqueAssociationSetIndex = (function(_super) {
|
|
|
|
__extends(PolymorphicUniqueAssociationSetIndex, _super);
|
|
|
|
function PolymorphicUniqueAssociationSetIndex(association, type, key) {
|
|
this.association = association;
|
|
this.type = type;
|
|
PolymorphicUniqueAssociationSetIndex.__super__.constructor.call(this, this.association.getRelatedModelForType(type).get('loaded'), key);
|
|
}
|
|
|
|
return PolymorphicUniqueAssociationSetIndex;
|
|
|
|
})(Batman.UniqueSetIndex);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
|
__slice = [].slice;
|
|
|
|
Batman.Navigator = (function() {
|
|
|
|
Navigator.defaultClass = function() {
|
|
if (Batman.config.usePushState && Batman.PushStateNavigator.isSupported()) {
|
|
return Batman.PushStateNavigator;
|
|
} else {
|
|
return Batman.HashbangNavigator;
|
|
}
|
|
};
|
|
|
|
Navigator.forApp = function(app) {
|
|
return new (this.defaultClass())(app);
|
|
};
|
|
|
|
function Navigator(app) {
|
|
this.app = app;
|
|
this.handleCurrentLocation = __bind(this.handleCurrentLocation, this);
|
|
|
|
}
|
|
|
|
Navigator.prototype.start = function() {
|
|
var _this = this;
|
|
if (typeof window === 'undefined') {
|
|
return;
|
|
}
|
|
if (this.started) {
|
|
return;
|
|
}
|
|
this.started = true;
|
|
this.startWatching();
|
|
Batman.currentApp.prevent('ready');
|
|
return Batman.setImmediate(function() {
|
|
if (_this.started && Batman.currentApp) {
|
|
_this.handleCurrentLocation();
|
|
return Batman.currentApp.allowAndFire('ready');
|
|
}
|
|
});
|
|
};
|
|
|
|
Navigator.prototype.stop = function() {
|
|
this.stopWatching();
|
|
return this.started = false;
|
|
};
|
|
|
|
Navigator.prototype.handleLocation = function(location) {
|
|
var path;
|
|
path = this.pathFromLocation(location);
|
|
if (path === this.cachedPath) {
|
|
return;
|
|
}
|
|
return this.dispatch(path);
|
|
};
|
|
|
|
Navigator.prototype.handleCurrentLocation = function() {
|
|
return this.handleLocation(window.location);
|
|
};
|
|
|
|
Navigator.prototype.dispatch = function(params) {
|
|
this.cachedPath = this.app.get('dispatcher').dispatch(params);
|
|
if (this._lastRedirect) {
|
|
this.cachedPath = this._lastRedirect;
|
|
}
|
|
return this.cachedPath;
|
|
};
|
|
|
|
Navigator.prototype.push = function(params) {
|
|
var path, pathFromParams, _base;
|
|
pathFromParams = typeof (_base = this.app.get('dispatcher')).pathFromParams === "function" ? _base.pathFromParams(params) : void 0;
|
|
if (pathFromParams) {
|
|
this._lastRedirect = pathFromParams;
|
|
}
|
|
path = this.dispatch(params);
|
|
if (!this._lastRedirect || this._lastRedirect === path) {
|
|
this.pushState(null, '', path);
|
|
}
|
|
return path;
|
|
};
|
|
|
|
Navigator.prototype.replace = function(params) {
|
|
var path, pathFromParams, _base;
|
|
pathFromParams = typeof (_base = this.app.get('dispatcher')).pathFromParams === "function" ? _base.pathFromParams(params) : void 0;
|
|
if (pathFromParams) {
|
|
this._lastRedirect = pathFromParams;
|
|
}
|
|
path = this.dispatch(params);
|
|
if (!this._lastRedirect || this._lastRedirect === path) {
|
|
this.replaceState(null, '', path);
|
|
}
|
|
return path;
|
|
};
|
|
|
|
Navigator.prototype.redirect = Navigator.prototype.push;
|
|
|
|
Navigator.prototype.normalizePath = function() {
|
|
var i, seg, segments;
|
|
segments = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
segments = (function() {
|
|
var _i, _len, _results;
|
|
_results = [];
|
|
for (i = _i = 0, _len = segments.length; _i < _len; i = ++_i) {
|
|
seg = segments[i];
|
|
_results.push(("" + seg).replace(/^(?!\/)/, '/').replace(/\/+$/, ''));
|
|
}
|
|
return _results;
|
|
})();
|
|
return segments.join('') || '/';
|
|
};
|
|
|
|
Navigator.normalizePath = Navigator.prototype.normalizePath;
|
|
|
|
return Navigator;
|
|
|
|
})();
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.PushStateNavigator = (function(_super) {
|
|
|
|
__extends(PushStateNavigator, _super);
|
|
|
|
function PushStateNavigator() {
|
|
return PushStateNavigator.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
PushStateNavigator.isSupported = function() {
|
|
var _ref;
|
|
return (typeof window !== "undefined" && window !== null ? (_ref = window.history) != null ? _ref.pushState : void 0 : void 0) != null;
|
|
};
|
|
|
|
PushStateNavigator.prototype.startWatching = function() {
|
|
return Batman.DOM.addEventListener(window, 'popstate', this.handleCurrentLocation);
|
|
};
|
|
|
|
PushStateNavigator.prototype.stopWatching = function() {
|
|
return Batman.DOM.removeEventListener(window, 'popstate', this.handleCurrentLocation);
|
|
};
|
|
|
|
PushStateNavigator.prototype.pushState = function(stateObject, title, path) {
|
|
if (path !== this.pathFromLocation(window.location)) {
|
|
return window.history.pushState(stateObject, title, this.linkTo(path));
|
|
}
|
|
};
|
|
|
|
PushStateNavigator.prototype.replaceState = function(stateObject, title, path) {
|
|
if (path !== this.pathFromLocation(window.location)) {
|
|
return window.history.replaceState(stateObject, title, this.linkTo(path));
|
|
}
|
|
};
|
|
|
|
PushStateNavigator.prototype.linkTo = function(url) {
|
|
return this.normalizePath(Batman.config.pathPrefix, url);
|
|
};
|
|
|
|
PushStateNavigator.prototype.pathFromLocation = function(location) {
|
|
var fullPath, prefixPattern;
|
|
fullPath = "" + (location.pathname || '') + (location.search || '');
|
|
prefixPattern = new RegExp("^" + (this.normalizePath(Batman.config.pathPrefix)));
|
|
return this.normalizePath(fullPath.replace(prefixPattern, ''));
|
|
};
|
|
|
|
PushStateNavigator.prototype.handleLocation = function(location) {
|
|
var hashbangPath, path;
|
|
path = this.pathFromLocation(location);
|
|
if (path === '/' && (hashbangPath = Batman.HashbangNavigator.prototype.pathFromLocation(location)) !== '/') {
|
|
return this.replace(hashbangPath);
|
|
} else {
|
|
return PushStateNavigator.__super__.handleLocation.apply(this, arguments);
|
|
}
|
|
};
|
|
|
|
return PushStateNavigator;
|
|
|
|
})(Batman.Navigator);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.HashbangNavigator = (function(_super) {
|
|
|
|
__extends(HashbangNavigator, _super);
|
|
|
|
function HashbangNavigator() {
|
|
return HashbangNavigator.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
HashbangNavigator.prototype.HASH_PREFIX = '#!';
|
|
|
|
if ((typeof window !== "undefined" && window !== null) && 'onhashchange' in window) {
|
|
HashbangNavigator.prototype.startWatching = function() {
|
|
return Batman.DOM.addEventListener(window, 'hashchange', this.handleCurrentLocation);
|
|
};
|
|
HashbangNavigator.prototype.stopWatching = function() {
|
|
return Batman.DOM.removeEventListener(window, 'hashchange', this.handleCurrentLocation);
|
|
};
|
|
} else {
|
|
HashbangNavigator.prototype.startWatching = function() {
|
|
return this.interval = setInterval(this.handleCurrentLocation, 100);
|
|
};
|
|
HashbangNavigator.prototype.stopWatching = function() {
|
|
return this.interval = clearInterval(this.interval);
|
|
};
|
|
}
|
|
|
|
HashbangNavigator.prototype.pushState = function(stateObject, title, path) {
|
|
return window.location.hash = this.linkTo(path);
|
|
};
|
|
|
|
HashbangNavigator.prototype.replaceState = function(stateObject, title, path) {
|
|
var loc;
|
|
loc = window.location;
|
|
return loc.replace("" + loc.pathname + loc.search + (this.linkTo(path)));
|
|
};
|
|
|
|
HashbangNavigator.prototype.linkTo = function(url) {
|
|
return this.HASH_PREFIX + url;
|
|
};
|
|
|
|
HashbangNavigator.prototype.pathFromLocation = function(location) {
|
|
var hash;
|
|
hash = location.hash;
|
|
if ((hash != null ? hash.substr(0, 2) : void 0) === this.HASH_PREFIX) {
|
|
return this.normalizePath(hash.substr(2));
|
|
} else {
|
|
return '/';
|
|
}
|
|
};
|
|
|
|
HashbangNavigator.prototype.handleLocation = function(location) {
|
|
var realPath;
|
|
if (!Batman.config.usePushState) {
|
|
return HashbangNavigator.__super__.handleLocation.apply(this, arguments);
|
|
}
|
|
realPath = Batman.PushStateNavigator.prototype.pathFromLocation(location);
|
|
if (realPath === '/') {
|
|
return HashbangNavigator.__super__.handleLocation.apply(this, arguments);
|
|
} else {
|
|
return location.replace(this.normalizePath("" + Batman.config.pathPrefix + (this.linkTo(realPath))));
|
|
}
|
|
};
|
|
|
|
return HashbangNavigator;
|
|
|
|
})(Batman.Navigator);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
|
|
Batman.RouteMap = (function() {
|
|
|
|
RouteMap.prototype.memberRoute = null;
|
|
|
|
RouteMap.prototype.collectionRoute = null;
|
|
|
|
function RouteMap() {
|
|
this.childrenByOrder = [];
|
|
this.childrenByName = {};
|
|
}
|
|
|
|
RouteMap.prototype.routeForParams = function(params) {
|
|
var route, _i, _len, _ref;
|
|
_ref = this.childrenByOrder;
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
route = _ref[_i];
|
|
if (route.test(params)) {
|
|
return route;
|
|
}
|
|
}
|
|
return void 0;
|
|
};
|
|
|
|
RouteMap.prototype.addRoute = function(name, route) {
|
|
var base, names,
|
|
_this = this;
|
|
this.childrenByOrder.push(route);
|
|
if (name.length > 0 && (names = name.split('.')).length > 0) {
|
|
base = names.shift();
|
|
if (!this.childrenByName[base]) {
|
|
this.childrenByName[base] = new Batman.RouteMap;
|
|
}
|
|
this.childrenByName[base].addRoute(names.join('.'), route);
|
|
} else {
|
|
if (route.get('member')) {
|
|
Batman.developer["do"](function() {
|
|
if (_this.memberRoute) {
|
|
return Batman.developer.error("Member route with name " + name + " already exists!");
|
|
}
|
|
});
|
|
this.memberRoute = route;
|
|
} else {
|
|
Batman.developer["do"](function() {
|
|
if (_this.collectionRoute) {
|
|
return Batman.developer.error("Collection route with name " + name + " already exists!");
|
|
}
|
|
});
|
|
this.collectionRoute = route;
|
|
}
|
|
}
|
|
return true;
|
|
};
|
|
|
|
return RouteMap;
|
|
|
|
})();
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __slice = [].slice;
|
|
|
|
Batman.RouteMapBuilder = (function() {
|
|
|
|
RouteMapBuilder.BUILDER_FUNCTIONS = ['resources', 'member', 'collection', 'route', 'root'];
|
|
|
|
RouteMapBuilder.ROUTES = {
|
|
index: {
|
|
cardinality: 'collection',
|
|
path: function(resource) {
|
|
return resource;
|
|
},
|
|
name: function(resource) {
|
|
return resource;
|
|
}
|
|
},
|
|
"new": {
|
|
cardinality: 'collection',
|
|
path: function(resource) {
|
|
return "" + resource + "/new";
|
|
},
|
|
name: function(resource) {
|
|
return "" + resource + ".new";
|
|
}
|
|
},
|
|
show: {
|
|
cardinality: 'member',
|
|
path: function(resource) {
|
|
return "" + resource + "/:id";
|
|
},
|
|
name: function(resource) {
|
|
return resource;
|
|
}
|
|
},
|
|
edit: {
|
|
cardinality: 'member',
|
|
path: function(resource) {
|
|
return "" + resource + "/:id/edit";
|
|
},
|
|
name: function(resource) {
|
|
return "" + resource + ".edit";
|
|
}
|
|
},
|
|
collection: {
|
|
cardinality: 'collection',
|
|
path: function(resource, name) {
|
|
return "" + resource + "/" + name;
|
|
},
|
|
name: function(resource, name) {
|
|
return "" + resource + "." + name;
|
|
}
|
|
},
|
|
member: {
|
|
cardinality: 'member',
|
|
path: function(resource, name) {
|
|
return "" + resource + "/:id/" + name;
|
|
},
|
|
name: function(resource, name) {
|
|
return "" + resource + "." + name;
|
|
}
|
|
}
|
|
};
|
|
|
|
function RouteMapBuilder(app, routeMap, parent, baseOptions) {
|
|
this.app = app;
|
|
this.routeMap = routeMap;
|
|
this.parent = parent;
|
|
this.baseOptions = baseOptions != null ? baseOptions : {};
|
|
if (this.parent) {
|
|
this.rootPath = this.parent._nestingPath();
|
|
this.rootName = this.parent._nestingName();
|
|
} else {
|
|
this.rootPath = '';
|
|
this.rootName = '';
|
|
}
|
|
}
|
|
|
|
RouteMapBuilder.prototype.resources = function() {
|
|
var action, actions, arg, args, as, callback, childBuilder, controller, included, k, options, path, resourceName, resourceNames, resourceRoot, routeOptions, routeTemplate, v, _i, _j, _k, _len, _len1, _len2, _ref, _ref1;
|
|
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
resourceNames = (function() {
|
|
var _i, _len, _results;
|
|
_results = [];
|
|
for (_i = 0, _len = args.length; _i < _len; _i++) {
|
|
arg = args[_i];
|
|
if (typeof arg === 'string') {
|
|
_results.push(arg);
|
|
}
|
|
}
|
|
return _results;
|
|
})();
|
|
if (typeof args[args.length - 1] === 'function') {
|
|
callback = args.pop();
|
|
}
|
|
if (typeof args[args.length - 1] === 'object') {
|
|
options = args.pop();
|
|
} else {
|
|
options = {};
|
|
}
|
|
actions = {
|
|
index: true,
|
|
"new": true,
|
|
show: true,
|
|
edit: true
|
|
};
|
|
if (options.except) {
|
|
_ref = options.except;
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
k = _ref[_i];
|
|
actions[k] = false;
|
|
}
|
|
delete options.except;
|
|
} else if (options.only) {
|
|
for (k in actions) {
|
|
v = actions[k];
|
|
actions[k] = false;
|
|
}
|
|
_ref1 = options.only;
|
|
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
|
k = _ref1[_j];
|
|
actions[k] = true;
|
|
}
|
|
delete options.only;
|
|
}
|
|
for (_k = 0, _len2 = resourceNames.length; _k < _len2; _k++) {
|
|
resourceName = resourceNames[_k];
|
|
resourceRoot = Batman.helpers.pluralize(resourceName);
|
|
controller = Batman.helpers.camelize(resourceRoot, true);
|
|
childBuilder = this._childBuilder({
|
|
controller: controller
|
|
});
|
|
if (callback != null) {
|
|
callback.call(childBuilder);
|
|
}
|
|
for (action in actions) {
|
|
included = actions[action];
|
|
if (!(included)) {
|
|
continue;
|
|
}
|
|
routeTemplate = this.constructor.ROUTES[action];
|
|
as = routeTemplate.name(resourceRoot);
|
|
path = routeTemplate.path(resourceRoot);
|
|
routeOptions = Batman.extend({
|
|
controller: controller,
|
|
action: action,
|
|
path: path,
|
|
as: as
|
|
}, options);
|
|
childBuilder[routeTemplate.cardinality](action, routeOptions);
|
|
}
|
|
}
|
|
return true;
|
|
};
|
|
|
|
RouteMapBuilder.prototype.member = function() {
|
|
return this._addRoutesWithCardinality.apply(this, ['member'].concat(__slice.call(arguments)));
|
|
};
|
|
|
|
RouteMapBuilder.prototype.collection = function() {
|
|
return this._addRoutesWithCardinality.apply(this, ['collection'].concat(__slice.call(arguments)));
|
|
};
|
|
|
|
RouteMapBuilder.prototype.root = function(signature, options) {
|
|
return this.route('/', signature, options);
|
|
};
|
|
|
|
RouteMapBuilder.prototype.route = function(path, signature, options, callback) {
|
|
if (!callback) {
|
|
if (typeof options === 'function') {
|
|
callback = options;
|
|
options = void 0;
|
|
} else if (typeof signature === 'function') {
|
|
callback = signature;
|
|
signature = void 0;
|
|
}
|
|
}
|
|
if (!options) {
|
|
if (typeof signature === 'string') {
|
|
options = {
|
|
signature: signature
|
|
};
|
|
} else {
|
|
options = signature;
|
|
}
|
|
options || (options = {});
|
|
} else {
|
|
if (signature) {
|
|
options.signature = signature;
|
|
}
|
|
}
|
|
if (callback) {
|
|
options.callback = callback;
|
|
}
|
|
options.as || (options.as = this._nameFromPath(path));
|
|
options.path = path;
|
|
return this._addRoute(options);
|
|
};
|
|
|
|
RouteMapBuilder.prototype._addRoutesWithCardinality = function() {
|
|
var cardinality, name, names, options, resourceRoot, routeOptions, routeTemplate, _i, _j, _len;
|
|
cardinality = arguments[0], names = 3 <= arguments.length ? __slice.call(arguments, 1, _i = arguments.length - 1) : (_i = 1, []), options = arguments[_i++];
|
|
if (typeof options === 'string') {
|
|
names.push(options);
|
|
options = {};
|
|
}
|
|
options = Batman.extend({}, this.baseOptions, options);
|
|
options[cardinality] = true;
|
|
routeTemplate = this.constructor.ROUTES[cardinality];
|
|
resourceRoot = Batman.helpers.underscore(options.controller);
|
|
for (_j = 0, _len = names.length; _j < _len; _j++) {
|
|
name = names[_j];
|
|
routeOptions = Batman.extend({
|
|
action: name
|
|
}, options);
|
|
if (routeOptions.path == null) {
|
|
routeOptions.path = routeTemplate.path(resourceRoot, name);
|
|
}
|
|
if (routeOptions.as == null) {
|
|
routeOptions.as = routeTemplate.name(resourceRoot, name);
|
|
}
|
|
this._addRoute(routeOptions);
|
|
}
|
|
return true;
|
|
};
|
|
|
|
RouteMapBuilder.prototype._addRoute = function(options) {
|
|
var klass, name, path, route;
|
|
if (options == null) {
|
|
options = {};
|
|
}
|
|
path = this.rootPath + options.path;
|
|
name = this.rootName + Batman.helpers.camelize(options.as, true);
|
|
delete options.as;
|
|
delete options.path;
|
|
klass = options.callback ? Batman.CallbackActionRoute : Batman.ControllerActionRoute;
|
|
options.app = this.app;
|
|
route = new klass(path, options);
|
|
return this.routeMap.addRoute(name, route);
|
|
};
|
|
|
|
RouteMapBuilder.prototype._nameFromPath = function(path) {
|
|
path = path.replace(Batman.Route.regexps.namedOrSplat, '').replace(/\/+/g, '.').replace(/(^\.)|(\.$)/g, '');
|
|
return path;
|
|
};
|
|
|
|
RouteMapBuilder.prototype._nestingPath = function() {
|
|
var nestingParam, nestingSegment;
|
|
if (!this.parent) {
|
|
return "";
|
|
} else {
|
|
nestingParam = ":" + Batman.helpers.singularize(this.baseOptions.controller) + "Id";
|
|
nestingSegment = Batman.helpers.underscore(this.baseOptions.controller);
|
|
return "" + (this.parent._nestingPath()) + "/" + nestingSegment + "/" + nestingParam + "/";
|
|
}
|
|
};
|
|
|
|
RouteMapBuilder.prototype._nestingName = function() {
|
|
if (!this.parent) {
|
|
return "";
|
|
} else {
|
|
return this.baseOptions.controller + ".";
|
|
}
|
|
};
|
|
|
|
RouteMapBuilder.prototype._childBuilder = function(baseOptions) {
|
|
if (baseOptions == null) {
|
|
baseOptions = {};
|
|
}
|
|
return new Batman.RouteMapBuilder(this.app, this.routeMap, this, baseOptions);
|
|
};
|
|
|
|
return RouteMapBuilder;
|
|
|
|
})();
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
__slice = [].slice;
|
|
|
|
Batman.App = (function(_super) {
|
|
var name, _fn, _i, _len, _ref,
|
|
_this = this;
|
|
|
|
__extends(App, _super);
|
|
|
|
function App() {
|
|
return App.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
App.classAccessor('currentParams', {
|
|
get: function() {
|
|
return new Batman.Hash;
|
|
},
|
|
'final': true
|
|
});
|
|
|
|
App.classAccessor('paramsManager', {
|
|
get: function() {
|
|
var nav, params;
|
|
if (!(nav = this.get('navigator'))) {
|
|
return;
|
|
}
|
|
params = this.get('currentParams');
|
|
return params.replacer = new Batman.ParamsReplacer(nav, params);
|
|
},
|
|
'final': true
|
|
});
|
|
|
|
App.classAccessor('paramsPusher', {
|
|
get: function() {
|
|
var nav, params;
|
|
if (!(nav = this.get('navigator'))) {
|
|
return;
|
|
}
|
|
params = this.get('currentParams');
|
|
return params.pusher = new Batman.ParamsPusher(nav, params);
|
|
},
|
|
'final': true
|
|
});
|
|
|
|
App.classAccessor('routes', function() {
|
|
return new Batman.NamedRouteQuery(this.get('routeMap'));
|
|
});
|
|
|
|
App.classAccessor('routeMap', function() {
|
|
return new Batman.RouteMap;
|
|
});
|
|
|
|
App.classAccessor('routeMapBuilder', function() {
|
|
return new Batman.RouteMapBuilder(this, this.get('routeMap'));
|
|
});
|
|
|
|
App.classAccessor('dispatcher', function() {
|
|
return new Batman.Dispatcher(this, this.get('routeMap'));
|
|
});
|
|
|
|
App.classAccessor('controllers', function() {
|
|
return this.get('dispatcher.controllers');
|
|
});
|
|
|
|
App.classAccessor('_renderContext', function() {
|
|
return Batman.RenderContext.base.descend(this);
|
|
});
|
|
|
|
App.requirePath = '';
|
|
|
|
Batman.developer["do"](function() {
|
|
App.require = function() {
|
|
var base, name, names, path, _i, _len,
|
|
_this = this;
|
|
path = arguments[0], names = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
|
base = this.requirePath + path;
|
|
for (_i = 0, _len = names.length; _i < _len; _i++) {
|
|
name = names[_i];
|
|
this.prevent('run');
|
|
path = base + '/' + name + '.coffee';
|
|
new Batman.Request({
|
|
url: path,
|
|
type: 'html',
|
|
success: function(response) {
|
|
CoffeeScript["eval"](response);
|
|
_this.allow('run');
|
|
if (!_this.isPrevented('run')) {
|
|
_this.fire('loaded');
|
|
}
|
|
if (_this.wantsToRun) {
|
|
return _this.run();
|
|
}
|
|
}
|
|
});
|
|
}
|
|
return this;
|
|
};
|
|
App.controller = function() {
|
|
var names;
|
|
names = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
names = names.map(function(n) {
|
|
return n + '_controller';
|
|
});
|
|
return this.require.apply(this, ['controllers'].concat(__slice.call(names)));
|
|
};
|
|
App.model = function() {
|
|
return this.require.apply(this, ['models'].concat(__slice.call(arguments)));
|
|
};
|
|
return App.view = function() {
|
|
return this.require.apply(this, ['views'].concat(__slice.call(arguments)));
|
|
};
|
|
});
|
|
|
|
App.layout = void 0;
|
|
|
|
App.shouldAllowEvent = {};
|
|
|
|
_ref = Batman.RouteMapBuilder.BUILDER_FUNCTIONS;
|
|
_fn = function(name) {
|
|
return App[name] = function() {
|
|
var _ref1;
|
|
return (_ref1 = this.get('routeMapBuilder'))[name].apply(_ref1, arguments);
|
|
};
|
|
};
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
name = _ref[_i];
|
|
_fn(name);
|
|
}
|
|
|
|
App.event('ready').oneShot = true;
|
|
|
|
App.event('run').oneShot = true;
|
|
|
|
App.run = function() {
|
|
var layout, layoutClass,
|
|
_this = this;
|
|
if (Batman.currentApp) {
|
|
if (Batman.currentApp === this) {
|
|
return;
|
|
}
|
|
Batman.currentApp.stop();
|
|
}
|
|
if (this.hasRun) {
|
|
return false;
|
|
}
|
|
if (this.isPrevented('run')) {
|
|
this.wantsToRun = true;
|
|
return false;
|
|
} else {
|
|
delete this.wantsToRun;
|
|
}
|
|
Batman.currentApp = this;
|
|
Batman.App.set('current', this);
|
|
if (this.get('dispatcher') == null) {
|
|
this.set('dispatcher', new Batman.Dispatcher(this, this.get('routeMap')));
|
|
this.set('controllers', this.get('dispatcher.controllers'));
|
|
}
|
|
if (this.get('navigator') == null) {
|
|
this.set('navigator', Batman.Navigator.forApp(this));
|
|
this.on('run', function() {
|
|
Batman.navigator = _this.get('navigator');
|
|
if (Object.keys(_this.get('dispatcher').routeMap).length > 0) {
|
|
return Batman.navigator.start();
|
|
}
|
|
});
|
|
}
|
|
this.observe('layout', function(layout) {
|
|
return layout != null ? layout.on('ready', function() {
|
|
return _this.fire('ready');
|
|
}) : void 0;
|
|
});
|
|
layout = this.get('layout');
|
|
if (layout) {
|
|
if (typeof layout === 'string') {
|
|
layoutClass = this[Batman.helpers.camelize(layout) + 'View'];
|
|
}
|
|
} else {
|
|
if (layout !== null) {
|
|
layoutClass = Batman.View;
|
|
}
|
|
}
|
|
if (layoutClass) {
|
|
layout = this.set('layout', new layoutClass({
|
|
context: this,
|
|
node: document
|
|
}));
|
|
}
|
|
this.hasRun = true;
|
|
this.fire('run');
|
|
return this;
|
|
};
|
|
|
|
App.event('ready').oneShot = true;
|
|
|
|
App.event('stop').oneShot = true;
|
|
|
|
App.stop = function() {
|
|
var _ref1;
|
|
if ((_ref1 = this.navigator) != null) {
|
|
_ref1.stop();
|
|
}
|
|
Batman.navigator = null;
|
|
this.hasRun = false;
|
|
this.fire('stop');
|
|
return this;
|
|
};
|
|
|
|
return App;
|
|
|
|
}).call(this, Batman.Object);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
|
|
Batman.Association = (function() {
|
|
|
|
Association.prototype.associationType = '';
|
|
|
|
Association.prototype.isPolymorphic = false;
|
|
|
|
Association.prototype.defaultOptions = {
|
|
saveInline: true,
|
|
autoload: true,
|
|
nestUrl: false
|
|
};
|
|
|
|
function Association(model, label, options) {
|
|
var defaultOptions, encoder, getAccessor, self;
|
|
this.model = model;
|
|
this.label = label;
|
|
if (options == null) {
|
|
options = {};
|
|
}
|
|
defaultOptions = {
|
|
namespace: Batman.currentApp,
|
|
name: Batman.helpers.camelize(Batman.helpers.singularize(this.label))
|
|
};
|
|
this.options = Batman.extend(defaultOptions, this.defaultOptions, options);
|
|
if (this.options.nestUrl) {
|
|
if (!(this.model.urlNestsUnder != null)) {
|
|
developer.error("You must persist the the model " + this.model.constructor.name + " to use the url helpers on an association");
|
|
}
|
|
this.model.urlNestsUnder(Batman.helpers.underscore(this.getRelatedModel().get('resourceName')));
|
|
}
|
|
if (this.options.extend != null) {
|
|
Batman.extend(this, this.options.extend);
|
|
}
|
|
encoder = {
|
|
encode: this.options.saveInline ? this.encoder() : false,
|
|
decode: this.decoder()
|
|
};
|
|
this.model.encode(this.label, encoder);
|
|
self = this;
|
|
getAccessor = function() {
|
|
return self.getAccessor.call(this, self, this.model, this.label);
|
|
};
|
|
this.model.accessor(this.label, {
|
|
get: getAccessor,
|
|
set: model.defaultAccessor.set,
|
|
unset: model.defaultAccessor.unset
|
|
});
|
|
}
|
|
|
|
Association.prototype.getRelatedModel = function() {
|
|
var className, relatedModel, scope;
|
|
scope = this.options.namespace || Batman.currentApp;
|
|
className = this.options.name;
|
|
relatedModel = scope != null ? scope[className] : void 0;
|
|
Batman.developer["do"](function() {
|
|
if ((Batman.currentApp != null) && !relatedModel) {
|
|
return Batman.developer.warn("Related model " + className + " hasn't loaded yet.");
|
|
}
|
|
});
|
|
return relatedModel;
|
|
};
|
|
|
|
Association.prototype.getFromAttributes = function(record) {
|
|
return record.get("attributes." + this.label);
|
|
};
|
|
|
|
Association.prototype.setIntoAttributes = function(record, value) {
|
|
return record.get('attributes').set(this.label, value);
|
|
};
|
|
|
|
Association.prototype.inverse = function() {
|
|
var inverse, relatedAssocs,
|
|
_this = this;
|
|
if (relatedAssocs = this.getRelatedModel()._batman.get('associations')) {
|
|
if (this.options.inverseOf) {
|
|
return relatedAssocs.getByLabel(this.options.inverseOf);
|
|
}
|
|
inverse = null;
|
|
relatedAssocs.forEach(function(label, assoc) {
|
|
if (assoc.getRelatedModel() === _this.model) {
|
|
return inverse = assoc;
|
|
}
|
|
});
|
|
return inverse;
|
|
}
|
|
};
|
|
|
|
Association.prototype.reset = function() {
|
|
delete this.index;
|
|
return true;
|
|
};
|
|
|
|
return Association;
|
|
|
|
})();
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.PluralAssociation = (function(_super) {
|
|
|
|
__extends(PluralAssociation, _super);
|
|
|
|
PluralAssociation.prototype.proxyClass = Batman.AssociationSet;
|
|
|
|
PluralAssociation.prototype.isSingular = false;
|
|
|
|
function PluralAssociation() {
|
|
PluralAssociation.__super__.constructor.apply(this, arguments);
|
|
this._resetSetHashes();
|
|
}
|
|
|
|
PluralAssociation.prototype.setForRecord = function(record) {
|
|
var childModelSetIndex, indexValue,
|
|
_this = this;
|
|
indexValue = this.indexValueForRecord(record);
|
|
childModelSetIndex = this.setIndex();
|
|
Batman.Property.withoutTracking(function() {
|
|
return _this._setsByRecord.getOrSet(record, function() {
|
|
var existingValueSet, newSet;
|
|
if (indexValue != null) {
|
|
existingValueSet = _this._setsByValue.get(indexValue);
|
|
if (existingValueSet != null) {
|
|
return existingValueSet;
|
|
}
|
|
}
|
|
newSet = new _this.proxyClass(indexValue, _this);
|
|
if (indexValue != null) {
|
|
_this._setsByValue.set(indexValue, newSet);
|
|
}
|
|
return newSet;
|
|
});
|
|
});
|
|
if (indexValue != null) {
|
|
return childModelSetIndex.get(indexValue);
|
|
} else {
|
|
return this._setsByRecord.get(record);
|
|
}
|
|
};
|
|
|
|
PluralAssociation.prototype.setForKey = Batman.Property.wrapTrackingPrevention(function(indexValue) {
|
|
var foundSet,
|
|
_this = this;
|
|
foundSet = void 0;
|
|
this._setsByRecord.forEach(function(record, set) {
|
|
if (foundSet != null) {
|
|
return;
|
|
}
|
|
if (_this.indexValueForRecord(record) === indexValue) {
|
|
return foundSet = set;
|
|
}
|
|
});
|
|
if (foundSet != null) {
|
|
foundSet.foreignKeyValue = indexValue;
|
|
return foundSet;
|
|
}
|
|
return this._setsByValue.getOrSet(indexValue, function() {
|
|
return new _this.proxyClass(indexValue, _this);
|
|
});
|
|
});
|
|
|
|
PluralAssociation.prototype.getAccessor = function(self, model, label) {
|
|
var relatedRecords, setInAttributes,
|
|
_this = this;
|
|
if (!self.getRelatedModel()) {
|
|
return;
|
|
}
|
|
if (setInAttributes = self.getFromAttributes(this)) {
|
|
return setInAttributes;
|
|
} else {
|
|
relatedRecords = self.setForRecord(this);
|
|
self.setIntoAttributes(this, relatedRecords);
|
|
Batman.Property.withoutTracking(function() {
|
|
if (self.options.autoload && !_this.isNew() && !relatedRecords.loaded) {
|
|
return relatedRecords.load(function(error, records) {
|
|
if (error) {
|
|
throw error;
|
|
}
|
|
});
|
|
}
|
|
});
|
|
return relatedRecords;
|
|
}
|
|
};
|
|
|
|
PluralAssociation.prototype.parentSetIndex = function() {
|
|
this.parentIndex || (this.parentIndex = this.model.get('loaded').indexedByUnique(this.primaryKey));
|
|
return this.parentIndex;
|
|
};
|
|
|
|
PluralAssociation.prototype.setIndex = function() {
|
|
this.index || (this.index = new Batman.AssociationSetIndex(this, this[this.indexRelatedModelOn]));
|
|
return this.index;
|
|
};
|
|
|
|
PluralAssociation.prototype.indexValueForRecord = function(record) {
|
|
return record.get(this.primaryKey);
|
|
};
|
|
|
|
PluralAssociation.prototype.reset = function() {
|
|
PluralAssociation.__super__.reset.apply(this, arguments);
|
|
return this._resetSetHashes();
|
|
};
|
|
|
|
PluralAssociation.prototype._resetSetHashes = function() {
|
|
this._setsByRecord = new Batman.SimpleHash;
|
|
return this._setsByValue = new Batman.SimpleHash;
|
|
};
|
|
|
|
return PluralAssociation;
|
|
|
|
})(Batman.Association);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.HasManyAssociation = (function(_super) {
|
|
|
|
__extends(HasManyAssociation, _super);
|
|
|
|
HasManyAssociation.prototype.associationType = 'hasMany';
|
|
|
|
HasManyAssociation.prototype.indexRelatedModelOn = 'foreignKey';
|
|
|
|
function HasManyAssociation(model, label, options) {
|
|
if (options != null ? options.as : void 0) {
|
|
return (function(func, args, ctor) {
|
|
ctor.prototype = func.prototype;
|
|
var child = new ctor, result = func.apply(child, args), t = typeof result;
|
|
return t == "object" || t == "function" ? result || child : child;
|
|
})(Batman.PolymorphicHasManyAssociation, arguments, function(){});
|
|
}
|
|
HasManyAssociation.__super__.constructor.apply(this, arguments);
|
|
this.primaryKey = this.options.primaryKey || "id";
|
|
this.foreignKey = this.options.foreignKey || ("" + (Batman.helpers.underscore(model.get('resourceName'))) + "_id");
|
|
}
|
|
|
|
HasManyAssociation.prototype.apply = function(baseSaveError, base) {
|
|
var relations, set,
|
|
_this = this;
|
|
if (!baseSaveError) {
|
|
if (relations = this.getFromAttributes(base)) {
|
|
relations.forEach(function(model) {
|
|
return model.set(_this.foreignKey, base.get(_this.primaryKey));
|
|
});
|
|
}
|
|
base.set(this.label, set = this.setForRecord(base));
|
|
if (base.lifecycle.get('state') === 'creating') {
|
|
return set.markAsLoaded();
|
|
}
|
|
}
|
|
};
|
|
|
|
HasManyAssociation.prototype.encoder = function() {
|
|
var association;
|
|
association = this;
|
|
return function(relationSet, _, __, record) {
|
|
var jsonArray;
|
|
if (relationSet != null) {
|
|
jsonArray = [];
|
|
relationSet.forEach(function(relation) {
|
|
var relationJSON;
|
|
relationJSON = relation.toJSON();
|
|
if (!association.inverse() || association.inverse().options.encodeForeignKey) {
|
|
relationJSON[association.foreignKey] = record.get(association.primaryKey);
|
|
}
|
|
return jsonArray.push(relationJSON);
|
|
});
|
|
}
|
|
return jsonArray;
|
|
};
|
|
};
|
|
|
|
HasManyAssociation.prototype.decoder = function() {
|
|
var association;
|
|
association = this;
|
|
return function(data, key, _, __, parentRecord) {
|
|
var existingRecord, existingRelations, jsonObject, newRelations, record, relatedModel, savedRecord, _i, _len;
|
|
if (relatedModel = association.getRelatedModel()) {
|
|
existingRelations = association.getFromAttributes(parentRecord) || association.setForRecord(parentRecord);
|
|
newRelations = existingRelations.filter(function(relation) {
|
|
return relation.isNew();
|
|
}).toArray();
|
|
for (_i = 0, _len = data.length; _i < _len; _i++) {
|
|
jsonObject = data[_i];
|
|
record = new relatedModel();
|
|
record._withoutDirtyTracking(function() {
|
|
return this.fromJSON(jsonObject);
|
|
});
|
|
existingRecord = relatedModel.get('loaded').indexedByUnique('id').get(record.get('id'));
|
|
if (existingRecord != null) {
|
|
existingRecord._withoutDirtyTracking(function() {
|
|
return this.fromJSON(jsonObject);
|
|
});
|
|
record = existingRecord;
|
|
} else {
|
|
if (newRelations.length > 0) {
|
|
savedRecord = newRelations.shift();
|
|
savedRecord._withoutDirtyTracking(function() {
|
|
return this.fromJSON(jsonObject);
|
|
});
|
|
record = savedRecord;
|
|
}
|
|
}
|
|
record = relatedModel._mapIdentity(record);
|
|
existingRelations.add(record);
|
|
if (association.options.inverseOf) {
|
|
record.set(association.options.inverseOf, parentRecord);
|
|
}
|
|
}
|
|
existingRelations.markAsLoaded();
|
|
} else {
|
|
Batman.developer.error("Can't decode model " + association.options.name + " because it hasn't been loaded yet!");
|
|
}
|
|
return existingRelations;
|
|
};
|
|
};
|
|
|
|
return HasManyAssociation;
|
|
|
|
})(Batman.PluralAssociation);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.PolymorphicHasManyAssociation = (function(_super) {
|
|
|
|
__extends(PolymorphicHasManyAssociation, _super);
|
|
|
|
PolymorphicHasManyAssociation.prototype.proxyClass = Batman.PolymorphicAssociationSet;
|
|
|
|
PolymorphicHasManyAssociation.prototype.isPolymorphic = true;
|
|
|
|
function PolymorphicHasManyAssociation(model, label, options) {
|
|
options.inverseOf = this.foreignLabel = options.as;
|
|
delete options.as;
|
|
options.foreignKey || (options.foreignKey = "" + this.foreignLabel + "_id");
|
|
PolymorphicHasManyAssociation.__super__.constructor.call(this, model, label, options);
|
|
this.foreignTypeKey = options.foreignTypeKey || ("" + this.foreignLabel + "_type");
|
|
this.model.encode(this.foreignTypeKey);
|
|
}
|
|
|
|
PolymorphicHasManyAssociation.prototype.apply = function(baseSaveError, base) {
|
|
var relations,
|
|
_this = this;
|
|
if (!baseSaveError) {
|
|
if (relations = this.getFromAttributes(base)) {
|
|
PolymorphicHasManyAssociation.__super__.apply.apply(this, arguments);
|
|
relations.forEach(function(model) {
|
|
return model.set(_this.foreignTypeKey, _this.modelType());
|
|
});
|
|
}
|
|
}
|
|
return true;
|
|
};
|
|
|
|
PolymorphicHasManyAssociation.prototype.getRelatedModelForType = function() {
|
|
return this.getRelatedModel();
|
|
};
|
|
|
|
PolymorphicHasManyAssociation.prototype.modelType = function() {
|
|
return this.model.get('resourceName');
|
|
};
|
|
|
|
PolymorphicHasManyAssociation.prototype.setIndex = function() {
|
|
if (!this.typeIndex) {
|
|
this.typeIndex = new Batman.PolymorphicAssociationSetIndex(this, this.modelType(), this[this.indexRelatedModelOn]);
|
|
}
|
|
return this.typeIndex;
|
|
};
|
|
|
|
PolymorphicHasManyAssociation.prototype.encoder = function() {
|
|
var association;
|
|
association = this;
|
|
return function(relationSet, _, __, record) {
|
|
var jsonArray;
|
|
if (relationSet != null) {
|
|
jsonArray = [];
|
|
relationSet.forEach(function(relation) {
|
|
var relationJSON;
|
|
relationJSON = relation.toJSON();
|
|
relationJSON[association.foreignKey] = record.get(association.primaryKey);
|
|
relationJSON[association.foreignTypeKey] = association.modelType();
|
|
return jsonArray.push(relationJSON);
|
|
});
|
|
}
|
|
return jsonArray;
|
|
};
|
|
};
|
|
|
|
return PolymorphicHasManyAssociation;
|
|
|
|
})(Batman.HasManyAssociation);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.SingularAssociation = (function(_super) {
|
|
|
|
__extends(SingularAssociation, _super);
|
|
|
|
function SingularAssociation() {
|
|
return SingularAssociation.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
SingularAssociation.prototype.isSingular = true;
|
|
|
|
SingularAssociation.prototype.getAccessor = function(self, model, label) {
|
|
var parent, proxy, record, recordInAttributes, _ref;
|
|
if (recordInAttributes = self.getFromAttributes(this)) {
|
|
return recordInAttributes;
|
|
}
|
|
if (self.getRelatedModel()) {
|
|
proxy = this.associationProxy(self);
|
|
record = false;
|
|
parent = this;
|
|
if ((_ref = proxy._loadSetter) == null) {
|
|
proxy._loadSetter = proxy.once('loaded', function(child) {
|
|
return parent._withoutDirtyTracking(function() {
|
|
return this.set(self.label, child);
|
|
});
|
|
});
|
|
}
|
|
if (!Batman.Property.withoutTracking(function() {
|
|
return proxy.get('loaded');
|
|
})) {
|
|
if (self.options.autoload) {
|
|
Batman.Property.withoutTracking(function() {
|
|
return proxy.load();
|
|
});
|
|
} else {
|
|
record = proxy.loadFromLocal();
|
|
}
|
|
}
|
|
return record || proxy;
|
|
}
|
|
};
|
|
|
|
SingularAssociation.prototype.setIndex = function() {
|
|
this.index || (this.index = new Batman.UniqueAssociationSetIndex(this, this[this.indexRelatedModelOn]));
|
|
return this.index;
|
|
};
|
|
|
|
return SingularAssociation;
|
|
|
|
})(Batman.Association);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.HasOneAssociation = (function(_super) {
|
|
|
|
__extends(HasOneAssociation, _super);
|
|
|
|
HasOneAssociation.prototype.associationType = 'hasOne';
|
|
|
|
HasOneAssociation.prototype.proxyClass = Batman.HasOneProxy;
|
|
|
|
HasOneAssociation.prototype.indexRelatedModelOn = 'foreignKey';
|
|
|
|
function HasOneAssociation() {
|
|
HasOneAssociation.__super__.constructor.apply(this, arguments);
|
|
this.primaryKey = this.options.primaryKey || "id";
|
|
this.foreignKey = this.options.foreignKey || ("" + (Batman.helpers.underscore(this.model.get('resourceName'))) + "_id");
|
|
}
|
|
|
|
HasOneAssociation.prototype.apply = function(baseSaveError, base) {
|
|
var relation;
|
|
if (relation = this.getFromAttributes(base)) {
|
|
return relation.set(this.foreignKey, base.get(this.primaryKey));
|
|
}
|
|
};
|
|
|
|
HasOneAssociation.prototype.encoder = function() {
|
|
var association;
|
|
association = this;
|
|
return function(val, key, object, record) {
|
|
var json;
|
|
if (!association.options.saveInline) {
|
|
return;
|
|
}
|
|
if (json = val.toJSON()) {
|
|
json[association.foreignKey] = record.get(association.primaryKey);
|
|
}
|
|
return json;
|
|
};
|
|
};
|
|
|
|
HasOneAssociation.prototype.decoder = function() {
|
|
var association;
|
|
association = this;
|
|
return function(data, _, __, ___, parentRecord) {
|
|
var record, relatedModel;
|
|
if (!data) {
|
|
return;
|
|
}
|
|
relatedModel = association.getRelatedModel();
|
|
record = relatedModel.createFromJSON(data);
|
|
if (association.options.inverseOf) {
|
|
record.set(association.options.inverseOf, parentRecord);
|
|
}
|
|
return record;
|
|
};
|
|
};
|
|
|
|
return HasOneAssociation;
|
|
|
|
})(Batman.SingularAssociation);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.BelongsToAssociation = (function(_super) {
|
|
|
|
__extends(BelongsToAssociation, _super);
|
|
|
|
BelongsToAssociation.prototype.associationType = 'belongsTo';
|
|
|
|
BelongsToAssociation.prototype.proxyClass = Batman.BelongsToProxy;
|
|
|
|
BelongsToAssociation.prototype.indexRelatedModelOn = 'primaryKey';
|
|
|
|
BelongsToAssociation.prototype.defaultOptions = {
|
|
saveInline: false,
|
|
autoload: true,
|
|
encodeForeignKey: true
|
|
};
|
|
|
|
function BelongsToAssociation(model, label, options) {
|
|
if (options != null ? options.polymorphic : void 0) {
|
|
delete options.polymorphic;
|
|
return (function(func, args, ctor) {
|
|
ctor.prototype = func.prototype;
|
|
var child = new ctor, result = func.apply(child, args), t = typeof result;
|
|
return t == "object" || t == "function" ? result || child : child;
|
|
})(Batman.PolymorphicBelongsToAssociation, arguments, function(){});
|
|
}
|
|
BelongsToAssociation.__super__.constructor.apply(this, arguments);
|
|
this.foreignKey = this.options.foreignKey || ("" + this.label + "_id");
|
|
this.primaryKey = this.options.primaryKey || "id";
|
|
if (this.options.encodeForeignKey) {
|
|
this.model.encode(this.foreignKey);
|
|
}
|
|
}
|
|
|
|
BelongsToAssociation.prototype.encoder = function() {
|
|
return function(val) {
|
|
return val.toJSON();
|
|
};
|
|
};
|
|
|
|
BelongsToAssociation.prototype.decoder = function() {
|
|
var association;
|
|
association = this;
|
|
return function(data, _, __, ___, childRecord) {
|
|
var inverse, record, relatedModel;
|
|
relatedModel = association.getRelatedModel();
|
|
record = relatedModel.createFromJSON(data);
|
|
if (association.options.inverseOf) {
|
|
if (inverse = association.inverse()) {
|
|
if (inverse instanceof Batman.HasManyAssociation) {
|
|
childRecord.set(association.foreignKey, record.get(association.primaryKey));
|
|
} else {
|
|
record.set(inverse.label, childRecord);
|
|
}
|
|
}
|
|
}
|
|
childRecord.set(association.label, record);
|
|
return record;
|
|
};
|
|
};
|
|
|
|
BelongsToAssociation.prototype.apply = function(base) {
|
|
var foreignValue, model;
|
|
if (model = base.get(this.label)) {
|
|
foreignValue = model.get(this.primaryKey);
|
|
if (foreignValue !== void 0) {
|
|
return base.set(this.foreignKey, foreignValue);
|
|
}
|
|
}
|
|
};
|
|
|
|
return BelongsToAssociation;
|
|
|
|
})(Batman.SingularAssociation);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.PolymorphicBelongsToAssociation = (function(_super) {
|
|
|
|
__extends(PolymorphicBelongsToAssociation, _super);
|
|
|
|
PolymorphicBelongsToAssociation.prototype.isPolymorphic = true;
|
|
|
|
PolymorphicBelongsToAssociation.prototype.proxyClass = Batman.PolymorphicBelongsToProxy;
|
|
|
|
PolymorphicBelongsToAssociation.prototype.defaultOptions = Batman.mixin({}, Batman.BelongsToAssociation.prototype.defaultOptions, {
|
|
encodeForeignTypeKey: true
|
|
});
|
|
|
|
function PolymorphicBelongsToAssociation() {
|
|
PolymorphicBelongsToAssociation.__super__.constructor.apply(this, arguments);
|
|
this.foreignTypeKey = this.options.foreignTypeKey || ("" + this.label + "_type");
|
|
if (this.options.encodeForeignTypeKey) {
|
|
this.model.encode(this.foreignTypeKey);
|
|
}
|
|
this.typeIndicies = {};
|
|
}
|
|
|
|
PolymorphicBelongsToAssociation.prototype.getRelatedModel = false;
|
|
|
|
PolymorphicBelongsToAssociation.prototype.setIndex = false;
|
|
|
|
PolymorphicBelongsToAssociation.prototype.inverse = false;
|
|
|
|
PolymorphicBelongsToAssociation.prototype.apply = function(base) {
|
|
var foreignTypeValue, instanceOrProxy, model;
|
|
PolymorphicBelongsToAssociation.__super__.apply.apply(this, arguments);
|
|
if (instanceOrProxy = base.get(this.label)) {
|
|
if (instanceOrProxy instanceof Batman.AssociationProxy) {
|
|
model = instanceOrProxy.association.model;
|
|
} else {
|
|
model = instanceOrProxy.constructor;
|
|
}
|
|
foreignTypeValue = model.get('resourceName');
|
|
return base.set(this.foreignTypeKey, foreignTypeValue);
|
|
}
|
|
};
|
|
|
|
PolymorphicBelongsToAssociation.prototype.getAccessor = function(self, model, label) {
|
|
var proxy, recordInAttributes;
|
|
if (recordInAttributes = self.getFromAttributes(this)) {
|
|
return recordInAttributes;
|
|
}
|
|
if (self.getRelatedModelForType(this.get(self.foreignTypeKey))) {
|
|
proxy = this.associationProxy(self);
|
|
Batman.Property.withoutTracking(function() {
|
|
if (!proxy.get('loaded') && self.options.autoload) {
|
|
return proxy.load();
|
|
}
|
|
});
|
|
return proxy;
|
|
}
|
|
};
|
|
|
|
PolymorphicBelongsToAssociation.prototype.url = function(recordOptions) {
|
|
var ending, helper, id, inverse, root, type, _ref, _ref1;
|
|
type = (_ref = recordOptions.data) != null ? _ref[this.foreignTypeKey] : void 0;
|
|
if (type && (inverse = this.inverseForType(type))) {
|
|
root = Batman.helpers.pluralize(type).toLowerCase();
|
|
id = (_ref1 = recordOptions.data) != null ? _ref1[this.foreignKey] : void 0;
|
|
helper = inverse.isSingular ? "singularize" : "pluralize";
|
|
ending = Batman.helpers[helper](inverse.label);
|
|
return "/" + root + "/" + id + "/" + ending;
|
|
}
|
|
};
|
|
|
|
PolymorphicBelongsToAssociation.prototype.getRelatedModelForType = function(type) {
|
|
var relatedModel, scope;
|
|
scope = this.options.namespace || Batman.currentApp;
|
|
if (type) {
|
|
relatedModel = scope != null ? scope[type] : void 0;
|
|
relatedModel || (relatedModel = scope != null ? scope[Batman.helpers.camelize(type)] : void 0);
|
|
}
|
|
Batman.developer["do"](function() {
|
|
if ((Batman.currentApp != null) && !relatedModel) {
|
|
return Batman.developer.warn("Related model " + type + " for polymorphic association not found.");
|
|
}
|
|
});
|
|
return relatedModel;
|
|
};
|
|
|
|
PolymorphicBelongsToAssociation.prototype.setIndexForType = function(type) {
|
|
var _base;
|
|
(_base = this.typeIndicies)[type] || (_base[type] = new Batman.PolymorphicUniqueAssociationSetIndex(this, type, this.primaryKey));
|
|
return this.typeIndicies[type];
|
|
};
|
|
|
|
PolymorphicBelongsToAssociation.prototype.inverseForType = function(type) {
|
|
var inverse, relatedAssocs, _ref,
|
|
_this = this;
|
|
if (relatedAssocs = (_ref = this.getRelatedModelForType(type)) != null ? _ref._batman.get('associations') : void 0) {
|
|
if (this.options.inverseOf) {
|
|
return relatedAssocs.getByLabel(this.options.inverseOf);
|
|
}
|
|
inverse = null;
|
|
relatedAssocs.forEach(function(label, assoc) {
|
|
if (assoc.getRelatedModel() === _this.model) {
|
|
return inverse = assoc;
|
|
}
|
|
});
|
|
return inverse;
|
|
}
|
|
};
|
|
|
|
PolymorphicBelongsToAssociation.prototype.decoder = function() {
|
|
var association;
|
|
association = this;
|
|
return function(data, key, response, ___, childRecord) {
|
|
var foreignTypeValue, inverse, record, relatedModel;
|
|
foreignTypeValue = response[association.foreignTypeKey] || childRecord.get(association.foreignTypeKey);
|
|
relatedModel = association.getRelatedModelForType(foreignTypeValue);
|
|
record = relatedModel.createFromJSON(data);
|
|
if (association.options.inverseOf) {
|
|
if (inverse = association.inverseForType(foreignTypeValue)) {
|
|
if (inverse instanceof Batman.PolymorphicHasManyAssociation) {
|
|
childRecord.set(association.foreignKey, record.get(association.primaryKey));
|
|
childRecord.set(association.foreignTypeKey, foreignTypeValue);
|
|
} else {
|
|
record.set(inverse.label, childRecord);
|
|
}
|
|
}
|
|
}
|
|
childRecord.set(association.label, record);
|
|
return record;
|
|
};
|
|
};
|
|
|
|
return PolymorphicBelongsToAssociation;
|
|
|
|
})(Batman.BelongsToAssociation);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
__slice = [].slice;
|
|
|
|
Batman.Validator = (function(_super) {
|
|
|
|
__extends(Validator, _super);
|
|
|
|
Validator.triggers = function() {
|
|
var triggers;
|
|
triggers = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
if (this._triggers != null) {
|
|
return this._triggers.concat(triggers);
|
|
} else {
|
|
return this._triggers = triggers;
|
|
}
|
|
};
|
|
|
|
Validator.options = function() {
|
|
var options;
|
|
options = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
if (this._options != null) {
|
|
return this._options.concat(options);
|
|
} else {
|
|
return this._options = options;
|
|
}
|
|
};
|
|
|
|
Validator.matches = function(options) {
|
|
var key, results, shouldReturn, value, _ref, _ref1;
|
|
results = {};
|
|
shouldReturn = false;
|
|
for (key in options) {
|
|
value = options[key];
|
|
if (~((_ref = this._options) != null ? _ref.indexOf(key) : void 0)) {
|
|
results[key] = value;
|
|
}
|
|
if (~((_ref1 = this._triggers) != null ? _ref1.indexOf(key) : void 0)) {
|
|
results[key] = value;
|
|
shouldReturn = true;
|
|
}
|
|
}
|
|
if (shouldReturn) {
|
|
return results;
|
|
}
|
|
};
|
|
|
|
function Validator() {
|
|
var mixins, options;
|
|
options = arguments[0], mixins = 2 <= arguments.length ? __slice.call(arguments, 1) : [];
|
|
this.options = options;
|
|
Validator.__super__.constructor.apply(this, mixins);
|
|
}
|
|
|
|
Validator.prototype.validate = function(record) {
|
|
return Batman.developer.error("You must override validate in Batman.Validator subclasses.");
|
|
};
|
|
|
|
Validator.prototype.format = function(key, messageKey, interpolations) {
|
|
return Batman.t("errors.messages." + messageKey, interpolations);
|
|
};
|
|
|
|
Validator.prototype.handleBlank = function(value) {
|
|
if (this.options.allowBlank && !Batman.PresenceValidator.prototype.isPresent(value)) {
|
|
return true;
|
|
}
|
|
};
|
|
|
|
return Validator;
|
|
|
|
})(Batman.Object);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
|
|
Batman.Validators = [];
|
|
|
|
Batman.extend(Batman.translate.messages, {
|
|
errors: {
|
|
format: "%{attribute} %{message}",
|
|
messages: {
|
|
too_short: "must be at least %{count} characters",
|
|
too_long: "must be less than %{count} characters",
|
|
wrong_length: "must be %{count} characters",
|
|
blank: "can't be blank",
|
|
not_numeric: "must be a number",
|
|
greater_than: "must be greater than %{count}",
|
|
greater_than_or_equal_to: "must be greater than or equal to %{count}",
|
|
equal_to: "must be equal to %{count}",
|
|
less_than: "must be less than %{count}",
|
|
less_than_or_equal_to: "must be less than or equal to %{count}",
|
|
not_matching: "is not valid",
|
|
invalid_association: "is not valid"
|
|
}
|
|
}
|
|
});
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.RegExpValidator = (function(_super) {
|
|
|
|
__extends(RegExpValidator, _super);
|
|
|
|
RegExpValidator.triggers('regexp', 'pattern');
|
|
|
|
RegExpValidator.options('allowBlank');
|
|
|
|
function RegExpValidator(options) {
|
|
var _ref;
|
|
this.regexp = (_ref = options.regexp) != null ? _ref : options.pattern;
|
|
RegExpValidator.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
RegExpValidator.prototype.validateEach = function(errors, record, key, callback) {
|
|
var value;
|
|
value = record.get(key);
|
|
if (this.handleBlank(value)) {
|
|
return callback();
|
|
}
|
|
if (!(value != null) || value === '' || !this.regexp.test(value)) {
|
|
errors.add(key, this.format(key, 'not_matching'));
|
|
}
|
|
return callback();
|
|
};
|
|
|
|
return RegExpValidator;
|
|
|
|
})(Batman.Validator);
|
|
|
|
Batman.Validators.push(Batman.RegExpValidator);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.PresenceValidator = (function(_super) {
|
|
|
|
__extends(PresenceValidator, _super);
|
|
|
|
function PresenceValidator() {
|
|
return PresenceValidator.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
PresenceValidator.triggers('presence');
|
|
|
|
PresenceValidator.prototype.validateEach = function(errors, record, key, callback) {
|
|
var value;
|
|
value = record.get(key);
|
|
if (!this.isPresent(value)) {
|
|
errors.add(key, this.format(key, 'blank'));
|
|
}
|
|
return callback();
|
|
};
|
|
|
|
PresenceValidator.prototype.isPresent = function(value) {
|
|
return (value != null) && value !== '';
|
|
};
|
|
|
|
return PresenceValidator;
|
|
|
|
})(Batman.Validator);
|
|
|
|
Batman.Validators.push(Batman.PresenceValidator);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.NumericValidator = (function(_super) {
|
|
|
|
__extends(NumericValidator, _super);
|
|
|
|
function NumericValidator() {
|
|
return NumericValidator.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
NumericValidator.triggers('numeric', 'greaterThan', 'greaterThanOrEqualTo', 'equalTo', 'lessThan', 'lessThanOrEqualTo');
|
|
|
|
NumericValidator.options('allowBlank');
|
|
|
|
NumericValidator.prototype.validateEach = function(errors, record, key, callback) {
|
|
var options, value;
|
|
options = this.options;
|
|
value = record.get(key);
|
|
if (this.handleBlank(value)) {
|
|
return callback();
|
|
}
|
|
if (!(value != null) || !(this.isNumeric(value) || this.canCoerceToNumeric(value))) {
|
|
errors.add(key, this.format(key, 'not_numeric'));
|
|
} else {
|
|
if (options.greaterThan && value <= options.greaterThan) {
|
|
errors.add(key, this.format(key, 'greater_than', {
|
|
count: options.greaterThan
|
|
}));
|
|
}
|
|
if (options.greaterThanOrEqualTo && value < options.greaterThanOrEqualTo) {
|
|
errors.add(key, this.format(key, 'greater_than_or_equal_to', {
|
|
count: options.greaterThanOrEqualTo
|
|
}));
|
|
}
|
|
if (options.equalTo && value !== options.equalTo) {
|
|
errors.add(key, this.format(key, 'equal_to', {
|
|
count: options.equalTo
|
|
}));
|
|
}
|
|
if (options.lessThan && value >= options.lessThan) {
|
|
errors.add(key, this.format(key, 'less_than', {
|
|
count: options.lessThan
|
|
}));
|
|
}
|
|
if (options.lessThanOrEqualTo && value > options.lessThanOrEqualTo) {
|
|
errors.add(key, this.format(key, 'less_than_or_equal_to', {
|
|
count: options.lessThanOrEqualTo
|
|
}));
|
|
}
|
|
}
|
|
return callback();
|
|
};
|
|
|
|
NumericValidator.prototype.isNumeric = function(value) {
|
|
return !isNaN(parseFloat(value)) && isFinite(value);
|
|
};
|
|
|
|
NumericValidator.prototype.canCoerceToNumeric = function(value) {
|
|
return (value - 0) == value && value.length > 0;
|
|
};
|
|
|
|
return NumericValidator;
|
|
|
|
})(Batman.Validator);
|
|
|
|
Batman.Validators.push(Batman.NumericValidator);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.LengthValidator = (function(_super) {
|
|
|
|
__extends(LengthValidator, _super);
|
|
|
|
LengthValidator.triggers('minLength', 'maxLength', 'length', 'lengthWithin', 'lengthIn');
|
|
|
|
LengthValidator.options('allowBlank');
|
|
|
|
function LengthValidator(options) {
|
|
var range;
|
|
if (range = options.lengthIn || options.lengthWithin) {
|
|
options.minLength = range[0];
|
|
options.maxLength = range[1] || -1;
|
|
delete options.lengthWithin;
|
|
delete options.lengthIn;
|
|
}
|
|
LengthValidator.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
LengthValidator.prototype.validateEach = function(errors, record, key, callback) {
|
|
var options, value;
|
|
options = this.options;
|
|
value = record.get(key);
|
|
if (value !== '' && this.handleBlank(value)) {
|
|
return callback();
|
|
}
|
|
if (value == null) {
|
|
value = [];
|
|
}
|
|
if (options.minLength && value.length < options.minLength) {
|
|
errors.add(key, this.format(key, 'too_short', {
|
|
count: options.minLength
|
|
}));
|
|
}
|
|
if (options.maxLength && value.length > options.maxLength) {
|
|
errors.add(key, this.format(key, 'too_long', {
|
|
count: options.maxLength
|
|
}));
|
|
}
|
|
if (options.length && value.length !== options.length) {
|
|
errors.add(key, this.format(key, 'wrong_length', {
|
|
count: options.length
|
|
}));
|
|
}
|
|
return callback();
|
|
};
|
|
|
|
return LengthValidator;
|
|
|
|
})(Batman.Validator);
|
|
|
|
Batman.Validators.push(Batman.LengthValidator);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.AssociatedValidator = (function(_super) {
|
|
|
|
__extends(AssociatedValidator, _super);
|
|
|
|
function AssociatedValidator() {
|
|
return AssociatedValidator.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
AssociatedValidator.triggers('associated');
|
|
|
|
AssociatedValidator.prototype.validateEach = function(errors, record, key, callback) {
|
|
var childFinished, count, value,
|
|
_this = this;
|
|
value = record.get(key);
|
|
if (value != null) {
|
|
if (value instanceof Batman.AssociationProxy) {
|
|
value = typeof value.get === "function" ? value.get('target') : void 0;
|
|
}
|
|
count = 1;
|
|
childFinished = function(err, childErrors) {
|
|
if (childErrors.length > 0) {
|
|
errors.add(key, _this.format(key, 'invalid_association'));
|
|
}
|
|
if (--count === 0) {
|
|
return callback();
|
|
}
|
|
};
|
|
if ((value != null ? value.forEach : void 0) != null) {
|
|
value.forEach(function(record) {
|
|
count += 1;
|
|
return record.validate(childFinished);
|
|
});
|
|
} else if ((value != null ? value.validate : void 0) != null) {
|
|
count += 1;
|
|
value.validate(childFinished);
|
|
}
|
|
return childFinished(null, []);
|
|
} else {
|
|
return callback();
|
|
}
|
|
};
|
|
|
|
return AssociatedValidator;
|
|
|
|
})(Batman.Validator);
|
|
|
|
Batman.Validators.push(Batman.AssociatedValidator);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.ControllerActionFrame = (function(_super) {
|
|
|
|
__extends(ControllerActionFrame, _super);
|
|
|
|
ControllerActionFrame.prototype.operationOccurred = false;
|
|
|
|
ControllerActionFrame.prototype.remainingOperations = 0;
|
|
|
|
ControllerActionFrame.prototype.event('complete').oneShot = true;
|
|
|
|
function ControllerActionFrame(options, onComplete) {
|
|
ControllerActionFrame.__super__.constructor.call(this, options);
|
|
this.on('complete', onComplete);
|
|
}
|
|
|
|
ControllerActionFrame.prototype.startOperation = function(options) {
|
|
if (options == null) {
|
|
options = {};
|
|
}
|
|
if (!options.internal) {
|
|
this.operationOccurred = true;
|
|
}
|
|
this._changeOperationsCounter(1);
|
|
return true;
|
|
};
|
|
|
|
ControllerActionFrame.prototype.finishOperation = function() {
|
|
this._changeOperationsCounter(-1);
|
|
return true;
|
|
};
|
|
|
|
ControllerActionFrame.prototype.startAndFinishOperation = function(options) {
|
|
this.startOperation(options);
|
|
this.finishOperation(options);
|
|
return true;
|
|
};
|
|
|
|
ControllerActionFrame.prototype._changeOperationsCounter = function(delta) {
|
|
var _ref;
|
|
this.remainingOperations += delta;
|
|
if (this.remainingOperations === 0) {
|
|
this.fire('complete');
|
|
}
|
|
if ((_ref = this.parentFrame) != null) {
|
|
_ref._changeOperationsCounter(delta);
|
|
}
|
|
};
|
|
|
|
return ControllerActionFrame;
|
|
|
|
})(Batman.Object);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.DOM.InsertionBinding = (function(_super) {
|
|
|
|
__extends(InsertionBinding, _super);
|
|
|
|
InsertionBinding.prototype.isTwoWay = false;
|
|
|
|
InsertionBinding.prototype.bindImmediately = false;
|
|
|
|
function InsertionBinding(node, className, key, context, parentRenderer, invert) {
|
|
var result,
|
|
_this = this;
|
|
this.invert = invert != null ? invert : false;
|
|
this.placeholderNode = document.createComment("detached node " + (this.get('_batmanID')));
|
|
result = InsertionBinding.__super__.constructor.apply(this, arguments);
|
|
Batman.DOM.onParseExit(this.node, function() {
|
|
_this.bind();
|
|
if (_this.placeholderNode != null) {
|
|
return Batman.DOM.trackBinding(_this, _this.placeholderNode);
|
|
}
|
|
});
|
|
result;
|
|
|
|
}
|
|
|
|
InsertionBinding.prototype.dataChange = function(value) {
|
|
var parentNode;
|
|
parentNode = this.placeholderNode.parentNode || this.node.parentNode;
|
|
if (!!value === !this.invert) {
|
|
if (!(this.node.parentNode != null)) {
|
|
Batman.DOM.insertBefore(parentNode, this.node, this.placeholderNode);
|
|
return parentNode.removeChild(this.placeholderNode);
|
|
}
|
|
} else {
|
|
if (this.node.parentNode != null) {
|
|
parentNode.insertBefore(this.placeholderNode, this.node);
|
|
return Batman.DOM.removeNode(this.node);
|
|
}
|
|
}
|
|
};
|
|
|
|
InsertionBinding.prototype.die = function() {
|
|
if (this.dead) {
|
|
return;
|
|
}
|
|
InsertionBinding.__super__.die.apply(this, arguments);
|
|
if (!!this.get('filteredValue') === !this.invert) {
|
|
return Batman.DOM.destroyNode(this.placeholderNode);
|
|
} else {
|
|
return Batman.DOM.destroyNode(this.node);
|
|
}
|
|
};
|
|
|
|
return InsertionBinding;
|
|
|
|
})(Batman.DOM.AbstractBinding);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var isEmptyDataObject;
|
|
|
|
isEmptyDataObject = function(obj) {
|
|
var name;
|
|
for (name in obj) {
|
|
return false;
|
|
}
|
|
return true;
|
|
};
|
|
|
|
Batman.extend(Batman, {
|
|
cache: {},
|
|
uuid: 0,
|
|
expando: "batman" + Math.random().toString().replace(/\D/g, ''),
|
|
canDeleteExpando: (function() {
|
|
var div;
|
|
try {
|
|
div = document.createElement('div');
|
|
return delete div.test;
|
|
} catch (e) {
|
|
return Batman.canDeleteExpando = false;
|
|
}
|
|
})(),
|
|
noData: {
|
|
"embed": true,
|
|
"object": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",
|
|
"applet": true
|
|
},
|
|
hasData: function(elem) {
|
|
elem = (elem.nodeType ? Batman.cache[elem[Batman.expando]] : elem[Batman.expando]);
|
|
return !!elem && !isEmptyDataObject(elem);
|
|
},
|
|
data: function(elem, name, data, pvt) {
|
|
var cache, getByName, id, internalKey, ret, thisCache;
|
|
if (!Batman.acceptData(elem)) {
|
|
return;
|
|
}
|
|
internalKey = Batman.expando;
|
|
getByName = typeof name === "string";
|
|
cache = Batman.cache;
|
|
id = elem[Batman.expando];
|
|
if ((!id || (pvt && id && (cache[id] && !cache[id][internalKey]))) && getByName && data === void 0) {
|
|
return;
|
|
}
|
|
if (!id) {
|
|
if (elem.nodeType !== 3) {
|
|
elem[Batman.expando] = id = ++Batman.uuid;
|
|
} else {
|
|
id = Batman.expando;
|
|
}
|
|
}
|
|
if (!cache[id]) {
|
|
cache[id] = {};
|
|
}
|
|
if (typeof name === "object" || typeof name === "function") {
|
|
if (pvt) {
|
|
cache[id][internalKey] = Batman.extend(cache[id][internalKey], name);
|
|
} else {
|
|
cache[id] = Batman.extend(cache[id], name);
|
|
}
|
|
}
|
|
thisCache = cache[id];
|
|
if (pvt) {
|
|
thisCache[internalKey] || (thisCache[internalKey] = {});
|
|
thisCache = thisCache[internalKey];
|
|
}
|
|
if (data !== void 0) {
|
|
thisCache[name] = data;
|
|
}
|
|
if (getByName) {
|
|
ret = thisCache[name];
|
|
} else {
|
|
ret = thisCache;
|
|
}
|
|
return ret;
|
|
},
|
|
removeData: function(elem, name, pvt) {
|
|
var cache, id, internalCache, internalKey, isNode, thisCache;
|
|
if (!Batman.acceptData(elem)) {
|
|
return;
|
|
}
|
|
internalKey = Batman.expando;
|
|
isNode = elem.nodeType;
|
|
cache = Batman.cache;
|
|
id = elem[Batman.expando];
|
|
if (!cache[id]) {
|
|
return;
|
|
}
|
|
if (name) {
|
|
thisCache = pvt ? cache[id][internalKey] : cache[id];
|
|
if (thisCache) {
|
|
delete thisCache[name];
|
|
if (!isEmptyDataObject(thisCache)) {
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
if (pvt) {
|
|
delete cache[id][internalKey];
|
|
if (!isEmptyDataObject(cache[id])) {
|
|
return;
|
|
}
|
|
}
|
|
internalCache = cache[id][internalKey];
|
|
if (Batman.canDeleteExpando || !cache.setInterval) {
|
|
delete cache[id];
|
|
} else {
|
|
cache[id] = null;
|
|
}
|
|
if (internalCache) {
|
|
cache[id] = {};
|
|
return cache[id][internalKey] = internalCache;
|
|
} else {
|
|
if (Batman.canDeleteExpando) {
|
|
return delete elem[Batman.expando];
|
|
} else if (elem.removeAttribute) {
|
|
return elem.removeAttribute(Batman.expando);
|
|
} else {
|
|
return elem[Batman.expando] = null;
|
|
}
|
|
}
|
|
},
|
|
_data: function(elem, name, data) {
|
|
return Batman.data(elem, name, data, true);
|
|
},
|
|
acceptData: function(elem) {
|
|
var match;
|
|
if (elem.nodeName) {
|
|
match = Batman.noData[elem.nodeName.toLowerCase()];
|
|
if (match) {
|
|
return !(match === true || elem.getAttribute("classid") !== match);
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
});
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var buntUndefined, defaultAndOr,
|
|
__slice = [].slice;
|
|
|
|
buntUndefined = function(f) {
|
|
return function(value) {
|
|
if (value == null) {
|
|
return void 0;
|
|
} else {
|
|
return f.apply(this, arguments);
|
|
}
|
|
};
|
|
};
|
|
|
|
defaultAndOr = function(lhs, rhs) {
|
|
return lhs || rhs;
|
|
};
|
|
|
|
Batman.Filters = {
|
|
raw: buntUndefined(function(value, binding) {
|
|
binding.escapeValue = false;
|
|
return value;
|
|
}),
|
|
get: buntUndefined(function(value, key) {
|
|
if (value.get != null) {
|
|
return value.get(key);
|
|
} else {
|
|
return value[key];
|
|
}
|
|
}),
|
|
equals: buntUndefined(function(lhs, rhs, binding) {
|
|
return lhs === rhs;
|
|
}),
|
|
and: function(lhs, rhs) {
|
|
return lhs && rhs;
|
|
},
|
|
or: function(lhs, rhs, binding) {
|
|
return lhs || rhs;
|
|
},
|
|
not: function(value, binding) {
|
|
return !value;
|
|
},
|
|
trim: buntUndefined(function(value, binding) {
|
|
return value.trim();
|
|
}),
|
|
matches: buntUndefined(function(value, searchFor) {
|
|
return value.indexOf(searchFor) !== -1;
|
|
}),
|
|
truncate: buntUndefined(function(value, length, end, binding) {
|
|
if (end == null) {
|
|
end = "...";
|
|
}
|
|
if (!binding) {
|
|
binding = end;
|
|
end = "...";
|
|
}
|
|
if (value.length > length) {
|
|
value = value.substr(0, length - end.length) + end;
|
|
}
|
|
return value;
|
|
}),
|
|
"default": function(value, defaultValue, binding) {
|
|
if ((value != null) && value !== '') {
|
|
return value;
|
|
} else {
|
|
return defaultValue;
|
|
}
|
|
},
|
|
prepend: function(value, string, binding) {
|
|
return (string != null ? string : '') + (value != null ? value : '');
|
|
},
|
|
append: function(value, string, binding) {
|
|
return (value != null ? value : '') + (string != null ? string : '');
|
|
},
|
|
replace: buntUndefined(function(value, searchFor, replaceWith, flags, binding) {
|
|
if (!binding) {
|
|
binding = flags;
|
|
flags = void 0;
|
|
}
|
|
if (flags === void 0) {
|
|
return value.replace(searchFor, replaceWith);
|
|
} else {
|
|
return value.replace(searchFor, replaceWith, flags);
|
|
}
|
|
}),
|
|
downcase: buntUndefined(function(value) {
|
|
return value.toLowerCase();
|
|
}),
|
|
upcase: buntUndefined(function(value) {
|
|
return value.toUpperCase();
|
|
}),
|
|
pluralize: buntUndefined(function(string, count, includeCount, binding) {
|
|
if (!binding) {
|
|
binding = includeCount;
|
|
includeCount = true;
|
|
if (!binding) {
|
|
binding = count;
|
|
count = void 0;
|
|
}
|
|
}
|
|
if (count != null) {
|
|
return Batman.helpers.pluralize(count, string, void 0, includeCount);
|
|
} else {
|
|
return Batman.helpers.pluralize(string);
|
|
}
|
|
}),
|
|
humanize: buntUndefined(function(string, binding) {
|
|
return Batman.helpers.humanize(string);
|
|
}),
|
|
join: buntUndefined(function(value, withWhat, binding) {
|
|
if (withWhat == null) {
|
|
withWhat = '';
|
|
}
|
|
if (!binding) {
|
|
binding = withWhat;
|
|
withWhat = '';
|
|
}
|
|
return value.join(withWhat);
|
|
}),
|
|
sort: buntUndefined(function(value) {
|
|
return value.sort();
|
|
}),
|
|
map: buntUndefined(function(value, key) {
|
|
return value.map(function(x) {
|
|
return Batman.get(x, key);
|
|
});
|
|
}),
|
|
has: function(set, item) {
|
|
if (set == null) {
|
|
return false;
|
|
}
|
|
return Batman.contains(set, item);
|
|
},
|
|
first: buntUndefined(function(value) {
|
|
return value[0];
|
|
}),
|
|
meta: buntUndefined(function(value, keypath) {
|
|
Batman.developer.assert(value.meta, "Error, value doesn't have a meta to filter on!");
|
|
return value.meta.get(keypath);
|
|
}),
|
|
interpolate: function(string, interpolationKeypaths, binding) {
|
|
var k, v, values;
|
|
if (!binding) {
|
|
binding = interpolationKeypaths;
|
|
interpolationKeypaths = void 0;
|
|
}
|
|
if (!string) {
|
|
return;
|
|
}
|
|
values = {};
|
|
for (k in interpolationKeypaths) {
|
|
v = interpolationKeypaths[k];
|
|
values[k] = this.get(v);
|
|
if (!(values[k] != null)) {
|
|
Batman.developer.warn("Warning! Undefined interpolation key " + k + " for interpolation", string);
|
|
values[k] = '';
|
|
}
|
|
}
|
|
return Batman.helpers.interpolate(string, values);
|
|
},
|
|
withArguments: function() {
|
|
var binding, block, curryArgs, _i;
|
|
block = arguments[0], curryArgs = 3 <= arguments.length ? __slice.call(arguments, 1, _i = arguments.length - 1) : (_i = 1, []), binding = arguments[_i++];
|
|
if (!block) {
|
|
return;
|
|
}
|
|
return function() {
|
|
var regularArgs;
|
|
regularArgs = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
return block.call.apply(block, [this].concat(__slice.call(curryArgs), __slice.call(regularArgs)));
|
|
};
|
|
},
|
|
routeToAction: buntUndefined(function(model, action) {
|
|
var params;
|
|
params = Batman.Dispatcher.paramsFromArgument(model);
|
|
params.action = action;
|
|
return params;
|
|
}),
|
|
escape: buntUndefined(Batman.escapeHTML)
|
|
};
|
|
|
|
(function() {
|
|
var k, _i, _len, _ref, _results;
|
|
_ref = ['capitalize', 'singularize', 'underscore', 'camelize'];
|
|
_results = [];
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
k = _ref[_i];
|
|
_results.push(Batman.Filters[k] = buntUndefined(Batman.helpers[k]));
|
|
}
|
|
return _results;
|
|
})();
|
|
|
|
Batman.developer.addFilters();
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.RenderContext = (function() {
|
|
var ContextProxy;
|
|
|
|
RenderContext.deProxy = function(object) {
|
|
if ((object != null) && object.isContextProxy) {
|
|
return object.get('proxiedObject');
|
|
} else {
|
|
return object;
|
|
}
|
|
};
|
|
|
|
RenderContext.root = function() {
|
|
var root;
|
|
if (Batman.currentApp != null) {
|
|
root = Batman.currentApp.get('_renderContext');
|
|
}
|
|
return root != null ? root : root = this.base;
|
|
};
|
|
|
|
RenderContext.prototype.windowWrapper = {
|
|
window: Batman.container
|
|
};
|
|
|
|
function RenderContext(object, parent) {
|
|
this.object = object;
|
|
this.parent = parent;
|
|
}
|
|
|
|
RenderContext.prototype.findKey = function(key) {
|
|
var base, currentNode, val;
|
|
base = key.split('.')[0].split('|')[0].trim();
|
|
currentNode = this;
|
|
while (currentNode) {
|
|
val = Batman.get(currentNode.object, base);
|
|
if (typeof val !== 'undefined') {
|
|
val = Batman.get(currentNode.object, key);
|
|
return [val, currentNode.object].map(this.constructor.deProxy);
|
|
}
|
|
currentNode = currentNode.parent;
|
|
}
|
|
return [Batman.get(this.windowWrapper, key), this.windowWrapper];
|
|
};
|
|
|
|
RenderContext.prototype.get = function(key) {
|
|
return this.findKey(key)[0];
|
|
};
|
|
|
|
RenderContext.prototype.contextForKey = function(key) {
|
|
return this.findKey(key)[1];
|
|
};
|
|
|
|
RenderContext.prototype.descend = function(object, scopedKey) {
|
|
var oldObject;
|
|
if (scopedKey) {
|
|
oldObject = object;
|
|
object = new Batman.Object();
|
|
object[scopedKey] = oldObject;
|
|
}
|
|
return new this.constructor(object, this);
|
|
};
|
|
|
|
RenderContext.prototype.descendWithKey = function(key, scopedKey) {
|
|
var proxy;
|
|
proxy = new ContextProxy(this, key);
|
|
return this.descend(proxy, scopedKey);
|
|
};
|
|
|
|
RenderContext.prototype.chain = function() {
|
|
var parent, x;
|
|
x = [];
|
|
parent = this;
|
|
while (parent) {
|
|
x.push(parent.object);
|
|
parent = parent.parent;
|
|
}
|
|
return x;
|
|
};
|
|
|
|
RenderContext.ContextProxy = ContextProxy = (function(_super) {
|
|
|
|
__extends(ContextProxy, _super);
|
|
|
|
ContextProxy.prototype.isContextProxy = true;
|
|
|
|
ContextProxy.accessor('proxiedObject', function() {
|
|
return this.binding.get('filteredValue');
|
|
});
|
|
|
|
ContextProxy.accessor({
|
|
get: function(key) {
|
|
return this.get("proxiedObject." + key);
|
|
},
|
|
set: function(key, value) {
|
|
return this.set("proxiedObject." + key, value);
|
|
},
|
|
unset: function(key) {
|
|
return this.unset("proxiedObject." + key);
|
|
}
|
|
});
|
|
|
|
function ContextProxy(renderContext, keyPath, localKey) {
|
|
this.renderContext = renderContext;
|
|
this.keyPath = keyPath;
|
|
this.localKey = localKey;
|
|
this.binding = new Batman.DOM.AbstractBinding(void 0, this.keyPath, this.renderContext);
|
|
}
|
|
|
|
return ContextProxy;
|
|
|
|
})(Batman.Object);
|
|
|
|
return RenderContext;
|
|
|
|
}).call(this);
|
|
|
|
Batman.RenderContext.base = new Batman.RenderContext(Batman.RenderContext.prototype.windowWrapper);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Batman.ViewStore = (function(_super) {
|
|
|
|
__extends(ViewStore, _super);
|
|
|
|
function ViewStore() {
|
|
ViewStore.__super__.constructor.apply(this, arguments);
|
|
this._viewContents = {};
|
|
this._requestedPaths = new Batman.SimpleSet;
|
|
}
|
|
|
|
ViewStore.prototype.propertyClass = Batman.Property;
|
|
|
|
ViewStore.prototype.fetchView = function(path) {
|
|
var _this = this;
|
|
return new Batman.Request({
|
|
url: Batman.Navigator.normalizePath(Batman.config.viewPrefix, "" + path + ".html"),
|
|
type: 'html',
|
|
success: function(response) {
|
|
return _this.set(path, response);
|
|
},
|
|
error: function(response) {
|
|
throw new Error("Could not load view from " + path);
|
|
}
|
|
});
|
|
};
|
|
|
|
ViewStore.accessor({
|
|
'final': true,
|
|
get: function(path) {
|
|
var contents;
|
|
if (path[0] !== '/') {
|
|
return this.get("/" + path);
|
|
}
|
|
if (this._viewContents[path]) {
|
|
return this._viewContents[path];
|
|
}
|
|
if (this._requestedPaths.has(path)) {
|
|
return;
|
|
}
|
|
if (contents = this._sourceFromDOM(path)) {
|
|
return contents;
|
|
}
|
|
if (Batman.config.fetchRemoteViews) {
|
|
this.fetchView(path);
|
|
} else {
|
|
throw new Error("Couldn't find view source for \'" + path + "\'!");
|
|
}
|
|
},
|
|
set: function(path, content) {
|
|
if (path[0] !== '/') {
|
|
return this.set("/" + path, content);
|
|
}
|
|
this._requestedPaths.add(path);
|
|
return this._viewContents[path] = content;
|
|
}
|
|
});
|
|
|
|
ViewStore.prototype.prefetch = function(path) {
|
|
this.get(path);
|
|
return true;
|
|
};
|
|
|
|
ViewStore.prototype._sourceFromDOM = function(path) {
|
|
var node, relativePath;
|
|
relativePath = path.slice(1);
|
|
if (node = Batman.DOM.querySelector(document, "[data-defineview*='" + relativePath + "']")) {
|
|
Batman.setImmediate(function() {
|
|
var _ref;
|
|
return (_ref = node.parentNode) != null ? _ref.removeChild(node) : void 0;
|
|
});
|
|
return Batman.DOM.defineView(path, node);
|
|
}
|
|
};
|
|
|
|
return ViewStore;
|
|
|
|
})(Batman.Object);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
__slice = [].slice;
|
|
|
|
Batman.View = (function(_super) {
|
|
|
|
__extends(View, _super);
|
|
|
|
View.YieldStorage = (function(_super1) {
|
|
|
|
__extends(YieldStorage, _super1);
|
|
|
|
function YieldStorage() {
|
|
return YieldStorage.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
YieldStorage.wrapAccessor(function(core) {
|
|
return {
|
|
get: function(key) {
|
|
var val;
|
|
val = core.get.call(this, key);
|
|
if (!(val != null)) {
|
|
val = this.set(key, []);
|
|
}
|
|
return val;
|
|
}
|
|
};
|
|
});
|
|
|
|
return YieldStorage;
|
|
|
|
})(Batman.Hash);
|
|
|
|
View.store = new Batman.ViewStore();
|
|
|
|
View.option = function() {
|
|
var keys;
|
|
keys = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
return this.accessor.apply(this, __slice.call(keys).concat([{
|
|
get: function(key) {
|
|
var _ref;
|
|
return (_ref = this.get("argumentBindings." + key)) != null ? _ref.get('filteredValue') : void 0;
|
|
},
|
|
set: function(key, value) {
|
|
var _ref;
|
|
return (_ref = this.get("argumentBindings." + key)) != null ? _ref.set('filteredValue', value) : void 0;
|
|
},
|
|
unset: function(key) {
|
|
var _ref;
|
|
return (_ref = this.get("argumentBindings." + key)) != null ? _ref.unset('filteredValue') : void 0;
|
|
}
|
|
}]));
|
|
};
|
|
|
|
View.prototype.isView = true;
|
|
|
|
View.prototype.cache = true;
|
|
|
|
View.prototype._rendered = false;
|
|
|
|
View.prototype.node = null;
|
|
|
|
View.prototype.event('ready').oneShot = true;
|
|
|
|
View.accessor('argumentBindings', function() {
|
|
var _this = this;
|
|
return new Batman.TerminalAccessible(function(key) {
|
|
var bindingKey, context, keyPath, node, _ref;
|
|
if (!((node = _this.get('node')) && (context = _this.get('context')))) {
|
|
return;
|
|
}
|
|
keyPath = node.getAttribute(("data-view-" + key).toLowerCase());
|
|
if (keyPath == null) {
|
|
return;
|
|
}
|
|
bindingKey = "_argumentBinding" + key;
|
|
if ((_ref = _this[bindingKey]) != null) {
|
|
_ref.die();
|
|
}
|
|
return _this[bindingKey] = new Batman.DOM.ViewArgumentBinding(node, keyPath, context);
|
|
});
|
|
});
|
|
|
|
View.accessor('html', {
|
|
get: function() {
|
|
var source;
|
|
if (this.html && this.html.length > 0) {
|
|
return this.html;
|
|
}
|
|
if (!(source = this.get('source'))) {
|
|
return;
|
|
}
|
|
source = Batman.Navigator.normalizePath(source);
|
|
return this.html = this.constructor.store.get(source);
|
|
},
|
|
set: function(_, html) {
|
|
return this.html = html;
|
|
}
|
|
});
|
|
|
|
View.accessor('node', {
|
|
get: function() {
|
|
var html;
|
|
if (this.node == null) {
|
|
html = this.get('html');
|
|
if (!(html && html.length > 0)) {
|
|
return;
|
|
}
|
|
this.node = document.createElement('div');
|
|
this._setNodeOwner(this.node);
|
|
Batman.DOM.setInnerHTML(this.node, html);
|
|
}
|
|
return this.node;
|
|
},
|
|
set: function(_, node) {
|
|
var updateHTML,
|
|
_this = this;
|
|
this.node = node;
|
|
this._setNodeOwner(node);
|
|
updateHTML = function(html) {
|
|
if (html != null) {
|
|
Batman.DOM.setInnerHTML(_this.node, html);
|
|
return _this.forget('html', updateHTML);
|
|
}
|
|
};
|
|
this.observeAndFire('html', updateHTML);
|
|
return node;
|
|
}
|
|
});
|
|
|
|
View.accessor('yields', function() {
|
|
return new this.constructor.YieldStorage;
|
|
});
|
|
|
|
View.accessor('fetched?', function() {
|
|
return this.get('source') != null;
|
|
});
|
|
|
|
View.accessor('readyToRender', function() {
|
|
var _ref;
|
|
return this.get('node') && (this.get('fetched?') ? ((_ref = this.get('html')) != null ? _ref.length : void 0) > 0 : true);
|
|
});
|
|
|
|
function View(options) {
|
|
var context,
|
|
_this = this;
|
|
if (options == null) {
|
|
options = {};
|
|
}
|
|
context = options.context;
|
|
if (context) {
|
|
if (!(context instanceof Batman.RenderContext)) {
|
|
context = Batman.RenderContext.root().descend(context);
|
|
}
|
|
} else {
|
|
context = Batman.RenderContext.root();
|
|
}
|
|
options.context = context.descend(this);
|
|
View.__super__.constructor.call(this, options);
|
|
Batman.Property.withoutTracking(function() {
|
|
return _this.observeAndFire('readyToRender', function(ready) {
|
|
if (ready) {
|
|
return _this.render();
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
View.prototype.render = function() {
|
|
var node,
|
|
_this = this;
|
|
if (this._rendered) {
|
|
return;
|
|
}
|
|
this._rendered = true;
|
|
this._renderer = new Batman.Renderer(node = this.get('node'), this.get('context'), this);
|
|
return this._renderer.on('rendered', function() {
|
|
return _this.fire('ready', node);
|
|
});
|
|
};
|
|
|
|
View.prototype.isInDOM = function() {
|
|
var node;
|
|
if ((node = this.get('node'))) {
|
|
return (node.parentNode != null) || this.get('yields').some(function(name, nodes) {
|
|
var _i, _len;
|
|
for (_i = 0, _len = nodes.length; _i < _len; _i++) {
|
|
node = nodes[_i].node;
|
|
if (node.parentNode != null) {
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
});
|
|
} else {
|
|
return false;
|
|
}
|
|
};
|
|
|
|
View.prototype.applyYields = function() {
|
|
return this.get('yields').forEach(function(name, nodes) {
|
|
var action, node, yieldObject, _i, _len, _ref, _results;
|
|
yieldObject = Batman.DOM.Yield.withName(name);
|
|
_results = [];
|
|
for (_i = 0, _len = nodes.length; _i < _len; _i++) {
|
|
_ref = nodes[_i], node = _ref.node, action = _ref.action;
|
|
_results.push(yieldObject[action](node));
|
|
}
|
|
return _results;
|
|
});
|
|
};
|
|
|
|
View.prototype.retractYields = function() {
|
|
return this.get('yields').forEach(function(name, nodes) {
|
|
var node, _i, _len, _ref, _results;
|
|
_results = [];
|
|
for (_i = 0, _len = nodes.length; _i < _len; _i++) {
|
|
node = nodes[_i].node;
|
|
_results.push((_ref = node.parentNode) != null ? _ref.removeChild(node) : void 0);
|
|
}
|
|
return _results;
|
|
});
|
|
};
|
|
|
|
View.prototype.pushYieldAction = function(key, action, node) {
|
|
this._setNodeYielder(node);
|
|
return this.get("yields").get(key).push({
|
|
node: node,
|
|
action: action
|
|
});
|
|
};
|
|
|
|
View.prototype._setNodeOwner = function(node) {
|
|
return Batman._data(node, 'view', this);
|
|
};
|
|
|
|
View.prototype._setNodeYielder = function(node) {
|
|
return Batman._data(node, 'yielder', this);
|
|
};
|
|
|
|
View.prototype.on('ready', function() {
|
|
return typeof this.ready === "function" ? this.ready.apply(this, arguments) : void 0;
|
|
});
|
|
|
|
View.prototype.on('appear', function() {
|
|
return typeof this.viewDidAppear === "function" ? this.viewDidAppear.apply(this, arguments) : void 0;
|
|
});
|
|
|
|
View.prototype.on('disappear', function() {
|
|
return typeof this.viewDidDisappear === "function" ? this.viewDidDisappear.apply(this, arguments) : void 0;
|
|
});
|
|
|
|
View.prototype.on('beforeAppear', function() {
|
|
return typeof this.viewWillAppear === "function" ? this.viewWillAppear.apply(this, arguments) : void 0;
|
|
});
|
|
|
|
View.prototype.on('beforeDisappear', function() {
|
|
return typeof this.viewWillDisappear === "function" ? this.viewWillDisappear.apply(this, arguments) : void 0;
|
|
});
|
|
|
|
return View;
|
|
|
|
}).call(this, Batman.Object);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
var Yield,
|
|
__hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
__slice = [].slice;
|
|
|
|
Batman.DOM.Yield = Yield = (function(_super) {
|
|
|
|
__extends(Yield, _super);
|
|
|
|
Yield.yields = {};
|
|
|
|
Yield.queued = function(fn) {
|
|
return function() {
|
|
var args, handler,
|
|
_this = this;
|
|
args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
|
if (this.containerNode != null) {
|
|
return fn.apply(this, args);
|
|
} else {
|
|
return handler = this.observe('containerNode', function() {
|
|
var result;
|
|
result = fn.apply(_this, args);
|
|
_this.forget('containerNode', handler);
|
|
return result;
|
|
});
|
|
}
|
|
};
|
|
};
|
|
|
|
Yield.reset = function() {
|
|
return this.yields = {};
|
|
};
|
|
|
|
Yield.withName = function(name) {
|
|
var _base;
|
|
(_base = this.yields)[name] || (_base[name] = new this({
|
|
name: name
|
|
}));
|
|
return this.yields[name];
|
|
};
|
|
|
|
Yield.forEach = function(f) {
|
|
var name, yieldObject, _ref;
|
|
_ref = this.yields;
|
|
for (name in _ref) {
|
|
yieldObject = _ref[name];
|
|
f(yieldObject);
|
|
}
|
|
};
|
|
|
|
Yield.clearAll = function() {
|
|
return this.forEach(function(yieldObject) {
|
|
return yieldObject.clear();
|
|
});
|
|
};
|
|
|
|
Yield.cycleAll = function() {
|
|
return this.forEach(function(yieldObject) {
|
|
return yieldObject.cycle();
|
|
});
|
|
};
|
|
|
|
Yield.clearAllStale = function() {
|
|
return this.forEach(function(yieldObject) {
|
|
return yieldObject.clearStale();
|
|
});
|
|
};
|
|
|
|
function Yield() {
|
|
this.cycle();
|
|
}
|
|
|
|
Yield.prototype.cycle = function() {
|
|
return this.currentVersionNodes = [];
|
|
};
|
|
|
|
Yield.prototype.clear = Yield.queued(function() {
|
|
var child, _i, _len, _ref, _results;
|
|
this.cycle();
|
|
_ref = (function() {
|
|
var _j, _len, _ref, _results1;
|
|
_ref = this.containerNode.childNodes;
|
|
_results1 = [];
|
|
for (_j = 0, _len = _ref.length; _j < _len; _j++) {
|
|
child = _ref[_j];
|
|
_results1.push(child);
|
|
}
|
|
return _results1;
|
|
}).call(this);
|
|
_results = [];
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
child = _ref[_i];
|
|
_results.push(Batman.DOM.removeOrDestroyNode(child));
|
|
}
|
|
return _results;
|
|
});
|
|
|
|
Yield.prototype.clearStale = Yield.queued(function() {
|
|
var child, _i, _len, _ref, _results;
|
|
_ref = (function() {
|
|
var _j, _len, _ref, _results1;
|
|
_ref = this.containerNode.childNodes;
|
|
_results1 = [];
|
|
for (_j = 0, _len = _ref.length; _j < _len; _j++) {
|
|
child = _ref[_j];
|
|
_results1.push(child);
|
|
}
|
|
return _results1;
|
|
}).call(this);
|
|
_results = [];
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
child = _ref[_i];
|
|
if (!~this.currentVersionNodes.indexOf(child)) {
|
|
_results.push(Batman.DOM.removeOrDestroyNode(child));
|
|
}
|
|
}
|
|
return _results;
|
|
});
|
|
|
|
Yield.prototype.append = Yield.queued(function(node) {
|
|
this.currentVersionNodes.push(node);
|
|
return Batman.DOM.appendChild(this.containerNode, node, true);
|
|
});
|
|
|
|
Yield.prototype.replace = Yield.queued(function(node) {
|
|
this.clear();
|
|
return this.append(node);
|
|
});
|
|
|
|
return Yield;
|
|
|
|
})(Batman.Object);
|
|
|
|
}).call(this);
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
}).call(this);
|
|
(function() {
|
|
|
|
Batman.extend(Batman.DOM, {
|
|
querySelectorAll: function(node, selector) {
|
|
return jQuery(selector, node);
|
|
},
|
|
querySelector: function(node, selector) {
|
|
return jQuery(selector, node)[0];
|
|
},
|
|
setInnerHTML: function(node, html) {
|
|
var child, childNodes, result, _i, _j, _len, _len1;
|
|
childNodes = (function() {
|
|
var _i, _len, _ref, _results;
|
|
_ref = node.childNodes;
|
|
_results = [];
|
|
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
child = _ref[_i];
|
|
_results.push(child);
|
|
}
|
|
return _results;
|
|
})();
|
|
for (_i = 0, _len = childNodes.length; _i < _len; _i++) {
|
|
child = childNodes[_i];
|
|
Batman.DOM.willRemoveNode(child);
|
|
}
|
|
result = jQuery(node).html(html);
|
|
for (_j = 0, _len1 = childNodes.length; _j < _len1; _j++) {
|
|
child = childNodes[_j];
|
|
Batman.DOM.didRemoveNode(child);
|
|
}
|
|
return result;
|
|
},
|
|
removeNode: function(node) {
|
|
var _ref;
|
|
Batman.DOM.willRemoveNode(node);
|
|
if ((_ref = node.parentNode) != null) {
|
|
_ref.removeChild(node);
|
|
}
|
|
return Batman.DOM.didRemoveNode(node);
|
|
},
|
|
destroyNode: function(node) {
|
|
Batman.DOM.willDestroyNode(node);
|
|
Batman.DOM.willRemoveNode(node);
|
|
jQuery(node).remove();
|
|
Batman.DOM.didRemoveNode(node);
|
|
return Batman.DOM.didDestroyNode(node);
|
|
},
|
|
appendChild: function(parent, child) {
|
|
Batman.DOM.willInsertNode(child);
|
|
jQuery(parent).append(child);
|
|
return Batman.DOM.didInsertNode(child);
|
|
}
|
|
});
|
|
|
|
Batman.Request.prototype._parseResponseHeaders = function(xhr) {
|
|
var headers;
|
|
return headers = xhr.getAllResponseHeaders().split('\n').reduce(function(acc, header) {
|
|
var key, matches, value;
|
|
if (matches = header.match(/([^:]*):\s*(.*)/)) {
|
|
key = matches[1];
|
|
value = matches[2];
|
|
acc[key] = value;
|
|
}
|
|
return acc;
|
|
}, {});
|
|
};
|
|
|
|
Batman.Request.prototype._prepareOptions = function(data) {
|
|
var options, _ref,
|
|
_this = this;
|
|
options = {
|
|
url: this.get('url'),
|
|
type: this.get('method'),
|
|
dataType: this.get('type'),
|
|
data: data || this.get('data'),
|
|
username: this.get('username'),
|
|
password: this.get('password'),
|
|
headers: this.get('headers'),
|
|
beforeSend: function() {
|
|
return _this.fire('loading');
|
|
},
|
|
success: function(response, textStatus, xhr) {
|
|
_this.mixin({
|
|
xhr: xhr,
|
|
status: xhr.status,
|
|
response: response,
|
|
responseHeaders: _this._parseResponseHeaders(xhr)
|
|
});
|
|
return _this.fire('success', response);
|
|
},
|
|
error: function(xhr, status, error) {
|
|
_this.mixin({
|
|
xhr: xhr,
|
|
status: xhr.status,
|
|
response: xhr.responseText,
|
|
responseHeaders: _this._parseResponseHeaders(xhr)
|
|
});
|
|
xhr.request = _this;
|
|
return _this.fire('error', xhr);
|
|
},
|
|
complete: function() {
|
|
return _this.fire('loaded');
|
|
}
|
|
};
|
|
if ((_ref = this.get('method')) === 'PUT' || _ref === 'POST') {
|
|
if (!this.hasFileUploads()) {
|
|
options.contentType = this.get('contentType');
|
|
if (typeof options.data === 'object') {
|
|
options.processData = false;
|
|
options.data = Batman.URI.queryFromParams(options.data);
|
|
}
|
|
} else {
|
|
options.contentType = false;
|
|
options.processData = false;
|
|
options.data = this.constructor.objectToFormData(options.data);
|
|
}
|
|
}
|
|
return options;
|
|
};
|
|
|
|
Batman.Request.prototype.send = function(data) {
|
|
return jQuery.ajax(this._prepareOptions(data));
|
|
};
|
|
|
|
Batman.mixins.animation = {
|
|
show: function(addToParent) {
|
|
var jq, show, _ref, _ref1;
|
|
jq = $(this);
|
|
show = function() {
|
|
return jq.show(600);
|
|
};
|
|
if (addToParent) {
|
|
if ((_ref = addToParent.append) != null) {
|
|
_ref.appendChild(this);
|
|
}
|
|
if ((_ref1 = addToParent.before) != null) {
|
|
_ref1.parentNode.insertBefore(this, addToParent.before);
|
|
}
|
|
jq.hide();
|
|
setTimeout(show, 0);
|
|
} else {
|
|
show();
|
|
}
|
|
return this;
|
|
},
|
|
hide: function(removeFromParent) {
|
|
var _this = this;
|
|
$(this).hide(600, function() {
|
|
var _ref;
|
|
if (removeFromParent) {
|
|
if ((_ref = _this.parentNode) != null) {
|
|
_ref.removeChild(_this);
|
|
}
|
|
}
|
|
return Batman.DOM.didRemoveNode(_this);
|
|
});
|
|
return this;
|
|
}
|
|
};
|
|
|
|
}).call(this);
|
|
(function() {
|
|
var lastEvents, source, widgets,
|
|
__hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
|
|
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
|
_this = this;
|
|
|
|
Batman.Filters.prettyNumber = function(num) {
|
|
if (!isNaN(num)) {
|
|
return num.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
|
|
}
|
|
};
|
|
|
|
Batman.Filters.dashize = function(str) {
|
|
var dashes_rx1, dashes_rx2;
|
|
dashes_rx1 = /([A-Z]+)([A-Z][a-z])/g;
|
|
dashes_rx2 = /([a-z\d])([A-Z])/g;
|
|
return str.replace(dashes_rx1, '$1_$2').replace(dashes_rx2, '$1_$2').replace('_', '-').toLowerCase();
|
|
};
|
|
|
|
Batman.Filters.shortenedNumber = function(num) {
|
|
if (isNaN(num)) {
|
|
return num;
|
|
}
|
|
if (num >= 1000000000) {
|
|
return (num / 1000000000).toFixed(1) + 'B';
|
|
} else if (num >= 1000000) {
|
|
return (num / 1000000).toFixed(1) + 'M';
|
|
} else if (num >= 1000) {
|
|
return (num / 1000).toFixed(1) + 'K';
|
|
} else {
|
|
return num;
|
|
}
|
|
};
|
|
|
|
window.Dashing = (function(_super) {
|
|
|
|
__extends(Dashing, _super);
|
|
|
|
function Dashing() {
|
|
return Dashing.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
Dashing.root(function() {});
|
|
|
|
return Dashing;
|
|
|
|
})(Batman.App);
|
|
|
|
Dashing.params = Batman.URI.paramsFromQuery(window.location.search.slice(1));
|
|
|
|
Dashing.Widget = (function(_super) {
|
|
|
|
__extends(Widget, _super);
|
|
|
|
function Widget() {
|
|
this.onData = __bind(this.onData, this);
|
|
|
|
this.receiveData = __bind(this.receiveData, this);
|
|
|
|
var type, _base, _name;
|
|
this.constructor.prototype.source = Batman.Filters.underscore(this.constructor.name);
|
|
Widget.__super__.constructor.apply(this, arguments);
|
|
this.mixin($(this.node).data());
|
|
(_base = Dashing.widgets)[_name = this.id] || (_base[_name] = []);
|
|
Dashing.widgets[this.id].push(this);
|
|
this.mixin(Dashing.lastEvents[this.id]);
|
|
type = Batman.Filters.dashize(this.view);
|
|
$(this.node).addClass("widget widget-" + type + " " + this.id);
|
|
}
|
|
|
|
Widget.accessor('updatedAtMessage', function() {
|
|
var timestamp, updatedAt;
|
|
if (updatedAt = this.get('updatedAt')) {
|
|
timestamp = updatedAt.toString().match(/\d*:\d*/)[0];
|
|
return "Last updated at " + timestamp;
|
|
}
|
|
});
|
|
|
|
Widget.prototype.on('ready', function() {
|
|
return Dashing.Widget.fire('ready');
|
|
});
|
|
|
|
Widget.prototype.receiveData = function(data) {
|
|
this.mixin(data);
|
|
return this.onData(data);
|
|
};
|
|
|
|
Widget.prototype.onData = function(data) {};
|
|
|
|
return Widget;
|
|
|
|
})(Batman.View);
|
|
|
|
Dashing.AnimatedValue = {
|
|
get: Batman.Property.defaultAccessor.get,
|
|
set: function(k, to) {
|
|
var num, num_interval, timer, up,
|
|
_this = this;
|
|
if (!(to != null) || isNaN(to)) {
|
|
return this[k] = to;
|
|
} else {
|
|
timer = "interval_" + k;
|
|
num = !isNaN(this[k]) && (this[k] != null) ? this[k] : 0;
|
|
if (!(this[timer] || num === to)) {
|
|
to = parseFloat(to);
|
|
num = parseFloat(num);
|
|
up = to > num;
|
|
num_interval = Math.abs(num - to) / 90;
|
|
this[timer] = setInterval(function() {
|
|
num = up ? Math.ceil(num + num_interval) : Math.floor(num - num_interval);
|
|
if ((up && num > to) || (!up && num < to)) {
|
|
num = to;
|
|
clearInterval(_this[timer]);
|
|
_this[timer] = null;
|
|
delete _this[timer];
|
|
}
|
|
_this[k] = num;
|
|
return _this.set(k, to);
|
|
});
|
|
}
|
|
return this[k] = num;
|
|
}
|
|
}
|
|
};
|
|
|
|
Dashing.widgets = widgets = {};
|
|
|
|
Dashing.lastEvents = lastEvents = {};
|
|
|
|
Dashing.debugMode = false;
|
|
|
|
source = new EventSource('/events');
|
|
|
|
source.addEventListener('open', function(e) {
|
|
return console.log("Connection opened");
|
|
});
|
|
|
|
source.addEventListener('error', function(e) {
|
|
console.log("Connection error");
|
|
if (e.readyState === EventSource.CLOSED) {
|
|
return console.log("Connection closed");
|
|
}
|
|
});
|
|
|
|
source.addEventListener('message', function(e) {
|
|
var data, widget, _i, _len, _ref, _ref1, _results;
|
|
data = JSON.parse(e.data);
|
|
if (Dashing.debugMode) {
|
|
console.log("Received data for " + data.id, data);
|
|
}
|
|
lastEvents[data.id] = data;
|
|
if (((_ref = widgets[data.id]) != null ? _ref.length : void 0) > 0) {
|
|
_ref1 = widgets[data.id];
|
|
_results = [];
|
|
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
|
|
widget = _ref1[_i];
|
|
_results.push(widget.receiveData(data));
|
|
}
|
|
return _results;
|
|
}
|
|
});
|
|
|
|
$(document).ready(function() {
|
|
return Dashing.run();
|
|
});
|
|
|
|
}).call(this);
|
|
(function(){function d(a,b){try{for(var c in b)Object.defineProperty(a.prototype,c,{value:b[c],enumerable:!1})}catch(d){a.prototype=b}}function f(a){var b=-1,c=a.length,d=[];while(++b<c)d.push(a[b]);return d}function g(a){return Array.prototype.slice.call(a)}function j(){}function m(a){return a}function n(){return this}function o(){return!0}function p(a){return typeof a=="function"?a:function(){return a}}function q(a,b,c){return function(){var d=c.apply(b,arguments);return arguments.length?a:d}}function r(a){return a!=null&&!isNaN(a)}function s(a){return a.length}function u(a){return a==null}function v(a){return a.trim().replace(/\s+/g," ")}function w(a){var b=1;while(a*b%1)b*=10;return b}function z(){}function A(a){function d(){var c=b,d=-1,e=c.length,f;while(++d<e)(f=c[d].on)&&f.apply(this,arguments);return a}var b=[],c=new j;return d.on=function(d,e){var f=c.get(d),g;return arguments.length<2?f&&f.on:(f&&(f.on=null,b=b.slice(0,g=b.indexOf(f)).concat(b.slice(g+1)),c.remove(d)),e&&b.push(c.set(d,{on:e})),a)},d}function D(a,b){return b-(a?1+Math.floor(Math.log(a+Math.pow(10,1+Math.floor(Math.log(a)/Math.LN10)-b))/Math.LN10):1)}function E(a){return a+""}function F(a){var b=a.lastIndexOf("."),c=b>=0?a.substring(b):(b=a.length,""),d=[];while(b>0)d.push(a.substring(b-=3,b+3));return d.reverse().join(",")+c}function H(a,b){var c=Math.pow(10,Math.abs(8-b)*3);return{scale:b>8?function(a){return a/c}:function(a){return a*c},symbol:a}}function N(a){return function(b){return b<=0?0:b>=1?1:a(b)}}function O(a){return function(b){return 1-a(1-b)}}function P(a){return function(b){return.5*(b<.5?a(2*b):2-a(2-2*b))}}function Q(a){return a}function R(a){return function(b){return Math.pow(b,a)}}function S(a){return 1-Math.cos(a*Math.PI/2)}function T(a){return Math.pow(2,10*(a-1))}function U(a){return 1-Math.sqrt(1-a*a)}function V(a,b){var c;return arguments.length<2&&(b=.45),arguments.length<1?(a=1,c=b/4):c=b/(2*Math.PI)*Math.asin(1/a),function(d){return 1+a*Math.pow(2,10*-d)*Math.sin((d-c)*2*Math.PI/b)}}function W(a){return a||(a=1.70158),function(b){return b*b*((a+1)*b-a)}}function X(a){return a<1/2.75?7.5625*a*a:a<2/2.75?7.5625*(a-=1.5/2.75)*a+.75:a<2.5/2.75?7.5625*(a-=2.25/2.75)*a+.9375:7.5625*(a-=2.625/2.75)*a+.984375}function Y(){d3.event.stopPropagation(),d3.event.preventDefault()}function Z(){var a=d3.event,b;while(b=a.sourceEvent)a=b;return a}function $(a){var b=new z,c=0,d=arguments.length;while(++c<d)b[arguments[c]]=A(b);return b.of=function(c,d){return function(e){try{var f=e.sourceEvent=d3.event;e.target=a,d3.event=e,b[e.type].apply(c,d)}finally{d3.event=f}}},b}function _(a){var b=[a.a,a.b],c=[a.c,a.d],d=bb(b),e=ba(b,c),f=bb(bc(c,b,-e))||0;b[0]*c[1]<c[0]*b[1]&&(b[0]*=-1,b[1]*=-1,d*=-1,e*=-1),this.rotate=(d?Math.atan2(b[1],b[0]):Math.atan2(-c[0],c[1]))*bd,this.translate=[a.e,a.f],this.scale=[d,f],this.skew=f?Math.atan2(e,f)*bd:0}function ba(a,b){return a[0]*b[0]+a[1]*b[1]}function bb(a){var b=Math.sqrt(ba(a,a));return b&&(a[0]/=b,a[1]/=b),b}function bc(a,b,c){return a[0]+=c*b[0],a[1]+=c*b[1],a}function bg(a){return a=="transform"?d3.interpolateTransform:d3.interpolate}function bh(a,b){return b=b-(a=+a)?1/(b-a):0,function(c){return(c-a)*b}}function bi(a,b){return b=b-(a=+a)?1/(b-a):0,function(c){return Math.max(0,Math.min(1,(c-a)*b))}}function bj(a,b,c){return new bk(a,b,c)}function bk(a,b,c){this.r=a,this.g=b,this.b=c}function bl(a){return a<16?"0"+Math.max(0,a).toString(16):Math.min(255,a).toString(16)}function bm(a,b,c){var d=0,e=0,f=0,g,h,i;g=/([a-z]+)\((.*)\)/i.exec(a);if(g){h=g[2].split(",");switch(g[1]){case"hsl":return c(parseFloat(h[0]),parseFloat(h[1])/100,parseFloat(h[2])/100);case"rgb":return b(bq(h[0]),bq(h[1]),bq(h[2]))}}return(i=br.get(a))?b(i.r,i.g,i.b):(a!=null&&a.charAt(0)==="#"&&(a.length===4?(d=a.charAt(1),d+=d,e=a.charAt(2),e+=e,f=a.charAt(3),f+=f):a.length===7&&(d=a.substring(1,3),e=a.substring(3,5),f=a.substring(5,7)),d=parseInt(d,16),e=parseInt(e,16),f=parseInt(f,16)),b(d,e,f))}function bn(a,b,c){var d=Math.min(a/=255,b/=255,c/=255),e=Math.max(a,b,c),f=e-d,g,h,i=(e+d)/2;return f?(h=i<.5?f/(e+d):f/(2-e-d),a==e?g=(b-c)/f+(b<c?6:0):b==e?g=(c-a)/f+2:g=(a-b)/f+4,g*=60):h=g=0,bs(g,h,i)}function bo(a,b,c){a=bp(a),b=bp(b),c=bp(c);var d=bH((.4124564*a+.3575761*b+.1804375*c)/bB),e=bH((.2126729*a+.7151522*b+.072175*c)/bC),f=bH((.0193339*a+.119192*b+.9503041*c)/bD);return by(116*e-16,500*(d-e),200*(e-f))}function bp(a){return(a/=255)<=.04045?a/12.92:Math.pow((a+.055)/1.055,2.4)}function bq(a){var b=parseFloat(a);return a.charAt(a.length-1)==="%"?Math.round(b*2.55):b}function bs(a,b,c){return new bt(a,b,c)}function bt(a,b,c){this.h=a,this.s=b,this.l=c}function bu(a,b,c){function f(a){return a>360?a-=360:a<0&&(a+=360),a<60?d+(e-d)*a/60:a<180?e:a<240?d+(e-d)*(240-a)/60:d}function g(a){return Math.round(f(a)*255)}var d,e;return a%=360,a<0&&(a+=360),b=b<0?0:b>1?1:b,c=c<0?0:c>1?1:c,e=c<=.5?c*(1+b):c+b-c*b,d=2*c-e,bj(g(a+120),g(a),g(a-120))}function bv(a,b,c){return new bw(a,b,c)}function bw(a,b,c){this.h=a,this.c=b,this.l=c}function bx(a,b,c){return by(c,Math.cos(a*=Math.PI/180)*b,Math.sin(a)*b)}function by(a,b,c){return new bz(a,b,c)}function bz(a,b,c){this.l=a,this.a=b,this.b=c}function bE(a,b,c){var d=(a+16)/116,e=d+b/500,f=d-c/200;return e=bG(e)*bB,d=bG(d)*bC,f=bG(f)*bD,bj(bI(3.2404542*e-1.5371385*d-.4985314*f),bI(-0.969266*e+1.8760108*d+.041556*f),bI(.0556434*e-.2040259*d+1.0572252*f))}function bF(a,b,c){return bv(Math.atan2(c,b)/Math.PI*180,Math.sqrt(b*b+c*c),a)}function bG(a){return a>.206893034?a*a*a:(a-4/29)/7.787037}function bH(a){return a>.008856?Math.pow(a,1/3):7.787037*a+4/29}function bI(a){return Math.round(255*(a<=.00304?12.92*a:1.055*Math.pow(a,1/2.4)-.055))}function bJ(a){return i(a,bP),a}function bQ(a){return function(){return bK(a,this)}}function bR(a){return function(){return bL(a,this)}}function bS(a,b){function c(){this.removeAttribute(a)}function d(){this.removeAttributeNS(a.space,a.local)}function e(){this.setAttribute(a,b)}function f(){this.setAttributeNS(a.space,a.local,b)}function g(){var c=b.apply(this,arguments);c==null?this.removeAttribute(a):this.setAttribute(a,c)}function h(){var c=b.apply(this,arguments);c==null?this.removeAttributeNS(a.space,a.local):this.setAttributeNS(a.space,a.local,c)}return a=d3.ns.qualify(a),b==null?a.local?d:c:typeof b=="function"?a.local?h:g:a.local?f:e}function bT(a){return new RegExp("(?:^|\\s+)"+d3.requote(a)+"(?:\\s+|$)","g")}function bU(a,b){function d(){var d=-1;while(++d<c)a[d](this,b)}function e(){var d=-1,e=b.apply(this,arguments);while(++d<c)a[d](this,e)}a=a.trim().split(/\s+/).map(bV);var c=a.length;return typeof b=="function"?e:d}function bV(a){var b=bT(a);return function(c,d){if(e=c.classList)return d?e.add(a):e.remove(a);var e=c.className,f=e.baseVal!=null,g=f?e.baseVal:e;d?(b.lastIndex=0,b.test(g)||(g=v(g+" "+a),f?e.baseVal=g:c.className=g)):g&&(g=v(g.replace(b," ")),f?e.baseVal=g:c.className=g)}}function bW(a,b,c){function d(){this.style.removeProperty(a)}function e(){this.style.setProperty(a,b,c)}function f(){var d=b.apply(this,arguments);d==null?this.style.removeProperty(a):this.style.setProperty(a,d,c)}return b==null?d:typeof b=="function"?f:e}function bX(a,b){function c(){delete this[a]}function d(){this[a]=b}function e(){var c=b.apply(this,arguments);c==null?delete this[a]:this[a]=c}return b==null?c:typeof b=="function"?e:d}function bY(a){return{__data__:a}}function bZ(a){return function(){return bO(this,a)}}function b$(a){return arguments.length||(a=d3.ascending),function(b,c){return a(b&&b.__data__,c&&c.__data__)}}function b_(a,b,c){function f(){var b=this[d];b&&(this.removeEventListener(a,b,b.$),delete this[d])}function g(){function h(a){var c=d3.event;d3.event=a,g[0]=e.__data__;try{b.apply(e,g)}finally{d3.event=c}}var e=this,g=arguments;f.call(this),this.addEventListener(a,this[d]=h,h.$=c),h._=b}var d="__on"+a,e=a.indexOf(".");return e>0&&(a=a.substring(0,e)),b?g:f}function ca(a,b){for(var c=0,d=a.length;c<d;c++)for(var e=a[c],f=0,g=e.length,h;f<g;f++)(h=e[f])&&b(h,f,c);return a}function cc(a){return i(a,cd),a}function ce(a,b,c){i(a,cf);var d=new j,e=d3.dispatch("start","end"),f=cn;return a.id=b,a.time=c,a.tween=function(b,c){return arguments.length<2?d.get(b):(c==null?d.remove(b):d.set(b,c),a)},a.ease=function(b){return arguments.length?(f=typeof b=="function"?b:d3.ease.apply(d3,arguments),a):f},a.each=function(b,c){return arguments.length<2?co.call(a,b):(e.on(b,c),a)},d3.timer(function(g){return ca(a,function(a,h,i){function o(f){return m.active>b?q():(m.active=b,d.forEach(function(b,c){(c=c.call(a,n,h))&&j.push(c)}),e.start.call(a,n,h),p(f)||d3.timer(p,0,c),1)}function p(c){if(m.active!==b)return q();var d=(c-k)/l,g=f(d),i=j.length;while(i>0)j[--i].call(a,g);if(d>=1)return q(),ch=b,e.end.call(a,n,h),ch=0,1}function q(){return--m.count||delete a.__transition__,1}var j=[],k=a.delay,l=a.duration,m=(a=a.node).__transition__||(a.__transition__={active:0,count:0}),n=a.__data__;++m.count,k<=g?o(g):d3.timer(o,k,c)})},0,c),a}function co(a){var b=ch,c=cn,d=cl,e=cm;return ch=this.id,cn=this.ease(),ca(this,function(b,c,d){cl=b.delay,cm=b.duration,a.call(b=b.node,b.__data__,c,d)}),ch=b,cn=c,cl=d,cm=e,this}function cq(a,b,c){return c!=""&&cp}function cr(a,b){return d3.tween(a,bg(b))}function cv(){var a,b=Date.now(),c=cs;while(c)a=b-c.then,a>=c.delay&&(c.flush=c.callback(a)),c=c.next;var d=cw()-b;d>24?(isFinite(d)&&(clearTimeout(cu),cu=setTimeout(cv,d)),ct=0):(ct=1,cx(cv))}function cw(){var a=null,b=cs,c=Infinity;while(b)b.flush?b=a?a.next=b.next:cs=b.next:(c=Math.min(c,b.then+b.delay),b=(a=b).next);return c}function cz(a,b){var c=a.ownerSVGElement||a;if(c.createSVGPoint){var d=c.createSVGPoint();if(cy<0&&(window.scrollX||window.scrollY)){c=d3.select(document.body).append("svg").style("position","absolute").style("top",0).style("left",0);var e=c[0][0].getScreenCTM();cy=!e.f&&!e.e,c.remove()}return cy?(d.x=b.pageX,d.y=b.pageY):(d.x=b.clientX,d.y=b.clientY),d=d.matrixTransform(a.getScreenCTM().inverse()),[d.x,d.y]}var f=a.getBoundingClientRect();return[b.clientX-f.left-a.clientLeft,b.clientY-f.top-a.clientTop]}function cA(){}function cB(a){var b=a[0],c=a[a.length-1];return b<c?[b,c]:[c,b]}function cC(a){return a.rangeExtent?a.rangeExtent():cB(a.range())}function cD(a,b){var c=0,d=a.length-1,e=a[c],f=a[d],g;f<e&&(g=c,c=d,d=g,g=e,e=f,f=g);if(b=b(f-e))a[c]=b.floor(e),a[d]=b.ceil(f);return a}function cE(){return Math}function cF(a,b,c,d){function g(){var g=Math.min(a.length,b.length)>2?cM:cL,i=d?bi:bh;return e=g(a,b,i,c),f=g(b,a,i,d3.interpolate),h}function h(a){return e(a)}var e,f;return h.invert=function(a){return f(a)},h.domain=function(b){return arguments.length?(a=b.map(Number),g()):a},h.range=function(a){return arguments.length?(b=a,g()):b},h.rangeRound=function(a){return h.range(a).interpolate(d3.interpolateRound)},h.clamp=function(a){return arguments.length?(d=a,g()):d},h.interpolate=function(a){return arguments.length?(c=a,g()):c},h.ticks=function(b){return cJ(a,b)},h.tickFormat=function(b){return cK(a,b)},h.nice=function(){return cD(a,cH),g()},h.copy=function(){return cF(a,b,c,d)},g()}function cG(a,b){return d3.rebind(a,b,"range","rangeRound","interpolate","clamp")}function cH(a){return a=Math.pow(10,Math.round(Math.log(a)/Math.LN10)-1),a&&{floor:function(b){return Math.floor(b/a)*a},ceil:function(b){return Math.ceil(b/a)*a}}}function cI(a,b){var c=cB(a),d=c[1]-c[0],e=Math.pow(10,Math.floor(Math.log(d/b)/Math.LN10)),f=b/d*e;return f<=.15?e*=10:f<=.35?e*=5:f<=.75&&(e*=2),c[0]=Math.ceil(c[0]/e)*e,c[1]=Math.floor(c[1]/e)*e+e*.5,c[2]=e,c}function cJ(a,b){return d3.range.apply(d3,cI(a,b))}function cK(a,b){return d3.format(",."+Math.max(0,-Math.floor(Math.log(cI(a,b)[2])/Math.LN10+.01))+"f")}function cL(a,b,c,d){var e=c(a[0],a[1]),f=d(b[0],b[1]);return function(a){return f(e(a))}}function cM(a,b,c,d){var e=[],f=[],g=0,h=Math.min(a.length,b.length)-1;a[h]<a[0]&&(a=a.slice().reverse(),b=b.slice().reverse());while(++g<=h)e.push(c(a[g-1],a[g])),f.push(d(b[g-1],b[g]));return function(b){var c=d3.bisect(a,b,1,h)-1;return f[c](e[c](b))}}function cN(a,b){function d(c){return a(b(c))}var c=b.pow;return d.invert=function(b){return c(a.invert(b))},d.domain=function(e){return arguments.length?(b=e[0]<0?cQ:cP,c=b.pow,a.domain(e.map(b)),d):a.domain().map(c)},d.nice=function(){return a.domain(cD(a.domain(),cE)),d},d.ticks=function(){var d=cB(a.domain()),e=[];if(d.every(isFinite)){var f=Math.floor(d[0]),g=Math.ceil(d[1]),h=c(d[0]),i=c(d[1]);if(b===cQ){e.push(c(f));for(;f++<g;)for(var j=9;j>0;j--)e.push(c(f)*j)}else{for(;f<g;f++)for(var j=1;j<10;j++)e.push(c(f)*j);e.push(c(f))}for(f=0;e[f]<h;f++);for(g=e.length;e[g-1]>i;g--);e=e.slice(f,g)}return e},d.tickFormat=function(a,e){arguments.length<2&&(e=cO);if(arguments.length<1)return e;var f=Math.max(.1,a/d.ticks().length),g=b===cQ?(h=-1e-12,Math.floor):(h=1e-12,Math.ceil),h;return function(a){return a/c(g(b(a)+h))<=f?e(a):""}},d.copy=function(){return cN(a.copy(),b)},cG(d,a)}function cP(a){return Math.log(a<0?0:a)/Math.LN10}function cQ(a){return-Math.log(a>0?0:-a)/Math.LN10}function cR(a,b){function e(b){return a(c(b))}var c=cS(b),d=cS(1/b);return e.invert=function(b){return d(a.invert(b))},e.domain=function(b){return arguments.length?(a.domain(b.map(c)),e):a.domain().map(d)},e.ticks=function(a){return cJ(e.domain(),a)},e.tickFormat=function(a){return cK(e.domain(),a)},e.nice=function(){return e.domain(cD(e.domain(),cH))},e.exponent=function(a){if(!arguments.length)return b;var f=e.domain();return c=cS(b=a),d=cS(1/b),e.domain(f)},e.copy=function(){return cR(a.copy(),b)},cG(e,a)}function cS(a){return function(b){return b<0?-Math.pow(-b,a):Math.pow(b,a)}}function cT(a,b){function f(b){return d[((c.get(b)||c.set(b,a.push(b)))-1)%d.length]}function g(b,c){return d3.range(a.length).map(function(a){return b+c*a})}var c,d,e;return f.domain=function(d){if(!arguments.length)return a;a=[],c=new j;var e=-1,g=d.length,h;while(++e<g)c.has(h=d[e])||c.set(h,a.push(h));return f[b.t].apply(f,b.a)},f.range=function(a){return arguments.length?(d=a,e=0,b={t:"range",a:arguments},f):d},f.rangePoints=function(c,h){arguments.length<2&&(h=0);var i=c[0],j=c[1],k=(j-i)/(a.length-1+h);return d=g(a.length<2?(i+j)/2:i+k*h/2,k),e=0,b={t:"rangePoints",a:arguments},f},f.rangeBands=function(c,h,i){arguments.length<2&&(h=0),arguments.length<3&&(i=h);var j=c[1]<c[0],k=c[j-0],l=c[1-j],m=(l-k)/(a.length-h+2*i);return d=g(k+m*i,m),j&&d.reverse(),e=m*(1-h),b={t:"rangeBands",a:arguments},f},f.rangeRoundBands=function(c,h,i){arguments.length<2&&(h=0),arguments.length<3&&(i=h);var j=c[1]<c[0],k=c[j-0],l=c[1-j],m=Math.floor((l-k)/(a.length-h+2*i)),n=l-k-(a.length-h)*m;return d=g(k+Math.round(n/2),m),j&&d.reverse(),e=Math.round(m*(1-h)),b={t:"rangeRoundBands",a:arguments},f},f.rangeBand=function(){return e},f.rangeExtent=function(){return cB(b.a[0])},f.copy=function(){return cT(a,b)},f.domain(a)}function cY(a,b){function d(){var d=0,f=a.length,g=b.length;c=[];while(++d<g)c[d-1]=d3.quantile(a,d/g);return e}function e(a){return isNaN(a=+a)?NaN:b[d3.bisect(c,a)]}var c;return e.domain=function(b){return arguments.length?(a=b.filter(function(a){return!isNaN(a)}).sort(d3.ascending),d()):a},e.range=function(a){return arguments.length?(b=a,d()):b},e.quantiles=function(){return c},e.copy=function(){return cY(a,b)},d()}function cZ(a,b,c){function f(b){return c[Math.max(0,Math.min(e,Math.floor(d*(b-a))))]}function g(){return d=c.length/(b-a),e=c.length-1,f}var d,e;return f.domain=function(c){return arguments.length?(a=+c[0],b=+c[c.length-1],g()):[a,b]},f.range=function(a){return arguments.length?(c=a,g()):c},f.copy=function(){return cZ(a,b,c)},g()}function c$(a,b){function c(c){return b[d3.bisect(a,c)]}return c.domain=function(b){return arguments.length?(a=b,c):a},c.range=function(a){return arguments.length?(b=a,c):b},c.copy=function(){return c$(a,b)},c}function c_(a){function b(a){return+a}return b.invert=b,b.domain=b.range=function(c){return arguments.length?(a=c.map(b),b):a},b.ticks=function(b){return cJ(a,b)},b.tickFormat=function(b){return cK(a,b)},b.copy=function(){return c_(a)},b}function dc(a){return a.innerRadius}function dd(a){return a.outerRadius}function de(a){return a.startAngle}function df(a){return a.endAngle}function dg(a){function h(f){function o(){h.push("M",e(a(i),g))}var h=[],i=[],j=-1,k=f.length,l,m=p(b),n=p(c);while(++j<k)d.call(this,l=f[j],j)?i.push([+m.call(this,l,j),+n.call(this,l,j)]):i.length&&(o(),i=[]);return i.length&&o(),h.length?h.join(""):null}var b=dh,c=di,d=o,e=dk,f=e.key,g=.7;return h.x=function(a){return arguments.length?(b=a,h):b},h.y=function(a){return arguments.length?(c=a,h):c},h.defined=function(a){return arguments.length?(d=a,h):d},h.interpolate=function(a){return arguments.length?(typeof a=="function"?f=e=a:f=(e=dj.get(a)||dk).key,h):f},h.tension=function(a){return arguments.length?(g=a,h):g},h}function dh(a){return a[0]}function di(a){return a[1]}function dk(a){return a.join("L")}function dl(a){return dk(a)+"Z"}function dm(a){var b=0,c=a.length,d=a[0],e=[d[0],",",d[1]];while(++b<c)e.push("V",(d=a[b])[1],"H",d[0]);return e.join("")}function dn(a){var b=0,c=a.length,d=a[0],e=[d[0],",",d[1]];while(++b<c)e.push("H",(d=a[b])[0],"V",d[1]);return e.join("")}function dp(a,b){return a.length<4?dk(a):a[1]+ds(a.slice(1,a.length-1),dt(a,b))}function dq(a,b){return a.length<3?dk(a):a[0]+ds((a.push(a[0]),a),dt([a[a.length-2]].concat(a,[a[1]]),b))}function dr(a,b,c){return a.length<3?dk(a):a[0]+ds(a,dt(a,b))}function ds(a,b){if(b.length<1||a.length!=b.length&&a.length!=b.length+2)return dk(a);var c=a.length!=b.length,d="",e=a[0],f=a[1],g=b[0],h=g,i=1;c&&(d+="Q"+(f[0]-g[0]*2/3)+","+(f[1]-g[1]*2/3)+","+f[0]+","+f[1],e=a[1],i=2);if(b.length>1){h=b[1],f=a[i],i++,d+="C"+(e[0]+g[0])+","+(e[1]+g[1])+","+(f[0]-h[0])+","+(f[1]-h[1])+","+f[0]+","+f[1];for(var j=2;j<b.length;j++,i++)f=a[i],h=b[j],d+="S"+(f[0]-h[0])+","+(f[1]-h[1])+","+f[0]+","+f[1]}if(c){var k=a[i];d+="Q"+(f[0]+h[0]*2/3)+","+(f[1]+h[1]*2/3)+","+k[0]+","+k[1]}return d}function dt(a,b){var c=[],d=(1-b)/2,e,f=a[0],g=a[1],h=1,i=a.length;while(++h<i)e=f,f=g,g=a[h],c.push([d*(g[0]-e[0]),d*(g[1]-e[1])]);return c}function du(a){if(a.length<3)return dk(a);var b=1,c=a.length,d=a[0],e=d[0],f=d[1],g=[e,e,e,(d=a[1])[0]],h=[f,f,f,d[1]],i=[e,",",f];dC(i,g,h);while(++b<c)d=a[b],g.shift(),g.push(d[0]),h.shift(),h.push(d[1]),dC(i,g,h);b=-1;while(++b<2)g.shift(),g.push(d[0]),h.shift(),h.push(d[1]),dC(i,g,h);return i.join("")}function dv(a){if(a.length<4)return dk(a);var b=[],c=-1,d=a.length,e,f=[0],g=[0];while(++c<3)e=a[c],f.push(e[0]),g.push(e[1]);b.push(dy(dB,f)+","+dy(dB,g)),--c;while(++c<d)e=a[c],f.shift(),f.push(e[0]),g.shift(),g.push(e[1]),dC(b,f,g);return b.join("")}function dw(a){var b,c=-1,d=a.length,e=d+4,f,g=[],h=[];while(++c<4)f=a[c%d],g.push(f[0]),h.push(f[1]);b=[dy(dB,g),",",dy(dB,h)],--c;while(++c<e)f=a[c%d],g.shift(),g.push(f[0]),h.shift(),h.push(f[1]),dC(b,g,h);return b.join("")}function dx(a,b){var c=a.length-1;if(c){var d=a[0][0],e=a[0][1],f=a[c][0]-d,g=a[c][1]-e,h=-1,i,j;while(++h<=c)i=a[h],j=h/c,i[0]=b*i[0]+(1-b)*(d+j*f),i[1]=b*i[1]+(1-b)*(e+j*g)}return du(a)}function dy(a,b){return a[0]*b[0]+a[1]*b[1]+a[2]*b[2]+a[3]*b[3]}function dC(a,b,c){a.push("C",dy(dz,b),",",dy(dz,c),",",dy(dA,b),",",dy(dA,c),",",dy(dB,b),",",dy(dB,c))}function dD(a,b){return(b[1]-a[1])/(b[0]-a[0])}function dE(a){var b=0,c=a.length-1,d=[],e=a[0],f=a[1],g=d[0]=dD(e,f);while(++b<c)d[b]=(g+(g=dD(e=f,f=a[b+1])))/2;return d[b]=g,d}function dF(a){var b=[],c,d,e,f,g=dE(a),h=-1,i=a.length-1;while(++h<i)c=dD(a[h],a[h+1]),Math.abs(c)<1e-6?g[h]=g[h+1]=0:(d=g[h]/c,e=g[h+1]/c,f=d*d+e*e,f>9&&(f=c*3/Math.sqrt(f),g[h]=f*d,g[h+1]=f*e));h=-1;while(++h<=i)f=(a[Math.min(i,h+1)][0]-a[Math.max(0,h-1)][0])/(6*(1+g[h]*g[h])),b.push([f||0,g[h]*f||0]);return b}function dG(a){return a.length<3?dk(a):a[0]+ds(a,dF(a))}function dH(a){var b,c=-1,d=a.length,e,f;while(++c<d)b=a[c],e=b[0],f=b[1]+da,b[0]=e*Math.cos(f),b[1]=e*Math.sin(f);return a}function dI(a){function l(h){function y(){l.push("M",g(a(n),k),j,i(a(m.reverse()),k),"Z")}var l=[],m=[],n=[],o=-1,q=h.length,r,s=p(b),t=p(d),u=b===c?function(){return w}:p(c),v=d===e?function(){return x}:p(e),w,x;while(++o<q)f.call(this,r=h[o],o)?(m.push([w=+s.call(this,r,o),x=+t.call(this,r,o)]),n.push([+u.call(this,r,o),+v.call(this,r,o)])):m.length&&(y(),m=[],n=[]);return m.length&&y(),l.length?l.join(""):null}var b=dh,c=dh,d=0,e=di,f=o,g=dk,h=g.key,i=g,j="L",k=.7;return l.x=function(a){return arguments.length?(b=c=a,l):c},l.x0=function(a){return arguments.length?(b=a,l):b},l.x1=function(a){return arguments.length?(c=a,l):c},l.y=function(a){return arguments.length?(d=e=a,l):e},l.y0=function(a){return arguments.length?(d=a,l):d},l.y1=function(a){return arguments.length?(e=a,l):e},l.defined=function(a){return arguments.length?(f=a,l):f},l.interpolate=function(a){return arguments.length?(typeof a=="function"?h=g=a:h=(g=dj.get(a)||dk).key,i=g.reverse||g,j=g.closed?"M":"L",l):h},l.tension=function(a){return arguments.length?(k=a,l):k},l}function dJ(a){return a.source}function dK(a){return a.target}function dL(a){return a.radius}function dM(a){return a.startAngle}function dN(a){return a.endAngle}function dO(a){return[a.x,a.y]}function dP(a){return function(){var b=a.apply(this,arguments),c=b[0],d=b[1]+da;return[c*Math.cos(d),c*Math.sin(d)]}}function dQ(){return 64}function dR(){return"circle"}function dS(a){var b=Math.sqrt(a/Math.PI);return"M0,"+b+"A"+b+","+b+" 0 1,1 0,"+ -b+"A"+b+","+b+" 0 1,1 0,"+b+"Z"}function dW(a,b){a.attr("transform",function(a){return"translate("+b(a)+",0)"})}function dX(a,b){a.attr("transform",function(a){return"translate(0,"+b(a)+")"})}function dY(a,b,c){e=[];if(c&&b.length>1){var d=cB(a.domain()),e,f=-1,g=b.length,h=(b[1]-b[0])/++c,i,j;while(++f<g)for(i=c;--i>0;)(j=+b[f]-i*h)>=d[0]&&e.push(j);for(--f,i=0;++i<c&&(j=+b[f]+i*h)<d[1];)e.push(j)}return e}function eb(){d_||(d_=d3.select("body").append("div").style("visibility","hidden").style("top",0).style("height",0).style("width",0).style("overflow-y","scroll").append("div").style("height","2000px").node().parentNode);var a=d3.event,b;try{d_.scrollTop=1e3,d_.dispatchEvent(a),b=1e3-d_.scrollTop}catch(c){b=a.wheelDelta||-a.detail*5}return b}function ec(a){var b=a.source,c=a.target,d=ee(b,c),e=[b];while(b!==d)b=b.parent,e.push(b);var f=e.length;while(c!==d)e.splice(f,0,c),c=c.parent;return e}function ed(a){var b=[],c=a.parent;while(c!=null)b.push(a),a=c,c=c.parent;return b.push(a),b}function ee(a,b){if(a===b)return a;var c=ed(a),d=ed(b),e=c.pop(),f=d.pop(),g=null;while(e===f)g=e,e=c.pop(),f=d.pop();return g}function eh(a){a.fixed|=2}function ei(a){a!==eg&&(a.fixed&=1)}function ej(){eg.fixed&=1,ef=eg=null}function ek(){eg.px=d3.event.x,eg.py=d3.event.y,ef.resume()}function el(a,b,c){var d=0,e=0;a.charge=0;if(!a.leaf){var f=a.nodes,g=f.length,h=-1,i;while(++h<g){i=f[h];if(i==null)continue;el(i,b,c),a.charge+=i.charge,d+=i.charge*i.cx,e+=i.charge*i.cy}}if(a.point){a.leaf||(a.point.x+=Math.random()-.5,a.point.y+=Math.random()-.5);var j=b*c[a.point.index];a.charge+=a.pointCharge=j,d+=j*a.point.x,e+=j*a.point.y}a.cx=d/a.charge,a.cy=e/a.charge}function em(a){return 20}function en(a){return 1}function ep(a){return a.x}function eq(a){return a.y}function er(a,b,c){a.y0=b,a.y=c}function eu(a){return d3.range(a.length)}function ev(a){var b=-1,c=a[0].length,d=[];while(++b<c)d[b]=0;return d}function ew(a){var b=1,c=0,d=a[0][1],e,f=a.length;for(;b<f;++b)(e=a[b][1])>d&&(c=b,d=e);return c}function ex(a){return a.reduce(ey,0)}function ey(a,b){return a+b[1]}function ez(a,b){return eA(a,Math.ceil(Math.log(b.length)/Math.LN2+1))}function eA(a,b){var c=-1,d=+a[0],e=(a[1]-d)/b,f=[];while(++c<=b)f[c]=e*c+d;return f}function eB(a){return[d3.min(a),d3.max(a)]}function eC(a,b){return d3.rebind(a,b,"sort","children","value"),a.links=eG,a.nodes=function(b){return eH=!0,(a.nodes=a)(b)},a}function eD(a){return a.children}function eE(a){return a.value}function eF(a,b){return b.value-a.value}function eG(a){return d3.merge(a.map(function(a){return(a.children||[]).map(function(b){return{source:a,target:b}})}))}function eI(a,b){return a.value-b.value}function eJ(a,b){var c=a._pack_next;a._pack_next=b,b._pack_prev=a,b._pack_next=c,c._pack_prev=b}function eK(a,b){a._pack_next=b,b._pack_prev=a}function eL(a,b){var c=b.x-a.x,d=b.y-a.y,e=a.r+b.r;return e*e-c*c-d*d>.001}function eM(a){function n(a){c=Math.min(a.x-a.r,c),d=Math.max(a.x+a.r,d),e=Math.min(a.y-a.r,e),f=Math.max(a.y+a.r,f)}if(!(b=a.children)||!(m=b.length))return;var b,c=Infinity,d=-Infinity,e=Infinity,f=-Infinity,g,h,i,j,k,l,m;b.forEach(eN),g=b[0],g.x=-g.r,g.y=0,n(g);if(m>1){h=b[1],h.x=h.r,h.y=0,n(h);if(m>2){i=b[2],eQ(g,h,i),n(i),eJ(g,i),g._pack_prev=i,eJ(i,h),h=g._pack_next;for(j=3;j<m;j++){eQ(g,h,i=b[j]);var o=0,p=1,q=1;for(k=h._pack_next;k!==h;k=k._pack_next,p++)if(eL(k,i)){o=1;break}if(o==1)for(l=g._pack_prev;l!==k._pack_prev;l=l._pack_prev,q++)if(eL(l,i))break;o?(p<q||p==q&&h.r<g.r?eK(g,h=k):eK(g=l,h),j--):(eJ(g,i),h=i,n(i))}}}var r=(c+d)/2,s=(e+f)/2,t=0;for(j=0;j<m;j++)i=b[j],i.x-=r,i.y-=s,t=Math.max(t,i.r+Math.sqrt(i.x*i.x+i.y*i.y));a.r=t,b.forEach(eO)}function eN(a){a._pack_next=a._pack_prev=a}function eO(a){delete a._pack_next,delete a._pack_prev}function eP(a,b,c,d){var e=a.children;a.x=b+=d*a.x,a.y=c+=d*a.y,a.r*=d;if(e){var f=-1,g=e.length;while(++f<g)eP(e[f],b,c,d)}}function eQ(a,b,c){var d=a.r+c.r,e=b.x-a.x,f=b.y-a.y;if(d&&(e||f)){var g=b.r+c.r,h=e*e+f*f;g*=g,d*=d;var i=.5+(d-g)/(2*h),j=Math.sqrt(Math.max(0,2*g*(d+h)-(d-=h)*d-g*g))/(2*h);c.x=a.x+i*e+j*f,c.y=a.y+i*f-j*e}else c.x=a.x+d,c.y=a.y}function eR(a){return 1+d3.max(a,function(a){return a.y})}function eS(a){return a.reduce(function(a,b){return a+b.x},0)/a.length}function eT(a){var b=a.children;return b&&b.length?eT(b[0]):a}function eU(a){var b=a.children,c;return b&&(c=b.length)?eU(b[c-1]):a}function eV(a,b){return a.parent==b.parent?1:2}function eW(a){var b=a.children;return b&&b.length?b[0]:a._tree.thread}function eX(a){var b=a.children,c;return b&&(c=b.length)?b[c-1]:a._tree.thread}function eY(a,b){var c=a.children;if(c&&(e=c.length)){var d,e,f=-1;while(++f<e)b(d=eY(c[f],b),a)>0&&(a=d)}return a}function eZ(a,b){return a.x-b.x}function e$(a,b){return b.x-a.x}function e_(a,b){return a.depth-b.depth}function fa(a,b){function c(a,d){var e=a.children;if(e&&(i=e.length)){var f,g=null,h=-1,i;while(++h<i)f=e[h],c(f,g),g=f}b(a,d)}c(a,null)}function fb(a){var b=0,c=0,d=a.children,e=d.length,f;while(--e>=0)f=d[e]._tree,f.prelim+=b,f.mod+=b,b+=f.shift+(c+=f.change)}function fc(a,b,c){a=a._tree,b=b._tree;var d=c/(b.number-a.number);a.change+=d,b.change-=d,b.shift+=c,b.prelim+=c,b.mod+=c}function fd(a,b,c){return a._tree.ancestor.parent==b.parent?a._tree.ancestor:c}function fe(a){return{x:a.x,y:a.y,dx:a.dx,dy:a.dy}}function ff(a,b){var c=a.x+b[3],d=a.y+b[0],e=a.dx-b[1]-b[3],f=a.dy-b[0]-b[2];return e<0&&(c+=e/2,e=0),f<0&&(d+=f/2,f=0),{x:c,y:d,dx:e,dy:f}}function fg(a,b){function f(a,c){d3.text(a,b,function(a){c(a&&f.parse(a))})}function g(b){return b.map(h).join(a)}function h(a){return d.test(a)?'"'+a.replace(/\"/g,'""')+'"':a}var c=new RegExp("\r\n|["+a+"\r\n]","g"),d=new RegExp('["'+a+"\n]"),e=a.charCodeAt(0);return f.parse=function(a){var b;return f.parseRows(a,function(a,c){if(c){var d={},e=-1,f=b.length;while(++e<f)d[b[e]]=a[e];return d}return b=a,null})},f.parseRows=function(a,b){function k(){if(c.lastIndex>=a.length)return f;if(j)return j=!1,d;var b=c.lastIndex;if(a.charCodeAt(b)===34){var g=b;while(g++<a.length)if(a.charCodeAt(g)===34){if(a.charCodeAt(g+1)!==34)break;g++}c.lastIndex=g+2;var h=a.charCodeAt(g+1);return h===13?(j=!0,a.charCodeAt(g+2)===10&&c.lastIndex++):h===10&&(j=!0),a.substring(b+1,g).replace(/""/g,'"')}var i=c.exec(a);return i?(j=i[0].charCodeAt(0)!==e,a.substring(b,i.index)):(c.lastIndex=a.length,a.substring(b))}var d={},f={},g=[],h=0,i,j;c.lastIndex=0;while((i=k())!==f){var l=[];while(i!==d&&i!==f)l.push(i),i=k();if(b&&!(l=b(l,h++)))continue;g.push(l)}return g},f.format=function(a){return a.map(g).join("\n")},f}function fi(a,b){return function(c){return c&&a.hasOwnProperty(c.type)?a[c.type](c):b}}function fj(a){return"m0,"+a+"a"+a+","+a+" 0 1,1 0,"+ -2*a+"a"+a+","+a+" 0 1,1 0,"+2*a+"z"}function fk(a,b){fl.hasOwnProperty(a.type)&&fl[a.type](a,b)}function fm(a,b){fk(a.geometry,b)}function fn(a,b){for(var c=a.features,d=0,e=c.length;d<e;d++)fk(c[d].geometry,b)}function fo(a,b){for(var c=a.geometries,d=0,e=c.length;d<e;d++)fk(c[d],b)}function fp(a,b){for(var c=a.coordinates,d=0,e=c.length;d<e;d++)b.apply(null,c[d])}function fq(a,b){for(var c=a.coordinates,d=0,e=c.length;d<e;d++)for(var f=c[d],g=0,h=f.length;g<h;g++)b.apply(null,f[g])}function fr(a,b){for(var c=a.coordinates,d=0,e=c.length;d<e;d++)for(var f=c[d][0],g=0,h=f.length;g<h;g++)b.apply(null,f[g])}function fs(a,b){b.apply(null,a.coordinates)}function ft(a,b){for(var c=a.coordinates[0],d=0,e=c.length;d<e;d++)b.apply(null,c[d])}function fu(a){return a.source}function fv(a){return a.target}function fw(){function o(a){var b=Math.sin(a*=m)*n,c=Math.sin(m-a)*n,g=c*e+b*k,h=c*f+b*l,i=c*d+b*j;return[Math.atan2(h,g)/fh,Math.atan2(i,Math.sqrt(g*g+h*h))/fh]}var a,b,c,d,e,f,g,h,i,j,k,l,m,n;return o.distance=function(){return m==null&&(n=1/Math.sin(m=Math.acos(Math.max(-1,Math.min(1,d*j+c*i*Math.cos(g-a)))))),m},o.source=function(g){var h=Math.cos(a=g[0]*fh),i=Math.sin(a);return c=Math.cos(b=g[1]*fh),d=Math.sin(b),e=c*h,f=c*i,m=null,o},o.target=function(a){var b=Math.cos(g=a[0]*fh),c=Math.sin(g);return i=Math.cos(h=a[1]*fh),j=Math.sin(h),k=i*b,l=i*c,m=null,o},o}function fx(a,b){var c=fw().source(a).target(b);return c.distance(),c}function fA(a){var b=0,c=0;for(;;){if(a(b,c))return[b,c];b===0?(b=c+1,c=0):(b-=1,c+=1)}}function fB(a,b,c,d){var e,f,g,h,i,j,k;return e=d[a],f=e[0],g=e[1],e=d[b],h=e[0],i=e[1],e=d[c],j=e[0],k=e[1],(k-g)*(h-f)-(i-g)*(j-f)>0}function fC(a,b,c){return(c[0]-b[0])*(a[1]-b[1])<(c[1]-b[1])*(a[0]-b[0])}function fD(a,b,c,d){var e=a[0],f=b[0],g=c[0],h=d[0],i=a[1],j=b[1],k=c[1],l=d[1],m=e-g,n=f-e,o=h-g,p=i-k,q=j-i,r=l-k,s=(o*p-r*m)/(r*n-o*q);return[e+s*n,i+s*q]}function fF(a,b){var c={list:a.map(function(a,b){return{index:b,x:a[0],y:a[1]}}).sort(function(a,b){return a.y<b.y?-1:a.y>b.y?1:a.x<b.x?-1:a.x>b.x?1:0}),bottomSite:null},d={list:[],leftEnd:null,rightEnd:null,init:function(){d.leftEnd=d.createHalfEdge(null,"l"),d.rightEnd=d.createHalfEdge(null,"l"),d.leftEnd.r=d.rightEnd,d.rightEnd.l=d.leftEnd,d.list.unshift(d.leftEnd,d.rightEnd)},createHalfEdge:function(a,b){return{edge:a,side:b,vertex:null,l:null,r:null}},insert:function(a,b){b.l=a,b.r=a.r,a.r.l=b,a.r=b},leftBound:function(a){var b=d.leftEnd;do b=b.r;while(b!=d.rightEnd&&e.rightOf(b,a));return b=b.l,b},del:function(a){a.l.r=a.r,a.r.l=a.l,a.edge=null},right:function(a){return a.r},left:function(a){return a.l},leftRegion:function(a){return a.edge==null?c.bottomSite:a.edge.region[a.side]},rightRegion:function(a){return a.edge==null?c.bottomSite:a.edge.region[fE[a.side]]}},e={bisect:function(a,b){var c={region:{l:a,r:b},ep:{l:null,r:null}},d=b.x-a.x,e=b.y-a.y,f=d>0?d:-d,g=e>0?e:-e;return c.c=a.x*d+a.y*e+(d*d+e*e)*.5,f>g?(c.a=1,c.b=e/d,c.c/=d):(c.b=1,c.a=d/e,c.c/=e),c},intersect:function(a,b){var c=a.edge,d=b.edge;if(!c||!d||c.region.r==d.region.r)return null;var e=c.a*d.b-c.b*d.a;if(Math.abs(e)<1e-10)return null;var f=(c.c*d.b-d.c*c.b)/e,g=(d.c*c.a-c.c*d.a)/e,h=c.region.r,i=d.region.r,j,k;h.y<i.y||h.y==i.y&&h.x<i.x?(j=a,k=c):(j=b,k=d);var l=f>=k.region.r.x;return l&&j.side==="l"||!l&&j.side==="r"?null:{x:f,y:g}},rightOf:function(a,b){var c=a.edge,d=c.region.r,e=b.x>d.x;if(e&&a.side==="l")return 1;if(!e&&a.side==="r")return 0;if(c.a===1){var f=b.y-d.y,g=b.x-d.x,h=0,i=0;!e&&c.b<0||e&&c.b>=0?i=h=f>=c.b*g:(i=b.x+b.y*c.b>c.c,c.b<0&&(i=!i),i||(h=1));if(!h){var j=d.x-c.region.l.x;i=c.b*(g*g-f*f)<j*f*(1+2*g/j+c.b*c.b),c.b<0&&(i=!i)}}else{var k=c.c-c.a*b.x,l=b.y-k,m=b.x-d.x,n=k-d.y;i=l*l>m*m+n*n}return a.side==="l"?i:!i},endPoint:function(a,c,d){a.ep[c]=d;if(!a.ep[fE[c]])return;b(a)},distance:function(a,b){var c=a.x-b.x,d=a.y-b.y;return Math.sqrt(c*c+d*d)}},f={list:[],insert:function(a,b,c){a.vertex=b,a.ystar=b.y+c;for(var d=0,e=f.list,g=e.length;d<g;d++){var h=e[d];if(a.ystar>h.ystar||a.ystar==h.ystar&&b.x>h.vertex.x)continue;break}e.splice(d,0,a)},del:function(a){for(var b=0,c=f.list,d=c.length;b<d&&c[b]!=a;++b);c.splice(b,1)},empty:function(){return f.list.length===0},nextEvent:function(a){for(var b=0,c=f.list,d=c.length;b<d;++b)if(c[b]==a)return c[b+1];return null},min:function(){var a=f.list[0];return{x:a.vertex.x,y:a.ystar}},extractMin:function(){return f.list.shift()}};d.init(),c.bottomSite=c.list.shift();var g=c.list.shift(),h,i,j,k,l,m,n,o,p,q,r,s,t;for(;;){f.empty()||(h=f.min());if(g&&(f.empty()||g.y<h.y||g.y==h.y&&g.x<h.x))i=d.leftBound(g),j=d.right(i),n=d.rightRegion(i),s=e.bisect(n,g),m=d.createHalfEdge(s,"l"),d.insert(i,m),q=e.intersect
|
|
(i,m),q&&(f.del(i),f.insert(i,q,e.distance(q,g))),i=m,m=d.createHalfEdge(s,"r"),d.insert(i,m),q=e.intersect(m,j),q&&f.insert(m,q,e.distance(q,g)),g=c.list.shift();else if(!f.empty())i=f.extractMin(),k=d.left(i),j=d.right(i),l=d.right(j),n=d.leftRegion(i),o=d.rightRegion(j),r=i.vertex,e.endPoint(i.edge,i.side,r),e.endPoint(j.edge,j.side,r),d.del(i),f.del(j),d.del(j),t="l",n.y>o.y&&(p=n,n=o,o=p,t="r"),s=e.bisect(n,o),m=d.createHalfEdge(s,t),d.insert(k,m),e.endPoint(s,fE[t],r),q=e.intersect(k,m),q&&(f.del(k),f.insert(k,q,e.distance(q,n))),q=e.intersect(m,l),q&&f.insert(m,q,e.distance(q,n));else break}for(i=d.right(d.leftEnd);i!=d.rightEnd;i=d.right(i))b(i.edge)}function fG(){return{leaf:!0,nodes:[],point:null}}function fH(a,b,c,d,e,f){if(!a(b,c,d,e,f)){var g=(c+e)*.5,h=(d+f)*.5,i=b.nodes;i[0]&&fH(a,i[0],c,d,g,h),i[1]&&fH(a,i[1],g,d,e,h),i[2]&&fH(a,i[2],c,h,g,f),i[3]&&fH(a,i[3],g,h,e,f)}}function fI(a){return{x:a[0],y:a[1]}}function fL(){this._=new Date(arguments.length>1?Date.UTC.apply(this,arguments):arguments[0])}function fU(a){return a.substring(0,3)}function fV(a,b,c,d){var e,f,g=0,h=b.length,i=c.length;while(g<h){if(d>=i)return-1;e=b.charCodeAt(g++);if(e==37){f=gh[b.charAt(g++)];if(!f||(d=f(a,c,d))<0)return-1}else if(e!=c.charCodeAt(d++))return-1}return d}function fW(a){return new RegExp("^(?:"+a.map(d3.requote).join("|")+")","i")}function fX(a){var b=new j,c=-1,d=a.length;while(++c<d)b.set(a[c].toLowerCase(),c);return b}function gi(a,b,c){gb.lastIndex=0;var d=gb.exec(b.substring(c));return d?c+=d[0].length:-1}function gj(a,b,c){ga.lastIndex=0;var d=ga.exec(b.substring(c));return d?c+=d[0].length:-1}function gk(a,b,c){ge.lastIndex=0;var d=ge.exec(b.substring(c));return d?(a.m=gf.get(d[0].toLowerCase()),c+=d[0].length):-1}function gl(a,b,c){gc.lastIndex=0;var d=gc.exec(b.substring(c));return d?(a.m=gd.get(d[0].toLowerCase()),c+=d[0].length):-1}function gm(a,b,c){return fV(a,gg.c.toString(),b,c)}function gn(a,b,c){return fV(a,gg.x.toString(),b,c)}function go(a,b,c){return fV(a,gg.X.toString(),b,c)}function gp(a,b,c){gy.lastIndex=0;var d=gy.exec(b.substring(c,c+4));return d?(a.y=+d[0],c+=d[0].length):-1}function gq(a,b,c){gy.lastIndex=0;var d=gy.exec(b.substring(c,c+2));return d?(a.y=gr(+d[0]),c+=d[0].length):-1}function gr(a){return a+(a>68?1900:2e3)}function gs(a,b,c){gy.lastIndex=0;var d=gy.exec(b.substring(c,c+2));return d?(a.m=d[0]-1,c+=d[0].length):-1}function gt(a,b,c){gy.lastIndex=0;var d=gy.exec(b.substring(c,c+2));return d?(a.d=+d[0],c+=d[0].length):-1}function gu(a,b,c){gy.lastIndex=0;var d=gy.exec(b.substring(c,c+2));return d?(a.H=+d[0],c+=d[0].length):-1}function gv(a,b,c){gy.lastIndex=0;var d=gy.exec(b.substring(c,c+2));return d?(a.M=+d[0],c+=d[0].length):-1}function gw(a,b,c){gy.lastIndex=0;var d=gy.exec(b.substring(c,c+2));return d?(a.S=+d[0],c+=d[0].length):-1}function gx(a,b,c){gy.lastIndex=0;var d=gy.exec(b.substring(c,c+3));return d?(a.L=+d[0],c+=d[0].length):-1}function gz(a,b,c){var d=gA.get(b.substring(c,c+=2).toLowerCase());return d==null?-1:(a.p=d,c)}function gB(a){var b=a.getTimezoneOffset(),c=b>0?"-":"+",d=~~(Math.abs(b)/60),e=Math.abs(b)%60;return c+fY(d)+fY(e)}function gD(a){return a.toISOString()}function gE(a,b,c){function d(b){var c=a(b),d=f(c,1);return b-c<d-b?c:d}function e(c){return b(c=a(new fJ(c-1)),1),c}function f(a,c){return b(a=new fJ(+a),c),a}function g(a,d,f){var g=e(a),h=[];if(f>1)while(g<d)c(g)%f||h.push(new Date(+g)),b(g,1);else while(g<d)h.push(new Date(+g)),b(g,1);return h}function h(a,b,c){try{fJ=fL;var d=new fL;return d._=a,g(d,b,c)}finally{fJ=Date}}a.floor=a,a.round=d,a.ceil=e,a.offset=f,a.range=g;var i=a.utc=gF(a);return i.floor=i,i.round=gF(d),i.ceil=gF(e),i.offset=gF(f),i.range=h,a}function gF(a){return function(b,c){try{fJ=fL;var d=new fL;return d._=b,a(d,c)._}finally{fJ=Date}}}function gG(a,b,c){function d(b){return a(b)}return d.invert=function(b){return gI(a.invert(b))},d.domain=function(b){return arguments.length?(a.domain(b),d):a.domain().map(gI)},d.nice=function(a){return d.domain(cD(d.domain(),function(){return a}))},d.ticks=function(c,e){var f=gH(d.domain());if(typeof c!="function"){var g=f[1]-f[0],h=g/c,i=d3.bisect(gM,h);if(i==gM.length)return b.year(f,c);if(!i)return a.ticks(c).map(gI);Math.log(h/gM[i-1])<Math.log(gM[i]/h)&&--i,c=b[i],e=c[1],c=c[0].range}return c(f[0],new Date(+f[1]+1),e)},d.tickFormat=function(){return c},d.copy=function(){return gG(a.copy(),b,c)},d3.rebind(d,a,"range","rangeRound","interpolate","clamp")}function gH(a){var b=a[0],c=a[a.length-1];return b<c?[b,c]:[c,b]}function gI(a){return new Date(a)}function gJ(a){return function(b){var c=a.length-1,d=a[c];while(!d[1](b))d=a[--c];return d[0](b)}}function gK(a){var b=new Date(a,0,1);return b.setFullYear(a),b}function gL(a){var b=a.getFullYear(),c=gK(b),d=gK(b+1);return b+(a-c)/(d-c)}function gU(a){var b=new Date(Date.UTC(a,0,1));return b.setUTCFullYear(a),b}function gV(a){var b=a.getUTCFullYear(),c=gU(b),d=gU(b+1);return b+(a-c)/(d-c)}Date.now||(Date.now=function(){return+(new Date)});try{document.createElement("div").style.setProperty("opacity",0,"")}catch(a){var b=CSSStyleDeclaration.prototype,c=b.setProperty;b.setProperty=function(a,b,d){c.call(this,a,b+"",d)}}d3={version:"2.10.0"};var e=g;try{e(document.documentElement.childNodes)[0].nodeType}catch(h){e=f}var i=[].__proto__?function(a,b){a.__proto__=b}:function(a,b){for(var c in b)a[c]=b[c]};d3.map=function(a){var b=new j;for(var c in a)b.set(c,a[c]);return b},d(j,{has:function(a){return k+a in this},get:function(a){return this[k+a]},set:function(a,b){return this[k+a]=b},remove:function(a){return a=k+a,a in this&&delete this[a]},keys:function(){var a=[];return this.forEach(function(b){a.push(b)}),a},values:function(){var a=[];return this.forEach(function(b,c){a.push(c)}),a},entries:function(){var a=[];return this.forEach(function(b,c){a.push({key:b,value:c})}),a},forEach:function(a){for(var b in this)b.charCodeAt(0)===l&&a.call(this,b.substring(1),this[b])}});var k="\0",l=k.charCodeAt(0);d3.functor=p,d3.rebind=function(a,b){var c=1,d=arguments.length,e;while(++c<d)a[e=arguments[c]]=q(a,b,b[e]);return a},d3.ascending=function(a,b){return a<b?-1:a>b?1:a>=b?0:NaN},d3.descending=function(a,b){return b<a?-1:b>a?1:b>=a?0:NaN},d3.mean=function(a,b){var c=a.length,d,e=0,f=-1,g=0;if(arguments.length===1)while(++f<c)r(d=a[f])&&(e+=(d-e)/++g);else while(++f<c)r(d=b.call(a,a[f],f))&&(e+=(d-e)/++g);return g?e:undefined},d3.median=function(a,b){return arguments.length>1&&(a=a.map(b)),a=a.filter(r),a.length?d3.quantile(a.sort(d3.ascending),.5):undefined},d3.min=function(a,b){var c=-1,d=a.length,e,f;if(arguments.length===1){while(++c<d&&((e=a[c])==null||e!=e))e=undefined;while(++c<d)(f=a[c])!=null&&e>f&&(e=f)}else{while(++c<d&&((e=b.call(a,a[c],c))==null||e!=e))e=undefined;while(++c<d)(f=b.call(a,a[c],c))!=null&&e>f&&(e=f)}return e},d3.max=function(a,b){var c=-1,d=a.length,e,f;if(arguments.length===1){while(++c<d&&((e=a[c])==null||e!=e))e=undefined;while(++c<d)(f=a[c])!=null&&f>e&&(e=f)}else{while(++c<d&&((e=b.call(a,a[c],c))==null||e!=e))e=undefined;while(++c<d)(f=b.call(a,a[c],c))!=null&&f>e&&(e=f)}return e},d3.extent=function(a,b){var c=-1,d=a.length,e,f,g;if(arguments.length===1){while(++c<d&&((e=g=a[c])==null||e!=e))e=g=undefined;while(++c<d)(f=a[c])!=null&&(e>f&&(e=f),g<f&&(g=f))}else{while(++c<d&&((e=g=b.call(a,a[c],c))==null||e!=e))e=undefined;while(++c<d)(f=b.call(a,a[c],c))!=null&&(e>f&&(e=f),g<f&&(g=f))}return[e,g]},d3.random={normal:function(a,b){var c=arguments.length;return c<2&&(b=1),c<1&&(a=0),function(){var c,d,e;do c=Math.random()*2-1,d=Math.random()*2-1,e=c*c+d*d;while(!e||e>1);return a+b*c*Math.sqrt(-2*Math.log(e)/e)}},logNormal:function(a,b){var c=arguments.length;c<2&&(b=1),c<1&&(a=0);var d=d3.random.normal();return function(){return Math.exp(a+b*d())}},irwinHall:function(a){return function(){for(var b=0,c=0;c<a;c++)b+=Math.random();return b/a}}},d3.sum=function(a,b){var c=0,d=a.length,e,f=-1;if(arguments.length===1)while(++f<d)isNaN(e=+a[f])||(c+=e);else while(++f<d)isNaN(e=+b.call(a,a[f],f))||(c+=e);return c},d3.quantile=function(a,b){var c=(a.length-1)*b+1,d=Math.floor(c),e=a[d-1],f=c-d;return f?e+f*(a[d]-e):e},d3.transpose=function(a){return d3.zip.apply(d3,a)},d3.zip=function(){if(!(e=arguments.length))return[];for(var a=-1,b=d3.min(arguments,s),c=new Array(b);++a<b;)for(var d=-1,e,f=c[a]=new Array(e);++d<e;)f[d]=arguments[d][a];return c},d3.bisector=function(a){return{left:function(b,c,d,e){arguments.length<3&&(d=0),arguments.length<4&&(e=b.length);while(d<e){var f=d+e>>>1;a.call(b,b[f],f)<c?d=f+1:e=f}return d},right:function(b,c,d,e){arguments.length<3&&(d=0),arguments.length<4&&(e=b.length);while(d<e){var f=d+e>>>1;c<a.call(b,b[f],f)?e=f:d=f+1}return d}}};var t=d3.bisector(function(a){return a});d3.bisectLeft=t.left,d3.bisect=d3.bisectRight=t.right,d3.first=function(a,b){var c=0,d=a.length,e=a[0],f;arguments.length===1&&(b=d3.ascending);while(++c<d)b.call(a,e,f=a[c])>0&&(e=f);return e},d3.last=function(a,b){var c=0,d=a.length,e=a[0],f;arguments.length===1&&(b=d3.ascending);while(++c<d)b.call(a,e,f=a[c])<=0&&(e=f);return e},d3.nest=function(){function f(c,g){if(g>=b.length)return e?e.call(a,c):d?c.sort(d):c;var h=-1,i=c.length,k=b[g++],l,m,n=new j,o,p={};while(++h<i)(o=n.get(l=k(m=c[h])))?o.push(m):n.set(l,[m]);return n.forEach(function(a){p[a]=f(n.get(a),g)}),p}function g(a,d){if(d>=b.length)return a;var e=[],f=c[d++],h;for(h in a)e.push({key:h,values:g(a[h],d)});return f&&e.sort(function(a,b){return f(a.key,b.key)}),e}var a={},b=[],c=[],d,e;return a.map=function(a){return f(a,0)},a.entries=function(a){return g(f(a,0),0)},a.key=function(c){return b.push(c),a},a.sortKeys=function(d){return c[b.length-1]=d,a},a.sortValues=function(b){return d=b,a},a.rollup=function(b){return e=b,a},a},d3.keys=function(a){var b=[];for(var c in a)b.push(c);return b},d3.values=function(a){var b=[];for(var c in a)b.push(a[c]);return b},d3.entries=function(a){var b=[];for(var c in a)b.push({key:c,value:a[c]});return b},d3.permute=function(a,b){var c=[],d=-1,e=b.length;while(++d<e)c[d]=a[b[d]];return c},d3.merge=function(a){return Array.prototype.concat.apply([],a)},d3.split=function(a,b){var c=[],d=[],e,f=-1,g=a.length;arguments.length<2&&(b=u);while(++f<g)b.call(d,e=a[f],f)?d=[]:(d.length||c.push(d),d.push(e));return c},d3.range=function(a,b,c){arguments.length<3&&(c=1,arguments.length<2&&(b=a,a=0));if((b-a)/c===Infinity)throw new Error("infinite range");var d=[],e=w(Math.abs(c)),f=-1,g;a*=e,b*=e,c*=e;if(c<0)while((g=a+c*++f)>b)d.push(g/e);else while((g=a+c*++f)<b)d.push(g/e);return d},d3.requote=function(a){return a.replace(x,"\\$&")};var x=/[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;d3.round=function(a,b){return b?Math.round(a*(b=Math.pow(10,b)))/b:Math.round(a)},d3.xhr=function(a,b,c){var d=new XMLHttpRequest;arguments.length<3?(c=b,b=null):b&&d.overrideMimeType&&d.overrideMimeType(b),d.open("GET",a,!0),b&&d.setRequestHeader("Accept",b),d.onreadystatechange=function(){if(d.readyState===4){var a=d.status;c(!a&&d.response||a>=200&&a<300||a===304?d:null)}},d.send(null)},d3.text=function(a,b,c){function d(a){c(a&&a.responseText)}arguments.length<3&&(c=b,b=null),d3.xhr(a,b,d)},d3.json=function(a,b){d3.text(a,"application/json",function(a){b(a?JSON.parse(a):null)})},d3.html=function(a,b){d3.text(a,"text/html",function(a){if(a!=null){var c=document.createRange();c.selectNode(document.body),a=c.createContextualFragment(a)}b(a)})},d3.xml=function(a,b,c){function d(a){c(a&&a.responseXML)}arguments.length<3&&(c=b,b=null),d3.xhr(a,b,d)};var y={svg:"http://www.w3.org/2000/svg",xhtml:"http://www.w3.org/1999/xhtml",xlink:"http://www.w3.org/1999/xlink",xml:"http://www.w3.org/XML/1998/namespace",xmlns:"http://www.w3.org/2000/xmlns/"};d3.ns={prefix:y,qualify:function(a){var b=a.indexOf(":"),c=a;return b>=0&&(c=a.substring(0,b),a=a.substring(b+1)),y.hasOwnProperty(c)?{space:y[c],local:a}:a}},d3.dispatch=function(){var a=new z,b=-1,c=arguments.length;while(++b<c)a[arguments[b]]=A(a);return a},z.prototype.on=function(a,b){var c=a.indexOf("."),d="";return c>0&&(d=a.substring(c+1),a=a.substring(0,c)),arguments.length<2?this[a].on(d):this[a].on(d,b)},d3.format=function(a){var b=B.exec(a),c=b[1]||" ",d=b[3]||"",e=b[5],f=+b[6],g=b[7],h=b[8],i=b[9],j=1,k="",l=!1;h&&(h=+h.substring(1)),e&&(c="0",g&&(f-=Math.floor((f-1)/4)));switch(i){case"n":g=!0,i="g";break;case"%":j=100,k="%",i="f";break;case"p":j=100,k="%",i="r";break;case"d":l=!0,h=0;break;case"s":j=-1,i="r"}return i=="r"&&!h&&(i="g"),i=C.get(i)||E,function(a){if(l&&a%1)return"";var b=a<0&&(a=-a)?"-":d;if(j<0){var m=d3.formatPrefix(a,h);a=m.scale(a),k=m.symbol}else a*=j;a=i(a,h);if(e){var n=a.length+b.length;n<f&&(a=(new Array(f-n+1)).join(c)+a),g&&(a=F(a)),a=b+a}else{g&&(a=F(a)),a=b+a;var n=a.length;n<f&&(a=(new Array(f-n+1)).join(c)+a)}return a+k}};var B=/(?:([^{])?([<>=^]))?([+\- ])?(#)?(0)?([0-9]+)?(,)?(\.[0-9]+)?([a-zA-Z%])?/,C=d3.map({g:function(a,b){return a.toPrecision(b)},e:function(a,b){return a.toExponential(b)},f:function(a,b){return a.toFixed(b)},r:function(a,b){return d3.round(a,b=D(a,b)).toFixed(Math.max(0,Math.min(20,b)))}}),G=["y","z","a","f","p","n","μ","m","","k","M","G","T","P","E","Z","Y"].map(H);d3.formatPrefix=function(a,b){var c=0;return a&&(a<0&&(a*=-1),b&&(a=d3.round(a,D(a,b))),c=1+Math.floor(1e-12+Math.log(a)/Math.LN10),c=Math.max(-24,Math.min(24,Math.floor((c<=0?c+1:c-1)/3)*3))),G[8+c/3]};var I=R(2),J=R(3),K=function(){return Q},L=d3.map({linear:K,poly:R,quad:function(){return I},cubic:function(){return J},sin:function(){return S},exp:function(){return T},circle:function(){return U},elastic:V,back:W,bounce:function(){return X}}),M=d3.map({"in":Q,out:O,"in-out":P,"out-in":function(a){return P(O(a))}});d3.ease=function(a){var b=a.indexOf("-"),c=b>=0?a.substring(0,b):a,d=b>=0?a.substring(b+1):"in";return c=L.get(c)||K,d=M.get(d)||Q,N(d(c.apply(null,Array.prototype.slice.call(arguments,1))))},d3.event=null,d3.transform=function(a){var b=document.createElementNS(d3.ns.prefix.svg,"g");return(d3.transform=function(a){b.setAttribute("transform",a);var c=b.transform.baseVal.consolidate();return new _(c?c.matrix:be)})(a)},_.prototype.toString=function(){return"translate("+this.translate+")rotate("+this.rotate+")skewX("+this.skew+")scale("+this.scale+")"};var bd=180/Math.PI,be={a:1,b:0,c:0,d:1,e:0,f:0};d3.interpolate=function(a,b){var c=d3.interpolators.length,d;while(--c>=0&&!(d=d3.interpolators[c](a,b)));return d},d3.interpolateNumber=function(a,b){return b-=a,function(c){return a+b*c}},d3.interpolateRound=function(a,b){return b-=a,function(c){return Math.round(a+b*c)}},d3.interpolateString=function(a,b){var c,d,e,f=0,g=0,h=[],i=[],j,k;bf.lastIndex=0;for(d=0;c=bf.exec(b);++d)c.index&&h.push(b.substring(f,g=c.index)),i.push({i:h.length,x:c[0]}),h.push(null),f=bf.lastIndex;f<b.length&&h.push(b.substring(f));for(d=0,j=i.length;(c=bf.exec(a))&&d<j;++d){k=i[d];if(k.x==c[0]){if(k.i)if(h[k.i+1]==null){h[k.i-1]+=k.x,h.splice(k.i,1);for(e=d+1;e<j;++e)i[e].i--}else{h[k.i-1]+=k.x+h[k.i+1],h.splice(k.i,2);for(e=d+1;e<j;++e)i[e].i-=2}else if(h[k.i+1]==null)h[k.i]=k.x;else{h[k.i]=k.x+h[k.i+1],h.splice(k.i+1,1);for(e=d+1;e<j;++e)i[e].i--}i.splice(d,1),j--,d--}else k.x=d3.interpolateNumber(parseFloat(c[0]),parseFloat(k.x))}while(d<j)k=i.pop(),h[k.i+1]==null?h[k.i]=k.x:(h[k.i]=k.x+h[k.i+1],h.splice(k.i+1,1)),j--;return h.length===1?h[0]==null?i[0].x:function(){return b}:function(a){for(d=0;d<j;++d)h[(k=i[d]).i]=k.x(a);return h.join("")}},d3.interpolateTransform=function(a,b){var c=[],d=[],e,f=d3.transform(a),g=d3.transform(b),h=f.translate,i=g.translate,j=f.rotate,k=g.rotate,l=f.skew,m=g.skew,n=f.scale,o=g.scale;return h[0]!=i[0]||h[1]!=i[1]?(c.push("translate(",null,",",null,")"),d.push({i:1,x:d3.interpolateNumber(h[0],i[0])},{i:3,x:d3.interpolateNumber(h[1],i[1])})):i[0]||i[1]?c.push("translate("+i+")"):c.push(""),j!=k?(j-k>180?k+=360:k-j>180&&(j+=360),d.push({i:c.push(c.pop()+"rotate(",null,")")-2,x:d3.interpolateNumber(j,k)})):k&&c.push(c.pop()+"rotate("+k+")"),l!=m?d.push({i:c.push(c.pop()+"skewX(",null,")")-2,x:d3.interpolateNumber(l,m)}):m&&c.push(c.pop()+"skewX("+m+")"),n[0]!=o[0]||n[1]!=o[1]?(e=c.push(c.pop()+"scale(",null,",",null,")"),d.push({i:e-4,x:d3.interpolateNumber(n[0],o[0])},{i:e-2,x:d3.interpolateNumber(n[1],o[1])})):(o[0]!=1||o[1]!=1)&&c.push(c.pop()+"scale("+o+")"),e=d.length,function(a){var b=-1,f;while(++b<e)c[(f=d[b]).i]=f.x(a);return c.join("")}},d3.interpolateRgb=function(a,b){a=d3.rgb(a),b=d3.rgb(b);var c=a.r,d=a.g,e=a.b,f=b.r-c,g=b.g-d,h=b.b-e;return function(a){return"#"+bl(Math.round(c+f*a))+bl(Math.round(d+g*a))+bl(Math.round(e+h*a))}},d3.interpolateHsl=function(a,b){a=d3.hsl(a),b=d3.hsl(b);var c=a.h,d=a.s,e=a.l,f=b.h-c,g=b.s-d,h=b.l-e;return f>180?f-=360:f<-180&&(f+=360),function(a){return bu(c+f*a,d+g*a,e+h*a)+""}},d3.interpolateLab=function(a,b){a=d3.lab(a),b=d3.lab(b);var c=a.l,d=a.a,e=a.b,f=b.l-c,g=b.a-d,h=b.b-e;return function(a){return bE(c+f*a,d+g*a,e+h*a)+""}},d3.interpolateHcl=function(a,b){a=d3.hcl(a),b=d3.hcl(b);var c=a.h,d=a.c,e=a.l,f=b.h-c,g=b.c-d,h=b.l-e;return f>180?f-=360:f<-180&&(f+=360),function(a){return bx(c+f*a,d+g*a,e+h*a)+""}},d3.interpolateArray=function(a,b){var c=[],d=[],e=a.length,f=b.length,g=Math.min(a.length,b.length),h;for(h=0;h<g;++h)c.push(d3.interpolate(a[h],b[h]));for(;h<e;++h)d[h]=a[h];for(;h<f;++h)d[h]=b[h];return function(a){for(h=0;h<g;++h)d[h]=c[h](a);return d}},d3.interpolateObject=function(a,b){var c={},d={},e;for(e in a)e in b?c[e]=bg(e)(a[e],b[e]):d[e]=a[e];for(e in b)e in a||(d[e]=b[e]);return function(a){for(e in c)d[e]=c[e](a);return d}};var bf=/[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g;d3.interpolators=[d3.interpolateObject,function(a,b){return b instanceof Array&&d3.interpolateArray(a,b)},function(a,b){return(typeof a=="string"||typeof b=="string")&&d3.interpolateString(a+"",b+"")},function(a,b){return(typeof b=="string"?br.has(b)||/^(#|rgb\(|hsl\()/.test(b):b instanceof bk||b instanceof bt)&&d3.interpolateRgb(a,b)},function(a,b){return!isNaN(a=+a)&&!isNaN(b=+b)&&d3.interpolateNumber(a,b)}],d3.rgb=function(a,b,c){return arguments.length===1?a instanceof bk?bj(a.r,a.g,a.b):bm(""+a,bj,bu):bj(~~a,~~b,~~c)},bk.prototype.brighter=function(a){a=Math.pow(.7,arguments.length?a:1);var b=this.r,c=this.g,d=this.b,e=30;return!b&&!c&&!d?bj(e,e,e):(b&&b<e&&(b=e),c&&c<e&&(c=e),d&&d<e&&(d=e),bj(Math.min(255,Math.floor(b/a)),Math.min(255,Math.floor(c/a)),Math.min(255,Math.floor(d/a))))},bk.prototype.darker=function(a){return a=Math.pow(.7,arguments.length?a:1),bj(Math.floor(a*this.r),Math.floor(a*this.g),Math.floor(a*this.b))},bk.prototype.hsl=function(){return bn(this.r,this.g,this.b)},bk.prototype.toString=function(){return"#"+bl(this.r)+bl(this.g)+bl(this.b)};var br=d3.map({aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkgrey:"#a9a9a9",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkslategrey:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dimgrey:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",grey:"#808080",honeydew:"#f0fff0",hotpink:"#ff69b4",indianred:"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgray:"#d3d3d3",lightgreen:"#90ee90",lightgrey:"#d3d3d3",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightslategrey:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370db",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#db7093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",slategrey:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"});br.forEach(function(a,b){br.set(a,bm(b,bj,bu))}),d3.hsl=function(a,b,c){return arguments.length===1?a instanceof bt?bs(a.h,a.s,a.l):bm(""+a,bn,bs):bs(+a,+b,+c)},bt.prototype.brighter=function(a){return a=Math.pow(.7,arguments.length?a:1),bs(this.h,this.s,this.l/a)},bt.prototype.darker=function(a){return a=Math.pow(.7,arguments.length?a:1),bs(this.h,this.s,a*this.l)},bt.prototype.rgb=function(){return bu(this.h,this.s,this.l)},bt.prototype.toString=function(){return this.rgb().toString()},d3.hcl=function(a,b,c){return arguments.length===1?a instanceof bw?bv(a.h,a.c,a.l):a instanceof bz?bF(a.l,a.a,a.b):bF((a=bo((a=d3.rgb(a)).r,a.g,a.b)).l,a.a,a.b):bv(+a,+b,+c)},bw.prototype.brighter=function(a){return bv(this.h,this.c,Math.min(100,this.l+bA*(arguments.length?a:1)))},bw.prototype.darker=function(a){return bv(this.h,this.c,Math.max(0,this.l-bA*(arguments.length?a:1)))},bw.prototype.rgb=function(){return bx(this.h,this.c,this.l).rgb()},bw.prototype.toString=function(){return this.rgb()+""},d3.lab=function(a,b,c){return arguments.length===1?a instanceof bz?by(a.l,a.a,a.b):a instanceof bw?bx(a.l,a.c,a.h):bo((a=d3.rgb(a)).r,a.g,a.b):by(+a,+b,+c)};var bA=18,bB=.95047,bC=1,bD=1.08883;bz.prototype.brighter=function(a){return by(Math.min(100,this.l+bA*(arguments.length?a:1)),this.a,this.b)},bz.prototype.darker=function(a){return by(Math.max(0,this.l-bA*(arguments.length?a:1)),this.a,this.b)},bz.prototype.rgb=function(){return bE(this.l,this.a,this.b)},bz.prototype.toString=function(){return this.rgb()+""};var bK=function(a,b){return b.querySelector(a)},bL=function(a,b){return b.querySelectorAll(a)},bM=document.documentElement,bN=bM.matchesSelector||bM.webkitMatchesSelector||bM.mozMatchesSelector||bM.msMatchesSelector||bM.oMatchesSelector,bO=function(a,b){return bN.call(a,b)};typeof Sizzle=="function"&&(bK=function(a,b){return Sizzle(a,b)[0]||null},bL=function(a,b){return Sizzle.uniqueSort(Sizzle(a,b))},bO=Sizzle.matchesSelector);var bP=[];d3.selection=function(){return cb},d3.selection.prototype=bP,bP.select=function(a){var b=[],c,d,e,f;typeof a!="function"&&(a=bQ(a));for(var g=-1,h=this.length;++g<h;){b.push(c=[]),c.parentNode=(e=this[g]).parentNode;for(var i=-1,j=e.length;++i<j;)(f=e[i])?(c.push(d=a.call(f,f.__data__,i)),d&&"__data__"in f&&(d.__data__=f.__data__)):c.push(null)}return bJ(b)},bP.selectAll=function(a){var b=[],c,d;typeof a!="function"&&(a=bR(a));for(var f=-1,g=this.length;++f<g;)for(var h=this[f],i=-1,j=h.length;++i<j;)if(d=h[i])b.push(c=e(a.call(d,d.__data__,i))),c.parentNode=d;return bJ(b)},bP.attr=function(a,b){if(arguments.length<2){if(typeof a=="string"){var c=this.node();return a=d3.ns.qualify(a),a.local?c.getAttributeNS(a.space,a.local):c.getAttribute(a)}for(b in a)this.each(bS(b,a[b]));return this}return this.each(bS(a,b))},bP.classed=function(a,b){if(arguments.length<2){if(typeof a=="string"){var c=this.node(),d=(a=a.trim().split(/^|\s+/g)).length,e=-1;if(b=c.classList){while(++e<d)if(!b.contains(a[e]))return!1}else{b=c.className,b.baseVal!=null&&(b=b.baseVal);while(++e<d)if(!bT(a[e]).test(b))return!1}return!0}for(b in a)this.each(bU(b,a[b]));return this}return this.each(bU(a,b))},bP.style=function(a,b,c){var d=arguments.length;if(d<3){if(typeof a!="string"){d<2&&(b="");for(c in a)this.each(bW(c,a[c],b));return this}if(d<2)return window.getComputedStyle(this.node(),null).getPropertyValue(a);c=""}return this.each(bW(a,b,c))},bP.property=function(a,b){if(arguments.length<2){if(typeof a=="string")return this.node()[a];for(b in a)this.each(bX(b,a[b]));return this}return this.each(bX(a,b))},bP.text=function(a){return arguments.length<1?this.node().textContent:this.each(typeof a=="function"?function(){var b=a.apply(this,arguments);this.textContent=b==null?"":b}:a==null?function(){this.textContent=""}:function(){this.textContent=a})},bP.html=function(a){return arguments.length<1?this.node().innerHTML:this.each(typeof a=="function"?function(){var b=a.apply(this,arguments);this.innerHTML=b==null?"":b}:a==null?function(){this.innerHTML=""}:function(){this.innerHTML=a})},bP.append=function(a){function b(){return this.appendChild(document.createElementNS(this.namespaceURI,a))}function c(){return this.appendChild(document.createElementNS(a.space,a.local))}return a=d3.ns.qualify(a),this.select(a.local?c:b)},bP.insert=function(a,b){function c(){return this.insertBefore(document.createElementNS(this.namespaceURI,a),bK(b,this))}function d(){return this.insertBefore(document.createElementNS(a.space,a.local),bK(b,this))}return a=d3.ns.qualify(a),this.select(a.local?d:c)},bP.remove=function(){return this.each(function(){var a=this.parentNode;a&&a.removeChild(this)})},bP.data=function(a,b){function g(a,c){var d,e=a.length,f=c.length,g=Math.min(e,f),l=Math.max(e,f),m=[],n=[],o=[],p,q;if(b){var r=new j,s=[],t,u=c.length;for(d=-1;++d<e;)t=b.call(p=a[d],p.__data__,d),r.has(t)?o[u++]=p:r.set(t,p),s.push(t);for(d=-1;++d<f;)t=b.call(c,q=c[d],d),r.has(t)?(m[d]=p=r.get(t),p.__data__=q,n[d]=o[d]=null):(n[d]=bY(q),m[d]=o[d]=null),r.remove(t);for(d=-1;++d<e;)r.has(s[d])&&(o[d]=a[d])}else{for(d=-1;++d<g;)p=a[d],q=c[d],p?(p.__data__=q,m[d]=p,n[d]=o[d]=null):(n[d]=bY(q),m[d]=o[d]=null);for(;d<f;++d)n[d]=bY(c[d]),m[d]=o[d]=null;for(;d<l;++d)o[d]=a[d],n[d]=m[d]=null}n.update=m,n.parentNode=m.parentNode=o.parentNode=a.parentNode,h.push(n),i.push(m),k.push(o)}var c=-1,d=this.length,e,f;if(!arguments.length){a=new Array(d=(e=this[0]).length);while(++c<d)if(f=e[c])a[c]=f.__data__;return a}var h=cc([]),i=bJ([]),k=bJ([]);if(typeof a=="function")while(++c<d)g(e=this[c],a.call(e,e.parentNode.__data__,c));else while(++c<d)g(e=this[c],a);return i.enter=function(){return h},i.exit=function(){return k},i},bP.datum=bP.map=function(a){return arguments.length<1?this.property("__data__"):this.property("__data__",a)},bP.filter=function(a){var b=[],c,d,e;typeof a!="function"&&(a=bZ(a));for(var f=0,g=this.length;f<g;f++){b.push(c=[]),c.parentNode=(d=this[f]).parentNode;for(var h=0,i=d.length;h<i;h++)(e=d[h])&&a.call(e,e.__data__,h)&&c.push(e)}return bJ(b)},bP.order=function(){for(var a=-1,b=this.length;++a<b;)for(var c=this[a],d=c.length-1,e=c[d],f;--d>=0;)if(f=c[d])e&&e!==f.nextSibling&&e.parentNode.insertBefore(f,e),e=f;return this},bP.sort=function(a){a=b$.apply(this,arguments);for(var b=-1,c=this.length;++b<c;)this[b].sort(a);return this.order()},bP.on=function(a,b,c){var d=arguments.length;if(d<3){if(typeof a!="string"){d<2&&(b=!1);for(c in a)this.each(b_(c,a[c],b));return this}if(d<2)return(d=this.node()["__on"+a])&&d._;c=!1}return this.each(b_(a,b,c))},bP.each=function(a){return ca(this,function(b,c,d){a.call(b,b.__data__,c,d)})},bP.call=function(a){return a.apply(this,(arguments[0]=this,arguments)),this},bP.empty=function(){return!this.node()},bP.node=function(a){for(var b=0,c=this.length;b<c;b++)for(var d=this[b],e=0,f=d.length;e<f;e++){var g=d[e];if(g)return g}return null},bP.transition=function(){var a=[],b,c;for(var d=-1,e=this.length;++d<e;){a.push(b=[]);for(var f=this[d],g=-1,h=f.length;++g<h;)b.push((c=f[g])?{node:c,delay:cl,duration:cm}:null)}return ce(a,ch||++cg,Date.now())};var cb=bJ([[document]]);cb[0].parentNode=bM,d3.select=function(a){return typeof a=="string"?cb.select(a):bJ([[a]])},d3.selectAll=function(a){return typeof a=="string"?cb.selectAll(a):bJ([e(a)])};var cd=[];d3.selection.enter=cc,d3.selection.enter.prototype=cd,cd.append=bP.append,cd.insert=bP.insert,cd.empty=bP.empty,cd.node=bP.node,cd.select=function(a){var b=[],c,d,e,f,g;for(var h=-1,i=this.length;++h<i;){e=(f=this[h]).update,b.push(c=[]),c.parentNode=f.parentNode;for(var j=-1,k=f.length;++j<k;)(g=f[j])?(c.push(e[j]=d=a.call(f.parentNode,g.__data__,j)),d.__data__=g.__data__):c.push(null)}return bJ(b)};var cf=[],cg=0,ch=0,ci=0,cj=250,ck=d3.ease("cubic-in-out"),cl=ci,cm=cj,cn=ck;cf.call=bP.call,d3.transition=function(a){return arguments.length?ch?a.transition():a:cb.transition()},d3.transition.prototype=cf,cf.select=function(a){var b=[],c,d,e;typeof a!="function"&&(a=bQ(a));for(var f=-1,g=this.length;++f<g;){b.push(c=[]);for(var h=this[f],i=-1,j=h.length;++i<j;)(e=h[i])&&(d=a.call(e.node,e.node.__data__,i))?("__data__"in e.node&&(d.__data__=e.node.__data__),c.push({node:d,delay:e.delay,duration:e.duration})):c.push(null)}return ce(b,this.id,this.time).ease(this.ease())},cf.selectAll=function(a){var b=[],c,d,e;typeof a!="function"&&(a=bR(a));for(var f=-1,g=this.length;++f<g;)for(var h=this[f],i=-1,j=h.length;++i<j;)if(e=h[i]){d=a.call(e.node,e.node.__data__,i),b.push(c=[]);for(var k=-1,l=d.length;++k<l;)c.push({node:d[k],delay:e.delay,duration:e.duration})}return ce(b,this.id,this.time).ease(this.ease())},cf.filter=function(a){var b=[],c,d,e;typeof a!="function"&&(a=bZ(a));for(var f=0,g=this.length;f<g;f++){b.push(c=[]);for(var d=this[f],h=0,i=d.length;h<i;h++)(e=d[h])&&a.call(e.node,e.node.__data__,h)&&c.push(e)}return ce(b,this.id,this.time).ease(this.ease())},cf.attr=function(a,b){if(arguments.length<2){for(b in a)this.attrTween(b,cr(a[b],b));return this}return this.attrTween(a,cr(b,a))},cf.attrTween=function(a,b){function d(a,d){var e=b.call(this,a,d,this.getAttribute(c));return e===cp?(this.removeAttribute(c),null):e&&function(a){this.setAttribute(c,e(a))}}function e(a,d){var e=b.call(this,a,d,this.getAttributeNS(c.space,c.local));return e===cp?(this.removeAttributeNS(c.space,c.local),null):e&&function(a){this.setAttributeNS(c.space,c.local,e(a))}}var c=d3.ns.qualify(a);return this.tween("attr."+a,c.local?e:d)},cf.style=function(a,b,c){var d=arguments.length;if(d<3){if(typeof a!="string"){d<2&&(b="");for(c in a)this.styleTween(c,cr(a[c],c),b);return this}c=""}return this.styleTween(a,cr(b,a),c)},cf.styleTween=function(a,b,c){return arguments.length<3&&(c=""),this.tween("style."+a,function(d,e){var f=b.call(this,d,e,window.getComputedStyle(this,null).getPropertyValue(a));return f===cp?(this.style.removeProperty(a),null):f&&function(b){this.style.setProperty(a,f(b),c)}})},cf.text=function(a){return this.tween("text",function(b,c){this.textContent=typeof a=="function"?a.call(this,b,c):a})},cf.remove=function(){return this.each("end.transition",function(){var a;!this.__transition__&&(a=this.parentNode)&&a.removeChild(this)})},cf.delay=function(a){return ca(this,typeof a=="function"?function(b,c,d){b.delay=a.call(b=b.node,b.__data__,c,d)|0}:(a|=0,function(b){b.delay=a}))},cf.duration=function(a){return ca(this,typeof a=="function"?function(b,c,d){b.duration=Math.max(1,a.call(b=b.node,b.__data__,c,d)|0)}:(a=Math.max(1,a|0),function(b){b.duration=a}))},cf.transition=function(){return this.select(n)},d3.tween=function(a,b){function c(c,d,e){var f=a.call(this,c,d);return f==null?e!=""&&cp:e!=f&&b(e,f)}function d(c,d,e){return e!=a&&b(e,a)}return typeof a=="function"?c:a==null?cq:(a+="",d)};var cp={},cs=null,ct,cu;d3.timer=function(a,b,c){var d=!1,e,f=cs;if(arguments.length<3){if(arguments.length<2)b=0;else if(!isFinite(b))return;c=Date.now()}while(f){if(f.callback===a){f.then=c,f.delay=b,d=!0;break}e=f,f=f.next}d||(cs={callback:a,then:c,delay:b,next:cs}),ct||(cu=clearTimeout(cu),ct=1,cx(cv))},d3.timer.flush=function(){var a,b=Date.now(),c=cs;while(c)a=b-c.then,c.delay||(c.flush=c.callback
|
|
(a)),c=c.next;cw()};var cx=window.requestAnimationFrame||window.webkitRequestAnimationFrame||window.mozRequestAnimationFrame||window.oRequestAnimationFrame||window.msRequestAnimationFrame||function(a){setTimeout(a,17)};d3.mouse=function(a){return cz(a,Z())};var cy=/WebKit/.test(navigator.userAgent)?-1:0;d3.touches=function(a,b){return arguments.length<2&&(b=Z().touches),b?e(b).map(function(b){var c=cz(a,b);return c.identifier=b.identifier,c}):[]},d3.scale={},d3.scale.linear=function(){return cF([0,1],[0,1],d3.interpolate,!1)},d3.scale.log=function(){return cN(d3.scale.linear(),cP)};var cO=d3.format(".0e");cP.pow=function(a){return Math.pow(10,a)},cQ.pow=function(a){return-Math.pow(10,-a)},d3.scale.pow=function(){return cR(d3.scale.linear(),1)},d3.scale.sqrt=function(){return d3.scale.pow().exponent(.5)},d3.scale.ordinal=function(){return cT([],{t:"range",a:[[]]})},d3.scale.category10=function(){return d3.scale.ordinal().range(cU)},d3.scale.category20=function(){return d3.scale.ordinal().range(cV)},d3.scale.category20b=function(){return d3.scale.ordinal().range(cW)},d3.scale.category20c=function(){return d3.scale.ordinal().range(cX)};var cU=["#1f77b4","#ff7f0e","#2ca02c","#d62728","#9467bd","#8c564b","#e377c2","#7f7f7f","#bcbd22","#17becf"],cV=["#1f77b4","#aec7e8","#ff7f0e","#ffbb78","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5","#8c564b","#c49c94","#e377c2","#f7b6d2","#7f7f7f","#c7c7c7","#bcbd22","#dbdb8d","#17becf","#9edae5"],cW=["#393b79","#5254a3","#6b6ecf","#9c9ede","#637939","#8ca252","#b5cf6b","#cedb9c","#8c6d31","#bd9e39","#e7ba52","#e7cb94","#843c39","#ad494a","#d6616b","#e7969c","#7b4173","#a55194","#ce6dbd","#de9ed6"],cX=["#3182bd","#6baed6","#9ecae1","#c6dbef","#e6550d","#fd8d3c","#fdae6b","#fdd0a2","#31a354","#74c476","#a1d99b","#c7e9c0","#756bb1","#9e9ac8","#bcbddc","#dadaeb","#636363","#969696","#bdbdbd","#d9d9d9"];d3.scale.quantile=function(){return cY([],[])},d3.scale.quantize=function(){return cZ(0,1,[0,1])},d3.scale.threshold=function(){return c$([.5],[0,1])},d3.scale.identity=function(){return c_([0,1])},d3.svg={},d3.svg.arc=function(){function e(){var e=a.apply(this,arguments),f=b.apply(this,arguments),g=c.apply(this,arguments)+da,h=d.apply(this,arguments)+da,i=(h<g&&(i=g,g=h,h=i),h-g),j=i<Math.PI?"0":"1",k=Math.cos(g),l=Math.sin(g),m=Math.cos(h),n=Math.sin(h);return i>=db?e?"M0,"+f+"A"+f+","+f+" 0 1,1 0,"+ -f+"A"+f+","+f+" 0 1,1 0,"+f+"M0,"+e+"A"+e+","+e+" 0 1,0 0,"+ -e+"A"+e+","+e+" 0 1,0 0,"+e+"Z":"M0,"+f+"A"+f+","+f+" 0 1,1 0,"+ -f+"A"+f+","+f+" 0 1,1 0,"+f+"Z":e?"M"+f*k+","+f*l+"A"+f+","+f+" 0 "+j+",1 "+f*m+","+f*n+"L"+e*m+","+e*n+"A"+e+","+e+" 0 "+j+",0 "+e*k+","+e*l+"Z":"M"+f*k+","+f*l+"A"+f+","+f+" 0 "+j+",1 "+f*m+","+f*n+"L0,0"+"Z"}var a=dc,b=dd,c=de,d=df;return e.innerRadius=function(b){return arguments.length?(a=p(b),e):a},e.outerRadius=function(a){return arguments.length?(b=p(a),e):b},e.startAngle=function(a){return arguments.length?(c=p(a),e):c},e.endAngle=function(a){return arguments.length?(d=p(a),e):d},e.centroid=function(){var e=(a.apply(this,arguments)+b.apply(this,arguments))/2,f=(c.apply(this,arguments)+d.apply(this,arguments))/2+da;return[Math.cos(f)*e,Math.sin(f)*e]},e};var da=-Math.PI/2,db=2*Math.PI-1e-6;d3.svg.line=function(){return dg(m)};var dj=d3.map({linear:dk,"linear-closed":dl,"step-before":dm,"step-after":dn,basis:du,"basis-open":dv,"basis-closed":dw,bundle:dx,cardinal:dr,"cardinal-open":dp,"cardinal-closed":dq,monotone:dG});dj.forEach(function(a,b){b.key=a,b.closed=/-closed$/.test(a)});var dz=[0,2/3,1/3,0],dA=[0,1/3,2/3,0],dB=[0,1/6,2/3,1/6];d3.svg.line.radial=function(){var a=dg(dH);return a.radius=a.x,delete a.x,a.angle=a.y,delete a.y,a},dm.reverse=dn,dn.reverse=dm,d3.svg.area=function(){return dI(m)},d3.svg.area.radial=function(){var a=dI(dH);return a.radius=a.x,delete a.x,a.innerRadius=a.x0,delete a.x0,a.outerRadius=a.x1,delete a.x1,a.angle=a.y,delete a.y,a.startAngle=a.y0,delete a.y0,a.endAngle=a.y1,delete a.y1,a},d3.svg.chord=function(){function f(c,d){var e=g(this,a,c,d),f=g(this,b,c,d);return"M"+e.p0+i(e.r,e.p1,e.a1-e.a0)+(h(e,f)?j(e.r,e.p1,e.r,e.p0):j(e.r,e.p1,f.r,f.p0)+i(f.r,f.p1,f.a1-f.a0)+j(f.r,f.p1,e.r,e.p0))+"Z"}function g(a,b,f,g){var h=b.call(a,f,g),i=c.call(a,h,g),j=d.call(a,h,g)+da,k=e.call(a,h,g)+da;return{r:i,a0:j,a1:k,p0:[i*Math.cos(j),i*Math.sin(j)],p1:[i*Math.cos(k),i*Math.sin(k)]}}function h(a,b){return a.a0==b.a0&&a.a1==b.a1}function i(a,b,c){return"A"+a+","+a+" 0 "+ +(c>Math.PI)+",1 "+b}function j(a,b,c,d){return"Q 0,0 "+d}var a=dJ,b=dK,c=dL,d=de,e=df;return f.radius=function(a){return arguments.length?(c=p(a),f):c},f.source=function(b){return arguments.length?(a=p(b),f):a},f.target=function(a){return arguments.length?(b=p(a),f):b},f.startAngle=function(a){return arguments.length?(d=p(a),f):d},f.endAngle=function(a){return arguments.length?(e=p(a),f):e},f},d3.svg.diagonal=function(){function d(d,e){var f=a.call(this,d,e),g=b.call(this,d,e),h=(f.y+g.y)/2,i=[f,{x:f.x,y:h},{x:g.x,y:h},g];return i=i.map(c),"M"+i[0]+"C"+i[1]+" "+i[2]+" "+i[3]}var a=dJ,b=dK,c=dO;return d.source=function(b){return arguments.length?(a=p(b),d):a},d.target=function(a){return arguments.length?(b=p(a),d):b},d.projection=function(a){return arguments.length?(c=a,d):c},d},d3.svg.diagonal.radial=function(){var a=d3.svg.diagonal(),b=dO,c=a.projection;return a.projection=function(a){return arguments.length?c(dP(b=a)):b},a},d3.svg.mouse=d3.mouse,d3.svg.touches=d3.touches,d3.svg.symbol=function(){function c(c,d){return(dT.get(a.call(this,c,d))||dS)(b.call(this,c,d))}var a=dR,b=dQ;return c.type=function(b){return arguments.length?(a=p(b),c):a},c.size=function(a){return arguments.length?(b=p(a),c):b},c};var dT=d3.map({circle:dS,cross:function(a){var b=Math.sqrt(a/5)/2;return"M"+ -3*b+","+ -b+"H"+ -b+"V"+ -3*b+"H"+b+"V"+ -b+"H"+3*b+"V"+b+"H"+b+"V"+3*b+"H"+ -b+"V"+b+"H"+ -3*b+"Z"},diamond:function(a){var b=Math.sqrt(a/(2*dV)),c=b*dV;return"M0,"+ -b+"L"+c+",0"+" 0,"+b+" "+ -c+",0"+"Z"},square:function(a){var b=Math.sqrt(a)/2;return"M"+ -b+","+ -b+"L"+b+","+ -b+" "+b+","+b+" "+ -b+","+b+"Z"},"triangle-down":function(a){var b=Math.sqrt(a/dU),c=b*dU/2;return"M0,"+c+"L"+b+","+ -c+" "+ -b+","+ -c+"Z"},"triangle-up":function(a){var b=Math.sqrt(a/dU),c=b*dU/2;return"M0,"+ -c+"L"+b+","+c+" "+ -b+","+c+"Z"}});d3.svg.symbolTypes=dT.keys();var dU=Math.sqrt(3),dV=Math.tan(30*Math.PI/180);d3.svg.axis=function(){function k(k){k.each(function(){var k=d3.select(this),l=h==null?a.ticks?a.ticks.apply(a,g):a.domain():h,m=i==null?a.tickFormat?a.tickFormat.apply(a,g):String:i,n=dY(a,l,j),o=k.selectAll(".minor").data(n,String),p=o.enter().insert("line","g").attr("class","tick minor").style("opacity",1e-6),q=d3.transition(o.exit()).style("opacity",1e-6).remove(),r=d3.transition(o).style("opacity",1),s=k.selectAll("g").data(l,String),t=s.enter().insert("g","path").style("opacity",1e-6),u=d3.transition(s.exit()).style("opacity",1e-6).remove(),v=d3.transition(s).style("opacity",1),w,x=cC(a),y=k.selectAll(".domain").data([0]),z=y.enter().append("path").attr("class","domain"),A=d3.transition(y),B=a.copy(),C=this.__chart__||B;this.__chart__=B,t.append("line").attr("class","tick"),t.append("text");var D=t.select("line"),E=v.select("line"),F=s.select("text").text(m),G=t.select("text"),H=v.select("text");switch(b){case"bottom":w=dW,p.attr("y2",d),r.attr("x2",0).attr("y2",d),D.attr("y2",c),G.attr("y",Math.max(c,0)+f),E.attr("x2",0).attr("y2",c),H.attr("x",0).attr("y",Math.max(c,0)+f),F.attr("dy",".71em").attr("text-anchor","middle"),A.attr("d","M"+x[0]+","+e+"V0H"+x[1]+"V"+e);break;case"top":w=dW,p.attr("y2",-d),r.attr("x2",0).attr("y2",-d),D.attr("y2",-c),G.attr("y",-(Math.max(c,0)+f)),E.attr("x2",0).attr("y2",-c),H.attr("x",0).attr("y",-(Math.max(c,0)+f)),F.attr("dy","0em").attr("text-anchor","middle"),A.attr("d","M"+x[0]+","+ -e+"V0H"+x[1]+"V"+ -e);break;case"left":w=dX,p.attr("x2",-d),r.attr("x2",-d).attr("y2",0),D.attr("x2",-c),G.attr("x",-(Math.max(c,0)+f)),E.attr("x2",-c).attr("y2",0),H.attr("x",-(Math.max(c,0)+f)).attr("y",0),F.attr("dy",".32em").attr("text-anchor","end"),A.attr("d","M"+ -e+","+x[0]+"H0V"+x[1]+"H"+ -e);break;case"right":w=dX,p.attr("x2",d),r.attr("x2",d).attr("y2",0),D.attr("x2",c),G.attr("x",Math.max(c,0)+f),E.attr("x2",c).attr("y2",0),H.attr("x",Math.max(c,0)+f).attr("y",0),F.attr("dy",".32em").attr("text-anchor","start"),A.attr("d","M"+e+","+x[0]+"H0V"+x[1]+"H"+e)}if(a.ticks)t.call(w,C),v.call(w,B),u.call(w,B),p.call(w,C),r.call(w,B),q.call(w,B);else{var I=B.rangeBand()/2,J=function(a){return B(a)+I};t.call(w,J),v.call(w,J)}})}var a=d3.scale.linear(),b="bottom",c=6,d=6,e=6,f=3,g=[10],h=null,i,j=0;return k.scale=function(b){return arguments.length?(a=b,k):a},k.orient=function(a){return arguments.length?(b=a,k):b},k.ticks=function(){return arguments.length?(g=arguments,k):g},k.tickValues=function(a){return arguments.length?(h=a,k):h},k.tickFormat=function(a){return arguments.length?(i=a,k):i},k.tickSize=function(a,b,f){if(!arguments.length)return c;var g=arguments.length-1;return c=+a,d=g>1?+b:c,e=g>0?+arguments[g]:c,k},k.tickPadding=function(a){return arguments.length?(f=+a,k):f},k.tickSubdivide=function(a){return arguments.length?(j=+a,k):j},k},d3.svg.brush=function(){function g(a){a.each(function(){var a=d3.select(this),e=a.selectAll(".background").data([0]),f=a.selectAll(".extent").data([0]),l=a.selectAll(".resize").data(d,String),m;a.style("pointer-events","all").on("mousedown.brush",k).on("touchstart.brush",k),e.enter().append("rect").attr("class","background").style("visibility","hidden").style("cursor","crosshair"),f.enter().append("rect").attr("class","extent").style("cursor","move"),l.enter().append("g").attr("class",function(a){return"resize "+a}).style("cursor",function(a){return dZ[a]}).append("rect").attr("x",function(a){return/[ew]$/.test(a)?-3:null}).attr("y",function(a){return/^[ns]/.test(a)?-3:null}).attr("width",6).attr("height",6).style("visibility","hidden"),l.style("display",g.empty()?"none":null),l.exit().remove(),b&&(m=cC(b),e.attr("x",m[0]).attr("width",m[1]-m[0]),i(a)),c&&(m=cC(c),e.attr("y",m[0]).attr("height",m[1]-m[0]),j(a)),h(a)})}function h(a){a.selectAll(".resize").attr("transform",function(a){return"translate("+e[+/e$/.test(a)][0]+","+e[+/^s/.test(a)][1]+")"})}function i(a){a.select(".extent").attr("x",e[0][0]),a.selectAll(".extent,.n>rect,.s>rect").attr("width",e[1][0]-e[0][0])}function j(a){a.select(".extent").attr("y",e[0][1]),a.selectAll(".extent,.e>rect,.w>rect").attr("height",e[1][1]-e[0][1])}function k(){function x(){var a=d3.event.changedTouches;return a?d3.touches(d,a)[0]:d3.mouse(d)}function y(){d3.event.keyCode==32&&(q||(r=null,s[0]-=e[1][0],s[1]-=e[1][1],q=2),Y())}function z(){d3.event.keyCode==32&&q==2&&(s[0]+=e[1][0],s[1]+=e[1][1],q=0,Y())}function A(){var a=x(),d=!1;t&&(a[0]+=t[0],a[1]+=t[1]),q||(d3.event.altKey?(r||(r=[(e[0][0]+e[1][0])/2,(e[0][1]+e[1][1])/2]),s[0]=e[+(a[0]<r[0])][0],s[1]=e[+(a[1]<r[1])][1]):r=null),o&&B(a,b,0)&&(i(m),d=!0),p&&B(a,c,1)&&(j(m),d=!0),d&&(h(m),l({type:"brush",mode:q?"move":"resize"}))}function B(a,b,c){var d=cC(b),g=d[0],h=d[1],i=s[c],j=e[1][c]-e[0][c],k,l;q&&(g-=i,h-=j+i),k=Math.max(g,Math.min(h,a[c])),q?l=(k+=i)+j:(r&&(i=Math.max(g,Math.min(h,2*r[c]-k))),i<k?(l=k,k=i):l=i);if(e[0][c]!==k||e[1][c]!==l)return f=null,e[0][c]=k,e[1][c]=l,!0}function C(){A(),m.style("pointer-events","all").selectAll(".resize").style("display",g.empty()?"none":null),d3.select("body").style("cursor",null),u.on("mousemove.brush",null).on("mouseup.brush",null).on("touchmove.brush",null).on("touchend.brush",null).on("keydown.brush",null).on("keyup.brush",null),l({type:"brushend"}),Y()}var d=this,k=d3.select(d3.event.target),l=a.of(d,arguments),m=d3.select(d),n=k.datum(),o=!/^(n|s)$/.test(n)&&b,p=!/^(e|w)$/.test(n)&&c,q=k.classed("extent"),r,s=x(),t,u=d3.select(window).on("mousemove.brush",A).on("mouseup.brush",C).on("touchmove.brush",A).on("touchend.brush",C).on("keydown.brush",y).on("keyup.brush",z);if(q)s[0]=e[0][0]-s[0],s[1]=e[0][1]-s[1];else if(n){var v=+/w$/.test(n),w=+/^n/.test(n);t=[e[1-v][0]-s[0],e[1-w][1]-s[1]],s[0]=e[v][0],s[1]=e[w][1]}else d3.event.altKey&&(r=s.slice());m.style("pointer-events","none").selectAll(".resize").style("display",null),d3.select("body").style("cursor",k.style("cursor")),l({type:"brushstart"}),A(),Y()}var a=$(g,"brushstart","brush","brushend"),b=null,c=null,d=d$[0],e=[[0,0],[0,0]],f;return g.x=function(a){return arguments.length?(b=a,d=d$[!b<<1|!c],g):b},g.y=function(a){return arguments.length?(c=a,d=d$[!b<<1|!c],g):c},g.extent=function(a){var d,h,i,j,k;return arguments.length?(f=[[0,0],[0,0]],b&&(d=a[0],h=a[1],c&&(d=d[0],h=h[0]),f[0][0]=d,f[1][0]=h,b.invert&&(d=b(d),h=b(h)),h<d&&(k=d,d=h,h=k),e[0][0]=d|0,e[1][0]=h|0),c&&(i=a[0],j=a[1],b&&(i=i[1],j=j[1]),f[0][1]=i,f[1][1]=j,c.invert&&(i=c(i),j=c(j)),j<i&&(k=i,i=j,j=k),e[0][1]=i|0,e[1][1]=j|0),g):(a=f||e,b&&(d=a[0][0],h=a[1][0],f||(d=e[0][0],h=e[1][0],b.invert&&(d=b.invert(d),h=b.invert(h)),h<d&&(k=d,d=h,h=k))),c&&(i=a[0][1],j=a[1][1],f||(i=e[0][1],j=e[1][1],c.invert&&(i=c.invert(i),j=c.invert(j)),j<i&&(k=i,i=j,j=k))),b&&c?[[d,i],[h,j]]:b?[d,h]:c&&[i,j])},g.clear=function(){return f=null,e[0][0]=e[0][1]=e[1][0]=e[1][1]=0,g},g.empty=function(){return b&&e[0][0]===e[1][0]||c&&e[0][1]===e[1][1]},d3.rebind(g,a,"on")};var dZ={n:"ns-resize",e:"ew-resize",s:"ns-resize",w:"ew-resize",nw:"nwse-resize",ne:"nesw-resize",se:"nwse-resize",sw:"nesw-resize"},d$=[["n","e","s","w","nw","ne","se","sw"],["e","w"],["n","s"],[]];d3.behavior={},d3.behavior.drag=function(){function c(){this.on("mousedown.drag",d).on("touchstart.drag",d)}function d(){function j(){var a=c.parentNode,b=d3.event.changedTouches;return b?d3.touches(a,b)[0]:d3.mouse(a)}function k(){if(!c.parentNode)return l();var a=j(),b=a[0]-g[0],e=a[1]-g[1];h|=b|e,g=a,Y(),d({type:"drag",x:a[0]+f[0],y:a[1]+f[1],dx:b,dy:e})}function l(){d({type:"dragend"}),h&&(Y(),d3.event.target===e&&i.on("click.drag",m,!0)),i.on("mousemove.drag",null).on("touchmove.drag",null).on("mouseup.drag",null).on("touchend.drag",null)}function m(){Y(),i.on("click.drag",null)}var c=this,d=a.of(c,arguments),e=d3.event.target,f,g=j(),h=0,i=d3.select(window).on("mousemove.drag",k).on("touchmove.drag",k).on("mouseup.drag",l,!0).on("touchend.drag",l,!0);b?(f=b.apply(c,arguments),f=[f.x-g[0],f.y-g[1]]):f=[0,0],Y(),d({type:"dragstart"})}var a=$(c,"drag","dragstart","dragend"),b=null;return c.origin=function(a){return arguments.length?(b=a,c):b},d3.rebind(c,a,"on")},d3.behavior.zoom=function(){function l(){this.on("mousedown.zoom",r).on("mousewheel.zoom",s).on("mousemove.zoom",t).on("DOMMouseScroll.zoom",s).on("dblclick.zoom",u).on("touchstart.zoom",v).on("touchmove.zoom",w).on("touchend.zoom",v)}function m(b){return[(b[0]-a[0])/c,(b[1]-a[1])/c]}function n(b){return[b[0]*c+a[0],b[1]*c+a[1]]}function o(a){c=Math.max(e[0],Math.min(e[1],a))}function p(b,c){c=n(c),a[0]+=b[0]-c[0],a[1]+=b[1]-c[1]}function q(b){h&&h.domain(g.range().map(function(b){return(b-a[0])/c}).map(g.invert)),j&&j.domain(i.range().map(function(b){return(b-a[1])/c}).map(i.invert)),d3.event.preventDefault(),b({type:"zoom",scale:c,translate:a})}function r(){function h(){d=1,p(d3.mouse(a),g),q(b)}function i(){d&&Y(),e.on("mousemove.zoom",null).on("mouseup.zoom",null),d&&d3.event.target===c&&e.on("click.zoom",j,!0)}function j(){Y(),e.on("click.zoom",null)}var a=this,b=f.of(a,arguments),c=d3.event.target,d=0,e=d3.select(window).on("mousemove.zoom",h).on("mouseup.zoom",i),g=m(d3.mouse(a));window.focus(),Y()}function s(){b||(b=m(d3.mouse(this))),o(Math.pow(2,eb()*.002)*c),p(d3.mouse(this),b),q(f.of(this,arguments))}function t(){b=null}function u(){var a=d3.mouse(this),b=m(a);o(d3.event.shiftKey?c/2:c*2),p(a,b),q(f.of(this,arguments))}function v(){var a=d3.touches(this),e=Date.now();d=c,b={},a.forEach(function(a){b[a.identifier]=m(a)}),Y();if(a.length===1){if(e-k<500){var g=a[0],h=m(a[0]);o(c*2),p(g,h),q(f.of(this,arguments))}k=e}}function w(){var a=d3.touches(this),c=a[0],e=b[c.identifier];if(g=a[1]){var g,h=b[g.identifier];c=[(c[0]+g[0])/2,(c[1]+g[1])/2],e=[(e[0]+h[0])/2,(e[1]+h[1])/2],o(d3.event.scale*d)}p(c,e),k=null,q(f.of(this,arguments))}var a=[0,0],b,c=1,d,e=ea,f=$(l,"zoom"),g,h,i,j,k;return l.translate=function(b){return arguments.length?(a=b.map(Number),l):a},l.scale=function(a){return arguments.length?(c=+a,l):c},l.scaleExtent=function(a){return arguments.length?(e=a==null?ea:a.map(Number),l):e},l.x=function(a){return arguments.length?(h=a,g=a.copy(),l):h},l.y=function(a){return arguments.length?(j=a,i=a.copy(),l):j},d3.rebind(l,f,"on")};var d_,ea=[0,Infinity];d3.layout={},d3.layout.bundle=function(){return function(a){var b=[],c=-1,d=a.length;while(++c<d)b.push(ec(a[c]));return b}},d3.layout.chord=function(){function j(){var a={},j=[],l=d3.range(e),m=[],n,o,p,q,r;b=[],c=[],n=0,q=-1;while(++q<e){o=0,r=-1;while(++r<e)o+=d[q][r];j.push(o),m.push(d3.range(e)),n+=o}g&&l.sort(function(a,b){return g(j[a],j[b])}),h&&m.forEach(function(a,b){a.sort(function(a,c){return h(d[b][a],d[b][c])})}),n=(2*Math.PI-f*e)/n,o=0,q=-1;while(++q<e){p=o,r=-1;while(++r<e){var s=l[q],t=m[s][r],u=d[s][t],v=o,w=o+=u*n;a[s+"-"+t]={index:s,subindex:t,startAngle:v,endAngle:w,value:u}}c[s]={index:s,startAngle:p,endAngle:o,value:(o-p)/n},o+=f}q=-1;while(++q<e){r=q-1;while(++r<e){var x=a[q+"-"+r],y=a[r+"-"+q];(x.value||y.value)&&b.push(x.value<y.value?{source:y,target:x}:{source:x,target:y})}}i&&k()}function k(){b.sort(function(a,b){return i((a.source.value+a.target.value)/2,(b.source.value+b.target.value)/2)})}var a={},b,c,d,e,f=0,g,h,i;return a.matrix=function(f){return arguments.length?(e=(d=f)&&d.length,b=c=null,a):d},a.padding=function(d){return arguments.length?(f=d,b=c=null,a):f},a.sortGroups=function(d){return arguments.length?(g=d,b=c=null,a):g},a.sortSubgroups=function(c){return arguments.length?(h=c,b=null,a):h},a.sortChords=function(c){return arguments.length?(i=c,b&&k(),a):i},a.chords=function(){return b||j(),b},a.groups=function(){return c||j(),c},a},d3.layout.force=function(){function t(a){return function(b,c,d,e,f){if(b.point!==a){var g=b.cx-a.x,h=b.cy-a.y,i=1/Math.sqrt(g*g+h*h);if((e-c)*i<k){var j=b.charge*i*i;return a.px-=g*j,a.py-=h*j,!0}if(b.point&&isFinite(i)){var j=b.pointCharge*i*i;a.px-=g*j,a.py-=h*j}}return!b.charge}}function u(b){eh(eg=b),ef=a}var a={},b=d3.dispatch("start","tick","end"),c=[1,1],d,e,f=.9,g=em,h=en,i=-30,j=.1,k=.8,l,n=[],o=[],q,r,s;return a.tick=function(){if((e*=.99)<.005)return b.end({type:"end",alpha:e=0}),!0;var a=n.length,d=o.length,g,h,k,l,m,p,u,v,w;for(h=0;h<d;++h){k=o[h],l=k.source,m=k.target,v=m.x-l.x,w=m.y-l.y;if(p=v*v+w*w)p=e*r[h]*((p=Math.sqrt(p))-q[h])/p,v*=p,w*=p,m.x-=v*(u=l.weight/(m.weight+l.weight)),m.y-=w*u,l.x+=v*(u=1-u),l.y+=w*u}if(u=e*j){v=c[0]/2,w=c[1]/2,h=-1;if(u)while(++h<a)k=n[h],k.x+=(v-k.x)*u,k.y+=(w-k.y)*u}if(i){el(g=d3.geom.quadtree(n),e,s),h=-1;while(++h<a)(k=n[h]).fixed||g.visit(t(k))}h=-1;while(++h<a)k=n[h],k.fixed?(k.x=k.px,k.y=k.py):(k.x-=(k.px-(k.px=k.x))*f,k.y-=(k.py-(k.py=k.y))*f);b.tick({type:"tick",alpha:e})},a.nodes=function(b){return arguments.length?(n=b,a):n},a.links=function(b){return arguments.length?(o=b,a):o},a.size=function(b){return arguments.length?(c=b,a):c},a.linkDistance=function(b){return arguments.length?(g=p(b),a):g},a.distance=a.linkDistance,a.linkStrength=function(b){return arguments.length?(h=p(b),a):h},a.friction=function(b){return arguments.length?(f=b,a):f},a.charge=function(b){return arguments.length?(i=typeof b=="function"?b:+b,a):i},a.gravity=function(b){return arguments.length?(j=b,a):j},a.theta=function(b){return arguments.length?(k=b,a):k},a.alpha=function(c){return arguments.length?(e?c>0?e=c:e=0:c>0&&(b.start({type:"start",alpha:e=c}),d3.timer(a.tick)),a):e},a.start=function(){function p(a,c){var d=t(b),e=-1,f=d.length,g;while(++e<f)if(!isNaN(g=d[e][a]))return g;return Math.random()*c}function t(){if(!l){l=[];for(d=0;d<e;++d)l[d]=[];for(d=0;d<f;++d){var a=o[d];l[a.source.index].push(a.target),l[a.target.index].push(a.source)}}return l[b]}var b,d,e=n.length,f=o.length,j=c[0],k=c[1],l,m;for(b=0;b<e;++b)(m=n[b]).index=b,m.weight=0;q=[],r=[];for(b=0;b<f;++b)m=o[b],typeof m.source=="number"&&(m.source=n[m.source]),typeof m.target=="number"&&(m.target=n[m.target]),q[b]=g.call(this,m,b),r[b]=h.call(this,m,b),++m.source.weight,++m.target.weight;for(b=0;b<e;++b)m=n[b],isNaN(m.x)&&(m.x=p("x",j)),isNaN(m.y)&&(m.y=p("y",k)),isNaN(m.px)&&(m.px=m.x),isNaN(m.py)&&(m.py=m.y);s=[];if(typeof i=="function")for(b=0;b<e;++b)s[b]=+i.call(this,n[b],b);else for(b=0;b<e;++b)s[b]=i;return a.resume()},a.resume=function(){return a.alpha(.1)},a.stop=function(){return a.alpha(0)},a.drag=function(){d||(d=d3.behavior.drag().origin(m).on("dragstart",u).on("drag",ek).on("dragend",ej)),this.on("mouseover.force",eh).on("mouseout.force",ei).call(d)},d3.rebind(a,b,"on")};var ef,eg;d3.layout.partition=function(){function c(a,b,d,e){var f=a.children;a.x=b,a.y=a.depth*e,a.dx=d,a.dy=e;if(f&&(h=f.length)){var g=-1,h,i,j;d=a.value?d/a.value:0;while(++g<h)c(i=f[g],b,j=i.value*d,e),b+=j}}function d(a){var b=a.children,c=0;if(b&&(f=b.length)){var e=-1,f;while(++e<f)c=Math.max(c,d(b[e]))}return 1+c}function e(e,f){var g=a.call(this,e,f);return c(g[0],0,b[0],b[1]/d(g[0])),g}var a=d3.layout.hierarchy(),b=[1,1];return e.size=function(a){return arguments.length?(b=a,e):b},eC(e,a)},d3.layout.pie=function(){function e(f,g){var h=f.map(function(b,c){return+a.call(e,b,c)}),i=+(typeof c=="function"?c.apply(this,arguments):c),j=((typeof d=="function"?d.apply(this,arguments):d)-c)/d3.sum(h),k=d3.range(f.length);b!=null&&k.sort(b===eo?function(a,b){return h[b]-h[a]}:function(a,c){return b(f[a],f[c])});var l=[];return k.forEach(function(a){var b;l[a]={data:f[a],value:b=h[a],startAngle:i,endAngle:i+=b*j}}),l}var a=Number,b=eo,c=0,d=2*Math.PI;return e.value=function(b){return arguments.length?(a=b,e):a},e.sort=function(a){return arguments.length?(b=a,e):b},e.startAngle=function(a){return arguments.length?(c=a,e):c},e.endAngle=function(a){return arguments.length?(d=a,e):d},e};var eo={};d3.layout.stack=function(){function g(h,i){var j=h.map(function(b,c){return a.call(g,b,c)}),k=j.map(function(a,b){return a.map(function(a,b){return[e.call(g,a,b),f.call(g,a,b)]})}),l=b.call(g,k,i);j=d3.permute(j,l),k=d3.permute(k,l);var m=c.call(g,k,i),n=j.length,o=j[0].length,p,q,r;for(q=0;q<o;++q){d.call(g,j[0][q],r=m[q],k[0][q][1]);for(p=1;p<n;++p)d.call(g,j[p][q],r+=k[p-1][q][1],k[p][q][1])}return h}var a=m,b=eu,c=ev,d=er,e=ep,f=eq;return g.values=function(b){return arguments.length?(a=b,g):a},g.order=function(a){return arguments.length?(b=typeof a=="function"?a:es.get(a)||eu,g):b},g.offset=function(a){return arguments.length?(c=typeof a=="function"?a:et.get(a)||ev,g):c},g.x=function(a){return arguments.length?(e=a,g):e},g.y=function(a){return arguments.length?(f=a,g):f},g.out=function(a){return arguments.length?(d=a,g):d},g};var es=d3.map({"inside-out":function(a){var b=a.length,c,d,e=a.map(ew),f=a.map(ex),g=d3.range(b).sort(function(a,b){return e[a]-e[b]}),h=0,i=0,j=[],k=[];for(c=0;c<b;++c)d=g[c],h<i?(h+=f[d],j.push(d)):(i+=f[d],k.push(d));return k.reverse().concat(j)},reverse:function(a){return d3.range(a.length).reverse()},"default":eu}),et=d3.map({silhouette:function(a){var b=a.length,c=a[0].length,d=[],e=0,f,g,h,i=[];for(g=0;g<c;++g){for(f=0,h=0;f<b;f++)h+=a[f][g][1];h>e&&(e=h),d.push(h)}for(g=0;g<c;++g)i[g]=(e-d[g])/2;return i},wiggle:function(a){var b=a.length,c=a[0],d=c.length,e=0,f,g,h,i,j,k,l,m,n,o=[];o[0]=m=n=0;for(g=1;g<d;++g){for(f=0,i=0;f<b;++f)i+=a[f][g][1];for(f=0,j=0,l=c[g][0]-c[g-1][0];f<b;++f){for(h=0,k=(a[f][g][1]-a[f][g-1][1])/(2*l);h<f;++h)k+=(a[h][g][1]-a[h][g-1][1])/l;j+=k*a[f][g][1]}o[g]=m-=i?j/i*l:0,m<n&&(n=m)}for(g=0;g<d;++g)o[g]-=n;return o},expand:function(a){var b=a.length,c=a[0].length,d=1/b,e,f,g,h=[];for(f=0;f<c;++f){for(e=0,g=0;e<b;e++)g+=a[e][f][1];if(g)for(e=0;e<b;e++)a[e][f][1]/=g;else for(e=0;e<b;e++)a[e][f][1]=d}for(f=0;f<c;++f)h[f]=0;return h},zero:ev});d3.layout.histogram=function(){function e(e,f){var g=[],h=e.map(b,this),i=c.call(this,h,f),j=d.call(this,i,h,f),k,f=-1,l=h.length,m=j.length-1,n=a?1:1/l,o;while(++f<m)k=g[f]=[],k.dx=j[f+1]-(k.x=j[f]),k.y=0;if(m>0){f=-1;while(++f<l)o=h[f],o>=i[0]&&o<=i[1]&&(k=g[d3.bisect(j,o,1,m)-1],k.y+=n,k.push(e[f]))}return g}var a=!0,b=Number,c=eB,d=ez;return e.value=function(a){return arguments.length?(b=a,e):b},e.range=function(a){return arguments.length?(c=p(a),e):c},e.bins=function(a){return arguments.length?(d=typeof a=="number"?function(b){return eA(b,a)}:p(a),e):d},e.frequency=function(b){return arguments.length?(a=!!b,e):a},e},d3.layout.hierarchy=function(){function d(e,g,h){var i=b.call(f,e,g),j=eH?e:{data:e};j.depth=g,h.push(j);if(i&&(l=i.length)){var k=-1,l,m=j.children=[],n=0,o=g+1,p;while(++k<l)p=d(i[k],o,h),p.parent=j,m.push(p),n+=p.value;a&&m.sort(a),c&&(j.value=n)}else c&&(j.value=+c.call(f,e,g)||0);return j}function e(a,b){var d=a.children,g=0;if(d&&(i=d.length)){var h=-1,i,j=b+1;while(++h<i)g+=e(d[h],j)}else c&&(g=+c.call(f,eH?a:a.data,b)||0);return c&&(a.value=g),g}function f(a){var b=[];return d(a,0,b),b}var a=eF,b=eD,c=eE;return f.sort=function(b){return arguments.length?(a=b,f):a},f.children=function(a){return arguments.length?(b=a,f):b},f.value=function(a){return arguments.length?(c=a,f):c},f.revalue=function(a){return e(a,0),a},f};var eH=!1;d3.layout.pack=function(){function d(d,e){var f=a.call(this,d,e),g=f[0];g.x=0,g.y=0,fa(g,function(a){a.r=Math.sqrt(a.value)}),fa(g,eM);var h=c[0],i=c[1],j=Math.max(2*g.r/h,2*g.r/i);if(b>0){var k=b*j/2;fa(g,function(a){a.r+=k}),fa(g,eM),fa(g,function(a){a.r-=k}),j=Math.max(2*g.r/h,2*g.r/i)}return eP(g,h/2,i/2,1/j),f}var a=d3.layout.hierarchy().sort(eI),b=0,c=[1,1];return d.size=function(a){return arguments.length?(c=a,d):c},d.padding=function(a){return arguments.length?(b=+a,d):b},eC(d,a)},d3.layout.cluster=function(){function d(d,e){var f=a.call(this,d,e),g=f[0],h,i=0,j,k;fa(g,function(a){var c=a.children;c&&c.length?(a.x=eS(c),a.y=eR(c)):(a.x=h?i+=b(a,h):0,a.y=0,h=a)});var l=eT(g),m=eU(g),n=l.x-b(l,m)/2,o=m.x+b(m,l)/2;return fa(g,function(a){a.x=(a.x-n)/(o-n)*c[0],a.y=(1-(g.y?a.y/g.y:1))*c[1]}),f}var a=d3.layout.hierarchy().sort(null).value(null),b=eV,c=[1,1];return d.separation=function(a){return arguments.length?(b=a,d):b},d.size=function(a){return arguments.length?(c=a,d):c},eC(d,a)},d3.layout.tree=function(){function d(d,e){function h(a,c){var d=a.children,e=a._tree;if(d&&(f=d.length)){var f,g=d[0],i,k=g,l,m=-1;while(++m<f)l=d[m],h(l,i),k=j(l,i,k),i=l;fb(a);var n=.5*(g._tree.prelim+l._tree.prelim);c?(e.prelim=c._tree.prelim+b(a,c),e.mod=e.prelim-n):e.prelim=n}else c&&(e.prelim=c._tree.prelim+b(a,c))}function i(a,b){a.x=a._tree.prelim+b;var c=a.children;if(c&&(e=c.length)){var d=-1,e;b+=a._tree.mod;while(++d<e)i(c[d],b)}}function j(a,c,d){if(c){var e=a,f=a,g=c,h=a.parent.children[0],i=e._tree.mod,j=f._tree.mod,k=g._tree.mod,l=h._tree.mod,m;while(g=eX(g),e=eW(e),g&&e)h=eW(h),f=eX(f),f._tree.ancestor=a,m=g._tree.prelim+k-e._tree.prelim-i+b(g,e),m>0&&(fc(fd(g,a,d),a,m),i+=m,j+=m),k+=g._tree.mod,i+=e._tree.mod,l+=h._tree.mod,j+=f._tree.mod;g&&!eX(f)&&(f._tree.thread=g,f._tree.mod+=k-j),e&&!eW(h)&&(h._tree.thread=e,h._tree.mod+=i-l,d=a)}return d}var f=a.call(this,d,e),g=f[0];fa(g,function(a,b){a._tree={ancestor:a,prelim:0,mod:0,change:0,shift:0,number:b?b._tree.number+1:0}}),h(g),i(g,-g._tree.prelim);var k=eY(g,e$),l=eY(g,eZ),m=eY(g,e_),n=k.x-b(k,l)/2,o=l.x+b(l,k)/2,p=m.depth||1;return fa(g,function(a){a.x=(a.x-n)/(o-n)*c[0],a.y=a.depth/p*c[1],delete a._tree}),f}var a=d3.layout.hierarchy().sort(null).value(null),b=eV,c=[1,1];return d.separation=function(a){return arguments.length?(b=a,d):b},d.size=function(a){return arguments.length?(c=a,d):c},eC(d,a)},d3.layout.treemap=function(){function i(a,b){var c=-1,d=a.length,e,f;while(++c<d)f=(e=a[c]).value*(b<0?0:b),e.area=isNaN(f)||f<=0?0:f}function j(a){var b=a.children;if(b&&b.length){var c=e(a),d=[],f=b.slice(),g,h=Infinity,k,n=Math.min(c.dx,c.dy),o;i(f,c.dx*c.dy/a.value),d.area=0;while((o=f.length)>0)d.push(g=f[o-1]),d.area+=g.area,(k=l(d,n))<=h?(f.pop(),h=k):(d.area-=d.pop().area,m(d,n,c,!1),n=Math.min(c.dx,c.dy),d.length=d.area=0,h=Infinity);d.length&&(m(d,n,c,!0),d.length=d.area=0),b.forEach(j)}}function k(a){var b=a.children;if(b&&b.length){var c=e(a),d=b.slice(),f,g=[];i(d,c.dx*c.dy/a.value),g.area=0;while(f=d.pop())g.push(f),g.area+=f.area,f.z!=null&&(m(g,f.z?c.dx:c.dy,c,!d.length),g.length=g.area=0);b.forEach(k)}}function l(a,b){var c=a.area,d,e=0,f=Infinity,g=-1,i=a.length;while(++g<i){if(!(d=a[g].area))continue;d<f&&(f=d),d>e&&(e=d)}return c*=c,b*=b,c?Math.max(b*e*h/c,c/(b*f*h)):Infinity}function m(a,c,d,e){var f=-1,g=a.length,h=d.x,i=d.y,j=c?b(a.area/c):0,k;if(c==d.dx){if(e||j>d.dy)j=d.dy;while(++f<g)k=a[f],k.x=h,k.y=i,k.dy=j,h+=k.dx=Math.min(d.x+d.dx-h,j?b(k.area/j):0);k.z=!0,k.dx+=d.x+d.dx-h,d.y+=j,d.dy-=j}else{if(e||j>d.dx)j=d.dx;while(++f<g)k=a[f],k.x=h,k.y=i,k.dx=j,i+=k.dy=Math.min(d.y+d.dy-i,j?b(k.area/j):0);k.z=!1,k.dy+=d.y+d.dy-i,d.x+=j,d.dx-=j}}function n(b){var d=g||a(b),e=d[0];return e.x=0,e.y=0,e.dx=c[0],e.dy=c[1],g&&a.revalue(e),i([e],e.dx*e.dy/e.value),(g?k:j)(e),f&&(g=d),d}var a=d3.layout.hierarchy(),b=Math.round,c=[1,1],d=null,e=fe,f=!1,g,h=.5*(1+Math.sqrt(5));return n.size=function(a){return arguments.length?(c=a,n):c},n.padding=function(a){function b(b){var c=a.call(n,b,b.depth);return c==null?fe(b):ff(b,typeof c=="number"?[c,c,c,c]:c)}function c(b){return ff(b,a)}if(!arguments.length)return d;var f;return e=(d=a)==null?fe:(f=typeof a)==="function"?b:f==="number"?(a=[a,a,a,a],c):c,n},n.round=function(a){return arguments.length?(b=a?Math.round:Number,n):b!=Number},n.sticky=function(a){return arguments.length?(f=a,g=null,n):f},n.ratio=function(a){return arguments.length?(h=a,n):h},eC(n,a)},d3.csv=fg(",","text/csv"),d3.tsv=fg("\t","text/tab-separated-values"),d3.geo={};var fh=Math.PI/180;d3.geo.azimuthal=function(){function i(b){var f=b[0]*fh-e,i=b[1]*fh,j=Math.cos(f),k=Math.sin(f),l=Math.cos(i),m=Math.sin(i),n=a!=="orthographic"?h*m+g*l*j:null,o,p=a==="stereographic"?1/(1+n):a==="gnomonic"?1/n:a==="equidistant"?(o=Math.acos(n),o?o/Math.sin(o):0):a==="equalarea"?Math.sqrt(2/(1+n)):1,q=p*l*k,r=p*(h*l*j-g*m);return[c*q+d[0],c*r+d[1]]}var a="orthographic",b,c=200,d=[480,250],e,f,g,h;return i.invert=function(b){var f=(b[0]-d[0])/c,i=(b[1]-d[1])/c,j=Math.sqrt(f*f+i*i),k=a==="stereographic"?2*Math.atan(j):a==="gnomonic"?Math.atan(j):a==="equidistant"?j:a==="equalarea"?2*Math.asin(.5*j):Math.asin(j),l=Math.sin(k),m=Math.cos(k);return[(e+Math.atan2(f*l,j*g*m+i*h*l))/fh,Math.asin(m*h-(j?i*l*g/j:0))/fh]},i.mode=function(b){return arguments.length?(a=b+"",i):a},i.origin=function(a){return arguments.length?(b=a,e=b[0]*fh,f=b[1]*fh,g=Math.cos(f),h=Math.sin(f),i):b},i.scale=function(a){return arguments.length?(c=+a,i):c},i.translate=function(a){return arguments.length?(d=[+a[0],+a[1]],i):d},i.origin([0,0])},d3.geo.albers=function(){function i(a){var b=f*(fh*a[0]-e),i=Math.sqrt(g-2*f*Math.sin(fh*a[1]))/f;return[c*i*Math.sin(b)+d[0],c*(i*Math.cos(b)-h)+d[1]]}function j(){var c=fh*b[0],d=fh*b[1],j=fh*a[1],k=Math.sin(c),l=Math.cos(c);return e=fh*a[0],f=.5*(k+Math.sin(d)),g=l*l+2*f*k,h=Math.sqrt(g-2*f*Math.sin(j))/f,i}var a=[-98,38],b=[29.5,45.5],c=1e3,d=[480,250],e,f,g,h;return i.invert=function(a){var b=(a[0]-d[0])/c,i=(a[1]-d[1])/c,j=h+i,k=Math.atan2(b,j),l=Math.sqrt(b*b+j*j);return[(e+k/f)/fh,Math.asin((g-l*l*f*f)/(2*f))/fh]},i.origin=function(b){return arguments.length?(a=[+b[0],+b[1]],j()):a},i.parallels=function(a){return arguments.length?(b=[+a[0],+a[1]],j()):b},i.scale=function(a){return arguments.length?(c=+a,i):c},i.translate=function(a){return arguments.length?(d=[+a[0],+a[1]],i):d},j()},d3.geo.albersUsa=function(){function e(e){var f=e[0],g=e[1];return(g>50?b:f<-140?c:g<21?d:a)(e)}var a=d3.geo.albers(),b=d3.geo.albers().origin([-160,60]).parallels([55,65]),c=d3.geo.albers().origin([-160,20]).parallels([8,18]),d=d3.geo.albers().origin([-60,10]).parallels([8,18]);return e.scale=function(f){return arguments.length?(a.scale(f),b.scale(f*.6),c.scale(f),d.scale(f*1.5),e.translate(a.translate())):a.scale()},e.translate=function(f){if(!arguments.length)return a.translate();var g=a.scale()/1e3,h=f[0],i=f[1];return a.translate(f),b.translate([h-400*g,i+170*g]),c.translate([h-190*g,i+200*g]),d.translate([h+580*g,i+430*g]),e},e.scale(a.scale())},d3.geo.bonne=function(){function g(g){var h=g[0]*fh-c,i=g[1]*fh-d;if(e){var j=f+e-i,k=h*Math.cos(i)/j;h=j*Math.sin(k),i=j*Math.cos(k)-f}else h*=Math.cos(i),i*=-1;return[a*h+b[0],a*i+b[1]]}var a=200,b=[480,250],c,d,e,f;return g.invert=function(d){var g=(d[0]-b[0])/a,h=(d[1]-b[1])/a;if(e){var i=f+h,j=Math.sqrt(g*g+i*i);h=f+e-j,g=c+j*Math.atan2(g,i)/Math.cos(h)}else h*=-1,g/=Math.cos(h);return[g/fh,h/fh]},g.parallel=function(a){return arguments.length?(f=1/
|
|
Math.tan(e=a*fh),g):e/fh},g.origin=function(a){return arguments.length?(c=a[0]*fh,d=a[1]*fh,g):[c/fh,d/fh]},g.scale=function(b){return arguments.length?(a=+b,g):a},g.translate=function(a){return arguments.length?(b=[+a[0],+a[1]],g):b},g.origin([0,0]).parallel(45)},d3.geo.equirectangular=function(){function c(c){var d=c[0]/360,e=-c[1]/360;return[a*d+b[0],a*e+b[1]]}var a=500,b=[480,250];return c.invert=function(c){var d=(c[0]-b[0])/a,e=(c[1]-b[1])/a;return[360*d,-360*e]},c.scale=function(b){return arguments.length?(a=+b,c):a},c.translate=function(a){return arguments.length?(b=[+a[0],+a[1]],c):b},c},d3.geo.mercator=function(){function c(c){var d=c[0]/360,e=-(Math.log(Math.tan(Math.PI/4+c[1]*fh/2))/fh)/360;return[a*d+b[0],a*Math.max(-0.5,Math.min(.5,e))+b[1]]}var a=500,b=[480,250];return c.invert=function(c){var d=(c[0]-b[0])/a,e=(c[1]-b[1])/a;return[360*d,2*Math.atan(Math.exp(-360*e*fh))/fh-90]},c.scale=function(b){return arguments.length?(a=+b,c):a},c.translate=function(a){return arguments.length?(b=[+a[0],+a[1]],c):b},c},d3.geo.path=function(){function e(c,e){typeof a=="function"&&(b=fj(a.apply(this,arguments))),g(c);var f=d.length?d.join(""):null;return d=[],f}function f(a){return c(a).join(",")}function i(a){var b=l(a[0]),c=0,d=a.length;while(++c<d)b-=l(a[c]);return b}function j(a){var b=d3.geom.polygon(a[0].map(c)),d=b.area(),e=b.centroid(d<0?(d*=-1,1):-1),f=e[0],g=e[1],h=d,i=0,j=a.length;while(++i<j)b=d3.geom.polygon(a[i].map(c)),d=b.area(),e=b.centroid(d<0?(d*=-1,1):-1),f-=e[0],g-=e[1],h-=d;return[f,g,6*h]}function l(a){return Math.abs(d3.geom.polygon(a.map(c)).area())}var a=4.5,b=fj(a),c=d3.geo.albersUsa(),d=[],g=fi({FeatureCollection:function(a){var b=a.features,c=-1,e=b.length;while(++c<e)d.push(g(b[c].geometry))},Feature:function(a){g(a.geometry)},Point:function(a){d.push("M",f(a.coordinates),b)},MultiPoint:function(a){var c=a.coordinates,e=-1,g=c.length;while(++e<g)d.push("M",f(c[e]),b)},LineString:function(a){var b=a.coordinates,c=-1,e=b.length;d.push("M");while(++c<e)d.push(f(b[c]),"L");d.pop()},MultiLineString:function(a){var b=a.coordinates,c=-1,e=b.length,g,h,i;while(++c<e){g=b[c],h=-1,i=g.length,d.push("M");while(++h<i)d.push(f(g[h]),"L");d.pop()}},Polygon:function(a){var b=a.coordinates,c=-1,e=b.length,g,h,i;while(++c<e){g=b[c],h=-1;if((i=g.length-1)>0){d.push("M");while(++h<i)d.push(f(g[h]),"L");d[d.length-1]="Z"}}},MultiPolygon:function(a){var b=a.coordinates,c=-1,e=b.length,g,h,i,j,k,l;while(++c<e){g=b[c],h=-1,i=g.length;while(++h<i){j=g[h],k=-1;if((l=j.length-1)>0){d.push("M");while(++k<l)d.push(f(j[k]),"L");d[d.length-1]="Z"}}}},GeometryCollection:function(a){var b=a.geometries,c=-1,e=b.length;while(++c<e)d.push(g(b[c]))}}),h=e.area=fi({FeatureCollection:function(a){var b=0,c=a.features,d=-1,e=c.length;while(++d<e)b+=h(c[d]);return b},Feature:function(a){return h(a.geometry)},Polygon:function(a){return i(a.coordinates)},MultiPolygon:function(a){var b=0,c=a.coordinates,d=-1,e=c.length;while(++d<e)b+=i(c[d]);return b},GeometryCollection:function(a){var b=0,c=a.geometries,d=-1,e=c.length;while(++d<e)b+=h(c[d]);return b}},0),k=e.centroid=fi({Feature:function(a){return k(a.geometry)},Polygon:function(a){var b=j(a.coordinates);return[b[0]/b[2],b[1]/b[2]]},MultiPolygon:function(a){var b=0,c=a.coordinates,d,e=0,f=0,g=0,h=-1,i=c.length;while(++h<i)d=j(c[h]),e+=d[0],f+=d[1],g+=d[2];return[e/g,f/g]}});return e.projection=function(a){return c=a,e},e.pointRadius=function(c){return typeof c=="function"?a=c:(a=+c,b=fj(a)),e},e},d3.geo.bounds=function(a){var b=Infinity,c=Infinity,d=-Infinity,e=-Infinity;return fk(a,function(a,f){a<b&&(b=a),a>d&&(d=a),f<c&&(c=f),f>e&&(e=f)}),[[b,c],[d,e]]};var fl={Feature:fm,FeatureCollection:fn,GeometryCollection:fo,LineString:fp,MultiLineString:fq,MultiPoint:fp,MultiPolygon:fr,Point:fs,Polygon:ft};d3.geo.circle=function(){function e(){}function f(a){return d.distance(a)<c}function h(a){var b=-1,e=a.length,f=[],g,h,j,k,l;while(++b<e)l=d.distance(j=a[b]),l<c?(h&&f.push(fx(h,j)((k-c)/(k-l))),f.push(j),g=h=null):(h=j,!g&&f.length&&(f.push(fx(f[f.length-1],h)((c-k)/(l-k))),g=h)),k=l;return g=a[0],h=f[0],h&&j[0]===g[0]&&j[1]===g[1]&&(j[0]!==h[0]||j[1]!==h[1])&&f.push(h),i(f)}function i(a){var b=0,c=a.length,e,f,g=c?[a[0]]:a,h,i=d.source();while(++b<c){h=d.source(a[b-1])(a[b]).coordinates;for(e=0,f=h.length;++e<f;)g.push(h[e])}return d.source(i),g}var a=[0,0],b=89.99,c=b*fh,d=d3.geo.greatArc().source(a).target(m);e.clip=function(b){return typeof a=="function"&&d.source(a.apply(this,arguments)),g(b)||null};var g=fi({FeatureCollection:function(a){var b=a.features.map(g).filter(m);return b&&(a=Object.create(a),a.features=b,a)},Feature:function(a){var b=g(a.geometry);return b&&(a=Object.create(a),a.geometry=b,a)},Point:function(a){return f(a.coordinates)&&a},MultiPoint:function(a){var b=a.coordinates.filter(f);return b.length&&{type:a.type,coordinates:b}},LineString:function(a){var b=h(a.coordinates);return b.length&&(a=Object.create(a),a.coordinates=b,a)},MultiLineString:function(a){var b=a.coordinates.map(h).filter(function(a){return a.length});return b.length&&(a=Object.create(a),a.coordinates=b,a)},Polygon:function(a){var b=a.coordinates.map(h);return b[0].length&&(a=Object.create(a),a.coordinates=b,a)},MultiPolygon:function(a){var b=a.coordinates.map(function(a){return a.map(h)}).filter(function(a){return a[0].length});return b.length&&(a=Object.create(a),a.coordinates=b,a)},GeometryCollection:function(a){var b=a.geometries.map(g).filter(m);return b.length&&(a=Object.create(a),a.geometries=b,a)}});return e.origin=function(b){return arguments.length?(a=b,typeof a!="function"&&d.source(a),e):a},e.angle=function(a){return arguments.length?(c=(b=+a)*fh,e):b},d3.rebind(e,d,"precision")},d3.geo.greatArc=function(){function g(){var a=g.distance.apply(this,arguments),c=0,h=e/a,i=[b];while((c+=h)<1)i.push(f(c));return i.push(d),{type:"LineString",coordinates:i}}var a=fu,b,c=fv,d,e=6*fh,f=fw();return g.distance=function(){return typeof a=="function"&&f.source(b=a.apply(this,arguments)),typeof c=="function"&&f.target(d=c.apply(this,arguments)),f.distance()},g.source=function(c){return arguments.length?(a=c,typeof a!="function"&&f.source(b=a),g):a},g.target=function(a){return arguments.length?(c=a,typeof c!="function"&&f.target(d=c),g):c},g.precision=function(a){return arguments.length?(e=a*fh,g):e/fh},g},d3.geo.greatCircle=d3.geo.circle,d3.geom={},d3.geom.contour=function(a,b){var c=b||fA(a),d=[],e=c[0],f=c[1],g=0,h=0,i=NaN,j=NaN,k=0;do k=0,a(e-1,f-1)&&(k+=1),a(e,f-1)&&(k+=2),a(e-1,f)&&(k+=4),a(e,f)&&(k+=8),k===6?(g=j===-1?-1:1,h=0):k===9?(g=0,h=i===1?-1:1):(g=fy[k],h=fz[k]),g!=i&&h!=j&&(d.push([e,f]),i=g,j=h),e+=g,f+=h;while(c[0]!=e||c[1]!=f);return d};var fy=[1,0,1,1,-1,0,-1,1,0,0,0,0,-1,0,-1,NaN],fz=[0,-1,0,0,0,-1,0,0,1,-1,1,1,0,-1,0,NaN];d3.geom.hull=function(a){if(a.length<3)return[];var b=a.length,c=b-1,d=[],e=[],f,g,h=0,i,j,k,l,m,n,o,p;for(f=1;f<b;++f)a[f][1]<a[h][1]?h=f:a[f][1]==a[h][1]&&(h=a[f][0]<a[h][0]?f:h);for(f=0;f<b;++f){if(f===h)continue;j=a[f][1]-a[h][1],i=a[f][0]-a[h][0],d.push({angle:Math.atan2(j,i),index:f})}d.sort(function(a,b){return a.angle-b.angle}),o=d[0].angle,n=d[0].index,m=0;for(f=1;f<c;++f)g=d[f].index,o==d[f].angle?(i=a[n][0]-a[h][0],j=a[n][1]-a[h][1],k=a[g][0]-a[h][0],l=a[g][1]-a[h][1],i*i+j*j>=k*k+l*l?d[f].index=-1:(d[m].index=-1,o=d[f].angle,m=f,n=g)):(o=d[f].angle,m=f,n=g);e.push(h);for(f=0,g=0;f<2;++g)d[g].index!==-1&&(e.push(d[g].index),f++);p=e.length;for(;g<c;++g){if(d[g].index===-1)continue;while(!fB(e[p-2],e[p-1],d[g].index,a))--p;e[p++]=d[g].index}var q=[];for(f=0;f<p;++f)q.push(a[e[f]]);return q},d3.geom.polygon=function(a){return a.area=function(){var b=0,c=a.length,d=a[c-1][0]*a[0][1],e=a[c-1][1]*a[0][0];while(++b<c)d+=a[b-1][0]*a[b][1],e+=a[b-1][1]*a[b][0];return(e-d)*.5},a.centroid=function(b){var c=-1,d=a.length,e=0,f=0,g,h=a[d-1],i;arguments.length||(b=-1/(6*a.area()));while(++c<d)g=h,h=a[c],i=g[0]*h[1]-h[0]*g[1],e+=(g[0]+h[0])*i,f+=(g[1]+h[1])*i;return[e*b,f*b]},a.clip=function(b){var c,d=-1,e=a.length,f,g,h=a[e-1],i,j,k;while(++d<e){c=b.slice(),b.length=0,i=a[d],j=c[(g=c.length)-1],f=-1;while(++f<g)k=c[f],fC(k,h,i)?(fC(j,h,i)||b.push(fD(j,k,h,i)),b.push(k)):fC(j,h,i)&&b.push(fD(j,k,h,i)),j=k;h=i}return b},a},d3.geom.voronoi=function(a){var b=a.map(function(){return[]});return fF(a,function(a){var c,d,e,f,g,h;a.a===1&&a.b>=0?(c=a.ep.r,d=a.ep.l):(c=a.ep.l,d=a.ep.r),a.a===1?(g=c?c.y:-1e6,e=a.c-a.b*g,h=d?d.y:1e6,f=a.c-a.b*h):(e=c?c.x:-1e6,g=a.c-a.a*e,f=d?d.x:1e6,h=a.c-a.a*f);var i=[e,g],j=[f,h];b[a.region.l.index].push(i,j),b[a.region.r.index].push(i,j)}),b.map(function(b,c){var d=a[c][0],e=a[c][1];return b.forEach(function(a){a.angle=Math.atan2(a[0]-d,a[1]-e)}),b.sort(function(a,b){return a.angle-b.angle}).filter(function(a,c){return!c||a.angle-b[c-1].angle>1e-10})})};var fE={l:"r",r:"l"};d3.geom.delaunay=function(a){var b=a.map(function(){return[]}),c=[];return fF(a,function(c){b[c.region.l.index].push(a[c.region.r.index])}),b.forEach(function(b,d){var e=a[d],f=e[0],g=e[1];b.forEach(function(a){a.angle=Math.atan2(a[0]-f,a[1]-g)}),b.sort(function(a,b){return a.angle-b.angle});for(var h=0,i=b.length-1;h<i;h++)c.push([e,b[h],b[h+1]])}),c},d3.geom.quadtree=function(a,b,c,d,e){function k(a,b,c,d,e,f){if(isNaN(b.x)||isNaN(b.y))return;if(a.leaf){var g=a.point;g?Math.abs(g.x-b.x)+Math.abs(g.y-b.y)<.01?l(a,b,c,d,e,f):(a.point=null,l(a,g,c,d,e,f),l(a,b,c,d,e,f)):a.point=b}else l(a,b,c,d,e,f)}function l(a,b,c,d,e,f){var g=(c+e)*.5,h=(d+f)*.5,i=b.x>=g,j=b.y>=h,l=(j<<1)+i;a.leaf=!1,a=a.nodes[l]||(a.nodes[l]=fG()),i?c=g:e=g,j?d=h:f=h,k(a,b,c,d,e,f)}var f,g=-1,h=a.length;h&&isNaN(a[0].x)&&(a=a.map(fI));if(arguments.length<5)if(arguments.length===3)e=d=c,c=b;else{b=c=Infinity,d=e=-Infinity;while(++g<h)f=a[g],f.x<b&&(b=f.x),f.y<c&&(c=f.y),f.x>d&&(d=f.x),f.y>e&&(e=f.y);var i=d-b,j=e-c;i>j?e=c+i:d=b+j}var m=fG();return m.add=function(a){k(m,a,b,c,d,e)},m.visit=function(a){fH(a,m,b,c,d,e)},a.forEach(m.add),m},d3.time={};var fJ=Date,fK=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];fL.prototype={getDate:function(){return this._.getUTCDate()},getDay:function(){return this._.getUTCDay()},getFullYear:function(){return this._.getUTCFullYear()},getHours:function(){return this._.getUTCHours()},getMilliseconds:function(){return this._.getUTCMilliseconds()},getMinutes:function(){return this._.getUTCMinutes()},getMonth:function(){return this._.getUTCMonth()},getSeconds:function(){return this._.getUTCSeconds()},getTime:function(){return this._.getTime()},getTimezoneOffset:function(){return 0},valueOf:function(){return this._.valueOf()},setDate:function(){fM.setUTCDate.apply(this._,arguments)},setDay:function(){fM.setUTCDay.apply(this._,arguments)},setFullYear:function(){fM.setUTCFullYear.apply(this._,arguments)},setHours:function(){fM.setUTCHours.apply(this._,arguments)},setMilliseconds:function(){fM.setUTCMilliseconds.apply(this._,arguments)},setMinutes:function(){fM.setUTCMinutes.apply(this._,arguments)},setMonth:function(){fM.setUTCMonth.apply(this._,arguments)},setSeconds:function(){fM.setUTCSeconds.apply(this._,arguments)},setTime:function(){fM.setTime.apply(this._,arguments)}};var fM=Date.prototype,fN="%a %b %e %H:%M:%S %Y",fO="%m/%d/%y",fP="%H:%M:%S",fQ=fK,fR=fQ.map(fU),fS=["January","February","March","April","May","June","July","August","September","October","November","December"],fT=fS.map(fU);d3.time.format=function(a){function c(c){var d=[],e=-1,f=0,g,h;while(++e<b)a.charCodeAt(e)==37&&(d.push(a.substring(f,e),(h=gg[g=a.charAt(++e)])?h(c):g),f=e+1);return d.push(a.substring(f,e)),d.join("")}var b=a.length;return c.parse=function(b){var c={y:1900,m:0,d:1,H:0,M:0,S:0,L:0},d=fV(c,a,b,0);if(d!=b.length)return null;"p"in c&&(c.H=c.H%12+c.p*12);var e=new fJ;return e.setFullYear(c.y,c.m,c.d),e.setHours(c.H,c.M,c.S,c.L),e},c.toString=function(){return a},c};var fY=d3.format("02d"),fZ=d3.format("03d"),f$=d3.format("04d"),f_=d3.format("2d"),ga=fW(fQ),gb=fW(fR),gc=fW(fS),gd=fX(fS),ge=fW(fT),gf=fX(fT),gg={a:function(a){return fR[a.getDay()]},A:function(a){return fQ[a.getDay()]},b:function(a){return fT[a.getMonth()]},B:function(a){return fS[a.getMonth()]},c:d3.time.format(fN),d:function(a){return fY(a.getDate())},e:function(a){return f_(a.getDate())},H:function(a){return fY(a.getHours())},I:function(a){return fY(a.getHours()%12||12)},j:function(a){return fZ(1+d3.time.dayOfYear(a))},L:function(a){return fZ(a.getMilliseconds())},m:function(a){return fY(a.getMonth()+1)},M:function(a){return fY(a.getMinutes())},p:function(a){return a.getHours()>=12?"PM":"AM"},S:function(a){return fY(a.getSeconds())},U:function(a){return fY(d3.time.sundayOfYear(a))},w:function(a){return a.getDay()},W:function(a){return fY(d3.time.mondayOfYear(a))},x:d3.time.format(fO),X:d3.time.format(fP),y:function(a){return fY(a.getFullYear()%100)},Y:function(a){return f$(a.getFullYear()%1e4)},Z:gB,"%":function(a){return"%"}},gh={a:gi,A:gj,b:gk,B:gl,c:gm,d:gt,e:gt,H:gu,I:gu,L:gx,m:gs,M:gv,p:gz,S:gw,x:gn,X:go,y:gq,Y:gp},gy=/^\s*\d+/,gA=d3.map({am:0,pm:1});d3.time.format.utc=function(a){function c(a){try{fJ=fL;var c=new fJ;return c._=a,b(c)}finally{fJ=Date}}var b=d3.time.format(a);return c.parse=function(a){try{fJ=fL;var c=b.parse(a);return c&&c._}finally{fJ=Date}},c.toString=b.toString,c};var gC=d3.time.format.utc("%Y-%m-%dT%H:%M:%S.%LZ");d3.time.format.iso=Date.prototype.toISOString?gD:gC,gD.parse=function(a){var b=new Date(a);return isNaN(b)?null:b},gD.toString=gC.toString,d3.time.second=gE(function(a){return new fJ(Math.floor(a/1e3)*1e3)},function(a,b){a.setTime(a.getTime()+Math.floor(b)*1e3)},function(a){return a.getSeconds()}),d3.time.seconds=d3.time.second.range,d3.time.seconds.utc=d3.time.second.utc.range,d3.time.minute=gE(function(a){return new fJ(Math.floor(a/6e4)*6e4)},function(a,b){a.setTime(a.getTime()+Math.floor(b)*6e4)},function(a){return a.getMinutes()}),d3.time.minutes=d3.time.minute.range,d3.time.minutes.utc=d3.time.minute.utc.range,d3.time.hour=gE(function(a){var b=a.getTimezoneOffset()/60;return new fJ((Math.floor(a/36e5-b)+b)*36e5)},function(a,b){a.setTime(a.getTime()+Math.floor(b)*36e5)},function(a){return a.getHours()}),d3.time.hours=d3.time.hour.range,d3.time.hours.utc=d3.time.hour.utc.range,d3.time.day=gE(function(a){var b=new fJ(0,a.getMonth(),a.getDate());return b.setFullYear(a.getFullYear()),b},function(a,b){a.setDate(a.getDate()+b)},function(a){return a.getDate()-1}),d3.time.days=d3.time.day.range,d3.time.days.utc=d3.time.day.utc.range,d3.time.dayOfYear=function(a){var b=d3.time.year(a);return Math.floor((a-b-(a.getTimezoneOffset()-b.getTimezoneOffset())*6e4)/864e5)},fK.forEach(function(a,b){a=a.toLowerCase(),b=7-b;var c=d3.time[a]=gE(function(a){return(a=d3.time.day(a)).setDate(a.getDate()-(a.getDay()+b)%7),a},function(a,b){a.setDate(a.getDate()+Math.floor(b)*7)},function(a){var c=d3.time.year(a).getDay();return Math.floor((d3.time.dayOfYear(a)+(c+b)%7)/7)-(c!==b)});d3.time[a+"s"]=c.range,d3.time[a+"s"].utc=c.utc.range,d3.time[a+"OfYear"]=function(a){var c=d3.time.year(a).getDay();return Math.floor((d3.time.dayOfYear(a)+(c+b)%7)/7)}}),d3.time.week=d3.time.sunday,d3.time.weeks=d3.time.sunday.range,d3.time.weeks.utc=d3.time.sunday.utc.range,d3.time.weekOfYear=d3.time.sundayOfYear,d3.time.month=gE(function(a){return a=d3.time.day(a),a.setDate(1),a},function(a,b){a.setMonth(a.getMonth()+b)},function(a){return a.getMonth()}),d3.time.months=d3.time.month.range,d3.time.months.utc=d3.time.month.utc.range,d3.time.year=gE(function(a){return a=d3.time.day(a),a.setMonth(0,1),a},function(a,b){a.setFullYear(a.getFullYear()+b)},function(a){return a.getFullYear()}),d3.time.years=d3.time.year.range,d3.time.years.utc=d3.time.year.utc.range;var gM=[1e3,5e3,15e3,3e4,6e4,3e5,9e5,18e5,36e5,108e5,216e5,432e5,864e5,1728e5,6048e5,2592e6,7776e6,31536e6],gN=[[d3.time.second,1],[d3.time.second,5],[d3.time.second,15],[d3.time.second,30],[d3.time.minute,1],[d3.time.minute,5],[d3.time.minute,15],[d3.time.minute,30],[d3.time.hour,1],[d3.time.hour,3],[d3.time.hour,6],[d3.time.hour,12],[d3.time.day,1],[d3.time.day,2],[d3.time.week,1],[d3.time.month,1],[d3.time.month,3],[d3.time.year,1]],gO=[[d3.time.format("%Y"),function(a){return!0}],[d3.time.format("%B"),function(a){return a.getMonth()}],[d3.time.format("%b %d"),function(a){return a.getDate()!=1}],[d3.time.format("%a %d"),function(a){return a.getDay()&&a.getDate()!=1}],[d3.time.format("%I %p"),function(a){return a.getHours()}],[d3.time.format("%I:%M"),function(a){return a.getMinutes()}],[d3.time.format(":%S"),function(a){return a.getSeconds()}],[d3.time.format(".%L"),function(a){return a.getMilliseconds()}]],gP=d3.scale.linear(),gQ=gJ(gO);gN.year=function(a,b){return gP.domain(a.map(gL)).ticks(b).map(gK)},d3.time.scale=function(){return gG(d3.scale.linear(),gN,gQ)};var gR=gN.map(function(a){return[a[0].utc,a[1]]}),gS=[[d3.time.format.utc("%Y"),function(a){return!0}],[d3.time.format.utc("%B"),function(a){return a.getUTCMonth()}],[d3.time.format.utc("%b %d"),function(a){return a.getUTCDate()!=1}],[d3.time.format.utc("%a %d"),function(a){return a.getUTCDay()&&a.getUTCDate()!=1}],[d3.time.format.utc("%I %p"),function(a){return a.getUTCHours()}],[d3.time.format.utc("%I:%M"),function(a){return a.getUTCMinutes()}],[d3.time.format.utc(":%S"),function(a){return a.getUTCSeconds()}],[d3.time.format.utc(".%L"),function(a){return a.getUTCMilliseconds()}]],gT=gJ(gS);gR.year=function(a,b){return gP.domain(a.map(gV)).ticks(b).map(gU)},d3.time.scale.utc=function(){return gG(d3.scale.linear(),gR,gT)}})();
|
|
/*! gridster.js - v0.1.0 - 2012-08-14
|
|
* http://gridster.net/
|
|
* Copyright (c) 2012 ducksboard; Licensed MIT */
|
|
|
|
|
|
;(function($, window, document, undefined){
|
|
/**
|
|
* Creates objects with coordinates (x1, y1, x2, y2, cx, cy, width, height)
|
|
* to simulate DOM elements on the screen.
|
|
* Coords is used by Gridster to create a faux grid with any DOM element can
|
|
* collide.
|
|
*
|
|
* @class Coords
|
|
* @param {HTMLElement|Object} obj The jQuery HTMLElement or a object with: left,
|
|
* top, width and height properties.
|
|
* @return {Object} Coords instance.
|
|
* @constructor
|
|
*/
|
|
function Coords(obj) {
|
|
if (obj[0] && $.isPlainObject(obj[0])) {
|
|
this.data = obj[0];
|
|
}else {
|
|
this.el = obj;
|
|
}
|
|
|
|
this.isCoords = true;
|
|
this.coords = {};
|
|
this.init();
|
|
return this;
|
|
}
|
|
|
|
|
|
var fn = Coords.prototype;
|
|
|
|
|
|
fn.init = function(){
|
|
this.set();
|
|
this.original_coords = this.get();
|
|
};
|
|
|
|
|
|
fn.set = function(update, not_update_offsets) {
|
|
var el = this.el;
|
|
|
|
if (el && !update) {
|
|
this.data = el.offset();
|
|
this.data.width = el.width();
|
|
this.data.height = el.height();
|
|
}
|
|
|
|
if (el && update && !not_update_offsets) {
|
|
var offset = el.offset();
|
|
this.data.top = offset.top;
|
|
this.data.left = offset.left;
|
|
}
|
|
|
|
var d = this.data;
|
|
|
|
this.coords.x1 = d.left;
|
|
this.coords.y1 = d.top;
|
|
this.coords.x2 = d.left + d.width;
|
|
this.coords.y2 = d.top + d.height;
|
|
this.coords.cx = d.left + (d.width / 2);
|
|
this.coords.cy = d.top + (d.height / 2);
|
|
this.coords.width = d.width;
|
|
this.coords.height = d.height;
|
|
this.coords.el = el || false ;
|
|
|
|
return this;
|
|
};
|
|
|
|
|
|
fn.update = function(data){
|
|
if (!data && !this.el) {
|
|
return this;
|
|
}
|
|
|
|
if (data) {
|
|
var new_data = $.extend({}, this.data, data);
|
|
this.data = new_data;
|
|
return this.set(true, true);
|
|
}
|
|
|
|
this.set(true);
|
|
return this;
|
|
};
|
|
|
|
|
|
fn.get = function(){
|
|
return this.coords;
|
|
};
|
|
|
|
|
|
//jQuery adapter
|
|
$.fn.coords = function() {
|
|
if (this.data('coords') ) {
|
|
return this.data('coords');
|
|
}
|
|
|
|
var ins = new Coords(this, arguments[0]);
|
|
this.data('coords', ins);
|
|
return ins;
|
|
};
|
|
|
|
}(jQuery, window, document));
|
|
|
|
;(function($, window, document, undefined){
|
|
|
|
var defaults = {
|
|
colliders_context: document.body
|
|
// ,on_overlap: function(collider_data){},
|
|
// on_overlap_start : function(collider_data){},
|
|
// on_overlap_stop : function(collider_data){}
|
|
};
|
|
|
|
|
|
/**
|
|
* Detects collisions between a DOM element against other DOM elements or
|
|
* Coords objects.
|
|
*
|
|
* @class Collision
|
|
* @uses Coords
|
|
* @param {HTMLElement} el The jQuery wrapped HTMLElement.
|
|
* @param {HTMLElement|Array} colliders Can be a jQuery collection
|
|
* of HTMLElements or an Array of Coords instances.
|
|
* @param {Object} [options] An Object with all options you want to
|
|
* overwrite:
|
|
* @param {Function} [options.on_overlap_start] Executes a function the first
|
|
* time each `collider ` is overlapped.
|
|
* @param {Function} [options.on_overlap_stop] Executes a function when a
|
|
* `collider` is no longer collided.
|
|
* @param {Function} [options.on_overlap] Executes a function when the
|
|
* mouse is moved during the collision.
|
|
* @return {Object} Collision instance.
|
|
* @constructor
|
|
*/
|
|
function Collision(el, colliders, options) {
|
|
this.options = $.extend(defaults, options);
|
|
this.$element = el;
|
|
this.last_colliders = [];
|
|
this.last_colliders_coords = [];
|
|
if (typeof colliders === 'string' || colliders instanceof jQuery) {
|
|
this.$colliders = $(colliders,
|
|
this.options.colliders_context).not(this.$element);
|
|
}else{
|
|
this.colliders = $(colliders);
|
|
}
|
|
|
|
this.init();
|
|
}
|
|
|
|
|
|
var fn = Collision.prototype;
|
|
|
|
|
|
fn.init = function() {
|
|
this.find_collisions();
|
|
};
|
|
|
|
|
|
fn.overlaps = function(a, b) {
|
|
var x = false;
|
|
var y = false;
|
|
|
|
if ((b.x1 >= a.x1 && b.x1 <= a.x2) ||
|
|
(b.x2 >= a.x1 && b.x2 <= a.x2) ||
|
|
(a.x1 >= b.x1 && a.x2 <= b.x2)
|
|
) { x = true; }
|
|
|
|
if ((b.y1 >= a.y1 && b.y1 <= a.y2) ||
|
|
(b.y2 >= a.y1 && b.y2 <= a.y2) ||
|
|
(a.y1 >= b.y1 && a.y2 <= b.y2)
|
|
) { y = true; }
|
|
|
|
return (x && y);
|
|
};
|
|
|
|
|
|
fn.detect_overlapping_region = function(a, b){
|
|
var regionX = '';
|
|
var regionY = '';
|
|
|
|
if (a.y1 > b.cy && a.y1 < b.y2) { regionX = 'N'; }
|
|
if (a.y2 > b.y1 && a.y2 < b.cy) { regionX = 'S'; }
|
|
if (a.x1 > b.cx && a.x1 < b.x2) { regionY = 'W'; }
|
|
if (a.x2 > b.x1 && a.x2 < b.cx) { regionY = 'E'; }
|
|
|
|
return (regionX + regionY) || 'C';
|
|
};
|
|
|
|
|
|
fn.calculate_overlapped_area_coords = function(a, b){
|
|
var x1 = Math.max(a.x1, b.x1);
|
|
var y1 = Math.max(a.y1, b.y1);
|
|
var x2 = Math.min(a.x2, b.x2);
|
|
var y2 = Math.min(a.y2, b.y2);
|
|
|
|
return $({
|
|
left: x1,
|
|
top: y1,
|
|
width : (x2 - x1),
|
|
height: (y2 - y1)
|
|
}).coords().get();
|
|
};
|
|
|
|
|
|
fn.calculate_overlapped_area = function(coords){
|
|
return (coords.width * coords.height);
|
|
};
|
|
|
|
|
|
fn.manage_colliders_start_stop = function(new_colliders_coords, start_callback, stop_callback){
|
|
var last = this.last_colliders_coords;
|
|
|
|
for (var i = 0, il = last.length; i < il; i++) {
|
|
if ($.inArray(last[i], new_colliders_coords) === -1) {
|
|
start_callback.call(this, last[i]);
|
|
}
|
|
}
|
|
|
|
for (var j = 0, jl = new_colliders_coords.length; j < jl; j++) {
|
|
if ($.inArray(new_colliders_coords[j], last) === -1) {
|
|
stop_callback.call(this, new_colliders_coords[j]);
|
|
}
|
|
|
|
}
|
|
};
|
|
|
|
|
|
fn.find_collisions = function(player_data_coords){
|
|
var self = this;
|
|
var colliders_coords = [];
|
|
var colliders_data = [];
|
|
var $colliders = (this.colliders || this.$colliders);
|
|
var count = $colliders.length;
|
|
var player_coords = self.$element.coords()
|
|
.update(player_data_coords || false).get();
|
|
|
|
while(count--){
|
|
var $collider = self.$colliders ?
|
|
$($colliders[count]) : $colliders[count];
|
|
var $collider_coords_ins = ($collider.isCoords) ?
|
|
$collider : $collider.coords();
|
|
var collider_coords = $collider_coords_ins.get();
|
|
var overlaps = self.overlaps(player_coords, collider_coords);
|
|
|
|
if (!overlaps) {
|
|
continue;
|
|
}
|
|
|
|
var region = self.detect_overlapping_region(
|
|
player_coords, collider_coords);
|
|
|
|
//todo: make this an option
|
|
if (region === 'C'){
|
|
var area_coords = self.calculate_overlapped_area_coords(
|
|
player_coords, collider_coords);
|
|
var area = self.calculate_overlapped_area(area_coords);
|
|
var collider_data = {
|
|
area: area,
|
|
area_coords : area_coords,
|
|
region: region,
|
|
coords: collider_coords,
|
|
player_coords: player_coords,
|
|
el: $collider
|
|
};
|
|
|
|
if (self.options.on_overlap) {
|
|
self.options.on_overlap.call(this, collider_data);
|
|
}
|
|
colliders_coords.push($collider_coords_ins);
|
|
colliders_data.push(collider_data);
|
|
}
|
|
}
|
|
|
|
if (self.options.on_overlap_stop || self.options.on_overlap_start) {
|
|
this.manage_colliders_start_stop(colliders_coords,
|
|
self.options.on_overlap_stop, self.options.on_overlap_start);
|
|
}
|
|
|
|
this.last_colliders_coords = colliders_coords;
|
|
|
|
return colliders_data;
|
|
};
|
|
|
|
|
|
fn.get_closest_colliders = function(player_data_coords){
|
|
var colliders = this.find_collisions(player_data_coords);
|
|
var min_area = 100;
|
|
colliders.sort(function(a, b){
|
|
if (a.area <= min_area) {
|
|
return 1;
|
|
}
|
|
|
|
/* if colliders are being overlapped by the "C" (center) region,
|
|
* we have to set a lower index in the array to which they are placed
|
|
* above in the grid. */
|
|
if (a.region === 'C' && b.region === 'C') {
|
|
if (a.coords.y1 < b.coords.y1 || a.coords.x1 < b.coords.x1) {
|
|
return - 1;
|
|
}else{
|
|
return 1;
|
|
}
|
|
}
|
|
|
|
if (a.area < b.area){
|
|
return 1;
|
|
}
|
|
|
|
return 1;
|
|
});
|
|
return colliders;
|
|
};
|
|
|
|
|
|
//jQuery adapter
|
|
$.fn.collision = function(collider, options) {
|
|
return new Collision( this, collider, options );
|
|
};
|
|
|
|
|
|
}(jQuery, window, document));
|
|
|
|
;(function(window, undefined) {
|
|
/* Debounce and throttle functions taken from underscore.js */
|
|
window.debounce = function(func, wait, immediate) {
|
|
var timeout;
|
|
return function() {
|
|
var context = this, args = arguments;
|
|
var later = function() {
|
|
timeout = null;
|
|
if (!immediate) func.apply(context, args);
|
|
};
|
|
if (immediate && !timeout) func.apply(context, args);
|
|
clearTimeout(timeout);
|
|
timeout = setTimeout(later, wait);
|
|
};
|
|
};
|
|
|
|
|
|
window.throttle = function(func, wait) {
|
|
var context, args, timeout, throttling, more, result;
|
|
var whenDone = debounce(
|
|
function(){ more = throttling = false; }, wait);
|
|
return function() {
|
|
context = this; args = arguments;
|
|
var later = function() {
|
|
timeout = null;
|
|
if (more) func.apply(context, args);
|
|
whenDone();
|
|
};
|
|
if (!timeout) timeout = setTimeout(later, wait);
|
|
if (throttling) {
|
|
more = true;
|
|
} else {
|
|
result = func.apply(context, args);
|
|
}
|
|
whenDone();
|
|
throttling = true;
|
|
return result;
|
|
};
|
|
};
|
|
|
|
})(window);
|
|
|
|
;(function($, window, document, undefined){
|
|
|
|
var defaults = {
|
|
items: '.gs_w',
|
|
distance: 1,
|
|
limit: true,
|
|
offset_left: 0,
|
|
autoscroll: true
|
|
// ,drag: function(e){},
|
|
// start : function(e, ui){},
|
|
// stop : function(e){}
|
|
};
|
|
|
|
var $window = $(window);
|
|
var isTouch = !!('ontouchstart' in window);
|
|
var pointer_events = {
|
|
start: isTouch ? 'touchstart' : 'mousedown.draggable',
|
|
move: isTouch ? 'touchmove' : 'mousemove.draggable',
|
|
end: isTouch ? 'touchend' : 'mouseup.draggable'
|
|
};
|
|
|
|
/**
|
|
* Basic drag implementation for DOM elements inside a container.
|
|
* Provide start/stop/drag callbacks.
|
|
*
|
|
* @class Draggable
|
|
* @param {HTMLElement} el The HTMLelement that contains all the widgets
|
|
* to be dragged.
|
|
* @param {Object} [options] An Object with all options you want to
|
|
* overwrite:
|
|
* @param {HTMLElement|String} [options.items] Define who will
|
|
* be the draggable items. Can be a CSS Selector String or a
|
|
* collection of HTMLElements.
|
|
* @param {Number} [options.distance] Distance in pixels after mousedown
|
|
* the mouse must move before dragging should start.
|
|
* @param {Boolean} [options.limit] Constrains dragging to the width of
|
|
* the container
|
|
* @param {offset_left} [options.offset_left] Offset added to the item
|
|
* that is being dragged.
|
|
* @param {Number} [options.drag] Executes a callback when the mouse is
|
|
* moved during the dragging.
|
|
* @param {Number} [options.start] Executes a callback when the drag
|
|
* starts.
|
|
* @param {Number} [options.stop] Executes a callback when the drag stops.
|
|
* @return {Object} Returns `el`.
|
|
* @constructor
|
|
*/
|
|
function Draggable(el, options) {
|
|
this.options = $.extend({}, defaults, options);
|
|
this.$body = $(document.body);
|
|
this.$container = $(el);
|
|
this.$dragitems = $(this.options.items, this.$container);
|
|
this.is_dragging = false;
|
|
this.player_min_left = 0 + this.options.offset_left;
|
|
this.init();
|
|
}
|
|
|
|
var fn = Draggable.prototype;
|
|
|
|
fn.init = function() {
|
|
this.calculate_positions();
|
|
this.$container.css('position', 'relative');
|
|
this.enable();
|
|
|
|
$(window).bind('resize',
|
|
throttle($.proxy(this.calculate_positions, this), 200));
|
|
};
|
|
|
|
|
|
fn.get_actual_pos = function($el) {
|
|
var pos = $el.position();
|
|
return pos;
|
|
};
|
|
|
|
|
|
fn.get_mouse_pos = function(e) {
|
|
if (isTouch) {
|
|
var oe = e.originalEvent;
|
|
e = oe.touches.length ? oe.touches[0] : oe.changedTouches[0];
|
|
};
|
|
|
|
return {
|
|
left: e.clientX,
|
|
top: e.clientY
|
|
};
|
|
};
|
|
|
|
|
|
fn.get_offset = function(e) {
|
|
e.preventDefault();
|
|
var mouse_actual_pos = this.get_mouse_pos(e);
|
|
var diff_x = Math.round(
|
|
mouse_actual_pos.left - this.mouse_init_pos.left);
|
|
var diff_y = Math.round(mouse_actual_pos.top - this.mouse_init_pos.top);
|
|
|
|
var left = Math.round(this.el_init_offset.left + diff_x - this.baseX);
|
|
var top = Math.round(
|
|
this.el_init_offset.top + diff_y - this.baseY + this.scrollOffset);
|
|
|
|
if (this.options.limit) {
|
|
if (left > this.player_max_left) {
|
|
left = this.player_max_left;
|
|
}else if(left < this.player_min_left) {
|
|
left = this.player_min_left;
|
|
}
|
|
}
|
|
|
|
return {
|
|
left: left,
|
|
top: top,
|
|
mouse_left: mouse_actual_pos.left,
|
|
mouse_top: mouse_actual_pos.top
|
|
};
|
|
};
|
|
|
|
|
|
fn.manage_scroll = function(offset) {
|
|
/* scroll document */
|
|
var nextScrollTop;
|
|
var scrollTop = $window.scrollTop();
|
|
var min_window_y = scrollTop;
|
|
var max_window_y = min_window_y + this.window_height;
|
|
|
|
var mouse_down_zone = max_window_y - 50;
|
|
var mouse_up_zone = min_window_y + 50;
|
|
|
|
var abs_mouse_left = offset.mouse_left;
|
|
var abs_mouse_top = min_window_y + offset.mouse_top;
|
|
|
|
var max_player_y = (this.doc_height - this.window_height +
|
|
this.player_height);
|
|
|
|
if (abs_mouse_top >= mouse_down_zone) {
|
|
nextScrollTop = scrollTop + 30;
|
|
if (nextScrollTop < max_player_y) {
|
|
$window.scrollTop(nextScrollTop);
|
|
this.scrollOffset = this.scrollOffset + 30;
|
|
}
|
|
};
|
|
|
|
if (abs_mouse_top <= mouse_up_zone) {
|
|
nextScrollTop = scrollTop - 30;
|
|
if (nextScrollTop > 0) {
|
|
$window.scrollTop(nextScrollTop);
|
|
this.scrollOffset = this.scrollOffset - 30;
|
|
}
|
|
};
|
|
}
|
|
|
|
|
|
fn.calculate_positions = function(e) {
|
|
this.window_height = $window.height();
|
|
}
|
|
|
|
|
|
fn.drag_handler = function(e) {
|
|
var node = e.target.nodeName;
|
|
|
|
if (e.which !== 1 && !isTouch) {
|
|
return;
|
|
}
|
|
|
|
if (node === 'INPUT' || node === 'TEXTAREA' || node === 'SELECT' ||
|
|
node === 'BUTTON') {
|
|
return;
|
|
};
|
|
|
|
var self = this;
|
|
var first = true;
|
|
this.$player = $(e.currentTarget);
|
|
|
|
this.el_init_pos = this.get_actual_pos(this.$player);
|
|
this.mouse_init_pos = this.get_mouse_pos(e);
|
|
this.offsetY = this.mouse_init_pos.top - this.el_init_pos.top;
|
|
|
|
this.$body.on(pointer_events.move, function(mme){
|
|
var mouse_actual_pos = self.get_mouse_pos(mme);
|
|
var diff_x = Math.abs(
|
|
mouse_actual_pos.left - self.mouse_init_pos.left);
|
|
var diff_y = Math.abs(
|
|
mouse_actual_pos.top - self.mouse_init_pos.top);
|
|
if (!(diff_x > self.options.distance ||
|
|
diff_y > self.options.distance)
|
|
) {
|
|
return false;
|
|
}
|
|
|
|
if (first) {
|
|
first = false;
|
|
self.on_dragstart.call(self, mme);
|
|
return false;
|
|
}
|
|
|
|
if (self.is_dragging == true) {
|
|
self.on_dragmove.call(self, mme);
|
|
}
|
|
|
|
return false;
|
|
});
|
|
|
|
return false;
|
|
};
|
|
|
|
|
|
fn.on_dragstart = function(e) {
|
|
e.preventDefault();
|
|
this.drag_start = true;
|
|
this.is_dragging = true;
|
|
var offset = this.$container.offset();
|
|
this.baseX = Math.round(offset.left);
|
|
this.baseY = Math.round(offset.top);
|
|
this.doc_height = $(document).height();
|
|
|
|
if (this.options.helper === 'clone') {
|
|
this.$helper = this.$player.clone()
|
|
.appendTo(this.$container).addClass('helper');
|
|
this.helper = true;
|
|
}else{
|
|
this.helper = false;
|
|
}
|
|
this.scrollOffset = 0;
|
|
this.el_init_offset = this.$player.offset();
|
|
this.player_width = this.$player.width();
|
|
this.player_height = this.$player.height();
|
|
this.player_max_left = (this.$container.width() - this.player_width +
|
|
this.options.offset_left);
|
|
|
|
if (this.options.start) {
|
|
this.options.start.call(this.$player, e, {
|
|
helper: this.helper ? this.$helper : this.$player
|
|
});
|
|
}
|
|
return false;
|
|
};
|
|
|
|
|
|
fn.on_dragmove = function(e) {
|
|
var offset = this.get_offset(e);
|
|
|
|
this.options.autoscroll && this.manage_scroll(offset);
|
|
|
|
(this.helper ? this.$helper : this.$player).css({
|
|
'position': 'absolute',
|
|
'left' : offset.left,
|
|
'top' : offset.top
|
|
});
|
|
|
|
var ui = {
|
|
'position': {
|
|
'left': offset.left,
|
|
'top': offset.top
|
|
}
|
|
};
|
|
|
|
if (this.options.drag) {
|
|
this.options.drag.call(this.$player, e, ui);
|
|
}
|
|
return false;
|
|
};
|
|
|
|
|
|
fn.on_dragstop = function(e) {
|
|
var offset = this.get_offset(e);
|
|
this.drag_start = false;
|
|
|
|
var ui = {
|
|
'position': {
|
|
'left': offset.left,
|
|
'top': offset.top
|
|
}
|
|
};
|
|
|
|
if (this.options.stop) {
|
|
this.options.stop.call(this.$player, e, ui);
|
|
}
|
|
|
|
if (this.helper) {
|
|
this.$helper.remove();
|
|
}
|
|
|
|
return false;
|
|
};
|
|
|
|
fn.on_select_start = function(e) {
|
|
return false;
|
|
}
|
|
|
|
|
|
fn.enable = function(){
|
|
this.$container.on('selectstart', this.on_select_start);
|
|
|
|
this.$container.on(pointer_events.start, this.options.items, $.proxy(
|
|
this.drag_handler, this));
|
|
|
|
this.$body.on(pointer_events.end, $.proxy(function(e) {
|
|
this.is_dragging = false;
|
|
this.$body.off(pointer_events.move);
|
|
if (this.drag_start) {
|
|
this.on_dragstop(e);
|
|
}
|
|
}, this));
|
|
};
|
|
|
|
|
|
fn.disable = function(){
|
|
this.$container.off(pointer_events.start);
|
|
this.$body.off(pointer_events.end);
|
|
this.$container.off('selectstart', this.on_select_start);
|
|
};
|
|
|
|
|
|
fn.destroy = function(){
|
|
this.disable();
|
|
$.removeData(this.$container, 'drag');
|
|
};
|
|
|
|
|
|
//jQuery adapter
|
|
$.fn.drag = function ( options ) {
|
|
return this.each(function () {
|
|
if (!$.data(this, 'drag')) {
|
|
$.data(this, 'drag', new Draggable( this, options ));
|
|
}
|
|
});
|
|
};
|
|
|
|
|
|
}(jQuery, window, document));
|
|
|
|
;(function($, window, document, undefined) {
|
|
|
|
var defaults = {
|
|
widget_selector: '> li',
|
|
widget_margins: [10, 10],
|
|
widget_base_dimensions: [400, 225],
|
|
extra_rows: 0,
|
|
extra_cols: 0,
|
|
min_cols: 1,
|
|
min_rows: 15,
|
|
max_size_x: 6,
|
|
max_size_y: 6,
|
|
autogenerate_stylesheet: true,
|
|
avoid_overlapped_widgets: true,
|
|
serialize_params: function($w, wgd) {
|
|
return {
|
|
col: wgd.col,
|
|
row: wgd.row
|
|
};
|
|
},
|
|
collision: {},
|
|
draggable: {
|
|
distance: 4
|
|
}
|
|
};
|
|
|
|
|
|
/**
|
|
* @class Gridster
|
|
* @uses Draggable
|
|
* @uses Collision
|
|
* @param {HTMLElement} el The HTMLelement that contains all the widgets.
|
|
* @param {Object} [options] An Object with all options you want to
|
|
* overwrite:
|
|
* @param {HTMLElement|String} [options.widget_selector] Define who will
|
|
* be the draggable widgets. Can be a CSS Selector String or a
|
|
* collection of HTMLElements
|
|
* @param {Array} [options.widget_margins] Margin between widgets.
|
|
* The first index for the horizontal margin (left, right) and
|
|
* the second for the vertical margin (top, bottom).
|
|
* @param {Array} [options.widget_base_dimensions] Base widget dimensions
|
|
* in pixels. The first index for the width and the second for the
|
|
* height.
|
|
* @param {Number} [options.extra_cols] Add more columns in addition to
|
|
* those that have been calculated.
|
|
* @param {Number} [options.extra_rows] Add more rows in addition to
|
|
* those that have been calculated.
|
|
* @param {Number} [options.min_cols] The minimum required columns.
|
|
* @param {Number} [options.min_rows] The minimum required rows.
|
|
* @param {Number} [options.max_size_x] The maximum number of columns
|
|
* that a widget can span.
|
|
* @param {Number} [options.max_size_y] The maximum number of rows
|
|
* that a widget can span.
|
|
* @param {Boolean} [options.autogenerate_stylesheet] If true, all the
|
|
* CSS required to position all widgets in their respective columns
|
|
* and rows will be generated automatically and injected to the
|
|
* `<head>` of the document. You can set this to false, and write
|
|
* your own CSS targeting rows and cols via data-attributes like so:
|
|
* `[data-col="1"] { left: 10px; }`
|
|
* @param {Boolean} [options.avoid_overlapped_widgets] Avoid that widgets loaded
|
|
* from the DOM can be overlapped. It is helpful if the positions were
|
|
* bad stored in the database or if there was any conflict.
|
|
* @param {Function} [options.serialize_params] Return the data you want
|
|
* for each widget in the serialization. Two arguments are passed:
|
|
* `$w`: the jQuery wrapped HTMLElement, and `wgd`: the grid
|
|
* coords object (`col`, `row`, `size_x`, `size_y`).
|
|
* @param {Object} [options.collision] An Object with all options for
|
|
* Collision class you want to overwrite. See Collision docs for
|
|
* more info.
|
|
* @param {Object} [options.draggable] An Object with all options for
|
|
* Draggable class you want to overwrite. See Draggable docs for more
|
|
* info.
|
|
*
|
|
* @constructor
|
|
*/
|
|
function Gridster(el, options) {
|
|
this.options = $.extend(true, defaults, options);
|
|
this.$el = $(el);
|
|
this.$wrapper = this.$el.parent();
|
|
this.$widgets = $(this.options.widget_selector, this.$el).addClass('gs_w');
|
|
this.widgets = [];
|
|
this.$changed = $([]);
|
|
this.wrapper_width = this.$wrapper.width();
|
|
this.min_widget_width = (this.options.widget_margins[0] * 2) +
|
|
this.options.widget_base_dimensions[0];
|
|
this.min_widget_height = (this.options.widget_margins[1] * 2) +
|
|
this.options.widget_base_dimensions[1];
|
|
this.init();
|
|
}
|
|
|
|
Gridster.generated_stylesheets = [];
|
|
|
|
var fn = Gridster.prototype;
|
|
|
|
fn.init = function() {
|
|
this.generate_grid_and_stylesheet();
|
|
this.get_widgets_from_DOM();
|
|
this.set_dom_grid_height();
|
|
this.$wrapper.addClass('ready');
|
|
this.draggable();
|
|
|
|
$(window).bind(
|
|
'resize', throttle($.proxy(this.recalculate_faux_grid, this), 200));
|
|
};
|
|
|
|
|
|
/**
|
|
* Disables dragging.
|
|
*
|
|
* @method disable
|
|
* @return {Class} Returns the instance of the Gridster Class.
|
|
*/
|
|
fn.disable = function() {
|
|
this.$wrapper.find('.player-revert').removeClass('player-revert');
|
|
this.drag_api.disable();
|
|
return this;
|
|
};
|
|
|
|
|
|
/**
|
|
* Enables dragging.
|
|
*
|
|
* @method enable
|
|
* @return {Class} Returns the instance of the Gridster Class.
|
|
*/
|
|
fn.enable = function() {
|
|
this.drag_api.enable();
|
|
return this;
|
|
};
|
|
|
|
|
|
/**
|
|
* Add a new widget to the grid.
|
|
*
|
|
* @method add_widget
|
|
* @param {String} html The string representing the HTML of the widget.
|
|
* @param {Number} size_x The no of rows the widget occupies horizontally.
|
|
* @param {Number} size_y The no of columns the widget occupies vertically.
|
|
* @return {HTMLElement} Returns the jQuery wrapped HTMLElement representing.
|
|
* the widget that was just created.
|
|
*/
|
|
fn.add_widget = function(html, size_x, size_y) {
|
|
var next_pos = this.next_position(size_x, size_y);
|
|
|
|
var $w = $(html).attr({
|
|
'data-col': next_pos.col,
|
|
'data-row': next_pos.row,
|
|
'data-sizex' : next_pos.size_x,
|
|
'data-sizey' : next_pos.size_y
|
|
}).addClass('gs_w').appendTo(this.$el).hide();
|
|
|
|
this.$widgets = this.$widgets.add($w);
|
|
|
|
this.register_widget($w);
|
|
|
|
this.set_dom_grid_height();
|
|
|
|
return $w.fadeIn();
|
|
};
|
|
|
|
|
|
/**
|
|
* Get the most left column below to add a new widget.
|
|
*
|
|
* @method next_position
|
|
* @param {Number} size_x The no of rows the widget occupies horizontally.
|
|
* @param {Number} size_y The no of columns the widget occupies vertically.
|
|
* @return {Object} Returns a grid coords object representing the future
|
|
* widget coords.
|
|
*/
|
|
fn.next_position = function(size_x, size_y) {
|
|
size_x || (size_x = 1);
|
|
size_y || (size_y = 1);
|
|
var ga = this.gridmap;
|
|
var cols_l = ga.length;
|
|
var valid_pos = [];
|
|
|
|
for (var c = 1; c < cols_l; c++) {
|
|
var rows_l = ga[c].length;
|
|
for (var r = 1; r <= rows_l; r++) {
|
|
var can_move_to = this.can_move_to({
|
|
size_x: size_x,
|
|
size_y: size_y
|
|
}, c, r);
|
|
|
|
if (can_move_to) {
|
|
valid_pos.push({
|
|
col: c,
|
|
row: r,
|
|
size_y: size_y,
|
|
size_x: size_x
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
if (valid_pos.length) {
|
|
return this.sort_by_row_and_col_asc(valid_pos)[0];
|
|
}
|
|
return false;
|
|
};
|
|
|
|
|
|
/**
|
|
* Remove a widget from the grid.
|
|
*
|
|
* @method remove_widget
|
|
* @param {HTMLElement} el The jQuery wrapped HTMLElement you want to remove.
|
|
* @return {Class} Returns the instance of the Gridster Class.
|
|
*/
|
|
fn.remove_widget = function(el, callback) {
|
|
var $el = el instanceof jQuery ? el : $(el);
|
|
var wgd = $el.coords().grid;
|
|
|
|
this.cells_occupied_by_placeholder = {};
|
|
this.$widgets = this.$widgets.not($el);
|
|
|
|
var $nexts = this.widgets_below($el);
|
|
|
|
this.remove_from_gridmap(wgd);
|
|
|
|
$el.fadeOut($.proxy(function() {
|
|
$el.remove();
|
|
|
|
$nexts.each($.proxy(function(i, widget) {
|
|
this.move_widget_up( $(widget), wgd.size_y );
|
|
}, this));
|
|
|
|
this.set_dom_grid_height();
|
|
|
|
if (callback) {
|
|
callback.call(this, el);
|
|
}
|
|
}, this));
|
|
};
|
|
|
|
|
|
/**
|
|
* Returns a serialized array of the widgets in the grid.
|
|
*
|
|
* @method serialize
|
|
* @param {HTMLElement} [$widgets] The collection of jQuery wrapped
|
|
* HTMLElements you want to serialize. If no argument is passed all widgets
|
|
* will be serialized.
|
|
* @return {Array} Returns an Array of Objects with the data specified in
|
|
* the serialize_params option.
|
|
*/
|
|
fn.serialize = function($widgets) {
|
|
$widgets || ($widgets = this.$widgets);
|
|
var result = [];
|
|
$widgets.each($.proxy(function(i, widget) {
|
|
result.push(this.options.serialize_params(
|
|
$(widget), $(widget).coords().grid ) );
|
|
}, this));
|
|
|
|
return result;
|
|
};
|
|
|
|
|
|
/**
|
|
* Returns a serialized array of the widgets that have changed their
|
|
* position.
|
|
*
|
|
* @method serialize_changed
|
|
* @return {Array} Returns an Array of Objects with the data specified in
|
|
* the serialize_params option.
|
|
*/
|
|
fn.serialize_changed = function() {
|
|
return this.serialize(this.$changed);
|
|
};
|
|
|
|
|
|
/**
|
|
* Creates the grid coords object representing the widget a add it to the
|
|
* mapped array of positions.
|
|
*
|
|
* @method register_widget
|
|
* @return {Array} Returns the instance of the Gridster class.
|
|
*/
|
|
fn.register_widget = function($el) {
|
|
|
|
var wgd = {
|
|
'col': parseInt($el.attr('data-col'), 10),
|
|
'row': parseInt($el.attr('data-row'), 10),
|
|
'size_x': parseInt($el.attr('data-sizex'), 10),
|
|
'size_y': parseInt($el.attr('data-sizey'), 10),
|
|
'el': $el
|
|
};
|
|
|
|
if (this.options.avoid_overlapped_widgets &&
|
|
!this.can_move_to(
|
|
{size_x: wgd.size_x, size_y: wgd.size_y}, wgd.col, wgd.row)
|
|
) {
|
|
wgd = this.next_position(wgd.size_x, wgd.size_y);
|
|
wgd.el = $el;
|
|
$el.attr({
|
|
'data-col': wgd.col,
|
|
'data-row': wgd.row,
|
|
'data-sizex': wgd.size_x,
|
|
'data-sizey': wgd.size_y
|
|
});
|
|
}
|
|
|
|
// attach Coord object to player data-coord attribute
|
|
$el.data('coords', $el.coords());
|
|
|
|
// Extend Coord object with grid position info
|
|
$el.data('coords').grid = wgd;
|
|
|
|
this.add_to_gridmap(wgd, $el);
|
|
this.widgets.push($el);
|
|
return this;
|
|
};
|
|
|
|
|
|
/**
|
|
* Update in the mapped array of positions the value of cells represented by
|
|
* the grid coords object passed in the `grid_data` param.
|
|
*
|
|
* @param {Object} grid_data The grid coords object representing the cells
|
|
* to update in the mapped array.
|
|
* @param {HTMLElement|Boolean} value Pass `false` or the jQuery wrapped
|
|
* HTMLElement, depends if you want to delete an existing position or add
|
|
* a new one.
|
|
* @method update_widget_position
|
|
* @return {Class} Returns the instance of the Gridster Class.
|
|
*/
|
|
fn.update_widget_position = function(grid_data, value) {
|
|
this.for_each_cell_occupied(grid_data, function(col, row) {
|
|
if (!this.gridmap[col]) { return this; }
|
|
this.gridmap[col][row] = value;
|
|
});
|
|
return this;
|
|
};
|
|
|
|
|
|
/**
|
|
* Remove a widget from the mapped array of positions.
|
|
*
|
|
* @method remove_from_gridmap
|
|
* @param {Object} grid_data The grid coords object representing the cells
|
|
* to update in the mapped array.
|
|
* @return {Class} Returns the instance of the Gridster Class.
|
|
*/
|
|
fn.remove_from_gridmap = function(grid_data) {
|
|
return this.update_widget_position(grid_data, false);
|
|
};
|
|
|
|
|
|
/**
|
|
* Add a widget to the mapped array of positions.
|
|
*
|
|
* @method add_to_gridmap
|
|
* @param {Object} grid_data The grid coords object representing the cells
|
|
* to update in the mapped array.
|
|
* @param {HTMLElement|Boolean} value The value to set in the specified
|
|
* position .
|
|
* @return {Class} Returns the instance of the Gridster Class.
|
|
*/
|
|
fn.add_to_gridmap = function(grid_data, value) {
|
|
this.update_widget_position(grid_data, value || grid_data.el);
|
|
|
|
if (grid_data.el) {
|
|
var $widgets = this.widgets_below(grid_data.el);
|
|
$widgets.each($.proxy(function(i, widget) {
|
|
this.move_widget_up( $(widget));
|
|
}, this));
|
|
}
|
|
};
|
|
|
|
|
|
/**
|
|
* Make widgets draggable.
|
|
*
|
|
* @uses Draggable
|
|
* @method draggable
|
|
* @return {Class} Returns the instance of the Gridster Class.
|
|
*/
|
|
fn.draggable = function() {
|
|
var self = this;
|
|
var draggable_options = $.extend(true, {}, this.options.draggable, {
|
|
offset_left: this.options.widget_margins[0],
|
|
items: '.gs_w',
|
|
start: function(event, ui) {
|
|
self.$widgets.filter('.player-revert')
|
|
.removeClass('player-revert');
|
|
|
|
self.$player = $(this);
|
|
self.$helper = self.options.draggable.helper === 'clone' ?
|
|
$(ui.helper) : self.$player;
|
|
self.helper = !self.$helper.is(self.$player);
|
|
|
|
self.on_start_drag.call(self, event, ui);
|
|
self.$el.trigger('gridster:dragstart');
|
|
},
|
|
stop: function(event, ui) {
|
|
self.on_stop_drag.call(self, event, ui);
|
|
self.$el.trigger('gridster:dragstop');
|
|
},
|
|
drag: throttle(function(event, ui) {
|
|
self.on_drag.call(self, event, ui);
|
|
self.$el.trigger('gridster:drag');
|
|
}, 60)
|
|
});
|
|
|
|
this.drag_api = this.$el.drag(draggable_options).data('drag');
|
|
return this;
|
|
};
|
|
|
|
|
|
/**
|
|
* This function is executed when the player begins to be dragged.
|
|
*
|
|
* @method on_start_drag
|
|
* @param {Event} The original browser event
|
|
* @param {Object} A prepared ui object.
|
|
*/
|
|
fn.on_start_drag = function(event, ui) {
|
|
|
|
this.$helper.add(this.$player).add(this.$wrapper).addClass('dragging');
|
|
|
|
this.$player.addClass('player');
|
|
this.player_grid_data = this.$player.coords().grid;
|
|
this.placeholder_grid_data = $.extend({}, this.player_grid_data);
|
|
|
|
//set new grid height along the dragging period
|
|
this.$el.css('height', this.$el.height() +
|
|
(this.player_grid_data.size_y * this.min_widget_height));
|
|
|
|
var colliders = this.faux_grid;
|
|
var coords = this.$player.data('coords').coords;
|
|
|
|
this.cells_occupied_by_player = this.get_cells_occupied(
|
|
this.player_grid_data);
|
|
this.cells_occupied_by_placeholder = this.get_cells_occupied(
|
|
this.placeholder_grid_data);
|
|
|
|
this.last_cols = [];
|
|
this.last_rows = [];
|
|
|
|
|
|
// see jquery.collision.js
|
|
this.collision_api = this.$helper.collision(
|
|
colliders, this.options.collision);
|
|
|
|
this.$preview_holder = $('<li />', {
|
|
'class': 'preview-holder',
|
|
'data-row': this.$player.attr('data-row'),
|
|
'data-col': this.$player.attr('data-col'),
|
|
css: {
|
|
width: coords.width,
|
|
height: coords.height
|
|
}
|
|
}).appendTo(this.$el);
|
|
|
|
if (this.options.draggable.start) {
|
|
this.options.draggable.start.call(this, event, ui);
|
|
}
|
|
};
|
|
|
|
|
|
/**
|
|
* This function is executed when the player is being dragged.
|
|
*
|
|
* @method on_drag
|
|
* @param {Event} The original browser event
|
|
* @param {Object} A prepared ui object.
|
|
*/
|
|
fn.on_drag = function(event, ui) {
|
|
//break if dragstop has been fired
|
|
if (this.$player === null) {
|
|
return false;
|
|
};
|
|
|
|
var abs_offset = {
|
|
left: ui.position.left + this.baseX,
|
|
top: ui.position.top + this.baseY
|
|
};
|
|
|
|
this.colliders_data = this.collision_api.get_closest_colliders(
|
|
abs_offset);
|
|
|
|
this.on_overlapped_column_change(
|
|
this.on_start_overlapping_column,
|
|
this.on_stop_overlapping_column
|
|
);
|
|
|
|
this.on_overlapped_row_change(
|
|
this.on_start_overlapping_row,
|
|
this.on_stop_overlapping_row
|
|
);
|
|
|
|
if (this.helper && this.$player) {
|
|
this.$player.css({
|
|
'left': ui.position.left,
|
|
'top': ui.position.top
|
|
});
|
|
}
|
|
|
|
if (this.options.draggable.drag) {
|
|
this.options.draggable.drag.call(this, event, ui);
|
|
}
|
|
};
|
|
|
|
/**
|
|
* This function is executed when the player stops being dragged.
|
|
*
|
|
* @method on_stop_drag
|
|
* @param {Event} The original browser event
|
|
* @param {Object} A prepared ui object.
|
|
*/
|
|
fn.on_stop_drag = function(event, ui) {
|
|
this.$helper.add(this.$player).add(this.$wrapper)
|
|
.removeClass('dragging');
|
|
|
|
ui.position.left = ui.position.left + this.baseX;
|
|
ui.position.top = ui.position.top + this.baseY;
|
|
this.colliders_data = this.collision_api.get_closest_colliders(ui.position);
|
|
|
|
this.on_overlapped_column_change(
|
|
this.on_start_overlapping_column,
|
|
this.on_stop_overlapping_column
|
|
);
|
|
|
|
this.on_overlapped_row_change(
|
|
this.on_start_overlapping_row,
|
|
this.on_stop_overlapping_row
|
|
);
|
|
|
|
this.$player.addClass('player-revert').removeClass('player')
|
|
.attr({
|
|
'data-col': this.placeholder_grid_data.col,
|
|
'data-row': this.placeholder_grid_data.row
|
|
}).css({
|
|
'left': '',
|
|
'top': ''
|
|
});
|
|
|
|
this.$changed = this.$changed.add(this.$player);
|
|
|
|
this.cells_occupied_by_player = this.get_cells_occupied(
|
|
this.placeholder_grid_data);
|
|
this.set_cells_player_occupies(
|
|
this.placeholder_grid_data.col, this.placeholder_grid_data.row);
|
|
|
|
this.$player.coords().grid.row = this.placeholder_grid_data.row;
|
|
this.$player.coords().grid.col = this.placeholder_grid_data.col;
|
|
|
|
if (this.options.draggable.stop) {
|
|
this.options.draggable.stop.call(this, event, ui);
|
|
}
|
|
|
|
this.$preview_holder.remove();
|
|
this.$player = null;
|
|
|
|
this.set_dom_grid_height();
|
|
};
|
|
|
|
|
|
/**
|
|
* Executes the callbacks passed as arguments when a column begins to be
|
|
* overlapped or stops being overlapped.
|
|
*
|
|
* @param {Function} start_callback Function executed when a new column
|
|
* begins to be overlapped. The column is passed as first argument.
|
|
* @param {Function} stop_callback Function executed when a column stops
|
|
* being overlapped. The column is passed as first argument.
|
|
* @method on_overlapped_column_change
|
|
* @return {Class} Returns the instance of the Gridster Class.
|
|
*/
|
|
fn.on_overlapped_column_change = function(start_callback, stop_callback) {
|
|
if (!this.colliders_data.length) {
|
|
return;
|
|
}
|
|
var cols = this.get_targeted_columns(
|
|
this.colliders_data[0].el.data.col);
|
|
|
|
var last_n_cols = this.last_cols.length;
|
|
var n_cols = cols.length;
|
|
var i;
|
|
|
|
for (i = 0; i < n_cols; i++) {
|
|
if ($.inArray(cols[i], this.last_cols) === -1) {
|
|
(start_callback || $.noop).call(this, cols[i]);
|
|
}
|
|
}
|
|
|
|
for (i = 0; i< last_n_cols; i++) {
|
|
if ($.inArray(this.last_cols[i], cols) === -1) {
|
|
(stop_callback || $.noop).call(this, this.last_cols[i]);
|
|
}
|
|
}
|
|
|
|
this.last_cols = cols;
|
|
|
|
return this;
|
|
};
|
|
|
|
|
|
/**
|
|
* Executes the callbacks passed as arguments when a row starts to be
|
|
* overlapped or stops being overlapped.
|
|
*
|
|
* @param {Function} start_callback Function executed when a new row begins
|
|
* to be overlapped. The row is passed as first argument.
|
|
* @param {Function} stop_callback Function executed when a row stops being
|
|
* overlapped. The row is passed as first argument.
|
|
* @method on_overlapped_row_change
|
|
* @return {Class} Returns the instance of the Gridster Class.
|
|
*/
|
|
fn.on_overlapped_row_change = function(start_callback, end_callback) {
|
|
if (!this.colliders_data.length) {
|
|
return;
|
|
}
|
|
var rows = this.get_targeted_rows(this.colliders_data[0].el.data.row);
|
|
var last_n_rows = this.last_rows.length;
|
|
var n_rows = rows.length;
|
|
var i;
|
|
|
|
for (i = 0; i < n_rows; i++) {
|
|
if ($.inArray(rows[i], this.last_rows) === -1) {
|
|
(start_callback || $.noop).call(this, rows[i]);
|
|
}
|
|
}
|
|
|
|
for (i = 0; i < last_n_rows; i++) {
|
|
if ($.inArray(this.last_rows[i], rows) === -1) {
|
|
(end_callback || $.noop).call(this, this.last_rows[i]);
|
|
}
|
|
}
|
|
|
|
this.last_rows = rows;
|
|
};
|
|
|
|
|
|
/**
|
|
* Sets the current position of the player
|
|
*
|
|
* @param {Function} start_callback Function executed when a new row begins
|
|
* to be overlapped. The row is passed as first argument.
|
|
* @param {Function} stop_callback Function executed when a row stops being
|
|
* overlapped. The row is passed as first argument.
|
|
* @method set_player
|
|
* @return {Class} Returns the instance of the Gridster Class.
|
|
*/
|
|
fn.set_player = function(col, row) {
|
|
this.empty_cells_player_occupies();
|
|
|
|
var self = this;
|
|
var cell = self.colliders_data[0].el.data;
|
|
var to_col = cell.col;
|
|
var to_row = row || cell.row;
|
|
|
|
this.player_grid_data = {
|
|
col: to_col,
|
|
row: to_row,
|
|
size_y : this.player_grid_data.size_y,
|
|
size_x : this.player_grid_data.size_x
|
|
};
|
|
|
|
this.cells_occupied_by_player = this.get_cells_occupied(
|
|
this.player_grid_data);
|
|
|
|
var $overlapped_widgets = this.get_widgets_overlapped(
|
|
this.player_grid_data);
|
|
|
|
var constraints = this.widgets_constraints($overlapped_widgets);
|
|
|
|
this.manage_movements(constraints.can_go_up, to_col, to_row);
|
|
this.manage_movements(constraints.can_not_go_up, to_col, to_row);
|
|
|
|
/* if there is not widgets overlapping in the new player position,
|
|
* update the new placeholder position. */
|
|
if (!$overlapped_widgets.length) {
|
|
var pp = this.can_go_player_up(this.player_grid_data);
|
|
if (pp !== false) {
|
|
to_row = pp;
|
|
}
|
|
this.set_placeholder(to_col, to_row);
|
|
}
|
|
|
|
return {
|
|
col: to_col,
|
|
row: to_row
|
|
};
|
|
};
|
|
|
|
|
|
/**
|
|
* See which of the widgets in the $widgets param collection can go to
|
|
* a upper row and which not.
|
|
*
|
|
* @method widgets_contraints
|
|
* @param {HTMLElements} $widgets A jQuery wrapped collection of
|
|
* HTMLElements.
|
|
* @return {Array} Returns a literal Object with two keys: `can_go_up` &
|
|
* `can_not_go_up`. Each contains a set of HTMLElements.
|
|
*/
|
|
fn.widgets_constraints = function($widgets) {
|
|
var $widgets_can_go_up = $([]);
|
|
var $widgets_can_not_go_up;
|
|
var wgd_can_go_up = [];
|
|
var wgd_can_not_go_up = [];
|
|
|
|
$widgets.each($.proxy(function(i, w) {
|
|
var $w = $(w);
|
|
var wgd = $w.coords().grid;
|
|
if (this.can_go_widget_up(wgd)) {
|
|
$widgets_can_go_up = $widgets_can_go_up.add($w);
|
|
wgd_can_go_up.push(wgd);
|
|
}else{
|
|
wgd_can_not_go_up.push(wgd);
|
|
}
|
|
}, this));
|
|
|
|
$widgets_can_not_go_up = $widgets.not($widgets_can_go_up);
|
|
|
|
return {
|
|
can_go_up: this.sort_by_row_asc(wgd_can_go_up),
|
|
can_not_go_up: this.sort_by_row_desc(wgd_can_not_go_up)
|
|
};
|
|
};
|
|
|
|
|
|
/**
|
|
* Sorts an Array of grid coords objects (representing the grid coords of
|
|
* each widget) in ascending way.
|
|
*
|
|
* @method sort_by_row_asc
|
|
* @param {Array} widgets Array of grid coords objects
|
|
* @return {Array} Returns the array sorted.
|
|
*/
|
|
fn.sort_by_row_asc = function(widgets) {
|
|
widgets = widgets.sort(function(a, b) {
|
|
if (a.row > b.row) {
|
|
return 1;
|
|
}
|
|
return -1;
|
|
});
|
|
|
|
return widgets;
|
|
};
|
|
|
|
|
|
/**
|
|
* Sorts an Array of grid coords objects (representing the grid coords of
|
|
* each widget) placing first the empty cells upper left.
|
|
*
|
|
* @method sort_by_row_and_col_asc
|
|
* @param {Array} widgets Array of grid coords objects
|
|
* @return {Array} Returns the array sorted.
|
|
*/
|
|
fn.sort_by_row_and_col_asc = function(widgets) {
|
|
widgets = widgets.sort(function(a, b) {
|
|
if (a.row > b.row || a.row == b.row && a.col > b.col) {
|
|
return 1;
|
|
}
|
|
return -1;
|
|
});
|
|
|
|
return widgets;
|
|
};
|
|
|
|
|
|
/**
|
|
* Sorts an Array of grid coords objects by column (representing the grid
|
|
* coords of each widget) in ascending way.
|
|
*
|
|
* @method sort_by_col_asc
|
|
* @param {Array} widgets Array of grid coords objects
|
|
* @return {Array} Returns the array sorted.
|
|
*/
|
|
fn.sort_by_col_asc = function(widgets) {
|
|
widgets = widgets.sort(function(a, b) {
|
|
if (a.col > b.col) {
|
|
return 1;
|
|
}
|
|
return -1;
|
|
});
|
|
|
|
return widgets;
|
|
};
|
|
|
|
|
|
/**
|
|
* Sorts an Array of grid coords objects (representing the grid coords of
|
|
* each widget) in descending way.
|
|
*
|
|
* @method sort_by_row_desc
|
|
* @param {Array} widgets Array of grid coords objects
|
|
* @return {Array} Returns the array sorted.
|
|
*/
|
|
fn.sort_by_row_desc = function(widgets) {
|
|
widgets = widgets.sort(function(a, b) {
|
|
if (a.row + a.size_y < b.row + b.size_y) {
|
|
return 1;
|
|
}
|
|
return -1;
|
|
});
|
|
return widgets;
|
|
};
|
|
|
|
|
|
/**
|
|
* Sorts an Array of grid coords objects (representing the grid coords of
|
|
* each widget) in descending way.
|
|
*
|
|
* @method manage_movements
|
|
* @param {HTMLElements} $widgets A jQuery collection of HTMLElements
|
|
* representing the widgets you want to move.
|
|
* @param {Number} to_col The column to which we want to move the widgets.
|
|
* @param {Number} to_row The row to which we want to move the widgets.
|
|
* @return {Class} Returns the instance of the Gridster Class.
|
|
*/
|
|
fn.manage_movements = function($widgets, to_col, to_row) {
|
|
$.each($widgets, $.proxy(function(i, w) {
|
|
var wgd = w;
|
|
var $w = wgd.el;
|
|
|
|
var can_go_widget_up = this.can_go_widget_up(wgd);
|
|
|
|
if (can_go_widget_up) {
|
|
//target CAN go up
|
|
//so move widget up
|
|
this.move_widget_to($w, can_go_widget_up);
|
|
this.set_placeholder(to_col, can_go_widget_up + wgd.size_y);
|
|
|
|
} else {
|
|
//target can't go up
|
|
var can_go_player_up = this.can_go_player_up(
|
|
this.player_grid_data);
|
|
|
|
if (!can_go_player_up) {
|
|
// target can't go up
|
|
// player cant't go up
|
|
// so we need to move widget down to a position that dont
|
|
// overlaps player
|
|
var y = (to_row + this.player_grid_data.size_y) - wgd.row;
|
|
|
|
this.move_widget_down($w, y);
|
|
this.set_placeholder(to_col, to_row);
|
|
}
|
|
}
|
|
}, this));
|
|
|
|
return this;
|
|
};
|
|
|
|
/**
|
|
* Determines if there is a widget in the row and col given. Or if the
|
|
* HTMLElement passed as first argument is the player.
|
|
*
|
|
* @method is_player
|
|
* @param {Number|HTMLElement} col_or_el A jQuery wrapped collection of
|
|
* HTMLElements.
|
|
* @param {Number} [row] The column to which we want to move the widgets.
|
|
* @return {Boolean} Returns true or false.
|
|
*/
|
|
fn.is_player = function(col_or_el, row) {
|
|
if (row && !this.gridmap[col_or_el]) { return false; }
|
|
var $w = row ? this.gridmap[col_or_el][row] : col_or_el;
|
|
return $w && ($w.is(this.$player) || $w.is(this.$helper));
|
|
};
|
|
|
|
|
|
/**
|
|
* Determines if the widget that is being dragged is currently over the row
|
|
* and col given.
|
|
*
|
|
* @method is_player_in
|
|
* @param {Number} col The column to check.
|
|
* @param {Number} row The row to check.
|
|
* @return {Boolean} Returns true or false.
|
|
*/
|
|
fn.is_player_in = function(col, row) {
|
|
var c = this.cells_occupied_by_player || {};
|
|
return $.inArray(col, c.cols) >= 0 && $.inArray(row, c.rows) >= 0;
|
|
};
|
|
|
|
|
|
/**
|
|
* Determines if the placeholder is currently over the row and col given.
|
|
*
|
|
* @method is_placeholder_in
|
|
* @param {Number} col The column to check.
|
|
* @param {Number} row The row to check.
|
|
* @return {Boolean} Returns true or false.
|
|
*/
|
|
fn.is_placeholder_in = function(col, row) {
|
|
var c = this.cells_occupied_by_placeholder || {};
|
|
return this.is_placeholder_in_col(col) && $.inArray(row, c.rows) >= 0;
|
|
};
|
|
|
|
|
|
/**
|
|
* Determines if the placeholder is currently over the column given.
|
|
*
|
|
* @method is_placeholder_in_col
|
|
* @param {Number} col The column to check.
|
|
* @return {Boolean} Returns true or false.
|
|
*/
|
|
fn.is_placeholder_in_col = function(col) {
|
|
var c = this.cells_occupied_by_placeholder || [];
|
|
return $.inArray(col, c.cols) >= 0;
|
|
};
|
|
|
|
|
|
/**
|
|
* Determines if the cell represented by col and row params is empty.
|
|
*
|
|
* @method is_empty
|
|
* @param {Number} col The column to check.
|
|
* @param {Number} row The row to check.
|
|
* @return {Boolean} Returns true or false.
|
|
*/
|
|
fn.is_empty = function(col, row) {
|
|
if (typeof this.gridmap[col] !== 'undefined' &&
|
|
typeof this.gridmap[col][row] !== 'undefined' &&
|
|
this.gridmap[col][row] === false
|
|
) {
|
|
return true;
|
|
}
|
|
return false;
|
|
};
|
|
|
|
|
|
/**
|
|
* Determines if the cell represented by col and row params is occupied.
|
|
*
|
|
* @method is_occupied
|
|
* @param {Number} col The column to check.
|
|
* @param {Number} row The row to check.
|
|
* @return {Boolean} Returns true or false.
|
|
*/
|
|
fn.is_occupied = function(col, row) {
|
|
if (!this.gridmap[col]) {
|
|
return false;
|
|
}
|
|
|
|
if (this.gridmap[col][row]) {
|
|
return true;
|
|
}
|
|
return false;
|
|
};
|
|
|
|
|
|
/**
|
|
* Determines if there is a widget in the cell represented by col/row params.
|
|
*
|
|
* @method is_widget
|
|
* @param {Number} col The column to check.
|
|
* @param {Number} row The row to check.
|
|
* @return {Boolean|HTMLElement} Returns false if there is no widget,
|
|
* else returns the jQuery HTMLElement
|
|
*/
|
|
fn.is_widget = function(col, row) {
|
|
var cell = this.gridmap[col];
|
|
if (!cell) {
|
|
return false;
|
|
}
|
|
|
|
cell = cell[row];
|
|
|
|
if (cell) {
|
|
return cell;
|
|
}
|
|
|
|
return false;
|
|
};
|
|
|
|
|
|
/**
|
|
* Determines if there is a widget in the cell represented by col/row
|
|
* params and if this is under the widget that is being dragged.
|
|
*
|
|
* @method is_widget_under_player
|
|
* @param {Number} col The column to check.
|
|
* @param {Number} row The row to check.
|
|
* @return {Boolean} Returns true or false.
|
|
*/
|
|
fn.is_widget_under_player = function(col, row) {
|
|
if (this.is_widget(col, row)) {
|
|
return this.is_player_in(col, row);
|
|
}
|
|
return false;
|
|
};
|
|
|
|
|
|
/**
|
|
* Get widgets overlapping with the player.
|
|
*
|
|
* @method get_widgets_under_player
|
|
* @return {HTMLElement} Returns a jQuery collection of HTMLElements
|
|
*/
|
|
fn.get_widgets_under_player = function() {
|
|
var cells = this.cells_occupied_by_player;
|
|
var $widgets = $([]);
|
|
|
|
$.each(cells.cols, $.proxy(function(i, col) {
|
|
$.each(cells.rows, $.proxy(function(i, row) {
|
|
if(this.is_widget(col, row)) {
|
|
$widgets = $widgets.add(this.gridmap[col][row]);
|
|
}
|
|
}, this));
|
|
}, this));
|
|
|
|
return $widgets;
|
|
};
|
|
|
|
|
|
/**
|
|
* Put placeholder at the row and column specified.
|
|
*
|
|
* @method set_placeholder
|
|
* @param {Number} col The column to which we want to move the
|
|
* placeholder.
|
|
* @param {Number} row The row to which we want to move the
|
|
* placeholder.
|
|
* @return {Class} Returns the instance of the Gridster Class.
|
|
*/
|
|
fn.set_placeholder = function(col, row) {
|
|
var phgd = $.extend({}, this.placeholder_grid_data);
|
|
var $nexts = this.widgets_below({
|
|
col: phgd.col,
|
|
row: phgd.row,
|
|
size_y: phgd.size_y,
|
|
size_x: phgd.size_x
|
|
});
|
|
|
|
//Prevents widgets go out of the grid
|
|
var right_col = (col + phgd.size_x - 1);
|
|
if (right_col > this.cols) {
|
|
col = col - (right_col - col);
|
|
}
|
|
|
|
var moved_down = this.placeholder_grid_data.row < row;
|
|
var changed_column = this.placeholder_grid_data.col !== col;
|
|
|
|
this.placeholder_grid_data.col = col;
|
|
this.placeholder_grid_data.row = row;
|
|
|
|
this.cells_occupied_by_placeholder = this.get_cells_occupied(
|
|
this.placeholder_grid_data);
|
|
|
|
this.$preview_holder.attr({
|
|
'data-row' : row,
|
|
'data-col' : col
|
|
});
|
|
|
|
if (moved_down || changed_column) {
|
|
$nexts.each($.proxy(function(i, widget) {
|
|
this.move_widget_up(
|
|
$(widget), this.placeholder_grid_data.col - col + phgd.size_y);
|
|
}, this));
|
|
}
|
|
|
|
};
|
|
|
|
|
|
/**
|
|
* Determines whether the player can move to a position above.
|
|
*
|
|
* @method can_go_player_up
|
|
* @param {Object} widget_grid_data The actual grid coords object of the
|
|
* player.
|
|
* @return {Number|Boolean} If the player can be moved to an upper row
|
|
* returns the row number, else returns false.
|
|
*/
|
|
fn.can_go_player_up = function(widget_grid_data) {
|
|
var p_bottom_row = widget_grid_data.row + widget_grid_data.size_y - 1;
|
|
var result = true;
|
|
var upper_rows = [];
|
|
var min_row = 10000;
|
|
var $widgets_under_player = this.get_widgets_under_player();
|
|
|
|
/* generate an array with columns as index and array with upper rows
|
|
* empty as value */
|
|
this.for_each_column_occupied(widget_grid_data, function(tcol) {
|
|
var grid_col = this.gridmap[tcol];
|
|
var r = p_bottom_row + 1;
|
|
upper_rows[tcol] = [];
|
|
|
|
while (--r > 0) {
|
|
if (this.is_empty(tcol, r) || this.is_player(tcol, r) ||
|
|
this.is_widget(tcol, r) &&
|
|
grid_col[r].is($widgets_under_player)
|
|
) {
|
|
upper_rows[tcol].push(r);
|
|
min_row = r < min_row ? r : min_row;
|
|
}else{
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (upper_rows[tcol].length === 0) {
|
|
result = false;
|
|
return true; //break
|
|
}
|
|
|
|
upper_rows[tcol].sort();
|
|
});
|
|
|
|
if (!result) { return false; }
|
|
|
|
return this.get_valid_rows(widget_grid_data, upper_rows, min_row);
|
|
};
|
|
|
|
|
|
/**
|
|
* Determines whether a widget can move to a position above.
|
|
*
|
|
* @method can_go_widget_up
|
|
* @param {Object} widget_grid_data The actual grid coords object of the
|
|
* widget we want to check.
|
|
* @return {Number|Boolean} If the widget can be moved to an upper row
|
|
* returns the row number, else returns false.
|
|
*/
|
|
fn.can_go_widget_up = function(widget_grid_data) {
|
|
var p_bottom_row = widget_grid_data.row + widget_grid_data.size_y - 1;
|
|
var result = true;
|
|
var upper_rows = [];
|
|
var min_row = 10000;
|
|
|
|
if (widget_grid_data.col < this.player_grid_data.col &&
|
|
(widget_grid_data.col + widget_grid_data.size_y - 1) >
|
|
(this.player_grid_data.col + this.player_grid_data.size_y - 1)
|
|
) {
|
|
return false;
|
|
};
|
|
|
|
/* generate an array with columns as index and array with upper rows
|
|
* empty as value */
|
|
this.for_each_column_occupied(widget_grid_data, function(tcol) {
|
|
var grid_col = this.gridmap[tcol];
|
|
upper_rows[tcol] = [];
|
|
|
|
var r = p_bottom_row + 1;
|
|
|
|
while (--r > 0) {
|
|
if (this.is_widget(tcol, r) && !this.is_player_in(tcol, r)) {
|
|
if (!grid_col[r].is(widget_grid_data.el)) {
|
|
break;
|
|
};
|
|
}
|
|
|
|
if (!this.is_player(tcol, r) &&
|
|
!this.is_placeholder_in(tcol, r) &&
|
|
!this.is_player_in(tcol, r)) {
|
|
upper_rows[tcol].push(r);
|
|
};
|
|
|
|
if (r < min_row) {
|
|
min_row = r;
|
|
}
|
|
}
|
|
|
|
if (upper_rows[tcol].length === 0) {
|
|
result = false;
|
|
return true; //break
|
|
}
|
|
|
|
upper_rows[tcol].sort();
|
|
});
|
|
|
|
if (!result) { return false; }
|
|
|
|
return this.get_valid_rows(widget_grid_data, upper_rows, min_row);
|
|
};
|
|
|
|
|
|
/**
|
|
* Search a valid row for the widget represented by `widget_grid_data' in
|
|
* the `upper_rows` array. Iteration starts from row specified in `min_row`.
|
|
*
|
|
* @method get_valid_rows
|
|
* @param {Object} widget_grid_data The actual grid coords object of the
|
|
* player.
|
|
* @param {Array} upper_rows An array with columns as index and arrays
|
|
* of valid rows as values.
|
|
* @param {Number} min_row The upper row from which the iteration will start.
|
|
* @return {Number|Boolean} Returns the upper row valid from the `upper_rows`
|
|
* for the widget in question.
|
|
*/
|
|
fn.get_valid_rows = function(widget_grid_data, upper_rows, min_row) {
|
|
var p_top_row = widget_grid_data.row;
|
|
var p_bottom_row = widget_grid_data.row + widget_grid_data.size_y - 1;
|
|
var size_y = widget_grid_data.size_y;
|
|
var r = min_row - 1;
|
|
var valid_rows = [];
|
|
|
|
while (++r <= p_bottom_row ) {
|
|
var common = true;
|
|
$.each(upper_rows, function(col, rows) {
|
|
if ($.isArray(rows) && $.inArray(r, rows) === -1) {
|
|
common = false;
|
|
}
|
|
});
|
|
|
|
if (common === true) {
|
|
valid_rows.push(r);
|
|
if (valid_rows.length === size_y) {
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
var new_row = false;
|
|
if (size_y === 1) {
|
|
if (valid_rows[0] !== p_top_row) {
|
|
new_row = valid_rows[0] || false;
|
|
}
|
|
}else{
|
|
if (valid_rows[0] !== p_top_row) {
|
|
new_row = this.get_consecutive_numbers_index(
|
|
valid_rows, size_y);
|
|
}
|
|
}
|
|
|
|
return new_row;
|
|
};
|
|
|
|
|
|
fn.get_consecutive_numbers_index = function(arr, size_y) {
|
|
var max = arr.length;
|
|
var result = [];
|
|
var first = true;
|
|
var prev = -1; // or null?
|
|
|
|
for (var i=0; i < max; i++) {
|
|
if (first || arr[i] === prev + 1) {
|
|
result.push(i);
|
|
if (result.length === size_y) {
|
|
break;
|
|
}
|
|
first = false;
|
|
}else{
|
|
result = [];
|
|
first = true;
|
|
}
|
|
|
|
prev = arr[i];
|
|
}
|
|
|
|
return result.length >= size_y ? arr[result[0]] : false;
|
|
};
|
|
|
|
|
|
/**
|
|
* Get widgets overlapping with the player.
|
|
*
|
|
* @method get_widgets_overlapped
|
|
* @return {HTMLElements} Returns a jQuery collection of HTMLElements.
|
|
*/
|
|
fn.get_widgets_overlapped = function() {
|
|
var $w;
|
|
var $widgets = $([]);
|
|
var used = [];
|
|
var rows_from_bottom = this.cells_occupied_by_player.rows.slice(0);
|
|
rows_from_bottom.reverse();
|
|
|
|
$.each(this.cells_occupied_by_player.cols, $.proxy(function(i, col) {
|
|
$.each(rows_from_bottom, $.proxy(function(i, row) {
|
|
// if there is a widget in the player position
|
|
if (!this.gridmap[col]) { return true; } //next iteration
|
|
var $w = this.gridmap[col][row];
|
|
|
|
if (this.is_occupied(col, row) && !this.is_player($w) &&
|
|
$.inArray($w, used) === -1
|
|
) {
|
|
$widgets = $widgets.add($w);
|
|
used.push($w);
|
|
}
|
|
|
|
}, this));
|
|
}, this));
|
|
|
|
return $widgets;
|
|
};
|
|
|
|
|
|
/**
|
|
* This callback is executed when the player begins to collide with a column.
|
|
*
|
|
* @method on_start_overlapping_column
|
|
* @param {Number} col The collided column.
|
|
* @return {HTMLElements} Returns a jQuery collection of HTMLElements.
|
|
*/
|
|
fn.on_start_overlapping_column = function(col) {
|
|
this.set_player(col, false);
|
|
};
|
|
|
|
|
|
/**
|
|
* A callback executed when the player begins to collide with a row.
|
|
*
|
|
* @method on_start_overlapping_row
|
|
* @param {Number} col The collided row.
|
|
* @return {HTMLElements} Returns a jQuery collection of HTMLElements.
|
|
*/
|
|
fn.on_start_overlapping_row = function(row) {
|
|
this.set_player(false, row);
|
|
};
|
|
|
|
|
|
/**
|
|
* A callback executed when the the player ends to collide with a column.
|
|
*
|
|
* @method on_stop_overlapping_column
|
|
* @param {Number} col The collided row.
|
|
* @return {HTMLElements} Returns a jQuery collection of HTMLElements.
|
|
*/
|
|
fn.on_stop_overlapping_column = function(col) {
|
|
this.set_player(col, false);
|
|
|
|
var self = this;
|
|
this.for_each_widget_below(col, this.cells_occupied_by_player.rows[0],
|
|
function(tcol, trow) {
|
|
self.move_widget_up(this, self.player_grid_data.size_y);
|
|
});
|
|
};
|
|
|
|
|
|
/**
|
|
* This callback is executed when the player ends to collide with a row.
|
|
*
|
|
* @method on_stop_overlapping_row
|
|
* @param {Number} row The collided row.
|
|
* @return {HTMLElements} Returns a jQuery collection of HTMLElements.
|
|
*/
|
|
fn.on_stop_overlapping_row = function(row) {
|
|
this.set_player(false, row);
|
|
|
|
var self = this;
|
|
var cols = this.cells_occupied_by_player.cols;
|
|
for (var c = 0, cl = cols.length; c < cl; c++) {
|
|
this.for_each_widget_below(cols[c], row, function(tcol, trow) {
|
|
self.move_widget_up(this, self.player_grid_data.size_y);
|
|
});
|
|
}
|
|
};
|
|
|
|
|
|
/**
|
|
* Move a widget to a specific row. The cell or cells must be empty.
|
|
* If the widget has widgets below, all of these widgets will be moved also
|
|
* if they can.
|
|
*
|
|
* @method move_widget_to
|
|
* @param {HTMLElement} $widget The jQuery wrapped HTMLElement of the
|
|
* widget is going to be moved.
|
|
* @return {Class} Returns the instance of the Gridster Class.
|
|
*/
|
|
fn.move_widget_to = function($widget, row) {
|
|
var self = this;
|
|
var widget_grid_data = $widget.coords().grid;
|
|
var diff = row - widget_grid_data.row;
|
|
var $next_widgets = this.widgets_below($widget);
|
|
|
|
var can_move_to_new_cell = this.can_move_to(
|
|
widget_grid_data, widget_grid_data.col, row, $widget);
|
|
|
|
if (can_move_to_new_cell === false) {
|
|
return false;
|
|
}
|
|
|
|
this.remove_from_gridmap(widget_grid_data);
|
|
widget_grid_data.row = row;
|
|
this.add_to_gridmap(widget_grid_data);
|
|
$widget.attr('data-row', row);
|
|
this.$changed = this.$changed.add($widget);
|
|
|
|
|
|
$next_widgets.each(function(i, widget) {
|
|
var $w = $(widget);
|
|
var wgd = $w.coords().grid;
|
|
var can_go_up = self.can_go_widget_up(wgd);
|
|
if (can_go_up && can_go_up !== wgd.row) {
|
|
self.move_widget_to($w, can_go_up);
|
|
}
|
|
});
|
|
|
|
return this;
|
|
};
|
|
|
|
|
|
/**
|
|
* Move up the specified widget and all below it.
|
|
*
|
|
* @method move_widget_up
|
|
* @param {HTMLElement} $widget The widget you want to move.
|
|
* @param {Number} [y_units] The number of cells that the widget has to move.
|
|
* @return {Class} Returns the instance of the Gridster Class.
|
|
*/
|
|
fn.move_widget_up = function($widget, y_units) {
|
|
var el_grid_data = $widget.coords().grid;
|
|
var actual_row = el_grid_data.row;
|
|
var moved = [];
|
|
var can_go_up = true;
|
|
y_units || (y_units = 1);
|
|
|
|
if (!this.can_go_up($widget)) { return false; } //break;
|
|
|
|
this.for_each_column_occupied(el_grid_data, function(col) {
|
|
// can_go_up
|
|
if ($.inArray($widget, moved) === -1) {
|
|
var widget_grid_data = $widget.coords().grid;
|
|
var next_row = actual_row - y_units;
|
|
next_row = this.can_go_up_to_row(
|
|
widget_grid_data, col, next_row);
|
|
|
|
if (!next_row) {
|
|
return true;
|
|
}
|
|
|
|
var $next_widgets = this.widgets_below($widget);
|
|
|
|
this.remove_from_gridmap(widget_grid_data);
|
|
widget_grid_data.row = next_row;
|
|
this.add_to_gridmap(widget_grid_data);
|
|
$widget.attr('data-row', widget_grid_data.row);
|
|
this.$changed = this.$changed.add($widget);
|
|
|
|
moved.push($widget);
|
|
|
|
$next_widgets.each($.proxy(function(i, widget) {
|
|
this.move_widget_up($(widget), y_units);
|
|
}, this));
|
|
}
|
|
});
|
|
|
|
};
|
|
|
|
|
|
/**
|
|
* Move down the specified widget and all below it.
|
|
*
|
|
* @method move_widget_down
|
|
* @param {HTMLElement} $widget The jQuery object representing the widget
|
|
* you want to move.
|
|
* @param {Number} The number of cells that the widget has to move.
|
|
* @return {Class} Returns the instance of the Gridster Class.
|
|
*/
|
|
fn.move_widget_down = function($widget, y_units) {
|
|
var el_grid_data = $widget.coords().grid;
|
|
var actual_row = el_grid_data.row;
|
|
var moved = [];
|
|
var y_diff = y_units;
|
|
|
|
if (!$widget) { return false; }
|
|
|
|
if ($.inArray($widget, moved) === -1) {
|
|
|
|
var widget_grid_data = $widget.coords().grid;
|
|
var next_row = actual_row + y_units;
|
|
var $next_widgets = this.widgets_below($widget);
|
|
|
|
this.remove_from_gridmap(widget_grid_data);
|
|
|
|
$next_widgets.each($.proxy(function(i, widget) {
|
|
var $w = $(widget);
|
|
var wd = $w.coords().grid;
|
|
var tmp_y = this.displacement_diff(
|
|
wd, widget_grid_data, y_diff);
|
|
|
|
if (tmp_y > 0) {
|
|
this.move_widget_down($w, tmp_y);
|
|
}
|
|
}, this));
|
|
|
|
widget_grid_data.row = next_row;
|
|
this.update_widget_position(widget_grid_data, $widget);
|
|
$widget.attr('data-row', widget_grid_data.row);
|
|
this.$changed = this.$changed.add($widget);
|
|
|
|
moved.push($widget);
|
|
}
|
|
};
|
|
|
|
|
|
/**
|
|
* Check if the widget can move to the specified row, else returns the
|
|
* upper row possible.
|
|
*
|
|
* @method can_go_up_to_row
|
|
* @param {Number} widget_grid_data The current grid coords object of the
|
|
* widget.
|
|
* @param {Number} col The target column.
|
|
* @param {Number} row The target row.
|
|
* @return {Boolean|Number} Returns the row number if the widget can move
|
|
* to the target position, else returns false.
|
|
*/
|
|
fn.can_go_up_to_row = function(widget_grid_data, col, row) {
|
|
var ga = this.gridmap;
|
|
var result = true;
|
|
var urc = []; // upper_rows_in_columns
|
|
var actual_row = widget_grid_data.row;
|
|
var r;
|
|
|
|
/* generate an array with columns as index and array with
|
|
* upper rows empty in the column */
|
|
this.for_each_column_occupied(widget_grid_data, function(tcol) {
|
|
var grid_col = ga[tcol];
|
|
urc[tcol] = [];
|
|
|
|
r = actual_row;
|
|
while (r--) {
|
|
if (this.is_empty(tcol, r) &&
|
|
!this.is_placeholder_in(tcol, r)
|
|
) {
|
|
urc[tcol].push(r);
|
|
}else{
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (!urc[tcol].length) {
|
|
result = false;
|
|
return true;
|
|
}
|
|
|
|
});
|
|
|
|
if (!result) { return false; }
|
|
|
|
/* get common rows starting from upper position in all the columns
|
|
* that widget occupies */
|
|
r = row;
|
|
for (r = 1; r < actual_row; r++) {
|
|
var common = true;
|
|
|
|
for (var uc = 0, ucl = urc.length; uc < ucl; uc++) {
|
|
if (urc[uc] && $.inArray(r, urc[uc]) === -1) {
|
|
common = false;
|
|
}
|
|
}
|
|
|
|
if (common === true) {
|
|
result = r;
|
|
break;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
};
|
|
|
|
|
|
fn.displacement_diff = function(widget_grid_data, parent_bgd, y_units) {
|
|
var actual_row = widget_grid_data.row;
|
|
var diffs = [];
|
|
var parent_max_y = parent_bgd.row + parent_bgd.size_y;
|
|
|
|
this.for_each_column_occupied(widget_grid_data, function(col) {
|
|
var temp_y_units = 0;
|
|
|
|
for (var r = parent_max_y; r < actual_row; r++) {
|
|
if (this.is_empty(col, r)) {
|
|
temp_y_units = temp_y_units + 1;
|
|
}
|
|
}
|
|
|
|
diffs.push(temp_y_units);
|
|
});
|
|
|
|
var max_diff = Math.max.apply(Math, diffs);
|
|
y_units = (y_units - max_diff);
|
|
|
|
return y_units > 0 ? y_units : 0;
|
|
};
|
|
|
|
|
|
/**
|
|
* Get widgets below a widget.
|
|
*
|
|
* @method widgets_below
|
|
* @param {HTMLElement} $el The jQuery wrapped HTMLElement.
|
|
* @return {HTMLElements} A jQuery collection of HTMLElements.
|
|
*/
|
|
fn.widgets_below = function($el) {
|
|
var el_grid_data = $.isPlainObject($el) ? $el : $el.coords().grid;
|
|
var self = this;
|
|
var ga = this.gridmap;
|
|
var next_row = el_grid_data.row + el_grid_data.size_y - 1;
|
|
var $nexts = $([]);
|
|
|
|
this.for_each_column_occupied(el_grid_data, function(col) {
|
|
self.for_each_widget_below(col, next_row,
|
|
function(tcol, trow) {
|
|
if (!self.is_player(this) &&
|
|
$.inArray(this, $nexts) === -1) {
|
|
$nexts = $nexts.add(this);
|
|
return true; // break
|
|
}
|
|
});
|
|
});
|
|
|
|
return this.sort_by_row_asc($nexts);
|
|
};
|
|
|
|
|
|
/**
|
|
* Update the array of mapped positions with the new player position.
|
|
*
|
|
* @method set_cells_player_occupies
|
|
* @param {Number} col The new player col.
|
|
* @param {Number} col The new player row.
|
|
* @return {Class} Returns the instance of the Gridster Class.
|
|
*/
|
|
fn.set_cells_player_occupies = function(col, row) {
|
|
this.remove_from_gridmap(this.placeholder_grid_data);
|
|
this.placeholder_grid_data.col = col;
|
|
this.placeholder_grid_data.row = row;
|
|
this.add_to_gridmap(this.placeholder_grid_data, this.$player);
|
|
return this;
|
|
};
|
|
|
|
|
|
/**
|
|
* Remove from the array of mapped positions the reference to the player.
|
|
*
|
|
* @method empty_cells_player_occupies
|
|
* @return {Class} Returns the instance of the Gridster Class.
|
|
*/
|
|
fn.empty_cells_player_occupies = function() {
|
|
this.remove_from_gridmap(this.placeholder_grid_data);
|
|
return this;
|
|
};
|
|
|
|
|
|
fn.can_go_up = function($el) {
|
|
var el_grid_data = $el.coords().grid;
|
|
var initial_row = el_grid_data.row;
|
|
var prev_row = initial_row - 1;
|
|
var ga = this.gridmap;
|
|
var upper_rows_by_column = [];
|
|
|
|
var result = true;
|
|
if (initial_row === 1) { return false; }
|
|
|
|
this.for_each_column_occupied(el_grid_data, function(col) {
|
|
var $w = this.is_widget(col, prev_row);
|
|
if (this.is_occupied(col, prev_row) ||
|
|
this.is_player(col, prev_row) ||
|
|
this.is_placeholder_in(col, prev_row) ||
|
|
this.is_player_in(col, prev_row)
|
|
) {
|
|
result = false;
|
|
return true; //break
|
|
}
|
|
});
|
|
|
|
return result;
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
* Check if it's possible to move a widget to a specific col/row. It takes
|
|
* into account the dimensions (`size_y` and `size_x` attrs. of the grid
|
|
* coords object) the widget occupies.
|
|
*
|
|
* @method can_move_to
|
|
* @param {Object} widget_grid_data The grid coords object that represents
|
|
* the widget.
|
|
* @param {Object} col The col to check.
|
|
* @param {Object} row The row to check.
|
|
* @return {Boolean} Returns true if all cells are empty, else return false.
|
|
*/
|
|
fn.can_move_to = function(widget_grid_data, col, row) {
|
|
var ga = this.gridmap;
|
|
var $w = widget_grid_data.el;
|
|
var future_wd = {
|
|
size_y: widget_grid_data.size_y,
|
|
size_x: widget_grid_data.size_x,
|
|
col: col,
|
|
row: row
|
|
};
|
|
var result = true;
|
|
|
|
//Prevents widgets go out of the grid
|
|
var right_col = col + widget_grid_data.size_x - 1;
|
|
if (right_col > this.cols) {
|
|
return false;
|
|
};
|
|
|
|
this.for_each_cell_occupied(future_wd, function(tcol, trow) {
|
|
var $tw = this.is_widget(tcol, trow);
|
|
if ($tw && (!widget_grid_data.el || $tw.is($w))) {
|
|
result = false;
|
|
}
|
|
});
|
|
|
|
return result;
|
|
};
|
|
|
|
|
|
/**
|
|
* Given the leftmost column returns all columns that are overlapping
|
|
* with the player.
|
|
*
|
|
* @method get_targeted_columns
|
|
* @param {Number} [from_col] The leftmost column.
|
|
* @return {Array} Returns an array with column numbers.
|
|
*/
|
|
fn.get_targeted_columns = function(from_col) {
|
|
var max = (from_col || this.player_grid_data.col) +
|
|
(this.player_grid_data.size_x - 1);
|
|
var cols = [];
|
|
for (var col = from_col; col <= max; col++) {
|
|
cols.push(col);
|
|
}
|
|
return cols;
|
|
};
|
|
|
|
|
|
/**
|
|
* Given the upper row returns all rows that are overlapping with the player.
|
|
*
|
|
* @method get_targeted_rows
|
|
* @param {Number} [from_row] The upper row.
|
|
* @return {Array} Returns an array with row numbers.
|
|
*/
|
|
fn.get_targeted_rows = function(from_row) {
|
|
var max = (from_row || this.player_grid_data.row) +
|
|
(this.player_grid_data.size_y - 1);
|
|
var rows = [];
|
|
for (var row = from_row; row <= max; row++) {
|
|
rows.push(row);
|
|
}
|
|
return rows;
|
|
};
|
|
|
|
/**
|
|
* Get all columns and rows that a widget occupies.
|
|
*
|
|
* @method get_cells_occupied
|
|
* @param {Object} el_grid_data The grid coords object of the widget.
|
|
* @return {Object} Returns an object like `{ cols: [], rows: []}`.
|
|
*/
|
|
fn.get_cells_occupied = function(el_grid_data) {
|
|
var cells = { cols: [], rows: []};
|
|
var i;
|
|
if (arguments[1] instanceof jQuery) {
|
|
el_grid_data = arguments[1].coords().grid;
|
|
}
|
|
|
|
for (i = 0; i < el_grid_data.size_x; i++) {
|
|
var col = el_grid_data.col + i;
|
|
cells.cols.push(col);
|
|
}
|
|
|
|
for (i = 0; i < el_grid_data.size_y; i++) {
|
|
var row = el_grid_data.row + i;
|
|
cells.rows.push(row);
|
|
}
|
|
|
|
return cells;
|
|
};
|
|
|
|
|
|
/**
|
|
* Iterate over the cells occupied by a widget executing a function for
|
|
* each one.
|
|
*
|
|
* @method for_each_cell_occupied
|
|
* @param {Object} el_grid_data The grid coords object that represents the
|
|
* widget.
|
|
* @param {Function} callback The function to execute on each column
|
|
* iteration. Column and row are passed as arguments.
|
|
* @return {Class} Returns the instance of the Gridster Class.
|
|
*/
|
|
fn.for_each_cell_occupied = function(grid_data, callback) {
|
|
this.for_each_column_occupied(grid_data, function(col) {
|
|
this.for_each_row_occupied(grid_data, function(row) {
|
|
callback.call(this, col, row);
|
|
});
|
|
});
|
|
return this;
|
|
};
|
|
|
|
|
|
/**
|
|
* Iterate over the columns occupied by a widget executing a function for
|
|
* each one.
|
|
*
|
|
* @method for_each_column_occupied
|
|
* @param {Object} el_grid_data The grid coords object that represents
|
|
* the widget.
|
|
* @param {Function} callback The function to execute on each column
|
|
* iteration. The column number is passed as first argument.
|
|
* @return {Class} Returns the instance of the Gridster Class.
|
|
*/
|
|
fn.for_each_column_occupied = function(el_grid_data, callback) {
|
|
for (var i = 0; i < el_grid_data.size_x; i++) {
|
|
var col = el_grid_data.col + i;
|
|
callback.call(this, col, el_grid_data);
|
|
}
|
|
};
|
|
|
|
|
|
/**
|
|
* Iterate over the rows occupied by a widget executing a function for
|
|
* each one.
|
|
*
|
|
* @method for_each_row_occupied
|
|
* @param {Object} el_grid_data The grid coords object that represents
|
|
* the widget.
|
|
* @param {Function} callback The function to execute on each column
|
|
* iteration. The row number is passed as first argument.
|
|
* @return {Class} Returns the instance of the Gridster Class.
|
|
*/
|
|
fn.for_each_row_occupied = function(el_grid_data, callback) {
|
|
for (var i = 0; i < el_grid_data.size_y; i++) {
|
|
var row = el_grid_data.row + i;
|
|
callback.call(this, row, el_grid_data);
|
|
}
|
|
};
|
|
|
|
|
|
|
|
fn._traversing_widgets = function(type, direction, col, row, callback) {
|
|
var ga = this.gridmap;
|
|
if (!ga[col]) { return; }
|
|
|
|
var cr, max;
|
|
var action = type + '/' + direction;
|
|
if (arguments[2] instanceof jQuery) {
|
|
var el_grid_data = arguments[2].coords().grid;
|
|
col = el_grid_data.col;
|
|
row = el_grid_data.row;
|
|
callback = arguments[3];
|
|
}
|
|
var matched = [];
|
|
var trow = row;
|
|
|
|
|
|
var methods = {
|
|
'for_each/above': function() {
|
|
while (trow--) {
|
|
if (trow > 0 && this.is_widget(col, trow) &&
|
|
$.inArray(ga[col][trow], matched) === -1
|
|
) {
|
|
cr = callback.call(ga[col][trow], col, trow);
|
|
matched.push(ga[col][trow]);
|
|
if (cr) { break; }
|
|
}
|
|
}
|
|
},
|
|
'for_each/below': function() {
|
|
for (trow = row + 1, max = ga[col].length; trow < max; trow++) {
|
|
if (this.is_widget(col, trow) &&
|
|
$.inArray(ga[col][trow], matched) === -1
|
|
) {
|
|
cr = callback.call(ga[col][trow], col, trow);
|
|
matched.push(ga[col][trow]);
|
|
if (cr) { break; }
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
if (methods[action]) {
|
|
methods[action].call(this);
|
|
}
|
|
};
|
|
|
|
|
|
/**
|
|
* Iterate over each widget above the column and row specified.
|
|
*
|
|
* @method for_each_widget_above
|
|
* @param {Number} col The column to start iterating.
|
|
* @param {Number} row The row to start iterating.
|
|
* @param {Function} callback The function to execute on each widget
|
|
* iteration. The value of `this` inside the function is the jQuery
|
|
* wrapped HTMLElement.
|
|
* @return {Class} Returns the instance of the Gridster Class.
|
|
*/
|
|
fn.for_each_widget_above = function(col, row, callback) {
|
|
this._traversing_widgets('for_each', 'above', col, row, callback);
|
|
return this;
|
|
};
|
|
|
|
|
|
/**
|
|
* Iterate over each widget below the column and row specified.
|
|
*
|
|
* @method for_each_widget_below
|
|
* @param {Number} col The column to start iterating.
|
|
* @param {Number} row The row to start iterating.
|
|
* @param {Function} callback The function to execute on each widget
|
|
* iteration. The value of `this` inside the function is the jQuery wrapped
|
|
* HTMLElement.
|
|
* @return {Class} Returns the instance of the Gridster Class.
|
|
*/
|
|
fn.for_each_widget_below = function(col, row, callback) {
|
|
this._traversing_widgets('for_each', 'below', col, row, callback);
|
|
return this;
|
|
};
|
|
|
|
|
|
/**
|
|
* Returns the highest occupied cell in the grid.
|
|
*
|
|
* @method get_highest_occupied_cell
|
|
* @return {Object} Returns an object with `col` and `row` numbers.
|
|
*/
|
|
fn.get_highest_occupied_cell = function() {
|
|
var r;
|
|
var gm = this.gridmap;
|
|
var rows = [];
|
|
var row_in_col = [];
|
|
for (var c = gm.length - 1; c >= 1; c--) {
|
|
for (r = gm[c].length - 1; r >= 1; r--) {
|
|
if (this.is_widget(c, r)) {
|
|
rows.push(r);
|
|
row_in_col[r] = c;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
var highest_row = Math.max.apply(Math, rows);
|
|
|
|
this.highest_occupied_cell = {
|
|
col: row_in_col[highest_row],
|
|
row: highest_row
|
|
};
|
|
|
|
return this.highest_occupied_cell;
|
|
};
|
|
|
|
|
|
fn.get_widgets_from = function(col, row) {
|
|
var ga = this.gridmap;
|
|
var $widgets = $();
|
|
|
|
if (col) {
|
|
$widgets = $widgets.add(
|
|
this.$widgets.filter(function() {
|
|
var tcol = $(this).attr('data-col');
|
|
return (tcol === col || tcol > col);
|
|
})
|
|
);
|
|
}
|
|
|
|
if (row) {
|
|
$widgets = $widgets.add(
|
|
this.$widgets.filter(function() {
|
|
var trow = $(this).attr('data-row');
|
|
return (trow === row || trow > row);
|
|
})
|
|
);
|
|
}
|
|
|
|
return $widgets;
|
|
}
|
|
|
|
|
|
/**
|
|
* Set the current height of the parent grid.
|
|
*
|
|
* @method set_dom_grid_height
|
|
* @return {Object} Returns the instance of the Gridster class.
|
|
*/
|
|
fn.set_dom_grid_height = function() {
|
|
var r = this.get_highest_occupied_cell().row;
|
|
this.$el.css('height', r * this.min_widget_height);
|
|
return this;
|
|
};
|
|
|
|
|
|
/**
|
|
* It generates the neccessary styles to position the widgets.
|
|
*
|
|
* @method generate_stylesheet
|
|
* @param {Number} rows Number of columns.
|
|
* @param {Number} cols Number of rows.
|
|
* @return {Object} Returns the instance of the Gridster class.
|
|
*/
|
|
fn.generate_stylesheet = function(opts) {
|
|
var styles = '';
|
|
var extra_cells = 10;
|
|
var max_size_y = this.options.max_size_y;
|
|
var max_size_x = this.options.max_size_x;
|
|
var i;
|
|
var rules;
|
|
|
|
opts || (opts = {});
|
|
opts.cols || (opts.cols = this.cols);
|
|
opts.rows || (opts.rows = this.rows);
|
|
opts.namespace || (opts.namespace = '');
|
|
opts.widget_base_dimensions ||
|
|
(opts.widget_base_dimensions = this.options.widget_base_dimensions);
|
|
opts.widget_margins ||
|
|
(opts.widget_margins = this.options.widget_margins);
|
|
opts.min_widget_width = (opts.widget_margins[0] * 2) +
|
|
opts.widget_base_dimensions[0];
|
|
opts.min_widget_height = (opts.widget_margins[1] * 2) +
|
|
opts.widget_base_dimensions[1];
|
|
|
|
var serialized_opts = $.param(opts);
|
|
// don't duplicate stylesheets for the same configuration
|
|
if ($.inArray(serialized_opts, Gridster.generated_stylesheets) >= 0) {
|
|
return false;
|
|
}
|
|
|
|
Gridster.generated_stylesheets.push(serialized_opts);
|
|
|
|
/* generate CSS styles for cols */
|
|
for (i = opts.cols + extra_cells; i >= 0; i--) {
|
|
styles += (opts.namespace + ' [data-col="'+ (i + 1) + '"] { left:' +
|
|
((i * opts.widget_base_dimensions[0]) +
|
|
(i * opts.widget_margins[0]) +
|
|
((i + 1) * opts.widget_margins[0])) + 'px;} ');
|
|
}
|
|
|
|
/* generate CSS styles for rows */
|
|
for (i = opts.rows + extra_cells; i >= 0; i--) {
|
|
styles += (opts.namespace + ' [data-row="' + (i + 1) + '"] { top:' +
|
|
((i * opts.widget_base_dimensions[1]) +
|
|
(i * opts.widget_margins[1]) +
|
|
((i + 1) * opts.widget_margins[1]) ) + 'px;} ');
|
|
}
|
|
|
|
for (var y = 1; y <= max_size_y; y++) {
|
|
styles += (opts.namespace + ' [data-sizey="' + y + '"] { height:' +
|
|
(y * opts.widget_base_dimensions[1] +
|
|
(y - 1) * (opts.widget_margins[1] * 2)) + 'px;}');
|
|
}
|
|
|
|
for (var x = 1; x <= max_size_x; x++) {
|
|
styles += (opts.namespace + ' [data-sizex="' + x + '"] { width:' +
|
|
(x * opts.widget_base_dimensions[0] +
|
|
(x - 1) * (opts.widget_margins[0] * 2)) + 'px;}');
|
|
}
|
|
|
|
return this.add_style_tag(styles);
|
|
};
|
|
|
|
|
|
/**
|
|
* Injects the given CSS as string to the head of the document.
|
|
*
|
|
* @method add_style_tag
|
|
* @param {String} css The styles to apply.
|
|
* @return {Object} Returns the instance of the Gridster class.
|
|
*/
|
|
fn.add_style_tag = function(css) {
|
|
var d = document;
|
|
var tag = d.createElement('style');
|
|
|
|
d.getElementsByTagName('head')[0].appendChild(tag);
|
|
tag.setAttribute('type', 'text/css');
|
|
|
|
if (tag.styleSheet) {
|
|
tag.styleSheet.cssText = css;
|
|
}else{
|
|
tag.appendChild(document.createTextNode(css));
|
|
}
|
|
return this;
|
|
};
|
|
|
|
|
|
/**
|
|
* Generates a faux grid to collide with it when a widget is dragged and
|
|
* detect row or column that we want to go.
|
|
*
|
|
* @method generate_faux_grid
|
|
* @param {Number} rows Number of columns.
|
|
* @param {Number} cols Number of rows.
|
|
* @return {Object} Returns the instance of the Gridster class.
|
|
*/
|
|
fn.generate_faux_grid = function(rows, cols) {
|
|
this.faux_grid = [];
|
|
this.gridmap = [];
|
|
var col;
|
|
var row;
|
|
for (col = cols; col > 0; col--) {
|
|
this.gridmap[col] = [];
|
|
for (row = rows; row > 0; row--) {
|
|
var coords = $({
|
|
left: this.baseX + ((col - 1) * this.min_widget_width),
|
|
top: this.baseY + (row -1) * this.min_widget_height,
|
|
width: this.min_widget_width,
|
|
height: this.min_widget_height,
|
|
col: col,
|
|
row: row,
|
|
original_col: col,
|
|
original_row: row
|
|
}).coords();
|
|
|
|
this.gridmap[col][row] = false;
|
|
this.faux_grid.push(coords);
|
|
}
|
|
}
|
|
return this;
|
|
};
|
|
|
|
|
|
/**
|
|
* Recalculates the offsets for the faux grid. You need to use it when
|
|
* the browser is resized.
|
|
*
|
|
* @method recalculate_faux_grid
|
|
* @return {Object} Returns the instance of the Gridster class.
|
|
*/
|
|
fn.recalculate_faux_grid = function() {
|
|
var aw = this.$wrapper.width();
|
|
this.baseX = ($(window).width() - aw) / 2;
|
|
this.baseY = this.$wrapper.offset().top;
|
|
|
|
$.each(this.faux_grid, $.proxy(function(i, coords) {
|
|
this.faux_grid[i] = coords.update({
|
|
left: this.baseX + (coords.data.col -1) * this.min_widget_width,
|
|
top: this.baseY + (coords.data.row -1) * this.min_widget_height
|
|
});
|
|
|
|
}, this));
|
|
|
|
return this;
|
|
};
|
|
|
|
|
|
/**
|
|
* Get all widgets in the DOM and register them.
|
|
*
|
|
* @method get_widgets_from_DOM
|
|
* @return {Object} Returns the instance of the Gridster class.
|
|
*/
|
|
fn.get_widgets_from_DOM = function() {
|
|
this.$widgets.each($.proxy(function(i, widget) {
|
|
this.register_widget($(widget));
|
|
}, this));
|
|
return this;
|
|
};
|
|
|
|
|
|
/**
|
|
* Calculate columns and rows to be set based on the configuration
|
|
* parameters, grid dimensions, etc ...
|
|
*
|
|
* @method generate_grid_and_stylesheet
|
|
* @return {Object} Returns the instance of the Gridster class.
|
|
*/
|
|
fn.generate_grid_and_stylesheet = function() {
|
|
var aw = this.$wrapper.width();
|
|
var ah = this.$wrapper.height();
|
|
|
|
var cols = Math.floor(aw / this.min_widget_width) +
|
|
this.options.extra_cols;
|
|
var rows = Math.floor(ah / this.min_widget_height) +
|
|
this.options.extra_rows;
|
|
|
|
var actual_cols = this.$widgets.map(function() {
|
|
return $(this).attr('data-col');
|
|
});
|
|
actual_cols = Array.prototype.slice.call(actual_cols, 0);
|
|
//needed to pass tests with phantomjs
|
|
actual_cols.length || (actual_cols = [0]);
|
|
|
|
var actual_rows = this.$widgets.map(function() {
|
|
return $(this).attr('data-row');
|
|
});
|
|
actual_rows = Array.prototype.slice.call(actual_rows, 0);
|
|
//needed to pass tests with phantomjs
|
|
actual_rows.length || (actual_rows = [0]);
|
|
|
|
var min_cols = Math.max.apply(Math, actual_cols);
|
|
var min_rows = Math.max.apply(Math, actual_rows);
|
|
|
|
this.cols = Math.max(min_cols, cols, this.options.min_cols);
|
|
this.rows = Math.max(min_rows, rows, this.options.min_rows);
|
|
|
|
this.baseX = ($(window).width() - aw) / 2;
|
|
this.baseY = this.$wrapper.offset().top;
|
|
|
|
if (this.options.autogenerate_stylesheet) {
|
|
this.generate_stylesheet();
|
|
}
|
|
|
|
/* more faux rows that needed are created so that there are cells
|
|
* where drag beyond the limits */
|
|
return this.generate_faux_grid(this.rows, this.cols);
|
|
};
|
|
|
|
|
|
//jQuery adapter
|
|
$.fn.gridster = function(options) {
|
|
return this.each(function() {
|
|
if (!$(this).data('gridster')) {
|
|
$(this).data('gridster', new Gridster( this, options ));
|
|
}
|
|
});
|
|
};
|
|
|
|
|
|
}(jQuery, window, document));
|
|
// leanModal v1.1 by Ray Stone - http://finelysliced.com.au
|
|
// Dual licensed under the MIT and GPL
|
|
|
|
(function($){$.fn.extend({leanModal:function(options){var defaults={top:100,overlay:0.5,closeButton:null};var overlay=$("<div id='lean_overlay'></div>");$("body").append(overlay);options=$.extend(defaults,options);return this.each(function(){var o=options;$(this).click(function(e){var modal_id=$(this).attr("href");$("#lean_overlay").click(function(){close_modal(modal_id)});$(o.closeButton).click(function(){close_modal(modal_id)});var modal_height=$(modal_id).outerHeight();var modal_width=$(modal_id).outerWidth();
|
|
$("#lean_overlay").css({"display":"block",opacity:0});$("#lean_overlay").fadeTo(200,o.overlay);$(modal_id).css({"display":"block","position":"fixed","opacity":0,"z-index":11000,"left":50+"%","margin-left":-(modal_width/2)+"px","top":o.top+"px"});$(modal_id).fadeTo(200,1);e.preventDefault()})});function close_modal(modal_id){$("#lean_overlay").fadeOut(200);$(modal_id).css({"display":"none"})}}})})(jQuery);
|
|
(function() {
|
|
|
|
Dashing.gridsterLayout = function(positions) {
|
|
var index, widget, widgets, _i, _len, _results;
|
|
Dashing.customGridsterLayout = true;
|
|
positions = positions.replace(/^"|"$/g, '');
|
|
positions = $.parseJSON(positions);
|
|
widgets = $("[data-row^=]");
|
|
_results = [];
|
|
for (index = _i = 0, _len = widgets.length; _i < _len; index = ++_i) {
|
|
widget = widgets[index];
|
|
$(widget).attr('data-row', positions[index].row);
|
|
_results.push($(widget).attr('data-col', positions[index].col));
|
|
}
|
|
return _results;
|
|
};
|
|
|
|
Dashing.showGridsterInstructions = function() {
|
|
var data;
|
|
data = $(".gridster ul:first").gridster().data('gridster').serialize();
|
|
$('#save-gridster').slideDown();
|
|
return $('#gridster-code').text(" <script type='text/javascript'>\n $(function() {\n \ \ Dashing.gridsterLayout('" + (JSON.stringify(data)) + "')\n });\n </script> ");
|
|
};
|
|
|
|
$(function() {
|
|
$('#save-gridster').leanModal();
|
|
return $('#save-gridster').click(function() {
|
|
return $('#save-gridster').slideUp();
|
|
});
|
|
});
|
|
|
|
}).call(this);
|
|
/*!jQuery Knob*/
|
|
/**
|
|
* Downward compatible, touchable dial
|
|
*
|
|
* Version: 1.2.0 (15/07/2012)
|
|
* Requires: jQuery v1.7+
|
|
*
|
|
* Copyright (c) 2012 Anthony Terrien
|
|
* Under MIT and GPL licenses:
|
|
* http://www.opensource.org/licenses/mit-license.php
|
|
* http://www.gnu.org/licenses/gpl.html
|
|
*
|
|
* Thanks to vor, eskimoblood, spiffistan, FabrizioC
|
|
*/
|
|
|
|
$(function () {
|
|
|
|
/**
|
|
* Kontrol library
|
|
*/
|
|
"use strict";
|
|
|
|
/**
|
|
* Definition of globals and core
|
|
*/
|
|
var k = {}, // kontrol
|
|
max = Math.max,
|
|
min = Math.min;
|
|
|
|
k.c = {};
|
|
k.c.d = $(document);
|
|
k.c.t = function (e) {
|
|
return e.originalEvent.touches.length - 1;
|
|
};
|
|
|
|
/**
|
|
* Kontrol Object
|
|
*
|
|
* Definition of an abstract UI control
|
|
*
|
|
* Each concrete component must call this one.
|
|
* <code>
|
|
* k.o.call(this);
|
|
* </code>
|
|
*/
|
|
k.o = function () {
|
|
var s = this;
|
|
|
|
this.o = null; // array of options
|
|
this.$ = null; // jQuery wrapped element
|
|
this.i = null; // mixed HTMLInputElement or array of HTMLInputElement
|
|
this.g = null; // 2D graphics context for 'pre-rendering'
|
|
this.v = null; // value ; mixed array or integer
|
|
this.cv = null; // change value ; not commited value
|
|
this.x = 0; // canvas x position
|
|
this.y = 0; // canvas y position
|
|
this.$c = null; // jQuery canvas element
|
|
this.c = null; // rendered canvas context
|
|
this.t = 0; // touches index
|
|
this.isInit = false;
|
|
this.fgColor = null; // main color
|
|
this.pColor = null; // previous color
|
|
this.dH = null; // draw hook
|
|
this.cH = null; // change hook
|
|
this.eH = null; // cancel hook
|
|
this.rH = null; // release hook
|
|
|
|
this.run = function () {
|
|
var cf = function (e, conf) {
|
|
var k;
|
|
for (k in conf) {
|
|
s.o[k] = conf[k];
|
|
}
|
|
s.init();
|
|
s._configure()
|
|
._draw();
|
|
};
|
|
|
|
if(this.$.data('kontroled')) return;
|
|
this.$.data('kontroled', true);
|
|
|
|
this.extend();
|
|
this.o = $.extend(
|
|
{
|
|
// Config
|
|
min : this.$.data('min') || 0,
|
|
max : this.$.data('max') || 100,
|
|
stopper : true,
|
|
readOnly : this.$.data('readonly'),
|
|
|
|
// UI
|
|
cursor : (this.$.data('cursor') === true && 30)
|
|
|| this.$.data('cursor')
|
|
|| 0,
|
|
thickness : this.$.data('thickness') || 0.35,
|
|
width : this.$.data('width') || 200,
|
|
height : this.$.data('height') || 200,
|
|
displayInput : this.$.data('displayinput') == null || this.$.data('displayinput'),
|
|
displayPrevious : this.$.data('displayprevious'),
|
|
fgColor : this.$.data('fgcolor') || '#87CEEB',
|
|
inline : false,
|
|
|
|
// Hooks
|
|
draw : null, // function () {}
|
|
change : null, // function (value) {}
|
|
cancel : null, // function () {}
|
|
release : null // function (value) {}
|
|
}, this.o
|
|
);
|
|
|
|
// routing value
|
|
if(this.$.is('fieldset')) {
|
|
|
|
// fieldset = array of integer
|
|
this.v = {};
|
|
this.i = this.$.find('input')
|
|
this.i.each(function(k) {
|
|
var $this = $(this);
|
|
s.i[k] = $this;
|
|
s.v[k] = $this.val();
|
|
|
|
$this.bind(
|
|
'change'
|
|
, function () {
|
|
var val = {};
|
|
val[k] = $this.val();
|
|
s.val(val);
|
|
}
|
|
);
|
|
});
|
|
this.$.find('legend').remove();
|
|
|
|
} else {
|
|
// input = integer
|
|
this.i = this.$;
|
|
this.v = this.$.val();
|
|
(this.v == '') && (this.v = this.o.min);
|
|
|
|
this.$.bind(
|
|
'change'
|
|
, function () {
|
|
s.val(s.$.val());
|
|
}
|
|
);
|
|
}
|
|
|
|
(!this.o.displayInput) && this.$.hide();
|
|
|
|
this.$c = $('<canvas width="' +
|
|
this.o.width + 'px" height="' +
|
|
this.o.height + 'px"></canvas>');
|
|
this.c = this.$c[0].getContext("2d");
|
|
|
|
this.$
|
|
.wrap($('<div style="' + (this.o.inline ? 'display:inline;' : '') +
|
|
'width:' + this.o.width + 'px;height:' +
|
|
this.o.height + 'px;"></div>'))
|
|
.before(this.$c);
|
|
|
|
if (this.v instanceof Object) {
|
|
this.cv = {};
|
|
this.copy(this.v, this.cv);
|
|
} else {
|
|
this.cv = this.v;
|
|
}
|
|
|
|
this.$
|
|
.bind("configure", cf)
|
|
.parent()
|
|
.bind("configure", cf);
|
|
|
|
this._listen()
|
|
._configure()
|
|
._xy()
|
|
.init();
|
|
|
|
this.isInit = true;
|
|
|
|
this._draw();
|
|
|
|
return this;
|
|
};
|
|
|
|
this._draw = function () {
|
|
|
|
// canvas pre-rendering
|
|
var d = true,
|
|
c = document.createElement('canvas');
|
|
|
|
c.width = s.o.width;
|
|
c.height = s.o.height;
|
|
s.g = c.getContext('2d');
|
|
|
|
s.clear();
|
|
|
|
s.dH
|
|
&& (d = s.dH());
|
|
|
|
(d !== false) && s.draw();
|
|
|
|
s.c.drawImage(c, 0, 0);
|
|
c = null;
|
|
};
|
|
|
|
this._touch = function (e) {
|
|
|
|
var touchMove = function (e) {
|
|
|
|
var v = s.xy2val(
|
|
e.originalEvent.touches[s.t].pageX,
|
|
e.originalEvent.touches[s.t].pageY
|
|
);
|
|
|
|
if (v == s.cv) return;
|
|
|
|
if (
|
|
s.cH
|
|
&& (s.cH(v) === false)
|
|
) return;
|
|
|
|
|
|
s.change(v);
|
|
s._draw();
|
|
};
|
|
|
|
// get touches index
|
|
this.t = k.c.t(e);
|
|
|
|
// First touch
|
|
touchMove(e);
|
|
|
|
// Touch events listeners
|
|
k.c.d
|
|
.bind("touchmove.k", touchMove)
|
|
.bind(
|
|
"touchend.k"
|
|
, function () {
|
|
k.c.d.unbind('touchmove.k touchend.k');
|
|
|
|
if (
|
|
s.rH
|
|
&& (s.rH(s.cv) === false)
|
|
) return;
|
|
|
|
s.val(s.cv);
|
|
}
|
|
);
|
|
|
|
return this;
|
|
};
|
|
|
|
this._mouse = function (e) {
|
|
|
|
var mouseMove = function (e) {
|
|
var v = s.xy2val(e.pageX, e.pageY);
|
|
if (v == s.cv) return;
|
|
|
|
if (
|
|
s.cH
|
|
&& (s.cH(v) === false)
|
|
) return;
|
|
|
|
s.change(v);
|
|
s._draw();
|
|
};
|
|
|
|
// First click
|
|
mouseMove(e);
|
|
|
|
// Mouse events listeners
|
|
k.c.d
|
|
.bind("mousemove.k", mouseMove)
|
|
.bind(
|
|
// Escape key cancel current change
|
|
"keyup.k"
|
|
, function (e) {
|
|
if (e.keyCode === 27) {
|
|
k.c.d.unbind("mouseup.k mousemove.k keyup.k");
|
|
|
|
if (
|
|
s.eH
|
|
&& (s.eH() === false)
|
|
) return;
|
|
|
|
s.cancel();
|
|
}
|
|
}
|
|
)
|
|
.bind(
|
|
"mouseup.k"
|
|
, function (e) {
|
|
k.c.d.unbind('mousemove.k mouseup.k keyup.k');
|
|
|
|
if (
|
|
s.rH
|
|
&& (s.rH(s.cv) === false)
|
|
) return;
|
|
|
|
s.val(s.cv);
|
|
}
|
|
);
|
|
|
|
return this;
|
|
};
|
|
|
|
this._xy = function () {
|
|
var o = this.$c.offset();
|
|
this.x = o.left;
|
|
this.y = o.top;
|
|
return this;
|
|
};
|
|
|
|
this._listen = function () {
|
|
|
|
if (!this.o.readOnly) {
|
|
this.$c
|
|
.bind(
|
|
"mousedown"
|
|
, function (e) {
|
|
e.preventDefault();
|
|
s._xy()._mouse(e);
|
|
}
|
|
)
|
|
.bind(
|
|
"touchstart"
|
|
, function (e) {
|
|
e.preventDefault();
|
|
s._xy()._touch(e);
|
|
}
|
|
);
|
|
this.listen();
|
|
} else {
|
|
this.$.attr('readonly', 'readonly');
|
|
}
|
|
|
|
return this;
|
|
};
|
|
|
|
this._configure = function () {
|
|
|
|
// Hooks
|
|
if (this.o.draw) this.dH = this.o.draw;
|
|
if (this.o.change) this.cH = this.o.change;
|
|
if (this.o.cancel) this.eH = this.o.cancel;
|
|
if (this.o.release) this.rH = this.o.release;
|
|
|
|
if (this.o.displayPrevious) {
|
|
this.pColor = this.h2rgba(this.o.fgColor, "0.4");
|
|
this.fgColor = this.h2rgba(this.o.fgColor, "0.6");
|
|
} else {
|
|
this.fgColor = this.o.fgColor;
|
|
}
|
|
|
|
return this;
|
|
};
|
|
|
|
this._clear = function () {
|
|
this.$c[0].width = this.$c[0].width;
|
|
};
|
|
|
|
// Abstract methods
|
|
this.listen = function () {}; // on start, one time
|
|
this.extend = function () {}; // each time configure triggered
|
|
this.init = function () {}; // each time configure triggered
|
|
this.change = function (v) {}; // on change
|
|
this.val = function (v) {}; // on release
|
|
this.xy2val = function (x, y) {}; //
|
|
this.draw = function () {}; // on change / on release
|
|
this.clear = function () { this._clear(); };
|
|
|
|
// Utils
|
|
this.h2rgba = function (h, a) {
|
|
var rgb;
|
|
h = h.substring(1,7)
|
|
rgb = [parseInt(h.substring(0,2),16)
|
|
,parseInt(h.substring(2,4),16)
|
|
,parseInt(h.substring(4,6),16)];
|
|
return "rgba(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + "," + a + ")";
|
|
};
|
|
|
|
this.copy = function (f, t) {
|
|
for (var i in f) { t[i] = f[i]; }
|
|
};
|
|
};
|
|
|
|
|
|
/**
|
|
* k.Dial
|
|
*/
|
|
k.Dial = function () {
|
|
k.o.call(this);
|
|
|
|
this.startAngle = null;
|
|
this.xy = null;
|
|
this.radius = null;
|
|
this.lineWidth = null;
|
|
this.cursorExt = null;
|
|
this.w2 = null;
|
|
this.PI2 = 2*Math.PI;
|
|
|
|
this.extend = function () {
|
|
this.o = $.extend(
|
|
{
|
|
bgColor : this.$.data('bgcolor') || '#EEEEEE',
|
|
angleOffset : this.$.data('angleoffset') || 0,
|
|
angleArc : this.$.data('anglearc') || 360,
|
|
inline : true
|
|
}, this.o
|
|
);
|
|
};
|
|
|
|
this.val = function (v) {
|
|
if (null != v) {
|
|
this.cv = this.o.stopper ? max(min(v, this.o.max), this.o.min) : v;
|
|
this.v = this.cv;
|
|
this.$.val(this.v);
|
|
this._draw();
|
|
} else {
|
|
return this.v;
|
|
}
|
|
};
|
|
|
|
this.xy2val = function (x, y) {
|
|
var a, ret;
|
|
|
|
a = Math.atan2(
|
|
x - (this.x + this.w2)
|
|
, - (y - this.y - this.w2)
|
|
) - this.angleOffset;
|
|
|
|
if(this.angleArc != this.PI2 && (a < 0) && (a > -0.5)) {
|
|
// if isset angleArc option, set to min if .5 under min
|
|
a = 0;
|
|
} else if (a < 0) {
|
|
a += this.PI2;
|
|
}
|
|
|
|
ret = ~~ (0.5 + (a * (this.o.max - this.o.min) / this.angleArc))
|
|
+ this.o.min;
|
|
|
|
this.o.stopper
|
|
&& (ret = max(min(ret, this.o.max), this.o.min));
|
|
|
|
return ret;
|
|
};
|
|
|
|
this.listen = function () {
|
|
// bind MouseWheel
|
|
var s = this,
|
|
mw = function (e) {
|
|
e.preventDefault();
|
|
|
|
var ori = e.originalEvent
|
|
,deltaX = ori.detail || ori.wheelDeltaX
|
|
,deltaY = ori.detail || ori.wheelDeltaY
|
|
,v = parseInt(s.$.val()) + (deltaX>0 || deltaY>0 ? 1 : deltaX<0 || deltaY<0 ? -1 : 0);
|
|
|
|
if (
|
|
s.cH
|
|
&& (s.cH(v) === false)
|
|
) return;
|
|
|
|
s.val(v);
|
|
}
|
|
, kval, to, m = 1, kv = {37:-1, 38:1, 39:1, 40:-1};
|
|
|
|
this.$
|
|
.bind(
|
|
"keydown"
|
|
,function (e) {
|
|
var kc = e.keyCode;
|
|
kval = parseInt(String.fromCharCode(kc));
|
|
|
|
if (isNaN(kval)) {
|
|
|
|
(kc !== 13) // enter
|
|
&& (kc !== 8) // bs
|
|
&& (kc !== 9) // tab
|
|
&& (kc !== 189) // -
|
|
&& e.preventDefault();
|
|
|
|
// arrows
|
|
if ($.inArray(kc,[37,38,39,40]) > -1) {
|
|
e.preventDefault();
|
|
|
|
var v = parseInt(s.$.val()) + kv[kc] * m;
|
|
|
|
s.o.stopper
|
|
&& (v = max(min(v, s.o.max), s.o.min));
|
|
|
|
s.change(v);
|
|
s._draw();
|
|
|
|
// long time keydown speed-up
|
|
to = window.setTimeout(
|
|
function () { m*=2; }
|
|
,30
|
|
);
|
|
}
|
|
}
|
|
}
|
|
)
|
|
.bind(
|
|
"keyup"
|
|
,function (e) {
|
|
if (isNaN(kval)) {
|
|
if (to) {
|
|
window.clearTimeout(to);
|
|
to = null;
|
|
m = 1;
|
|
s.val(s.$.val());
|
|
}
|
|
} else {
|
|
// kval postcond
|
|
(s.$.val() > s.o.max && s.$.val(s.o.max))
|
|
|| (s.$.val() < s.o.min && s.$.val(s.o.min));
|
|
}
|
|
|
|
}
|
|
);
|
|
|
|
this.$c.bind("mousewheel DOMMouseScroll", mw);
|
|
this.$.bind("mousewheel DOMMouseScroll", mw)
|
|
};
|
|
|
|
this.init = function () {
|
|
|
|
if (
|
|
this.v < this.o.min
|
|
|| this.v > this.o.max
|
|
) this.v = this.o.min;
|
|
|
|
this.$.val(this.v);
|
|
this.w2 = this.o.width / 2;
|
|
this.cursorExt = this.o.cursor / 100;
|
|
this.xy = this.w2;
|
|
this.lineWidth = this.xy * this.o.thickness;
|
|
this.radius = this.xy - this.lineWidth / 2;
|
|
|
|
this.o.angleOffset
|
|
&& (this.o.angleOffset = isNaN(this.o.angleOffset) ? 0 : this.o.angleOffset);
|
|
|
|
this.o.angleArc
|
|
&& (this.o.angleArc = isNaN(this.o.angleArc) ? this.PI2 : this.o.angleArc);
|
|
|
|
// deg to rad
|
|
this.angleOffset = this.o.angleOffset * Math.PI / 180;
|
|
this.angleArc = this.o.angleArc * Math.PI / 180;
|
|
|
|
// compute start and end angles
|
|
this.startAngle = 1.5 * Math.PI + this.angleOffset;
|
|
this.endAngle = 1.5 * Math.PI + this.angleOffset + this.angleArc;
|
|
|
|
var s = max(
|
|
String(Math.abs(this.o.max)).length
|
|
, String(Math.abs(this.o.min)).length
|
|
, 2
|
|
) + 2;
|
|
|
|
this.o.displayInput
|
|
&& this.i.css({
|
|
'width' : ((this.o.width / 2 + 4) >> 0) + 'px'
|
|
,'height' : ((this.o.width / 3) >> 0) + 'px'
|
|
,'position' : 'absolute'
|
|
,'vertical-align' : 'middle'
|
|
,'margin-top' : ((this.o.width / 3) >> 0) + 'px'
|
|
,'margin-left' : '-' + ((this.o.width * 3 / 4 + 2) >> 0) + 'px'
|
|
,'border' : 0
|
|
,'background' : 'none'
|
|
,'font' : 'bold ' + ((this.o.width / s) >> 0) + 'px Arial'
|
|
,'text-align' : 'center'
|
|
,'color' : this.o.fgColor
|
|
,'padding' : '0px'
|
|
,'-webkit-appearance': 'none'
|
|
})
|
|
|| this.i.css({
|
|
'width' : '0px'
|
|
,'visibility' : 'hidden'
|
|
});
|
|
};
|
|
|
|
this.change = function (v) {
|
|
this.cv = v;
|
|
this.$.val(v);
|
|
};
|
|
|
|
this.angle = function (v) {
|
|
return (v - this.o.min) * this.angleArc / (this.o.max - this.o.min);
|
|
};
|
|
|
|
this.draw = function () {
|
|
|
|
var c = this.g, // context
|
|
a = this.angle(this.cv) // Angle
|
|
, sat = this.startAngle // Start angle
|
|
, eat = sat + a // End angle
|
|
, sa, ea // Previous angles
|
|
, r = 1;
|
|
|
|
c.lineWidth = this.lineWidth;
|
|
|
|
this.o.cursor
|
|
&& (sat = eat - this.cursorExt)
|
|
&& (eat = eat + this.cursorExt);
|
|
|
|
c.beginPath();
|
|
c.strokeStyle = this.o.bgColor;
|
|
c.arc(this.xy, this.xy, this.radius, this.endAngle, this.startAngle, true);
|
|
c.stroke();
|
|
|
|
if (this.o.displayPrevious) {
|
|
ea = this.startAngle + this.angle(this.v);
|
|
sa = this.startAngle;
|
|
this.o.cursor
|
|
&& (sa = ea - this.cursorExt)
|
|
&& (ea = ea + this.cursorExt);
|
|
|
|
c.beginPath();
|
|
c.strokeStyle = this.pColor;
|
|
c.arc(this.xy, this.xy, this.radius, sa, ea, false);
|
|
c.stroke();
|
|
r = (this.cv == this.v);
|
|
}
|
|
|
|
c.beginPath();
|
|
c.strokeStyle = r ? this.o.fgColor : this.fgColor ;
|
|
c.arc(this.xy, this.xy, this.radius, sat, eat, false);
|
|
c.stroke();
|
|
};
|
|
|
|
this.cancel = function () {
|
|
this.val(this.v);
|
|
};
|
|
};
|
|
|
|
$.fn.dial = $.fn.knob = function (o) {
|
|
return this.each(
|
|
function () {
|
|
var d = new k.Dial();
|
|
d.o = o;
|
|
d.$ = $(this);
|
|
d.run();
|
|
}
|
|
).parent();
|
|
};
|
|
|
|
});
|
|
Rickshaw={namespace:function(a,b){var c=a.split("."),d=typeof global!="undefined"?global:window,e=d.Rickshaw;for(var f=1,g=c.length;f<g;f++)currentPart=c[f],e[currentPart]=e[currentPart]||{},e=e[currentPart];return e},keys:function(a){var b=[];for(var c in a)b.push(c);return b},extend:function(a,b){for(var c in b)a[c]=b[c];return a}},function(a){function j(a){return b.call(a)===i}function k(a,b){for(var c in b)b.hasOwnProperty(c)&&(a[c]=b[c]);return a}function l(a){if(m(a)!==h)throw new TypeError;var b=[];for(var c in a)a.hasOwnProperty(c)&&b.push(c);return b}function m(a){switch(a){case null:return c;case void 0:return d}var b=typeof a;switch(b){case"boolean":return e;case"number":return f;case"string":return g}return h}function n(a){return typeof a=="undefined"}function p(a){var b=a.toString().match(/^[\s\(]*function[^(]*\(([^)]*)\)/)[1].replace(/\/\/.*?[\r\n]|\/\*(?:.|[\r\n])*?\*\//g,"").replace(/\s+/g,"").split(",");return b.length==1&&!b[0]?[]:b}function q(a,b){var c=a;return function(){var a=r([t(c,this)],arguments);return b.apply(this,a)}}function r(a,b){var c=a.length,d=b.length;while(d--)a[c+d]=b[d];return a}function s(a,b){return a=o.call(a,0),r(a,b)}function t(a,b){if(arguments.length<2&&n(arguments[0]))return this;var c=a,d=o.call(arguments,2);return function(){var a=s(d,arguments);return c.apply(b,a)}}var b=Object.prototype.toString,c="Null",d="Undefined",e="Boolean",f="Number",g="String",h="Object",i="[object Function]",o=Array.prototype.slice,u=function(){},v=function(){function b(){}function c(){function d(){this.initialize.apply(this,arguments)}var a=null,c=[].slice.apply(arguments);j(c[0])&&(a=c.shift()),k(d,v.Methods),d.superclass=a,d.subclasses=[];if(a){b.prototype=a.prototype,d.prototype=new b;try{a.subclasses.push(d)}catch(e){}}for(var f=0,g=c.length;f<g;f++)d.addMethods(c[f]);return d.prototype.initialize||(d.prototype.initialize=u),d.prototype.constructor=d,d}function d(b){var c=this.superclass&&this.superclass.prototype,d=l(b);a&&(b.toString!=Object.prototype.toString&&d.push("toString"),b.valueOf!=Object.prototype.valueOf&&d.push("valueOf"));for(var e=0,f=d.length;e<f;e++){var g=d[e],h=b[g];if(c&&j(h)&&p(h)[0]=="$super"){var i=h;h=q(function(a){return function(){return c[a].apply(this,arguments)}}(g),i),h.valueOf=t(i.valueOf,i),h.toString=t(i.toString,i)}this.prototype[g]=h}return this}var a=function(){for(var a in{toString:1})if(a==="toString")return!1;return!0}();return{create:c,Methods:{addMethods:d}}}();a.exports?a.exports.Class=v:a.Class=v}(Rickshaw),Rickshaw.namespace("Rickshaw.Compat.ClassList"),Rickshaw.Compat.ClassList=function(){typeof document!="undefined"&&!("classList"in document.createElement("a"))&&function(a){"use strict";var b="classList",c="prototype",d=(a.HTMLElement||a.Element)[c],e=Object,f=String[c].trim||function(){return this.replace(/^\s+|\s+$/g,"")},g=Array[c].indexOf||function(a){var b=0,c=this.length;for(;b<c;b++)if(b in this&&this[b]===a)return b;return-1},h=function(a,b){this.name=a,this.code=DOMException[a],this.message=b},i=function(a,b){if(b==="")throw new h("SYNTAX_ERR","An invalid or illegal string was specified");if(/\s/.test(b))throw new h("INVALID_CHARACTER_ERR","String contains an invalid character");return g.call(a,b)},j=function(a){var b=f.call(a.className),c=b?b.split(/\s+/):[],d=0,e=c.length;for(;d<e;d++)this.push(c[d]);this._updateClassName=function(){a.className=this.toString()}},k=j[c]=[],l=function(){return new j(this)};h[c]=Error[c],k.item=function(a){return this[a]||null},k.contains=function(a){return a+="",i(this,a)!==-1},k.add=function(a){a+="",i(this,a)===-1&&(this.push(a),this._updateClassName())},k.remove=function(a){a+="";var b=i(this,a);b!==-1&&(this.splice(b,1),this._updateClassName())},k.toggle=function(a){a+="",i(this,a)===-1?this.add(a):this.remove(a)},k.toString=function(){return this.join(" ")};if(e.defineProperty){var m={get:l,enumerable:!0,configurable:!0};try{e.defineProperty(d,b,m)}catch(n){n.number===-2146823252&&(m.enumerable=!1,e.defineProperty(d,b,m))}}else e[c].__defineGetter__&&d.__defineGetter__(b,l)}(self)},(typeof RICKSHAW_NO_COMPAT!="undefined"&&!RICKSHAW_NO_COMPAT||typeof RICKSHAW_NO_COMPAT=="undefined")&&new Rickshaw.Compat.ClassList,Rickshaw.namespace("Rickshaw.Graph"),Rickshaw.Graph=function(a){this.element=a.element,this.series=a.series,this.defaults={interpolation:"cardinal",offset:"zero",min:undefined,max:undefined},Rickshaw.keys(this.defaults).forEach(function(b){this[b]=a[b]||this.defaults[b]},this),this.window={},this.updateCallbacks=[];var b=this;this.initialize=function(a){this.validateSeries(a.series),this.series.active=function(){return b.series.filter(function(a){return!a.disabled})},this.setSize({width:a.width,height:a.height}),this.element.classList.add("rickshaw_graph"),this.vis=d3.select(this.element).append("svg:svg").attr("width",this.width).attr("height",this.height);var c=[Rickshaw.Graph.Renderer.Stack,Rickshaw.Graph.Renderer.Line,Rickshaw.Graph.Renderer.Bar,Rickshaw.Graph.Renderer.Area,Rickshaw.Graph.Renderer.ScatterPlot];c.forEach(function(a){if(!a)return;b.registerRenderer(new a({graph:b}))}),this.setRenderer(a.renderer||"stack",a),this.discoverRange()},this.validateSeries=function(a){if(!(a instanceof Array||a instanceof Rickshaw.Series)){var b=Object.prototype.toString.apply(a);throw"series is not an array: "+b}var c;a.forEach(function(a){if(!(a instanceof Object))throw"series element is not an object: "+a;if(!a.data)throw"series has no data: "+JSON.stringify(a);if(!(a.data instanceof Array))throw"series data is not an array: "+JSON.stringify(a.data);c=c||a.data.length;if(c&&a.data.length!=c)throw"series cannot have differing numbers of points: "+c+" vs "+a.data.length+"; see Rickshaw.Series.zeroFill()";var b=typeof a.data[0].x,d=typeof a.data[0].y;if(b!="number"||d!="number")throw"x and y properties of points should be numbers instead of "+b+" and "+d})},this.dataDomain=function(){var a=this.series[0].data;return[a[0].x,a.slice(-1).shift().x]},this.discoverRange=function(){var a=this.renderer.domain();this.x=d3.scale.linear().domain(a.x).range([0,this.width]),this.y=d3.scale.linear().domain(a.y).range([this.height,0]),this.y.magnitude=d3.scale.linear().domain(a.y).range([0,this.height])},this.render=function(){var a=this.stackData();this.discoverRange(),this.renderer.render(),this.updateCallbacks.forEach(function(a){a()})},this.update=this.render,this.stackData=function(){var a=this.series.active().map(function(a){return a.data}).map(function(a){return a.filter(function(a){return this._slice(a)},this)},this);this.stackData.hooks.data.forEach(function(c){a=c.f.apply(b,[a])});var c=d3.layout.stack();c.offset(b.offset);var d=c(a);this.stackData.hooks.after.forEach(function(c){d=c.f.apply(b,[a])});var e=0;return this.series.forEach(function(a){if(a.disabled)return;a.stack=d[e++]}),this.stackedData=d,d},this.stackData.hooks={data:[],after:[]},this._slice=function(a){if(this.window.xMin||this.window.xMax){var b=!0;return this.window.xMin&&a.x<this.window.xMin&&(b=!1),this.window.xMax&&a.x>this.window.xMax&&(b=!1),b}return!0},this.onUpdate=function(a){this.updateCallbacks.push(a)},this.registerRenderer=function(a){this._renderers=this._renderers||{},this._renderers[a.name]=a},this.configure=function(a){(a.width||a.height)&&this.setSize(a),Rickshaw.keys(this.defaults).forEach(function(b){this[b]=b in a?a[b]:b in this?this[b]:this.defaults[b]},this),this.setRenderer(a.renderer||this.renderer.name,a)},this.setRenderer=function(a,b){if(!this._renderers[a])throw"couldn't find renderer "+a;this.renderer=this._renderers[a],typeof b=="object"&&this.renderer.configure(b)},this.setSize=function(a){a=a||{};if(typeof window!==undefined)var b=window.getComputedStyle(this.element,null),c=parseInt(b.getPropertyValue("width")),d=parseInt(b.getPropertyValue("height"));this.width=a.width||c||400,this.height=a.height||d||250,this.vis&&this.vis.attr("width",this.width).attr("height",this.height)},this.initialize(a)},Rickshaw.namespace("Rickshaw.Fixtures.Color"),Rickshaw.Fixtures.Color=function(){this.schemes={},this.schemes.spectrum14=["#ecb796","#dc8f70","#b2a470","#92875a","#716c49","#d2ed82","#bbe468","#a1d05d","#e7cbe6","#d8aad6","#a888c2","#9dc2d3","#649eb9","#387aa3"].reverse(),this.schemes.spectrum2000=["#57306f","#514c76","#646583","#738394","#6b9c7d","#84b665","#a7ca50","#bfe746","#e2f528","#fff726","#ecdd00","#d4b11d","#de8800","#de4800","#c91515","#9a0000","#7b0429","#580839","#31082b"],this.schemes.spectrum2001=["#2f243f","#3c2c55","#4a3768","#565270","#6b6b7c","#72957f","#86ad6e","#a1bc5e","#b8d954","#d3e04e","#ccad2a","#cc8412","#c1521d","#ad3821","#8a1010","#681717","#531e1e","#3d1818","#320a1b"],this.schemes.classic9=["#423d4f","#4a6860","#848f39","#a2b73c","#ddcb53","#c5a32f","#7d5836","#963b20","#7c2626","#491d37","#2f254a"].reverse(),this.schemes.httpStatus={503:"#ea5029",502:"#d23f14",500:"#bf3613",410:"#efacea",409:"#e291dc",403:"#f457e8",408:"#e121d2",401:"#b92dae",405:"#f47ceb",404:"#a82a9f",400:"#b263c6",301:"#6fa024",302:"#87c32b",307:"#a0d84c",304:"#28b55c",200:"#1a4f74",206:"#27839f",201:"#52adc9",202:"#7c979f",203:"#a5b8bd",204:"#c1cdd1"},this.schemes.colorwheel=["#b5b6a9","#858772","#785f43","#96557e","#4682b4","#65b9ac","#73c03a","#cb513a"].reverse(),this.schemes.cool=["#5e9d2f","#73c03a","#4682b4","#7bc3b8","#a9884e","#c1b266","#a47493","#c09fb5"],this.schemes.munin=["#00cc00","#0066b3","#ff8000","#ffcc00","#330099","#990099","#ccff00","#ff0000","#808080","#008f00","#00487d","#b35a00","#b38f00","#6b006b","#8fb300","#b30000","#bebebe","#80ff80","#80c9ff","#ffc080","#ffe680","#aa80ff","#ee00cc","#ff8080","#666600","#ffbfff","#00ffcc","#cc6699","#999900"]},Rickshaw.namespace("Rickshaw.Fixtures.RandomData"),Rickshaw.Fixtures.RandomData=function(a){var b;a=a||1;var c=200,d=Math.floor((new Date).getTime()/1e3);this.addData=function(b){var e=Math.random()*100+15+c,f=b[0].length,g=1;b.forEach(function(b){var c=Math.random()*20,h=e/25+g++ +(Math.cos(f*g*11/960)+2)*15+(Math.cos(f/7)+2)*7+(Math.cos(f/17)+2)*1;b.push({x:f*a+d,y:h+c})}),c=e*.85}},Rickshaw.namespace("Rickshaw.Fixtures.Time"),Rickshaw.Fixtures.Time=function(){var a=(new Date).getTimezoneOffset()*60,b=this;this.months=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],this.units=[{name:"decade",seconds:315576e3,formatter:function(a){return parseInt(a.getUTCFullYear()/10)*10}},{name:"year",seconds:31557600,formatter:function(a){return a.getUTCFullYear()}},{name:"month",seconds:2635200,formatter:function(a){return b.months[a.getUTCMonth()]}},{name:"week",seconds:604800,formatter:function(a){return b.formatDate(a)}},{name:"day",seconds:86400,formatter:function(a){return a.getUTCDate()}},{name:"6 hour",seconds:21600,formatter:function(a){return b.formatTime(a)}},{name:"hour",seconds:3600,formatter:function(a){return b.formatTime(a)}},{name:"15 minute",seconds:900,formatter:function(a){return b.formatTime(a)}},{name:"minute",seconds:60,formatter:function(a){return a.getUTCMinutes()}},{name:"15 second",seconds:15,formatter:function(a){return a.getUTCSeconds()+"s"}},{name:"second",seconds:1,formatter:function(a){return a.getUTCSeconds()+"s"}}],this.unit=function(a){return this.units.filter(function(b){return a==b.name}).shift()},this.formatDate=function(a){return a.toUTCString().match(/, (\w+ \w+ \w+)/)[1]},this.formatTime=function(a){return a.toUTCString().match(/(\d+:\d+):/)[1]},this.ceil=function(a,b){if(b.name=="month"){var c=new Date((a+b.seconds-1)*1e3),d=new Date(0);return d.setUTCFullYear(c.getUTCFullYear()),d.setUTCMonth(c.getUTCMonth()),d.setUTCDate(1),d.setUTCHours(0),d.setUTCMinutes(0),d.setUTCSeconds(0),d.setUTCMilliseconds(0),d.getTime()/1e3}if(b.name=="year"){var c=new Date((a+b.seconds-1)*1e3),d=new Date(0);return d.setUTCFullYear(c.getUTCFullYear()),d.setUTCMonth(0),d.setUTCDate(1),d.setUTCHours(0),d.setUTCMinutes(0),d.setUTCSeconds(0),d.setUTCMilliseconds(0),d.getTime()/1e3}return Math.ceil(a/b.seconds)*b.seconds}},Rickshaw.namespace("Rickshaw.Fixtures.Number"),Rickshaw.Fixtures.Number.formatKMBT=function(a){return a>=1e12?a/1e12+"T":a>=1e9?a/1e9+"B":a>=1e6?a/1e6+"M":a>=1e3?a/1e3+"K":a<1&&a>0?a.toFixed(2):a==0?"":a},Rickshaw.Fixtures.Number.formatBase1024KMGTP=function(a){return a>=0x4000000000000?a/0x4000000000000+"P":a>=1099511627776?a/1099511627776+"T":a>=1073741824?a/1073741824+"G":a>=1048576?a/1048576+"M":a>=1024?a/1024+"K":a<1&&a>0?a.toFixed(2):a==0?"":a},Rickshaw.namespace("Rickshaw.Color.Palette"),Rickshaw.Color.Palette=function(a){var b=new Rickshaw.Fixtures.Color;a=a||{},this.schemes={},this.scheme=b.schemes[a.scheme]||a.scheme||b.schemes.colorwheel,this.runningIndex=0,this.generatorIndex=0;if(a.interpolatedStopCount){var c=this.scheme.length-1,d,e,f=[];for(d=0;d<c;d++){f.push(this.scheme[d]);var g=d3.interpolateHsl(this.scheme[d],this.scheme[d+1]);for(e=1;e<a.interpolatedStopCount;e++)f.push(g(1/a.interpolatedStopCount*e))}f.push(this.scheme[this.scheme.length-1]),this.scheme=f}this.rotateCount=this.scheme.length,this.color=function(a){return this.scheme[a]||this.scheme[this.runningIndex++]||this.interpolateColor()||"#808080"},this.interpolateColor=function(){var a;return this.generatorIndex==this.rotateCount*2-1?(a=d3.interpolateHsl(this.scheme[this.generatorIndex],this.scheme[0])(.5),this.generatorIndex=0,this.rotateCount*=2):(a=d3.interpolateHsl(this.scheme[this.generatorIndex],this.scheme[this.generatorIndex+1])(.5),this.generatorIndex++),this.scheme.push(a),a}},Rickshaw.namespace("Graph.Ajax"),Rickshaw.Graph.Ajax=function(a){var b=this;this.dataURL=a.dataURL,$.ajax({url:this.dataURL,complete:function(c,d){d==="error"&&console.log("error loading dataURL: "+this.dataURL);var e=JSON.parse(c.responseText);if(typeof a.onData=="function"){var f=a.onData(e);e=f}a.series?a.series.forEach(function(a){var b=a.key||a.name;if(!b)throw"series needs a key or a name";e.forEach(function(c){var d=c.key||c.name;if(!d)throw"data needs a key or a name";if(b==d){var e=["color","name","data"];e.forEach(function(b){a[b]=a[b]||c[b]})}})}):a.series=e,b.graph=new Rickshaw.Graph(a),b.graph.render(),typeof a.onComplete=="function"&&a.onComplete(b)}})},Rickshaw.namespace("Rickshaw.Graph.Annotate"),Rickshaw.Graph.Annotate=function(a){var b=this.graph=a.graph;this.elements={timeline:a.element};var c=this;this.data={},this.elements.timeline.classList.add("rickshaw_annotation_timeline"),this.add=function(a,b){c.data[a]=c.data[a]||{boxes:[]},c.data[a].boxes.push({content:b})},this.update=function(){Rickshaw.keys(c.data).forEach(function(a){var b=c.data[a],d=c.graph.x(a);if(d<0||d>c.graph.x.range()[1]){b.element&&(b.element.style.display="none");return}if(!b.element){var e=b.element=document.createElement("div");e.classList.add("annotation"),this.elements.timeline.appendChild(e),e.addEventListener("click",function(a){e.classList.toggle("active"),b.line.classList.toggle("active")},!1)}b.element.style.left=d+"px",b.element.style.display="block",b.boxes.forEach(function(a){var e=a.element;e||(e=a.element=document.createElement("div"),e.classList.add("content"),e.innerHTML=a.content,b.element.appendChild(e),b.line=document.createElement("div"),b.line.classList.add("annotation_line"),c.graph.element.appendChild(b.line)),b.line.style.left=d+"px"})},this)},this.graph.onUpdate(function(){c.update()})},Rickshaw.namespace("Rickshaw.Graph.Axis.Time"),Rickshaw.Graph.Axis.Time=function(a){var b=this;this.graph=a.graph,this.elements=[],this.ticksTreatment=a.ticksTreatment||"plain",this.fixedTimeUnit=a.timeUnit;var c=new Rickshaw.Fixtures.Time;this.appropriateTimeUnit=function(){var a,b=c.units,d=this.graph.x.domain(),e=d[1]-d[0];return b.forEach(function(b){Math.floor(e/b.seconds)>=2&&(a=a||b)}),a||c.units[c.units.length-1]},this.tickOffsets=function(){var a=this.graph.x.domain(),b=this.fixedTimeUnit||this.appropriateTimeUnit(),d=Math.ceil((a[1]-a[0])/b.seconds),e=a[0],f=[];for(var g=0;g<d;g++)tickValue=c.ceil(e,b),e=tickValue+b.seconds/2,f.push({value:tickValue,unit:b});return f},this.render=function(){this.elements.forEach(function(a){a.parentNode.removeChild(a)}),this.elements=[];var a=this.tickOffsets();a.forEach(function(a){if(b.graph.x(a.value)>b.graph.x.range()[1])return;var c=document.createElement("div");c.style.left=b.graph.x(a.value)+"px",c.classList.add("x_tick"),c.classList.add(b.ticksTreatment);var d=document.createElement("div");d.classList.add("title"),d.innerHTML=a.unit.formatter(new Date(a.value*1e3)),c.appendChild(d),b.graph.element.appendChild(c),b.elements.push(c)})},this.graph.onUpdate(function(){b.render()})},Rickshaw.namespace("Rickshaw.Graph.Axis.Y"),Rickshaw.Graph.Axis.Y=function(a){var b=this,c=.1;this.initialize=function(a){this.graph=a.graph,this.orientation=a.orientation||"right";var c=a.pixelsPerTick||75;this.ticks=a.ticks||Math.floor(this.graph.height/c),this.tickSize=a.tickSize||4,this.ticksTreatment=a.ticksTreatment||"plain",a.element?(this.element=a.element,this.vis=d3.select(a.element).append("svg:svg").attr("class","rickshaw_graph y_axis"),this.element=this.vis[0][0],this.element.style.position="relative",this.setSize({width:a.width,height:a.height})):this.vis=this.graph.vis,this.graph.onUpdate(function(){b.render()})},this.setSize=function(a){a=a||{};if(!this.element)return;if(typeof window!="undefined"){var b=window.getComputedStyle(this.element.parentNode,null),d=parseInt(b.getPropertyValue("width"));if(!a.auto)var e=parseInt(b.getPropertyValue("height"))}this.width=a.width||d||this.graph.width*c,this.height=a.height||e||this.graph.height,this.vis.attr("width",this.width).attr("height",this.height*(1+c));var f=this.height*c;this.element.style.top=-1*f+"px"},this.render=function(){this.graph.height!==this._renderHeight&&this.setSize({auto:!0});var b=d3.svg.axis().scale(this.graph.y).orient(this.orientation);b.tickFormat(a.tickFormat||function(a){return a});if(this.orientation=="left")var d=this.height*c,e="translate("+this.width+", "+d+")";this.element&&this.vis.selectAll("*").remove(),this.vis.append("svg:g").attr("class",["y_ticks",this.ticksTreatment].join(" ")).attr("transform",e).call(b.ticks(this.ticks).tickSubdivide(0).tickSize(this.tickSize));var f=(this.orientation=="right"?1:-1)*this.graph.width;this.graph.vis.append("svg:g").attr("class","y_grid").call(b.ticks(this.ticks).tickSubdivide(0).tickSize(f)),this._renderHeight=this.graph.height},this.initialize(a)},Rickshaw.namespace("Rickshaw.Graph.Behavior.Series.Highlight"),Rickshaw.Graph.Behavior.Series.Highlight=function(a){this.graph=a.graph,this.legend=a.legend;var b=this,c={};this.addHighlightEvents=function(a){a.element.addEventListener("mouseover",function(d){b.legend.lines.forEach(function(b){if(a===b)return;c[b.series.name]=c[b.series.name]||b.series.color,b.series.color=d3.interpolateRgb(b.series.color,d3.rgb("#d8d8d8"))(.8).toString()}),b.graph.update()},!1),a.element.addEventListener("mouseout",function(a){b.legend.lines.forEach(function(a){c[a.series.name]&&(a.series.color=c[a.series.name])}),b.graph.update()},!1)},this.legend&&this.legend.lines.forEach(function(a){b.addHighlightEvents(a)})},Rickshaw.namespace("Rickshaw.Graph.Behavior.Series.Order"),Rickshaw.Graph.Behavior.Series.Order=function(a){this.graph=a.graph,this.legend=a.legend;var b=this;$(function(){$(b.legend.list).sortable({containment:"parent",tolerance:"pointer",update:function(a,c){var d=[];$(b.legend.list).find("li").each(function(a,b){if(!b.series)return;d.push(b.series)});for(var e=b.graph.series.length-1;e>=0;e--)b.graph.series[e]=d.shift();b.graph.update()}}),$(b.legend.list).disableSelection()}),this.graph.onUpdate(function(){var a=window.getComputedStyle(b.legend.element).height;b.legend.element.style.height=a})},Rickshaw.namespace("Rickshaw.Graph.Behavior.Series.Toggle"),Rickshaw.Graph.Behavior.Series.Toggle=function(a){this.graph=a.graph,this.legend=a.legend;var b=this;this.addAnchor=function(a){var c=document.createElement("a");c.innerHTML="✔",c.classList.add("action"),a.element.insertBefore(c,a.element.firstChild),c.onclick=function(b){a.series.disabled?(a.series.enable(),a.element.classList.remove("disabled")):(a.series.disable(),a.element.classList.add("disabled"))};var d=a.element.getElementsByTagName("span")[0];d.onclick=function(c){var d=a.series.disabled;if(!d)for(var e=0;e<b.legend.lines.length;e++){var f=b.legend.lines[e];if(a.series!==f.series&&!f.series.disabled){d=!0;break}}d?(a.series.enable(),a.element.classList.remove("disabled"),b.legend.lines.forEach(function(b){a.series!==b.series&&(b.series.disable(),b.element.classList.add("disabled"))})):b.legend.lines.forEach(function(a){a.series.enable(),a.element.classList.remove("disabled")})}},this.legend&&($(this.legend.list).sortable({start:function(a,b){b.item.bind("no.onclick",function(a){a.preventDefault()})},stop:function(a,b){setTimeout(function(){b.item.unbind("no.onclick")},250)}}),this.legend.lines.forEach(function(a){b.addAnchor(a)})),this._addBehavior=function(){this.graph.series.forEach(function(a){a.disable=function(){if(b.graph.series.length<=1)throw"only one series left";a.disabled=!0,b.graph.update()},a.enable=function(){a.disabled=!1,b.graph.update()}})},this._addBehavior(),this.updateBehaviour=function(){this._addBehavior()}},Rickshaw.namespace("Rickshaw.Graph.HoverDetail"),Rickshaw.Graph.HoverDetail=Rickshaw.Class.create({initialize:function(a){var b=this.graph=a.graph;this.xFormatter=a.xFormatter||function(a){return(new Date(a*1e3)).toUTCString()},this.yFormatter=a.yFormatter||function(a){return a.toFixed(2)};var c=this.element=document.createElement("div");c.className="detail",this.visible=!0,b.element.appendChild(c),this.lastEvent=null,this._addListeners(),this.onShow=a.onShow,this.onHide=a.onHide,this.onRender=a.onRender,this.formatter=a.formatter||this.formatter},formatter:function(a,b,c,d,e,f){return a.name+": "+e},update:function(a){a=a||this.lastEvent;if(!a)return;this.lastEvent=a;if(!a.target.nodeName.match(/^(path|svg|rect)$/))return;var b=this.graph,c=a.offsetX||a.layerX,d=a.offsetY||a.layerY,e=b.x.invert(c),f=b.stackedData,g=f.slice(-1).shift(),h=d3.scale.linear().domain([g[0].x,g.slice(-1).shift().x]).range([0,g.length]),i=Math.floor(h(e)),j=Math.min(i||0,f[0].length-1);for(var k=i;k<f[0].length-1;){if(!f[0][k]||!f[0][k+1])break;if(f[0][k].x<=e&&f[0][k+1].x>e){j=k;break}f[0][k+1]<=e?k++:k--}var e=f[0][j].x,l=this.xFormatter(e),m=b.x(e),n=0,o=b.series.active().map(function(a){return{order:n++,series:a,name:a.name,value:a.stack[j]}}),p,q=function(a,b){return a.value.y0+a.value.y-(b.value.y0+b.value.y)},r=b.y.magnitude.invert(b.element.offsetHeight-d);o.sort(q).forEach(function(a){a.formattedYValue=this.yFormatter.constructor==Array?this.yFormatter[o.indexOf(a)](a.value.y):this.yFormatter(a.value.y),a.graphX=m,a.graphY=b.y(a.value.y0+a.value.y),r>a.value.y0&&r<a.value.y0+a.value.y&&!p&&(p=a,a.active=!0)},this),this.element.innerHTML="",this.element.style.left=b.x(e)+"px",this.visible&&this.render({detail:o,domainX:e,formattedXValue:l,mouseX:c,mouseY:d})},hide:function(){this.visible=!1,this.element.classList.add("inactive"),typeof this.onHide=="function"&&this.onHide()},show:function(){this.visible=!0,this.element.classList.remove("inactive"),typeof this.onShow=="function"&&this.onShow()},render:function(a){var b=a.detail,c=a.domainX,d=a.mouseX,e=a.mouseY,f=a.formattedXValue,g=document.createElement("div");g.className="x_label",g.innerHTML=f,this.element.appendChild(g),b.forEach(function(a){var b=document.createElement("div");b.className="item",b.innerHTML=this.formatter(a.series,c,a.value.y,f,a.formattedYValue,a),b.style.top=this.graph.y(a.value.y0+a.value.y)+"px",this.element.appendChild(b);var d=document.createElement("div");d.className="dot",d.style.top=b.style.top,d.style.borderColor=a.series.color,this.element.appendChild(d),a.active&&(b.className="item active",d.className="dot active")},this),this.show(),typeof this.onRender=="function"&&this.onRender(a)},_addListeners:function(){this.graph.element.addEventListener("mousemove",function(a){this.visible=!0,this.update(a)}.bind(this),!1),this.graph.onUpdate(function(){this.update()}.bind(this)),this.graph.element.addEventListener("mouseout",function(a){a.relatedTarget&&!(a.relatedTarget.compareDocumentPosition(this.graph.element)&Node.DOCUMENT_POSITION_CONTAINS)&&this.hide()}.bind(this),!1)}}),Rickshaw.namespace("Rickshaw.Graph.JSONP"),Rickshaw.Graph.JSONP=function(a){var b=this;this.dataURL=a.dataURL,$.ajax({url:this.dataURL,dataType:"jsonp",success:function(c,d,e){d==="error"&&console.log("error loading dataURL: "+this.dataURL);if(typeof a.onData=="function"){var f=a.onData(c);c=f}a.series?a.series.forEach(function(a){var b=a.key||a.name;if(!b)throw"series needs a key or a name";c.forEach(function(c){var d=c.key||c.name;if(!d)throw"data needs a key or a name";if(b==d){var e=["color","name","data"];e.forEach(function(b){a[b]=a[b]||c[b]})}})}):a.series=c,b.graph=new Rickshaw.Graph(a),b.graph.render(),typeof a.onComplete=="function"&&a.onComplete(b)}})},Rickshaw.namespace("Rickshaw.Graph.Legend"),Rickshaw.Graph.Legend=function(a){var b=this.element=a.element,c=this.graph=a.graph,d=this;b.classList.add("rickshaw_legend");var e=this.list=document.createElement("ul");b.appendChild(e);var f=c.series.map(function(a){return a}).reverse();this.lines=[],this.addLine=function(a){var b=document.createElement("li");b.className="line";var c=document.createElement("div");c.className="swatch",c.style.backgroundColor=a.color,b.appendChild(c);var f=document.createElement("span");f.className="label",f.innerHTML=a.name,b.appendChild(f),e.appendChild(b),b.series=a,a.noLegend&&(b.style.display="none");var g={element:b,series:a};d.shelving&&(d.shelving.addAnchor(g),d.shelving.updateBehaviour()),d.highlighter&&d.highlighter.addHighlightEvents(g),d.lines.push(g)},f.forEach(function(a){d.addLine(a)}),c.onUpdate(function(){})},Rickshaw.namespace("Rickshaw.Graph.RangeSlider"),Rickshaw.Graph.RangeSlider=function(a){var b=this.element=a.element,c=this.graph=a.graph;$(function(){$(b).slider({range:!0,min:c.dataDomain()[0],max:c.dataDomain()[1],values:[c.dataDomain()[0],c.dataDomain()[1]],slide:function(a,b){c.window.xMin=b.values[0],c.window.xMax=b.values[1],c.update(),c.dataDomain()[0]==b.values[0]&&(c.window.xMin=undefined),c.dataDomain()[1]==b.values[1]&&(c.window.xMax=undefined)}})}),b[0].style.width=c.width+"px",c.onUpdate(function(){var a=$(b).slider("option","values");$(b).slider("option","min",c.dataDomain()[0]),$(b).slider("option","max",c.dataDomain()[1]),c.window.xMin==undefined&&(a[0]=c.dataDomain()[0]),c.window.xMax==undefined&&(a[1]=c.dataDomain()[1]),$(b).slider("option","values",a)})},Rickshaw.namespace("Rickshaw.Graph.Renderer"),Rickshaw.Graph.Renderer=Rickshaw.Class.create({initialize:function(a){this.graph=a.graph,this.tension=a.tension||this.tension,this.graph.unstacker=this.graph.unstacker||new Rickshaw.Graph.Unstacker({graph:this.graph}),this.configure(a)},seriesPathFactory:function(){},seriesStrokeFactory:function(){},defaults:function(){return{tension:.8,strokeWidth:2,unstack:!0,padding:{top:.01,right:0,bottom:.01,left:0},stroke:!1,fill:!1}},domain:function(){var a=[],b=this.graph.stackedData||this.graph.stackData(),c=this.unstack?b:[b.slice(-1).shift()];c.forEach(function(b){b.forEach(function(b){a.push(b.y+b.y0)})});var d=b[0][0].x,e=b[0][b[0].length-1].x;d-=(e-d)*this.padding.left,e+=(e-d)*this.padding.right;var f=this.graph.min==="auto"?d3.min(a):this.graph.min||0,g=this.graph.max||d3.max(a);if(this.graph.min==="auto"||f<0)f-=(g-f)*this.padding.bottom;return this.graph.max===undefined&&(g+=(g-f)*this.padding.top),{x:[d,e],y:[f,g]}},render:function(){var a=this.graph;a.vis.selectAll("*").remove();var b=a.vis.selectAll("path").data(this.graph.stackedData).enter().append("svg:path").attr("d",this.seriesPathFactory()),c=0;a.series.forEach(function(a){if(a.disabled)return;a.path=b[0][c++],this._styleSeries(a)},this)},_styleSeries:function(a){var b=this.fill?a.color:"none",c=this.stroke?a.color:"none";a.path.setAttribute("fill",b),a.path.setAttribute("stroke",c),a.path.setAttribute("stroke-width",this.strokeWidth),a.path.setAttribute("class",a.className)},configure:function(a){a=a||{},Rickshaw.keys(this.defaults()).forEach(function(b){if(!a.hasOwnProperty(b)){this[b]=this[b]||this.graph[b]||this.defaults()[b];return}typeof this.defaults()[b]=="object"?Rickshaw.keys(this.defaults()[b]).forEach(function(c){this[b][c]=a[b][c]!==undefined?a[b][c]:this[b][c]!==undefined?this[b][c]:this.defaults()[b][c]},this):this[b]=a[b]!==undefined?a[b]:this[b]!==undefined?this[b]:this.graph[b]!==undefined?this.graph[b]:this.defaults()[b]},this)},setStrokeWidth:function(a){a!==undefined&&(this.strokeWidth=a)},setTension:function(a){a!==undefined&&(this.tension=a)}}),Rickshaw.namespace("Rickshaw.Graph.Renderer.Line"),Rickshaw.Graph.Renderer.Line=Rickshaw.Class.create(Rickshaw.Graph.Renderer,{name:"line",defaults:function($super){return Rickshaw.extend($super(),{unstack:!0,fill:!1,stroke:!0})},seriesPathFactory:function(){var a=this.graph;return d3.svg.line().x(function(b){return a.x(b.x)}).y(function(b){return a.y(b.y)}).interpolate(this.graph.interpolation).tension(this.tension)}}),Rickshaw.namespace("Rickshaw.Graph.Renderer.Stack"),Rickshaw.Graph.Renderer.Stack=Rickshaw.Class.create(Rickshaw.Graph.Renderer,{name:"stack",defaults:function($super){return Rickshaw.extend($super(),{fill:!0,stroke:!1,unstack:!1})},seriesPathFactory:function(){var a=this.graph;return d3.svg.area().x(function(b){return a.x(b.x)}).y0(function(b){return a.y(b.y0)}).y1(function(b){return a.y(b.y+b.y0)}).interpolate(this.graph.interpolation).tension(this.tension)}}),Rickshaw.namespace("Rickshaw.Graph.Renderer.Bar"),Rickshaw.Graph.Renderer.Bar=Rickshaw.Class.create(Rickshaw.Graph.Renderer,{name:"bar",defaults:function($super){var a=Rickshaw.extend($super(),{gapSize:.05,unstack:!1});return delete a.tension,a},initialize:function($super,a){a=a||{},this.gapSize=a.gapSize||this.gapSize,$super(a)},domain:function($super){var a=$super(),b=this._frequentInterval();return a.x[1]+=parseInt(b.magnitude),a},barWidth:function(){var a=this.graph.stackedData||this.graph.stackData(),b=a.slice(-1).shift(),c=this._frequentInterval(),d=this.graph.x(b[0].x+c.magnitude*(1-this.gapSize));return d},render:function(){var a=this.graph;a.vis.selectAll("*").remove();var b=this.barWidth(),c=0,d=a.series.filter(function(a){return!a.disabled}).length,e=this.unstack?b/d:b;a.series.forEach(function(b){if(b.disabled)return;var d=a.vis.selectAll("path").data(b.stack).enter().append("svg:rect").attr("x",function(b){return a.x(b.x)+c}).attr("y",function(b){return a.y(b.y0+b.y)}).attr("width",e).attr("height",function(b){return a.y.magnitude(b.y)});Array.prototype.forEach.call(d[0],function(a){a.setAttribute("fill",b.color)}),this.unstack&&(c+=e)},this)},_frequentInterval:function(){var a=this.graph.stackedData||this.graph.stackData(),b=a.slice(-1).shift(),c={};for(var d=0;d<b.length-1;d++){var e=b[d+1].x-b[d].x;c[e]=c[e]||0,c[e]++}var f={count:0};return Rickshaw.keys(c).forEach(function(a){f.count<c[a]&&(f={count:c[a],magnitude:a})}),this._frequentInterval=function(){return f},f}}),Rickshaw.namespace("Rickshaw.Graph.Renderer.Area"),Rickshaw.Graph.Renderer.Area=Rickshaw.Class.create(Rickshaw.Graph.Renderer,{name:"area",defaults:function($super){return Rickshaw.extend($super(),{unstack:!1,fill:!1,stroke:!1})},seriesPathFactory:function(){var a=this.graph;return d3.svg.area().x(function(b){return a.x(b.x)}).y0(function(b){return a.y(b.y0)}).y1(function(b){return a.y(b.y+b.y0)}).interpolate(a.interpolation).tension(this.tension)},seriesStrokeFactory:function(){var a=this.graph;return d3.svg.line().x(function(b){return a.x(b.x)}).y(function(b){return a.y(b.y+b.y0)}).interpolate(a.interpolation).tension(this.tension)},render:function(){var a=this.graph;a.vis.selectAll("*").remove();var b=a.vis.selectAll("path").data(this.graph.stackedData).enter().insert("svg:g","g");b.append("svg:path").attr("d",this.seriesPathFactory()).attr("class","area"),this.stroke&&b.append("svg:path").attr("d",this.seriesStrokeFactory()).attr("class","line");var c=0;a.series.forEach(function(a){if(a.disabled)return;a.path=b[0][c++],this._styleSeries(a)},this)},_styleSeries:function(a){if(!a.path)return;d3.select(a.path).select(".area").attr("fill",a.color),this.stroke&&d3.select(a.path).select(".line").attr("fill","none").attr("stroke",a.stroke||d3.interpolateRgb(a.color,"black")(.125)).attr("stroke-width",this.strokeWidth),a.className&&a.path.setAttribute("class",a.className)}}),Rickshaw.namespace("Rickshaw.Graph.Renderer.ScatterPlot"),Rickshaw.Graph.Renderer.ScatterPlot=Rickshaw.Class.create(Rickshaw.Graph.Renderer,{name:"scatterplot",defaults:function($super){return Rickshaw.extend($super(),{unstack:!0,fill:!0,stroke:!1,padding
|
|
:{top:.01,right:.01,bottom:.01,left:.01},dotSize:4})},initialize:function($super,a){$super(a)},render:function(){var a=this.graph;a.vis.selectAll("*").remove(),a.series.forEach(function(b){if(b.disabled)return;var c=a.vis.selectAll("path").data(b.stack).enter().append("svg:circle").attr("cx",function(b){return a.x(b.x)}).attr("cy",function(b){return a.y(b.y)}).attr("r",function(b){return"r"in b?b.r:a.renderer.dotSize});Array.prototype.forEach.call(c[0],function(a){a.setAttribute("fill",b.color)})},this)}}),Rickshaw.namespace("Rickshaw.Graph.Smoother"),Rickshaw.Graph.Smoother=function(a){this.graph=a.graph,this.element=a.element;var b=this;this.aggregationScale=1,this.element&&$(function(){$(b.element).slider({min:1,max:100,slide:function(a,c){b.setScale(c.value),b.graph.update()}})}),b.graph.stackData.hooks.data.push({name:"smoother",orderPosition:50,f:function(a){var c=[];return a.forEach(function(a){var d=[];while(a.length){var e=0,f=0,g=a.splice(0,b.aggregationScale);g.forEach(function(a){e+=a.x/g.length,f+=a.y/g.length}),d.push({x:e,y:f})}c.push(d)}),c}}),this.setScale=function(a){if(a<1)throw"scale out of range: "+a;this.aggregationScale=a,this.graph.update()}},Rickshaw.namespace("Rickshaw.Graph.Unstacker"),Rickshaw.Graph.Unstacker=function(a){this.graph=a.graph;var b=this;this.graph.stackData.hooks.after.push({name:"unstacker",f:function(a){return b.graph.renderer.unstack?(a.forEach(function(a){a.forEach(function(a){a.y0=0})}),a):a}})},Rickshaw.namespace("Rickshaw.Series"),Rickshaw.Series=Rickshaw.Class.create(Array,{initialize:function(a,b,c){c=c||{},this.palette=new Rickshaw.Color.Palette(b),this.timeBase=typeof c.timeBase=="undefined"?Math.floor((new Date).getTime()/1e3):c.timeBase;var d=typeof c.timeInterval=="undefined"?1e3:c.timeInterval;this.setTimeInterval(d),a&&typeof a=="object"&&a instanceof Array&&a.forEach(function(a){this.addItem(a)},this)},addItem:function(a){if(typeof a.name=="undefined")throw"addItem() needs a name";a.color=a.color||this.palette.color(a.name),a.data=a.data||[],a.data.length==0&&this.length&&this.getIndex()>0?this[0].data.forEach(function(b){a.data.push({x:b.x,y:0})}):a.data.length==0&&a.data.push({x:this.timeBase-(this.timeInterval||0),y:0}),this.push(a),this.legend&&this.legend.addLine(this.itemByName(a.name))},addData:function(a){var b=this.getIndex();Rickshaw.keys(a).forEach(function(a){this.itemByName(a)||this.addItem({name:a})},this),this.forEach(function(c){c.data.push({x:(b*this.timeInterval||1)+this.timeBase,y:a[c.name]||0})},this)},getIndex:function(){return this[0]&&this[0].data&&this[0].data.length?this[0].data.length:0},itemByName:function(a){for(var b=0;b<this.length;b++)if(this[b].name==a)return this[b]},setTimeInterval:function(a){this.timeInterval=a/1e3},setTimeBase:function(a){this.timeBase=a},dump:function(){var a={timeBase:this.timeBase,timeInterval:this.timeInterval,items:[]};return this.forEach(function(b){var c={color:b.color,name:b.name,data:[]};b.data.forEach(function(a){c.data.push({x:a.x,y:a.y})}),a.items.push(c)}),a},load:function(a){a.timeInterval&&(this.timeInterval=a.timeInterval),a.timeBase&&(this.timeBase=a.timeBase),a.items&&a.items.forEach(function(a){this.push(a),this.legend&&this.legend.addLine(this.itemByName(a.name))},this)}}),Rickshaw.Series.zeroFill=function(a){var b,c=0,d=a.map(function(a){return a.data});while(c<Math.max.apply(null,d.map(function(a){return a.length})))b=Math.min.apply(null,d.filter(function(a){return a[c]}).map(function(a){return a[c].x})),d.forEach(function(a){(!a[c]||a[c].x!=b)&&a.splice(c,0,{x:b,y:0})}),c++},Rickshaw.namespace("Rickshaw.Series.FixedDuration"),Rickshaw.Series.FixedDuration=Rickshaw.Class.create(Rickshaw.Series,{initialize:function(a,b,c){var c=c||{};if(typeof c.timeInterval=="undefined")throw new Error("FixedDuration series requires timeInterval");if(typeof c.maxDataPoints=="undefined")throw new Error("FixedDuration series requires maxDataPoints");this.palette=new Rickshaw.Color.Palette(b),this.timeBase=typeof c.timeBase=="undefined"?Math.floor((new Date).getTime()/1e3):c.timeBase,this.setTimeInterval(c.timeInterval),this[0]&&this[0].data&&this[0].data.length?(this.currentSize=this[0].data.length,this.currentIndex=this[0].data.length):(this.currentSize=0,this.currentIndex=0),this.maxDataPoints=c.maxDataPoints,a&&typeof a=="object"&&a instanceof Array&&(a.forEach(function(a){this.addItem(a)},this),this.currentSize+=1,this.currentIndex+=1),this.timeBase-=(this.maxDataPoints-this.currentSize)*this.timeInterval;if(typeof this.maxDataPoints!="undefined"&&this.currentSize<this.maxDataPoints)for(var d=this.maxDataPoints-this.currentSize-1;d>0;d--)this.currentSize+=1,this.currentIndex+=1,this.forEach(function(a){a.data.unshift({x:((d-1)*this.timeInterval||1)+this.timeBase,y:0,i:d})},this)},addData:function($super,a){$super(a),this.currentSize+=1,this.currentIndex+=1;if(this.maxDataPoints!==undefined)while(this.currentSize>this.maxDataPoints)this.dropData()},dropData:function(){this.forEach(function(a){a.data.splice(0,1)}),this.currentSize-=1},getIndex:function(){return this.currentIndex}});
|
|
(function() {
|
|
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
|
__hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Dashing.Clock = (function(_super) {
|
|
|
|
__extends(Clock, _super);
|
|
|
|
function Clock() {
|
|
this.startTime = __bind(this.startTime, this);
|
|
return Clock.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
Clock.prototype.ready = function() {
|
|
return setInterval(this.startTime, 500);
|
|
};
|
|
|
|
Clock.prototype.startTime = function() {
|
|
var h, m, s, today;
|
|
today = new Date();
|
|
h = today.getHours();
|
|
m = today.getMinutes();
|
|
s = today.getSeconds();
|
|
m = this.formatTime(m);
|
|
s = this.formatTime(s);
|
|
this.set('time', h + ":" + m + ":" + s);
|
|
return this.set('date', today.toDateString());
|
|
};
|
|
|
|
Clock.prototype.formatTime = function(i) {
|
|
if (i < 10) {
|
|
return "0" + i;
|
|
} else {
|
|
return i;
|
|
}
|
|
};
|
|
|
|
return Clock;
|
|
|
|
})(Dashing.Widget);
|
|
|
|
}).call(this);
|
|
(function() {
|
|
var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
|
__hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Dashing.Comments = (function(_super) {
|
|
|
|
__extends(Comments, _super);
|
|
|
|
function Comments() {
|
|
this.nextComment = __bind(this.nextComment, this);
|
|
return Comments.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
Comments.accessor('quote', function() {
|
|
var _ref;
|
|
return "“" + ((_ref = this.get('current_comment')) != null ? _ref.body : void 0) + "â€";
|
|
});
|
|
|
|
Comments.prototype.ready = function() {
|
|
this.currentIndex = 0;
|
|
this.commentElem = $(this.node).find('.comment-container');
|
|
this.nextComment();
|
|
return this.startCarousel();
|
|
};
|
|
|
|
Comments.prototype.onData = function(data) {
|
|
return this.currentIndex = 0;
|
|
};
|
|
|
|
Comments.prototype.startCarousel = function() {
|
|
return setInterval(this.nextComment, 8000);
|
|
};
|
|
|
|
Comments.prototype.nextComment = function() {
|
|
var comments,
|
|
_this = this;
|
|
comments = this.get('comments');
|
|
if (comments) {
|
|
return this.commentElem.fadeOut(function() {
|
|
_this.currentIndex = (_this.currentIndex + 1) % comments.length;
|
|
_this.set('current_comment', comments[_this.currentIndex]);
|
|
return _this.commentElem.fadeIn();
|
|
});
|
|
}
|
|
};
|
|
|
|
return Comments;
|
|
|
|
})(Dashing.Widget);
|
|
|
|
}).call(this);
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Dashing.Graph = (function(_super) {
|
|
|
|
__extends(Graph, _super);
|
|
|
|
function Graph() {
|
|
return Graph.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
Graph.accessor('current', function() {
|
|
var points;
|
|
if (this.get('displayedValue')) {
|
|
return this.get('displayedValue');
|
|
}
|
|
points = this.get('points');
|
|
if (points) {
|
|
return points[points.length - 1].y;
|
|
}
|
|
});
|
|
|
|
Graph.prototype.ready = function() {
|
|
var container, height, width, x_axis, y_axis;
|
|
container = $(this.node).parent();
|
|
width = (Dashing.widget_base_dimensions[0] * container.data("sizex")) + Dashing.widget_margins[0] * 2 * (container.data("sizex") - 1);
|
|
height = Dashing.widget_base_dimensions[1] * container.data("sizey");
|
|
this.graph = new Rickshaw.Graph({
|
|
element: this.node,
|
|
width: width,
|
|
height: height,
|
|
series: [
|
|
{
|
|
color: "#fff",
|
|
data: [
|
|
{
|
|
x: 0,
|
|
y: 0
|
|
}
|
|
]
|
|
}
|
|
]
|
|
});
|
|
if (this.get('points')) {
|
|
this.graph.series[0].data = this.get('points');
|
|
}
|
|
x_axis = new Rickshaw.Graph.Axis.Time({
|
|
graph: this.graph
|
|
});
|
|
y_axis = new Rickshaw.Graph.Axis.Y({
|
|
graph: this.graph,
|
|
tickFormat: Rickshaw.Fixtures.Number.formatKMBT
|
|
});
|
|
return this.graph.render();
|
|
};
|
|
|
|
Graph.prototype.onData = function(data) {
|
|
if (this.graph) {
|
|
this.graph.series[0].data = data.points;
|
|
return this.graph.render();
|
|
}
|
|
};
|
|
|
|
return Graph;
|
|
|
|
})(Dashing.Widget);
|
|
|
|
}).call(this);
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Dashing.Iframe = (function(_super) {
|
|
|
|
__extends(Iframe, _super);
|
|
|
|
function Iframe() {
|
|
return Iframe.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
Iframe.prototype.ready = function() {};
|
|
|
|
Iframe.prototype.onData = function(data) {};
|
|
|
|
return Iframe;
|
|
|
|
})(Dashing.Widget);
|
|
|
|
}).call(this);
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Dashing.Image = (function(_super) {
|
|
|
|
__extends(Image, _super);
|
|
|
|
function Image() {
|
|
return Image.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
Image.prototype.ready = function() {};
|
|
|
|
Image.prototype.onData = function(data) {};
|
|
|
|
return Image;
|
|
|
|
})(Dashing.Widget);
|
|
|
|
}).call(this);
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Dashing.List = (function(_super) {
|
|
|
|
__extends(List, _super);
|
|
|
|
function List() {
|
|
return List.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
List.prototype.ready = function() {
|
|
if (this.get('unordered')) {
|
|
return $(this.node).find('ol').remove();
|
|
} else {
|
|
return $(this.node).find('ul').remove();
|
|
}
|
|
};
|
|
|
|
return List;
|
|
|
|
})(Dashing.Widget);
|
|
|
|
}).call(this);
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Dashing.Meter = (function(_super) {
|
|
|
|
__extends(Meter, _super);
|
|
|
|
Meter.accessor('value', Dashing.AnimatedValue);
|
|
|
|
function Meter() {
|
|
Meter.__super__.constructor.apply(this, arguments);
|
|
this.observe('value', function(value) {
|
|
return $(this.node).find(".meter").val(value).trigger('change');
|
|
});
|
|
}
|
|
|
|
Meter.prototype.ready = function() {
|
|
var meter;
|
|
meter = $(this.node).find(".meter");
|
|
meter.attr("data-bgcolor", meter.css("background-color"));
|
|
meter.attr("data-fgcolor", meter.css("color"));
|
|
return meter.knob();
|
|
};
|
|
|
|
return Meter;
|
|
|
|
})(Dashing.Widget);
|
|
|
|
}).call(this);
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Dashing.Number = (function(_super) {
|
|
|
|
__extends(Number, _super);
|
|
|
|
function Number() {
|
|
return Number.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
Number.accessor('current', Dashing.AnimatedValue);
|
|
|
|
Number.accessor('difference', function() {
|
|
var current, diff, last;
|
|
if (this.get('last')) {
|
|
last = parseInt(this.get('last'));
|
|
current = parseInt(this.get('current'));
|
|
if (last !== 0) {
|
|
diff = Math.abs(Math.round((current - last) / last * 100));
|
|
return "" + diff + "%";
|
|
}
|
|
} else {
|
|
return "";
|
|
}
|
|
});
|
|
|
|
Number.accessor('arrow', function() {
|
|
if (this.get('last')) {
|
|
if (parseInt(this.get('current')) > parseInt(this.get('last'))) {
|
|
return 'icon-arrow-up';
|
|
} else {
|
|
return 'icon-arrow-down';
|
|
}
|
|
}
|
|
});
|
|
|
|
Number.accessor('needsAttention', function() {
|
|
return this.get('status') === 'warning' || this.get('status') === 'danger';
|
|
});
|
|
|
|
Number.prototype.onData = function(data) {
|
|
if (data.status) {
|
|
return $(this.get('node')).addClass("status-" + data.status);
|
|
}
|
|
};
|
|
|
|
return Number;
|
|
|
|
})(Dashing.Widget);
|
|
|
|
}).call(this);
|
|
(function() {
|
|
var __hasProp = {}.hasOwnProperty,
|
|
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
|
|
|
|
Dashing.Text = (function(_super) {
|
|
|
|
__extends(Text, _super);
|
|
|
|
function Text() {
|
|
return Text.__super__.constructor.apply(this, arguments);
|
|
}
|
|
|
|
return Text;
|
|
|
|
})(Dashing.Widget);
|
|
|
|
}).call(this);
|
|
(function() {
|
|
|
|
console.log("Yeah! The dashboard has started!");
|
|
|
|
Dashing.on('ready', function() {
|
|
var contentWidth;
|
|
Dashing.widget_margins || (Dashing.widget_margins = [5, 5]);
|
|
Dashing.widget_base_dimensions || (Dashing.widget_base_dimensions = [300, 360]);
|
|
Dashing.numColumns || (Dashing.numColumns = 4);
|
|
contentWidth = (Dashing.widget_base_dimensions[0] + Dashing.widget_margins[0] * 2) * Dashing.numColumns;
|
|
return Batman.setImmediate(function() {
|
|
$('.gridster').width(contentWidth);
|
|
return $('.gridster ul:first').gridster({
|
|
widget_margins: Dashing.widget_margins,
|
|
widget_base_dimensions: Dashing.widget_base_dimensions,
|
|
avoid_overlapped_widgets: !Dashing.customGridsterLayout,
|
|
draggable: {
|
|
stop: Dashing.showGridsterInstructions
|
|
}
|
|
});
|
|
});
|
|
});
|
|
|
|
}).call(this);
|