(function(){var t=function(t,e){return function(){return t.apply(e,arguments)}},e=function(t,e){function i(){this.constructor=t}for(var o in e)n.call(e,o)&&(t[o]=e[o]);return i.prototype=e.prototype,t.prototype=new i,t.__super__=e.prototype,t},n={}.hasOwnProperty,i=[].slice;!function(t,e){var n,i,o;"function"==typeof define&&define.amd?define(["backbone","underscore","jquery"],function(n,i,o){return e(t,n,i,o)}):"object"==typeof exports?(i=require("backbone"),o=require("underscore"),n=require("jquery"),module.exports=e(t,i,o,n)):t.Vigor=e(t,t.Backbone,t._,t.$)}(this,function(n,o,r,s){var a,l,c,u,p,d,h,f,g,_,m,v,I,y,C,N,O;return N=o.Vigor=n.Vigor||{},N.extend=N.extend||o.Model.extend,c=function(n){function o(){return this._triggerUpdates=t(this._triggerUpdates,this),this._onRemove=t(this._onRemove,this),this._onChange=t(this._onChange,this),this._onAdd=t(this._onAdd,this),o.__super__.constructor.apply(this,arguments)}return e(o,n),o.prototype.THROTTLED_DIFF="throttled_diff",o.prototype.THROTTLED_ADD="throttled_add",o.prototype.THROTTLED_CHANGE="throttled_change",o.prototype.THROTTLED_REMOVE="throttled_remove",o.prototype._throttledAddedModels=void 0,o.prototype._throttledChangedModels=void 0,o.prototype._throttledRemovedModels=void 0,o.prototype._throttledTriggerUpdates=void 0,o.prototype._throttleDelay=50,o.prototype.initialize=function(){return this._throttledAddedModels={},this._throttledChangedModels={},this._throttledRemovedModels={},this._throttledTriggerUpdates=r.throttle(this._triggerUpdates,this._throttleDelay,{leading:!1}),this.addThrottledListeners(),o.__super__.initialize.apply(this,arguments)},o.prototype.addThrottledListeners=function(){return this.on("all",this._onAll)},o.prototype.getByIds=function(t){var e,n,i,o;for(o=[],n=0,i=t.length;i>n;n++)e=t[n],o.push(this.get(e));return o},o.prototype.isEmpty=function(){return this.models.length<=0},o.prototype._onAll=function(){var t,e;switch(e=arguments[0],t=2<=arguments.length?i.call(arguments,1):[],e){case"add":this._onAdd.apply(this,t);break;case"change":this._onChange.apply(this,t);break;case"remove":this._onRemove.apply(this,t)}return this._throttledTriggerUpdates()},o.prototype._onAdd=function(t){return this._throttledAddedModels[t.id]=t},o.prototype._onChange=function(t){return this._throttledChangedModels[t.id]=t},o.prototype._onRemove=function(t){return this._throttledRemovedModels[t.id]=t},o.prototype._throttledAdd=function(){var t,e;return t=o.prototype.THROTTLED_ADD,e=r.values(this._throttledAddedModels),this._throttledAddedModels={},e.length>0&&this.trigger(t,e,t),e},o.prototype._throttledChange=function(){var t,e;return t=o.prototype.THROTTLED_CHANGE,e=r.values(this._throttledChangedModels),this._throttledChangedModels={},e.length>0&&this.trigger(t,e,t),e},o.prototype._throttledRemove=function(){var t,e;return t=o.prototype.THROTTLED_REMOVE,e=r.values(this._throttledRemovedModels),this._throttledRemovedModels={},e.length>0&&this.trigger(t,e,t),e},o.prototype._throttledDiff=function(t,e,n){var i,s,a;return s=o.prototype.THROTTLED_DIFF,t.length||e.length||n.length?(t=r.difference(t,n),i=r.uniq(t.concat(e)),a={added:t,changed:e,removed:n,consolidated:i},this.trigger(s,a,s)):void 0},o.prototype._triggerUpdates=function(){return this._throttledDiff(this._throttledAdd(),this._throttledChange(),this._throttledRemove())},o}(o.Collection),p=function(t){function n(){return n.__super__.constructor.apply(this,arguments)}return e(n,t),n.prototype.parse=function(t){var e,n,i,o;if(null!=t.vcmArgumentFields&&null==t.vcmArgumentFieldValues)for(t.vcmArgumentFieldValues={},o=t.vcmArgumentFields,n=0,i=o.length;i>n;n++)e=o[n],t.vcmArgumentFieldValues[e.id]=e["default"];return t},n.prototype.getArgs=function(){var t,e;return t=this.get("args")||{},e=this.get("vcmArgumentFieldValues")||{},r.extend({},t,e)},n.prototype.getCustomProperties=function(t){var e,n,i,o;if(null==t&&(t=!0),e=r.keys(this.defaults),n=r.omit(this.toJSON(),e),t)for(i in n)o=n[i],n.hasOwnProperty(i)&&void 0===n[i]&&delete n[i];return n},n.prototype.dispose=function(){},n}(o.Model),I=function(t){function n(){return n.__super__.constructor.apply(this,arguments)}return e(n,t),n.prototype.getArguments=function(t,e){var n,i,o,s,a,l;for(r.isArray(t)||(t=[t]),n=[],i=0,o=t.length;o>i;i++)l=t[i],s=this.doesUrlPatternMatch(l,e),s?(a=this._getArgumentsFromUrl(l,e),a._id=l,a.url=e):a={_id:l,url:e},n.push(a);return n},n.prototype.routeToRegExp=function(t){return this._routeToRegExp(t)},n.prototype.doesUrlPatternMatch=function(t,e){var n;return"global"===t?!0:(n=this.routeToRegExp(t),n.test(e))},n.prototype._getArgumentsFromUrl=function(t,e){var n,i;return i=t,r.isRegExp(t)||(t=this._routeToRegExp(t)),t.exec(e)&&(n=r.compact(this._extractParameters(t,e))),this._getParamsObject(i,n)},n.prototype._getParamsObject=function(t,e){var n,i,o,s,a,l,c,u;return r.isString(t)?(o=/\((.*?)\)/g,n=/(\(\?)?:\w+/g,l=/\*\w+/g,a={},s=t.match(new RegExp(o)),i=t.match(new RegExp(n)),c=t.match(new RegExp(l)),u=function(t,e){var n,i,o,r,s;for(s=[],n=i=0,o=t.length;o>i;n=++i)r=t[n],r=r.replace(/([^a-z0-9]+)/gi,""),s.push(a[r]=e[n]);return s},s&&u(s,e),i&&u(i,e),c&&u(c,e),a):e},n}(o.Router),O=new I,g=function(t){function n(){return n.__super__.constructor.apply(this,arguments)}return e(n,t),n.prototype.defaults={url:void 0,filterString:void 0,includeIfMatch:void 0,excludeIfMatch:void 0,hasToMatch:void 0,cantMatch:void 0,options:{add:!0,remove:!0,merge:!0,invert:!1,forceFilterStringMatching:!1}},n.prototype.parse=function(t){var e;return this.clear({silent:!0}),e=r.extend({},this.defaults,t),e.options=r.extend({},this.defaults.options,e.options),e},n.prototype.serialize=function(t){var e;return null==t&&(t=!0),e=t?r.omit(this.toJSON(),"options"):this.toJSON(),JSON.stringify(e)},n}(p),_=function(n){function i(e){this.onIframeLoaded=t(this.onIframeLoaded,this),r.extend(this.attributes,null!=e?e.iframeAttributes:void 0),(null!=e?e.targetOrigin:void 0)&&(this.targetOrigin=e.targetOrigin),i.__super__.constructor.apply(this,arguments)}return e(i,n),i.prototype.tagName="iframe",i.prototype.className="vigor-component--iframe",i.prototype.attributes={seamless:"seamless",scrolling:!1,border:0,frameborder:0},i.prototype.src=void 0,i.prototype.targetOrigin="http://localhost:7070",i.prototype.initialize=function(t){return this.addListeners(),null!=(null!=t?t.src:void 0)&&(this.src=t.src),i.__super__.initialize.apply(this,arguments)},i.prototype.addListeners=function(){return this.$el.on("load",this.onIframeLoaded)},i.prototype.removeListeners=function(){return this.$el.off("load",this.onIframeLoaded)},i.prototype.render=function(){return this.$el.attr("src",this.src),this},i.prototype.dispose=function(){return this.removeListeners(),this.remove()},i.prototype.postMessageToIframe=function(t){var e;return e=this.$el.get(0).contentWindow,e.postMessage(t,this.targetOrigin)},i.prototype.receiveMessage=function(t){},i.prototype.onIframeLoaded=function(t){},i}(o.View),N.IframeComponent=_,d=function(t){function n(){return n.__super__.constructor.apply(this,arguments)}return e(n,t),n.prototype.ERROR={VALIDATION:{ID_UNDEFINED:"id cant be undefined",ID_NOT_A_STRING:"id should be a string",ID_IS_EMPTY_STRING:"id can not be an empty string",SRC_UNDEFINED:"src cant be undefined",SRC_WRONG_TYPE:"src should be a string or a constructor function",SRC_IS_EMPTY_STRING:"src can not be an empty string"},NO_CONSTRUCTOR_FOUND:function(t){return"No constructor function found for "+t},MISSING_CONDITION:function(t){return"Trying to verify condition "+t+" but it has not been registered yet"}},n.prototype.defaults={id:void 0,src:void 0,componentClass:void 0,args:void 0,conditions:void 0,maxShowCount:void 0,vcmArgumentFields:void 0,vcmArgumentFieldValues:void 0},n.prototype.deferred=void 0,n.prototype.initialize=function(){return this.deferred=s.Deferred(),n.__super__.initialize.apply(this,arguments)},n.prototype.validate=function(t,e){var n;if(!t.id)throw this.ERROR.VALIDATION.ID_UNDEFINED;if("string"!=typeof t.id)throw this.ERROR.VALIDATION.ID_NOT_A_STRING;if(/^\s+$/g.test(t.id))throw this.ERROR.VALIDATION.ID_IS_EMPTY_STRING;if(!t.src)throw this.ERROR.VALIDATION.SRC_UNDEFINED;if(n=r.isString(t.src)||r.isFunction(t.src),!n)throw this.ERROR.VALIDATION.SRC_WRONG_TYPE;if(r.isString(t.src)&&/^\s+$/g.test(t.src))throw this.ERROR.VALIDATION.SRC_IS_EMPTY_STRING},n.prototype.getClass=function(){var t,e,n,i,o,s,a;if(s=this.get("src"),o=function(t){return function(e){if(r.isFunction(e))return t.set("componentClass",e,{silent:!0}),t.deferred.resolve({componentDefinition:t,componentClass:e});throw t.ERROR.NO_CONSTRUCTOR_FOUND(s)}}(this),this.get("componentClass"))o(this.get("componentClass"));else if(r.isString(s)&&this._isUrl(s))o(N.IframeComponent);else if(r.isString(s))if(r.isString(s)&&"function"==typeof define&&define.amd)N.require([s],function(t){return function(t){return o(t)}}(this));else if(r.isString(s)&&"object"==typeof exports)o(N.require(s));else{for(n=window,a=s.split("."),t=0,e=a.length;e>t;t++)i=a[t],n=n[i];o(n)}else{if(!r.isFunction(s))throw this.ERROR.VALIDATION.SRC_WRONG_TYPE;o(s)}return this.deferred.promise()},n.prototype.getComponentClassPromise=function(){return this.deferred.promise()},n.prototype.passesFilter=function(t,e){return!!this._areConditionsMet(t,e)},n.prototype._areConditionsMet=function(t,e){var n,i,o,s,a,l,c;if(o=(null!=t?t.toJSON():void 0)||{},s=(null!=e?e.toJSON():void 0)||{},n=this.get("conditions"),c=!0,n)for(r.isArray(n)||(n=[n]),a=0,l=n.length;l>a;a++){if(i=n[a],r.isFunction(i)&&!i(o,this.getArgs())){c=!1;break}if(r.isString(i)){if(null==s[i])throw this.ERROR.MISSING_CONDITION(i);if(c=!!s[i](o,this.getArgs()),!c)break}}return c},n.prototype._isUrl=function(t){var e;return e=/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[\-;:&=\+\$,\w]+@)?[A-Za-z0-9\.\-]+|(?:www\.|[\-;:&=\+\$,\w]+@)[A-Za-z0-9\.\-]+)((?:\/[\+~%\/\.\w\-]*)?\??(?:[\-\+=&;%@\.\w]*)#?(?:[\.\!\/\\\w]*))?)/g,e.test(t)},n}(p),h=function(t){function n(){return n.__super__.constructor.apply(this,arguments)}return e(n,t),n.prototype.model=d,n.prototype.ERROR={UNKNOWN_COMPONENT_DEFINITION:"Unknown componentDefinition, are you referencing correct componentId?"},n.prototype.getComponentClassPromisesByInstanceDefinitions=function(t){var e,n,i,o,r;for(r=[],i=0,o=t.length;o>i;i++)n=t[i],e=this.getComponentDefinitionByInstanceDefinition(n),r.push(e.getClass());return r},n.prototype.getComponentClassPromiseByInstanceDefinition=function(t){var e;return e=this.getComponentDefinitionByInstanceDefinition(t),e.getClass()},n.prototype.getComponentClassByInstanceDefinition=function(t){var e;return e=this.getComponentDefinitionByInstanceDefinition(t),e.get("componentClass")},n.prototype.getComponentDefinitionByInstanceDefinition=function(t){var e;return e=t.get("componentId"),this.getComponentDefinitionById(e)},n.prototype.getComponentDefinitionById=function(t){var e;if(e=this.get(t),!e)throw this.ERROR.UNKNOWN_COMPONENT_DEFINITION;return e},n}(c),C=function(t){function n(){return n.__super__.constructor.apply(this,arguments)}return e(n,t),n.prototype.idAttribute="_id",n}(o.Model),y=function(t){function n(){return n.__super__.constructor.apply(this,arguments)}return e(n,t),n.prototype.model=C,n}(o.Collection),a=function(t){function n(){return n.__super__.constructor.apply(this,arguments)}return e(n,t),n.prototype.ERROR={MISSING_RENDER_METHOD:function(t){return"The instance for "+t+" does not have a render method"}},n.prototype.defaults={id:void 0,componentClass:void 0,target:void 0,targetPrefix:void 0,componentClassName:void 0,instanceArguments:void 0,order:void 0,reInstantiate:!1,instance:void 0,urlParams:void 0,urlParamsCollection:void 0,serializedFilter:void 0},n.prototype.initialize=function(){return n.__super__.initialize.apply(this,arguments),this.set("urlParamsCollection",new y,{silent:!0}),this.listenTo(this,"add",this._onAdd),this.listenTo(this,"remove",this._onRemove),this.listenTo(this,"change:instance",this._onInstanceChange),this.listenTo(this,"change:urlParams",this._onUrlParamsChange),this.listenTo(this,"change:order",this._onOrderChange),this.listenTo(this,"change:target",this._onTargetChange),this.listenTo(this,"change:componentClassName",this._onComponentClassNameChange),this.listenTo(this,"change:serializedFilter",this._onSerializedFilterChange),this.listenTo(this,"change:instanceArguments",this._onArgumentChange),this._updateUrlParamsCollection()},n.prototype.tryToReAddStraysToDom=function(){var t,e;return this._isAttached()?void 0:(e=this._addInstanceInOrder(),e?(t=this.get("instance"),(null!=t?t.delegateEvents:void 0)&&r.isFunction(null!=t?t.delegateEvents:void 0)&&t.delegateEvents()):this._disposeInstance(),this._updateTargetPopulatedState())},n.prototype.dispose=function(){return this._disposeInstance(),this._updateTargetPopulatedState(),this.stopListening(),this.off()},n.prototype._createInstance=function(){var t,e;return t=this.get("componentClass"),e=new t(this._getInstanceArguments()),this.set("instance",e),this._updateComponentClassNameOnInstance()},n.prototype._renderInstance=function(){var t;if(t=this.get("instance")){if(null==t.render||!r.isFunction(t.render))throw this.ERROR.MISSING_RENDER_METHOD(this.get("id"));return null!=t.preRender&&r.isFunction(t.preRender)&&t.preRender(),t.render(),null!=t.postRender&&r.isFunction(t.postRender)?t.postRender():void 0}},n.prototype._addInstanceInOrder=function(){var t,e,n,i,o;return n=this.get("instance"),e=this.get("target"),o=this.get("order"),i=!1,o?"top"===o?(n.$el.data("order",0),e.prepend(n.$el)):"bottom"===o?(n.$el.data("order",999),e.append(n.$el)):(t=this._getPrecedingElement(e.children().last(),o),n.$el.data("order",o),n.$el.attr("data-order",o),t?n.$el.insertAfter(t):e.prepend(n.$el)):e.append(n.$el),i=this._isAttached(),i&&null!=n.onAddedToDom&&r.isFunction(n.onAddedToDom)&&n.onAddedToDom(),i},n.prototype._disposeInstance=function(){var t;return t=this.get("instance"),null!=(null!=t?t.dispose:void 0)&&t.dispose(),t=void 0,this.set("instance",void 0,{silent:!0})},n.prototype._isTargetPopulated=function(){var t;return t=this.get("target"),(null!=t?t.children().length:void 0)>0},n.prototype._updateTargetPopulatedState=function(){var t,e;return t=this.get("target"),e=this.get("targetPrefix"),null!=t?t.toggleClass(e+"--has-components",this._isTargetPopulated()):void 0},n.prototype._isAttached=function(){var t,e,n;return n=this.get("instance"),t=!1,n?(e=!n.el&&n.$el?n.$el.get(0):n.el,n&&(t=s.contains(document.body,e)),t):t},n.prototype._getInstanceArguments=function(){var t;return t=this.get("instanceArguments")||{},t.urlParams=this.get("urlParams"),t.urlParamsCollection=this.get("urlParamsCollection"),t},n.prototype._getPrecedingElement=function(t,e){return null==e&&(e=0),t.length>0?t.data("order")<=e?t:this._getPrecedingElement(t.prev(),e):void 0},n.prototype._updateUrlParamsCollection=function(){var t,e;return t=this.get("urlParams"),e=this.get("urlParamsCollection"),e.set(t)},n.prototype._updateComponentClassNameOnInstance=function(){var t,e,n;return e=this.get("instance"),t=this.get("componentClassName"),n=this.previousAttributes().componentClassName,t!==n&&e.$el.removeClass(n),e.$el.addClass(t)},n.prototype._onArgumentChange=function(t,e,n){var i,o;return o=r.omit(t.previousAttributes().instanceArguments,["urlParams","urlParamsCollection"]),i=r.omit(t.toJSON().instanceArguments,["urlParams","urlParamsCollection"]),r.isEqual(o,i)?void 0:(this._disposeInstance(),this._createInstance())},n.prototype._onComponentClassNameChange=function(){return this._updateComponentClassNameOnInstance()},n.prototype._onInstanceChange=function(){return this._renderInstance(),this._addInstanceInOrder(),this._updateTargetPopulatedState()},n.prototype._onUrlParamsChange=function(){return this._updateUrlParamsCollection()},n.prototype._onOrderChange=function(){return this._addInstanceInOrder()},n.prototype._onTargetChange=function(){return this._addInstanceInOrder()},n.prototype._onSerializedFilterChange=function(){return this.get("reInstantiate")?(this._disposeInstance(),this._createInstance()):void 0},n.prototype._onAdd=function(){return this._createInstance()},n.prototype._onRemove=function(){return this.dispose()},n}(p),m=function(t){function n(){return n.__super__.constructor.apply(this,arguments)}return e(n,t),n.prototype.ERROR={VALIDATION:{ID_UNDEFINED:"id cant be undefined",ID_NOT_A_STRING:"id should be a string",ID_IS_EMPTY_STRING:"id can not be an empty string",COMPONENT_ID_UNDEFINED:"componentId cant be undefined",COMPONENT_ID_NOT_A_STRING:"componentId should be a string",COMPONENT_ID_IS_EMPTY_STRING:"componentId can not be an empty string",TARGET_NAME_UNDEFINED:"targetName cant be undefined",TARGET_WRONG_FORMAT:"target should be a string or a jquery object"},MISSING_GLOBAL_CONDITIONS:"No global conditions was passed, condition could not be tested",MISSING_CONDITION:function(t){return"Trying to verify condition "+t+" but it has not been registered yet"}},n.prototype.defaults={id:void 0,componentId:void 0,args:void 0,order:void 0,targetName:void 0,reInstantiate:!1,filterString:void 0,includeIfFilterStringMatches:void 0,excludeIfFilterStringMatches:void 0,conditions:void 0,maxShowCount:void 0,urlPattern:void 0,showCount:0,vcmArgumentFields:void 0,vcmArgumentFieldValues:void 0},n.prototype._$target=void 0,n.prototype.validate=function(t,e){var n;if(!t.id)throw this.ERROR.VALIDATION.ID_UNDEFINED;if(!r.isString(t.id))throw this.ERROR.VALIDATION.ID_NOT_A_STRING;if(!/^.*[^ ].*$/.test(t.id))throw this.ERROR.VALIDATION.ID_IS_EMPTY_STRING;if(!t.componentId)throw this.ERROR.VALIDATION.COMPONENT_ID_UNDEFINED;if(!r.isString(t.componentId))throw this.ERROR.VALIDATION.COMPONENT_ID_NOT_A_STRING;if(!/^.*[^ ].*$/.test(t.componentId))throw this.ERROR.VALIDATION.COMPONENT_ID_IS_EMPTY_STRING;if(!t.targetName)throw this.ERROR.VALIDATION.TARGET_NAME_UNDEFINED;if(!r.isString(t.targetName)&&null==(null!=(n=t.targetName)?n.jquery:void 0))throw this.ERROR.VALIDATION.TARGET_WRONG_FORMAT},n.prototype.incrementShowCount=function(t){var e;return null==t&&(t=!0),e=this.get("showCount"),e++,this.set("showCount",e,{silent:t})},n.prototype.passesFilter=function(t,e){var n,i,o,r,s,a,l,c;if(i=(null!=t?t.toJSON():void 0)||{},r=(null!=e?e.toJSON():void 0)||{},((null!=i?i.url:void 0)||""===(null!=i?i.url:void 0))&&(c=this._doesUrlPatternMatch(i.url),null!=c&&!c))return!1;if(this.get("conditions")&&(n=this._areConditionsMet(i,r),null!=n&&!n))return!1;if(null!=i?i.filterString:void 0){if(null!=this.get("includeIfFilterStringMatches")&&(o=this._includeIfFilterStringMatches(i.filterString),null!=o&&!o))return!1;if(null!=this.get("excludeIfFilterStringMatches")&&(o=this._excludeIfFilterStringMatches(i.filterString),null!=o&&!o))return!1}return(null!=i&&null!=(s=i.options)?s.forceFilterStringMatching:void 0)&&null!=this.get("filterString")&&null==(null!=i?i.includeIfMatch:void 0)&&null==(null!=i?i.excludeIfMatch:void 0)&&null==(null!=i?i.hasToMatch:void 0)&&null==(null!=i?i.cantMatch:void 0)?!1:(null!=i?i.includeIfMatch:void 0)&&(o=this._includeIfMatch(i.includeIfMatch),(null!=i&&null!=(a=i.options)?a.forceFilterStringMatching:void 0)&&(o=!!o),null!=o&&!o)?!1:(null!=i?i.excludeIfMatch:void 0)&&(o=this._excludeIfMatch(i.excludeIfMatch),(null!=i&&null!=(l=i.options)?l.forceFilterStringMatching:void 0)&&(o=!!o),null!=o&&!o)?!1:(null!=i?i.hasToMatch:void 0)&&(o=this._hasToMatch(i.hasToMatch),null!=o&&!o)?!1:(null!=i?!i.cantMatch:!0)||(o=this._cantMatch(i.cantMatch),null==o||o)},n.prototype.exceedsMaximumShowCount=function(t){var e,n,i;return i=this.get("showCount"),n=parseInt(this.get("maxShowCount",10)),e=!1,n||(n=t),n&&i>n&&(e=!0),e},n.prototype.isTargetAvailable=function(t,e){var n;return null==t&&(t=s("body")),null==e&&(e=!0),(null!=(n=this.getTarget(t,e))?n.length:void 0)>0},n.prototype.getTarget=function(t,e){var n,i;return null==t&&(t=s("body")),null==e&&(e=!1),i=(null!=(n=this._$target)?n.selector:void 0)||"",i.indexOf(this._getTargetName())>-1&&!e||this._refreshTarget(t),this._$target},n.prototype.unsetTarget=function(){return this._$target=void 0},n.prototype.updateTargetPrefix=function(t){var e,n;return n=this.get("targetName"),e=n.split("--")[1],this.set("targetName",t+"--"+e)},n.prototype._includeIfMatch=function(t){var e;return e=this.get("filterString"),e?!!e.match(t):void 0},n.prototype._excludeIfMatch=function(t){var e;return e=this.get("filterString"),e?!e.match(t):void 0},n.prototype._hasToMatch=function(t){return!!this._includeIfMatch(t)},n.prototype._cantMatch=function(t){return!!this._excludeIfMatch(t)},n.prototype._includeIfFilterStringMatches=function(t){var e;return e=this.get("includeIfFilterStringMatches"),e?!!(null!=t?t.match(e):void 0):void 0},n.prototype._excludeIfFilterStringMatches=function(t){var e;return e=this.get("excludeIfFilterStringMatches"),e?!(null!=t?t.match(e):void 0):void 0},n.prototype._doesUrlPatternMatch=function(t){var e,n,i,o,s;if(i=!1,s=this.get("urlPattern"),null!=s){for(r.isArray(s)||(s=[s]),e=0,n=s.length;n>e;e++)if(o=s[e],i=O.doesUrlPatternMatch(o,t))return i;return i}},n.prototype._areConditionsMet=function(t,e){var n,i,o,s,a;if(i=this.get("conditions"),a=!0,i)for(r.isArray(i)||(i=[i]),o=0,s=i.length;s>o;o++){if(n=i[o],r.isFunction(n)&&!n(t,this.getArgs())){a=!1;break}if(r.isString(n)){if(!e)throw this.ERROR.MISSING_GLOBAL_CONDITIONS;if(null==e[n])throw this.ERROR.MISSING_CONDITION(n);if(a=e[n](t,this.getArgs()),!a)break}}return a},n.prototype._refreshTarget=function(t){var e,n;if(null==t&&(t=s("body")),n=this._getTargetName(),r.isString(n))e="body"===n?s(n):s(n,t);else{if(null==(null!=n?n.jquery:void 0))throw this.ERROR.VALIDATION.TARGET_WRONG_FORMAT;e=n}return this._$target=e,this._$target},n.prototype._getTargetName=function(){var t;return t=this.get("targetName"),r.isString(t)&&"body"!==t&&"."!==t.charAt(0)&&(t="."+t),t},n}(p),u=function(t){function n(){return n.__super__.constructor.apply(this,arguments)}return e(n,t),n.prototype.ERROR={UNKNOWN_INSTANCE_DEFINITION:"Unknown instanceDefinition, are you referencing correct instanceId?"},n.prototype.model=m,n.prototype.initialize=function(){return this.on("reset",this._onReset),n.__super__.initialize.apply(this,arguments)},n.prototype.getInstanceDefinitionById=function(t){var e;if(e=this.get(t),!e)throw this.ERROR.UNKNOWN_INSTANCE_DEFINITION;return e},n.prototype._onReset=function(t,e){return r.invoke(e.previousModels,"dispose")},n}(c),v=function(t){function n(){return n.__super__.constructor.apply(this,arguments)}return e(n,t),n.prototype.model=m,n.prototype.parse=function(t,e){var n,i,o,s,a,l,c,u,p,d,h,f;if(d=void 0,a=[],f=t.targetPrefix,i=t.instanceDefinitions,r.isObject(i)&&!r.isArray(i))for(h in i){if(s=i[h],!r.isArray(s)){i.targetName&&(i.targetName=this._formatTargetName(i.targetName,f)),d=i;break}for(l=0,u=s.length;u>l;l++)o=s[l],o.targetName=this._formatTargetName(h,f),a.push(o);d=a}else if(r.isArray(i)){for(n=c=0,p=i.length;p>c;n=++c)o=i[n],o.targetName&&(o.targetName=this._formatTargetName(o.targetName,f)),i[n]=o;d=i}return d},n.prototype._formatTargetName=function(t,e){return r.isString(t)&&"body"!==t&&("."===t.charAt(0)&&(t=t.substring(1)),t.indexOf(e)<0&&(t=e+"--"+t),t="."+t),t},n}(u),l=function(t){function n(){return n.__super__.constructor.apply(this,arguments)}return e(n,t),n.prototype.model=a,n}(u),f=function(){function e(){this._onMessageReceived=t(this._onMessageReceived,this),this._onActiveInstanceAdd=t(this._onActiveInstanceAdd,this),this._updateActiveComponents=t(this._updateActiveComponents,this)}var n,i,c,u;return i="vigorjs.componentmanager",n="vigor-component",c="component-area",u="http://localhost:3000",e.prototype.ERROR={CONDITION:{WRONG_FORMAT:"condition has to be an object with key value pairs"},MESSAGE:{MISSING_ID:"The id of targeted instance must be passed as first argument",MISSING_MESSAGE:"No message was passed",MISSING_RECEIVE_MESSAGE_METHOD:"The instance does not seem to have a receiveMessage method"},CONTEXT:{WRONG_FORMAT:"context should be a string or a jquery object"}},e.prototype.EVENTS={INITIALIZED:"initialized",FILTER_CHANGE:"filter-change",CONDITIONS_CHANGED:"conditions-changed",ADD:"add",CHANGE:"change",REMOVE:"remove",COMPONENT_ADD:"component-add",COMPONENT_CHANGE:"component-change",COMPONENT_REMOVE:"component-remove",INSTANCE_ADD:"instance-add",INSTANCE_CHANGE:"instance-change",INSTANCE_REMOVE:"instance-remove"},e.prototype._componentDefinitionsCollection=void 0,e.prototype._instanceDefinitionsCollection=void 0,e.prototype._activeInstancesCollection=void 0,e.prototype._globalConditionsModel=void 0,e.prototype._filterModel=void 0,e.prototype._$context=void 0,e.prototype._componentClassName=void 0,e.prototype._targetPrefix=void 0,e.prototype._listenForMessages=!1,e.prototype._whitelistedOrigins=u,e.prototype.initialize=function(t){return this._componentDefinitionsCollection=new h,this._instanceDefinitionsCollection=new v,this._activeInstancesCollection=new l,this._globalConditionsModel=new o.Model,this._filterModel=new g,t&&r.isString(t)&&(t=this.parse(t)),null!=(null!=t?t.listenForMessages:void 0)&&(this._listenForMessages=null!=t?t.listenForMessages:void 0),this.addListeners(),this._parse(t),this.trigger(this.EVENTS.INITIALIZED,this),this},e.prototype.updateSettings=function(t){return null!=(null!=t?t.listenForMessages:void 0)&&(this._listenForMessages=null!=t?t.listenForMessages:void 0),this._parse(t),this},e.prototype.refresh=function(t){var e;return this._filterModel.set(this._filterModel.parse(t)),e=this._updateActiveComponents(),e.then(function(t){return function(e){return t.trigger(t.EVENTS.FILTER_CHANGE,t.getActiveFilter(),e)}}(this)),e},e.prototype.serialize=function(){var t,e,n,i,o,r,s,a,l,c,u,p,d,h;for(o={},r=this._globalConditionsModel.toJSON(),i=this._componentDefinitionsCollection.toJSON(),l=this._instanceDefinitionsCollection.toJSON(),c=0,u=i.length;u>c;c++)n=i[c],n.componentClass=void 0;return t=this.getContext(),t.length>0?(h=t.prop("tagName").toLowerCase(),e=null!=(p=t.attr("class"))?p.replace(" ","."):void 0,s=t.selector||h+"."+e):s="body",d={context:s,componentClassName:this.getComponentClassName(),targetPrefix:this.getTargetPrefix(),componentSettings:{conditions:r,components:i,instances:l}},a=function(t,e){return"function"==typeof e?e.toString():e},JSON.stringify(d,a)},e.prototype.parse=function(t,e){var n,i;return null==e&&(e=!1),n=function(t,e){var n,i,o,r,s,a,l,c;return a=e&&"string"==typeof e,s=a&&"function"===e.substr(0,8),a&&s?(c=e.indexOf("{")+1,r=e.lastIndexOf("}"),l=e.indexOf("(")+1,o=e.indexOf(")"),n=e.substring(l,o),i=e.substring(c,r),new Function(n,i)):e},i=JSON.parse(t,n),e&&this.updateSettings(i),i},e.prototype.clear=function(){var t,e,i,o,r;return null!=(t=this._componentDefinitionsCollection)&&t.reset(),null!=(e=this._instanceDefinitionsCollection)&&e.reset(),null!=(i=this._activeInstancesCollection)&&i.reset(),null!=(o=this._filterModel)&&o.clear({silent:!0}),null!=(r=this._globalConditionsModel)&&r.clear({silent:!0}),this._$context=void 0,this._listenForMessages=!1,this._componentClassName=n,this._targetPrefix=c,this._whitelistedOrigins=[u],this},e.prototype.dispose=function(){return this.clear(),this.removeListeners(),this._componentDefinitionsCollection=void 0,this._instanceDefinitionsCollection=void 0,this._globalConditionsModel=void 0,this._activeInstancesCollection=void 0,this._filterModel=void 0},e.prototype.addListeners=function(){var t,e,n;return this._componentDefinitionsCollection.on("throttled_diff",this._updateActiveComponents),this._instanceDefinitionsCollection.on("throttled_diff",this._updateActiveComponents),this._globalConditionsModel.on("change",this._updateActiveComponents),this._activeInstancesCollection.on("add",this._onActiveInstanceAdd),this._globalConditionsModel.on("change",function(t){return function(e,n){return t.trigger(t.EVENTS.CONDITIONS_CHANGED,e.toJSON())}}(this)),this._componentDefinitionsCollection.on("add",function(t){return function(e,n,i){return t.trigger(t.EVENTS.COMPONENT_ADD,e.toJSON(),n.toJSON())}}(this)),this._componentDefinitionsCollection.on("change",function(t){return function(e,n){return t.trigger(t.EVENTS.COMPONENT_CHANGE,e.toJSON(),t._componentDefinitionsCollection.toJSON())}}(this)),this._componentDefinitionsCollection.on("remove",function(t){return function(e,n,i){return t.trigger(t.EVENTS.COMPONENT_REMOVE,e.toJSON(),n.toJSON())}}(this)),this._instanceDefinitionsCollection.on("add",function(t){return function(e,n,i){return t.trigger(t.EVENTS.INSTANCE_ADD,e.toJSON(),n.toJSON())}}(this)),this._instanceDefinitionsCollection.on("change",function(t){return function(e,n){return t.trigger(t.EVENTS.INSTANCE_CHANGE,e.toJSON(),t._instanceDefinitionsCollection.toJSON())}}(this)),this._instanceDefinitionsCollection.on("remove",function(t){return function(e,n,i){return t.trigger(t.EVENTS.INSTANCE_REMOVE,e.toJSON(),n.toJSON())}}(this)),this._activeInstancesCollection.on("add",function(t){return function(e,n,i){return t.trigger(t.EVENTS.ADD,e.get("instance"),t.getActiveInstances())}}(this)),this._activeInstancesCollection.on("change",function(t){return function(e,n){return t.trigger(t.EVENTS.CHANGE,e.get("instance"),t.getActiveInstances())}}(this)),this._activeInstancesCollection.on("remove",function(t){return function(e,n,i){return t.trigger(t.EVENTS.REMOVE,e.get("instance"),t.getActiveInstances())}}(this)),this._listenForMessages&&(t=window.addEventListener?"addEventListener":"attachEvent",e=window[t],n="attachEvent"===t?"onmessage":"message",e(n,this._onMessageReceived,!1)),this},e.prototype.addConditions=function(t,e){var n;if(null==e&&(e=!1),!r.isObject(t))throw this.ERROR.CONDITION.WRONG_FORMAT;return n=this._globalConditionsModel.get("conditions")||{},t=r.extend(n,t),this._globalConditionsModel.set(t,{silent:e}),this},e.prototype.addComponentDefinitions=function(t){return this._componentDefinitionsCollection.set(t,{parse:!0,validate:!0,remove:!1}),this},e.prototype.addInstanceDefinitions=function(t){var e;return e={instanceDefinitions:t,targetPrefix:this.getTargetPrefix()},this._instanceDefinitionsCollection.set(e,{parse:!0,validate:!0,remove:!1}),this},e.prototype.updateComponentDefinitions=function(t){return this.addComponentDefinitions(t),this},e.prototype.updateInstanceDefinitions=function(t){return this.addInstanceDefinitions(t),this},e.prototype.removeComponentDefinition=function(t){var e;return e=this._instanceDefinitionsCollection.where({componentId:t}),this._instanceDefinitionsCollection.remove(e),this._componentDefinitionsCollection.remove(t),this},e.prototype.removeInstanceDefinition=function(t){return this._instanceDefinitionsCollection.remove(t),this},e.prototype.removeListeners=function(){var t,e,n,i,o,r,s,a;return null!=(i=this._activeInstancesCollection)&&i.off(),null!=(o=this._filterModel)&&o.off(),null!=(r=this._instanceDefinitionsCollection)&&r.off(),null!=(s=this._componentDefinitionsCollection)&&s.off(),null!=(a=this._globalConditionsModel)&&a.off(),this._listenForMessages&&(t=window.removeEventListener?"removeEventListener":"detachEvent",e=window[t],n="detachEvent"===t?"onmessage":"message",e(n,this._onMessageReceived)),this},e.prototype.setContext=function(t,e){var n,i;if(null==t&&(t="body"),null==e&&(e=!0),r.isString(t))this._$context=s(t);else{if(null==t.jquery)throw this.ERROR.CONTEXT.WRONG_FORMAT;this._$context=t}return e&&(r.invoke(null!=(n=this._instanceDefinitionsCollection)?n.models:void 0,"unsetTarget"),null!=(i=this._activeInstancesCollection)&&i.reset(),this._updateActiveComponents()),this},e.prototype.setComponentClassName=function(t){var e;return this._componentClassName=null!=t?t:n,r.invoke(null!=(e=this._activeInstancesCollection)?e.models:void 0,"set",{componentClassName:this._componentClassName}),this},e.prototype.setTargetPrefix=function(t){var e;return this._targetPrefix=null!=t?t:c,r.invoke(null!=(e=this._instanceDefinitionsCollection)?e.models:void 0,"updateTargetPrefix",this._targetPrefix),this},e.prototype.setWhitelistedOrigins=function(t){return this._whitelistedOrigins=null!=t?t:[u],r.isArray(this._whitelistedOrigins)||(this._whitelistedOrigins=[this._whitelistedOrigins]),
this},e.prototype.getContext=function(){return this._$context},e.prototype.getComponentClassName=function(){return this._componentClassName||n},e.prototype.getTargetPrefix=function(){return this._targetPrefix||c},e.prototype.getListenForMessages=function(){return this._listenForMessages},e.prototype.getWhitelistedOrigins=function(){return this._whitelistedOrigins},e.prototype.getActiveFilter=function(){return this._filterModel.toJSON()},e.prototype.getConditions=function(){return this._globalConditionsModel.toJSON()},e.prototype.getComponentDefinitionById=function(t){return this._componentDefinitionsCollection.getComponentDefinitionById(t).toJSON()},e.prototype.getInstanceDefinitionById=function(t){return this._instanceDefinitionsCollection.getInstanceDefinitionById(t).toJSON()},e.prototype.getComponentDefinitions=function(){return this._componentDefinitionsCollection.toJSON()},e.prototype.getInstanceDefinitions=function(){return this._instanceDefinitionsCollection.toJSON()},e.prototype.getComponentDefinitionByInstanceDefinitionId=function(t){var e;return e=this._instanceDefinitionsCollection.getInstanceDefinitionById(t),this._componentDefinitionsCollection.getComponentDefinitionByInstanceDefinition(e).toJSON()},e.prototype.getActiveInstances=function(){return this._mapInstances(this._activeInstancesCollection.models)},e.prototype.getActiveInstancesByComponentId=function(t){return r.compact(r.map(this._activeInstancesCollection.models,function(e){return function(n){return n.get("componentId")===t?e._mapInstances(n)[0]:void 0}}(this)))},e.prototype.getActiveInstanceById=function(t){var e;return null!=(e=this._activeInstancesCollection.getInstanceDefinitionById(t))?e.get("instance"):void 0},e.prototype.postMessageToInstance=function(t,e){var n;if(!t)throw this.ERROR.MESSAGE.MISSING_ID;if(!e)throw this.ERROR.MESSAGE.MISSING_MESSAGE;if(n=this.getActiveInstanceById(t),r.isFunction(null!=n?n.receiveMessage:void 0))return n.receiveMessage(e);throw this.ERROR.MESSAGE.MISSING_RECEIVE_MESSAGE_METHOD},e.prototype._parse=function(t){var e;return e=!1,this.setContext(null!=t?t.context:void 0,e),this.setComponentClassName(null!=t?t.componentClassName:void 0),this.setTargetPrefix(null!=t?t.targetPrefix:void 0),this.setWhitelistedOrigins(null!=t?t.whitelistedOrigins:void 0),(null!=t?t.require:void 0)?N.require=(null!=t?t.require:void 0)||N.require:"function"==typeof require&&(N.require=require),(null!=t?t.componentSettings:void 0)?this._parseComponentSettings(t.componentSettings):t&&this._parseComponentSettings(t),this},e.prototype._parseComponentSettings=function(t){var e,n,i,o;return e=t.components||t.widgets||t.componentDefinitions,i=t.layoutsArray||t.targets||t.instanceDefinitions||t.instances,o=!0,t.conditions&&(n=t.conditions,r.isObject(n)&&!r.isEmpty(n)&&this.addConditions(n,o)),e&&this._registerComponentDefinitions(e),i&&this._registerInstanceDefinitions(i),this},e.prototype._registerComponentDefinitions=function(t){return this._componentDefinitionsCollection.set(t,{validate:!0,parse:!0,silent:!0}),this},e.prototype._registerInstanceDefinitions=function(t){var e;return e={instanceDefinitions:t,targetPrefix:this.getTargetPrefix()},this._instanceDefinitionsCollection.set(e,{validate:!0,parse:!0,silent:!0}),this},e.prototype._updateActiveComponents=function(){var t,e,n,i;return e=s.Deferred(),i=this._filterModel.get("options"),n=this._filterInstanceDefinitions(),i.invert&&(n=r.difference(this._instanceDefinitionsCollection.models,n)),t=this._componentDefinitionsCollection.getComponentClassPromisesByInstanceDefinitions(n),s.when.apply(s,t).then(function(t){return function(){var o,s,l;return o=t._createActiveInstanceDefinitionObjects(n),s=t._activeInstancesCollection.set(o,i),s=r.filter(s,function(t){return t instanceof a}),r.invoke(s,"tryToReAddStraysToDom"),l={filter:t._filterModel.toJSON(),activeInstances:t._mapInstances(t._activeInstancesCollection.models),activeInstanceDefinitions:t._activeInstancesCollection.toJSON(),lastChangedInstances:t._mapInstances(s),lastChangedInstanceDefinitions:t._modelsToJSON(s)},e.resolve(l)}}(this)),e.promise()},e.prototype._createActiveInstanceDefinitionObjects=function(t){var e,n,i,o,s,a,l,c;return o=!0,c=this._filterModel.get("url"),s=this._filterModel.get("options"),a=this._filterModel.serialize(o),l=this.getTargetPrefix(),i=this.getComponentClassName(),e=this.getContext(),r.isArray(t)||(t=[t]),n=r.map(t,function(t){return function(n){var o,r,s,u;return r=t._componentDefinitionsCollection.getComponentDefinitionByInstanceDefinition(n),u=n.get("urlPattern"),s=void 0,s=u?O.getArguments(u,c):{_id:"noUrlPatternsDefined",url:c},o={id:n.id,componentClass:r.get("componentClass"),componentId:r.get("id"),target:n.getTarget(e),targetPrefix:l,componentClassName:i,instanceArguments:t._getInstanceArguments(n,r),order:n.get("order"),reInstantiate:n.get("reInstantiate"),urlParams:s,serializedFilter:a}}}(this))},e.prototype._filterInstanceDefinitions=function(){var t;return t=this._instanceDefinitionsCollection.models,t=this._filterInstanceDefinitionsByComponentLevelFilters(t),t=this._filterInstanceDefinitionsByInstanceLevelFilters(t),t=this._filterInstanceDefinitionsByCustomProperties(t),t=this._filterInstanceDefinitionsByShowCount(t),t=this._filterInstanceDefinitionsByTargetAvailability(t)},e.prototype._filterInstanceDefinitionsByComponentLevelFilters=function(t){return r.filter(t,function(t){return function(e){var n;return n=t._componentDefinitionsCollection.getComponentDefinitionByInstanceDefinition(e),n.passesFilter(t._filterModel,t._globalConditionsModel)}}(this))},e.prototype._filterInstanceDefinitionsByInstanceLevelFilters=function(t){return r.filter(t,function(t){return function(e){return e.passesFilter(t._filterModel,t._globalConditionsModel)}}(this))},e.prototype._filterInstanceDefinitionsByCustomProperties=function(t){var e;return e=this._filterModel.getCustomProperties(),r.filter(t,function(t){return function(n){var i,o;return i=t._componentDefinitionsCollection.getComponentDefinitionByInstanceDefinition(n),o=r.extend({},i.getCustomProperties(),n.getCustomProperties()),r.isEmpty(e)?!0:r.isMatch(o,e)}}(this))},e.prototype._filterInstanceDefinitionsByShowCount=function(t){return r.filter(t,function(t){return function(e){var n,i;return n=t._componentDefinitionsCollection.getComponentDefinitionByInstanceDefinition(e),i=parseInt(n.get("maxShowCount",10)),!e.exceedsMaximumShowCount(i)}}(this))},e.prototype._filterInstanceDefinitionsByTargetAvailability=function(t){return r.filter(t,function(t){return function(e){return e.isTargetAvailable(t.getContext())}}(this))},e.prototype._getInstanceArguments=function(t,e){var n,i,o,s;return o=e.get("componentClass"),n={},i=e.getArgs(),s=t.getArgs(),null!=(null!=i?i.iframeAttributes:void 0)&&null!=(null!=s?s.iframeAttributes:void 0)&&(s.iframeAttributes=r.extend(i.iframeAttributes,s.iframeAttributes)),r.extend(n,i,s),o===N.IframeComponent&&(n.src=e.get("src")),n},e.prototype._mapInstances=function(t){var e;return r.isArray(t)||(t=[t]),t=r.compact(t),e=r.map(t,function(t){return function(t){return t.get("instance")}}(this)),r.compact(e)},e.prototype._modelToJSON=function(t){return t.toJSON()},e.prototype._modelsToJSON=function(t){return r.map(t,this._modelToJSON)},e.prototype._onActiveInstanceAdd=function(t){var e;return e=this._instanceDefinitionsCollection.get(t.id),e.incrementShowCount()},e.prototype._onMessageReceived=function(t){var e,n,o;if(r.isArray(this._whitelistedOrigins)||(this._whitelistedOrigins=[this._whitelistedOrigins]),this._whitelistedOrigins.indexOf(t.origin)>-1&&(e=t.data,e&&e.recipient===i)){if(n=e.id,o=e.message,!n)throw this.ERROR.MESSAGE.MISSING_ID;if(!o)throw this.ERROR.MESSAGE.MISSING_MESSAGE;return this.postMessageToInstance(n,o)}},e}(),r.extend(f.prototype,o.Events),N.ComponentManager=f,N.addRequireReference=function(t){return function(t){return N.require=t,t}}(this),N.componentManager=new N.ComponentManager,N})}).call(this);