UNPKG

5.87 kBJavaScriptView Raw
1"use strict";function _interopDefault(t){return t&&"object"==typeof t&&"default"in t?t.default:t}var Util=_interopDefault(require("../util.js")),extendStatics=function(t,e){return(extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};function __extends(t,e){function r(){this.constructor=t}extendStatics(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}var Component=function(){function t(t,e,r){var n=this;this.template="",this.id=null,this.eventHandlers=[],this.registeredElements=[],this.name=t;var o="string"==typeof r.element?document.querySelector(r.element):r.element,s={};if(o){var i=Util.Selector.attrConfig(o);i&&(s=i)}this.defaultProps=e,this.props=Object.assign(e,s,r,{element:o}),this.id=this.uid(),this.elementListener=function(t){return n.onBeforeElementEvent(t)},this.setEventsHandler()}return t.prototype.setTemplate=function(t){this.template=t},t.prototype.getTemplate=function(){return this.template},t.prototype.getElement=function(){return this.getProp("element")||null},t.prototype.setElement=function(t){this.props.element=t},t.prototype.getId=function(){return this.id},t.prototype.uid=function(){return Math.random().toString(36).substr(2,10)},t.prototype.getName=function(){return this.name},t.prototype.getProps=function(){return this.props},t.prototype.getProp=function(t){var e=this.defaultProps[t];return void 0!==this.props[t]?this.props[t]:e},t.prototype.setProps=function(t){var e=Object.assign({},t);this.props=Object.assign(this.props,e)},t.prototype.setProp=function(t,e){if(void 0===this.props[t])throw new Error("Cannot set an invalid prop");this.props[t]=e},t.prototype.registerElements=function(t){var e=this;t.forEach(function(t){return e.registerElement(t)})},t.prototype.registerElement=function(t){t.target.addEventListener(t.event,this.elementListener),this.registeredElements.push(t)},t.prototype.unregisterElements=function(){var e=this;this.registeredElements.forEach(function(t){e.unregisterElement(t)})},t.prototype.unregisterElement=function(e){var t=this.registeredElements.findIndex(function(t){return t.target===e.target&&t.event===e.event});-1<t?(e.target.removeEventListener(e.event,this.elementListener),this.registeredElements.splice(t,1)):console.error("Warning! Could not remove element: "+e.target+" with event: "+e.event+".")},t.prototype.triggerEvent=function(t,e,r){var n=this;void 0===e&&(e={}),void 0===r&&(r=!1);var o=t.split(".").reduce(function(t,e,r){return 0===r?e:t+e.charAt(0).toUpperCase()+e.slice(1)}),s="on"+o.charAt(0).toUpperCase()+o.slice(1),i=this.getProps();if(this.eventHandlers.forEach(function(t){"function"==typeof t[o]&&t[o].apply(n,[e]),"function"==typeof t[s]&&i[s].apply(n,[e])}),!r){var p=this.getElement();p?Util.Dispatch.elementEvent(p,t,this.name,e):Util.Dispatch.winDocEvent(t,this.name,e)}},t.prototype.preventClosable=function(){return!1},t.prototype.destroy=function(){this.unregisterElements()},t.prototype.onElementEvent=function(t){},t.prototype.setEventsHandler=function(){var r=this.getProps(),t=Object.keys(r).reduce(function(t,e){return"function"==typeof r[e]&&(t[e]=r[e]),t},{});0<Object.keys(t).length&&this.eventHandlers.push(t)},t.prototype.onBeforeElementEvent=function(t){this.preventClosable()||this.onElementEvent(t)},t}(),Progress=function(r){function n(t){var e=r.call(this,"progress",{height:8,min:0,max:100,now:0,label:!1,striped:!1,animate:!0,background:null},t)||this;return e.onTransition=!1,e.setHeight(),e.setAccessibility(),e.getProp("striped")&&e.setStriped(),e.getProp("background")&&e.setBackground(),e.set(e.getProp("now")),e}return __extends(n,r),n.attachDOM=function(){Util.Observer.subscribe({componentClass:"progress",onAdded:function(t,e){e(new n({element:t}))},onRemoved:function(t,e){e("Progress",t)}})},n.prototype.set=function(t){void 0===t&&(t=0);var e=this.getProgressBar(),r=this.getProp("min"),n=this.getProp("max"),o=Math.round(t/(r+n)*100);return t<r?(console.error("Progress: Warning, "+t+" is under min value."),!1):n<t?(console.error("Progress: Warning, "+t+" is above max value."),!1):(e.setAttribute("aria-valuenow",""+t),this.getProp("label")&&(e.innerHTML=o+"%"),e.style.width=o+"%",!0)},n.prototype.animateProgressBar=function(t){if(void 0===t&&(t=!0),!this.getProp("striped"))throw new Error("Progress: Animation works only with striped progress.");var e=this.getProgressBar();return t&&!e.classList.contains("progress-bar-animated")&&e.classList.add("progress-bar-animated"),!t&&e.classList.contains("progress-bar-animated")&&e.classList.remove("progress-bar-animated"),!0},n.prototype.show=function(){return this.getElement().style.height=this.getProp("height")+"px",this.triggerEvent(Util.Event.SHOW),this.triggerEvent(Util.Event.SHOWN),!0},n.prototype.hide=function(){return this.getElement().style.height="0px",this.triggerEvent(Util.Event.HIDE),this.triggerEvent(Util.Event.HIDDEN),!0},n.prototype.destroy=function(){this.unregisterElements(),this.hide()},n.prototype.setHeight=function(){this.getElement().style.height=this.getProp("height")+"px"},n.prototype.setAccessibility=function(){var t=this.getElement();t.setAttribute("aria-valuemin",""+this.getProp("min")),t.setAttribute("aria-valuemax",""+this.getProp("max"))},n.prototype.setStriped=function(){this.getProgressBar().classList.add("progress-bar-striped"),this.getProp("animate")&&this.animateProgressBar()},n.prototype.setBackground=function(){var t=this.getProgressBar(),e=this.getProp("background");t.classList.contains("bg-"+e)&&t.classList.add("bg-"+e)},n.prototype.getProgressBar=function(){return this.getElement().querySelector(".progress-bar")},n}(Component);Progress.attachDOM(),module.exports=Progress;
2//# sourceMappingURL=/home/qathom/Workspaces/Web/phonon/dist/js/components/progress.min.js.map
\No newline at end of file