UNPKG

2.78 kBJavaScriptView Raw
1!function(){"use strict";window.Ractive.controller("pl-grouped-buttons",function(t,o,e,n,i){function c(t){t.on("showNotification",function(o){var e=parseInt($(t.el).attr("data-index"),10);d.once("positionsChanged",function(){d.set("compactPositionsTop["+e+"]",0),d.set("compactPositions["+e+"]",0),d.get("mode")==s.COMPACT&&d.set("compactButtonPosition",-100)}),d.set("buttons["+e+"].width",o.width+5)}),t.on("hideNotification",function(){var o=parseInt($(t.el).attr("data-index"),10);d.set("buttons["+o+"].width",50),d.get("mode")==s.COMPACT&&d.set("compactButtonPosition",-15)})}function a(t){d.require().then(function(){for(var o=d.get("orientation"),e=d.get("buttons"),n=d.get("positions"),i=d.get("compactPositionsTop"),a=d.get("compactPositions"),s=d.get("compactOpened"),p=d.get("hidden"),u=$(window).width(),m=0,r=20,f=0,h=60,g=e.length-1;g>=0;g--){var P=e[g],C=d.findChild("data-index",g);if(p?(n[g]=-100,a[g]=-100):(n[g]=m-("right"==o&&"indicator"==P.type?5:0),s?a[g]=r:a[g]=-100),i[g]=f,!C)return;P.isReady||(P.isReady=!0,P.width=50,"indicator"==P.type&&c(C,P,g),P.ready&&P.ready(C)),m+=P.width||0,r+=P.width||0,!p&&r>u&&(h+=50,f+=50,r=20,i[g]=f,s&&(a[g]=r))}d.set("positions",n),d.set("compactPositionsTop",i),d.set("compactPositions",a),setTimeout(function(){d.fire("positionsChanged")}),t&&t({compactHeight:h})})}var s={DEFAULT:"default",COMPACT:"compact"},d=t({plName:"pl-grouped-buttons",data:$.extend(!0,{mode:s.DEFAULT,hidden:!0,orientation:"left",buttons:[],positions:[],compactPositionsTop:[],compactPositions:[],compactButtonPosition:-100,compactOpened:!1,compactHeight:0,action:function(t,o,e){if(o){var n=parseInt($(o.el).attr("data-index"),10),i=d.get("buttons["+n+"]"),o=d.findChild("data-index",n);d.fire("beforeAction",{event:t,button:i,component:o,userBehavior:e}),d.get("mode")==s.COMPACT&&d.get("compactOpened")&&d.fire("compactAction"),i&&i.action&&i.action(t,o,e),d.fire("action",{event:t,button:i,component:o,userBehavior:e})}}},o),hide:function(){d.get("hidden")||(d.set("hidden",!0),d.set("compactButtonPosition",-100),a())},show:function(){d.get("hidden")&&(d.set("hidden",!1),d.get("mode")==s.COMPACT&&d.set("compactButtonPosition",-15),a())},compactMode:function(){d.get("mode")!=s.COMPACT&&(d.set("mode",s.COMPACT),d.set("compactButtonPosition",-15))},defaultMode:function(){d.get("mode")!=s.DEFAULT&&(d.get("compactOpened")&&d.fire("compactAction"),d.set("mode",s.DEFAULT),d.set("compactButtonPosition",-100))}});d.on("compactAction",function(){var t=!d.get("compactOpened");d.fire("beforeCompact",{button:d,opened:t}),d.set("compactOpened",t),a(function(o){t&&d.set("compactHeight",o.compactHeight),d.fire("compact",{button:d,opened:t})})}),d.observe("buttons",function(){a()}),a(),i()})}();
2//# sourceMappingURL=pl-grouped-buttons.min.js.map