From a9e676eb8af8f9881c152dacbea450610e8002fa Mon Sep 17 00:00:00 2001 From: Yves Fischer Date: Sat, 20 Dec 2014 03:24:02 +0100 Subject: upgrade to ember.js --- imdb-lookup/js/Makefile | 13 + imdb-lookup/js/all.min.js | 1327 + imdb-lookup/js/app.js | 60 + imdb-lookup/js/index.html | 0 imdb-lookup/js/libs/ember-1.9.0.js | 50331 ++++++++++++++++++++++ imdb-lookup/js/libs/ember-data-1.0.0-beta.12.js | 12945 ++++++ imdb-lookup/js/libs/handlebars-v2.0.0.js | 3079 ++ imdb-lookup/js/libs/jquery-1.11.2.js | 10346 +++++ 8 files changed, 78101 insertions(+) create mode 100644 imdb-lookup/js/Makefile create mode 100644 imdb-lookup/js/all.min.js create mode 100644 imdb-lookup/js/app.js create mode 100644 imdb-lookup/js/index.html create mode 100644 imdb-lookup/js/libs/ember-1.9.0.js create mode 100644 imdb-lookup/js/libs/ember-data-1.0.0-beta.12.js create mode 100644 imdb-lookup/js/libs/handlebars-v2.0.0.js create mode 100644 imdb-lookup/js/libs/jquery-1.11.2.js (limited to 'imdb-lookup/js') diff --git a/imdb-lookup/js/Makefile b/imdb-lookup/js/Makefile new file mode 100644 index 0000000..5189c3f --- /dev/null +++ b/imdb-lookup/js/Makefile @@ -0,0 +1,13 @@ +CLOSURE_FLAGS=\ + --compilation_level SIMPLE_OPTIMIZATIONS + +all: + java -jar ~/vcs/v86/closure-compiler/compiler.jar \ + $(CLOSURE_FLAGS) \ + libs/jquery-1.11.2.js \ + libs/handlebars-v2.0.0.js \ + libs/ember-1.9.0.js \ + libs/ember-data-1.0.0-beta.12.js \ + app.js \ + > all.min.js + diff --git a/imdb-lookup/js/all.min.js b/imdb-lookup/js/all.min.js new file mode 100644 index 0000000..182bef3 --- /dev/null +++ b/imdb-lookup/js/all.min.js @@ -0,0 +1,1327 @@ +var global$$inline_545="undefined"!==typeof window?window:this,factory$$inline_546=function(c,m){function n(E){var a=E.length,b=p.type(E);return"function"===b||p.isWindow(E)?!1:1===E.nodeType&&a?!0:"array"===b||0===a||"number"===typeof a&&0")).appendTo(a.documentElement),a=(Eb[0].contentWindow||Eb[0].contentDocument).document,a.write(),a.close(),b=A(E,a),Eb.detach()),Nc[E]=b);return b}function C(E,a){return{get:function(){var b=E();if(null!=b)if(b)delete this.get;else return(this.get=a).apply(this,arguments)}}} +function J(E,a){if(a in E)return a;for(var b=a.charAt(0).toUpperCase()+a.slice(1),d=a,e=Oc.length;e--;)if(a=Oc[e]+b,a in E)return a;return d}function I(E,a){for(var b,d,e,c=[],g=0,f=E.length;gb;b+=2)"margin"===d&&(g+=p.css(a,d+Ka[b],!0,c)),e?("content"===d&&(g-=p.css(a,"padding"+Ka[b],!0,c)),"margin"!==d&&(g-=p.css(a,"border"+Ka[b]+"Width",!0,c))):(g+=p.css(a,"padding"+Ka[b],!0,c),"padding"!==d&&(g+=p.css(a,"border"+Ka[b]+"Width",!0,c)));return g} +function U(a,b,d){var e=!0,c="width"===b?a.offsetWidth:a.offsetHeight,g=Za(a),f=H.boxSizing&&"border-box"===p.css(a,"boxSizing",!1,g);if(0>=c||null==c){c=$a(a,b,g);if(0>c||null==c)c=a.style[b];if(Ob.test(c))return c;e=f&&(H.boxSizingReliable()||c===a.style[b]);c=parseFloat(c)||0}return c+F(a,b,d||(f?"border":"content"),e,g)+"px"}function M(a,b,d,e,c){return new M.prototype.init(a,b,d,e,c)}function G(){setTimeout(function(){ob=void 0});return ob=p.now()}function L(a,b){var d,e={height:a},c=0;for(b= +b?1:0;4>c;c+=2-b)d=Ka[c],e["margin"+d]=e["padding"+d]=a;b&&(e.opacity=e.width=a);return e}function P(a,b,d){for(var e,c=(Fb[b]||[]).concat(Fb["*"]),p=0,g=c.length;pd&&p)return b;h.resolveWith(a, +[r]);return!1},r=h.promise({elem:a,props:p.extend({},b),opts:p.extend(!0,{specialEasing:{}},d),originalProperties:b,originalOptions:d,startTime:ob||G(),duration:d.duration,tweens:[],createTween:function(b,d){var e=p.Tween(a,r.opts,b,d,r.opts.specialEasing[b]||r.opts.easing);r.tweens.push(e);return e},stop:function(b){var d=0,e=b?r.tweens.length:0;if(c)return this;for(c=!0;da?this[a+this.length]:this[a]:ba.call(this)},pushStack:function(a){a=p.merge(this.constructor(),a);a.prevObject=this;a.context= +this.context;return a},each:function(a,b){return p.each(this,a,b)},map:function(a){return this.pushStack(p.map(this,function(b,d){return a.call(b,d,b)}))},slice:function(){return this.pushStack(ba.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(a){var b=this.length;a=+a+(0>a?b:0);return this.pushStack(0<=a&&ad?Math.max(0,e+d):d:0;dW.cacheLength&&delete a[b.shift()];return a[d+" "]=e}var b=[];return a},la=function(a){a[ea]=!0;return a},ta=function(a){var b= +ja.createElement("div");try{return!!a(b)}catch(d){return!1}finally{b.parentNode&&b.parentNode.removeChild(b)}},bb=function(a,b){for(var d=a.split("|"),e=a.length;e--;)W.attrHandle[d[e]]=b},sb=function(a,b){var d=b&&a,e=d&&1===a.nodeType&&1===b.nodeType&&(~b.sourceIndex||rb)-(~a.sourceIndex||rb);if(e)return e;if(d)for(;d=d.nextSibling;)if(d===b)return-1;return a?1:-1},Hb=function(a){return function(b){return"input"===b.nodeName.toLowerCase()&&b.type===a}},Ib=function(a){return function(b){var d=b.nodeName.toLowerCase(); +return("input"===d||"button"===d)&&b.type===a}},Ca=function(a){return la(function(b){b=+b;return la(function(d,e){for(var c,g=a([],d.length,b),p=g.length;p--;)d[c=g[p]]&&(d[c]=!(e[c]=d[c]))})})},ab=function(a){return a&&"undefined"!==typeof a.getElementsByTagName&&a},tb=function(){},Qa=function(a){for(var b=0,d=a.length,e="";b+~]|[\x20\t\r\n\f])[\x20\t\r\n\f]*/,sc=RegExp("=[\\x20\\t\\r\\n\\f]*([^\\]'\"]*?)[\\x20\\t\\r\\n\\f]*\\]","g"),tc=RegExp(Mb),uc=RegExp("^"+Rb+"$"),xb={ID:/^#((?:\\.|[\w-]|[^\x00-\xa0])+)/,CLASS:/^\.((?:\\.|[\w-]|[^\x00-\xa0])+)/,TAG:RegExp("^("+"(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+".replace("w","w*")+")"),ATTR:RegExp("^"+Sb),PSEUDO:RegExp("^"+Mb),CHILD:RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\([\\x20\\t\\r\\n\\f]*(even|odd|(([+-]|)(\\d*)n|)[\\x20\\t\\r\\n\\f]*(?:([+-]|)[\\x20\\t\\r\\n\\f]*(\\d+)|))[\\x20\\t\\r\\n\\f]*\\)|)", +"i"),bool:RegExp("^(?:checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped)$","i"),needsContext:RegExp("^[\\x20\\t\\r\\n\\f]*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\([\\x20\\t\\r\\n\\f]*((?:-\\d)?\\d*)[\\x20\\t\\r\\n\\f]*\\)|)(?=[^-]|$)","i")},vc=/^(?:input|select|textarea|button)$/i,wc=/^h\d$/i,jb=/^[^{]+\{\s*\[native \w/,nc=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,Gb=/[+~]/,oc=/'|\\/g,Fa=RegExp("\\\\([\\da-f]{1,6}[\\x20\\t\\r\\n\\f]?|([\\x20\\t\\r\\n\\f])|.)", +"ig"),Ga=function(a,b,d){a="0x"+b-65536;return a!==a||d?b:0>a?String.fromCharCode(a+65536):String.fromCharCode(a>>10|55296,a&1023|56320)},Tb=function(){Ba()};try{Ha.apply(Ea=Qb.call(oa.childNodes),oa.childNodes),Ea[oa.childNodes.length].nodeType}catch(Pc){Ha={apply:Ea.length?function(a,b){ma.apply(a,Qb.call(b))}:function(a,b){for(var d=a.length,e=0;a[d++]=b[e++];);a.length=d-1}}}da=R.support={};ub=R.isXML=function(a){return(a=a&&(a.ownerDocument||a).documentElement)?"HTML"!==a.nodeName:!1};Ba=R.setDocument= +function(a){var b=a?a.ownerDocument||a:oa;if(b===ja||9!==b.nodeType||!b.documentElement)return ja;ja=b;qa=b.documentElement;(a=b.defaultView)&&a!==a.top&&(a.addEventListener?a.addEventListener("unload",Tb,!1):a.attachEvent&&a.attachEvent("onunload",Tb));ra=!ub(b);da.attributes=ta(function(a){a.className="i";return!a.getAttribute("className")});da.getElementsByTagName=ta(function(a){a.appendChild(b.createComment(""));return!a.getElementsByTagName("*").length});da.getElementsByClassName=jb.test(b.getElementsByClassName); +da.getById=ta(function(a){qa.appendChild(a).id=ea;return!b.getElementsByName||!b.getElementsByName(ea).length});da.getById?(W.find.ID=function(a,b){if("undefined"!==typeof b.getElementById&&ra){var d=b.getElementById(a);return d&&d.parentNode?[d]:[]}},W.filter.ID=function(a){var b=a.replace(Fa,Ga);return function(a){return a.getAttribute("id")===b}}):(delete W.find.ID,W.filter.ID=function(a){var b=a.replace(Fa,Ga);return function(a){return(a="undefined"!==typeof a.getAttributeNode&&a.getAttributeNode("id"))&& +a.value===b}});W.find.TAG=da.getElementsByTagName?function(a,b){if("undefined"!==typeof b.getElementsByTagName)return b.getElementsByTagName(a);if(da.qsa)return b.querySelectorAll(a)}:function(a,b){var d,e=[],E=0,c=b.getElementsByTagName(a);if("*"===a){for(;d=c[E++];)1===d.nodeType&&e.push(d);return e}return c};W.find.CLASS=da.getElementsByClassName&&function(a,b){if(ra)return b.getElementsByClassName(a)};Da=[];ia=[];if(da.qsa=jb.test(b.querySelectorAll))ta(function(a){qa.appendChild(a).innerHTML= +"";a.querySelectorAll("[msallowcapture^='']").length&&ia.push("[*^$]=[\\x20\\t\\r\\n\\f]*(?:''|\"\")");a.querySelectorAll("[selected]").length||ia.push("\\[[\\x20\\t\\r\\n\\f]*(?:value|checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped)");a.querySelectorAll("[id~="+ea+"-]").length||ia.push("~=");a.querySelectorAll(":checked").length|| +ia.push(":checked");a.querySelectorAll("a#"+ea+"+*").length||ia.push(".#.+[+~]")}),ta(function(a){var d=b.createElement("input");d.setAttribute("type","hidden");a.appendChild(d).setAttribute("name","D");a.querySelectorAll("[name=d]").length&&ia.push("name[\\x20\\t\\r\\n\\f]*[*^$|!~]?=");a.querySelectorAll(":enabled").length||ia.push(":enabled",":disabled");a.querySelectorAll("*,:x");ia.push(",.*:")});(da.matchesSelector=jb.test(Ua=qa.matches||qa.webkitMatchesSelector||qa.mozMatchesSelector||qa.oMatchesSelector|| +qa.msMatchesSelector))&&ta(function(a){da.disconnectedMatch=Ua.call(a,"div");Ua.call(a,"[s!='']:x");Da.push("!=",Mb)});ia=ia.length&&RegExp(ia.join("|"));Da=Da.length&&RegExp(Da.join("|"));La=(a=jb.test(qa.compareDocumentPosition))||jb.test(qa.contains)?function(a,b){var d=9===a.nodeType?a.documentElement:a,e=b&&b.parentNode;return a===e||!!(e&&1===e.nodeType&&(d.contains?d.contains(e):a.compareDocumentPosition&&a.compareDocumentPosition(e)&16))}:function(a,b){if(b)for(;b=b.parentNode;)if(b===a)return!0; +return!1};ib=a?function(a,d){if(a===d)return Ja=!0,0;var e=!a.compareDocumentPosition-!d.compareDocumentPosition;if(e)return e;e=(a.ownerDocument||a)===(d.ownerDocument||d)?a.compareDocumentPosition(d):1;return e&1||!da.sortDetached&&d.compareDocumentPosition(a)===e?a===b||a.ownerDocument===oa&&La(oa,a)?-1:d===b||d.ownerDocument===oa&&La(oa,d)?1:va?Na(va,a)-Na(va,d):0:e&4?-1:1}:function(a,d){if(a===d)return Ja=!0,0;var e,E=0;e=a.parentNode;var c=d.parentNode,g=[a],p=[d];if(!e||!c)return a===b?-1: +d===b?1:e?-1:c?1:va?Na(va,a)-Na(va,d):0;if(e===c)return sb(a,d);for(e=a;e=e.parentNode;)g.unshift(e);for(e=d;e=e.parentNode;)p.unshift(e);for(;g[E]===p[E];)E++;return E?sb(g[E],p[E]):g[E]===oa?-1:p[E]===oa?1:0};return b};R.matches=function(a,b){return R(a,null,null,b)};R.matchesSelector=function(a,b){(a.ownerDocument||a)!==ja&&Ba(a);b=b.replace(sc,"='$1']");if(da.matchesSelector&&ra&&!(Da&&Da.test(b)||ia&&ia.test(b)))try{var d=Ua.call(a,b);if(d||da.disconnectedMatch||a.document&&11!==a.document.nodeType)return d}catch(e){}return 0< +R(b,ja,null,[a]).length};R.contains=function(a,b){(a.ownerDocument||a)!==ja&&Ba(a);return La(a,b)};R.attr=function(a,b){(a.ownerDocument||a)!==ja&&Ba(a);var d=W.attrHandle[b.toLowerCase()],d=d&&Kb.call(W.attrHandle,b.toLowerCase())?d(a,b,!ra):void 0;return void 0!==d?d:da.attributes||!ra?a.getAttribute(b):(d=a.getAttributeNode(b))&&d.specified?d.value:null};R.error=function(a){throw Error("Syntax error, unrecognized expression: "+a);};R.uniqueSort=function(a){var b,d=[],e=0,c=0;Ja=!da.detectDuplicates; +va=!da.sortStable&&a.slice(0);a.sort(ib);if(Ja){for(;b=a[c++];)b===a[c]&&(e=d.push(c));for(;e--;)a.splice(d[e],1)}va=null;return a};Ta=R.getText=function(a){var b,d="",e=0;b=a.nodeType;if(!b)for(;b=a[e++];)d+=Ta(b);else if(1===b||9===b||11===b){if("string"===typeof a.textContent)return a.textContent;for(a=a.firstChild;a;a=a.nextSibling)d+=Ta(a)}else if(3===b||4===b)return a.nodeValue;return d};W=R.selectors={cacheLength:50,createPseudo:la,match:xb,attrHandle:{},find:{},relative:{">":{dir:"parentNode", +first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(a){a[1]=a[1].replace(Fa,Ga);a[3]=(a[3]||a[4]||a[5]||"").replace(Fa,Ga);"~="===a[2]&&(a[3]=" "+a[3]+" ");return a.slice(0,4)},CHILD:function(a){a[1]=a[1].toLowerCase();"nth"===a[1].slice(0,3)?(a[3]||R.error(a[0]),a[4]=+(a[4]?a[5]+(a[6]||1):2*("even"===a[3]||"odd"===a[3])),a[5]=+(a[7]+a[8]||"odd"===a[3])):a[3]&&R.error(a[0]);return a},PSEUDO:function(a){var b,d=!a[6]&&a[2];if(xb.CHILD.test(a[0]))return null; +a[3]?a[2]=a[4]||a[5]||"":d&&tc.test(d)&&(b=Ma(d,!0))&&(b=d.indexOf(")",d.length-b)-d.length)&&(a[0]=a[0].slice(0,b),a[2]=d.slice(0,b));return a.slice(0,3)}},filter:{TAG:function(a){var b=a.replace(Fa,Ga).toLowerCase();return"*"===a?function(){return!0}:function(a){return a.nodeName&&a.nodeName.toLowerCase()===b}},CLASS:function(a){var b=vb[a+" "];return b||(b=RegExp("(^|[\\x20\\t\\r\\n\\f])"+a+"([\\x20\\t\\r\\n\\f]|$)"))&&vb(a,function(a){return b.test("string"===typeof a.className&&a.className|| +"undefined"!==typeof a.getAttribute&&a.getAttribute("class")||"")})},ATTR:function(a,b,d){return function(e){e=R.attr(e,a);if(null==e)return"!="===b;if(!b)return!0;e+="";return"="===b?e===d:"!="===b?e!==d:"^="===b?d&&0===e.indexOf(d):"*="===b?d&&-1a.nodeType)return!1;return!0},parent:function(a){return!W.pseudos.empty(a)},header:function(a){return wc.test(a.nodeName)},input:function(a){return vc.test(a.nodeName)},button:function(a){var b= +a.nodeName.toLowerCase();return"input"===b&&"button"===a.type||"button"===b},text:function(a){var b;return"input"===a.nodeName.toLowerCase()&&"text"===a.type&&(null==(b=a.getAttribute("type"))||"text"===b.toLowerCase())},first:Ca(function(){return[0]}),last:Ca(function(a,b){return[b-1]}),eq:Ca(function(a,b,d){return[0>d?d+b:d]}),even:Ca(function(a,b){for(var d=0;dd?d+b:d;0<=--b;)a.push(b); +return a}),gt:Ca(function(a,b,d){for(d=0>d?d+b:d;++d"; +a.firstChild.setAttribute("value","");return""===a.firstChild.getAttribute("value")})||bb("value",function(a,b,d){if(!d&&"input"===a.nodeName.toLowerCase())return a.defaultValue});ta(function(a){return null==a.getAttribute("disabled")})||bb("checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",function(a,b,d){var e;if(!d)return!0===a[b]?b.toLowerCase():(e=a.getAttributeNode(b))&&e.specified?e.value:null});p.find=R;p.expr=R.selectors; +p.expr[":"]=p.expr.pseudos;p.unique=R.uniqueSort;p.text=R.getText;p.isXMLDoc=R.isXML;p.contains=R.contains;var Ub=p.expr.match.needsContext,Vb=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,jc=/^.[^:#\[\.,]*$/;p.filter=function(a,b,d){var e=b[0];d&&(a=":not("+a+")");return 1===b.length&&1===e.nodeType?p.find.matchesSelector(e,a)?[e]:[]:p.find.matches(a,p.grep(b,function(a){return 1===a.nodeType}))};p.fn.extend({find:function(a){var b,d=[],e=this,c=e.length;if("string"!==typeof a)return this.pushStack(p(a).filter(function(){for(b= +0;b)[^>]*|#([\w-]*))$/;(p.fn.init=function(a,b){var d,e;if(!a)return this;if("string"=== +typeof a){d="<"===a.charAt(0)&&">"===a.charAt(a.length-1)&&3<=a.length?[null,a,null]:xc.exec(a);if(!d||!d[1]&&b)return!b||b.jquery?(b||kb).find(a):this.constructor(b).find(a);if(d[1]){if(b=b instanceof p?b[0]:b,p.merge(this,p.parseHTML(d[1],b&&b.nodeType?b.ownerDocument||b:Q,!0)),Vb.test(d[1])&&p.isPlainObject(b))for(d in b)if(p.isFunction(this[d]))this[d](b[d]);else this.attr(d,b[d])}else{if((e=Q.getElementById(d[2]))&&e.parentNode){if(e.id!==d[2])return kb.find(a);this.length=1;this[0]=e}this.context= +Q;this.selector=a}return this}if(a.nodeType)return this.context=this[0]=a,this.length=1,this;if(p.isFunction(a))return"undefined"!==typeof kb.ready?kb.ready(a):a(p);void 0!==a.selector&&(this.selector=a.selector,this.context=a.context);return p.makeArray(a,this)}).prototype=p.fn;kb=p(Q);var yc=/^(?:parents|prev(?:Until|All))/,zc={children:!0,contents:!0,next:!0,prev:!0};p.extend({dir:function(a,b,d){var e=[];for(a=a[b];a&&9!==a.nodeType&&(void 0===d||1!==a.nodeType||!p(a).is(d));)1===a.nodeType&& +e.push(a),a=a[b];return e},sibling:function(a,b){for(var d=[];a;a=a.nextSibling)1===a.nodeType&&a!==b&&d.push(a);return d}});p.fn.extend({has:function(a){var b,d=p(a,this),e=d.length;return this.filter(function(){for(b=0;bd.nodeType&&(f?-1
a";H.leadingWhitespace=3===na.firstChild.nodeType;H.tbody=!na.getElementsByTagName("tbody").length;H.htmlSerialize=!!na.getElementsByTagName("link").length; +H.html5Clone="<:nav>"!==Q.createElement("nav").cloneNode(!0).outerHTML;Pa.type="checkbox";Pa.checked=!0;Rc.appendChild(Pa);H.appendChecked=Pa.checked;na.innerHTML="";H.noCloneChecked=!!na.cloneNode(!0).lastChild.defaultValue;Rc.appendChild(na);na.innerHTML="";H.checkClone=na.cloneNode(!0).cloneNode(!0).lastChild.checked;H.noCloneEvent=!0;na.attachEvent&&(na.attachEvent("onclick",function(){H.noCloneEvent=!1}),na.cloneNode(!0).click()); +if(null==H.deleteExpando){H.deleteExpando=!0;try{delete na.test}catch(Td){H.deleteExpando=!1}}var Yb,Zb,Sc=Q.createElement("div");for(Yb in{submit:!0,change:!0,focusin:!0})Zb="on"+Yb,(H[Yb+"Bubbles"]=Zb in c)||(Sc.setAttribute(Zb,"t"),H[Yb+"Bubbles"]=!1===Sc.attributes[Zb].expando);var Bc=/^(?:input|select|textarea)$/i,rd=/^key/,sd=/^(?:mouse|pointer|contextmenu)|click/,Tc=/^(?:focusinfocus|focusoutblur)$/,Uc=/^([^.]*)(?:\.(.+)|)$/;p.event={global:{},add:function(a,b,d,e,c){var g,f,h,l,r,s,t,k,u; +if(h=p._data(a)){d.handler&&(l=d,d=l.handler,c=l.selector);d.guid||(d.guid=p.guid++);(f=h.events)||(f=h.events={});(r=h.handle)||(r=h.handle=function(a){return typeof p===ua||a&&p.event.triggered===a.type?void 0:p.event.dispatch.apply(r.elem,arguments)},r.elem=a);b=(b||"").match(xa)||[""];for(h=b.length;h--;)g=Uc.exec(b[h])||[],k=s=g[1],u=(g[2]||"").split(".").sort(),k&&(g=p.event.special[k]||{},k=(c?g.delegateType:g.bindType)||k,g=p.event.special[k]||{},s=p.extend({type:k,origType:s,data:e,handler:d, +guid:d.guid,selector:c,needsContext:c&&p.expr.match.needsContext.test(c),namespace:u.join(".")},l),(t=f[k])||(t=f[k]=[],t.delegateCount=0,g.setup&&!1!==g.setup.call(a,e,u,r)||(a.addEventListener?a.addEventListener(k,r,!1):a.attachEvent&&a.attachEvent("on"+k,r))),g.add&&(g.add.call(a,s),s.handler.guid||(s.handler.guid=d.guid)),c?t.splice(t.delegateCount++,0,s):t.push(s),p.event.global[k]=!0);a=null}},remove:function(a,b,d,e,c){var g,f,h,l,r,s,t,k,u,w,q,m=p.hasData(a)&&p._data(a);if(m&&(s=m.events)){b= +(b||"").match(xa)||[""];for(r=b.length;r--;)if(h=Uc.exec(b[r])||[],u=q=h[1],w=(h[2]||"").split(".").sort(),u){t=p.event.special[u]||{};u=(e?t.delegateType:t.bindType)||u;k=s[u]||[];h=h[2]&&RegExp("(^|\\.)"+w.join("\\.(?:.*\\.|)")+"(\\.|$)");for(l=g=k.length;g--;)f=k[g],!c&&q!==f.origType||d&&d.guid!==f.guid||h&&!h.test(f.namespace)||e&&!(e===f.selector||"**"===e&&f.selector)||(k.splice(g,1),f.selector&&k.delegateCount--,t.remove&&t.remove.call(a,f));l&&!k.length&&(t.teardown&&!1!==t.teardown.call(a, +w,m.handle)||p.removeEvent(a,u,m.handle),delete s[u])}else for(u in s)p.event.remove(a,u+b[r],d,e,!0);p.isEmptyObject(s)&&(delete m.handle,p._removeData(a,"events"))}},trigger:function(a,b,d,e){var g,f,h,l,r,s,t=[d||Q],k=$.call(a,"type")?a.type:a;r=$.call(a,"namespace")?a.namespace.split("."):[];h=g=d=d||Q;if(3!==d.nodeType&&8!==d.nodeType&&!Tc.test(k+p.event.triggered)&&(0<=k.indexOf(".")&&(r=k.split("."),k=r.shift(),r.sort()),f=0>k.indexOf(":")&&"on"+k,a=a[p.expando]?a:new p.Event(k,"object"=== +typeof a&&a),a.isTrigger=e?2:3,a.namespace=r.join("."),a.namespace_re=a.namespace?RegExp("(^|\\.)"+r.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,a.result=void 0,a.target||(a.target=d),b=null==b?[a]:p.makeArray(b,[a]),r=p.event.special[k]||{},e||!r.trigger||!1!==r.trigger.apply(d,b))){if(!e&&!r.noBubble&&!p.isWindow(d)){l=r.delegateType||k;Tc.test(l+k)||(h=h.parentNode);for(;h;h=h.parentNode)t.push(h),g=h;g===(d.ownerDocument||Q)&&t.push(g.defaultView||g.parentWindow||c)}for(s=0;(h=t[s++])&&!a.isPropagationStopped();)a.type= +1]","i"),Cc=/^\s+/,Wc=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi, +Xc=/<([\w:]+)/,Yc=/\s*$/g,wa={option:[1,""],legend:[1,"
","
"],area:[1,"",""],param:[1,"",""],thead:[1,"","
"],tr:[2,"","
"],col:[2,"","
"],td:[3, +"","
"],_default:H.htmlSerialize?[0,"",""]:[1,"X
","
"]},Dc=t(Q).appendChild(Q.createElement("div"));wa.optgroup=wa.option;wa.tbody=wa.tfoot=wa.colgroup=wa.caption=wa.thead;wa.th=wa.td;p.extend({clone:function(a,b,d){var e,c,g,f,h,l=p.contains(a.ownerDocument,a);H.html5Clone||p.isXMLDoc(a)||!Vc.test("<"+a.nodeName+">")?g=a.cloneNode(!0):(Dc.innerHTML=a.outerHTML,Dc.removeChild(g=Dc.firstChild));if(!(H.noCloneEvent&&H.noCloneChecked||1!==a.nodeType&&11!== +a.nodeType||p.isXMLDoc(a)))for(e=r(g),h=r(a),f=0;null!=(c=h[f]);++f)if(e[f]){var s=e[f],k=void 0,t=void 0,q=void 0;if(1===s.nodeType){k=s.nodeName.toLowerCase();if(!H.noCloneEvent&&s[p.expando]){q=p._data(s);for(t in q.events)p.removeEvent(s,t,q.handle);s.removeAttribute(p.expando)}if("script"===k&&s.text!==c.text)u(s).text=c.text,w(s);else if("object"===k)s.parentNode&&(s.outerHTML=c.outerHTML),H.html5Clone&&c.innerHTML&&!p.trim(s.innerHTML)&&(s.innerHTML=c.innerHTML);else if("input"===k&&Db.test(c.type))s.defaultChecked= +s.checked=c.checked,s.value!==c.value&&(s.value=c.value);else if("option"===k)s.defaultSelected=s.selected=c.defaultSelected;else if("input"===k||"textarea"===k)s.defaultValue=c.defaultValue}}if(b)if(d)for(h=h||r(a),e=e||r(g),f=0;null!=(c=h[f]);f++)z(c,e[f]);else z(a,g);e=r(g,"script");0")+s[2];for(c=s[0];c--;)f=f.lastChild;!H.leadingWhitespace&&Cc.test(g)&&w.push(b.createTextNode(Cc.exec(g)[0]));if(!H.tbody)for(c=(g="table"!==h||Yc.test(g)?""!==s[1]||Yc.test(g)?0:f:f.firstChild)&&g.childNodes.length;c--;)p.nodeName(l=g.childNodes[c],"tbody")&&!l.childNodes.length&&g.removeChild(l);p.merge(w,f.childNodes);for(f.textContent="";f.firstChild;)f.removeChild(f.firstChild); +f=u.lastChild}else w.push(b.createTextNode(g));f&&u.removeChild(f);H.appendChecked||p.grep(r(w,"input"),v);for(q=0;g=w[q++];)if(!e||-1===p.inArray(g,e))if(a=p.contains(g.ownerDocument,g),f=r(u.appendChild(g),"script"),a&&x(f),d)for(c=0;g=f[c++];)Zc.test(g.type||"")&&d.push(g);return u},cleanData:function(a,b){for(var d,e,c,g,f=0,h=p.expando,l=p.cache,r=H.deleteExpando,s=p.event.special;null!=(d=a[f]);f++)if(b||p.acceptData(d))if(g=(c=d[h])&&l[c]){if(g.events)for(e in g.events)s[e]?p.event.remove(d, +e):p.removeEvent(d,e,g.handle);l[c]&&(delete l[c],r?delete d[h]:typeof d.removeAttribute!==ua?d.removeAttribute(h):d[h]=null,aa.push(c))}}});p.fn.extend({text:function(a){return Oa(this,function(a){return void 0===a?p.text(this):this.empty().append((this[0]&&this[0].ownerDocument||Q).createTextNode(a))},null,a,arguments.length)},append:function(){return this.domManip(arguments,function(a){1!==this.nodeType&&11!==this.nodeType&&9!==this.nodeType||y(this,a).appendChild(a)})},prepend:function(){return this.domManip(arguments, +function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=y(this,a);b.insertBefore(a,b.firstChild)}})},before:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this)})},after:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this.nextSibling)})},remove:function(a,b){for(var d,e=a?p.filter(a,this):this,c=0;null!=(d=e[c]);c++)b||1!==d.nodeType||p.cleanData(r(d)),d.parentNode&& +(b&&p.contains(d.ownerDocument,d)&&x(r(d,"script")),d.parentNode.removeChild(d));return this},empty:function(){for(var a,b=0;null!=(a=this[b]);b++){for(1===a.nodeType&&p.cleanData(r(a,!1));a.firstChild;)a.removeChild(a.firstChild);a.options&&p.nodeName(a,"select")&&(a.options.length=0)}return this},clone:function(a,b){a=null==a?!1:a;b=null==b?a:b;return this.map(function(){return p.clone(this,a,b)})},html:function(a){return Oa(this,function(a){var b=this[0]||{},d=0,e=this.length;if(void 0===a)return 1=== +b.nodeType?b.innerHTML.replace(td,""):void 0;if("string"===typeof a&&!(vd.test(a)||!H.htmlSerialize&&Vc.test(a)||!H.leadingWhitespace&&Cc.test(a)||wa[(Xc.exec(a)||["",""])[1].toLowerCase()])){a=a.replace(Wc,"<$1>");try{for(;d
t
";e=a.getElementsByTagName("td");e[0].style.cssText= +"margin:0;border:0;padding:0;display:none";if(cc=0===e[0].offsetHeight)e[0].style.display="",e[1].style.display="none",cc=0===e[0].offsetHeight;b.removeChild(d)}},Ab,lb,ad,$b,ac,cc,bc;Ab=Q.createElement("div");Ab.innerHTML="
a";if(lb=(ad=Ab.getElementsByTagName("a")[0])&&ad.style)lb.cssText="float:left;opacity:.5",H.opacity="0.5"===lb.opacity,H.cssFloat=!!lb.cssFloat,Ab.style.backgroundClip="content-box",Ab.cloneNode(!0).style.backgroundClip= +"",H.clearCloneStyle="content-box"===Ab.style.backgroundClip,H.boxSizing=""===lb.boxSizing||""===lb.MozBoxSizing||""===lb.WebkitBoxSizing,p.extend(H,{reliableHiddenOffsets:function(){null==cc&&dc();return cc},boxSizingReliable:function(){null==ac&&dc();return ac},pixelPosition:function(){null==$b&&dc();return $b},reliableMarginRight:function(){null==bc&&dc();return bc}});p.swap=function(a,b,d,e){var c,g={};for(c in b)g[c]=a.style[c],a.style[c]=b[c];d=d.apply(a,e||[]);for(c in b)a.style[c]=g[c];return d}; +var Ec=/alpha\([^)]*\)/i,zd=/opacity\s*=\s*([^)]*)/,Ad=/^(none|table(?!-c[ea]).+)/,od=RegExp("^("+zb+")(.*)$","i"),Bd=RegExp("^([+-])=("+zb+")","i"),Cd={position:"absolute",visibility:"hidden",display:"block"},bd={letterSpacing:"0",fontWeight:"400"},Oc=["Webkit","O","Moz","ms"];p.extend({cssHooks:{opacity:{get:function(a,b){if(b){var d=$a(a,"opacity");return""===d?"1":d}}}},cssNumber:{columnCount:!0,fillOpacity:!0,flexGrow:!0,flexShrink:!0,fontWeight:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0, +widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":H.cssFloat?"cssFloat":"styleFloat"},style:function(a,b,d,e){if(a&&3!==a.nodeType&&8!==a.nodeType&&a.style){var c,g,f,h=p.camelCase(b),l=a.style;b=p.cssProps[h]||(p.cssProps[h]=J(l,h));f=p.cssHooks[b]||p.cssHooks[h];if(void 0!==d){if(g=typeof d,"string"===g&&(c=Bd.exec(d))&&(d=(c[1]+1)*c[2]+parseFloat(p.css(a,b)),g="number"),null!=d&&d===d&&("number"!==g||p.cssNumber[h]||(d+="px"),H.clearCloneStyle||""!==d||0!==b.indexOf("background")||(l[b]="inherit"), +!(f&&"set"in f&&void 0===(d=f.set(a,d,e)))))try{l[b]=d}catch(r){}}else return f&&"get"in f&&void 0!==(c=f.get(a,!1,e))?c:l[b]}},css:function(a,b,d,e){var c,g;g=p.camelCase(b);b=p.cssProps[g]||(p.cssProps[g]=J(a.style,g));(g=p.cssHooks[b]||p.cssHooks[g])&&"get"in g&&(c=g.get(a,!0,d));void 0===c&&(c=$a(a,b,e));"normal"===c&&b in bd&&(c=bd[b]);return""===d||d?(a=parseFloat(c),!0===d||p.isNumeric(a)?a||0:c):c}});p.each(["height","width"],function(a,b){p.cssHooks[b]={get:function(a,d,e){if(d)return Ad.test(p.css(a, +"display"))&&0===a.offsetWidth?p.swap(a,Cd,function(){return U(a,b,e)}):U(a,b,e)},set:function(a,d,e){var c=e&&Za(a);return K(a,d,e?F(a,b,e,H.boxSizing&&"border-box"===p.css(a,"boxSizing",!1,c),c):0)}}});H.opacity||(p.cssHooks.opacity={get:function(a,b){return zd.test((b&&a.currentStyle?a.currentStyle.filter:a.style.filter)||"")?0.01*parseFloat(RegExp.$1)+"":b?"1":""},set:function(a,b){var d=a.style,e=a.currentStyle,c=p.isNumeric(b)?"alpha(opacity="+100*b+")":"",g=e&&e.filter||d.filter||"";d.zoom= +1;if((1<=b||""===b)&&""===p.trim(g.replace(Ec,""))&&d.removeAttribute&&(d.removeAttribute("filter"),""===b||e&&!e.filter))return;d.filter=Ec.test(g)?g.replace(Ec,c):g+" "+c}});p.cssHooks.marginRight=C(H.reliableMarginRight,function(a,b){if(b)return p.swap(a,{display:"inline-block"},$a,[a,"marginRight"])});p.each({margin:"",padding:"",border:"Width"},function(a,b){p.cssHooks[a+b]={expand:function(d){var e=0,c={};for(d="string"===typeof d?d.split(" "):[d];4>e;e++)c[a+Ka[e]+b]=d[e]||d[e-2]||d[0];return c}}; +$c.test(a)||(p.cssHooks[a+b].set=K)});p.fn.extend({css:function(a,b){return Oa(this,function(a,b,d){var e,c={},g=0;if(p.isArray(b)){d=Za(a);for(e=b.length;g
a";fc=Bb.getElementsByTagName("a")[0];Fc=Q.createElement("select"); +Gc=Fc.appendChild(Q.createElement("option"));Va=Bb.getElementsByTagName("input")[0];fc.style.cssText="top:1px";H.getSetAttribute="t"!==Bb.className;H.style=/top/.test(fc.getAttribute("style"));H.hrefNormalized="/a"===fc.getAttribute("href");H.checkOn=!!Va.value;H.optSelected=Gc.selected;H.enctype=!!Q.createElement("form").enctype;Fc.disabled=!0;H.optDisabled=!Gc.disabled;Va=Q.createElement("input");Va.setAttribute("value","");H.input=""===Va.getAttribute("value");Va.value="t";Va.setAttribute("type", +"radio");H.radioValue="t"===Va.value;var Fd=/\r/g;p.fn.extend({val:function(a){var b,d,e,c=this[0];if(arguments.length)return e=p.isFunction(a),this.each(function(d){1===this.nodeType&&(d=e?a.call(this,d,p(this).val()):a,null==d?d="":"number"===typeof d?d+="":p.isArray(d)&&(d=p.map(d,function(a){return null==a?"":a+""})),b=p.valHooks[this.type]||p.valHooks[this.nodeName.toLowerCase()],b&&"set"in b&&void 0!==b.set(this,d,"value")||(this.value=d))});if(c){if((b=p.valHooks[c.type]||p.valHooks[c.nodeName.toLowerCase()])&& +"get"in b&&void 0!==(d=b.get(c,"value")))return d;d=c.value;return"string"===typeof d?d.replace(Fd,""):null==d?"":d}}});p.extend({valHooks:{option:{get:function(a){var b=p.find.attr(a,"value");return null!=b?b:p.trim(p.text(a))}},select:{get:function(a){for(var b,d=a.options,e=a.selectedIndex,c=(a="select-one"===a.type||0>e)?null:[],g=a?e+1:d.length,f=0>e?g:a?e:0;fe.indexOf(" "+c+" ")&&(e+=c+" ");e=p.trim(e);d.className!==e&&(d.className=e)}return this},removeClass:function(a){var b, +d,e,c,g,f=0,h=this.length;b=0===arguments.length||"string"===typeof a&&a;if(p.isFunction(a))return this.each(function(b){p(this).removeClass(a.call(this,b,this.className))});if(b)for(b=(a||"").match(xa)||[];fa||304===a;if(e){v=k;for(var z=x,A,H,$,B,C=v.contents,J=v.dataTypes;"*"===J[0];)J.shift(),void 0===H&&(H=v.mimeType||z.getResponseHeader("Content-Type"));if(H)for(B in C)if(C[B]&&C[B].test(H)){J.unshift(B);break}if(J[0]in e)$=J[0];else{for(B in e){if(!J[0]||v.converters[B+" "+J[0]]){$=B;break}A||(A=B)}$=$||A}$?($!==J[0]&&J.unshift($),v=e[$]):v=void 0}a:{e=k;A=v;H=x;$=c;var F, +O,K,z={},C=e.dataTypes.slice();if(C[1])for(O in e.converters)z[O.toLowerCase()]=e.converters[O];for(B=C.shift();B;)if(e.responseFields[B]&&(H[e.responseFields[B]]=A),!K&&$&&e.dataFilter&&(A=e.dataFilter(A,e.dataType)),K=B,B=C.shift())if("*"===B)B=K;else if("*"!==K&&K!==B){O=z[K+" "+B]||z["* "+B];if(!O)for(F in z)if(v=F.split(" "),v[1]===B&&(O=z[K+" "+v[0]]||z["* "+v[0]])){!0===O?O=z[F]:!0!==z[F]&&(B=v[0],C.unshift(v[1]));break}if(!0!==O)if(O&&e["throws"])A=O(A);else try{A=O(A)}catch(I){v={state:"parsererror", +error:O?I:"No conversion from "+K+" to "+B};break a}}v={state:"success",data:A}}if(c)k.ifModified&&((V=x.getResponseHeader("Last-Modified"))&&(p.lastModified[g]=V),(V=x.getResponseHeader("etag"))&&(p.etag[g]=V)),204===a||"HEAD"===k.type?V="nocontent":304===a?V="notmodified":(V=v.state,s=v.data,n=v.error,c=!n);else if(n=V,a||!V)V="error",0>a&&(a=0);x.status=a;x.statusText=(b||V)+"";c?w.resolveWith(t,[s,V,x]):w.rejectWith(t,[x,V,n]);x.statusCode(m);m=void 0;l&&u.trigger(c?"ajaxSuccess":"ajaxError", +[x,k,c?s:n]);q.fireWith(t,[x,V]);l&&(u.trigger("ajaxComplete",[x,k]),--p.active||p.event.trigger("ajaxStop"))}}"object"===typeof a&&(b=a,a=void 0);b=b||{};var e,c,g,f,h,l,r,s,k=p.ajaxSetup({},b),t=k.context||k,u=k.context&&(t.nodeType||t.jquery)?p(t):p.event,w=p.Deferred(),q=p.Callbacks("once memory"),m=k.statusCode||{},n={},v={},y=0,V="canceled",x={readyState:0,getResponseHeader:function(a){var b;if(2===y){if(!s)for(s={};b=Kd.exec(f);)s[b[1].toLowerCase()]=b[2];b=s[a.toLowerCase()]}return null== +b?null:b},getAllResponseHeaders:function(){return 2===y?f:null},setRequestHeader:function(a,b){var d=a.toLowerCase();y||(a=v[d]=v[d]||a,n[a]=b);return this},overrideMimeType:function(a){y||(k.mimeType=a);return this},statusCode:function(a){var b;if(a)if(2>y)for(b in a)m[b]=[m[b],a[b]];else x.always(a[x.status]);return this},abort:function(a){a=a||V;r&&r.abort(a);d(0,a);return this}};w.promise(x).complete=q.add;x.success=x.done;x.error=x.fail;k.url=((a||k.url||Xa)+"").replace(Jd,"").replace(Md,nb[1]+ +"//");k.type=b.method||b.type||k.method||k.type;k.dataTypes=p.trim(k.dataType||"*").toLowerCase().match(xa)||[""];null==k.crossDomain&&(e=fd.exec(k.url.toLowerCase()),k.crossDomain=!(!e||e[1]===nb[1]&&e[2]===nb[2]&&(e[3]||("http:"===e[1]?"80":"443"))===(nb[3]||("http:"===nb[1]?"80":"443"))));k.data&&k.processData&&"string"!==typeof k.data&&(k.data=p.param(k.data,k.traditional));T(gd,k,b,x);if(2===y)return x;(l=p.event&&k.global)&&0===p.active++&&p.event.trigger("ajaxStart");k.type=k.type.toUpperCase(); +k.hasContent=!Ld.test(k.type);g=k.url;k.hasContent||(k.data&&(g=k.url+=(Kc.test(g)?"&":"?")+k.data,delete k.data),!1===k.cache&&(k.url=ed.test(g)?g.replace(ed,"$1_="+Jc++):g+(Kc.test(g)?"&":"?")+"_="+Jc++));k.ifModified&&(p.lastModified[g]&&x.setRequestHeader("If-Modified-Since",p.lastModified[g]),p.etag[g]&&x.setRequestHeader("If-None-Match",p.etag[g]));(k.data&&k.hasContent&&!1!==k.contentType||b.contentType)&&x.setRequestHeader("Content-Type",k.contentType);x.setRequestHeader("Accept",k.dataTypes[0]&& +k.accepts[k.dataTypes[0]]?k.accepts[k.dataTypes[0]]+("*"!==k.dataTypes[0]?", "+hd+"; q=0.01":""):k.accepts["*"]);for(c in k.headers)x.setRequestHeader(c,k.headers[c]);if(k.beforeSend&&(!1===k.beforeSend.call(t,x,k)||2===y))return x.abort();V="abort";for(c in{success:1,error:1,complete:1})x[c](k[c]);if(r=T(mc,k,b,x)){x.readyState=1;l&&u.trigger("ajaxSend",[x,k]);k.async&&0y)d(-1,z);else throw z;}}else d(-1, +"No Transport");return x},getJSON:function(a,b,d){return p.get(a,b,d,"json")},getScript:function(a,b){return p.get(a,void 0,b,"script")}});p.each(["get","post"],function(a,b){p[b]=function(a,d,e,c){p.isFunction(d)&&(c=c||e,e=d,d=void 0);return p.ajax({url:a,type:b,dataType:c,data:d,success:e})}});p._evalUrl=function(a){return p.ajax({url:a,type:"GET",dataType:"script",async:!1,global:!1,"throws":!0})};p.fn.extend({wrapAll:function(a){if(p.isFunction(a))return this.each(function(b){p(this).wrapAll(a.call(this, +b))});if(this[0]){var b=p(a,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&b.insertBefore(this[0]);b.map(function(){for(var a=this;a.firstChild&&1===a.firstChild.nodeType;)a=a.firstChild;return a}).append(this)}return this},wrapInner:function(a){return p.isFunction(a)?this.each(function(b){p(this).wrapInner(a.call(this,b))}):this.each(function(){var b=p(this),d=b.contents();d.length?d.wrapAll(a):b.append(a)})},wrap:function(a){var b=p.isFunction(a);return this.each(function(d){p(this).wrapAll(b? +a.call(this,d):a)})},unwrap:function(){return this.parent().each(function(){p.nodeName(this,"body")||p(this).replaceWith(this.childNodes)}).end()}});p.expr.filters.hidden=function(a){return 0>=a.offsetWidth&&0>=a.offsetHeight||!H.reliableHiddenOffsets()&&"none"===(a.style&&a.style.display||p.css(a,"display"))};p.expr.filters.visible=function(a){return!p.expr.filters.hidden(a)};var Nd=/%20/g,qd=/\[\]$/,id=/\r?\n/g,Od=/^(?:submit|button|image|reset|file)$/i,Pd=/^(?:input|select|textarea|keygen)/i;p.param= +function(a,b){var d,e=[],c=function(a,b){b=p.isFunction(b)?b():null==b?"":b;e[e.length]=encodeURIComponent(a)+"="+encodeURIComponent(b)};void 0===b&&(b=p.ajaxSettings&&p.ajaxSettings.traditional);if(p.isArray(a)||a.jquery&&!p.isPlainObject(a))p.each(a,function(){c(this.name,this.value)});else for(d in a)X(d,a[d],b,c);return e.join("&").replace(Nd,"+")};p.fn.extend({serialize:function(){return p.param(this.serializeArray())},serializeArray:function(){return this.map(function(){var a=p.prop(this,"elements"); +return a?p.makeArray(a):this}).filter(function(){var a=this.type;return this.name&&!p(this).is(":disabled")&&Pd.test(this.nodeName)&&!Od.test(a)&&(this.checked||!Db.test(a))}).map(function(a,b){var d=p(this).val();return null==d?null:p.isArray(d)?p.map(d,function(a){return{name:b.name,value:a.replace(id,"\r\n")}}):{name:b.name,value:d.replace(id,"\r\n")}}).get()}});p.ajaxSettings.xhr=void 0!==c.ActiveXObject?function(){var a;if(!(a=!this.isLocal&&/^(get|post|head|put|delete|options)$/i.test(this.type)&& +Y()))a:{try{a=new c.ActiveXObject("Microsoft.XMLHTTP");break a}catch(b){}a=void 0}return a}:Y;var Qd=0,hc={},ic=p.ajaxSettings.xhr();c.attachEvent&&c.attachEvent("onunload",function(){for(var a in hc)hc[a](void 0,!0)});H.cors=!!ic&&"withCredentials"in ic;(ic=H.ajax=!!ic)&&p.ajaxTransport(function(a){if(!a.crossDomain||H.cors){var b;return{send:function(d,e){var c,g=a.xhr(),f=++Qd;g.open(a.type,a.url,a.async,a.username,a.password);if(a.xhrFields)for(c in a.xhrFields)g[c]=a.xhrFields[c];a.mimeType&& +g.overrideMimeType&&g.overrideMimeType(a.mimeType);a.crossDomain||d["X-Requested-With"]||(d["X-Requested-With"]="XMLHttpRequest");for(c in d)void 0!==d[c]&&g.setRequestHeader(c,d[c]+"");g.send(a.hasContent&&a.data||null);b=function(d,c){var h,l,r;if(b&&(c||4===g.readyState))if(delete hc[f],b=void 0,g.onreadystatechange=p.noop,c)4!==g.readyState&&g.abort();else{r={};h=g.status;"string"===typeof g.responseText&&(r.text=g.responseText);try{l=g.statusText}catch(k){l=""}h||!a.isLocal||a.crossDomain?1223=== +h&&(h=204):h=r.text?200:404}r&&e(h,l,r,g.getAllResponseHeaders())};a.async?4===g.readyState?setTimeout(b):g.onreadystatechange=hc[f]=b:b()},abort:function(){b&&b(void 0,!0)}}}});p.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/(?:java|ecma)script/},converters:{"text script":function(a){p.globalEval(a);return a}}});p.ajaxPrefilter("script",function(a){void 0===a.cache&&(a.cache=!1);a.crossDomain&&(a.type="GET", +a.global=!1)});p.ajaxTransport("script",function(a){if(a.crossDomain){var b,d=Q.head||p("head")[0]||Q.documentElement;return{send:function(e,c){b=Q.createElement("script");b.async=!0;a.scriptCharset&&(b.charset=a.scriptCharset);b.src=a.url;b.onload=b.onreadystatechange=function(a,d){if(d||!b.readyState||/loaded|complete/.test(b.readyState))b.onload=b.onreadystatechange=null,b.parentNode&&b.parentNode.removeChild(b),b=null,d||c(200,"success")};d.insertBefore(b,d.firstChild)},abort:function(){if(b)b.onload(void 0, +!0)}}}});var jd=[],Lc=/(=)\?(?=&|$)|\?\?/;p.ajaxSetup({jsonp:"callback",jsonpCallback:function(){var a=jd.pop()||p.expando+"_"+Jc++;this[a]=!0;return a}});p.ajaxPrefilter("json jsonp",function(a,b,d){var e,g,f,h=!1!==a.jsonp&&(Lc.test(a.url)?"url":"string"===typeof a.data&&!(a.contentType||"").indexOf("application/x-www-form-urlencoded")&&Lc.test(a.data)&&"data");if(h||"jsonp"===a.dataTypes[0])return e=a.jsonpCallback=p.isFunction(a.jsonpCallback)?a.jsonpCallback():a.jsonpCallback,h?a[h]=a[h].replace(Lc, +"$1"+e):!1!==a.jsonp&&(a.url+=(Kc.test(a.url)?"&":"?")+a.jsonp+"="+e),a.converters["script json"]=function(){f||p.error(e+" was not called");return f[0]},a.dataTypes[0]="json",g=c[e],c[e]=function(){f=arguments},d.always(function(){c[e]=g;a[e]&&(a.jsonpCallback=b.jsonpCallback,jd.push(e));f&&p.isFunction(g)&&g(f[0]);f=g=void 0}),"script"});p.parseHTML=function(a,b,d){if(!a||"string"!==typeof a)return null;"boolean"===typeof b&&(d=b,b=!1);b=b||Q;var e=Vb.exec(a);d=!d&&[];if(e)return[b.createElement(e[1])]; +e=p.buildFragment([a],b,d);d&&d.length&&p(d).remove();return p.merge([],e.childNodes)};var kd=p.fn.load;p.fn.load=function(a,b,d){if("string"!==typeof a&&kd)return kd.apply(this,arguments);var e,c,g,f=this,h=a.indexOf(" ");0<=h&&(e=p.trim(a.slice(h,a.length)),a=a.slice(0,h));p.isFunction(b)?(d=b,b=void 0):b&&"object"===typeof b&&(g="POST");0").append(p.parseHTML(a)).find(e):a)}).complete(d&&function(a, +b){f.each(d,c||[a.responseText,b,a])});return this};p.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),function(a,b){p.fn[b]=function(a){return this.on(b,a)}});p.expr.filters.animated=function(a){return p.grep(p.timers,function(b){return a===b.elem}).length};var ld=c.document.documentElement;p.offset={setOffset:function(a,b,d){var e,c,g,f=p.css(a,"position"),h=p(a),l={};"static"===f&&(a.style.position="relative");g=h.offset();c=p.css(a,"top");e=p.css(a,"left");("absolute"=== +f||"fixed"===f)&&-1":">",'"':""","'":"'","`":"`"},q=/[&<>"'`]/g,l=/[&<>"'`]/;n.extend=function(a){for(var b=1;b= 2.0.0-beta.1"};var t=e.isArray,r=e.isFunction,v=e.toString;g.HandlebarsEnvironment=f;f.prototype={constructor:f,logger:y,log:u,registerHelper:function(a,b){if("[object Object]"===v.call(a)){if(b)throw new s("Arg not supported with multiple helpers");e.extend(this.helpers,a)}else this.helpers[a]=b},unregisterHelper:function(a){delete this.helpers[a]}, +registerPartial:function(a,b){"[object Object]"===v.call(a)?e.extend(this.partials,a):this.partials[a]=b},unregisterPartial:function(a){delete this.partials[a]}};var y={methodMap:{0:"debug",1:"info",2:"warn",3:"error"},DEBUG:0,INFO:1,WARN:2,ERROR:3,level:3,log:function(a,b){if(y.level<=a){var d=y.methodMap[a];"undefined"!==typeof console&&console[d]&&console[d].call(console,b)}}};g.logger=y;var u=y.log;g.log=u;var w=function(a){var b=e.extend({},a);b._parent=a;return b};g.createFrame=w;var x=function(a, +b,d,e,c){var g=function(b,g){g=g||{};return d.call(a,b,a.helpers,a.partials,g.data||e,c&&[b].concat(c))};g.program=b;g.depth=c?c.length:0;return g},z={},A=g.COMPILER_REVISION,B=g.REVISION_CHANGES,C=g.createFrame;z.checkRevision=function(b){var d=b&&b[0]||1;if(d!==A){if(da.length&&(a+=this._input.substr(0,20-a.length));return(a.substr(0,20)+(20a[0].length)||(a=b,d=c,this.options.flex));c++);if(a){if(b=a[0].match(/(?:\r\n?|\n).*/g))this.yylineno+=b.length;this.yylloc={first_line:this.yylloc.last_line,last_line:this.yylineno+ +1,first_column:this.yylloc.last_column,last_column:b?b[b.length-1].length-b[b.length-1].match(/\r?\n?/)[0].length:this.yylloc.last_column+a[0].length};this.yytext+=a[0];this.match+=a[0];this.matches=a;this.yyleng=this.yytext.length;this.options.ranges&&(this.yylloc.range=[this.offset,this.offset+=this.yyleng]);this._more=!1;this._input=this._input.slice(a[0].length);this.matched+=a[0];a=this.performAction.call(this,this.yy,this,e[d],this.conditionStack[this.conditionStack.length-1]);this.done&&this._input&& +(this.done=!1);if(a)return a}else return""===this._input?this.EOF:this.parseError("Lexical error on line "+(this.yylineno+1)+". Unrecognized text.\n"+this.showPosition(),{text:"",token:null,line:this.yylineno})},lex:function(){var a=this.next();return"undefined"!==typeof a?a:this.lex()},begin:function(a){this.conditionStack.push(a)},popState:function(){return this.conditionStack.pop()},_currentRules:function(){return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules},topState:function(){return this.conditionStack[this.conditionStack.length- +2]},pushState:function(a){this.begin(a)},options:{},performAction:function(a,b,d){function e(a,d){return b.yytext=b.yytext.substr(a,b.yyleng-d)}switch(d){case 0:"\\\\"===b.yytext.slice(-2)?(e(0,1),this.begin("mu")):"\\"===b.yytext.slice(-1)?(e(0,1),this.begin("emu")):this.begin("mu");if(b.yytext)return 12;break;case 1:return 12;case 2:return this.popState(),12;case 3:return b.yytext=b.yytext.substr(5,b.yyleng-9),this.popState(),15;case 4:return 12;case 5:return e(0,4),this.popState(),13;case 6:return 45; +case 7:return 46;case 8:return 16;case 9:return this.popState(),this.begin("raw"),18;case 10:return 34;case 11:return 24;case 12:return 29;case 13:return this.popState(),28;case 14:return this.popState(),28;case 15:return 26;case 16:return 26;case 17:return 32;case 18:return 31;case 19:this.popState();this.begin("com");break;case 20:return e(3,5),this.popState(),13;case 21:return 31;case 22:return 51;case 23:return 50;case 24:return 50;case 25:return 54;case 27:return this.popState(),33;case 28:return this.popState(), +25;case 29:return b.yytext=e(1,2).replace(/\\"/g,'"'),42;case 30:return b.yytext=e(1,2).replace(/\\'/g,"'"),42;case 31:return 52;case 32:return 44;case 33:return 44;case 34:return 43;case 35:return 50;case 36:return b.yytext=e(1,2),50;case 37:return"INVALID";case 38:return 5}},rules:[/^(?:[^\x00]*?(?=(\{\{)))/,/^(?:[^\x00]+)/,/^(?:[^\x00]{2,}?(?=(\{\{|\\\{\{|\\\\\{\{|$)))/,/^(?:\{\{\{\{\/[^\s!"#%-,\.\/;->@\[-\^`\{-~]+(?=[=}\s\/.])\}\}\}\})/,/^(?:[^\x00]*?(?=(\{\{\{\{\/)))/,/^(?:[\s\S]*?--\}\})/,/^(?:\()/, +/^(?:\))/,/^(?:\{\{\{\{)/,/^(?:\}\}\}\})/,/^(?:\{\{(~)?>)/,/^(?:\{\{(~)?#)/,/^(?:\{\{(~)?\/)/,/^(?:\{\{(~)?\^\s*(~)?\}\})/,/^(?:\{\{(~)?\s*else\s*(~)?\}\})/,/^(?:\{\{(~)?\^)/,/^(?:\{\{(~)?\s*else\b)/,/^(?:\{\{(~)?\{)/,/^(?:\{\{(~)?&)/,/^(?:\{\{!--)/,/^(?:\{\{![\s\S]*?\}\})/,/^(?:\{\{(~)?)/,/^(?:=)/,/^(?:\.\.)/,/^(?:\.(?=([=~}\s\/.)])))/,/^(?:[\/.])/,/^(?:\s+)/,/^(?:\}(~)?\}\})/,/^(?:(~)?\}\})/,/^(?:"(\\["]|[^"])*")/,/^(?:'(\\[']|[^'])*')/,/^(?:@)/,/^(?:true(?=([~}\s)])))/,/^(?:false(?=([~}\s)])))/, +/^(?:-?[0-9]+(?:\.[0-9]+)?(?=([~}\s)])))/,/^(?:([^\s!"#%-,\.\/;->@\[-\^`\{-~]+(?=([=~}\s\/.)]))))/,/^(?:\[[^\]]*\])/,/^(?:.)/,/^(?:$)/],conditions:{mu:{rules:[6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38],inclusive:!1},emu:{rules:[2],inclusive:!1},com:{rules:[5],inclusive:!1},raw:{rules:[3,4],inclusive:!1},INITIAL:{rules:[0,1,38],inclusive:!0}}}};f.prototype=U;U.Parser=f;F=new f;var M=function(a,b,d){void 0===b&&(b=a.length);var e=a[b-1];a=a[b-2]; +if(!e)return d;if("content"===e.type)return(a||!d?/\r?\n\s*?$/:/(^|\r?\n)\s*?$/).test(e.original)},G=function(a,b,d){void 0===b&&(b=-1);var e=a[b+1];a=a[b+2];if(!e)return d;if("content"===e.type)return(a||!d?/^\s*?\r?\n/:/^\s*?(\r?\n|$)/).test(e.original)},L=function(a,b,d){!(a=a[null==b?0:b+1])||"content"!==a.type||!d&&a.rightStripped||(b=a.string,a.string=a.string.replace(d?/^\s+/:/^[ \t]*\r?\n?/,""),a.rightStripped=a.string!==b)},P=function(a,b,d){if((a=a[null==b?a.length-1:b-1])&&"content"=== +a.type&&(d||!a.leftStripped))return b=a.string,a.string=a.string.replace(d?/\s+$/:/[ \t]+$/,""),a.leftStripped=a.string!==b,a.leftStripped},f=n.extend,O={};f(O,{stripFlags:function(a,b){return{left:"~"===a.charAt(2),right:"~"===b.charAt(b.length-3)}},prepareBlock:function(b,d,e,c,g,f){if(b.sexpr.id.original!==c.path.original)throw new a(b.sexpr.id.original+" doesn't match "+c.path.original,b);var h=e&&e.program,l={left:b.strip.left,right:c.strip.right,openStandalone:G(d.statements),closeStandalone:M((h|| +d).statements)};b.strip.right&&L(d.statements,null,!0);h?(e=e.strip,e.left&&P(d.statements,null,!0),e.right&&L(h.statements,null,!0),c.strip.left&&P(h.statements,null,!0),M(d.statements)&&G(h.statements)&&(P(d.statements),L(h.statements))):c.strip.left&&P(d.statements,null,!0);return g?new this.BlockNode(b,h,d,l,f):new this.BlockNode(b,d,h,l,f)},prepareProgram:function(a,b){for(var d=0,e=a.length;dd||this.addDepth(d-1);return b},block:function(a){var b=a.mustache,d=a.program;a=a.inverse;d&&(d=this.compileProgram(d));a&&(a=this.compileProgram(a));var b=b.sexpr,e=this.classifySexpr(b);"helper"===e?this.helperSexpr(b,d,a):"simple"===e?(this.simpleSexpr(b),this.opcode("pushProgram",d),this.opcode("pushProgram",a),this.opcode("emptyHash"),this.opcode("blockValue",b.id.original)):(this.ambiguousSexpr(b,d,a),this.opcode("pushProgram", +d),this.opcode("pushProgram",a),this.opcode("emptyHash"),this.opcode("ambiguousBlockValue"));this.opcode("append")},hash:function(a){a=a.pairs;var b,d;this.opcode("pushHash");b=0;for(d=a.length;bthis.stackVars.length&&this.stackVars.push("stack"+this.stackSlot);return this.topStackName()},topStackName:function(){return"stack"+this.stackSlot},flushInline:function(){var a=this.inlineStack;if(a.length){this.inlineStack=[];for(var b=0,d=a.length;bd.length)return!1;e=a(d[0],d[1],b);return-1=n[l]?k=l+2:q=l;return c>=n[k]?k+2:k}}); +enifed$$inline_1454("backburner/deferred-action-queues",["./utils","./queue","exports"],function(c,m,n){function k(c,f){var b=this.queues=Object.create(null);this.queueNames=c=c||[];this.options=f;q(c,function(a){b[a]=new l(a,f[a],f)})}var q=c.each,l=m["default"];k.prototype={schedule:function(c,f,b,a,d,g){var e=this.queues[c];if(!e)throw Error("You attempted to schedule an action in a queue ("+c+") that doesn't exist");return d?e.pushUnique(f,b,a,g):e.push(f,b,a,g)},flush:function(){for(var c=this.queues, +f=this.queueNames,b,a=0,d=f.length;a\s*\(([^\)]+)\)/gm, +"{anonymous}($1)").split("\n"),e.shift()):e=e.stack.replace(/(?:\n@:0)?\s+$/m,"").replace(/^\(/gm,"{anonymous}(").split("\n");k="\n "+e.slice(2).join("\n ");a+=k}f.warn("DEPRECATION: "+a)}};l.deprecateFunc=function(a,b){return function(){l.deprecate(a);return b.apply(this,arguments)}};l.runInDebug=function(a){a()};k._warnIfUsingStrippedFeatureFlags=q;if(!l.testing){l.FEATURES["features-stripped-test"]=!0;delete l.FEATURES["features-stripped-test"];q(l.ENV.FEATURES,!0);var b="undefined"!==typeof InstallTrigger, +a=!!window.chrome&&!window.opera;"undefined"!==typeof window&&(b||a)&&window.addEventListener&&window.addEventListener("load",function(){if(document.documentElement&&document.documentElement.dataset&&!document.documentElement.dataset.emberExtension){var d;a?d="https://chrome.google.com/webstore/detail/ember-inspector/bmdblncegkenkacieihfhpjfppoconhi":b&&(d="https://addons.mozilla.org/en-US/firefox/addon/ember-inspector/");l.debug("For more advanced debugging, install the Ember Inspector from "+d)}}, +!1)}});enifed$$inline_1454("ember-extension-support",["ember-metal/core","ember-extension-support/data_adapter","ember-extension-support/container_debug_adapter"],function(c,m,n){c=c["default"];n=n["default"];c.DataAdapter=m["default"];c.ContainerDebugAdapter=n}); +enifed$$inline_1454("ember-extension-support/container_debug_adapter","ember-metal/core ember-runtime/system/native_array ember-metal/utils ember-runtime/system/string ember-runtime/system/namespace ember-runtime/system/object exports".split(" "),function(c,m,n,k,q,l,h){var f=c["default"],b=m.A,a=n.typeOf,d=k.dasherize,g=k.classify,e=q["default"];h["default"]=l["default"].extend({container:null,resolver:null,canCatalogEntriesByType:function(a){return"model"===a||"template"===a?!1:!0},catalogEntriesByType:function(c){var h= +b(e.NAMESPACES),l=b(),k=RegExp(g(c)+"$");h.forEach(function(b){if(b!==f)for(var e in b)b.hasOwnProperty(e)&&k.test(e)&&"class"===a(b[e])&&l.push(d(e.replace(k,"")))});return l}})}); +enifed$$inline_1454("ember-extension-support/data_adapter","ember-metal/core ember-metal/property_get ember-metal/run_loop ember-runtime/system/string ember-runtime/system/namespace ember-runtime/system/object ember-runtime/system/native_array ember-application/system/application exports".split(" "),function(c,m,n,k,q,l,h,f,b){var a=c["default"],d=m.get,g=n["default"],e=k.dasherize,s=q["default"],t=h.A,r=f["default"];b["default"]=l["default"].extend({init:function(){this._super();this.releaseMethods= +t()},container:null,containerDebugAdapter:void 0,attributeLimit:3,releaseMethods:t(),getFilters:function(){return t()},watchModelTypes:function(a,b){var d=this.getModelTypes(),e=this,c=t(),d=d.map(function(a){var d=a.klass;a=e.wrapModelType(d,a.name);c.push(e.observeModelType(d,b));return a});a(d);var g=function(){c.forEach(function(a){a()});e.releaseMethods.removeObject(g)};this.releaseMethods.pushObject(g);return g},_nameToClass:function(a){"string"===typeof a&&(a=this.container.lookupFactory("model:"+ +a));return a},watchRecords:function(b,d,e,c){var g=this,f=t(),h=this.getRecords(b),l,r=function(a){e([a])};b=h.map(function(a){f.push(g.observeRecord(a,r));return g.wrapRecord(a)});var k={didChange:function(a,b,e,h){for(var l=b;larguments.length);return f.helpers.view.call(this,b,a)}};f.helpers=k(h.helpers);f.Compiler=function(){};h.Compiler&&(f.Compiler.prototype=k(h.Compiler.prototype));f.Compiler.prototype.compiler=f.Compiler;f.JavaScriptCompiler=function(){}; +h.JavaScriptCompiler&&(f.JavaScriptCompiler.prototype=k(h.JavaScriptCompiler.prototype),f.JavaScriptCompiler.prototype.compiler=f.JavaScriptCompiler);f.JavaScriptCompiler.prototype.namespace="Ember.Handlebars";f.JavaScriptCompiler.prototype.initializeBuffer=function(){return"''"};f.JavaScriptCompiler.prototype.appendToBuffer=function(b){return"data.buffer.push("+b+");"};f.Compiler.prototype.mustache=function(b){if(!b.params.length&&!b.hash){var a=new h.AST.IdNode([{part:"_triageMustache"}]);b.escaped|| +(b.hash=b.hash||new h.AST.HashNode([]),b.hash.pairs.push(["unescaped",new h.AST.StringNode("true")]));b=new h.AST.MustacheNode([a].concat([b.id]),b.hash,!b.escaped)}return h.Compiler.prototype.mustache.call(this,b)};f.precompile=function(b,a){var d=h.parse(b),c={knownHelpers:{action:!0,unbound:!0,"bind-attr":!0,template:!0,view:!0,_triageMustache:!0},data:!0,stringParams:!0};a=void 0===a?!0:a;d=(new f.Compiler).compile(d,c);return(new f.JavaScriptCompiler).compile(d,c,void 0,a)};h.compile&&(f.compile= +function(b){var a=h.parse(b);b={data:!0,stringParams:!0};a=(new f.Compiler).compile(a,b);b=(new f.JavaScriptCompiler).compile(a,b,void 0,!0);b=f.template(b);b.isMethod=!1;return b});m["default"]=f}); +enifed$$inline_1454("ember-handlebars","ember-handlebars-compiler ember-metal/core ember-runtime/system/lazy_load ember-handlebars/loader ember-handlebars/ext ember-handlebars/string ember-handlebars/helpers/binding ember-handlebars/helpers/if_unless ember-handlebars/helpers/with ember-handlebars/helpers/bind_attr ember-handlebars/helpers/collection ember-handlebars/helpers/view ember-handlebars/helpers/unbound ember-handlebars/helpers/debug ember-handlebars/helpers/each ember-handlebars/helpers/template ember-handlebars/helpers/partial ember-handlebars/helpers/yield ember-handlebars/helpers/loc ember-handlebars/controls/checkbox ember-handlebars/controls/select ember-handlebars/controls/text_area ember-handlebars/controls/text_field ember-handlebars/controls/text_support ember-handlebars/controls ember-handlebars/component_lookup ember-handlebars/views/handlebars_bound_view ember-handlebars/views/metamorph_view exports".split(" "),function(c, +m,n,k,q,l,h,f,b,a,d,g,e,s,t,r,v,y,u,w,x,z,A,B,C,J,I,K,F){c=c["default"];m=m["default"];n=n.runLoadHooks;l=q.makeBoundHelper;var U=q.registerBoundHelper,M=q.helperMissingHelper,G=q.blockHelperMissingHelper;q=q.handlebarsGet;var L=h.bind,P=h._triageMustacheHelper,O=h.resolveHelper;h=h.bindHelper;var S=f.ifHelper,T=f.boundIfHelper,D=f.unboundIfHelper;f=f.unlessHelper;b=b["default"];var X=a.bindAttrHelper,Y=a.bindAttrHelperDeprecated;a=a.bindClasses;d=d["default"];var Z=g.ViewHelper;g=g.viewHelper;e= +e["default"];var aa=s.logHelper;s=s.debuggerHelper;var ba=t.EachView;t=t.eachHelper;r=r["default"];v=v["default"];y=y["default"];u=u["default"];w=w["default"];var ca=x.Select,ha=x.SelectOption;x=x.SelectOptgroup;z=z["default"];A=A["default"];B=B["default"];var fa=C.inputHelper;C=C.textareaHelper;J=J["default"];var N=I._HandlebarsBoundView;I=I.SimpleHandlebarsView;var V=K["default"],$=K._SimpleMetamorphView;K=K._Metamorph;c.bootstrap=k["default"];c.makeBoundHelper=l;c.registerBoundHelper=U;c.resolveHelper= +O;c.bind=L;c.bindClasses=a;c.EachView=ba;c.ViewHelper=Z;m.Handlebars=c;c.get=q;m.ComponentLookup=J;m._SimpleHandlebarsView=I;m._HandlebarsBoundView=N;m._SimpleMetamorphView=$;m._MetamorphView=V;m._Metamorph=K;m.TextSupport=B;m.Checkbox=w;m.Select=ca;m.SelectOption=ha;m.SelectOptgroup=x;m.TextArea=z;m.TextField=A;m.TextSupport=B;c.registerHelper("helperMissing",M);c.registerHelper("blockHelperMissing",G);c.registerHelper("bind",h);c.registerHelper("boundIf",T);c.registerHelper("_triageMustache",P); +c.registerHelper("unboundIf",D);c.registerHelper("with",b);c.registerHelper("if",S);c.registerHelper("unless",f);c.registerHelper("bind-attr",X);c.registerHelper("bindAttr",Y);c.registerHelper("collection",d);c.registerHelper("log",aa);c.registerHelper("debugger",s);c.registerHelper("each",t);c.registerHelper("loc",u);c.registerHelper("partial",v);c.registerHelper("template",r);c.registerHelper("yield",y);c.registerHelper("view",g);c.registerHelper("unbound",e);c.registerHelper("input",fa);c.registerHelper("textarea", +C);n("Ember.Handlebars",c);F["default"]=c});enifed$$inline_1454("ember-handlebars/component_lookup",["ember-runtime/system/object","exports"],function(c,m){m["default"]=c["default"].extend({lookupFactory:function(c,k){k=k||this.container;var m="component:"+c,l="template:components/"+c,h=k&&k.has(l);h&&k.injection(m,"layout",l);l=k.lookupFactory(m);if(h||l)return l||(k.register(m,Ember$$inline_1458.Component),l=k.lookupFactory(m)),l}})}); +enifed$$inline_1454("ember-handlebars/controls","ember-handlebars/controls/checkbox ember-handlebars/controls/text_field ember-handlebars/controls/text_area ember-metal/core ember-handlebars-compiler exports".split(" "),function(c,m,n,k,q,l){var h=c["default"],f=m["default"],b=n["default"],a=k["default"],d=q["default"];l.inputHelper=function(b){a.assert("You can only pass attributes to the `input` helper, not arguments",2>arguments.length);var e=b.data.view,c=b.hash,l=b.hashTypes,r=c.on;if("checkbox"=== +("ID"===l.type?e.getStream(c.type).value():c.type))return delete c.type,delete l.type,a.assert("{{input type='checkbox'}} does not support setting `value=someBooleanValue`; you must use `checked=someBooleanValue` instead.","ID"!==b.hashTypes.value),d.helpers.view.call(this,h,b);delete c.on;c.onEvent=r||"enter";return d.helpers.view.call(this,f,b)};l.textareaHelper=function(c){a.assert("You can only pass attributes to the `textarea` helper, not arguments",2>arguments.length);return d.helpers.view.call(this, +b,c)}}); +enifed$$inline_1454("ember-handlebars/controls/checkbox",["ember-metal/property_get","ember-metal/property_set","ember-views/views/view","exports"],function(c,m,n,k){var q=c.get,l=m.set;k["default"]=n["default"].extend({instrumentDisplay:'{{input type="checkbox"}}',classNames:["ember-checkbox"],tagName:"input",attributeBindings:"type checked indeterminate disabled tabindex name autofocus required form".split(" "),type:"checkbox",checked:!1,disabled:!1,indeterminate:!1,init:function(){this._super();this.on("change", +this,this._updateElementValue)},didInsertElement:function(){this._super();q(this,"element").indeterminate=!!q(this,"indeterminate")},_updateElementValue:function(){l(this,"checked",this.$().prop("checked"))}})}); +enifed$$inline_1454("ember-handlebars/controls/select","ember-handlebars-compiler ember-metal/enumerable_utils ember-metal/property_get ember-metal/property_set ember-views/views/view ember-views/views/collection_view ember-metal/utils ember-metal/is_none ember-metal/computed ember-runtime/system/native_array ember-metal/mixin ember-metal/properties exports".split(" "),function(c,m,n,k,q,l,h,f,b,a,d,g,e){var s=c["default"],t=m.forEach,r=m.indexOf,v=m.indexesOf,y=m.replace,u=n.get,w=k.set;c=q["default"]; +l=l["default"];var x=h.isArray,z=f["default"],A=b.computed,B=a.A;h=d.observer;var C=g.defineProperty;g=c.extend({instrumentDisplay:"Ember.SelectOption",tagName:"option",attributeBindings:["value","selected"],defaultTemplate:function(a,b){b={data:b.data,hash:{}};s.helpers.bind.call(a,"view.label",b)},init:function(){this.labelPathDidChange();this.valuePathDidChange();this._super()},selected:A(function(){var a=u(this,"content"),b=u(this,"parentView.selection");return u(this,"parentView.multiple")?b&& +-1');a=b._triageMustache.call(a,"view.prompt",{name:"_triageMustache",hash:{}, +hashTypes:{},hashContexts:{},types:["ID"],contexts:[a],data:e});null!=a&&e.buffer.push(a);e.buffer.push("");return""},3:function(a,b,d,e){a=b.each.call(a,"group","in","view.groupedContent",{name:"each",hash:{},hashTypes:{},hashContexts:{},fn:this.program(4,e),inverse:this.noop,types:["ID","ID","ID"],contexts:[a,a,a],data:e});null!=a?e.buffer.push(a):e.buffer.push("")},4:function(a,b,d,e){d=this.escapeExpression;e.buffer.push(d(b.view.call(a,"view.groupView",{name:"view",hash:{label:"group.label", +content:"group.content"},hashTypes:{label:"ID",content:"ID"},hashContexts:{label:a,content:a},types:["ID"],contexts:[a],data:e})))},6:function(a,b,d,e){a=b.each.call(a,"item","in","view.content",{name:"each",hash:{},hashTypes:{},hashContexts:{},fn:this.program(7,e),inverse:this.noop,types:["ID","ID","ID"],contexts:[a,a,a],data:e});null!=a?e.buffer.push(a):e.buffer.push("")},7:function(a,b,d,e){d=this.escapeExpression;e.buffer.push(d(b.view.call(a,"view.optionView",{name:"view",hash:{content:"item"}, +hashTypes:{content:"ID"},hashContexts:{content:a},types:["ID"],contexts:[a],data:e})))},compiler:[6,">= 2.0.0-beta.1"],main:function(a,b,d,e){d=b["if"].call(a,"view.prompt",{name:"if",hash:{},hashTypes:{},hashContexts:{},fn:this.program(1,e),inverse:this.noop,types:["ID"],contexts:[a],data:e});null!=d&&e.buffer.push(d);d=b["if"].call(a,"view.optionGroupPath",{name:"if",hash:{},hashTypes:{},hashContexts:{},fn:this.program(3,e),inverse:this.program(6,e),types:["ID"],contexts:[a],data:e});null!=d&&e.buffer.push(d); +return""},useData:!0}),attributeBindings:"multiple disabled tabindex name required autofocus form size".split(" "),multiple:!1,disabled:!1,required:!1,content:null,selection:null,value:A(function(a,b){if(2===arguments.length)return b;var d=u(this,"optionValuePath").replace(/^content\.?/,"");return d?u(this,"selection."+d):u(this,"selection")}).property("selection"),prompt:null,optionLabelPath:"content",optionValuePath:"content",optionGroupPath:null,groupView:f,groupedContent:A(function(){var a=u(this, +"optionGroupPath"),b=B(),d=u(this,"content")||[];t(d,function(d){var e=u(d,a);u(b,"lastObject.label")!==e&&b.pushObject({label:e,content:B()});u(b,"lastObject.content").push(d)});return b}).property("optionGroupPath","content.@each"),optionView:g,_change:function(){u(this,"multiple")?this._changeMultiple():this._changeSingle()},selectionDidChange:h("selection.@each",function(){var a=u(this,"selection");u(this,"multiple")?x(a)?this._selectionDidChangeMultiple():w(this,"selection",B([a])):this._selectionDidChangeSingle()}), +valueDidChange:h("value",function(){var a=u(this,"content"),b=u(this,"value"),d=u(this,"optionValuePath").replace(/^content\.?/,""),e=d?u(this,"selection."+d):u(this,"selection");b!==e&&(a=a?a.find(function(a){return b===(d?u(a,d):a)}):null,this.set("selection",a))}),_triggerChange:function(){var a=u(this,"selection"),b=u(this,"value");z(a)||this.selectionDidChange();z(b)||this.valueDidChange();this._change()},_changeSingle:function(){var a=this.$()[0].selectedIndex,b=u(this,"content"),d=u(this,"prompt"); +b&&u(b,"length")&&(d&&0===a?w(this,"selection",null):(d&&(a-=1),w(this,"selection",b.objectAt(a))))},_changeMultiple:function(){var a=this.$("option:selected"),b=u(this,"prompt")?1:0,d=u(this,"content"),e=u(this,"selection");d&&a&&(a=a.map(function(){return this.index-b}).toArray(),d=d.objectsAt(a),x(e)?y(e,0,u(e,"length"),d):w(this,"selection",d))},_selectionDidChangeSingle:function(){var a=this.get("element");if(a){var b=u(this,"content"),d=u(this,"selection"),b=b?r(b,d):-1;u(this,"prompt")&&(b+= +1);a&&(a.selectedIndex=b)}},_selectionDidChangeMultiple:function(){var a=u(this,"content"),b=u(this,"selection"),d=a?v(a,b):[-1],e=u(this,"prompt")?1:0,a=this.$("option"),c;a&&a.each(function(){c=-1=arguments.length);var e=g.resolveHelper(b.data.view.container,a);return e?e.call(this,b):y.bind.call(this,a,b)};f.resolveHelper=function(a,b){if(y[b])return y[b];if(a&&!u.get(b)){var e=a.lookup("helper:"+b);if(!e){var c=a.lookup("component-lookup:main"); +d.assert("Could not find 'component-lookup:main' on the provided container, which is necessary for performing component lookups",c);if(c=c.lookupFactory(b,a))e=g.makeViewHelper(c),a.register("helper:"+b,e)}return e}};f.bindHelper=function(e,c){d.assert("You cannot pass more than one argument to the bind helper",2>=arguments.length);var g=c.contexts&&c.contexts.length?c.contexts[0]:this;if(c.fn)return c.helperName="bind",a.call(g,e,c,!1,b);var g=c.data.view.getStream(e),f=c.data.view,h=new v(g,!c.hash.unescaped); +h._parentView=f;f.appendChild(h);g.subscribe(f._wrapAsScheduled(function(){s.scheduleOnce("render",h,"rerender")}))}}); +enifed$$inline_1454("ember-handlebars/helpers/collection","ember-metal/core ember-handlebars-compiler ember-metal/mixin ember-runtime/system/string ember-metal/property_get ember-metal/streams/simple ember-handlebars/ext ember-handlebars/helpers/view ember-views/views/view ember-views/views/collection_view exports".split(" "),function(c,m,n,k,q,l,h,f,b,a,d){var g=c["default"],e=m["default"],s=n.IS_BINDING,t=k.fmt,r=q.get,v=l["default"],y=h.handlebarsGetView,u=f.ViewHelper,w=b["default"],x=a["default"]; +d["default"]=function(a,b){g.deprecate("Using the {{collection}} helper without specifying a class has been deprecated as the {{each}} helper now supports the same functionality.","collection"!==a);a&&a.data&&a.data.isRenderData?(b=a,a=void 0,g.assert("You cannot pass more than one argument to the collection helper",1===arguments.length)):g.assert("You cannot pass more than one argument to the collection helper",2===arguments.length);var d=b.fn,c=b.data,f=b.inverse,h=b.data.view,l=h.controller&&h.controller.container? +h.controller.container:h.container,k;a?(k=y(this,a,l,b.data),g.assert(t("%@ #collection: Could not find collection class %@",[c.view,a]),!!k)):k=x;var m=b.hash,n=b.hashTypes,q={},L,P=k.proto(),O;m.itemView?O=m.itemView:m.itemViewClass?"ID"===n.itemViewClass?(O=h.getStream(m.itemViewClass),g.deprecate('Resolved the view "'+m.itemViewClass+'" on the global context. Pass a view name to be looked up on the container instead, such as {{view "select"}}. http://emberjs.com/guides/deprecations#toc_global-lookup-of-views', +!O.isGlobal()),O=O.value()):O=m.itemViewClass:O=P.itemViewClass;"string"===typeof O&&(O=l.lookupFactory("view:"+O));g.assert(t("%@ #collection: Could not find itemViewClass %@",[c.view,O]),!!O);delete m.itemViewClass;delete m.itemView;delete n.itemViewClass;delete n.itemView;for(var S in m)"itemController"!==S&&"itemClassBinding"!==S&&m.hasOwnProperty(S)&&(L=S.match(/^item(.)(.*)$/))&&(L=L[1].toLowerCase()+L[2],"ID"===n[S]||s.test(S)?q[L]=h._getBindingForStream(m[S]):q[L]=m[S],delete m[S]);d&&(q.template= +d,delete b.fn);var T;f&&f!==e.VM.noop?(T=r(P,"emptyViewClass"),T=T.extend({template:f,tagName:q.tagName})):m.emptyViewClass&&(T=y(this,m.emptyViewClass,l,b.data));T&&(m.emptyView=T);q._contextBinding=m.keyword?"_parentView.context":"content";d=u.propertiesFromHTMLOptions({data:c,hash:q},this);if(m.itemClassBinding){c=m.itemClassBinding.split(" ");for(f=0;f=h)return b.getStream(c).value();f.data.isUnbound=!0;f.types.shift();for(var b=Array(h-1),d=1;d=arguments.length);var b=arguments[arguments.length-1],e=b.types,c=b.data.view,g=c.container||c._keywords.view.value().container;1===arguments.length?g=g?g.lookupFactory("view:toplevel"):r:("string"===typeof a&&"ID"===e[0]?(e=c.getStream(a),d.deprecate('Resolved the view "'+a+'" on the global context. Pass a view name to be looked up on the container instead, such as {{view "select"}}. http://emberjs.com/guides/deprecations#toc_global-lookup-of-views', +!e.isGlobal())):e=a,g=t(e,g));b.helperName=b.helperName||"view";return y.helper(this,g,b)}}); +enifed$$inline_1454("ember-handlebars/helpers/with","ember-metal/core ember-metal/property_set ember-metal/utils ember-metal/platform ember-metal/is_none ember-handlebars/helpers/binding ember-handlebars/views/handlebars_bound_view exports".split(" "),function(c,m,n,k,q,l,h,f){function b(a){return!s(a)}var a=c["default"],d=m.set,g=n.apply,e=k.create,s=q["default"],t=l.bind,r=h._HandlebarsBoundView.extend({init:function(){g(this,this._super,arguments);var a=this.templateHash.keywordName,b=this.templateHash.controller; +if(b){var e=this.previousContext,c=this.container.lookupFactory("controller:"+b).create({parentController:e,target:e});this._generatedController=c;this.preserveContext?(this._keywords[a]=c,this.lazyValue.subscribe(function(a){d(c,"model",a.value())})):(d(this,"controller",c),this.valueNormalizerFunc=function(a){c.set("model",a);return c});d(c,"model",this.lazyValue.value())}},willDestroy:function(){this._super();this._generatedController&&this._generatedController.destroy()}});f["default"]=function(d){var c= +arguments[arguments.length-1],g=c.data.view,f,h="with";if(4===arguments.length){a.assert("If you pass more than one argument to the with helper, it must be in the form #with foo as bar","as"===arguments[1]);var l=arguments[2];d&&(h+=" "+d+" as "+l);a.assert("You must pass a block to the with helper",c.fn&&c.fn!==Handlebars.VM.noop);f=e(c);f.data=e(c.data);f.keywords={};f.keywords[l]=g.getStream(d);f.hash.keywordName=l;g=this;c=f;f=!0}else a.deprecate("Using the context switching form of `{{with}}` is deprecated. Please use the keyword form (`{{with foo as bar}}`) instead. See http://emberjs.com/guides/deprecations/#toc_more-consistent-handlebars-scope for more details."), +a.assert("You must pass exactly one argument to the with helper",2===arguments.length),a.assert("You must pass a block to the with helper",c.fn&&c.fn!==Handlebars.VM.noop),h+=" "+d,g=c.contexts[0],f=!1;c.helperName=h;return t.call(g,d,c,f,b,void 0,void 0,r)}}); +enifed$$inline_1454("ember-handlebars/helpers/yield",["ember-metal/core","ember-metal/property_get","exports"],function(c,m,n){var k=c["default"],q=m.get;n["default"]=function(c){for(var h=c.data.view;h&&!q(h,"layout");)h=h._contextView?h._contextView:q(h,"_parentView");k.assert("You called yield in a template that was not a layout",!!h);h._yield(this,c)}}); +enifed$$inline_1454("ember-handlebars/loader","ember-handlebars/component_lookup ember-views/system/jquery ember-metal/error ember-runtime/system/lazy_load ember-handlebars-compiler exports".split(" "),function(c,m,n,k,q,l){function h(a){d('script[type="text/x-handlebars"], script[type="text/x-raw-handlebars"]',a).each(function(){var a=d(this),b="text/x-raw-handlebars"===a.attr("type")?d.proxy(Handlebars.compile,Handlebars):d.proxy(e.compile,e),c=a.attr("data-template-name")||a.attr("id")||"application", +b=b(a.html());if(void 0!==Ember$$inline_1458.TEMPLATES[c])throw new g('Template named "'+c+'" already exists.');Ember$$inline_1458.TEMPLATES[c]=b;a.remove()})}function f(){h(d(document))}function b(b){b.register("component-lookup:main",a)}var a=c["default"],d=m["default"],g=n["default"];c=k.onLoad;var e=q["default"];c("Ember.Application",function(a){a.initializer({name:"domTemplates",initialize:f});a.initializer({name:"registerComponentLookup",after:"domTemplates",initialize:b})});l["default"]=h}); +enifed$$inline_1454("ember-handlebars/string",["ember-runtime/system/string","exports"],function(c,m){function n(c){if(null===c||void 0===c)return"";"string"!==typeof c&&(c=""+c);return new Handlebars.SafeString(c)}c["default"].htmlSafe=n;if(!0===Ember$$inline_1458.EXTEND_PROTOTYPES||Ember$$inline_1458.EXTEND_PROTOTYPES.String)String.prototype.htmlSafe=function(){return n(this)};m["default"]=n}); +enifed$$inline_1454("ember-handlebars/views/handlebars_bound_view","ember-handlebars-compiler ember-metal/core ember-metal/error ember-metal/property_get ember-metal/property_set ember-metal/merge ember-metal/run_loop ember-handlebars/string ember-views/views/states ember-handlebars/views/metamorph_view ember-metal/utils exports".split(" "),function(c,m,n,k,q,l,h,f,b,a,d,g){function e(a,b){this.lazyValue=a;this.isEscaped=b;this[t.GUID_KEY]=x();this._lastNormalizedValue=void 0;this.state="preRender"; +this._morph=this.buffer=this._parentView=this.updateId=null}var s=c["default"],t=m["default"];c=t.K;var r=n["default"],v=k.get,y=q.set;n=l["default"];var u=h["default"],w=f["default"];h=b.cloneStates;b=b.states;a=a["default"];var x=d.uuid;e.prototype={isVirtual:!0,isView:!0,destroy:function(){this.updateId&&(u.cancel(this.updateId),this.updateId=null);this._parentView&&this._parentView.removeChild(this);this.morph=null;this.state="destroyed"},propertyWillChange:c,propertyDidChange:c,normalizedValue:function(){var a= +this.lazyValue.value();null===a||void 0===a?a="":this.isEscaped||a instanceof s.SafeString||(a=w(a));return a},render:function(a){var b=this.normalizedValue();this._lastNormalizedValue=b;a._element=b},rerender:function(){switch(this.state){case "inBuffer":throw new r("Something you did tried to replace an {{expression}} before it was inserted into the DOM.");case "hasElement":case "inDOM":this.updateId=u.scheduleOnce("render",this,"update")}return this},update:function(){this.updateId=null;var a= +this.normalizedValue();a!==this._lastNormalizedValue&&(this._lastNormalizedValue=a,this._morph.update(a))},_transitionTo:function(a){this.state=a}};d=h(b);n(d._default,{rerenderIfNeeded:c});n(d.inDOM,{rerenderIfNeeded:function(a){a.normalizedValue()!==a._lastNormalizedValue&&a.rerender()}});d=a.extend({instrumentName:"boundHandlebars",_states:d,shouldDisplayFunc:null,preserveContext:!1,previousContext:null,displayTemplate:null,inverseTemplate:null,lazyValue:null,normalizedValue:function(){var a=this.lazyValue.value(), +b=v(this,"valueNormalizerFunc");return b?b(a):a},rerenderIfNeeded:function(){this.currentState.rerenderIfNeeded(this)},render:function(a){var b=v(this,"isEscaped"),d=v(this,"shouldDisplayFunc"),e=v(this,"preserveContext"),c=v(this,"previousContext"),g=v(this,"inverseTemplate"),f=v(this,"displayTemplate"),h=this.normalizedValue();this._lastNormalizedValue=h;if(d(h))if(y(this,"template",f),e)y(this,"_context",c);else if(f)y(this,"_context",h);else{null===h||void 0===h?h="":h instanceof s.SafeString|| +(h=String(h));b&&(h=Handlebars.Utils.escapeExpression(h));a.push(h);return}else g?(y(this,"template",g),e?y(this,"_context",c):y(this,"_context",h)):y(this,"template",function(){return""});return this._super(a)}});g._HandlebarsBoundView=d;g.SimpleHandlebarsView=e}); +enifed$$inline_1454("ember-handlebars/views/metamorph_view",["ember-metal/core","ember-views/views/core_view","ember-views/views/view","ember-metal/mixin","exports"],function(c,m,n,k,q){var l=c["default"];c=m["default"];n=n["default"];k=k.Mixin.create({isVirtual:!0,tagName:"",instrumentName:"metamorph",init:function(){this._super();l.deprecate("Supplying a tagName to Metamorph views is unreliable and is deprecated. You may be setting the tagName on a Handlebars helper that creates a Metamorph.",!this.tagName)}}); +q._Metamorph=k;q["default"]=n.extend(k);k=c.extend(k);q._SimpleMetamorphView=k});enifed$$inline_1454("ember-metal-views",["ember-metal-views/renderer","exports"],function(c,m){m.Renderer=c["default"]}); +enifed$$inline_1454("ember-metal-views/renderer",["morph","exports"],function(c,m){function n(){this._uuid=0;this._views=Array(2E3);this._queue=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this._parents=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0];this._elements=Array(17);this._inserts={};this._dom=new k}var k=c.DOMHelper;n.prototype.uuid=function(c){void 0===c._uuid&&(c._uuid=++this._uuid,c._renderer=this);return c._uuid};n.prototype.scheduleInsert=function(c,h){if(c._morph||c._elementCreated)throw Error("You cannot insert a View that has already been rendered"); +Ember$$inline_1458.assert("You cannot insert a View without a morph",h);c._morph=h;var f=this.uuid(c);this._inserts[f]=this.scheduleRender(this,function(){this._inserts[f]=null;this.renderTree(c)})};n.prototype.appendTo=function(c,h){var f=this._dom.appendMorph(h);this.scheduleInsert(c,f)};n.prototype.replaceIn=function(c,h){var f=this._dom.createMorph(h,null,null);this.scheduleInsert(c,f)};n.prototype.remove=function(c,h,f){var b=this.uuid(c);this._inserts[b]&&(this.cancelRender(this._inserts[b]), +this._inserts[b]=void 0);if(c._elementCreated){var b=[],a=[],d=c._morph,g,e,k,t,r;b.push(c);for(g=0;g>>0,g=Array(d),e=0;e>>0,g=0;gb&&(b=Math.max(0,this.length+b));for(var a=b,d=this.length;ab?Math.ceil(b):Math.floor(b);0>b&&(b+=a);for(a=b;0<=a;a--)if(this[a]===c)return a;return-1},n=n(m.filter)?m.filter:function(c,b){var a,d,g=[],e=this.length;for(a=0;a("+this._from+" -> "+this._to+")"+a},connect:function(b){a.assert("Must pass a valid object to Ember.Binding.connect()",!!b);var e=this._from,c=this._to;g(b,c,d(y(e)?a.lookup:b,e));s(b, +e,this,this.fromDidChange);this._oneWay||s(b,c,this,this.toDidChange);this._readyToSync=!0;return this},disconnect:function(b){a.assert("Must pass a valid object to Ember.Binding.disconnect()",!!b);var d=!this._oneWay;t(b,this._from,this,this.fromDidChange);d&&t(b,this._to,this,this.toDidChange);this._readyToSync=!1;return this},fromDidChange:function(a){this._scheduleSync(a,"fwd")},toDidChange:function(a){this._scheduleSync(a,"back")},_scheduleSync:function(a,b){var d=this._direction;void 0===d&& +(v.schedule("sync",this,this._sync,a),this._direction=b);"back"===d&&"fwd"===b&&(this._direction="fwd")},_sync:function(b){var e=a.LOG_BINDINGS;if(!b.isDestroyed&&this._readyToSync){var c=this._direction,f=this._from,h=this._to;this._direction=void 0;if("fwd"===c){var l=d(y(this._from)?a.lookup:b,this._from);e&&a.Logger.log(" ",this.toString(),"->",l,b);this._oneWay?g(b,h,l):r(b,h,this,this.toDidChange,function(){g(b,h,l)})}else if("back"===c){var k=d(b,this._to);e&&a.Logger.log(" ",this.toString(), +"<-",k,b);r(b,f,this,this.fromDidChange,function(){g(y(f)?a.lookup:b,f,k)})}}}};c={from:function(a){return new this(void 0,a)},to:function(a){return new this(a,void 0)},oneWay:function(a,b){return(new this(void 0,a)).oneWay(b)}};for(var u in c)c.hasOwnProperty(u)&&(b[u]=c[u]);f.bind=function(a,d,e){return(new b(d,e)).connect(a)};f.oneWay=function(a,d,e){return(new b(d,e)).oneWay().connect(a)};f.Binding=b;f.isGlobalPath=y}); +enifed$$inline_1454("ember-metal/cache",["ember-metal/dictionary","exports"],function(c,m){function n(c,h){this.store=k(null);this.hits=this.misses=this.size=0;this.limit=c;this.func=h}var k=c["default"];m["default"]=n;var q=function(){};n.prototype={set:function(c,h){this.limit>this.size&&(this.size++,this.store[c]=void 0===h?q:h);return h},get:function(c){var h=this.store[c];void 0===h?(this.misses++,h=this.set(c,this.func(c))):h===q?(this.hits++,h=void 0):this.hits++;return h},purge:function(){this.store= +k(null);this.misses=this.hits=this.size=0}}}); +enifed$$inline_1454("ember-metal/chains","ember-metal/core ember-metal/property_get ember-metal/utils ember-metal/array ember-metal/watch_key exports".split(" "),function(c,m,n,k,q,l){function h(a,b,d){if(a&&"object"===typeof a){var e=g(a),c=e.chainWatchers;e.hasOwnProperty("chainWatchers")||(c=e.chainWatchers={});c[b]||(c[b]=[]);c[b].push(d);s(a,b,e)}}function f(a,b,d){if(a&&"object"===typeof a){var e=a.__ember_meta__;if(!e||e.hasOwnProperty("chainWatchers")){var c=e&&e.chainWatchers;if(c&&c[b])for(var c= +c[b],g=0,f=c.length;g=d[e]||a.add(e);return a};c.add=function(a){var b,e,c;e=this._paths;e[a]=(e[a]||0)+1;b=this.value();e=d(b,a);if(e[0]&&e[0]===b)a=e[1],b=a.match(v)[0],a=a.slice(b.length+1);else if(e[0])c=e[0],b=a.slice(0,0-(e[1].length+1)),a=e[1];else{y.push([this,a]);e.length=0;return}e.length=0;this.chain(b,a,c)};c.remove=function(a){var b,e;e=this._paths; +0=e.count&&(delete d[e._key], +e.destroy())};c.willChange=function(a){var b=this._chains;if(b)for(var d in b)b.hasOwnProperty(d)&&b[d].willChange(a);this._parent&&this._parent.chainWillChange(this,this._key,1,a)};c.chainWillChange=function(a,b,d,e){this._key&&(b=this._key+"."+b);this._parent?this._parent.chainWillChange(this,b,d+1,e):(1b});b("gte",function(a,b){return g(this,a)>=b});b("lt",function(a,b){return g(this,a)=g&&(g=0),f=e.splice(0,6E4),f=[b,g].concat(f),b+=6E4,d-=g,c=c.concat(v.apply(a,f));return c}function d(b,d,e,c){return b.replace?b.replace(d,e,c):a(b,d,e,c)}function g(a,b){var d=[];k(a,function(a){0<=l(b,a)&&d.push(a)});return d}var e=c.filter,s=c.forEach,t=c.indexOf,r=c.map,v=Array.prototype.splice;m.map=n;m.forEach=k;m.filter=q;m.indexOf=l;m.indexesOf=h;m.addObject=f;m.removeObject=b;m._replace=a;m.replace=d;m.intersection= +g;m["default"]={_replace:a,addObject:f,filter:q,forEach:k,indexOf:l,indexesOf:h,intersection:g,map:n,removeObject:b,replace:d}}); +enifed$$inline_1454("ember-metal/error",["ember-metal/platform","exports"],function(c,m){function n(){var c=Error.apply(this,arguments);Error.captureStackTrace&&Error.captureStackTrace(this,Ember$$inline_1458.Error);for(var h=0;h=v&&(t.clear(),r.flush())}var a=c.guidFor,d=c.tryFinally, +g=m.sendEvent,e=m.listenersUnion,s=m.listenersDiff;c=n["default"];var t=new c,r=new c,v=0,y,u;k.propertyWillChange=q;k.propertyDidChange=l;k.overrideChains=function(a,b,d){f(a,b,d,!0)};k.beginPropertyChanges=function(){v++};k.endPropertyChanges=b;k.changeProperties=function(a,c){v++;d(a,b,c)}}); +enifed$$inline_1454("ember-metal/property_get",["ember-metal/core","ember-metal/error","ember-metal/path_cache","ember-metal/platform","exports"],function(c,m,n,k,q){function l(d,c){var e=g(c),h=!e&&a(c);if(!d||h)d=f.lookup;e&&(c=c.slice(5));f.deprecate("normalizeTuple will return '"+c+"' as a non-global. This behavior will change in the future (issue #3852)",d===f.lookup||!d||e||h||!a(c+"."));d===f.lookup&&(e=c.match(s)[0],d=t(d,e),c=c.slice(e.length+1));if(!c||0===c.length)throw new b("Path cannot be empty"); +return[d,c]}function h(a,b){var c,e,h;if(null===a&&!d(b))return t(f.lookup,b);c=g(b);if(!a||c)c=l(a,b),a=c[0],b=c[1],c.length=0;c=b.split(".");h=c.length;for(e=0;null!=a&&em&&(h=k);h=F(h,d,null);(h=a.isActive.apply(a,h))?(l=w.isEmpty(w.keys(b.queryParams)),e||l||!h||(h={},z(h,b.queryParams),a._prepareQueryParams(b.targetRouteName,b.models,h),h=u(h,a.router.state.queryParams))):h=!1;if(h)return x(this,"activeClass")}}),loading:c("loadedParams",function(){if(!x(this,"loadedParams"))return x(this,"loadingClass")}),router:c(function(){var a=x(this,"controller");if(a&&a.container)return a.container.lookup("router:main")}), +_invoke:function(a){if(!I(a))return!0;if(!1!==this.preventDefault){var b=x(this,"target");b&&"_self"!==b||a.preventDefault()}!1===this.bubbles&&a.stopPropagation();if(x(this,"_isDisabled"))return!1;if(x(this,"loading"))return w.Logger.warn("This link-to is in an inactive loading state because at least one of its parameters presently has a null/undefined value, or the provided route name is invalid."),!1;if((a=x(this,"target"))&&"_self"!==a)return!1;var b=x(this,"router"),d=x(this,"loadedParams"); +a=b._doTransition(d.targetRouteName,d.models,d.queryParams);x(this,"replace")&&a.method("replace");d=F(d.targetRouteName,d.models,a.state.queryParams);b=b.router.generate.apply(b.router,d);A.scheduleOnce("routerTransitions",this,this._eagerUpdateUrl,a,b)},_eagerUpdateUrl:function(a,b){if(a.isActive&&a.urlMethod){0===b.indexOf("#")&&(b=b.slice(1));var d=x(this,"router.router");"update"===a.urlMethod?d.updateURL(b):"replace"===a.urlMethod&&d.replaceURL(b);a.method(null)}},resolvedParams:c("router.url", +function(){var a=this.params,b,d=[];if(0===a.length)b=this.container.lookup("controller:application"),b=x(b,"currentRouteName");else{b=M(a[0]);for(var c=1;c "+a,{fullName:a});return b}}); +enifed$$inline_1454("ember-routing/system/route","ember-metal/core ember-metal/error ember-metal/property_get ember-metal/property_set ember-metal/get_properties ember-metal/enumerable_utils ember-metal/is_none ember-metal/computed ember-metal/merge ember-metal/utils ember-metal/run_loop ember-metal/keys ember-runtime/copy ember-runtime/system/string ember-runtime/system/object ember-runtime/mixins/evented ember-runtime/mixins/action_handler ember-routing/system/generate_controller ember-routing/utils exports".split(" "),function(c, +m,n,k,q,l,h,f,b,a,d,g,e,s,t,r,v,y,u,w){function x(a){a:{var b=a.router.router.state.handlerInfos;if(b)for(var d,c=0,e=b.length;cb.resolveIndex?void 0:b.state.handlerInfos[b.resolveIndex-1].context},deserialize:function(a,b){return this.model(this.paramsFor(this.routeName),b)},findModel:function(){var a=C(this,"store");return a.find.apply(a,arguments)},store:c(function(){var a=this.container,b=this.routeName,d=C(this,"router.namespace");return{find:function(c,e){var g=a.lookupFactory("model:"+c);A.assert("You used the dynamic segment "+c+"_id in your route "+ +b+", but "+d+"."+T(c)+" did not exist and you did not override your route's `model` hook.",g);if(g)return A.assert(T(c)+" has no method `find`.","function"===typeof g.find),g.find(e)}}}),serialize:function(a,b){if(!(1>b.length)&&a){var d=b[0],c={};/_id$/.test(d)&&1===b.length?c[d]=C(a,"id"):c=I(a,b);return c}},setupController:function(a,b){a&&void 0!==b&&J(a,"model",b)},controllerFor:function(a,b){var d=this.container,c=d.lookup("route:"+a);c&&c.controllerName&&(a=c.controllerName);d=d.lookup("controller:"+ +a);A.assert("The controller named '"+a+"' could not be found. Make sure that this route exists and has already been entered at least once. If you are accessing a controller not associated with a route, make sure the controller class is explicitly defined.",d||!0===b);return d},generateController:function(a,b){var d=this.container;b=b||this.modelFor(a);return D(d,a,b)},modelFor:function(a){var b=this.container.lookup("route:"+a),d=this.router?this.router.router.activeTransition:null;return d&&(a=b&& +b.routeName||a,d.resolvedModels.hasOwnProperty(a))?d.resolvedModels[a]:b&&b.currentModel},renderTemplate:function(){this.render()},render:function(a,b){A.assert("The name in the given arguments is undefined",0 "+g,{fullName:g}));f.routeName=e;return f}},_setupRouter:function(a,b){var d,c=this;a.getHandler=this._getHandlerFunction();var e=function(){b.setURL(d)}; +a.updateURL=function(a){d=a;O.once(e)};if(b.replaceURL){var g=function(){b.replaceURL(d)};a.replaceURL=function(a){d=a;O.once(g)}}a.didTransition=function(a){c.didTransition(a)}},_serializeQueryParams:function(a,b){var d={};K(this,a,b,function(a,c,e){var g=e.urlKey;d[g]||(d[g]=[]);d[g].push({qp:e,value:c});delete b[a]});for(var c in d){var e=d[c];if(1a)}var q=c.typeOf,l=m["default"],h={undefined:0,"null":1,"boolean":2,number:3,string:4,array:5,object:6,instance:7,"function":8,"class":9,date:10};n["default"]=function b(a,d){if(a===d)return 0;var c=q(a),e=q(d);if(l){if("instance"===c&&l.detect(a.constructor))return a.constructor.compare(a,d);if("instance"===e&&l.detect(d.constructor))return 1- +d.constructor.compare(d,a)}e=k(h[c],h[e]);if(0!==e)return e;switch(c){case "boolean":case "number":return k(a,d);case "string":return k(a.localeCompare(d),0);case "array":for(var c=a.length,e=d.length,m=Math.min(c,e),n=0;nb?Math.max(0,h+b):b=h)break;l=a.objectAt(g);S(f,c,this);g=new y(a,l,g,this.instanceMeta.propertyName,this.cp,d);this.setValue(e.call(this.instanceMeta.context,this.getValue(),l,g,this.instanceMeta.sugarMeta))}this.callbacks.flushedChanges.call(this.instanceMeta.context,this.getValue(),this.instanceMeta.sugarMeta)}},dependentArrayDidChange:function(a,b,d,c){if(!this.suspended){var e=this.callbacks.addedItem;d=C(a);var g=this.dependentKeysByGuid[d],f=Array(c),h=this.cp._itemPropertyKeys[g];d= +t(a,"length");var l=0>b?Math.max(0,d+b):barguments.length&&(c=x(a,"length"));3>arguments.length&&(d=0);if(d=== +c)return d;e=d+Math.floor((c-d)/2);g=a.objectAt(e);f=A(g);h=A(b);if(f===h)return e;g=this.order(g,b);0===g&&(g=fg?this.binarySearch(a,b,e+1,c):0a)return a}})};e.map=s;e.mapBy=t;e.mapProperty=t;e.filter=r;e.filterBy=v;e.filterProperty=v;e.uniq=y;e.union=y;e.intersect=function(){var a=L.call(arguments);a.push({initialize:function(a,b,d){d.itemCounts={}},addedItem:function(a, +b,d,c){var e=A(b),g=A(d.arrayChanged);d=d.property._dependentKeys.length;c=c.itemCounts;c[e]||(c[e]={});void 0===c[e][g]&&(c[e][g]=0);1===++c[e][g]&&d===M(c[e]).length&&a.addObject(b);return a},removedItem:function(a,b,d,c){var e=A(b);d=A(d.arrayChanged);c=c.itemCounts;void 0===c[e][d]&&(c[e][d]=0);0===--c[e][d]&&(delete c[e][d],d=M(c[e]).length,0===d&&delete c[e],a.removeObject(b));return a}});return K.apply(null,a)};e.setDiff=function(a,b){if(2!==arguments.length)throw new B("setDiff requires exactly two dependent arrays."); +return K(a,b,{addedItem:function(d,c,e){var g=x(this,a),f=x(this,b);e.arrayChanged===g?f.contains(c)||d.addObject(c):d.removeObject(c);return d},removedItem:function(d,c,e){var g=x(this,a),f=x(this,b);e.arrayChanged===f?g.contains(c)&&d.addObject(c):d.removeObject(c);return d}})};e.sort=function(a,b){w.assert("Ember.computed.sort requires two arguments: an array key to sort and either a sort properties key or sort function",2===arguments.length);var d;if("function"===typeof b)d=K(a,{initialize:function(a, +d,c){c.order=b;c.binarySearch=u;c.waitingInsertions=[];c.insertWaiting=function(){var b,d,e=c.waitingInsertions;c.waitingInsertions=[];for(var g=0;ga&&(f=g[a]))return f;h=this._isVirtual?d(this,"parentController"):this;f="controller:"+c;if(!e.has(f))throw new s('Could not resolve itemController: "'+c+'"');f=e.lookupFactory(f).create({target:h,parentController:h,model:b});return g[a]=f},_subControllers:null,_resetSubControllers:function(){var a,b=this._subControllers;if(b.length){for(var d=0,c=b.length;c>d;d++)(a=b[d])&&a.destroy();b.length= +0}},willDestroy:function(){this._resetSubControllers();this._super()}})});enifed$$inline_1454("ember-runtime/controllers/controller",["ember-metal/core","ember-runtime/system/object","ember-runtime/mixins/controller","ember-runtime/inject","exports"],function(c,m,n,k,q){c=m["default"].extend(n["default"]);q["default"]=c}); +enifed$$inline_1454("ember-runtime/controllers/object_controller",["ember-runtime/mixins/controller","ember-runtime/system/object_proxy","exports"],function(c,m,n){n["default"]=m["default"].extend(c["default"])}); +enifed$$inline_1454("ember-runtime/copy",["ember-metal/enumerable_utils","ember-metal/utils","ember-runtime/system/object","ember-runtime/mixins/copyable","exports"],function(c,m,n,k,q){function l(d,c,e,k){var m,n,q;if("object"!==typeof d||null===d)return d;if(c&&0<=(n=h(e,d)))return k[n];Ember$$inline_1458.assert("Cannot clone an Ember.Object that does not implement Ember.Copyable",!(d instanceof b)||a&&a.detect(d));if("array"===f(d)){if(m=d.slice(),c)for(n=m.length;0<=--n;)m[n]=l(m[n],c,e,k)}else if(a&& +a.detect(d))m=d.copy(c,e,k);else if(d instanceof Date)m=new Date(d.getTime());else for(q in m={},d)Object.prototype.hasOwnProperty.call(d,q)&&"__"!==q.substring(0,2)&&(m[q]=c?l(d[q],c,e,k):d[q]);c&&(e.push(d),k.push(m));return m}var h=c.indexOf,f=m.typeOf,b=n["default"],a=k["default"];q["default"]=function(b,c){return"object"!==typeof b||null===b?b:a&&a.detect(b)?b.copy(c):l(b,c,c?[]:null,c?[]:null)}}); +enifed$$inline_1454("ember-runtime/core",["exports"],function(c){c.isEqual=function(c,n){return c&&"function"===typeof c.isEqual?c.isEqual(n):c instanceof Date&&n instanceof Date?c.getTime()===n.getTime():c===n}}); +enifed$$inline_1454("ember-runtime/ext/function",["ember-metal/core","ember-metal/expand_properties","ember-metal/computed","ember-metal/mixin"],function(c,m,n,k){var q=c["default"],l=m["default"],h=n.computed,f=k.observer,b=Array.prototype.slice;c=Function.prototype;if(!0===q.EXTEND_PROTOTYPES||q.EXTEND_PROTOTYPES.Function)c.property=function(){var a=h(this);return a.property.apply(a,arguments)},c.observes=function(){for(var a=arguments.length,b=Array(a),c=0;ca||a>=s(this,"length")?void 0:s(this,a)},objectsAt:function(a){var b=this;return v(a,function(a){return b.objectAt(a)})},nextObject:function(a){return this.objectAt(a)}, +"[]":c(function(a,b){void 0!==b&&this.replace(0,s(this,"length"),b);return this}),firstObject:c(function(){return this.objectAt(0)}),lastObject:c(function(){return this.objectAt(s(this,"length")-1)}),contains:function(a){return 0<=this.indexOf(a)},slice:function(a,b){var d=e.A(),c=s(this,"length");r(a)&&(a=0);if(r(b)||b>c)b=c;0>a&&(a=c+a);for(0>b&&(b=c+b);ab&&(b+=d);for(c=b;c=d)b=d-1;0>b&&(b+=d);for(d=b;0<=d;d--)if(this.objectAt(d)===a)return d;return-1},addArrayObserver:function(a,b){return g(this,a,b,w,!1)},removeArrayObserver:function(a,b){return g(this,a,b,x,!0)},hasArrayObservers:c(function(){return A(this,"@array:change")||A(this,"@array:before")}),arrayContentWillChange:function(a,b,d){var c;void 0===a?(a=0,b=d=-1):(void 0===b&&(b=-1),void 0===d&&(d=-1));B(this,"@each")&&s(this, +"@each");z(this,"@array:before",[this,a,b,d]);if(0<=a&&0<=b&&s(this,"hasEnumerableObservers"))for(c=[],b=a+b;au(a,b)&&a.push(b)});return a},"[]":l(function(){return this}),addEnumerableObserver:function(a, +b){var d=b&&b.willChange||"enumerableWillChange",c=b&&b.didChange||"enumerableDidChange",e=r(this,"hasEnumerableObservers");e||w(this,"hasEnumerableObservers");z(this,"@enumerable:before",a,d);z(this,"@enumerable:change",a,c);e||x(this,"hasEnumerableObservers");return this},removeEnumerableObserver:function(a,b){var d=b&&b.willChange||"enumerableWillChange",c=b&&b.didChange||"enumerableDidChange",e=r(this,"hasEnumerableObservers");e&&w(this,"hasEnumerableObservers");A(this,"@enumerable:before",a, +d);A(this,"@enumerable:change",a,c);e&&x(this,"hasEnumerableObservers");return this},hasEnumerableObservers:l(function(){return C(this,"@enumerable:change")||C(this,"@enumerable:before")}),enumerableContentWillChange:function(a,b){var d,c;d="number"===typeof a?a:a?r(a,"length"):a=-1;c="number"===typeof b?b:b?r(b,"length"):b=-1;d=0>c||0>d||0!==c-d;-1===a&&(a=null);-1===b&&(b=null);w(this,"[]");d&&w(this,"length");B(this,"@enumerable:before",[this,a,b]);return this},enumerableContentDidChange:function(a, +b){var d,c;d="number"===typeof a?a:a?r(a,"length"):a=-1;c="number"===typeof b?b:b?r(b,"length"):b=-1;d=0>c||0>d||0!==c-d;-1===a&&(a=null);-1===b&&(b=null);B(this,"@enumerable:change",[this,a,b]);d&&x(this,"length");x(this,"[]");return this},sortBy:function(){var a=arguments;return this.toArray().sort(function(b,d){for(var c=0;ca(this,"length"))throw new g("Index out of range");this.replace(b,0,[d]);return this},removeAt:function(d,c){if("number"===typeof d){if(0>d||d>=a(this,"length"))throw new g("Index out of range");void 0===c&&(c=1);this.replace(d,c,b)}return this},pushObject:function(b){this.insertAt(a(this,"length"),b);return b},pushObjects:function(b){if(!e.detect(b)&&!d(b))throw new TypeError("Must pass Ember.Enumerable to Ember.MutableArray#pushObjects");this.replace(a(this, +"length"),0,b);return this},popObject:function(){var b=a(this,"length");if(0===b)return null;var d=this.objectAt(b-1);this.removeAt(b-1,1);return d},shiftObject:function(){if(0===a(this,"length"))return null;var b=this.objectAt(0);this.removeAt(0);return b},unshiftObject:function(a){this.insertAt(0,a);return a},unshiftObjects:function(a){this.replace(0,0,a);return this},reverseObjects:function(){var b=a(this,"length");if(0===b)return this;var d=this.toArray().reverse();this.replace(0,b,d);return this}, +setObjects:function(b){if(0===b.length)return this.clear();var d=a(this,"length");this.replace(0,d,b);return this},removeObject:function(b){for(var d=a(this,"length")||0;0<=--d;)this.objectAt(d)===b&&this.removeAt(d);return this},addObject:function(a){this.contains(a)||this.pushObject(a);return this}})}); +enifed$$inline_1454("ember-runtime/mixins/mutable_enumerable",["ember-metal/enumerable_utils","ember-runtime/mixins/enumerable","ember-metal/mixin","ember-metal/property_events","exports"],function(c,m,n,k,q){var l=c.forEach;c=n.required;var h=k.beginPropertyChanges,f=k.endPropertyChanges;q["default"]=n.Mixin.create(m["default"],{addObject:c(Function),addObjects:function(b){h(this);l(b,function(a){this.addObject(a)},this);f(this);return this},removeObject:c(Function),removeObjects:function(b){h(this); +for(var a=b.length-1;0<=a;a--)this.removeObject(b[a]);f(this);return this}})}); +enifed$$inline_1454("ember-runtime/mixins/observable","ember-metal/core ember-metal/property_get ember-metal/property_set ember-metal/utils ember-metal/get_properties ember-metal/set_properties ember-metal/mixin ember-metal/events ember-metal/property_events ember-metal/observer ember-metal/computed ember-metal/is_none exports".split(" "),function(c,m,n,k,q,l,h,f,b,a,d,g,e){var s=c["default"],t=m.get,r=m.getWithDefault,v=n.set,y=k.apply,u=q["default"],w=l["default"],x=f.hasListeners,z=b.beginPropertyChanges, +A=b.propertyWillChange,B=b.propertyDidChange,C=b.endPropertyChanges,J=a.addObserver,I=a.addBeforeObserver,K=a.removeObserver,F=a.observersFor,U=d.cacheFor,M=g["default"],G=Array.prototype.slice;e["default"]=h.Mixin.create({get:function(a){return t(this,a)},getProperties:function(){return y(null,u,[this].concat(G.call(arguments)))},set:function(a,b){v(this,a,b);return this},setProperties:function(a){return w(this,a)},beginPropertyChanges:function(){z();return this},endPropertyChanges:function(){C(); +return this},propertyWillChange:function(a){A(this,a);return this},propertyDidChange:function(a){B(this,a);return this},notifyPropertyChange:function(a){this.propertyWillChange(a);this.propertyDidChange(a);return this},addBeforeObserver:function(a,b,d){I(this,a,b,d)},addObserver:function(a,b,d){J(this,a,b,d)},removeObserver:function(a,b,d){K(this,a,b,d)},hasObserverFor:function(a){return x(this,a+":change")},getWithDefault:function(a,b){return r(this,a,b)},incrementProperty:function(a,b){M(b)&&(b= +1);s.assert("Must pass a numeric value to incrementProperty",!isNaN(parseFloat(b))&&isFinite(b));v(this,a,(parseFloat(t(this,a))||0)+b);return t(this,a)},decrementProperty:function(a,b){M(b)&&(b=1);s.assert("Must pass a numeric value to decrementProperty",!isNaN(parseFloat(b))&&isFinite(b));v(this,a,(t(this,a)||0)-b);return t(this,a)},toggleProperty:function(a){v(this,a,!t(this,a));return t(this,a)},cacheFor:function(a){return U(this,a)},observersForKey:function(a){return F(this,a)}})}); +enifed$$inline_1454("ember-runtime/mixins/promise_proxy","ember-metal/property_get ember-metal/set_properties ember-metal/computed ember-metal/mixin ember-metal/error exports".split(" "),function(c,m,n,k,q,l){function h(a){return function(){var b=f(this,"promise");return b[a].apply(b,arguments)}}var f=c.get,b=m["default"];c=n.computed;var a=q["default"];q=c.not;m=c.or;l["default"]=k.Mixin.create({reason:null,isPending:q("isSettled").readOnly(),isSettled:m("isRejected","isFulfilled").readOnly(),isRejected:!1, +isFulfilled:!1,promise:c(function(d,c){if(2===arguments.length){var e=this;b(e,{isFulfilled:!1,isRejected:!1});return c.then(function(a){b(e,{content:a,isFulfilled:!0});return a},function(a){b(e,{reason:a,isRejected:!0});throw a;},"Ember: PromiseProxy")}throw new a("PromiseProxy's promise must be set");}),then:h("then"),"catch":h("catch"),"finally":h("finally")})}); +enifed$$inline_1454("ember-runtime/mixins/sortable","ember-metal/core ember-metal/property_get ember-metal/enumerable_utils ember-metal/mixin ember-runtime/mixins/mutable_enumerable ember-runtime/compare ember-metal/observer ember-metal/computed exports".split(" "),function(c,m,n,k,q,l,h,f,b){var a=c["default"],d=m.get,g=n.forEach,e=h.addObserver,s=h.removeObserver;c=f.computed;m=k.beforeObserver;n=k.observer;b["default"]=k.Mixin.create(q["default"],{sortProperties:null,sortAscending:!0,sortFunction:l["default"], +orderBy:function(b,c){var e=0,f=d(this,"sortProperties"),h=d(this,"sortAscending"),l=d(this,"sortFunction");a.assert("you need to define `sortProperties`",!!f);g(f,function(a){0===e&&(e=l.call(this,d(b,a),d(c,a)),0===e||h||(e*=-1))},this);return e},destroy:function(){var a=d(this,"content"),b=d(this,"sortProperties");a&&b&&g(a,function(a){g(b,function(b){s(a,b,this,"contentItemSortPropertyDidChange")},this)},this);return this._super()},isSorted:c.notEmpty("sortProperties"),arrangedContent:c("content", +"sortProperties.@each",function(){var b=d(this,"content"),c=d(this,"isSorted"),f=d(this,"sortProperties"),h=this;return b&&c?(b=b.slice(),b.sort(function(a,b){return h.orderBy(a,b)}),g(b,function(a){g(f,function(b){e(a,b,this,"contentItemSortPropertyDidChange")},this)},this),a.A(b)):b}),_contentWillChange:m("content",function(){var a=d(this,"content"),b=d(this,"sortProperties");a&&b&&g(a,function(a){g(b,function(b){s(a,b,this,"contentItemSortPropertyDidChange")},this)},this);this._super()}),sortPropertiesWillChange:m("sortProperties", +function(){this._lastSortAscending=void 0}),sortPropertiesDidChange:n("sortProperties",function(){this._lastSortAscending=void 0}),sortAscendingWillChange:m("sortAscending",function(){this._lastSortAscending=d(this,"sortAscending")}),sortAscendingDidChange:n("sortAscending",function(){void 0!==this._lastSortAscending&&d(this,"sortAscending")!==this._lastSortAscending&&d(this,"arrangedContent").reverseObjects()}),contentArrayWillChange:function(a,b,c,e){if(d(this,"isSorted")){var f=d(this,"arrangedContent"), +h=a.slice(b,b+c),l=d(this,"sortProperties");g(h,function(a){f.removeObject(a);g(l,function(b){s(a,b,this,"contentItemSortPropertyDidChange")},this)},this)}return this._super(a,b,c,e)},contentArrayDidChange:function(a,b,c,f){var h=d(this,"isSorted"),l=d(this,"sortProperties");h&&(h=a.slice(b,b+f),g(h,function(a){this.insertItemSorted(a);g(l,function(b){e(a,b,this,"contentItemSortPropertyDidChange")},this)},this));return this._super(a,b,c,f)},insertItemSorted:function(a){var b=d(this,"arrangedContent"), +c=d(b,"length"),c=this._binarySearch(a,0,c);b.insertAt(c,a)},contentItemSortPropertyDidChange:function(a){var b=d(this,"arrangedContent"),c=b.indexOf(a),e=b.objectAt(c-1),c=b.objectAt(c+1),e=e&&this.orderBy(a,e),c=c&&this.orderBy(a,c);if(0>e||0g?this._binarySearch(a,e+1,c):0t(this,"content.length"))throw new w("Index out of range");this._replace(a,0,[b]);return this},insertAt:function(a,b){if(t(this,"arrangedContent")===t(this,"content"))return this._insertAt(a,b);throw new w("Using insertAt on an arranged ArrayProxy is not allowed.");},removeAt:function(a,b){if("number"===typeof a){var d=t(this,"content"),c=t(this,"arrangedContent"),e=[],g;if(0>a||a>=t(this,"length"))throw new w("Index out of range");void 0===b&&(b=1);for(g=a;g";this.toString=function(){return b};return b}});k.PrototypeMixin.ownerConstructor=k;w.config.overridePrototypeMixin&&w.config.overridePrototypeMixin(k.PrototypeMixin);k.__super__=null;r={ClassMixin:m(),PrototypeMixin:m(),isClass:!0,isMethod:!1,extend:function(){var a=u(),b;a.ClassMixin=G.create(this.ClassMixin);a.PrototypeMixin=G.create(this.PrototypeMixin);a.ClassMixin.ownerConstructor=a;a.PrototypeMixin.ownerConstructor=a;fa.apply(a.PrototypeMixin,arguments);a.superclass=this;a.__super__=this.prototype; +b=a.prototype=B(this.prototype);b.constructor=a;C(b);I(b).proto=b;a.ClassMixin.apply(a);return a},createWithMixins:function(){var a=arguments.length;if(0=c;)if(f=a.objectAt(e))r.assert("When using @each to observe the array "+ +a+", the array must return an object","instance"===C(f)||"object"===C(f)),z(f,b,d,"contentKeyWillChange"),x(f,b,d,"contentKeyDidChange"),f=y(f),g[f]||(g[f]=[]),g[f].push(e)}function t(a,b,d,c,e){var g=d._objects;g||(g=d._objects={});for(var f;--e>=c;)if(f=a.objectAt(e))A(f,b,d,"contentKeyWillChange"),B(f,b,d,"contentKeyDidChange"),f=y(f),f=g[f],f[w.call(f,e)]=null}var r=c["default"],v=m.get,y=n.guidFor,u=k.forEach,w=q.indexOf;c=h["default"];f=f.computed;var x=b.addObserver,z=b.addBeforeObserver,A= +b.removeBeforeObserver,B=b.removeObserver,C=n.typeOf,J=a.watchedEvents,I=d.defineProperty,K=g.beginPropertyChanges,F=g.propertyDidChange,U=g.propertyWillChange,M=g.endPropertyChanges,G=g.changeProperties,L=c.extend(l["default"],{init:function(a,b,d){this._super();this._keyName=b;this._owner=d;this._content=a},objectAt:function(a){return(a=this._content.objectAt(a))&&v(a,this._keyName)},length:f(function(){var a=this._content;return a?v(a,"length"):0})}),P=/^.+:(before|change)$/;n=c.extend({init:function(a){this._super(); +this._content=a;a.addArrayObserver(this);u(J(this),function(a){this.didAddListener(a)},this)},unknownProperty:function(a){var b;b=new L(this._content,a,this);I(this,a,null,b);this.beginObservingContentKey(a);return b},arrayWillChange:function(a,b,d){var c=this._keys,e;d=0=--b[a]){var b=this._content,d=v(b,"length"); +t(b,a,this,0,d)}},contentKeyWillChange:function(a,b){U(this,b)},contentKeyDidChange:function(a,b){F(this,b)}});e.EachArray=L;e.EachProxy=n}); +enifed$$inline_1454("ember-runtime/system/lazy_load",["ember-metal/core","ember-metal/array","ember-runtime/system/native_array","exports"],function(c,m,n,k){var q=c["default"],l=m.forEach,h=q.ENV.EMBER_LOAD_HOOKS||{},f={};k.onLoad=function(b,a){var d;h[b]=h[b]||q.A();h[b].pushObject(a);(d=f[b])&&a(d)};k.runLoadHooks=function(b,a){f[b]=a;if("object"===typeof window&&"function"===typeof window.dispatchEvent&&"function"===typeof CustomEvent){var d=new CustomEvent(b,{detail:a,name:b});window.dispatchEvent(d)}h[b]&& +l.call(h[b],function(b){b(a)})}}); +enifed$$inline_1454("ember-runtime/system/namespace","ember-metal/core ember-metal/property_get ember-metal/array ember-metal/utils ember-metal/mixin ember-runtime/system/object exports".split(" "),function(c,m,n,k,q,l,h){function f(a,b,c){var g=a.length;u[a.join(".")]=b;for(var h in b)if(w.call(b,h)){var l=b[h];a[g]=h;l&&l.toString===d?(l.toString=e(a.join(".")),l[z]=a.join(".")):l&&l.isNamespace&&!c[v(l)]&&(c[v(l)]=!0,f(a,l,c))}a.length=g}function b(){var a=s.lookup,b;if(!y.PROCESSED)for(var d in a)if(x.test(d)&& +(!a.hasOwnProperty||a.hasOwnProperty(d))){a:{try{var c=a[d];b=c&&c.isNamespace&&c;break a}catch(e){}b=void 0}b&&(b[z]=d)}}function a(b){if(b=b.superclass)return b[z]?b[z]:a(b)}function d(){s.BOOTED||this[z]||g();var b;this[z]?b=this[z]:this._toString?b=this._toString:(b=(b=a(this))?"(subclass of "+b+")":"(unknown mixin)",this.toString=e(b));return b}function g(){var a=!y.PROCESSED,d=s.anyUnprocessedMixins;a&&(b(),y.PROCESSED=!0);if(a||d){for(var a=y.NAMESPACES,c=0,e=a.length;c",[d.join(",")])}})}); +enifed$$inline_1454("ember-runtime/system/string",["ember-metal/core","ember-metal/utils","ember-metal/cache","exports"],function(c,m,n,k){function q(a,b){var d=b;if(!t(d)||2arguments.length&&(b=0);this._operations=0=k&&b<=m){a(l,e,k,m,c);return}l.type===f&&(c+=l.count)}d(c)},_composeAt:function(b){var a=this._operations[b],d;a&&(0arguments.length&&(a=[]);var d=h(a,"length");this._operations=d?[new q(b,d,a)]:[]}function q(a,b,c){this.type=a;this.count=b;this.items=c}function l(a,b,c,e){this.operation=a;this.index=b;this.split=c;this.rangeStart=e}var h=c.get,f=m.forEach,b="r";n["default"]=k;k.RETAIN=b;k.INSERT="i";k.DELETE="d";k.prototype={addItems:function(a,b){var c= +h(b,"length");if(!(1>c)){var e=this._findArrayOperation(a),f=e.operation,l=e.index,k=e.rangeStart,c=new q("i",c,b);f?e.split?(this._split(l,a-k,c),e=l+1):(this._operations.splice(l,0,c),e=l):(this._operations.push(c),e=l);this._composeInsert(e)}},removeItems:function(a,b){if(!(1>b)){var c=this._findArrayOperation(a),e=c.index,f=c.rangeStart,h;h=new q("d",b);c.split?(this._split(e,a-f,h),c=e+1):(this._operations.splice(e,0,h),c=e);return this._composeDelete(c)}},apply:function(a){var d=[],c=0;f(this._operations, +function(b,f){a(b.items,c,b.type,f);"d"!==b.type&&(c+=b.count,d=d.concat(b.items))});this._operations=[new q(b,d.length,d)]},_findArrayOperation:function(a){var b=!1,c,e,f,h,k;c=f=0;for(k=this._operations.length;cf&&a<=h){b=!0;break}else f=h+1;return new l(e,c,b,f)},_split:function(a,b,c){var e=this._operations[a],f=e.items.slice(b),f=new q(e.type,f.length,f);e.count=b;e.items=e.items.slice(0,b);this._operations.splice(a+ +1,0,c,f)},_composeInsert:function(a){var b=this._operations[a],c=this._operations[a-1],e=this._operations[a+1],f=e&&e.type;"i"===(c&&c.type)?(c.count+=b.count,c.items=c.items.concat(b.items),"i"===f?(c.count+=e.count,c.items=c.items.concat(e.items),this._operations.splice(a,2)):this._operations.splice(a,1)):"i"===f&&(b.count+=e.count,b.items=b.items.concat(e.items),this._operations.splice(a+1,1))},_composeDelete:function(a){var b=this._operations[a],c=b.count,e=this._operations[a-1],f,h,l=!1,k=[]; +"d"===(e&&e.type)&&(b=e,a-=1);for(var m=a+1;0c?(k=k.concat(e.items.splice(0,c)),e.count-=c,m-=1,h=c,c=0):(h===c&&(l=!0),k=k.concat(e.items),c-=h),"i"===f&&(b.count-=h));0').css({position:"absolute",left:"-1000px",top:"-1000px"}).appendTo("body").on("click",c).trigger("click").remove()}var k=c["default"],q=m["default"];q(function(){n(function(){this.checked||q.event.special.click||(q.event.special.click={trigger:function(){if(q.nodeName(this,"input")&&"checkbox"===this.type&&this.click)return this.click(),!1}})});n(function(){k.warn("clicked checkboxes should be checked! the jQuery patch didn't work", +this.checked)})})}); +enifed$$inline_1454("ember-testing/test","ember-metal/core ember-metal/run_loop ember-metal/platform ember-runtime/compare ember-runtime/ext/rsvp ember-testing/setup_for_testing ember-application/system/application exports".split(" "),function(c,m,n,k,q,l,h,f){function b(a,b){var d=v[b].method,c=v[b].meta;return function(){var b=r.call(arguments),e=u.lastPromise;b.unshift(a);if(!c.wait)return d.apply(a,b);if(e){var f=function(){e=u.resolve(e).then(function(){return d.apply(a,b)})};g.currentRunLoop? +f():g(f)}else e=d.apply(a,b);return e}}function a(a,b,d,c){a[b]=function(){var a=arguments;return c?d.apply(this,a):this.then(function(){return d.apply(this,a)})}}var d=c["default"],g=m["default"];c=n.create;var e=k["default"],s=q["default"],t=l["default"],r=[].slice,v={},y=[],u={_helpers:v,registerHelper:function(a,b){v[a]={method:b,meta:{wait:!1}}},registerAsyncHelper:function(a,b){v[a]={method:b,meta:{wait:!0}}},unregisterHelper:function(a){delete v[a];delete u.Promise.prototype[a]},onInjectHelpers:function(a){y.push(a)}, +promise:function(a){return new u.Promise(a)},adapter:null,resolve:function(a){return u.promise(function(b){return b(a)})},registerWaiter:function(a,b){1===arguments.length&&(b=a,a=null);this.waiters||(this.waiters=d.A());this.waiters.push([a,b])},unregisterWaiter:function(a,b){var c;this.waiters&&(1===arguments.length&&(b=a,a=null),c=[a,b],this.waiters=d.A(this.waiters.filter(function(a){return 0!==e(a,c)})))}};h["default"].reopen({testHelpers:{},originalMethods:{},testing:!1,setupForTesting:function(){t(); +this.testing=!0;this.Router.reopen({location:"none"})},helperContainer:window,injectTestHelpers:function(d){d&&(this.helperContainer=d);this.testHelpers={};for(var c in v)this.originalMethods[c]=this.helperContainer[c],this.testHelpers[c]=this.helperContainer[c]=b(this,c),a(u.Promise.prototype,c,b(this,c),v[c].meta.wait);d=0;for(c=y.length;d"'`]/g,v=/[&<>"'`]/,y;c=document.createElement("div");m=document.createElement("input");m.setAttribute("name","foo");c.appendChild(m);y=!!c.innerHTML.match("foo");q["default"]=function(a,b){return new h(a,b)};h.prototype={reset:function(a,b){this.tagName=a;this._element=this.buffer=null;this._outerContextualElement=b;this.elementStyle=this.elementTag=this.elementProperties= +this.elementAttributes=this.elementId=this.elementClasses=null;this.childViews.length=0},_element:null,_outerContextualElement:null,elementClasses:null,classes:null,elementId:null,elementAttributes:null,elementProperties:null,elementTag:null,elementStyle:null,pushChildView:function(a){var b=this.childViews.length;this.childViews[b]=a;this.push(" + ``` + + And associate it by name using a view's `templateName` property: + + ```javascript + AView = Ember.View.extend({ + templateName: 'some-template' + }); + ``` + + If you have nested resources, your Handlebars template will look like this: + + ```html + + ``` + + And `templateName` property: + + ```javascript + AView = Ember.View.extend({ + templateName: 'posts/new' + }); + ``` + + Using a value for `templateName` that does not have a Handlebars template + with a matching `data-template-name` attribute will throw an error. + + For views classes that may have a template later defined (e.g. as the block + portion of a `{{view}}` Handlebars helper call in another template or in + a subclass), you can provide a `defaultTemplate` property set to compiled + template function. If a template is not later provided for the view instance + the `defaultTemplate` value will be used: + + ```javascript + AView = Ember.View.extend({ + defaultTemplate: Ember.Handlebars.compile('I was the default'), + template: null, + templateName: null + }); + ``` + + Will result in instances with an HTML representation of: + + ```html +
I was the default
+ ``` + + If a `template` or `templateName` is provided it will take precedence over + `defaultTemplate`: + + ```javascript + AView = Ember.View.extend({ + defaultTemplate: Ember.Handlebars.compile('I was the default') + }); + + aView = AView.create({ + template: Ember.Handlebars.compile('I was the template, not default') + }); + ``` + + Will result in the following HTML representation when rendered: + + ```html +
I was the template, not default
+ ``` + + ## View Context + + The default context of the compiled template is the view's controller: + + ```javascript + AView = Ember.View.extend({ + template: Ember.Handlebars.compile('Hello {{excitedGreeting}}') + }); + + aController = Ember.Object.create({ + firstName: 'Barry', + excitedGreeting: function() { + return this.get("content.firstName") + "!!!" + }.property() + }); + + aView = AView.create({ + controller: aController + }); + ``` + + Will result in an HTML representation of: + + ```html +
Hello Barry!!!
+ ``` + + A context can also be explicitly supplied through the view's `context` + property. If the view has neither `context` nor `controller` properties, the + `parentView`'s context will be used. + + ## Layouts + + Views can have a secondary template that wraps their main template. Like + primary templates, layouts can be any function that accepts an optional + context parameter and returns a string of HTML that will be inserted inside + view's tag. Views whose HTML element is self closing (e.g. ``) + cannot have a layout and this property will be ignored. + + Most typically in Ember a layout will be a compiled `Ember.Handlebars` + template. + + A view's layout can be set directly with the `layout` property or reference + an existing Handlebars template by name with the `layoutName` property. + + A template used as a layout must contain a single use of the Handlebars + `{{yield}}` helper. The HTML contents of a view's rendered `template` will be + inserted at this location: + + ```javascript + AViewWithLayout = Ember.View.extend({ + layout: Ember.Handlebars.compile("
{{yield}}
"), + template: Ember.Handlebars.compile("I got wrapped") + }); + ``` + + Will result in view instances with an HTML representation of: + + ```html +
+
+ I got wrapped +
+
+ ``` + + See [Ember.Handlebars.helpers.yield](/api/classes/Ember.Handlebars.helpers.html#method_yield) + for more information. + + ## Responding to Browser Events + + Views can respond to user-initiated events in one of three ways: method + implementation, through an event manager, and through `{{action}}` helper use + in their template or layout. + + ### Method Implementation + + Views can respond to user-initiated events by implementing a method that + matches the event name. A `jQuery.Event` object will be passed as the + argument to this method. + + ```javascript + AView = Ember.View.extend({ + click: function(event) { + // will be called when when an instance's + // rendered element is clicked + } + }); + ``` + + ### Event Managers + + Views can define an object as their `eventManager` property. This object can + then implement methods that match the desired event names. Matching events + that occur on the view's rendered HTML or the rendered HTML of any of its DOM + descendants will trigger this method. A `jQuery.Event` object will be passed + as the first argument to the method and an `Ember.View` object as the + second. The `Ember.View` will be the view whose rendered HTML was interacted + with. This may be the view with the `eventManager` property or one of its + descendent views. + + ```javascript + AView = Ember.View.extend({ + eventManager: Ember.Object.create({ + doubleClick: function(event, view) { + // will be called when when an instance's + // rendered element or any rendering + // of this views's descendent + // elements is clicked + } + }) + }); + ``` + + An event defined for an event manager takes precedence over events of the + same name handled through methods on the view. + + ```javascript + AView = Ember.View.extend({ + mouseEnter: function(event) { + // will never trigger. + }, + eventManager: Ember.Object.create({ + mouseEnter: function(event, view) { + // takes precedence over AView#mouseEnter + } + }) + }); + ``` + + Similarly a view's event manager will take precedence for events of any views + rendered as a descendent. A method name that matches an event name will not + be called if the view instance was rendered inside the HTML representation of + a view that has an `eventManager` property defined that handles events of the + name. Events not handled by the event manager will still trigger method calls + on the descendent. + + ```javascript + var App = Ember.Application.create(); + App.OuterView = Ember.View.extend({ + template: Ember.Handlebars.compile("outer {{#view 'inner'}}inner{{/view}} outer"), + eventManager: Ember.Object.create({ + mouseEnter: function(event, view) { + // view might be instance of either + // OuterView or InnerView depending on + // where on the page the user interaction occured + } + }) + }); + + App.InnerView = Ember.View.extend({ + click: function(event) { + // will be called if rendered inside + // an OuterView because OuterView's + // eventManager doesn't handle click events + }, + mouseEnter: function(event) { + // will never be called if rendered inside + // an OuterView. + } + }); + ``` + + ### Handlebars `{{action}}` Helper + + See [Handlebars.helpers.action](/api/classes/Ember.Handlebars.helpers.html#method_action). + + ### Event Names + + All of the event handling approaches described above respond to the same set + of events. The names of the built-in events are listed below. (The hash of + built-in events exists in `Ember.EventDispatcher`.) Additional, custom events + can be registered by using `Ember.Application.customEvents`. + + Touch events: + + * `touchStart` + * `touchMove` + * `touchEnd` + * `touchCancel` + + Keyboard events + + * `keyDown` + * `keyUp` + * `keyPress` + + Mouse events + + * `mouseDown` + * `mouseUp` + * `contextMenu` + * `click` + * `doubleClick` + * `mouseMove` + * `focusIn` + * `focusOut` + * `mouseEnter` + * `mouseLeave` + + Form events: + + * `submit` + * `change` + * `focusIn` + * `focusOut` + * `input` + + HTML5 drag and drop events: + + * `dragStart` + * `drag` + * `dragEnter` + * `dragLeave` + * `dragOver` + * `dragEnd` + * `drop` + + ## Handlebars `{{view}}` Helper + + Other `Ember.View` instances can be included as part of a view's template by + using the `{{view}}` Handlebars helper. See [Ember.Handlebars.helpers.view](/api/classes/Ember.Handlebars.helpers.html#method_view) + for additional information. + + @class View + @namespace Ember + @extends Ember.CoreView + */ + var View = CoreView.extend({ + + concatenatedProperties: ['classNames', 'classNameBindings', 'attributeBindings'], + + /** + @property isView + @type Boolean + @default true + @static + */ + isView: true, + + // .......................................................... + // TEMPLATE SUPPORT + // + + /** + The name of the template to lookup if no template is provided. + + By default `Ember.View` will lookup a template with this name in + `Ember.TEMPLATES` (a shared global object). + + @property templateName + @type String + @default null + */ + templateName: null, + + /** + The name of the layout to lookup if no layout is provided. + + By default `Ember.View` will lookup a template with this name in + `Ember.TEMPLATES` (a shared global object). + + @property layoutName + @type String + @default null + */ + layoutName: null, + + /** + Used to identify this view during debugging + + @property instrumentDisplay + @type String + */ + instrumentDisplay: computed(function() { + if (this.helperName) { + return '{{' + this.helperName + '}}'; + } + }), + + /** + The template used to render the view. This should be a function that + accepts an optional context parameter and returns a string of HTML that + will be inserted into the DOM relative to its parent view. + + In general, you should set the `templateName` property instead of setting + the template yourself. + + @property template + @type Function + */ + template: computed('templateName', function(key, value) { + if (value !== undefined) { return value; } + + var templateName = get(this, 'templateName'); + var template = this.templateForName(templateName, 'template'); + + Ember.assert("You specified the templateName " + templateName + " for " + this + ", but it did not exist.", !templateName || template); + + return template || get(this, 'defaultTemplate'); + }), + + /** + The controller managing this view. If this property is set, it will be + made available for use by the template. + + @property controller + @type Object + */ + controller: computed('_parentView', function(key) { + var parentView = get(this, '_parentView'); + return parentView ? get(parentView, 'controller') : null; + }), + + /** + A view may contain a layout. A layout is a regular template but + supersedes the `template` property during rendering. It is the + responsibility of the layout template to retrieve the `template` + property from the view (or alternatively, call `Handlebars.helpers.yield`, + `{{yield}}`) to render it in the correct location. + + This is useful for a view that has a shared wrapper, but which delegates + the rendering of the contents of the wrapper to the `template` property + on a subclass. + + @property layout + @type Function + */ + layout: computed(function(key) { + var layoutName = get(this, 'layoutName'); + var layout = this.templateForName(layoutName, 'layout'); + + Ember.assert("You specified the layoutName " + layoutName + " for " + this + ", but it did not exist.", !layoutName || layout); + + return layout || get(this, 'defaultLayout'); + }).property('layoutName'), + + _yield: function(context, options) { + var template = get(this, 'template'); + if (template) { template(context, options); } + }, + + templateForName: function(name, type) { + if (!name) { return; } + Ember.assert("templateNames are not allowed to contain periods: "+name, name.indexOf('.') === -1); + + if (!this.container) { + throw new EmberError('Container was not found when looking up a views template. ' + + 'This is most likely due to manually instantiating an Ember.View. ' + + 'See: http://git.io/EKPpnA'); + } + + return this.container.lookup('template:' + name); + }, + + /** + The object from which templates should access properties. + + This object will be passed to the template function each time the render + method is called, but it is up to the individual function to decide what + to do with it. + + By default, this will be the view's controller. + + @property context + @type Object + */ + context: computed(function(key, value) { + if (arguments.length === 2) { + set(this, '_context', value); + return value; + } else { + return get(this, '_context'); + } + })["volatile"](), + + /** + Private copy of the view's template context. This can be set directly + by Handlebars without triggering the observer that causes the view + to be re-rendered. + + The context of a view is looked up as follows: + + 1. Supplied context (usually by Handlebars) + 2. Specified controller + 3. `parentView`'s context (for a child of a ContainerView) + + The code in Handlebars that overrides the `_context` property first + checks to see whether the view has a specified controller. This is + something of a hack and should be revisited. + + @property _context + @private + */ + _context: computed(function(key) { + var parentView, controller; + + if (controller = get(this, 'controller')) { + return controller; + } + + parentView = this._parentView; + if (parentView) { + return get(parentView, '_context'); + } + + return null; + }), + + /** + If a value that affects template rendering changes, the view should be + re-rendered to reflect the new value. + + @method _contextDidChange + @private + */ + _contextDidChange: observer('context', function() { + this.rerender(); + }), + + /** + If `false`, the view will appear hidden in DOM. + + @property isVisible + @type Boolean + @default null + */ + isVisible: true, + + /** + Array of child views. You should never edit this array directly. + Instead, use `appendChild` and `removeFromParent`. + + @property childViews + @type Array + @default [] + @private + */ + childViews: childViewsProperty, + + _childViews: EMPTY_ARRAY, + + // When it's a virtual view, we need to notify the parent that their + // childViews will change. + _childViewsWillChange: beforeObserver('childViews', function() { + if (this.isVirtual) { + var parentView = get(this, 'parentView'); + if (parentView) { propertyWillChange(parentView, 'childViews'); } + } + }), + + // When it's a virtual view, we need to notify the parent that their + // childViews did change. + _childViewsDidChange: observer('childViews', function() { + if (this.isVirtual) { + var parentView = get(this, 'parentView'); + if (parentView) { propertyDidChange(parentView, 'childViews'); } + } + }), + + /** + Return the nearest ancestor that is an instance of the provided + class. + + @method nearestInstanceOf + @param {Class} klass Subclass of Ember.View (or Ember.View itself) + @return Ember.View + @deprecated + */ + nearestInstanceOf: function(klass) { + Ember.deprecate("nearestInstanceOf is deprecated and will be removed from future releases. Use nearestOfType."); + var view = get(this, 'parentView'); + + while (view) { + if (view instanceof klass) { return view; } + view = get(view, 'parentView'); + } + }, + + /** + Return the nearest ancestor that is an instance of the provided + class or mixin. + + @method nearestOfType + @param {Class,Mixin} klass Subclass of Ember.View (or Ember.View itself), + or an instance of Ember.Mixin. + @return Ember.View + */ + nearestOfType: function(klass) { + var view = get(this, 'parentView'); + var isOfType = klass instanceof Mixin ? + function(view) { return klass.detect(view); } : + function(view) { return klass.detect(view.constructor); }; + + while (view) { + if (isOfType(view)) { return view; } + view = get(view, 'parentView'); + } + }, + + /** + Return the nearest ancestor that has a given property. + + @method nearestWithProperty + @param {String} property A property name + @return Ember.View + */ + nearestWithProperty: function(property) { + var view = get(this, 'parentView'); + + while (view) { + if (property in view) { return view; } + view = get(view, 'parentView'); + } + }, + + /** + Return the nearest ancestor whose parent is an instance of + `klass`. + + @method nearestChildOf + @param {Class} klass Subclass of Ember.View (or Ember.View itself) + @return Ember.View + */ + nearestChildOf: function(klass) { + var view = get(this, 'parentView'); + + while (view) { + if (get(view, 'parentView') instanceof klass) { return view; } + view = get(view, 'parentView'); + } + }, + + /** + When the parent view changes, recursively invalidate `controller` + + @method _parentViewDidChange + @private + */ + _parentViewDidChange: observer('_parentView', function() { + if (this.isDestroying) { return; } + + this._setupKeywords(); + this.trigger('parentViewDidChange'); + + if (get(this, 'parentView.controller') && !get(this, 'controller')) { + this.notifyPropertyChange('controller'); + } + }), + + _controllerDidChange: observer('controller', function() { + if (this.isDestroying) { return; } + + this.rerender(); + + this.forEachChildView(function(view) { + view.propertyDidChange('controller'); + }); + }), + + _setupKeywords: function() { + var keywords = this._keywords; + var contextView = this._contextView || this._parentView; + + if (contextView) { + var parentKeywords = contextView._keywords; + + keywords.view.setSource(this.isVirtual ? parentKeywords.view : this); + + for (var name in parentKeywords) { + if (keywords[name]) continue; + keywords[name] = parentKeywords[name]; + } + } else { + keywords.view.setSource(this.isVirtual ? null : this); + } + }, + + /** + Called on your view when it should push strings of HTML into a + `Ember.RenderBuffer`. Most users will want to override the `template` + or `templateName` properties instead of this method. + + By default, `Ember.View` will look for a function in the `template` + property and invoke it with the value of `context`. The value of + `context` will be the view's controller unless you override it. + + @method render + @param {Ember.RenderBuffer} buffer The render buffer + */ + render: function(buffer) { + // If this view has a layout, it is the responsibility of the + // the layout to render the view's template. Otherwise, render the template + // directly. + var template = get(this, 'layout') || get(this, 'template'); + + if (template) { + var context = get(this, 'context'); + var output; + + var data = { + view: this, + buffer: buffer, + isRenderData: true + }; + + // Invoke the template with the provided template context, which + // is the view's controller by default. A hash of data is also passed that provides + // the template with access to the view and render buffer. + + Ember.assert('template must be a function. Did you mean to call Ember.Handlebars.compile("...") or specify templateName instead?', typeof template === 'function'); + // The template should write directly to the render buffer instead + // of returning a string. + output = template(context, { data: data }); + + // If the template returned a string instead of writing to the buffer, + // push the string onto the buffer. + if (output !== undefined) { buffer.push(output); } + } + }, + + /** + Renders the view again. This will work regardless of whether the + view is already in the DOM or not. If the view is in the DOM, the + rendering process will be deferred to give bindings a chance + to synchronize. + + If children were added during the rendering process using `appendChild`, + `rerender` will remove them, because they will be added again + if needed by the next `render`. + + In general, if the display of your view changes, you should modify + the DOM element directly instead of manually calling `rerender`, which can + be slow. + + @method rerender + */ + rerender: function() { + return this.currentState.rerender(this); + }, + + /** + Iterates over the view's `classNameBindings` array, inserts the value + of the specified property into the `classNames` array, then creates an + observer to update the view's element if the bound property ever changes + in the future. + + @method _applyClassNameBindings + @private + */ + _applyClassNameBindings: function(classBindings) { + var classNames = this.classNames; + var elem, newClass, dasherizedClass; + + // Loop through all of the configured bindings. These will be either + // property names ('isUrgent') or property paths relative to the view + // ('content.isUrgent') + forEach(classBindings, function(binding) { + + var parsedPath; + + if (typeof binding === 'string') { + Ember.assert("classNameBindings must not have spaces in them. Multiple class name bindings can be provided as elements of an array, e.g. ['foo', ':bar']", binding.indexOf(' ') === -1); + parsedPath = View._parsePropertyPath(binding); + if (parsedPath.path === '') { + parsedPath.stream = new SimpleStream(true); + } else { + parsedPath.stream = this.getStream('_view.' + parsedPath.path); + } + } else { + parsedPath = binding; + } + + // Variable in which the old class value is saved. The observer function + // closes over this variable, so it knows which string to remove when + // the property changes. + var oldClass; + + // Set up an observer on the context. If the property changes, toggle the + // class name. + var observer = this._wrapAsScheduled(function() { + // Get the current value of the property + newClass = this._classStringForProperty(parsedPath); + elem = this.$(); + + // If we had previously added a class to the element, remove it. + if (oldClass) { + elem.removeClass(oldClass); + // Also remove from classNames so that if the view gets rerendered, + // the class doesn't get added back to the DOM. + classNames.removeObject(oldClass); + } + + // If necessary, add a new class. Make sure we keep track of it so + // it can be removed in the future. + if (newClass) { + elem.addClass(newClass); + oldClass = newClass; + } else { + oldClass = null; + } + }); + + // Get the class name for the property at its current value + dasherizedClass = this._classStringForProperty(parsedPath); + + if (dasherizedClass) { + // Ensure that it gets into the classNames array + // so it is displayed when we render. + addObject(classNames, dasherizedClass); + + // Save a reference to the class name so we can remove it + // if the observer fires. Remember that this variable has + // been closed over by the observer. + oldClass = dasherizedClass; + } + + parsedPath.stream.subscribe(observer, this); + // Remove className so when the view is rerendered, + // the className is added based on binding reevaluation + this.one('willClearRender', function() { + if (oldClass) { + classNames.removeObject(oldClass); + oldClass = null; + } + }); + + }, this); + }, + + _unspecifiedAttributeBindings: null, + + /** + Iterates through the view's attribute bindings, sets up observers for each, + then applies the current value of the attributes to the passed render buffer. + + @method _applyAttributeBindings + @param {Ember.RenderBuffer} buffer + @private + */ + _applyAttributeBindings: function(buffer, attributeBindings) { + var attributeValue; + var unspecifiedAttributeBindings = this._unspecifiedAttributeBindings = this._unspecifiedAttributeBindings || {}; + + forEach(attributeBindings, function(binding) { + var split = binding.split(':'); + var property = split[0]; + var attributeName = split[1] || property; + + Ember.assert('You cannot use class as an attributeBinding, use classNameBindings instead.', attributeName !== 'class'); + + if (property in this) { + this._setupAttributeBindingObservation(property, attributeName); + + // Determine the current value and add it to the render buffer + // if necessary. + attributeValue = get(this, property); + View.applyAttributeBindings(buffer, attributeName, attributeValue); + } else { + unspecifiedAttributeBindings[property] = attributeName; + } + }, this); + + // Lazily setup setUnknownProperty after attributeBindings are initially applied + this.setUnknownProperty = this._setUnknownProperty; + }, + + _setupAttributeBindingObservation: function(property, attributeName) { + var attributeValue, elem; + + // Create an observer to add/remove/change the attribute if the + // JavaScript property changes. + var observer = function() { + elem = this.$(); + + attributeValue = get(this, property); + + View.applyAttributeBindings(elem, attributeName, attributeValue); + }; + + this.registerObserver(this, property, observer); + }, + + /** + We're using setUnknownProperty as a hook to setup attributeBinding observers for + properties that aren't defined on a view at initialization time. + + Note: setUnknownProperty will only be called once for each property. + + @method setUnknownProperty + @param key + @param value + @private + */ + setUnknownProperty: null, // Gets defined after initialization by _applyAttributeBindings + + _setUnknownProperty: function(key, value) { + var attributeName = this._unspecifiedAttributeBindings && this._unspecifiedAttributeBindings[key]; + if (attributeName) { + this._setupAttributeBindingObservation(key, attributeName); + } + + defineProperty(this, key); + return set(this, key, value); + }, + + /** + Given a property name, returns a dasherized version of that + property name if the property evaluates to a non-falsy value. + + For example, if the view has property `isUrgent` that evaluates to true, + passing `isUrgent` to this method will return `"is-urgent"`. + + @method _classStringForProperty + @param property + @private + */ + _classStringForProperty: function(parsedPath) { + return View._classStringForValue(parsedPath.path, parsedPath.stream.value(), parsedPath.className, parsedPath.falsyClassName); + }, + + // .......................................................... + // ELEMENT SUPPORT + // + + /** + Returns the current DOM element for the view. + + @property element + @type DOMElement + */ + element: null, + + /** + Returns a jQuery object for this view's element. If you pass in a selector + string, this method will return a jQuery object, using the current element + as its buffer. + + For example, calling `view.$('li')` will return a jQuery object containing + all of the `li` elements inside the DOM element of this view. + + @method $ + @param {String} [selector] a jQuery-compatible selector string + @return {jQuery} the jQuery object for the DOM node + */ + $: function(sel) { + return this.currentState.$(this, sel); + }, + + mutateChildViews: function(callback) { + var childViews = this._childViews; + var idx = childViews.length; + var view; + + while(--idx >= 0) { + view = childViews[idx]; + callback(this, view, idx); + } + + return this; + }, + + forEachChildView: function(callback) { + var childViews = this._childViews; + + if (!childViews) { return this; } + + var len = childViews.length; + var view, idx; + + for (idx = 0; idx < len; idx++) { + view = childViews[idx]; + callback(view); + } + + return this; + }, + + /** + Appends the view's element to the specified parent element. + + If the view does not have an HTML representation yet, `createElement()` + will be called automatically. + + Note that this method just schedules the view to be appended; the DOM + element will not be appended to the given element until all bindings have + finished synchronizing. + + This is not typically a function that you will need to call directly when + building your application. You might consider using `Ember.ContainerView` + instead. If you do need to use `appendTo`, be sure that the target element + you are providing is associated with an `Ember.Application` and does not + have an ancestor element that is associated with an Ember view. + + @method appendTo + @param {String|DOMElement|jQuery} A selector, element, HTML string, or jQuery object + @return {Ember.View} receiver + */ + appendTo: function(selector) { + var target = jQuery(selector); + + Ember.assert("You tried to append to (" + selector + ") but that isn't in the DOM", target.length > 0); + Ember.assert("You cannot append to an existing Ember.View. Consider using Ember.ContainerView instead.", !target.is('.ember-view') && !target.parents().is('.ember-view')); + + this.constructor.renderer.appendTo(this, target[0]); + + return this; + }, + + /** + Replaces the content of the specified parent element with this view's + element. If the view does not have an HTML representation yet, + `createElement()` will be called automatically. + + Note that this method just schedules the view to be appended; the DOM + element will not be appended to the given element until all bindings have + finished synchronizing + + @method replaceIn + @param {String|DOMElement|jQuery} target A selector, element, HTML string, or jQuery object + @return {Ember.View} received + */ + replaceIn: function(selector) { + var target = jQuery(selector); + + Ember.assert("You tried to replace in (" + selector + ") but that isn't in the DOM", target.length > 0); + Ember.assert("You cannot replace an existing Ember.View. Consider using Ember.ContainerView instead.", !target.is('.ember-view') && !target.parents().is('.ember-view')); + + this.constructor.renderer.replaceIn(this, target[0]); + + return this; + }, + + /** + Appends the view's element to the document body. If the view does + not have an HTML representation yet, `createElement()` will be called + automatically. + + If your application uses the `rootElement` property, you must append + the view within that element. Rendering views outside of the `rootElement` + is not supported. + + Note that this method just schedules the view to be appended; the DOM + element will not be appended to the document body until all bindings have + finished synchronizing. + + @method append + @return {Ember.View} receiver + */ + append: function() { + return this.appendTo(document.body); + }, + + /** + Removes the view's element from the element to which it is attached. + + @method remove + @return {Ember.View} receiver + */ + remove: function() { + // What we should really do here is wait until the end of the run loop + // to determine if the element has been re-appended to a different + // element. + // In the interim, we will just re-render if that happens. It is more + // important than elements get garbage collected. + if (!this.removedFromDOM) { this.destroyElement(); } + }, + + elementId: null, + + /** + Attempts to discover the element in the parent element. The default + implementation looks for an element with an ID of `elementId` (or the + view's guid if `elementId` is null). You can override this method to + provide your own form of lookup. For example, if you want to discover your + element using a CSS class name instead of an ID. + + @method findElementInParentElement + @param {DOMElement} parentElement The parent's DOM element + @return {DOMElement} The discovered element + */ + findElementInParentElement: function(parentElem) { + var id = "#" + this.elementId; + return jQuery(id)[0] || jQuery(id, parentElem)[0]; + }, + + /** + Creates a DOM representation of the view and all of its child views by + recursively calling the `render()` method. + + After the element has been inserted into the DOM, `didInsertElement` will + be called on this view and all of its child views. + + @method createElement + @return {Ember.View} receiver + */ + createElement: function() { + if (this.element) { return this; } + + this._didCreateElementWithoutMorph = true; + this.constructor.renderer.renderTree(this); + + return this; + }, + + /** + Called when a view is going to insert an element into the DOM. + + @event willInsertElement + */ + willInsertElement: Ember.K, + + /** + Called when the element of the view has been inserted into the DOM + or after the view was re-rendered. Override this function to do any + set up that requires an element in the document body. + + When a view has children, didInsertElement will be called on the + child view(s) first, bubbling upwards through the hierarchy. + + @event didInsertElement + */ + didInsertElement: Ember.K, + + /** + Called when the view is about to rerender, but before anything has + been torn down. This is a good opportunity to tear down any manual + observers you have installed based on the DOM state + + @event willClearRender + */ + willClearRender: Ember.K, + + /** + Destroys any existing element along with the element for any child views + as well. If the view does not currently have a element, then this method + will do nothing. + + If you implement `willDestroyElement()` on your view, then this method will + be invoked on your view before your element is destroyed to give you a + chance to clean up any event handlers, etc. + + If you write a `willDestroyElement()` handler, you can assume that your + `didInsertElement()` handler was called earlier for the same element. + + You should not call or override this method yourself, but you may + want to implement the above callbacks. + + @method destroyElement + @return {Ember.View} receiver + */ + destroyElement: function() { + return this.currentState.destroyElement(this); + }, + + /** + Called when the element of the view is going to be destroyed. Override + this function to do any teardown that requires an element, like removing + event listeners. + + Please note: any property changes made during this event will have no + effect on object observers. + + @event willDestroyElement + */ + willDestroyElement: Ember.K, + + /** + Called when the parentView property has changed. + + @event parentViewDidChange + */ + parentViewDidChange: Ember.K, + + instrumentName: 'view', + + instrumentDetails: function(hash) { + hash.template = get(this, 'templateName'); + this._super(hash); + }, + + beforeRender: function(buffer) {}, + + afterRender: function(buffer) {}, + + applyAttributesToBuffer: function(buffer) { + // Creates observers for all registered class name and attribute bindings, + // then adds them to the element. + var classNameBindings = get(this, 'classNameBindings'); + if (classNameBindings.length) { + this._applyClassNameBindings(classNameBindings); + } + + // Pass the render buffer so the method can apply attributes directly. + // This isn't needed for class name bindings because they use the + // existing classNames infrastructure. + var attributeBindings = get(this, 'attributeBindings'); + if (attributeBindings.length) { + this._applyAttributeBindings(buffer, attributeBindings); + } + + buffer.setClasses(this.classNames); + buffer.id(this.elementId); + + var role = get(this, 'ariaRole'); + if (role) { + buffer.attr('role', role); + } + + if (get(this, 'isVisible') === false) { + buffer.style('display', 'none'); + } + }, + + // .......................................................... + // STANDARD RENDER PROPERTIES + // + + /** + Tag name for the view's outer element. The tag name is only used when an + element is first created. If you change the `tagName` for an element, you + must destroy and recreate the view element. + + By default, the render buffer will use a `
` tag for views. + + @property tagName + @type String + @default null + */ + + // We leave this null by default so we can tell the difference between + // the default case and a user-specified tag. + tagName: null, + + /** + The WAI-ARIA role of the control represented by this view. For example, a + button may have a role of type 'button', or a pane may have a role of + type 'alertdialog'. This property is used by assistive software to help + visually challenged users navigate rich web applications. + + The full list of valid WAI-ARIA roles is available at: + [http://www.w3.org/TR/wai-aria/roles#roles_categorization](http://www.w3.org/TR/wai-aria/roles#roles_categorization) + + @property ariaRole + @type String + @default null + */ + ariaRole: null, + + /** + Standard CSS class names to apply to the view's outer element. This + property automatically inherits any class names defined by the view's + superclasses as well. + + @property classNames + @type Array + @default ['ember-view'] + */ + classNames: ['ember-view'], + + /** + A list of properties of the view to apply as class names. If the property + is a string value, the value of that string will be applied as a class + name. + + ```javascript + // Applies the 'high' class to the view element + Ember.View.extend({ + classNameBindings: ['priority'] + priority: 'high' + }); + ``` + + If the value of the property is a Boolean, the name of that property is + added as a dasherized class name. + + ```javascript + // Applies the 'is-urgent' class to the view element + Ember.View.extend({ + classNameBindings: ['isUrgent'] + isUrgent: true + }); + ``` + + If you would prefer to use a custom value instead of the dasherized + property name, you can pass a binding like this: + + ```javascript + // Applies the 'urgent' class to the view element + Ember.View.extend({ + classNameBindings: ['isUrgent:urgent'] + isUrgent: true + }); + ``` + + This list of properties is inherited from the view's superclasses as well. + + @property classNameBindings + @type Array + @default [] + */ + classNameBindings: EMPTY_ARRAY, + + /** + A list of properties of the view to apply as attributes. If the property is + a string value, the value of that string will be applied as the attribute. + + ```javascript + // Applies the type attribute to the element + // with the value "button", like
+ Ember.View.extend({ + attributeBindings: ['type'], + type: 'button' + }); + ``` + + If the value of the property is a Boolean, the name of that property is + added as an attribute. + + ```javascript + // Renders something like
+ Ember.View.extend({ + attributeBindings: ['enabled'], + enabled: true + }); + ``` + + @property attributeBindings + */ + attributeBindings: EMPTY_ARRAY, + + // ....................................................... + // CORE DISPLAY METHODS + // + + /** + Setup a view, but do not finish waking it up. + + * configure `childViews` + * register the view with the global views hash, which is used for event + dispatch + + @method init + @private + */ + init: function() { + if (!this.isVirtual && !this.elementId) { + this.elementId = guidFor(this); + } + + this._super(); + + // setup child views. be sure to clone the child views array first + this._childViews = this._childViews.slice(); + this._baseContext = undefined; + this._contextStream = undefined; + this._streamBindings = undefined; + + if (!this._keywords) { + this._keywords = create(null); + } + this._keywords.view = new SimpleStream(); + this._keywords._view = this; + this._keywords.controller = new KeyStream(this, 'controller'); + this._setupKeywords(); + + Ember.assert("Only arrays are allowed for 'classNameBindings'", typeOf(this.classNameBindings) === 'array'); + this.classNameBindings = emberA(this.classNameBindings.slice()); + + Ember.assert("Only arrays are allowed for 'classNames'", typeOf(this.classNames) === 'array'); + this.classNames = emberA(this.classNames.slice()); + }, + + appendChild: function(view, options) { + return this.currentState.appendChild(this, view, options); + }, + + /** + Removes the child view from the parent view. + + @method removeChild + @param {Ember.View} view + @return {Ember.View} receiver + */ + removeChild: function(view) { + // If we're destroying, the entire subtree will be + // freed, and the DOM will be handled separately, + // so no need to mess with childViews. + if (this.isDestroying) { return; } + + // update parent node + set(view, '_parentView', null); + + // remove view from childViews array. + var childViews = this._childViews; + + removeObject(childViews, view); + + this.propertyDidChange('childViews'); // HUH?! what happened to will change? + + return this; + }, + + /** + Removes all children from the `parentView`. + + @method removeAllChildren + @return {Ember.View} receiver + */ + removeAllChildren: function() { + return this.mutateChildViews(function(parentView, view) { + parentView.removeChild(view); + }); + }, + + destroyAllChildren: function() { + return this.mutateChildViews(function(parentView, view) { + view.destroy(); + }); + }, + + /** + Removes the view from its `parentView`, if one is found. Otherwise + does nothing. + + @method removeFromParent + @return {Ember.View} receiver + */ + removeFromParent: function() { + var parent = this._parentView; + + // Remove DOM element from parent + this.remove(); + + if (parent) { parent.removeChild(this); } + return this; + }, + + /** + You must call `destroy` on a view to destroy the view (and all of its + child views). This will remove the view from any parent node, then make + sure that the DOM element managed by the view can be released by the + memory manager. + + @method destroy + */ + destroy: function() { + // get parentView before calling super because it'll be destroyed + var nonVirtualParentView = get(this, 'parentView'); + var viewName = this.viewName; + + if (!this._super()) { return; } + + // remove from non-virtual parent view if viewName was specified + if (viewName && nonVirtualParentView) { + nonVirtualParentView.set(viewName, null); + } + + return this; + }, + + /** + Instantiates a view to be added to the childViews array during view + initialization. You generally will not call this method directly unless + you are overriding `createChildViews()`. Note that this method will + automatically configure the correct settings on the new view instance to + act as a child of the parent. + + @method createChildView + @param {Class|String} viewClass + @param {Hash} [attrs] Attributes to add + @return {Ember.View} new instance + */ + createChildView: function(view, attrs) { + if (!view) { + throw new TypeError("createChildViews first argument must exist"); + } + + if (view.isView && view._parentView === this && view.container === this.container) { + return view; + } + + attrs = attrs || {}; + attrs._parentView = this; + + if (CoreView.detect(view)) { + attrs.templateData = attrs.templateData || get(this, 'templateData'); + + attrs.container = this.container; + view = view.create(attrs); + + // don't set the property on a virtual view, as they are invisible to + // consumers of the view API + if (view.viewName) { + set(get(this, 'concreteView'), view.viewName, view); + } + } else if ('string' === typeof view) { + var fullName = 'view:' + view; + var ViewKlass = this.container.lookupFactory(fullName); + + Ember.assert("Could not find view: '" + fullName + "'", !!ViewKlass); + + attrs.templateData = get(this, 'templateData'); + view = ViewKlass.create(attrs); + } else { + Ember.assert('You must pass instance or subclass of View', view.isView); + attrs.container = this.container; + + if (!get(view, 'templateData')) { + attrs.templateData = get(this, 'templateData'); + } + + setProperties(view, attrs); + + } + + return view; + }, + + becameVisible: Ember.K, + becameHidden: Ember.K, + + /** + When the view's `isVisible` property changes, toggle the visibility + element of the actual DOM element. + + @method _isVisibleDidChange + @private + */ + _isVisibleDidChange: observer('isVisible', function() { + if (this._isVisible === get(this, 'isVisible')) { return ; } + run.scheduleOnce('render', this, this._toggleVisibility); + }), + + _toggleVisibility: function() { + var $el = this.$(); + var isVisible = get(this, 'isVisible'); + + if (this._isVisible === isVisible) { return ; } + + // It's important to keep these in sync, even if we don't yet have + // an element in the DOM to manipulate: + this._isVisible = isVisible; + + if (!$el) { return; } + + $el.toggle(isVisible); + + if (this._isAncestorHidden()) { return; } + + if (isVisible) { + this._notifyBecameVisible(); + } else { + this._notifyBecameHidden(); + } + }, + + _notifyBecameVisible: function() { + this.trigger('becameVisible'); + + this.forEachChildView(function(view) { + var isVisible = get(view, 'isVisible'); + + if (isVisible || isVisible === null) { + view._notifyBecameVisible(); + } + }); + }, + + _notifyBecameHidden: function() { + this.trigger('becameHidden'); + this.forEachChildView(function(view) { + var isVisible = get(view, 'isVisible'); + + if (isVisible || isVisible === null) { + view._notifyBecameHidden(); + } + }); + }, + + _isAncestorHidden: function() { + var parent = get(this, 'parentView'); + + while (parent) { + if (get(parent, 'isVisible') === false) { return true; } + + parent = get(parent, 'parentView'); + } + + return false; + }, + transitionTo: function(state, children) { + Ember.deprecate("Ember.View#transitionTo has been deprecated, it is for internal use only"); + this._transitionTo(state, children); + }, + _transitionTo: function(state, children) { + var priorState = this.currentState; + var currentState = this.currentState = this._states[state]; + this._state = state; + + if (priorState && priorState.exit) { priorState.exit(this); } + if (currentState.enter) { currentState.enter(this); } + }, + + // ....................................................... + // EVENT HANDLING + // + + /** + Handle events from `Ember.EventDispatcher` + + @method handleEvent + @param eventName {String} + @param evt {Event} + @private + */ + handleEvent: function(eventName, evt) { + return this.currentState.handleEvent(this, eventName, evt); + }, + + registerObserver: function(root, path, target, observer) { + if (!observer && 'function' === typeof target) { + observer = target; + target = null; + } + + if (!root || typeof root !== 'object') { + return; + } + + var scheduledObserver = this._wrapAsScheduled(observer); + + addObserver(root, path, target, scheduledObserver); + + this.one('willClearRender', function() { + removeObserver(root, path, target, scheduledObserver); + }); + }, + + _wrapAsScheduled: function(fn) { + var view = this; + var stateCheckedFn = function() { + view.currentState.invokeObserver(this, fn); + }; + var scheduledFn = function() { + run.scheduleOnce('render', this, stateCheckedFn); + }; + return scheduledFn; + }, + + getStream: function(path) { + return this._getContextStream().get(path); + }, + + _getBindingForStream: function(path) { + if (this._streamBindings === undefined) { + this._streamBindings = create(null); + this.one('willDestroyElement', this, this._destroyStreamBindings); + } + + if (this._streamBindings[path] !== undefined) { + return this._streamBindings[path]; + } else { + var stream = this._getContextStream().get(path); + return this._streamBindings[path] = new StreamBinding(stream); + } + }, + + _destroyStreamBindings: function() { + var streamBindings = this._streamBindings; + for (var path in streamBindings) { + streamBindings[path].destroy(); + } + this._streamBindings = undefined; + }, + + _getContextStream: function() { + if (this._contextStream === undefined) { + this._baseContext = new KeyStream(this, 'context'); + this._contextStream = new ContextStream(this); + this.one('willDestroyElement', this, this._destroyContextStream); + } + + return this._contextStream; + }, + + _destroyContextStream: function() { + this._baseContext.destroy(); + this._baseContext = undefined; + this._contextStream.destroy(); + this._contextStream = undefined; + }, + + _unsubscribeFromStreamBindings: function() { + for (var key in this._streamBindingSubscriptions) { + var streamBinding = this[key + 'Binding']; + var callback = this._streamBindingSubscriptions[key]; + streamBinding.unsubscribe(callback); + } + } + }); + + deprecateProperty(View.prototype, 'state', '_state'); + deprecateProperty(View.prototype, 'states', '_states'); + + /* + Describe how the specified actions should behave in the various + states that a view can exist in. Possible states: + + * preRender: when a view is first instantiated, and after its + element was destroyed, it is in the preRender state + * inBuffer: once a view has been rendered, but before it has + been inserted into the DOM, it is in the inBuffer state + * hasElement: the DOM representation of the view is created, + and is ready to be inserted + * inDOM: once a view has been inserted into the DOM it is in + the inDOM state. A view spends the vast majority of its + existence in this state. + * destroyed: once a view has been destroyed (using the destroy + method), it is in this state. No further actions can be invoked + on a destroyed view. + */ + + // in the destroyed state, everything is illegal + + // before rendering has begun, all legal manipulations are noops. + + // inside the buffer, legal manipulations are done on the buffer + + // once the view has been inserted into the DOM, legal manipulations + // are done on the DOM element. + + View.reopenClass({ + + /** + Parse a path and return an object which holds the parsed properties. + + For example a path like "content.isEnabled:enabled:disabled" will return the + following object: + + ```javascript + { + path: "content.isEnabled", + className: "enabled", + falsyClassName: "disabled", + classNames: ":enabled:disabled" + } + ``` + + @method _parsePropertyPath + @static + @private + */ + _parsePropertyPath: function(path) { + var split = path.split(':'); + var propertyPath = split[0]; + var classNames = ""; + var className, falsyClassName; + + // check if the property is defined as prop:class or prop:trueClass:falseClass + if (split.length > 1) { + className = split[1]; + if (split.length === 3) { falsyClassName = split[2]; } + + classNames = ':' + className; + if (falsyClassName) { classNames += ":" + falsyClassName; } + } + + return { + stream: undefined, + path: propertyPath, + classNames: classNames, + className: (className === '') ? undefined : className, + falsyClassName: falsyClassName + }; + }, + + /** + Get the class name for a given value, based on the path, optional + `className` and optional `falsyClassName`. + + - if a `className` or `falsyClassName` has been specified: + - if the value is truthy and `className` has been specified, + `className` is returned + - if the value is falsy and `falsyClassName` has been specified, + `falsyClassName` is returned + - otherwise `null` is returned + - if the value is `true`, the dasherized last part of the supplied path + is returned + - if the value is not `false`, `undefined` or `null`, the `value` + is returned + - if none of the above rules apply, `null` is returned + + @method _classStringForValue + @param path + @param val + @param className + @param falsyClassName + @static + @private + */ + _classStringForValue: function(path, val, className, falsyClassName) { + if(isArray(val)) { + val = get(val, 'length') !== 0; + } + + // When using the colon syntax, evaluate the truthiness or falsiness + // of the value to determine which className to return + if (className || falsyClassName) { + if (className && !!val) { + return className; + + } else if (falsyClassName && !val) { + return falsyClassName; + + } else { + return null; + } + + // If value is a Boolean and true, return the dasherized property + // name. + } else if (val === true) { + // Normalize property path to be suitable for use + // as a class name. For exaple, content.foo.barBaz + // becomes bar-baz. + var parts = path.split('.'); + return dasherize(parts[parts.length-1]); + + // If the value is not false, undefined, or null, return the current + // value of the property. + } else if (val !== false && val != null) { + return val; + + // Nothing to display. Return null so that the old class is removed + // but no new class is added. + } else { + return null; + } + } + }); + + var mutation = EmberObject.extend(Evented).create(); + // TODO MOVE TO RENDERER HOOKS + View.addMutationListener = function(callback) { + mutation.on('change', callback); + }; + + View.removeMutationListener = function(callback) { + mutation.off('change', callback); + }; + + View.notifyMutationListeners = function() { + mutation.trigger('change'); + }; + + /** + Global views hash + + @property views + @static + @type Hash + */ + View.views = {}; + + // If someone overrides the child views computed property when + // defining their class, we want to be able to process the user's + // supplied childViews and then restore the original computed property + // at view initialization time. This happens in Ember.ContainerView's init + // method. + View.childViewsProperty = childViewsProperty; + + View.applyAttributeBindings = function(elem, name, value) { + var type = typeOf(value); + + // if this changes, also change the logic in ember-handlebars/lib/helpers/binding.js + if (name !== 'value' && (type === 'string' || (type === 'number' && !isNaN(value)))) { + if (value !== elem.attr(name)) { + elem.attr(name, value); + } + } else if (name === 'value' || type === 'boolean') { + if (isNone(value) || value === false) { + // `null`, `undefined` or `false` should remove attribute + elem.removeAttr(name); + // In IE8 `prop` couldn't remove attribute when name is `required`. + if (name === 'required') { + elem.removeProp(name); + } else { + elem.prop(name, ''); + } + } else if (value !== elem.prop(name)) { + // value should always be properties + elem.prop(name, value); + } + } else if (!value) { + elem.removeAttr(name); + } + }; + + __exports__["default"] = View; + }); +enifed("ember", + ["ember-metal","ember-runtime","ember-handlebars","ember-views","ember-routing","ember-routing-handlebars","ember-application","ember-extension-support"], + function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__, __dependency6__, __dependency7__, __dependency8__) { + "use strict"; + /* global navigator */ + // require the main entry points for each of these packages + // this is so that the global exports occur properly + + // do this to ensure that Ember.Test is defined properly on the global + // if it is present. + if (Ember.__loader.registry['ember-testing']) { + requireModule('ember-testing'); + } + + /** + Ember + + @module ember + */ + + Ember.deprecate('Usage of Ember is deprecated for Internet Explorer 6 and 7, support will be removed in the next major version.', !navigator.userAgent.match(/MSIE [67]/)); + }); +enifed("morph", + ["./morph/morph","./morph/dom-helper","exports"], + function(__dependency1__, __dependency2__, __exports__) { + "use strict"; + var Morph = __dependency1__["default"]; + var Morph; + __exports__.Morph = Morph; + var DOMHelper = __dependency2__["default"]; + var DOMHelper; + __exports__.DOMHelper = DOMHelper; + }); +enifed("morph/dom-helper", + ["../morph/morph","./dom-helper/build-html-dom","exports"], + function(__dependency1__, __dependency2__, __exports__) { + "use strict"; + var Morph = __dependency1__["default"]; + var buildHTMLDOM = __dependency2__.buildHTMLDOM; + var svgNamespace = __dependency2__.svgNamespace; + var svgHTMLIntegrationPoints = __dependency2__.svgHTMLIntegrationPoints; + + var deletesBlankTextNodes = (function(){ + var element = document.createElement('div'); + element.appendChild( document.createTextNode('') ); + var clonedElement = element.cloneNode(true); + return clonedElement.childNodes.length === 0; + })(); + + var ignoresCheckedAttribute = (function(){ + var element = document.createElement('input'); + element.setAttribute('checked', 'checked'); + var clonedElement = element.cloneNode(false); + return !clonedElement.checked; + })(); + + function isSVG(ns){ + return ns === svgNamespace; + } + + // This is not the namespace of the element, but of + // the elements inside that elements. + function interiorNamespace(element){ + if ( + element && + element.namespaceURI === svgNamespace && + !svgHTMLIntegrationPoints[element.tagName] + ) { + return svgNamespace; + } else { + return null; + } + } + + // The HTML spec allows for "omitted start tags". These tags are optional + // when their intended child is the first thing in the parent tag. For + // example, this is a tbody start tag: + // + // + // + // + // + // The tbody may be omitted, and the browser will accept and render: + // + //
+ // + // + // However, the omitted start tag will still be added to the DOM. Here + // we test the string and context to see if the browser is about to + // perform this cleanup. + // + // http://www.whatwg.org/specs/web-apps/current-work/multipage/syntax.html#optional-tags + // describes which tags are omittable. The spec for tbody and colgroup + // explains this behavior: + // + // http://www.whatwg.org/specs/web-apps/current-work/multipage/tables.html#the-tbody-element + // http://www.whatwg.org/specs/web-apps/current-work/multipage/tables.html#the-colgroup-element + // + + var omittedStartTagChildTest = /<([\w:]+)/; + function detectOmittedStartTag(string, contextualElement){ + // Omitted start tags are only inside table tags. + if (contextualElement.tagName === 'TABLE') { + var omittedStartTagChildMatch = omittedStartTagChildTest.exec(string); + if (omittedStartTagChildMatch) { + var omittedStartTagChild = omittedStartTagChildMatch[1]; + // It is already asserted that the contextual element is a table + // and not the proper start tag. Just see if a tag was omitted. + return omittedStartTagChild === 'tr' || + omittedStartTagChild === 'col'; + } + } + } + + function buildSVGDOM(html, dom){ + var div = dom.document.createElement('div'); + div.innerHTML = ''+html+''; + return div.firstChild.childNodes; + } + + /* + * A class wrapping DOM functions to address environment compatibility, + * namespaces, contextual elements for morph un-escaped content + * insertion. + * + * When entering a template, a DOMHelper should be passed: + * + * template(context, { hooks: hooks, dom: new DOMHelper() }); + * + * TODO: support foreignObject as a passed contextual element. It has + * a namespace (svg) that does not match its internal namespace + * (xhtml). + * + * @class DOMHelper + * @constructor + * @param {HTMLDocument} _document The document DOM methods are proxied to + */ + function DOMHelper(_document){ + this.document = _document || window.document; + this.namespace = null; + } + + var prototype = DOMHelper.prototype; + prototype.constructor = DOMHelper; + + prototype.insertBefore = function(element, childElement, referenceChild) { + return element.insertBefore(childElement, referenceChild); + }; + + prototype.appendChild = function(element, childElement) { + return element.appendChild(childElement); + }; + + prototype.appendText = function(element, text) { + return element.appendChild(this.document.createTextNode(text)); + }; + + prototype.setAttribute = function(element, name, value) { + element.setAttribute(name, value); + }; + + if (document.createElementNS) { + // Only opt into namespace detection if a contextualElement + // is passed. + prototype.createElement = function(tagName, contextualElement) { + var namespace = this.namespace; + if (contextualElement) { + if (tagName === 'svg') { + namespace = svgNamespace; + } else { + namespace = interiorNamespace(contextualElement); + } + } + if (namespace) { + return this.document.createElementNS(namespace, tagName); + } else { + return this.document.createElement(tagName); + } + }; + } else { + prototype.createElement = function(tagName) { + return this.document.createElement(tagName); + }; + } + + prototype.setNamespace = function(ns) { + this.namespace = ns; + }; + + prototype.detectNamespace = function(element) { + this.namespace = interiorNamespace(element); + }; + + prototype.createDocumentFragment = function(){ + return this.document.createDocumentFragment(); + }; + + prototype.createTextNode = function(text){ + return this.document.createTextNode(text); + }; + + prototype.repairClonedNode = function(element, blankChildTextNodes, isChecked){ + if (deletesBlankTextNodes && blankChildTextNodes.length > 0) { + for (var i=0, len=blankChildTextNodes.length;i]*selected/; + detectAutoSelectedOption = function detectAutoSelectedOption(select, option, html) { //jshint ignore:line + return select.selectedIndex === 0 && + !detectAutoSelectedOptionRegex.test(html); + }; + } else { + detectAutoSelectedOption = function detectAutoSelectedOption(select, option, html) { //jshint ignore:line + var selectedAttribute = option.getAttribute('selected'); + return select.selectedIndex === 0 && ( + selectedAttribute === null || + ( selectedAttribute !== '' && selectedAttribute.toLowerCase() !== 'selected' ) + ); + }; + } + + // IE 9 and earlier don't allow us to set innerHTML on col, colgroup, frameset, + // html, style, table, tbody, tfoot, thead, title, tr. Detect this and add + // them to an initial list of corrected tags. + // + // Here we are only dealing with the ones which can have child nodes. + // + var tagNamesRequiringInnerHTMLFix, tableNeedsInnerHTMLFix; + var tableInnerHTMLTestElement = document.createElement('table'); + try { + tableInnerHTMLTestElement.innerHTML = ''; + } catch (e) { + } finally { + tableNeedsInnerHTMLFix = (tableInnerHTMLTestElement.childNodes.length === 0); + } + if (tableNeedsInnerHTMLFix) { + tagNamesRequiringInnerHTMLFix = { + colgroup: ['table'], + table: [], + tbody: ['table'], + tfoot: ['table'], + thead: ['table'], + tr: ['table', 'tbody'] + }; + } + + // IE 8 doesn't allow setting innerHTML on a select tag. Detect this and + // add it to the list of corrected tags. + // + var selectInnerHTMLTestElement = document.createElement('select'); + selectInnerHTMLTestElement.innerHTML = ''; + if (selectInnerHTMLTestElement) { + tagNamesRequiringInnerHTMLFix = tagNamesRequiringInnerHTMLFix || {}; + tagNamesRequiringInnerHTMLFix.select = []; + } + + function scriptSafeInnerHTML(element, html) { + // without a leading text node, IE will drop a leading script tag. + html = '­'+html; + + element.innerHTML = html; + + var nodes = element.childNodes; + + // Look for ­ to remove it. + var shyElement = nodes[0]; + while (shyElement.nodeType === 1 && !shyElement.nodeName) { + shyElement = shyElement.firstChild; + } + // At this point it's the actual unicode character. + if (shyElement.nodeType === 3 && shyElement.nodeValue.charAt(0) === "\u00AD") { + var newValue = shyElement.nodeValue.slice(1); + if (newValue.length) { + shyElement.nodeValue = shyElement.nodeValue.slice(1); + } else { + shyElement.parentNode.removeChild(shyElement); + } + } + + return nodes; + } + + function buildDOMWithFix(html, contextualElement){ + var tagName = contextualElement.tagName; + + // Firefox versions < 11 do not have support for element.outerHTML. + var outerHTML = contextualElement.outerHTML || new XMLSerializer().serializeToString(contextualElement); + if (!outerHTML) { + throw "Can't set innerHTML on "+tagName+" in this browser"; + } + + var wrappingTags = tagNamesRequiringInnerHTMLFix[tagName.toLowerCase()]; + var startTag = outerHTML.match(new RegExp("<"+tagName+"([^>]*)>", 'i'))[0]; + var endTag = ''; + + var wrappedHTML = [startTag, html, endTag]; + + var i = wrappingTags.length; + var wrappedDepth = 1 + i; + while(i--) { + wrappedHTML.unshift('<'+wrappingTags[i]+'>'); + wrappedHTML.push(''); + } + + var wrapper = document.createElement('div'); + scriptSafeInnerHTML(wrapper, wrappedHTML.join('')); + var element = wrapper; + while (wrappedDepth--) { + element = element.firstChild; + while (element && element.nodeType !== 1) { + element = element.nextSibling; + } + } + while (element && element.tagName !== tagName) { + element = element.nextSibling; + } + return element ? element.childNodes : []; + } + + var buildDOM; + if (needsShy) { + buildDOM = function buildDOM(html, contextualElement, dom){ + contextualElement = dom.cloneNode(contextualElement, false); + scriptSafeInnerHTML(contextualElement, html); + return contextualElement.childNodes; + }; + } else { + buildDOM = function buildDOM(html, contextualElement, dom){ + contextualElement = dom.cloneNode(contextualElement, false); + contextualElement.innerHTML = html; + return contextualElement.childNodes; + }; + } + + var buildIESafeDOM; + if (tagNamesRequiringInnerHTMLFix || movesWhitespace) { + buildIESafeDOM = function buildIESafeDOM(html, contextualElement, dom) { + // Make a list of the leading text on script nodes. Include + // script tags without any whitespace for easier processing later. + var spacesBefore = []; + var spacesAfter = []; + html = html.replace(/(\s*)()(\s*)/g, function(match, tag, spaces) { + spacesAfter.push(spaces); + return tag; + }); + + // Fetch nodes + var nodes; + if (tagNamesRequiringInnerHTMLFix[contextualElement.tagName.toLowerCase()]) { + // buildDOMWithFix uses string wrappers for problematic innerHTML. + nodes = buildDOMWithFix(html, contextualElement); + } else { + nodes = buildDOM(html, contextualElement, dom); + } + + // Build a list of script tags, the nodes themselves will be + // mutated as we add test nodes. + var i, j, node, nodeScriptNodes; + var scriptNodes = []; + for (i=0;node=nodes[i];i++) { + if (node.nodeType !== 1) { + continue; + } + if (node.tagName === 'SCRIPT') { + scriptNodes.push(node); + } else { + nodeScriptNodes = node.getElementsByTagName('script'); + for (j=0;j 0) { + textNode = dom.document.createTextNode(spaceBefore); + scriptNode.parentNode.insertBefore(textNode, scriptNode); + } + + spaceAfter = spacesAfter[i]; + if (spaceAfter && spaceAfter.length > 0) { + textNode = dom.document.createTextNode(spaceAfter); + scriptNode.parentNode.insertBefore(textNode, scriptNode.nextSibling); + } + } + + return nodes; + }; + } else { + buildIESafeDOM = buildDOM; + } + + // When parsing innerHTML, the browser may set up DOM with some things + // not desired. For example, with a select element context and option + // innerHTML the first option will be marked selected. + // + // This method cleans up some of that, resetting those values back to + // their defaults. + // + function buildSafeDOM(html, contextualElement, dom) { + var childNodes = buildIESafeDOM(html, contextualElement, dom); + + if (contextualElement.tagName === 'SELECT') { + // Walk child nodes + for (var i = 0; childNodes[i]; i++) { + // Find and process the first option child node + if (childNodes[i].tagName === 'OPTION') { + if (detectAutoSelectedOption(childNodes[i].parentNode, childNodes[i], html)) { + // If the first node is selected but does not have an attribute, + // presume it is not really selected. + childNodes[i].parentNode.selectedIndex = -1; + } + break; + } + } + } + + return childNodes; + } + + var buildHTMLDOM; + if (needsIntegrationPointFix) { + buildHTMLDOM = function buildHTMLDOM(html, contextualElement, dom){ + if (svgHTMLIntegrationPoints[contextualElement.tagName]) { + return buildSafeDOM(html, document.createElement('div'), dom); + } else { + return buildSafeDOM(html, contextualElement, dom); + } + }; + } else { + buildHTMLDOM = buildSafeDOM; + } + + __exports__.buildHTMLDOM = buildHTMLDOM; + }); +enifed("morph/morph", + ["exports"], + function(__exports__) { + "use strict"; + var splice = Array.prototype.splice; + + function ensureStartEnd(start, end) { + if (start === null || end === null) { + throw new Error('a fragment parent must have boundary nodes in order to detect insertion'); + } + } + + function ensureContext(contextualElement) { + if (!contextualElement || contextualElement.nodeType !== 1) { + throw new Error('An element node must be provided for a contextualElement, you provided ' + + (contextualElement ? 'nodeType ' + contextualElement.nodeType : 'nothing')); + } + } + + // TODO: this is an internal API, this should be an assert + function Morph(parent, start, end, domHelper, contextualElement) { + if (parent.nodeType === 11) { + ensureStartEnd(start, end); + this.element = null; + } else { + this.element = parent; + } + this._parent = parent; + this.start = start; + this.end = end; + this.domHelper = domHelper; + ensureContext(contextualElement); + this.contextualElement = contextualElement; + this.reset(); + } + + Morph.prototype.reset = function() { + this.text = null; + this.owner = null; + this.morphs = null; + this.before = null; + this.after = null; + this.escaped = true; + }; + + Morph.prototype.parent = function () { + if (!this.element) { + var parent = this.start.parentNode; + if (this._parent !== parent) { + this.element = this._parent = parent; + } + } + return this._parent; + }; + + Morph.prototype.destroy = function () { + if (this.owner) { + this.owner.removeMorph(this); + } else { + clear(this.element || this.parent(), this.start, this.end); + } + }; + + Morph.prototype.removeMorph = function (morph) { + var morphs = this.morphs; + for (var i=0, l=morphs.length; i 0 ? morphs[index-1] : null; + var after = index < morphs.length ? morphs[index] : null; + var start = before === null ? this.start : (before.end === null ? parent.lastChild : before.end.previousSibling); + var end = after === null ? this.end : (after.start === null ? parent.firstChild : after.start.nextSibling); + var morph = new Morph(parent, start, end, this.domHelper, this.contextualElement); + + morph.owner = this; + morph._update(parent, node); + + if (before !== null) { + morph.before = before; + before.end = start.nextSibling; + before.after = morph; + } + + if (after !== null) { + morph.after = after; + after.before = morph; + after.start = end.previousSibling; + } + + this.morphs.splice(index, 0, morph); + return morph; + }; + + Morph.prototype.replace = function (index, removedLength, addedNodes) { + if (this.morphs === null) this.morphs = []; + var parent = this.element || this.parent(); + var morphs = this.morphs; + var before = index > 0 ? morphs[index-1] : null; + var after = index+removedLength < morphs.length ? morphs[index+removedLength] : null; + var start = before === null ? this.start : (before.end === null ? parent.lastChild : before.end.previousSibling); + var end = after === null ? this.end : (after.start === null ? parent.firstChild : after.start.nextSibling); + var addedLength = addedNodes === undefined ? 0 : addedNodes.length; + var args, i, current; + + if (removedLength > 0) { + clear(parent, start, end); + } + + if (addedLength === 0) { + if (before !== null) { + before.after = after; + before.end = end; + } + if (after !== null) { + after.before = before; + after.start = start; + } + morphs.splice(index, removedLength); + return; + } + + args = new Array(addedLength+2); + if (addedLength > 0) { + for (i=0; i " + n.nextStates.map(function(s) { return s.debug() }).join(" or ") + " )"; + }).join(", ") + } + END IF **/ + + // This is a somewhat naive strategy, but should work in a lot of cases + // A better strategy would properly resolve /posts/:id/new and /posts/edit/:id. + // + // This strategy generally prefers more static and less dynamic matching. + // Specifically, it + // + // * prefers fewer stars to more, then + // * prefers using stars for less of the match to more, then + // * prefers fewer dynamic segments to more, then + // * prefers more static segments to more + function sortSolutions(states) { + return states.sort(function(a, b) { + if (a.types.stars !== b.types.stars) { return a.types.stars - b.types.stars; } + + if (a.types.stars) { + if (a.types.statics !== b.types.statics) { return b.types.statics - a.types.statics; } + if (a.types.dynamics !== b.types.dynamics) { return b.types.dynamics - a.types.dynamics; } + } + + if (a.types.dynamics !== b.types.dynamics) { return a.types.dynamics - b.types.dynamics; } + if (a.types.statics !== b.types.statics) { return b.types.statics - a.types.statics; } + + return 0; + }); + } + + function recognizeChar(states, ch) { + var nextStates = []; + + for (var i=0, l=states.length; i 2 && key.slice(keyLength -2) === '[]') { + isArray = true; + key = key.slice(0, keyLength - 2); + if(!queryParams[key]) { + queryParams[key] = []; + } + } + value = pair[1] ? decodeURIComponent(pair[1]) : ''; + } + if (isArray) { + queryParams[key].push(value); + } else { + queryParams[key] = value; + } + } + return queryParams; + }, + + recognize: function(path) { + var states = [ this.rootState ], + pathLen, i, l, queryStart, queryParams = {}, + isSlashDropped = false; + + queryStart = path.indexOf('?'); + if (queryStart !== -1) { + var queryString = path.substr(queryStart + 1, path.length); + path = path.substr(0, queryStart); + queryParams = this.parseQueryString(queryString); + } + + path = decodeURI(path); + + // DEBUG GROUP path + + if (path.charAt(0) !== "/") { path = "/" + path; } + + pathLen = path.length; + if (pathLen > 1 && path.charAt(pathLen - 1) === "/") { + path = path.substr(0, pathLen - 1); + isSlashDropped = true; + } + + for (i=0, l=path.length; i= 0 && proceed; --i) { + var route = routes[i]; + recognizer.add(routes, { as: route.handler }); + proceed = route.path === '/' || route.path === '' || route.handler.slice(-6) === '.index'; + } + }); + }, + + hasRoute: function(route) { + return this.recognizer.hasRoute(route); + }, + + queryParamsTransition: function(changelist, wasTransitioning, oldState, newState) { + var router = this; + + fireQueryParamDidChange(this, newState, changelist); + + if (!wasTransitioning && this.activeTransition) { + // One of the handlers in queryParamsDidChange + // caused a transition. Just return that transition. + return this.activeTransition; + } else { + // Running queryParamsDidChange didn't change anything. + // Just update query params and be on our way. + + // We have to return a noop transition that will + // perform a URL update at the end. This gives + // the user the ability to set the url update + // method (default is replaceState). + var newTransition = new Transition(this); + newTransition.queryParamsOnly = true; + + oldState.queryParams = finalizeQueryParamChange(this, newState.handlerInfos, newState.queryParams, newTransition); + + newTransition.promise = newTransition.promise.then(function(result) { + updateURL(newTransition, oldState, true); + if (router.didTransition) { + router.didTransition(router.currentHandlerInfos); + } + return result; + }, null, promiseLabel("Transition complete")); + return newTransition; + } + }, + + // NOTE: this doesn't really belong here, but here + // it shall remain until our ES6 transpiler can + // handle cyclical deps. + transitionByIntent: function(intent, isIntermediate) { + try { + return getTransitionByIntent.apply(this, arguments); + } catch(e) { + return new Transition(this, intent, null, e); + } + }, + + /** + Clears the current and target route handlers and triggers exit + on each of them starting at the leaf and traversing up through + its ancestors. + */ + reset: function() { + if (this.state) { + forEach(this.state.handlerInfos.slice().reverse(), function(handlerInfo) { + var handler = handlerInfo.handler; + callHook(handler, 'exit'); + }); + } + + this.state = new TransitionState(); + this.currentHandlerInfos = null; + }, + + activeTransition: null, + + /** + var handler = handlerInfo.handler; + The entry point for handling a change to the URL (usually + via the back and forward button). + + Returns an Array of handlers and the parameters associated + with those parameters. + + @param {String} url a URL to process + + @return {Array} an Array of `[handler, parameter]` tuples + */ + handleURL: function(url) { + // Perform a URL-based transition, but don't change + // the URL afterward, since it already happened. + var args = slice.call(arguments); + if (url.charAt(0) !== '/') { args[0] = '/' + url; } + + return doTransition(this, args).method(null); + }, + + /** + Hook point for updating the URL. + + @param {String} url a URL to update to + */ + updateURL: function() { + throw new Error("updateURL is not implemented"); + }, + + /** + Hook point for replacing the current URL, i.e. with replaceState + + By default this behaves the same as `updateURL` + + @param {String} url a URL to update to + */ + replaceURL: function(url) { + this.updateURL(url); + }, + + /** + Transition into the specified named route. + + If necessary, trigger the exit callback on any handlers + that are no longer represented by the target route. + + @param {String} name the name of the route + */ + transitionTo: function(name) { + return doTransition(this, arguments); + }, + + intermediateTransitionTo: function(name) { + return doTransition(this, arguments, true); + }, + + refresh: function(pivotHandler) { + var state = this.activeTransition ? this.activeTransition.state : this.state; + var handlerInfos = state.handlerInfos; + var params = {}; + for (var i = 0, len = handlerInfos.length; i < len; ++i) { + var handlerInfo = handlerInfos[i]; + params[handlerInfo.name] = handlerInfo.params || {}; + } + + log(this, "Starting a refresh transition"); + var intent = new NamedTransitionIntent({ + name: handlerInfos[handlerInfos.length - 1].name, + pivotHandler: pivotHandler || handlerInfos[0].handler, + contexts: [], // TODO collect contexts...? + queryParams: this._changedQueryParams || state.queryParams || {} + }); + + return this.transitionByIntent(intent, false); + }, + + /** + Identical to `transitionTo` except that the current URL will be replaced + if possible. + + This method is intended primarily for use with `replaceState`. + + @param {String} name the name of the route + */ + replaceWith: function(name) { + return doTransition(this, arguments).method('replace'); + }, + + /** + Take a named route and context objects and generate a + URL. + + @param {String} name the name of the route to generate + a URL for + @param {...Object} objects a list of objects to serialize + + @return {String} a URL + */ + generate: function(handlerName) { + + var partitionedArgs = extractQueryParams(slice.call(arguments, 1)), + suppliedParams = partitionedArgs[0], + queryParams = partitionedArgs[1]; + + // Construct a TransitionIntent with the provided params + // and apply it to the present state of the router. + var intent = new NamedTransitionIntent({ name: handlerName, contexts: suppliedParams }); + var state = intent.applyToState(this.state, this.recognizer, this.getHandler); + var params = {}; + + for (var i = 0, len = state.handlerInfos.length; i < len; ++i) { + var handlerInfo = state.handlerInfos[i]; + var handlerParams = handlerInfo.serialize(); + merge(params, handlerParams); + } + params.queryParams = queryParams; + + return this.recognizer.generate(handlerName, params); + }, + + applyIntent: function(handlerName, contexts) { + var intent = new NamedTransitionIntent({ + name: handlerName, + contexts: contexts + }); + + var state = this.activeTransition && this.activeTransition.state || this.state; + return intent.applyToState(state, this.recognizer, this.getHandler); + }, + + isActiveIntent: function(handlerName, contexts, queryParams) { + var targetHandlerInfos = this.state.handlerInfos, + found = false, names, object, handlerInfo, handlerObj, i, len; + + if (!targetHandlerInfos.length) { return false; } + + var targetHandler = targetHandlerInfos[targetHandlerInfos.length - 1].name; + var recogHandlers = this.recognizer.handlersFor(targetHandler); + + var index = 0; + for (len = recogHandlers.length; index < len; ++index) { + handlerInfo = targetHandlerInfos[index]; + if (handlerInfo.name === handlerName) { break; } + } + + if (index === recogHandlers.length) { + // The provided route name isn't even in the route hierarchy. + return false; + } + + var state = new TransitionState(); + state.handlerInfos = targetHandlerInfos.slice(0, index + 1); + recogHandlers = recogHandlers.slice(0, index + 1); + + var intent = new NamedTransitionIntent({ + name: targetHandler, + contexts: contexts + }); + + var newState = intent.applyToHandlers(state, recogHandlers, this.getHandler, targetHandler, true, true); + + var handlersEqual = handlerInfosEqual(newState.handlerInfos, state.handlerInfos); + if (!queryParams || !handlersEqual) { + return handlersEqual; + } + + // Get a hash of QPs that will still be active on new route + var activeQPsOnNewHandler = {}; + merge(activeQPsOnNewHandler, queryParams); + + var activeQueryParams = this.state.queryParams; + for (var key in activeQueryParams) { + if (activeQueryParams.hasOwnProperty(key) && + activeQPsOnNewHandler.hasOwnProperty(key)) { + activeQPsOnNewHandler[key] = activeQueryParams[key]; + } + } + + return handlersEqual && !getChangelist(activeQPsOnNewHandler, queryParams); + }, + + isActive: function(handlerName) { + var partitionedArgs = extractQueryParams(slice.call(arguments, 1)); + return this.isActiveIntent(handlerName, partitionedArgs[0], partitionedArgs[1]); + }, + + trigger: function(name) { + var args = slice.call(arguments); + trigger(this, this.currentHandlerInfos, false, args); + }, + + /** + Hook point for logging transition status updates. + + @param {String} message The message to log. + */ + log: null, + + _willChangeContextEvent: 'willChangeContext', + _triggerWillChangeContext: function(handlerInfos, newTransition) { + trigger(this, handlerInfos, true, [this._willChangeContextEvent, newTransition]); + }, + + _triggerWillLeave: function(handlerInfos, newTransition, leavingChecker) { + trigger(this, handlerInfos, true, ['willLeave', newTransition, leavingChecker]); + } + }; + + /** + @private + + Fires queryParamsDidChange event + */ + function fireQueryParamDidChange(router, newState, queryParamChangelist) { + // If queryParams changed trigger event + if (queryParamChangelist) { + + // This is a little hacky but we need some way of storing + // changed query params given that no activeTransition + // is guaranteed to have occurred. + router._changedQueryParams = queryParamChangelist.all; + trigger(router, newState.handlerInfos, true, ['queryParamsDidChange', queryParamChangelist.changed, queryParamChangelist.all, queryParamChangelist.removed]); + router._changedQueryParams = null; + } + } + + /** + @private + + Takes an Array of `HandlerInfo`s, figures out which ones are + exiting, entering, or changing contexts, and calls the + proper handler hooks. + + For example, consider the following tree of handlers. Each handler is + followed by the URL segment it handles. + + ``` + |~index ("/") + | |~posts ("/posts") + | | |-showPost ("/:id") + | | |-newPost ("/new") + | | |-editPost ("/edit") + | |~about ("/about/:id") + ``` + + Consider the following transitions: + + 1. A URL transition to `/posts/1`. + 1. Triggers the `*model` callbacks on the + `index`, `posts`, and `showPost` handlers + 2. Triggers the `enter` callback on the same + 3. Triggers the `setup` callback on the same + 2. A direct transition to `newPost` + 1. Triggers the `exit` callback on `showPost` + 2. Triggers the `enter` callback on `newPost` + 3. Triggers the `setup` callback on `newPost` + 3. A direct transition to `about` with a specified + context object + 1. Triggers the `exit` callback on `newPost` + and `posts` + 2. Triggers the `serialize` callback on `about` + 3. Triggers the `enter` callback on `about` + 4. Triggers the `setup` callback on `about` + + @param {Router} transition + @param {TransitionState} newState + */ + function setupContexts(router, newState, transition) { + var partition = partitionHandlers(router.state, newState); + + forEach(partition.exited, function(handlerInfo) { + var handler = handlerInfo.handler; + delete handler.context; + + callHook(handler, 'reset', true, transition); + callHook(handler, 'exit', transition); + }); + + var oldState = router.oldState = router.state; + router.state = newState; + var currentHandlerInfos = router.currentHandlerInfos = partition.unchanged.slice(); + + try { + forEach(partition.reset, function(handlerInfo) { + var handler = handlerInfo.handler; + callHook(handler, 'reset', false, transition); + }); + + forEach(partition.updatedContext, function(handlerInfo) { + return handlerEnteredOrUpdated(currentHandlerInfos, handlerInfo, false, transition); + }); + + forEach(partition.entered, function(handlerInfo) { + return handlerEnteredOrUpdated(currentHandlerInfos, handlerInfo, true, transition); + }); + } catch(e) { + router.state = oldState; + router.currentHandlerInfos = oldState.handlerInfos; + throw e; + } + + router.state.queryParams = finalizeQueryParamChange(router, currentHandlerInfos, newState.queryParams, transition); + } + + + /** + @private + + Helper method used by setupContexts. Handles errors or redirects + that may happen in enter/setup. + */ + function handlerEnteredOrUpdated(currentHandlerInfos, handlerInfo, enter, transition) { + + var handler = handlerInfo.handler, + context = handlerInfo.context; + + if (enter) { + callHook(handler, 'enter', transition); + } + if (transition && transition.isAborted) { + throw new TransitionAborted(); + } + + handler.context = context; + callHook(handler, 'contextDidChange'); + + callHook(handler, 'setup', context, transition); + if (transition && transition.isAborted) { + throw new TransitionAborted(); + } + + currentHandlerInfos.push(handlerInfo); + + return true; + } + + + /** + @private + + This function is called when transitioning from one URL to + another to determine which handlers are no longer active, + which handlers are newly active, and which handlers remain + active but have their context changed. + + Take a list of old handlers and new handlers and partition + them into four buckets: + + * unchanged: the handler was active in both the old and + new URL, and its context remains the same + * updated context: the handler was active in both the + old and new URL, but its context changed. The handler's + `setup` method, if any, will be called with the new + context. + * exited: the handler was active in the old URL, but is + no longer active. + * entered: the handler was not active in the old URL, but + is now active. + + The PartitionedHandlers structure has four fields: + + * `updatedContext`: a list of `HandlerInfo` objects that + represent handlers that remain active but have a changed + context + * `entered`: a list of `HandlerInfo` objects that represent + handlers that are newly active + * `exited`: a list of `HandlerInfo` objects that are no + longer active. + * `unchanged`: a list of `HanderInfo` objects that remain active. + + @param {Array[HandlerInfo]} oldHandlers a list of the handler + information for the previous URL (or `[]` if this is the + first handled transition) + @param {Array[HandlerInfo]} newHandlers a list of the handler + information for the new URL + + @return {Partition} + */ + function partitionHandlers(oldState, newState) { + var oldHandlers = oldState.handlerInfos; + var newHandlers = newState.handlerInfos; + + var handlers = { + updatedContext: [], + exited: [], + entered: [], + unchanged: [] + }; + + var handlerChanged, contextChanged = false, i, l; + + for (i=0, l=newHandlers.length; i= 0; --i) { + var handlerInfo = handlerInfos[i]; + merge(params, handlerInfo.params); + if (handlerInfo.handler.inaccessibleByURL) { + urlMethod = null; + } + } + + if (urlMethod) { + params.queryParams = transition._visibleQueryParams || state.queryParams; + var url = router.recognizer.generate(handlerName, params); + + if (urlMethod === 'replace') { + router.replaceURL(url); + } else { + router.updateURL(url); + } + } + } + + /** + @private + + Updates the URL (if necessary) and calls `setupContexts` + to update the router's array of `currentHandlerInfos`. + */ + function finalizeTransition(transition, newState) { + + try { + log(transition.router, transition.sequence, "Resolved all models on destination route; finalizing transition."); + + var router = transition.router, + handlerInfos = newState.handlerInfos, + seq = transition.sequence; + + // Run all the necessary enter/setup/exit hooks + setupContexts(router, newState, transition); + + // Check if a redirect occurred in enter/setup + if (transition.isAborted) { + // TODO: cleaner way? distinguish b/w targetHandlerInfos? + router.state.handlerInfos = router.currentHandlerInfos; + return Promise.reject(logAbort(transition)); + } + + updateURL(transition, newState, transition.intent.url); + + transition.isActive = false; + router.activeTransition = null; + + trigger(router, router.currentHandlerInfos, true, ['didTransition']); + + if (router.didTransition) { + router.didTransition(router.currentHandlerInfos); + } + + log(router, transition.sequence, "TRANSITION COMPLETE."); + + // Resolve with the final handler. + return handlerInfos[handlerInfos.length - 1].handler; + } catch(e) { + if (!((e instanceof TransitionAborted))) { + //var erroneousHandler = handlerInfos.pop(); + var infos = transition.state.handlerInfos; + transition.trigger(true, 'error', e, transition, infos[infos.length-1].handler); + transition.abort(); + } + + throw e; + } + } + + /** + @private + + Begins and returns a Transition based on the provided + arguments. Accepts arguments in the form of both URL + transitions and named transitions. + + @param {Router} router + @param {Array[Object]} args arguments passed to transitionTo, + replaceWith, or handleURL + */ + function doTransition(router, args, isIntermediate) { + // Normalize blank transitions to root URL transitions. + var name = args[0] || '/'; + + var lastArg = args[args.length-1]; + var queryParams = {}; + if (lastArg && lastArg.hasOwnProperty('queryParams')) { + queryParams = pop.call(args).queryParams; + } + + var intent; + if (args.length === 0) { + + log(router, "Updating query params"); + + // A query param update is really just a transition + // into the route you're already on. + var handlerInfos = router.state.handlerInfos; + intent = new NamedTransitionIntent({ + name: handlerInfos[handlerInfos.length - 1].name, + contexts: [], + queryParams: queryParams + }); + + } else if (name.charAt(0) === '/') { + + log(router, "Attempting URL transition to " + name); + intent = new URLTransitionIntent({ url: name }); + + } else { + + log(router, "Attempting transition to " + name); + intent = new NamedTransitionIntent({ + name: args[0], + contexts: slice.call(args, 1), + queryParams: queryParams + }); + } + + return router.transitionByIntent(intent, isIntermediate); + } + + function handlerInfosEqual(handlerInfos, otherHandlerInfos) { + if (handlerInfos.length !== otherHandlerInfos.length) { + return false; + } + + for (var i = 0, len = handlerInfos.length; i < len; ++i) { + if (handlerInfos[i] !== otherHandlerInfos[i]) { + return false; + } + } + return true; + } + + function finalizeQueryParamChange(router, resolvedHandlers, newQueryParams, transition) { + // We fire a finalizeQueryParamChange event which + // gives the new route hierarchy a chance to tell + // us which query params it's consuming and what + // their final values are. If a query param is + // no longer consumed in the final route hierarchy, + // its serialized segment will be removed + // from the URL. + + for (var k in newQueryParams) { + if (newQueryParams.hasOwnProperty(k) && + newQueryParams[k] === null) { + delete newQueryParams[k]; + } + } + + var finalQueryParamsArray = []; + trigger(router, resolvedHandlers, true, ['finalizeQueryParamChange', newQueryParams, finalQueryParamsArray, transition]); + + if (transition) { + transition._visibleQueryParams = {}; + } + + var finalQueryParams = {}; + for (var i = 0, len = finalQueryParamsArray.length; i < len; ++i) { + var qp = finalQueryParamsArray[i]; + finalQueryParams[qp.key] = qp.value; + if (transition && qp.visible !== false) { + transition._visibleQueryParams[qp.key] = qp.value; + } + } + return finalQueryParams; + } + + function notifyExistingHandlers(router, newState, newTransition) { + var oldHandlers = router.state.handlerInfos, + changing = [], + leavingIndex = null, + leaving, leavingChecker, i, oldHandlerLen, oldHandler, newHandler; + + oldHandlerLen = oldHandlers.length; + for (i = 0; i < oldHandlerLen; i++) { + oldHandler = oldHandlers[i]; + newHandler = newState.handlerInfos[i]; + + if (!newHandler || oldHandler.name !== newHandler.name) { + leavingIndex = i; + break; + } + + if (!newHandler.isResolved) { + changing.push(oldHandler); + } + } + + if (leavingIndex !== null) { + leaving = oldHandlers.slice(leavingIndex, oldHandlerLen); + leavingChecker = function(name) { + for (var h = 0, len = leaving.length; h < len; h++) { + if (leaving[h].name === name) { + return true; + } + } + return false; + }; + + router._triggerWillLeave(leaving, newTransition, leavingChecker); + } + + if (changing.length > 0) { + router._triggerWillChangeContext(changing, newTransition); + } + + trigger(router, oldHandlers, true, ['willTransition', newTransition]); + } + + __exports__["default"] = Router; + }); +enifed("router/transition-intent", + ["./utils","exports"], + function(__dependency1__, __exports__) { + "use strict"; + var merge = __dependency1__.merge; + + function TransitionIntent(props) { + this.initialize(props); + + // TODO: wat + this.data = this.data || {}; + } + + TransitionIntent.prototype = { + initialize: null, + applyToState: null + }; + + __exports__["default"] = TransitionIntent; + }); +enifed("router/transition-intent/named-transition-intent", + ["../transition-intent","../transition-state","../handler-info/factory","../utils","exports"], + function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __exports__) { + "use strict"; + var TransitionIntent = __dependency1__["default"]; + var TransitionState = __dependency2__["default"]; + var handlerInfoFactory = __dependency3__["default"]; + var isParam = __dependency4__.isParam; + var extractQueryParams = __dependency4__.extractQueryParams; + var merge = __dependency4__.merge; + var subclass = __dependency4__.subclass; + + __exports__["default"] = subclass(TransitionIntent, { + name: null, + pivotHandler: null, + contexts: null, + queryParams: null, + + initialize: function(props) { + this.name = props.name; + this.pivotHandler = props.pivotHandler; + this.contexts = props.contexts || []; + this.queryParams = props.queryParams; + }, + + applyToState: function(oldState, recognizer, getHandler, isIntermediate) { + + var partitionedArgs = extractQueryParams([this.name].concat(this.contexts)), + pureArgs = partitionedArgs[0], + queryParams = partitionedArgs[1], + handlers = recognizer.handlersFor(pureArgs[0]); + + var targetRouteName = handlers[handlers.length-1].handler; + + return this.applyToHandlers(oldState, handlers, getHandler, targetRouteName, isIntermediate); + }, + + applyToHandlers: function(oldState, handlers, getHandler, targetRouteName, isIntermediate, checkingIfActive) { + + var i, len; + var newState = new TransitionState(); + var objects = this.contexts.slice(0); + + var invalidateIndex = handlers.length; + + // Pivot handlers are provided for refresh transitions + if (this.pivotHandler) { + for (i = 0, len = handlers.length; i < len; ++i) { + if (getHandler(handlers[i].handler) === this.pivotHandler) { + invalidateIndex = i; + break; + } + } + } + + var pivotHandlerFound = !this.pivotHandler; + + for (i = handlers.length - 1; i >= 0; --i) { + var result = handlers[i]; + var name = result.handler; + var handler = getHandler(name); + + var oldHandlerInfo = oldState.handlerInfos[i]; + var newHandlerInfo = null; + + if (result.names.length > 0) { + if (i >= invalidateIndex) { + newHandlerInfo = this.createParamHandlerInfo(name, handler, result.names, objects, oldHandlerInfo); + } else { + newHandlerInfo = this.getHandlerInfoForDynamicSegment(name, handler, result.names, objects, oldHandlerInfo, targetRouteName, i); + } + } else { + // This route has no dynamic segment. + // Therefore treat as a param-based handlerInfo + // with empty params. This will cause the `model` + // hook to be called with empty params, which is desirable. + newHandlerInfo = this.createParamHandlerInfo(name, handler, result.names, objects, oldHandlerInfo); + } + + if (checkingIfActive) { + // If we're performing an isActive check, we want to + // serialize URL params with the provided context, but + // ignore mismatches between old and new context. + newHandlerInfo = newHandlerInfo.becomeResolved(null, newHandlerInfo.context); + var oldContext = oldHandlerInfo && oldHandlerInfo.context; + if (result.names.length > 0 && newHandlerInfo.context === oldContext) { + // If contexts match in isActive test, assume params also match. + // This allows for flexibility in not requiring that every last + // handler provide a `serialize` method + newHandlerInfo.params = oldHandlerInfo && oldHandlerInfo.params; + } + newHandlerInfo.context = oldContext; + } + + var handlerToUse = oldHandlerInfo; + if (i >= invalidateIndex || newHandlerInfo.shouldSupercede(oldHandlerInfo)) { + invalidateIndex = Math.min(i, invalidateIndex); + handlerToUse = newHandlerInfo; + } + + if (isIntermediate && !checkingIfActive) { + handlerToUse = handlerToUse.becomeResolved(null, handlerToUse.context); + } + + newState.handlerInfos.unshift(handlerToUse); + } + + if (objects.length > 0) { + throw new Error("More context objects were passed than there are dynamic segments for the route: " + targetRouteName); + } + + if (!isIntermediate) { + this.invalidateChildren(newState.handlerInfos, invalidateIndex); + } + + merge(newState.queryParams, this.queryParams || {}); + + return newState; + }, + + invalidateChildren: function(handlerInfos, invalidateIndex) { + for (var i = invalidateIndex, l = handlerInfos.length; i < l; ++i) { + var handlerInfo = handlerInfos[i]; + handlerInfos[i] = handlerInfos[i].getUnresolved(); + } + }, + + getHandlerInfoForDynamicSegment: function(name, handler, names, objects, oldHandlerInfo, targetRouteName, i) { + + var numNames = names.length; + var objectToUse; + if (objects.length > 0) { + + // Use the objects provided for this transition. + objectToUse = objects[objects.length - 1]; + if (isParam(objectToUse)) { + return this.createParamHandlerInfo(name, handler, names, objects, oldHandlerInfo); + } else { + objects.pop(); + } + } else if (oldHandlerInfo && oldHandlerInfo.name === name) { + // Reuse the matching oldHandlerInfo + return oldHandlerInfo; + } else { + if (this.preTransitionState) { + var preTransitionHandlerInfo = this.preTransitionState.handlerInfos[i]; + objectToUse = preTransitionHandlerInfo && preTransitionHandlerInfo.context; + } else { + // Ideally we should throw this error to provide maximal + // information to the user that not enough context objects + // were provided, but this proves too cumbersome in Ember + // in cases where inner template helpers are evaluated + // before parent helpers un-render, in which cases this + // error somewhat prematurely fires. + //throw new Error("Not enough context objects were provided to complete a transition to " + targetRouteName + ". Specifically, the " + name + " route needs an object that can be serialized into its dynamic URL segments [" + names.join(', ') + "]"); + return oldHandlerInfo; + } + } + + return handlerInfoFactory('object', { + name: name, + handler: handler, + context: objectToUse, + names: names + }); + }, + + createParamHandlerInfo: function(name, handler, names, objects, oldHandlerInfo) { + var params = {}; + + // Soak up all the provided string/numbers + var numNames = names.length; + while (numNames--) { + + // Only use old params if the names match with the new handler + var oldParams = (oldHandlerInfo && name === oldHandlerInfo.name && oldHandlerInfo.params) || {}; + + var peek = objects[objects.length - 1]; + var paramName = names[numNames]; + if (isParam(peek)) { + params[paramName] = "" + objects.pop(); + } else { + // If we're here, this means only some of the params + // were string/number params, so try and use a param + // value from a previous handler. + if (oldParams.hasOwnProperty(paramName)) { + params[paramName] = oldParams[paramName]; + } else { + throw new Error("You didn't provide enough string/numeric parameters to satisfy all of the dynamic segments for route " + name); + } + } + } + + return handlerInfoFactory('param', { + name: name, + handler: handler, + params: params + }); + } + }); + }); +enifed("router/transition-intent/url-transition-intent", + ["../transition-intent","../transition-state","../handler-info/factory","../utils","exports"], + function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __exports__) { + "use strict"; + var TransitionIntent = __dependency1__["default"]; + var TransitionState = __dependency2__["default"]; + var handlerInfoFactory = __dependency3__["default"]; + var oCreate = __dependency4__.oCreate; + var merge = __dependency4__.merge; + var subclass = __dependency4__.subclass; + + __exports__["default"] = subclass(TransitionIntent, { + url: null, + + initialize: function(props) { + this.url = props.url; + }, + + applyToState: function(oldState, recognizer, getHandler) { + var newState = new TransitionState(); + + var results = recognizer.recognize(this.url), + queryParams = {}, + i, len; + + if (!results) { + throw new UnrecognizedURLError(this.url); + } + + var statesDiffer = false; + + for (i = 0, len = results.length; i < len; ++i) { + var result = results[i]; + var name = result.handler; + var handler = getHandler(name); + + if (handler.inaccessibleByURL) { + throw new UnrecognizedURLError(this.url); + } + + var newHandlerInfo = handlerInfoFactory('param', { + name: name, + handler: handler, + params: result.params + }); + + var oldHandlerInfo = oldState.handlerInfos[i]; + if (statesDiffer || newHandlerInfo.shouldSupercede(oldHandlerInfo)) { + statesDiffer = true; + newState.handlerInfos[i] = newHandlerInfo; + } else { + newState.handlerInfos[i] = oldHandlerInfo; + } + } + + merge(newState.queryParams, results.queryParams); + + return newState; + } + }); + + /** + Promise reject reasons passed to promise rejection + handlers for failed transitions. + */ + function UnrecognizedURLError(message) { + this.message = (message || "UnrecognizedURLError"); + this.name = "UnrecognizedURLError"; + } + }); +enifed("router/transition-state", + ["./handler-info","./utils","rsvp/promise","exports"], + function(__dependency1__, __dependency2__, __dependency3__, __exports__) { + "use strict"; + var ResolvedHandlerInfo = __dependency1__.ResolvedHandlerInfo; + var forEach = __dependency2__.forEach; + var promiseLabel = __dependency2__.promiseLabel; + var callHook = __dependency2__.callHook; + var Promise = __dependency3__["default"]; + + function TransitionState(other) { + this.handlerInfos = []; + this.queryParams = {}; + this.params = {}; + } + + TransitionState.prototype = { + handlerInfos: null, + queryParams: null, + params: null, + + promiseLabel: function(label) { + var targetName = ''; + forEach(this.handlerInfos, function(handlerInfo) { + if (targetName !== '') { + targetName += '.'; + } + targetName += handlerInfo.name; + }); + return promiseLabel("'" + targetName + "': " + label); + }, + + resolve: function(shouldContinue, payload) { + var self = this; + // First, calculate params for this state. This is useful + // information to provide to the various route hooks. + var params = this.params; + forEach(this.handlerInfos, function(handlerInfo) { + params[handlerInfo.name] = handlerInfo.params || {}; + }); + + payload = payload || {}; + payload.resolveIndex = 0; + + var currentState = this; + var wasAborted = false; + + // The prelude RSVP.resolve() asyncs us into the promise land. + return Promise.resolve(null, this.promiseLabel("Start transition")) + .then(resolveOneHandlerInfo, null, this.promiseLabel('Resolve handler'))['catch'](handleError, this.promiseLabel('Handle error')); + + function innerShouldContinue() { + return Promise.resolve(shouldContinue(), currentState.promiseLabel("Check if should continue"))['catch'](function(reason) { + // We distinguish between errors that occurred + // during resolution (e.g. beforeModel/model/afterModel), + // and aborts due to a rejecting promise from shouldContinue(). + wasAborted = true; + return Promise.reject(reason); + }, currentState.promiseLabel("Handle abort")); + } + + function handleError(error) { + // This is the only possible + // reject value of TransitionState#resolve + var handlerInfos = currentState.handlerInfos; + var errorHandlerIndex = payload.resolveIndex >= handlerInfos.length ? + handlerInfos.length - 1 : payload.resolveIndex; + return Promise.reject({ + error: error, + handlerWithError: currentState.handlerInfos[errorHandlerIndex].handler, + wasAborted: wasAborted, + state: currentState + }); + } + + function proceed(resolvedHandlerInfo) { + var wasAlreadyResolved = currentState.handlerInfos[payload.resolveIndex].isResolved; + + // Swap the previously unresolved handlerInfo with + // the resolved handlerInfo + currentState.handlerInfos[payload.resolveIndex++] = resolvedHandlerInfo; + + if (!wasAlreadyResolved) { + // Call the redirect hook. The reason we call it here + // vs. afterModel is so that redirects into child + // routes don't re-run the model hooks for this + // already-resolved route. + var handler = resolvedHandlerInfo.handler; + callHook(handler, 'redirect', resolvedHandlerInfo.context, payload); + } + + // Proceed after ensuring that the redirect hook + // didn't abort this transition by transitioning elsewhere. + return innerShouldContinue().then(resolveOneHandlerInfo, null, currentState.promiseLabel('Resolve handler')); + } + + function resolveOneHandlerInfo() { + if (payload.resolveIndex === currentState.handlerInfos.length) { + // This is is the only possible + // fulfill value of TransitionState#resolve + return { + error: null, + state: currentState + }; + } + + var handlerInfo = currentState.handlerInfos[payload.resolveIndex]; + + return handlerInfo.resolve(innerShouldContinue, payload) + .then(proceed, null, currentState.promiseLabel('Proceed')); + } + } + }; + + __exports__["default"] = TransitionState; + }); +enifed("router/transition", + ["rsvp/promise","./handler-info","./utils","exports"], + function(__dependency1__, __dependency2__, __dependency3__, __exports__) { + "use strict"; + var Promise = __dependency1__["default"]; + var ResolvedHandlerInfo = __dependency2__.ResolvedHandlerInfo; + var trigger = __dependency3__.trigger; + var slice = __dependency3__.slice; + var log = __dependency3__.log; + var promiseLabel = __dependency3__.promiseLabel; + + /** + @private + + A Transition is a thennable (a promise-like object) that represents + an attempt to transition to another route. It can be aborted, either + explicitly via `abort` or by attempting another transition while a + previous one is still underway. An aborted transition can also + be `retry()`d later. + */ + function Transition(router, intent, state, error) { + var transition = this; + this.state = state || router.state; + this.intent = intent; + this.router = router; + this.data = this.intent && this.intent.data || {}; + this.resolvedModels = {}; + this.queryParams = {}; + + if (error) { + this.promise = Promise.reject(error); + this.error = error; + return; + } + + if (state) { + this.params = state.params; + this.queryParams = state.queryParams; + this.handlerInfos = state.handlerInfos; + + var len = state.handlerInfos.length; + if (len) { + this.targetName = state.handlerInfos[len-1].name; + } + + for (var i = 0; i < len; ++i) { + var handlerInfo = state.handlerInfos[i]; + + // TODO: this all seems hacky + if (!handlerInfo.isResolved) { break; } + this.pivotHandler = handlerInfo.handler; + } + + this.sequence = Transition.currentSequence++; + this.promise = state.resolve(checkForAbort, this)['catch'](function(result) { + if (result.wasAborted || transition.isAborted) { + return Promise.reject(logAbort(transition)); + } else { + transition.trigger('error', result.error, transition, result.handlerWithError); + transition.abort(); + return Promise.reject(result.error); + } + }, promiseLabel('Handle Abort')); + } else { + this.promise = Promise.resolve(this.state); + this.params = {}; + } + + function checkForAbort() { + if (transition.isAborted) { + return Promise.reject(undefined, promiseLabel("Transition aborted - reject")); + } + } + } + + Transition.currentSequence = 0; + + Transition.prototype = { + targetName: null, + urlMethod: 'update', + intent: null, + params: null, + pivotHandler: null, + resolveIndex: 0, + handlerInfos: null, + resolvedModels: null, + isActive: true, + state: null, + queryParamsOnly: false, + + isTransition: true, + + isExiting: function(handler) { + var handlerInfos = this.handlerInfos; + for (var i = 0, len = handlerInfos.length; i < len; ++i) { + var handlerInfo = handlerInfos[i]; + if (handlerInfo.name === handler || handlerInfo.handler === handler) { + return false; + } + } + return true; + }, + + /** + @public + + The Transition's internal promise. Calling `.then` on this property + is that same as calling `.then` on the Transition object itself, but + this property is exposed for when you want to pass around a + Transition's promise, but not the Transition object itself, since + Transition object can be externally `abort`ed, while the promise + cannot. + */ + promise: null, + + /** + @public + + Custom state can be stored on a Transition's `data` object. + This can be useful for decorating a Transition within an earlier + hook and shared with a later hook. Properties set on `data` will + be copied to new transitions generated by calling `retry` on this + transition. + */ + data: null, + + /** + @public + + A standard promise hook that resolves if the transition + succeeds and rejects if it fails/redirects/aborts. + + Forwards to the internal `promise` property which you can + use in situations where you want to pass around a thennable, + but not the Transition itself. + + @param {Function} onFulfilled + @param {Function} onRejected + @param {String} label optional string for labeling the promise. + Useful for tooling. + @return {Promise} + */ + then: function(onFulfilled, onRejected, label) { + return this.promise.then(onFulfilled, onRejected, label); + }, + + /** + @public + + Forwards to the internal `promise` property which you can + use in situations where you want to pass around a thennable, + but not the Transition itself. + + @method catch + @param {Function} onRejection + @param {String} label optional string for labeling the promise. + Useful for tooling. + @return {Promise} + */ + "catch": function(onRejection, label) { + return this.promise["catch"](onRejection, label); + }, + + /** + @public + + Forwards to the internal `promise` property which you can + use in situations where you want to pass around a thennable, + but not the Transition itself. + + @method finally + @param {Function} callback + @param {String} label optional string for labeling the promise. + Useful for tooling. + @return {Promise} + */ + "finally": function(callback, label) { + return this.promise["finally"](callback, label); + }, + + /** + @public + + Aborts the Transition. Note you can also implicitly abort a transition + by initiating another transition while a previous one is underway. + */ + abort: function() { + if (this.isAborted) { return this; } + log(this.router, this.sequence, this.targetName + ": transition was aborted"); + this.intent.preTransitionState = this.router.state; + this.isAborted = true; + this.isActive = false; + this.router.activeTransition = null; + return this; + }, + + /** + @public + + Retries a previously-aborted transition (making sure to abort the + transition if it's still active). Returns a new transition that + represents the new attempt to transition. + */ + retry: function() { + // TODO: add tests for merged state retry()s + this.abort(); + return this.router.transitionByIntent(this.intent, false); + }, + + /** + @public + + Sets the URL-changing method to be employed at the end of a + successful transition. By default, a new Transition will just + use `updateURL`, but passing 'replace' to this method will + cause the URL to update using 'replaceWith' instead. Omitting + a parameter will disable the URL change, allowing for transitions + that don't update the URL at completion (this is also used for + handleURL, since the URL has already changed before the + transition took place). + + @param {String} method the type of URL-changing method to use + at the end of a transition. Accepted values are 'replace', + falsy values, or any other non-falsy value (which is + interpreted as an updateURL transition). + + @return {Transition} this transition + */ + method: function(method) { + this.urlMethod = method; + return this; + }, + + /** + @public + + Fires an event on the current list of resolved/resolving + handlers within this transition. Useful for firing events + on route hierarchies that haven't fully been entered yet. + + Note: This method is also aliased as `send` + + @param {Boolean} [ignoreFailure=false] a boolean specifying whether unhandled events throw an error + @param {String} name the name of the event to fire + */ + trigger: function (ignoreFailure) { + var args = slice.call(arguments); + if (typeof ignoreFailure === 'boolean') { + args.shift(); + } else { + // Throw errors on unhandled trigger events by default + ignoreFailure = false; + } + trigger(this.router, this.state.handlerInfos.slice(0, this.resolveIndex + 1), ignoreFailure, args); + }, + + /** + @public + + Transitions are aborted and their promises rejected + when redirects occur; this method returns a promise + that will follow any redirects that occur and fulfill + with the value fulfilled by any redirecting transitions + that occur. + + @return {Promise} a promise that fulfills with the same + value that the final redirecting transition fulfills with + */ + followRedirects: function() { + var router = this.router; + return this.promise['catch'](function(reason) { + if (router.activeTransition) { + return router.activeTransition.followRedirects(); + } + return Promise.reject(reason); + }); + }, + + toString: function() { + return "Transition (sequence " + this.sequence + ")"; + }, + + /** + @private + */ + log: function(message) { + log(this.router, this.sequence, message); + } + }; + + // Alias 'trigger' as 'send' + Transition.prototype.send = Transition.prototype.trigger; + + /** + @private + + Logs and returns a TransitionAborted error. + */ + function logAbort(transition) { + log(transition.router, transition.sequence, "detected abort."); + return new TransitionAborted(); + } + + function TransitionAborted(message) { + this.message = (message || "TransitionAborted"); + this.name = "TransitionAborted"; + } + + __exports__.Transition = Transition; + __exports__.logAbort = logAbort; + __exports__.TransitionAborted = TransitionAborted; + }); +enifed("router/utils", + ["exports"], + function(__exports__) { + "use strict"; + var slice = Array.prototype.slice; + + var _isArray; + if (!Array.isArray) { + _isArray = function (x) { + return Object.prototype.toString.call(x) === "[object Array]"; + }; + } else { + _isArray = Array.isArray; + } + + var isArray = _isArray; + __exports__.isArray = isArray; + function merge(hash, other) { + for (var prop in other) { + if (other.hasOwnProperty(prop)) { hash[prop] = other[prop]; } + } + } + + var oCreate = Object.create || function(proto) { + function F() {} + F.prototype = proto; + return new F(); + }; + __exports__.oCreate = oCreate; + /** + @private + + Extracts query params from the end of an array + **/ + function extractQueryParams(array) { + var len = (array && array.length), head, queryParams; + + if(len && len > 0 && array[len - 1] && array[len - 1].hasOwnProperty('queryParams')) { + queryParams = array[len - 1].queryParams; + head = slice.call(array, 0, len - 1); + return [head, queryParams]; + } else { + return [array, null]; + } + } + + __exports__.extractQueryParams = extractQueryParams;/** + @private + + Coerces query param properties and array elements into strings. + **/ + function coerceQueryParamsToString(queryParams) { + for (var key in queryParams) { + if (typeof queryParams[key] === 'number') { + queryParams[key] = '' + queryParams[key]; + } else if (isArray(queryParams[key])) { + for (var i = 0, l = queryParams[key].length; i < l; i++) { + queryParams[key][i] = '' + queryParams[key][i]; + } + } + } + } + /** + @private + */ + function log(router, sequence, msg) { + if (!router.log) { return; } + + if (arguments.length === 3) { + router.log("Transition #" + sequence + ": " + msg); + } else { + msg = sequence; + router.log(msg); + } + } + + __exports__.log = log;function bind(context, fn) { + var boundArgs = arguments; + return function(value) { + var args = slice.call(boundArgs, 2); + args.push(value); + return fn.apply(context, args); + }; + } + + __exports__.bind = bind;function isParam(object) { + return (typeof object === "string" || object instanceof String || typeof object === "number" || object instanceof Number); + } + + + function forEach(array, callback) { + for (var i=0, l=array.length; i=0; i--) { + var handlerInfo = handlerInfos[i], + handler = handlerInfo.handler; + + if (handler.events && handler.events[name]) { + if (handler.events[name].apply(handler, args) === true) { + eventWasHandled = true; + } else { + return; + } + } + } + + if (!eventWasHandled && !ignoreFailure) { + throw new Error("Nothing handled the event '" + name + "'."); + } + } + + __exports__.trigger = trigger;function getChangelist(oldObject, newObject) { + var key; + var results = { + all: {}, + changed: {}, + removed: {} + }; + + merge(results.all, newObject); + + var didChange = false; + coerceQueryParamsToString(oldObject); + coerceQueryParamsToString(newObject); + + // Calculate removals + for (key in oldObject) { + if (oldObject.hasOwnProperty(key)) { + if (!newObject.hasOwnProperty(key)) { + didChange = true; + results.removed[key] = oldObject[key]; + } + } + } + + // Calculate changes + for (key in newObject) { + if (newObject.hasOwnProperty(key)) { + if (isArray(oldObject[key]) && isArray(newObject[key])) { + if (oldObject[key].length !== newObject[key].length) { + results.changed[key] = newObject[key]; + didChange = true; + } else { + for (var i = 0, l = oldObject[key].length; i < l; i++) { + if (oldObject[key][i] !== newObject[key][i]) { + results.changed[key] = newObject[key]; + didChange = true; + } + } + } + } + else { + if (oldObject[key] !== newObject[key]) { + results.changed[key] = newObject[key]; + didChange = true; + } + } + } + } + + return didChange && results; + } + + __exports__.getChangelist = getChangelist;function promiseLabel(label) { + return 'Router: ' + label; + } + + __exports__.promiseLabel = promiseLabel;function subclass(parentConstructor, proto) { + function C(props) { + parentConstructor.call(this, props || {}); + } + C.prototype = oCreate(parentConstructor.prototype); + merge(C.prototype, proto); + return C; + } + + __exports__.subclass = subclass;function resolveHook(obj, hookName) { + if (!obj) { return; } + var underscored = "_" + hookName; + return obj[underscored] && underscored || + obj[hookName] && hookName; + } + + function callHook(obj, hookName) { + var args = slice.call(arguments, 2); + return applyHook(obj, hookName, args); + } + + function applyHook(obj, _hookName, args) { + var hookName = resolveHook(obj, _hookName); + if (hookName) { + return obj[hookName].apply(obj, args); + } + } + + __exports__.merge = merge; + __exports__.slice = slice; + __exports__.isParam = isParam; + __exports__.coerceQueryParamsToString = coerceQueryParamsToString; + __exports__.callHook = callHook; + __exports__.resolveHook = resolveHook; + __exports__.applyHook = applyHook; + }); +enifed("rsvp", + ["./rsvp/promise","./rsvp/events","./rsvp/node","./rsvp/all","./rsvp/all-settled","./rsvp/race","./rsvp/hash","./rsvp/hash-settled","./rsvp/rethrow","./rsvp/defer","./rsvp/config","./rsvp/map","./rsvp/resolve","./rsvp/reject","./rsvp/filter","./rsvp/asap","exports"], + function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__, __dependency6__, __dependency7__, __dependency8__, __dependency9__, __dependency10__, __dependency11__, __dependency12__, __dependency13__, __dependency14__, __dependency15__, __dependency16__, __exports__) { + "use strict"; + var Promise = __dependency1__["default"]; + var EventTarget = __dependency2__["default"]; + var denodeify = __dependency3__["default"]; + var all = __dependency4__["default"]; + var allSettled = __dependency5__["default"]; + var race = __dependency6__["default"]; + var hash = __dependency7__["default"]; + var hashSettled = __dependency8__["default"]; + var rethrow = __dependency9__["default"]; + var defer = __dependency10__["default"]; + var config = __dependency11__.config; + var configure = __dependency11__.configure; + var map = __dependency12__["default"]; + var resolve = __dependency13__["default"]; + var reject = __dependency14__["default"]; + var filter = __dependency15__["default"]; + var asap = __dependency16__["default"]; + + config.async = asap; // default async is asap; + var cast = resolve; + function async(callback, arg) { + config.async(callback, arg); + } + + function on() { + config.on.apply(config, arguments); + } + + function off() { + config.off.apply(config, arguments); + } + + // Set up instrumentation through `window.__PROMISE_INTRUMENTATION__` + if (typeof window !== 'undefined' && typeof window['__PROMISE_INSTRUMENTATION__'] === 'object') { + var callbacks = window['__PROMISE_INSTRUMENTATION__']; + configure('instrument', true); + for (var eventName in callbacks) { + if (callbacks.hasOwnProperty(eventName)) { + on(eventName, callbacks[eventName]); + } + } + } + + __exports__.cast = cast; + __exports__.Promise = Promise; + __exports__.EventTarget = EventTarget; + __exports__.all = all; + __exports__.allSettled = allSettled; + __exports__.race = race; + __exports__.hash = hash; + __exports__.hashSettled = hashSettled; + __exports__.rethrow = rethrow; + __exports__.defer = defer; + __exports__.denodeify = denodeify; + __exports__.configure = configure; + __exports__.on = on; + __exports__.off = off; + __exports__.resolve = resolve; + __exports__.reject = reject; + __exports__.async = async; + __exports__.map = map; + __exports__.filter = filter; + }); +enifed("rsvp.umd", + ["./rsvp"], + function(__dependency1__) { + "use strict"; + var Promise = __dependency1__.Promise; + var allSettled = __dependency1__.allSettled; + var hash = __dependency1__.hash; + var hashSettled = __dependency1__.hashSettled; + var denodeify = __dependency1__.denodeify; + var on = __dependency1__.on; + var off = __dependency1__.off; + var map = __dependency1__.map; + var filter = __dependency1__.filter; + var resolve = __dependency1__.resolve; + var reject = __dependency1__.reject; + var rethrow = __dependency1__.rethrow; + var all = __dependency1__.all; + var defer = __dependency1__.defer; + var EventTarget = __dependency1__.EventTarget; + var configure = __dependency1__.configure; + var race = __dependency1__.race; + var async = __dependency1__.async; + + var RSVP = { + 'race': race, + 'Promise': Promise, + 'allSettled': allSettled, + 'hash': hash, + 'hashSettled': hashSettled, + 'denodeify': denodeify, + 'on': on, + 'off': off, + 'map': map, + 'filter': filter, + 'resolve': resolve, + 'reject': reject, + 'all': all, + 'rethrow': rethrow, + 'defer': defer, + 'EventTarget': EventTarget, + 'configure': configure, + 'async': async + }; + + /* global define:true module:true window: true */ + if (typeof enifed === 'function' && enifed['amd']) { + enifed(function() { return RSVP; }); + } else if (typeof module !== 'undefined' && module['exports']) { + module['exports'] = RSVP; + } else if (typeof this !== 'undefined') { + this['RSVP'] = RSVP; + } + }); +enifed("rsvp/-internal", + ["./utils","./instrument","./config","exports"], + function(__dependency1__, __dependency2__, __dependency3__, __exports__) { + "use strict"; + var objectOrFunction = __dependency1__.objectOrFunction; + var isFunction = __dependency1__.isFunction; + + var instrument = __dependency2__["default"]; + + var config = __dependency3__.config; + + function withOwnPromise() { + return new TypeError('A promises callback cannot return that same promise.'); + } + + function noop() {} + + var PENDING = void 0; + var FULFILLED = 1; + var REJECTED = 2; + + var GET_THEN_ERROR = new ErrorObject(); + + function getThen(promise) { + try { + return promise.then; + } catch(error) { + GET_THEN_ERROR.error = error; + return GET_THEN_ERROR; + } + } + + function tryThen(then, value, fulfillmentHandler, rejectionHandler) { + try { + then.call(value, fulfillmentHandler, rejectionHandler); + } catch(e) { + return e; + } + } + + function handleForeignThenable(promise, thenable, then) { + config.async(function(promise) { + var sealed = false; + var error = tryThen(then, thenable, function(value) { + if (sealed) { return; } + sealed = true; + if (thenable !== value) { + resolve(promise, value); + } else { + fulfill(promise, value); + } + }, function(reason) { + if (sealed) { return; } + sealed = true; + + reject(promise, reason); + }, 'Settle: ' + (promise._label || ' unknown promise')); + + if (!sealed && error) { + sealed = true; + reject(promise, error); + } + }, promise); + } + + function handleOwnThenable(promise, thenable) { + if (thenable._state === FULFILLED) { + fulfill(promise, thenable._result); + } else if (promise._state === REJECTED) { + reject(promise, thenable._result); + } else { + subscribe(thenable, undefined, function(value) { + if (thenable !== value) { + resolve(promise, value); + } else { + fulfill(promise, value); + } + }, function(reason) { + reject(promise, reason); + }); + } + } + + function handleMaybeThenable(promise, maybeThenable) { + if (maybeThenable.constructor === promise.constructor) { + handleOwnThenable(promise, maybeThenable); + } else { + var then = getThen(maybeThenable); + + if (then === GET_THEN_ERROR) { + reject(promise, GET_THEN_ERROR.error); + } else if (then === undefined) { + fulfill(promise, maybeThenable); + } else if (isFunction(then)) { + handleForeignThenable(promise, maybeThenable, then); + } else { + fulfill(promise, maybeThenable); + } + } + } + + function resolve(promise, value) { + if (promise === value) { + fulfill(promise, value); + } else if (objectOrFunction(value)) { + handleMaybeThenable(promise, value); + } else { + fulfill(promise, value); + } + } + + function publishRejection(promise) { + if (promise._onerror) { + promise._onerror(promise._result); + } + + publish(promise); + } + + function fulfill(promise, value) { + if (promise._state !== PENDING) { return; } + + promise._result = value; + promise._state = FULFILLED; + + if (promise._subscribers.length === 0) { + if (config.instrument) { + instrument('fulfilled', promise); + } + } else { + config.async(publish, promise); + } + } + + function reject(promise, reason) { + if (promise._state !== PENDING) { return; } + promise._state = REJECTED; + promise._result = reason; + + config.async(publishRejection, promise); + } + + function subscribe(parent, child, onFulfillment, onRejection) { + var subscribers = parent._subscribers; + var length = subscribers.length; + + parent._onerror = null; + + subscribers[length] = child; + subscribers[length + FULFILLED] = onFulfillment; + subscribers[length + REJECTED] = onRejection; + + if (length === 0 && parent._state) { + config.async(publish, parent); + } + } + + function publish(promise) { + var subscribers = promise._subscribers; + var settled = promise._state; + + if (config.instrument) { + instrument(settled === FULFILLED ? 'fulfilled' : 'rejected', promise); + } + + if (subscribers.length === 0) { return; } + + var child, callback, detail = promise._result; + + for (var i = 0; i < subscribers.length; i += 3) { + child = subscribers[i]; + callback = subscribers[i + settled]; + + if (child) { + invokeCallback(settled, child, callback, detail); + } else { + callback(detail); + } + } + + promise._subscribers.length = 0; + } + + function ErrorObject() { + this.error = null; + } + + var TRY_CATCH_ERROR = new ErrorObject(); + + function tryCatch(callback, detail) { + try { + return callback(detail); + } catch(e) { + TRY_CATCH_ERROR.error = e; + return TRY_CATCH_ERROR; + } + } + + function invokeCallback(settled, promise, callback, detail) { + var hasCallback = isFunction(callback), + value, error, succeeded, failed; + + if (hasCallback) { + value = tryCatch(callback, detail); + + if (value === TRY_CATCH_ERROR) { + failed = true; + error = value.error; + value = null; + } else { + succeeded = true; + } + + if (promise === value) { + reject(promise, withOwnPromise()); + return; + } + + } else { + value = detail; + succeeded = true; + } + + if (promise._state !== PENDING) { + // noop + } else if (hasCallback && succeeded) { + resolve(promise, value); + } else if (failed) { + reject(promise, error); + } else if (settled === FULFILLED) { + fulfill(promise, value); + } else if (settled === REJECTED) { + reject(promise, value); + } + } + + function initializePromise(promise, resolver) { + try { + resolver(function resolvePromise(value){ + resolve(promise, value); + }, function rejectPromise(reason) { + reject(promise, reason); + }); + } catch(e) { + reject(promise, e); + } + } + + __exports__.noop = noop; + __exports__.resolve = resolve; + __exports__.reject = reject; + __exports__.fulfill = fulfill; + __exports__.subscribe = subscribe; + __exports__.publish = publish; + __exports__.publishRejection = publishRejection; + __exports__.initializePromise = initializePromise; + __exports__.invokeCallback = invokeCallback; + __exports__.FULFILLED = FULFILLED; + __exports__.REJECTED = REJECTED; + __exports__.PENDING = PENDING; + }); +enifed("rsvp/all-settled", + ["./enumerator","./promise","./utils","exports"], + function(__dependency1__, __dependency2__, __dependency3__, __exports__) { + "use strict"; + var Enumerator = __dependency1__["default"]; + var makeSettledResult = __dependency1__.makeSettledResult; + var Promise = __dependency2__["default"]; + var o_create = __dependency3__.o_create; + + function AllSettled(Constructor, entries, label) { + this._superConstructor(Constructor, entries, false /* don't abort on reject */, label); + } + + AllSettled.prototype = o_create(Enumerator.prototype); + AllSettled.prototype._superConstructor = Enumerator; + AllSettled.prototype._makeResult = makeSettledResult; + AllSettled.prototype._validationError = function() { + return new Error('allSettled must be called with an array'); + }; + + /** + `RSVP.allSettled` is similar to `RSVP.all`, but instead of implementing + a fail-fast method, it waits until all the promises have returned and + shows you all the results. This is useful if you want to handle multiple + promises' failure states together as a set. + + Returns a promise that is fulfilled when all the given promises have been + settled. The return promise is fulfilled with an array of the states of + the promises passed into the `promises` array argument. + + Each state object will either indicate fulfillment or rejection, and + provide the corresponding value or reason. The states will take one of + the following formats: + + ```javascript + { state: 'fulfilled', value: value } + or + { state: 'rejected', reason: reason } + ``` + + Example: + + ```javascript + var promise1 = RSVP.Promise.resolve(1); + var promise2 = RSVP.Promise.reject(new Error('2')); + var promise3 = RSVP.Promise.reject(new Error('3')); + var promises = [ promise1, promise2, promise3 ]; + + RSVP.allSettled(promises).then(function(array){ + // array == [ + // { state: 'fulfilled', value: 1 }, + // { state: 'rejected', reason: Error }, + // { state: 'rejected', reason: Error } + // ] + // Note that for the second item, reason.message will be '2', and for the + // third item, reason.message will be '3'. + }, function(error) { + // Not run. (This block would only be called if allSettled had failed, + // for instance if passed an incorrect argument type.) + }); + ``` + + @method allSettled + @static + @for RSVP + @param {Array} promises + @param {String} label - optional string that describes the promise. + Useful for tooling. + @return {Promise} promise that is fulfilled with an array of the settled + states of the constituent promises. + */ + + __exports__["default"] = function allSettled(entries, label) { + return new AllSettled(Promise, entries, label).promise; + } + }); +enifed("rsvp/all", + ["./promise","exports"], + function(__dependency1__, __exports__) { + "use strict"; + var Promise = __dependency1__["default"]; + + /** + This is a convenient alias for `RSVP.Promise.all`. + + @method all + @static + @for RSVP + @param {Array} array Array of promises. + @param {String} label An optional label. This is useful + for tooling. + */ + __exports__["default"] = function all(array, label) { + return Promise.all(array, label); + } + }); +enifed("rsvp/asap", + ["exports"], + function(__exports__) { + "use strict"; + var len = 0; + + __exports__["default"] = function asap(callback, arg) { + queue[len] = callback; + queue[len + 1] = arg; + len += 2; + if (len === 2) { + // If len is 1, that means that we need to schedule an async flush. + // If additional callbacks are queued before the queue is flushed, they + // will be processed by this flush that we are scheduling. + scheduleFlush(); + } + } + + var browserWindow = (typeof window !== 'undefined') ? window : undefined + var browserGlobal = browserWindow || {}; + var BrowserMutationObserver = browserGlobal.MutationObserver || browserGlobal.WebKitMutationObserver; + + // test for web worker but not in IE10 + var isWorker = typeof Uint8ClampedArray !== 'undefined' && + typeof importScripts !== 'undefined' && + typeof MessageChannel !== 'undefined'; + + // node + function useNextTick() { + return function() { + process.nextTick(flush); + }; + } + + // vertx + function useVertxTimer() { + return function() { + vertxNext(flush); + }; + } + + function useMutationObserver() { + var iterations = 0; + var observer = new BrowserMutationObserver(flush); + var node = document.createTextNode(''); + observer.observe(node, { characterData: true }); + + return function() { + node.data = (iterations = ++iterations % 2); + }; + } + + // web worker + function useMessageChannel() { + var channel = new MessageChannel(); + channel.port1.onmessage = flush; + return function () { + channel.port2.postMessage(0); + }; + } + + function useSetTimeout() { + return function() { + setTimeout(flush, 1); + }; + } + + var queue = new Array(1000); + function flush() { + for (var i = 0; i < len; i+=2) { + var callback = queue[i]; + var arg = queue[i+1]; + + callback(arg); + + queue[i] = undefined; + queue[i+1] = undefined; + } + + len = 0; + } + + function attemptVertex() { + try { + var vertx = eriuqer('vertx'); + var vertxNext = vertx.runOnLoop || vertx.runOnContext; + return useVertxTimer(); + } catch(e) { + return useSetTimeout(); + } + } + + var scheduleFlush; + // Decide what async method to use to triggering processing of queued callbacks: + if (typeof process !== 'undefined' && {}.toString.call(process) === '[object process]') { + scheduleFlush = useNextTick(); + } else if (BrowserMutationObserver) { + scheduleFlush = useMutationObserver(); + } else if (isWorker) { + scheduleFlush = useMessageChannel(); + } else if (browserWindow === undefined && typeof eriuqer === 'function') { + scheduleFlush = attemptVertex(); + } else { + scheduleFlush = useSetTimeout(); + } + }); +enifed("rsvp/config", + ["./events","exports"], + function(__dependency1__, __exports__) { + "use strict"; + var EventTarget = __dependency1__["default"]; + + var config = { + instrument: false + }; + + EventTarget.mixin(config); + + function configure(name, value) { + if (name === 'onerror') { + // handle for legacy users that expect the actual + // error to be passed to their function added via + // `RSVP.configure('onerror', someFunctionHere);` + config.on('error', value); + return; + } + + if (arguments.length === 2) { + config[name] = value; + } else { + return config[name]; + } + } + + __exports__.config = config; + __exports__.configure = configure; + }); +enifed("rsvp/defer", + ["./promise","exports"], + function(__dependency1__, __exports__) { + "use strict"; + var Promise = __dependency1__["default"]; + + /** + `RSVP.defer` returns an object similar to jQuery's `$.Deferred`. + `RSVP.defer` should be used when porting over code reliant on `$.Deferred`'s + interface. New code should use the `RSVP.Promise` constructor instead. + + The object returned from `RSVP.defer` is a plain object with three properties: + + * promise - an `RSVP.Promise`. + * reject - a function that causes the `promise` property on this object to + become rejected + * resolve - a function that causes the `promise` property on this object to + become fulfilled. + + Example: + + ```javascript + var deferred = RSVP.defer(); + + deferred.resolve("Success!"); + + defered.promise.then(function(value){ + // value here is "Success!" + }); + ``` + + @method defer + @static + @for RSVP + @param {String} label optional string for labeling the promise. + Useful for tooling. + @return {Object} + */ + + __exports__["default"] = function defer(label) { + var deferred = { }; + + deferred['promise'] = new Promise(function(resolve, reject) { + deferred['resolve'] = resolve; + deferred['reject'] = reject; + }, label); + + return deferred; + } + }); +enifed("rsvp/enumerator", + ["./utils","./-internal","exports"], + function(__dependency1__, __dependency2__, __exports__) { + "use strict"; + var isArray = __dependency1__.isArray; + var isMaybeThenable = __dependency1__.isMaybeThenable; + + var noop = __dependency2__.noop; + var reject = __dependency2__.reject; + var fulfill = __dependency2__.fulfill; + var subscribe = __dependency2__.subscribe; + var FULFILLED = __dependency2__.FULFILLED; + var REJECTED = __dependency2__.REJECTED; + var PENDING = __dependency2__.PENDING; + + function makeSettledResult(state, position, value) { + if (state === FULFILLED) { + return { + state: 'fulfilled', + value: value + }; + } else { + return { + state: 'rejected', + reason: value + }; + } + } + + __exports__.makeSettledResult = makeSettledResult;function Enumerator(Constructor, input, abortOnReject, label) { + this._instanceConstructor = Constructor; + this.promise = new Constructor(noop, label); + this._abortOnReject = abortOnReject; + + if (this._validateInput(input)) { + this._input = input; + this.length = input.length; + this._remaining = input.length; + + this._init(); + + if (this.length === 0) { + fulfill(this.promise, this._result); + } else { + this.length = this.length || 0; + this._enumerate(); + if (this._remaining === 0) { + fulfill(this.promise, this._result); + } + } + } else { + reject(this.promise, this._validationError()); + } + } + + Enumerator.prototype._validateInput = function(input) { + return isArray(input); + }; + + Enumerator.prototype._validationError = function() { + return new Error('Array Methods must be provided an Array'); + }; + + Enumerator.prototype._init = function() { + this._result = new Array(this.length); + }; + + __exports__["default"] = Enumerator; + + Enumerator.prototype._enumerate = function() { + var length = this.length; + var promise = this.promise; + var input = this._input; + + for (var i = 0; promise._state === PENDING && i < length; i++) { + this._eachEntry(input[i], i); + } + }; + + Enumerator.prototype._eachEntry = function(entry, i) { + var c = this._instanceConstructor; + if (isMaybeThenable(entry)) { + if (entry.constructor === c && entry._state !== PENDING) { + entry._onerror = null; + this._settledAt(entry._state, i, entry._result); + } else { + this._willSettleAt(c.resolve(entry), i); + } + } else { + this._remaining--; + this._result[i] = this._makeResult(FULFILLED, i, entry); + } + }; + + Enumerator.prototype._settledAt = function(state, i, value) { + var promise = this.promise; + + if (promise._state === PENDING) { + this._remaining--; + + if (this._abortOnReject && state === REJECTED) { + reject(promise, value); + } else { + this._result[i] = this._makeResult(state, i, value); + } + } + + if (this._remaining === 0) { + fulfill(promise, this._result); + } + }; + + Enumerator.prototype._makeResult = function(state, i, value) { + return value; + }; + + Enumerator.prototype._willSettleAt = function(promise, i) { + var enumerator = this; + + subscribe(promise, undefined, function(value) { + enumerator._settledAt(FULFILLED, i, value); + }, function(reason) { + enumerator._settledAt(REJECTED, i, reason); + }); + }; + }); +enifed("rsvp/events", + ["exports"], + function(__exports__) { + "use strict"; + function indexOf(callbacks, callback) { + for (var i=0, l=callbacks.length; i 1; + }; + + RSVP.filter(promises, filterFn).then(function(result){ + // result is [ 2, 3 ] + }); + ``` + + If any of the `promises` given to `RSVP.filter` are rejected, the first promise + that is rejected will be given as an argument to the returned promise's + rejection handler. For example: + + ```javascript + var promise1 = RSVP.resolve(1); + var promise2 = RSVP.reject(new Error('2')); + var promise3 = RSVP.reject(new Error('3')); + var promises = [ promise1, promise2, promise3 ]; + + var filterFn = function(item){ + return item > 1; + }; + + RSVP.filter(promises, filterFn).then(function(array){ + // Code here never runs because there are rejected promises! + }, function(reason) { + // reason.message === '2' + }); + ``` + + `RSVP.filter` will also wait for any promises returned from `filterFn`. + For instance, you may want to fetch a list of users then return a subset + of those users based on some asynchronous operation: + + ```javascript + + var alice = { name: 'alice' }; + var bob = { name: 'bob' }; + var users = [ alice, bob ]; + + var promises = users.map(function(user){ + return RSVP.resolve(user); + }); + + var filterFn = function(user){ + // Here, Alice has permissions to create a blog post, but Bob does not. + return getPrivilegesForUser(user).then(function(privs){ + return privs.can_create_blog_post === true; + }); + }; + RSVP.filter(promises, filterFn).then(function(users){ + // true, because the server told us only Alice can create a blog post. + users.length === 1; + // false, because Alice is the only user present in `users` + users[0] === bob; + }); + ``` + + @method filter + @static + @for RSVP + @param {Array} promises + @param {Function} filterFn - function to be called on each resolved value to + filter the final results. + @param {String} label optional string describing the promise. Useful for + tooling. + @return {Promise} + */ + __exports__["default"] = function filter(promises, filterFn, label) { + return Promise.all(promises, label).then(function(values) { + if (!isFunction(filterFn)) { + throw new TypeError("You must pass a function as filter's second argument."); + } + + var length = values.length; + var filtered = new Array(length); + + for (var i = 0; i < length; i++) { + filtered[i] = filterFn(values[i]); + } + + return Promise.all(filtered, label).then(function(filtered) { + var results = new Array(length); + var newLength = 0; + + for (var i = 0; i < length; i++) { + if (filtered[i]) { + results[newLength] = values[i]; + newLength++; + } + } + + results.length = newLength; + + return results; + }); + }); + } + }); +enifed("rsvp/hash-settled", + ["./promise","./enumerator","./promise-hash","./utils","exports"], + function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __exports__) { + "use strict"; + var Promise = __dependency1__["default"]; + var makeSettledResult = __dependency2__.makeSettledResult; + var PromiseHash = __dependency3__["default"]; + var Enumerator = __dependency2__["default"]; + var o_create = __dependency4__.o_create; + + function HashSettled(Constructor, object, label) { + this._superConstructor(Constructor, object, false, label); + } + + HashSettled.prototype = o_create(PromiseHash.prototype); + HashSettled.prototype._superConstructor = Enumerator; + HashSettled.prototype._makeResult = makeSettledResult; + + HashSettled.prototype._validationError = function() { + return new Error('hashSettled must be called with an object'); + }; + + /** + `RSVP.hashSettled` is similar to `RSVP.allSettled`, but takes an object + instead of an array for its `promises` argument. + + Unlike `RSVP.all` or `RSVP.hash`, which implement a fail-fast method, + but like `RSVP.allSettled`, `hashSettled` waits until all the + constituent promises have returned and then shows you all the results + with their states and values/reasons. This is useful if you want to + handle multiple promises' failure states together as a set. + + Returns a promise that is fulfilled when all the given promises have been + settled, or rejected if the passed parameters are invalid. + + The returned promise is fulfilled with a hash that has the same key names as + the `promises` object argument. If any of the values in the object are not + promises, they will be copied over to the fulfilled object and marked with state + 'fulfilled'. + + Example: + + ```javascript + var promises = { + myPromise: RSVP.Promise.resolve(1), + yourPromise: RSVP.Promise.resolve(2), + theirPromise: RSVP.Promise.resolve(3), + notAPromise: 4 + }; + + RSVP.hashSettled(promises).then(function(hash){ + // hash here is an object that looks like: + // { + // myPromise: { state: 'fulfilled', value: 1 }, + // yourPromise: { state: 'fulfilled', value: 2 }, + // theirPromise: { state: 'fulfilled', value: 3 }, + // notAPromise: { state: 'fulfilled', value: 4 } + // } + }); + ``` + + If any of the `promises` given to `RSVP.hash` are rejected, the state will + be set to 'rejected' and the reason for rejection provided. + + Example: + + ```javascript + var promises = { + myPromise: RSVP.Promise.resolve(1), + rejectedPromise: RSVP.Promise.reject(new Error('rejection')), + anotherRejectedPromise: RSVP.Promise.reject(new Error('more rejection')), + }; + + RSVP.hashSettled(promises).then(function(hash){ + // hash here is an object that looks like: + // { + // myPromise: { state: 'fulfilled', value: 1 }, + // rejectedPromise: { state: 'rejected', reason: Error }, + // anotherRejectedPromise: { state: 'rejected', reason: Error }, + // } + // Note that for rejectedPromise, reason.message == 'rejection', + // and for anotherRejectedPromise, reason.message == 'more rejection'. + }); + ``` + + An important note: `RSVP.hashSettled` is intended for plain JavaScript objects that + are just a set of keys and values. `RSVP.hashSettled` will NOT preserve prototype + chains. + + Example: + + ```javascript + function MyConstructor(){ + this.example = RSVP.Promise.resolve('Example'); + } + + MyConstructor.prototype = { + protoProperty: RSVP.Promise.resolve('Proto Property') + }; + + var myObject = new MyConstructor(); + + RSVP.hashSettled(myObject).then(function(hash){ + // protoProperty will not be present, instead you will just have an + // object that looks like: + // { + // example: { state: 'fulfilled', value: 'Example' } + // } + // + // hash.hasOwnProperty('protoProperty'); // false + // 'undefined' === typeof hash.protoProperty + }); + ``` + + @method hashSettled + @for RSVP + @param {Object} promises + @param {String} label optional string that describes the promise. + Useful for tooling. + @return {Promise} promise that is fulfilled when when all properties of `promises` + have been settled. + @static + */ + __exports__["default"] = function hashSettled(object, label) { + return new HashSettled(Promise, object, label).promise; + } + }); +enifed("rsvp/hash", + ["./promise","./promise-hash","exports"], + function(__dependency1__, __dependency2__, __exports__) { + "use strict"; + var Promise = __dependency1__["default"]; + var PromiseHash = __dependency2__["default"]; + + /** + `RSVP.hash` is similar to `RSVP.all`, but takes an object instead of an array + for its `promises` argument. + + Returns a promise that is fulfilled when all the given promises have been + fulfilled, or rejected if any of them become rejected. The returned promise + is fulfilled with a hash that has the same key names as the `promises` object + argument. If any of the values in the object are not promises, they will + simply be copied over to the fulfilled object. + + Example: + + ```javascript + var promises = { + myPromise: RSVP.resolve(1), + yourPromise: RSVP.resolve(2), + theirPromise: RSVP.resolve(3), + notAPromise: 4 + }; + + RSVP.hash(promises).then(function(hash){ + // hash here is an object that looks like: + // { + // myPromise: 1, + // yourPromise: 2, + // theirPromise: 3, + // notAPromise: 4 + // } + }); + ```` + + If any of the `promises` given to `RSVP.hash` are rejected, the first promise + that is rejected will be given as the reason to the rejection handler. + + Example: + + ```javascript + var promises = { + myPromise: RSVP.resolve(1), + rejectedPromise: RSVP.reject(new Error('rejectedPromise')), + anotherRejectedPromise: RSVP.reject(new Error('anotherRejectedPromise')), + }; + + RSVP.hash(promises).then(function(hash){ + // Code here never runs because there are rejected promises! + }, function(reason) { + // reason.message === 'rejectedPromise' + }); + ``` + + An important note: `RSVP.hash` is intended for plain JavaScript objects that + are just a set of keys and values. `RSVP.hash` will NOT preserve prototype + chains. + + Example: + + ```javascript + function MyConstructor(){ + this.example = RSVP.resolve('Example'); + } + + MyConstructor.prototype = { + protoProperty: RSVP.resolve('Proto Property') + }; + + var myObject = new MyConstructor(); + + RSVP.hash(myObject).then(function(hash){ + // protoProperty will not be present, instead you will just have an + // object that looks like: + // { + // example: 'Example' + // } + // + // hash.hasOwnProperty('protoProperty'); // false + // 'undefined' === typeof hash.protoProperty + }); + ``` + + @method hash + @static + @for RSVP + @param {Object} promises + @param {String} label optional string that describes the promise. + Useful for tooling. + @return {Promise} promise that is fulfilled when all properties of `promises` + have been fulfilled, or rejected if any of them become rejected. + */ + __exports__["default"] = function hash(object, label) { + return new PromiseHash(Promise, object, label).promise; + } + }); +enifed("rsvp/instrument", + ["./config","./utils","exports"], + function(__dependency1__, __dependency2__, __exports__) { + "use strict"; + var config = __dependency1__.config; + var now = __dependency2__.now; + + var queue = []; + + function scheduleFlush() { + setTimeout(function() { + var entry; + for (var i = 0; i < queue.length; i++) { + entry = queue[i]; + + var payload = entry.payload; + + payload.guid = payload.key + payload.id; + payload.childGuid = payload.key + payload.childId; + if (payload.error) { + payload.stack = payload.error.stack; + } + + config.trigger(entry.name, entry.payload); + } + queue.length = 0; + }, 50); + } + + __exports__["default"] = function instrument(eventName, promise, child) { + if (1 === queue.push({ + name: eventName, + payload: { + key: promise._guidKey, + id: promise._id, + eventName: eventName, + detail: promise._result, + childId: child && child._id, + label: promise._label, + timeStamp: now(), + error: config["instrument-with-stack"] ? new Error(promise._label) : null + }})) { + scheduleFlush(); + } + } + }); +enifed("rsvp/map", + ["./promise","./utils","exports"], + function(__dependency1__, __dependency2__, __exports__) { + "use strict"; + var Promise = __dependency1__["default"]; + var isFunction = __dependency2__.isFunction; + + /** + `RSVP.map` is similar to JavaScript's native `map` method, except that it + waits for all promises to become fulfilled before running the `mapFn` on + each item in given to `promises`. `RSVP.map` returns a promise that will + become fulfilled with the result of running `mapFn` on the values the promises + become fulfilled with. + + For example: + + ```javascript + + var promise1 = RSVP.resolve(1); + var promise2 = RSVP.resolve(2); + var promise3 = RSVP.resolve(3); + var promises = [ promise1, promise2, promise3 ]; + + var mapFn = function(item){ + return item + 1; + }; + + RSVP.map(promises, mapFn).then(function(result){ + // result is [ 2, 3, 4 ] + }); + ``` + + If any of the `promises` given to `RSVP.map` are rejected, the first promise + that is rejected will be given as an argument to the returned promise's + rejection handler. For example: + + ```javascript + var promise1 = RSVP.resolve(1); + var promise2 = RSVP.reject(new Error('2')); + var promise3 = RSVP.reject(new Error('3')); + var promises = [ promise1, promise2, promise3 ]; + + var mapFn = function(item){ + return item + 1; + }; + + RSVP.map(promises, mapFn).then(function(array){ + // Code here never runs because there are rejected promises! + }, function(reason) { + // reason.message === '2' + }); + ``` + + `RSVP.map` will also wait if a promise is returned from `mapFn`. For example, + say you want to get all comments from a set of blog posts, but you need + the blog posts first because they contain a url to those comments. + + ```javscript + + var mapFn = function(blogPost){ + // getComments does some ajax and returns an RSVP.Promise that is fulfilled + // with some comments data + return getComments(blogPost.comments_url); + }; + + // getBlogPosts does some ajax and returns an RSVP.Promise that is fulfilled + // with some blog post data + RSVP.map(getBlogPosts(), mapFn).then(function(comments){ + // comments is the result of asking the server for the comments + // of all blog posts returned from getBlogPosts() + }); + ``` + + @method map + @static + @for RSVP + @param {Array} promises + @param {Function} mapFn function to be called on each fulfilled promise. + @param {String} label optional string for labeling the promise. + Useful for tooling. + @return {Promise} promise that is fulfilled with the result of calling + `mapFn` on each fulfilled promise or value when they become fulfilled. + The promise will be rejected if any of the given `promises` become rejected. + @static + */ + __exports__["default"] = function map(promises, mapFn, label) { + return Promise.all(promises, label).then(function(values) { + if (!isFunction(mapFn)) { + throw new TypeError("You must pass a function as map's second argument."); + } + + var length = values.length; + var results = new Array(length); + + for (var i = 0; i < length; i++) { + results[i] = mapFn(values[i]); + } + + return Promise.all(results, label); + }); + } + }); +enifed("rsvp/node", + ["./promise","./-internal","./utils","exports"], + function(__dependency1__, __dependency2__, __dependency3__, __exports__) { + "use strict"; + var Promise = __dependency1__["default"]; + var noop = __dependency2__.noop; + var resolve = __dependency2__.resolve; + var reject = __dependency2__.reject; + var isArray = __dependency3__.isArray; + + function Result() { + this.value = undefined; + } + + var ERROR = new Result(); + var GET_THEN_ERROR = new Result(); + + function getThen(obj) { + try { + return obj.then; + } catch(error) { + ERROR.value= error; + return ERROR; + } + } + + + function tryApply(f, s, a) { + try { + f.apply(s, a); + } catch(error) { + ERROR.value = error; + return ERROR; + } + } + + function makeObject(_, argumentNames) { + var obj = {}; + var name; + var i; + var length = _.length; + var args = new Array(length); + + for (var x = 0; x < length; x++) { + args[x] = _[x]; + } + + for (i = 0; i < argumentNames.length; i++) { + name = argumentNames[i]; + obj[name] = args[i + 1]; + } + + return obj; + } + + function arrayResult(_) { + var length = _.length; + var args = new Array(length - 1); + + for (var i = 1; i < length; i++) { + args[i - 1] = _[i]; + } + + return args; + } + + function wrapThenable(then, promise) { + return { + then: function(onFulFillment, onRejection) { + return then.call(promise, onFulFillment, onRejection); + } + }; + } + + /** + `RSVP.denodeify` takes a 'node-style' function and returns a function that + will return an `RSVP.Promise`. You can use `denodeify` in Node.js or the + browser when you'd prefer to use promises over using callbacks. For example, + `denodeify` transforms the following: + + ```javascript + var fs = require('fs'); + + fs.readFile('myfile.txt', function(err, data){ + if (err) return handleError(err); + handleData(data); + }); + ``` + + into: + + ```javascript + var fs = require('fs'); + var readFile = RSVP.denodeify(fs.readFile); + + readFile('myfile.txt').then(handleData, handleError); + ``` + + If the node function has multiple success parameters, then `denodeify` + just returns the first one: + + ```javascript + var request = RSVP.denodeify(require('request')); + + request('http://example.com').then(function(res) { + // ... + }); + ``` + + However, if you need all success parameters, setting `denodeify`'s + second parameter to `true` causes it to return all success parameters + as an array: + + ```javascript + var request = RSVP.denodeify(require('request'), true); + + request('http://example.com').then(function(result) { + // result[0] -> res + // result[1] -> body + }); + ``` + + Or if you pass it an array with names it returns the parameters as a hash: + + ```javascript + var request = RSVP.denodeify(require('request'), ['res', 'body']); + + request('http://example.com').then(function(result) { + // result.res + // result.body + }); + ``` + + Sometimes you need to retain the `this`: + + ```javascript + var app = require('express')(); + var render = RSVP.denodeify(app.render.bind(app)); + ``` + + The denodified function inherits from the original function. It works in all + environments, except IE 10 and below. Consequently all properties of the original + function are available to you. However, any properties you change on the + denodeified function won't be changed on the original function. Example: + + ```javascript + var request = RSVP.denodeify(require('request')), + cookieJar = request.jar(); // <- Inheritance is used here + + request('http://example.com', {jar: cookieJar}).then(function(res) { + // cookieJar.cookies holds now the cookies returned by example.com + }); + ``` + + Using `denodeify` makes it easier to compose asynchronous operations instead + of using callbacks. For example, instead of: + + ```javascript + var fs = require('fs'); + + fs.readFile('myfile.txt', function(err, data){ + if (err) { ... } // Handle error + fs.writeFile('myfile2.txt', data, function(err){ + if (err) { ... } // Handle error + console.log('done') + }); + }); + ``` + + you can chain the operations together using `then` from the returned promise: + + ```javascript + var fs = require('fs'); + var readFile = RSVP.denodeify(fs.readFile); + var writeFile = RSVP.denodeify(fs.writeFile); + + readFile('myfile.txt').then(function(data){ + return writeFile('myfile2.txt', data); + }).then(function(){ + console.log('done') + }).catch(function(error){ + // Handle error + }); + ``` + + @method denodeify + @static + @for RSVP + @param {Function} nodeFunc a 'node-style' function that takes a callback as + its last argument. The callback expects an error to be passed as its first + argument (if an error occurred, otherwise null), and the value from the + operation as its second argument ('function(err, value){ }'). + @param {Boolean|Array} argumentNames An optional paramter that if set + to `true` causes the promise to fulfill with the callback's success arguments + as an array. This is useful if the node function has multiple success + paramters. If you set this paramter to an array with names, the promise will + fulfill with a hash with these names as keys and the success parameters as + values. + @return {Function} a function that wraps `nodeFunc` to return an + `RSVP.Promise` + @static + */ + __exports__["default"] = function denodeify(nodeFunc, options) { + var fn = function() { + var self = this; + var l = arguments.length; + var args = new Array(l + 1); + var arg; + var promiseInput = false; + + for (var i = 0; i < l; ++i) { + arg = arguments[i]; + + if (!promiseInput) { + // TODO: clean this up + promiseInput = needsPromiseInput(arg); + if (promiseInput === GET_THEN_ERROR) { + var p = new Promise(noop); + reject(p, GET_THEN_ERROR.value); + return p; + } else if (promiseInput && promiseInput !== true) { + arg = wrapThenable(promiseInput, arg); + } + } + args[i] = arg; + } + + var promise = new Promise(noop); + + args[l] = function(err, val) { + if (err) + reject(promise, err); + else if (options === undefined) + resolve(promise, val); + else if (options === true) + resolve(promise, arrayResult(arguments)); + else if (isArray(options)) + resolve(promise, makeObject(arguments, options)); + else + resolve(promise, val); + }; + + if (promiseInput) { + return handlePromiseInput(promise, args, nodeFunc, self); + } else { + return handleValueInput(promise, args, nodeFunc, self); + } + }; + + fn.__proto__ = nodeFunc; + + return fn; + } + + function handleValueInput(promise, args, nodeFunc, self) { + var result = tryApply(nodeFunc, self, args); + if (result === ERROR) { + reject(promise, result.value); + } + return promise; + } + + function handlePromiseInput(promise, args, nodeFunc, self){ + return Promise.all(args).then(function(args){ + var result = tryApply(nodeFunc, self, args); + if (result === ERROR) { + reject(promise, result.value); + } + return promise; + }); + } + + function needsPromiseInput(arg) { + if (arg && typeof arg === 'object') { + if (arg.constructor === Promise) { + return true; + } else { + return getThen(arg); + } + } else { + return false; + } + } + }); +enifed("rsvp/promise-hash", + ["./enumerator","./-internal","./utils","exports"], + function(__dependency1__, __dependency2__, __dependency3__, __exports__) { + "use strict"; + var Enumerator = __dependency1__["default"]; + var PENDING = __dependency2__.PENDING; + var o_create = __dependency3__.o_create; + + function PromiseHash(Constructor, object, label) { + this._superConstructor(Constructor, object, true, label); + } + + __exports__["default"] = PromiseHash; + + PromiseHash.prototype = o_create(Enumerator.prototype); + PromiseHash.prototype._superConstructor = Enumerator; + PromiseHash.prototype._init = function() { + this._result = {}; + }; + + PromiseHash.prototype._validateInput = function(input) { + return input && typeof input === 'object'; + }; + + PromiseHash.prototype._validationError = function() { + return new Error('Promise.hash must be called with an object'); + }; + + PromiseHash.prototype._enumerate = function() { + var promise = this.promise; + var input = this._input; + var results = []; + + for (var key in input) { + if (promise._state === PENDING && input.hasOwnProperty(key)) { + results.push({ + position: key, + entry: input[key] + }); + } + } + + var length = results.length; + this._remaining = length; + var result; + + for (var i = 0; promise._state === PENDING && i < length; i++) { + result = results[i]; + this._eachEntry(result.entry, result.position); + } + }; + }); +enifed("rsvp/promise", + ["./config","./instrument","./utils","./-internal","./promise/all","./promise/race","./promise/resolve","./promise/reject","exports"], + function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__, __dependency6__, __dependency7__, __dependency8__, __exports__) { + "use strict"; + var config = __dependency1__.config; + var instrument = __dependency2__["default"]; + + var isFunction = __dependency3__.isFunction; + var now = __dependency3__.now; + + var noop = __dependency4__.noop; + var subscribe = __dependency4__.subscribe; + var initializePromise = __dependency4__.initializePromise; + var invokeCallback = __dependency4__.invokeCallback; + var FULFILLED = __dependency4__.FULFILLED; + var REJECTED = __dependency4__.REJECTED; + + var all = __dependency5__["default"]; + var race = __dependency6__["default"]; + var Resolve = __dependency7__["default"]; + var Reject = __dependency8__["default"]; + + var guidKey = 'rsvp_' + now() + '-'; + var counter = 0; + + function needsResolver() { + throw new TypeError('You must pass a resolver function as the first argument to the promise constructor'); + } + + function needsNew() { + throw new TypeError("Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function."); + } + __exports__["default"] = Promise; + /** + Promise objects represent the eventual result of an asynchronous operation. The + primary way of interacting with a promise is through its `then` method, which + registers callbacks to receive either a promise’s eventual value or the reason + why the promise cannot be fulfilled. + + Terminology + ----------- + + - `promise` is an object or function with a `then` method whose behavior conforms to this specification. + - `thenable` is an object or function that defines a `then` method. + - `value` is any legal JavaScript value (including undefined, a thenable, or a promise). + - `exception` is a value that is thrown using the throw statement. + - `reason` is a value that indicates why a promise was rejected. + - `settled` the final resting state of a promise, fulfilled or rejected. + + A promise can be in one of three states: pending, fulfilled, or rejected. + + Promises that are fulfilled have a fulfillment value and are in the fulfilled + state. Promises that are rejected have a rejection reason and are in the + rejected state. A fulfillment value is never a thenable. + + Promises can also be said to *resolve* a value. If this value is also a + promise, then the original promise's settled state will match the value's + settled state. So a promise that *resolves* a promise that rejects will + itself reject, and a promise that *resolves* a promise that fulfills will + itself fulfill. + + + Basic Usage: + ------------ + + ```js + var promise = new Promise(function(resolve, reject) { + // on success + resolve(value); + + // on failure + reject(reason); + }); + + promise.then(function(value) { + // on fulfillment + }, function(reason) { + // on rejection + }); + ``` + + Advanced Usage: + --------------- + + Promises shine when abstracting away asynchronous interactions such as + `XMLHttpRequest`s. + + ```js + function getJSON(url) { + return new Promise(function(resolve, reject){ + var xhr = new XMLHttpRequest(); + + xhr.open('GET', url); + xhr.onreadystatechange = handler; + xhr.responseType = 'json'; + xhr.setRequestHeader('Accept', 'application/json'); + xhr.send(); + + function handler() { + if (this.readyState === this.DONE) { + if (this.status === 200) { + resolve(this.response); + } else { + reject(new Error('getJSON: `' + url + '` failed with status: [' + this.status + ']')); + } + } + }; + }); + } + + getJSON('/posts.json').then(function(json) { + // on fulfillment + }, function(reason) { + // on rejection + }); + ``` + + Unlike callbacks, promises are great composable primitives. + + ```js + Promise.all([ + getJSON('/posts'), + getJSON('/comments') + ]).then(function(values){ + values[0] // => postsJSON + values[1] // => commentsJSON + + return values; + }); + ``` + + @class RSVP.Promise + @param {function} resolver + @param {String} label optional string for labeling the promise. + Useful for tooling. + @constructor + */ + function Promise(resolver, label) { + this._id = counter++; + this._label = label; + this._state = undefined; + this._result = undefined; + this._subscribers = []; + + if (config.instrument) { + instrument('created', this); + } + + if (noop !== resolver) { + if (!isFunction(resolver)) { + needsResolver(); + } + + if (!(this instanceof Promise)) { + needsNew(); + } + + initializePromise(this, resolver); + } + } + + Promise.cast = Resolve; // deprecated + Promise.all = all; + Promise.race = race; + Promise.resolve = Resolve; + Promise.reject = Reject; + + Promise.prototype = { + constructor: Promise, + + _guidKey: guidKey, + + _onerror: function (reason) { + config.trigger('error', reason); + }, + + /** + The primary way of interacting with a promise is through its `then` method, + which registers callbacks to receive either a promise's eventual value or the + reason why the promise cannot be fulfilled. + + ```js + findUser().then(function(user){ + // user is available + }, function(reason){ + // user is unavailable, and you are given the reason why + }); + ``` + + Chaining + -------- + + The return value of `then` is itself a promise. This second, 'downstream' + promise is resolved with the return value of the first promise's fulfillment + or rejection handler, or rejected if the handler throws an exception. + + ```js + findUser().then(function (user) { + return user.name; + }, function (reason) { + return 'default name'; + }).then(function (userName) { + // If `findUser` fulfilled, `userName` will be the user's name, otherwise it + // will be `'default name'` + }); + + findUser().then(function (user) { + throw new Error('Found user, but still unhappy'); + }, function (reason) { + throw new Error('`findUser` rejected and we're unhappy'); + }).then(function (value) { + // never reached + }, function (reason) { + // if `findUser` fulfilled, `reason` will be 'Found user, but still unhappy'. + // If `findUser` rejected, `reason` will be '`findUser` rejected and we're unhappy'. + }); + ``` + If the downstream promise does not specify a rejection handler, rejection reasons will be propagated further downstream. + + ```js + findUser().then(function (user) { + throw new PedagogicalException('Upstream error'); + }).then(function (value) { + // never reached + }).then(function (value) { + // never reached + }, function (reason) { + // The `PedgagocialException` is propagated all the way down to here + }); + ``` + + Assimilation + ------------ + + Sometimes the value you want to propagate to a downstream promise can only be + retrieved asynchronously. This can be achieved by returning a promise in the + fulfillment or rejection handler. The downstream promise will then be pending + until the returned promise is settled. This is called *assimilation*. + + ```js + findUser().then(function (user) { + return findCommentsByAuthor(user); + }).then(function (comments) { + // The user's comments are now available + }); + ``` + + If the assimliated promise rejects, then the downstream promise will also reject. + + ```js + findUser().then(function (user) { + return findCommentsByAuthor(user); + }).then(function (comments) { + // If `findCommentsByAuthor` fulfills, we'll have the value here + }, function (reason) { + // If `findCommentsByAuthor` rejects, we'll have the reason here + }); + ``` + + Simple Example + -------------- + + Synchronous Example + + ```javascript + var result; + + try { + result = findResult(); + // success + } catch(reason) { + // failure + } + ``` + + Errback Example + + ```js + findResult(function(result, err){ + if (err) { + // failure + } else { + // success + } + }); + ``` + + Promise Example; + + ```javascript + findResult().then(function(result){ + // success + }, function(reason){ + // failure + }); + ``` + + Advanced Example + -------------- + + Synchronous Example + + ```javascript + var author, books; + + try { + author = findAuthor(); + books = findBooksByAuthor(author); + // success + } catch(reason) { + // failure + } + ``` + + Errback Example + + ```js + + function foundBooks(books) { + + } + + function failure(reason) { + + } + + findAuthor(function(author, err){ + if (err) { + failure(err); + // failure + } else { + try { + findBoooksByAuthor(author, function(books, err) { + if (err) { + failure(err); + } else { + try { + foundBooks(books); + } catch(reason) { + failure(reason); + } + } + }); + } catch(error) { + failure(err); + } + // success + } + }); + ``` + + Promise Example; + + ```javascript + findAuthor(). + then(findBooksByAuthor). + then(function(books){ + // found books + }).catch(function(reason){ + // something went wrong + }); + ``` + + @method then + @param {Function} onFulfilled + @param {Function} onRejected + @param {String} label optional string for labeling the promise. + Useful for tooling. + @return {Promise} + */ + then: function(onFulfillment, onRejection, label) { + var parent = this; + var state = parent._state; + + if (state === FULFILLED && !onFulfillment || state === REJECTED && !onRejection) { + if (config.instrument) { + instrument('chained', this, this); + } + return this; + } + + parent._onerror = null; + + var child = new this.constructor(noop, label); + var result = parent._result; + + if (config.instrument) { + instrument('chained', parent, child); + } + + if (state) { + var callback = arguments[state - 1]; + config.async(function(){ + invokeCallback(state, child, callback, result); + }); + } else { + subscribe(parent, child, onFulfillment, onRejection); + } + + return child; + }, + + /** + `catch` is simply sugar for `then(undefined, onRejection)` which makes it the same + as the catch block of a try/catch statement. + + ```js + function findAuthor(){ + throw new Error('couldn't find that author'); + } + + // synchronous + try { + findAuthor(); + } catch(reason) { + // something went wrong + } + + // async with promises + findAuthor().catch(function(reason){ + // something went wrong + }); + ``` + + @method catch + @param {Function} onRejection + @param {String} label optional string for labeling the promise. + Useful for tooling. + @return {Promise} + */ + 'catch': function(onRejection, label) { + return this.then(null, onRejection, label); + }, + + /** + `finally` will be invoked regardless of the promise's fate just as native + try/catch/finally behaves + + Synchronous example: + + ```js + findAuthor() { + if (Math.random() > 0.5) { + throw new Error(); + } + return new Author(); + } + + try { + return findAuthor(); // succeed or fail + } catch(error) { + return findOtherAuther(); + } finally { + // always runs + // doesn't affect the return value + } + ``` + + Asynchronous example: + + ```js + findAuthor().catch(function(reason){ + return findOtherAuther(); + }).finally(function(){ + // author was either found, or not + }); + ``` + + @method finally + @param {Function} callback + @param {String} label optional string for labeling the promise. + Useful for tooling. + @return {Promise} + */ + 'finally': function(callback, label) { + var constructor = this.constructor; + + return this.then(function(value) { + return constructor.resolve(callback()).then(function(){ + return value; + }); + }, function(reason) { + return constructor.resolve(callback()).then(function(){ + throw reason; + }); + }, label); + } + }; + }); +enifed("rsvp/promise/all", + ["../enumerator","exports"], + function(__dependency1__, __exports__) { + "use strict"; + var Enumerator = __dependency1__["default"]; + + /** + `RSVP.Promise.all` accepts an array of promises, and returns a new promise which + is fulfilled with an array of fulfillment values for the passed promises, or + rejected with the reason of the first passed promise to be rejected. It casts all + elements of the passed iterable to promises as it runs this algorithm. + + Example: + + ```javascript + var promise1 = RSVP.resolve(1); + var promise2 = RSVP.resolve(2); + var promise3 = RSVP.resolve(3); + var promises = [ promise1, promise2, promise3 ]; + + RSVP.Promise.all(promises).then(function(array){ + // The array here would be [ 1, 2, 3 ]; + }); + ``` + + If any of the `promises` given to `RSVP.all` are rejected, the first promise + that is rejected will be given as an argument to the returned promises's + rejection handler. For example: + + Example: + + ```javascript + var promise1 = RSVP.resolve(1); + var promise2 = RSVP.reject(new Error("2")); + var promise3 = RSVP.reject(new Error("3")); + var promises = [ promise1, promise2, promise3 ]; + + RSVP.Promise.all(promises).then(function(array){ + // Code here never runs because there are rejected promises! + }, function(error) { + // error.message === "2" + }); + ``` + + @method all + @static + @param {Array} entries array of promises + @param {String} label optional string for labeling the promise. + Useful for tooling. + @return {Promise} promise that is fulfilled when all `promises` have been + fulfilled, or rejected if any of them become rejected. + @static + */ + __exports__["default"] = function all(entries, label) { + return new Enumerator(this, entries, true /* abort on reject */, label).promise; + } + }); +enifed("rsvp/promise/race", + ["../utils","../-internal","exports"], + function(__dependency1__, __dependency2__, __exports__) { + "use strict"; + var isArray = __dependency1__.isArray; + + var noop = __dependency2__.noop; + var resolve = __dependency2__.resolve; + var reject = __dependency2__.reject; + var subscribe = __dependency2__.subscribe; + var PENDING = __dependency2__.PENDING; + + /** + `RSVP.Promise.race` returns a new promise which is settled in the same way as the + first passed promise to settle. + + Example: + + ```javascript + var promise1 = new RSVP.Promise(function(resolve, reject){ + setTimeout(function(){ + resolve('promise 1'); + }, 200); + }); + + var promise2 = new RSVP.Promise(function(resolve, reject){ + setTimeout(function(){ + resolve('promise 2'); + }, 100); + }); + + RSVP.Promise.race([promise1, promise2]).then(function(result){ + // result === 'promise 2' because it was resolved before promise1 + // was resolved. + }); + ``` + + `RSVP.Promise.race` is deterministic in that only the state of the first + settled promise matters. For example, even if other promises given to the + `promises` array argument are resolved, but the first settled promise has + become rejected before the other promises became fulfilled, the returned + promise will become rejected: + + ```javascript + var promise1 = new RSVP.Promise(function(resolve, reject){ + setTimeout(function(){ + resolve('promise 1'); + }, 200); + }); + + var promise2 = new RSVP.Promise(function(resolve, reject){ + setTimeout(function(){ + reject(new Error('promise 2')); + }, 100); + }); + + RSVP.Promise.race([promise1, promise2]).then(function(result){ + // Code here never runs + }, function(reason){ + // reason.message === 'promise 2' because promise 2 became rejected before + // promise 1 became fulfilled + }); + ``` + + An example real-world use case is implementing timeouts: + + ```javascript + RSVP.Promise.race([ajax('foo.json'), timeout(5000)]) + ``` + + @method race + @static + @param {Array} promises array of promises to observe + @param {String} label optional string for describing the promise returned. + Useful for tooling. + @return {Promise} a promise which settles in the same way as the first passed + promise to settle. + */ + __exports__["default"] = function race(entries, label) { + /*jshint validthis:true */ + var Constructor = this; + + var promise = new Constructor(noop, label); + + if (!isArray(entries)) { + reject(promise, new TypeError('You must pass an array to race.')); + return promise; + } + + var length = entries.length; + + function onFulfillment(value) { + resolve(promise, value); + } + + function onRejection(reason) { + reject(promise, reason); + } + + for (var i = 0; promise._state === PENDING && i < length; i++) { + subscribe(Constructor.resolve(entries[i]), undefined, onFulfillment, onRejection); + } + + return promise; + } + }); +enifed("rsvp/promise/reject", + ["../-internal","exports"], + function(__dependency1__, __exports__) { + "use strict"; + var noop = __dependency1__.noop; + var _reject = __dependency1__.reject; + + /** + `RSVP.Promise.reject` returns a promise rejected with the passed `reason`. + It is shorthand for the following: + + ```javascript + var promise = new RSVP.Promise(function(resolve, reject){ + reject(new Error('WHOOPS')); + }); + + promise.then(function(value){ + // Code here doesn't run because the promise is rejected! + }, function(reason){ + // reason.message === 'WHOOPS' + }); + ``` + + Instead of writing the above, your code now simply becomes the following: + + ```javascript + var promise = RSVP.Promise.reject(new Error('WHOOPS')); + + promise.then(function(value){ + // Code here doesn't run because the promise is rejected! + }, function(reason){ + // reason.message === 'WHOOPS' + }); + ``` + + @method reject + @static + @param {Any} reason value that the returned promise will be rejected with. + @param {String} label optional string for identifying the returned promise. + Useful for tooling. + @return {Promise} a promise rejected with the given `reason`. + */ + __exports__["default"] = function reject(reason, label) { + /*jshint validthis:true */ + var Constructor = this; + var promise = new Constructor(noop, label); + _reject(promise, reason); + return promise; + } + }); +enifed("rsvp/promise/resolve", + ["../-internal","exports"], + function(__dependency1__, __exports__) { + "use strict"; + var noop = __dependency1__.noop; + var _resolve = __dependency1__.resolve; + + /** + `RSVP.Promise.resolve` returns a promise that will become resolved with the + passed `value`. It is shorthand for the following: + + ```javascript + var promise = new RSVP.Promise(function(resolve, reject){ + resolve(1); + }); + + promise.then(function(value){ + // value === 1 + }); + ``` + + Instead of writing the above, your code now simply becomes the following: + + ```javascript + var promise = RSVP.Promise.resolve(1); + + promise.then(function(value){ + // value === 1 + }); + ``` + + @method resolve + @static + @param {Any} value value that the returned promise will be resolved with + @param {String} label optional string for identifying the returned promise. + Useful for tooling. + @return {Promise} a promise that will become fulfilled with the given + `value` + */ + __exports__["default"] = function resolve(object, label) { + /*jshint validthis:true */ + var Constructor = this; + + if (object && typeof object === 'object' && object.constructor === Constructor) { + return object; + } + + var promise = new Constructor(noop, label); + _resolve(promise, object); + return promise; + } + }); +enifed("rsvp/race", + ["./promise","exports"], + function(__dependency1__, __exports__) { + "use strict"; + var Promise = __dependency1__["default"]; + + /** + This is a convenient alias for `RSVP.Promise.race`. + + @method race + @static + @for RSVP + @param {Array} array Array of promises. + @param {String} label An optional label. This is useful + for tooling. + */ + __exports__["default"] = function race(array, label) { + return Promise.race(array, label); + } + }); +enifed("rsvp/reject", + ["./promise","exports"], + function(__dependency1__, __exports__) { + "use strict"; + var Promise = __dependency1__["default"]; + + /** + This is a convenient alias for `RSVP.Promise.reject`. + + @method reject + @static + @for RSVP + @param {Any} reason value that the returned promise will be rejected with. + @param {String} label optional string for identifying the returned promise. + Useful for tooling. + @return {Promise} a promise rejected with the given `reason`. + */ + __exports__["default"] = function reject(reason, label) { + return Promise.reject(reason, label); + } + }); +enifed("rsvp/resolve", + ["./promise","exports"], + function(__dependency1__, __exports__) { + "use strict"; + var Promise = __dependency1__["default"]; + + /** + This is a convenient alias for `RSVP.Promise.resolve`. + + @method resolve + @static + @for RSVP + @param {Any} value value that the returned promise will be resolved with + @param {String} label optional string for identifying the returned promise. + Useful for tooling. + @return {Promise} a promise that will become fulfilled with the given + `value` + */ + __exports__["default"] = function resolve(value, label) { + return Promise.resolve(value, label); + } + }); +enifed("rsvp/rethrow", + ["exports"], + function(__exports__) { + "use strict"; + /** + `RSVP.rethrow` will rethrow an error on the next turn of the JavaScript event + loop in order to aid debugging. + + Promises A+ specifies that any exceptions that occur with a promise must be + caught by the promises implementation and bubbled to the last handler. For + this reason, it is recommended that you always specify a second rejection + handler function to `then`. However, `RSVP.rethrow` will throw the exception + outside of the promise, so it bubbles up to your console if in the browser, + or domain/cause uncaught exception in Node. `rethrow` will also throw the + error again so the error can be handled by the promise per the spec. + + ```javascript + function throws(){ + throw new Error('Whoops!'); + } + + var promise = new RSVP.Promise(function(resolve, reject){ + throws(); + }); + + promise.catch(RSVP.rethrow).then(function(){ + // Code here doesn't run because the promise became rejected due to an + // error! + }, function (err){ + // handle the error here + }); + ``` + + The 'Whoops' error will be thrown on the next turn of the event loop + and you can watch for it in your console. You can also handle it using a + rejection handler given to `.then` or `.catch` on the returned promise. + + @method rethrow + @static + @for RSVP + @param {Error} reason reason the promise became rejected. + @throws Error + @static + */ + __exports__["default"] = function rethrow(reason) { + setTimeout(function() { + throw reason; + }); + throw reason; + } + }); +enifed("rsvp/utils", + ["exports"], + function(__exports__) { + "use strict"; + function objectOrFunction(x) { + return typeof x === 'function' || (typeof x === 'object' && x !== null); + } + + __exports__.objectOrFunction = objectOrFunction;function isFunction(x) { + return typeof x === 'function'; + } + + __exports__.isFunction = isFunction;function isMaybeThenable(x) { + return typeof x === 'object' && x !== null; + } + + __exports__.isMaybeThenable = isMaybeThenable;var _isArray; + if (!Array.isArray) { + _isArray = function (x) { + return Object.prototype.toString.call(x) === '[object Array]'; + }; + } else { + _isArray = Array.isArray; + } + + var isArray = _isArray; + __exports__.isArray = isArray; + // Date.now is not available in browsers < IE9 + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now#Compatibility + var now = Date.now || function() { return new Date().getTime(); }; + __exports__.now = now; + function F() { } + + var o_create = (Object.create || function (o) { + if (arguments.length > 1) { + throw new Error('Second argument not supported'); + } + if (typeof o !== 'object') { + throw new TypeError('Argument must be an object'); + } + F.prototype = o; + return new F(); + }); + __exports__.o_create = o_create; + }); +requireModule("ember"); + +})(); \ No newline at end of file diff --git a/imdb-lookup/js/libs/ember-data-1.0.0-beta.12.js b/imdb-lookup/js/libs/ember-data-1.0.0-beta.12.js new file mode 100644 index 0000000..a2851b9 --- /dev/null +++ b/imdb-lookup/js/libs/ember-data-1.0.0-beta.12.js @@ -0,0 +1,12945 @@ +(function(global){ +var enifed, requireModule, eriuqer, requirejs; + +(function() { + + var _isArray; + if (!Array.isArray) { + _isArray = function (x) { + return Object.prototype.toString.call(x) === "[object Array]"; + }; + } else { + _isArray = Array.isArray; + } + + var registry = {}, seen = {}, state = {}; + var FAILED = false; + + enifed = function(name, deps, callback) { + + if (!_isArray(deps)) { + callback = deps; + deps = []; + } + + registry[name] = { + deps: deps, + callback: callback + }; + }; + + function reify(deps, name, seen) { + var length = deps.length; + var reified = new Array(length); + var dep; + var exports; + + for (var i = 0, l = length; i < l; i++) { + dep = deps[i]; + if (dep === 'exports') { + exports = reified[i] = seen; + } else { + reified[i] = eriuqer(resolve(dep, name)); + } + } + + return { + deps: reified, + exports: exports + }; + } + + requirejs = eriuqer = requireModule = function(name) { + if (state[name] !== FAILED && + seen.hasOwnProperty(name)) { + return seen[name]; + } + + if (!registry[name]) { + throw new Error('Could not find module ' + name); + } + + var mod = registry[name]; + var reified; + var module; + var loaded = false; + + seen[name] = { }; // placeholder for run-time cycles + + try { + reified = reify(mod.deps, name, seen[name]); + module = mod.callback.apply(this, reified.deps); + loaded = true; + } finally { + if (!loaded) { + state[name] = FAILED; + } + } + + return reified.exports ? seen[name] : (seen[name] = module); + }; + + function resolve(child, name) { + if (child.charAt(0) !== '.') { return child; } + + var parts = child.split('/'); + var nameParts = name.split('/'); + var parentBase; + + if (nameParts.length === 1) { + parentBase = nameParts; + } else { + parentBase = nameParts.slice(0, -1); + } + + for (var i = 0, l = parts.length; i < l; i++) { + var part = parts[i]; + + if (part === '..') { parentBase.pop(); } + else if (part === '.') { continue; } + else { parentBase.push(part); } + } + + return parentBase.join('/'); + } + + requirejs.entries = requirejs._eak_seen = registry; + requirejs.clear = function(){ + requirejs.entries = requirejs._eak_seen = registry = {}; + seen = state = {}; + }; +})(); + +enifed("activemodel-adapter", + ["activemodel-adapter/system","exports"], + function(__dependency1__, __exports__) { + "use strict"; + var ActiveModelAdapter = __dependency1__.ActiveModelAdapter; + var ActiveModelSerializer = __dependency1__.ActiveModelSerializer; + + __exports__.ActiveModelAdapter = ActiveModelAdapter; + __exports__.ActiveModelSerializer = ActiveModelSerializer; + }); +enifed("activemodel-adapter/setup-container", + ["ember-data/system/container_proxy","activemodel-adapter/system/active_model_serializer","activemodel-adapter/system/active_model_adapter","exports"], + function(__dependency1__, __dependency2__, __dependency3__, __exports__) { + "use strict"; + var ContainerProxy = __dependency1__["default"]; + var ActiveModelSerializer = __dependency2__["default"]; + var ActiveModelAdapter = __dependency3__["default"]; + + __exports__["default"] = function setupActiveModelAdapter(container, application){ + var proxy = new ContainerProxy(container); + proxy.registerDeprecations([ + { deprecated: 'serializer:_ams', valid: 'serializer:-active-model' }, + { deprecated: 'adapter:_ams', valid: 'adapter:-active-model' } + ]); + + container.register('serializer:-active-model', ActiveModelSerializer); + container.register('adapter:-active-model', ActiveModelAdapter); + }; + }); +enifed("activemodel-adapter/system", + ["activemodel-adapter/system/active_model_adapter","activemodel-adapter/system/active_model_serializer","exports"], + function(__dependency1__, __dependency2__, __exports__) { + "use strict"; + var ActiveModelAdapter = __dependency1__["default"]; + var ActiveModelSerializer = __dependency2__["default"]; + + __exports__.ActiveModelAdapter = ActiveModelAdapter; + __exports__.ActiveModelSerializer = ActiveModelSerializer; + }); +enifed("activemodel-adapter/system/active_model_adapter", + ["ember-data/adapters","ember-data/system/adapter","ember-inflector","exports"], + function(__dependency1__, __dependency2__, __dependency3__, __exports__) { + "use strict"; + var RESTAdapter = __dependency1__.RESTAdapter; + var InvalidError = __dependency2__.InvalidError; + var pluralize = __dependency3__.pluralize; + + /** + @module ember-data + */ + + var decamelize = Ember.String.decamelize, + underscore = Ember.String.underscore; + + /** + The ActiveModelAdapter is a subclass of the RESTAdapter designed to integrate + with a JSON API that uses an underscored naming convention instead of camelCasing. + It has been designed to work out of the box with the + [active_model_serializers](http://github.com/rails-api/active_model_serializers) + Ruby gem. This Adapter expects specific settings using ActiveModel::Serializers, + `embed :ids, embed_in_root: true` which sideloads the records. + + This adapter extends the DS.RESTAdapter by making consistent use of the camelization, + decamelization and pluralization methods to normalize the serialized JSON into a + format that is compatible with a conventional Rails backend and Ember Data. + + ## JSON Structure + + The ActiveModelAdapter expects the JSON returned from your server to follow + the REST adapter conventions substituting underscored keys for camelcased ones. + + Unlike the DS.RESTAdapter, async relationship keys must be the singular form + of the relationship name, followed by "_id" for DS.belongsTo relationships, + or "_ids" for DS.hasMany relationships. + + ### Conventional Names + + Attribute names in your JSON payload should be the underscored versions of + the attributes in your Ember.js models. + + For example, if you have a `Person` model: + + ```js + App.FamousPerson = DS.Model.extend({ + firstName: DS.attr('string'), + lastName: DS.attr('string'), + occupation: DS.attr('string') + }); + ``` + + The JSON returned should look like this: + + ```js + { + "famous_person": { + "id": 1, + "first_name": "Barack", + "last_name": "Obama", + "occupation": "President" + } + } + ``` + + Let's imagine that `Occupation` is just another model: + + ```js + App.Person = DS.Model.extend({ + firstName: DS.attr('string'), + lastName: DS.attr('string'), + occupation: DS.belongsTo('occupation') + }); + + App.Occupation = DS.Model.extend({ + name: DS.attr('string'), + salary: DS.attr('number'), + people: DS.hasMany('person') + }); + ``` + + The JSON needed to avoid extra server calls, should look like this: + + ```js + { + "people": [{ + "id": 1, + "first_name": "Barack", + "last_name": "Obama", + "occupation_id": 1 + }], + + "occupations": [{ + "id": 1, + "name": "President", + "salary": 100000, + "person_ids": [1] + }] + } + ``` + + @class ActiveModelAdapter + @constructor + @namespace DS + @extends DS.RESTAdapter + **/ + + var ActiveModelAdapter = RESTAdapter.extend({ + defaultSerializer: '-active-model', + /** + The ActiveModelAdapter overrides the `pathForType` method to build + underscored URLs by decamelizing and pluralizing the object type name. + + ```js + this.pathForType("famousPerson"); + //=> "famous_people" + ``` + + @method pathForType + @param {String} type + @return String + */ + pathForType: function(type) { + var decamelized = decamelize(type); + var underscored = underscore(decamelized); + return pluralize(underscored); + }, + + /** + The ActiveModelAdapter overrides the `ajaxError` method + to return a DS.InvalidError for all 422 Unprocessable Entity + responses. + + A 422 HTTP response from the server generally implies that the request + was well formed but the API was unable to process it because the + content was not semantically correct or meaningful per the API. + + For more information on 422 HTTP Error code see 11.2 WebDAV RFC 4918 + https://tools.ietf.org/html/rfc4918#section-11.2 + + @method ajaxError + @param {Object} jqXHR + @return error + */ + ajaxError: function(jqXHR) { + var error = this._super(jqXHR); + + if (jqXHR && jqXHR.status === 422) { + return new InvalidError(Ember.$.parseJSON(jqXHR.responseText)); + } else { + return error; + } + } + }); + + __exports__["default"] = ActiveModelAdapter; + }); +enifed("activemodel-adapter/system/active_model_serializer", + ["ember-inflector","ember-data/serializers/rest_serializer","exports"], + function(__dependency1__, __dependency2__, __exports__) { + "use strict"; + var singularize = __dependency1__.singularize; + var RESTSerializer = __dependency2__["default"]; + /** + @module ember-data + */ + + var get = Ember.get, + forEach = Ember.EnumerableUtils.forEach, + camelize = Ember.String.camelize, + capitalize = Ember.String.capitalize, + decamelize = Ember.String.decamelize, + underscore = Ember.String.underscore; + /** + The ActiveModelSerializer is a subclass of the RESTSerializer designed to integrate + with a JSON API that uses an underscored naming convention instead of camelCasing. + It has been designed to work out of the box with the + [active_model_serializers](http://github.com/rails-api/active_model_serializers) + Ruby gem. This Serializer expects specific settings using ActiveModel::Serializers, + `embed :ids, embed_in_root: true` which sideloads the records. + + This serializer extends the DS.RESTSerializer by making consistent + use of the camelization, decamelization and pluralization methods to + normalize the serialized JSON into a format that is compatible with + a conventional Rails backend and Ember Data. + + ## JSON Structure + + The ActiveModelSerializer expects the JSON returned from your server + to follow the REST adapter conventions substituting underscored keys + for camelcased ones. + + ### Conventional Names + + Attribute names in your JSON payload should be the underscored versions of + the attributes in your Ember.js models. + + For example, if you have a `Person` model: + + ```js + App.FamousPerson = DS.Model.extend({ + firstName: DS.attr('string'), + lastName: DS.attr('string'), + occupation: DS.attr('string') + }); + ``` + + The JSON returned should look like this: + + ```js + { + "famous_person": { + "id": 1, + "first_name": "Barack", + "last_name": "Obama", + "occupation": "President" + } + } + ``` + + Let's imagine that `Occupation` is just another model: + + ```js + App.Person = DS.Model.extend({ + firstName: DS.attr('string'), + lastName: DS.attr('string'), + occupation: DS.belongsTo('occupation') + }); + + App.Occupation = DS.Model.extend({ + name: DS.attr('string'), + salary: DS.attr('number'), + people: DS.hasMany('person') + }); + ``` + + The JSON needed to avoid extra server calls, should look like this: + + ```js + { + "people": [{ + "id": 1, + "first_name": "Barack", + "last_name": "Obama", + "occupation_id": 1 + }], + + "occupations": [{ + "id": 1, + "name": "President", + "salary": 100000, + "person_ids": [1] + }] + } + ``` + + @class ActiveModelSerializer + @namespace DS + @extends DS.RESTSerializer + */ + var ActiveModelSerializer = RESTSerializer.extend({ + // SERIALIZE + + /** + Converts camelCased attributes to underscored when serializing. + + @method keyForAttribute + @param {String} attribute + @return String + */ + keyForAttribute: function(attr) { + return decamelize(attr); + }, + + /** + Underscores relationship names and appends "_id" or "_ids" when serializing + relationship keys. + + @method keyForRelationship + @param {String} key + @param {String} kind + @return String + */ + keyForRelationship: function(rawKey, kind) { + var key = decamelize(rawKey); + if (kind === "belongsTo") { + return key + "_id"; + } else if (kind === "hasMany") { + return singularize(key) + "_ids"; + } else { + return key; + } + }, + + /* + Does not serialize hasMany relationships by default. + */ + serializeHasMany: Ember.K, + + /** + Underscores the JSON root keys when serializing. + + @method serializeIntoHash + @param {Object} hash + @param {subclass of DS.Model} type + @param {DS.Model} record + @param {Object} options + */ + serializeIntoHash: function(data, type, record, options) { + var root = underscore(decamelize(type.typeKey)); + data[root] = this.serialize(record, options); + }, + + /** + Serializes a polymorphic type as a fully capitalized model name. + + @method serializePolymorphicType + @param {DS.Model} record + @param {Object} json + @param {Object} relationship + */ + serializePolymorphicType: function(record, json, relationship) { + var key = relationship.key; + var belongsTo = get(record, key); + var jsonKey = underscore(key + "_type"); + + if (Ember.isNone(belongsTo)) { + json[jsonKey] = null; + } else { + json[jsonKey] = capitalize(camelize(belongsTo.constructor.typeKey)); + } + }, + + // EXTRACT + + /** + Add extra step to `DS.RESTSerializer.normalize` so links are normalized. + + If your payload looks like: + + ```js + { + "post": { + "id": 1, + "title": "Rails is omakase", + "links": { "flagged_comments": "api/comments/flagged" } + } + } + ``` + + The normalized version would look like this + + ```js + { + "post": { + "id": 1, + "title": "Rails is omakase", + "links": { "flaggedComments": "api/comments/flagged" } + } + } + ``` + + @method normalize + @param {subclass of DS.Model} type + @param {Object} hash + @param {String} prop + @return Object + */ + + normalize: function(type, hash, prop) { + this.normalizeLinks(hash); + + return this._super(type, hash, prop); + }, + + /** + Convert `snake_cased` links to `camelCase` + + @method normalizeLinks + @param {Object} data + */ + + normalizeLinks: function(data){ + if (data.links) { + var links = data.links; + + for (var link in links) { + var camelizedLink = camelize(link); + + if (camelizedLink !== link) { + links[camelizedLink] = links[link]; + delete links[link]; + } + } + } + }, + + /** + Normalize the polymorphic type from the JSON. + + Normalize: + ```js + { + id: "1" + minion: { type: "evil_minion", id: "12"} + } + ``` + + To: + ```js + { + id: "1" + minion: { type: "evilMinion", id: "12"} + } + ``` + + @method normalizeRelationships + @private + */ + normalizeRelationships: function(type, hash) { + + if (this.keyForRelationship) { + type.eachRelationship(function(key, relationship) { + var payloadKey, payload; + if (relationship.options.polymorphic) { + payloadKey = this.keyForAttribute(key); + payload = hash[payloadKey]; + if (payload && payload.type) { + payload.type = this.typeForRoot(payload.type); + } else if (payload && relationship.kind === "hasMany") { + var self = this; + forEach(payload, function(single) { + single.type = self.typeForRoot(single.type); + }); + } + } else { + payloadKey = this.keyForRelationship(key, relationship.kind); + if (!hash.hasOwnProperty(payloadKey)) { return; } + payload = hash[payloadKey]; + } + + hash[key] = payload; + + if (key !== payloadKey) { + delete hash[payloadKey]; + } + }, this); + } + } + }); + + __exports__["default"] = ActiveModelSerializer; + }); +enifed("ember-data", + ["ember-data/system/create","ember-data/core","ember-data/ext/date","ember-data/system/promise_proxies","ember-data/system/store","ember-data/system/model","ember-data/system/adapter","ember-data/system/debug","ember-data/system/record_arrays","ember-data/system/record_array_manager","ember-data/adapters","ember-data/serializers/json_serializer","ember-data/serializers/rest_serializer","ember-inflector","ember-data/serializers/embedded_records_mixin","activemodel-adapter","ember-data/transforms","ember-data/system/relationships","ember-data/ember-initializer","ember-data/setup-container","ember-data/system/container_proxy","ember-data/system/relationships/relationship","exports"], + function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__, __dependency6__, __dependency7__, __dependency8__, __dependency9__, __dependency10__, __dependency11__, __dependency12__, __dependency13__, __dependency14__, __dependency15__, __dependency16__, __dependency17__, __dependency18__, __dependency19__, __dependency20__, __dependency21__, __dependency22__, __exports__) { + "use strict"; + /** + Ember Data + + @module ember-data + @main ember-data + */ + + // support RSVP 2.x via resolve, but prefer RSVP 3.x's Promise.cast + Ember.RSVP.Promise.cast = Ember.RSVP.Promise.cast || Ember.RSVP.resolve; + + var DS = __dependency2__["default"]; + + var PromiseArray = __dependency4__.PromiseArray; + var PromiseObject = __dependency4__.PromiseObject; + var Store = __dependency5__.Store; + var Model = __dependency6__.Model; + var Errors = __dependency6__.Errors; + var RootState = __dependency6__.RootState; + var attr = __dependency6__.attr; + var InvalidError = __dependency7__.InvalidError; + var Adapter = __dependency7__.Adapter; + var DebugAdapter = __dependency8__["default"]; + var RecordArray = __dependency9__.RecordArray; + var FilteredRecordArray = __dependency9__.FilteredRecordArray; + var AdapterPopulatedRecordArray = __dependency9__.AdapterPopulatedRecordArray; + var ManyArray = __dependency9__.ManyArray; + var RecordArrayManager = __dependency10__["default"]; + var RESTAdapter = __dependency11__.RESTAdapter; + var FixtureAdapter = __dependency11__.FixtureAdapter; + var JSONSerializer = __dependency12__["default"]; + var RESTSerializer = __dependency13__["default"]; + var EmbeddedRecordsMixin = __dependency15__["default"]; + var ActiveModelAdapter = __dependency16__.ActiveModelAdapter; + var ActiveModelSerializer = __dependency16__.ActiveModelSerializer; + + var Transform = __dependency17__.Transform; + var DateTransform = __dependency17__.DateTransform; + var NumberTransform = __dependency17__.NumberTransform; + var StringTransform = __dependency17__.StringTransform; + var BooleanTransform = __dependency17__.BooleanTransform; + + var hasMany = __dependency18__.hasMany; + var belongsTo = __dependency18__.belongsTo; + var setupContainer = __dependency20__["default"]; + + var ContainerProxy = __dependency21__["default"]; + var Relationship = __dependency22__.Relationship; + + DS.Store = Store; + DS.PromiseArray = PromiseArray; + DS.PromiseObject = PromiseObject; + + DS.Model = Model; + DS.RootState = RootState; + DS.attr = attr; + DS.Errors = Errors; + + DS.Adapter = Adapter; + DS.InvalidError = InvalidError; + + DS.DebugAdapter = DebugAdapter; + + DS.RecordArray = RecordArray; + DS.FilteredRecordArray = FilteredRecordArray; + DS.AdapterPopulatedRecordArray = AdapterPopulatedRecordArray; + DS.ManyArray = ManyArray; + + DS.RecordArrayManager = RecordArrayManager; + + DS.RESTAdapter = RESTAdapter; + DS.FixtureAdapter = FixtureAdapter; + + DS.RESTSerializer = RESTSerializer; + DS.JSONSerializer = JSONSerializer; + + DS.Transform = Transform; + DS.DateTransform = DateTransform; + DS.StringTransform = StringTransform; + DS.NumberTransform = NumberTransform; + DS.BooleanTransform = BooleanTransform; + + DS.ActiveModelAdapter = ActiveModelAdapter; + DS.ActiveModelSerializer = ActiveModelSerializer; + DS.EmbeddedRecordsMixin = EmbeddedRecordsMixin; + + DS.belongsTo = belongsTo; + DS.hasMany = hasMany; + + DS.Relationship = Relationship; + + DS.ContainerProxy = ContainerProxy; + + DS._setupContainer = setupContainer; + + Ember.lookup.DS = DS; + + __exports__["default"] = DS; + }); +enifed("ember-data/adapters", + ["ember-data/adapters/fixture_adapter","ember-data/adapters/rest_adapter","exports"], + function(__dependency1__, __dependency2__, __exports__) { + "use strict"; + /** + @module ember-data + */ + + var FixtureAdapter = __dependency1__["default"]; + var RESTAdapter = __dependency2__["default"]; + + __exports__.RESTAdapter = RESTAdapter; + __exports__.FixtureAdapter = FixtureAdapter; + }); +enifed("ember-data/adapters/fixture_adapter", + ["ember-data/system/adapter","exports"], + function(__dependency1__, __exports__) { + "use strict"; + /** + @module ember-data + */ + + var get = Ember.get; + var fmt = Ember.String.fmt; + var indexOf = Ember.EnumerableUtils.indexOf; + + var counter = 0; + + var Adapter = __dependency1__["default"]; + + /** + `DS.FixtureAdapter` is an adapter that loads records from memory. + It's primarily used for development and testing. You can also use + `DS.FixtureAdapter` while working on the API but is not ready to + integrate yet. It is a fully functioning adapter. All CRUD methods + are implemented. You can also implement query logic that a remote + system would do. It's possible to develop your entire application + with `DS.FixtureAdapter`. + + For information on how to use the `FixtureAdapter` in your + application please see the [FixtureAdapter + guide](/guides/models/the-fixture-adapter/). + + @class FixtureAdapter + @namespace DS + @extends DS.Adapter + */ + __exports__["default"] = Adapter.extend({ + // by default, fixtures are already in normalized form + serializer: null, + + /** + If `simulateRemoteResponse` is `true` the `FixtureAdapter` will + wait a number of milliseconds before resolving promises with the + fixture values. The wait time can be configured via the `latency` + property. + + @property simulateRemoteResponse + @type {Boolean} + @default true + */ + simulateRemoteResponse: true, + + /** + By default the `FixtureAdapter` will simulate a wait of the + `latency` milliseconds before resolving promises with the fixture + values. This behavior can be turned off via the + `simulateRemoteResponse` property. + + @property latency + @type {Number} + @default 50 + */ + latency: 50, + + /** + Implement this method in order to provide data associated with a type + + @method fixturesForType + @param {Subclass of DS.Model} type + @return {Array} + */ + fixturesForType: function(type) { + if (type.FIXTURES) { + var fixtures = Ember.A(type.FIXTURES); + return fixtures.map(function(fixture){ + var fixtureIdType = typeof fixture.id; + if(fixtureIdType !== "number" && fixtureIdType !== "string"){ + throw new Error(fmt('the id property must be defined as a number or string for fixture %@', [fixture])); + } + fixture.id = fixture.id + ''; + return fixture; + }); + } + return null; + }, + + /** + Implement this method in order to query fixtures data + + @method queryFixtures + @param {Array} fixture + @param {Object} query + @param {Subclass of DS.Model} type + @return {Promise|Array} + */ + queryFixtures: function(fixtures, query, type) { + Ember.assert('Not implemented: You must override the DS.FixtureAdapter::queryFixtures method to support querying the fixture store.'); + }, + + /** + @method updateFixtures + @param {Subclass of DS.Model} type + @param {Array} fixture + */ + updateFixtures: function(type, fixture) { + if(!type.FIXTURES) { + type.FIXTURES = []; + } + + var fixtures = type.FIXTURES; + + this.deleteLoadedFixture(type, fixture); + + fixtures.push(fixture); + }, + + /** + Implement this method in order to provide json for CRUD methods + + @method mockJSON + @param {Subclass of DS.Model} type + @param {DS.Model} record + */ + mockJSON: function(store, type, record) { + return store.serializerFor(type).serialize(record, { includeId: true }); + }, + + /** + @method generateIdForRecord + @param {DS.Store} store + @param {DS.Model} record + @return {String} id + */ + generateIdForRecord: function(store) { + return "fixture-" + counter++; + }, + + /** + @method find + @param {DS.Store} store + @param {subclass of DS.Model} type + @param {String} id + @return {Promise} promise + */ + find: function(store, type, id) { + var fixtures = this.fixturesForType(type); + var fixture; + + Ember.assert("Unable to find fixtures for model type "+type.toString() +". If you're defining your fixtures using `Model.FIXTURES = ...`, please change it to `Model.reopenClass({ FIXTURES: ... })`.", fixtures); + + if (fixtures) { + fixture = Ember.A(fixtures).findBy('id', id); + } + + if (fixture) { + return this.simulateRemoteCall(function() { + return fixture; + }, this); + } + }, + + /** + @method findMany + @param {DS.Store} store + @param {subclass of DS.Model} type + @param {Array} ids + @return {Promise} promise + */ + findMany: function(store, type, ids) { + var fixtures = this.fixturesForType(type); + + Ember.assert("Unable to find fixtures for model type "+type.toString(), fixtures); + + if (fixtures) { + fixtures = fixtures.filter(function(item) { + return indexOf(ids, item.id) !== -1; + }); + } + + if (fixtures) { + return this.simulateRemoteCall(function() { + return fixtures; + }, this); + } + }, + + /** + @private + @method findAll + @param {DS.Store} store + @param {subclass of DS.Model} type + @param {String} sinceToken + @return {Promise} promise + */ + findAll: function(store, type) { + var fixtures = this.fixturesForType(type); + + Ember.assert("Unable to find fixtures for model type "+type.toString(), fixtures); + + return this.simulateRemoteCall(function() { + return fixtures; + }, this); + }, + + /** + @private + @method findQuery + @param {DS.Store} store + @param {subclass of DS.Model} type + @param {Object} query + @param {DS.AdapterPopulatedRecordArray} recordArray + @return {Promise} promise + */ + findQuery: function(store, type, query, array) { + var fixtures = this.fixturesForType(type); + + Ember.assert("Unable to find fixtures for model type " + type.toString(), fixtures); + + fixtures = this.queryFixtures(fixtures, query, type); + + if (fixtures) { + return this.simulateRemoteCall(function() { + return fixtures; + }, this); + } + }, + + /** + @method createRecord + @param {DS.Store} store + @param {subclass of DS.Model} type + @param {DS.Model} record + @return {Promise} promise + */ + createRecord: function(store, type, record) { + var fixture = this.mockJSON(store, type, record); + + this.updateFixtures(type, fixture); + + return this.simulateRemoteCall(function() { + return fixture; + }, this); + }, + + /** + @method updateRecord + @param {DS.Store} store + @param {subclass of DS.Model} type + @param {DS.Model} record + @return {Promise} promise + */ + updateRecord: function(store, type, record) { + var fixture = this.mockJSON(store, type, record); + + this.updateFixtures(type, fixture); + + return this.simulateRemoteCall(function() { + return fixture; + }, this); + }, + + /** + @method deleteRecord + @param {DS.Store} store + @param {subclass of DS.Model} type + @param {DS.Model} record + @return {Promise} promise + */ + deleteRecord: function(store, type, record) { + this.deleteLoadedFixture(type, record); + + return this.simulateRemoteCall(function() { + // no payload in a deletion + return null; + }); + }, + + /* + @method deleteLoadedFixture + @private + @param type + @param record + */ + deleteLoadedFixture: function(type, record) { + var existingFixture = this.findExistingFixture(type, record); + + if (existingFixture) { + var index = indexOf(type.FIXTURES, existingFixture); + type.FIXTURES.splice(index, 1); + return true; + } + }, + + /* + @method findExistingFixture + @private + @param type + @param record + */ + findExistingFixture: function(type, record) { + var fixtures = this.fixturesForType(type); + var id = get(record, 'id'); + + return this.findFixtureById(fixtures, id); + }, + + /* + @method findFixtureById + @private + @param fixtures + @param id + */ + findFixtureById: function(fixtures, id) { + return Ember.A(fixtures).find(function(r) { + if (''+get(r, 'id') === ''+id) { + return true; + } else { + return false; + } + }); + }, + + /* + @method simulateRemoteCall + @private + @param callback + @param context + */ + simulateRemoteCall: function(callback, context) { + var adapter = this; + + return new Ember.RSVP.Promise(function(resolve) { + var value = Ember.copy(callback.call(context), true); + if (get(adapter, 'simulateRemoteResponse')) { + // Schedule with setTimeout + Ember.run.later(function() { + resolve(value); + }, get(adapter, 'latency')); + } else { + // Asynchronous, but at the of the runloop with zero latency + Ember.run.schedule('actions', null, function() { + resolve(value); + }); + } + }, "DS: FixtureAdapter#simulateRemoteCall"); + } + }); + }); +enifed("ember-data/adapters/rest_adapter", + ["ember-data/system/adapter","ember-data/system/map","exports"], + function(__dependency1__, __dependency2__, __exports__) { + "use strict"; + /** + @module ember-data + */ + + var Adapter = __dependency1__.Adapter; + var InvalidError = __dependency1__.InvalidError; + var MapWithDefault = __dependency2__.MapWithDefault; + var get = Ember.get; + var forEach = Ember.ArrayPolyfills.forEach; + + /** + The REST adapter allows your store to communicate with an HTTP server by + transmitting JSON via XHR. Most Ember.js apps that consume a JSON API + should use the REST adapter. + + This adapter is designed around the idea that the JSON exchanged with + the server should be conventional. + + ## JSON Structure + + The REST adapter expects the JSON returned from your server to follow + these conventions. + + ### Object Root + + The JSON payload should be an object that contains the record inside a + root property. For example, in response to a `GET` request for + `/posts/1`, the JSON should look like this: + + ```js + { + "post": { + "id": 1, + "title": "I'm Running to Reform the W3C's Tag", + "author": "Yehuda Katz" + } + } + ``` + + Similarly, in response to a `GET` request for `/posts`, the JSON should + look like this: + + ```js + { + "posts": [ + { + "id": 1, + "title": "I'm Running to Reform the W3C's Tag", + "author": "Yehuda Katz" + }, + { + "id": 2, + "title": "Rails is omakase", + "author": "D2H" + } + ] + } + ``` + + ### Conventional Names + + Attribute names in your JSON payload should be the camelCased versions of + the attributes in your Ember.js models. + + For example, if you have a `Person` model: + + ```js + App.Person = DS.Model.extend({ + firstName: DS.attr('string'), + lastName: DS.attr('string'), + occupation: DS.attr('string') + }); + ``` + + The JSON returned should look like this: + + ```js + { + "person": { + "id": 5, + "firstName": "Barack", + "lastName": "Obama", + "occupation": "President" + } + } + ``` + + ## Customization + + ### Endpoint path customization + + Endpoint paths can be prefixed with a `namespace` by setting the namespace + property on the adapter: + + ```js + DS.RESTAdapter.reopen({ + namespace: 'api/1' + }); + ``` + Requests for `App.Person` would now target `/api/1/people/1`. + + ### Host customization + + An adapter can target other hosts by setting the `host` property. + + ```js + DS.RESTAdapter.reopen({ + host: 'https://api.example.com' + }); + ``` + + ### Headers customization + + Some APIs require HTTP headers, e.g. to provide an API key. Arbitrary + headers can be set as key/value pairs on the `RESTAdapter`'s `headers` + object and Ember Data will send them along with each ajax request. + + + ```js + App.ApplicationAdapter = DS.RESTAdapter.extend({ + headers: { + "API_KEY": "secret key", + "ANOTHER_HEADER": "Some header value" + } + }); + ``` + + `headers` can also be used as a computed property to support dynamic + headers. In the example below, the `session` object has been + injected into an adapter by Ember's container. + + ```js + App.ApplicationAdapter = DS.RESTAdapter.extend({ + headers: function() { + return { + "API_KEY": this.get("session.authToken"), + "ANOTHER_HEADER": "Some header value" + }; + }.property("session.authToken") + }); + ``` + + In some cases, your dynamic headers may require data from some + object outside of Ember's observer system (for example + `document.cookie`). You can use the + [volatile](/api/classes/Ember.ComputedProperty.html#method_volatile) + function to set the property into a non-cached mode causing the headers to + be recomputed with every request. + + ```js + App.ApplicationAdapter = DS.RESTAdapter.extend({ + headers: function() { + return { + "API_KEY": Ember.get(document.cookie.match(/apiKey\=([^;]*)/), "1"), + "ANOTHER_HEADER": "Some header value" + }; + }.property().volatile() + }); + ``` + + @class RESTAdapter + @constructor + @namespace DS + @extends DS.Adapter + */ + __exports__["default"] = Adapter.extend({ + defaultSerializer: '-rest', + + /** + By default the RESTAdapter will send each find request coming from a `store.find` + or from accessing a relationship separately to the server. If your server supports passing + ids as a query string, you can set coalesceFindRequests to true to coalesce all find requests + within a single runloop. + + For example, if you have an initial payload of + ```javascript + post: { + id:1, + comments: [1,2] + } + ``` + + By default calling `post.get('comments')` will trigger the following requests(assuming the + comments haven't been loaded before): + + ``` + GET /comments/1 + GET /comments/2 + ``` + + If you set coalesceFindRequests to `true` it will instead trigger the following request: + + ``` + GET /comments?ids[]=1&ids[]=2 + ``` + + Setting coalesceFindRequests to `true` also works for `store.find` requests and `belongsTo` + relationships accessed within the same runloop. If you set `coalesceFindRequests: true` + + ```javascript + store.find('comment', 1); + store.find('comment', 2); + ``` + + will also send a request to: `GET /comments?ids[]=1&ids[]=2` + + Note: Requests coalescing rely on URL building strategy. So if you override `buildUrl` in your app + `groupRecordsForFindMany` more likely should be overriden as well in order for coalescing to work. + + @property coalesceFindRequests + @type {boolean} + */ + coalesceFindRequests: false, + + /** + Endpoint paths can be prefixed with a `namespace` by setting the namespace + property on the adapter: + + ```javascript + DS.RESTAdapter.reopen({ + namespace: 'api/1' + }); + ``` + + Requests for `App.Post` would now target `/api/1/post/`. + + @property namespace + @type {String} + */ + + /** + An adapter can target other hosts by setting the `host` property. + + ```javascript + DS.RESTAdapter.reopen({ + host: 'https://api.example.com' + }); + ``` + + Requests for `App.Post` would now target `https://api.example.com/post/`. + + @property host + @type {String} + */ + + /** + Some APIs require HTTP headers, e.g. to provide an API + key. Arbitrary headers can be set as key/value pairs on the + `RESTAdapter`'s `headers` object and Ember Data will send them + along with each ajax request. For dynamic headers see [headers + customization](/api/data/classes/DS.RESTAdapter.html#toc_headers-customization). + + ```javascript + App.ApplicationAdapter = DS.RESTAdapter.extend({ + headers: { + "API_KEY": "secret key", + "ANOTHER_HEADER": "Some header value" + } + }); + ``` + + @property headers + @type {Object} + */ + + /** + Called by the store in order to fetch the JSON for a given + type and ID. + + The `find` method makes an Ajax request to a URL computed by `buildURL`, and returns a + promise for the resulting payload. + + This method performs an HTTP `GET` request with the id provided as part of the query string. + + @method find + @param {DS.Store} store + @param {subclass of DS.Model} type + @param {String} id + @param {DS.Model} record + @return {Promise} promise + */ + find: function(store, type, id, record) { + return this.ajax(this.buildURL(type.typeKey, id, record), 'GET'); + }, + + /** + Called by the store in order to fetch a JSON array for all + of the records for a given type. + + The `findAll` method makes an Ajax (HTTP GET) request to a URL computed by `buildURL`, and returns a + promise for the resulting payload. + + @private + @method findAll + @param {DS.Store} store + @param {subclass of DS.Model} type + @param {String} sinceToken + @return {Promise} promise + */ + findAll: function(store, type, sinceToken) { + var query; + + if (sinceToken) { + query = { since: sinceToken }; + } + + return this.ajax(this.buildURL(type.typeKey), 'GET', { data: query }); + }, + + /** + Called by the store in order to fetch a JSON array for + the records that match a particular query. + + The `findQuery` method makes an Ajax (HTTP GET) request to a URL computed by `buildURL`, and returns a + promise for the resulting payload. + + The `query` argument is a simple JavaScript object that will be passed directly + to the server as parameters. + + @private + @method findQuery + @param {DS.Store} store + @param {subclass of DS.Model} type + @param {Object} query + @return {Promise} promise + */ + findQuery: function(store, type, query) { + return this.ajax(this.buildURL(type.typeKey), 'GET', { data: query }); + }, + + /** + Called by the store in order to fetch several records together if `coalesceFindRequests` is true + + For example, if the original payload looks like: + + ```js + { + "id": 1, + "title": "Rails is omakase", + "comments": [ 1, 2, 3 ] + } + ``` + + The IDs will be passed as a URL-encoded Array of IDs, in this form: + + ``` + ids[]=1&ids[]=2&ids[]=3 + ``` + + Many servers, such as Rails and PHP, will automatically convert this URL-encoded array + into an Array for you on the server-side. If you want to encode the + IDs, differently, just override this (one-line) method. + + The `findMany` method makes an Ajax (HTTP GET) request to a URL computed by `buildURL`, and returns a + promise for the resulting payload. + + @method findMany + @param {DS.Store} store + @param {subclass of DS.Model} type + @param {Array} ids + @param {Array} records + @return {Promise} promise + */ + findMany: function(store, type, ids, records) { + return this.ajax(this.buildURL(type.typeKey, ids, records), 'GET', { data: { ids: ids } }); + }, + + /** + Called by the store in order to fetch a JSON array for + the unloaded records in a has-many relationship that were originally + specified as a URL (inside of `links`). + + For example, if your original payload looks like this: + + ```js + { + "post": { + "id": 1, + "title": "Rails is omakase", + "links": { "comments": "/posts/1/comments" } + } + } + ``` + + This method will be called with the parent record and `/posts/1/comments`. + + The `findHasMany` method will make an Ajax (HTTP GET) request to the originally specified URL. + If the URL is host-relative (starting with a single slash), the + request will use the host specified on the adapter (if any). + + @method findHasMany + @param {DS.Store} store + @param {DS.Model} record + @param {String} url + @return {Promise} promise + */ + findHasMany: function(store, record, url, relationship) { + var host = get(this, 'host'); + var id = get(record, 'id'); + var type = record.constructor.typeKey; + + if (host && url.charAt(0) === '/' && url.charAt(1) !== '/') { + url = host + url; + } + + return this.ajax(this.urlPrefix(url, this.buildURL(type, id)), 'GET'); + }, + + /** + Called by the store in order to fetch a JSON array for + the unloaded records in a belongs-to relationship that were originally + specified as a URL (inside of `links`). + + For example, if your original payload looks like this: + + ```js + { + "person": { + "id": 1, + "name": "Tom Dale", + "links": { "group": "/people/1/group" } + } + } + ``` + + This method will be called with the parent record and `/people/1/group`. + + The `findBelongsTo` method will make an Ajax (HTTP GET) request to the originally specified URL. + + @method findBelongsTo + @param {DS.Store} store + @param {DS.Model} record + @param {String} url + @return {Promise} promise + */ + findBelongsTo: function(store, record, url, relationship) { + var id = get(record, 'id'); + var type = record.constructor.typeKey; + + return this.ajax(this.urlPrefix(url, this.buildURL(type, id)), 'GET'); + }, + + /** + Called by the store when a newly created record is + saved via the `save` method on a model record instance. + + The `createRecord` method serializes the record and makes an Ajax (HTTP POST) request + to a URL computed by `buildURL`. + + See `serialize` for information on how to customize the serialized form + of a record. + + @method createRecord + @param {DS.Store} store + @param {subclass of DS.Model} type + @param {DS.Model} record + @return {Promise} promise + */ + createRecord: function(store, type, record) { + var data = {}; + var serializer = store.serializerFor(type.typeKey); + + serializer.serializeIntoHash(data, type, record, { includeId: true }); + + return this.ajax(this.buildURL(type.typeKey, null, record), "POST", { data: data }); + }, + + /** + Called by the store when an existing record is saved + via the `save` method on a model record instance. + + The `updateRecord` method serializes the record and makes an Ajax (HTTP PUT) request + to a URL computed by `buildURL`. + + See `serialize` for information on how to customize the serialized form + of a record. + + @method updateRecord + @param {DS.Store} store + @param {subclass of DS.Model} type + @param {DS.Model} record + @return {Promise} promise + */ + updateRecord: function(store, type, record) { + var data = {}; + var serializer = store.serializerFor(type.typeKey); + + serializer.serializeIntoHash(data, type, record); + + var id = get(record, 'id'); + + return this.ajax(this.buildURL(type.typeKey, id, record), "PUT", { data: data }); + }, + + /** + Called by the store when a record is deleted. + + The `deleteRecord` method makes an Ajax (HTTP DELETE) request to a URL computed by `buildURL`. + + @method deleteRecord + @param {DS.Store} store + @param {subclass of DS.Model} type + @param {DS.Model} record + @return {Promise} promise + */ + deleteRecord: function(store, type, record) { + var id = get(record, 'id'); + + return this.ajax(this.buildURL(type.typeKey, id, record), "DELETE"); + }, + + /** + Builds a URL for a given type and optional ID. + + By default, it pluralizes the type's name (for example, 'post' + becomes 'posts' and 'person' becomes 'people'). To override the + pluralization see [pathForType](#method_pathForType). + + If an ID is specified, it adds the ID to the path generated + for the type, separated by a `/`. + + @method buildURL + @param {String} type + @param {String} id + @param {DS.Model} record + @return {String} url + */ + buildURL: function(type, id, record) { + var url = [], + host = get(this, 'host'), + prefix = this.urlPrefix(); + + if (type) { url.push(this.pathForType(type)); } + + //We might get passed in an array of ids from findMany + //in which case we don't want to modify the url, as the + //ids will be passed in through a query param + if (id && !Ember.isArray(id)) { url.push(encodeURIComponent(id)); } + + if (prefix) { url.unshift(prefix); } + + url = url.join('/'); + if (!host && url) { url = '/' + url; } + + return url; + }, + + /** + @method urlPrefix + @private + @param {String} path + @param {String} parentUrl + @return {String} urlPrefix + */ + urlPrefix: function(path, parentURL) { + var host = get(this, 'host'); + var namespace = get(this, 'namespace'); + var url = []; + + if (path) { + // Absolute path + if (path.charAt(0) === '/') { + if (host) { + path = path.slice(1); + url.push(host); + } + // Relative path + } else if (!/^http(s)?:\/\//.test(path)) { + url.push(parentURL); + } + } else { + if (host) { url.push(host); } + if (namespace) { url.push(namespace); } + } + + if (path) { + url.push(path); + } + + return url.join('/'); + }, + + _stripIDFromURL: function(store, record) { + var type = record.constructor; + var url = this.buildURL(type.typeKey, record.get('id'), record); + + var expandedURL = url.split('/'); + //Case when the url is of the format ...something/:id + var lastSegment = expandedURL[ expandedURL.length - 1 ]; + var id = record.get('id'); + if (lastSegment === id) { + expandedURL[expandedURL.length - 1] = ""; + } else if(endsWith(lastSegment, '?id=' + id)) { + //Case when the url is of the format ...something?id=:id + expandedURL[expandedURL.length - 1] = lastSegment.substring(0, lastSegment.length - id.length - 1); + } + + return expandedURL.join('/'); + }, + + /** + http://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers + */ + maxUrlLength: 2048, + + /** + Organize records into groups, each of which is to be passed to separate + calls to `findMany`. + + This implementation groups together records that have the same base URL but + differing ids. For example `/comments/1` and `/comments/2` will be grouped together + because we know findMany can coalesce them together as `/comments?ids[]=1&ids[]=2` + + It also supports urls where ids are passed as a query param, such as `/comments?id=1` + but not those where there is more than 1 query param such as `/comments?id=2&name=David` + Currently only the query param of `id` is supported. If you need to support others, please + override this or the `_stripIDFromURL` method. + + It does not group records that have differing base urls, such as for example: `/posts/1/comments/2` + and `/posts/2/comments/3` + + @method groupRecordsForFindMany + @param {DS.Store} store + @param {Array} records + @return {Array} an array of arrays of records, each of which is to be + loaded separately by `findMany`. + */ + groupRecordsForFindMany: function (store, records) { + var groups = MapWithDefault.create({defaultValue: function(){return [];}}); + var adapter = this; + var maxUrlLength = this.maxUrlLength; + + forEach.call(records, function(record){ + var baseUrl = adapter._stripIDFromURL(store, record); + groups.get(baseUrl).push(record); + }); + + function splitGroupToFitInUrl(group, maxUrlLength, paramNameLength) { + var baseUrl = adapter._stripIDFromURL(store, group[0]); + var idsSize = 0; + var splitGroups = [[]]; + + forEach.call(group, function(record) { + var additionalLength = encodeURIComponent(record.get('id')).length + paramNameLength; + if (baseUrl.length + idsSize + additionalLength >= maxUrlLength) { + idsSize = 0; + splitGroups.push([]); + } + + idsSize += additionalLength; + + var lastGroupIndex = splitGroups.length - 1; + splitGroups[lastGroupIndex].push(record); + }); + + return splitGroups; + } + + var groupsArray = []; + groups.forEach(function(group, key){ + var paramNameLength = '&ids%5B%5D='.length; + var splitGroups = splitGroupToFitInUrl(group, maxUrlLength, paramNameLength); + + forEach.call(splitGroups, function(splitGroup) { + groupsArray.push(splitGroup); + }); + }); + + return groupsArray; + }, + + /** + Determines the pathname for a given type. + + By default, it pluralizes the type's name (for example, + 'post' becomes 'posts' and 'person' becomes 'people'). + + ### Pathname customization + + For example if you have an object LineItem with an + endpoint of "/line_items/". + + ```js + App.ApplicationAdapter = DS.RESTAdapter.extend({ + pathForType: function(type) { + var decamelized = Ember.String.decamelize(type); + return Ember.String.pluralize(decamelized); + } + }); + ``` + + @method pathForType + @param {String} type + @return {String} path + **/ + pathForType: function(type) { + var camelized = Ember.String.camelize(type); + return Ember.String.pluralize(camelized); + }, + + /** + Takes an ajax response, and returns an error payload. + + Returning a `DS.InvalidError` from this method will cause the + record to transition into the `invalid` state and make the + `errors` object available on the record. + + This function should return the entire payload as received from the + server. Error object extraction and normalization of model errors + should be performed by `extractErrors` on the serializer. + + Example + + ```javascript + App.ApplicationAdapter = DS.RESTAdapter.extend({ + ajaxError: function(jqXHR) { + var error = this._super(jqXHR); + + if (jqXHR && jqXHR.status === 422) { + var jsonErrors = Ember.$.parseJSON(jqXHR.responseText); + + return new DS.InvalidError(jsonErrors); + } else { + return error; + } + } + }); + ``` + + Note: As a correctness optimization, the default implementation of + the `ajaxError` method strips out the `then` method from jquery's + ajax response (jqXHR). This is important because the jqXHR's + `then` method fulfills the promise with itself resulting in a + circular "thenable" chain which may cause problems for some + promise libraries. + + @method ajaxError + @param {Object} jqXHR + @param {Object} responseText + @return {Object} jqXHR + */ + ajaxError: function(jqXHR, responseText) { + if (jqXHR && typeof jqXHR === 'object') { + jqXHR.then = null; + } + + return jqXHR; + }, + + /** + Takes an ajax response, and returns the json payload. + + By default this hook just returns the jsonPayload passed to it. + You might want to override it in two cases: + + 1. Your API might return useful results in the request headers. + If you need to access these, you can override this hook to copy them + from jqXHR to the payload object so they can be processed in you serializer. + + + 2. Your API might return errors as successful responses with status code + 200 and an Errors text or object. You can return a DS.InvalidError from + this hook and it will automatically reject the promise and put your record + into the invalid state. + + @method ajaxSuccess + @param {Object} jqXHR + @param {Object} jsonPayload + @return {Object} jsonPayload + */ + + ajaxSuccess: function(jqXHR, jsonPayload) { + return jsonPayload; + }, + + /** + Takes a URL, an HTTP method and a hash of data, and makes an + HTTP request. + + When the server responds with a payload, Ember Data will call into `extractSingle` + or `extractArray` (depending on whether the original query was for one record or + many records). + + By default, `ajax` method has the following behavior: + + * It sets the response `dataType` to `"json"` + * If the HTTP method is not `"GET"`, it sets the `Content-Type` to be + `application/json; charset=utf-8` + * If the HTTP method is not `"GET"`, it stringifies the data passed in. The + data is the serialized record in the case of a save. + * Registers success and failure handlers. + + @method ajax + @private + @param {String} url + @param {String} type The request type GET, POST, PUT, DELETE etc. + @param {Object} hash + @return {Promise} promise + */ + ajax: function(url, type, options) { + var adapter = this; + + return new Ember.RSVP.Promise(function(resolve, reject) { + var hash = adapter.ajaxOptions(url, type, options); + + hash.success = function(json, textStatus, jqXHR) { + json = adapter.ajaxSuccess(jqXHR, json); + if (json instanceof InvalidError) { + Ember.run(null, reject, json); + } else { + Ember.run(null, resolve, json); + } + }; + + hash.error = function(jqXHR, textStatus, errorThrown) { + Ember.run(null, reject, adapter.ajaxError(jqXHR, jqXHR.responseText)); + }; + + Ember.$.ajax(hash); + }, "DS: RESTAdapter#ajax " + type + " to " + url); + }, + + /** + @method ajaxOptions + @private + @param {String} url + @param {String} type The request type GET, POST, PUT, DELETE etc. + @param {Object} hash + @return {Object} hash + */ + ajaxOptions: function(url, type, options) { + var hash = options || {}; + hash.url = url; + hash.type = type; + hash.dataType = 'json'; + hash.context = this; + + if (hash.data && type !== 'GET') { + hash.contentType = 'application/json; charset=utf-8'; + hash.data = JSON.stringify(hash.data); + } + + var headers = get(this, 'headers'); + if (headers !== undefined) { + hash.beforeSend = function (xhr) { + forEach.call(Ember.keys(headers), function(key) { + xhr.setRequestHeader(key, headers[key]); + }); + }; + } + + return hash; + } + }); + + //From http://stackoverflow.com/questions/280634/endswith-in-javascript + function endsWith(string, suffix){ + if (typeof String.prototype.endsWith !== 'function') { + return string.indexOf(suffix, string.length - suffix.length) !== -1; + } else { + return string.endsWith(suffix); + } + } + }); +enifed("ember-data/core", + ["exports"], + function(__exports__) { + "use strict"; + /** + @module ember-data + */ + + /** + All Ember Data methods and functions are defined inside of this namespace. + + @class DS + @static + */ + var DS; + if ('undefined' === typeof DS) { + /** + @property VERSION + @type String + @default '1.0.0-beta.12' + @static + */ + DS = Ember.Namespace.create({ + VERSION: '1.0.0-beta.12' + }); + + if (Ember.libraries) { + Ember.libraries.registerCoreLibrary('Ember Data', DS.VERSION); + } + } + + __exports__["default"] = DS; + }); +enifed("ember-data/ember-initializer", + ["ember-data/setup-container"], + function(__dependency1__) { + "use strict"; + var setupContainer = __dependency1__["default"]; + + var K = Ember.K; + + /** + @module ember-data + */ + + /* + + This code initializes Ember-Data onto an Ember application. + + If an Ember.js developer defines a subclass of DS.Store on their application, + as `App.ApplicationStore` (or via a module system that resolves to `store:application`) + this code will automatically instantiate it and make it available on the + router. + + Additionally, after an application's controllers have been injected, they will + each have the store made available to them. + + For example, imagine an Ember.js application with the following classes: + + App.ApplicationStore = DS.Store.extend({ + adapter: 'custom' + }); + + App.PostsController = Ember.ArrayController.extend({ + // ... + }); + + When the application is initialized, `App.ApplicationStore` will automatically be + instantiated, and the instance of `App.PostsController` will have its `store` + property set to that instance. + + Note that this code will only be run if the `ember-application` package is + loaded. If Ember Data is being used in an environment other than a + typical application (e.g., node.js where only `ember-runtime` is available), + this code will be ignored. + */ + + Ember.onLoad('Ember.Application', function(Application) { + + Application.initializer({ + name: "ember-data", + initialize: setupContainer + }); + + // Deprecated initializers to satisfy old code that depended on them + + Application.initializer({ + name: "store", + after: "ember-data", + initialize: K + }); + + Application.initializer({ + name: "activeModelAdapter", + before: "store", + initialize: K + }); + + Application.initializer({ + name: "transforms", + before: "store", + initialize: K + }); + + Application.initializer({ + name: "data-adapter", + before: "store", + initialize: K + }); + + Application.initializer({ + name: "injectStore", + before: "store", + initialize: K + }); + }); + }); +enifed("ember-data/ext/date", + [], + function() { + "use strict"; + /** + @module ember-data + */ + + /** + Date.parse with progressive enhancement for ISO 8601 + + © 2011 Colin Snover + + Released under MIT license. + + @class Date + @namespace Ember + @static + */ + Ember.Date = Ember.Date || {}; + + var origParse = Date.parse, numericKeys = [ 1, 4, 5, 6, 7, 10, 11 ]; + + /** + @method parse + @param {Date} date + @return {Number} timestamp + */ + Ember.Date.parse = function (date) { + var timestamp, struct, minutesOffset = 0; + + // ES5 §15.9.4.2 states that the string should attempt to be parsed as a Date Time String Format string + // before falling back to any implementation-specific date parsing, so that’s what we do, even if native + // implementations could be faster + // 1 YYYY 2 MM 3 DD 4 HH 5 mm 6 ss 7 msec 8 Z 9 ± 10 tzHH 11 tzmm + if ((struct = /^(\d{4}|[+\-]\d{6})(?:-(\d{2})(?:-(\d{2}))?)?(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{3}))?)?(?:(Z)|([+\-])(\d{2})(?::(\d{2}))?)?)?$/.exec(date))) { + // avoid NaN timestamps caused by “undefined” values being passed to Date.UTC + for (var i = 0, k; (k = numericKeys[i]); ++i) { + struct[k] = +struct[k] || 0; + } + + // allow undefined days and months + struct[2] = (+struct[2] || 1) - 1; + struct[3] = +struct[3] || 1; + + if (struct[8] !== 'Z' && struct[9] !== undefined) { + minutesOffset = struct[10] * 60 + struct[11]; + + if (struct[9] === '+') { + minutesOffset = 0 - minutesOffset; + } + } + + timestamp = Date.UTC(struct[1], struct[2], struct[3], struct[4], struct[5] + minutesOffset, struct[6], struct[7]); + } + else { + timestamp = origParse ? origParse(date) : NaN; + } + + return timestamp; + }; + + if (Ember.EXTEND_PROTOTYPES === true || Ember.EXTEND_PROTOTYPES.Date) { + Date.parse = Ember.Date.parse; + } + }); +enifed("ember-data/initializers/data_adapter", + ["ember-data/system/debug/debug_adapter","exports"], + function(__dependency1__, __exports__) { + "use strict"; + var DebugAdapter = __dependency1__["default"]; + + /** + Configures a container with injections on Ember applications + for the Ember-Data store. Accepts an optional namespace argument. + + @method initializeStoreInjections + @param {Ember.Container} container + */ + __exports__["default"] = function initializeDebugAdapter(container){ + container.register('data-adapter:main', DebugAdapter); + }; + }); +enifed("ember-data/initializers/store", + ["ember-data/serializers","ember-data/adapters","ember-data/system/container_proxy","ember-data/system/store","exports"], + function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __exports__) { + "use strict"; + var JSONSerializer = __dependency1__.JSONSerializer; + var RESTSerializer = __dependency1__.RESTSerializer; + var RESTAdapter = __dependency2__.RESTAdapter; + var ContainerProxy = __dependency3__["default"]; + var Store = __dependency4__["default"]; + + /** + Configures a container for use with an Ember-Data + store. Accepts an optional namespace argument. + + @method initializeStore + @param {Ember.Container} container + @param {Object} [application] an application namespace + */ + __exports__["default"] = function initializeStore(container, application){ + Ember.deprecate('Specifying a custom Store for Ember Data on your global namespace as `App.Store` ' + + 'has been deprecated. Please use `App.ApplicationStore` instead.', !(application && application.Store)); + + container.register('store:main', container.lookupFactory('store:application') || (application && application.Store) || Store); + + // allow older names to be looked up + + var proxy = new ContainerProxy(container); + proxy.registerDeprecations([ + { deprecated: 'serializer:_default', valid: 'serializer:-default' }, + { deprecated: 'serializer:_rest', valid: 'serializer:-rest' }, + { deprecated: 'adapter:_rest', valid: 'adapter:-rest' } + ]); + + // new go forward paths + container.register('serializer:-default', JSONSerializer); + container.register('serializer:-rest', RESTSerializer); + container.register('adapter:-rest', RESTAdapter); + + // Eagerly generate the store so defaultStore is populated. + // TODO: Do this in a finisher hook + container.lookup('store:main'); + }; + }); +enifed("ember-data/initializers/store_injections", + ["exports"], + function(__exports__) { + "use strict"; + /** + Configures a container with injections on Ember applications + for the Ember-Data store. Accepts an optional namespace argument. + + @method initializeStoreInjections + @param {Ember.Container} container + */ + __exports__["default"] = function initializeStoreInjections(container){ + container.injection('controller', 'store', 'store:main'); + container.injection('route', 'store', 'store:main'); + container.injection('serializer', 'store', 'store:main'); + container.injection('data-adapter', 'store', 'store:main'); + }; + }); +enifed("ember-data/initializers/transforms", + ["ember-data/transforms","exports"], + function(__dependency1__, __exports__) { + "use strict"; + var BooleanTransform = __dependency1__.BooleanTransform; + var DateTransform = __dependency1__.DateTransform; + var StringTransform = __dependency1__.StringTransform; + var NumberTransform = __dependency1__.NumberTransform; + + /** + Configures a container for use with Ember-Data + transforms. + + @method initializeTransforms + @param {Ember.Container} container + */ + __exports__["default"] = function initializeTransforms(container){ + container.register('transform:boolean', BooleanTransform); + container.register('transform:date', DateTransform); + container.register('transform:number', NumberTransform); + container.register('transform:string', StringTransform); + }; + }); +enifed("ember-data/serializers", + ["ember-data/serializers/json_serializer","ember-data/serializers/rest_serializer","exports"], + function(__dependency1__, __dependency2__, __exports__) { + "use strict"; + var JSONSerializer = __dependency1__["default"]; + var RESTSerializer = __dependency2__["default"]; + + __exports__.JSONSerializer = JSONSerializer; + __exports__.RESTSerializer = RESTSerializer; + }); +enifed("ember-data/serializers/embedded_records_mixin", + ["exports"], + function(__exports__) { + "use strict"; + var get = Ember.get; + var forEach = Ember.EnumerableUtils.forEach; + var camelize = Ember.String.camelize; + + /** + ## Using Embedded Records + + `DS.EmbeddedRecordsMixin` supports serializing embedded records. + + To set up embedded records, include the mixin when extending a serializer + then define and configure embedded (model) relationships. + + Below is an example of a per-type serializer ('post' type). + + ```js + App.PostSerializer = DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { + attrs: { + author: { embedded: 'always' }, + comments: { serialize: 'ids' } + } + }); + ``` + Note that this use of `{ embedded: 'always' }` is unrelated to + the `{ embedded: 'always' }` that is defined as an option on `DS.attr` as part of + defining a model while working with the ActiveModelSerializer. Nevertheless, + using `{ embedded: 'always' }` as an option to DS.attr is not a valid way to setup + embedded records. + + The `attrs` option for a resource `{ embedded: 'always' }` is shorthand for: + + ```js + { + serialize: 'records', + deserialize: 'records' + } + ``` + + ### Configuring Attrs + + A resource's `attrs` option may be set to use `ids`, `records` or false for the + `serialize` and `deserialize` settings. + + The `attrs` property can be set on the ApplicationSerializer or a per-type + serializer. + + In the case where embedded JSON is expected while extracting a payload (reading) + the setting is `deserialize: 'records'`, there is no need to use `ids` when + extracting as that is the default behavior without this mixin if you are using + the vanilla EmbeddedRecordsMixin. Likewise, to embed JSON in the payload while + serializing `serialize: 'records'` is the setting to use. There is an option of + not embedding JSON in the serialized payload by using `serialize: 'ids'`. If you + do not want the relationship sent at all, you can use `serialize: false`. + + + ### EmbeddedRecordsMixin defaults + If you do not overwrite `attrs` for a specific relationship, the `EmbeddedRecordsMixin` + will behave in the following way: + + BelongsTo: `{ serialize: 'id', deserialize: 'id' }` + HasMany: `{ serialize: false, deserialize: 'ids' }` + + ### Model Relationships + + Embedded records must have a model defined to be extracted and serialized. Note that + when defining any relationships on your model such as `belongsTo` and `hasMany`, you + should not both specify `async:true` and also indicate through the serializer's + `attrs` attribute that the related model should be embedded. If a model is + declared embedded, then do not use `async:true`. + + To successfully extract and serialize embedded records the model relationships + must be setup correcty See the + [defining relationships](/guides/models/defining-models/#toc_defining-relationships) + section of the **Defining Models** guide page. + + Records without an `id` property are not considered embedded records, model + instances must have an `id` property to be used with Ember Data. + + ### Example JSON payloads, Models and Serializers + + **When customizing a serializer it is important to grok what the customizations + are. Please read the docs for the methods this mixin provides, in case you need + to modify it to fit your specific needs.** + + For example review the docs for each method of this mixin: + * [normalize](/api/data/classes/DS.EmbeddedRecordsMixin.html#method_normalize) + * [serializeBelongsTo](/api/data/classes/DS.EmbeddedRecordsMixin.html#method_serializeBelongsTo) + * [serializeHasMany](/api/data/classes/DS.EmbeddedRecordsMixin.html#method_serializeHasMany) + + @class EmbeddedRecordsMixin + @namespace DS + */ + var EmbeddedRecordsMixin = Ember.Mixin.create({ + + /** + Normalize the record and recursively normalize/extract all the embedded records + while pushing them into the store as they are encountered + + A payload with an attr configured for embedded records needs to be extracted: + + ```js + { + "post": { + "id": "1" + "title": "Rails is omakase", + "comments": [{ + "id": "1", + "body": "Rails is unagi" + }, { + "id": "2", + "body": "Omakase O_o" + }] + } + } + ``` + @method normalize + @param {subclass of DS.Model} type + @param {Object} hash to be normalized + @param {String} key the hash has been referenced by + @return {Object} the normalized hash + **/ + normalize: function(type, hash, prop) { + var normalizedHash = this._super(type, hash, prop); + return extractEmbeddedRecords(this, this.store, type, normalizedHash); + }, + + keyForRelationship: function(key, type){ + if (this.hasDeserializeRecordsOption(key)) { + return this.keyForAttribute(key); + } else { + return this._super(key, type) || key; + } + }, + + /** + Serialize `belongsTo` relationship when it is configured as an embedded object. + + This example of an author model belongs to a post model: + + ```js + Post = DS.Model.extend({ + title: DS.attr('string'), + body: DS.attr('string'), + author: DS.belongsTo('author') + }); + + Author = DS.Model.extend({ + name: DS.attr('string'), + post: DS.belongsTo('post') + }); + ``` + + Use a custom (type) serializer for the post model to configure embedded author + + ```js + App.PostSerializer = DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { + attrs: { + author: {embedded: 'always'} + } + }) + ``` + + A payload with an attribute configured for embedded records can serialize + the records together under the root attribute's payload: + + ```js + { + "post": { + "id": "1" + "title": "Rails is omakase", + "author": { + "id": "2" + "name": "dhh" + } + } + } + ``` + + @method serializeBelongsTo + @param {DS.Model} record + @param {Object} json + @param {Object} relationship + */ + serializeBelongsTo: function(record, json, relationship) { + var attr = relationship.key; + if (this.noSerializeOptionSpecified(attr)) { + this._super(record, json, relationship); + return; + } + var includeIds = this.hasSerializeIdsOption(attr); + var includeRecords = this.hasSerializeRecordsOption(attr); + var embeddedRecord = record.get(attr); + var key; + if (includeIds) { + key = this.keyForRelationship(attr, relationship.kind); + if (!embeddedRecord) { + json[key] = null; + } else { + json[key] = get(embeddedRecord, 'id'); + } + } else if (includeRecords) { + key = this.keyForAttribute(attr); + if (!embeddedRecord) { + json[key] = null; + } else { + json[key] = embeddedRecord.serialize({includeId: true}); + this.removeEmbeddedForeignKey(record, embeddedRecord, relationship, json[key]); + } + } + }, + + /** + Serialize `hasMany` relationship when it is configured as embedded objects. + + This example of a post model has many comments: + + ```js + Post = DS.Model.extend({ + title: DS.attr('string'), + body: DS.attr('string'), + comments: DS.hasMany('comment') + }); + + Comment = DS.Model.extend({ + body: DS.attr('string'), + post: DS.belongsTo('post') + }); + ``` + + Use a custom (type) serializer for the post model to configure embedded comments + + ```js + App.PostSerializer = DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { + attrs: { + comments: {embedded: 'always'} + } + }) + ``` + + A payload with an attribute configured for embedded records can serialize + the records together under the root attribute's payload: + + ```js + { + "post": { + "id": "1" + "title": "Rails is omakase", + "body": "I want this for my ORM, I want that for my template language..." + "comments": [{ + "id": "1", + "body": "Rails is unagi" + }, { + "id": "2", + "body": "Omakase O_o" + }] + } + } + ``` + + The attrs options object can use more specific instruction for extracting and + serializing. When serializing, an option to embed `ids` or `records` can be set. + When extracting the only option is `records`. + + So `{embedded: 'always'}` is shorthand for: + `{serialize: 'records', deserialize: 'records'}` + + To embed the `ids` for a related object (using a hasMany relationship): + + ```js + App.PostSerializer = DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, { + attrs: { + comments: {serialize: 'ids', deserialize: 'records'} + } + }) + ``` + + ```js + { + "post": { + "id": "1" + "title": "Rails is omakase", + "body": "I want this for my ORM, I want that for my template language..." + "comments": ["1", "2"] + } + } + ``` + + @method serializeHasMany + @param {DS.Model} record + @param {Object} json + @param {Object} relationship + */ + serializeHasMany: function(record, json, relationship) { + var attr = relationship.key; + if (this.noSerializeOptionSpecified(attr)) { + this._super(record, json, relationship); + return; + } + var includeIds = this.hasSerializeIdsOption(attr); + var includeRecords = this.hasSerializeRecordsOption(attr); + var key; + if (includeIds) { + key = this.keyForRelationship(attr, relationship.kind); + json[key] = get(record, attr).mapBy('id'); + } else if (includeRecords) { + key = this.keyForAttribute(attr); + json[key] = get(record, attr).map(function(embeddedRecord) { + var serializedEmbeddedRecord = embeddedRecord.serialize({includeId: true}); + this.removeEmbeddedForeignKey(record, embeddedRecord, relationship, serializedEmbeddedRecord); + return serializedEmbeddedRecord; + }, this); + } + }, + + /** + When serializing an embedded record, modify the property (in the json payload) + that refers to the parent record (foreign key for relationship). + + Serializing a `belongsTo` relationship removes the property that refers to the + parent record + + Serializing a `hasMany` relationship does not remove the property that refers to + the parent record. + + @method removeEmbeddedForeignKey + @param {DS.Model} record + @param {DS.Model} embeddedRecord + @param {Object} relationship + @param {Object} json + */ + removeEmbeddedForeignKey: function (record, embeddedRecord, relationship, json) { + if (relationship.kind === 'hasMany') { + return; + } else if (relationship.kind === 'belongsTo') { + var parentRecord = record.constructor.inverseFor(relationship.key); + if (parentRecord) { + var name = parentRecord.name; + var embeddedSerializer = this.store.serializerFor(embeddedRecord.constructor); + var parentKey = embeddedSerializer.keyForRelationship(name, parentRecord.kind); + if (parentKey) { + delete json[parentKey]; + } + } + } + }, + + // checks config for attrs option to embedded (always) - serialize and deserialize + hasEmbeddedAlwaysOption: function (attr) { + var option = this.attrsOption(attr); + return option && option.embedded === 'always'; + }, + + // checks config for attrs option to serialize ids + hasSerializeRecordsOption: function(attr) { + var alwaysEmbed = this.hasEmbeddedAlwaysOption(attr); + var option = this.attrsOption(attr); + return alwaysEmbed || (option && (option.serialize === 'records')); + }, + + // checks config for attrs option to serialize records + hasSerializeIdsOption: function(attr) { + var option = this.attrsOption(attr); + return option && (option.serialize === 'ids' || option.serialize === 'id'); + }, + + // checks config for attrs option to serialize records + noSerializeOptionSpecified: function(attr) { + var option = this.attrsOption(attr); + return !(option && (option.serialize || option.embedded)); + }, + + // checks config for attrs option to deserialize records + // a defined option object for a resource is treated the same as + // `deserialize: 'records'` + hasDeserializeRecordsOption: function(attr) { + var alwaysEmbed = this.hasEmbeddedAlwaysOption(attr); + var option = this.attrsOption(attr); + return alwaysEmbed || (option && option.deserialize === 'records'); + }, + + attrsOption: function(attr) { + var attrs = this.get('attrs'); + return attrs && (attrs[camelize(attr)] || attrs[attr]); + } + }); + + // chooses a relationship kind to branch which function is used to update payload + // does not change payload if attr is not embedded + function extractEmbeddedRecords(serializer, store, type, partial) { + + type.eachRelationship(function(key, relationship) { + if (serializer.hasDeserializeRecordsOption(key)) { + var embeddedType = store.modelFor(relationship.type.typeKey); + if (relationship.kind === "hasMany") { + if (relationship.options.polymorphic) { + extractEmbeddedHasManyPolymorphic(store, key, partial); + } + else { + extractEmbeddedHasMany(store, key, embeddedType, partial); + } + } + if (relationship.kind === "belongsTo") { + extractEmbeddedBelongsTo(store, key, embeddedType, partial); + } + } + }); + + return partial; + } + + // handles embedding for `hasMany` relationship + function extractEmbeddedHasMany(store, key, embeddedType, hash) { + if (!hash[key]) { + return hash; + } + + var ids = []; + + var embeddedSerializer = store.serializerFor(embeddedType.typeKey); + forEach(hash[key], function(data) { + var embeddedRecord = embeddedSerializer.normalize(embeddedType, data, null); + store.push(embeddedType, embeddedRecord); + ids.push(embeddedRecord.id); + }); + + hash[key] = ids; + return hash; + } + + function extractEmbeddedHasManyPolymorphic(store, key, hash) { + if (!hash[key]) { + return hash; + } + + var ids = []; + + forEach(hash[key], function(data) { + var typeKey = data.type; + var embeddedSerializer = store.serializerFor(typeKey); + var embeddedType = store.modelFor(typeKey); + var primaryKey = get(embeddedSerializer, 'primaryKey'); + + var embeddedRecord = embeddedSerializer.normalize(embeddedType, data, null); + store.push(embeddedType, embeddedRecord); + ids.push({ id: embeddedRecord[primaryKey], type: typeKey }); + }); + + hash[key] = ids; + return hash; + } + + function extractEmbeddedBelongsTo(store, key, embeddedType, hash) { + if (!hash[key]) { + return hash; + } + + var embeddedSerializer = store.serializerFor(embeddedType.typeKey); + var embeddedRecord = embeddedSerializer.normalize(embeddedType, hash[key], null); + store.push(embeddedType, embeddedRecord); + + hash[key] = embeddedRecord.id; + //TODO Need to add a reference to the parent later so relationship works between both `belongsTo` records + return hash; + } + + __exports__["default"] = EmbeddedRecordsMixin; + }); +enifed("ember-data/serializers/json_serializer", + ["exports"], + function(__exports__) { + "use strict"; + var get = Ember.get; + var isNone = Ember.isNone; + var map = Ember.ArrayPolyfills.map; + var merge = Ember.merge; + + /** + In Ember Data a Serializer is used to serialize and deserialize + records when they are transferred in and out of an external source. + This process involves normalizing property names, transforming + attribute values and serializing relationships. + + For maximum performance Ember Data recommends you use the + [RESTSerializer](DS.RESTSerializer.html) or one of its subclasses. + + `JSONSerializer` is useful for simpler or legacy backends that may + not support the http://jsonapi.org/ spec. + + @class JSONSerializer + @namespace DS + */ + __exports__["default"] = Ember.Object.extend({ + /** + The primaryKey is used when serializing and deserializing + data. Ember Data always uses the `id` property to store the id of + the record. The external source may not always follow this + convention. In these cases it is useful to override the + primaryKey property to match the primaryKey of your external + store. + + Example + + ```javascript + App.ApplicationSerializer = DS.JSONSerializer.extend({ + primaryKey: '_id' + }); + ``` + + @property primaryKey + @type {String} + @default 'id' + */ + primaryKey: 'id', + + /** + The `attrs` object can be used to declare a simple mapping between + property names on `DS.Model` records and payload keys in the + serialized JSON object representing the record. An object with the + property `key` can also be used to designate the attribute's key on + the response payload. + + Example + + ```javascript + App.Person = DS.Model.extend({ + firstName: DS.attr('string'), + lastName: DS.attr('string'), + occupation: DS.attr('string'), + admin: DS.attr('boolean') + }); + + App.PersonSerializer = DS.JSONSerializer.extend({ + attrs: { + admin: 'is_admin', + occupation: {key: 'career'} + } + }); + ``` + + You can also remove attributes by setting the `serialize` key to + false in your mapping object. + + Example + + ```javascript + App.PersonSerializer = DS.JSONSerializer.extend({ + attrs: { + admin: {serialize: false}, + occupation: {key: 'career'} + } + }); + ``` + + When serialized: + + ```javascript + { + "career": "magician" + } + ``` + + Note that the `admin` is now not included in the payload. + + @property attrs + @type {Object} + */ + + /** + Given a subclass of `DS.Model` and a JSON object this method will + iterate through each attribute of the `DS.Model` and invoke the + `DS.Transform#deserialize` method on the matching property of the + JSON object. This method is typically called after the + serializer's `normalize` method. + + @method applyTransforms + @private + @param {subclass of DS.Model} type + @param {Object} data The data to transform + @return {Object} data The transformed data object + */ + applyTransforms: function(type, data) { + type.eachTransformedAttribute(function applyTransform(key, type) { + if (!data.hasOwnProperty(key)) { return; } + + var transform = this.transformFor(type); + data[key] = transform.deserialize(data[key]); + }, this); + + return data; + }, + + /** + Normalizes a part of the JSON payload returned by + the server. You should override this method, munge the hash + and call super if you have generic normalization to do. + + It takes the type of the record that is being normalized + (as a DS.Model class), the property where the hash was + originally found, and the hash to normalize. + + You can use this method, for example, to normalize underscored keys to camelized + or other general-purpose normalizations. + + Example + + ```javascript + App.ApplicationSerializer = DS.JSONSerializer.extend({ + normalize: function(type, hash) { + var fields = Ember.get(type, 'fields'); + fields.forEach(function(field) { + var payloadField = Ember.String.underscore(field); + if (field === payloadField) { return; } + + hash[field] = hash[payloadField]; + delete hash[payloadField]; + }); + return this._super.apply(this, arguments); + } + }); + ``` + + @method normalize + @param {subclass of DS.Model} type + @param {Object} hash + @return {Object} + */ + normalize: function(type, hash) { + if (!hash) { return hash; } + + this.normalizeId(hash); + this.normalizeAttributes(type, hash); + this.normalizeRelationships(type, hash); + + this.normalizeUsingDeclaredMapping(type, hash); + this.applyTransforms(type, hash); + return hash; + }, + + /** + You can use this method to normalize all payloads, regardless of whether they + represent single records or an array. + + For example, you might want to remove some extraneous data from the payload: + + ```js + App.ApplicationSerializer = DS.JSONSerializer.extend({ + normalizePayload: function(payload) { + delete payload.version; + delete payload.status; + return payload; + } + }); + ``` + + @method normalizePayload + @param {Object} payload + @return {Object} the normalized payload + */ + normalizePayload: function(payload) { + return payload; + }, + + /** + @method normalizeAttributes + @private + */ + normalizeAttributes: function(type, hash) { + var payloadKey; + + if (this.keyForAttribute) { + type.eachAttribute(function(key) { + payloadKey = this.keyForAttribute(key); + if (key === payloadKey) { return; } + if (!hash.hasOwnProperty(payloadKey)) { return; } + + hash[key] = hash[payloadKey]; + delete hash[payloadKey]; + }, this); + } + }, + + /** + @method normalizeRelationships + @private + */ + normalizeRelationships: function(type, hash) { + var payloadKey; + + if (this.keyForRelationship) { + type.eachRelationship(function(key, relationship) { + payloadKey = this.keyForRelationship(key, relationship.kind); + if (key === payloadKey) { return; } + if (!hash.hasOwnProperty(payloadKey)) { return; } + + hash[key] = hash[payloadKey]; + delete hash[payloadKey]; + }, this); + } + }, + + /** + @method normalizeUsingDeclaredMapping + @private + */ + normalizeUsingDeclaredMapping: function(type, hash) { + var attrs = get(this, 'attrs'), payloadKey, key; + + if (attrs) { + for (key in attrs) { + payloadKey = this._getMappedKey(key); + if (!hash.hasOwnProperty(payloadKey)) { continue; } + + if (payloadKey !== key) { + hash[key] = hash[payloadKey]; + delete hash[payloadKey]; + } + } + } + }, + + /** + @method normalizeId + @private + */ + normalizeId: function(hash) { + var primaryKey = get(this, 'primaryKey'); + + if (primaryKey === 'id') { return; } + + hash.id = hash[primaryKey]; + delete hash[primaryKey]; + }, + + /** + @method normalizeErrors + @private + */ + normalizeErrors: function(type, hash) { + this.normalizeId(hash); + this.normalizeAttributes(type, hash); + this.normalizeRelationships(type, hash); + }, + + /** + Looks up the property key that was set by the custom `attr` mapping + passed to the serializer. + + @method _getMappedKey + @private + @param {String} key + @return {String} key + */ + _getMappedKey: function(key) { + var attrs = get(this, 'attrs'); + var mappedKey; + if (attrs && attrs[key]) { + mappedKey = attrs[key]; + //We need to account for both the {title: 'post_title'} and + //{title: {key: 'post_title'}} forms + if (mappedKey.key){ + mappedKey = mappedKey.key; + } + if (typeof mappedKey === 'string'){ + key = mappedKey; + } + } + + return key; + }, + + /** + Check attrs.key.serialize property to inform if the `key` + can be serialized + + @method _canSerialize + @private + @param {String} key + @return {boolean} true if the key can be serialized + */ + _canSerialize: function(key) { + var attrs = get(this, 'attrs'); + + return !attrs || !attrs[key] || attrs[key].serialize !== false; + }, + + // SERIALIZE + /** + Called when a record is saved in order to convert the + record into JSON. + + By default, it creates a JSON object with a key for + each attribute and belongsTo relationship. + + For example, consider this model: + + ```javascript + App.Comment = DS.Model.extend({ + title: DS.attr(), + body: DS.attr(), + + author: DS.belongsTo('user') + }); + ``` + + The default serialization would create a JSON object like: + + ```javascript + { + "title": "Rails is unagi", + "body": "Rails? Omakase? O_O", + "author": 12 + } + ``` + + By default, attributes are passed through as-is, unless + you specified an attribute type (`DS.attr('date')`). If + you specify a transform, the JavaScript value will be + serialized when inserted into the JSON hash. + + By default, belongs-to relationships are converted into + IDs when inserted into the JSON hash. + + ## IDs + + `serialize` takes an options hash with a single option: + `includeId`. If this option is `true`, `serialize` will, + by default include the ID in the JSON object it builds. + + The adapter passes in `includeId: true` when serializing + a record for `createRecord`, but not for `updateRecord`. + + ## Customization + + Your server may expect a different JSON format than the + built-in serialization format. + + In that case, you can implement `serialize` yourself and + return a JSON hash of your choosing. + + ```javascript + App.PostSerializer = DS.JSONSerializer.extend({ + serialize: function(post, options) { + var json = { + POST_TTL: post.get('title'), + POST_BDY: post.get('body'), + POST_CMS: post.get('comments').mapBy('id') + } + + if (options.includeId) { + json.POST_ID_ = post.get('id'); + } + + return json; + } + }); + ``` + + ## Customizing an App-Wide Serializer + + If you want to define a serializer for your entire + application, you'll probably want to use `eachAttribute` + and `eachRelationship` on the record. + + ```javascript + App.ApplicationSerializer = DS.JSONSerializer.extend({ + serialize: function(record, options) { + var json = {}; + + record.eachAttribute(function(name) { + json[serverAttributeName(name)] = record.get(name); + }) + + record.eachRelationship(function(name, relationship) { + if (relationship.kind === 'hasMany') { + json[serverHasManyName(name)] = record.get(name).mapBy('id'); + } + }); + + if (options.includeId) { + json.ID_ = record.get('id'); + } + + return json; + } + }); + + function serverAttributeName(attribute) { + return attribute.underscore().toUpperCase(); + } + + function serverHasManyName(name) { + return serverAttributeName(name.singularize()) + "_IDS"; + } + ``` + + This serializer will generate JSON that looks like this: + + ```javascript + { + "TITLE": "Rails is omakase", + "BODY": "Yep. Omakase.", + "COMMENT_IDS": [ 1, 2, 3 ] + } + ``` + + ## Tweaking the Default JSON + + If you just want to do some small tweaks on the default JSON, + you can call super first and make the tweaks on the returned + JSON. + + ```javascript + App.PostSerializer = DS.JSONSerializer.extend({ + serialize: function(record, options) { + var json = this._super.apply(this, arguments); + + json.subject = json.title; + delete json.title; + + return json; + } + }); + ``` + + @method serialize + @param {subclass of DS.Model} record + @param {Object} options + @return {Object} json + */ + serialize: function(record, options) { + var json = {}; + + if (options && options.includeId) { + var id = get(record, 'id'); + + if (id) { + json[get(this, 'primaryKey')] = id; + } + } + + record.eachAttribute(function(key, attribute) { + this.serializeAttribute(record, json, key, attribute); + }, this); + + record.eachRelationship(function(key, relationship) { + if (relationship.kind === 'belongsTo') { + this.serializeBelongsTo(record, json, relationship); + } else if (relationship.kind === 'hasMany') { + this.serializeHasMany(record, json, relationship); + } + }, this); + + return json; + }, + + /** + You can use this method to customize how a serialized record is added to the complete + JSON hash to be sent to the server. By default the JSON Serializer does not namespace + the payload and just sends the raw serialized JSON object. + If your server expects namespaced keys, you should consider using the RESTSerializer. + Otherwise you can override this method to customize how the record is added to the hash. + + For example, your server may expect underscored root objects. + + ```js + App.ApplicationSerializer = DS.RESTSerializer.extend({ + serializeIntoHash: function(data, type, record, options) { + var root = Ember.String.decamelize(type.typeKey); + data[root] = this.serialize(record, options); + } + }); + ``` + + @method serializeIntoHash + @param {Object} hash + @param {subclass of DS.Model} type + @param {DS.Model} record + @param {Object} options + */ + serializeIntoHash: function(hash, type, record, options) { + merge(hash, this.serialize(record, options)); + }, + + /** + `serializeAttribute` can be used to customize how `DS.attr` + properties are serialized + + For example if you wanted to ensure all your attributes were always + serialized as properties on an `attributes` object you could + write: + + ```javascript + App.ApplicationSerializer = DS.JSONSerializer.extend({ + serializeAttribute: function(record, json, key, attributes) { + json.attributes = json.attributes || {}; + this._super(record, json.attributes, key, attributes); + } + }); + ``` + + @method serializeAttribute + @param {DS.Model} record + @param {Object} json + @param {String} key + @param {Object} attribute + */ + serializeAttribute: function(record, json, key, attribute) { + var type = attribute.type; + + if (this._canSerialize(key)) { + var value = get(record, key); + if (type) { + var transform = this.transformFor(type); + value = transform.serialize(value); + } + + // if provided, use the mapping provided by `attrs` in + // the serializer + var payloadKey = this._getMappedKey(key); + + if (payloadKey === key && this.keyForAttribute) { + payloadKey = this.keyForAttribute(key); + } + + json[payloadKey] = value; + } + }, + + /** + `serializeBelongsTo` can be used to customize how `DS.belongsTo` + properties are serialized. + + Example + + ```javascript + App.PostSerializer = DS.JSONSerializer.extend({ + serializeBelongsTo: function(record, json, relationship) { + var key = relationship.key; + + var belongsTo = get(record, key); + + key = this.keyForRelationship ? this.keyForRelationship(key, "belongsTo") : key; + + json[key] = Ember.isNone(belongsTo) ? belongsTo : belongsTo.toJSON(); + } + }); + ``` + + @method serializeBelongsTo + @param {DS.Model} record + @param {Object} json + @param {Object} relationship + */ + serializeBelongsTo: function(record, json, relationship) { + var key = relationship.key; + + if (this._canSerialize(key)) { + var belongsTo = get(record, key); + + // if provided, use the mapping provided by `attrs` in + // the serializer + var payloadKey = this._getMappedKey(key); + if (payloadKey === key && this.keyForRelationship) { + payloadKey = this.keyForRelationship(key, "belongsTo"); + } + + //Need to check whether the id is there for new&async records + if (isNone(belongsTo) || isNone(get(belongsTo, 'id'))) { + json[payloadKey] = null; + } else { + json[payloadKey] = get(belongsTo, 'id'); + } + + if (relationship.options.polymorphic) { + this.serializePolymorphicType(record, json, relationship); + } + } + }, + + /** + `serializeHasMany` can be used to customize how `DS.hasMany` + properties are serialized. + + Example + + ```javascript + App.PostSerializer = DS.JSONSerializer.extend({ + serializeHasMany: function(record, json, relationship) { + var key = relationship.key; + if (key === 'comments') { + return; + } else { + this._super.apply(this, arguments); + } + } + }); + ``` + + @method serializeHasMany + @param {DS.Model} record + @param {Object} json + @param {Object} relationship + */ + serializeHasMany: function(record, json, relationship) { + var key = relationship.key; + + if (this._canSerialize(key)) { + var payloadKey; + + // if provided, use the mapping provided by `attrs` in + // the serializer + payloadKey = this._getMappedKey(key); + if (payloadKey === key && this.keyForRelationship) { + payloadKey = this.keyForRelationship(key, "hasMany"); + } + + var relationshipType = record.constructor.determineRelationshipType(relationship); + + if (relationshipType === 'manyToNone' || relationshipType === 'manyToMany') { + json[payloadKey] = get(record, key).mapBy('id'); + // TODO support for polymorphic manyToNone and manyToMany relationships + } + } + }, + + /** + You can use this method to customize how polymorphic objects are + serialized. Objects are considered to be polymorphic if + `{polymorphic: true}` is pass as the second argument to the + `DS.belongsTo` function. + + Example + + ```javascript + App.CommentSerializer = DS.JSONSerializer.extend({ + serializePolymorphicType: function(record, json, relationship) { + var key = relationship.key, + belongsTo = get(record, key); + key = this.keyForAttribute ? this.keyForAttribute(key) : key; + + if (Ember.isNone(belongsTo)) { + json[key + "_type"] = null; + } else { + json[key + "_type"] = belongsTo.constructor.typeKey; + } + } + }); + ``` + + @method serializePolymorphicType + @param {DS.Model} record + @param {Object} json + @param {Object} relationship + */ + serializePolymorphicType: Ember.K, + + // EXTRACT + + /** + The `extract` method is used to deserialize payload data from the + server. By default the `JSONSerializer` does not push the records + into the store. However records that subclass `JSONSerializer` + such as the `RESTSerializer` may push records into the store as + part of the extract call. + + This method delegates to a more specific extract method based on + the `requestType`. + + Example + + ```javascript + var get = Ember.get; + socket.on('message', function(message) { + var modelName = message.model; + var data = message.data; + var type = store.modelFor(modelName); + var serializer = store.serializerFor(type.typeKey); + var record = serializer.extract(store, type, data, get(data, 'id'), 'single'); + store.push(modelName, record); + }); + ``` + + @method extract + @param {DS.Store} store + @param {subclass of DS.Model} type + @param {Object} payload + @param {String or Number} id + @param {String} requestType + @return {Object} json The deserialized payload + */ + extract: function(store, type, payload, id, requestType) { + this.extractMeta(store, type, payload); + + var specificExtract = "extract" + requestType.charAt(0).toUpperCase() + requestType.substr(1); + return this[specificExtract](store, type, payload, id, requestType); + }, + + /** + `extractFindAll` is a hook into the extract method used when a + call is made to `DS.Store#findAll`. By default this method is an + alias for [extractArray](#method_extractArray). + + @method extractFindAll + @param {DS.Store} store + @param {subclass of DS.Model} type + @param {Object} payload + @param {String or Number} id + @param {String} requestType + @return {Array} array An array of deserialized objects + */ + extractFindAll: function(store, type, payload, id, requestType){ + return this.extractArray(store, type, payload, id, requestType); + }, + /** + `extractFindQuery` is a hook into the extract method used when a + call is made to `DS.Store#findQuery`. By default this method is an + alias for [extractArray](#method_extractArray). + + @method extractFindQuery + @param {DS.Store} store + @param {subclass of DS.Model} type + @param {Object} payload + @param {String or Number} id + @param {String} requestType + @return {Array} array An array of deserialized objects + */ + extractFindQuery: function(store, type, payload, id, requestType){ + return this.extractArray(store, type, payload, id, requestType); + }, + /** + `extractFindMany` is a hook into the extract method used when a + call is made to `DS.Store#findMany`. By default this method is + alias for [extractArray](#method_extractArray). + + @method extractFindMany + @param {DS.Store} store + @param {subclass of DS.Model} type + @param {Object} payload + @param {String or Number} id + @param {String} requestType + @return {Array} array An array of deserialized objects + */ + extractFindMany: function(store, type, payload, id, requestType){ + return this.extractArray(store, type, payload, id, requestType); + }, + /** + `extractFindHasMany` is a hook into the extract method used when a + call is made to `DS.Store#findHasMany`. By default this method is + alias for [extractArray](#method_extractArray). + + @method extractFindHasMany + @param {DS.Store} store + @param {subclass of DS.Model} type + @param {Object} payload + @param {String or Number} id + @param {String} requestType + @return {Array} array An array of deserialized objects + */ + extractFindHasMany: function(store, type, payload, id, requestType){ + return this.extractArray(store, type, payload, id, requestType); + }, + + /** + `extractCreateRecord` is a hook into the extract method used when a + call is made to `DS.Store#createRecord`. By default this method is + alias for [extractSave](#method_extractSave). + + @method extractCreateRecord + @param {DS.Store} store + @param {subclass of DS.Model} type + @param {Object} payload + @param {String or Number} id + @param {String} requestType + @return {Object} json The deserialized payload + */ + extractCreateRecord: function(store, type, payload, id, requestType) { + return this.extractSave(store, type, payload, id, requestType); + }, + /** + `extractUpdateRecord` is a hook into the extract method used when + a call is made to `DS.Store#update`. By default this method is alias + for [extractSave](#method_extractSave). + + @method extractUpdateRecord + @param {DS.Store} store + @param {subclass of DS.Model} type + @param {Object} payload + @param {String or Number} id + @param {String} requestType + @return {Object} json The deserialized payload + */ + extractUpdateRecord: function(store, type, payload, id, requestType) { + return this.extractSave(store, type, payload, id, requestType); + }, + /** + `extractDeleteRecord` is a hook into the extract method used when + a call is made to `DS.Store#deleteRecord`. By default this method is + alias for [extractSave](#method_extractSave). + + @method extractDeleteRecord + @param {DS.Store} store + @param {subclass of DS.Model} type + @param {Object} payload + @param {String or Number} id + @param {String} requestType + @return {Object} json The deserialized payload + */ + extractDeleteRecord: function(store, type, payload, id, requestType) { + return this.extractSave(store, type, payload, id, requestType); + }, + + /** + `extractFind` is a hook into the extract method used when + a call is made to `DS.Store#find`. By default this method is + alias for [extractSingle](#method_extractSingle). + + @method extractFind + @param {DS.Store} store + @param {subclass of DS.Model} type + @param {Object} payload + @param {String or Number} id + @param {String} requestType + @return {Object} json The deserialized payload + */ + extractFind: function(store, type, payload, id, requestType) { + return this.extractSingle(store, type, payload, id, requestType); + }, + /** + `extractFindBelongsTo` is a hook into the extract method used when + a call is made to `DS.Store#findBelongsTo`. By default this method is + alias for [extractSingle](#method_extractSingle). + + @method extractFindBelongsTo + @param {DS.Store} store + @param {subclass of DS.Model} type + @param {Object} payload + @param {String or Number} id + @param {String} requestType + @return {Object} json The deserialized payload + */ + extractFindBelongsTo: function(store, type, payload, id, requestType) { + return this.extractSingle(store, type, payload, id, requestType); + }, + /** + `extractSave` is a hook into the extract method used when a call + is made to `DS.Model#save`. By default this method is alias + for [extractSingle](#method_extractSingle). + + @method extractSave + @param {DS.Store} store + @param {subclass of DS.Model} type + @param {Object} payload + @param {String or Number} id + @param {String} requestType + @return {Object} json The deserialized payload + */ + extractSave: function(store, type, payload, id, requestType) { + return this.extractSingle(store, type, payload, id, requestType); + }, + + /** + `extractSingle` is used to deserialize a single record returned + from the adapter. + + Example + + ```javascript + App.PostSerializer = DS.JSONSerializer.extend({ + extractSingle: function(store, type, payload) { + payload.comments = payload._embedded.comment; + delete payload._embedded; + + return this._super(store, type, payload); + }, + }); + ``` + + @method extractSingle + @param {DS.Store} store + @param {subclass of DS.Model} type + @param {Object} payload + @param {String or Number} id + @param {String} requestType + @return {Object} json The deserialized payload + */ + extractSingle: function(store, type, payload, id, requestType) { + payload = this.normalizePayload(payload); + return this.normalize(type, payload); + }, + + /** + `extractArray` is used to deserialize an array of records + returned from the adapter. + + Example + + ```javascript + App.PostSerializer = DS.JSONSerializer.extend({ + extractArray: function(store, type, payload) { + return payload.map(function(json) { + return this.extractSingle(store, type, json); + }, this); + } + }); + ``` + + @method extractArray + @param {DS.Store} store + @param {subclass of DS.Model} type + @param {Object} payload + @param {String or Number} id + @param {String} requestType + @return {Array} array An array of deserialized objects + */ + extractArray: function(store, type, arrayPayload, id, requestType) { + var normalizedPayload = this.normalizePayload(arrayPayload); + var serializer = this; + + return map.call(normalizedPayload, function(singlePayload) { + return serializer.normalize(type, singlePayload); + }); + }, + + /** + `extractMeta` is used to deserialize any meta information in the + adapter payload. By default Ember Data expects meta information to + be located on the `meta` property of the payload object. + + Example + + ```javascript + App.PostSerializer = DS.JSONSerializer.extend({ + extractMeta: function(store, type, payload) { + if (payload && payload._pagination) { + store.metaForType(type, payload._pagination); + delete payload._pagination; + } + } + }); + ``` + + @method extractMeta + @param {DS.Store} store + @param {subclass of DS.Model} type + @param {Object} payload + */ + extractMeta: function(store, type, payload) { + if (payload && payload.meta) { + store.metaForType(type, payload.meta); + delete payload.meta; + } + }, + + /** + `extractErrors` is used to extract model errors when a call is made + to `DS.Model#save` which fails with an InvalidError`. By default + Ember Data expects error information to be located on the `errors` + property of the payload object. + + Example + + ```javascript + App.PostSerializer = DS.JSONSerializer.extend({ + extractErrors: function(store, type, payload, id) { + if (payload && typeof payload === 'object' && payload._problems) { + payload = payload._problems; + this.normalizeErrors(type, payload); + } + return payload; + } + }); + ``` + + @method extractErrors + @param {DS.Store} store + @param {subclass of DS.Model} type + @param {Object} payload + @param {String or Number} id + @return {Object} json The deserialized errors + */ + extractErrors: function(store, type, payload, id) { + if (payload && typeof payload === 'object' && payload.errors) { + payload = payload.errors; + this.normalizeErrors(type, payload); + } + return payload; + }, + + /** + `keyForAttribute` can be used to define rules for how to convert an + attribute name in your model to a key in your JSON. + + Example + + ```javascript + App.ApplicationSerializer = DS.RESTSerializer.extend({ + keyForAttribute: function(attr) { + return Ember.String.underscore(attr).toUpperCase(); + } + }); + ``` + + @method keyForAttribute + @param {String} key + @return {String} normalized key + */ + keyForAttribute: function(key){ + return key; + }, + + /** + `keyForRelationship` can be used to define a custom key when + serializing relationship properties. By default `JSONSerializer` + does not provide an implementation of this method. + + Example + + ```javascript + App.PostSerializer = DS.JSONSerializer.extend({ + keyForRelationship: function(key, relationship) { + return 'rel_' + Ember.String.underscore(key); + } + }); + ``` + + @method keyForRelationship + @param {String} key + @param {String} relationship type + @return {String} normalized key + */ + + keyForRelationship: function(key, type){ + return key; + }, + + // HELPERS + + /** + @method transformFor + @private + @param {String} attributeType + @param {Boolean} skipAssertion + @return {DS.Transform} transform + */ + transformFor: function(attributeType, skipAssertion) { + var transform = this.container.lookup('transform:' + attributeType); + Ember.assert("Unable to find transform for '" + attributeType + "'", skipAssertion || !!transform); + return transform; + } + }); + }); +enifed("ember-data/serializers/rest_serializer", + ["ember-data/serializers/json_serializer","ember-inflector/system/string","exports"], + function(__dependency1__, __dependency2__, __exports__) { + "use strict"; + /** + @module ember-data + */ + + var JSONSerializer = __dependency1__["default"]; + var get = Ember.get; + var forEach = Ember.ArrayPolyfills.forEach; + var map = Ember.ArrayPolyfills.map; + var camelize = Ember.String.camelize; + + var singularize = __dependency2__.singularize; + + function coerceId(id) { + return id == null ? null : id + ''; + } + + /** + Normally, applications will use the `RESTSerializer` by implementing + the `normalize` method and individual normalizations under + `normalizeHash`. + + This allows you to do whatever kind of munging you need, and is + especially useful if your server is inconsistent and you need to + do munging differently for many different kinds of responses. + + See the `normalize` documentation for more information. + + ## Across the Board Normalization + + There are also a number of hooks that you might find useful to define + across-the-board rules for your payload. These rules will be useful + if your server is consistent, or if you're building an adapter for + an infrastructure service, like Parse, and want to encode service + conventions. + + For example, if all of your keys are underscored and all-caps, but + otherwise consistent with the names you use in your models, you + can implement across-the-board rules for how to convert an attribute + name in your model to a key in your JSON. + + ```js + App.ApplicationSerializer = DS.RESTSerializer.extend({ + keyForAttribute: function(attr) { + return Ember.String.underscore(attr).toUpperCase(); + } + }); + ``` + + You can also implement `keyForRelationship`, which takes the name + of the relationship as the first parameter, and the kind of + relationship (`hasMany` or `belongsTo`) as the second parameter. + + @class RESTSerializer + @namespace DS + @extends DS.JSONSerializer + */ + var RESTSerializer = JSONSerializer.extend({ + /** + If you want to do normalizations specific to some part of the payload, you + can specify those under `normalizeHash`. + + For example, given the following json where the the `IDs` under + `"comments"` are provided as `_id` instead of `id`. + + ```javascript + { + "post": { + "id": 1, + "title": "Rails is omakase", + "comments": [ 1, 2 ] + }, + "comments": [{ + "_id": 1, + "body": "FIRST" + }, { + "_id": 2, + "body": "Rails is unagi" + }] + } + ``` + + You use `normalizeHash` to normalize just the comments: + + ```javascript + App.PostSerializer = DS.RESTSerializer.extend({ + normalizeHash: { + comments: function(hash) { + hash.id = hash._id; + delete hash._id; + return hash; + } + } + }); + ``` + + The key under `normalizeHash` is usually just the original key + that was in the original payload. However, key names will be + impacted by any modifications done in the `normalizePayload` + method. The `DS.RESTSerializer`'s default implementation makes no + changes to the payload keys. + + @property normalizeHash + @type {Object} + @default undefined + */ + + /** + Normalizes a part of the JSON payload returned by + the server. You should override this method, munge the hash + and call super if you have generic normalization to do. + + It takes the type of the record that is being normalized + (as a DS.Model class), the property where the hash was + originally found, and the hash to normalize. + + For example, if you have a payload that looks like this: + + ```js + { + "post": { + "id": 1, + "title": "Rails is omakase", + "comments": [ 1, 2 ] + }, + "comments": [{ + "id": 1, + "body": "FIRST" + }, { + "id": 2, + "body": "Rails is unagi" + }] + } + ``` + + The `normalize` method will be called three times: + + * With `App.Post`, `"posts"` and `{ id: 1, title: "Rails is omakase", ... }` + * With `App.Comment`, `"comments"` and `{ id: 1, body: "FIRST" }` + * With `App.Comment`, `"comments"` and `{ id: 2, body: "Rails is unagi" }` + + You can use this method, for example, to normalize underscored keys to camelized + or other general-purpose normalizations. + + If you want to do normalizations specific to some part of the payload, you + can specify those under `normalizeHash`. + + For example, if the `IDs` under `"comments"` are provided as `_id` instead of + `id`, you can specify how to normalize just the comments: + + ```js + App.PostSerializer = DS.RESTSerializer.extend({ + normalizeHash: { + comments: function(hash) { + hash.id = hash._id; + delete hash._id; + return hash; + } + } + }); + ``` + + The key under `normalizeHash` is just the original key that was in the original + payload. + + @method normalize + @param {subclass of DS.Model} type + @param {Object} hash + @param {String} prop + @return {Object} + */ + normalize: function(type, hash, prop) { + this.normalizeId(hash); + this.normalizeAttributes(type, hash); + this.normalizeRelationships(type, hash); + + this.normalizeUsingDeclaredMapping(type, hash); + + if (this.normalizeHash && this.normalizeHash[prop]) { + this.normalizeHash[prop](hash); + } + + this.applyTransforms(type, hash); + return hash; + }, + + + /** + Called when the server has returned a payload representing + a single record, such as in response to a `find` or `save`. + + It is your opportunity to clean up the server's response into the normalized + form expected by Ember Data. + + If you want, you can just restructure the top-level of your payload, and + do more fine-grained normalization in the `normalize` method. + + For example, if you have a payload like this in response to a request for + post 1: + + ```js + { + "id": 1, + "title": "Rails is omakase", + + "_embedded": { + "comment": [{ + "_id": 1, + "comment_title": "FIRST" + }, { + "_id": 2, + "comment_title": "Rails is unagi" + }] + } + } + ``` + + You could implement a serializer that looks like this to get your payload + into shape: + + ```js + App.PostSerializer = DS.RESTSerializer.extend({ + // First, restructure the top-level so it's organized by type + extractSingle: function(store, type, payload, id) { + var comments = payload._embedded.comment; + delete payload._embedded; + + payload = { comments: comments, post: payload }; + return this._super(store, type, payload, id); + }, + + normalizeHash: { + // Next, normalize individual comments, which (after `extract`) + // are now located under `comments` + comments: function(hash) { + hash.id = hash._id; + hash.title = hash.comment_title; + delete hash._id; + delete hash.comment_title; + return hash; + } + } + }) + ``` + + When you call super from your own implementation of `extractSingle`, the + built-in implementation will find the primary record in your normalized + payload and push the remaining records into the store. + + The primary record is the single hash found under `post` or the first + element of the `posts` array. + + The primary record has special meaning when the record is being created + for the first time or updated (`createRecord` or `updateRecord`). In + particular, it will update the properties of the record that was saved. + + @method extractSingle + @param {DS.Store} store + @param {subclass of DS.Model} primaryType + @param {Object} payload + @param {String} recordId + @return {Object} the primary response to the original request + */ + extractSingle: function(store, primaryType, rawPayload, recordId) { + var payload = this.normalizePayload(rawPayload); + var primaryTypeName = primaryType.typeKey; + var primaryRecord; + + for (var prop in payload) { + var typeName = this.typeForRoot(prop); + + if (!store.modelFactoryFor(typeName)){ + Ember.warn(this.warnMessageNoModelForKey(prop, typeName), false); + continue; + } + var type = store.modelFor(typeName); + var isPrimary = type.typeKey === primaryTypeName; + var value = payload[prop]; + + if (value === null) { + continue; + } + + // legacy support for singular resources + if (isPrimary && Ember.typeOf(value) !== "array" ) { + primaryRecord = this.normalize(primaryType, value, prop); + continue; + } + + /*jshint loopfunc:true*/ + forEach.call(value, function(hash) { + var typeName = this.typeForRoot(prop); + var type = store.modelFor(typeName); + var typeSerializer = store.serializerFor(type); + + hash = typeSerializer.normalize(type, hash, prop); + + var isFirstCreatedRecord = isPrimary && !recordId && !primaryRecord; + var isUpdatedRecord = isPrimary && coerceId(hash.id) === recordId; + + // find the primary record. + // + // It's either: + // * the record with the same ID as the original request + // * in the case of a newly created record that didn't have an ID, the first + // record in the Array + if (isFirstCreatedRecord || isUpdatedRecord) { + primaryRecord = hash; + } else { + store.push(typeName, hash); + } + }, this); + } + + return primaryRecord; + }, + + /** + Called when the server has returned a payload representing + multiple records, such as in response to a `findAll` or `findQuery`. + + It is your opportunity to clean up the server's response into the normalized + form expected by Ember Data. + + If you want, you can just restructure the top-level of your payload, and + do more fine-grained normalization in the `normalize` method. + + For example, if you have a payload like this in response to a request for + all posts: + + ```js + { + "_embedded": { + "post": [{ + "id": 1, + "title": "Rails is omakase" + }, { + "id": 2, + "title": "The Parley Letter" + }], + "comment": [{ + "_id": 1, + "comment_title": "Rails is unagi" + "post_id": 1 + }, { + "_id": 2, + "comment_title": "Don't tread on me", + "post_id": 2 + }] + } + } + ``` + + You could implement a serializer that looks like this to get your payload + into shape: + + ```js + App.PostSerializer = DS.RESTSerializer.extend({ + // First, restructure the top-level so it's organized by type + // and the comments are listed under a post's `comments` key. + extractArray: function(store, type, payload) { + var posts = payload._embedded.post; + var comments = []; + var postCache = {}; + + posts.forEach(function(post) { + post.comments = []; + postCache[post.id] = post; + }); + + payload._embedded.comment.forEach(function(comment) { + comments.push(comment); + postCache[comment.post_id].comments.push(comment); + delete comment.post_id; + }); + + payload = { comments: comments, posts: payload }; + + return this._super(store, type, payload); + }, + + normalizeHash: { + // Next, normalize individual comments, which (after `extract`) + // are now located under `comments` + comments: function(hash) { + hash.id = hash._id; + hash.title = hash.comment_title; + delete hash._id; + delete hash.comment_title; + return hash; + } + } + }) + ``` + + When you call super from your own implementation of `extractArray`, the + built-in implementation will find the primary array in your normalized + payload and push the remaining records into the store. + + The primary array is the array found under `posts`. + + The primary record has special meaning when responding to `findQuery` + or `findHasMany`. In particular, the primary array will become the + list of records in the record array that kicked off the request. + + If your primary array contains secondary (embedded) records of the same type, + you cannot place these into the primary array `posts`. Instead, place the + secondary items into an underscore prefixed property `_posts`, which will + push these items into the store and will not affect the resulting query. + + @method extractArray + @param {DS.Store} store + @param {subclass of DS.Model} primaryType + @param {Object} payload + @return {Array} The primary array that was returned in response + to the original query. + */ + extractArray: function(store, primaryType, rawPayload) { + var payload = this.normalizePayload(rawPayload); + var primaryTypeName = primaryType.typeKey; + var primaryArray; + + for (var prop in payload) { + var typeKey = prop; + var forcedSecondary = false; + + if (prop.charAt(0) === '_') { + forcedSecondary = true; + typeKey = prop.substr(1); + } + + var typeName = this.typeForRoot(typeKey); + if (!store.modelFactoryFor(typeName)) { + Ember.warn(this.warnMessageNoModelForKey(prop, typeName), false); + continue; + } + var type = store.modelFor(typeName); + var typeSerializer = store.serializerFor(type); + var isPrimary = (!forcedSecondary && (type.typeKey === primaryTypeName)); + + /*jshint loopfunc:true*/ + var normalizedArray = map.call(payload[prop], function(hash) { + return typeSerializer.normalize(type, hash, prop); + }, this); + + if (isPrimary) { + primaryArray = normalizedArray; + } else { + store.pushMany(typeName, normalizedArray); + } + } + + return primaryArray; + }, + + /** + This method allows you to push a payload containing top-level + collections of records organized per type. + + ```js + { + "posts": [{ + "id": "1", + "title": "Rails is omakase", + "author", "1", + "comments": [ "1" ] + }], + "comments": [{ + "id": "1", + "body": "FIRST" + }], + "users": [{ + "id": "1", + "name": "@d2h" + }] + } + ``` + + It will first normalize the payload, so you can use this to push + in data streaming in from your server structured the same way + that fetches and saves are structured. + + @method pushPayload + @param {DS.Store} store + @param {Object} payload + */ + pushPayload: function(store, rawPayload) { + var payload = this.normalizePayload(rawPayload); + + for (var prop in payload) { + var typeName = this.typeForRoot(prop); + if (!store.modelFactoryFor(typeName, prop)){ + Ember.warn(this.warnMessageNoModelForKey(prop, typeName), false); + continue; + } + var type = store.modelFor(typeName); + var typeSerializer = store.serializerFor(type); + + /*jshint loopfunc:true*/ + var normalizedArray = map.call(Ember.makeArray(payload[prop]), function(hash) { + return typeSerializer.normalize(type, hash, prop); + }, this); + + store.pushMany(typeName, normalizedArray); + } + }, + + /** + This method is used to convert each JSON root key in the payload + into a typeKey that it can use to look up the appropriate model for + that part of the payload. By default the typeKey for a model is its + name in camelCase, so if your JSON root key is 'fast-car' you would + use typeForRoot to convert it to 'fastCar' so that Ember Data finds + the `FastCar` model. + + If you diverge from this norm you should also consider changes to + store._normalizeTypeKey as well. + + For example, your server may return prefixed root keys like so: + + ```js + { + "response-fast-car": { + "id": "1", + "name": "corvette" + } + } + ``` + + In order for Ember Data to know that the model corresponding to + the 'response-fast-car' hash is `FastCar` (typeKey: 'fastCar'), + you can override typeForRoot to convert 'response-fast-car' to + 'fastCar' like so: + + ```js + App.ApplicationSerializer = DS.RESTSerializer.extend({ + typeForRoot: function(root) { + // 'response-fast-car' should become 'fast-car' + var subRoot = root.substring(9); + + // _super normalizes 'fast-car' to 'fastCar' + return this._super(subRoot); + } + }); + ``` + + @method typeForRoot + @param {String} key + @return {String} the model's typeKey + */ + typeForRoot: function(key) { + return camelize(singularize(key)); + }, + + // SERIALIZE + + /** + Called when a record is saved in order to convert the + record into JSON. + + By default, it creates a JSON object with a key for + each attribute and belongsTo relationship. + + For example, consider this model: + + ```js + App.Comment = DS.Model.extend({ + title: DS.attr(), + body: DS.attr(), + + author: DS.belongsTo('user') + }); + ``` + + The default serialization would create a JSON object like: + + ```js + { + "title": "Rails is unagi", + "body": "Rails? Omakase? O_O", + "author": 12 + } + ``` + + By default, attributes are passed through as-is, unless + you specified an attribute type (`DS.attr('date')`). If + you specify a transform, the JavaScript value will be + serialized when inserted into the JSON hash. + + By default, belongs-to relationships are converted into + IDs when inserted into the JSON hash. + + ## IDs + + `serialize` takes an options hash with a single option: + `includeId`. If this option is `true`, `serialize` will, + by default include the ID in the JSON object it builds. + + The adapter passes in `includeId: true` when serializing + a record for `createRecord`, but not for `updateRecord`. + + ## Customization + + Your server may expect a different JSON format than the + built-in serialization format. + + In that case, you can implement `serialize` yourself and + return a JSON hash of your choosing. + + ```js + App.PostSerializer = DS.RESTSerializer.extend({ + serialize: function(post, options) { + var json = { + POST_TTL: post.get('title'), + POST_BDY: post.get('body'), + POST_CMS: post.get('comments').mapBy('id') + } + + if (options.includeId) { + json.POST_ID_ = post.get('id'); + } + + return json; + } + }); + ``` + + ## Customizing an App-Wide Serializer + + If you want to define a serializer for your entire + application, you'll probably want to use `eachAttribute` + and `eachRelationship` on the record. + + ```js + App.ApplicationSerializer = DS.RESTSerializer.extend({ + serialize: function(record, options) { + var json = {}; + + record.eachAttribute(function(name) { + json[serverAttributeName(name)] = record.get(name); + }) + + record.eachRelationship(function(name, relationship) { + if (relationship.kind === 'hasMany') { + json[serverHasManyName(name)] = record.get(name).mapBy('id'); + } + }); + + if (options.includeId) { + json.ID_ = record.get('id'); + } + + return json; + } + }); + + function serverAttributeName(attribute) { + return attribute.underscore().toUpperCase(); + } + + function serverHasManyName(name) { + return serverAttributeName(name.singularize()) + "_IDS"; + } + ``` + + This serializer will generate JSON that looks like this: + + ```js + { + "TITLE": "Rails is omakase", + "BODY": "Yep. Omakase.", + "COMMENT_IDS": [ 1, 2, 3 ] + } + ``` + + ## Tweaking the Default JSON + + If you just want to do some small tweaks on the default JSON, + you can call super first and make the tweaks on the returned + JSON. + + ```js + App.PostSerializer = DS.RESTSerializer.extend({ + serialize: function(record, options) { + var json = this._super(record, options); + + json.subject = json.title; + delete json.title; + + return json; + } + }); + ``` + + @method serialize + @param {subclass of DS.Model} record + @param {Object} options + @return {Object} json + */ + serialize: function(record, options) { + return this._super.apply(this, arguments); + }, + + /** + You can use this method to customize the root keys serialized into the JSON. + By default the REST Serializer sends the typeKey of a model, which is a camelized + version of the name. + + For example, your server may expect underscored root objects. + + ```js + App.ApplicationSerializer = DS.RESTSerializer.extend({ + serializeIntoHash: function(data, type, record, options) { + var root = Ember.String.decamelize(type.typeKey); + data[root] = this.serialize(record, options); + } + }); + ``` + + @method serializeIntoHash + @param {Object} hash + @param {subclass of DS.Model} type + @param {DS.Model} record + @param {Object} options + */ + serializeIntoHash: function(hash, type, record, options) { + hash[type.typeKey] = this.serialize(record, options); + }, + + /** + You can use this method to customize how polymorphic objects are serialized. + By default the JSON Serializer creates the key by appending `Type` to + the attribute and value from the model's camelcased model name. + + @method serializePolymorphicType + @param {DS.Model} record + @param {Object} json + @param {Object} relationship + */ + serializePolymorphicType: function(record, json, relationship) { + var key = relationship.key; + var belongsTo = get(record, key); + key = this.keyForAttribute ? this.keyForAttribute(key) : key; + if (Ember.isNone(belongsTo)) { + json[key + "Type"] = null; + } else { + json[key + "Type"] = Ember.String.camelize(belongsTo.constructor.typeKey); + } + } + }); + + Ember.runInDebug(function(){ + RESTSerializer.reopen({ + warnMessageNoModelForKey: function(prop, typeKey){ + return 'Encountered "' + prop + '" in payload, but no model was found for model name "' + typeKey + '" (resolved model name using ' + this.constructor.toString() + '.typeForRoot("' + prop + '"))'; + } + }); + }); + + __exports__["default"] = RESTSerializer; + }); +enifed("ember-data/setup-container", + ["ember-data/initializers/store","ember-data/initializers/transforms","ember-data/initializers/store_injections","ember-data/initializers/data_adapter","activemodel-adapter/setup-container","exports"], + function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __dependency5__, __exports__) { + "use strict"; + var initializeStore = __dependency1__["default"]; + var initializeTransforms = __dependency2__["default"]; + var initializeStoreInjections = __dependency3__["default"]; + var initializeDataAdapter = __dependency4__["default"]; + var setupActiveModelContainer = __dependency5__["default"]; + + __exports__["default"] = function setupContainer(container, application){ + // application is not a required argument. This ensures + // testing setups can setup a container without booting an + // entire ember application. + + initializeDataAdapter(container, application); + initializeTransforms(container, application); + initializeStoreInjections(container, application); + initializeStore(container, application); + setupActiveModelContainer(container, application); + }; + }); +enifed("ember-data/system/adapter", + ["exports"], + function(__exports__) { + "use strict"; + /** + @module ember-data + */ + + var get = Ember.get; + + var errorProps = [ + 'description', + 'fileName', + 'lineNumber', + 'message', + 'name', + 'number', + 'stack' + ]; + + /** + A `DS.InvalidError` is used by an adapter to signal the external API + was unable to process a request because the content was not + semantically correct or meaningful per the API. Usually this means a + record failed some form of server side validation. When a promise + from an adapter is rejected with a `DS.InvalidError` the record will + transition to the `invalid` state and the errors will be set to the + `errors` property on the record. + + This function should return the entire payload as received from the + server. Error object extraction and normalization of model errors + should be performed by `extractErrors` on the serializer. + + Example + + ```javascript + App.ApplicationAdapter = DS.RESTAdapter.extend({ + ajaxError: function(jqXHR) { + var error = this._super(jqXHR); + + if (jqXHR && jqXHR.status === 422) { + var jsonErrors = Ember.$.parseJSON(jqXHR.responseText); + return new DS.InvalidError(jsonErrors); + } else { + return error; + } + } + }); + ``` + + The `DS.InvalidError` must be constructed with a single object whose + keys are the invalid model properties, and whose values are the + corresponding error messages. For example: + + ```javascript + return new DS.InvalidError({ + length: 'Must be less than 15', + name: 'Must not be blank' + }); + ``` + + @class InvalidError + @namespace DS + */ + function InvalidError(errors) { + var tmp = Error.prototype.constructor.call(this, "The backend rejected the commit because it was invalid: " + Ember.inspect(errors)); + this.errors = errors; + + for (var i=0, l=errorProps.length; i 0; i--) { + proxyPair = proxyPairs[i - 1]; + deprecated = proxyPair['deprecated']; + valid = proxyPair['valid']; + + this.registerDeprecation(deprecated, valid); + } + }; + + __exports__["default"] = ContainerProxy; + }); +enifed("ember-data/system/create", + [], + function() { + "use strict"; + /* + Detect if the user has a correct Object.create shim. + Ember has provided this for a long time but has had an incorrect shim before 1.8 + TODO: Remove for Ember Data 1.0. + */ + var object = Ember.create(null); + if (object.toString !== undefined && Ember.keys(Ember.create({}))[0] === '__proto__'){ + throw new Error("Ember Data requires a correct Object.create shim. You should upgrade to Ember >= 1.8 which provides one for you. If you are using ES5-shim, you should try removing that after upgrading Ember."); + } + }); +enifed("ember-data/system/debug", + ["ember-data/system/debug/debug_info","ember-data/system/debug/debug_adapter","exports"], + function(__dependency1__, __dependency2__, __exports__) { + "use strict"; + /** + @module ember-data + */ + + var DebugAdapter = __dependency2__["default"]; + + __exports__["default"] = DebugAdapter; + }); +enifed("ember-data/system/debug/debug_adapter", + ["ember-data/system/model","exports"], + function(__dependency1__, __exports__) { + "use strict"; + /** + @module ember-data + */ + var Model = __dependency1__.Model; + var get = Ember.get; + var capitalize = Ember.String.capitalize; + var underscore = Ember.String.underscore; + + /** + Extend `Ember.DataAdapter` with ED specific code. + + @class DebugAdapter + @namespace DS + @extends Ember.DataAdapter + @private + */ + __exports__["default"] = Ember.DataAdapter.extend({ + getFilters: function() { + return [ + { name: 'isNew', desc: 'New' }, + { name: 'isModified', desc: 'Modified' }, + { name: 'isClean', desc: 'Clean' } + ]; + }, + + detect: function(klass) { + return klass !== Model && Model.detect(klass); + }, + + columnsForType: function(type) { + var columns = [{ + name: 'id', + desc: 'Id' + }]; + var count = 0; + var self = this; + get(type, 'attributes').forEach(function(meta, name) { + if (count++ > self.attributeLimit) { return false; } + var desc = capitalize(underscore(name).replace('_', ' ')); + columns.push({ name: name, desc: desc }); + }); + return columns; + }, + + getRecords: function(type) { + return this.get('store').all(type); + }, + + getRecordColumnValues: function(record) { + var self = this, count = 0; + var columnValues = { id: get(record, 'id') }; + + record.eachAttribute(function(key) { + if (count++ > self.attributeLimit) { + return false; + } + var value = get(record, key); + columnValues[key] = value; + }); + return columnValues; + }, + + getRecordKeywords: function(record) { + var keywords = []; + var keys = Ember.A(['id']); + record.eachAttribute(function(key) { + keys.push(key); + }); + keys.forEach(function(key) { + keywords.push(get(record, key)); + }); + return keywords; + }, + + getRecordFilterValues: function(record) { + return { + isNew: record.get('isNew'), + isModified: record.get('isDirty') && !record.get('isNew'), + isClean: !record.get('isDirty') + }; + }, + + getRecordColor: function(record) { + var color = 'black'; + if (record.get('isNew')) { + color = 'green'; + } else if (record.get('isDirty')) { + color = 'blue'; + } + return color; + }, + + observeRecord: function(record, recordUpdated) { + var releaseMethods = Ember.A(), self = this; + var keysToObserve = Ember.A(['id', 'isNew', 'isDirty']); + + record.eachAttribute(function(key) { + keysToObserve.push(key); + }); + + keysToObserve.forEach(function(key) { + var handler = function() { + recordUpdated(self.wrapRecord(record)); + }; + Ember.addObserver(record, key, handler); + releaseMethods.push(function() { + Ember.removeObserver(record, key, handler); + }); + }); + + var release = function() { + releaseMethods.forEach(function(fn) { fn(); } ); + }; + + return release; + } + + }); + }); +enifed("ember-data/system/debug/debug_info", + ["ember-data/system/model","exports"], + function(__dependency1__, __exports__) { + "use strict"; + var Model = __dependency1__.Model; + + Model.reopen({ + + /** + Provides info about the model for debugging purposes + by grouping the properties into more semantic groups. + + Meant to be used by debugging tools such as the Chrome Ember Extension. + + - Groups all attributes in "Attributes" group. + - Groups all belongsTo relationships in "Belongs To" group. + - Groups all hasMany relationships in "Has Many" group. + - Groups all flags in "Flags" group. + - Flags relationship CPs as expensive properties. + + @method _debugInfo + @for DS.Model + @private + */ + _debugInfo: function() { + var attributes = ['id'], + relationships = { belongsTo: [], hasMany: [] }, + expensiveProperties = []; + + this.eachAttribute(function(name, meta) { + attributes.push(name); + }, this); + + this.eachRelationship(function(name, relationship) { + relationships[relationship.kind].push(name); + expensiveProperties.push(name); + }); + + var groups = [ + { + name: 'Attributes', + properties: attributes, + expand: true + }, + { + name: 'Belongs To', + properties: relationships.belongsTo, + expand: true + }, + { + name: 'Has Many', + properties: relationships.hasMany, + expand: true + }, + { + name: 'Flags', + properties: ['isLoaded', 'isDirty', 'isSaving', 'isDeleted', 'isError', 'isNew', 'isValid'] + } + ]; + + return { + propertyInfo: { + // include all other mixins / properties (not just the grouped ones) + includeOtherProperties: true, + groups: groups, + // don't pre-calculate unless cached + expensiveProperties: expensiveProperties + } + }; + } + }); + + __exports__["default"] = Model; + }); +enifed("ember-data/system/map", + ["exports"], + function(__exports__) { + "use strict"; + /** + * Polyfill Ember.Map behavior for Ember <= 1.7 + * This can probably be removed before 1.0 final + */ + var mapForEach, deleteFn; + + function OrderedSet(){ + Ember.OrderedSet.apply(this, arguments); + } + + function Map() { + Ember.Map.apply(this, arguments); + } + + function MapWithDefault(){ + Ember.MapWithDefault.apply(this, arguments); + } + + var testMap = Ember.Map.create(); + testMap.set('key', 'value'); + + var usesOldBehavior = false; + + testMap.forEach(function(value, key){ + usesOldBehavior = value === 'key' && key === 'value'; + }); + + Map.prototype = Ember.create(Ember.Map.prototype); + MapWithDefault.prototype = Ember.create(Ember.MapWithDefault.prototype); + OrderedSet.prototype = Ember.create(Ember.OrderedSet.prototype); + + OrderedSet.create = function(){ + return new OrderedSet(); + }; + + /** + * returns a function that calls the original + * callback function in the correct order. + * if we are in pre-Ember.1.8 land, Map/MapWithDefault + * forEach calls with key, value, in that order. + * >= 1.8 forEach is called with the order value, key as per + * the ES6 spec. + */ + function translate(valueKeyOrderedCallback){ + return function(key, value){ + valueKeyOrderedCallback.call(this, value, key); + }; + } + + // old, non ES6 compliant behavior + if (usesOldBehavior){ + mapForEach = function(callback, thisArg){ + this.__super$forEach(translate(callback), thisArg); + }; + + /* alias to remove */ + deleteFn = function(thing){ + this.remove(thing); + }; + + Map.prototype.__super$forEach = Ember.Map.prototype.forEach; + Map.prototype.forEach = mapForEach; + Map.prototype["delete"] = deleteFn; + + MapWithDefault.prototype.forEach = mapForEach; + MapWithDefault.prototype.__super$forEach = Ember.MapWithDefault.prototype.forEach; + MapWithDefault.prototype["delete"] = deleteFn; + + OrderedSet.prototype["delete"] = deleteFn; + } + + MapWithDefault.constructor = MapWithDefault; + Map.constructor = Map; + + MapWithDefault.create = function(options){ + if (options) { + return new MapWithDefault(options); + } else { + return new Map(); + } + }; + + Map.create = function(){ + return new this.constructor(); + }; + + __exports__["default"] = Map; + __exports__.Map = Map; + __exports__.MapWithDefault = MapWithDefault; + __exports__.OrderedSet = OrderedSet; + }); +enifed("ember-data/system/model", + ["ember-data/system/model/model","ember-data/system/model/attributes","ember-data/system/model/states","ember-data/system/model/errors","exports"], + function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __exports__) { + "use strict"; + /** + @module ember-data + */ + + var Model = __dependency1__["default"]; + var attr = __dependency2__["default"]; + var RootState = __dependency3__["default"]; + var Errors = __dependency4__["default"]; + + __exports__.Model = Model; + __exports__.RootState = RootState; + __exports__.attr = attr; + __exports__.Errors = Errors; + }); +enifed("ember-data/system/model/attributes", + ["ember-data/system/model/model","ember-data/system/map","exports"], + function(__dependency1__, __dependency2__, __exports__) { + "use strict"; + var Model = __dependency1__["default"]; + var Map = __dependency2__.Map; + + /** + @module ember-data + */ + + var get = Ember.get; + + /** + @class Model + @namespace DS + */ + Model.reopenClass({ + /** + A map whose keys are the attributes of the model (properties + described by DS.attr) and whose values are the meta object for the + property. + + Example + + ```javascript + + App.Person = DS.Model.extend({ + firstName: attr('string'), + lastName: attr('string'), + birthday: attr('date') + }); + + var attributes = Ember.get(App.Person, 'attributes') + + attributes.forEach(function(name, meta) { + console.log(name, meta); + }); + + // prints: + // firstName {type: "string", isAttribute: true, options: Object, parentType: function, name: "firstName"} + // lastName {type: "string", isAttribute: true, options: Object, parentType: function, name: "lastName"} + // birthday {type: "date", isAttribute: true, options: Object, parentType: function, name: "birthday"} + ``` + + @property attributes + @static + @type {Ember.Map} + @readOnly + */ + attributes: Ember.computed(function() { + var map = Map.create(); + + this.eachComputedProperty(function(name, meta) { + if (meta.isAttribute) { + Ember.assert("You may not set `id` as an attribute on your model. Please remove any lines that look like: `id: DS.attr('')` from " + this.toString(), name !== 'id'); + + meta.name = name; + map.set(name, meta); + } + }); + + return map; + }).readOnly(), + + /** + A map whose keys are the attributes of the model (properties + described by DS.attr) and whose values are type of transformation + applied to each attribute. This map does not include any + attributes that do not have an transformation type. + + Example + + ```javascript + App.Person = DS.Model.extend({ + firstName: attr(), + lastName: attr('string'), + birthday: attr('date') + }); + + var transformedAttributes = Ember.get(App.Person, 'transformedAttributes') + + transformedAttributes.forEach(function(field, type) { + console.log(field, type); + }); + + // prints: + // lastName string + // birthday date + ``` + + @property transformedAttributes + @static + @type {Ember.Map} + @readOnly + */ + transformedAttributes: Ember.computed(function() { + var map = Map.create(); + + this.eachAttribute(function(key, meta) { + if (meta.type) { + map.set(key, meta.type); + } + }); + + return map; + }).readOnly(), + + /** + Iterates through the attributes of the model, calling the passed function on each + attribute. + + The callback method you provide should have the following signature (all + parameters are optional): + + ```javascript + function(name, meta); + ``` + + - `name` the name of the current property in the iteration + - `meta` the meta object for the attribute property in the iteration + + Note that in addition to a callback, you can also pass an optional target + object that will be set as `this` on the context. + + Example + + ```javascript + App.Person = DS.Model.extend({ + firstName: attr('string'), + lastName: attr('string'), + birthday: attr('date') + }); + + App.Person.eachAttribute(function(name, meta) { + console.log(name, meta); + }); + + // prints: + // firstName {type: "string", isAttribute: true, options: Object, parentType: function, name: "firstName"} + // lastName {type: "string", isAttribute: true, options: Object, parentType: function, name: "lastName"} + // birthday {type: "date", isAttribute: true, options: Object, parentType: function, name: "birthday"} + ``` + + @method eachAttribute + @param {Function} callback The callback to execute + @param {Object} [target] The target object to use + @static + */ + eachAttribute: function(callback, binding) { + get(this, 'attributes').forEach(function(meta, name) { + callback.call(binding, name, meta); + }, binding); + }, + + /** + Iterates through the transformedAttributes of the model, calling + the passed function on each attribute. Note the callback will not be + called for any attributes that do not have an transformation type. + + The callback method you provide should have the following signature (all + parameters are optional): + + ```javascript + function(name, type); + ``` + + - `name` the name of the current property in the iteration + - `type` a string containing the name of the type of transformed + applied to the attribute + + Note that in addition to a callback, you can also pass an optional target + object that will be set as `this` on the context. + + Example + + ```javascript + App.Person = DS.Model.extend({ + firstName: attr(), + lastName: attr('string'), + birthday: attr('date') + }); + + App.Person.eachTransformedAttribute(function(name, type) { + console.log(name, type); + }); + + // prints: + // lastName string + // birthday date + ``` + + @method eachTransformedAttribute + @param {Function} callback The callback to execute + @param {Object} [target] The target object to use + @static + */ + eachTransformedAttribute: function(callback, binding) { + get(this, 'transformedAttributes').forEach(function(type, name) { + callback.call(binding, name, type); + }); + } + }); + + + Model.reopen({ + eachAttribute: function(callback, binding) { + this.constructor.eachAttribute(callback, binding); + } + }); + + function getDefaultValue(record, options, key) { + if (typeof options.defaultValue === "function") { + return options.defaultValue.apply(null, arguments); + } else { + return options.defaultValue; + } + } + + function hasValue(record, key) { + return record._attributes.hasOwnProperty(key) || + record._inFlightAttributes.hasOwnProperty(key) || + record._data.hasOwnProperty(key); + } + + function getValue(record, key) { + if (record._attributes.hasOwnProperty(key)) { + return record._attributes[key]; + } else if (record._inFlightAttributes.hasOwnProperty(key)) { + return record._inFlightAttributes[key]; + } else { + return record._data[key]; + } + } + + /** + `DS.attr` defines an attribute on a [DS.Model](/api/data/classes/DS.Model.html). + By default, attributes are passed through as-is, however you can specify an + optional type to have the value automatically transformed. + Ember Data ships with four basic transform types: `string`, `number`, + `boolean` and `date`. You can define your own transforms by subclassing + [DS.Transform](/api/data/classes/DS.Transform.html). + + Note that you cannot use `attr` to define an attribute of `id`. + + `DS.attr` takes an optional hash as a second parameter, currently + supported options are: + + - `defaultValue`: Pass a string or a function to be called to set the attribute + to a default value if none is supplied. + + Example + + ```javascript + var attr = DS.attr; + + App.User = DS.Model.extend({ + username: attr('string'), + email: attr('string'), + verified: attr('boolean', {defaultValue: false}) + }); + ``` + + @namespace + @method attr + @for DS + @param {String} type the attribute type + @param {Object} options a hash of options + @return {Attribute} + */ + + __exports__["default"] = function attr(type, options) { + options = options || {}; + + var meta = { + type: type, + isAttribute: true, + options: options + }; + + return Ember.computed(function(key, value) { + if (arguments.length > 1) { + Ember.assert("You may not set `id` as an attribute on your model. Please remove any lines that look like: `id: DS.attr('')` from " + this.constructor.toString(), key !== 'id'); + var oldValue = getValue(this, key); + + if (value !== oldValue) { + // Add the new value to the changed attributes hash; it will get deleted by + // the 'didSetProperty' handler if it is no different from the original value + this._attributes[key] = value; + + this.send('didSetProperty', { + name: key, + oldValue: oldValue, + originalValue: this._data[key], + value: value + }); + } + + return value; + } else if (hasValue(this, key)) { + return getValue(this, key); + } else { + return getDefaultValue(this, options, key); + } + + // `data` is never set directly. However, it may be + // invalidated from the state manager's setData + // event. + }).meta(meta); + }; + }); +enifed("ember-data/system/model/errors", + ["ember-data/system/map","exports"], + function(__dependency1__, __exports__) { + "use strict"; + var get = Ember.get; + var isEmpty = Ember.isEmpty; + var map = Ember.EnumerableUtils.map; + + var MapWithDefault = __dependency1__.MapWithDefault; + + /** + @module ember-data + */ + + /** + Holds validation errors for a given record organized by attribute names. + + Every DS.Model has an `errors` property that is an instance of + `DS.Errors`. This can be used to display validation error + messages returned from the server when a `record.save()` rejects. + This works automatically with `DS.ActiveModelAdapter`, but you + can implement [ajaxError](/api/data/classes/DS.RESTAdapter.html#method_ajaxError) + in other adapters as well. + + For Example, if you had an `User` model that looked like this: + + ```javascript + App.User = DS.Model.extend({ + username: attr('string'), + email: attr('string') + }); + ``` + And you attempted to save a record that did not validate on the backend. + + ```javascript + var user = store.createRecord('user', { + username: 'tomster', + email: 'invalidEmail' + }); + user.save(); + ``` + + Your backend data store might return a response that looks like + this. This response will be used to populate the error object. + + ```javascript + { + "errors": { + "username": ["This username is already taken!"], + "email": ["Doesn't look like a valid email."] + } + } + ``` + + Errors can be displayed to the user by accessing their property name + or using the `messages` property to get an array of all errors. + + ```handlebars + {{#each errors.messages}} +
+ {{message}} +
+ {{/each}} + + + {{#each errors.username}} +
+ {{message}} +
+ {{/each}} + + + {{#each errors.email}} +
+ {{message}} +
+ {{/each}} + ``` + + @class Errors + @namespace DS + @extends Ember.Object + @uses Ember.Enumerable + @uses Ember.Evented + */ + __exports__["default"] = Ember.Object.extend(Ember.Enumerable, Ember.Evented, { + /** + Register with target handler + + @method registerHandlers + @param {Object} target + @param {Function} becameInvalid + @param {Function} becameValid + */ + registerHandlers: function(target, becameInvalid, becameValid) { + this.on('becameInvalid', target, becameInvalid); + this.on('becameValid', target, becameValid); + }, + + /** + @property errorsByAttributeName + @type {Ember.MapWithDefault} + @private + */ + errorsByAttributeName: Ember.reduceComputed("content", { + initialValue: function() { + return MapWithDefault.create({ + defaultValue: function() { + return Ember.A(); + } + }); + }, + + addedItem: function(errors, error) { + errors.get(error.attribute).pushObject(error); + + return errors; + }, + + removedItem: function(errors, error) { + errors.get(error.attribute).removeObject(error); + + return errors; + } + }), + + /** + Returns errors for a given attribute + + ```javascript + var user = store.createRecord('user', { + username: 'tomster', + email: 'invalidEmail' + }); + user.save().catch(function(){ + user.get('errors').errorsFor('email'); // ["Doesn't look like a valid email."] + }); + ``` + + @method errorsFor + @param {String} attribute + @return {Array} + */ + errorsFor: function(attribute) { + return get(this, 'errorsByAttributeName').get(attribute); + }, + + /** + An array containing all of the error messages for this + record. This is useful for displaying all errors to the user. + + ```handlebars + {{#each errors.messages}} +
+ {{message}} +
+ {{/each}} + ``` + + @property messages + @type {Array} + */ + messages: Ember.computed.mapBy('content', 'message'), + + /** + @property content + @type {Array} + @private + */ + content: Ember.computed(function() { + return Ember.A(); + }), + + /** + @method unknownProperty + @private + */ + unknownProperty: function(attribute) { + var errors = this.errorsFor(attribute); + if (isEmpty(errors)) { return null; } + return errors; + }, + + /** + @method nextObject + @private + */ + nextObject: function(index, previousObject, context) { + return get(this, 'content').objectAt(index); + }, + + /** + Total number of errors. + + @property length + @type {Number} + @readOnly + */ + length: Ember.computed.oneWay('content.length').readOnly(), + + /** + @property isEmpty + @type {Boolean} + @readOnly + */ + isEmpty: Ember.computed.not('length').readOnly(), + + /** + Adds error messages to a given attribute and sends + `becameInvalid` event to the record. + + Example: + + ```javascript + if (!user.get('username') { + user.get('errors').add('username', 'This field is required'); + } + ``` + + @method add + @param {String} attribute + @param {Array|String} messages + */ + add: function(attribute, messages) { + var wasEmpty = get(this, 'isEmpty'); + + messages = this._findOrCreateMessages(attribute, messages); + get(this, 'content').addObjects(messages); + + this.notifyPropertyChange(attribute); + this.enumerableContentDidChange(); + + if (wasEmpty && !get(this, 'isEmpty')) { + this.trigger('becameInvalid'); + } + }, + + /** + @method _findOrCreateMessages + @private + */ + _findOrCreateMessages: function(attribute, messages) { + var errors = this.errorsFor(attribute); + + return map(Ember.makeArray(messages), function(message) { + return errors.findBy('message', message) || { + attribute: attribute, + message: message + }; + }); + }, + + /** + Removes all error messages from the given attribute and sends + `becameValid` event to the record if there no more errors left. + + Example: + + ```javascript + App.User = DS.Model.extend({ + email: DS.attr('string'), + twoFactorAuth: DS.attr('boolean'), + phone: DS.attr('string') + }); + + App.UserEditRoute = Ember.Route.extend({ + actions: { + save: function(user) { + if (!user.get('twoFactorAuth')) { + user.get('errors').remove('phone'); + } + user.save(); + } + } + }); + ``` + + @method remove + @param {String} attribute + */ + remove: function(attribute) { + if (get(this, 'isEmpty')) { return; } + + var content = get(this, 'content').rejectBy('attribute', attribute); + get(this, 'content').setObjects(content); + + this.notifyPropertyChange(attribute); + this.enumerableContentDidChange(); + + if (get(this, 'isEmpty')) { + this.trigger('becameValid'); + } + }, + + /** + Removes all error messages and sends `becameValid` event + to the record. + + Example: + + ```javascript + App.UserEditRoute = Ember.Route.extend({ + actions: { + retrySave: function(user) { + user.get('errors').clear(); + user.save(); + } + } + }); + ``` + + @method clear + */ + clear: function() { + if (get(this, 'isEmpty')) { return; } + + get(this, 'content').clear(); + this.enumerableContentDidChange(); + + this.trigger('becameValid'); + }, + + /** + Checks if there is error messages for the given attribute. + + ```javascript + App.UserEditRoute = Ember.Route.extend({ + actions: { + save: function(user) { + if (user.get('errors').has('email')) { + return alert('Please update your email before attempting to save.'); + } + user.save(); + } + } + }); + ``` + + @method has + @param {String} attribute + @return {Boolean} true if there some errors on given attribute + */ + has: function(attribute) { + return !isEmpty(this.errorsFor(attribute)); + } + }); + }); +enifed("ember-data/system/model/model", + ["ember-data/system/model/states","ember-data/system/model/errors","ember-data/system/promise_proxies","ember-data/system/relationships/relationship","exports"], + function(__dependency1__, __dependency2__, __dependency3__, __dependency4__, __exports__) { + "use strict"; + var RootState = __dependency1__["default"]; + var Errors = __dependency2__["default"]; + var PromiseObject = __dependency3__.PromiseObject; + var createRelationshipFor = __dependency4__.createRelationshipFor; + + /** + @module ember-data + */ + + var get = Ember.get; + var set = Ember.set; + var merge = Ember.merge; + var Promise = Ember.RSVP.Promise; + var forEach = Ember.ArrayPolyfills.forEach; + var map = Ember.ArrayPolyfills.map; + + var JSONSerializer; + var retrieveFromCurrentState = Ember.computed('currentState', function(key, value) { + return get(get(this, 'currentState'), key); + }).readOnly(); + + var _extractPivotNameCache = Ember.create(null); + var _splitOnDotCache = Ember.create(null); + + function splitOnDot(name) { + return _splitOnDotCache[name] || ( + _splitOnDotCache[name] = name.split('.') + ); + } + + function extractPivotName(name) { + return _extractPivotNameCache[name] || ( + _extractPivotNameCache[name] = splitOnDot(name)[0] + ); + } + + /** + + The model class that all Ember Data records descend from. + + @class Model + @namespace DS + @extends Ember.Object + @uses Ember.Evented + */ + var Model = Ember.Object.extend(Ember.Evented, { + _recordArrays: undefined, + _relationships: undefined, + _loadingRecordArrays: undefined, + /** + If this property is `true` the record is in the `empty` + state. Empty is the first state all records enter after they have + been created. Most records created by the store will quickly + transition to the `loading` state if data needs to be fetched from + the server or the `created` state if the record is created on the + client. A record can also enter the empty state if the adapter is + unable to locate the record. + + @property isEmpty + @type {Boolean} + @readOnly + */ + isEmpty: retrieveFromCurrentState, + /** + If this property is `true` the record is in the `loading` state. A + record enters this state when the store asks the adapter for its + data. It remains in this state until the adapter provides the + requested data. + + @property isLoading + @type {Boolean} + @readOnly + */ + isLoading: retrieveFromCurrentState, + /** + If this property is `true` the record is in the `loaded` state. A + record enters this state when its data is populated. Most of a + record's lifecycle is spent inside substates of the `loaded` + state. + + Example + + ```javascript + var record = store.createRecord('model'); + record.get('isLoaded'); // true + + store.find('model', 1).then(function(model) { + model.get('isLoaded'); // true + }); + ``` + + @property isLoaded + @type {Boolean} + @readOnly + */ + isLoaded: retrieveFromCurrentState, + /** + If this property is `true` the record is in the `dirty` state. The + record has local changes that have not yet been saved by the + adapter. This includes records that have been created (but not yet + saved) or deleted. + + Example + + ```javascript + var record = store.createRecord('model'); + record.get('isDirty'); // true + + store.find('model', 1).then(function(model) { + model.get('isDirty'); // false + model.set('foo', 'some value'); + model.get('isDirty'); // true + }); + ``` + + @property isDirty + @type {Boolean} + @readOnly + */ + isDirty: retrieveFromCurrentState, + /** + If this property is `true` the record is in the `saving` state. A + record enters the saving state when `save` is called, but the + adapter has not yet acknowledged that the changes have been + persisted to the backend. + + Example + + ```javascript + var record = store.createRecord('model'); + record.get('isSaving'); // false + var promise = record.save(); + record.get('isSaving'); // true + promise.then(function() { + record.get('isSaving'); // false + }); + ``` + + @property isSaving + @type {Boolean} + @readOnly + */ + isSaving: retrieveFromCurrentState, + /** + If this property is `true` the record is in the `deleted` state + and has been marked for deletion. When `isDeleted` is true and + `isDirty` is true, the record is deleted locally but the deletion + was not yet persisted. When `isSaving` is true, the change is + in-flight. When both `isDirty` and `isSaving` are false, the + change has persisted. + + Example + + ```javascript + var record = store.createRecord('model'); + record.get('isDeleted'); // false + record.deleteRecord(); + + // Locally deleted + record.get('isDeleted'); // true + record.get('isDirty'); // true + record.get('isSaving'); // false + + // Persisting the deletion + var promise = record.save(); + record.get('isDeleted'); // true + record.get('isSaving'); // true + + // Deletion Persisted + promise.then(function() { + record.get('isDeleted'); // true + record.get('isSaving'); // false + record.get('isDirty'); // false + }); + ``` + + @property isDeleted + @type {Boolean} + @readOnly + */ + isDeleted: retrieveFromCurrentState, + /** + If this property is `true` the record is in the `new` state. A + record will be in the `new` state when it has been created on the + client and the adapter has not yet report that it was successfully + saved. + + Example + + ```javascript + var record = store.createRecord('model'); + record.get('isNew'); // true + + record.save().then(function(model) { + model.get('isNew'); // false + }); + ``` + + @property isNew + @type {Boolean} + @readOnly + */ + isNew: retrieveFromCurrentState, + /** + If this property is `true` the record is in the `valid` state. + + A record will be in the `valid` state when the adapter did not report any + server-side validation failures. + + @property isValid + @type {Boolean} + @readOnly + */ + isValid: retrieveFromCurrentState, + /** + If the record is in the dirty state this property will report what + kind of change has caused it to move into the dirty + state. Possible values are: + + - `created` The record has been created by the client and not yet saved to the adapter. + - `updated` The record has been updated by the client and not yet saved to the adapter. + - `deleted` The record has been deleted by the client and not yet saved to the adapter. + + Example + + ```javascript + var record = store.createRecord('model'); + record.get('dirtyType'); // 'created' + ``` + + @property dirtyType + @type {String} + @readOnly + */ + dirtyType: retrieveFromCurrentState, + + /** + If `true` the adapter reported that it was unable to save local + changes to the backend for any reason other than a server-side + validation error. + + Example + + ```javascript + record.get('isError'); // false + record.set('foo', 'valid value'); + record.save().then(null, function() { + record.get('isError'); // true + }); + ``` + + @property isError + @type {Boolean} + @readOnly + */ + isError: false, + /** + If `true` the store is attempting to reload the record form the adapter. + + Example + + ```javascript + record.get('isReloading'); // false + record.reload(); + record.get('isReloading'); // true + ``` + + @property isReloading + @type {Boolean} + @readOnly + */ + isReloading: false, + + /** + The `clientId` property is a transient numerical identifier + generated at runtime by the data store. It is important + primarily because newly created objects may not yet have an + externally generated id. + + @property clientId + @private + @type {Number|String} + */ + clientId: null, + /** + All ember models have an id property. This is an identifier + managed by an external source. These are always coerced to be + strings before being used internally. Note when declaring the + attributes for a model it is an error to declare an id + attribute. + + ```javascript + var record = store.createRecord('model'); + record.get('id'); // null + + store.find('model', 1).then(function(model) { + model.get('id'); // '1' + }); + ``` + + @property id + @type {String} + */ + id: null, + + /** + @property currentState + @private + @type {Object} + */ + currentState: RootState.empty, + + /** + When the record is in the `invalid` state this object will contain + any errors returned by the adapter. When present the errors hash + typically contains keys corresponding to the invalid property names + and values which are an array of error messages. + + ```javascript + record.get('errors.length'); // 0 + record.set('foo', 'invalid value'); + record.save().then(null, function() { + record.get('errors').get('foo'); // ['foo should be a number.'] + }); + ``` + + @property errors + @type {DS.Errors} + */ + errors: Ember.computed(function() { + var errors = Errors.create(); + + errors.registerHandlers(this, function() { + this.send('becameInvalid'); + }, function() { + this.send('becameValid'); + }); + + return errors; + }).readOnly(), + + /** + Create a JSON representation of the record, using the serialization + strategy of the store's adapter. + + `serialize` takes an optional hash as a parameter, currently + supported options are: + + - `includeId`: `true` if the record's ID should be included in the + JSON representation. + + @method serialize + @param {Object} options + @return {Object} an object whose values are primitive JSON values only + */ + serialize: function(options) { + var store = get(this, 'store'); + return store.serialize(this, options); + }, + + /** + Use [DS.JSONSerializer](DS.JSONSerializer.html) to + get the JSON representation of a record. + + `toJSON` takes an optional hash as a parameter, currently + supported options are: + + - `includeId`: `true` if the record's ID should be included in the + JSON representation. + + @method toJSON + @param {Object} options + @return {Object} A JSON representation of the object. + */ + toJSON: function(options) { + if (!JSONSerializer) { JSONSerializer = requireModule("ember-data/serializers/json_serializer")["default"]; } + // container is for lazy transform lookups + var serializer = JSONSerializer.create({ container: this.container }); + return serializer.serialize(this, options); + }, + + /** + Fired when the record is loaded from the server. + + @event didLoad + */ + didLoad: Ember.K, + + /** + Fired when the record is updated. + + @event didUpdate + */ + didUpdate: Ember.K, + + /** + Fired when the record is created. + + @event didCreate + */ + didCreate: Ember.K, + + /** + Fired when the record is deleted. + + @event didDelete + */ + didDelete: Ember.K, + + /** + Fired when the record becomes invalid. + + @event becameInvalid + */ + becameInvalid: Ember.K, + + /** + Fired when the record enters the error state. + + @event becameError + */ + becameError: Ember.K, + + /** + @property data + @private + @type {Object} + */ + data: Ember.computed(function() { + this._data = this._data || {}; + return this._data; + }).readOnly(), + + _data: null, + + init: function() { + this._super(); + this._setup(); + }, + + _setup: function() { + this._changesToSync = {}; + this._deferredTriggers = []; + this._data = {}; + this._attributes = {}; + this._inFlightAttributes = {}; + this._relationships = {}; + /* + implicit relationships are relationship which have not been declared but the inverse side exists on + another record somewhere + For example if there was + ``` + App.Comment = DS.Model.extend({ + name: DS.attr() + }) + ``` + but there is also + ``` + App.Post = DS.Model.extend({ + name: DS.attr(), + comments: DS.hasMany('comment') + }) + ``` + + would have a implicit post relationship in order to be do things like remove ourselves from the post + when we are deleted + */ + this._implicitRelationships = Ember.create(null); + var model = this; + //TODO Move into a getter for better perf + this.constructor.eachRelationship(function(key, descriptor) { + model._relationships[key] = createRelationshipFor(model, descriptor, model.store); + }); + + }, + + /** + @method send + @private + @param {String} name + @param {Object} context + */ + send: function(name, context) { + var currentState = get(this, 'currentState'); + + if (!currentState[name]) { + this._unhandledEvent(currentState, name, context); + } + + return currentState[name](this, context); + }, + + /** + @method transitionTo + @private + @param {String} name + */ + transitionTo: function(name) { + // POSSIBLE TODO: Remove this code and replace with + // always having direct references to state objects + + var pivotName = extractPivotName(name); + var currentState = get(this, 'currentState'); + var state = currentState; + + do { + if (state.exit) { state.exit(this); } + state = state.parentState; + } while (!state.hasOwnProperty(pivotName)); + + var path = splitOnDot(name); + var setups = [], enters = [], i, l; + + for (i=0, l=path.length; i "root.created.uncommitted" + ``` + + The hierarchy of valid states that ship with ember data looks like + this: + + ```text + * root + * deleted + * saved + * uncommitted + * inFlight + * empty + * loaded + * created + * uncommitted + * inFlight + * saved + * updated + * uncommitted + * inFlight + * loading + ``` + + The `DS.Model` states are themselves stateless. What that means is + that, the hierarchical states that each of *those* points to is a + shared data structure. For performance reasons, instead of each + record getting its own copy of the hierarchy of states, each record + points to this global, immutable shared instance. How does a state + know which record it should be acting on? We pass the record + instance into the state's event handlers as the first argument. + + The record passed as the first parameter is where you should stash + state about the record if needed; you should never store data on the state + object itself. + + ### Events and Flags + + A state may implement zero or more events and flags. + + #### Events + + Events are named functions that are invoked when sent to a record. The + record will first look for a method with the given name on the + current state. If no method is found, it will search the current + state's parent, and then its grandparent, and so on until reaching + the top of the hierarchy. If the root is reached without an event + handler being found, an exception will be raised. This can be very + helpful when debugging new features. + + Here's an example implementation of a state with a `myEvent` event handler: + + ```javascript + aState: DS.State.create({ + myEvent: function(manager, param) { + console.log("Received myEvent with", param); + } + }) + ``` + + To trigger this event: + + ```javascript + record.send('myEvent', 'foo'); + //=> "Received myEvent with foo" + ``` + + Note that an optional parameter can be sent to a record's `send()` method, + which will be passed as the second parameter to the event handler. + + Events should transition to a different state if appropriate. This can be + done by calling the record's `transitionTo()` method with a path to the + desired state. The state manager will attempt to resolve the state path + relative to the current state. If no state is found at that path, it will + attempt to resolve it relative to the current state's parent, and then its + parent, and so on until the root is reached. For example, imagine a hierarchy + like this: + + * created + * uncommitted <-- currentState + * inFlight + * updated + * inFlight + + If we are currently in the `uncommitted` state, calling + `transitionTo('inFlight')` would transition to the `created.inFlight` state, + while calling `transitionTo('updated.inFlight')` would transition to + the `updated.inFlight` state. + + Remember that *only events* should ever cause a state transition. You should + never call `transitionTo()` from outside a state's event handler. If you are + tempted to do so, create a new event and send that to the state manager. + + #### Flags + + Flags are Boolean values that can be used to introspect a record's current + state in a more user-friendly way than examining its state path. For example, + instead of doing this: + + ```javascript + var statePath = record.get('stateManager.currentPath'); + if (statePath === 'created.inFlight') { + doSomething(); + } + ``` + + You can say: + + ```javascript + if (record.get('isNew') && record.get('isSaving')) { + doSomething(); + } + ``` + + If your state does not set a value for a given flag, the value will + be inherited from its parent (or the first place in the state hierarchy + where it is defined). + + The current set of flags are defined below. If you want to add a new flag, + in addition to the area below, you will also need to declare it in the + `DS.Model` class. + + + * [isEmpty](DS.Model.html#property_isEmpty) + * [isLoading](DS.Model.html#property_isLoading) + * [isLoaded](DS.Model.html#property_isLoaded) + * [isDirty](DS.Model.html#property_isDirty) + * [isSaving](DS.Model.html#property_isSaving) + * [isDeleted](DS.Model.html#property_isDeleted) + * [isNew](DS.Model.html#property_isNew) + * [isValid](DS.Model.html#property_isValid) + + @namespace DS + @class RootState + */ + + function didSetProperty(record, context) { + if (context.value === context.originalValue) { + delete record._attributes[context.name]; + record.send('propertyWasReset', context.name); + } else if (context.value !== context.oldValue) { + record.send('becomeDirty'); + } + + record.updateRecordArraysLater(); + } + + // Implementation notes: + // + // Each state has a boolean value for all of the following flags: + // + // * isLoaded: The record has a populated `data` property. When a + // record is loaded via `store.find`, `isLoaded` is false + // until the adapter sets it. When a record is created locally, + // its `isLoaded` property is always true. + // * isDirty: The record has local changes that have not yet been + // saved by the adapter. This includes records that have been + // created (but not yet saved) or deleted. + // * isSaving: The record has been committed, but + // the adapter has not yet acknowledged that the changes have + // been persisted to the backend. + // * isDeleted: The record was marked for deletion. When `isDeleted` + // is true and `isDirty` is true, the record is deleted locally + // but the deletion was not yet persisted. When `isSaving` is + // true, the change is in-flight. When both `isDirty` and + // `isSaving` are false, the change has persisted. + // * isError: The adapter reported that it was unable to save + // local changes to the backend. This may also result in the + // record having its `isValid` property become false if the + // adapter reported that server-side validations failed. + // * isNew: The record was created on the client and the adapter + // did not yet report that it was successfully saved. + // * isValid: The adapter did not report any server-side validation + // failures. + + // The dirty state is a abstract state whose functionality is + // shared between the `created` and `updated` states. + // + // The deleted state shares the `isDirty` flag with the + // subclasses of `DirtyState`, but with a very different + // implementation. + // + // Dirty states have three child states: + // + // `uncommitted`: the store has not yet handed off the record + // to be saved. + // `inFlight`: the store has handed off the record to be saved, + // but the adapter has not yet acknowledged success. + // `invalid`: the record has invalid information and cannot be + // send to the adapter yet. + var DirtyState = { + initialState: 'uncommitted', + + // FLAGS + isDirty: true, + + // SUBSTATES + + // When a record first becomes dirty, it is `uncommitted`. + // This means that there are local pending changes, but they + // have not yet begun to be saved, and are not invalid. + uncommitted: { + // EVENTS + didSetProperty: didSetProperty, + + //TODO(Igor) reloading now triggers a + //loadingData event, though it seems fine? + loadingData: Ember.K, + + propertyWasReset: function(record, name) { + var length = Ember.keys(record._attributes); + var stillDirty = length > 0; + + if (!stillDirty) { record.send('rolledBack'); } + }, + + pushedData: Ember.K, + + becomeDirty: Ember.K, + + willCommit: function(record) { + record.transitionTo('inFlight'); + }, + + reloadRecord: function(record, resolve) { + resolve(get(record, 'store').reloadRecord(record)); + }, + + rolledBack: function(record) { + record.transitionTo('loaded.saved'); + }, + + becameInvalid: function(record) { + record.transitionTo('invalid'); + }, + + rollback: function(record) { + record.rollback(); + } + }, + + // Once a record has been handed off to the adapter to be + // saved, it is in the 'in flight' state. Changes to the + // record cannot be made during this window. + inFlight: { + // FLAGS + isSaving: true, + + // EVENTS + didSetProperty: didSetProperty, + becomeDirty: Ember.K, + pushedData: Ember.K, + + unloadRecord: function(record) { + Ember.assert("You can only unload a record which is not inFlight. `" + Ember.inspect(record) + " `", false); + }, + + // TODO: More robust semantics around save-while-in-flight + willCommit: Ember.K, + + didCommit: function(record) { + var dirtyType = get(this, 'dirtyType'); + + record.transitionTo('saved'); + record.send('invokeLifecycleCallbacks', dirtyType); + }, + + becameInvalid: function(record) { + record.transitionTo('invalid'); + record.send('invokeLifecycleCallbacks'); + }, + + becameError: function(record) { + record.transitionTo('uncommitted'); + record.triggerLater('becameError', record); + } + }, + + // A record is in the `invalid` if the adapter has indicated + // the the record failed server-side invalidations. + invalid: { + // FLAGS + isValid: false, + + // EVENTS + deleteRecord: function(record) { + record.transitionTo('deleted.uncommitted'); + record.disconnectRelationships(); + }, + + didSetProperty: function(record, context) { + get(record, 'errors').remove(context.name); + + didSetProperty(record, context); + }, + + becomeDirty: Ember.K, + + willCommit: function(record) { + get(record, 'errors').clear(); + record.transitionTo('inFlight'); + }, + + rolledBack: function(record) { + get(record, 'errors').clear(); + }, + + becameValid: function(record) { + record.transitionTo('uncommitted'); + }, + + invokeLifecycleCallbacks: function(record) { + record.triggerLater('becameInvalid', record); + }, + + exit: function(record) { + record._inFlightAttributes = {}; + } + } + }; + + // The created and updated states are created outside the state + // chart so we can reopen their substates and add mixins as + // necessary. + + function deepClone(object) { + var clone = {}, value; + + for (var prop in object) { + value = object[prop]; + if (value && typeof value === 'object') { + clone[prop] = deepClone(value); + } else { + clone[prop] = value; + } + } + + return clone; + } + + function mixin(original, hash) { + for (var prop in hash) { + original[prop] = hash[prop]; + } + + return original; + } + + function dirtyState(options) { + var newState = deepClone(DirtyState); + return mixin(newState, options); + } + + var createdState = dirtyState({ + dirtyType: 'created', + // FLAGS + isNew: true + }); + + createdState.uncommitted.rolledBack = function(record) { + record.transitionTo('deleted.saved'); + }; + + var updatedState = dirtyState({ + dirtyType: 'updated' + }); + + createdState.uncommitted.deleteRecord = function(record) { + record.disconnectRelationships(); + record.transitionTo('deleted.saved'); + }; + + createdState.uncommitted.rollback = function(record) { + DirtyState.uncommitted.rollback.apply(this, arguments); + record.transitionTo('deleted.saved'); + }; + + createdState.uncommitted.propertyWasReset = Ember.K; + + function assertAgainstUnloadRecord(record) { + Ember.assert("You can only unload a record which is not inFlight. `" + Ember.inspect(record) + "`", false); + } + + updatedState.inFlight.unloadRecord = assertAgainstUnloadRecord; + + updatedState.uncommitted.deleteRecord = function(record) { + record.transitionTo('deleted.uncommitted'); + record.disconnectRelationships(); + }; + + var RootState = { + // FLAGS + isEmpty: false, + isLoading: false, + isLoaded: false, + isDirty: false, + isSaving: false, + isDeleted: false, + isNew: false, + isValid: true, + + // DEFAULT EVENTS + + // Trying to roll back if you're not in the dirty state + // doesn't change your state. For example, if you're in the + // in-flight state, rolling back the record doesn't move + // you out of the in-flight state. + rolledBack: Ember.K, + unloadRecord: function(record) { + // clear relationships before moving to deleted state + // otherwise it fails + record.clearRelationships(); + record.transitionTo('deleted.saved'); + }, + + + propertyWasReset: Ember.K, + + // SUBSTATES + + // A record begins its lifecycle in the `empty` state. + // If its data will come from the adapter, it will + // transition into the `loading` state. Otherwise, if + // the record is being created on the client, it will + // transition into the `created` state. + empty: { + isEmpty: true, + + // EVENTS + loadingData: function(record, promise) { + record._loadingPromise = promise; + record.transitionTo('loading'); + }, + + loadedData: function(record) { + record.transitionTo('loaded.created.uncommitted'); + record.notifyPropertyChange('data'); + }, + + pushedData: function(record) { + record.transitionTo('loaded.saved'); + record.triggerLater('didLoad'); + } + }, + + // A record enters this state when the store asks + // the adapter for its data. It remains in this state + // until the adapter provides the requested data. + // + // Usually, this process is asynchronous, using an + // XHR to retrieve the data. + loading: { + // FLAGS + isLoading: true, + + exit: function(record) { + record._loadingPromise = null; + }, + + // EVENTS + pushedData: function(record) { + record.transitionTo('loaded.saved'); + record.triggerLater('didLoad'); + set(record, 'isError', false); + }, + + becameError: function(record) { + record.triggerLater('becameError', record); + }, + + notFound: function(record) { + record.transitionTo('empty'); + } + }, + + // A record enters this state when its data is populated. + // Most of a record's lifecycle is spent inside substates + // of the `loaded` state. + loaded: { + initialState: 'saved', + + // FLAGS + isLoaded: true, + + //TODO(Igor) Reloading now triggers a loadingData event, + //but it should be ok? + loadingData: Ember.K, + + // SUBSTATES + + // If there are no local changes to a record, it remains + // in the `saved` state. + saved: { + setup: function(record) { + var attrs = record._attributes; + var isDirty = false; + + for (var prop in attrs) { + if (attrs.hasOwnProperty(prop)) { + isDirty = true; + break; + } + } + + if (isDirty) { + record.adapterDidDirty(); + } + }, + + // EVENTS + didSetProperty: didSetProperty, + + pushedData: Ember.K, + + becomeDirty: function(record) { + record.transitionTo('updated.uncommitted'); + }, + + willCommit: function(record) { + record.transitionTo('updated.inFlight'); + }, + + reloadRecord: function(record, resolve) { + resolve(get(record, 'store').reloadRecord(record)); + }, + + deleteRecord: function(record) { + record.transitionTo('deleted.uncommitted'); + record.disconnectRelationships(); + }, + + unloadRecord: function(record) { + // clear relationships before moving to deleted state + // otherwise it fails + record.clearRelationships(); + record.transitionTo('deleted.saved'); + }, + + didCommit: function(record) { + record.send('invokeLifecycleCallbacks', get(record, 'lastDirtyType')); + }, + + // loaded.saved.notFound would be triggered by a failed + // `reload()` on an unchanged record + notFound: Ember.K + + }, + + // A record is in this state after it has been locally + // created but before the adapter has indicated that + // it has been saved. + created: createdState, + + // A record is in this state if it has already been + // saved to the server, but there are new local changes + // that have not yet been saved. + updated: updatedState + }, + + // A record is in this state if it was deleted from the store. + deleted: { + initialState: 'uncommitted', + dirtyType: 'deleted', + + // FLAGS + isDeleted: true, + isLoaded: true, + isDirty: true, + + // TRANSITIONS + setup: function(record) { + record.updateRecordArrays(); + }, + + // SUBSTATES + + // When a record is deleted, it enters the `start` + // state. It will exit this state when the record + // starts to commit. + uncommitted: { + + // EVENTS + + willCommit: function(record) { + record.transitionTo('inFlight'); + }, + + rollback: function(record) { + record.rollback(); + }, + + becomeDirty: Ember.K, + deleteRecord: Ember.K, + + rolledBack: function(record) { + record.transitionTo('loaded.saved'); + } + }, + + // After a record starts committing, but + // before the adapter indicates that the deletion + // has saved to the server, a record is in the + // `inFlight` substate of `deleted`. + inFlight: { + // FLAGS + isSaving: true, + + // EVENTS + + unloadRecord: assertAgainstUnloadRecord, + + // TODO: More robust semantics around save-while-in-flight + willCommit: Ember.K, + didCommit: function(record) { + record.transitionTo('saved'); + + record.send('invokeLifecycleCallbacks'); + }, + + becameError: function(record) { + record.transitionTo('uncommitted'); + record.triggerLater('becameError', record); + } + }, + + // Once the adapter indicates that the deletion has + // been saved, the record enters the `saved` substate + // of `deleted`. + saved: { + // FLAGS + isDirty: false, + + setup: function(record) { + var store = get(record, 'store'); + store.dematerializeRecord(record); + }, + + invokeLifecycleCallbacks: function(record) { + record.triggerLater('didDelete', record); + record.triggerLater('didCommit', record); + }, + + willCommit: Ember.K, + + didCommit: Ember.K + } + }, + + invokeLifecycleCallbacks: function(record, dirtyType) { + if (dirtyType === 'created') { + record.triggerLater('didCreate', record); + } else { + record.triggerLater('didUpdate', record); + } + + record.triggerLater('didCommit', record); + } + }; + + function wireState(object, parent, name) { + /*jshint proto:true*/ + // TODO: Use Object.create and copy instead + object = mixin(parent ? Ember.create(parent) : {}, object); + object.parentState = parent; + object.stateName = name; + + for (var prop in object) { + if (!object.hasOwnProperty(prop) || prop === 'parentState' || prop === 'stateName') { continue; } + if (typeof object[prop] === 'object') { + object[prop] = wireState(object[prop], object, name + "." + prop); + } + } + + return object; + } + + RootState = wireState(RootState, null, "root"); + + __exports__["default"] = RootState; + }); +enifed("ember-data/system/promise_proxies", + ["exports"], + function(__exports__) { + "use strict"; + var Promise = Ember.RSVP.Promise; + var get = Ember.get; + + /** + A `PromiseArray` is an object that acts like both an `Ember.Array` + and a promise. When the promise is resolved the resulting value + will be set to the `PromiseArray`'s `content` property. This makes + it easy to create data bindings with the `PromiseArray` that will be + updated when the promise resolves. + + For more information see the [Ember.PromiseProxyMixin + documentation](/api/classes/Ember.PromiseProxyMixin.html). + + Example + + ```javascript + var promiseArray = DS.PromiseArray.create({ + promise: $.getJSON('/some/remote/data.json') + }); + + promiseArray.get('length'); // 0 + + promiseArray.then(function() { + promiseArray.get('length'); // 100 + }); + ``` + + @class PromiseArray + @namespace DS + @extends Ember.ArrayProxy + @uses Ember.PromiseProxyMixin + */ + var PromiseArray = Ember.ArrayProxy.extend(Ember.PromiseProxyMixin); + + /** + A `PromiseObject` is an object that acts like both an `Ember.Object` + and a promise. When the promise is resolved, then the resulting value + will be set to the `PromiseObject`'s `content` property. This makes + it easy to create data bindings with the `PromiseObject` that will + be updated when the promise resolves. + + For more information see the [Ember.PromiseProxyMixin + documentation](/api/classes/Ember.PromiseProxyMixin.html). + + Example + + ```javascript + var promiseObject = DS.PromiseObject.create({ + promise: $.getJSON('/some/remote/data.json') + }); + + promiseObject.get('name'); // null + + promiseObject.then(function() { + promiseObject.get('name'); // 'Tomster' + }); + ``` + + @class PromiseObject + @namespace DS + @extends Ember.ObjectProxy + @uses Ember.PromiseProxyMixin + */ + var PromiseObject = Ember.ObjectProxy.extend(Ember.PromiseProxyMixin); + + var promiseObject = function(promise, label) { + return PromiseObject.create({ + promise: Promise.resolve(promise, label) + }); + }; + + var promiseArray = function(promise, label) { + return PromiseArray.create({ + promise: Promise.resolve(promise, label) + }); + }; + + /** + A PromiseManyArray is a PromiseArray that also proxies certain method calls + to the underlying manyArray. + Right now we proxy: + `reload()` + `createRecord()` + `on()` + `one()` + `trigger()` + `off()` + `has()` + */ + + function proxyToContent(method) { + return function() { + var content = get(this, 'content'); + return content[method].apply(content, arguments); + }; + } + + var PromiseManyArray = PromiseArray.extend({ + reload: function() { + //I don't think this should ever happen right now, but worth guarding if we refactor the async relationships + Ember.assert('You are trying to reload an async manyArray before it has been created', get(this, 'content')); + return get(this, 'content').reload(); + }, + + createRecord: proxyToContent('createRecord'), + + on: proxyToContent('on'), + + one: proxyToContent('one'), + + trigger: proxyToContent('trigger'), + + off: proxyToContent('off'), + + has: proxyToContent('has') + }); + + var promiseManyArray = function(promise, label) { + return PromiseManyArray.create({ + promise: Promise.resolve(promise, label) + }); + }; + + + __exports__.PromiseArray = PromiseArray; + __exports__.PromiseObject = PromiseObject; + __exports__.PromiseManyArray = PromiseManyArray; + __exports__.promiseArray = promiseArray; + __exports__.promiseObject = promiseObject; + __exports__.promiseManyArray = promiseManyArray; + }); +enifed("ember-data/system/record_array_manager", + ["ember-data/system/record_arrays","ember-data/system/map","exports"], + function(__dependency1__, __dependency2__, __exports__) { + "use strict"; + /** + @module ember-data + */ + + var RecordArray = __dependency1__.RecordArray; + var FilteredRecordArray = __dependency1__.FilteredRecordArray; + var AdapterPopulatedRecordArray = __dependency1__.AdapterPopulatedRecordArray; + var ManyArray = __dependency1__.ManyArray; + var MapWithDefault = __dependency2__.MapWithDefault; + var OrderedSet = __dependency2__.OrderedSet; + var get = Ember.get; + var forEach = Ember.EnumerableUtils.forEach; + var indexOf = Ember.EnumerableUtils.indexOf; + + /** + @class RecordArrayManager + @namespace DS + @private + @extends Ember.Object + */ + __exports__["default"] = Ember.Object.extend({ + init: function() { + this.filteredRecordArrays = MapWithDefault.create({ + defaultValue: function() { return []; } + }); + + this.changedRecords = []; + this._adapterPopulatedRecordArrays = []; + }, + + recordDidChange: function(record) { + if (this.changedRecords.push(record) !== 1) { return; } + + Ember.run.schedule('actions', this, this.updateRecordArrays); + }, + + recordArraysForRecord: function(record) { + record._recordArrays = record._recordArrays || OrderedSet.create(); + return record._recordArrays; + }, + + /** + This method is invoked whenever data is loaded into the store by the + adapter or updated by the adapter, or when a record has changed. + + It updates all record arrays that a record belongs to. + + To avoid thrashing, it only runs at most once per run loop. + + @method updateRecordArrays + @param {Class} type + @param {Number|String} clientId + */ + updateRecordArrays: function() { + forEach(this.changedRecords, function(record) { + if (get(record, 'isDeleted')) { + this._recordWasDeleted(record); + } else { + this._recordWasChanged(record); + } + }, this); + + this.changedRecords.length = 0; + }, + + _recordWasDeleted: function (record) { + var recordArrays = record._recordArrays; + + if (!recordArrays) { return; } + + recordArrays.forEach(function(array){ + array.removeRecord(record); + }); + + record._recordArrays = null; + }, + + _recordWasChanged: function (record) { + var type = record.constructor; + var recordArrays = this.filteredRecordArrays.get(type); + var filter; + + forEach(recordArrays, function(array) { + filter = get(array, 'filterFunction'); + this.updateRecordArray(array, filter, type, record); + }, this); + + // loop through all manyArrays containing an unloaded copy of this + // clientId and notify them that the record was loaded. + var manyArrays = record._loadingRecordArrays; + + if (manyArrays) { + for (var i=0, l=manyArrays.length; i 0){ + records = get(this, 'content').slice(idx, idx+amt); + this.get('relationship').removeRecords(records); + } + if (objects){ + this.get('relationship').addRecords(objects, idx); + } + }, + /** + @method reload + @public + */ + reload: function() { + return this.relationship.reload(); + }, + + /** + Create a child record within the owner + + @method createRecord + @private + @param {Object} hash + @return {DS.Model} record + */ + createRecord: function(hash) { + var store = get(this, 'store'); + var type = get(this, 'type'); + var record; + + Ember.assert("You cannot add '" + type.typeKey + "' records to this polymorphic relationship.", !get(this, 'isPolymorphic')); + + record = store.createRecord(type, hash); + this.pushObject(record); + + return record; + } + }); + }); +enifed("ember-data/system/record_arrays/record_array", + ["ember-data/system/promise_proxies","exports"], + function(__dependency1__, __exports__) { + "use strict"; + /** + @module ember-data + */ + + var PromiseArray = __dependency1__.PromiseArray; + var get = Ember.get; + + /** + A record array is an array that contains records of a certain type. The record + array materializes records as needed when they are retrieved for the first + time. You should not create record arrays yourself. Instead, an instance of + `DS.RecordArray` or its subclasses will be returned by your application's store + in response to queries. + + @class RecordArray + @namespace DS + @extends Ember.ArrayProxy + @uses Ember.Evented + */ + + __exports__["default"] = Ember.ArrayProxy.extend(Ember.Evented, { + /** + The model type contained by this record array. + + @property type + @type DS.Model + */ + type: null, + + /** + The array of client ids backing the record array. When a + record is requested from the record array, the record + for the client id at the same index is materialized, if + necessary, by the store. + + @property content + @private + @type Ember.Array + */ + content: null, + + /** + The flag to signal a `RecordArray` is currently loading data. + + Example + + ```javascript + var people = store.all('person'); + people.get('isLoaded'); // true + ``` + + @property isLoaded + @type Boolean + */ + isLoaded: false, + /** + The flag to signal a `RecordArray` is currently loading data. + + Example + + ```javascript + var people = store.all('person'); + people.get('isUpdating'); // false + people.update(); + people.get('isUpdating'); // true + ``` + + @property isUpdating + @type Boolean + */ + isUpdating: false, + + /** + The store that created this record array. + + @property store + @private + @type DS.Store + */ + store: null, + + /** + Retrieves an object from the content by index. + + @method objectAtContent + @private + @param {Number} index + @return {DS.Model} record + */ + objectAtContent: function(index) { + var content = get(this, 'content'); + + return content.objectAt(index); + }, + + /** + Used to get the latest version of all of the records in this array + from the adapter. + + Example + + ```javascript + var people = store.all('person'); + people.get('isUpdating'); // false + people.update(); + people.get('isUpdating'); // true + ``` + + @method update + */ + update: function() { + if (get(this, 'isUpdating')) { return; } + + var store = get(this, 'store'); + var type = get(this, 'type'); + + return store.fetchAll(type, this); + }, + + /** + Adds a record to the `RecordArray` without duplicates + + @method addRecord + @private + @param {DS.Model} record + @param {DS.Model} an optional index to insert at + */ + addRecord: function(record, idx) { + var content = get(this, 'content'); + if (idx === undefined) { + content.addObject(record); + } else { + if (!content.contains(record)) { + content.insertAt(idx, record); + } + } + }, + + /** + Adds a record to the `RecordArray`, but allows duplicates + + @method pushRecord + @private + @param {DS.Model} record + */ + pushRecord: function(record) { + get(this, 'content').pushObject(record); + }, + + + /** + Removes a record to the `RecordArray`. + + @method removeRecord + @private + @param {DS.Model} record + */ + removeRecord: function(record) { + get(this, 'content').removeObject(record); + }, + + /** + Saves all of the records in the `RecordArray`. + + Example + + ```javascript + var messages = store.all('message'); + messages.forEach(function(message) { + message.set('hasBeenSeen', true); + }); + messages.save(); + ``` + + @method save + @return {DS.PromiseArray} promise + */ + save: function() { + var promiseLabel = "DS: RecordArray#save " + get(this, 'type'); + var promise = Ember.RSVP.all(this.invoke("save"), promiseLabel).then(function(array) { + return Ember.A(array); + }, null, "DS: RecordArray#save apply Ember.NativeArray"); + + return PromiseArray.create({ promise: promise }); + }, + + _dissociateFromOwnRecords: function() { + var array = this; + + this.forEach(function(record){ + var recordArrays = record._recordArrays; + + if (recordArrays) { + recordArrays["delete"](array); + } + }); + }, + + willDestroy: function(){ + this._dissociateFromOwnRecords(); + this._super(); + } + }); + }); +enifed("ember-data/system/relationship-meta", + ["ember-inflector/system","exports"], + function(__dependency1__, __exports__) { + "use strict"; + var singularize = __dependency1__.singularize; + + function typeForRelationshipMeta(store, meta) { + var typeKey, type; + + typeKey = meta.type || meta.key; + if (typeof typeKey === 'string') { + if (meta.kind === 'hasMany') { + typeKey = singularize(typeKey); + } + type = store.modelFor(typeKey); + } else { + type = meta.type; + } + + return type; + } + + __exports__.typeForRelationshipMeta = typeForRelationshipMeta;function relationshipFromMeta(store, meta) { + return { + key: meta.key, + kind: meta.kind, + type: typeForRelationshipMeta(store, meta), + options: meta.options, + parentType: meta.parentType, + isRelationship: true + }; + } + + __exports__.relationshipFromMeta = relationshipFromMeta; + }); +enifed("ember-data/system/relationships", + ["./relationships/belongs_to","./relationships/has_many","ember-data/system/relationships/ext","exports"], + function(__dependency1__, __dependency2__, __dependency3__, __exports__) { + "use strict"; + /** + @module ember-data + */ + + var belongsTo = __dependency1__["default"]; + var hasMany = __dependency2__["default"]; + + + __exports__.belongsTo = belongsTo; + __exports__.hasMany = hasMany; + }); +enifed("ember-data/system/relationships/belongs_to", + ["ember-data/system/model","exports"], + function(__dependency1__, __exports__) { + "use strict"; + var Model = __dependency1__.Model; + + + /** + `DS.belongsTo` is used to define One-To-One and One-To-Many + relationships on a [DS.Model](/api/data/classes/DS.Model.html). + + + `DS.belongsTo` takes an optional hash as a second parameter, currently + supported options are: + + - `async`: A boolean value used to explicitly declare this to be an async relationship. + - `inverse`: A string used to identify the inverse property on a + related model in a One-To-Many relationship. See [Explicit Inverses](#toc_explicit-inverses) + + #### One-To-One + To declare a one-to-one relationship between two models, use + `DS.belongsTo`: + + ```javascript + App.User = DS.Model.extend({ + profile: DS.belongsTo('profile') + }); + + App.Profile = DS.Model.extend({ + user: DS.belongsTo('user') + }); + ``` + + #### One-To-Many + To declare a one-to-many relationship between two models, use + `DS.belongsTo` in combination with `DS.hasMany`, like this: + + ```javascript + App.Post = DS.Model.extend({ + comments: DS.hasMany('comment') + }); + + App.Comment = DS.Model.extend({ + post: DS.belongsTo('post') + }); + ``` + + @namespace + @method belongsTo + @for DS + @param {String or DS.Model} type the model type of the relationship + @param {Object} options a hash of options + @return {Ember.computed} relationship + */ + function belongsTo(type, options) { + if (typeof type === 'object') { + options = type; + type = undefined; + } else { + Ember.assert("The first argument to DS.belongsTo must be a string representing a model type key, e.g. use DS.belongsTo('person') to define a relation to the App.Person model", !!type && (typeof type === 'string' || Model.detect(type))); + } + + options = options || {}; + + var meta = { + type: type, + isRelationship: true, + options: options, + kind: 'belongsTo', + key: null + }; + + return Ember.computed(function(key, value) { + if (arguments.length>1) { + if ( value === undefined ) { + value = null; + } + if (value && value.then) { + this._relationships[key].setRecordPromise(value); + } else { + this._relationships[key].setRecord(value); + } + } + + return this._relationships[key].getRecord(); + }).meta(meta); + } + + /** + These observers observe all `belongsTo` relationships on the record. See + `relationships/ext` to see how these observers get their dependencies. + + @class Model + @namespace DS + */ + Model.reopen({ + notifyBelongsToAdded: function(key, relationship) { + this.notifyPropertyChange(key); + }, + + notifyBelongsToRemoved: function(key) { + this.notifyPropertyChange(key); + } + }); + + __exports__["default"] = belongsTo; + }); +enifed("ember-data/system/relationships/ext", + ["ember-data/system/relationship-meta","ember-data/system/model","ember-data/system/map"], + function(__dependency1__, __dependency2__, __dependency3__) { + "use strict"; + var typeForRelationshipMeta = __dependency1__.typeForRelationshipMeta; + var relationshipFromMeta = __dependency1__.relationshipFromMeta; + var Model = __dependency2__.Model; + var Map = __dependency3__.Map; + var MapWithDefault = __dependency3__.MapWithDefault; + + var get = Ember.get; + var filter = Ember.ArrayPolyfills.filter; + + /** + @module ember-data + */ + + /* + This file defines several extensions to the base `DS.Model` class that + add support for one-to-many relationships. + */ + + /** + @class Model + @namespace DS + */ + Model.reopen({ + + /** + This Ember.js hook allows an object to be notified when a property + is defined. + + In this case, we use it to be notified when an Ember Data user defines a + belongs-to relationship. In that case, we need to set up observers for + each one, allowing us to track relationship changes and automatically + reflect changes in the inverse has-many array. + + This hook passes the class being set up, as well as the key and value + being defined. So, for example, when the user does this: + + ```javascript + DS.Model.extend({ + parent: DS.belongsTo('user') + }); + ``` + + This hook would be called with "parent" as the key and the computed + property returned by `DS.belongsTo` as the value. + + @method didDefineProperty + @param {Object} proto + @param {String} key + @param {Ember.ComputedProperty} value + */ + didDefineProperty: function(proto, key, value) { + // Check if the value being set is a computed property. + if (value instanceof Ember.ComputedProperty) { + + // If it is, get the metadata for the relationship. This is + // populated by the `DS.belongsTo` helper when it is creating + // the computed property. + var meta = value.meta(); + + meta.parentType = proto.constructor; + } + } + }); + + /* + These DS.Model extensions add class methods that provide relationship + introspection abilities about relationships. + + A note about the computed properties contained here: + + **These properties are effectively sealed once called for the first time.** + To avoid repeatedly doing expensive iteration over a model's fields, these + values are computed once and then cached for the remainder of the runtime of + your application. + + If your application needs to modify a class after its initial definition + (for example, using `reopen()` to add additional attributes), make sure you + do it before using your model with the store, which uses these properties + extensively. + */ + + Model.reopenClass({ + + /** + For a given relationship name, returns the model type of the relationship. + + For example, if you define a model like this: + + ```javascript + App.Post = DS.Model.extend({ + comments: DS.hasMany('comment') + }); + ``` + + Calling `App.Post.typeForRelationship('comments')` will return `App.Comment`. + + @method typeForRelationship + @static + @param {String} name the name of the relationship + @return {subclass of DS.Model} the type of the relationship, or undefined + */ + typeForRelationship: function(name) { + var relationship = get(this, 'relationshipsByName').get(name); + return relationship && relationship.type; + }, + + inverseMap: Ember.computed(function() { + return Ember.create(null); + }), + + /** + Find the relationship which is the inverse of the one asked for. + + For example, if you define models like this: + + ```javascript + App.Post = DS.Model.extend({ + comments: DS.hasMany('message') + }); + + App.Message = DS.Model.extend({ + owner: DS.belongsTo('post') + }); + ``` + + App.Post.inverseFor('comments') -> {type: App.Message, name:'owner', kind:'belongsTo'} + App.Message.inverseFor('owner') -> {type: App.Post, name:'comments', kind:'hasMany'} + + @method inverseFor + @static + @param {String} name the name of the relationship + @return {Object} the inverse relationship, or null + */ + inverseFor: function(name) { + var inverseMap = get(this, 'inverseMap'); + if (inverseMap[name]) { + return inverseMap[name]; + } else { + var inverse = this._findInverseFor(name); + inverseMap[name] = inverse; + return inverse; + } + }, + + //Calculate the inverse, ignoring the cache + _findInverseFor: function(name) { + + var inverseType = this.typeForRelationship(name); + if (!inverseType) { + return null; + } + + //If inverse is manually specified to be null, like `comments: DS.hasMany('message', {inverse: null})` + var options = this.metaForProperty(name).options; + if (options.inverse === null) { return null; } + + var inverseName, inverseKind, inverse; + + //If inverse is specified manually, return the inverse + if (options.inverse) { + inverseName = options.inverse; + inverse = Ember.get(inverseType, 'relationshipsByName').get(inverseName); + + Ember.assert("We found no inverse relationships by the name of '" + inverseName + "' on the '" + inverseType.typeKey + + "' model. This is most likely due to a missing attribute on your model definition.", !Ember.isNone(inverse)); + + inverseKind = inverse.kind; + } else { + //No inverse was specified manually, we need to use a heuristic to guess one + var possibleRelationships = findPossibleInverses(this, inverseType); + + if (possibleRelationships.length === 0) { return null; } + + var filteredRelationships = filter.call(possibleRelationships, function(possibleRelationship) { + var optionsForRelationship = inverseType.metaForProperty(possibleRelationship.name).options; + return name === optionsForRelationship.inverse; + }); + + Ember.assert("You defined the '" + name + "' relationship on " + this + ", but you defined the inverse relationships of type " + + inverseType.toString() + " multiple times. Look at http://emberjs.com/guides/models/defining-models/#toc_explicit-inverses for how to explicitly specify inverses", + filteredRelationships.length < 2); + + if (filteredRelationships.length === 1 ) { + possibleRelationships = filteredRelationships; + } + + Ember.assert("You defined the '" + name + "' relationship on " + this + ", but multiple possible inverse relationships of type " + + this + " were found on " + inverseType + ". Look at http://emberjs.com/guides/models/defining-models/#toc_explicit-inverses for how to explicitly specify inverses", + possibleRelationships.length === 1); + + inverseName = possibleRelationships[0].name; + inverseKind = possibleRelationships[0].kind; + } + + function findPossibleInverses(type, inverseType, relationshipsSoFar) { + var possibleRelationships = relationshipsSoFar || []; + + var relationshipMap = get(inverseType, 'relationships'); + if (!relationshipMap) { return; } + + var relationships = relationshipMap.get(type); + + relationships = filter.call(relationships, function(relationship) { + var optionsForRelationship = inverseType.metaForProperty(relationship.name).options; + + if (!optionsForRelationship.inverse){ + return true; + } + + return name === optionsForRelationship.inverse; + }); + + if (relationships) { + possibleRelationships.push.apply(possibleRelationships, relationships); + } + + //Recurse to support polymorphism + if (type.superclass) { + findPossibleInverses(type.superclass, inverseType, possibleRelationships); + } + + return possibleRelationships; + } + + return { + type: inverseType, + name: inverseName, + kind: inverseKind + }; + }, + + /** + The model's relationships as a map, keyed on the type of the + relationship. The value of each entry is an array containing a descriptor + for each relationship with that type, describing the name of the relationship + as well as the type. + + For example, given the following model definition: + + ```javascript + App.Blog = DS.Model.extend({ + users: DS.hasMany('user'), + owner: DS.belongsTo('user'), + posts: DS.hasMany('post') + }); + ``` + + This computed property would return a map describing these + relationships, like this: + + ```javascript + var relationships = Ember.get(App.Blog, 'relationships'); + relationships.get(App.User); + //=> [ { name: 'users', kind: 'hasMany' }, + // { name: 'owner', kind: 'belongsTo' } ] + relationships.get(App.Post); + //=> [ { name: 'posts', kind: 'hasMany' } ] + ``` + + @property relationships + @static + @type Ember.Map + @readOnly + */ + relationships: Ember.computed(function() { + var map = new MapWithDefault({ + defaultValue: function() { return []; } + }); + + // Loop through each computed property on the class + this.eachComputedProperty(function(name, meta) { + // If the computed property is a relationship, add + // it to the map. + if (meta.isRelationship) { + meta.key = name; + var relationshipsForType = map.get(typeForRelationshipMeta(this.store, meta)); + + relationshipsForType.push({ + name: name, + kind: meta.kind + }); + } + }); + + return map; + }).cacheable(false).readOnly(), + + /** + A hash containing lists of the model's relationships, grouped + by the relationship kind. For example, given a model with this + definition: + + ```javascript + App.Blog = DS.Model.extend({ + users: DS.hasMany('user'), + owner: DS.belongsTo('user'), + + posts: DS.hasMany('post') + }); + ``` + + This property would contain the following: + + ```javascript + var relationshipNames = Ember.get(App.Blog, 'relationshipNames'); + relationshipNames.hasMany; + //=> ['users', 'posts'] + relationshipNames.belongsTo; + //=> ['owner'] + ``` + + @property relationshipNames + @static + @type Object + @readOnly + */ + relationshipNames: Ember.computed(function() { + var names = { + hasMany: [], + belongsTo: [] + }; + + this.eachComputedProperty(function(name, meta) { + if (meta.isRelationship) { + names[meta.kind].push(name); + } + }); + + return names; + }), + + /** + An array of types directly related to a model. Each type will be + included once, regardless of the number of relationships it has with + the model. + + For example, given a model with this definition: + + ```javascript + App.Blog = DS.Model.extend({ + users: DS.hasMany('user'), + owner: DS.belongsTo('user'), + + posts: DS.hasMany('post') + }); + ``` + + This property would contain the following: + + ```javascript + var relatedTypes = Ember.get(App.Blog, 'relatedTypes'); + //=> [ App.User, App.Post ] + ``` + + @property relatedTypes + @static + @type Ember.Array + @readOnly + */ + relatedTypes: Ember.computed(function() { + var type; + var types = Ember.A(); + + // Loop through each computed property on the class, + // and create an array of the unique types involved + // in relationships + this.eachComputedProperty(function(name, meta) { + if (meta.isRelationship) { + meta.key = name; + type = typeForRelationshipMeta(this.store, meta); + + Ember.assert("You specified a hasMany (" + meta.type + ") on " + meta.parentType + " but " + meta.type + " was not found.", type); + + if (!types.contains(type)) { + Ember.assert("Trying to sideload " + name + " on " + this.toString() + " but the type doesn't exist.", !!type); + types.push(type); + } + } + }); + + return types; + }).cacheable(false).readOnly(), + + /** + A map whose keys are the relationships of a model and whose values are + relationship descriptors. + + For example, given a model with this + definition: + + ```javascript + App.Blog = DS.Model.extend({ + users: DS.hasMany('user'), + owner: DS.belongsTo('user'), + + posts: DS.hasMany('post') + }); + ``` + + This property would contain the following: + + ```javascript + var relationshipsByName = Ember.get(App.Blog, 'relationshipsByName'); + relationshipsByName.get('users'); + //=> { key: 'users', kind: 'hasMany', type: App.User } + relationshipsByName.get('owner'); + //=> { key: 'owner', kind: 'belongsTo', type: App.User } + ``` + + @property relationshipsByName + @static + @type Ember.Map + @readOnly + */ + relationshipsByName: Ember.computed(function() { + var map = Map.create(); + + this.eachComputedProperty(function(name, meta) { + if (meta.isRelationship) { + meta.key = name; + var relationship = relationshipFromMeta(this.store, meta); + relationship.type = typeForRelationshipMeta(this.store, meta); + map.set(name, relationship); + } + }); + + return map; + }).cacheable(false).readOnly(), + + /** + A map whose keys are the fields of the model and whose values are strings + describing the kind of the field. A model's fields are the union of all of its + attributes and relationships. + + For example: + + ```javascript + + App.Blog = DS.Model.extend({ + users: DS.hasMany('user'), + owner: DS.belongsTo('user'), + + posts: DS.hasMany('post'), + + title: DS.attr('string') + }); + + var fields = Ember.get(App.Blog, 'fields'); + fields.forEach(function(kind, field) { + console.log(field, kind); + }); + + // prints: + // users, hasMany + // owner, belongsTo + // posts, hasMany + // title, attribute + ``` + + @property fields + @static + @type Ember.Map + @readOnly + */ + fields: Ember.computed(function() { + var map = Map.create(); + + this.eachComputedProperty(function(name, meta) { + if (meta.isRelationship) { + map.set(name, meta.kind); + } else if (meta.isAttribute) { + map.set(name, 'attribute'); + } + }); + + return map; + }).readOnly(), + + /** + Given a callback, iterates over each of the relationships in the model, + invoking the callback with the name of each relationship and its relationship + descriptor. + + @method eachRelationship + @static + @param {Function} callback the callback to invoke + @param {any} binding the value to which the callback's `this` should be bound + */ + eachRelationship: function(callback, binding) { + get(this, 'relationshipsByName').forEach(function(relationship, name) { + callback.call(binding, name, relationship); + }); + }, + + /** + Given a callback, iterates over each of the types related to a model, + invoking the callback with the related type's class. Each type will be + returned just once, regardless of how many different relationships it has + with a model. + + @method eachRelatedType + @static + @param {Function} callback the callback to invoke + @param {any} binding the value to which the callback's `this` should be bound + */ + eachRelatedType: function(callback, binding) { + get(this, 'relatedTypes').forEach(function(type) { + callback.call(binding, type); + }); + }, + + determineRelationshipType: function(knownSide) { + var knownKey = knownSide.key; + var knownKind = knownSide.kind; + var inverse = this.inverseFor(knownKey); + var key, otherKind; + + if (!inverse) { + return knownKind === 'belongsTo' ? 'oneToNone' : 'manyToNone'; + } + + key = inverse.name; + otherKind = inverse.kind; + + if (otherKind === 'belongsTo') { + return knownKind === 'belongsTo' ? 'oneToOne' : 'manyToOne'; + } else { + return knownKind === 'belongsTo' ? 'oneToMany' : 'manyToMany'; + } + } + + }); + + Model.reopen({ + /** + Given a callback, iterates over each of the relationships in the model, + invoking the callback with the name of each relationship and its relationship + descriptor. + + @method eachRelationship + @param {Function} callback the callback to invoke + @param {any} binding the value to which the callback's `this` should be bound + */ + eachRelationship: function(callback, binding) { + this.constructor.eachRelationship(callback, binding); + }, + + relationshipFor: function(name) { + return get(this.constructor, 'relationshipsByName').get(name); + }, + + inverseFor: function(key) { + return this.constructor.inverseFor(key); + } + + }); + }); +enifed("ember-data/system/relationships/has_many", + ["ember-data/system/model","exports"], + function(__dependency1__, __exports__) { + "use strict"; + /** + @module ember-data + */ + + var Model = __dependency1__.Model; + + /** + `DS.hasMany` is used to define One-To-Many and Many-To-Many + relationships on a [DS.Model](/api/data/classes/DS.Model.html). + + `DS.hasMany` takes an optional hash as a second parameter, currently + supported options are: + + - `async`: A boolean value used to explicitly declare this to be an async relationship. + - `inverse`: A string used to identify the inverse property on a related model. + + #### One-To-Many + To declare a one-to-many relationship between two models, use + `DS.belongsTo` in combination with `DS.hasMany`, like this: + + ```javascript + App.Post = DS.Model.extend({ + comments: DS.hasMany('comment') + }); + + App.Comment = DS.Model.extend({ + post: DS.belongsTo('post') + }); + ``` + + #### Many-To-Many + To declare a many-to-many relationship between two models, use + `DS.hasMany`: + + ```javascript + App.Post = DS.Model.extend({ + tags: DS.hasMany('tag') + }); + + App.Tag = DS.Model.extend({ + posts: DS.hasMany('post') + }); + ``` + + #### Explicit Inverses + + Ember Data will do its best to discover which relationships map to + one another. In the one-to-many code above, for example, Ember Data + can figure out that changing the `comments` relationship should update + the `post` relationship on the inverse because post is the only + relationship to that model. + + However, sometimes you may have multiple `belongsTo`/`hasManys` for the + same type. You can specify which property on the related model is + the inverse using `DS.hasMany`'s `inverse` option: + + ```javascript + var belongsTo = DS.belongsTo, + hasMany = DS.hasMany; + + App.Comment = DS.Model.extend({ + onePost: belongsTo('post'), + twoPost: belongsTo('post'), + redPost: belongsTo('post'), + bluePost: belongsTo('post') + }); + + App.Post = DS.Model.extend({ + comments: hasMany('comment', { + inverse: 'redPost' + }) + }); + ``` + + You can also specify an inverse on a `belongsTo`, which works how + you'd expect. + + @namespace + @method hasMany + @for DS + @param {String or DS.Model} type the model type of the relationship + @param {Object} options a hash of options + @return {Ember.computed} relationship + */ + function hasMany(type, options) { + if (typeof type === 'object') { + options = type; + type = undefined; + } + + options = options || {}; + + // Metadata about relationships is stored on the meta of + // the relationship. This is used for introspection and + // serialization. Note that `key` is populated lazily + // the first time the CP is called. + var meta = { + type: type, + isRelationship: true, + options: options, + kind: 'hasMany', + key: null + }; + + return Ember.computed(function(key) { + var relationship = this._relationships[key]; + return relationship.getRecords(); + }).meta(meta).readOnly(); + } + + Model.reopen({ + notifyHasManyAdded: function(key, record, idx) { + var relationship = this._relationships[key]; + var manyArray = relationship.manyArray; + manyArray.addRecord(record, idx); + //We need to notifyPropertyChange in the adding case because we need to make sure + //we fetch the newly added record in case it is unloaded + //TODO(Igor): Consider whether we could do this only if the record state is unloaded + this.notifyPropertyChange(key); + }, + + notifyHasManyRemoved: function(key, record) { + var relationship = this._relationships[key]; + var manyArray = relationship.manyArray; + manyArray.removeRecord(record); + } + }); + + + __exports__["default"] = hasMany; + }); +enifed("ember-data/system/relationships/relationship", + ["ember-data/system/promise_proxies","ember-data/system/map","exports"], + function(__dependency1__, __dependency2__, __exports__) { + "use strict"; + var PromiseManyArray = __dependency1__.PromiseManyArray; + var PromiseObject = __dependency1__.PromiseObject; + var OrderedSet = __dependency2__.OrderedSet; + + var Relationship = function(store, record, inverseKey, relationshipMeta) { + this.members = new OrderedSet(); + this.store = store; + this.key = relationshipMeta.key; + this.inverseKey = inverseKey; + this.record = record; + this.isAsync = relationshipMeta.options.async; + this.relationshipMeta = relationshipMeta; + //This probably breaks for polymorphic relationship in complex scenarios, due to + //multiple possible typeKeys + this.inverseKeyForImplicit = this.store.modelFor(this.record.constructor).typeKey + this.key; + //Cached promise when fetching the relationship from a link + this.linkPromise = null; + }; + + Relationship.prototype = { + constructor: Relationship, + + destroy: Ember.K, + + clear: function() { + this.members.forEach(function(member) { + this.removeRecord(member); + }, this); + }, + + disconnect: function(){ + this.members.forEach(function(member) { + this.removeRecordFromInverse(member); + }, this); + }, + + reconnect: function(){ + this.members.forEach(function(member) { + this.addRecordToInverse(member); + }, this); + }, + + removeRecords: function(records){ + var length = Ember.get(records, 'length'); + var record; + for (var i = 0; i < length; i++){ + record = records[i]; + this.removeRecord(record); + } + }, + + addRecords: function(records, idx){ + var length = Ember.get(records, 'length'); + var record; + for (var i = 0; i < length; i++){ + record = records[i]; + this.addRecord(record, idx); + if (idx !== undefined) { + idx++; + } + } + }, + + addRecord: function(record, idx) { + if (!this.members.has(record)) { + this.members.add(record); + this.notifyRecordRelationshipAdded(record, idx); + if (this.inverseKey) { + record._relationships[this.inverseKey].addRecord(this.record); + } else { + if (!record._implicitRelationships[this.inverseKeyForImplicit]) { + record._implicitRelationships[this.inverseKeyForImplicit] = new Relationship(this.store, record, this.key, {options:{}}); + } + record._implicitRelationships[this.inverseKeyForImplicit].addRecord(this.record); + } + this.record.updateRecordArrays(); + } + }, + + removeRecord: function(record) { + if (this.members.has(record)) { + this.removeRecordFromOwn(record); + if (this.inverseKey) { + this.removeRecordFromInverse(record); + } else { + if (record._implicitRelationships[this.inverseKeyForImplicit]) { + record._implicitRelationships[this.inverseKeyForImplicit].removeRecord(this.record); + } + } + } + }, + + addRecordToInverse: function(record) { + if (this.inverseKey) { + record._relationships[this.inverseKey].addRecord(this.record); + } + }, + + removeRecordFromInverse: function(record) { + var inverseRelationship = record._relationships[this.inverseKey]; + //Need to check for existence, as the record might unloading at the moment + if (inverseRelationship) { + inverseRelationship.removeRecordFromOwn(this.record); + } + }, + + removeRecordFromOwn: function(record) { + this.members["delete"](record); + this.notifyRecordRelationshipRemoved(record); + this.record.updateRecordArrays(); + }, + + updateLink: function(link) { + Ember.assert("You have pushed a record of type '" + this.record.constructor.typeKey + "' with '" + this.key + "' as a link, but the value of that link is not a string.", typeof link === 'string' || link === null); + if (link !== this.link) { + this.link = link; + this.linkPromise = null; + this.record.notifyPropertyChange(this.key); + } + }, + + findLink: function() { + if (this.linkPromise) { + return this.linkPromise; + } else { + var promise = this.fetchLink(); + this.linkPromise = promise; + return promise.then(function(result) { + return result; + }); + } + }, + + updateRecordsFromAdapter: function(records) { + //TODO Once we have adapter support, we need to handle updated and canonical changes + this.computeChanges(records); + }, + + notifyRecordRelationshipAdded: Ember.K, + notifyRecordRelationshipRemoved: Ember.K + }; + + var ManyRelationship = function(store, record, inverseKey, relationshipMeta) { + this._super$constructor(store, record, inverseKey, relationshipMeta); + this.belongsToType = relationshipMeta.type; + this.manyArray = store.recordArrayManager.createManyArray(this.belongsToType, Ember.A()); + this.manyArray.relationship = this; + this.isPolymorphic = relationshipMeta.options.polymorphic; + this.manyArray.isPolymorphic = this.isPolymorphic; + }; + + ManyRelationship.prototype = Ember.create(Relationship.prototype); + ManyRelationship.prototype.constructor = ManyRelationship; + ManyRelationship.prototype._super$constructor = Relationship; + + ManyRelationship.prototype.destroy = function() { + this.manyArray.destroy(); + }; + + ManyRelationship.prototype.notifyRecordRelationshipAdded = function(record, idx) { + Ember.assert("You cannot add '" + record.constructor.typeKey + "' records to this relationship (only '" + this.belongsToType.typeKey + "' allowed)", !this.belongsToType || record instanceof this.belongsToType); + this.record.notifyHasManyAdded(this.key, record, idx); + }; + + ManyRelationship.prototype.notifyRecordRelationshipRemoved = function(record) { + this.record.notifyHasManyRemoved(this.key, record); + }; + + ManyRelationship.prototype.reload = function() { + var self = this; + if (this.link) { + return this.fetchLink(); + } else { + return this.store.scheduleFetchMany(this.manyArray.toArray()).then(function() { + //Goes away after the manyArray refactor + self.manyArray.set('isLoaded', true); + return self.manyArray; + }); + } + }; + + ManyRelationship.prototype.computeChanges = function(records) { + var members = this.members; + var recordsToRemove = []; + var length; + var record; + var i; + + records = setForArray(records); + + members.forEach(function(member) { + if (records.has(member)) return; + + recordsToRemove.push(member); + }); + this.removeRecords(recordsToRemove); + + var hasManyArray = this.manyArray; + + // Using records.toArray() since currently using + // removeRecord can modify length, messing stuff up + // forEach since it directly looks at "length" each + // iteration + records = records.toArray(); + length = records.length; + for (i = 0; i < length; i++){ + record = records[i]; + //Need to preserve the order of incoming records + if (hasManyArray.objectAt(i) === record ) { + continue; + } + this.removeRecord(record); + this.addRecord(record, i); + } + }; + + ManyRelationship.prototype.fetchLink = function() { + var self = this; + return this.store.findHasMany(this.record, this.link, this.relationshipMeta).then(function(records){ + self.updateRecordsFromAdapter(records); + return self.manyArray; + }); + }; + + ManyRelationship.prototype.findRecords = function() { + var manyArray = this.manyArray; + return this.store.findMany(manyArray.toArray()).then(function(){ + //Goes away after the manyArray refactor + manyArray.set('isLoaded', true); + return manyArray; + }); + }; + + ManyRelationship.prototype.getRecords = function() { + if (this.isAsync) { + var self = this; + var promise; + if (this.link) { + promise = this.findLink().then(function() { + return self.findRecords(); + }); + } else { + promise = this.findRecords(); + } + return PromiseManyArray.create({ + content: this.manyArray, + promise: promise + }); + } else { + Ember.assert("You looked up the '" + this.key + "' relationship on a '" + this.record.constructor.typeKey + "' with id " + this.record.get('id') + " but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async (`DS.hasMany({ async: true })`)", this.manyArray.isEvery('isEmpty', false)); + + if (!this.manyArray.get('isDestroyed')) { + this.manyArray.set('isLoaded', true); + } + return this.manyArray; + } + }; + + var BelongsToRelationship = function(store, record, inverseKey, relationshipMeta) { + this._super$constructor(store, record, inverseKey, relationshipMeta); + this.record = record; + this.key = relationshipMeta.key; + this.inverseRecord = null; + }; + + BelongsToRelationship.prototype = Ember.create(Relationship.prototype); + BelongsToRelationship.prototype.constructor = BelongsToRelationship; + BelongsToRelationship.prototype._super$constructor = Relationship; + + BelongsToRelationship.prototype.setRecord = function(newRecord) { + if (newRecord) { + this.addRecord(newRecord); + } else if (this.inverseRecord) { + this.removeRecord(this.inverseRecord); + } + }; + + BelongsToRelationship.prototype._super$addRecord = Relationship.prototype.addRecord; + BelongsToRelationship.prototype.addRecord = function(newRecord) { + if (this.members.has(newRecord)){ return;} + var type = this.relationshipMeta.type; + Ember.assert("You can only add a '" + type.typeKey + "' record to this relationship", newRecord instanceof type); + + if (this.inverseRecord) { + this.removeRecord(this.inverseRecord); + } + + this.inverseRecord = newRecord; + this._super$addRecord(newRecord); + }; + + BelongsToRelationship.prototype.setRecordPromise = function(newPromise) { + var content = newPromise.get && newPromise.get('content'); + Ember.assert("You passed in a promise that did not originate from an EmberData relationship. You can only pass promises that come from a belongsTo or hasMany relationship to the get call.", content !== undefined); + this.setRecord(content); + }; + + BelongsToRelationship.prototype.notifyRecordRelationshipAdded = function(newRecord) { + this.record.notifyBelongsToAdded(this.key, this); + }; + + BelongsToRelationship.prototype.notifyRecordRelationshipRemoved = function(record) { + this.record.notifyBelongsToRemoved(this.key, this); + }; + + BelongsToRelationship.prototype._super$removeRecordFromOwn = Relationship.prototype.removeRecordFromOwn; + BelongsToRelationship.prototype.removeRecordFromOwn = function(record) { + if (!this.members.has(record)) { return; } + this.inverseRecord = null; + this._super$removeRecordFromOwn(record); + }; + + BelongsToRelationship.prototype.findRecord = function() { + if (this.inverseRecord) { + return this.store._findByRecord(this.inverseRecord); + } else { + return Ember.RSVP.Promise.resolve(null); + } + }; + + BelongsToRelationship.prototype.fetchLink = function() { + var self = this; + return this.store.findBelongsTo(this.record, this.link, this.relationshipMeta).then(function(record){ + if (record) { + self.addRecord(record); + } + return record; + }); + }; + + BelongsToRelationship.prototype.getRecord = function() { + if (this.isAsync) { + var promise; + if (this.link){ + var self = this; + promise = this.findLink().then(function() { + return self.findRecord(); + }); + } else { + promise = this.findRecord(); + } + + return PromiseObject.create({ + promise: promise, + content: this.inverseRecord + }); + } else { + Ember.assert("You looked up the '" + this.key + "' relationship on a '" + this.record.constructor.typeKey + "' with id " + this.record.get('id') + " but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async (`DS.belongsTo({ async: true })`)", this.inverseRecord === null || !this.inverseRecord.get('isEmpty')); + return this.inverseRecord; + } + }; + + function setForArray(array) { + var set = new OrderedSet(); + + if (array) { + for (var i=0, l=array.length; i= 1); + Ember.assert("You may not pass `" + id + "` as id to the store's find method", arguments.length === 1 || !Ember.isNone(id)); + + if (arguments.length === 1) { + return this.findAll(type); + } + + // We are passed a query instead of an id. + if (Ember.typeOf(id) === 'object') { + return this.findQuery(type, id); + } + + return this.findById(type, coerceId(id), preload); + }, + + /** + This method returns a fresh record for a given type and id combination. + + If a record is available for the given type/id combination, then it will fetch this record from the store then reload it. If there's no record corresponding in the store it will simply call store.find. + + @method fetch + @param {String or subclass of DS.Model} type + @param {Object|String|Integer|null} id + @param {Object} preload - optional set of attributes and relationships passed in either as IDs or as actual models + @return {Promise} promise + */ + fetch: function(type, id, preload) { + if (this.hasRecordForId(type, id)) { + return this.getById(type, id).reload(); + } else { + return this.find(type, id, preload); + } + }, + + /** + This method returns a record for a given type and id combination. + + @method findById + @private + @param {String or subclass of DS.Model} type + @param {String|Integer} id + @param {Object} preload - optional set of attributes and relationships passed in either as IDs or as actual models + @return {Promise} promise + */ + findById: function(typeName, id, preload) { + + var type = this.modelFor(typeName); + var record = this.recordForId(type, id); + + return this._findByRecord(record, preload); + }, + + _findByRecord: function(record, preload) { + var fetchedRecord; + + if (preload) { + record._preloadData(preload); + } + + if (get(record, 'isEmpty')) { + fetchedRecord = this.scheduleFetch(record); + //TODO double check about reloading + } else if (get(record, 'isLoading')){ + fetchedRecord = record._loadingPromise; + } + + return promiseObject(fetchedRecord || record, "DS: Store#findByRecord " + record.typeKey + " with id: " + get(record, 'id')); + }, + + /** + This method makes a series of requests to the adapter's `find` method + and returns a promise that resolves once they are all loaded. + + @private + @method findByIds + @param {String} type + @param {Array} ids + @return {Promise} promise + */ + findByIds: function(type, ids) { + var store = this; + + return promiseArray(Ember.RSVP.all(map(ids, function(id) { + return store.findById(type, id); + })).then(Ember.A, null, "DS: Store#findByIds of " + type + " complete")); + }, + + /** + This method is called by `findById` if it discovers that a particular + type/id pair hasn't been loaded yet to kick off a request to the + adapter. + + @method fetchRecord + @private + @param {DS.Model} record + @return {Promise} promise + */ + fetchRecord: function(record) { + var type = record.constructor; + var id = get(record, 'id'); + var adapter = this.adapterFor(type); + + Ember.assert("You tried to find a record but you have no adapter (for " + type + ")", adapter); + Ember.assert("You tried to find a record but your adapter (for " + type + ") does not implement 'find'", typeof adapter.find === 'function'); + + var promise = _find(adapter, this, type, id, record); + return promise; + }, + + scheduleFetchMany: function(records) { + return Promise.all(map(records, this.scheduleFetch, this)); + }, + + scheduleFetch: function(record) { + var type = record.constructor; + if (isNone(record)) { return null; } + if (record._loadingPromise) { return record._loadingPromise; } + + var resolver = Ember.RSVP.defer('Fetching ' + type + 'with id: ' + record.get('id')); + var recordResolverPair = { + record: record, + resolver: resolver + }; + var promise = resolver.promise; + + record.loadingData(promise); + + if (!this._pendingFetch.get(type)){ + this._pendingFetch.set(type, [recordResolverPair]); + } else { + this._pendingFetch.get(type).push(recordResolverPair); + } + Ember.run.scheduleOnce('afterRender', this, this.flushAllPendingFetches); + + return promise; + }, + + flushAllPendingFetches: function(){ + if (this.isDestroyed || this.isDestroying) { + return; + } + + this._pendingFetch.forEach(this._flushPendingFetchForType, this); + this._pendingFetch = Map.create(); + }, + + _flushPendingFetchForType: function (recordResolverPairs, type) { + var store = this; + var adapter = store.adapterFor(type); + var shouldCoalesce = !!adapter.findMany && adapter.coalesceFindRequests; + var records = Ember.A(recordResolverPairs).mapBy('record'); + + function _fetchRecord(recordResolverPair) { + recordResolverPair.resolver.resolve(store.fetchRecord(recordResolverPair.record)); + } + + function resolveFoundRecords(records) { + forEach(records, function(record){ + var pair = Ember.A(recordResolverPairs).findBy('record', record); + if (pair){ + var resolver = pair.resolver; + resolver.resolve(record); + } + }); + } + + function makeMissingRecordsRejector(requestedRecords) { + return function rejectMissingRecords(resolvedRecords) { + var missingRecords = requestedRecords.without(resolvedRecords); + rejectRecords(missingRecords); + }; + } + + function makeRecordsRejector(records) { + return function (error) { + rejectRecords(records, error); + }; + } + + function rejectRecords(records, error) { + forEach(records, function(record){ + var pair = Ember.A(recordResolverPairs).findBy('record', record); + if (pair){ + var resolver = pair.resolver; + resolver.reject(error); + } + }); + } + + if (recordResolverPairs.length === 1) { + _fetchRecord(recordResolverPairs[0]); + } else if (shouldCoalesce) { + var groups = adapter.groupRecordsForFindMany(this, records); + forEach(groups, function (groupOfRecords) { + var requestedRecords = Ember.A(groupOfRecords); + var ids = requestedRecords.mapBy('id'); + if (ids.length > 1) { + _findMany(adapter, store, type, ids, requestedRecords). + then(resolveFoundRecords). + then(makeMissingRecordsRejector(requestedRecords)). + then(null, makeRecordsRejector(requestedRecords)); + } else if (ids.length === 1) { + var pair = Ember.A(recordResolverPairs).findBy('record', groupOfRecords[0]); + _fetchRecord(pair); + } else { + Ember.assert("You cannot return an empty array from adapter's method groupRecordsForFindMany", false); + } + }); + } else { + forEach(recordResolverPairs, _fetchRecord); + } + }, + + /** + Get a record by a given type and ID without triggering a fetch. + + This method will synchronously return the record if it is available in the store, + otherwise it will return `null`. A record is available if it has been fetched earlier, or + pushed manually into the store. + + _Note: This is an synchronous method and does not return a promise._ + + ```js + var post = store.getById('post', 1); + + post.get('id'); // 1 + ``` + + @method getById + @param {String or subclass of DS.Model} type + @param {String|Integer} id + @return {DS.Model|null} record + */ + getById: function(type, id) { + if (this.hasRecordForId(type, id)) { + return this.recordForId(type, id); + } else { + return null; + } + }, + + /** + This method is called by the record's `reload` method. + + This method calls the adapter's `find` method, which returns a promise. When + **that** promise resolves, `reloadRecord` will resolve the promise returned + by the record's `reload`. + + @method reloadRecord + @private + @param {DS.Model} record + @return {Promise} promise + */ + reloadRecord: function(record) { + var type = record.constructor; + var adapter = this.adapterFor(type); + var id = get(record, 'id'); + + Ember.assert("You cannot reload a record without an ID", id); + Ember.assert("You tried to reload a record but you have no adapter (for " + type + ")", adapter); + Ember.assert("You tried to reload a record but your adapter does not implement `find`", typeof adapter.find === 'function'); + + return this.scheduleFetch(record); + }, + + /** + Returns true if a record for a given type and ID is already loaded. + + @method hasRecordForId + @param {String or subclass of DS.Model} type + @param {String|Integer} id + @return {Boolean} + */ + hasRecordForId: function(typeName, inputId) { + var type = this.modelFor(typeName); + var id = coerceId(inputId); + return !!this.typeMapFor(type).idToRecord[id]; + }, + + /** + Returns id record for a given type and ID. If one isn't already loaded, + it builds a new record and leaves it in the `empty` state. + + @method recordForId + @private + @param {String or subclass of DS.Model} type + @param {String|Integer} id + @return {DS.Model} record + */ + recordForId: function(typeName, inputId) { + var type = this.modelFor(typeName); + var id = coerceId(inputId); + var idToRecord = this.typeMapFor(type).idToRecord; + var record = idToRecord[id]; + + if (!record || !idToRecord[id]) { + record = this.buildRecord(type, id); + } + + return record; + }, + + /** + @method findMany + @private + @param {DS.Model} owner + @param {Array} records + @param {String or subclass of DS.Model} type + @param {Resolver} resolver + @return {DS.ManyArray} records + */ + findMany: function(records) { + var store = this; + return Promise.all(map(records, function(record) { + return store._findByRecord(record); + })); + }, + + + /** + If a relationship was originally populated by the adapter as a link + (as opposed to a list of IDs), this method is called when the + relationship is fetched. + + The link (which is usually a URL) is passed through unchanged, so the + adapter can make whatever request it wants. + + The usual use-case is for the server to register a URL as a link, and + then use that URL in the future to make a request for the relationship. + + @method findHasMany + @private + @param {DS.Model} owner + @param {any} link + @param {String or subclass of DS.Model} type + @return {Promise} promise + */ + findHasMany: function(owner, link, type) { + var adapter = this.adapterFor(owner.constructor); + + Ember.assert("You tried to load a hasMany relationship but you have no adapter (for " + owner.constructor + ")", adapter); + Ember.assert("You tried to load a hasMany relationship from a specified `link` in the original payload but your adapter does not implement `findHasMany`", typeof adapter.findHasMany === 'function'); + + return _findHasMany(adapter, this, owner, link, type); + }, + + /** + @method findBelongsTo + @private + @param {DS.Model} owner + @param {any} link + @param {Relationship} relationship + @return {Promise} promise + */ + findBelongsTo: function(owner, link, relationship) { + var adapter = this.adapterFor(owner.constructor); + + Ember.assert("You tried to load a belongsTo relationship but you have no adapter (for " + owner.constructor + ")", adapter); + Ember.assert("You tried to load a belongsTo relationship from a specified `link` in the original payload but your adapter does not implement `findBelongsTo`", typeof adapter.findBelongsTo === 'function'); + + return _findBelongsTo(adapter, this, owner, link, relationship); + }, + + /** + This method delegates a query to the adapter. This is the one place where + adapter-level semantics are exposed to the application. + + Exposing queries this way seems preferable to creating an abstract query + language for all server-side queries, and then require all adapters to + implement them. + + This method returns a promise, which is resolved with a `RecordArray` + once the server returns. + + @method findQuery + @private + @param {String or subclass of DS.Model} type + @param {any} query an opaque query to be used by the adapter + @return {Promise} promise + */ + findQuery: function(typeName, query) { + var type = this.modelFor(typeName); + var array = this.recordArrayManager + .createAdapterPopulatedRecordArray(type, query); + + var adapter = this.adapterFor(type); + + Ember.assert("You tried to load a query but you have no adapter (for " + type + ")", adapter); + Ember.assert("You tried to load a query but your adapter does not implement `findQuery`", typeof adapter.findQuery === 'function'); + + return promiseArray(_findQuery(adapter, this, type, query, array)); + }, + + /** + This method returns an array of all records adapter can find. + It triggers the adapter's `findAll` method to give it an opportunity to populate + the array with records of that type. + + @method findAll + @private + @param {String or subclass of DS.Model} type + @return {DS.AdapterPopulatedRecordArray} + */ + findAll: function(typeName) { + var type = this.modelFor(typeName); + + return this.fetchAll(type, this.all(type)); + }, + + /** + @method fetchAll + @private + @param {DS.Model} type + @param {DS.RecordArray} array + @return {Promise} promise + */ + fetchAll: function(type, array) { + var adapter = this.adapterFor(type); + var sinceToken = this.typeMapFor(type).metadata.since; + + set(array, 'isUpdating', true); + + Ember.assert("You tried to load all records but you have no adapter (for " + type + ")", adapter); + Ember.assert("You tried to load all records but your adapter does not implement `findAll`", typeof adapter.findAll === 'function'); + + return promiseArray(_findAll(adapter, this, type, sinceToken)); + }, + + /** + @method didUpdateAll + @param {DS.Model} type + */ + didUpdateAll: function(type) { + var findAllCache = this.typeMapFor(type).findAllCache; + set(findAllCache, 'isUpdating', false); + }, + + /** + This method returns a filtered array that contains all of the + known records for a given type in the store. + + Note that because it's just a filter, the result will contain any + locally created records of the type, however, it will not make a + request to the backend to retrieve additional records. If you + would like to request all the records from the backend please use + [store.find](#method_find). + + Also note that multiple calls to `all` for a given type will always + return the same `RecordArray`. + + Example + + ```javascript + var localPosts = store.all('post'); + ``` + + @method all + @param {String or subclass of DS.Model} type + @return {DS.RecordArray} + */ + all: function(typeName) { + var type = this.modelFor(typeName); + var typeMap = this.typeMapFor(type); + var findAllCache = typeMap.findAllCache; + + if (findAllCache) { return findAllCache; } + + var array = this.recordArrayManager.createRecordArray(type); + + typeMap.findAllCache = array; + return array; + }, + + + /** + This method unloads all of the known records for a given type. + + ```javascript + store.unloadAll('post'); + ``` + + @method unloadAll + @param {String or subclass of DS.Model} type + */ + unloadAll: function(type) { + var modelType = this.modelFor(type); + var typeMap = this.typeMapFor(modelType); + var records = typeMap.records.slice(); + var record; + + for (var i = 0; i < records.length; i++) { + record = records[i]; + record.unloadRecord(); + record.destroy(); // maybe within unloadRecord + } + + typeMap.findAllCache = null; + }, + + /** + Takes a type and filter function, and returns a live RecordArray that + remains up to date as new records are loaded into the store or created + locally. + + The filter function takes a materialized record, and returns true + if the record should be included in the filter and false if it should + not. + + Example + + ```javascript + store.filter('post', function(post) { + return post.get('unread'); + }); + ``` + + The filter function is called once on all records for the type when + it is created, and then once on each newly loaded or created record. + + If any of a record's properties change, or if it changes state, the + filter function will be invoked again to determine whether it should + still be in the array. + + Optionally you can pass a query, which is the equivalent of calling + [find](#method_find) with that same query, to fetch additional records + from the server. The results returned by the server could then appear + in the filter if they match the filter function. + + The query itself is not used to filter records, it's only sent to your + server for you to be able to do server-side filtering. The filter + function will be applied on the returned results regardless. + + Example + + ```javascript + store.filter('post', { unread: true }, function(post) { + return post.get('unread'); + }).then(function(unreadPosts) { + unreadPosts.get('length'); // 5 + var unreadPost = unreadPosts.objectAt(0); + unreadPost.set('unread', false); + unreadPosts.get('length'); // 4 + }); + ``` + + @method filter + @param {String or subclass of DS.Model} type + @param {Object} query optional query + @param {Function} filter + @return {DS.PromiseArray} + */ + filter: function(type, query, filter) { + var promise; + var length = arguments.length; + var array; + var hasQuery = length === 3; + + // allow an optional server query + if (hasQuery) { + promise = this.findQuery(type, query); + } else if (arguments.length === 2) { + filter = query; + } + + type = this.modelFor(type); + + if (hasQuery) { + array = this.recordArrayManager.createFilteredRecordArray(type, filter, query); + } else { + array = this.recordArrayManager.createFilteredRecordArray(type, filter); + } + + promise = promise || Promise.cast(array); + + + return promiseArray(promise.then(function() { + return array; + }, null, "DS: Store#filter of " + type)); + }, + + /** + This method returns if a certain record is already loaded + in the store. Use this function to know beforehand if a find() + will result in a request or that it will be a cache hit. + + Example + + ```javascript + store.recordIsLoaded('post', 1); // false + store.find('post', 1).then(function() { + store.recordIsLoaded('post', 1); // true + }); + ``` + + @method recordIsLoaded + @param {String or subclass of DS.Model} type + @param {string} id + @return {boolean} + */ + recordIsLoaded: function(type, id) { + if (!this.hasRecordForId(type, id)) { return false; } + return !get(this.recordForId(type, id), 'isEmpty'); + }, + + /** + This method returns the metadata for a specific type. + + @method metadataFor + @param {String or subclass of DS.Model} type + @return {object} + */ + metadataFor: function(type) { + type = this.modelFor(type); + return this.typeMapFor(type).metadata; + }, + + // ............ + // . UPDATING . + // ............ + + /** + If the adapter updates attributes or acknowledges creation + or deletion, the record will notify the store to update its + membership in any filters. + To avoid thrashing, this method is invoked only once per + + run loop per record. + + @method dataWasUpdated + @private + @param {Class} type + @param {DS.Model} record + */ + dataWasUpdated: function(type, record) { + this.recordArrayManager.recordDidChange(record); + }, + + // .............. + // . PERSISTING . + // .............. + + /** + This method is called by `record.save`, and gets passed a + resolver for the promise that `record.save` returns. + + It schedules saving to happen at the end of the run loop. + + @method scheduleSave + @private + @param {DS.Model} record + @param {Resolver} resolver + */ + scheduleSave: function(record, resolver) { + record.adapterWillCommit(); + this._pendingSave.push([record, resolver]); + once(this, 'flushPendingSave'); + }, + + /** + This method is called at the end of the run loop, and + flushes any records passed into `scheduleSave` + + @method flushPendingSave + @private + */ + flushPendingSave: function() { + var pending = this._pendingSave.slice(); + this._pendingSave = []; + + forEach(pending, function(tuple) { + var record = tuple[0], resolver = tuple[1]; + var adapter = this.adapterFor(record.constructor); + var operation; + + if (get(record, 'currentState.stateName') === 'root.deleted.saved') { + return resolver.resolve(record); + } else if (get(record, 'isNew')) { + operation = 'createRecord'; + } else if (get(record, 'isDeleted')) { + operation = 'deleteRecord'; + } else { + operation = 'updateRecord'; + } + + resolver.resolve(_commit(adapter, this, operation, record)); + }, this); + }, + + /** + This method is called once the promise returned by an + adapter's `createRecord`, `updateRecord` or `deleteRecord` + is resolved. + + If the data provides a server-generated ID, it will + update the record and the store's indexes. + + @method didSaveRecord + @private + @param {DS.Model} record the in-flight record + @param {Object} data optional data (see above) + */ + didSaveRecord: function(record, data) { + if (data) { + // normalize relationship IDs into records + data = normalizeRelationships(this, record.constructor, data, record); + setupRelationships(this, record, data); + + this.updateId(record, data); + } + + record.adapterDidCommit(data); + }, + + /** + This method is called once the promise returned by an + adapter's `createRecord`, `updateRecord` or `deleteRecord` + is rejected with a `DS.InvalidError`. + + @method recordWasInvalid + @private + @param {DS.Model} record + @param {Object} errors + */ + recordWasInvalid: function(record, errors) { + record.adapterDidInvalidate(errors); + }, + + /** + This method is called once the promise returned by an + adapter's `createRecord`, `updateRecord` or `deleteRecord` + is rejected (with anything other than a `DS.InvalidError`). + + @method recordWasError + @private + @param {DS.Model} record + */ + recordWasError: function(record) { + record.adapterDidError(); + }, + + /** + When an adapter's `createRecord`, `updateRecord` or `deleteRecord` + resolves with data, this method extracts the ID from the supplied + data. + + @method updateId + @private + @param {DS.Model} record + @param {Object} data + */ + updateId: function(record, data) { + var oldId = get(record, 'id'); + var id = coerceId(data.id); + + Ember.assert("An adapter cannot assign a new id to a record that already has an id. " + record + " had id: " + oldId + " and you tried to update it with " + id + ". This likely happened because your server returned data in response to a find or update that had a different id than the one you sent.", oldId === null || id === oldId); + + this.typeMapFor(record.constructor).idToRecord[id] = record; + + set(record, 'id', id); + }, + + /** + Returns a map of IDs to client IDs for a given type. + + @method typeMapFor + @private + @param {subclass of DS.Model} type + @return {Object} typeMap + */ + typeMapFor: function(type) { + var typeMaps = get(this, 'typeMaps'); + var guid = Ember.guidFor(type); + var typeMap; + + typeMap = typeMaps[guid]; + + if (typeMap) { return typeMap; } + + typeMap = { + idToRecord: Ember.create(null), + records: [], + metadata: Ember.create(null), + type: type + }; + + typeMaps[guid] = typeMap; + + return typeMap; + }, + + // ................ + // . LOADING DATA . + // ................ + + /** + This internal method is used by `push`. + + @method _load + @private + @param {String or subclass of DS.Model} type + @param {Object} data + @param {Boolean} partial the data should be merged into + the existing data, not replace it. + */ + _load: function(type, data, partial) { + var id = coerceId(data.id); + var record = this.recordForId(type, id); + + record.setupData(data, partial); + this.recordArrayManager.recordDidChange(record); + + return record; + }, + + /** + Returns a model class for a particular key. Used by + methods that take a type key (like `find`, `createRecord`, + etc.) + + @method modelFor + @param {String or subclass of DS.Model} key + @return {subclass of DS.Model} + */ + modelFor: function(key) { + var factory; + + if (typeof key === 'string') { + factory = this.modelFactoryFor(key); + if (!factory) { + throw new Ember.Error("No model was found for '" + key + "'"); + } + factory.typeKey = factory.typeKey || this._normalizeTypeKey(key); + } else { + // A factory already supplied. Ensure it has a normalized key. + factory = key; + if (factory.typeKey) { + factory.typeKey = this._normalizeTypeKey(factory.typeKey); + } + } + + factory.store = this; + return factory; + }, + + modelFactoryFor: function(key){ + return this.container.lookupFactory('model:' + key); + }, + + /** + Push some data for a given type into the store. + + This method expects normalized data: + + * The ID is a key named `id` (an ID is mandatory) + * The names of attributes are the ones you used in + your model's `DS.attr`s. + * Your relationships must be: + * represented as IDs or Arrays of IDs + * represented as model instances + * represented as URLs, under the `links` key + + For this model: + + ```js + App.Person = DS.Model.extend({ + firstName: DS.attr(), + lastName: DS.attr(), + + children: DS.hasMany('person') + }); + ``` + + To represent the children as IDs: + + ```js + { + id: 1, + firstName: "Tom", + lastName: "Dale", + children: [1, 2, 3] + } + ``` + + To represent the children relationship as a URL: + + ```js + { + id: 1, + firstName: "Tom", + lastName: "Dale", + links: { + children: "/people/1/children" + } + } + ``` + + If you're streaming data or implementing an adapter, + make sure that you have converted the incoming data + into this form. + + This method can be used both to push in brand new + records, as well as to update existing records. + + @method push + @param {String or subclass of DS.Model} type + @param {Object} data + @return {DS.Model} the record that was created or + updated. + */ + push: function(typeName, data, _partial) { + // _partial is an internal param used by `update`. + // If passed, it means that the data should be + // merged into the existing data, not replace it. + Ember.assert("Expected an object as `data` in a call to `push`/`update` for " + typeName + " , but was " + data, Ember.typeOf(data) === 'object'); + Ember.assert("You must include an `id` for " + typeName + " in an object passed to `push`/`update`", data.id != null && data.id !== ''); + + var type = this.modelFor(typeName); + var filter = Ember.EnumerableUtils.filter; + + // If the payload contains relationships that are specified as + // IDs, normalizeRelationships will convert them into DS.Model instances + // (possibly unloaded) before we push the payload into the + // store. + + data = normalizeRelationships(this, type, data); + + Ember.warn("The payload for '" + typeName + "' contains these unknown keys: " + + Ember.inspect(filter(Ember.keys(data), function(key) { + return !get(type, 'fields').has(key) && key !== 'id' && key !== 'links'; + })) + ". Make sure they've been defined in your model.", + filter(Ember.keys(data), function(key) { + return !get(type, 'fields').has(key) && key !== 'id' && key !== 'links'; + }).length === 0 + ); + + // Actually load the record into the store. + + this._load(type, data, _partial); + + var record = this.recordForId(type, data.id); + + // Now that the pushed record as well as any related records + // are in the store, create the data structures used to track + // relationships. + setupRelationships(this, record, data); + + return record; + }, + + /** + Push some raw data into the store. + + This method can be used both to push in brand new + records, as well as to update existing records. You + can push in more than one type of object at once. + All objects should be in the format expected by the + serializer. + + ```js + App.ApplicationSerializer = DS.ActiveModelSerializer; + + var pushData = { + posts: [ + {id: 1, post_title: "Great post", comment_ids: [2]} + ], + comments: [ + {id: 2, comment_body: "Insightful comment"} + ] + } + + store.pushPayload(pushData); + ``` + + By default, the data will be deserialized using a default + serializer (the application serializer if it exists). + + Alternatively, `pushPayload` will accept a model type which + will determine which serializer will process the payload. + However, the serializer itself (processing this data via + `normalizePayload`) will not know which model it is + deserializing. + + ```js + App.ApplicationSerializer = DS.ActiveModelSerializer; + App.PostSerializer = DS.JSONSerializer; + store.pushPayload('comment', pushData); // Will use the ApplicationSerializer + store.pushPayload('post', pushData); // Will use the PostSerializer + ``` + + @method pushPayload + @param {String} type Optionally, a model used to determine which serializer will be used + @param {Object} payload + */ + pushPayload: function (type, inputPayload) { + var serializer; + var payload; + if (!inputPayload) { + payload = type; + serializer = defaultSerializer(this.container); + Ember.assert("You cannot use `store#pushPayload` without a type unless your default serializer defines `pushPayload`", typeof serializer.pushPayload === 'function'); + } else { + payload = inputPayload; + serializer = this.serializerFor(type); + } + serializer.pushPayload(this, payload); + }, + + /** + `normalize` converts a json payload into the normalized form that + [push](#method_push) expects. + + Example + + ```js + socket.on('message', function(message) { + var modelName = message.model; + var data = message.data; + store.push(modelName, store.normalize(modelName, data)); + }); + ``` + + @method normalize + @param {String} type The name of the model type for this payload + @param {Object} payload + @return {Object} The normalized payload + */ + normalize: function (type, payload) { + var serializer = this.serializerFor(type); + var model = this.modelFor(type); + return serializer.normalize(model, payload); + }, + + /** + Update existing records in the store. Unlike [push](#method_push), + update will merge the new data properties with the existing + properties. This makes it safe to use with a subset of record + attributes. This method expects normalized data. + + `update` is useful if your app broadcasts partial updates to + records. + + ```js + App.Person = DS.Model.extend({ + firstName: DS.attr('string'), + lastName: DS.attr('string') + }); + + store.get('person', 1).then(function(tom) { + tom.get('firstName'); // Tom + tom.get('lastName'); // Dale + + var updateEvent = {id: 1, firstName: "TomHuda"}; + store.update('person', updateEvent); + + tom.get('firstName'); // TomHuda + tom.get('lastName'); // Dale + }); + ``` + + @method update + @param {String} type + @param {Object} data + @return {DS.Model} the record that was updated. + */ + update: function(type, data) { + return this.push(type, data, true); + }, + + /** + If you have an Array of normalized data to push, + you can call `pushMany` with the Array, and it will + call `push` repeatedly for you. + + @method pushMany + @param {String or subclass of DS.Model} type + @param {Array} datas + @return {Array} + */ + pushMany: function(type, datas) { + var length = datas.length; + var result = new Array(length); + + for (var i = 0; i < length; i++) { + result[i] = this.push(type, datas[i]); + } + + return result; + }, + + /** + If you have some metadata to set for a type + you can call `metaForType`. + + @method metaForType + @param {String or subclass of DS.Model} type + @param {Object} metadata + */ + metaForType: function(typeName, metadata) { + var type = this.modelFor(typeName); + + Ember.merge(this.typeMapFor(type).metadata, metadata); + }, + + /** + Build a brand new record for a given type, ID, and + initial data. + + @method buildRecord + @private + @param {subclass of DS.Model} type + @param {String} id + @param {Object} data + @return {DS.Model} record + */ + buildRecord: function(type, id, data) { + var typeMap = this.typeMapFor(type); + var idToRecord = typeMap.idToRecord; + + Ember.assert('The id ' + id + ' has already been used with another record of type ' + type.toString() + '.', !id || !idToRecord[id]); + Ember.assert("`" + Ember.inspect(type)+ "` does not appear to be an ember-data model", (typeof type._create === 'function') ); + + // lookupFactory should really return an object that creates + // instances with the injections applied + var record = type._create({ + id: id, + store: this, + container: this.container + }); + + if (data) { + record.setupData(data); + } + + // if we're creating an item, this process will be done + // later, once the object has been persisted. + if (id) { + idToRecord[id] = record; + } + + typeMap.records.push(record); + + return record; + }, + + // ............... + // . DESTRUCTION . + // ............... + + /** + When a record is destroyed, this un-indexes it and + removes it from any record arrays so it can be GCed. + + @method dematerializeRecord + @private + @param {DS.Model} record + */ + dematerializeRecord: function(record) { + var type = record.constructor; + var typeMap = this.typeMapFor(type); + var id = get(record, 'id'); + + record.updateRecordArrays(); + + if (id) { + delete typeMap.idToRecord[id]; + } + + var loc = indexOf(typeMap.records, record); + typeMap.records.splice(loc, 1); + }, + + // ...................... + // . PER-TYPE ADAPTERS + // ...................... + + /** + Returns the adapter for a given type. + + @method adapterFor + @private + @param {subclass of DS.Model} type + @return DS.Adapter + */ + adapterFor: function(type) { + var container = this.container, adapter; + + if (container) { + adapter = container.lookup('adapter:' + type.typeKey) || container.lookup('adapter:application'); + } + + return adapter || get(this, 'defaultAdapter'); + }, + + // .............................. + // . RECORD CHANGE NOTIFICATION . + // .............................. + + /** + Returns an instance of the serializer for a given type. For + example, `serializerFor('person')` will return an instance of + `App.PersonSerializer`. + + If no `App.PersonSerializer` is found, this method will look + for an `App.ApplicationSerializer` (the default serializer for + your entire application). + + If no `App.ApplicationSerializer` is found, it will fall back + to an instance of `DS.JSONSerializer`. + + @method serializerFor + @private + @param {String} type the record to serialize + @return {DS.Serializer} + */ + serializerFor: function(type) { + type = this.modelFor(type); + var adapter = this.adapterFor(type); + + return serializerFor(this.container, type.typeKey, adapter && adapter.defaultSerializer); + }, + + willDestroy: function() { + var typeMaps = this.typeMaps; + var keys = Ember.keys(typeMaps); + + var types = map(keys, byType); + + this.recordArrayManager.destroy(); + + forEach(types, this.unloadAll, this); + + function byType(entry) { + return typeMaps[entry]['type']; + } + + }, + + /** + All typeKeys are camelCase internally. Changing this function may + require changes to other normalization hooks (such as typeForRoot). + + @method _normalizeTypeKey + @private + @param {String} type + @return {String} if the adapter can generate one, an ID + */ + _normalizeTypeKey: function(key) { + return camelize(singularize(key)); + } + }); + + + function normalizeRelationships(store, type, data, record) { + type.eachRelationship(function(key, relationship) { + var kind = relationship.kind; + var value = data[key]; + if (kind === 'belongsTo') { + deserializeRecordId(store, data, key, relationship, value); + } else if (kind === 'hasMany') { + deserializeRecordIds(store, data, key, relationship, value); + } + }); + + return data; + } + + function deserializeRecordId(store, data, key, relationship, id) { + if (!Model) { Model = requireModule("ember-data/system/model")["Model"]; } + if (isNone(id) || id instanceof Model) { + return; + } + Ember.assert("A " + relationship.parentType + " record was pushed into the store with the value of " + key + " being " + Ember.inspect(id) + ", but " + key + " is a belongsTo relationship so the value must not be an array. You should probably check your data payload or serializer.", !Ember.isArray(id)); + + var type; + + if (typeof id === 'number' || typeof id === 'string') { + type = typeFor(relationship, key, data); + data[key] = store.recordForId(type, id); + } else if (typeof id === 'object') { + // polymorphic + data[key] = store.recordForId(id.type, id.id); + } + } + + function typeFor(relationship, key, data) { + if (relationship.options.polymorphic) { + return data[key + "Type"]; + } else { + return relationship.type; + } + } + + function deserializeRecordIds(store, data, key, relationship, ids) { + if (isNone(ids)) { + return; + } + + Ember.assert("A " + relationship.parentType + " record was pushed into the store with the value of " + key + " being '" + Ember.inspect(ids) + "', but " + key + " is a hasMany relationship so the value must be an array. You should probably check your data payload or serializer.", Ember.isArray(ids)); + for (var i=0, l=ids.length; i 'kine' + inflector.singularize('kine'); //=> 'cow' + ``` + + Creating an inflector and adding rules later. + + ```javascript + var inflector = Ember.Inflector.inflector; + + inflector.pluralize('advice'); // => 'advices' + inflector.uncountable('advice'); + inflector.pluralize('advice'); // => 'advice' + + inflector.pluralize('formula'); // => 'formulas' + inflector.irregular('formula', 'formulae'); + inflector.pluralize('formula'); // => 'formulae' + + // you would not need to add these as they are the default rules + inflector.plural(/$/, 's'); + inflector.singular(/s$/i, ''); + ``` + + Creating an inflector with a nondefault ruleset. + + ```javascript + var rules = { + plurals: [ /$/, 's' ], + singular: [ /\s$/, '' ], + irregularPairs: [ + [ 'cow', 'kine' ] + ], + uncountable: [ 'fish' ] + }; + + var inflector = new Ember.Inflector(rules); + ``` + + @class Inflector + @namespace Ember + */ + function Inflector(ruleSet) { + ruleSet = ruleSet || {}; + ruleSet.uncountable = ruleSet.uncountable || makeDictionary(); + ruleSet.irregularPairs = ruleSet.irregularPairs || makeDictionary(); + + var rules = this.rules = { + plurals: ruleSet.plurals || [], + singular: ruleSet.singular || [], + irregular: makeDictionary(), + irregularInverse: makeDictionary(), + uncountable: makeDictionary() + }; + + loadUncountable(rules, ruleSet.uncountable); + loadIrregular(rules, ruleSet.irregularPairs); + + this.enableCache(); + } + + if (!Object.create && !Object.create(null).hasOwnProperty) { + throw new Error("This browser does not support Object.create(null), please polyfil with es5-sham: http://git.io/yBU2rg"); + } + + function makeDictionary() { + var cache = Object.create(null); + cache['_dict'] = null; + delete cache['_dict']; + return cache; + } + + Inflector.prototype = { + /** + @public + + As inflections can be costly, and commonly the same subset of words are repeatedly + inflected an optional cache is provided. + + @method enableCache + */ + enableCache: function() { + this.purgeCache(); + + this.singularize = function(word) { + this._cacheUsed = true; + return this._sCache[word] || (this._sCache[word] = this._singularize(word)); + }; + + this.pluralize = function(word) { + this._cacheUsed = true; + return this._pCache[word] || (this._pCache[word] = this._pluralize(word)); + }; + }, + + /** + @public + + @method purgedCache + */ + purgeCache: function() { + this._cacheUsed = false; + this._sCache = makeDictionary(); + this._pCache = makeDictionary(); + }, + + /** + @public + disable caching + + @method disableCache; + */ + disableCache: function() { + this._sCache = null; + this._pCache = null; + this.singularize = function(word) { + return this._singularize(word); + }; + + this.pluralize = function(word) { + return this._pluralize(word); + }; + }, + + /** + @method plural + @param {RegExp} regex + @param {String} string + */ + plural: function(regex, string) { + if (this._cacheUsed) { this.purgeCache(); } + this.rules.plurals.push([regex, string.toLowerCase()]); + }, + + /** + @method singular + @param {RegExp} regex + @param {String} string + */ + singular: function(regex, string) { + if (this._cacheUsed) { this.purgeCache(); } + this.rules.singular.push([regex, string.toLowerCase()]); + }, + + /** + @method uncountable + @param {String} regex + */ + uncountable: function(string) { + if (this._cacheUsed) { this.purgeCache(); } + loadUncountable(this.rules, [string.toLowerCase()]); + }, + + /** + @method irregular + @param {String} singular + @param {String} plural + */ + irregular: function (singular, plural) { + if (this._cacheUsed) { this.purgeCache(); } + loadIrregular(this.rules, [[singular, plural]]); + }, + + /** + @method pluralize + @param {String} word + */ + pluralize: function(word) { + return this._pluralize(word); + }, + + _pluralize: function(word) { + return this.inflect(word, this.rules.plurals, this.rules.irregular); + }, + /** + @method singularize + @param {String} word + */ + singularize: function(word) { + return this._singularize(word); + }, + + _singularize: function(word) { + return this.inflect(word, this.rules.singular, this.rules.irregularInverse); + }, + + /** + @protected + + @method inflect + @param {String} word + @param {Object} typeRules + @param {Object} irregular + */ + inflect: function(word, typeRules, irregular) { + var inflection, substitution, result, lowercase, wordSplit, + firstPhrase, lastWord, isBlank, isCamelized, isUncountable, + isIrregular, isIrregularInverse, rule; + + isBlank = BLANK_REGEX.test(word); + isCamelized = CAMELIZED_REGEX.test(word); + firstPhrase = ""; + + if (isBlank) { + return word; + } + + lowercase = word.toLowerCase(); + wordSplit = LAST_WORD_DASHED_REGEX.exec(word) || LAST_WORD_CAMELIZED_REGEX.exec(word); + if (wordSplit){ + firstPhrase = wordSplit[1]; + lastWord = wordSplit[2].toLowerCase(); + } + + isUncountable = this.rules.uncountable[lowercase] || this.rules.uncountable[lastWord]; + + if (isUncountable) { + return word; + } + + isIrregular = irregular && (irregular[lowercase] || irregular[lastWord]); + + if (isIrregular) { + if (irregular[lowercase]){ + return isIrregular; + } + else { + isIrregular = (isCamelized) ? isIrregular.capitalize() : isIrregular; + return firstPhrase + isIrregular; + } + } + + for (var i = typeRules.length, min = 0; i > min; i--) { + inflection = typeRules[i-1]; + rule = inflection[0]; + + if (rule.test(word)) { + break; + } + } + + inflection = inflection || []; + + rule = inflection[0]; + substitution = inflection[1]; + + result = word.replace(rule, substitution); + + return result; + } + }; + + __exports__["default"] = Inflector; + }); +enifed("ember-inflector/system/string", + ["./inflector","exports"], + function(__dependency1__, __exports__) { + "use strict"; + var Inflector = __dependency1__["default"]; + + function pluralize(word) { + return Inflector.inflector.pluralize(word); + } + + function singularize(word) { + return Inflector.inflector.singularize(word); + } + + __exports__.pluralize = pluralize; + __exports__.singularize = singularize; + }); + global.DS = requireModule('ember-data')['default']; + })(this); \ No newline at end of file diff --git a/imdb-lookup/js/libs/handlebars-v2.0.0.js b/imdb-lookup/js/libs/handlebars-v2.0.0.js new file mode 100644 index 0000000..f826bbf --- /dev/null +++ b/imdb-lookup/js/libs/handlebars-v2.0.0.js @@ -0,0 +1,3079 @@ +/*! + + handlebars v2.0.0 + +Copyright (C) 2011-2014 by Yehuda Katz + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + +@license +*/ +/* exported Handlebars */ +(function (root, factory) { + if (typeof define === 'function' && define.amd) { + define([], factory); + } else if (typeof exports === 'object') { + module.exports = factory(); + } else { + root.Handlebars = root.Handlebars || factory(); + } +}(this, function () { +// handlebars/safe-string.js +var __module4__ = (function() { + "use strict"; + var __exports__; + // Build out our basic SafeString type + function SafeString(string) { + this.string = string; + } + + SafeString.prototype.toString = function() { + return "" + this.string; + }; + + __exports__ = SafeString; + return __exports__; +})(); + +// handlebars/utils.js +var __module3__ = (function(__dependency1__) { + "use strict"; + var __exports__ = {}; + /*jshint -W004 */ + var SafeString = __dependency1__; + + var escape = { + "&": "&", + "<": "<", + ">": ">", + '"': """, + "'": "'", + "`": "`" + }; + + var badChars = /[&<>"'`]/g; + var possible = /[&<>"'`]/; + + function escapeChar(chr) { + return escape[chr]; + } + + function extend(obj /* , ...source */) { + for (var i = 1; i < arguments.length; i++) { + for (var key in arguments[i]) { + if (Object.prototype.hasOwnProperty.call(arguments[i], key)) { + obj[key] = arguments[i][key]; + } + } + } + + return obj; + } + + __exports__.extend = extend;var toString = Object.prototype.toString; + __exports__.toString = toString; + // Sourced from lodash + // https://github.com/bestiejs/lodash/blob/master/LICENSE.txt + var isFunction = function(value) { + return typeof value === 'function'; + }; + // fallback for older versions of Chrome and Safari + /* istanbul ignore next */ + if (isFunction(/x/)) { + isFunction = function(value) { + return typeof value === 'function' && toString.call(value) === '[object Function]'; + }; + } + var isFunction; + __exports__.isFunction = isFunction; + /* istanbul ignore next */ + var isArray = Array.isArray || function(value) { + return (value && typeof value === 'object') ? toString.call(value) === '[object Array]' : false; + }; + __exports__.isArray = isArray; + + function escapeExpression(string) { + // don't escape SafeStrings, since they're already safe + if (string instanceof SafeString) { + return string.toString(); + } else if (string == null) { + return ""; + } else if (!string) { + return string + ''; + } + + // Force a string conversion as this will be done by the append regardless and + // the regex test will do this transparently behind the scenes, causing issues if + // an object's to string has escaped characters in it. + string = "" + string; + + if(!possible.test(string)) { return string; } + return string.replace(badChars, escapeChar); + } + + __exports__.escapeExpression = escapeExpression;function isEmpty(value) { + if (!value && value !== 0) { + return true; + } else if (isArray(value) && value.length === 0) { + return true; + } else { + return false; + } + } + + __exports__.isEmpty = isEmpty;function appendContextPath(contextPath, id) { + return (contextPath ? contextPath + '.' : '') + id; + } + + __exports__.appendContextPath = appendContextPath; + return __exports__; +})(__module4__); + +// handlebars/exception.js +var __module5__ = (function() { + "use strict"; + var __exports__; + + var errorProps = ['description', 'fileName', 'lineNumber', 'message', 'name', 'number', 'stack']; + + function Exception(message, node) { + var line; + if (node && node.firstLine) { + line = node.firstLine; + + message += ' - ' + line + ':' + node.firstColumn; + } + + var tmp = Error.prototype.constructor.call(this, message); + + // Unfortunately errors are not enumerable in Chrome (at least), so `for prop in tmp` doesn't work. + for (var idx = 0; idx < errorProps.length; idx++) { + this[errorProps[idx]] = tmp[errorProps[idx]]; + } + + if (line) { + this.lineNumber = line; + this.column = node.firstColumn; + } + } + + Exception.prototype = new Error(); + + __exports__ = Exception; + return __exports__; +})(); + +// handlebars/base.js +var __module2__ = (function(__dependency1__, __dependency2__) { + "use strict"; + var __exports__ = {}; + var Utils = __dependency1__; + var Exception = __dependency2__; + + var VERSION = "2.0.0"; + __exports__.VERSION = VERSION;var COMPILER_REVISION = 6; + __exports__.COMPILER_REVISION = COMPILER_REVISION; + var REVISION_CHANGES = { + 1: '<= 1.0.rc.2', // 1.0.rc.2 is actually rev2 but doesn't report it + 2: '== 1.0.0-rc.3', + 3: '== 1.0.0-rc.4', + 4: '== 1.x.x', + 5: '== 2.0.0-alpha.x', + 6: '>= 2.0.0-beta.1' + }; + __exports__.REVISION_CHANGES = REVISION_CHANGES; + var isArray = Utils.isArray, + isFunction = Utils.isFunction, + toString = Utils.toString, + objectType = '[object Object]'; + + function HandlebarsEnvironment(helpers, partials) { + this.helpers = helpers || {}; + this.partials = partials || {}; + + registerDefaultHelpers(this); + } + + __exports__.HandlebarsEnvironment = HandlebarsEnvironment;HandlebarsEnvironment.prototype = { + constructor: HandlebarsEnvironment, + + logger: logger, + log: log, + + registerHelper: function(name, fn) { + if (toString.call(name) === objectType) { + if (fn) { throw new Exception('Arg not supported with multiple helpers'); } + Utils.extend(this.helpers, name); + } else { + this.helpers[name] = fn; + } + }, + unregisterHelper: function(name) { + delete this.helpers[name]; + }, + + registerPartial: function(name, partial) { + if (toString.call(name) === objectType) { + Utils.extend(this.partials, name); + } else { + this.partials[name] = partial; + } + }, + unregisterPartial: function(name) { + delete this.partials[name]; + } + }; + + function registerDefaultHelpers(instance) { + instance.registerHelper('helperMissing', function(/* [args, ]options */) { + if(arguments.length === 1) { + // A missing field in a {{foo}} constuct. + return undefined; + } else { + // Someone is actually trying to call something, blow up. + throw new Exception("Missing helper: '" + arguments[arguments.length-1].name + "'"); + } + }); + + instance.registerHelper('blockHelperMissing', function(context, options) { + var inverse = options.inverse, + fn = options.fn; + + if(context === true) { + return fn(this); + } else if(context === false || context == null) { + return inverse(this); + } else if (isArray(context)) { + if(context.length > 0) { + if (options.ids) { + options.ids = [options.name]; + } + + return instance.helpers.each(context, options); + } else { + return inverse(this); + } + } else { + if (options.data && options.ids) { + var data = createFrame(options.data); + data.contextPath = Utils.appendContextPath(options.data.contextPath, options.name); + options = {data: data}; + } + + return fn(context, options); + } + }); + + instance.registerHelper('each', function(context, options) { + if (!options) { + throw new Exception('Must pass iterator to #each'); + } + + var fn = options.fn, inverse = options.inverse; + var i = 0, ret = "", data; + + var contextPath; + if (options.data && options.ids) { + contextPath = Utils.appendContextPath(options.data.contextPath, options.ids[0]) + '.'; + } + + if (isFunction(context)) { context = context.call(this); } + + if (options.data) { + data = createFrame(options.data); + } + + if(context && typeof context === 'object') { + if (isArray(context)) { + for(var j = context.length; i 0) { + throw new Exception("Invalid path: " + original, this); + } else if (part === "..") { + depth++; + depthString += '../'; + } else { + this.isScoped = true; + } + } else { + dig.push(part); + } + } + + this.original = original; + this.parts = dig; + this.string = dig.join('.'); + this.depth = depth; + this.idName = depthString + this.string; + + // an ID is simple if it only has one part, and that part is not + // `..` or `this`. + this.isSimple = parts.length === 1 && !this.isScoped && depth === 0; + + this.stringModeValue = this.string; + }, + + PartialNameNode: function(name, locInfo) { + LocationInfo.call(this, locInfo); + this.type = "PARTIAL_NAME"; + this.name = name.original; + }, + + DataNode: function(id, locInfo) { + LocationInfo.call(this, locInfo); + this.type = "DATA"; + this.id = id; + this.stringModeValue = id.stringModeValue; + this.idName = '@' + id.stringModeValue; + }, + + StringNode: function(string, locInfo) { + LocationInfo.call(this, locInfo); + this.type = "STRING"; + this.original = + this.string = + this.stringModeValue = string; + }, + + NumberNode: function(number, locInfo) { + LocationInfo.call(this, locInfo); + this.type = "NUMBER"; + this.original = + this.number = number; + this.stringModeValue = Number(number); + }, + + BooleanNode: function(bool, locInfo) { + LocationInfo.call(this, locInfo); + this.type = "BOOLEAN"; + this.bool = bool; + this.stringModeValue = bool === "true"; + }, + + CommentNode: function(comment, locInfo) { + LocationInfo.call(this, locInfo); + this.type = "comment"; + this.comment = comment; + + this.strip = { + inlineStandalone: true + }; + } + }; + + + // Must be exported as an object rather than the root of the module as the jison lexer + // most modify the object to operate properly. + __exports__ = AST; + return __exports__; +})(__module5__); + +// handlebars/compiler/parser.js +var __module9__ = (function() { + "use strict"; + var __exports__; + /* jshint ignore:start */ + /* istanbul ignore next */ + /* Jison generated parser */ + var handlebars = (function(){ + var parser = {trace: function trace() { }, + yy: {}, + symbols_: {"error":2,"root":3,"program":4,"EOF":5,"program_repetition0":6,"statement":7,"mustache":8,"block":9,"rawBlock":10,"partial":11,"CONTENT":12,"COMMENT":13,"openRawBlock":14,"END_RAW_BLOCK":15,"OPEN_RAW_BLOCK":16,"sexpr":17,"CLOSE_RAW_BLOCK":18,"openBlock":19,"block_option0":20,"closeBlock":21,"openInverse":22,"block_option1":23,"OPEN_BLOCK":24,"CLOSE":25,"OPEN_INVERSE":26,"inverseAndProgram":27,"INVERSE":28,"OPEN_ENDBLOCK":29,"path":30,"OPEN":31,"OPEN_UNESCAPED":32,"CLOSE_UNESCAPED":33,"OPEN_PARTIAL":34,"partialName":35,"param":36,"partial_option0":37,"partial_option1":38,"sexpr_repetition0":39,"sexpr_option0":40,"dataName":41,"STRING":42,"NUMBER":43,"BOOLEAN":44,"OPEN_SEXPR":45,"CLOSE_SEXPR":46,"hash":47,"hash_repetition_plus0":48,"hashSegment":49,"ID":50,"EQUALS":51,"DATA":52,"pathSegments":53,"SEP":54,"$accept":0,"$end":1}, + terminals_: {2:"error",5:"EOF",12:"CONTENT",13:"COMMENT",15:"END_RAW_BLOCK",16:"OPEN_RAW_BLOCK",18:"CLOSE_RAW_BLOCK",24:"OPEN_BLOCK",25:"CLOSE",26:"OPEN_INVERSE",28:"INVERSE",29:"OPEN_ENDBLOCK",31:"OPEN",32:"OPEN_UNESCAPED",33:"CLOSE_UNESCAPED",34:"OPEN_PARTIAL",42:"STRING",43:"NUMBER",44:"BOOLEAN",45:"OPEN_SEXPR",46:"CLOSE_SEXPR",50:"ID",51:"EQUALS",52:"DATA",54:"SEP"}, + productions_: [0,[3,2],[4,1],[7,1],[7,1],[7,1],[7,1],[7,1],[7,1],[10,3],[14,3],[9,4],[9,4],[19,3],[22,3],[27,2],[21,3],[8,3],[8,3],[11,5],[11,4],[17,3],[17,1],[36,1],[36,1],[36,1],[36,1],[36,1],[36,3],[47,1],[49,3],[35,1],[35,1],[35,1],[41,2],[30,1],[53,3],[53,1],[6,0],[6,2],[20,0],[20,1],[23,0],[23,1],[37,0],[37,1],[38,0],[38,1],[39,0],[39,2],[40,0],[40,1],[48,1],[48,2]], + performAction: function anonymous(yytext,yyleng,yylineno,yy,yystate,$$,_$) { + + var $0 = $$.length - 1; + switch (yystate) { + case 1: yy.prepareProgram($$[$0-1].statements, true); return $$[$0-1]; + break; + case 2:this.$ = new yy.ProgramNode(yy.prepareProgram($$[$0]), {}, this._$); + break; + case 3:this.$ = $$[$0]; + break; + case 4:this.$ = $$[$0]; + break; + case 5:this.$ = $$[$0]; + break; + case 6:this.$ = $$[$0]; + break; + case 7:this.$ = new yy.ContentNode($$[$0], this._$); + break; + case 8:this.$ = new yy.CommentNode($$[$0], this._$); + break; + case 9:this.$ = new yy.RawBlockNode($$[$0-2], $$[$0-1], $$[$0], this._$); + break; + case 10:this.$ = new yy.MustacheNode($$[$0-1], null, '', '', this._$); + break; + case 11:this.$ = yy.prepareBlock($$[$0-3], $$[$0-2], $$[$0-1], $$[$0], false, this._$); + break; + case 12:this.$ = yy.prepareBlock($$[$0-3], $$[$0-2], $$[$0-1], $$[$0], true, this._$); + break; + case 13:this.$ = new yy.MustacheNode($$[$0-1], null, $$[$0-2], yy.stripFlags($$[$0-2], $$[$0]), this._$); + break; + case 14:this.$ = new yy.MustacheNode($$[$0-1], null, $$[$0-2], yy.stripFlags($$[$0-2], $$[$0]), this._$); + break; + case 15:this.$ = { strip: yy.stripFlags($$[$0-1], $$[$0-1]), program: $$[$0] }; + break; + case 16:this.$ = {path: $$[$0-1], strip: yy.stripFlags($$[$0-2], $$[$0])}; + break; + case 17:this.$ = new yy.MustacheNode($$[$0-1], null, $$[$0-2], yy.stripFlags($$[$0-2], $$[$0]), this._$); + break; + case 18:this.$ = new yy.MustacheNode($$[$0-1], null, $$[$0-2], yy.stripFlags($$[$0-2], $$[$0]), this._$); + break; + case 19:this.$ = new yy.PartialNode($$[$0-3], $$[$0-2], $$[$0-1], yy.stripFlags($$[$0-4], $$[$0]), this._$); + break; + case 20:this.$ = new yy.PartialNode($$[$0-2], undefined, $$[$0-1], yy.stripFlags($$[$0-3], $$[$0]), this._$); + break; + case 21:this.$ = new yy.SexprNode([$$[$0-2]].concat($$[$0-1]), $$[$0], this._$); + break; + case 22:this.$ = new yy.SexprNode([$$[$0]], null, this._$); + break; + case 23:this.$ = $$[$0]; + break; + case 24:this.$ = new yy.StringNode($$[$0], this._$); + break; + case 25:this.$ = new yy.NumberNode($$[$0], this._$); + break; + case 26:this.$ = new yy.BooleanNode($$[$0], this._$); + break; + case 27:this.$ = $$[$0]; + break; + case 28:$$[$0-1].isHelper = true; this.$ = $$[$0-1]; + break; + case 29:this.$ = new yy.HashNode($$[$0], this._$); + break; + case 30:this.$ = [$$[$0-2], $$[$0]]; + break; + case 31:this.$ = new yy.PartialNameNode($$[$0], this._$); + break; + case 32:this.$ = new yy.PartialNameNode(new yy.StringNode($$[$0], this._$), this._$); + break; + case 33:this.$ = new yy.PartialNameNode(new yy.NumberNode($$[$0], this._$)); + break; + case 34:this.$ = new yy.DataNode($$[$0], this._$); + break; + case 35:this.$ = new yy.IdNode($$[$0], this._$); + break; + case 36: $$[$0-2].push({part: $$[$0], separator: $$[$0-1]}); this.$ = $$[$0-2]; + break; + case 37:this.$ = [{part: $$[$0]}]; + break; + case 38:this.$ = []; + break; + case 39:$$[$0-1].push($$[$0]); + break; + case 48:this.$ = []; + break; + case 49:$$[$0-1].push($$[$0]); + break; + case 52:this.$ = [$$[$0]]; + break; + case 53:$$[$0-1].push($$[$0]); + break; + } + }, + table: [{3:1,4:2,5:[2,38],6:3,12:[2,38],13:[2,38],16:[2,38],24:[2,38],26:[2,38],31:[2,38],32:[2,38],34:[2,38]},{1:[3]},{5:[1,4]},{5:[2,2],7:5,8:6,9:7,10:8,11:9,12:[1,10],13:[1,11],14:16,16:[1,20],19:14,22:15,24:[1,18],26:[1,19],28:[2,2],29:[2,2],31:[1,12],32:[1,13],34:[1,17]},{1:[2,1]},{5:[2,39],12:[2,39],13:[2,39],16:[2,39],24:[2,39],26:[2,39],28:[2,39],29:[2,39],31:[2,39],32:[2,39],34:[2,39]},{5:[2,3],12:[2,3],13:[2,3],16:[2,3],24:[2,3],26:[2,3],28:[2,3],29:[2,3],31:[2,3],32:[2,3],34:[2,3]},{5:[2,4],12:[2,4],13:[2,4],16:[2,4],24:[2,4],26:[2,4],28:[2,4],29:[2,4],31:[2,4],32:[2,4],34:[2,4]},{5:[2,5],12:[2,5],13:[2,5],16:[2,5],24:[2,5],26:[2,5],28:[2,5],29:[2,5],31:[2,5],32:[2,5],34:[2,5]},{5:[2,6],12:[2,6],13:[2,6],16:[2,6],24:[2,6],26:[2,6],28:[2,6],29:[2,6],31:[2,6],32:[2,6],34:[2,6]},{5:[2,7],12:[2,7],13:[2,7],16:[2,7],24:[2,7],26:[2,7],28:[2,7],29:[2,7],31:[2,7],32:[2,7],34:[2,7]},{5:[2,8],12:[2,8],13:[2,8],16:[2,8],24:[2,8],26:[2,8],28:[2,8],29:[2,8],31:[2,8],32:[2,8],34:[2,8]},{17:21,30:22,41:23,50:[1,26],52:[1,25],53:24},{17:27,30:22,41:23,50:[1,26],52:[1,25],53:24},{4:28,6:3,12:[2,38],13:[2,38],16:[2,38],24:[2,38],26:[2,38],28:[2,38],29:[2,38],31:[2,38],32:[2,38],34:[2,38]},{4:29,6:3,12:[2,38],13:[2,38],16:[2,38],24:[2,38],26:[2,38],28:[2,38],29:[2,38],31:[2,38],32:[2,38],34:[2,38]},{12:[1,30]},{30:32,35:31,42:[1,33],43:[1,34],50:[1,26],53:24},{17:35,30:22,41:23,50:[1,26],52:[1,25],53:24},{17:36,30:22,41:23,50:[1,26],52:[1,25],53:24},{17:37,30:22,41:23,50:[1,26],52:[1,25],53:24},{25:[1,38]},{18:[2,48],25:[2,48],33:[2,48],39:39,42:[2,48],43:[2,48],44:[2,48],45:[2,48],46:[2,48],50:[2,48],52:[2,48]},{18:[2,22],25:[2,22],33:[2,22],46:[2,22]},{18:[2,35],25:[2,35],33:[2,35],42:[2,35],43:[2,35],44:[2,35],45:[2,35],46:[2,35],50:[2,35],52:[2,35],54:[1,40]},{30:41,50:[1,26],53:24},{18:[2,37],25:[2,37],33:[2,37],42:[2,37],43:[2,37],44:[2,37],45:[2,37],46:[2,37],50:[2,37],52:[2,37],54:[2,37]},{33:[1,42]},{20:43,27:44,28:[1,45],29:[2,40]},{23:46,27:47,28:[1,45],29:[2,42]},{15:[1,48]},{25:[2,46],30:51,36:49,38:50,41:55,42:[1,52],43:[1,53],44:[1,54],45:[1,56],47:57,48:58,49:60,50:[1,59],52:[1,25],53:24},{25:[2,31],42:[2,31],43:[2,31],44:[2,31],45:[2,31],50:[2,31],52:[2,31]},{25:[2,32],42:[2,32],43:[2,32],44:[2,32],45:[2,32],50:[2,32],52:[2,32]},{25:[2,33],42:[2,33],43:[2,33],44:[2,33],45:[2,33],50:[2,33],52:[2,33]},{25:[1,61]},{25:[1,62]},{18:[1,63]},{5:[2,17],12:[2,17],13:[2,17],16:[2,17],24:[2,17],26:[2,17],28:[2,17],29:[2,17],31:[2,17],32:[2,17],34:[2,17]},{18:[2,50],25:[2,50],30:51,33:[2,50],36:65,40:64,41:55,42:[1,52],43:[1,53],44:[1,54],45:[1,56],46:[2,50],47:66,48:58,49:60,50:[1,59],52:[1,25],53:24},{50:[1,67]},{18:[2,34],25:[2,34],33:[2,34],42:[2,34],43:[2,34],44:[2,34],45:[2,34],46:[2,34],50:[2,34],52:[2,34]},{5:[2,18],12:[2,18],13:[2,18],16:[2,18],24:[2,18],26:[2,18],28:[2,18],29:[2,18],31:[2,18],32:[2,18],34:[2,18]},{21:68,29:[1,69]},{29:[2,41]},{4:70,6:3,12:[2,38],13:[2,38],16:[2,38],24:[2,38],26:[2,38],29:[2,38],31:[2,38],32:[2,38],34:[2,38]},{21:71,29:[1,69]},{29:[2,43]},{5:[2,9],12:[2,9],13:[2,9],16:[2,9],24:[2,9],26:[2,9],28:[2,9],29:[2,9],31:[2,9],32:[2,9],34:[2,9]},{25:[2,44],37:72,47:73,48:58,49:60,50:[1,74]},{25:[1,75]},{18:[2,23],25:[2,23],33:[2,23],42:[2,23],43:[2,23],44:[2,23],45:[2,23],46:[2,23],50:[2,23],52:[2,23]},{18:[2,24],25:[2,24],33:[2,24],42:[2,24],43:[2,24],44:[2,24],45:[2,24],46:[2,24],50:[2,24],52:[2,24]},{18:[2,25],25:[2,25],33:[2,25],42:[2,25],43:[2,25],44:[2,25],45:[2,25],46:[2,25],50:[2,25],52:[2,25]},{18:[2,26],25:[2,26],33:[2,26],42:[2,26],43:[2,26],44:[2,26],45:[2,26],46:[2,26],50:[2,26],52:[2,26]},{18:[2,27],25:[2,27],33:[2,27],42:[2,27],43:[2,27],44:[2,27],45:[2,27],46:[2,27],50:[2,27],52:[2,27]},{17:76,30:22,41:23,50:[1,26],52:[1,25],53:24},{25:[2,47]},{18:[2,29],25:[2,29],33:[2,29],46:[2,29],49:77,50:[1,74]},{18:[2,37],25:[2,37],33:[2,37],42:[2,37],43:[2,37],44:[2,37],45:[2,37],46:[2,37],50:[2,37],51:[1,78],52:[2,37],54:[2,37]},{18:[2,52],25:[2,52],33:[2,52],46:[2,52],50:[2,52]},{12:[2,13],13:[2,13],16:[2,13],24:[2,13],26:[2,13],28:[2,13],29:[2,13],31:[2,13],32:[2,13],34:[2,13]},{12:[2,14],13:[2,14],16:[2,14],24:[2,14],26:[2,14],28:[2,14],29:[2,14],31:[2,14],32:[2,14],34:[2,14]},{12:[2,10]},{18:[2,21],25:[2,21],33:[2,21],46:[2,21]},{18:[2,49],25:[2,49],33:[2,49],42:[2,49],43:[2,49],44:[2,49],45:[2,49],46:[2,49],50:[2,49],52:[2,49]},{18:[2,51],25:[2,51],33:[2,51],46:[2,51]},{18:[2,36],25:[2,36],33:[2,36],42:[2,36],43:[2,36],44:[2,36],45:[2,36],46:[2,36],50:[2,36],52:[2,36],54:[2,36]},{5:[2,11],12:[2,11],13:[2,11],16:[2,11],24:[2,11],26:[2,11],28:[2,11],29:[2,11],31:[2,11],32:[2,11],34:[2,11]},{30:79,50:[1,26],53:24},{29:[2,15]},{5:[2,12],12:[2,12],13:[2,12],16:[2,12],24:[2,12],26:[2,12],28:[2,12],29:[2,12],31:[2,12],32:[2,12],34:[2,12]},{25:[1,80]},{25:[2,45]},{51:[1,78]},{5:[2,20],12:[2,20],13:[2,20],16:[2,20],24:[2,20],26:[2,20],28:[2,20],29:[2,20],31:[2,20],32:[2,20],34:[2,20]},{46:[1,81]},{18:[2,53],25:[2,53],33:[2,53],46:[2,53],50:[2,53]},{30:51,36:82,41:55,42:[1,52],43:[1,53],44:[1,54],45:[1,56],50:[1,26],52:[1,25],53:24},{25:[1,83]},{5:[2,19],12:[2,19],13:[2,19],16:[2,19],24:[2,19],26:[2,19],28:[2,19],29:[2,19],31:[2,19],32:[2,19],34:[2,19]},{18:[2,28],25:[2,28],33:[2,28],42:[2,28],43:[2,28],44:[2,28],45:[2,28],46:[2,28],50:[2,28],52:[2,28]},{18:[2,30],25:[2,30],33:[2,30],46:[2,30],50:[2,30]},{5:[2,16],12:[2,16],13:[2,16],16:[2,16],24:[2,16],26:[2,16],28:[2,16],29:[2,16],31:[2,16],32:[2,16],34:[2,16]}], + defaultActions: {4:[2,1],44:[2,41],47:[2,43],57:[2,47],63:[2,10],70:[2,15],73:[2,45]}, + parseError: function parseError(str, hash) { + throw new Error(str); + }, + parse: function parse(input) { + var self = this, stack = [0], vstack = [null], lstack = [], table = this.table, yytext = "", yylineno = 0, yyleng = 0, recovering = 0, TERROR = 2, EOF = 1; + this.lexer.setInput(input); + this.lexer.yy = this.yy; + this.yy.lexer = this.lexer; + this.yy.parser = this; + if (typeof this.lexer.yylloc == "undefined") + this.lexer.yylloc = {}; + var yyloc = this.lexer.yylloc; + lstack.push(yyloc); + var ranges = this.lexer.options && this.lexer.options.ranges; + if (typeof this.yy.parseError === "function") + this.parseError = this.yy.parseError; + function popStack(n) { + stack.length = stack.length - 2 * n; + vstack.length = vstack.length - n; + lstack.length = lstack.length - n; + } + function lex() { + var token; + token = self.lexer.lex() || 1; + if (typeof token !== "number") { + token = self.symbols_[token] || token; + } + return token; + } + var symbol, preErrorSymbol, state, action, a, r, yyval = {}, p, len, newState, expected; + while (true) { + state = stack[stack.length - 1]; + if (this.defaultActions[state]) { + action = this.defaultActions[state]; + } else { + if (symbol === null || typeof symbol == "undefined") { + symbol = lex(); + } + action = table[state] && table[state][symbol]; + } + if (typeof action === "undefined" || !action.length || !action[0]) { + var errStr = ""; + if (!recovering) { + expected = []; + for (p in table[state]) + if (this.terminals_[p] && p > 2) { + expected.push("'" + this.terminals_[p] + "'"); + } + if (this.lexer.showPosition) { + errStr = "Parse error on line " + (yylineno + 1) + ":\n" + this.lexer.showPosition() + "\nExpecting " + expected.join(", ") + ", got '" + (this.terminals_[symbol] || symbol) + "'"; + } else { + errStr = "Parse error on line " + (yylineno + 1) + ": Unexpected " + (symbol == 1?"end of input":"'" + (this.terminals_[symbol] || symbol) + "'"); + } + this.parseError(errStr, {text: this.lexer.match, token: this.terminals_[symbol] || symbol, line: this.lexer.yylineno, loc: yyloc, expected: expected}); + } + } + if (action[0] instanceof Array && action.length > 1) { + throw new Error("Parse Error: multiple actions possible at state: " + state + ", token: " + symbol); + } + switch (action[0]) { + case 1: + stack.push(symbol); + vstack.push(this.lexer.yytext); + lstack.push(this.lexer.yylloc); + stack.push(action[1]); + symbol = null; + if (!preErrorSymbol) { + yyleng = this.lexer.yyleng; + yytext = this.lexer.yytext; + yylineno = this.lexer.yylineno; + yyloc = this.lexer.yylloc; + if (recovering > 0) + recovering--; + } else { + symbol = preErrorSymbol; + preErrorSymbol = null; + } + break; + case 2: + len = this.productions_[action[1]][1]; + yyval.$ = vstack[vstack.length - len]; + yyval._$ = {first_line: lstack[lstack.length - (len || 1)].first_line, last_line: lstack[lstack.length - 1].last_line, first_column: lstack[lstack.length - (len || 1)].first_column, last_column: lstack[lstack.length - 1].last_column}; + if (ranges) { + yyval._$.range = [lstack[lstack.length - (len || 1)].range[0], lstack[lstack.length - 1].range[1]]; + } + r = this.performAction.call(yyval, yytext, yyleng, yylineno, this.yy, action[1], vstack, lstack); + if (typeof r !== "undefined") { + return r; + } + if (len) { + stack = stack.slice(0, -1 * len * 2); + vstack = vstack.slice(0, -1 * len); + lstack = lstack.slice(0, -1 * len); + } + stack.push(this.productions_[action[1]][0]); + vstack.push(yyval.$); + lstack.push(yyval._$); + newState = table[stack[stack.length - 2]][stack[stack.length - 1]]; + stack.push(newState); + break; + case 3: + return true; + } + } + return true; + } + }; + /* Jison generated lexer */ + var lexer = (function(){ + var lexer = ({EOF:1, + parseError:function parseError(str, hash) { + if (this.yy.parser) { + this.yy.parser.parseError(str, hash); + } else { + throw new Error(str); + } + }, + setInput:function (input) { + this._input = input; + this._more = this._less = this.done = false; + this.yylineno = this.yyleng = 0; + this.yytext = this.matched = this.match = ''; + this.conditionStack = ['INITIAL']; + this.yylloc = {first_line:1,first_column:0,last_line:1,last_column:0}; + if (this.options.ranges) this.yylloc.range = [0,0]; + this.offset = 0; + return this; + }, + input:function () { + var ch = this._input[0]; + this.yytext += ch; + this.yyleng++; + this.offset++; + this.match += ch; + this.matched += ch; + var lines = ch.match(/(?:\r\n?|\n).*/g); + if (lines) { + this.yylineno++; + this.yylloc.last_line++; + } else { + this.yylloc.last_column++; + } + if (this.options.ranges) this.yylloc.range[1]++; + + this._input = this._input.slice(1); + return ch; + }, + unput:function (ch) { + var len = ch.length; + var lines = ch.split(/(?:\r\n?|\n)/g); + + this._input = ch + this._input; + this.yytext = this.yytext.substr(0, this.yytext.length-len-1); + //this.yyleng -= len; + this.offset -= len; + var oldLines = this.match.split(/(?:\r\n?|\n)/g); + this.match = this.match.substr(0, this.match.length-1); + this.matched = this.matched.substr(0, this.matched.length-1); + + if (lines.length-1) this.yylineno -= lines.length-1; + var r = this.yylloc.range; + + this.yylloc = {first_line: this.yylloc.first_line, + last_line: this.yylineno+1, + first_column: this.yylloc.first_column, + last_column: lines ? + (lines.length === oldLines.length ? this.yylloc.first_column : 0) + oldLines[oldLines.length - lines.length].length - lines[0].length: + this.yylloc.first_column - len + }; + + if (this.options.ranges) { + this.yylloc.range = [r[0], r[0] + this.yyleng - len]; + } + return this; + }, + more:function () { + this._more = true; + return this; + }, + less:function (n) { + this.unput(this.match.slice(n)); + }, + pastInput:function () { + var past = this.matched.substr(0, this.matched.length - this.match.length); + return (past.length > 20 ? '...':'') + past.substr(-20).replace(/\n/g, ""); + }, + upcomingInput:function () { + var next = this.match; + if (next.length < 20) { + next += this._input.substr(0, 20-next.length); + } + return (next.substr(0,20)+(next.length > 20 ? '...':'')).replace(/\n/g, ""); + }, + showPosition:function () { + var pre = this.pastInput(); + var c = new Array(pre.length + 1).join("-"); + return pre + this.upcomingInput() + "\n" + c+"^"; + }, + next:function () { + if (this.done) { + return this.EOF; + } + if (!this._input) this.done = true; + + var token, + match, + tempMatch, + index, + col, + lines; + if (!this._more) { + this.yytext = ''; + this.match = ''; + } + var rules = this._currentRules(); + for (var i=0;i < rules.length; i++) { + tempMatch = this._input.match(this.rules[rules[i]]); + if (tempMatch && (!match || tempMatch[0].length > match[0].length)) { + match = tempMatch; + index = i; + if (!this.options.flex) break; + } + } + if (match) { + lines = match[0].match(/(?:\r\n?|\n).*/g); + if (lines) this.yylineno += lines.length; + this.yylloc = {first_line: this.yylloc.last_line, + last_line: this.yylineno+1, + first_column: this.yylloc.last_column, + last_column: lines ? lines[lines.length-1].length-lines[lines.length-1].match(/\r?\n?/)[0].length : this.yylloc.last_column + match[0].length}; + this.yytext += match[0]; + this.match += match[0]; + this.matches = match; + this.yyleng = this.yytext.length; + if (this.options.ranges) { + this.yylloc.range = [this.offset, this.offset += this.yyleng]; + } + this._more = false; + this._input = this._input.slice(match[0].length); + this.matched += match[0]; + token = this.performAction.call(this, this.yy, this, rules[index],this.conditionStack[this.conditionStack.length-1]); + if (this.done && this._input) this.done = false; + if (token) return token; + else return; + } + if (this._input === "") { + return this.EOF; + } else { + return this.parseError('Lexical error on line '+(this.yylineno+1)+'. Unrecognized text.\n'+this.showPosition(), + {text: "", token: null, line: this.yylineno}); + } + }, + lex:function lex() { + var r = this.next(); + if (typeof r !== 'undefined') { + return r; + } else { + return this.lex(); + } + }, + begin:function begin(condition) { + this.conditionStack.push(condition); + }, + popState:function popState() { + return this.conditionStack.pop(); + }, + _currentRules:function _currentRules() { + return this.conditions[this.conditionStack[this.conditionStack.length-1]].rules; + }, + topState:function () { + return this.conditionStack[this.conditionStack.length-2]; + }, + pushState:function begin(condition) { + this.begin(condition); + }}); + lexer.options = {}; + lexer.performAction = function anonymous(yy,yy_,$avoiding_name_collisions,YY_START) { + + + function strip(start, end) { + return yy_.yytext = yy_.yytext.substr(start, yy_.yyleng-end); + } + + + var YYSTATE=YY_START + switch($avoiding_name_collisions) { + case 0: + if(yy_.yytext.slice(-2) === "\\\\") { + strip(0,1); + this.begin("mu"); + } else if(yy_.yytext.slice(-1) === "\\") { + strip(0,1); + this.begin("emu"); + } else { + this.begin("mu"); + } + if(yy_.yytext) return 12; + + break; + case 1:return 12; + break; + case 2: + this.popState(); + return 12; + + break; + case 3: + yy_.yytext = yy_.yytext.substr(5, yy_.yyleng-9); + this.popState(); + return 15; + + break; + case 4: return 12; + break; + case 5:strip(0,4); this.popState(); return 13; + break; + case 6:return 45; + break; + case 7:return 46; + break; + case 8: return 16; + break; + case 9: + this.popState(); + this.begin('raw'); + return 18; + + break; + case 10:return 34; + break; + case 11:return 24; + break; + case 12:return 29; + break; + case 13:this.popState(); return 28; + break; + case 14:this.popState(); return 28; + break; + case 15:return 26; + break; + case 16:return 26; + break; + case 17:return 32; + break; + case 18:return 31; + break; + case 19:this.popState(); this.begin('com'); + break; + case 20:strip(3,5); this.popState(); return 13; + break; + case 21:return 31; + break; + case 22:return 51; + break; + case 23:return 50; + break; + case 24:return 50; + break; + case 25:return 54; + break; + case 26:// ignore whitespace + break; + case 27:this.popState(); return 33; + break; + case 28:this.popState(); return 25; + break; + case 29:yy_.yytext = strip(1,2).replace(/\\"/g,'"'); return 42; + break; + case 30:yy_.yytext = strip(1,2).replace(/\\'/g,"'"); return 42; + break; + case 31:return 52; + break; + case 32:return 44; + break; + case 33:return 44; + break; + case 34:return 43; + break; + case 35:return 50; + break; + case 36:yy_.yytext = strip(1,2); return 50; + break; + case 37:return 'INVALID'; + break; + case 38:return 5; + break; + } + }; + lexer.rules = [/^(?:[^\x00]*?(?=(\{\{)))/,/^(?:[^\x00]+)/,/^(?:[^\x00]{2,}?(?=(\{\{|\\\{\{|\\\\\{\{|$)))/,/^(?:\{\{\{\{\/[^\s!"#%-,\.\/;->@\[-\^`\{-~]+(?=[=}\s\/.])\}\}\}\})/,/^(?:[^\x00]*?(?=(\{\{\{\{\/)))/,/^(?:[\s\S]*?--\}\})/,/^(?:\()/,/^(?:\))/,/^(?:\{\{\{\{)/,/^(?:\}\}\}\})/,/^(?:\{\{(~)?>)/,/^(?:\{\{(~)?#)/,/^(?:\{\{(~)?\/)/,/^(?:\{\{(~)?\^\s*(~)?\}\})/,/^(?:\{\{(~)?\s*else\s*(~)?\}\})/,/^(?:\{\{(~)?\^)/,/^(?:\{\{(~)?\s*else\b)/,/^(?:\{\{(~)?\{)/,/^(?:\{\{(~)?&)/,/^(?:\{\{!--)/,/^(?:\{\{![\s\S]*?\}\})/,/^(?:\{\{(~)?)/,/^(?:=)/,/^(?:\.\.)/,/^(?:\.(?=([=~}\s\/.)])))/,/^(?:[\/.])/,/^(?:\s+)/,/^(?:\}(~)?\}\})/,/^(?:(~)?\}\})/,/^(?:"(\\["]|[^"])*")/,/^(?:'(\\[']|[^'])*')/,/^(?:@)/,/^(?:true(?=([~}\s)])))/,/^(?:false(?=([~}\s)])))/,/^(?:-?[0-9]+(?:\.[0-9]+)?(?=([~}\s)])))/,/^(?:([^\s!"#%-,\.\/;->@\[-\^`\{-~]+(?=([=~}\s\/.)]))))/,/^(?:\[[^\]]*\])/,/^(?:.)/,/^(?:$)/]; + lexer.conditions = {"mu":{"rules":[6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38],"inclusive":false},"emu":{"rules":[2],"inclusive":false},"com":{"rules":[5],"inclusive":false},"raw":{"rules":[3,4],"inclusive":false},"INITIAL":{"rules":[0,1,38],"inclusive":true}}; + return lexer;})() + parser.lexer = lexer; + function Parser () { this.yy = {}; }Parser.prototype = parser;parser.Parser = Parser; + return new Parser; + })();__exports__ = handlebars; + /* jshint ignore:end */ + return __exports__; +})(); + +// handlebars/compiler/helpers.js +var __module10__ = (function(__dependency1__) { + "use strict"; + var __exports__ = {}; + var Exception = __dependency1__; + + function stripFlags(open, close) { + return { + left: open.charAt(2) === '~', + right: close.charAt(close.length-3) === '~' + }; + } + + __exports__.stripFlags = stripFlags; + function prepareBlock(mustache, program, inverseAndProgram, close, inverted, locInfo) { + /*jshint -W040 */ + if (mustache.sexpr.id.original !== close.path.original) { + throw new Exception(mustache.sexpr.id.original + ' doesn\'t match ' + close.path.original, mustache); + } + + var inverse = inverseAndProgram && inverseAndProgram.program; + + var strip = { + left: mustache.strip.left, + right: close.strip.right, + + // Determine the standalone candiacy. Basically flag our content as being possibly standalone + // so our parent can determine if we actually are standalone + openStandalone: isNextWhitespace(program.statements), + closeStandalone: isPrevWhitespace((inverse || program).statements) + }; + + if (mustache.strip.right) { + omitRight(program.statements, null, true); + } + + if (inverse) { + var inverseStrip = inverseAndProgram.strip; + + if (inverseStrip.left) { + omitLeft(program.statements, null, true); + } + if (inverseStrip.right) { + omitRight(inverse.statements, null, true); + } + if (close.strip.left) { + omitLeft(inverse.statements, null, true); + } + + // Find standalone else statments + if (isPrevWhitespace(program.statements) + && isNextWhitespace(inverse.statements)) { + + omitLeft(program.statements); + omitRight(inverse.statements); + } + } else { + if (close.strip.left) { + omitLeft(program.statements, null, true); + } + } + + if (inverted) { + return new this.BlockNode(mustache, inverse, program, strip, locInfo); + } else { + return new this.BlockNode(mustache, program, inverse, strip, locInfo); + } + } + + __exports__.prepareBlock = prepareBlock; + function prepareProgram(statements, isRoot) { + for (var i = 0, l = statements.length; i < l; i++) { + var current = statements[i], + strip = current.strip; + + if (!strip) { + continue; + } + + var _isPrevWhitespace = isPrevWhitespace(statements, i, isRoot, current.type === 'partial'), + _isNextWhitespace = isNextWhitespace(statements, i, isRoot), + + openStandalone = strip.openStandalone && _isPrevWhitespace, + closeStandalone = strip.closeStandalone && _isNextWhitespace, + inlineStandalone = strip.inlineStandalone && _isPrevWhitespace && _isNextWhitespace; + + if (strip.right) { + omitRight(statements, i, true); + } + if (strip.left) { + omitLeft(statements, i, true); + } + + if (inlineStandalone) { + omitRight(statements, i); + + if (omitLeft(statements, i)) { + // If we are on a standalone node, save the indent info for partials + if (current.type === 'partial') { + current.indent = (/([ \t]+$)/).exec(statements[i-1].original) ? RegExp.$1 : ''; + } + } + } + if (openStandalone) { + omitRight((current.program || current.inverse).statements); + + // Strip out the previous content node if it's whitespace only + omitLeft(statements, i); + } + if (closeStandalone) { + // Always strip the next node + omitRight(statements, i); + + omitLeft((current.inverse || current.program).statements); + } + } + + return statements; + } + + __exports__.prepareProgram = prepareProgram;function isPrevWhitespace(statements, i, isRoot) { + if (i === undefined) { + i = statements.length; + } + + // Nodes that end with newlines are considered whitespace (but are special + // cased for strip operations) + var prev = statements[i-1], + sibling = statements[i-2]; + if (!prev) { + return isRoot; + } + + if (prev.type === 'content') { + return (sibling || !isRoot ? (/\r?\n\s*?$/) : (/(^|\r?\n)\s*?$/)).test(prev.original); + } + } + function isNextWhitespace(statements, i, isRoot) { + if (i === undefined) { + i = -1; + } + + var next = statements[i+1], + sibling = statements[i+2]; + if (!next) { + return isRoot; + } + + if (next.type === 'content') { + return (sibling || !isRoot ? (/^\s*?\r?\n/) : (/^\s*?(\r?\n|$)/)).test(next.original); + } + } + + // Marks the node to the right of the position as omitted. + // I.e. {{foo}}' ' will mark the ' ' node as omitted. + // + // If i is undefined, then the first child will be marked as such. + // + // If mulitple is truthy then all whitespace will be stripped out until non-whitespace + // content is met. + function omitRight(statements, i, multiple) { + var current = statements[i == null ? 0 : i + 1]; + if (!current || current.type !== 'content' || (!multiple && current.rightStripped)) { + return; + } + + var original = current.string; + current.string = current.string.replace(multiple ? (/^\s+/) : (/^[ \t]*\r?\n?/), ''); + current.rightStripped = current.string !== original; + } + + // Marks the node to the left of the position as omitted. + // I.e. ' '{{foo}} will mark the ' ' node as omitted. + // + // If i is undefined then the last child will be marked as such. + // + // If mulitple is truthy then all whitespace will be stripped out until non-whitespace + // content is met. + function omitLeft(statements, i, multiple) { + var current = statements[i == null ? statements.length - 1 : i - 1]; + if (!current || current.type !== 'content' || (!multiple && current.leftStripped)) { + return; + } + + // We omit the last node if it's whitespace only and not preceeded by a non-content node. + var original = current.string; + current.string = current.string.replace(multiple ? (/\s+$/) : (/[ \t]+$/), ''); + current.leftStripped = current.string !== original; + return current.leftStripped; + } + return __exports__; +})(__module5__); + +// handlebars/compiler/base.js +var __module8__ = (function(__dependency1__, __dependency2__, __dependency3__, __dependency4__) { + "use strict"; + var __exports__ = {}; + var parser = __dependency1__; + var AST = __dependency2__; + var Helpers = __dependency3__; + var extend = __dependency4__.extend; + + __exports__.parser = parser; + + var yy = {}; + extend(yy, Helpers, AST); + + function parse(input) { + // Just return if an already-compile AST was passed in. + if (input.constructor === AST.ProgramNode) { return input; } + + parser.yy = yy; + + return parser.parse(input); + } + + __exports__.parse = parse; + return __exports__; +})(__module9__, __module7__, __module10__, __module3__); + +// handlebars/compiler/compiler.js +var __module11__ = (function(__dependency1__, __dependency2__) { + "use strict"; + var __exports__ = {}; + var Exception = __dependency1__; + var isArray = __dependency2__.isArray; + + var slice = [].slice; + + function Compiler() {} + + __exports__.Compiler = Compiler;// the foundHelper register will disambiguate helper lookup from finding a + // function in a context. This is necessary for mustache compatibility, which + // requires that context functions in blocks are evaluated by blockHelperMissing, + // and then proceed as if the resulting value was provided to blockHelperMissing. + + Compiler.prototype = { + compiler: Compiler, + + equals: function(other) { + var len = this.opcodes.length; + if (other.opcodes.length !== len) { + return false; + } + + for (var i = 0; i < len; i++) { + var opcode = this.opcodes[i], + otherOpcode = other.opcodes[i]; + if (opcode.opcode !== otherOpcode.opcode || !argEquals(opcode.args, otherOpcode.args)) { + return false; + } + } + + // We know that length is the same between the two arrays because they are directly tied + // to the opcode behavior above. + len = this.children.length; + for (i = 0; i < len; i++) { + if (!this.children[i].equals(other.children[i])) { + return false; + } + } + + return true; + }, + + guid: 0, + + compile: function(program, options) { + this.opcodes = []; + this.children = []; + this.depths = {list: []}; + this.options = options; + this.stringParams = options.stringParams; + this.trackIds = options.trackIds; + + // These changes will propagate to the other compiler components + var knownHelpers = this.options.knownHelpers; + this.options.knownHelpers = { + 'helperMissing': true, + 'blockHelperMissing': true, + 'each': true, + 'if': true, + 'unless': true, + 'with': true, + 'log': true, + 'lookup': true + }; + if (knownHelpers) { + for (var name in knownHelpers) { + this.options.knownHelpers[name] = knownHelpers[name]; + } + } + + return this.accept(program); + }, + + accept: function(node) { + return this[node.type](node); + }, + + program: function(program) { + var statements = program.statements; + + for(var i=0, l=statements.length; i 0) { + varDeclarations += ", " + locals.join(", "); + } + + // Generate minimizer alias mappings + for (var alias in this.aliases) { + if (this.aliases.hasOwnProperty(alias)) { + varDeclarations += ', ' + alias + '=' + this.aliases[alias]; + } + } + + var params = ["depth0", "helpers", "partials", "data"]; + + if (this.useDepths) { + params.push('depths'); + } + + // Perform a second pass over the output to merge content when possible + var source = this.mergeSource(varDeclarations); + + if (asObject) { + params.push(source); + + return Function.apply(this, params); + } else { + return 'function(' + params.join(',') + ') {\n ' + source + '}'; + } + }, + mergeSource: function(varDeclarations) { + var source = '', + buffer, + appendOnly = !this.forceBuffer, + appendFirst; + + for (var i = 0, len = this.source.length; i < len; i++) { + var line = this.source[i]; + if (line.appendToBuffer) { + if (buffer) { + buffer = buffer + '\n + ' + line.content; + } else { + buffer = line.content; + } + } else { + if (buffer) { + if (!source) { + appendFirst = true; + source = buffer + ';\n '; + } else { + source += 'buffer += ' + buffer + ';\n '; + } + buffer = undefined; + } + source += line + '\n '; + + if (!this.environment.isSimple) { + appendOnly = false; + } + } + } + + if (appendOnly) { + if (buffer || !source) { + source += 'return ' + (buffer || '""') + ';\n'; + } + } else { + varDeclarations += ", buffer = " + (appendFirst ? '' : this.initializeBuffer()); + if (buffer) { + source += 'return buffer + ' + buffer + ';\n'; + } else { + source += 'return buffer;\n'; + } + } + + if (varDeclarations) { + source = 'var ' + varDeclarations.substring(2) + (appendFirst ? '' : ';\n ') + source; + } + + return source; + }, + + // [blockValue] + // + // On stack, before: hash, inverse, program, value + // On stack, after: return value of blockHelperMissing + // + // The purpose of this opcode is to take a block of the form + // `{{#this.foo}}...{{/this.foo}}`, resolve the value of `foo`, and + // replace it on the stack with the result of properly + // invoking blockHelperMissing. + blockValue: function(name) { + this.aliases.blockHelperMissing = 'helpers.blockHelperMissing'; + + var params = [this.contextName(0)]; + this.setupParams(name, 0, params); + + var blockName = this.popStack(); + params.splice(1, 0, blockName); + + this.push('blockHelperMissing.call(' + params.join(', ') + ')'); + }, + + // [ambiguousBlockValue] + // + // On stack, before: hash, inverse, program, value + // Compiler value, before: lastHelper=value of last found helper, if any + // On stack, after, if no lastHelper: same as [blockValue] + // On stack, after, if lastHelper: value + ambiguousBlockValue: function() { + this.aliases.blockHelperMissing = 'helpers.blockHelperMissing'; + + // We're being a bit cheeky and reusing the options value from the prior exec + var params = [this.contextName(0)]; + this.setupParams('', 0, params, true); + + this.flushInline(); + + var current = this.topStack(); + params.splice(1, 0, current); + + this.pushSource("if (!" + this.lastHelper + ") { " + current + " = blockHelperMissing.call(" + params.join(", ") + "); }"); + }, + + // [appendContent] + // + // On stack, before: ... + // On stack, after: ... + // + // Appends the string value of `content` to the current buffer + appendContent: function(content) { + if (this.pendingContent) { + content = this.pendingContent + content; + } + + this.pendingContent = content; + }, + + // [append] + // + // On stack, before: value, ... + // On stack, after: ... + // + // Coerces `value` to a String and appends it to the current buffer. + // + // If `value` is truthy, or 0, it is coerced into a string and appended + // Otherwise, the empty string is appended + append: function() { + // Force anything that is inlined onto the stack so we don't have duplication + // when we examine local + this.flushInline(); + var local = this.popStack(); + this.pushSource('if (' + local + ' != null) { ' + this.appendToBuffer(local) + ' }'); + if (this.environment.isSimple) { + this.pushSource("else { " + this.appendToBuffer("''") + " }"); + } + }, + + // [appendEscaped] + // + // On stack, before: value, ... + // On stack, after: ... + // + // Escape `value` and append it to the buffer + appendEscaped: function() { + this.aliases.escapeExpression = 'this.escapeExpression'; + + this.pushSource(this.appendToBuffer("escapeExpression(" + this.popStack() + ")")); + }, + + // [getContext] + // + // On stack, before: ... + // On stack, after: ... + // Compiler value, after: lastContext=depth + // + // Set the value of the `lastContext` compiler value to the depth + getContext: function(depth) { + this.lastContext = depth; + }, + + // [pushContext] + // + // On stack, before: ... + // On stack, after: currentContext, ... + // + // Pushes the value of the current context onto the stack. + pushContext: function() { + this.pushStackLiteral(this.contextName(this.lastContext)); + }, + + // [lookupOnContext] + // + // On stack, before: ... + // On stack, after: currentContext[name], ... + // + // Looks up the value of `name` on the current context and pushes + // it onto the stack. + lookupOnContext: function(parts, falsy, scoped) { + /*jshint -W083 */ + var i = 0, + len = parts.length; + + if (!scoped && this.options.compat && !this.lastContext) { + // The depthed query is expected to handle the undefined logic for the root level that + // is implemented below, so we evaluate that directly in compat mode + this.push(this.depthedLookup(parts[i++])); + } else { + this.pushContext(); + } + + for (; i < len; i++) { + this.replaceStack(function(current) { + var lookup = this.nameLookup(current, parts[i], 'context'); + // We want to ensure that zero and false are handled properly if the context (falsy flag) + // needs to have the special handling for these values. + if (!falsy) { + return ' != null ? ' + lookup + ' : ' + current; + } else { + // Otherwise we can use generic falsy handling + return ' && ' + lookup; + } + }); + } + }, + + // [lookupData] + // + // On stack, before: ... + // On stack, after: data, ... + // + // Push the data lookup operator + lookupData: function(depth, parts) { + /*jshint -W083 */ + if (!depth) { + this.pushStackLiteral('data'); + } else { + this.pushStackLiteral('this.data(data, ' + depth + ')'); + } + + var len = parts.length; + for (var i = 0; i < len; i++) { + this.replaceStack(function(current) { + return ' && ' + this.nameLookup(current, parts[i], 'data'); + }); + } + }, + + // [resolvePossibleLambda] + // + // On stack, before: value, ... + // On stack, after: resolved value, ... + // + // If the `value` is a lambda, replace it on the stack by + // the return value of the lambda + resolvePossibleLambda: function() { + this.aliases.lambda = 'this.lambda'; + + this.push('lambda(' + this.popStack() + ', ' + this.contextName(0) + ')'); + }, + + // [pushStringParam] + // + // On stack, before: ... + // On stack, after: string, currentContext, ... + // + // This opcode is designed for use in string mode, which + // provides the string value of a parameter along with its + // depth rather than resolving it immediately. + pushStringParam: function(string, type) { + this.pushContext(); + this.pushString(type); + + // If it's a subexpression, the string result + // will be pushed after this opcode. + if (type !== 'sexpr') { + if (typeof string === 'string') { + this.pushString(string); + } else { + this.pushStackLiteral(string); + } + } + }, + + emptyHash: function() { + this.pushStackLiteral('{}'); + + if (this.trackIds) { + this.push('{}'); // hashIds + } + if (this.stringParams) { + this.push('{}'); // hashContexts + this.push('{}'); // hashTypes + } + }, + pushHash: function() { + if (this.hash) { + this.hashes.push(this.hash); + } + this.hash = {values: [], types: [], contexts: [], ids: []}; + }, + popHash: function() { + var hash = this.hash; + this.hash = this.hashes.pop(); + + if (this.trackIds) { + this.push('{' + hash.ids.join(',') + '}'); + } + if (this.stringParams) { + this.push('{' + hash.contexts.join(',') + '}'); + this.push('{' + hash.types.join(',') + '}'); + } + + this.push('{\n ' + hash.values.join(',\n ') + '\n }'); + }, + + // [pushString] + // + // On stack, before: ... + // On stack, after: quotedString(string), ... + // + // Push a quoted version of `string` onto the stack + pushString: function(string) { + this.pushStackLiteral(this.quotedString(string)); + }, + + // [push] + // + // On stack, before: ... + // On stack, after: expr, ... + // + // Push an expression onto the stack + push: function(expr) { + this.inlineStack.push(expr); + return expr; + }, + + // [pushLiteral] + // + // On stack, before: ... + // On stack, after: value, ... + // + // Pushes a value onto the stack. This operation prevents + // the compiler from creating a temporary variable to hold + // it. + pushLiteral: function(value) { + this.pushStackLiteral(value); + }, + + // [pushProgram] + // + // On stack, before: ... + // On stack, after: program(guid), ... + // + // Push a program expression onto the stack. This takes + // a compile-time guid and converts it into a runtime-accessible + // expression. + pushProgram: function(guid) { + if (guid != null) { + this.pushStackLiteral(this.programExpression(guid)); + } else { + this.pushStackLiteral(null); + } + }, + + // [invokeHelper] + // + // On stack, before: hash, inverse, program, params..., ... + // On stack, after: result of helper invocation + // + // Pops off the helper's parameters, invokes the helper, + // and pushes the helper's return value onto the stack. + // + // If the helper is not found, `helperMissing` is called. + invokeHelper: function(paramSize, name, isSimple) { + this.aliases.helperMissing = 'helpers.helperMissing'; + + var nonHelper = this.popStack(); + var helper = this.setupHelper(paramSize, name); + + var lookup = (isSimple ? helper.name + ' || ' : '') + nonHelper + ' || helperMissing'; + this.push('((' + lookup + ').call(' + helper.callParams + '))'); + }, + + // [invokeKnownHelper] + // + // On stack, before: hash, inverse, program, params..., ... + // On stack, after: result of helper invocation + // + // This operation is used when the helper is known to exist, + // so a `helperMissing` fallback is not required. + invokeKnownHelper: function(paramSize, name) { + var helper = this.setupHelper(paramSize, name); + this.push(helper.name + ".call(" + helper.callParams + ")"); + }, + + // [invokeAmbiguous] + // + // On stack, before: hash, inverse, program, params..., ... + // On stack, after: result of disambiguation + // + // This operation is used when an expression like `{{foo}}` + // is provided, but we don't know at compile-time whether it + // is a helper or a path. + // + // This operation emits more code than the other options, + // and can be avoided by passing the `knownHelpers` and + // `knownHelpersOnly` flags at compile-time. + invokeAmbiguous: function(name, helperCall) { + this.aliases.functionType = '"function"'; + this.aliases.helperMissing = 'helpers.helperMissing'; + this.useRegister('helper'); + + var nonHelper = this.popStack(); + + this.emptyHash(); + var helper = this.setupHelper(0, name, helperCall); + + var helperName = this.lastHelper = this.nameLookup('helpers', name, 'helper'); + + this.push( + '((helper = (helper = ' + helperName + ' || ' + nonHelper + ') != null ? helper : helperMissing' + + (helper.paramsInit ? '),(' + helper.paramsInit : '') + '),' + + '(typeof helper === functionType ? helper.call(' + helper.callParams + ') : helper))'); + }, + + // [invokePartial] + // + // On stack, before: context, ... + // On stack after: result of partial invocation + // + // This operation pops off a context, invokes a partial with that context, + // and pushes the result of the invocation back. + invokePartial: function(name, indent) { + var params = [this.nameLookup('partials', name, 'partial'), "'" + indent + "'", "'" + name + "'", this.popStack(), this.popStack(), "helpers", "partials"]; + + if (this.options.data) { + params.push("data"); + } else if (this.options.compat) { + params.push('undefined'); + } + if (this.options.compat) { + params.push('depths'); + } + + this.push("this.invokePartial(" + params.join(", ") + ")"); + }, + + // [assignToHash] + // + // On stack, before: value, ..., hash, ... + // On stack, after: ..., hash, ... + // + // Pops a value off the stack and assigns it to the current hash + assignToHash: function(key) { + var value = this.popStack(), + context, + type, + id; + + if (this.trackIds) { + id = this.popStack(); + } + if (this.stringParams) { + type = this.popStack(); + context = this.popStack(); + } + + var hash = this.hash; + if (context) { + hash.contexts.push("'" + key + "': " + context); + } + if (type) { + hash.types.push("'" + key + "': " + type); + } + if (id) { + hash.ids.push("'" + key + "': " + id); + } + hash.values.push("'" + key + "': (" + value + ")"); + }, + + pushId: function(type, name) { + if (type === 'ID' || type === 'DATA') { + this.pushString(name); + } else if (type === 'sexpr') { + this.pushStackLiteral('true'); + } else { + this.pushStackLiteral('null'); + } + }, + + // HELPERS + + compiler: JavaScriptCompiler, + + compileChildren: function(environment, options) { + var children = environment.children, child, compiler; + + for(var i=0, l=children.length; i this.stackVars.length) { this.stackVars.push("stack" + this.stackSlot); } + return this.topStackName(); + }, + topStackName: function() { + return "stack" + this.stackSlot; + }, + flushInline: function() { + var inlineStack = this.inlineStack; + if (inlineStack.length) { + this.inlineStack = []; + for (var i = 0, len = inlineStack.length; i < len; i++) { + var entry = inlineStack[i]; + if (entry instanceof Literal) { + this.compileStack.push(entry); + } else { + this.pushStack(entry); + } + } + } + }, + isInline: function() { + return this.inlineStack.length; + }, + + popStack: function(wrapped) { + var inline = this.isInline(), + item = (inline ? this.inlineStack : this.compileStack).pop(); + + if (!wrapped && (item instanceof Literal)) { + return item.value; + } else { + if (!inline) { + /* istanbul ignore next */ + if (!this.stackSlot) { + throw new Exception('Invalid stack pop'); + } + this.stackSlot--; + } + return item; + } + }, + + topStack: function() { + var stack = (this.isInline() ? this.inlineStack : this.compileStack), + item = stack[stack.length - 1]; + + if (item instanceof Literal) { + return item.value; + } else { + return item; + } + }, + + contextName: function(context) { + if (this.useDepths && context) { + return 'depths[' + context + ']'; + } else { + return 'depth' + context; + } + }, + + quotedString: function(str) { + return '"' + str + .replace(/\\/g, '\\\\') + .replace(/"/g, '\\"') + .replace(/\n/g, '\\n') + .replace(/\r/g, '\\r') + .replace(/\u2028/g, '\\u2028') // Per Ecma-262 7.3 + 7.8.4 + .replace(/\u2029/g, '\\u2029') + '"'; + }, + + objectLiteral: function(obj) { + var pairs = []; + + for (var key in obj) { + if (obj.hasOwnProperty(key)) { + pairs.push(this.quotedString(key) + ':' + obj[key]); + } + } + + return '{' + pairs.join(',') + '}'; + }, + + setupHelper: function(paramSize, name, blockHelper) { + var params = [], + paramsInit = this.setupParams(name, paramSize, params, blockHelper); + var foundHelper = this.nameLookup('helpers', name, 'helper'); + + return { + params: params, + paramsInit: paramsInit, + name: foundHelper, + callParams: [this.contextName(0)].concat(params).join(", ") + }; + }, + + setupOptions: function(helper, paramSize, params) { + var options = {}, contexts = [], types = [], ids = [], param, inverse, program; + + options.name = this.quotedString(helper); + options.hash = this.popStack(); + + if (this.trackIds) { + options.hashIds = this.popStack(); + } + if (this.stringParams) { + options.hashTypes = this.popStack(); + options.hashContexts = this.popStack(); + } + + inverse = this.popStack(); + program = this.popStack(); + + // Avoid setting fn and inverse if neither are set. This allows + // helpers to do a check for `if (options.fn)` + if (program || inverse) { + if (!program) { + program = 'this.noop'; + } + + if (!inverse) { + inverse = 'this.noop'; + } + + options.fn = program; + options.inverse = inverse; + } + + // The parameters go on to the stack in order (making sure that they are evaluated in order) + // so we need to pop them off the stack in reverse order + var i = paramSize; + while (i--) { + param = this.popStack(); + params[i] = param; + + if (this.trackIds) { + ids[i] = this.popStack(); + } + if (this.stringParams) { + types[i] = this.popStack(); + contexts[i] = this.popStack(); + } + } + + if (this.trackIds) { + options.ids = "[" + ids.join(",") + "]"; + } + if (this.stringParams) { + options.types = "[" + types.join(",") + "]"; + options.contexts = "[" + contexts.join(",") + "]"; + } + + if (this.options.data) { + options.data = "data"; + } + + return options; + }, + + // the params and contexts arguments are passed in arrays + // to fill in + setupParams: function(helperName, paramSize, params, useRegister) { + var options = this.objectLiteral(this.setupOptions(helperName, paramSize, params)); + + if (useRegister) { + this.useRegister('options'); + params.push('options'); + return 'options=' + options; + } else { + params.push(options); + return ''; + } + } + }; + + var reservedWords = ( + "break else new var" + + " case finally return void" + + " catch for switch while" + + " continue function this with" + + " default if throw" + + " delete in try" + + " do instanceof typeof" + + " abstract enum int short" + + " boolean export interface static" + + " byte extends long super" + + " char final native synchronized" + + " class float package throws" + + " const goto private transient" + + " debugger implements protected volatile" + + " double import public let yield" + ).split(" "); + + var compilerWords = JavaScriptCompiler.RESERVED_WORDS = {}; + + for(var i=0, l=reservedWords.length; i= 0 && j < len ? [ this[j] ] : [] ); + }, + + end: function() { + return this.prevObject || this.constructor(null); + }, + + // For internal use only. + // Behaves like an Array's method, not like a jQuery method. + push: push, + sort: deletedIds.sort, + splice: deletedIds.splice +}; + +jQuery.extend = jQuery.fn.extend = function() { + var src, copyIsArray, copy, name, options, clone, + target = arguments[0] || {}, + i = 1, + length = arguments.length, + deep = false; + + // Handle a deep copy situation + if ( typeof target === "boolean" ) { + deep = target; + + // skip the boolean and the target + target = arguments[ i ] || {}; + i++; + } + + // Handle case when target is a string or something (possible in deep copy) + if ( typeof target !== "object" && !jQuery.isFunction(target) ) { + target = {}; + } + + // extend jQuery itself if only one argument is passed + if ( i === length ) { + target = this; + i--; + } + + for ( ; i < length; i++ ) { + // Only deal with non-null/undefined values + if ( (options = arguments[ i ]) != null ) { + // Extend the base object + for ( name in options ) { + src = target[ name ]; + copy = options[ name ]; + + // Prevent never-ending loop + if ( target === copy ) { + continue; + } + + // Recurse if we're merging plain objects or arrays + if ( deep && copy && ( jQuery.isPlainObject(copy) || (copyIsArray = jQuery.isArray(copy)) ) ) { + if ( copyIsArray ) { + copyIsArray = false; + clone = src && jQuery.isArray(src) ? src : []; + + } else { + clone = src && jQuery.isPlainObject(src) ? src : {}; + } + + // Never move original objects, clone them + target[ name ] = jQuery.extend( deep, clone, copy ); + + // Don't bring in undefined values + } else if ( copy !== undefined ) { + target[ name ] = copy; + } + } + } + } + + // Return the modified object + return target; +}; + +jQuery.extend({ + // Unique for each copy of jQuery on the page + expando: "jQuery" + ( version + Math.random() ).replace( /\D/g, "" ), + + // Assume jQuery is ready without the ready module + isReady: true, + + error: function( msg ) { + throw new Error( msg ); + }, + + noop: function() {}, + + // See test/unit/core.js for details concerning isFunction. + // Since version 1.3, DOM methods and functions like alert + // aren't supported. They return false on IE (#2968). + isFunction: function( obj ) { + return jQuery.type(obj) === "function"; + }, + + isArray: Array.isArray || function( obj ) { + return jQuery.type(obj) === "array"; + }, + + isWindow: function( obj ) { + /* jshint eqeqeq: false */ + return obj != null && obj == obj.window; + }, + + isNumeric: function( obj ) { + // parseFloat NaNs numeric-cast false positives (null|true|false|"") + // ...but misinterprets leading-number strings, particularly hex literals ("0x...") + // subtraction forces infinities to NaN + // adding 1 corrects loss of precision from parseFloat (#15100) + return !jQuery.isArray( obj ) && (obj - parseFloat( obj ) + 1) >= 0; + }, + + isEmptyObject: function( obj ) { + var name; + for ( name in obj ) { + return false; + } + return true; + }, + + isPlainObject: function( obj ) { + var key; + + // Must be an Object. + // Because of IE, we also have to check the presence of the constructor property. + // Make sure that DOM nodes and window objects don't pass through, as well + if ( !obj || jQuery.type(obj) !== "object" || obj.nodeType || jQuery.isWindow( obj ) ) { + return false; + } + + try { + // Not own constructor property must be Object + if ( obj.constructor && + !hasOwn.call(obj, "constructor") && + !hasOwn.call(obj.constructor.prototype, "isPrototypeOf") ) { + return false; + } + } catch ( e ) { + // IE8,9 Will throw exceptions on certain host objects #9897 + return false; + } + + // Support: IE<9 + // Handle iteration over inherited properties before own properties. + if ( support.ownLast ) { + for ( key in obj ) { + return hasOwn.call( obj, key ); + } + } + + // Own properties are enumerated firstly, so to speed up, + // if last one is own, then all properties are own. + for ( key in obj ) {} + + return key === undefined || hasOwn.call( obj, key ); + }, + + type: function( obj ) { + if ( obj == null ) { + return obj + ""; + } + return typeof obj === "object" || typeof obj === "function" ? + class2type[ toString.call(obj) ] || "object" : + typeof obj; + }, + + // Evaluates a script in a global context + // Workarounds based on findings by Jim Driscoll + // http://weblogs.java.net/blog/driscoll/archive/2009/09/08/eval-javascript-global-context + globalEval: function( data ) { + if ( data && jQuery.trim( data ) ) { + // We use execScript on Internet Explorer + // We use an anonymous function so that context is window + // rather than jQuery in Firefox + ( window.execScript || function( data ) { + window[ "eval" ].call( window, data ); + } )( data ); + } + }, + + // Convert dashed to camelCase; used by the css and data modules + // Microsoft forgot to hump their vendor prefix (#9572) + camelCase: function( string ) { + return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase ); + }, + + nodeName: function( elem, name ) { + return elem.nodeName && elem.nodeName.toLowerCase() === name.toLowerCase(); + }, + + // args is for internal usage only + each: function( obj, callback, args ) { + var value, + i = 0, + length = obj.length, + isArray = isArraylike( obj ); + + if ( args ) { + if ( isArray ) { + for ( ; i < length; i++ ) { + value = callback.apply( obj[ i ], args ); + + if ( value === false ) { + break; + } + } + } else { + for ( i in obj ) { + value = callback.apply( obj[ i ], args ); + + if ( value === false ) { + break; + } + } + } + + // A special, fast, case for the most common use of each + } else { + if ( isArray ) { + for ( ; i < length; i++ ) { + value = callback.call( obj[ i ], i, obj[ i ] ); + + if ( value === false ) { + break; + } + } + } else { + for ( i in obj ) { + value = callback.call( obj[ i ], i, obj[ i ] ); + + if ( value === false ) { + break; + } + } + } + } + + return obj; + }, + + // Support: Android<4.1, IE<9 + trim: function( text ) { + return text == null ? + "" : + ( text + "" ).replace( rtrim, "" ); + }, + + // results is for internal usage only + makeArray: function( arr, results ) { + var ret = results || []; + + if ( arr != null ) { + if ( isArraylike( Object(arr) ) ) { + jQuery.merge( ret, + typeof arr === "string" ? + [ arr ] : arr + ); + } else { + push.call( ret, arr ); + } + } + + return ret; + }, + + inArray: function( elem, arr, i ) { + var len; + + if ( arr ) { + if ( indexOf ) { + return indexOf.call( arr, elem, i ); + } + + len = arr.length; + i = i ? i < 0 ? Math.max( 0, len + i ) : i : 0; + + for ( ; i < len; i++ ) { + // Skip accessing in sparse arrays + if ( i in arr && arr[ i ] === elem ) { + return i; + } + } + } + + return -1; + }, + + merge: function( first, second ) { + var len = +second.length, + j = 0, + i = first.length; + + while ( j < len ) { + first[ i++ ] = second[ j++ ]; + } + + // Support: IE<9 + // Workaround casting of .length to NaN on otherwise arraylike objects (e.g., NodeLists) + if ( len !== len ) { + while ( second[j] !== undefined ) { + first[ i++ ] = second[ j++ ]; + } + } + + first.length = i; + + return first; + }, + + grep: function( elems, callback, invert ) { + var callbackInverse, + matches = [], + i = 0, + length = elems.length, + callbackExpect = !invert; + + // Go through the array, only saving the items + // that pass the validator function + for ( ; i < length; i++ ) { + callbackInverse = !callback( elems[ i ], i ); + if ( callbackInverse !== callbackExpect ) { + matches.push( elems[ i ] ); + } + } + + return matches; + }, + + // arg is for internal usage only + map: function( elems, callback, arg ) { + var value, + i = 0, + length = elems.length, + isArray = isArraylike( elems ), + ret = []; + + // Go through the array, translating each of the items to their new values + if ( isArray ) { + for ( ; i < length; i++ ) { + value = callback( elems[ i ], i, arg ); + + if ( value != null ) { + ret.push( value ); + } + } + + // Go through every key on the object, + } else { + for ( i in elems ) { + value = callback( elems[ i ], i, arg ); + + if ( value != null ) { + ret.push( value ); + } + } + } + + // Flatten any nested arrays + return concat.apply( [], ret ); + }, + + // A global GUID counter for objects + guid: 1, + + // Bind a function to a context, optionally partially applying any + // arguments. + proxy: function( fn, context ) { + var args, proxy, tmp; + + if ( typeof context === "string" ) { + tmp = fn[ context ]; + context = fn; + fn = tmp; + } + + // Quick check to determine if target is callable, in the spec + // this throws a TypeError, but we will just return undefined. + if ( !jQuery.isFunction( fn ) ) { + return undefined; + } + + // Simulated bind + args = slice.call( arguments, 2 ); + proxy = function() { + return fn.apply( context || this, args.concat( slice.call( arguments ) ) ); + }; + + // Set the guid of unique handler to the same of original handler, so it can be removed + proxy.guid = fn.guid = fn.guid || jQuery.guid++; + + return proxy; + }, + + now: function() { + return +( new Date() ); + }, + + // jQuery.support is not used in Core but other projects attach their + // properties to it so it needs to exist. + support: support +}); + +// Populate the class2type map +jQuery.each("Boolean Number String Function Array Date RegExp Object Error".split(" "), function(i, name) { + class2type[ "[object " + name + "]" ] = name.toLowerCase(); +}); + +function isArraylike( obj ) { + var length = obj.length, + type = jQuery.type( obj ); + + if ( type === "function" || jQuery.isWindow( obj ) ) { + return false; + } + + if ( obj.nodeType === 1 && length ) { + return true; + } + + return type === "array" || length === 0 || + typeof length === "number" && length > 0 && ( length - 1 ) in obj; +} +var Sizzle = +/*! + * Sizzle CSS Selector Engine v2.2.0-pre + * http://sizzlejs.com/ + * + * Copyright 2008, 2014 jQuery Foundation, Inc. and other contributors + * Released under the MIT license + * http://jquery.org/license + * + * Date: 2014-12-16 + */ +(function( window ) { + +var i, + support, + Expr, + getText, + isXML, + tokenize, + compile, + select, + outermostContext, + sortInput, + hasDuplicate, + + // Local document vars + setDocument, + document, + docElem, + documentIsHTML, + rbuggyQSA, + rbuggyMatches, + matches, + contains, + + // Instance-specific data + expando = "sizzle" + 1 * new Date(), + preferredDoc = window.document, + dirruns = 0, + done = 0, + classCache = createCache(), + tokenCache = createCache(), + compilerCache = createCache(), + sortOrder = function( a, b ) { + if ( a === b ) { + hasDuplicate = true; + } + return 0; + }, + + // General-purpose constants + MAX_NEGATIVE = 1 << 31, + + // Instance methods + hasOwn = ({}).hasOwnProperty, + arr = [], + pop = arr.pop, + push_native = arr.push, + push = arr.push, + slice = arr.slice, + // Use a stripped-down indexOf as it's faster than native + // http://jsperf.com/thor-indexof-vs-for/5 + indexOf = function( list, elem ) { + var i = 0, + len = list.length; + for ( ; i < len; i++ ) { + if ( list[i] === elem ) { + return i; + } + } + return -1; + }, + + booleans = "checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped", + + // Regular expressions + + // Whitespace characters http://www.w3.org/TR/css3-selectors/#whitespace + whitespace = "[\\x20\\t\\r\\n\\f]", + // http://www.w3.org/TR/css3-syntax/#characters + characterEncoding = "(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+", + + // Loosely modeled on CSS identifier characters + // An unquoted value should be a CSS identifier http://www.w3.org/TR/css3-selectors/#attribute-selectors + // Proper syntax: http://www.w3.org/TR/CSS21/syndata.html#value-def-identifier + identifier = characterEncoding.replace( "w", "w#" ), + + // Attribute selectors: http://www.w3.org/TR/selectors/#attribute-selectors + attributes = "\\[" + whitespace + "*(" + characterEncoding + ")(?:" + whitespace + + // Operator (capture 2) + "*([*^$|!~]?=)" + whitespace + + // "Attribute values must be CSS identifiers [capture 5] or strings [capture 3 or capture 4]" + "*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|(" + identifier + "))|)" + whitespace + + "*\\]", + + pseudos = ":(" + characterEncoding + ")(?:\\((" + + // To reduce the number of selectors needing tokenize in the preFilter, prefer arguments: + // 1. quoted (capture 3; capture 4 or capture 5) + "('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|" + + // 2. simple (capture 6) + "((?:\\\\.|[^\\\\()[\\]]|" + attributes + ")*)|" + + // 3. anything else (capture 2) + ".*" + + ")\\)|)", + + // Leading and non-escaped trailing whitespace, capturing some non-whitespace characters preceding the latter + rwhitespace = new RegExp( whitespace + "+", "g" ), + rtrim = new RegExp( "^" + whitespace + "+|((?:^|[^\\\\])(?:\\\\.)*)" + whitespace + "+$", "g" ), + + rcomma = new RegExp( "^" + whitespace + "*," + whitespace + "*" ), + rcombinators = new RegExp( "^" + whitespace + "*([>+~]|" + whitespace + ")" + whitespace + "*" ), + + rattributeQuotes = new RegExp( "=" + whitespace + "*([^\\]'\"]*?)" + whitespace + "*\\]", "g" ), + + rpseudo = new RegExp( pseudos ), + ridentifier = new RegExp( "^" + identifier + "$" ), + + matchExpr = { + "ID": new RegExp( "^#(" + characterEncoding + ")" ), + "CLASS": new RegExp( "^\\.(" + characterEncoding + ")" ), + "TAG": new RegExp( "^(" + characterEncoding.replace( "w", "w*" ) + ")" ), + "ATTR": new RegExp( "^" + attributes ), + "PSEUDO": new RegExp( "^" + pseudos ), + "CHILD": new RegExp( "^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\(" + whitespace + + "*(even|odd|(([+-]|)(\\d*)n|)" + whitespace + "*(?:([+-]|)" + whitespace + + "*(\\d+)|))" + whitespace + "*\\)|)", "i" ), + "bool": new RegExp( "^(?:" + booleans + ")$", "i" ), + // For use in libraries implementing .is() + // We use this for POS matching in `select` + "needsContext": new RegExp( "^" + whitespace + "*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\(" + + whitespace + "*((?:-\\d)?\\d*)" + whitespace + "*\\)|)(?=[^-]|$)", "i" ) + }, + + rinputs = /^(?:input|select|textarea|button)$/i, + rheader = /^h\d$/i, + + rnative = /^[^{]+\{\s*\[native \w/, + + // Easily-parseable/retrievable ID or TAG or CLASS selectors + rquickExpr = /^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/, + + rsibling = /[+~]/, + rescape = /'|\\/g, + + // CSS escapes http://www.w3.org/TR/CSS21/syndata.html#escaped-characters + runescape = new RegExp( "\\\\([\\da-f]{1,6}" + whitespace + "?|(" + whitespace + ")|.)", "ig" ), + funescape = function( _, escaped, escapedWhitespace ) { + var high = "0x" + escaped - 0x10000; + // NaN means non-codepoint + // Support: Firefox<24 + // Workaround erroneous numeric interpretation of +"0x" + return high !== high || escapedWhitespace ? + escaped : + high < 0 ? + // BMP codepoint + String.fromCharCode( high + 0x10000 ) : + // Supplemental Plane codepoint (surrogate pair) + String.fromCharCode( high >> 10 | 0xD800, high & 0x3FF | 0xDC00 ); + }, + + // Used for iframes + // See setDocument() + // Removing the function wrapper causes a "Permission Denied" + // error in IE + unloadHandler = function() { + setDocument(); + }; + +// Optimize for push.apply( _, NodeList ) +try { + push.apply( + (arr = slice.call( preferredDoc.childNodes )), + preferredDoc.childNodes + ); + // Support: Android<4.0 + // Detect silently failing push.apply + arr[ preferredDoc.childNodes.length ].nodeType; +} catch ( e ) { + push = { apply: arr.length ? + + // Leverage slice if possible + function( target, els ) { + push_native.apply( target, slice.call(els) ); + } : + + // Support: IE<9 + // Otherwise append directly + function( target, els ) { + var j = target.length, + i = 0; + // Can't trust NodeList.length + while ( (target[j++] = els[i++]) ) {} + target.length = j - 1; + } + }; +} + +function Sizzle( selector, context, results, seed ) { + var match, elem, m, nodeType, + // QSA vars + i, groups, old, nid, newContext, newSelector; + + if ( ( context ? context.ownerDocument || context : preferredDoc ) !== document ) { + setDocument( context ); + } + + context = context || document; + results = results || []; + nodeType = context.nodeType; + + if ( typeof selector !== "string" || !selector || + nodeType !== 1 && nodeType !== 9 && nodeType !== 11 ) { + + return results; + } + + if ( !seed && documentIsHTML ) { + + // Try to shortcut find operations when possible (e.g., not under DocumentFragment) + if ( nodeType !== 11 && (match = rquickExpr.exec( selector )) ) { + // Speed-up: Sizzle("#ID") + if ( (m = match[1]) ) { + if ( nodeType === 9 ) { + elem = context.getElementById( m ); + // Check parentNode to catch when Blackberry 4.6 returns + // nodes that are no longer in the document (jQuery #6963) + if ( elem && elem.parentNode ) { + // Handle the case where IE, Opera, and Webkit return items + // by name instead of ID + if ( elem.id === m ) { + results.push( elem ); + return results; + } + } else { + return results; + } + } else { + // Context is not a document + if ( context.ownerDocument && (elem = context.ownerDocument.getElementById( m )) && + contains( context, elem ) && elem.id === m ) { + results.push( elem ); + return results; + } + } + + // Speed-up: Sizzle("TAG") + } else if ( match[2] ) { + push.apply( results, context.getElementsByTagName( selector ) ); + return results; + + // Speed-up: Sizzle(".CLASS") + } else if ( (m = match[3]) && support.getElementsByClassName ) { + push.apply( results, context.getElementsByClassName( m ) ); + return results; + } + } + + // QSA path + if ( support.qsa && (!rbuggyQSA || !rbuggyQSA.test( selector )) ) { + nid = old = expando; + newContext = context; + newSelector = nodeType !== 1 && selector; + + // qSA works strangely on Element-rooted queries + // We can work around this by specifying an extra ID on the root + // and working up from there (Thanks to Andrew Dupont for the technique) + // IE 8 doesn't work on object elements + if ( nodeType === 1 && context.nodeName.toLowerCase() !== "object" ) { + groups = tokenize( selector ); + + if ( (old = context.getAttribute("id")) ) { + nid = old.replace( rescape, "\\$&" ); + } else { + context.setAttribute( "id", nid ); + } + nid = "[id='" + nid + "'] "; + + i = groups.length; + while ( i-- ) { + groups[i] = nid + toSelector( groups[i] ); + } + newContext = rsibling.test( selector ) && testContext( context.parentNode ) || context; + newSelector = groups.join(","); + } + + if ( newSelector ) { + try { + push.apply( results, + newContext.querySelectorAll( newSelector ) + ); + return results; + } catch(qsaError) { + } finally { + if ( !old ) { + context.removeAttribute("id"); + } + } + } + } + } + + // All others + return select( selector.replace( rtrim, "$1" ), context, results, seed ); +} + +/** + * Create key-value caches of limited size + * @returns {Function(string, Object)} Returns the Object data after storing it on itself with + * property name the (space-suffixed) string and (if the cache is larger than Expr.cacheLength) + * deleting the oldest entry + */ +function createCache() { + var keys = []; + + function cache( key, value ) { + // Use (key + " ") to avoid collision with native prototype properties (see Issue #157) + if ( keys.push( key + " " ) > Expr.cacheLength ) { + // Only keep the most recent entries + delete cache[ keys.shift() ]; + } + return (cache[ key + " " ] = value); + } + return cache; +} + +/** + * Mark a function for special use by Sizzle + * @param {Function} fn The function to mark + */ +function markFunction( fn ) { + fn[ expando ] = true; + return fn; +} + +/** + * Support testing using an element + * @param {Function} fn Passed the created div and expects a boolean result + */ +function assert( fn ) { + var div = document.createElement("div"); + + try { + return !!fn( div ); + } catch (e) { + return false; + } finally { + // Remove from its parent by default + if ( div.parentNode ) { + div.parentNode.removeChild( div ); + } + // release memory in IE + div = null; + } +} + +/** + * Adds the same handler for all of the specified attrs + * @param {String} attrs Pipe-separated list of attributes + * @param {Function} handler The method that will be applied + */ +function addHandle( attrs, handler ) { + var arr = attrs.split("|"), + i = attrs.length; + + while ( i-- ) { + Expr.attrHandle[ arr[i] ] = handler; + } +} + +/** + * Checks document order of two siblings + * @param {Element} a + * @param {Element} b + * @returns {Number} Returns less than 0 if a precedes b, greater than 0 if a follows b + */ +function siblingCheck( a, b ) { + var cur = b && a, + diff = cur && a.nodeType === 1 && b.nodeType === 1 && + ( ~b.sourceIndex || MAX_NEGATIVE ) - + ( ~a.sourceIndex || MAX_NEGATIVE ); + + // Use IE sourceIndex if available on both nodes + if ( diff ) { + return diff; + } + + // Check if b follows a + if ( cur ) { + while ( (cur = cur.nextSibling) ) { + if ( cur === b ) { + return -1; + } + } + } + + return a ? 1 : -1; +} + +/** + * Returns a function to use in pseudos for input types + * @param {String} type + */ +function createInputPseudo( type ) { + return function( elem ) { + var name = elem.nodeName.toLowerCase(); + return name === "input" && elem.type === type; + }; +} + +/** + * Returns a function to use in pseudos for buttons + * @param {String} type + */ +function createButtonPseudo( type ) { + return function( elem ) { + var name = elem.nodeName.toLowerCase(); + return (name === "input" || name === "button") && elem.type === type; + }; +} + +/** + * Returns a function to use in pseudos for positionals + * @param {Function} fn + */ +function createPositionalPseudo( fn ) { + return markFunction(function( argument ) { + argument = +argument; + return markFunction(function( seed, matches ) { + var j, + matchIndexes = fn( [], seed.length, argument ), + i = matchIndexes.length; + + // Match elements found at the specified indexes + while ( i-- ) { + if ( seed[ (j = matchIndexes[i]) ] ) { + seed[j] = !(matches[j] = seed[j]); + } + } + }); + }); +} + +/** + * Checks a node for validity as a Sizzle context + * @param {Element|Object=} context + * @returns {Element|Object|Boolean} The input node if acceptable, otherwise a falsy value + */ +function testContext( context ) { + return context && typeof context.getElementsByTagName !== "undefined" && context; +} + +// Expose support vars for convenience +support = Sizzle.support = {}; + +/** + * Detects XML nodes + * @param {Element|Object} elem An element or a document + * @returns {Boolean} True iff elem is a non-HTML XML node + */ +isXML = Sizzle.isXML = function( elem ) { + // documentElement is verified for cases where it doesn't yet exist + // (such as loading iframes in IE - #4833) + var documentElement = elem && (elem.ownerDocument || elem).documentElement; + return documentElement ? documentElement.nodeName !== "HTML" : false; +}; + +/** + * Sets document-related variables once based on the current document + * @param {Element|Object} [doc] An element or document object to use to set the document + * @returns {Object} Returns the current document + */ +setDocument = Sizzle.setDocument = function( node ) { + var hasCompare, parent, + doc = node ? node.ownerDocument || node : preferredDoc; + + // If no document and documentElement is available, return + if ( doc === document || doc.nodeType !== 9 || !doc.documentElement ) { + return document; + } + + // Set our document + document = doc; + docElem = doc.documentElement; + parent = doc.defaultView; + + // Support: IE>8 + // If iframe document is assigned to "document" variable and if iframe has been reloaded, + // IE will throw "permission denied" error when accessing "document" variable, see jQuery #13936 + // IE6-8 do not support the defaultView property so parent will be undefined + if ( parent && parent !== parent.top ) { + // IE11 does not have attachEvent, so all must suffer + if ( parent.addEventListener ) { + parent.addEventListener( "unload", unloadHandler, false ); + } else if ( parent.attachEvent ) { + parent.attachEvent( "onunload", unloadHandler ); + } + } + + /* Support tests + ---------------------------------------------------------------------- */ + documentIsHTML = !isXML( doc ); + + /* Attributes + ---------------------------------------------------------------------- */ + + // Support: IE<8 + // Verify that getAttribute really returns attributes and not properties + // (excepting IE8 booleans) + support.attributes = assert(function( div ) { + div.className = "i"; + return !div.getAttribute("className"); + }); + + /* getElement(s)By* + ---------------------------------------------------------------------- */ + + // Check if getElementsByTagName("*") returns only elements + support.getElementsByTagName = assert(function( div ) { + div.appendChild( doc.createComment("") ); + return !div.getElementsByTagName("*").length; + }); + + // Support: IE<9 + support.getElementsByClassName = rnative.test( doc.getElementsByClassName ); + + // Support: IE<10 + // Check if getElementById returns elements by name + // The broken getElementById methods don't pick up programatically-set names, + // so use a roundabout getElementsByName test + support.getById = assert(function( div ) { + docElem.appendChild( div ).id = expando; + return !doc.getElementsByName || !doc.getElementsByName( expando ).length; + }); + + // ID find and filter + if ( support.getById ) { + Expr.find["ID"] = function( id, context ) { + if ( typeof context.getElementById !== "undefined" && documentIsHTML ) { + var m = context.getElementById( id ); + // Check parentNode to catch when Blackberry 4.6 returns + // nodes that are no longer in the document #6963 + return m && m.parentNode ? [ m ] : []; + } + }; + Expr.filter["ID"] = function( id ) { + var attrId = id.replace( runescape, funescape ); + return function( elem ) { + return elem.getAttribute("id") === attrId; + }; + }; + } else { + // Support: IE6/7 + // getElementById is not reliable as a find shortcut + delete Expr.find["ID"]; + + Expr.filter["ID"] = function( id ) { + var attrId = id.replace( runescape, funescape ); + return function( elem ) { + var node = typeof elem.getAttributeNode !== "undefined" && elem.getAttributeNode("id"); + return node && node.value === attrId; + }; + }; + } + + // Tag + Expr.find["TAG"] = support.getElementsByTagName ? + function( tag, context ) { + if ( typeof context.getElementsByTagName !== "undefined" ) { + return context.getElementsByTagName( tag ); + + // DocumentFragment nodes don't have gEBTN + } else if ( support.qsa ) { + return context.querySelectorAll( tag ); + } + } : + + function( tag, context ) { + var elem, + tmp = [], + i = 0, + // By happy coincidence, a (broken) gEBTN appears on DocumentFragment nodes too + results = context.getElementsByTagName( tag ); + + // Filter out possible comments + if ( tag === "*" ) { + while ( (elem = results[i++]) ) { + if ( elem.nodeType === 1 ) { + tmp.push( elem ); + } + } + + return tmp; + } + return results; + }; + + // Class + Expr.find["CLASS"] = support.getElementsByClassName && function( className, context ) { + if ( documentIsHTML ) { + return context.getElementsByClassName( className ); + } + }; + + /* QSA/matchesSelector + ---------------------------------------------------------------------- */ + + // QSA and matchesSelector support + + // matchesSelector(:active) reports false when true (IE9/Opera 11.5) + rbuggyMatches = []; + + // qSa(:focus) reports false when true (Chrome 21) + // We allow this because of a bug in IE8/9 that throws an error + // whenever `document.activeElement` is accessed on an iframe + // So, we allow :focus to pass through QSA all the time to avoid the IE error + // See http://bugs.jquery.com/ticket/13378 + rbuggyQSA = []; + + if ( (support.qsa = rnative.test( doc.querySelectorAll )) ) { + // Build QSA regex + // Regex strategy adopted from Diego Perini + assert(function( div ) { + // Select is set to empty string on purpose + // This is to test IE's treatment of not explicitly + // setting a boolean content attribute, + // since its presence should be enough + // http://bugs.jquery.com/ticket/12359 + docElem.appendChild( div ).innerHTML = "" + + ""; + + // Support: IE8, Opera 11-12.16 + // Nothing should be selected when empty strings follow ^= or $= or *= + // The test attribute must be unknown in Opera but "safe" for WinRT + // http://msdn.microsoft.com/en-us/library/ie/hh465388.aspx#attribute_section + if ( div.querySelectorAll("[msallowcapture^='']").length ) { + rbuggyQSA.push( "[*^$]=" + whitespace + "*(?:''|\"\")" ); + } + + // Support: IE8 + // Boolean attributes and "value" are not treated correctly + if ( !div.querySelectorAll("[selected]").length ) { + rbuggyQSA.push( "\\[" + whitespace + "*(?:value|" + booleans + ")" ); + } + + // Support: Chrome<29, Android<4.2+, Safari<7.0+, iOS<7.0+, PhantomJS<1.9.7+ + if ( !div.querySelectorAll( "[id~=" + expando + "-]" ).length ) { + rbuggyQSA.push("~="); + } + + // Webkit/Opera - :checked should return selected option elements + // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked + // IE8 throws error here and will not see later tests + if ( !div.querySelectorAll(":checked").length ) { + rbuggyQSA.push(":checked"); + } + + // Support: Safari 8+, iOS 8+ + // https://bugs.webkit.org/show_bug.cgi?id=136851 + // In-page `selector#id sibing-combinator selector` fails + if ( !div.querySelectorAll( "a#" + expando + "+*" ).length ) { + rbuggyQSA.push(".#.+[+~]"); + } + }); + + assert(function( div ) { + // Support: Windows 8 Native Apps + // The type and name attributes are restricted during .innerHTML assignment + var input = doc.createElement("input"); + input.setAttribute( "type", "hidden" ); + div.appendChild( input ).setAttribute( "name", "D" ); + + // Support: IE8 + // Enforce case-sensitivity of name attribute + if ( div.querySelectorAll("[name=d]").length ) { + rbuggyQSA.push( "name" + whitespace + "*[*^$|!~]?=" ); + } + + // FF 3.5 - :enabled/:disabled and hidden elements (hidden elements are still enabled) + // IE8 throws error here and will not see later tests + if ( !div.querySelectorAll(":enabled").length ) { + rbuggyQSA.push( ":enabled", ":disabled" ); + } + + // Opera 10-11 does not throw on post-comma invalid pseudos + div.querySelectorAll("*,:x"); + rbuggyQSA.push(",.*:"); + }); + } + + if ( (support.matchesSelector = rnative.test( (matches = docElem.matches || + docElem.webkitMatchesSelector || + docElem.mozMatchesSelector || + docElem.oMatchesSelector || + docElem.msMatchesSelector) )) ) { + + assert(function( div ) { + // Check to see if it's possible to do matchesSelector + // on a disconnected node (IE 9) + support.disconnectedMatch = matches.call( div, "div" ); + + // This should fail with an exception + // Gecko does not error, returns false instead + matches.call( div, "[s!='']:x" ); + rbuggyMatches.push( "!=", pseudos ); + }); + } + + rbuggyQSA = rbuggyQSA.length && new RegExp( rbuggyQSA.join("|") ); + rbuggyMatches = rbuggyMatches.length && new RegExp( rbuggyMatches.join("|") ); + + /* Contains + ---------------------------------------------------------------------- */ + hasCompare = rnative.test( docElem.compareDocumentPosition ); + + // Element contains another + // Purposefully does not implement inclusive descendent + // As in, an element does not contain itself + contains = hasCompare || rnative.test( docElem.contains ) ? + function( a, b ) { + var adown = a.nodeType === 9 ? a.documentElement : a, + bup = b && b.parentNode; + return a === bup || !!( bup && bup.nodeType === 1 && ( + adown.contains ? + adown.contains( bup ) : + a.compareDocumentPosition && a.compareDocumentPosition( bup ) & 16 + )); + } : + function( a, b ) { + if ( b ) { + while ( (b = b.parentNode) ) { + if ( b === a ) { + return true; + } + } + } + return false; + }; + + /* Sorting + ---------------------------------------------------------------------- */ + + // Document order sorting + sortOrder = hasCompare ? + function( a, b ) { + + // Flag for duplicate removal + if ( a === b ) { + hasDuplicate = true; + return 0; + } + + // Sort on method existence if only one input has compareDocumentPosition + var compare = !a.compareDocumentPosition - !b.compareDocumentPosition; + if ( compare ) { + return compare; + } + + // Calculate position if both inputs belong to the same document + compare = ( a.ownerDocument || a ) === ( b.ownerDocument || b ) ? + a.compareDocumentPosition( b ) : + + // Otherwise we know they are disconnected + 1; + + // Disconnected nodes + if ( compare & 1 || + (!support.sortDetached && b.compareDocumentPosition( a ) === compare) ) { + + // Choose the first element that is related to our preferred document + if ( a === doc || a.ownerDocument === preferredDoc && contains(preferredDoc, a) ) { + return -1; + } + if ( b === doc || b.ownerDocument === preferredDoc && contains(preferredDoc, b) ) { + return 1; + } + + // Maintain original order + return sortInput ? + ( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) : + 0; + } + + return compare & 4 ? -1 : 1; + } : + function( a, b ) { + // Exit early if the nodes are identical + if ( a === b ) { + hasDuplicate = true; + return 0; + } + + var cur, + i = 0, + aup = a.parentNode, + bup = b.parentNode, + ap = [ a ], + bp = [ b ]; + + // Parentless nodes are either documents or disconnected + if ( !aup || !bup ) { + return a === doc ? -1 : + b === doc ? 1 : + aup ? -1 : + bup ? 1 : + sortInput ? + ( indexOf( sortInput, a ) - indexOf( sortInput, b ) ) : + 0; + + // If the nodes are siblings, we can do a quick check + } else if ( aup === bup ) { + return siblingCheck( a, b ); + } + + // Otherwise we need full lists of their ancestors for comparison + cur = a; + while ( (cur = cur.parentNode) ) { + ap.unshift( cur ); + } + cur = b; + while ( (cur = cur.parentNode) ) { + bp.unshift( cur ); + } + + // Walk down the tree looking for a discrepancy + while ( ap[i] === bp[i] ) { + i++; + } + + return i ? + // Do a sibling check if the nodes have a common ancestor + siblingCheck( ap[i], bp[i] ) : + + // Otherwise nodes in our document sort first + ap[i] === preferredDoc ? -1 : + bp[i] === preferredDoc ? 1 : + 0; + }; + + return doc; +}; + +Sizzle.matches = function( expr, elements ) { + return Sizzle( expr, null, null, elements ); +}; + +Sizzle.matchesSelector = function( elem, expr ) { + // Set document vars if needed + if ( ( elem.ownerDocument || elem ) !== document ) { + setDocument( elem ); + } + + // Make sure that attribute selectors are quoted + expr = expr.replace( rattributeQuotes, "='$1']" ); + + if ( support.matchesSelector && documentIsHTML && + ( !rbuggyMatches || !rbuggyMatches.test( expr ) ) && + ( !rbuggyQSA || !rbuggyQSA.test( expr ) ) ) { + + try { + var ret = matches.call( elem, expr ); + + // IE 9's matchesSelector returns false on disconnected nodes + if ( ret || support.disconnectedMatch || + // As well, disconnected nodes are said to be in a document + // fragment in IE 9 + elem.document && elem.document.nodeType !== 11 ) { + return ret; + } + } catch (e) {} + } + + return Sizzle( expr, document, null, [ elem ] ).length > 0; +}; + +Sizzle.contains = function( context, elem ) { + // Set document vars if needed + if ( ( context.ownerDocument || context ) !== document ) { + setDocument( context ); + } + return contains( context, elem ); +}; + +Sizzle.attr = function( elem, name ) { + // Set document vars if needed + if ( ( elem.ownerDocument || elem ) !== document ) { + setDocument( elem ); + } + + var fn = Expr.attrHandle[ name.toLowerCase() ], + // Don't get fooled by Object.prototype properties (jQuery #13807) + val = fn && hasOwn.call( Expr.attrHandle, name.toLowerCase() ) ? + fn( elem, name, !documentIsHTML ) : + undefined; + + return val !== undefined ? + val : + support.attributes || !documentIsHTML ? + elem.getAttribute( name ) : + (val = elem.getAttributeNode(name)) && val.specified ? + val.value : + null; +}; + +Sizzle.error = function( msg ) { + throw new Error( "Syntax error, unrecognized expression: " + msg ); +}; + +/** + * Document sorting and removing duplicates + * @param {ArrayLike} results + */ +Sizzle.uniqueSort = function( results ) { + var elem, + duplicates = [], + j = 0, + i = 0; + + // Unless we *know* we can detect duplicates, assume their presence + hasDuplicate = !support.detectDuplicates; + sortInput = !support.sortStable && results.slice( 0 ); + results.sort( sortOrder ); + + if ( hasDuplicate ) { + while ( (elem = results[i++]) ) { + if ( elem === results[ i ] ) { + j = duplicates.push( i ); + } + } + while ( j-- ) { + results.splice( duplicates[ j ], 1 ); + } + } + + // Clear input after sorting to release objects + // See https://github.com/jquery/sizzle/pull/225 + sortInput = null; + + return results; +}; + +/** + * Utility function for retrieving the text value of an array of DOM nodes + * @param {Array|Element} elem + */ +getText = Sizzle.getText = function( elem ) { + var node, + ret = "", + i = 0, + nodeType = elem.nodeType; + + if ( !nodeType ) { + // If no nodeType, this is expected to be an array + while ( (node = elem[i++]) ) { + // Do not traverse comment nodes + ret += getText( node ); + } + } else if ( nodeType === 1 || nodeType === 9 || nodeType === 11 ) { + // Use textContent for elements + // innerText usage removed for consistency of new lines (jQuery #11153) + if ( typeof elem.textContent === "string" ) { + return elem.textContent; + } else { + // Traverse its children + for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) { + ret += getText( elem ); + } + } + } else if ( nodeType === 3 || nodeType === 4 ) { + return elem.nodeValue; + } + // Do not include comment or processing instruction nodes + + return ret; +}; + +Expr = Sizzle.selectors = { + + // Can be adjusted by the user + cacheLength: 50, + + createPseudo: markFunction, + + match: matchExpr, + + attrHandle: {}, + + find: {}, + + relative: { + ">": { dir: "parentNode", first: true }, + " ": { dir: "parentNode" }, + "+": { dir: "previousSibling", first: true }, + "~": { dir: "previousSibling" } + }, + + preFilter: { + "ATTR": function( match ) { + match[1] = match[1].replace( runescape, funescape ); + + // Move the given value to match[3] whether quoted or unquoted + match[3] = ( match[3] || match[4] || match[5] || "" ).replace( runescape, funescape ); + + if ( match[2] === "~=" ) { + match[3] = " " + match[3] + " "; + } + + return match.slice( 0, 4 ); + }, + + "CHILD": function( match ) { + /* matches from matchExpr["CHILD"] + 1 type (only|nth|...) + 2 what (child|of-type) + 3 argument (even|odd|\d*|\d*n([+-]\d+)?|...) + 4 xn-component of xn+y argument ([+-]?\d*n|) + 5 sign of xn-component + 6 x of xn-component + 7 sign of y-component + 8 y of y-component + */ + match[1] = match[1].toLowerCase(); + + if ( match[1].slice( 0, 3 ) === "nth" ) { + // nth-* requires argument + if ( !match[3] ) { + Sizzle.error( match[0] ); + } + + // numeric x and y parameters for Expr.filter.CHILD + // remember that false/true cast respectively to 0/1 + match[4] = +( match[4] ? match[5] + (match[6] || 1) : 2 * ( match[3] === "even" || match[3] === "odd" ) ); + match[5] = +( ( match[7] + match[8] ) || match[3] === "odd" ); + + // other types prohibit arguments + } else if ( match[3] ) { + Sizzle.error( match[0] ); + } + + return match; + }, + + "PSEUDO": function( match ) { + var excess, + unquoted = !match[6] && match[2]; + + if ( matchExpr["CHILD"].test( match[0] ) ) { + return null; + } + + // Accept quoted arguments as-is + if ( match[3] ) { + match[2] = match[4] || match[5] || ""; + + // Strip excess characters from unquoted arguments + } else if ( unquoted && rpseudo.test( unquoted ) && + // Get excess from tokenize (recursively) + (excess = tokenize( unquoted, true )) && + // advance to the next closing parenthesis + (excess = unquoted.indexOf( ")", unquoted.length - excess ) - unquoted.length) ) { + + // excess is a negative index + match[0] = match[0].slice( 0, excess ); + match[2] = unquoted.slice( 0, excess ); + } + + // Return only captures needed by the pseudo filter method (type and argument) + return match.slice( 0, 3 ); + } + }, + + filter: { + + "TAG": function( nodeNameSelector ) { + var nodeName = nodeNameSelector.replace( runescape, funescape ).toLowerCase(); + return nodeNameSelector === "*" ? + function() { return true; } : + function( elem ) { + return elem.nodeName && elem.nodeName.toLowerCase() === nodeName; + }; + }, + + "CLASS": function( className ) { + var pattern = classCache[ className + " " ]; + + return pattern || + (pattern = new RegExp( "(^|" + whitespace + ")" + className + "(" + whitespace + "|$)" )) && + classCache( className, function( elem ) { + return pattern.test( typeof elem.className === "string" && elem.className || typeof elem.getAttribute !== "undefined" && elem.getAttribute("class") || "" ); + }); + }, + + "ATTR": function( name, operator, check ) { + return function( elem ) { + var result = Sizzle.attr( elem, name ); + + if ( result == null ) { + return operator === "!="; + } + if ( !operator ) { + return true; + } + + result += ""; + + return operator === "=" ? result === check : + operator === "!=" ? result !== check : + operator === "^=" ? check && result.indexOf( check ) === 0 : + operator === "*=" ? check && result.indexOf( check ) > -1 : + operator === "$=" ? check && result.slice( -check.length ) === check : + operator === "~=" ? ( " " + result.replace( rwhitespace, " " ) + " " ).indexOf( check ) > -1 : + operator === "|=" ? result === check || result.slice( 0, check.length + 1 ) === check + "-" : + false; + }; + }, + + "CHILD": function( type, what, argument, first, last ) { + var simple = type.slice( 0, 3 ) !== "nth", + forward = type.slice( -4 ) !== "last", + ofType = what === "of-type"; + + return first === 1 && last === 0 ? + + // Shortcut for :nth-*(n) + function( elem ) { + return !!elem.parentNode; + } : + + function( elem, context, xml ) { + var cache, outerCache, node, diff, nodeIndex, start, + dir = simple !== forward ? "nextSibling" : "previousSibling", + parent = elem.parentNode, + name = ofType && elem.nodeName.toLowerCase(), + useCache = !xml && !ofType; + + if ( parent ) { + + // :(first|last|only)-(child|of-type) + if ( simple ) { + while ( dir ) { + node = elem; + while ( (node = node[ dir ]) ) { + if ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) { + return false; + } + } + // Reverse direction for :only-* (if we haven't yet done so) + start = dir = type === "only" && !start && "nextSibling"; + } + return true; + } + + start = [ forward ? parent.firstChild : parent.lastChild ]; + + // non-xml :nth-child(...) stores cache data on `parent` + if ( forward && useCache ) { + // Seek `elem` from a previously-cached index + outerCache = parent[ expando ] || (parent[ expando ] = {}); + cache = outerCache[ type ] || []; + nodeIndex = cache[0] === dirruns && cache[1]; + diff = cache[0] === dirruns && cache[2]; + node = nodeIndex && parent.childNodes[ nodeIndex ]; + + while ( (node = ++nodeIndex && node && node[ dir ] || + + // Fallback to seeking `elem` from the start + (diff = nodeIndex = 0) || start.pop()) ) { + + // When found, cache indexes on `parent` and break + if ( node.nodeType === 1 && ++diff && node === elem ) { + outerCache[ type ] = [ dirruns, nodeIndex, diff ]; + break; + } + } + + // Use previously-cached element index if available + } else if ( useCache && (cache = (elem[ expando ] || (elem[ expando ] = {}))[ type ]) && cache[0] === dirruns ) { + diff = cache[1]; + + // xml :nth-child(...) or :nth-last-child(...) or :nth(-last)?-of-type(...) + } else { + // Use the same loop as above to seek `elem` from the start + while ( (node = ++nodeIndex && node && node[ dir ] || + (diff = nodeIndex = 0) || start.pop()) ) { + + if ( ( ofType ? node.nodeName.toLowerCase() === name : node.nodeType === 1 ) && ++diff ) { + // Cache the index of each encountered element + if ( useCache ) { + (node[ expando ] || (node[ expando ] = {}))[ type ] = [ dirruns, diff ]; + } + + if ( node === elem ) { + break; + } + } + } + } + + // Incorporate the offset, then check against cycle size + diff -= last; + return diff === first || ( diff % first === 0 && diff / first >= 0 ); + } + }; + }, + + "PSEUDO": function( pseudo, argument ) { + // pseudo-class names are case-insensitive + // http://www.w3.org/TR/selectors/#pseudo-classes + // Prioritize by case sensitivity in case custom pseudos are added with uppercase letters + // Remember that setFilters inherits from pseudos + var args, + fn = Expr.pseudos[ pseudo ] || Expr.setFilters[ pseudo.toLowerCase() ] || + Sizzle.error( "unsupported pseudo: " + pseudo ); + + // The user may use createPseudo to indicate that + // arguments are needed to create the filter function + // just as Sizzle does + if ( fn[ expando ] ) { + return fn( argument ); + } + + // But maintain support for old signatures + if ( fn.length > 1 ) { + args = [ pseudo, pseudo, "", argument ]; + return Expr.setFilters.hasOwnProperty( pseudo.toLowerCase() ) ? + markFunction(function( seed, matches ) { + var idx, + matched = fn( seed, argument ), + i = matched.length; + while ( i-- ) { + idx = indexOf( seed, matched[i] ); + seed[ idx ] = !( matches[ idx ] = matched[i] ); + } + }) : + function( elem ) { + return fn( elem, 0, args ); + }; + } + + return fn; + } + }, + + pseudos: { + // Potentially complex pseudos + "not": markFunction(function( selector ) { + // Trim the selector passed to compile + // to avoid treating leading and trailing + // spaces as combinators + var input = [], + results = [], + matcher = compile( selector.replace( rtrim, "$1" ) ); + + return matcher[ expando ] ? + markFunction(function( seed, matches, context, xml ) { + var elem, + unmatched = matcher( seed, null, xml, [] ), + i = seed.length; + + // Match elements unmatched by `matcher` + while ( i-- ) { + if ( (elem = unmatched[i]) ) { + seed[i] = !(matches[i] = elem); + } + } + }) : + function( elem, context, xml ) { + input[0] = elem; + matcher( input, null, xml, results ); + // Don't keep the element (issue #299) + input[0] = null; + return !results.pop(); + }; + }), + + "has": markFunction(function( selector ) { + return function( elem ) { + return Sizzle( selector, elem ).length > 0; + }; + }), + + "contains": markFunction(function( text ) { + text = text.replace( runescape, funescape ); + return function( elem ) { + return ( elem.textContent || elem.innerText || getText( elem ) ).indexOf( text ) > -1; + }; + }), + + // "Whether an element is represented by a :lang() selector + // is based solely on the element's language value + // being equal to the identifier C, + // or beginning with the identifier C immediately followed by "-". + // The matching of C against the element's language value is performed case-insensitively. + // The identifier C does not have to be a valid language name." + // http://www.w3.org/TR/selectors/#lang-pseudo + "lang": markFunction( function( lang ) { + // lang value must be a valid identifier + if ( !ridentifier.test(lang || "") ) { + Sizzle.error( "unsupported lang: " + lang ); + } + lang = lang.replace( runescape, funescape ).toLowerCase(); + return function( elem ) { + var elemLang; + do { + if ( (elemLang = documentIsHTML ? + elem.lang : + elem.getAttribute("xml:lang") || elem.getAttribute("lang")) ) { + + elemLang = elemLang.toLowerCase(); + return elemLang === lang || elemLang.indexOf( lang + "-" ) === 0; + } + } while ( (elem = elem.parentNode) && elem.nodeType === 1 ); + return false; + }; + }), + + // Miscellaneous + "target": function( elem ) { + var hash = window.location && window.location.hash; + return hash && hash.slice( 1 ) === elem.id; + }, + + "root": function( elem ) { + return elem === docElem; + }, + + "focus": function( elem ) { + return elem === document.activeElement && (!document.hasFocus || document.hasFocus()) && !!(elem.type || elem.href || ~elem.tabIndex); + }, + + // Boolean properties + "enabled": function( elem ) { + return elem.disabled === false; + }, + + "disabled": function( elem ) { + return elem.disabled === true; + }, + + "checked": function( elem ) { + // In CSS3, :checked should return both checked and selected elements + // http://www.w3.org/TR/2011/REC-css3-selectors-20110929/#checked + var nodeName = elem.nodeName.toLowerCase(); + return (nodeName === "input" && !!elem.checked) || (nodeName === "option" && !!elem.selected); + }, + + "selected": function( elem ) { + // Accessing this property makes selected-by-default + // options in Safari work properly + if ( elem.parentNode ) { + elem.parentNode.selectedIndex; + } + + return elem.selected === true; + }, + + // Contents + "empty": function( elem ) { + // http://www.w3.org/TR/selectors/#empty-pseudo + // :empty is negated by element (1) or content nodes (text: 3; cdata: 4; entity ref: 5), + // but not by others (comment: 8; processing instruction: 7; etc.) + // nodeType < 6 works because attributes (2) do not appear as children + for ( elem = elem.firstChild; elem; elem = elem.nextSibling ) { + if ( elem.nodeType < 6 ) { + return false; + } + } + return true; + }, + + "parent": function( elem ) { + return !Expr.pseudos["empty"]( elem ); + }, + + // Element/input types + "header": function( elem ) { + return rheader.test( elem.nodeName ); + }, + + "input": function( elem ) { + return rinputs.test( elem.nodeName ); + }, + + "button": function( elem ) { + var name = elem.nodeName.toLowerCase(); + return name === "input" && elem.type === "button" || name === "button"; + }, + + "text": function( elem ) { + var attr; + return elem.nodeName.toLowerCase() === "input" && + elem.type === "text" && + + // Support: IE<8 + // New HTML5 attribute values (e.g., "search") appear with elem.type === "text" + ( (attr = elem.getAttribute("type")) == null || attr.toLowerCase() === "text" ); + }, + + // Position-in-collection + "first": createPositionalPseudo(function() { + return [ 0 ]; + }), + + "last": createPositionalPseudo(function( matchIndexes, length ) { + return [ length - 1 ]; + }), + + "eq": createPositionalPseudo(function( matchIndexes, length, argument ) { + return [ argument < 0 ? argument + length : argument ]; + }), + + "even": createPositionalPseudo(function( matchIndexes, length ) { + var i = 0; + for ( ; i < length; i += 2 ) { + matchIndexes.push( i ); + } + return matchIndexes; + }), + + "odd": createPositionalPseudo(function( matchIndexes, length ) { + var i = 1; + for ( ; i < length; i += 2 ) { + matchIndexes.push( i ); + } + return matchIndexes; + }), + + "lt": createPositionalPseudo(function( matchIndexes, length, argument ) { + var i = argument < 0 ? argument + length : argument; + for ( ; --i >= 0; ) { + matchIndexes.push( i ); + } + return matchIndexes; + }), + + "gt": createPositionalPseudo(function( matchIndexes, length, argument ) { + var i = argument < 0 ? argument + length : argument; + for ( ; ++i < length; ) { + matchIndexes.push( i ); + } + return matchIndexes; + }) + } +}; + +Expr.pseudos["nth"] = Expr.pseudos["eq"]; + +// Add button/input type pseudos +for ( i in { radio: true, checkbox: true, file: true, password: true, image: true } ) { + Expr.pseudos[ i ] = createInputPseudo( i ); +} +for ( i in { submit: true, reset: true } ) { + Expr.pseudos[ i ] = createButtonPseudo( i ); +} + +// Easy API for creating new setFilters +function setFilters() {} +setFilters.prototype = Expr.filters = Expr.pseudos; +Expr.setFilters = new setFilters(); + +tokenize = Sizzle.tokenize = function( selector, parseOnly ) { + var matched, match, tokens, type, + soFar, groups, preFilters, + cached = tokenCache[ selector + " " ]; + + if ( cached ) { + return parseOnly ? 0 : cached.slice( 0 ); + } + + soFar = selector; + groups = []; + preFilters = Expr.preFilter; + + while ( soFar ) { + + // Comma and first run + if ( !matched || (match = rcomma.exec( soFar )) ) { + if ( match ) { + // Don't consume trailing commas as valid + soFar = soFar.slice( match[0].length ) || soFar; + } + groups.push( (tokens = []) ); + } + + matched = false; + + // Combinators + if ( (match = rcombinators.exec( soFar )) ) { + matched = match.shift(); + tokens.push({ + value: matched, + // Cast descendant combinators to space + type: match[0].replace( rtrim, " " ) + }); + soFar = soFar.slice( matched.length ); + } + + // Filters + for ( type in Expr.filter ) { + if ( (match = matchExpr[ type ].exec( soFar )) && (!preFilters[ type ] || + (match = preFilters[ type ]( match ))) ) { + matched = match.shift(); + tokens.push({ + value: matched, + type: type, + matches: match + }); + soFar = soFar.slice( matched.length ); + } + } + + if ( !matched ) { + break; + } + } + + // Return the length of the invalid excess + // if we're just parsing + // Otherwise, throw an error or return tokens + return parseOnly ? + soFar.length : + soFar ? + Sizzle.error( selector ) : + // Cache the tokens + tokenCache( selector, groups ).slice( 0 ); +}; + +function toSelector( tokens ) { + var i = 0, + len = tokens.length, + selector = ""; + for ( ; i < len; i++ ) { + selector += tokens[i].value; + } + return selector; +} + +function addCombinator( matcher, combinator, base ) { + var dir = combinator.dir, + checkNonElements = base && dir === "parentNode", + doneName = done++; + + return combinator.first ? + // Check against closest ancestor/preceding element + function( elem, context, xml ) { + while ( (elem = elem[ dir ]) ) { + if ( elem.nodeType === 1 || checkNonElements ) { + return matcher( elem, context, xml ); + } + } + } : + + // Check against all ancestor/preceding elements + function( elem, context, xml ) { + var oldCache, outerCache, + newCache = [ dirruns, doneName ]; + + // We can't set arbitrary data on XML nodes, so they don't benefit from dir caching + if ( xml ) { + while ( (elem = elem[ dir ]) ) { + if ( elem.nodeType === 1 || checkNonElements ) { + if ( matcher( elem, context, xml ) ) { + return true; + } + } + } + } else { + while ( (elem = elem[ dir ]) ) { + if ( elem.nodeType === 1 || checkNonElements ) { + outerCache = elem[ expando ] || (elem[ expando ] = {}); + if ( (oldCache = outerCache[ dir ]) && + oldCache[ 0 ] === dirruns && oldCache[ 1 ] === doneName ) { + + // Assign to newCache so results back-propagate to previous elements + return (newCache[ 2 ] = oldCache[ 2 ]); + } else { + // Reuse newcache so results back-propagate to previous elements + outerCache[ dir ] = newCache; + + // A match means we're done; a fail means we have to keep checking + if ( (newCache[ 2 ] = matcher( elem, context, xml )) ) { + return true; + } + } + } + } + } + }; +} + +function elementMatcher( matchers ) { + return matchers.length > 1 ? + function( elem, context, xml ) { + var i = matchers.length; + while ( i-- ) { + if ( !matchers[i]( elem, context, xml ) ) { + return false; + } + } + return true; + } : + matchers[0]; +} + +function multipleContexts( selector, contexts, results ) { + var i = 0, + len = contexts.length; + for ( ; i < len; i++ ) { + Sizzle( selector, contexts[i], results ); + } + return results; +} + +function condense( unmatched, map, filter, context, xml ) { + var elem, + newUnmatched = [], + i = 0, + len = unmatched.length, + mapped = map != null; + + for ( ; i < len; i++ ) { + if ( (elem = unmatched[i]) ) { + if ( !filter || filter( elem, context, xml ) ) { + newUnmatched.push( elem ); + if ( mapped ) { + map.push( i ); + } + } + } + } + + return newUnmatched; +} + +function setMatcher( preFilter, selector, matcher, postFilter, postFinder, postSelector ) { + if ( postFilter && !postFilter[ expando ] ) { + postFilter = setMatcher( postFilter ); + } + if ( postFinder && !postFinder[ expando ] ) { + postFinder = setMatcher( postFinder, postSelector ); + } + return markFunction(function( seed, results, context, xml ) { + var temp, i, elem, + preMap = [], + postMap = [], + preexisting = results.length, + + // Get initial elements from seed or context + elems = seed || multipleContexts( selector || "*", context.nodeType ? [ context ] : context, [] ), + + // Prefilter to get matcher input, preserving a map for seed-results synchronization + matcherIn = preFilter && ( seed || !selector ) ? + condense( elems, preMap, preFilter, context, xml ) : + elems, + + matcherOut = matcher ? + // If we have a postFinder, or filtered seed, or non-seed postFilter or preexisting results, + postFinder || ( seed ? preFilter : preexisting || postFilter ) ? + + // ...intermediate processing is necessary + [] : + + // ...otherwise use results directly + results : + matcherIn; + + // Find primary matches + if ( matcher ) { + matcher( matcherIn, matcherOut, context, xml ); + } + + // Apply postFilter + if ( postFilter ) { + temp = condense( matcherOut, postMap ); + postFilter( temp, [], context, xml ); + + // Un-match failing elements by moving them back to matcherIn + i = temp.length; + while ( i-- ) { + if ( (elem = temp[i]) ) { + matcherOut[ postMap[i] ] = !(matcherIn[ postMap[i] ] = elem); + } + } + } + + if ( seed ) { + if ( postFinder || preFilter ) { + if ( postFinder ) { + // Get the final matcherOut by condensing this intermediate into postFinder contexts + temp = []; + i = matcherOut.length; + while ( i-- ) { + if ( (elem = matcherOut[i]) ) { + // Restore matcherIn since elem is not yet a final match + temp.push( (matcherIn[i] = elem) ); + } + } + postFinder( null, (matcherOut = []), temp, xml ); + } + + // Move matched elements from seed to results to keep them synchronized + i = matcherOut.length; + while ( i-- ) { + if ( (elem = matcherOut[i]) && + (temp = postFinder ? indexOf( seed, elem ) : preMap[i]) > -1 ) { + + seed[temp] = !(results[temp] = elem); + } + } + } + + // Add elements to results, through postFinder if defined + } else { + matcherOut = condense( + matcherOut === results ? + matcherOut.splice( preexisting, matcherOut.length ) : + matcherOut + ); + if ( postFinder ) { + postFinder( null, results, matcherOut, xml ); + } else { + push.apply( results, matcherOut ); + } + } + }); +} + +function matcherFromTokens( tokens ) { + var checkContext, matcher, j, + len = tokens.length, + leadingRelative = Expr.relative[ tokens[0].type ], + implicitRelative = leadingRelative || Expr.relative[" "], + i = leadingRelative ? 1 : 0, + + // The foundational matcher ensures that elements are reachable from top-level context(s) + matchContext = addCombinator( function( elem ) { + return elem === checkContext; + }, implicitRelative, true ), + matchAnyContext = addCombinator( function( elem ) { + return indexOf( checkContext, elem ) > -1; + }, implicitRelative, true ), + matchers = [ function( elem, context, xml ) { + var ret = ( !leadingRelative && ( xml || context !== outermostContext ) ) || ( + (checkContext = context).nodeType ? + matchContext( elem, context, xml ) : + matchAnyContext( elem, context, xml ) ); + // Avoid hanging onto element (issue #299) + checkContext = null; + return ret; + } ]; + + for ( ; i < len; i++ ) { + if ( (matcher = Expr.relative[ tokens[i].type ]) ) { + matchers = [ addCombinator(elementMatcher( matchers ), matcher) ]; + } else { + matcher = Expr.filter[ tokens[i].type ].apply( null, tokens[i].matches ); + + // Return special upon seeing a positional matcher + if ( matcher[ expando ] ) { + // Find the next relative operator (if any) for proper handling + j = ++i; + for ( ; j < len; j++ ) { + if ( Expr.relative[ tokens[j].type ] ) { + break; + } + } + return setMatcher( + i > 1 && elementMatcher( matchers ), + i > 1 && toSelector( + // If the preceding token was a descendant combinator, insert an implicit any-element `*` + tokens.slice( 0, i - 1 ).concat({ value: tokens[ i - 2 ].type === " " ? "*" : "" }) + ).replace( rtrim, "$1" ), + matcher, + i < j && matcherFromTokens( tokens.slice( i, j ) ), + j < len && matcherFromTokens( (tokens = tokens.slice( j )) ), + j < len && toSelector( tokens ) + ); + } + matchers.push( matcher ); + } + } + + return elementMatcher( matchers ); +} + +function matcherFromGroupMatchers( elementMatchers, setMatchers ) { + var bySet = setMatchers.length > 0, + byElement = elementMatchers.length > 0, + superMatcher = function( seed, context, xml, results, outermost ) { + var elem, j, matcher, + matchedCount = 0, + i = "0", + unmatched = seed && [], + setMatched = [], + contextBackup = outermostContext, + // We must always have either seed elements or outermost context + elems = seed || byElement && Expr.find["TAG"]( "*", outermost ), + // Use integer dirruns iff this is the outermost matcher + dirrunsUnique = (dirruns += contextBackup == null ? 1 : Math.random() || 0.1), + len = elems.length; + + if ( outermost ) { + outermostContext = context !== document && context; + } + + // Add elements passing elementMatchers directly to results + // Keep `i` a string if there are no elements so `matchedCount` will be "00" below + // Support: IE<9, Safari + // Tolerate NodeList properties (IE: "length"; Safari: ) matching elements by id + for ( ; i !== len && (elem = elems[i]) != null; i++ ) { + if ( byElement && elem ) { + j = 0; + while ( (matcher = elementMatchers[j++]) ) { + if ( matcher( elem, context, xml ) ) { + results.push( elem ); + break; + } + } + if ( outermost ) { + dirruns = dirrunsUnique; + } + } + + // Track unmatched elements for set filters + if ( bySet ) { + // They will have gone through all possible matchers + if ( (elem = !matcher && elem) ) { + matchedCount--; + } + + // Lengthen the array for every element, matched or not + if ( seed ) { + unmatched.push( elem ); + } + } + } + + // Apply set filters to unmatched elements + matchedCount += i; + if ( bySet && i !== matchedCount ) { + j = 0; + while ( (matcher = setMatchers[j++]) ) { + matcher( unmatched, setMatched, context, xml ); + } + + if ( seed ) { + // Reintegrate element matches to eliminate the need for sorting + if ( matchedCount > 0 ) { + while ( i-- ) { + if ( !(unmatched[i] || setMatched[i]) ) { + setMatched[i] = pop.call( results ); + } + } + } + + // Discard index placeholder values to get only actual matches + setMatched = condense( setMatched ); + } + + // Add matches to results + push.apply( results, setMatched ); + + // Seedless set matches succeeding multiple successful matchers stipulate sorting + if ( outermost && !seed && setMatched.length > 0 && + ( matchedCount + setMatchers.length ) > 1 ) { + + Sizzle.uniqueSort( results ); + } + } + + // Override manipulation of globals by nested matchers + if ( outermost ) { + dirruns = dirrunsUnique; + outermostContext = contextBackup; + } + + return unmatched; + }; + + return bySet ? + markFunction( superMatcher ) : + superMatcher; +} + +compile = Sizzle.compile = function( selector, match /* Internal Use Only */ ) { + var i, + setMatchers = [], + elementMatchers = [], + cached = compilerCache[ selector + " " ]; + + if ( !cached ) { + // Generate a function of recursive functions that can be used to check each element + if ( !match ) { + match = tokenize( selector ); + } + i = match.length; + while ( i-- ) { + cached = matcherFromTokens( match[i] ); + if ( cached[ expando ] ) { + setMatchers.push( cached ); + } else { + elementMatchers.push( cached ); + } + } + + // Cache the compiled function + cached = compilerCache( selector, matcherFromGroupMatchers( elementMatchers, setMatchers ) ); + + // Save selector and tokenization + cached.selector = selector; + } + return cached; +}; + +/** + * A low-level selection function that works with Sizzle's compiled + * selector functions + * @param {String|Function} selector A selector or a pre-compiled + * selector function built with Sizzle.compile + * @param {Element} context + * @param {Array} [results] + * @param {Array} [seed] A set of elements to match against + */ +select = Sizzle.select = function( selector, context, results, seed ) { + var i, tokens, token, type, find, + compiled = typeof selector === "function" && selector, + match = !seed && tokenize( (selector = compiled.selector || selector) ); + + results = results || []; + + // Try to minimize operations if there is no seed and only one group + if ( match.length === 1 ) { + + // Take a shortcut and set the context if the root selector is an ID + tokens = match[0] = match[0].slice( 0 ); + if ( tokens.length > 2 && (token = tokens[0]).type === "ID" && + support.getById && context.nodeType === 9 && documentIsHTML && + Expr.relative[ tokens[1].type ] ) { + + context = ( Expr.find["ID"]( token.matches[0].replace(runescape, funescape), context ) || [] )[0]; + if ( !context ) { + return results; + + // Precompiled matchers will still verify ancestry, so step up a level + } else if ( compiled ) { + context = context.parentNode; + } + + selector = selector.slice( tokens.shift().value.length ); + } + + // Fetch a seed set for right-to-left matching + i = matchExpr["needsContext"].test( selector ) ? 0 : tokens.length; + while ( i-- ) { + token = tokens[i]; + + // Abort if we hit a combinator + if ( Expr.relative[ (type = token.type) ] ) { + break; + } + if ( (find = Expr.find[ type ]) ) { + // Search, expanding context for leading sibling combinators + if ( (seed = find( + token.matches[0].replace( runescape, funescape ), + rsibling.test( tokens[0].type ) && testContext( context.parentNode ) || context + )) ) { + + // If seed is empty or no tokens remain, we can return early + tokens.splice( i, 1 ); + selector = seed.length && toSelector( tokens ); + if ( !selector ) { + push.apply( results, seed ); + return results; + } + + break; + } + } + } + } + + // Compile and execute a filtering function if one is not provided + // Provide `match` to avoid retokenization if we modified the selector above + ( compiled || compile( selector, match ) )( + seed, + context, + !documentIsHTML, + results, + rsibling.test( selector ) && testContext( context.parentNode ) || context + ); + return results; +}; + +// One-time assignments + +// Sort stability +support.sortStable = expando.split("").sort( sortOrder ).join("") === expando; + +// Support: Chrome 14-35+ +// Always assume duplicates if they aren't passed to the comparison function +support.detectDuplicates = !!hasDuplicate; + +// Initialize against the default document +setDocument(); + +// Support: Webkit<537.32 - Safari 6.0.3/Chrome 25 (fixed in Chrome 27) +// Detached nodes confoundingly follow *each other* +support.sortDetached = assert(function( div1 ) { + // Should return 1, but returns 4 (following) + return div1.compareDocumentPosition( document.createElement("div") ) & 1; +}); + +// Support: IE<8 +// Prevent attribute/property "interpolation" +// http://msdn.microsoft.com/en-us/library/ms536429%28VS.85%29.aspx +if ( !assert(function( div ) { + div.innerHTML = ""; + return div.firstChild.getAttribute("href") === "#" ; +}) ) { + addHandle( "type|href|height|width", function( elem, name, isXML ) { + if ( !isXML ) { + return elem.getAttribute( name, name.toLowerCase() === "type" ? 1 : 2 ); + } + }); +} + +// Support: IE<9 +// Use defaultValue in place of getAttribute("value") +if ( !support.attributes || !assert(function( div ) { + div.innerHTML = ""; + div.firstChild.setAttribute( "value", "" ); + return div.firstChild.getAttribute( "value" ) === ""; +}) ) { + addHandle( "value", function( elem, name, isXML ) { + if ( !isXML && elem.nodeName.toLowerCase() === "input" ) { + return elem.defaultValue; + } + }); +} + +// Support: IE<9 +// Use getAttributeNode to fetch booleans when getAttribute lies +if ( !assert(function( div ) { + return div.getAttribute("disabled") == null; +}) ) { + addHandle( booleans, function( elem, name, isXML ) { + var val; + if ( !isXML ) { + return elem[ name ] === true ? name.toLowerCase() : + (val = elem.getAttributeNode( name )) && val.specified ? + val.value : + null; + } + }); +} + +return Sizzle; + +})( window ); + + + +jQuery.find = Sizzle; +jQuery.expr = Sizzle.selectors; +jQuery.expr[":"] = jQuery.expr.pseudos; +jQuery.unique = Sizzle.uniqueSort; +jQuery.text = Sizzle.getText; +jQuery.isXMLDoc = Sizzle.isXML; +jQuery.contains = Sizzle.contains; + + + +var rneedsContext = jQuery.expr.match.needsContext; + +var rsingleTag = (/^<(\w+)\s*\/?>(?:<\/\1>|)$/); + + + +var risSimple = /^.[^:#\[\.,]*$/; + +// Implement the identical functionality for filter and not +function winnow( elements, qualifier, not ) { + if ( jQuery.isFunction( qualifier ) ) { + return jQuery.grep( elements, function( elem, i ) { + /* jshint -W018 */ + return !!qualifier.call( elem, i, elem ) !== not; + }); + + } + + if ( qualifier.nodeType ) { + return jQuery.grep( elements, function( elem ) { + return ( elem === qualifier ) !== not; + }); + + } + + if ( typeof qualifier === "string" ) { + if ( risSimple.test( qualifier ) ) { + return jQuery.filter( qualifier, elements, not ); + } + + qualifier = jQuery.filter( qualifier, elements ); + } + + return jQuery.grep( elements, function( elem ) { + return ( jQuery.inArray( elem, qualifier ) >= 0 ) !== not; + }); +} + +jQuery.filter = function( expr, elems, not ) { + var elem = elems[ 0 ]; + + if ( not ) { + expr = ":not(" + expr + ")"; + } + + return elems.length === 1 && elem.nodeType === 1 ? + jQuery.find.matchesSelector( elem, expr ) ? [ elem ] : [] : + jQuery.find.matches( expr, jQuery.grep( elems, function( elem ) { + return elem.nodeType === 1; + })); +}; + +jQuery.fn.extend({ + find: function( selector ) { + var i, + ret = [], + self = this, + len = self.length; + + if ( typeof selector !== "string" ) { + return this.pushStack( jQuery( selector ).filter(function() { + for ( i = 0; i < len; i++ ) { + if ( jQuery.contains( self[ i ], this ) ) { + return true; + } + } + }) ); + } + + for ( i = 0; i < len; i++ ) { + jQuery.find( selector, self[ i ], ret ); + } + + // Needed because $( selector, context ) becomes $( context ).find( selector ) + ret = this.pushStack( len > 1 ? jQuery.unique( ret ) : ret ); + ret.selector = this.selector ? this.selector + " " + selector : selector; + return ret; + }, + filter: function( selector ) { + return this.pushStack( winnow(this, selector || [], false) ); + }, + not: function( selector ) { + return this.pushStack( winnow(this, selector || [], true) ); + }, + is: function( selector ) { + return !!winnow( + this, + + // If this is a positional/relative selector, check membership in the returned set + // so $("p:first").is("p:last") won't return true for a doc with two "p". + typeof selector === "string" && rneedsContext.test( selector ) ? + jQuery( selector ) : + selector || [], + false + ).length; + } +}); + + +// Initialize a jQuery object + + +// A central reference to the root jQuery(document) +var rootjQuery, + + // Use the correct document accordingly with window argument (sandbox) + document = window.document, + + // A simple way to check for HTML strings + // Prioritize #id over to avoid XSS via location.hash (#9521) + // Strict HTML recognition (#11290: must start with <) + rquickExpr = /^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/, + + init = jQuery.fn.init = function( selector, context ) { + var match, elem; + + // HANDLE: $(""), $(null), $(undefined), $(false) + if ( !selector ) { + return this; + } + + // Handle HTML strings + if ( typeof selector === "string" ) { + if ( selector.charAt(0) === "<" && selector.charAt( selector.length - 1 ) === ">" && selector.length >= 3 ) { + // Assume that strings that start and end with <> are HTML and skip the regex check + match = [ null, selector, null ]; + + } else { + match = rquickExpr.exec( selector ); + } + + // Match html or make sure no context is specified for #id + if ( match && (match[1] || !context) ) { + + // HANDLE: $(html) -> $(array) + if ( match[1] ) { + context = context instanceof jQuery ? context[0] : context; + + // scripts is true for back-compat + // Intentionally let the error be thrown if parseHTML is not present + jQuery.merge( this, jQuery.parseHTML( + match[1], + context && context.nodeType ? context.ownerDocument || context : document, + true + ) ); + + // HANDLE: $(html, props) + if ( rsingleTag.test( match[1] ) && jQuery.isPlainObject( context ) ) { + for ( match in context ) { + // Properties of context are called as methods if possible + if ( jQuery.isFunction( this[ match ] ) ) { + this[ match ]( context[ match ] ); + + // ...and otherwise set as attributes + } else { + this.attr( match, context[ match ] ); + } + } + } + + return this; + + // HANDLE: $(#id) + } else { + elem = document.getElementById( match[2] ); + + // Check parentNode to catch when Blackberry 4.6 returns + // nodes that are no longer in the document #6963 + if ( elem && elem.parentNode ) { + // Handle the case where IE and Opera return items + // by name instead of ID + if ( elem.id !== match[2] ) { + return rootjQuery.find( selector ); + } + + // Otherwise, we inject the element directly into the jQuery object + this.length = 1; + this[0] = elem; + } + + this.context = document; + this.selector = selector; + return this; + } + + // HANDLE: $(expr, $(...)) + } else if ( !context || context.jquery ) { + return ( context || rootjQuery ).find( selector ); + + // HANDLE: $(expr, context) + // (which is just equivalent to: $(context).find(expr) + } else { + return this.constructor( context ).find( selector ); + } + + // HANDLE: $(DOMElement) + } else if ( selector.nodeType ) { + this.context = this[0] = selector; + this.length = 1; + return this; + + // HANDLE: $(function) + // Shortcut for document ready + } else if ( jQuery.isFunction( selector ) ) { + return typeof rootjQuery.ready !== "undefined" ? + rootjQuery.ready( selector ) : + // Execute immediately if ready is not present + selector( jQuery ); + } + + if ( selector.selector !== undefined ) { + this.selector = selector.selector; + this.context = selector.context; + } + + return jQuery.makeArray( selector, this ); + }; + +// Give the init function the jQuery prototype for later instantiation +init.prototype = jQuery.fn; + +// Initialize central reference +rootjQuery = jQuery( document ); + + +var rparentsprev = /^(?:parents|prev(?:Until|All))/, + // methods guaranteed to produce a unique set when starting from a unique set + guaranteedUnique = { + children: true, + contents: true, + next: true, + prev: true + }; + +jQuery.extend({ + dir: function( elem, dir, until ) { + var matched = [], + cur = elem[ dir ]; + + while ( cur && cur.nodeType !== 9 && (until === undefined || cur.nodeType !== 1 || !jQuery( cur ).is( until )) ) { + if ( cur.nodeType === 1 ) { + matched.push( cur ); + } + cur = cur[dir]; + } + return matched; + }, + + sibling: function( n, elem ) { + var r = []; + + for ( ; n; n = n.nextSibling ) { + if ( n.nodeType === 1 && n !== elem ) { + r.push( n ); + } + } + + return r; + } +}); + +jQuery.fn.extend({ + has: function( target ) { + var i, + targets = jQuery( target, this ), + len = targets.length; + + return this.filter(function() { + for ( i = 0; i < len; i++ ) { + if ( jQuery.contains( this, targets[i] ) ) { + return true; + } + } + }); + }, + + closest: function( selectors, context ) { + var cur, + i = 0, + l = this.length, + matched = [], + pos = rneedsContext.test( selectors ) || typeof selectors !== "string" ? + jQuery( selectors, context || this.context ) : + 0; + + for ( ; i < l; i++ ) { + for ( cur = this[i]; cur && cur !== context; cur = cur.parentNode ) { + // Always skip document fragments + if ( cur.nodeType < 11 && (pos ? + pos.index(cur) > -1 : + + // Don't pass non-elements to Sizzle + cur.nodeType === 1 && + jQuery.find.matchesSelector(cur, selectors)) ) { + + matched.push( cur ); + break; + } + } + } + + return this.pushStack( matched.length > 1 ? jQuery.unique( matched ) : matched ); + }, + + // Determine the position of an element within + // the matched set of elements + index: function( elem ) { + + // No argument, return index in parent + if ( !elem ) { + return ( this[0] && this[0].parentNode ) ? this.first().prevAll().length : -1; + } + + // index in selector + if ( typeof elem === "string" ) { + return jQuery.inArray( this[0], jQuery( elem ) ); + } + + // Locate the position of the desired element + return jQuery.inArray( + // If it receives a jQuery object, the first element is used + elem.jquery ? elem[0] : elem, this ); + }, + + add: function( selector, context ) { + return this.pushStack( + jQuery.unique( + jQuery.merge( this.get(), jQuery( selector, context ) ) + ) + ); + }, + + addBack: function( selector ) { + return this.add( selector == null ? + this.prevObject : this.prevObject.filter(selector) + ); + } +}); + +function sibling( cur, dir ) { + do { + cur = cur[ dir ]; + } while ( cur && cur.nodeType !== 1 ); + + return cur; +} + +jQuery.each({ + parent: function( elem ) { + var parent = elem.parentNode; + return parent && parent.nodeType !== 11 ? parent : null; + }, + parents: function( elem ) { + return jQuery.dir( elem, "parentNode" ); + }, + parentsUntil: function( elem, i, until ) { + return jQuery.dir( elem, "parentNode", until ); + }, + next: function( elem ) { + return sibling( elem, "nextSibling" ); + }, + prev: function( elem ) { + return sibling( elem, "previousSibling" ); + }, + nextAll: function( elem ) { + return jQuery.dir( elem, "nextSibling" ); + }, + prevAll: function( elem ) { + return jQuery.dir( elem, "previousSibling" ); + }, + nextUntil: function( elem, i, until ) { + return jQuery.dir( elem, "nextSibling", until ); + }, + prevUntil: function( elem, i, until ) { + return jQuery.dir( elem, "previousSibling", until ); + }, + siblings: function( elem ) { + return jQuery.sibling( ( elem.parentNode || {} ).firstChild, elem ); + }, + children: function( elem ) { + return jQuery.sibling( elem.firstChild ); + }, + contents: function( elem ) { + return jQuery.nodeName( elem, "iframe" ) ? + elem.contentDocument || elem.contentWindow.document : + jQuery.merge( [], elem.childNodes ); + } +}, function( name, fn ) { + jQuery.fn[ name ] = function( until, selector ) { + var ret = jQuery.map( this, fn, until ); + + if ( name.slice( -5 ) !== "Until" ) { + selector = until; + } + + if ( selector && typeof selector === "string" ) { + ret = jQuery.filter( selector, ret ); + } + + if ( this.length > 1 ) { + // Remove duplicates + if ( !guaranteedUnique[ name ] ) { + ret = jQuery.unique( ret ); + } + + // Reverse order for parents* and prev-derivatives + if ( rparentsprev.test( name ) ) { + ret = ret.reverse(); + } + } + + return this.pushStack( ret ); + }; +}); +var rnotwhite = (/\S+/g); + + + +// String to Object options format cache +var optionsCache = {}; + +// Convert String-formatted options into Object-formatted ones and store in cache +function createOptions( options ) { + var object = optionsCache[ options ] = {}; + jQuery.each( options.match( rnotwhite ) || [], function( _, flag ) { + object[ flag ] = true; + }); + return object; +} + +/* + * Create a callback list using the following parameters: + * + * options: an optional list of space-separated options that will change how + * the callback list behaves or a more traditional option object + * + * By default a callback list will act like an event callback list and can be + * "fired" multiple times. + * + * Possible options: + * + * once: will ensure the callback list can only be fired once (like a Deferred) + * + * memory: will keep track of previous values and will call any callback added + * after the list has been fired right away with the latest "memorized" + * values (like a Deferred) + * + * unique: will ensure a callback can only be added once (no duplicate in the list) + * + * stopOnFalse: interrupt callings when a callback returns false + * + */ +jQuery.Callbacks = function( options ) { + + // Convert options from String-formatted to Object-formatted if needed + // (we check in cache first) + options = typeof options === "string" ? + ( optionsCache[ options ] || createOptions( options ) ) : + jQuery.extend( {}, options ); + + var // Flag to know if list is currently firing + firing, + // Last fire value (for non-forgettable lists) + memory, + // Flag to know if list was already fired + fired, + // End of the loop when firing + firingLength, + // Index of currently firing callback (modified by remove if needed) + firingIndex, + // First callback to fire (used internally by add and fireWith) + firingStart, + // Actual callback list + list = [], + // Stack of fire calls for repeatable lists + stack = !options.once && [], + // Fire callbacks + fire = function( data ) { + memory = options.memory && data; + fired = true; + firingIndex = firingStart || 0; + firingStart = 0; + firingLength = list.length; + firing = true; + for ( ; list && firingIndex < firingLength; firingIndex++ ) { + if ( list[ firingIndex ].apply( data[ 0 ], data[ 1 ] ) === false && options.stopOnFalse ) { + memory = false; // To prevent further calls using add + break; + } + } + firing = false; + if ( list ) { + if ( stack ) { + if ( stack.length ) { + fire( stack.shift() ); + } + } else if ( memory ) { + list = []; + } else { + self.disable(); + } + } + }, + // Actual Callbacks object + self = { + // Add a callback or a collection of callbacks to the list + add: function() { + if ( list ) { + // First, we save the current length + var start = list.length; + (function add( args ) { + jQuery.each( args, function( _, arg ) { + var type = jQuery.type( arg ); + if ( type === "function" ) { + if ( !options.unique || !self.has( arg ) ) { + list.push( arg ); + } + } else if ( arg && arg.length && type !== "string" ) { + // Inspect recursively + add( arg ); + } + }); + })( arguments ); + // Do we need to add the callbacks to the + // current firing batch? + if ( firing ) { + firingLength = list.length; + // With memory, if we're not firing then + // we should call right away + } else if ( memory ) { + firingStart = start; + fire( memory ); + } + } + return this; + }, + // Remove a callback from the list + remove: function() { + if ( list ) { + jQuery.each( arguments, function( _, arg ) { + var index; + while ( ( index = jQuery.inArray( arg, list, index ) ) > -1 ) { + list.splice( index, 1 ); + // Handle firing indexes + if ( firing ) { + if ( index <= firingLength ) { + firingLength--; + } + if ( index <= firingIndex ) { + firingIndex--; + } + } + } + }); + } + return this; + }, + // Check if a given callback is in the list. + // If no argument is given, return whether or not list has callbacks attached. + has: function( fn ) { + return fn ? jQuery.inArray( fn, list ) > -1 : !!( list && list.length ); + }, + // Remove all callbacks from the list + empty: function() { + list = []; + firingLength = 0; + return this; + }, + // Have the list do nothing anymore + disable: function() { + list = stack = memory = undefined; + return this; + }, + // Is it disabled? + disabled: function() { + return !list; + }, + // Lock the list in its current state + lock: function() { + stack = undefined; + if ( !memory ) { + self.disable(); + } + return this; + }, + // Is it locked? + locked: function() { + return !stack; + }, + // Call all callbacks with the given context and arguments + fireWith: function( context, args ) { + if ( list && ( !fired || stack ) ) { + args = args || []; + args = [ context, args.slice ? args.slice() : args ]; + if ( firing ) { + stack.push( args ); + } else { + fire( args ); + } + } + return this; + }, + // Call all the callbacks with the given arguments + fire: function() { + self.fireWith( this, arguments ); + return this; + }, + // To know if the callbacks have already been called at least once + fired: function() { + return !!fired; + } + }; + + return self; +}; + + +jQuery.extend({ + + Deferred: function( func ) { + var tuples = [ + // action, add listener, listener list, final state + [ "resolve", "done", jQuery.Callbacks("once memory"), "resolved" ], + [ "reject", "fail", jQuery.Callbacks("once memory"), "rejected" ], + [ "notify", "progress", jQuery.Callbacks("memory") ] + ], + state = "pending", + promise = { + state: function() { + return state; + }, + always: function() { + deferred.done( arguments ).fail( arguments ); + return this; + }, + then: function( /* fnDone, fnFail, fnProgress */ ) { + var fns = arguments; + return jQuery.Deferred(function( newDefer ) { + jQuery.each( tuples, function( i, tuple ) { + var fn = jQuery.isFunction( fns[ i ] ) && fns[ i ]; + // deferred[ done | fail | progress ] for forwarding actions to newDefer + deferred[ tuple[1] ](function() { + var returned = fn && fn.apply( this, arguments ); + if ( returned && jQuery.isFunction( returned.promise ) ) { + returned.promise() + .done( newDefer.resolve ) + .fail( newDefer.reject ) + .progress( newDefer.notify ); + } else { + newDefer[ tuple[ 0 ] + "With" ]( this === promise ? newDefer.promise() : this, fn ? [ returned ] : arguments ); + } + }); + }); + fns = null; + }).promise(); + }, + // Get a promise for this deferred + // If obj is provided, the promise aspect is added to the object + promise: function( obj ) { + return obj != null ? jQuery.extend( obj, promise ) : promise; + } + }, + deferred = {}; + + // Keep pipe for back-compat + promise.pipe = promise.then; + + // Add list-specific methods + jQuery.each( tuples, function( i, tuple ) { + var list = tuple[ 2 ], + stateString = tuple[ 3 ]; + + // promise[ done | fail | progress ] = list.add + promise[ tuple[1] ] = list.add; + + // Handle state + if ( stateString ) { + list.add(function() { + // state = [ resolved | rejected ] + state = stateString; + + // [ reject_list | resolve_list ].disable; progress_list.lock + }, tuples[ i ^ 1 ][ 2 ].disable, tuples[ 2 ][ 2 ].lock ); + } + + // deferred[ resolve | reject | notify ] + deferred[ tuple[0] ] = function() { + deferred[ tuple[0] + "With" ]( this === deferred ? promise : this, arguments ); + return this; + }; + deferred[ tuple[0] + "With" ] = list.fireWith; + }); + + // Make the deferred a promise + promise.promise( deferred ); + + // Call given func if any + if ( func ) { + func.call( deferred, deferred ); + } + + // All done! + return deferred; + }, + + // Deferred helper + when: function( subordinate /* , ..., subordinateN */ ) { + var i = 0, + resolveValues = slice.call( arguments ), + length = resolveValues.length, + + // the count of uncompleted subordinates + remaining = length !== 1 || ( subordinate && jQuery.isFunction( subordinate.promise ) ) ? length : 0, + + // the master Deferred. If resolveValues consist of only a single Deferred, just use that. + deferred = remaining === 1 ? subordinate : jQuery.Deferred(), + + // Update function for both resolve and progress values + updateFunc = function( i, contexts, values ) { + return function( value ) { + contexts[ i ] = this; + values[ i ] = arguments.length > 1 ? slice.call( arguments ) : value; + if ( values === progressValues ) { + deferred.notifyWith( contexts, values ); + + } else if ( !(--remaining) ) { + deferred.resolveWith( contexts, values ); + } + }; + }, + + progressValues, progressContexts, resolveContexts; + + // add listeners to Deferred subordinates; treat others as resolved + if ( length > 1 ) { + progressValues = new Array( length ); + progressContexts = new Array( length ); + resolveContexts = new Array( length ); + for ( ; i < length; i++ ) { + if ( resolveValues[ i ] && jQuery.isFunction( resolveValues[ i ].promise ) ) { + resolveValues[ i ].promise() + .done( updateFunc( i, resolveContexts, resolveValues ) ) + .fail( deferred.reject ) + .progress( updateFunc( i, progressContexts, progressValues ) ); + } else { + --remaining; + } + } + } + + // if we're not waiting on anything, resolve the master + if ( !remaining ) { + deferred.resolveWith( resolveContexts, resolveValues ); + } + + return deferred.promise(); + } +}); + + +// The deferred used on DOM ready +var readyList; + +jQuery.fn.ready = function( fn ) { + // Add the callback + jQuery.ready.promise().done( fn ); + + return this; +}; + +jQuery.extend({ + // Is the DOM ready to be used? Set to true once it occurs. + isReady: false, + + // A counter to track how many items to wait for before + // the ready event fires. See #6781 + readyWait: 1, + + // Hold (or release) the ready event + holdReady: function( hold ) { + if ( hold ) { + jQuery.readyWait++; + } else { + jQuery.ready( true ); + } + }, + + // Handle when the DOM is ready + ready: function( wait ) { + + // Abort if there are pending holds or we're already ready + if ( wait === true ? --jQuery.readyWait : jQuery.isReady ) { + return; + } + + // Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443). + if ( !document.body ) { + return setTimeout( jQuery.ready ); + } + + // Remember that the DOM is ready + jQuery.isReady = true; + + // If a normal DOM Ready event fired, decrement, and wait if need be + if ( wait !== true && --jQuery.readyWait > 0 ) { + return; + } + + // If there are functions bound, to execute + readyList.resolveWith( document, [ jQuery ] ); + + // Trigger any bound ready events + if ( jQuery.fn.triggerHandler ) { + jQuery( document ).triggerHandler( "ready" ); + jQuery( document ).off( "ready" ); + } + } +}); + +/** + * Clean-up method for dom ready events + */ +function detach() { + if ( document.addEventListener ) { + document.removeEventListener( "DOMContentLoaded", completed, false ); + window.removeEventListener( "load", completed, false ); + + } else { + document.detachEvent( "onreadystatechange", completed ); + window.detachEvent( "onload", completed ); + } +} + +/** + * The ready event handler and self cleanup method + */ +function completed() { + // readyState === "complete" is good enough for us to call the dom ready in oldIE + if ( document.addEventListener || event.type === "load" || document.readyState === "complete" ) { + detach(); + jQuery.ready(); + } +} + +jQuery.ready.promise = function( obj ) { + if ( !readyList ) { + + readyList = jQuery.Deferred(); + + // Catch cases where $(document).ready() is called after the browser event has already occurred. + // we once tried to use readyState "interactive" here, but it caused issues like the one + // discovered by ChrisS here: http://bugs.jquery.com/ticket/12282#comment:15 + if ( document.readyState === "complete" ) { + // Handle it asynchronously to allow scripts the opportunity to delay ready + setTimeout( jQuery.ready ); + + // Standards-based browsers support DOMContentLoaded + } else if ( document.addEventListener ) { + // Use the handy event callback + document.addEventListener( "DOMContentLoaded", completed, false ); + + // A fallback to window.onload, that will always work + window.addEventListener( "load", completed, false ); + + // If IE event model is used + } else { + // Ensure firing before onload, maybe late but safe also for iframes + document.attachEvent( "onreadystatechange", completed ); + + // A fallback to window.onload, that will always work + window.attachEvent( "onload", completed ); + + // If IE and not a frame + // continually check to see if the document is ready + var top = false; + + try { + top = window.frameElement == null && document.documentElement; + } catch(e) {} + + if ( top && top.doScroll ) { + (function doScrollCheck() { + if ( !jQuery.isReady ) { + + try { + // Use the trick by Diego Perini + // http://javascript.nwbox.com/IEContentLoaded/ + top.doScroll("left"); + } catch(e) { + return setTimeout( doScrollCheck, 50 ); + } + + // detach all dom ready events + detach(); + + // and execute any waiting functions + jQuery.ready(); + } + })(); + } + } + } + return readyList.promise( obj ); +}; + + +var strundefined = typeof undefined; + + + +// Support: IE<9 +// Iteration over object's inherited properties before its own +var i; +for ( i in jQuery( support ) ) { + break; +} +support.ownLast = i !== "0"; + +// Note: most support tests are defined in their respective modules. +// false until the test is run +support.inlineBlockNeedsLayout = false; + +// Execute ASAP in case we need to set body.style.zoom +jQuery(function() { + // Minified: var a,b,c,d + var val, div, body, container; + + body = document.getElementsByTagName( "body" )[ 0 ]; + if ( !body || !body.style ) { + // Return for frameset docs that don't have a body + return; + } + + // Setup + div = document.createElement( "div" ); + container = document.createElement( "div" ); + container.style.cssText = "position:absolute;border:0;width:0;height:0;top:0;left:-9999px"; + body.appendChild( container ).appendChild( div ); + + if ( typeof div.style.zoom !== strundefined ) { + // Support: IE<8 + // Check if natively block-level elements act like inline-block + // elements when setting their display to 'inline' and giving + // them layout + div.style.cssText = "display:inline;margin:0;border:0;padding:1px;width:1px;zoom:1"; + + support.inlineBlockNeedsLayout = val = div.offsetWidth === 3; + if ( val ) { + // Prevent IE 6 from affecting layout for positioned elements #11048 + // Prevent IE from shrinking the body in IE 7 mode #12869 + // Support: IE<8 + body.style.zoom = 1; + } + } + + body.removeChild( container ); +}); + + + + +(function() { + var div = document.createElement( "div" ); + + // Execute the test only if not already executed in another module. + if (support.deleteExpando == null) { + // Support: IE<9 + support.deleteExpando = true; + try { + delete div.test; + } catch( e ) { + support.deleteExpando = false; + } + } + + // Null elements to avoid leaks in IE. + div = null; +})(); + + +/** + * Determines whether an object can have data + */ +jQuery.acceptData = function( elem ) { + var noData = jQuery.noData[ (elem.nodeName + " ").toLowerCase() ], + nodeType = +elem.nodeType || 1; + + // Do not set data on non-element DOM nodes because it will not be cleared (#8335). + return nodeType !== 1 && nodeType !== 9 ? + false : + + // Nodes accept data unless otherwise specified; rejection can be conditional + !noData || noData !== true && elem.getAttribute("classid") === noData; +}; + + +var rbrace = /^(?:\{[\w\W]*\}|\[[\w\W]*\])$/, + rmultiDash = /([A-Z])/g; + +function dataAttr( elem, key, data ) { + // If nothing was found internally, try to fetch any + // data from the HTML5 data-* attribute + if ( data === undefined && elem.nodeType === 1 ) { + + var name = "data-" + key.replace( rmultiDash, "-$1" ).toLowerCase(); + + data = elem.getAttribute( name ); + + if ( typeof data === "string" ) { + try { + data = data === "true" ? true : + data === "false" ? false : + data === "null" ? null : + // Only convert to a number if it doesn't change the string + +data + "" === data ? +data : + rbrace.test( data ) ? jQuery.parseJSON( data ) : + data; + } catch( e ) {} + + // Make sure we set the data so it isn't changed later + jQuery.data( elem, key, data ); + + } else { + data = undefined; + } + } + + return data; +} + +// checks a cache object for emptiness +function isEmptyDataObject( obj ) { + var name; + for ( name in obj ) { + + // if the public data object is empty, the private is still empty + if ( name === "data" && jQuery.isEmptyObject( obj[name] ) ) { + continue; + } + if ( name !== "toJSON" ) { + return false; + } + } + + return true; +} + +function internalData( elem, name, data, pvt /* Internal Use Only */ ) { + if ( !jQuery.acceptData( elem ) ) { + return; + } + + var ret, thisCache, + internalKey = jQuery.expando, + + // We have to handle DOM nodes and JS objects differently because IE6-7 + // can't GC object references properly across the DOM-JS boundary + isNode = elem.nodeType, + + // Only DOM nodes need the global jQuery cache; JS object data is + // attached directly to the object so GC can occur automatically + cache = isNode ? jQuery.cache : elem, + + // Only defining an ID for JS objects if its cache already exists allows + // the code to shortcut on the same path as a DOM node with no cache + id = isNode ? elem[ internalKey ] : elem[ internalKey ] && internalKey; + + // Avoid doing any more work than we need to when trying to get data on an + // object that has no data at all + if ( (!id || !cache[id] || (!pvt && !cache[id].data)) && data === undefined && typeof name === "string" ) { + return; + } + + if ( !id ) { + // Only DOM nodes need a new unique ID for each element since their data + // ends up in the global cache + if ( isNode ) { + id = elem[ internalKey ] = deletedIds.pop() || jQuery.guid++; + } else { + id = internalKey; + } + } + + if ( !cache[ id ] ) { + // Avoid exposing jQuery metadata on plain JS objects when the object + // is serialized using JSON.stringify + cache[ id ] = isNode ? {} : { toJSON: jQuery.noop }; + } + + // An object can be passed to jQuery.data instead of a key/value pair; this gets + // shallow copied over onto the existing cache + if ( typeof name === "object" || typeof name === "function" ) { + if ( pvt ) { + cache[ id ] = jQuery.extend( cache[ id ], name ); + } else { + cache[ id ].data = jQuery.extend( cache[ id ].data, name ); + } + } + + thisCache = cache[ id ]; + + // jQuery data() is stored in a separate object inside the object's internal data + // cache in order to avoid key collisions between internal data and user-defined + // data. + if ( !pvt ) { + if ( !thisCache.data ) { + thisCache.data = {}; + } + + thisCache = thisCache.data; + } + + if ( data !== undefined ) { + thisCache[ jQuery.camelCase( name ) ] = data; + } + + // Check for both converted-to-camel and non-converted data property names + // If a data property was specified + if ( typeof name === "string" ) { + + // First Try to find as-is property data + ret = thisCache[ name ]; + + // Test for null|undefined property data + if ( ret == null ) { + + // Try to find the camelCased property + ret = thisCache[ jQuery.camelCase( name ) ]; + } + } else { + ret = thisCache; + } + + return ret; +} + +function internalRemoveData( elem, name, pvt ) { + if ( !jQuery.acceptData( elem ) ) { + return; + } + + var thisCache, i, + isNode = elem.nodeType, + + // See jQuery.data for more information + cache = isNode ? jQuery.cache : elem, + id = isNode ? elem[ jQuery.expando ] : jQuery.expando; + + // If there is already no cache entry for this object, there is no + // purpose in continuing + if ( !cache[ id ] ) { + return; + } + + if ( name ) { + + thisCache = pvt ? cache[ id ] : cache[ id ].data; + + if ( thisCache ) { + + // Support array or space separated string names for data keys + if ( !jQuery.isArray( name ) ) { + + // try the string as a key before any manipulation + if ( name in thisCache ) { + name = [ name ]; + } else { + + // split the camel cased version by spaces unless a key with the spaces exists + name = jQuery.camelCase( name ); + if ( name in thisCache ) { + name = [ name ]; + } else { + name = name.split(" "); + } + } + } else { + // If "name" is an array of keys... + // When data is initially created, via ("key", "val") signature, + // keys will be converted to camelCase. + // Since there is no way to tell _how_ a key was added, remove + // both plain key and camelCase key. #12786 + // This will only penalize the array argument path. + name = name.concat( jQuery.map( name, jQuery.camelCase ) ); + } + + i = name.length; + while ( i-- ) { + delete thisCache[ name[i] ]; + } + + // If there is no data left in the cache, we want to continue + // and let the cache object itself get destroyed + if ( pvt ? !isEmptyDataObject(thisCache) : !jQuery.isEmptyObject(thisCache) ) { + return; + } + } + } + + // See jQuery.data for more information + if ( !pvt ) { + delete cache[ id ].data; + + // Don't destroy the parent cache unless the internal data object + // had been the only thing left in it + if ( !isEmptyDataObject( cache[ id ] ) ) { + return; + } + } + + // Destroy the cache + if ( isNode ) { + jQuery.cleanData( [ elem ], true ); + + // Use delete when supported for expandos or `cache` is not a window per isWindow (#10080) + /* jshint eqeqeq: false */ + } else if ( support.deleteExpando || cache != cache.window ) { + /* jshint eqeqeq: true */ + delete cache[ id ]; + + // When all else fails, null + } else { + cache[ id ] = null; + } +} + +jQuery.extend({ + cache: {}, + + // The following elements (space-suffixed to avoid Object.prototype collisions) + // throw uncatchable exceptions if you attempt to set expando properties + noData: { + "applet ": true, + "embed ": true, + // ...but Flash objects (which have this classid) *can* handle expandos + "object ": "clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" + }, + + hasData: function( elem ) { + elem = elem.nodeType ? jQuery.cache[ elem[jQuery.expando] ] : elem[ jQuery.expando ]; + return !!elem && !isEmptyDataObject( elem ); + }, + + data: function( elem, name, data ) { + return internalData( elem, name, data ); + }, + + removeData: function( elem, name ) { + return internalRemoveData( elem, name ); + }, + + // For internal use only. + _data: function( elem, name, data ) { + return internalData( elem, name, data, true ); + }, + + _removeData: function( elem, name ) { + return internalRemoveData( elem, name, true ); + } +}); + +jQuery.fn.extend({ + data: function( key, value ) { + var i, name, data, + elem = this[0], + attrs = elem && elem.attributes; + + // Special expections of .data basically thwart jQuery.access, + // so implement the relevant behavior ourselves + + // Gets all values + if ( key === undefined ) { + if ( this.length ) { + data = jQuery.data( elem ); + + if ( elem.nodeType === 1 && !jQuery._data( elem, "parsedAttrs" ) ) { + i = attrs.length; + while ( i-- ) { + + // Support: IE11+ + // The attrs elements can be null (#14894) + if ( attrs[ i ] ) { + name = attrs[ i ].name; + if ( name.indexOf( "data-" ) === 0 ) { + name = jQuery.camelCase( name.slice(5) ); + dataAttr( elem, name, data[ name ] ); + } + } + } + jQuery._data( elem, "parsedAttrs", true ); + } + } + + return data; + } + + // Sets multiple values + if ( typeof key === "object" ) { + return this.each(function() { + jQuery.data( this, key ); + }); + } + + return arguments.length > 1 ? + + // Sets one value + this.each(function() { + jQuery.data( this, key, value ); + }) : + + // Gets one value + // Try to fetch any internally stored data first + elem ? dataAttr( elem, key, jQuery.data( elem, key ) ) : undefined; + }, + + removeData: function( key ) { + return this.each(function() { + jQuery.removeData( this, key ); + }); + } +}); + + +jQuery.extend({ + queue: function( elem, type, data ) { + var queue; + + if ( elem ) { + type = ( type || "fx" ) + "queue"; + queue = jQuery._data( elem, type ); + + // Speed up dequeue by getting out quickly if this is just a lookup + if ( data ) { + if ( !queue || jQuery.isArray(data) ) { + queue = jQuery._data( elem, type, jQuery.makeArray(data) ); + } else { + queue.push( data ); + } + } + return queue || []; + } + }, + + dequeue: function( elem, type ) { + type = type || "fx"; + + var queue = jQuery.queue( elem, type ), + startLength = queue.length, + fn = queue.shift(), + hooks = jQuery._queueHooks( elem, type ), + next = function() { + jQuery.dequeue( elem, type ); + }; + + // If the fx queue is dequeued, always remove the progress sentinel + if ( fn === "inprogress" ) { + fn = queue.shift(); + startLength--; + } + + if ( fn ) { + + // Add a progress sentinel to prevent the fx queue from being + // automatically dequeued + if ( type === "fx" ) { + queue.unshift( "inprogress" ); + } + + // clear up the last queue stop function + delete hooks.stop; + fn.call( elem, next, hooks ); + } + + if ( !startLength && hooks ) { + hooks.empty.fire(); + } + }, + + // not intended for public consumption - generates a queueHooks object, or returns the current one + _queueHooks: function( elem, type ) { + var key = type + "queueHooks"; + return jQuery._data( elem, key ) || jQuery._data( elem, key, { + empty: jQuery.Callbacks("once memory").add(function() { + jQuery._removeData( elem, type + "queue" ); + jQuery._removeData( elem, key ); + }) + }); + } +}); + +jQuery.fn.extend({ + queue: function( type, data ) { + var setter = 2; + + if ( typeof type !== "string" ) { + data = type; + type = "fx"; + setter--; + } + + if ( arguments.length < setter ) { + return jQuery.queue( this[0], type ); + } + + return data === undefined ? + this : + this.each(function() { + var queue = jQuery.queue( this, type, data ); + + // ensure a hooks for this queue + jQuery._queueHooks( this, type ); + + if ( type === "fx" && queue[0] !== "inprogress" ) { + jQuery.dequeue( this, type ); + } + }); + }, + dequeue: function( type ) { + return this.each(function() { + jQuery.dequeue( this, type ); + }); + }, + clearQueue: function( type ) { + return this.queue( type || "fx", [] ); + }, + // Get a promise resolved when queues of a certain type + // are emptied (fx is the type by default) + promise: function( type, obj ) { + var tmp, + count = 1, + defer = jQuery.Deferred(), + elements = this, + i = this.length, + resolve = function() { + if ( !( --count ) ) { + defer.resolveWith( elements, [ elements ] ); + } + }; + + if ( typeof type !== "string" ) { + obj = type; + type = undefined; + } + type = type || "fx"; + + while ( i-- ) { + tmp = jQuery._data( elements[ i ], type + "queueHooks" ); + if ( tmp && tmp.empty ) { + count++; + tmp.empty.add( resolve ); + } + } + resolve(); + return defer.promise( obj ); + } +}); +var pnum = (/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/).source; + +var cssExpand = [ "Top", "Right", "Bottom", "Left" ]; + +var isHidden = function( elem, el ) { + // isHidden might be called from jQuery#filter function; + // in that case, element will be second argument + elem = el || elem; + return jQuery.css( elem, "display" ) === "none" || !jQuery.contains( elem.ownerDocument, elem ); + }; + + + +// Multifunctional method to get and set values of a collection +// The value/s can optionally be executed if it's a function +var access = jQuery.access = function( elems, fn, key, value, chainable, emptyGet, raw ) { + var i = 0, + length = elems.length, + bulk = key == null; + + // Sets many values + if ( jQuery.type( key ) === "object" ) { + chainable = true; + for ( i in key ) { + jQuery.access( elems, fn, i, key[i], true, emptyGet, raw ); + } + + // Sets one value + } else if ( value !== undefined ) { + chainable = true; + + if ( !jQuery.isFunction( value ) ) { + raw = true; + } + + if ( bulk ) { + // Bulk operations run against the entire set + if ( raw ) { + fn.call( elems, value ); + fn = null; + + // ...except when executing function values + } else { + bulk = fn; + fn = function( elem, key, value ) { + return bulk.call( jQuery( elem ), value ); + }; + } + } + + if ( fn ) { + for ( ; i < length; i++ ) { + fn( elems[i], key, raw ? value : value.call( elems[i], i, fn( elems[i], key ) ) ); + } + } + } + + return chainable ? + elems : + + // Gets + bulk ? + fn.call( elems ) : + length ? fn( elems[0], key ) : emptyGet; +}; +var rcheckableType = (/^(?:checkbox|radio)$/i); + + + +(function() { + // Minified: var a,b,c + var input = document.createElement( "input" ), + div = document.createElement( "div" ), + fragment = document.createDocumentFragment(); + + // Setup + div.innerHTML = "
a"; + + // IE strips leading whitespace when .innerHTML is used + support.leadingWhitespace = div.firstChild.nodeType === 3; + + // Make sure that tbody elements aren't automatically inserted + // IE will insert them into empty tables + support.tbody = !div.getElementsByTagName( "tbody" ).length; + + // Make sure that link elements get serialized correctly by innerHTML + // This requires a wrapper element in IE + support.htmlSerialize = !!div.getElementsByTagName( "link" ).length; + + // Makes sure cloning an html5 element does not cause problems + // Where outerHTML is undefined, this still works + support.html5Clone = + document.createElement( "nav" ).cloneNode( true ).outerHTML !== "<:nav>"; + + // Check if a disconnected checkbox will retain its checked + // value of true after appended to the DOM (IE6/7) + input.type = "checkbox"; + input.checked = true; + fragment.appendChild( input ); + support.appendChecked = input.checked; + + // Make sure textarea (and checkbox) defaultValue is properly cloned + // Support: IE6-IE11+ + div.innerHTML = ""; + support.noCloneChecked = !!div.cloneNode( true ).lastChild.defaultValue; + + // #11217 - WebKit loses check when the name is after the checked attribute + fragment.appendChild( div ); + div.innerHTML = ""; + + // Support: Safari 5.1, iOS 5.1, Android 4.x, Android 2.3 + // old WebKit doesn't clone checked state correctly in fragments + support.checkClone = div.cloneNode( true ).cloneNode( true ).lastChild.checked; + + // Support: IE<9 + // Opera does not clone events (and typeof div.attachEvent === undefined). + // IE9-10 clones events bound via attachEvent, but they don't trigger with .click() + support.noCloneEvent = true; + if ( div.attachEvent ) { + div.attachEvent( "onclick", function() { + support.noCloneEvent = false; + }); + + div.cloneNode( true ).click(); + } + + // Execute the test only if not already executed in another module. + if (support.deleteExpando == null) { + // Support: IE<9 + support.deleteExpando = true; + try { + delete div.test; + } catch( e ) { + support.deleteExpando = false; + } + } +})(); + + +(function() { + var i, eventName, + div = document.createElement( "div" ); + + // Support: IE<9 (lack submit/change bubble), Firefox 23+ (lack focusin event) + for ( i in { submit: true, change: true, focusin: true }) { + eventName = "on" + i; + + if ( !(support[ i + "Bubbles" ] = eventName in window) ) { + // Beware of CSP restrictions (https://developer.mozilla.org/en/Security/CSP) + div.setAttribute( eventName, "t" ); + support[ i + "Bubbles" ] = div.attributes[ eventName ].expando === false; + } + } + + // Null elements to avoid leaks in IE. + div = null; +})(); + + +var rformElems = /^(?:input|select|textarea)$/i, + rkeyEvent = /^key/, + rmouseEvent = /^(?:mouse|pointer|contextmenu)|click/, + rfocusMorph = /^(?:focusinfocus|focusoutblur)$/, + rtypenamespace = /^([^.]*)(?:\.(.+)|)$/; + +function returnTrue() { + return true; +} + +function returnFalse() { + return false; +} + +function safeActiveElement() { + try { + return document.activeElement; + } catch ( err ) { } +} + +/* + * Helper functions for managing events -- not part of the public interface. + * Props to Dean Edwards' addEvent library for many of the ideas. + */ +jQuery.event = { + + global: {}, + + add: function( elem, types, handler, data, selector ) { + var tmp, events, t, handleObjIn, + special, eventHandle, handleObj, + handlers, type, namespaces, origType, + elemData = jQuery._data( elem ); + + // Don't attach events to noData or text/comment nodes (but allow plain objects) + if ( !elemData ) { + return; + } + + // Caller can pass in an object of custom data in lieu of the handler + if ( handler.handler ) { + handleObjIn = handler; + handler = handleObjIn.handler; + selector = handleObjIn.selector; + } + + // Make sure that the handler has a unique ID, used to find/remove it later + if ( !handler.guid ) { + handler.guid = jQuery.guid++; + } + + // Init the element's event structure and main handler, if this is the first + if ( !(events = elemData.events) ) { + events = elemData.events = {}; + } + if ( !(eventHandle = elemData.handle) ) { + eventHandle = elemData.handle = function( e ) { + // Discard the second event of a jQuery.event.trigger() and + // when an event is called after a page has unloaded + return typeof jQuery !== strundefined && (!e || jQuery.event.triggered !== e.type) ? + jQuery.event.dispatch.apply( eventHandle.elem, arguments ) : + undefined; + }; + // Add elem as a property of the handle fn to prevent a memory leak with IE non-native events + eventHandle.elem = elem; + } + + // Handle multiple events separated by a space + types = ( types || "" ).match( rnotwhite ) || [ "" ]; + t = types.length; + while ( t-- ) { + tmp = rtypenamespace.exec( types[t] ) || []; + type = origType = tmp[1]; + namespaces = ( tmp[2] || "" ).split( "." ).sort(); + + // There *must* be a type, no attaching namespace-only handlers + if ( !type ) { + continue; + } + + // If event changes its type, use the special event handlers for the changed type + special = jQuery.event.special[ type ] || {}; + + // If selector defined, determine special event api type, otherwise given type + type = ( selector ? special.delegateType : special.bindType ) || type; + + // Update special based on newly reset type + special = jQuery.event.special[ type ] || {}; + + // handleObj is passed to all event handlers + handleObj = jQuery.extend({ + type: type, + origType: origType, + data: data, + handler: handler, + guid: handler.guid, + selector: selector, + needsContext: selector && jQuery.expr.match.needsContext.test( selector ), + namespace: namespaces.join(".") + }, handleObjIn ); + + // Init the event handler queue if we're the first + if ( !(handlers = events[ type ]) ) { + handlers = events[ type ] = []; + handlers.delegateCount = 0; + + // Only use addEventListener/attachEvent if the special events handler returns false + if ( !special.setup || special.setup.call( elem, data, namespaces, eventHandle ) === false ) { + // Bind the global event handler to the element + if ( elem.addEventListener ) { + elem.addEventListener( type, eventHandle, false ); + + } else if ( elem.attachEvent ) { + elem.attachEvent( "on" + type, eventHandle ); + } + } + } + + if ( special.add ) { + special.add.call( elem, handleObj ); + + if ( !handleObj.handler.guid ) { + handleObj.handler.guid = handler.guid; + } + } + + // Add to the element's handler list, delegates in front + if ( selector ) { + handlers.splice( handlers.delegateCount++, 0, handleObj ); + } else { + handlers.push( handleObj ); + } + + // Keep track of which events have ever been used, for event optimization + jQuery.event.global[ type ] = true; + } + + // Nullify elem to prevent memory leaks in IE + elem = null; + }, + + // Detach an event or set of events from an element + remove: function( elem, types, handler, selector, mappedTypes ) { + var j, handleObj, tmp, + origCount, t, events, + special, handlers, type, + namespaces, origType, + elemData = jQuery.hasData( elem ) && jQuery._data( elem ); + + if ( !elemData || !(events = elemData.events) ) { + return; + } + + // Once for each type.namespace in types; type may be omitted + types = ( types || "" ).match( rnotwhite ) || [ "" ]; + t = types.length; + while ( t-- ) { + tmp = rtypenamespace.exec( types[t] ) || []; + type = origType = tmp[1]; + namespaces = ( tmp[2] || "" ).split( "." ).sort(); + + // Unbind all events (on this namespace, if provided) for the element + if ( !type ) { + for ( type in events ) { + jQuery.event.remove( elem, type + types[ t ], handler, selector, true ); + } + continue; + } + + special = jQuery.event.special[ type ] || {}; + type = ( selector ? special.delegateType : special.bindType ) || type; + handlers = events[ type ] || []; + tmp = tmp[2] && new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" ); + + // Remove matching events + origCount = j = handlers.length; + while ( j-- ) { + handleObj = handlers[ j ]; + + if ( ( mappedTypes || origType === handleObj.origType ) && + ( !handler || handler.guid === handleObj.guid ) && + ( !tmp || tmp.test( handleObj.namespace ) ) && + ( !selector || selector === handleObj.selector || selector === "**" && handleObj.selector ) ) { + handlers.splice( j, 1 ); + + if ( handleObj.selector ) { + handlers.delegateCount--; + } + if ( special.remove ) { + special.remove.call( elem, handleObj ); + } + } + } + + // Remove generic event handler if we removed something and no more handlers exist + // (avoids potential for endless recursion during removal of special event handlers) + if ( origCount && !handlers.length ) { + if ( !special.teardown || special.teardown.call( elem, namespaces, elemData.handle ) === false ) { + jQuery.removeEvent( elem, type, elemData.handle ); + } + + delete events[ type ]; + } + } + + // Remove the expando if it's no longer used + if ( jQuery.isEmptyObject( events ) ) { + delete elemData.handle; + + // removeData also checks for emptiness and clears the expando if empty + // so use it instead of delete + jQuery._removeData( elem, "events" ); + } + }, + + trigger: function( event, data, elem, onlyHandlers ) { + var handle, ontype, cur, + bubbleType, special, tmp, i, + eventPath = [ elem || document ], + type = hasOwn.call( event, "type" ) ? event.type : event, + namespaces = hasOwn.call( event, "namespace" ) ? event.namespace.split(".") : []; + + cur = tmp = elem = elem || document; + + // Don't do events on text and comment nodes + if ( elem.nodeType === 3 || elem.nodeType === 8 ) { + return; + } + + // focus/blur morphs to focusin/out; ensure we're not firing them right now + if ( rfocusMorph.test( type + jQuery.event.triggered ) ) { + return; + } + + if ( type.indexOf(".") >= 0 ) { + // Namespaced trigger; create a regexp to match event type in handle() + namespaces = type.split("."); + type = namespaces.shift(); + namespaces.sort(); + } + ontype = type.indexOf(":") < 0 && "on" + type; + + // Caller can pass in a jQuery.Event object, Object, or just an event type string + event = event[ jQuery.expando ] ? + event : + new jQuery.Event( type, typeof event === "object" && event ); + + // Trigger bitmask: & 1 for native handlers; & 2 for jQuery (always true) + event.isTrigger = onlyHandlers ? 2 : 3; + event.namespace = namespaces.join("."); + event.namespace_re = event.namespace ? + new RegExp( "(^|\\.)" + namespaces.join("\\.(?:.*\\.|)") + "(\\.|$)" ) : + null; + + // Clean up the event in case it is being reused + event.result = undefined; + if ( !event.target ) { + event.target = elem; + } + + // Clone any incoming data and prepend the event, creating the handler arg list + data = data == null ? + [ event ] : + jQuery.makeArray( data, [ event ] ); + + // Allow special events to draw outside the lines + special = jQuery.event.special[ type ] || {}; + if ( !onlyHandlers && special.trigger && special.trigger.apply( elem, data ) === false ) { + return; + } + + // Determine event propagation path in advance, per W3C events spec (#9951) + // Bubble up to document, then to window; watch for a global ownerDocument var (#9724) + if ( !onlyHandlers && !special.noBubble && !jQuery.isWindow( elem ) ) { + + bubbleType = special.delegateType || type; + if ( !rfocusMorph.test( bubbleType + type ) ) { + cur = cur.parentNode; + } + for ( ; cur; cur = cur.parentNode ) { + eventPath.push( cur ); + tmp = cur; + } + + // Only add window if we got to document (e.g., not plain obj or detached DOM) + if ( tmp === (elem.ownerDocument || document) ) { + eventPath.push( tmp.defaultView || tmp.parentWindow || window ); + } + } + + // Fire handlers on the event path + i = 0; + while ( (cur = eventPath[i++]) && !event.isPropagationStopped() ) { + + event.type = i > 1 ? + bubbleType : + special.bindType || type; + + // jQuery handler + handle = ( jQuery._data( cur, "events" ) || {} )[ event.type ] && jQuery._data( cur, "handle" ); + if ( handle ) { + handle.apply( cur, data ); + } + + // Native handler + handle = ontype && cur[ ontype ]; + if ( handle && handle.apply && jQuery.acceptData( cur ) ) { + event.result = handle.apply( cur, data ); + if ( event.result === false ) { + event.preventDefault(); + } + } + } + event.type = type; + + // If nobody prevented the default action, do it now + if ( !onlyHandlers && !event.isDefaultPrevented() ) { + + if ( (!special._default || special._default.apply( eventPath.pop(), data ) === false) && + jQuery.acceptData( elem ) ) { + + // Call a native DOM method on the target with the same name name as the event. + // Can't use an .isFunction() check here because IE6/7 fails that test. + // Don't do default actions on window, that's where global variables be (#6170) + if ( ontype && elem[ type ] && !jQuery.isWindow( elem ) ) { + + // Don't re-trigger an onFOO event when we call its FOO() method + tmp = elem[ ontype ]; + + if ( tmp ) { + elem[ ontype ] = null; + } + + // Prevent re-triggering of the same event, since we already bubbled it above + jQuery.event.triggered = type; + try { + elem[ type ](); + } catch ( e ) { + // IE<9 dies on focus/blur to hidden element (#1486,#12518) + // only reproducible on winXP IE8 native, not IE9 in IE8 mode + } + jQuery.event.triggered = undefined; + + if ( tmp ) { + elem[ ontype ] = tmp; + } + } + } + } + + return event.result; + }, + + dispatch: function( event ) { + + // Make a writable jQuery.Event from the native event object + event = jQuery.event.fix( event ); + + var i, ret, handleObj, matched, j, + handlerQueue = [], + args = slice.call( arguments ), + handlers = ( jQuery._data( this, "events" ) || {} )[ event.type ] || [], + special = jQuery.event.special[ event.type ] || {}; + + // Use the fix-ed jQuery.Event rather than the (read-only) native event + args[0] = event; + event.delegateTarget = this; + + // Call the preDispatch hook for the mapped type, and let it bail if desired + if ( special.preDispatch && special.preDispatch.call( this, event ) === false ) { + return; + } + + // Determine handlers + handlerQueue = jQuery.event.handlers.call( this, event, handlers ); + + // Run delegates first; they may want to stop propagation beneath us + i = 0; + while ( (matched = handlerQueue[ i++ ]) && !event.isPropagationStopped() ) { + event.currentTarget = matched.elem; + + j = 0; + while ( (handleObj = matched.handlers[ j++ ]) && !event.isImmediatePropagationStopped() ) { + + // Triggered event must either 1) have no namespace, or + // 2) have namespace(s) a subset or equal to those in the bound event (both can have no namespace). + if ( !event.namespace_re || event.namespace_re.test( handleObj.namespace ) ) { + + event.handleObj = handleObj; + event.data = handleObj.data; + + ret = ( (jQuery.event.special[ handleObj.origType ] || {}).handle || handleObj.handler ) + .apply( matched.elem, args ); + + if ( ret !== undefined ) { + if ( (event.result = ret) === false ) { + event.preventDefault(); + event.stopPropagation(); + } + } + } + } + } + + // Call the postDispatch hook for the mapped type + if ( special.postDispatch ) { + special.postDispatch.call( this, event ); + } + + return event.result; + }, + + handlers: function( event, handlers ) { + var sel, handleObj, matches, i, + handlerQueue = [], + delegateCount = handlers.delegateCount, + cur = event.target; + + // Find delegate handlers + // Black-hole SVG instance trees (#13180) + // Avoid non-left-click bubbling in Firefox (#3861) + if ( delegateCount && cur.nodeType && (!event.button || event.type !== "click") ) { + + /* jshint eqeqeq: false */ + for ( ; cur != this; cur = cur.parentNode || this ) { + /* jshint eqeqeq: true */ + + // Don't check non-elements (#13208) + // Don't process clicks on disabled elements (#6911, #8165, #11382, #11764) + if ( cur.nodeType === 1 && (cur.disabled !== true || event.type !== "click") ) { + matches = []; + for ( i = 0; i < delegateCount; i++ ) { + handleObj = handlers[ i ]; + + // Don't conflict with Object.prototype properties (#13203) + sel = handleObj.selector + " "; + + if ( matches[ sel ] === undefined ) { + matches[ sel ] = handleObj.needsContext ? + jQuery( sel, this ).index( cur ) >= 0 : + jQuery.find( sel, this, null, [ cur ] ).length; + } + if ( matches[ sel ] ) { + matches.push( handleObj ); + } + } + if ( matches.length ) { + handlerQueue.push({ elem: cur, handlers: matches }); + } + } + } + } + + // Add the remaining (directly-bound) handlers + if ( delegateCount < handlers.length ) { + handlerQueue.push({ elem: this, handlers: handlers.slice( delegateCount ) }); + } + + return handlerQueue; + }, + + fix: function( event ) { + if ( event[ jQuery.expando ] ) { + return event; + } + + // Create a writable copy of the event object and normalize some properties + var i, prop, copy, + type = event.type, + originalEvent = event, + fixHook = this.fixHooks[ type ]; + + if ( !fixHook ) { + this.fixHooks[ type ] = fixHook = + rmouseEvent.test( type ) ? this.mouseHooks : + rkeyEvent.test( type ) ? this.keyHooks : + {}; + } + copy = fixHook.props ? this.props.concat( fixHook.props ) : this.props; + + event = new jQuery.Event( originalEvent ); + + i = copy.length; + while ( i-- ) { + prop = copy[ i ]; + event[ prop ] = originalEvent[ prop ]; + } + + // Support: IE<9 + // Fix target property (#1925) + if ( !event.target ) { + event.target = originalEvent.srcElement || document; + } + + // Support: Chrome 23+, Safari? + // Target should not be a text node (#504, #13143) + if ( event.target.nodeType === 3 ) { + event.target = event.target.parentNode; + } + + // Support: IE<9 + // For mouse/key events, metaKey==false if it's undefined (#3368, #11328) + event.metaKey = !!event.metaKey; + + return fixHook.filter ? fixHook.filter( event, originalEvent ) : event; + }, + + // Includes some event props shared by KeyEvent and MouseEvent + props: "altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "), + + fixHooks: {}, + + keyHooks: { + props: "char charCode key keyCode".split(" "), + filter: function( event, original ) { + + // Add which for key events + if ( event.which == null ) { + event.which = original.charCode != null ? original.charCode : original.keyCode; + } + + return event; + } + }, + + mouseHooks: { + props: "button buttons clientX clientY fromElement offsetX offsetY pageX pageY screenX screenY toElement".split(" "), + filter: function( event, original ) { + var body, eventDoc, doc, + button = original.button, + fromElement = original.fromElement; + + // Calculate pageX/Y if missing and clientX/Y available + if ( event.pageX == null && original.clientX != null ) { + eventDoc = event.target.ownerDocument || document; + doc = eventDoc.documentElement; + body = eventDoc.body; + + event.pageX = original.clientX + ( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) - ( doc && doc.clientLeft || body && body.clientLeft || 0 ); + event.pageY = original.clientY + ( doc && doc.scrollTop || body && body.scrollTop || 0 ) - ( doc && doc.clientTop || body && body.clientTop || 0 ); + } + + // Add relatedTarget, if necessary + if ( !event.relatedTarget && fromElement ) { + event.relatedTarget = fromElement === event.target ? original.toElement : fromElement; + } + + // Add which for click: 1 === left; 2 === middle; 3 === right + // Note: button is not normalized, so don't use it + if ( !event.which && button !== undefined ) { + event.which = ( button & 1 ? 1 : ( button & 2 ? 3 : ( button & 4 ? 2 : 0 ) ) ); + } + + return event; + } + }, + + special: { + load: { + // Prevent triggered image.load events from bubbling to window.load + noBubble: true + }, + focus: { + // Fire native event if possible so blur/focus sequence is correct + trigger: function() { + if ( this !== safeActiveElement() && this.focus ) { + try { + this.focus(); + return false; + } catch ( e ) { + // Support: IE<9 + // If we error on focus to hidden element (#1486, #12518), + // let .trigger() run the handlers + } + } + }, + delegateType: "focusin" + }, + blur: { + trigger: function() { + if ( this === safeActiveElement() && this.blur ) { + this.blur(); + return false; + } + }, + delegateType: "focusout" + }, + click: { + // For checkbox, fire native event so checked state will be right + trigger: function() { + if ( jQuery.nodeName( this, "input" ) && this.type === "checkbox" && this.click ) { + this.click(); + return false; + } + }, + + // For cross-browser consistency, don't fire native .click() on links + _default: function( event ) { + return jQuery.nodeName( event.target, "a" ); + } + }, + + beforeunload: { + postDispatch: function( event ) { + + // Support: Firefox 20+ + // Firefox doesn't alert if the returnValue field is not set. + if ( event.result !== undefined && event.originalEvent ) { + event.originalEvent.returnValue = event.result; + } + } + } + }, + + simulate: function( type, elem, event, bubble ) { + // Piggyback on a donor event to simulate a different one. + // Fake originalEvent to avoid donor's stopPropagation, but if the + // simulated event prevents default then we do the same on the donor. + var e = jQuery.extend( + new jQuery.Event(), + event, + { + type: type, + isSimulated: true, + originalEvent: {} + } + ); + if ( bubble ) { + jQuery.event.trigger( e, null, elem ); + } else { + jQuery.event.dispatch.call( elem, e ); + } + if ( e.isDefaultPrevented() ) { + event.preventDefault(); + } + } +}; + +jQuery.removeEvent = document.removeEventListener ? + function( elem, type, handle ) { + if ( elem.removeEventListener ) { + elem.removeEventListener( type, handle, false ); + } + } : + function( elem, type, handle ) { + var name = "on" + type; + + if ( elem.detachEvent ) { + + // #8545, #7054, preventing memory leaks for custom events in IE6-8 + // detachEvent needed property on element, by name of that event, to properly expose it to GC + if ( typeof elem[ name ] === strundefined ) { + elem[ name ] = null; + } + + elem.detachEvent( name, handle ); + } + }; + +jQuery.Event = function( src, props ) { + // Allow instantiation without the 'new' keyword + if ( !(this instanceof jQuery.Event) ) { + return new jQuery.Event( src, props ); + } + + // Event object + if ( src && src.type ) { + this.originalEvent = src; + this.type = src.type; + + // Events bubbling up the document may have been marked as prevented + // by a handler lower down the tree; reflect the correct value. + this.isDefaultPrevented = src.defaultPrevented || + src.defaultPrevented === undefined && + // Support: IE < 9, Android < 4.0 + src.returnValue === false ? + returnTrue : + returnFalse; + + // Event type + } else { + this.type = src; + } + + // Put explicitly provided properties onto the event object + if ( props ) { + jQuery.extend( this, props ); + } + + // Create a timestamp if incoming event doesn't have one + this.timeStamp = src && src.timeStamp || jQuery.now(); + + // Mark it as fixed + this[ jQuery.expando ] = true; +}; + +// jQuery.Event is based on DOM3 Events as specified by the ECMAScript Language Binding +// http://www.w3.org/TR/2003/WD-DOM-Level-3-Events-20030331/ecma-script-binding.html +jQuery.Event.prototype = { + isDefaultPrevented: returnFalse, + isPropagationStopped: returnFalse, + isImmediatePropagationStopped: returnFalse, + + preventDefault: function() { + var e = this.originalEvent; + + this.isDefaultPrevented = returnTrue; + if ( !e ) { + return; + } + + // If preventDefault exists, run it on the original event + if ( e.preventDefault ) { + e.preventDefault(); + + // Support: IE + // Otherwise set the returnValue property of the original event to false + } else { + e.returnValue = false; + } + }, + stopPropagation: function() { + var e = this.originalEvent; + + this.isPropagationStopped = returnTrue; + if ( !e ) { + return; + } + // If stopPropagation exists, run it on the original event + if ( e.stopPropagation ) { + e.stopPropagation(); + } + + // Support: IE + // Set the cancelBubble property of the original event to true + e.cancelBubble = true; + }, + stopImmediatePropagation: function() { + var e = this.originalEvent; + + this.isImmediatePropagationStopped = returnTrue; + + if ( e && e.stopImmediatePropagation ) { + e.stopImmediatePropagation(); + } + + this.stopPropagation(); + } +}; + +// Create mouseenter/leave events using mouseover/out and event-time checks +jQuery.each({ + mouseenter: "mouseover", + mouseleave: "mouseout", + pointerenter: "pointerover", + pointerleave: "pointerout" +}, function( orig, fix ) { + jQuery.event.special[ orig ] = { + delegateType: fix, + bindType: fix, + + handle: function( event ) { + var ret, + target = this, + related = event.relatedTarget, + handleObj = event.handleObj; + + // For mousenter/leave call the handler if related is outside the target. + // NB: No relatedTarget if the mouse left/entered the browser window + if ( !related || (related !== target && !jQuery.contains( target, related )) ) { + event.type = handleObj.origType; + ret = handleObj.handler.apply( this, arguments ); + event.type = fix; + } + return ret; + } + }; +}); + +// IE submit delegation +if ( !support.submitBubbles ) { + + jQuery.event.special.submit = { + setup: function() { + // Only need this for delegated form submit events + if ( jQuery.nodeName( this, "form" ) ) { + return false; + } + + // Lazy-add a submit handler when a descendant form may potentially be submitted + jQuery.event.add( this, "click._submit keypress._submit", function( e ) { + // Node name check avoids a VML-related crash in IE (#9807) + var elem = e.target, + form = jQuery.nodeName( elem, "input" ) || jQuery.nodeName( elem, "button" ) ? elem.form : undefined; + if ( form && !jQuery._data( form, "submitBubbles" ) ) { + jQuery.event.add( form, "submit._submit", function( event ) { + event._submit_bubble = true; + }); + jQuery._data( form, "submitBubbles", true ); + } + }); + // return undefined since we don't need an event listener + }, + + postDispatch: function( event ) { + // If form was submitted by the user, bubble the event up the tree + if ( event._submit_bubble ) { + delete event._submit_bubble; + if ( this.parentNode && !event.isTrigger ) { + jQuery.event.simulate( "submit", this.parentNode, event, true ); + } + } + }, + + teardown: function() { + // Only need this for delegated form submit events + if ( jQuery.nodeName( this, "form" ) ) { + return false; + } + + // Remove delegated handlers; cleanData eventually reaps submit handlers attached above + jQuery.event.remove( this, "._submit" ); + } + }; +} + +// IE change delegation and checkbox/radio fix +if ( !support.changeBubbles ) { + + jQuery.event.special.change = { + + setup: function() { + + if ( rformElems.test( this.nodeName ) ) { + // IE doesn't fire change on a check/radio until blur; trigger it on click + // after a propertychange. Eat the blur-change in special.change.handle. + // This still fires onchange a second time for check/radio after blur. + if ( this.type === "checkbox" || this.type === "radio" ) { + jQuery.event.add( this, "propertychange._change", function( event ) { + if ( event.originalEvent.propertyName === "checked" ) { + this._just_changed = true; + } + }); + jQuery.event.add( this, "click._change", function( event ) { + if ( this._just_changed && !event.isTrigger ) { + this._just_changed = false; + } + // Allow triggered, simulated change events (#11500) + jQuery.event.simulate( "change", this, event, true ); + }); + } + return false; + } + // Delegated event; lazy-add a change handler on descendant inputs + jQuery.event.add( this, "beforeactivate._change", function( e ) { + var elem = e.target; + + if ( rformElems.test( elem.nodeName ) && !jQuery._data( elem, "changeBubbles" ) ) { + jQuery.event.add( elem, "change._change", function( event ) { + if ( this.parentNode && !event.isSimulated && !event.isTrigger ) { + jQuery.event.simulate( "change", this.parentNode, event, true ); + } + }); + jQuery._data( elem, "changeBubbles", true ); + } + }); + }, + + handle: function( event ) { + var elem = event.target; + + // Swallow native change events from checkbox/radio, we already triggered them above + if ( this !== elem || event.isSimulated || event.isTrigger || (elem.type !== "radio" && elem.type !== "checkbox") ) { + return event.handleObj.handler.apply( this, arguments ); + } + }, + + teardown: function() { + jQuery.event.remove( this, "._change" ); + + return !rformElems.test( this.nodeName ); + } + }; +} + +// Create "bubbling" focus and blur events +if ( !support.focusinBubbles ) { + jQuery.each({ focus: "focusin", blur: "focusout" }, function( orig, fix ) { + + // Attach a single capturing handler on the document while someone wants focusin/focusout + var handler = function( event ) { + jQuery.event.simulate( fix, event.target, jQuery.event.fix( event ), true ); + }; + + jQuery.event.special[ fix ] = { + setup: function() { + var doc = this.ownerDocument || this, + attaches = jQuery._data( doc, fix ); + + if ( !attaches ) { + doc.addEventListener( orig, handler, true ); + } + jQuery._data( doc, fix, ( attaches || 0 ) + 1 ); + }, + teardown: function() { + var doc = this.ownerDocument || this, + attaches = jQuery._data( doc, fix ) - 1; + + if ( !attaches ) { + doc.removeEventListener( orig, handler, true ); + jQuery._removeData( doc, fix ); + } else { + jQuery._data( doc, fix, attaches ); + } + } + }; + }); +} + +jQuery.fn.extend({ + + on: function( types, selector, data, fn, /*INTERNAL*/ one ) { + var type, origFn; + + // Types can be a map of types/handlers + if ( typeof types === "object" ) { + // ( types-Object, selector, data ) + if ( typeof selector !== "string" ) { + // ( types-Object, data ) + data = data || selector; + selector = undefined; + } + for ( type in types ) { + this.on( type, selector, data, types[ type ], one ); + } + return this; + } + + if ( data == null && fn == null ) { + // ( types, fn ) + fn = selector; + data = selector = undefined; + } else if ( fn == null ) { + if ( typeof selector === "string" ) { + // ( types, selector, fn ) + fn = data; + data = undefined; + } else { + // ( types, data, fn ) + fn = data; + data = selector; + selector = undefined; + } + } + if ( fn === false ) { + fn = returnFalse; + } else if ( !fn ) { + return this; + } + + if ( one === 1 ) { + origFn = fn; + fn = function( event ) { + // Can use an empty set, since event contains the info + jQuery().off( event ); + return origFn.apply( this, arguments ); + }; + // Use same guid so caller can remove using origFn + fn.guid = origFn.guid || ( origFn.guid = jQuery.guid++ ); + } + return this.each( function() { + jQuery.event.add( this, types, fn, data, selector ); + }); + }, + one: function( types, selector, data, fn ) { + return this.on( types, selector, data, fn, 1 ); + }, + off: function( types, selector, fn ) { + var handleObj, type; + if ( types && types.preventDefault && types.handleObj ) { + // ( event ) dispatched jQuery.Event + handleObj = types.handleObj; + jQuery( types.delegateTarget ).off( + handleObj.namespace ? handleObj.origType + "." + handleObj.namespace : handleObj.origType, + handleObj.selector, + handleObj.handler + ); + return this; + } + if ( typeof types === "object" ) { + // ( types-object [, selector] ) + for ( type in types ) { + this.off( type, selector, types[ type ] ); + } + return this; + } + if ( selector === false || typeof selector === "function" ) { + // ( types [, fn] ) + fn = selector; + selector = undefined; + } + if ( fn === false ) { + fn = returnFalse; + } + return this.each(function() { + jQuery.event.remove( this, types, fn, selector ); + }); + }, + + trigger: function( type, data ) { + return this.each(function() { + jQuery.event.trigger( type, data, this ); + }); + }, + triggerHandler: function( type, data ) { + var elem = this[0]; + if ( elem ) { + return jQuery.event.trigger( type, data, elem, true ); + } + } +}); + + +function createSafeFragment( document ) { + var list = nodeNames.split( "|" ), + safeFrag = document.createDocumentFragment(); + + if ( safeFrag.createElement ) { + while ( list.length ) { + safeFrag.createElement( + list.pop() + ); + } + } + return safeFrag; +} + +var nodeNames = "abbr|article|aside|audio|bdi|canvas|data|datalist|details|figcaption|figure|footer|" + + "header|hgroup|mark|meter|nav|output|progress|section|summary|time|video", + rinlinejQuery = / jQuery\d+="(?:null|\d+)"/g, + rnoshimcache = new RegExp("<(?:" + nodeNames + ")[\\s/>]", "i"), + rleadingWhitespace = /^\s+/, + rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi, + rtagName = /<([\w:]+)/, + rtbody = /\s*$/g, + + // We have to close these tags to support XHTML (#13200) + wrapMap = { + option: [ 1, "" ], + legend: [ 1, "
", "
" ], + area: [ 1, "", "" ], + param: [ 1, "", "" ], + thead: [ 1, "", "
" ], + tr: [ 2, "", "
" ], + col: [ 2, "", "
" ], + td: [ 3, "", "
" ], + + // IE6-8 can't serialize link, script, style, or any html5 (NoScope) tags, + // unless wrapped in a div with non-breaking characters in front of it. + _default: support.htmlSerialize ? [ 0, "", "" ] : [ 1, "X
", "
" ] + }, + safeFragment = createSafeFragment( document ), + fragmentDiv = safeFragment.appendChild( document.createElement("div") ); + +wrapMap.optgroup = wrapMap.option; +wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead; +wrapMap.th = wrapMap.td; + +function getAll( context, tag ) { + var elems, elem, + i = 0, + found = typeof context.getElementsByTagName !== strundefined ? context.getElementsByTagName( tag || "*" ) : + typeof context.querySelectorAll !== strundefined ? context.querySelectorAll( tag || "*" ) : + undefined; + + if ( !found ) { + for ( found = [], elems = context.childNodes || context; (elem = elems[i]) != null; i++ ) { + if ( !tag || jQuery.nodeName( elem, tag ) ) { + found.push( elem ); + } else { + jQuery.merge( found, getAll( elem, tag ) ); + } + } + } + + return tag === undefined || tag && jQuery.nodeName( context, tag ) ? + jQuery.merge( [ context ], found ) : + found; +} + +// Used in buildFragment, fixes the defaultChecked property +function fixDefaultChecked( elem ) { + if ( rcheckableType.test( elem.type ) ) { + elem.defaultChecked = elem.checked; + } +} + +// Support: IE<8 +// Manipulating tables requires a tbody +function manipulationTarget( elem, content ) { + return jQuery.nodeName( elem, "table" ) && + jQuery.nodeName( content.nodeType !== 11 ? content : content.firstChild, "tr" ) ? + + elem.getElementsByTagName("tbody")[0] || + elem.appendChild( elem.ownerDocument.createElement("tbody") ) : + elem; +} + +// Replace/restore the type attribute of script elements for safe DOM manipulation +function disableScript( elem ) { + elem.type = (jQuery.find.attr( elem, "type" ) !== null) + "/" + elem.type; + return elem; +} +function restoreScript( elem ) { + var match = rscriptTypeMasked.exec( elem.type ); + if ( match ) { + elem.type = match[1]; + } else { + elem.removeAttribute("type"); + } + return elem; +} + +// Mark scripts as having already been evaluated +function setGlobalEval( elems, refElements ) { + var elem, + i = 0; + for ( ; (elem = elems[i]) != null; i++ ) { + jQuery._data( elem, "globalEval", !refElements || jQuery._data( refElements[i], "globalEval" ) ); + } +} + +function cloneCopyEvent( src, dest ) { + + if ( dest.nodeType !== 1 || !jQuery.hasData( src ) ) { + return; + } + + var type, i, l, + oldData = jQuery._data( src ), + curData = jQuery._data( dest, oldData ), + events = oldData.events; + + if ( events ) { + delete curData.handle; + curData.events = {}; + + for ( type in events ) { + for ( i = 0, l = events[ type ].length; i < l; i++ ) { + jQuery.event.add( dest, type, events[ type ][ i ] ); + } + } + } + + // make the cloned public data object a copy from the original + if ( curData.data ) { + curData.data = jQuery.extend( {}, curData.data ); + } +} + +function fixCloneNodeIssues( src, dest ) { + var nodeName, e, data; + + // We do not need to do anything for non-Elements + if ( dest.nodeType !== 1 ) { + return; + } + + nodeName = dest.nodeName.toLowerCase(); + + // IE6-8 copies events bound via attachEvent when using cloneNode. + if ( !support.noCloneEvent && dest[ jQuery.expando ] ) { + data = jQuery._data( dest ); + + for ( e in data.events ) { + jQuery.removeEvent( dest, e, data.handle ); + } + + // Event data gets referenced instead of copied if the expando gets copied too + dest.removeAttribute( jQuery.expando ); + } + + // IE blanks contents when cloning scripts, and tries to evaluate newly-set text + if ( nodeName === "script" && dest.text !== src.text ) { + disableScript( dest ).text = src.text; + restoreScript( dest ); + + // IE6-10 improperly clones children of object elements using classid. + // IE10 throws NoModificationAllowedError if parent is null, #12132. + } else if ( nodeName === "object" ) { + if ( dest.parentNode ) { + dest.outerHTML = src.outerHTML; + } + + // This path appears unavoidable for IE9. When cloning an object + // element in IE9, the outerHTML strategy above is not sufficient. + // If the src has innerHTML and the destination does not, + // copy the src.innerHTML into the dest.innerHTML. #10324 + if ( support.html5Clone && ( src.innerHTML && !jQuery.trim(dest.innerHTML) ) ) { + dest.innerHTML = src.innerHTML; + } + + } else if ( nodeName === "input" && rcheckableType.test( src.type ) ) { + // IE6-8 fails to persist the checked state of a cloned checkbox + // or radio button. Worse, IE6-7 fail to give the cloned element + // a checked appearance if the defaultChecked value isn't also set + + dest.defaultChecked = dest.checked = src.checked; + + // IE6-7 get confused and end up setting the value of a cloned + // checkbox/radio button to an empty string instead of "on" + if ( dest.value !== src.value ) { + dest.value = src.value; + } + + // IE6-8 fails to return the selected option to the default selected + // state when cloning options + } else if ( nodeName === "option" ) { + dest.defaultSelected = dest.selected = src.defaultSelected; + + // IE6-8 fails to set the defaultValue to the correct value when + // cloning other types of input fields + } else if ( nodeName === "input" || nodeName === "textarea" ) { + dest.defaultValue = src.defaultValue; + } +} + +jQuery.extend({ + clone: function( elem, dataAndEvents, deepDataAndEvents ) { + var destElements, node, clone, i, srcElements, + inPage = jQuery.contains( elem.ownerDocument, elem ); + + if ( support.html5Clone || jQuery.isXMLDoc(elem) || !rnoshimcache.test( "<" + elem.nodeName + ">" ) ) { + clone = elem.cloneNode( true ); + + // IE<=8 does not properly clone detached, unknown element nodes + } else { + fragmentDiv.innerHTML = elem.outerHTML; + fragmentDiv.removeChild( clone = fragmentDiv.firstChild ); + } + + if ( (!support.noCloneEvent || !support.noCloneChecked) && + (elem.nodeType === 1 || elem.nodeType === 11) && !jQuery.isXMLDoc(elem) ) { + + // We eschew Sizzle here for performance reasons: http://jsperf.com/getall-vs-sizzle/2 + destElements = getAll( clone ); + srcElements = getAll( elem ); + + // Fix all IE cloning issues + for ( i = 0; (node = srcElements[i]) != null; ++i ) { + // Ensure that the destination node is not null; Fixes #9587 + if ( destElements[i] ) { + fixCloneNodeIssues( node, destElements[i] ); + } + } + } + + // Copy the events from the original to the clone + if ( dataAndEvents ) { + if ( deepDataAndEvents ) { + srcElements = srcElements || getAll( elem ); + destElements = destElements || getAll( clone ); + + for ( i = 0; (node = srcElements[i]) != null; i++ ) { + cloneCopyEvent( node, destElements[i] ); + } + } else { + cloneCopyEvent( elem, clone ); + } + } + + // Preserve script evaluation history + destElements = getAll( clone, "script" ); + if ( destElements.length > 0 ) { + setGlobalEval( destElements, !inPage && getAll( elem, "script" ) ); + } + + destElements = srcElements = node = null; + + // Return the cloned set + return clone; + }, + + buildFragment: function( elems, context, scripts, selection ) { + var j, elem, contains, + tmp, tag, tbody, wrap, + l = elems.length, + + // Ensure a safe fragment + safe = createSafeFragment( context ), + + nodes = [], + i = 0; + + for ( ; i < l; i++ ) { + elem = elems[ i ]; + + if ( elem || elem === 0 ) { + + // Add nodes directly + if ( jQuery.type( elem ) === "object" ) { + jQuery.merge( nodes, elem.nodeType ? [ elem ] : elem ); + + // Convert non-html into a text node + } else if ( !rhtml.test( elem ) ) { + nodes.push( context.createTextNode( elem ) ); + + // Convert html into DOM nodes + } else { + tmp = tmp || safe.appendChild( context.createElement("div") ); + + // Deserialize a standard representation + tag = (rtagName.exec( elem ) || [ "", "" ])[ 1 ].toLowerCase(); + wrap = wrapMap[ tag ] || wrapMap._default; + + tmp.innerHTML = wrap[1] + elem.replace( rxhtmlTag, "<$1>" ) + wrap[2]; + + // Descend through wrappers to the right content + j = wrap[0]; + while ( j-- ) { + tmp = tmp.lastChild; + } + + // Manually add leading whitespace removed by IE + if ( !support.leadingWhitespace && rleadingWhitespace.test( elem ) ) { + nodes.push( context.createTextNode( rleadingWhitespace.exec( elem )[0] ) ); + } + + // Remove IE's autoinserted from table fragments + if ( !support.tbody ) { + + // String was a , *may* have spurious + elem = tag === "table" && !rtbody.test( elem ) ? + tmp.firstChild : + + // String was a bare or + wrap[1] === "
" && !rtbody.test( elem ) ? + tmp : + 0; + + j = elem && elem.childNodes.length; + while ( j-- ) { + if ( jQuery.nodeName( (tbody = elem.childNodes[j]), "tbody" ) && !tbody.childNodes.length ) { + elem.removeChild( tbody ); + } + } + } + + jQuery.merge( nodes, tmp.childNodes ); + + // Fix #12392 for WebKit and IE > 9 + tmp.textContent = ""; + + // Fix #12392 for oldIE + while ( tmp.firstChild ) { + tmp.removeChild( tmp.firstChild ); + } + + // Remember the top-level container for proper cleanup + tmp = safe.lastChild; + } + } + } + + // Fix #11356: Clear elements from fragment + if ( tmp ) { + safe.removeChild( tmp ); + } + + // Reset defaultChecked for any radios and checkboxes + // about to be appended to the DOM in IE 6/7 (#8060) + if ( !support.appendChecked ) { + jQuery.grep( getAll( nodes, "input" ), fixDefaultChecked ); + } + + i = 0; + while ( (elem = nodes[ i++ ]) ) { + + // #4087 - If origin and destination elements are the same, and this is + // that element, do not do anything + if ( selection && jQuery.inArray( elem, selection ) !== -1 ) { + continue; + } + + contains = jQuery.contains( elem.ownerDocument, elem ); + + // Append to fragment + tmp = getAll( safe.appendChild( elem ), "script" ); + + // Preserve script evaluation history + if ( contains ) { + setGlobalEval( tmp ); + } + + // Capture executables + if ( scripts ) { + j = 0; + while ( (elem = tmp[ j++ ]) ) { + if ( rscriptType.test( elem.type || "" ) ) { + scripts.push( elem ); + } + } + } + } + + tmp = null; + + return safe; + }, + + cleanData: function( elems, /* internal */ acceptData ) { + var elem, type, id, data, + i = 0, + internalKey = jQuery.expando, + cache = jQuery.cache, + deleteExpando = support.deleteExpando, + special = jQuery.event.special; + + for ( ; (elem = elems[i]) != null; i++ ) { + if ( acceptData || jQuery.acceptData( elem ) ) { + + id = elem[ internalKey ]; + data = id && cache[ id ]; + + if ( data ) { + if ( data.events ) { + for ( type in data.events ) { + if ( special[ type ] ) { + jQuery.event.remove( elem, type ); + + // This is a shortcut to avoid jQuery.event.remove's overhead + } else { + jQuery.removeEvent( elem, type, data.handle ); + } + } + } + + // Remove cache only if it was not already removed by jQuery.event.remove + if ( cache[ id ] ) { + + delete cache[ id ]; + + // IE does not allow us to delete expando properties from nodes, + // nor does it have a removeAttribute function on Document nodes; + // we must handle all of these cases + if ( deleteExpando ) { + delete elem[ internalKey ]; + + } else if ( typeof elem.removeAttribute !== strundefined ) { + elem.removeAttribute( internalKey ); + + } else { + elem[ internalKey ] = null; + } + + deletedIds.push( id ); + } + } + } + } + } +}); + +jQuery.fn.extend({ + text: function( value ) { + return access( this, function( value ) { + return value === undefined ? + jQuery.text( this ) : + this.empty().append( ( this[0] && this[0].ownerDocument || document ).createTextNode( value ) ); + }, null, value, arguments.length ); + }, + + append: function() { + return this.domManip( arguments, function( elem ) { + if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) { + var target = manipulationTarget( this, elem ); + target.appendChild( elem ); + } + }); + }, + + prepend: function() { + return this.domManip( arguments, function( elem ) { + if ( this.nodeType === 1 || this.nodeType === 11 || this.nodeType === 9 ) { + var target = manipulationTarget( this, elem ); + target.insertBefore( elem, target.firstChild ); + } + }); + }, + + before: function() { + return this.domManip( arguments, function( elem ) { + if ( this.parentNode ) { + this.parentNode.insertBefore( elem, this ); + } + }); + }, + + after: function() { + return this.domManip( arguments, function( elem ) { + if ( this.parentNode ) { + this.parentNode.insertBefore( elem, this.nextSibling ); + } + }); + }, + + remove: function( selector, keepData /* Internal Use Only */ ) { + var elem, + elems = selector ? jQuery.filter( selector, this ) : this, + i = 0; + + for ( ; (elem = elems[i]) != null; i++ ) { + + if ( !keepData && elem.nodeType === 1 ) { + jQuery.cleanData( getAll( elem ) ); + } + + if ( elem.parentNode ) { + if ( keepData && jQuery.contains( elem.ownerDocument, elem ) ) { + setGlobalEval( getAll( elem, "script" ) ); + } + elem.parentNode.removeChild( elem ); + } + } + + return this; + }, + + empty: function() { + var elem, + i = 0; + + for ( ; (elem = this[i]) != null; i++ ) { + // Remove element nodes and prevent memory leaks + if ( elem.nodeType === 1 ) { + jQuery.cleanData( getAll( elem, false ) ); + } + + // Remove any remaining nodes + while ( elem.firstChild ) { + elem.removeChild( elem.firstChild ); + } + + // If this is a select, ensure that it displays empty (#12336) + // Support: IE<9 + if ( elem.options && jQuery.nodeName( elem, "select" ) ) { + elem.options.length = 0; + } + } + + return this; + }, + + clone: function( dataAndEvents, deepDataAndEvents ) { + dataAndEvents = dataAndEvents == null ? false : dataAndEvents; + deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents; + + return this.map(function() { + return jQuery.clone( this, dataAndEvents, deepDataAndEvents ); + }); + }, + + html: function( value ) { + return access( this, function( value ) { + var elem = this[ 0 ] || {}, + i = 0, + l = this.length; + + if ( value === undefined ) { + return elem.nodeType === 1 ? + elem.innerHTML.replace( rinlinejQuery, "" ) : + undefined; + } + + // See if we can take a shortcut and just use innerHTML + if ( typeof value === "string" && !rnoInnerhtml.test( value ) && + ( support.htmlSerialize || !rnoshimcache.test( value ) ) && + ( support.leadingWhitespace || !rleadingWhitespace.test( value ) ) && + !wrapMap[ (rtagName.exec( value ) || [ "", "" ])[ 1 ].toLowerCase() ] ) { + + value = value.replace( rxhtmlTag, "<$1>" ); + + try { + for (; i < l; i++ ) { + // Remove element nodes and prevent memory leaks + elem = this[i] || {}; + if ( elem.nodeType === 1 ) { + jQuery.cleanData( getAll( elem, false ) ); + elem.innerHTML = value; + } + } + + elem = 0; + + // If using innerHTML throws an exception, use the fallback method + } catch(e) {} + } + + if ( elem ) { + this.empty().append( value ); + } + }, null, value, arguments.length ); + }, + + replaceWith: function() { + var arg = arguments[ 0 ]; + + // Make the changes, replacing each context element with the new content + this.domManip( arguments, function( elem ) { + arg = this.parentNode; + + jQuery.cleanData( getAll( this ) ); + + if ( arg ) { + arg.replaceChild( elem, this ); + } + }); + + // Force removal if there was no new content (e.g., from empty arguments) + return arg && (arg.length || arg.nodeType) ? this : this.remove(); + }, + + detach: function( selector ) { + return this.remove( selector, true ); + }, + + domManip: function( args, callback ) { + + // Flatten any nested arrays + args = concat.apply( [], args ); + + var first, node, hasScripts, + scripts, doc, fragment, + i = 0, + l = this.length, + set = this, + iNoClone = l - 1, + value = args[0], + isFunction = jQuery.isFunction( value ); + + // We can't cloneNode fragments that contain checked, in WebKit + if ( isFunction || + ( l > 1 && typeof value === "string" && + !support.checkClone && rchecked.test( value ) ) ) { + return this.each(function( index ) { + var self = set.eq( index ); + if ( isFunction ) { + args[0] = value.call( this, index, self.html() ); + } + self.domManip( args, callback ); + }); + } + + if ( l ) { + fragment = jQuery.buildFragment( args, this[ 0 ].ownerDocument, false, this ); + first = fragment.firstChild; + + if ( fragment.childNodes.length === 1 ) { + fragment = first; + } + + if ( first ) { + scripts = jQuery.map( getAll( fragment, "script" ), disableScript ); + hasScripts = scripts.length; + + // Use the original fragment for the last item instead of the first because it can end up + // being emptied incorrectly in certain situations (#8070). + for ( ; i < l; i++ ) { + node = fragment; + + if ( i !== iNoClone ) { + node = jQuery.clone( node, true, true ); + + // Keep references to cloned scripts for later restoration + if ( hasScripts ) { + jQuery.merge( scripts, getAll( node, "script" ) ); + } + } + + callback.call( this[i], node, i ); + } + + if ( hasScripts ) { + doc = scripts[ scripts.length - 1 ].ownerDocument; + + // Reenable scripts + jQuery.map( scripts, restoreScript ); + + // Evaluate executable scripts on first document insertion + for ( i = 0; i < hasScripts; i++ ) { + node = scripts[ i ]; + if ( rscriptType.test( node.type || "" ) && + !jQuery._data( node, "globalEval" ) && jQuery.contains( doc, node ) ) { + + if ( node.src ) { + // Optional AJAX dependency, but won't run scripts if not present + if ( jQuery._evalUrl ) { + jQuery._evalUrl( node.src ); + } + } else { + jQuery.globalEval( ( node.text || node.textContent || node.innerHTML || "" ).replace( rcleanScript, "" ) ); + } + } + } + } + + // Fix #11809: Avoid leaking memory + fragment = first = null; + } + } + + return this; + } +}); + +jQuery.each({ + appendTo: "append", + prependTo: "prepend", + insertBefore: "before", + insertAfter: "after", + replaceAll: "replaceWith" +}, function( name, original ) { + jQuery.fn[ name ] = function( selector ) { + var elems, + i = 0, + ret = [], + insert = jQuery( selector ), + last = insert.length - 1; + + for ( ; i <= last; i++ ) { + elems = i === last ? this : this.clone(true); + jQuery( insert[i] )[ original ]( elems ); + + // Modern browsers can apply jQuery collections as arrays, but oldIE needs a .get() + push.apply( ret, elems.get() ); + } + + return this.pushStack( ret ); + }; +}); + + +var iframe, + elemdisplay = {}; + +/** + * Retrieve the actual display of a element + * @param {String} name nodeName of the element + * @param {Object} doc Document object + */ +// Called only from within defaultDisplay +function actualDisplay( name, doc ) { + var style, + elem = jQuery( doc.createElement( name ) ).appendTo( doc.body ), + + // getDefaultComputedStyle might be reliably used only on attached element + display = window.getDefaultComputedStyle && ( style = window.getDefaultComputedStyle( elem[ 0 ] ) ) ? + + // Use of this method is a temporary fix (more like optmization) until something better comes along, + // since it was removed from specification and supported only in FF + style.display : jQuery.css( elem[ 0 ], "display" ); + + // We don't have any data stored on the element, + // so use "detach" method as fast way to get rid of the element + elem.detach(); + + return display; +} + +/** + * Try to determine the default display value of an element + * @param {String} nodeName + */ +function defaultDisplay( nodeName ) { + var doc = document, + display = elemdisplay[ nodeName ]; + + if ( !display ) { + display = actualDisplay( nodeName, doc ); + + // If the simple way fails, read from inside an iframe + if ( display === "none" || !display ) { + + // Use the already-created iframe if possible + iframe = (iframe || jQuery( "