bulma-slider
Version:
Display classic slider more sexy, in different colors, sizes, and states
1 lines • 7.73 kB
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 t={d:(e,r)=>{for(var n in r)t.o(r,n)&&!t.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:r[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};function r(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function n(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)}}t.d(e,{default:()=>v});var i=function(){function t(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];r(this,t),this._listeners=new Map(e),this._middlewares=new Map}var e,i;return e=t,i=[{key:"listenerCount",value:function(t){return this._listeners.has(t)?this._listeners.get(t).length:0}},{key:"removeListeners",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null,r=arguments.length>1&&void 0!==arguments[1]&&arguments[1];null!==e?Array.isArray(e)?name.forEach((function(e){return t.removeListeners(e,r)})):(this._listeners.delete(e),r&&this.removeMiddleware(e)):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 t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;null!==e?Array.isArray(e)?name.forEach((function(e){return t.removeMiddleware(e)})):this._middlewares.delete(e):this._middlewares=new Map}},{key:"on",value:function(t,e){var r=this,n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(Array.isArray(t))t.forEach((function(t){return r.on(t,e)}));else{var i=(t=t.toString()).split(/,|, | /);i.length>1?i.forEach((function(t){return r.on(t,e)})):(Array.isArray(this._listeners.get(t))||this._listeners.set(t,[]),this._listeners.get(t).push({once:n,callback:e}))}}},{key:"once",value:function(t,e){this.on(t,e,!0)}},{key:"emit",value:function(t,e){var r=this,n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];t=t.toString();var i=this._listeners.get(t),o=null,u=0,l=n;if(Array.isArray(i))for(i.forEach((function(a,s){n||(o=r._middlewares.get(t),Array.isArray(o)?(o.forEach((function(r){r(e,(function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:null;null!==t&&(e=t),u++}),t)})),u>=o.length&&(l=!0)):l=!0),l&&(a.once&&(i[s]=null),a.callback(e))}));-1!==i.indexOf(null);)i.splice(i.indexOf(null),1)}}],i&&n(e.prototype,i),Object.defineProperty(e,"prototype",{writable:!1}),t}();function o(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),r.push.apply(r,n)}return r}function u(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?o(Object(r),!0).forEach((function(e){l(t,e,r[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):o(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}function l(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function a(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function s(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 c(t,e){return c=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},c(t,e)}function f(t,e){if(e&&("object"===y(e)||"function"==typeof e))return e;if(void 0!==e)throw new TypeError("Derived constructors may only return object or undefined");return p(t)}function p(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function h(t){return h=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},h(t)}function y(t){return y="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},y(t)}var d=function(t){return"string"==typeof t||!!t&&"object"===y(t)&&"[object String]"===Object.prototype.toString.call(t)},v=function(t){!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&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),Object.defineProperty(t,"prototype",{writable:!1}),e&&c(t,e)}(y,t);var e,r,n,i,o,l=(i=y,o=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=h(i);if(o){var r=h(this).constructor;t=Reflect.construct(e,arguments,r)}else t=e.apply(this,arguments);return f(this,t)});function y(t){var e,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(a(this,y),(e=l.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=u({},r),e.onSliderInput=e.onSliderInput.bind(p(e)),e.init(),e}return e=y,n=[{key:"attach",value:function(){var t=this,e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:'input[type="range"].slider',r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},n=new Array,i=d(e)?document.querySelectorAll(e):Array.isArray(e)?e:[e];return i.forEach((function(e){if(void 0===e[t.constructor.name]){var i=new y(e,r);e[t.constructor.name]=i,n.push(i)}else n.push(e[t.constructor.name])})),n}}],(r=[{key:"init",value:function(){if(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")){var t=this._getSliderOutputPosition();this.output.style.left=t.position}this.emit("bulmaslider:ready",this.element.value)}},{key:"_findOutputForSlider",value:function(){var t=this,e=null,r=document.getElementsByTagName("output")||[];return Array.from(r).forEach((function(r){if(r.htmlFor==t.element.getAttribute("id"))return e=r,!0})),e}},{key:"_getSliderOutputPosition",value:function(){var t,e=window.getComputedStyle(this.element,null),r=parseInt(e.getPropertyValue("width"),10);t=this.element.getAttribute("min")?this.element.getAttribute("min"):0;var n=(this.element.value-t)/(this.element.getAttribute("max")-t);return{position:(n<0?0:n>1?r:r*n)+"px"}}},{key:"_bindEvents",value:function(){this.output&&this.element.addEventListener("input",this.onSliderInput,!1)}},{key:"onSliderInput",value:function(t){if(t.preventDefault(),this.element.classList.contains("has-output-tooltip")){var e=this._getSliderOutputPosition();this.output.style.left=e.position}var r=this.output.hasAttribute("data-prefix")?this.output.getAttribute("data-prefix"):"",n=this.output.hasAttribute("data-postfix")?this.output.getAttribute("data-postfix"):"";this.output.value=r+this.element.value+n,this.emit("bulmaslider:ready",this.element.value)}}])&&s(e.prototype,r),n&&s(e,n),Object.defineProperty(e,"prototype",{writable:!1}),y}(i);return e.default})()}));