v-button
Version:
vButton - AngularJS pressable button with a busy indicator
9 lines (8 loc) • 2.06 kB
JavaScript
/**
* vButton - AngularJS pressable button with a busy indicator
* @version v1.2.1
* @link http://lukaszwatroba.github.io/v-button
* @author Łukasz Wątroba <l@lukaszwatroba.com>
* @license MIT License, http://www.opensource.org/licenses/MIT
*/
!function(t,e){"use strict";function n(t,n){return{restrict:"A",scope:{isBusy:"=vBusy",busyLabel:"@vBusyLabel",busyText:"@vBusyText"},compile:function(t,s){var o=e.element(t.find("span"));return o[0]||(t.html("<span>"+t.html()+"</span>"),o=e.element(t.find("span"))),function(t,e){var u=o.html(),i=t.busyLabel||n.busyLabel,a=t.busyText;t.$watch("isBusy",function(t){t?(e.addClass(n.states.busy),o.html(i)):(e.removeClass(n.states.busy),o.html(a||u))}),s.$observe("vBusyLabel",function(t){i=t}),s.$observe("vBusyText",function(t){a=t})}}}}function s(){return"ontouchstart"in t||t.navigator.MaxTouchPoints>0||t.navigator.msMaxTouchPoints>0}function o(t,n){return{restrict:"A",link:function(o,u){function i(n,s){var o,i,a=u[0].getBoundingClientRect(),c=u[0].querySelector("v-ripple");e.element(c).remove(),c=t[0].createElement("v-ripple"),c.style.height=c.style.width=Math.max(a.width,a.height)+"px",u.append(c),i=n-a.left-c.offsetWidth/2-f[0].scrollLeft,o=s-a.top-c.offsetHeight/2-f[0].scrollTop,c.style.left=i+"px",c.style.top=o+"px"}function a(){u.addClass(n.states.pressed),f.on(d,c)}function c(t){var e,s;r?(e=t.changedTouches[0].pageX,s=t.changedTouches[0].pageY):(e=t.pageX,s=t.pageY),i(e,s),u.removeClass(n.states.pressed),f.off(d,c)}var r=s(),l=r?"touchstart":"mousedown",d=r?"touchend":"mouseup",f=e.element(t[0].body);u.on(l,a),o.$on("$destroy",function(){u.off(l,a),f.off(d,c)})}}}e.module("vButton.config",[]).constant("buttonConfig",{busyLabel:"Loading",states:{busy:"is-busy",pressed:"is-pressed"}}),e.module("vButton.directives",[]),e.module("vButton",["vButton.config","vButton.directives"]),e.module("vButton.directives").directive("vBusy",n),n.$inject=["$document","buttonConfig"],e.module("vButton.directives").directive("vPressable",o),o.$inject=["$document","buttonConfig"]}(window,angular);