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