1/*! 2 * Copyright (c) 2012 Ben Olson (https://github.com/bseth99/jquery-ui-extensions) 3 * jQuery UI LabeledSlider @VERSION 4 * 5 * Permission is hereby granted, free of charge, to any person 6 * obtaining a copy of this software and associated documentation 7 * files (the "Software"), to deal in the Software without 8 * restriction, including without limitation the rights to use, 9 * copy, modify, merge, publish, distribute, sublicense, and/or sell 10 * copies of the Software, and to permit persons to whom the 11 * Software is furnished to do so, subject to the following 12 * conditions: 13 * 14 * The above copyright notice and this permission notice shall be 15 * included in all copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 19 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 20 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 21 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 22 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 23 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 24 * OTHER DEALINGS IN THE SOFTWARE. 25 * 26 * Depends: 27 * jquery.ui.core.js 28 * jquery.ui.widget.js 29 * jquery.ui.mouse.js 30 * jquery.ui.slider.js 31 */ 32 33( function ( $, undefined ) { 34 $.widget( 'ui.labeledslider', $.ui.slider, { 35 version: '@VERSION', 36 37 options: { 38 tickInterval: 0, 39 tweenLabels: true, 40 tickLabels: null, 41 tickArray: [], 42 }, 43 44 uiSlider: null, 45 tickInterval: 0, 46 tweenLabels: true, 47 48 _create() { 49 this._detectOrientation(); 50 51 this.uiSlider = this.element 52 .wrap( '<div class="ui-slider-wrapper ui-widget"></div>' ) 53 .before( '<div class="ui-slider-labels"></div>' ) 54 .parent() 55 .addClass( this.orientation ) 56 .css( 'font-size', this.element.css( 'font-size' ) ); 57 58 this._super(); 59 60 this.element.removeClass( 'ui-widget' ); 61 62 this._alignWithStep(); 63 64 if ( this.orientation == 'horizontal' ) { 65 this.uiSlider.width( this.element.css( 'width' ) ); 66 } else { 67 this.uiSlider.height( this.element.css( 'height' ) ); 68 } 69 70 this._drawLabels(); 71 }, 72 73 _drawLabels() { 74 let labels = this.options.tickLabels || {}, 75 $lbl = this.uiSlider.children( '.ui-slider-labels' ), 76 dir = this.orientation == 'horizontal' ? 'left' : 'bottom', 77 min = this.options.min, 78 max = this.options.max, 79 inr = this.tickInterval, 80 cnt = max - min, 81 tickArray = this.options.tickArray, 82 ta = tickArray.length > 0, 83 label, 84 pt, 85 i = 0; 86 87 $lbl.html( '' ); 88 89 for ( ; i <= cnt; i++ ) { 90 if ( 91 ( ! ta && i % inr == 0 ) || 92 ( ta && tickArray.indexOf( i + min ) > -1 ) 93 ) { 94 label = labels[ i + min ] 95 ? labels[ i + min ] 96 : this.options.tweenLabels 97 ? i + min 98 : ''; 99 100 $( '<div>' ) 101 .addClass( 102 'ui-slider-label-ticks' + 103 ' ult-slider-ticks' + 104 ( i + 1 ) 105 ) 106 .css( 107 dir, 108 Math.round( ( i / cnt ) * 10000 ) / 100 + '%' 109 ) 110 .html( '<span>' + label + '</span>' ) 111 .appendTo( $lbl ); 112 } 113 } 114 }, 115 116 _setOption( key, value ) { 117 this._super( key, value ); 118 119 switch ( key ) { 120 case 'tickInterval': 121 case 'tickLabels': 122 case 'tickArray':
123 case 'min': 124 case 'max': 125 case 'step': 126 this._alignWithStep(); 127 this._drawLabels(); 128 break; 129 130 case 'orientation': 131 this.element 132 .removeClass( 'horizontal vertical' ) 133 .addClass( this.orientation ); 134 135 this._drawLabels(); 136 break; 137 } 138 }, 139 140 _alignWithStep() { 141 if ( this.options.tickInterval < this.options.step ) 142 this.tickInterval = this.options.step; 143 else this.tickInterval = this.options.tickInterval; 144 }, 145 146 _destroy() { 147 this._super(); 148 this.uiSlider.replaceWith( this.element ); 149 }, 150 151 widget() { 152 return this.uiSlider; 153 }, 154 } ); 155} )( jQuery );
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.