%PDF- %PDF-
Direktori : /proc/985914/root/data/old/home/stash/atlassian-stash/static/util/ |
Current File : //proc/985914/root/data/old/home/stash/atlassian-stash/static/util/feature-loader-min.js |
define("util/feature-loader",["jquery","require","underscore","util/events"],function(F,D,C,E){function A(I,H){if(typeof I.load!=="function"||typeof I.unload!=="function"){throw new Error("Modules require both a load and unload callback. Please use:\n"+G(H))}}function G(H){return"FeatureLoader.registerHandler('"+H+"', /urlMatcher/, {\n load : loadFn,\n unload : unloadFn,\n keyboardShortcutContexts : [ 'changeset', ... ]});"}function B(J){if(!(this instanceof B)){return new B(J)}J=F.extend({},B.defaults,J);var a=window.location.href;var K=[];var c={};var X=F.Deferred().resolve();var P;var V=false;var I;var H;function T(e){I=e}function d(e){H=e}function M(e,h,g){var f;if(C.has(c,e)){throw new Error("A handler with the name '"+e+"' already exists.")}if(!g){throw new Error("No module or module name was provided. Please use:\n"+G(e))}if(typeof g==="string"){f=c[e]={name:e,urlRegex:h,moduleName:g}}else{A(g,e);f=c[e]={name:e,urlRegex:h,module:g}}if(V&&!P&&C.contains(W(window.location.href),f)){O(f)}return this}function R(f){if(!C.contains(K,f)){return F.Deferred().resolve()}var e=f.module.unload(I);K=C.without(K,f);function g(){E.trigger(J.unloadedEvent,null,f)}if(e&&e.then){return e.then(g)}else{g();return F.Deferred().resolve()}}function O(f){if(C.contains(K,f)){return F.Deferred().resolve()}if(!f.module){f.module=D(f.moduleName);A(f.module,f.name)}var e=f.module.load(I);K.push(f);function g(){E.trigger(J.loadedEvent,null,f)}if(e&&e.then){return e.then(g)}else{g();return F.Deferred().resolve()}}function Q(){if(V&&a===window.location.href){return }a=window.location.href;var e=W(a);if(e.length){C.each(e,function(f){E.trigger(J.requestedEvent,null,f.name)});if(!P){P=true;X.then(Z)}}else{if(!V){E.trigger(J.errorEvent,null,{message:AJS.I18n.getText("stash.util.feature-loader.no-handler"),code:B.NO_HANDLER})}else{window.location.reload()}}}function Z(){P=false;var j=W(window.location.href);var g=C.difference(j,K);var i=C.difference(K,j);var e=g.length||i.length;if(e){var f=function(){if(!K.length){F(I).empty();return F.Deferred().resolve()}return F.when.apply(F,C.map(i,R))};var h=function(){return F.when.apply(F,C.map(g,O))};var k=function(){return f().then(h)};X=k().then(function(){if(H){H.resetContexts()}})}}function W(e){return C.filter(c,function(f){return f.urlRegex&&f.urlRegex.test(e)})}function S(){return K.slice()}function L(){Q()}function Y(e){return e.module&&e.module.keyboardShortcutContexts||[]}function N(e){var f=C.chain(K).map(Y).flatten().uniq().value();C.each(f,function(g){e.enableContext(g)})}function U(e){T(e);Q();E.on("memoir.changestate",L);E.on("stash.widget.keyboard-shortcuts.register-contexts",N);V=true}function b(){E.off("memoir.changestate",L);E.off("stash.widget.keyboard-shortcuts.register-contexts",N)}this.registerHandler=M;this.setElement=T;this.setKeyboardShortcuts=d;this.current=S;this.init=U;this.destroy=b;return this}B.defaults={unloadedEvent:"stash.util.feature-loader.unloaded",loadedEvent:"stash.util.feature-loader.loaded",requestedEvent:"stash.util.feature-loader.loadRequested",errorEvent:"stash.util.feature-loader.errorOccurred"};B.NO_HANDLER="NO_HANDLER";return B});