title: AngularJS in Confluence
body: <p>I have problem with AngularJS in Confluence. I tried to add angular files as web resource in atlassian-plugin.xml:</p>
  
  <pre><code>&lt;web-resource name="Angular js files" key="angular-sources"&gt;
      &lt;resource type="download" name="angular.js" location="js/angular/angular.js"/&gt;
      &lt;resource type="download" name="angular-animate.js" location="js/angular/angular-animate.js"/&gt;
      &lt;context&gt;atl.general&lt;/context&gt;
    &lt;/web-resource&gt;
  </code></pre>
  
  <p>It works fine when I use atlas-run or atlas-debug. But when I generate new jar file using atlas-package and install it on new Confluence instance, my macro editor js files doesn't see variables defined in angular.js.</p>
  
  <p>I tried also to add angular files directly in web resource for my new macro, but it also doesn't work:</p>
  
  <pre><code>&lt;web-resource name="Resources - handle macros with JS" key="macroeditor-resources"&gt;
      &lt;resource type="download" name="angular.js" location="js/angular/angular.js"/&gt;
      &lt;resource type="download" name="angular-animate.js" location="js/angular/angular-animate.js"/&gt;
      …
      &lt;resource type="download" name="page-move-dialog.js" location="js/page-move-dialog.js"/&gt;
      &lt;resource type="download" name="macro-editor-module.js" location="js/macro-editor-module.js"/&gt;
      …
  &lt;/web-resource&gt;
  </code></pre>
  
  <p>It looks like a Confluence ignore the contents of the file angular.js. What may be the reason of that behavior? Below, fragment of javascript file generated by the Confluence. It has no content of angular.js:</p>
  
  <pre><code>try {
  /* module-key = 'plugin.key:angular-sources', location = 'js/angular/angular.js' */
  // HERE SHOULD BE INCLUDED angular.js
  } catch (err) {
      if (console &amp;&amp; console.log &amp;&amp; console.error) {
          console.log("Error running batched script.");
          console.error(err);
      }
  }
  
  
  try {
  /* module-key = 'plugin.key:angular-sources', location = 'js/angular/angular-animate.js' */
  (function(b,a,c){a.module("ngAnimate",["ng"]).config(["$provide","$animateProvider",function(g,i){var l=a.noop;var f=a.forEach;var j=i.$$selectors;var e=1;var h="$$ngAnimateState";var k="ng-animate";var d={running:true};g.decorator("$animate",["$delegate","$injector","$sniffer","$rootElement","$timeout","$rootScope","$document",function(t,x,n,y,q,u,s){y.data(h,d);u.$$postDigest(function(){d.running=false});function p(B){if(B){var E=[],F={},D=B.substr(1).split(".");if(n.transitions||n.animations){D.push("")}for(var C=0;C&lt;D.length;C++){var z=D[C],A=j[z];if(A&amp;&amp;!F[z]){E.push(x.get(A));F[z]=true}}return E}}return{enter:function(B,A,C,z){this.enabled(false,B);t.enter(B,A,C);u.$$postDigest(function(){w("enter","ng-enter",B,A,C,l,z)})},leave:function(A,z){v(A);this.enabled(false,A);u.$$postDigest(function(){w("leave","ng-leave",A,null,null,function(){t.leave(A)},z)})},move:function(B,A,C,z){v(B);this.enabled(false,B);t.move(B,A,C);u.$$postDigest(function(){w("move","ng-move",B,A,C,l,z)})},addClass:function(A,B,z){w("addClass",B,A,null,null,function(){t.addClass(A,B)},z)},removeClass:function(A,B,z){w("removeClass",B,A,null,null,function(){t.removeClass(A,B)},z)},enabled:function(B,z){switch(arguments.length){case 2:if(B){o(z)}else{var A=z.data(h)||{};A.disabled=true;z.data(h,A)}break;case 1:d.disabled=!B;break;default:B=!d.disabled;break}return !!B}};function w(A,J,G,O,z,L,B){var D=(G.attr("class")||"")+" "+J;var I=(" "+D).replace(/\s+/g,".");if(!O){O=z?z.parent():G.parent()}var H=p(I);var K=A=="addClass"||A=="removeClass";var C=G.data(h)||{};if(m(G,O)||H.length===0){L();E();return}var P=[];if(!C.running||!(K&amp;&amp;C.structural)){f(H,function(Q){if(!Q.allowCancel||Q.allowCancel(G,A,J)){var S,R=Q[A];if(A=="leave"){S=R;R=null}else{S=Q["before"+A.charAt(0).toUpperCase()+A.substr(1)]}P.push({before:S,after:R})}})}if(P.length===0){L();M();return}if(C.running){q.cancel(C.closeAnimationTimeout);o(G);r(C.animations);(C.done||l)(true)}if((A=="addClass"&amp;&amp;G.hasClass(J))||(A=="removeClass"&amp;&amp;!G.hasClass(J))){L();M();return}G.addClass(k);G.data(h,{running:true,structural:!K,animations:P,done:N});F(P,"before",N);function N(Q){L();if(Q===true){E();return}var R=G.data(h);if(R){R.done=E;G.data(h,R)}F(P,"after",E)}function F(U,Q,T){var S=Q+"End";f(U,function(X,W){var V=function(){R(W,Q)};if(Q=="before"&amp;&amp;(A=="enter"||A=="move")){V();return}if(X[Q]){X[S]=K?X[Q](G,J,V):X[Q](G,V)}else{V()}});function R(W,V){var Z=V+"Complete";var Y=U[W];Y[Z]=true;(Y[S]||l)();for(var X=0;X&lt;U.length;X++){if(!U[X][Z]){return}}T()}}function M(){B&amp;&amp;q(B,0,false)}function E(){if(!E.hasBeenRun){E.hasBeenRun=true;var Q=G.data(h);if(Q){if(K){o(G)}else{Q.closeAnimationTimeout=q(function(){o(G)},0,false);G.data(h,Q)}}M()}}}function v(z){var A=z[0];if(A.nodeType!=e){return}f(A.querySelectorAll("."+k),function(B){B=a.element(B);var C=B.data(h);if(C){r(C.animations);o(B)}})}function r(A){var z=true;f(A,function(B){if(!A.beforeComplete){(B.beforeEnd||l)(z)}if(!A.afterComplete){(B.afterEnd||l)(z)}})}function o(z){if(z[0]==y[0]){if(!d.disabled){d.running=false;d.structural=false}}else{z.removeClass(k);z.removeData(h)}}function m(C,A){if(d.disabled){return true}if(C[0]==y[0]){return d.disabled||d.running}do{if(A.length===0){break}var B=A[0]==y[0];var D=B?d:A.data(h);var z=D&amp;&amp;(!!D.disabled||!!D.running);if(B||z){return z}if(B){return true}}while(A=A.parent());return true}}]);i.register("",["$window","$sniffer","$timeout",function(C,O,S){var R="",T,B,m,q;if(b.ontransitionend===c&amp;&amp;b.onwebkittransitionend!==c){R="-webkit-";T="WebkitTransition";B="webkitTransitionEnd transitionend"}else{T="transition";B="transitionend"}if(b.onanimationend===c&amp;&amp;b.onwebkitanimationend!==c){R="-webkit-";m="WebkitAnimation";q="webkitAnimationEnd animationend"}else{m="animation";q="animationend"}var w="Duration";var G="Property";var F="Delay";var N="IterationCount";var o="$$ngAnimateKey";var J="$$ngAnimateCSS3Data";var H="ng-animate-start";var K="ng-animate-active";var A={};var D=0;var y=[],E,I=false;function t(U){y.push(U);S.cancel(E);E=S(function(){f(y,function(V){V()});y=[];E=null;A={}},10,false)}function Q(X,V){var U=X.getAttribute("style")||"";var W=(U.length&gt;0?"; ":"")+V;X.setAttribute("style",W);return U}function M(Z,ac){var Y=ac?A[ac]:null;if(!Y){var X=0;var ab=0;var ae=0;var aa=0;var U;var W;var V;var ad;f(Z,function(ag){if(ag.nodeType==e){var af=C.getComputedStyle(ag)||{};V=af[T+w];X=Math.max(L(V),X);ad=af[T+G];U=af[T+F];ab=Math.max(L(U),ab);W=af[m+F];aa=Math.max(L(W),aa);var ah=L(af[m+w]);if(ah&gt;0){ah*=parseInt(af[m+N],10)||1}ae=Math.max(ah,ae)}});Y={total:0,transitionPropertyStyle:ad,transitionDurationStyle:V,transitionDelayStyle:U,transitionDelay:ab,transitionDuration:X,animationDelayStyle:W,animationDelay:aa,animationDuration:ae};if(ac){A[ac]=Y}}return Y}function L(W){var V=0;var U=a.isString(W)?W.split(/\s*,\s*/):[];f(U,function(X){V=Math.max(parseFloat(X)||0,V)});return V}function s(V){var U=V.parent();var W=U.data(o);if(!W){U.data(o,++D);W=D}return W+"-"+V[0].className}function x(aa,ae){var ad=s(aa);var ab=ad+" "+ae;var V={};var af=A[ab]?++A[ab].total:0;if(af&gt;0){var Z=ae+"-stagger";var U=ad+" "+Z;var ac=!A[U];ac&amp;&amp;aa.addClass(Z);V=M(aa,U);ac&amp;&amp;aa.removeClass(Z)}aa.addClass(ae);var Y=M(aa,ab);var X=Math.max(Y.transitionDuration,Y.animationDuration);if(X===0){aa.removeClass(ae);return false}var W=aa[0];var ag="";if(Y.transitionDuration&gt;0){aa.addClass(H);ag+=K+" ";W.style[T+G]="none"}f(ae.split(" "),function(ah,ai){ag+=(ai&gt;0?" ":"")+ah+"-active"});aa.data(J,{className:ae,activeClassName:ag,maxDuration:X,classes:ae+" "+ag,timings:Y,stagger:V,ii:af});return true}function u(V,X,ae){var ao=V.data(J);if(!V.hasClass(X)||!ao){ae();return}var ai=V[0];var aj=ao.timings;var am=ao.stagger;var ac=ao.maxDuration;var U=ao.activeClassName;var Y=Math.max(aj.transitionDelay,aj.animationDelay)*1000;var ah=Date.now();var Z=q+" "+B;var al;var af=ao.ii;var ad,ak="";if(aj.transitionDuration&gt;0){ai.style[T+G]="";var an=aj.transitionPropertyStyle;if(an.indexOf("all")==-1){ad=true;var W=O.msie?"-ms-zoom":"clip";ak+=R+"transition-property: "+an+", "+W+"; ";ak+=R+"transition-duration: "+aj.transitionDurationStyle+", "+aj.transitionDuration+"s; "}}if(af&gt;0){if(am.transitionDelay&gt;0&amp;&amp;am.transitionDuration===0){var ag=aj.transitionDelayStyle;if(ad){ag+=", "+aj.transitionDelay+"s"}ak+=R+"transition-delay: "+n(ag,am.transitionDelay,af)+"; "}if(am.animationDelay&gt;0&amp;&amp;am.animationDuration===0){ak+=R+"animation-delay: "+n(aj.animationDelayStyle,am.animationDelay,af)+"; "}}if(ak.length&gt;0){al=Q(ai,ak)}V.on(Z,aa);V.addClass(U);return function ab(ap){V.off(Z,aa);V.removeClass(U);v(V,X);if(al!=null){al.length&gt;0?ai.setAttribute("style",al):ai.removeAttribute("style")}};function aa(ar){ar.stopPropagation();var aq=ar.originalEvent||ar;var ap=aq.$manualTimeStamp||aq.timeStamp||Date.now();if(Math.max(ap-ah,0)&gt;=Y&amp;&amp;aq.elapsedTime&gt;=ac){ae()}}}function n(X,U,V){var W="";f(X.split(","),function(Z,Y){W+=(Y&gt;0?",":"")+(V*U+parseInt(Z,10))+"s"});return W}function z(U,V){if(x(U,V)){return function(W){W&amp;&amp;v(U,V)}}}function P(V,W,U){if(V.data(J)){return u(V,W,U)}else{v(V,W);U()}}function r(W,X,U){var V=z(W,X);if(!V){U();return}var Y=V;t(function(){Y=P(W,X,U)});return function(Z){(Y||l)(Z)}}function v(U,V){U.removeClass(V);U.removeClass(H);U.removeData(J)}return{allowCancel:function(W,Z,Y){var V=(W.data(J)||{}).classes;if(!V||["enter","leave","move"].indexOf(Z)&gt;=0){return true}var U=W.parent();var ab=a.element(W[0].cloneNode());ab.attr("style","position:absolute; top:-9999px; left:-9999px");ab.removeAttr("id");ab.html("");f(V.split(" "),function(ac){ab.removeClass(ac)});var aa=Z=="addClass"?"-add":"-remove";ab.addClass(p(Y,aa));U.append(ab);var X=M(ab);ab.remove();return Math.max(X.transitionDuration,X.animationDuration)&gt;0},enter:function(U,V){return r(U,"ng-enter",V)},leave:function(U,V){return r(U,"ng-leave",V)},move:function(U,V){return r(U,"ng-move",V)},beforeAddClass:function(U,V,W){var X=z(U,p(V,"-add"));if(X){t(W);return X}W()},addClass:function(U,V,W){return P(U,p(V,"-add"),W)},beforeRemoveClass:function(U,V,W){var X=z(U,p(V,"-remove"));if(X){t(W);return X}W()},removeClass:function(U,V,W){return P(U,p(V,"-remove"),W)}};function p(U,W){var V="";U=a.isArray(U)?U:U.split(/\s+/);f(U,function(X,Y){if(X&amp;&amp;X.length&gt;0){V+=(Y&gt;0?" ":"")+X+W}});return V}}])}])})(window,window.angular);
  } catch (err) {
      if (console &amp;&amp; console.log &amp;&amp; console.error) {
          console.log("Error running batched script.");
          console.error(err);
      }
  }
  </code></pre>
  
  <p>There is other way to include angular files to Confluence?</p>