forked from Hacklone/ng-grid-panel
-
Notifications
You must be signed in to change notification settings - Fork 1
/
ng-grid-panel.min.js
6 lines (6 loc) · 2.3 KB
/
ng-grid-panel.min.js
1
2
3
4
5
6
/**
* @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:"&",onPanelUpdate:"&"},compile:function(o,a){function l(){var e=o.find("grid-panel-item:first, .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-last:first, .grid-panel-last").clone();if(!e.length)throw new Error("grid-panel-item template must be set");return e}function u(){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 f=angular.element(t),s=angular.element(r).find("html, body"),d=l(),p=c(),m=u();if(!a.repeat)throw new Error("repeat attribute must be set");var g=a.repeat.match(/\s?(.*)\sin\s(.*)\s?/);if(!g||g.length<3)throw new Error('repeat attribute must be set like repeat="item in items"');var v,h,w,$=g[1],b=g[2];return{pre:function(t,r){function o(){t.$parent.$watchCollection(b,a)}function a(i){r.empty();var o=p.clone();e.enter(o,r),n(o)(t.$new(!1,t.$parent));for(var a=0,c=i.length;c>a;a++){var u=t.$new(!1,t.$parent),f=i[a];u[$]=f;var s=d.clone();s.addClass("grid-panel-item-"+a).on("click",function(e,n){return function(){l(e,n)}}(a,f)),e.enter(s,r),n(s)(u)}}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(){h=E;d(),w=t.$new(!1,t.$parent),v=m.clone(),v.find(".close-x").on("click",function(e){return function(){d(),t.onPanelClosed({item:e})}}(a)),e.enter(v,null,P),n(v)(w),u(),t.onPanelOpened({item:a})}function u(){w[$]=a,w.$digest(),t.onPanelUpdate({item:a})}function d(){v&&(e.leave(v),v=void 0),w&&(w.$destroy(),w=void 0),t.$digest()}function p(){function e(){var e=v.offset().top,n=f.scrollTop()+f.height()/2;e>n&&s.animate({scrollTop:e-2*b.outerHeight(!0)},500)}v&&i(e,350)}function g(){v&&v.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");v&&h===E?u():c(),g(),p()}o()}}}}}]);