diff --git a/dist/index.js b/dist/index.js index 8f2933b..b2ef7ab 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1,7 +1,7 @@ (function(){ var ldslider; ldslider = function(opt){ - var root, ro, i$, to$, i, that, handle, el, mouse, this$ = this; + var root, i$, to$, i, that, handle, ro, el, mouse, this$ = this; opt == null && (opt = {}); this.evtHandler = {}; this.opt = import$({ @@ -18,12 +18,6 @@ this.root = root = typeof opt.root === 'string' ? document.querySelector(opt.root) : opt.root; - if (typeof ResizeObserver != 'undefined' && ResizeObserver !== null) { - ro = new ResizeObserver(function(es){ - return this$.set(this$.get()); - }); - ro.observe(this.root); - } if (this.root.tagName === 'INPUT') { this.input = this.root; ld$.attr(this.input, 'type', 'hidden'); @@ -64,6 +58,12 @@ this.input.addEventListener('change', handle); this.input.addEventListener('input', handle); } + if (typeof ResizeObserver != 'undefined' && ResizeObserver !== null) { + ro = new ResizeObserver(function(es){ + return this$.set(this$.get()); + }); + ro.observe(this.root); + } this.root._ldrs = this; this.root.classList.add('ldrs'); this.root.innerHTML = "
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
"; diff --git a/dist/index.min.js b/dist/index.min.js index ff1e71a..5303938 100644 --- a/dist/index.min.js +++ b/dist/index.min.js @@ -1 +1 @@ -!function(){var t;function r(t,i){var e,s={}.hasOwnProperty;for(e in i)s.call(i,e)&&(t[e]=i[e]);return t}(t=function(t){var i,e,s,n,o,l=this;if(null==t&&(t={}),this.evtHandler={},this.opt=r({min:0,max:100,from:0,to:0,step:1},t),this.val={to:0,from:0},this.root=t="string"==typeof t.root?document.querySelector(t.root):t.root,"undefined"!=typeof ResizeObserver&&null!==ResizeObserver&&new ResizeObserver(function(t){return l.set(l.get())}).observe(this.root),"INPUT"===this.root.tagName){for(this.input=this.root,ld$.attr(this.input,"type","hidden"),this.root=t=document.createElement("div"),this.input.parentNode.insertBefore(this.root,this.input),i=0,e=this.input.classList.length;i\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n\n
\n
\n
',this.el=n={b:{fg:ld$.find(t,".fg",0)},p:ld$.find(t,".line.p",0),q:ld$.find(t,".line.p.alt",0),h:{p:ld$.find(t,".hint.p",0),q:ld$.find(t,".hint.p.alt",0),l:ld$.find(t,".hint.l",0),r:ld$.find(t,".hint.r",0),lock:ld$.find(t,".hint.lock",0),lockLine:ld$.find(t,".lock-line",0)}},o={move:function(t){return 1&t.buttons?l.repos(t.clientX,!0,!0,!1,o.alt):o.up(t)},up:function(){var t;return document.removeEventListener("mouseup",o.up),document.removeEventListener("mousemove",o.move),(t=o.alt?[l.el.h.q,l.val.to]:[l.el.h.p,l.val.from])[0].innerText=l.label.ptr(Math.round(1e4*t[1])/1e4)},prepare:function(t){return o.alt=!!(t.target&&t.target.classList&&t.target.classList.contains("alt")),document.addEventListener("mousemove",o.move),document.addEventListener("mouseup",o.up)}},n.p.addEventListener("mousedown",o.prepare),t.addEventListener("click",o.move),t.addEventListener("mousedown",o.prepare),this.prepare(),this}).prototype=r(Object.create(Object.prototype),{on:function(t,i){var e;return((e=this.evtHandler)[t]||(e[t]=[])).push(i)},fire:function(t){for(var i,e,s,n,o=[],l=[],r=1,a=arguments.length;r(m=this.opt.min)?d:m)<(f=this.opt.max)?u:f,this.val[o]=x,v={},u=this.val)t=u[c],!this.range&&"to"===c||(p=null!=this.opt.limitMax?t>this.opt.limitMax?(t-this.opt.limitMax)/(this.opt.max-this.opt.limitMax)*40+60:this.expFactor?60*Math.pow((t-this.opt.min)/(this.opt.limitMax-this.opt.min),1/this.expFactor):60*(t-this.opt.min)/(this.opt.limitMax-this.opt.min):this.expFactor?100*Math.pow((t-this.opt.min)/(this.opt.max-this.opt.min),1/this.expFactor):(t-this.opt.min)/(this.opt.max-this.opt.min)*100,null!=this.opt.limitMax&&this.opt.limitHard&&(60this.opt.limitMax&&(t=this.opt.limitMax)),this.val[c]=t,v[c]=p);if(p=v[o],t=this.val[o],f=this.range?Math.min(v.from,v.to)+.5:0,x=this.range?Math.max(v.from,v.to)-f+.5:v.from,r.getBoundingClientRect(),r.innerText=this.label.ptr(Math.round(1e4*t)/1e4),r.style.left=.01*p*h.width*100/h.width+"%",r.style.transform="translate(-50%,0)",a.style.left=p+"%",this.el.b.fg.style.width=x+"%",this.el.b.fg.style.left=f+"%",t!==l&&i&&this.fire("change",this.range?this.val:this.val[o]),this.input)return this.updateInput({now:!s})}}),"undefined"!=typeof module&&null!==module?module.exports=t:"undefined"!=typeof window&&null!==window&&(window.ldslider=t)}.call(this); +!function(){var t;function r(t,i){var e,s={}.hasOwnProperty;for(e in i)s.call(i,e)&&(t[e]=i[e]);return t}(t=function(t){var i,e,s,n,o,l=this;if(null==t&&(t={}),this.evtHandler={},this.opt=r({min:0,max:100,from:0,to:0,step:1},t),this.val={to:0,from:0},this.root=t="string"==typeof t.root?document.querySelector(t.root):t.root,"INPUT"===this.root.tagName){for(this.input=this.root,ld$.attr(this.input,"type","hidden"),this.root=t=document.createElement("div"),this.input.parentNode.insertBefore(this.root,this.input),i=0,e=this.input.classList.length;i\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n\n
\n
\n
',this.el=n={b:{fg:ld$.find(t,".fg",0)},p:ld$.find(t,".line.p",0),q:ld$.find(t,".line.p.alt",0),h:{p:ld$.find(t,".hint.p",0),q:ld$.find(t,".hint.p.alt",0),l:ld$.find(t,".hint.l",0),r:ld$.find(t,".hint.r",0),lock:ld$.find(t,".hint.lock",0),lockLine:ld$.find(t,".lock-line",0)}},o={move:function(t){return 1&t.buttons?l.repos(t.clientX,!0,!0,!1,o.alt):o.up(t)},up:function(){var t;return document.removeEventListener("mouseup",o.up),document.removeEventListener("mousemove",o.move),(t=o.alt?[l.el.h.q,l.val.to]:[l.el.h.p,l.val.from])[0].innerText=l.label.ptr(Math.round(1e4*t[1])/1e4)},prepare:function(t){return o.alt=!!(t.target&&t.target.classList&&t.target.classList.contains("alt")),document.addEventListener("mousemove",o.move),document.addEventListener("mouseup",o.up)}},n.p.addEventListener("mousedown",o.prepare),t.addEventListener("click",o.move),t.addEventListener("mousedown",o.prepare),this.prepare(),this}).prototype=r(Object.create(Object.prototype),{on:function(t,i){var e;return((e=this.evtHandler)[t]||(e[t]=[])).push(i)},fire:function(t){for(var i,e,s,n,o=[],l=[],r=1,a=arguments.length;r(m=this.opt.min)?d:m)<(f=this.opt.max)?u:f,this.val[o]=x,v={},u=this.val)t=u[c],!this.range&&"to"===c||(p=null!=this.opt.limitMax?t>this.opt.limitMax?(t-this.opt.limitMax)/(this.opt.max-this.opt.limitMax)*40+60:this.expFactor?60*Math.pow((t-this.opt.min)/(this.opt.limitMax-this.opt.min),1/this.expFactor):60*(t-this.opt.min)/(this.opt.limitMax-this.opt.min):this.expFactor?100*Math.pow((t-this.opt.min)/(this.opt.max-this.opt.min),1/this.expFactor):(t-this.opt.min)/(this.opt.max-this.opt.min)*100,null!=this.opt.limitMax&&this.opt.limitHard&&(60this.opt.limitMax&&(t=this.opt.limitMax)),this.val[c]=t,v[c]=p);if(p=v[o],t=this.val[o],f=this.range?Math.min(v.from,v.to)+.5:0,x=this.range?Math.max(v.from,v.to)-f+.5:v.from,r.getBoundingClientRect(),r.innerText=this.label.ptr(Math.round(1e4*t)/1e4),r.style.left=.01*p*h.width*100/h.width+"%",r.style.transform="translate(-50%,0)",a.style.left=p+"%",this.el.b.fg.style.width=x+"%",this.el.b.fg.style.left=f+"%",t!==l&&i&&this.fire("change",this.range?this.val:this.val[o]),this.input)return this.updateInput({now:!s})}}),"undefined"!=typeof module&&null!==module?module.exports=t:"undefined"!=typeof window&&null!==window&&(window.ldslider=t)}.call(this); diff --git a/src/index.ls b/src/index.ls index 1588353..27d6772 100644 --- a/src/index.ls +++ b/src/index.ls @@ -2,9 +2,6 @@ ldslider = (opt={}) -> @ <<< evt-handler: {}, opt: {min: 0, max: 100, from: 0, to: 0, step: 1} <<< opt @val = {to: 0, from: 0} @root = root = if typeof(opt.root) == \string => document.querySelector(opt.root) else opt.root - if ResizeObserver? => - ro = new ResizeObserver (es) ~> @set @get! - ro.observe @root if @root.tagName == \INPUT => @input = @root ld$.attr @input, \type, \hidden @@ -28,6 +25,10 @@ ldslider = (opt={}) -> @input.addEventListener \change, handle @input.addEventListener \input, handle + if ResizeObserver? => + ro = new ResizeObserver (es) ~> @set @get! + ro.observe @root + @root._ldrs = @ @root.classList.add \ldrs @root.innerHTML = """ diff --git a/web/static/assets/lib/ldslider/dev/index.js b/web/static/assets/lib/ldslider/dev/index.js index 8f2933b..b2ef7ab 100644 --- a/web/static/assets/lib/ldslider/dev/index.js +++ b/web/static/assets/lib/ldslider/dev/index.js @@ -1,7 +1,7 @@ (function(){ var ldslider; ldslider = function(opt){ - var root, ro, i$, to$, i, that, handle, el, mouse, this$ = this; + var root, i$, to$, i, that, handle, ro, el, mouse, this$ = this; opt == null && (opt = {}); this.evtHandler = {}; this.opt = import$({ @@ -18,12 +18,6 @@ this.root = root = typeof opt.root === 'string' ? document.querySelector(opt.root) : opt.root; - if (typeof ResizeObserver != 'undefined' && ResizeObserver !== null) { - ro = new ResizeObserver(function(es){ - return this$.set(this$.get()); - }); - ro.observe(this.root); - } if (this.root.tagName === 'INPUT') { this.input = this.root; ld$.attr(this.input, 'type', 'hidden'); @@ -64,6 +58,12 @@ this.input.addEventListener('change', handle); this.input.addEventListener('input', handle); } + if (typeof ResizeObserver != 'undefined' && ResizeObserver !== null) { + ro = new ResizeObserver(function(es){ + return this$.set(this$.get()); + }); + ro.observe(this.root); + } this.root._ldrs = this; this.root.classList.add('ldrs'); this.root.innerHTML = "
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
"; diff --git a/web/static/assets/lib/ldslider/dev/index.min.js b/web/static/assets/lib/ldslider/dev/index.min.js index ff1e71a..5303938 100644 --- a/web/static/assets/lib/ldslider/dev/index.min.js +++ b/web/static/assets/lib/ldslider/dev/index.min.js @@ -1 +1 @@ -!function(){var t;function r(t,i){var e,s={}.hasOwnProperty;for(e in i)s.call(i,e)&&(t[e]=i[e]);return t}(t=function(t){var i,e,s,n,o,l=this;if(null==t&&(t={}),this.evtHandler={},this.opt=r({min:0,max:100,from:0,to:0,step:1},t),this.val={to:0,from:0},this.root=t="string"==typeof t.root?document.querySelector(t.root):t.root,"undefined"!=typeof ResizeObserver&&null!==ResizeObserver&&new ResizeObserver(function(t){return l.set(l.get())}).observe(this.root),"INPUT"===this.root.tagName){for(this.input=this.root,ld$.attr(this.input,"type","hidden"),this.root=t=document.createElement("div"),this.input.parentNode.insertBefore(this.root,this.input),i=0,e=this.input.classList.length;i\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n\n
\n
\n
',this.el=n={b:{fg:ld$.find(t,".fg",0)},p:ld$.find(t,".line.p",0),q:ld$.find(t,".line.p.alt",0),h:{p:ld$.find(t,".hint.p",0),q:ld$.find(t,".hint.p.alt",0),l:ld$.find(t,".hint.l",0),r:ld$.find(t,".hint.r",0),lock:ld$.find(t,".hint.lock",0),lockLine:ld$.find(t,".lock-line",0)}},o={move:function(t){return 1&t.buttons?l.repos(t.clientX,!0,!0,!1,o.alt):o.up(t)},up:function(){var t;return document.removeEventListener("mouseup",o.up),document.removeEventListener("mousemove",o.move),(t=o.alt?[l.el.h.q,l.val.to]:[l.el.h.p,l.val.from])[0].innerText=l.label.ptr(Math.round(1e4*t[1])/1e4)},prepare:function(t){return o.alt=!!(t.target&&t.target.classList&&t.target.classList.contains("alt")),document.addEventListener("mousemove",o.move),document.addEventListener("mouseup",o.up)}},n.p.addEventListener("mousedown",o.prepare),t.addEventListener("click",o.move),t.addEventListener("mousedown",o.prepare),this.prepare(),this}).prototype=r(Object.create(Object.prototype),{on:function(t,i){var e;return((e=this.evtHandler)[t]||(e[t]=[])).push(i)},fire:function(t){for(var i,e,s,n,o=[],l=[],r=1,a=arguments.length;r(m=this.opt.min)?d:m)<(f=this.opt.max)?u:f,this.val[o]=x,v={},u=this.val)t=u[c],!this.range&&"to"===c||(p=null!=this.opt.limitMax?t>this.opt.limitMax?(t-this.opt.limitMax)/(this.opt.max-this.opt.limitMax)*40+60:this.expFactor?60*Math.pow((t-this.opt.min)/(this.opt.limitMax-this.opt.min),1/this.expFactor):60*(t-this.opt.min)/(this.opt.limitMax-this.opt.min):this.expFactor?100*Math.pow((t-this.opt.min)/(this.opt.max-this.opt.min),1/this.expFactor):(t-this.opt.min)/(this.opt.max-this.opt.min)*100,null!=this.opt.limitMax&&this.opt.limitHard&&(60this.opt.limitMax&&(t=this.opt.limitMax)),this.val[c]=t,v[c]=p);if(p=v[o],t=this.val[o],f=this.range?Math.min(v.from,v.to)+.5:0,x=this.range?Math.max(v.from,v.to)-f+.5:v.from,r.getBoundingClientRect(),r.innerText=this.label.ptr(Math.round(1e4*t)/1e4),r.style.left=.01*p*h.width*100/h.width+"%",r.style.transform="translate(-50%,0)",a.style.left=p+"%",this.el.b.fg.style.width=x+"%",this.el.b.fg.style.left=f+"%",t!==l&&i&&this.fire("change",this.range?this.val:this.val[o]),this.input)return this.updateInput({now:!s})}}),"undefined"!=typeof module&&null!==module?module.exports=t:"undefined"!=typeof window&&null!==window&&(window.ldslider=t)}.call(this); +!function(){var t;function r(t,i){var e,s={}.hasOwnProperty;for(e in i)s.call(i,e)&&(t[e]=i[e]);return t}(t=function(t){var i,e,s,n,o,l=this;if(null==t&&(t={}),this.evtHandler={},this.opt=r({min:0,max:100,from:0,to:0,step:1},t),this.val={to:0,from:0},this.root=t="string"==typeof t.root?document.querySelector(t.root):t.root,"INPUT"===this.root.tagName){for(this.input=this.root,ld$.attr(this.input,"type","hidden"),this.root=t=document.createElement("div"),this.input.parentNode.insertBefore(this.root,this.input),i=0,e=this.input.classList.length;i\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n\n
\n
\n
',this.el=n={b:{fg:ld$.find(t,".fg",0)},p:ld$.find(t,".line.p",0),q:ld$.find(t,".line.p.alt",0),h:{p:ld$.find(t,".hint.p",0),q:ld$.find(t,".hint.p.alt",0),l:ld$.find(t,".hint.l",0),r:ld$.find(t,".hint.r",0),lock:ld$.find(t,".hint.lock",0),lockLine:ld$.find(t,".lock-line",0)}},o={move:function(t){return 1&t.buttons?l.repos(t.clientX,!0,!0,!1,o.alt):o.up(t)},up:function(){var t;return document.removeEventListener("mouseup",o.up),document.removeEventListener("mousemove",o.move),(t=o.alt?[l.el.h.q,l.val.to]:[l.el.h.p,l.val.from])[0].innerText=l.label.ptr(Math.round(1e4*t[1])/1e4)},prepare:function(t){return o.alt=!!(t.target&&t.target.classList&&t.target.classList.contains("alt")),document.addEventListener("mousemove",o.move),document.addEventListener("mouseup",o.up)}},n.p.addEventListener("mousedown",o.prepare),t.addEventListener("click",o.move),t.addEventListener("mousedown",o.prepare),this.prepare(),this}).prototype=r(Object.create(Object.prototype),{on:function(t,i){var e;return((e=this.evtHandler)[t]||(e[t]=[])).push(i)},fire:function(t){for(var i,e,s,n,o=[],l=[],r=1,a=arguments.length;r(m=this.opt.min)?d:m)<(f=this.opt.max)?u:f,this.val[o]=x,v={},u=this.val)t=u[c],!this.range&&"to"===c||(p=null!=this.opt.limitMax?t>this.opt.limitMax?(t-this.opt.limitMax)/(this.opt.max-this.opt.limitMax)*40+60:this.expFactor?60*Math.pow((t-this.opt.min)/(this.opt.limitMax-this.opt.min),1/this.expFactor):60*(t-this.opt.min)/(this.opt.limitMax-this.opt.min):this.expFactor?100*Math.pow((t-this.opt.min)/(this.opt.max-this.opt.min),1/this.expFactor):(t-this.opt.min)/(this.opt.max-this.opt.min)*100,null!=this.opt.limitMax&&this.opt.limitHard&&(60this.opt.limitMax&&(t=this.opt.limitMax)),this.val[c]=t,v[c]=p);if(p=v[o],t=this.val[o],f=this.range?Math.min(v.from,v.to)+.5:0,x=this.range?Math.max(v.from,v.to)-f+.5:v.from,r.getBoundingClientRect(),r.innerText=this.label.ptr(Math.round(1e4*t)/1e4),r.style.left=.01*p*h.width*100/h.width+"%",r.style.transform="translate(-50%,0)",a.style.left=p+"%",this.el.b.fg.style.width=x+"%",this.el.b.fg.style.left=f+"%",t!==l&&i&&this.fire("change",this.range?this.val:this.val[o]),this.input)return this.updateInput({now:!s})}}),"undefined"!=typeof module&&null!==module?module.exports=t:"undefined"!=typeof window&&null!==window&&(window.ldslider=t)}.call(this);