/**
 * Copyright 2016 Adobe Systems, Inc. http://www.adobe.com
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
!function(e,t){"use strict";function o(e,o){o=o||{};var n={mbox:o.mbox,params:o.params,timeout:o.timeout},r=e.defer();return n.success=function(e){e&&e.length>0?r.resolve({mbox:o.mbox,offer:e,selector:o.selector||o.element}):r.reject("Empty offer")},n.error=function(e,t){r.reject(t)},t.getOffer(n),r.promise}function n(e,o){return e(function(e,n){t.applyOffer(o),e()})}function r(e){this.getOfferPromise=function(t){return o(e,t)},this.applyOfferPromise=function(t){return n(e,t)}}function i(e,t){return!(0!==t.allowedRoutesFilter.length&&t.allowedRoutesFilter.indexOf(e)===-1||t.disallowedRoutesFilter.length>0&&t.disallowedRoutesFilter.indexOf(e)!==-1)}function u(e){this.isRouteAllowed=function(t){return i(t,e)}}function a(e,t){return{mbox:t.mbox||e.globalMboxName,timeout:t.timeout||e.timeout,globalMboxAutoCreate:e.globalMboxAutoCreate,params:t.params||null,selector:t.selector||null,allowedRoutesFilter:t.allowedRoutesFilter||[],disallowedRoutesFilter:t.disallowedRoutesFilter||[],appendToSelector:t.appendToSelector||!1}}function l(t,o,n){e.module("target.angular.common",[]).constant("version","0.3.0").constant("settings",t).constant("logger",o).constant("customOptions",n||{}).factory("options",["settings","customOptions",a]).service("routeService",["options",u]).service("offerService",["$q",r])}t.registerExtension({name:"angular.setupCommon",modules:["settings","logger"],register:function(e,t){return function(o){l(e,t,o)}}})}(angular,adobe.target),function(e,t,o){"use strict";function n(e,t){t.forEach(function(t){e.requires.indexOf(t)===-1&&e.requires.push(t)})}function r(e){e.directive("mbox",["logger","options","offerService",function(e,t,o){return{restrict:"AE",link:{pre:function(e,t){t.addClass("mboxDefault")},post:function(n,r,i){o.getOfferPromise({mbox:i.mboxname,params:t.params,timeout:t.timeout,selector:t.selector||r[0]}).then(o.applyOfferPromise)["catch"](function(t){e.error("mboxDirective error: "+t)})["finally"](function(){r.removeClass("mboxDefault")})}}}}])}function i(t){return e.querySelectorAll(t)}function u(e,t,o,n){return e.isRouteAllowed(t)&&!i("#"+n).length&&i(o.selector).length>0}function a(e,t,o,n,r){if(n.appendToSelector){var i=e('<div id="'+r+'" mbox data-mboxname="'+n.mbox+'"></div>')(o);t.append(i)}else t.attr("mbox",""),t.attr("data-mboxname",n.mbox),t.attr("id",r),e(t)(o)}function l(e){e.run(["$rootScope","$injector","$location","$compile","routeService","options","logger",function(e,o,n,r,l,s,c){e.$on("$viewContentLoaded",function(e,o,f){var m=n.path();c.log("$viewContentLoaded "+m);var d=s.mbox+"-dir";if(u(l,m,s,d)){var p=t.element(i(s.selector));a(r,p,p.scope(),s,d),c.log((s.appendToSelector?"appended":"created")+" mbox directive",s.mbox)}})}])}o.ext.angular.initDirective=function(e,i){o.ext.angular.setupCommon(i);var u="string"==typeof e?t.module(e):e;n(u,["target.angular.common"]),r(u),l(u)}}(document,angular,adobe.target);