11 lines
No EOL
17 KiB
JavaScript
11 lines
No EOL
17 KiB
JavaScript
/*
|
|
* # Fomantic UI - 2.9.2
|
|
* https://github.com/fomantic/Fomantic-UI
|
|
* https://fomantic-ui.com/
|
|
*
|
|
* Copyright 2023 Contributors
|
|
* Released under the MIT license
|
|
* https://opensource.org/licenses/MIT
|
|
*
|
|
*/
|
|
!function(Y,t,n){"use strict";t=void 0!==t&&t.Math===Math?t:globalThis,Y.fn.slider=function(S){var A,e=Y(this),F=Y(n),O=Y(t),N=e.selector||"",j=Date.now(),z=[],I=S,R="string"==typeof I,B=[].slice.call(arguments,1),U=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"],X=0;return e.each(function(){var l,r,s,u,e,c,d,t,m,v,f,g,o,b,i,h,p=Y.isPlainObject(S)?Y.extend(!0,{},Y.fn.slider.settings,S):Y.extend({},Y.fn.slider.settings),n=p.className,a=p.metadata,k=p.namespace,V=p.error,T=p.keys,y=p.interpretLabel,w=!1,M="."+k,x="module-"+k,P=Y(this),E=this,C=P.data(x),L=1,D={initialize:function(){D.debug("Initializing slider",p),h=!0,t=X+=1,D.setup.layout(),D.setup.labels(),D.is.disabled()||D.bind.events(),D.read.metadata(),D.read.settings(),h=!1,D.instantiate()},instantiate:function(){D.verbose("Storing instance of slider",D),C=D,P.data(x,D)},destroy:function(){D.verbose("Destroying previous slider for",P),clearInterval(C.interval),D.unbind.events(),D.unbind.slidingEvents(),P.removeData(x),C=void 0},setup:{layout:function(){void 0===P.attr("tabindex")&&P.attr("tabindex",0),0===P.find(".inner").length&&P.append("<div class='inner'><div class='track'></div><div class='track-fill'></div><div class='thumb'></div></div>"),o=D.get.precision(),s=P.find(".thumb:not(.second)"),l=s,D.is.range()&&(0===P.find(".thumb.second").length&&P.find(".inner").append("<div class='thumb second'></div>"),u=P.find(".thumb.second")),e=P.find(".track"),c=P.find(".track-fill"),g=s.width()/2},labels:function(){D.is.labeled()&&(0<(d=P.find(".labels:not(.auto)")).length?D.setup.customLabel():D.setup.autoLabel(),p.showLabelTicks&&P.addClass(n.ticked))},customLabel:function(){var n,e=d.find(".label"),a=e.length,o=D.get.min(),i=D.get.max();e.each(function(e){var t=Y(this).attr("data-value");n=t?((t=i<t?i:t<o?o:t)-o)/(i-o):(e+1)/(a+1),D.update.labelPosition(n,Y(this))})},autoLabel:function(){0<(d=P.find(".labels")).length?d.empty():d=P.append('<ul class="auto labels"></ul>').find(".labels");for(var e=0,t=D.get.numLabels();e<=t;e++){var n=D.get.label(e),n=""!==n?e%D.get.gapRatio()?Y('<li class="halftick label"></li>'):Y('<li class="label">'+n+"</li>"):null;n&&(D.update.labelPosition(e/t,n),d.append(n))}}},bind:{events:function(){D.bind.globalKeyboardEvents(),D.bind.keyboardEvents(),D.bind.mouseEvents(),p.autoAdjustLabels&&D.bind.windowEvents()},keyboardEvents:function(){D.verbose("Binding keyboard events"),P.on("keydown"+M,D.event.keydown)},globalKeyboardEvents:function(){F.on("keydown"+M+t,D.event.activateFocus)},mouseEvents:function(){D.verbose("Binding mouse and touch events"),P.find(".track, .thumb, .inner").on("mousedown"+M,function(e){e.stopImmediatePropagation(),e.preventDefault(),D.event.down(e)}),P.on("mousedown"+M,D.event.down),P.on("mouseenter"+M,function(e){w=!0}),P.on("mouseleave"+M,function(e){w=!1}),P.find(".thumb").on("touchstart"+M,D.event.touchDown).on("touchmove"+M,D.event.move).on("touchend"+M,D.event.up).on("touchcancel"+M,D.event.touchCancel)},slidingEvents:function(){D.verbose("Binding page wide events while handle is being draged"),F.on("mousemove"+M,D.event.move),F.on("mouseup"+M,D.event.up)},windowEvents:function(){O.on("resize"+M,D.event.resize)}},unbind:{events:function(){P.find(".track, .thumb, .inner").off("mousedown"+M),P.off("mousedown"+M),P.off("mouseenter"+M),P.off("mouseleave"+M),P.find(".thumb").off("touchstart"+M).off("touchmove"+M).off("touchend"+M).off("touchcancel"+M),P.off("keydown"+M),P.off("focusout"+M),F.off("keydown"+M+t,D.event.activateFocus),O.off("resize"+M)},slidingEvents:function(){F.off("mousemove"+M),F.off("mouseup"+M)}},event:{down:function(e){e.preventDefault(),D.is.range()?(e=D.determine.eventPos(e),e=D.determine.pos(e),l=p.preventCrossover&&D.is.range()&&D.thumbVal===D.secondThumbVal?void(i=e):D.determine.closestThumb(e),void 0===b&&(b=D.get.currentThumbValue())):void 0===b&&(b=D.get.value()),D.is.disabled()||D.bind.slidingEvents()},touchDown:function(e){e.preventDefault(),e.stopImmediatePropagation(),void 0===r&&(l=Y(e.target),e=e.touches?e:e.originalEvent,r=e.targetTouches[0].identifier,void 0===b&&(b=D.get.currentThumbValue()))},move:function(e){var t,n,a;"mousemove"===e.type&&e.preventDefault(),D.is.disabled()||(t=D.determine.valueFromEvent(e),"mousemove"===e.type&&void 0===l&&(n=D.determine.eventPos(e),n=D.determine.pos(n),l=n<i?s:u),0===D.get.step()||D.is.smooth()?(n=D.thumbVal,a=D.secondThumbVal,e=D.determine.smoothValueFromEvent(e),l.hasClass("second")?(p.preventCrossover&&D.is.range()&&(t=Math.max(n,t),e=Math.max(n,e)),a=t):(p.preventCrossover&&D.is.range()&&(t=Math.min(a,t),e=Math.min(a,e)),n=t),t=Math.abs(n-(a||0)),D.update.position(e),p.onMove.call(E,t,n,a)):D.update.value(t,function(e,t,n){p.onMove.call(E,e,t,n)}))},up:function(e){e.preventDefault(),D.is.disabled()||(e=D.determine.valueFromEvent(e),D.set.value(e),D.unbind.slidingEvents(),(r=void 0)!==b&&(b=void 0))},touchCancel:function(e){e.preventDefault(),(r=void 0)!==b&&(D.update.value(b),b=void 0)},keydown:function(e,t){if(p.preventCrossover&&D.is.range()&&D.thumbVal===D.secondThumbVal&&(l=void 0),D.is.focused()&&F.trigger(e),t||D.is.focused()){t=D.determine.keyMovement(e);if(0!==t)switch(e.preventDefault(),t){case 1:D.takeStep();break;case 2:D.takeStep(D.get.multiplier());break;case-1:D.backStep();break;case-2:D.backStep(D.get.multiplier())}}},activateFocus:function(e){!D.is.focused()&&D.is.hover()&&0!==D.determine.keyMovement(e)&&(e.preventDefault(),D.event.keydown(e,!0),P.trigger("focus"))},resize:function(e){L!==D.get.gapRatio()&&(D.setup.labels(),L=D.get.gapRatio())}},resync:function(){D.verbose("Resyncing thumb position based on value"),D.is.range()&&D.update.position(D.secondThumbVal,u),D.update.position(D.thumbVal,s),D.setup.labels()},takeStep:function(e){e=e||1;var t=D.get.step(),n=D.get.currentThumbValue();D.verbose("Taking a step"),0<t?D.set.value(n+t*e):0===t&&(t=D.get.precision(),D.set.value(Math.round((n+e/t)*t)/t))},backStep:function(e){e=e||1;var t=D.get.step(),n=D.get.currentThumbValue();D.verbose("Going back a step"),0<t?D.set.value(n-t*e):0===t&&(t=D.get.precision(),D.set.value(Math.round((n-e/t)*t)/t))},is:{range:function(){return P.hasClass(p.className.range)},hover:function(){return w},focused:function(){return P.is(":focus")},disabled:function(){return P.hasClass(p.className.disabled)},labeled:function(){return P.hasClass(p.className.labeled)},reversed:function(){return P.hasClass(p.className.reversed)},vertical:function(){return P.hasClass(p.className.vertical)},smooth:function(){return p.smooth||P.hasClass(p.className.smooth)}},get:{trackOffset:function(){return D.is.vertical()?e.offset().top:e.offset().left},trackLength:function(){return D.is.vertical()?e.height():e.width()},trackLeft:function(){return D.is.vertical()?e.position().top:e.position().left},trackStartPos:function(){return D.is.reversed()?D.get.trackLeft()+D.get.trackLength():D.get.trackLeft()},trackEndPos:function(){return D.is.reversed()?D.get.trackLeft():D.get.trackLeft()+D.get.trackLength()},trackStartMargin:function(){var e=D.is.vertical()?D.is.reversed()?P.css("padding-bottom"):P.css("padding-top"):D.is.reversed()?P.css("padding-right"):P.css("padding-left");return e||"0px"},trackEndMargin:function(){var e=D.is.vertical()?D.is.reversed()?P.css("padding-top"):P.css("padding-bottom"):D.is.reversed()?P.css("padding-left"):P.css("padding-right");return e||"0px"},precision:function(){var e=D.get.step(),e=(e=0!==e?2===(e=String(e).split(".")).length?e[1].length:0:p.decimalPlaces,Math.pow(10,e));return D.debug("Precision determined",e),e},min:function(){return p.min},max:function(){var e=D.get.step(),t=D.get.min(),n=0===e?0:Math.floor((p.max-t)/e);return 0==(0===e?0:(p.max-t)%e)?p.max:t+n*e},step:function(){return p.step},numLabels:function(){var e=Math.round((D.get.max()-D.get.min())/(0===D.get.step()?1:D.get.step()));return D.debug("Determined that there should be "+e+" labels"),e},labelType:function(){return p.labelType},label:function(e){if(y)return y(e);switch(p.labelType){case p.labelTypes.number:return Math.round((e*(0===D.get.step()?1:D.get.step())+D.get.min())*o)/o;case p.labelTypes.letter:return U[e%26];default:return e}},value:function(){return m},currentThumbValue:function(){return void 0!==l&&l.hasClass("second")?D.secondThumbVal:D.thumbVal},thumbValue:function(e){return"second"!==e?D.thumbVal:D.is.range()?D.secondThumbVal:void D.error(V.notrange)},multiplier:function(){return p.pageMultiplier},thumbPosition:function(e){return"second"!==e?v:D.is.range()?f:void D.error(V.notrange)},gapRatio:function(){var e=1;if(p.autoAdjustLabels){var t=D.get.numLabels(),n=D.get.trackLength(),a=1;if(0<n)for(;n/t*a<p.labelDistance;)t%a||(e=a),a+=1}return e}},determine:{pos:function(e){return D.is.reversed()?D.get.trackStartPos()-e+D.get.trackOffset():e-D.get.trackOffset()-D.get.trackStartPos()},closestThumb:function(e){var t=parseFloat(D.determine.thumbPos(s)),t=Math.abs(e-t),n=parseFloat(D.determine.thumbPos(u)),e=Math.abs(e-n);return(t!==e||D.get.thumbValue()!==D.get.min())&&t<=e?s:u},closestThumbPos:function(e){var t=parseFloat(D.determine.thumbPos(s)),n=Math.abs(e-t),a=parseFloat(D.determine.thumbPos(u));return n<=Math.abs(e-a)?t:a},thumbPos:function(e){return D.is.vertical()?D.is.reversed()?e.css("bottom"):e.css("top"):D.is.reversed()?e.css("right"):e.css("left")},positionFromValue:function(e){var t=D.get.min(),n=D.get.max(),e=n<e?n:e<t?t:e,a=D.get.trackLength(),n=Math.round((e-t)/(n-t)*a);return D.verbose("Determined position: "+n+" from value: "+e),n},positionFromRatio:function(e){var t=D.get.trackLength(),n=D.get.step(),e=Math.round(e*t);return 0===n?e:Math.round(e/n)*n},valueFromEvent:function(e){var e=D.determine.eventPos(e),t=D.determine.pos(e),e=e<D.get.trackOffset()?D.is.reversed()?D.get.max():D.get.min():e>D.get.trackOffset()+D.get.trackLength()?D.is.reversed()?D.get.min():D.get.max():D.determine.value(t);return e},smoothValueFromEvent:function(e){var t=D.get.min(),n=D.get.max(),a=D.get.trackLength(),e=D.determine.eventPos(e)-D.get.trackOffset(),e=(e=e<0?0:a<e?a:e)/a;return(e=D.is.reversed()?1-e:e)*(n-t)+t},eventPos:function(e){if("touchmove"===e.type||"touchend"===e.type){for(var t=e.touches?e:e.originalEvent,n=t.changedTouches[0],a=0;a<t.touches.length;a++)if(t.touches[a].identifier===r){n=t.touches[a];break}var o=n.pageY,i=n.pageX;return D.is.vertical()?o:i}o=e.pageY||e.originalEvent.pageY,i=e.pageX||e.originalEvent.pageX;return D.is.vertical()?o:i},value:function(e){var t=D.is.reversed()?D.get.trackEndPos():D.get.trackStartPos(),t=(e-t)/((D.is.reversed()?D.get.trackStartPos():D.get.trackEndPos())-t),n=D.get.max()-D.get.min(),a=D.get.step(),t=t*n,n=0===a?t:Math.round(t/a)*a;return D.verbose("Determined value based upon position: "+e+" as: "+t),t!=n&&D.verbose("Rounding value to closest step: "+n),D.verbose("Cutting off additional decimal places"),Math.round((n+D.get.min())*o)/o},keyMovement:function(e){var e=e.which,t=!D.is.vertical()||D.is.reversed()?T.downArrow:T.upArrow,n=!D.is.vertical()||D.is.reversed()?T.upArrow:T.downArrow,a=!D.is.vertical()&&D.is.reversed()?T.rightArrow:T.leftArrow,o=!D.is.vertical()&&D.is.reversed()?T.leftArrow:T.rightArrow;return e===t||e===a?-1:e===n||e===o?1:e===T.pageDown?-2:e===T.pageUp?2:0}},handleNewValuePosition:function(e){var t=D.get.min(),n=D.get.max();return e<=t?e=t:n<=e&&(e=n),D.determine.positionFromValue(e)},set:{value:function(a,o){o=!1!==o;var i=void 0===b;b=void 0===b?D.get.value():b,D.update.value(a,function(e,t,n){h&&!p.fireOnInit||!o||(a!==b&&p.onChange.call(E,e,t,n),p.onMove.call(E,e,t,n)),i&&(b=void 0)})},rangeValue:function(e,t,n){var a,o,i;n=!1!==n,D.is.range()?(a=D.get.min(),o=D.get.max(),b=(i=void 0===b)?D.get.value():b,e<=a?e=a:o<=e&&(e=o),t<=a?t=a:o<=t&&(t=o),D.thumbVal=e,D.secondThumbVal=t,m=Math.abs(D.thumbVal-D.secondThumbVal),D.update.position(D.thumbVal,s),D.update.position(D.secondThumbVal,u),h&&!p.fireOnInit||!n||(m!==b&&p.onChange.call(E,m,D.thumbVal,D.secondThumbVal),p.onMove.call(E,m,D.thumbVal,D.secondThumbVal)),i&&(b=void 0)):D.error(V.notrange)},position:function(e,t){e=D.determine.value(e);"second"===t?(D.secondThumbVal=e,D.update.position(e,u)):(D.thumbVal=e,D.update.position(e,s)),m=Math.abs(D.thumbVal-(D.secondThumbVal||0)),D.set.value(m)}},update:{value:function(e,t){var n=D.get.min(),a=D.get.max();e<=n?e=n:a<=e&&(e=a),D.is.range()?((l=void 0===l?e<=D.get.currentThumbValue()?s:u:l).hasClass("second")?(p.preventCrossover&&D.is.range()&&(e=Math.max(D.thumbVal,e)),D.secondThumbVal=e):(p.preventCrossover&&D.is.range()&&(e=Math.min(D.secondThumbVal,e)),D.thumbVal=e),m=Math.abs(D.thumbVal-D.secondThumbVal)):(m=e,D.thumbVal=m),D.update.position(e),D.debug("Setting slider value to "+m),"function"==typeof t&&t(m,D.thumbVal,D.secondThumbVal)},position:function(e,t){var n=D.handleNewValuePosition(e),t=t||l,a=D.thumbVal||D.get.min(),o=D.secondThumbVal||D.get.min();D.is.range()&&t.hasClass("second")?(f=n,o=e):(v=n,a=e);var i,r=D.get.min(),s=D.get.max(),e=(e-r)/(s-r)*100,u=(Math.min(a,o)-r)/(s-r)*100,a=100*(1-(Math.max(a,o)-r)/(s-r)),o=D.is.vertical()?D.is.reversed()?(i={bottom:"calc("+e+"% - "+g+"px)",top:"auto"},{bottom:u+"%",top:a+"%"}):(i={top:"calc("+e+"% - "+g+"px)",bottom:"auto"},{top:u+"%",bottom:a+"%"}):D.is.reversed()?(i={right:"calc("+e+"% - "+g+"px)",left:"auto"},{right:u+"%",left:a+"%"}):(i={left:"calc("+e+"% - "+g+"px)",right:"auto"},{left:u+"%",right:a+"%"});t.css(i),c.css(o),D.debug("Setting slider position to "+n)},labelPosition:function(e,t){var n=D.get.trackStartMargin(),a=D.get.trackEndMargin(),o=D.is.vertical()?D.is.reversed()?"bottom":"top":D.is.reversed()?"right":"left",i=D.is.reversed()&&!D.is.vertical()?" - ":" + ";t.css(o,"calc("+("(100% - "+n+" - "+a+") * "+e)+i+n+")")}},goto:{max:function(){D.set.value(D.get.max())},min:function(){D.set.value(D.get.min())}},read:{metadata:function(){var e={thumbVal:P.data(a.thumbVal),secondThumbVal:P.data(a.secondThumbVal)};e.thumbVal&&(D.is.range()&&e.secondThumbVal?(D.debug("Current value set from metadata",e.thumbVal,e.secondThumbVal),D.set.rangeValue(e.thumbVal,e.secondThumbVal)):(D.debug("Current value set from metadata",e.thumbVal),D.set.value(e.thumbVal)))},settings:function(){!1!==p.start&&(D.is.range()?(D.debug("Start position set from settings",p.start,p.end),D.set.rangeValue(p.start,p.end)):(D.debug("Start position set from settings",p.start),D.set.value(p.start)))}},setting:function(e,t){if(D.debug("Changing setting",e,t),Y.isPlainObject(e))Y.extend(!0,p,e);else{if(void 0===t)return p[e];Y.isPlainObject(p[e])?Y.extend(!0,p[e],t):p[e]=t}},internal:function(e,t){if(Y.isPlainObject(e))Y.extend(!0,D,e);else{if(void 0===t)return D[e];D[e]=t}},debug:function(){!p.silent&&p.debug&&(p.performance?D.performance.log(arguments):(D.debug=Function.prototype.bind.call(console.info,console,p.name+":"),D.debug.apply(console,arguments)))},verbose:function(){!p.silent&&p.verbose&&p.debug&&(p.performance?D.performance.log(arguments):(D.verbose=Function.prototype.bind.call(console.info,console,p.name+":"),D.verbose.apply(console,arguments)))},error:function(){p.silent||(D.error=Function.prototype.bind.call(console.error,console,p.name+":"),D.error.apply(console,arguments))},performance:{log:function(e){var t,n;p.performance&&(n=(t=Date.now())-(j||t),j=t,z.push({Name:e[0],Arguments:[].slice.call(e,1)||"",Element:E,"Execution Time":n})),clearTimeout(D.performance.timer),D.performance.timer=setTimeout(D.performance.display,500)},display:function(){var e=p.name+":",n=0;j=!1,clearTimeout(D.performance.timer),Y.each(z,function(e,t){n+=t["Execution Time"]}),e+=" "+n+"ms",N&&(e+=" '"+N+"'"),0<z.length&&(console.groupCollapsed(e),console.table?console.table(z):Y.each(z,function(e,t){console.log(t.Name+": "+t["Execution Time"]+"ms")}),console.groupEnd()),z=[]}},invoke:function(a,e,t){var o,i,n,r,s=C;return e=e||B,t=t||E,"string"==typeof a&&void 0!==s&&(a=a.split(/[ .]/),o=a.length-1,Y.each(a,function(e,t){var n=e!==o?t+a[e+1].charAt(0).toUpperCase()+a[e+1].slice(1):a;if(Y.isPlainObject(s[n])&&e!==o)s=s[n];else{if(void 0!==s[n])return i=s[n],!1;{if(!Y.isPlainObject(s[t])||e===o)return void 0!==s[t]?i=s[t]:D.error(V.method,a),!1;s=s[t]}}})),"function"==typeof(r=i)&&"number"!=typeof r.nodeType?n=i.apply(t,e):void 0!==i&&(n=i),Array.isArray(A)?A.push(n):void 0!==A?A=[A,n]:void 0!==n&&(A=n),i}};R?(void 0===C&&D.initialize(),D.invoke(I)):(void 0!==C&&C.invoke("destroy"),D.initialize())}),void 0!==A?A:this},Y.fn.slider.settings={silent:!1,debug:!1,verbose:!1,performance:!0,name:"Slider",namespace:"slider",error:{method:"The method you called is not defined.",notrange:"This slider is not a range slider"},metadata:{thumbVal:"thumbVal",secondThumbVal:"secondThumbVal"},min:0,max:20,step:1,start:0,end:20,labelType:"number",showLabelTicks:!1,smooth:!1,autoAdjustLabels:!0,labelDistance:100,preventCrossover:!0,fireOnInit:!1,interpretLabel:!1,decimalPlaces:2,pageMultiplier:2,selector:{},className:{reversed:"reversed",disabled:"disabled",labeled:"labeled",ticked:"ticked",vertical:"vertical",range:"range",smooth:"smooth"},keys:{pageUp:33,pageDown:34,leftArrow:37,upArrow:38,rightArrow:39,downArrow:40},labelTypes:{number:"number",letter:"letter"},onChange:function(e,t,n){},onMove:function(e,t,n){}}}(jQuery,window,document); |