UNPKG

cozy-proxy

Version:

Cozy Proxy redirects requests properly to the right application of the Cozy platform depending on given path. It also handles authentication to the Cozy for users and devices.

2 lines 295 kB
!function(e){function t(n){if(r[n])return r[n].exports;var i=r[n]={exports:{},id:n,loaded:!1};return e[n].call(i.exports,i,i.exports,t),i.loaded=!0,i.exports}var n=window.webpackJsonp;window.webpackJsonp=function(r,o){for(var s,a,u=0,c=[];u<r.length;u++)a=r[u],i[a]&&c.push.apply(c,i[a]),i[a]=0;for(s in o){var l=o[s];switch(typeof l){case"object":e[s]=function(t){var n=t.slice(1),r=t[0];return function(t,i,o){e[r].apply(this,[t,i,o].concat(n))}}(l);break;case"function":e[s]=l;break;default:e[s]=e[l]}}for(n&&n(r,o);c.length;)c.shift().call(null,t)};var r={},i={1:0};return t.e=function(e,n){if(0===i[e])return n.call(null,t);if(void 0!==i[e])i[e].push(n);else{i[e]=[n];var r=document.getElementsByTagName("head")[0],o=document.createElement("script");o.type="text/javascript",o.charset="utf-8",o.async=!0,o.src=t.p+"register.d2101618e41e9fb91a6a.js",r.appendChild(o)}},t.m=e,t.c=r,t.p="",t(0)}(function(e){for(var t in e)if(Object.prototype.hasOwnProperty.call(e,t))switch(typeof e[t]){case"function":break;case"object":e[t]=function(t){var n=t.slice(1),r=e[t[0]];return function(e,t,i){r.apply(this,[e,t,i].concat(n))}}(e[t]);break;default:e[t]=e[e[t]]}return e}([function(e,t,n){var r,i,o;r=n(81),i=n(58),o=function(){var e,t,i,o,s;i=document.documentElement.getAttribute("lang");try{o=n(53)("./"+i)}catch(t){e=t,o=n(13)}return s=new r({phrases:o,locale:i}),window.t=s.t.bind(s)},document.addEventListener("DOMContentLoaded",function(){return o(),i.start()})},function(e,t,n){var r,i;!function(o,s){r=[n(9),n(6),n(56),n(55)],i=function(e,t){return o.Marionette=o.Mn=s(o,e,t)}.apply(t,r),!(void 0!==i&&(e.exports=i))}(this,function(e,t,n){"use strict";var r=e.Marionette,i=e.Mn,o=t.Marionette={};o.VERSION="2.4.5",o.noConflict=function(){return e.Marionette=r,e.Mn=i,this},o.Deferred=t.$.Deferred,o.FEATURES={},o.isEnabled=function(e){return!!o.FEATURES[e]},o.extend=t.Model.extend,o.isNodeAttached=function(e){return t.$.contains(document.documentElement,e)},o.mergeOptions=function(e,t){e&&n.extend(this,n.pick(e,t))},o.getOption=function(e,t){return e&&t?e.options&&void 0!==e.options[t]?e.options[t]:e[t]:void 0},o.proxyGetOption=function(e){return o.getOption(this,e)},o._getValue=function(e,t,r){return n.isFunction(e)&&(e=r?e.apply(t,r):e.call(t)),e},o.normalizeMethods=function(e){return n.reduce(e,function(e,t,r){return n.isFunction(t)||(t=this[t]),t&&(e[r]=t),e},{},this)},o.normalizeUIString=function(e,t){return e.replace(/@ui\.[a-zA-Z-_$0-9]*/g,function(e){return t[e.slice(4)]})},o.normalizeUIKeys=function(e,t){return n.reduce(e,function(e,n,r){var i=o.normalizeUIString(r,t);return e[i]=n,e},{})},o.normalizeUIValues=function(e,t,r){return n.each(e,function(i,s){n.isString(i)?e[s]=o.normalizeUIString(i,t):n.isObject(i)&&n.isArray(r)&&(n.extend(i,o.normalizeUIValues(n.pick(i,r),t)),n.each(r,function(e){var r=i[e];n.isString(r)&&(i[e]=o.normalizeUIString(r,t))}))}),e},o.actAsCollection=function(e,t){var r=["forEach","each","map","find","detect","filter","select","reject","every","all","some","any","include","contains","invoke","toArray","first","initial","rest","last","without","isEmpty","pluck"];n.each(r,function(r){e[r]=function(){var e=n.values(n.result(this,t)),i=[e].concat(n.toArray(arguments));return n[r].apply(n,i)}})};var s=o.deprecate=function(e,t){n.isObject(e)&&(e=e.prev+" is going to be removed in the future. Please use "+e.next+" instead."+(e.url?" See: "+e.url:"")),void 0!==t&&t||s._cache[e]||(s._warn("Deprecation warning: "+e),s._cache[e]=!0)};s._console="undefined"!=typeof console?console:{},s._warn=function(){var e=s._console.warn||s._console.log||function(){};return e.apply(s._console,arguments)},s._cache={},o._triggerMethod=function(){function e(e,t,n){return n.toUpperCase()}var t=/(^|:)(\w)/gi;return function(r,i,o){var s=arguments.length<3;s&&(o=i,i=o[0]);var a,u="on"+i.replace(t,e),c=r[u];return n.isFunction(c)&&(a=c.apply(r,s?n.rest(o):o)),n.isFunction(r.trigger)&&(s+o.length>1?r.trigger.apply(r,s?o:[i].concat(n.drop(o,0))):r.trigger(i)),a}}(),o.triggerMethod=function(e){return o._triggerMethod(this,arguments)},o.triggerMethodOn=function(e){var t=n.isFunction(e.triggerMethod)?e.triggerMethod:o.triggerMethod;return t.apply(e,n.rest(arguments))},o.MonitorDOMRefresh=function(e){function t(){e._isShown=!0,r()}function n(){e._isRendered=!0,r()}function r(){e._isShown&&e._isRendered&&o.isNodeAttached(e.el)&&o.triggerMethodOn(e,"dom:refresh",e)}e._isDomRefreshMonitored||(e._isDomRefreshMonitored=!0,e.on({show:t,render:n}))},function(e){function t(t,r,i,o){var s=o.split(/\s+/);n.each(s,function(n){var o=t[n];if(!o)throw new e.Error('Method "'+n+'" was configured as an event handler, but does not exist.');t.listenTo(r,i,o)})}function r(e,t,n,r){e.listenTo(t,n,r)}function i(e,t,r,i){var o=i.split(/\s+/);n.each(o,function(n){var i=e[n];e.stopListening(t,r,i)})}function o(e,t,n,r){e.stopListening(t,n,r)}function s(t,r,i,o,s){if(r&&i){if(!n.isObject(i))throw new e.Error({message:"Bindings must be an object or function.",url:"marionette.functions.html#marionettebindentityevents"});i=e._getValue(i,t),n.each(i,function(e,i){n.isFunction(e)?o(t,r,i,e):s(t,r,i,e)})}}e.bindEntityEvents=function(e,n,i){s(e,n,i,r,t)},e.unbindEntityEvents=function(e,t,n){s(e,t,n,o,i)},e.proxyBindEntityEvents=function(t,n){return e.bindEntityEvents(this,t,n)},e.proxyUnbindEntityEvents=function(t,n){return e.unbindEntityEvents(this,t,n)}}(o);var a=["description","fileName","lineNumber","name","message","number"];return o.Error=o.extend.call(Error,{urlRoot:"http://marionettejs.com/docs/v"+o.VERSION+"/",constructor:function(e,t){n.isObject(e)?(t=e,e=t.message):t||(t={});var r=Error.call(this,e);n.extend(this,n.pick(r,a),n.pick(t,a)),this.captureStackTrace(),t.url&&(this.url=this.urlRoot+t.url)},captureStackTrace:function(){Error.captureStackTrace&&Error.captureStackTrace(this,o.Error)},toString:function(){return this.name+": "+this.message+(this.url?" See: "+this.url:"")}}),o.Error.extend=o.extend,o.Callbacks=function(){this._deferred=o.Deferred(),this._callbacks=[]},n.extend(o.Callbacks.prototype,{add:function(e,t){var r=n.result(this._deferred,"promise");this._callbacks.push({cb:e,ctx:t}),r.then(function(n){t&&(n.context=t),e.call(n.context,n.options)})},run:function(e,t){this._deferred.resolve({options:e,context:t})},reset:function(){var e=this._callbacks;this._deferred=o.Deferred(),this._callbacks=[],n.each(e,function(e){this.add(e.cb,e.ctx)},this)}}),o.Controller=function(e){this.options=e||{},n.isFunction(this.initialize)&&this.initialize(this.options)},o.Controller.extend=o.extend,n.extend(o.Controller.prototype,t.Events,{destroy:function(){return o._triggerMethod(this,"before:destroy",arguments),o._triggerMethod(this,"destroy",arguments),this.stopListening(),this.off(),this},triggerMethod:o.triggerMethod,mergeOptions:o.mergeOptions,getOption:o.proxyGetOption}),o.Object=function(e){this.options=n.extend({},n.result(this,"options"),e),this.initialize.apply(this,arguments)},o.Object.extend=o.extend,n.extend(o.Object.prototype,t.Events,{initialize:function(){},destroy:function(e){return e=e||{},this.triggerMethod("before:destroy",e),this.triggerMethod("destroy",e),this.stopListening(),this},triggerMethod:o.triggerMethod,mergeOptions:o.mergeOptions,getOption:o.proxyGetOption,bindEntityEvents:o.proxyBindEntityEvents,unbindEntityEvents:o.proxyUnbindEntityEvents}),o.Region=o.Object.extend({constructor:function(e){if(this.options=e||{},this.el=this.getOption("el"),this.el=this.el instanceof t.$?this.el[0]:this.el,!this.el)throw new o.Error({name:"NoElError",message:'An "el" must be specified for a region.'});this.$el=this.getEl(this.el),o.Object.call(this,e)},show:function(e,t){if(this._ensureElement()){this._ensureViewIsIntact(e),o.MonitorDOMRefresh(e);var r=t||{},i=e!==this.currentView,s=!!r.preventDestroy,a=!!r.forceShow,u=!!this.currentView,c=i&&!s,l=i||a;if(u&&this.triggerMethod("before:swapOut",this.currentView,this,t),this.currentView&&i&&delete this.currentView._parent,c?this.empty():u&&l&&this.currentView.off("destroy",this.empty,this),l){e.once("destroy",this.empty,this),e._parent=this,this._renderView(e),u&&this.triggerMethod("before:swap",e,this,t),this.triggerMethod("before:show",e,this,t),o.triggerMethodOn(e,"before:show",e,this,t),u&&this.triggerMethod("swapOut",this.currentView,this,t);var h=o.isNodeAttached(this.el),f=[],p=n.extend({triggerBeforeAttach:this.triggerBeforeAttach,triggerAttach:this.triggerAttach},r);return h&&p.triggerBeforeAttach&&(f=this._displayedViews(e),this._triggerAttach(f,"before:")),this.attachHtml(e),this.currentView=e,h&&p.triggerAttach&&(f=this._displayedViews(e),this._triggerAttach(f)),u&&this.triggerMethod("swap",e,this,t),this.triggerMethod("show",e,this,t),o.triggerMethodOn(e,"show",e,this,t),this}return this}},triggerBeforeAttach:!0,triggerAttach:!0,_triggerAttach:function(e,t){var r=(t||"")+"attach";n.each(e,function(e){o.triggerMethodOn(e,r,e,this)},this)},_displayedViews:function(e){return n.union([e],n.result(e,"_getNestedViews")||[])},_renderView:function(e){e.supportsRenderLifecycle||o.triggerMethodOn(e,"before:render",e),e.render(),e.supportsRenderLifecycle||o.triggerMethodOn(e,"render",e)},_ensureElement:function(){if(n.isObject(this.el)||(this.$el=this.getEl(this.el),this.el=this.$el[0]),!this.$el||0===this.$el.length){if(this.getOption("allowMissingEl"))return!1;throw new o.Error('An "el" '+this.$el.selector+" must exist in DOM")}return!0},_ensureViewIsIntact:function(e){if(!e)throw new o.Error({name:"ViewNotValid",message:"The view passed is undefined and therefore invalid. You must pass a view instance to show."});if(e.isDestroyed)throw new o.Error({name:"ViewDestroyedError",message:'View (cid: "'+e.cid+'") has already been destroyed and cannot be used.'})},getEl:function(e){return t.$(e,o._getValue(this.options.parentEl,this))},attachHtml:function(e){this.$el.contents().detach(),this.el.appendChild(e.el)},empty:function(e){var t=this.currentView,n=e||{},r=!!n.preventDestroy;return t?(t.off("destroy",this.empty,this),this.triggerMethod("before:empty",t),r||this._destroyView(),this.triggerMethod("empty",t),delete this.currentView,r&&this.$el.contents().detach(),this):this},_destroyView:function(){var e=this.currentView;e.isDestroyed||(e.supportsDestroyLifecycle||o.triggerMethodOn(e,"before:destroy",e),e.destroy?e.destroy():(e.remove(),e.isDestroyed=!0),e.supportsDestroyLifecycle||o.triggerMethodOn(e,"destroy",e))},attachView:function(e){return this.currentView&&delete this.currentView._parent,e._parent=this,this.currentView=e,this},hasView:function(){return!!this.currentView},reset:function(){return this.empty(),this.$el&&(this.el=this.$el.selector),delete this.$el,this}},{buildRegion:function(e,t){if(n.isString(e))return this._buildRegionFromSelector(e,t);if(e.selector||e.el||e.regionClass)return this._buildRegionFromObject(e,t);if(n.isFunction(e))return this._buildRegionFromRegionClass(e);throw new o.Error({message:"Improper region configuration type.",url:"marionette.region.html#region-configuration-types"})},_buildRegionFromSelector:function(e,t){return new t({el:e})},_buildRegionFromObject:function(e,t){var r=e.regionClass||t,i=n.omit(e,"selector","regionClass");return e.selector&&!i.el&&(i.el=e.selector),new r(i)},_buildRegionFromRegionClass:function(e){return new e}}),o.RegionManager=o.Controller.extend({constructor:function(e){this._regions={},this.length=0,o.Controller.call(this,e),this.addRegions(this.getOption("regions"))},addRegions:function(e,t){return e=o._getValue(e,this,arguments),n.reduce(e,function(e,r,i){return n.isString(r)&&(r={selector:r}),r.selector&&(r=n.defaults({},r,t)),e[i]=this.addRegion(i,r),e},{},this)},addRegion:function(e,t){var n;return n=t instanceof o.Region?t:o.Region.buildRegion(t,o.Region),this.triggerMethod("before:add:region",e,n),n._parent=this,this._store(e,n),this.triggerMethod("add:region",e,n),n},get:function(e){return this._regions[e]},getRegions:function(){return n.clone(this._regions)},removeRegion:function(e){var t=this._regions[e];return this._remove(e,t),t},removeRegions:function(){var e=this.getRegions();return n.each(this._regions,function(e,t){this._remove(t,e)},this),e},emptyRegions:function(){var e=this.getRegions();return n.invoke(e,"empty"),e},destroy:function(){return this.removeRegions(),o.Controller.prototype.destroy.apply(this,arguments)},_store:function(e,t){this._regions[e]||this.length++,this._regions[e]=t},_remove:function(e,t){this.triggerMethod("before:remove:region",e,t),t.empty(),t.stopListening(),delete t._parent,delete this._regions[e],this.length--,this.triggerMethod("remove:region",e,t)}}),o.actAsCollection(o.RegionManager.prototype,"_regions"),o.TemplateCache=function(e){this.templateId=e},n.extend(o.TemplateCache,{templateCaches:{},get:function(e,t){var n=this.templateCaches[e];return n||(n=new o.TemplateCache(e),this.templateCaches[e]=n),n.load(t)},clear:function(){var e,t=n.toArray(arguments),r=t.length;if(r>0)for(e=0;r>e;e++)delete this.templateCaches[t[e]];else this.templateCaches={}}}),n.extend(o.TemplateCache.prototype,{load:function(e){if(this.compiledTemplate)return this.compiledTemplate;var t=this.loadTemplate(this.templateId,e);return this.compiledTemplate=this.compileTemplate(t,e),this.compiledTemplate},loadTemplate:function(e,n){var r=t.$(e);if(!r.length)throw new o.Error({name:"NoTemplateError",message:'Could not find template: "'+e+'"'});return r.html()},compileTemplate:function(e,t){return n.template(e,t)}}),o.Renderer={render:function(e,t){if(!e)throw new o.Error({name:"TemplateNotFoundError",message:"Cannot render the template since its false, null or undefined."});var r=n.isFunction(e)?e:o.TemplateCache.get(e);return r(t)}},o.View=t.View.extend({isDestroyed:!1,supportsRenderLifecycle:!0,supportsDestroyLifecycle:!0,constructor:function(e){this.render=n.bind(this.render,this),e=o._getValue(e,this),this.options=n.extend({},n.result(this,"options"),e),this._behaviors=o.Behaviors(this),t.View.call(this,this.options),o.MonitorDOMRefresh(this)},getTemplate:function(){return this.getOption("template")},serializeModel:function(e){return e.toJSON.apply(e,n.rest(arguments))},mixinTemplateHelpers:function(e){e=e||{};var t=this.getOption("templateHelpers");return t=o._getValue(t,this),n.extend(e,t)},normalizeUIKeys:function(e){var t=n.result(this,"_uiBindings");return o.normalizeUIKeys(e,t||n.result(this,"ui"))},normalizeUIValues:function(e,t){var r=n.result(this,"ui"),i=n.result(this,"_uiBindings");return o.normalizeUIValues(e,i||r,t)},configureTriggers:function(){if(this.triggers){var e=this.normalizeUIKeys(n.result(this,"triggers"));return n.reduce(e,function(e,t,n){return e[n]=this._buildViewTrigger(t),e},{},this)}},delegateEvents:function(e){return this._delegateDOMEvents(e),this.bindEntityEvents(this.model,this.getOption("modelEvents")),this.bindEntityEvents(this.collection,this.getOption("collectionEvents")),n.each(this._behaviors,function(e){e.bindEntityEvents(this.model,e.getOption("modelEvents")),e.bindEntityEvents(this.collection,e.getOption("collectionEvents"))},this),this},_delegateDOMEvents:function(e){var r=o._getValue(e||this.events,this);r=this.normalizeUIKeys(r),n.isUndefined(e)&&(this.events=r);var i={},s=n.result(this,"behaviorEvents")||{},a=this.configureTriggers(),u=n.result(this,"behaviorTriggers")||{};n.extend(i,s,r,a,u),t.View.prototype.delegateEvents.call(this,i)},undelegateEvents:function(){return t.View.prototype.undelegateEvents.apply(this,arguments),this.unbindEntityEvents(this.model,this.getOption("modelEvents")),this.unbindEntityEvents(this.collection,this.getOption("collectionEvents")),n.each(this._behaviors,function(e){e.unbindEntityEvents(this.model,e.getOption("modelEvents")),e.unbindEntityEvents(this.collection,e.getOption("collectionEvents"))},this),this},_ensureViewIsIntact:function(){if(this.isDestroyed)throw new o.Error({name:"ViewDestroyedError",message:'View (cid: "'+this.cid+'") has already been destroyed and cannot be used.'})},destroy:function(){if(this.isDestroyed)return this;var e=n.toArray(arguments);return this.triggerMethod.apply(this,["before:destroy"].concat(e)),this.isDestroyed=!0,this.triggerMethod.apply(this,["destroy"].concat(e)),this.unbindUIElements(),this.isRendered=!1,this.remove(),n.invoke(this._behaviors,"destroy",e),this},bindUIElements:function(){this._bindUIElements(),n.invoke(this._behaviors,this._bindUIElements)},_bindUIElements:function(){if(this.ui){this._uiBindings||(this._uiBindings=this.ui);var e=n.result(this,"_uiBindings");this.ui={},n.each(e,function(e,t){this.ui[t]=this.$(e)},this)}},unbindUIElements:function(){this._unbindUIElements(),n.invoke(this._behaviors,this._unbindUIElements)},_unbindUIElements:function(){this.ui&&this._uiBindings&&(n.each(this.ui,function(e,t){delete this.ui[t]},this),this.ui=this._uiBindings,delete this._uiBindings)},_buildViewTrigger:function(e){var t=n.defaults({},e,{preventDefault:!0,stopPropagation:!0}),r=n.isObject(e)?t.event:e;return function(e){e&&(e.preventDefault&&t.preventDefault&&e.preventDefault(),e.stopPropagation&&t.stopPropagation&&e.stopPropagation());var n={view:this,model:this.model,collection:this.collection};this.triggerMethod(r,n)}},setElement:function(){var e=t.View.prototype.setElement.apply(this,arguments);return n.invoke(this._behaviors,"proxyViewProperties",this),e},triggerMethod:function(){var e=o._triggerMethod(this,arguments);return this._triggerEventOnBehaviors(arguments),this._triggerEventOnParentLayout(arguments[0],n.rest(arguments)),e},_triggerEventOnBehaviors:function(e){for(var t=o._triggerMethod,n=this._behaviors,r=0,i=n&&n.length;i>r;r++)t(n[r],e)},_triggerEventOnParentLayout:function(e,t){var r=this._parentLayoutView();if(r){var i=o.getOption(r,"childViewEventPrefix"),s=i+":"+e,a=[this].concat(t);o._triggerMethod(r,s,a);var u=o.getOption(r,"childEvents");u=o._getValue(u,r);var c=r.normalizeMethods(u);c&&n.isFunction(c[e])&&c[e].apply(r,a)}},_getImmediateChildren:function(){return[]},_getNestedViews:function(){var e=this._getImmediateChildren();return e.length?n.reduce(e,function(e,t){return t._getNestedViews?e.concat(t._getNestedViews()):e},e):e},_parentLayoutView:function(){for(var e=this._parent;e;){if(e instanceof o.LayoutView)return e;e=e._parent}},normalizeMethods:o.normalizeMethods,mergeOptions:o.mergeOptions,getOption:o.proxyGetOption,bindEntityEvents:o.proxyBindEntityEvents,unbindEntityEvents:o.proxyUnbindEntityEvents}),o.ItemView=o.View.extend({constructor:function(){o.View.apply(this,arguments)},serializeData:function(){if(!this.model&&!this.collection)return{};var e=[this.model||this.collection];return arguments.length&&e.push.apply(e,arguments),this.model?this.serializeModel.apply(this,e):{items:this.serializeCollection.apply(this,e)}},serializeCollection:function(e){return e.toJSON.apply(e,n.rest(arguments))},render:function(){return this._ensureViewIsIntact(),this.triggerMethod("before:render",this),this._renderTemplate(),this.isRendered=!0,this.bindUIElements(),this.triggerMethod("render",this),this},_renderTemplate:function(){var e=this.getTemplate();if(e!==!1){if(!e)throw new o.Error({name:"UndefinedTemplateError",message:"Cannot render the template since it is null or undefined."});var t=this.mixinTemplateHelpers(this.serializeData()),n=o.Renderer.render(e,t,this);return this.attachElContent(n),this}},attachElContent:function(e){return this.$el.html(e),this}}),o.CollectionView=o.View.extend({childViewEventPrefix:"childview",sort:!0,constructor:function(e){this.once("render",this._initialEvents),this._initChildViewStorage(),o.View.apply(this,arguments),this.on({"before:show":this._onBeforeShowCalled,show:this._onShowCalled,"before:attach":this._onBeforeAttachCalled,attach:this._onAttachCalled}),this.initRenderBuffer()},initRenderBuffer:function(){this._bufferedChildren=[]},startBuffering:function(){this.initRenderBuffer(),this.isBuffering=!0},endBuffering:function(){var e,t=this._isShown&&o.isNodeAttached(this.el);this.isBuffering=!1,this._isShown&&this._triggerMethodMany(this._bufferedChildren,this,"before:show"),t&&this._triggerBeforeAttach&&(e=this._getNestedViews(),this._triggerMethodMany(e,this,"before:attach")),this.attachBuffer(this,this._createBuffer()),t&&this._triggerAttach&&(e=this._getNestedViews(),this._triggerMethodMany(e,this,"attach")),this._isShown&&this._triggerMethodMany(this._bufferedChildren,this,"show"),this.initRenderBuffer()},_triggerMethodMany:function(e,t,r){var i=n.drop(arguments,3);n.each(e,function(e){o.triggerMethodOn.apply(e,[e,r,e,t].concat(i))})},_initialEvents:function(){this.collection&&(this.listenTo(this.collection,"add",this._onCollectionAdd),this.listenTo(this.collection,"remove",this._onCollectionRemove),this.listenTo(this.collection,"reset",this.render),this.getOption("sort")&&this.listenTo(this.collection,"sort",this._sortViews))},_onCollectionAdd:function(e,t,r){var i=void 0!==r.at&&(r.index||t.indexOf(e));if((this.getOption("filter")||i===!1)&&(i=n.indexOf(this._filteredSortedModels(i),e)),this._shouldAddChild(e,i)){this.destroyEmptyView();var o=this.getChildView(e);this.addChild(e,o,i)}},_onCollectionRemove:function(e){var t=this.children.findByModel(e);this.removeChildView(t),this.checkEmpty()},_onBeforeShowCalled:function(){this._triggerBeforeAttach=this._triggerAttach=!1,this.children.each(function(e){o.triggerMethodOn(e,"before:show",e)})},_onShowCalled:function(){this.children.each(function(e){o.triggerMethodOn(e,"show",e)})},_onBeforeAttachCalled:function(){this._triggerBeforeAttach=!0},_onAttachCalled:function(){this._triggerAttach=!0},render:function(){return this._ensureViewIsIntact(),this.triggerMethod("before:render",this),this._renderChildren(),this.isRendered=!0,this.triggerMethod("render",this),this},reorder:function(){var e=this.children,t=this._filteredSortedModels(),r=n.some(t,function(t){return!e.findByModel(t)});if(r)this.render();else{var i=n.map(t,function(t,n){var r=e.findByModel(t);return r._index=n,r.el}),o=e.filter(function(e){return!n.contains(i,e.el)});this.triggerMethod("before:reorder"),this._appendReorderedChildren(i),n.each(o,this.removeChildView,this),this.checkEmpty(),this.triggerMethod("reorder")}},resortView:function(){o.getOption(this,"reorderOnSort")?this.reorder():this.render()},_sortViews:function(){var e=this._filteredSortedModels(),t=n.find(e,function(e,t){var n=this.children.findByModel(e);return!n||n._index!==t},this);t&&this.resortView()},_emptyViewIndex:-1,_appendReorderedChildren:function(e){this.$el.append(e)},_renderChildren:function(){this.destroyEmptyView(),this.destroyChildren({checkEmpty:!1}),this.isEmpty(this.collection)?this.showEmptyView():(this.triggerMethod("before:render:collection",this),this.startBuffering(),this.showCollection(),this.endBuffering(),this.triggerMethod("render:collection",this),this.children.isEmpty()&&this.getOption("filter")&&this.showEmptyView())},showCollection:function(){var e,t=this._filteredSortedModels();n.each(t,function(t,n){e=this.getChildView(t),this.addChild(t,e,n)},this)},_filteredSortedModels:function(e){var t=this.getViewComparator(),r=this.collection.models;if(e=Math.min(Math.max(e,0),r.length-1),t){var i;e&&(i=r[e],r=r.slice(0,e).concat(r.slice(e+1))),r=this._sortModelsBy(r,t),i&&r.splice(e,0,i)}return this.getOption("filter")&&(r=n.filter(r,function(e,t){return this._shouldAddChild(e,t)},this)),r},_sortModelsBy:function(e,t){return"string"==typeof t?n.sortBy(e,function(e){return e.get(t)},this):1===t.length?n.sortBy(e,t,this):e.sort(n.bind(t,this))},showEmptyView:function(){var e=this.getEmptyView();if(e&&!this._showingEmptyView){this.triggerMethod("before:render:empty"),this._showingEmptyView=!0;var n=new t.Model;this.addEmptyView(n,e),this.triggerMethod("render:empty")}},destroyEmptyView:function(){this._showingEmptyView&&(this.triggerMethod("before:remove:empty"),this.destroyChildren(),delete this._showingEmptyView,this.triggerMethod("remove:empty"))},getEmptyView:function(){return this.getOption("emptyView")},addEmptyView:function(e,t){var r,i=this._isShown&&!this.isBuffering&&o.isNodeAttached(this.el),s=this.getOption("emptyViewOptions")||this.getOption("childViewOptions");n.isFunction(s)&&(s=s.call(this,e,this._emptyViewIndex));var a=this.buildChildView(e,t,s);a._parent=this,this.proxyChildEvents(a),a.once("render",function(){this._isShown&&o.triggerMethodOn(a,"before:show",a),i&&this._triggerBeforeAttach&&(r=this._getViewAndNested(a),this._triggerMethodMany(r,this,"before:attach"))},this),this.children.add(a),this.renderChildView(a,this._emptyViewIndex),i&&this._triggerAttach&&(r=this._getViewAndNested(a),this._triggerMethodMany(r,this,"attach")),this._isShown&&o.triggerMethodOn(a,"show",a)},getChildView:function(e){var t=this.getOption("childView");if(!t)throw new o.Error({name:"NoChildViewError",message:'A "childView" must be specified'});return t},addChild:function(e,t,n){var r=this.getOption("childViewOptions");r=o._getValue(r,this,[e,n]);var i=this.buildChildView(e,t,r);return this._updateIndices(i,!0,n),this.triggerMethod("before:add:child",i),this._addChildView(i,n),this.triggerMethod("add:child",i),i._parent=this,i},_updateIndices:function(e,t,n){this.getOption("sort")&&(t&&(e._index=n),this.children.each(function(n){n._index>=e._index&&(n._index+=t?1:-1)}))},_addChildView:function(e,t){var n,r=this._isShown&&!this.isBuffering&&o.isNodeAttached(this.el);this.proxyChildEvents(e),e.once("render",function(){this._isShown&&!this.isBuffering&&o.triggerMethodOn(e,"before:show",e),r&&this._triggerBeforeAttach&&(n=this._getViewAndNested(e),this._triggerMethodMany(n,this,"before:attach"))},this),this.children.add(e),this.renderChildView(e,t),r&&this._triggerAttach&&(n=this._getViewAndNested(e),this._triggerMethodMany(n,this,"attach")),this._isShown&&!this.isBuffering&&o.triggerMethodOn(e,"show",e)},renderChildView:function(e,t){return e.supportsRenderLifecycle||o.triggerMethodOn(e,"before:render",e),e.render(),e.supportsRenderLifecycle||o.triggerMethodOn(e,"render",e),this.attachHtml(this,e,t),e},buildChildView:function(e,t,r){var i=n.extend({model:e},r),s=new t(i);return o.MonitorDOMRefresh(s),s},removeChildView:function(e){return e?(this.triggerMethod("before:remove:child",e),e.supportsDestroyLifecycle||o.triggerMethodOn(e,"before:destroy",e),e.destroy?e.destroy():e.remove(),e.supportsDestroyLifecycle||o.triggerMethodOn(e,"destroy",e),delete e._parent,this.stopListening(e),this.children.remove(e),this.triggerMethod("remove:child",e),this._updateIndices(e,!1),e):e},isEmpty:function(){return!this.collection||0===this.collection.length},checkEmpty:function(){this.isEmpty(this.collection)&&this.showEmptyView()},attachBuffer:function(e,t){e.$el.append(t)},_createBuffer:function(){var e=document.createDocumentFragment();return n.each(this._bufferedChildren,function(t){e.appendChild(t.el)}),e},attachHtml:function(e,t,n){e.isBuffering?e._bufferedChildren.splice(n,0,t):e._insertBefore(t,n)||e._insertAfter(t)},_insertBefore:function(e,t){var n,r=this.getOption("sort")&&t<this.children.length-1;return r&&(n=this.children.find(function(e){return e._index===t+1})),n?(n.$el.before(e.el),!0):!1},_insertAfter:function(e){this.$el.append(e.el)},_initChildViewStorage:function(){this.children=new t.ChildViewContainer},destroy:function(){return this.isDestroyed?this:(this.triggerMethod("before:destroy:collection"),this.destroyChildren({checkEmpty:!1}),this.triggerMethod("destroy:collection"),o.View.prototype.destroy.apply(this,arguments))},destroyChildren:function(e){var t=e||{},r=!0,i=this.children.map(n.identity);return n.isUndefined(t.checkEmpty)||(r=t.checkEmpty),this.children.each(this.removeChildView,this),r&&this.checkEmpty(),i},_shouldAddChild:function(e,t){var r=this.getOption("filter");return!n.isFunction(r)||r.call(this,e,t,this.collection)},proxyChildEvents:function(e){var t=this.getOption("childViewEventPrefix");this.listenTo(e,"all",function(){var r=n.toArray(arguments),i=r[0],o=this.normalizeMethods(n.result(this,"childEvents"));r[0]=t+":"+i,r.splice(1,0,e),"undefined"!=typeof o&&n.isFunction(o[i])&&o[i].apply(this,r.slice(1)),this.triggerMethod.apply(this,r)})},_getImmediateChildren:function(){return n.values(this.children._views)},_getViewAndNested:function(e){return[e].concat(n.result(e,"_getNestedViews")||[])},getViewComparator:function(){return this.getOption("viewComparator")}}),o.CompositeView=o.CollectionView.extend({constructor:function(){o.CollectionView.apply(this,arguments)},_initialEvents:function(){this.collection&&(this.listenTo(this.collection,"add",this._onCollectionAdd),this.listenTo(this.collection,"remove",this._onCollectionRemove),this.listenTo(this.collection,"reset",this._renderChildren),this.getOption("sort")&&this.listenTo(this.collection,"sort",this._sortViews))},getChildView:function(e){var t=this.getOption("childView")||this.constructor;return t},serializeData:function(){var e={};return this.model&&(e=n.partial(this.serializeModel,this.model).apply(this,arguments)),e},render:function(){return this._ensureViewIsIntact(),this._isRendering=!0,this.resetChildViewContainer(),this.triggerMethod("before:render",this),this._renderTemplate(),this._renderChildren(),this._isRendering=!1,this.isRendered=!0,this.triggerMethod("render",this),this},_renderChildren:function(){(this.isRendered||this._isRendering)&&o.CollectionView.prototype._renderChildren.call(this)},_renderTemplate:function(){var e={};e=this.serializeData(),e=this.mixinTemplateHelpers(e),this.triggerMethod("before:render:template");var t=this.getTemplate(),n=o.Renderer.render(t,e,this);this.attachElContent(n),this.bindUIElements(),this.triggerMethod("render:template")},attachElContent:function(e){return this.$el.html(e),this},attachBuffer:function(e,t){var n=this.getChildViewContainer(e);n.append(t)},_insertAfter:function(e){var t=this.getChildViewContainer(this,e);t.append(e.el)},_appendReorderedChildren:function(e){var t=this.getChildViewContainer(this);t.append(e)},getChildViewContainer:function(e,t){if(e.$childViewContainer)return e.$childViewContainer;var n,r=o.getOption(e,"childViewContainer");if(r){var i=o._getValue(r,e);if(n="@"===i.charAt(0)&&e.ui?e.ui[i.substr(4)]:e.$(i),n.length<=0)throw new o.Error({name:"ChildViewContainerMissingError",message:'The specified "childViewContainer" was not found: '+e.childViewContainer})}else n=e.$el;return e.$childViewContainer=n,n},resetChildViewContainer:function(){this.$childViewContainer&&(this.$childViewContainer=void 0)}}),o.LayoutView=o.ItemView.extend({regionClass:o.Region,options:{destroyImmediate:!1},childViewEventPrefix:"childview",constructor:function(e){e=e||{},this._firstRender=!0,this._initializeRegions(e),o.ItemView.call(this,e)},render:function(){return this._ensureViewIsIntact(),this._firstRender?this._firstRender=!1:this._reInitializeRegions(),o.ItemView.prototype.render.apply(this,arguments)},destroy:function(){return this.isDestroyed?this:(this.getOption("destroyImmediate")===!0&&this.$el.remove(),this.regionManager.destroy(),o.ItemView.prototype.destroy.apply(this,arguments))},showChildView:function(e,t,r){var i=this.getRegion(e);return i.show.apply(i,n.rest(arguments))},getChildView:function(e){return this.getRegion(e).currentView},addRegion:function(e,t){var n={};return n[e]=t,this._buildRegions(n)[e]},addRegions:function(e){return this.regions=n.extend({},this.regions,e),this._buildRegions(e)},removeRegion:function(e){return delete this.regions[e],this.regionManager.removeRegion(e)},getRegion:function(e){return this.regionManager.get(e)},getRegions:function(){return this.regionManager.getRegions()},_buildRegions:function(e){var t={regionClass:this.getOption("regionClass"),parentEl:n.partial(n.result,this,"el")};return this.regionManager.addRegions(e,t)},_initializeRegions:function(e){var t;this._initRegionManager(),t=o._getValue(this.regions,this,[e])||{};var r=this.getOption.call(e,"regions");r=o._getValue(r,this,[e]),n.extend(t,r),t=this.normalizeUIValues(t,["selector","el"]),this.addRegions(t)},_reInitializeRegions:function(){this.regionManager.invoke("reset"); },getRegionManager:function(){return new o.RegionManager},_initRegionManager:function(){this.regionManager=this.getRegionManager(),this.regionManager._parent=this,this.listenTo(this.regionManager,"before:add:region",function(e){this.triggerMethod("before:add:region",e)}),this.listenTo(this.regionManager,"add:region",function(e,t){this[e]=t,this.triggerMethod("add:region",e,t)}),this.listenTo(this.regionManager,"before:remove:region",function(e){this.triggerMethod("before:remove:region",e)}),this.listenTo(this.regionManager,"remove:region",function(e,t){delete this[e],this.triggerMethod("remove:region",e,t)})},_getImmediateChildren:function(){return n.chain(this.regionManager.getRegions()).pluck("currentView").compact().value()}}),o.Behavior=o.Object.extend({constructor:function(e,t){this.view=t,this.defaults=n.result(this,"defaults")||{},this.options=n.extend({},this.defaults,e),this.ui=n.extend({},n.result(t,"ui"),n.result(this,"ui")),o.Object.apply(this,arguments)},$:function(){return this.view.$.apply(this.view,arguments)},destroy:function(){return this.stopListening(),this},proxyViewProperties:function(e){this.$el=e.$el,this.el=e.el}}),o.Behaviors=function(e,t){function n(e,r){return t.isObject(e.behaviors)?(r=n.parseBehaviors(e,r||t.result(e,"behaviors")),n.wrap(e,r,t.keys(s)),r):{}}function r(e,t){this._view=e,this._behaviors=t,this._triggers={}}function i(e){return e._uiBindings||e.ui}var o=/^(\S+)\s*(.*)$/,s={behaviorTriggers:function(e,t){var n=new r(this,t);return n.buildBehaviorTriggers()},behaviorEvents:function(n,r){var s={};return t.each(r,function(n,r){var a={},u=t.clone(t.result(n,"events"))||{};u=e.normalizeUIKeys(u,i(n));var c=0;t.each(u,function(e,i){var s=i.match(o),u=s[1]+"."+[this.cid,r,c++," "].join(""),l=s[2],h=u+l,f=t.isFunction(e)?e:n[e];f&&(a[h]=t.bind(f,n))},this),s=t.extend(s,a)},this),s}};return t.extend(n,{behaviorsLookup:function(){throw new e.Error({message:"You must define where your behaviors are stored.",url:"marionette.behaviors.html#behaviorslookup"})},getBehaviorClass:function(t,r){return t.behaviorClass?t.behaviorClass:e._getValue(n.behaviorsLookup,this,[t,r])[r]},parseBehaviors:function(e,r){return t.chain(r).map(function(r,i){var o=n.getBehaviorClass(r,i),s=new o(r,e),a=n.parseBehaviors(e,t.result(s,"behaviors"));return[s].concat(a)}).flatten().value()},wrap:function(e,n,r){t.each(r,function(r){e[r]=t.partial(s[r],e[r],n)})}}),t.extend(r.prototype,{buildBehaviorTriggers:function(){return t.each(this._behaviors,this._buildTriggerHandlersForBehavior,this),this._triggers},_buildTriggerHandlersForBehavior:function(n,r){var o=t.clone(t.result(n,"triggers"))||{};o=e.normalizeUIKeys(o,i(n)),t.each(o,t.bind(this._setHandlerForBehavior,this,n,r))},_setHandlerForBehavior:function(e,t,n,r){var i=r.replace(/^\S+/,function(e){return e+".behaviortriggers"+t});this._triggers[i]=this._view._buildViewTrigger(n)}}),n}(o,n),o.AppRouter=t.Router.extend({constructor:function(e){this.options=e||{},t.Router.apply(this,arguments);var n=this.getOption("appRoutes"),r=this._getController();this.processAppRoutes(r,n),this.on("route",this._processOnRoute,this)},appRoute:function(e,t){var n=this._getController();this._addAppRoute(n,e,t)},_processOnRoute:function(e,t){if(n.isFunction(this.onRoute)){var r=n.invert(this.getOption("appRoutes"))[e];this.onRoute(e,r,t)}},processAppRoutes:function(e,t){if(t){var r=n.keys(t).reverse();n.each(r,function(n){this._addAppRoute(e,n,t[n])},this)}},_getController:function(){return this.getOption("controller")},_addAppRoute:function(e,t,r){var i=e[r];if(!i)throw new o.Error('Method "'+r+'" was not found on the controller');this.route(t,r,n.bind(i,e))},mergeOptions:o.mergeOptions,getOption:o.proxyGetOption,triggerMethod:o.triggerMethod,bindEntityEvents:o.proxyBindEntityEvents,unbindEntityEvents:o.proxyUnbindEntityEvents}),o.Application=o.Object.extend({constructor:function(e){this._initializeRegions(e),this._initCallbacks=new o.Callbacks,this.submodules={},n.extend(this,e),this._initChannel(),o.Object.apply(this,arguments)},execute:function(){this.commands.execute.apply(this.commands,arguments)},request:function(){return this.reqres.request.apply(this.reqres,arguments)},addInitializer:function(e){this._initCallbacks.add(e)},start:function(e){this.triggerMethod("before:start",e),this._initCallbacks.run(e,this),this.triggerMethod("start",e)},addRegions:function(e){return this._regionManager.addRegions(e)},emptyRegions:function(){return this._regionManager.emptyRegions()},removeRegion:function(e){return this._regionManager.removeRegion(e)},getRegion:function(e){return this._regionManager.get(e)},getRegions:function(){return this._regionManager.getRegions()},module:function(e,t){var r=o.Module.getClass(t),i=n.toArray(arguments);return i.unshift(this),r.create.apply(r,i)},getRegionManager:function(){return new o.RegionManager},_initializeRegions:function(e){var t=n.isFunction(this.regions)?this.regions(e):this.regions||{};this._initRegionManager();var r=o.getOption(e,"regions");return n.isFunction(r)&&(r=r.call(this,e)),n.extend(t,r),this.addRegions(t),this},_initRegionManager:function(){this._regionManager=this.getRegionManager(),this._regionManager._parent=this,this.listenTo(this._regionManager,"before:add:region",function(){o._triggerMethod(this,"before:add:region",arguments)}),this.listenTo(this._regionManager,"add:region",function(e,t){this[e]=t,o._triggerMethod(this,"add:region",arguments)}),this.listenTo(this._regionManager,"before:remove:region",function(){o._triggerMethod(this,"before:remove:region",arguments)}),this.listenTo(this._regionManager,"remove:region",function(e){delete this[e],o._triggerMethod(this,"remove:region",arguments)})},_initChannel:function(){this.channelName=n.result(this,"channelName")||"global",this.channel=n.result(this,"channel")||t.Wreqr.radio.channel(this.channelName),this.vent=n.result(this,"vent")||this.channel.vent,this.commands=n.result(this,"commands")||this.channel.commands,this.reqres=n.result(this,"reqres")||this.channel.reqres}}),o.Module=function(e,t,r){this.moduleName=e,this.options=n.extend({},this.options,r),this.initialize=r.initialize||this.initialize,this.submodules={},this._setupInitializersAndFinalizers(),this.app=t,n.isFunction(this.initialize)&&this.initialize(e,t,this.options)},o.Module.extend=o.extend,n.extend(o.Module.prototype,t.Events,{startWithParent:!0,initialize:function(){},addInitializer:function(e){this._initializerCallbacks.add(e)},addFinalizer:function(e){this._finalizerCallbacks.add(e)},start:function(e){this._isInitialized||(n.each(this.submodules,function(t){t.startWithParent&&t.start(e)}),this.triggerMethod("before:start",e),this._initializerCallbacks.run(e,this),this._isInitialized=!0,this.triggerMethod("start",e))},stop:function(){this._isInitialized&&(this._isInitialized=!1,this.triggerMethod("before:stop"),n.invoke(this.submodules,"stop"),this._finalizerCallbacks.run(void 0,this),this._initializerCallbacks.reset(),this._finalizerCallbacks.reset(),this.triggerMethod("stop"))},addDefinition:function(e,t){this._runModuleDefinition(e,t)},_runModuleDefinition:function(e,r){if(e){var i=n.flatten([this,this.app,t,o,t.$,n,r]);e.apply(this,i)}},_setupInitializersAndFinalizers:function(){this._initializerCallbacks=new o.Callbacks,this._finalizerCallbacks=new o.Callbacks},triggerMethod:o.triggerMethod}),n.extend(o.Module,{create:function(e,t,r){var i=e,o=n.drop(arguments,3);t=t.split(".");var s=t.length,a=[];return a[s-1]=r,n.each(t,function(t,n){var s=i;i=this._getModule(s,t,e,r),this._addModuleDefinition(s,i,a[n],o)},this),i},_getModule:function(e,t,r,i,o){var s=n.extend({},i),a=this.getClass(i),u=e[t];return u||(u=new a(t,r,s),e[t]=u,e.submodules[t]=u),u},getClass:function(e){var t=o.Module;return e?e.prototype instanceof t?e:e.moduleClass||t:t},_addModuleDefinition:function(e,t,n,r){var i=this._getDefine(n),o=this._getStartWithParent(n,t);i&&t.addDefinition(i,r),this._addStartWithParent(e,t,o)},_getStartWithParent:function(e,t){var r;return n.isFunction(e)&&e.prototype instanceof o.Module?(r=t.constructor.prototype.startWithParent,n.isUndefined(r)?!0:r):n.isObject(e)?(r=e.startWithParent,n.isUndefined(r)?!0:r):!0},_getDefine:function(e){return!n.isFunction(e)||e.prototype instanceof o.Module?n.isObject(e)?e.define:null:e},_addStartWithParent:function(e,t,n){t.startWithParent=t.startWithParent&&n,t.startWithParent&&!t.startWithParentIsConfigured&&(t.startWithParentIsConfigured=!0,e.addInitializer(function(e){t.startWithParent&&t.start(e)}))}}),o})},function(e,t,n){var r,i;(function(e,o){(function(){function s(e,t){var n=arguments.length<=2||void 0===arguments[2]?!1:arguments[2];this.obs=e,this.sync=t,this.lazy=n,this.queue=[]}function a(){s.apply(this,arguments)}function u(e){s.call(this,e,!0)}function c(e,t,n){this.context=e,this.method=t,this.args=n}function l(e){this.value=e}function h(){this.id=++se}function f(e,t){return this instanceof f?(h.call(this),void(!t&&q.isFunction(e)||(null!=e?e._isNext:void 0)?(this.valueF=e,this.valueInternal=void 0):(this.valueF=void 0,this.valueInternal=e))):new f(e,t)}function p(e,t){return this instanceof p?void f.call(this,e,t):new p(e,t)}function d(){return this instanceof d?void h.call(this):new d}function g(e){return this instanceof g?(this.error=e,void h.call(this)):new g(e)}function v(e){this.desc=e,this.id=++he,this.initialDesc=this.desc}function m(){var e=arguments.length<=0||void 0===arguments[0]?[]:arguments[0];this.unsubscribe=q.bind(this.unsubscribe,this),this.unsubscribed=!1,this.subscriptions=[],this.starting=[];for(var t,n=0;n<e.length;n++)t=e[n],this.add(t)}function y(e,t){this._subscribe=e,this._handleEvent=t,this.subscribe=q.bind(this.subscribe,this),this.handleEvent=q.bind(this.handleEvent,this),this.pushing=!1,this.ended=!1,this.prevError=void 0,this.unsubSrc=void 0,this.subscriptions=[],this.queue=[]}function b(e,t,n){return this instanceof b?(q.isFunction(e)&&(n=t,t=e,e=c.empty),v.call(this,e),z(t),this.dispatcher=new y(t,n),void fe(this)):new b(e,t,n)}function w(e,t,n){y.call(this,t,n),this.property=e,this.subscribe=q.bind(this.subscribe,this),this.current=ie,this.currentValueRootId=void 0,this.propertyEnded=!1}function x(e,t,n){v.call(this,e),z(t),this.dispatcher=new w(this,t,n),fe(this)}function _(){return this instanceof _?(this.unsubAll=q.bind(this.unsubAll,this),this.subscribeAll=q.bind(this.subscribeAll,this),this.guardedSink=q.bind(this.guardedSink,this),this.sink=void 0,this.subscriptions=[],this.ended=!1,void b.call(this,new S.Desc(S,"Bus",[]),this.subscribeAll)):new _}function E(e){return[e,ce()]}var C=Array.prototype.slice,S={toString:function(){return"Bacon"}};S.version="0.7.84";var k=("undefined"!=typeof e&&null!==e?e:this).Error,O=function(){},T=function(e,t){return e},A=function(e){return e.slice(0)},M=function(e,t){if(!t)throw new k(e)},j=function(e){if((null!=e?e._isObservable:void 0)&&!(null!=e?e._isProperty:void 0))throw new k("Observable is not a Property : "+e)},D=function(e){if(!(null!=e?e._isEventStream:void 0))throw new k("not an EventStream : "+e)},I=function(e){if(!(null!=e?e._isObservable:void 0))throw new k("not an Observable : "+e)},z=function(e){return M("not a function : "+e,q.isFunction(e))},R=function(e){return e instanceof Array},N=function(e){return e&&e._isObservable},P=function(e){if(!R(e))throw new k("not an array : "+e)},V=function(e){return M("no arguments supported",0===e.length)},H=function(e){for(var t=arguments.length,n=1;t>1?t>n:n>t;t>1?n++:n--)for(var r in arguments[n])e[r]=arguments[n][r];return e},B=function(e,t){var n={}.hasOwnProperty,r=function(){};r.prototype=t.prototype,e.prototype=new r;for(var i in t)n.call(t,i)&&(e[i]=t[i]);return e},q={indexOf:function(){return Array.prototype.indexOf?function(e,t){return e.indexOf(t)}:function(e,t){for(var n,r=0;r<e.length;r++)if(n=e[r],t===n)return r;return-1}}(),indexWhere:function(e,t){for(var n,r=0;r<e.length;r++)if(n=e[r],t(n))return r;return-1},head:function(e){return e[0]},always:function(e){return function(){return e}},negate:function(e){return function(t){return!e(t)}},empty:function(e){return 0===e.length},tail:function(e){return e.slice(1,e.length)},filter:function(e,t){for(var n,r=[],i=0;i<t.length;i++)n=t[i],e(n)&&r.push(n);return r},map:function(e,t){return function(){for(var n,r=[],i=0;i<t.length;i++)n=t[i],r.push(e(n));return r}()},each:function(e,t){for(var n in e)if(Object.prototype.hasOwnProperty.call(e,n)){var r=e[n];t(n,r)}},toArray:function(e){return R(e)?e:[e]},contains:function(e,t){return-1!==q.indexOf(e,t)},id:function(e){return e},last:function(e){return e[e.length-1]},all:function(e){for(var t,n=arguments.length<=1||void 0===arguments[1]?q.id:arguments[1],r=0;r<e.length;r++)if(t=e[r],!n(t))return!1;return!0},any:function(e){for(var t,n=arguments.length<=1||void 0===arguments[1]?q.id:arguments[1],r=0;r<e.length;r++)if(t=e[r],n(t))return!0;return!1},without:function(e,t){return q.filter(function(t){return t!==e},t)},remove:function(e,t){var n=q.indexOf(t,e);return n>=0?t.splice(n,1):void 0},fold:function(e,t,n){for(var r,i=0;i<e.length;i++)r=e[i],t=n(t,r);return t},flatMap:function(e,t){return q.fold(t,[],function(t,n){return t.concat(e(n))})},cached:function(e){var t=ie;return function(){return("undefined"!=typeof t&&null!==t?t._isNone:void 0)&&(t=e(),e=void 0),t}},bind:function(e,t){return function(){return e.apply(t,arguments)}},isFunction:function(e){return"function"==typeof e},toString:function(e){var t,n,r,i={}.hasOwnProperty;try{return F++,null==e?"undefined":q.isFunction(e)?"function":R(e)?F>5?"[..]":"["+q.map(q.toString,e).toString()+"]":null!=(null!=e?e.toString:void 0)&&e.toString!==Object.prototype.toString?e.toString():"object"==typeof e?F>5?"{..}":(t=function(){var t=[];for(n in e)i.call(e,n)&&(r=function(){var t;try{return e[n]}catch(t){return t}}(),t.push(q.toString(n)+":"+q.toString(r)));return t}(),"{"+t+"}"):e}finally{F--}}},F=0;S._=q;var L=S.UpdateBarrier=function(){var e,t=[],n={},r=[],i=0,o={},s=function(t){return e?r.push(t):t()},a=function(r,i){if(e){var o=n[r.id];return"undefined"==typeof o||null===o?(o=n[r.id]=[i],t.push(r)):o.push(i)}return i()},u=function(){for(;t.length>0;)c(0,!0);o={}},c=function(e,r){var i=t[e],o=i.id,s=n[o];t.splice(e,1),delete n[o],r&&t.length>0&&l(i);for(var a,u=0;u<s.length;u++)(a=s[u])()},l=function(e){if(!o[e.id]){for(var r,i=e.internalDeps(),s=0;s<i.length;s++)if(r=i[s],l(r),n[r.id]){var a=q.indexOf(t,r);c(a,!1)}o[e.id]=!0}},h=function(t,n,o,s){if(e)return o.apply(n,s);e=t;try{var a=o.apply(n,s);u()}finally{for(e=void 0;i<r.length;){var c=r[i];i++,c()}i=0,r=[]}return a},f=function(){return e?e.id:void 0},p=function(e,t){var n=!1,r=!1,i=function(){return r=!0},o=function(){return n=!0,i()};return i=e.dispatcher.subscribe(function(e){return s(function(){if(!n){var r=t(e);if(r===S.noMore)return o()}})}),r&&i(),o},d=function(){return t.length>0};return{whenDoneWith:a,hasWaiters:d,inTransaction:h,currentEventId:f,wrappedSubscribe:p,afterTransaction:s}}();H(s.prototype,{_isSource:!0,subscribe:function(e){return this.obs.dispatcher.subscribe(e)},toString:function(){return this.obs.toString()},markEnded:function(){return this.ended=!0,!0},consume:function(){return this.lazy?{value:q.always(this.queue[0])}:this.queue[0]},push:function(e){return this.queue=[e],[e]},mayHave:function(){return!0},hasAtLeast:function(){return this.queue.length},flatten:!0}),B(a,s),H(a.prototype,{consume:function(){return this.queue.shift()},push:function(e){return this.queue.push(e)},mayHave:function(e){return!this.ended||this.queue.length>=e},hasAtLeast:function(e){return this.queue.length>=e},flatten:!1}),B(u,s),H(u.prototype,{consume:function(){var e=this.queue;return this.queue=[],{value:function(){return e}}},push:function(e){return this.queue.push(e.value())},hasAtLeast:function(){return!0}}),s.isTrigger=function(e){return(null!=e?e._isSource:void 0)?e.sync:null!=e?e._isEventStream:void 0},s.fromObservable=function(e){return(null!=e?e._isSource:void 0)?e:(null!=e?e._isProperty:void 0)?new s(e,!1):new a(e,!0)},H(c.prototype,{_isDesc:!0,deps:function(){return this.cached||(this.cached=U([this.context].concat(this.args))),this.cached},toString:function(){return q.toString(this.context)+"."+q.toString(this.method)+"("+q.map(q.toString,this.args)+")"}});var $=function(e,t){var n=e||t;if(n&&n._isDesc)return e||t;for(var r=arguments.length,i=Array(r>2?r-2:0),o=2;r>o;o++)i[o-2]=arguments[o];return new c(e,t,i)},W=function(e,t){return t.desc=e,t},U=function(e){return R(e)?q.flatMap(U,e):N(e)?[e]:("undefined"!=typeof e&&null!==e?e._isSource:void 0)?[e.obs]:[]};S.Desc=c,S.Desc.empty=new S.Desc("","",[]);var G=function(e){return function(t){for(var n=arguments.length,r=Array(n>1?n-1:0),i=1;n>i;i++)r[i-1]=arguments[i];if("object"==typeof t&&r.length){var o=t,s=r[0];t=function(){return o[s].apply(o,arguments)},r=r.slice(1)}return e.apply(void 0,[t].concat(r))}},J=function(e){return e=Array.prototype.slice.call(e),Z.apply(void 0,e)},X=function(e,t){return function(){for(var n=arguments.length,r=Array(n),i=0;n>i;i++)r[i]=arguments[i];return e.apply(void 0,t.concat(r))}},Y=function(e){return function(t){return function(n){if("undefined"!=typeof n&&null!==n){var r=n[t];return q.isFunction(r)?r.apply(n,e):r}}}},K=function(e,t){var n=e.slice(1).split("."),r=q.map(Y(t),n);return function(e){for(var t,n=0;n<r.length;n++)t=r[n],e=t(e);return e}},Q=function(e){return"string"==typeof e&&e.length>1&&"."===e.charAt(0)},Z=G(function(e){for(var t=arguments.length,n=Array(t>1?t-1:0),r=1;t>r;r++)n[r-1]=arguments[r];return q.isFunction(e)?n.length?X(e,n):e:Q(e)?K(e,n):q.always(e)}),ee=function(e,t){return Z.apply(void 0,[e].concat(t))},te=function(e,t,n,r){if("undefined"!=typeof t&&null!==t?t._isProperty:void 0){var i=t.sampledBy(e,function(e,t){return[e,t]});return r.call(i,function(e){var t=e[0];e[1];return t}).map(function(e){var t=(e[0],e[1]);return t})}return t=ee(t,n),r.call(e,t)},ne=function(e){if(q.isFunction(e))return e;if(Q(e)){var t=re(e);