private-bower
Version:
A simple private bower registry
6 lines • 2.09 kB
JavaScript
/**
* @license ngGridPanel
* (c) 2014 Hacklone https://github.com/Hacklone
* License: MIT
*/
angular.module("ngGridPanel",["ngAnimate"]).directive("gridPanel",["$animate","$compile","$window","$document","$timeout",function(e,n,t,r,i){return{restrict:"AE",scope:{onPanelOpened:"&",onPanelClosed:"&"},compile:function(o,a){function l(){var e=o.find("grid-panel-item, .grid-panel-item").clone();if(!e.length)throw new Error("grid-panel-item template must be set");return e}function c(){var e=o.find("grid-panel-content, .grid-panel-content").clone();if(!e.length)throw new Error("grid-panel-content template must be set");return e.prepend(angular.element('<div class="close-x">')).prepend(angular.element('<div class="triangle">')),e}var u=angular.element(t),f=angular.element(r).find("html, body"),s=l(),d=c();if(!a.repeat)throw new Error("repeat attribute must be set");var p=a.repeat.match(/\s?(.*)\sin\s(.*)\s?/);if(!p||p.length<3)throw new Error('repeat attribute must be set like repeat="item in items"');var m,g,v,h=p[1],w=p[2];return{pre:function(t,r){function o(){t.$parent.$watchCollection(w,a)}function a(i){r.empty();for(var o=0,a=i.length;a>o;o++){var c=t.$new(),u=i[o];c[h]=u;var f=s.clone();f.addClass("grid-panel-item-"+o).on("click",function(e,n){return function(){l(e,n)}}(o,u)),e.enter(f,r),n(f)(c)}}function l(o,a){function l(e){for(var n=e,t=e.next();t.length&&n.offset().top===t.offset().top;)n=t,t=n.next();return n}function c(){g=E;var r=!!m;p(),v=t.$new(),v[h]=a,m=d.clone(),m.find(".close-x").on("click",function(e){return function(){p(),t.onPanelClosed({item:e})}}(a)),e.enter(m,null,P),n(m)(v),v.$digest(),r&&t.onPanelOpened({item:a})}function s(){v[h]=a,v.$digest()}function p(){m&&(e.leave(m),m=void 0),v&&(v.$destroy(),v=void 0),t.$digest()}function w(){function e(){var e=m.offset().top,n=u.scrollTop()+u.height()/2;e>n&&f.animate({scrollTop:e-2*b.outerHeight(!0)},500)}m&&i(e,350)}function $(){m&&m.find(".triangle").css({left:b.position().left+b.width()/2})}var b=r.find(".grid-panel-item-"+o),P=l(b),E=P.attr("class");m&&g===E?s():c(),$(),w()}o()}}}}}]);