11 lines
No EOL
17 KiB
JavaScript
11 lines
No EOL
17 KiB
JavaScript
/*
|
|
* # Fomantic UI - 2.8.8
|
|
* 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(S){var A,e=X(this),D=X(t),O=e.selector||"",N=(new Date).getTime(),j=[],z=S,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,e,c,u,t,d,m,f,v,o,n,g,s,b,h=X.isPlainObject(S)?X.extend(!0,{},X.fn.slider.settings,S):X.extend({},X.fn.slider.settings),a=h.className,p=h.metadata,k=h.namespace,V=h.error,T=h.keys,w=h.interpretLabel,y=!1,M="."+k,x="module-"+k,P=X(this),E=this,C=P.data(x),L=1,F={initialize:function(){F.debug("Initializing slider",h),b=!0,t=U+=1,n=F.setup.testOutTouch(),F.setup.layout(),F.setup.labels(),F.is.disabled()||F.bind.events(),F.read.metadata(),F.read.settings(),b=!1,F.instantiate()},instantiate:function(){F.verbose("Storing instance of slider",F),C=F,P.data(x,F)},destroy:function(){F.verbose("Destroying previous slider for",P),clearInterval(C.interval),F.unbind.events(),F.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=F.get.precision(),r=P.find(".thumb:not(.second)"),l=r,F.is.range()&&(0==P.find(".thumb.second").length&&P.find(".inner").append("<div class='thumb second'></div>"),i=P.find(".thumb.second")),e=P.find(".track"),c=P.find(".track-fill"),v=r.width()/2},labels:function(){F.is.labeled()&&(0!=(u=P.find(".labels:not(.auto)")).length?F.setup.customLabel():F.setup.autoLabel(),h.showLabelTicks&&P.addClass(a.ticked))},testOutTouch:function(){try{return Y.createEvent("TouchEvent"),!0}catch(e){return!1}},customLabel:function(){var n,e=u.find(".label"),a=e.length,o=F.get.min(),s=F.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),F.update.labelPosition(n,X(this))})},autoLabel:function(){0!=(u=P.find(".labels")).length?u.empty():u=P.append('<ul class="auto labels"></ul>').find(".labels");for(var e=0,t=F.get.numLabels();e<=t;e++){var n=F.get.label(e),n=""!==n?e%F.get.gapRatio()?X('<li class="halftick label"></li>'):X('<li class="label">'+n+"</li>"):null;n&&(F.update.labelPosition(e/t,n),u.append(n))}}},bind:{events:function(){F.bind.globalKeyboardEvents(),F.bind.keyboardEvents(),F.bind.mouseEvents(),F.is.touch()&&F.bind.touchEvents(),h.autoAdjustLabels&&F.bind.windowEvents()},keyboardEvents:function(){F.verbose("Binding keyboard events"),P.on("keydown"+M,F.event.keydown)},globalKeyboardEvents:function(){X(Y).on("keydown"+M+t,F.event.activateFocus)},mouseEvents:function(){F.verbose("Binding mouse events"),P.find(".track, .thumb, .inner").on("mousedown"+M,function(e){e.stopImmediatePropagation(),e.preventDefault(),F.event.down(e)}),P.on("mousedown"+M,F.event.down),P.on("mouseenter"+M,function(e){y=!0}),P.on("mouseleave"+M,function(e){y=!1})},touchEvents:function(){F.verbose("Binding touch events"),P.find(".track, .thumb, .inner").on("touchstart"+M,function(e){e.stopImmediatePropagation(),e.preventDefault(),F.event.down(e)}),P.on("touchstart"+M,F.event.down)},slidingEvents:function(){F.verbose("Binding page wide events while handle is being draged"),F.is.touch()?(X(Y).on("touchmove"+M,F.event.move),X(Y).on("touchend"+M,F.event.up)):(X(Y).on("mousemove"+M,F.event.move),X(Y).on("mouseup"+M,F.event.up))},windowEvents:function(){D.on("resize"+M,F.event.resize)}},unbind:{events:function(){P.find(".track, .thumb, .inner").off("mousedown"+M),P.find(".track, .thumb, .inner").off("touchstart"+M),P.off("mousedown"+M),P.off("mouseenter"+M),P.off("mouseleave"+M),P.off("touchstart"+M),P.off("keydown"+M),P.off("focusout"+M),X(Y).off("keydown"+M+t,F.event.activateFocus),D.off("resize"+M)},slidingEvents:function(){F.is.touch()?(X(Y).off("touchmove"+M),X(Y).off("touchend"+M)):(X(Y).off("mousemove"+M),X(Y).off("mouseup"+M))}},event:{down:function(e){e.preventDefault(),F.is.range()?(e=F.determine.eventPos(e),e=F.determine.pos(e),l=h.preventCrossover&&F.is.range()&&F.thumbVal===F.secondThumbVal?(s=e,K):F.determine.closestThumb(e),g===K&&(g=F.get.currentThumbValue())):g===K&&(g=F.get.value()),F.is.disabled()||F.bind.slidingEvents()},move:function(e){e.preventDefault();var t,n,a=F.determine.valueFromEvent(e);l===K&&(t=F.determine.eventPos(e),n=F.determine.pos(t),l=n<s?r:i),0==F.get.step()||F.is.smooth()?(t=F.thumbVal,n=F.secondThumbVal,e=F.determine.smoothValueFromEvent(e),l.hasClass("second")?(h.preventCrossover&&F.is.range()&&(a=Math.max(t,a),e=Math.max(t,e)),n=a):(h.preventCrossover&&F.is.range()&&(a=Math.min(n,a),e=Math.min(n,e)),t=a),a=Math.abs(t-(n||0)),F.update.position(e),h.onMove.call(E,a,t,n)):F.update.value(a,function(e,t,n){h.onMove.call(E,e,t,n)})},up:function(e){e.preventDefault();e=F.determine.valueFromEvent(e);F.set.value(e),F.unbind.slidingEvents(),g!==K&&(g=K)},keydown:function(e,t){if(h.preventCrossover&&F.is.range()&&F.thumbVal===F.secondThumbVal&&(l=K),F.is.focused()&&X(Y).trigger(e),t||F.is.focused()){t=F.determine.keyMovement(e);if(0!=t)switch(e.preventDefault(),t){case 1:F.takeStep();break;case 2:F.takeStep(F.get.multiplier());break;case-1:F.backStep();break;case-2:F.backStep(F.get.multiplier())}}},activateFocus:function(e){!F.is.focused()&&F.is.hover()&&0!=F.determine.keyMovement(e)&&(e.preventDefault(),F.event.keydown(e,!0),P.focus())},resize:function(e){L!=F.get.gapRatio()&&(F.setup.labels(),L=F.get.gapRatio())}},resync:function(){F.verbose("Resyncing thumb position based on value"),F.is.range()&&F.update.position(F.secondThumbVal,i),F.update.position(F.thumbVal,r),F.setup.labels()},takeStep:function(e){var e=e!=K?e:1,t=F.get.step(),n=F.get.currentThumbValue();F.verbose("Taking a step"),0<t?F.set.value(n+t*e):0==t&&(t=F.get.precision(),F.set.value(Math.round((n+e/t)*t)/t))},backStep:function(e){var e=e!=K?e:1,t=F.get.step(),n=F.get.currentThumbValue();F.verbose("Going back a step"),0<t?F.set.value(n-t*e):0==t&&(t=F.get.precision(),F.set.value(Math.round((n-e/t)*t)/t))},is:{range:function(){return P.hasClass(h.className.range)},hover:function(){return y},focused:function(){return P.is(":focus")},disabled:function(){return P.hasClass(h.className.disabled)},labeled:function(){return P.hasClass(h.className.labeled)},reversed:function(){return P.hasClass(h.className.reversed)},vertical:function(){return P.hasClass(h.className.vertical)},smooth:function(){return h.smooth||P.hasClass(h.className.smooth)},touch:function(){return n}},get:{trackOffset:function(){return F.is.vertical()?e.offset().top:e.offset().left},trackLength:function(){return F.is.vertical()?e.height():e.width()},trackLeft:function(){return F.is.vertical()?e.position().top:e.position().left},trackStartPos:function(){return F.is.reversed()?F.get.trackLeft()+F.get.trackLength():F.get.trackLeft()},trackEndPos:function(){return F.is.reversed()?F.get.trackLeft():F.get.trackLeft()+F.get.trackLength()},trackStartMargin:function(){var e=F.is.vertical()?F.is.reversed()?P.css("padding-bottom"):P.css("padding-top"):F.is.reversed()?P.css("padding-right"):P.css("padding-left");return e||"0px"},trackEndMargin:function(){var e=F.is.vertical()?F.is.reversed()?P.css("padding-top"):P.css("padding-bottom"):F.is.reversed()?P.css("padding-left"):P.css("padding-right");return e||"0px"},precision:function(){var e=F.get.step();t=0!=e?2==(t=String(e).split(".")).length?t[1].length:0:h.decimalPlaces;var t=Math.pow(10,t);return F.debug("Precision determined",t),t},min:function(){return h.min},max:function(){var e=F.get.step(),t=F.get.min(),n=0===e?0:Math.floor((h.max-t)/e);return 0==(0===e?0:(h.max-t)%e)?h.max:t+n*e},step:function(){return h.step},numLabels:function(){var e=Math.round((F.get.max()-F.get.min())/(0===F.get.step()?1:F.get.step()));return F.debug("Determined that there should be "+e+" labels"),e},labelType:function(){return h.labelType},label:function(e){if(w)return w(e);switch(h.labelType){case h.labelTypes.number:return Math.round((e*(0===F.get.step()?1:F.get.step())+F.get.min())*o)/o;case h.labelTypes.letter:return B[e%26];default:return e}},value:function(){return d},currentThumbValue:function(){return l!==K&&l.hasClass("second")?F.secondThumbVal:F.thumbVal},thumbValue:function(e){return"second"!==e?F.thumbVal:F.is.range()?F.secondThumbVal:void F.error(V.notrange)},multiplier:function(){return h.pageMultiplier},thumbPosition:function(e){return"second"!==e?m:F.is.range()?f:void F.error(V.notrange)},gapRatio:function(){var e=1;if(h.autoAdjustLabels){var t=F.get.numLabels(),n=F.get.trackLength(),a=1;if(0<n)for(;n/t*a<h.labelDistance;)t%a||(e=a),a+=1}return e}},determine:{pos:function(e){return F.is.reversed()?F.get.trackStartPos()-e+F.get.trackOffset():e-F.get.trackOffset()-F.get.trackStartPos()},closestThumb:function(e){var t=parseFloat(F.determine.thumbPos(r)),n=Math.abs(e-t),t=parseFloat(F.determine.thumbPos(i)),t=Math.abs(e-t);return(n!==t||F.get.thumbValue()!==F.get.min())&&n<=t?r:i},closestThumbPos:function(e){var t=parseFloat(F.determine.thumbPos(r)),n=Math.abs(e-t),a=parseFloat(F.determine.thumbPos(i));return n<=Math.abs(e-a)?t:a},thumbPos:function(e){return F.is.vertical()?F.is.reversed()?e.css("bottom"):e.css("top"):F.is.reversed()?e.css("right"):e.css("left")},positionFromValue:function(e){var t=F.get.min(),n=F.get.max(),e=n<e?n:e<t?t:e,a=F.get.trackLength(),a=Math.round((e-t)/(n-t)*a);return F.verbose("Determined position: "+a+" from value: "+e),a},positionFromRatio:function(e){var t=F.get.trackLength(),n=F.get.step(),t=Math.round(e*t);return 0==n?t:Math.round(t/n)*n},valueFromEvent:function(e){var t=F.determine.eventPos(e),e=F.determine.pos(t),e=t<F.get.trackOffset()?F.is.reversed()?F.get.max():F.get.min():t>F.get.trackOffset()+F.get.trackLength()?F.is.reversed()?F.get.min():F.get.max():F.determine.value(e);return e},smoothValueFromEvent:function(e){var t=F.get.min(),n=F.get.max(),a=F.get.trackLength(),e=F.determine.eventPos(e)-F.get.trackOffset(),a=(e=e<0?0:a<e?a:e)/a;return(a=F.is.reversed()?1-a:a)*(n-t)+t},eventPos:function(e){if(F.is.touch()){var t=e.changedTouches?e:e.originalEvent,n=t.changedTouches[0]?t.changedTouches:t.touches,t=n[0].pageY,n=n[0].pageX;return F.is.vertical()?t:n}n=e.pageY||e.originalEvent.pageY,e=e.pageX||e.originalEvent.pageX;return F.is.vertical()?n:e},value:function(e){var t=F.is.reversed()?F.get.trackEndPos():F.get.trackStartPos(),n=(e-t)/((F.is.reversed()?F.get.trackStartPos():F.get.trackEndPos())-t),a=F.get.max()-F.get.min(),t=F.get.step(),a=n*a,t=0==t?a:Math.round(a/t)*t;return F.verbose("Determined value based upon position: "+e+" as: "+a),a!=t&&F.verbose("Rounding value to closest step: "+t),F.verbose("Cutting off additional decimal places"),Math.round((t+F.get.min())*o)/o},keyMovement:function(e){var t=e.which,n=!F.is.vertical()||F.is.reversed()?T.downArrow:T.upArrow,a=!F.is.vertical()||F.is.reversed()?T.upArrow:T.downArrow,o=!F.is.vertical()&&F.is.reversed()?T.rightArrow:T.leftArrow,e=!F.is.vertical()&&F.is.reversed()?T.leftArrow:T.rightArrow;return t==n||t==o?-1:t==a||t==e?1:t==T.pageDown?-2:t==T.pageUp?2:0}},handleNewValuePosition:function(e){var t=F.get.min(),n=F.get.max();return e<=t?e=t:n<=e&&(e=n),F.determine.positionFromValue(e)},set:{value:function(a,o){o=!1!==o;var s=g===K;g=g===K?F.get.value():g,F.update.value(a,function(e,t,n){b&&!h.fireOnInit||!o||(a!==g&&h.onChange.call(E,e,t,n),h.onMove.call(E,e,t,n)),s&&(g=K)})},rangeValue:function(e,t,n){var a,o,s;n=!1!==n,F.is.range()?(a=F.get.min(),o=F.get.max(),g=(s=g===K)?F.get.value():g,e<=a?e=a:o<=e&&(e=o),t<=a?t=a:o<=t&&(t=o),F.thumbVal=e,F.secondThumbVal=t,d=Math.abs(F.thumbVal-F.secondThumbVal),F.update.position(F.thumbVal,r),F.update.position(F.secondThumbVal,i),b&&!h.fireOnInit||!n||(d!==g&&h.onChange.call(E,d,F.thumbVal,F.secondThumbVal),h.onMove.call(E,d,F.thumbVal,F.secondThumbVal)),s&&(g=K)):F.error(V.notrange)},position:function(e,t){e=F.determine.value(e);"second"===t?(F.secondThumbVal=e,F.update.position(e,i)):(F.thumbVal=e,F.update.position(e,r)),d=Math.abs(F.thumbVal-(F.secondThumbVal||0)),F.set.value(d)}},update:{value:function(e,t){var n=F.get.min(),a=F.get.max();e<=n?e=n:a<=e&&(e=a),F.is.range()?((l=l===K?e<=F.get.currentThumbValue()?r:i:l).hasClass("second")?(h.preventCrossover&&F.is.range()&&(e=Math.max(F.thumbVal,e)),F.secondThumbVal=e):(h.preventCrossover&&F.is.range()&&(e=Math.min(F.secondThumbVal,e)),F.thumbVal=e),d=Math.abs(F.thumbVal-F.secondThumbVal)):(d=e,F.thumbVal=d),F.update.position(e),F.debug("Setting slider value to "+d),"function"==typeof t&&t(d,F.thumbVal,F.secondThumbVal)},position:function(e,t){var n=F.handleNewValuePosition(e),a=t!=K?t:l,o=F.thumbVal||F.get.min(),s=F.secondThumbVal||F.get.min();F.is.range()&&a.hasClass("second")?(f=n,s=e):(m=n,o=e);var r,i=F.get.min(),u=F.get.max(),t=100*(e-i)/(u-i),e=100*(Math.min(o,s)-i)/(u-i),i=100*(1-(Math.max(o,s)-i)/(u-i)),i=F.is.vertical()?F.is.reversed()?(r={bottom:"calc("+t+"% - "+v+"px)",top:"auto"},{bottom:e+"%",top:i+"%"}):(r={top:"calc("+t+"% - "+v+"px)",bottom:"auto"},{top:e+"%",bottom:i+"%"}):F.is.reversed()?(r={right:"calc("+t+"% - "+v+"px)",left:"auto"},{right:e+"%",left:i+"%"}):(r={left:"calc("+t+"% - "+v+"px)",right:"auto"},{left:e+"%",right:i+"%"});a.css(r),c.css(i),F.debug("Setting slider position to "+n)},labelPosition:function(e,t){var n=F.get.trackStartMargin(),a=F.get.trackEndMargin(),o=F.is.vertical()?F.is.reversed()?"bottom":"top":F.is.reversed()?"right":"left",s=F.is.reversed()&&!F.is.vertical()?" - ":" + ";t.css(o,"calc("+("(100% - "+n+" - "+a+") * "+e)+s+n+")")}},goto:{max:function(){F.set.value(F.get.max())},min:function(){F.set.value(F.get.min())}},read:{metadata:function(){var e={thumbVal:P.data(p.thumbVal),secondThumbVal:P.data(p.secondThumbVal)};e.thumbVal&&(F.is.range()&&e.secondThumbVal?(F.debug("Current value set from metadata",e.thumbVal,e.secondThumbVal),F.set.rangeValue(e.thumbVal,e.secondThumbVal)):(F.debug("Current value set from metadata",e.thumbVal),F.set.value(e.thumbVal)))},settings:function(){!1!==h.start&&(F.is.range()?(F.debug("Start position set from settings",h.start,h.end),F.set.rangeValue(h.start,h.end)):(F.debug("Start position set from settings",h.start),F.set.value(h.start)))}},setting:function(e,t){if(F.debug("Changing setting",e,t),X.isPlainObject(e))X.extend(!0,h,e);else{if(t===K)return h[e];X.isPlainObject(h[e])?X.extend(!0,h[e],t):h[e]=t}},internal:function(e,t){if(X.isPlainObject(e))X.extend(!0,F,e);else{if(t===K)return F[e];F[e]=t}},debug:function(){!h.silent&&h.debug&&(h.performance?F.performance.log(arguments):(F.debug=Function.prototype.bind.call(console.info,console,h.name+":"),F.debug.apply(console,arguments)))},verbose:function(){!h.silent&&h.verbose&&h.debug&&(h.performance?F.performance.log(arguments):(F.verbose=Function.prototype.bind.call(console.info,console,h.name+":"),F.verbose.apply(console,arguments)))},error:function(){h.silent||(F.error=Function.prototype.bind.call(console.error,console,h.name+":"),F.error.apply(console,arguments))},performance:{log:function(e){var t,n;h.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(F.performance.timer),F.performance.timer=setTimeout(F.performance.display,500)},display:function(){var e=h.name+":",n=0;N=!1,clearTimeout(F.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=E||t,"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]:F.error(V.method,a),!1;r=r[t]}}})),X.isFunction(s)?n=s.apply(t,e):s!==K&&(n=s),X.isArray(A)?A.push(n):A!==K?A=[A,n]:n!==K&&(A=n),s}};I?(C===K&&F.initialize(),F.invoke(z)):(C!==K&&C.invoke("destroy"),F.initialize())}),A!==K?A: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); |