wishthis/node_modules/fomantic-ui/dist/components/slider.min.js
2022-05-29 11:24:36 +02:00

11 lines
No EOL
17 KiB
JavaScript

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