11 lines
No EOL
17 KiB
JavaScript
11 lines
No EOL
17 KiB
JavaScript
/*
|
|
* # Fomantic UI - 2.9.0
|
|
* https://github.com/fomantic/Fomantic-UI
|
|
* http://fomantic-ui.com/
|
|
*
|
|
* Copyright 2022 Contributors
|
|
* Released under the MIT license
|
|
* http://opensource.org/licenses/MIT
|
|
*
|
|
*/
|
|
!function(X,t,Y,K){"use strict";t=void 0!==t&&t.Math==Math?t:"undefined"!=typeof self&&self.Math==Math?self:Function("return this")(),X.fn.slider=function(F){var S,e=X(this),A=X(t),O=e.selector||"",N=(new Date).getTime(),j=[],z=F,I="string"==typeof z,R=[].slice.call(arguments,1),B=["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"],U=0;return e.each(function(){var l,r,i,u,e,c,d,t,m,f,g,v,o,b,s,h,p=X.isPlainObject(F)?X.extend(!0,{},X.fn.slider.settings,F):X.extend({},X.fn.slider.settings),n=p.className,a=p.metadata,k=p.namespace,V=p.error,T=p.keys,w=p.interpretLabel,y=!1,M="."+k,x="module-"+k,P=X(this),E=this,C=P.data(x),L=1,D={initialize:function(){D.debug("Initializing slider",p),h=!0,t=U+=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=K},setup:{layout:function(){P.attr("tabindex")===K&&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(),i=P.find(".thumb:not(.second)"),l=i,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"),v=i.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(),s=D.get.max();e.each(function(e){var t=X(this).attr("data-value");n=t?((t=s<t?s:t<o?o:t)-o)/(s-o):(e+1)/(a+1),D.update.labelPosition(n,X(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()?X('<li class="halftick label"></li>'):X('<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(){X(Y).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){y=!0}),P.on("mouseleave"+M,function(e){y=!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"),X(Y).on("mousemove"+M,D.event.move),X(Y).on("mouseup"+M,D.event.up)},windowEvents:function(){A.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),X(Y).off("keydown"+M+t,D.event.activateFocus),A.off("resize"+M)},slidingEvents:function(){X(Y).off("mousemove"+M),X(Y).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?(s=e,K):D.determine.closestThumb(e),b===K&&(b=D.get.currentThumbValue())):b===K&&(b=D.get.value()),D.is.disabled()||D.bind.slidingEvents()},touchDown:function(e){e.preventDefault(),e.stopImmediatePropagation(),r===K&&(l=X(e.target),e=e.touches?e:e.originalEvent,r=e.targetTouches[0].identifier,b===K&&(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&&l===K&&(n=D.determine.eventPos(e),n=D.determine.pos(n),l=n<s?i: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(),b!==(r=K)&&(b=K))},touchCancel:function(e){e.preventDefault(),b!==(r=K)&&(D.update.value(b),b=K)},keydown:function(e,t){if(p.preventCrossover&&D.is.range()&&D.thumbVal===D.secondThumbVal&&(l=K),D.is.focused()&&X(Y).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.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,i),D.setup.labels()},takeStep:function(e){e=e!=K?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!=K?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 y},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(w)return w(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 B[e%26];default:return e}},value:function(){return m},currentThumbValue:function(){return l!==K&&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?f:D.is.range()?g: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(i)),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?i:u},closestThumbPos:function(e){var t=parseFloat(D.determine.thumbPos(i)),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,s=n.pageX;return D.is.vertical()?o:s}o=e.pageY||e.originalEvent.pageY,s=e.pageX||e.originalEvent.pageX;return D.is.vertical()?o:s},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 s=b===K;b=b===K?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)),s&&(b=K)})},rangeValue:function(e,t,n){var a,o,s;n=!1!==n,D.is.range()?(a=D.get.min(),o=D.get.max(),b=(s=b===K)?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,i),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)),s&&(b=K)):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,i)),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=l===K?e<=D.get.currentThumbValue()?i: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!=K?t:l,a=D.thumbVal||D.get.min(),o=D.secondThumbVal||D.get.min();D.is.range()&&t.hasClass("second")?(g=n,o=e):(f=n,a=e);var s,r=D.get.min(),i=D.get.max(),e=100*(e-r)/(i-r),u=100*(Math.min(a,o)-r)/(i-r),a=100*(1-(Math.max(a,o)-r)/(i-r)),o=D.is.vertical()?D.is.reversed()?(s={bottom:"calc("+e+"% - "+v+"px)",top:"auto"},{bottom:u+"%",top:a+"%"}):(s={top:"calc("+e+"% - "+v+"px)",bottom:"auto"},{top:u+"%",bottom:a+"%"}):D.is.reversed()?(s={right:"calc("+e+"% - "+v+"px)",left:"auto"},{right:u+"%",left:a+"%"}):(s={left:"calc("+e+"% - "+v+"px)",right:"auto"},{left:u+"%",right:a+"%"});t.css(s),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",s=D.is.reversed()&&!D.is.vertical()?" - ":" + ";t.css(o,"calc("+("(100% - "+n+" - "+a+") * "+e)+s+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),X.isPlainObject(e))X.extend(!0,p,e);else{if(t===K)return p[e];X.isPlainObject(p[e])?X.extend(!0,p[e],t):p[e]=t}},internal:function(e,t){if(X.isPlainObject(e))X.extend(!0,D,e);else{if(t===K)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=(new Date).getTime())-(N||t),N=t,j.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;N=!1,clearTimeout(D.performance.timer),X.each(j,function(e,t){n+=t["Execution Time"]}),e+=" "+n+"ms",O&&(e+=" '"+O+"'"),(console.group!==K||console.table!==K)&&0<j.length&&(console.groupCollapsed(e),console.table?console.table(j):X.each(j,function(e,t){console.log(t.Name+": "+t["Execution Time"]+"ms")}),console.groupEnd()),j=[]}},invoke:function(a,e,t){var o,s,n,r=C;return e=e||R,t=t||E,"string"==typeof a&&r!==K&&(a=a.split(/[\. ]/),o=a.length-1,X.each(a,function(e,t){var n=e!=o?t+a[e+1].charAt(0).toUpperCase()+a[e+1].slice(1):a;if(X.isPlainObject(r[n])&&e!=o)r=r[n];else{if(r[n]!==K)return s=r[n],!1;{if(!X.isPlainObject(r[t])||e==o)return r[t]!==K?s=r[t]:D.error(V.method,a),!1;r=r[t]}}})),X.isFunction(s)?n=s.apply(t,e):s!==K&&(n=s),X.isArray(S)?S.push(n):S!==K?S=[S,n]:n!==K&&(S=n),s}};I?(C===K&&D.initialize(),D.invoke(z)):(C!==K&&C.invoke("destroy"),D.initialize())}),S!==K?S:this},X.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); |