You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
7.4 KiB
JavaScript

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.bulmaSlider=e():t.bulmaSlider=e()}(self,function(){return(()=>{"use strict";var n={d:(t,e)=>{for(var r in e)n.o(e,r)&&!n.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},t={};n.d(t,{default:()=>o});var e,u=(function(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}((e=r).prototype,[{key:"listenerCount",value:function(t){return this._listeners.has(t)?this._listeners.get(t).length:0}},{key:"removeListeners",value:function(){var e=this,t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:null,r=1<arguments.length&&void 0!==arguments[1]&&arguments[1];null!==t?Array.isArray(t)?name.forEach(function(t){return e.removeListeners(t,r)}):(this._listeners.delete(t),r&&this.removeMiddleware(t)):this._listeners=new Map}},{key:"middleware",value:function(t,e){var r=this;Array.isArray(t)?name.forEach(function(t){return r.middleware(t,e)}):(Array.isArray(this._middlewares.get(t))||this._middlewares.set(t,[]),this._middlewares.get(t).push(e))}},{key:"removeMiddleware",value:function(){var e=this,t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:null;null!==t?Array.isArray(t)?name.forEach(function(t){return e.removeMiddleware(t)}):this._middlewares.delete(t):this._middlewares=new Map}},{key:"on",value:function(t,e){var r,n=this,o=2<arguments.length&&void 0!==arguments[2]&&arguments[2];Array.isArray(t)?t.forEach(function(t){return n.on(t,e)}):1<(r=(t=t.toString()).split(/,|, | /)).length?r.forEach(function(t){return n.on(t,e)}):(Array.isArray(this._listeners.get(t))||this._listeners.set(t,[]),this._listeners.get(t).push({once:o,callback:e}))}},{key:"once",value:function(t,e){this.on(t,e,!0)}},{key:"emit",value:function(r,n){var o=this,i=2<arguments.length&&void 0!==arguments[2]&&arguments[2];r=r.toString();var u=this._listeners.get(r),l=null,a=0,s=i;if(Array.isArray(u))for(u.forEach(function(t,e){i||(l=o._middlewares.get(r),Array.isArray(l)?(l.forEach(function(t){t(n,function(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:null;null!==t&&(n=t),a++},r)}),a>=l.length&&(s=!0)):s=!0),s&&(t.once&&(u[e]=null),t.callback(n))});-1!==u.indexOf(null);)u.splice(u.indexOf(null),1)}}]),Object.defineProperty(e,"prototype",{writable:!1}),r);function r(){var t=0<arguments.length&&void 0!==arguments[0]?arguments[0]:[];(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")})(this,r),this._listeners=new Map(t),this._middlewares=new Map}function i(e,t){var r,n=Object.keys(e);return Object.getOwnPropertySymbols&&(r=Object.getOwnPropertySymbols(e),t&&(r=r.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,r)),n}function l(n){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?i(Object(o),!0).forEach(function(t){var e,r;e=n,t=o[r=t],r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t}):Object.getOwnPropertyDescriptors?Object.defineProperties(n,Object.getOwnPropertyDescriptors(o)):i(Object(o)).forEach(function(t){Object.defineProperty(n,t,Object.getOwnPropertyDescriptor(o,t))})}return n}function a(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function s(t,e){return(s=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function c(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function f(t){return(f=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function p(t){return(p="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}var o=function(){!function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),s(t,e)}(i,u);var t,e,r,n,o=(r=i,n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],function(){})),!0}catch(t){return!1}}(),function(){var t,e=f(r);return function(t,e){if(e&&("object"===p(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return c(t)}(this,n?(t=f(this).constructor,Reflect.construct(e,arguments,t)):e.apply(this,arguments))});function i(t){var e,r=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{};if(function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,i),(e=o.call(this)).element="string"==typeof t?document.querySelector(t):t,!e.element)throw new Error("An invalid selector or non-DOM node has been provided.");return e._clickEvents=["click"],e.options=l({},r),e.onSliderInput=e.onSliderInput.bind(c(e)),e.init(),e}return e=[{key:"attach",value:function(){var t,r=this,e=0<arguments.length&&void 0!==arguments[0]?arguments[0]:'input[type="range"].slider',n=1<arguments.length&&void 0!==arguments[1]?arguments[1]:{},o=new Array;return("string"==typeof(t=e)||!!t&&"object"===p(t)&&"[object String]"===Object.prototype.toString.call(t)?document.querySelectorAll(e):Array.isArray(e)?e:[e]).forEach(function(t){var e;void 0===t[r.constructor.name]?(e=new i(t,n),t[r.constructor.name]=e,o.push(e)):o.push(t[r.constructor.name])}),o}}],a((t=i).prototype,[{key:"init",value:function(){var t;this._id="bulmaSlider"+(new Date).getTime()+Math.floor(Math.random()*Math.floor(9999)),this.output=this._findOutputForSlider(),this._bindEvents(),this.output&&this.element.classList.contains("has-output-tooltip")&&(t=this._getSliderOutputPosition(),this.output.style.left=t.position),this.emit("bulmaslider:ready",this.element.value)}},{key:"_findOutputForSlider",value:function(){var e=this,r=null,t=document.getElementsByTagName("output")||[];return Array.from(t).forEach(function(t){if(t.htmlFor==e.element.getAttribute("id"))return r=t,!0}),r}},{key:"_getSliderOutputPosition",value:function(){var t=window.getComputedStyle(this.element,null),e=parseInt(t.getPropertyValue("width"),10),t=this.element.getAttribute("min")?this.element.getAttribute("min"):0,t=(this.element.value-t)/(this.element.getAttribute("max")-t);return{position:(t<0?0:1<t?e:e*t)+"px"}}},{key:"_bindEvents",value:function(){this.output&&this.element.addEventListener("input",this.onSliderInput,!1)}},{key:"onSliderInput",value:function(t){t.preventDefault(),this.element.classList.contains("has-output-tooltip")&&(e=this._getSliderOutputPosition(),this.output.style.left=e.position);var t=this.output.hasAttribute("data-prefix")?this.output.getAttribute("data-prefix"):"",e=this.output.hasAttribute("data-postfix")?this.output.getAttribute("data-postfix"):"";this.output.value=t+this.element.value+e,this.emit("bulmaslider:ready",this.element.value)}}]),a(t,e),Object.defineProperty(t,"prototype",{writable:!1}),i}();return t.default})()});