1(function( $, undefined ) { 2 3// number of pages in a slider 4// (how many times can you page up/down to go through the whole range) 5var numPages = 5; 6 7$.widget( "ui.slider", $.ui.mouse, { 8 9 /*JA: use slidez instead of slide to resolve conflict of slider between jquery and mootools*/ 10 widgetEventPrefix: "slidez", 11 12 options: { 13 animate: false, 14 distance: 0, 15 max: 100, 16 min: 0, 17 orientation: "horizontal", 18 range: false, 19 step: 1, 20 value: 0, 21 values: null 22 }, 23 24 _create: function() { 25 var self = this, 26 o = this.options, 27 existingHandles = this.element.find( ".ui-slider-handle" ).addClass( "ui-state-default ui-corner-all" ), 28 handle = "<a class='ui-slider-handle ui-state-default ui-corner-all' href='#'></a>", 29 handleCount = ( o.values && o.values.length ) || 1, 30 handles = []; 31 32 this._keySliding = false; 33 this._mouseSliding = false; 34 this._animateOff = true; 35 this._handleIndex = null; 36 this._detectOrientation(); 37 this._mouseInit(); 38 39 this.element 40 .addClass( "ui-slider" + 41 " ui-slider-" + this.orientation + 42 " ui-widget" + 43 " ui-widget-content" + 44 " ui-corner-all" + 45 ( o.disabled ? " ui-slider-disabled ui-disabled" : "" ) ); 46 47 this.range = $([]); 48 49 if ( o.range ) { 50 if ( o.range === true ) { 51 if ( !o.values ) { 52 o.values = [ this._valueMin(), this._valueMin() ]; 53 } 54 if ( o.values.length && o.values.length !== 2 ) { 55 o.values = [ o.values[0], o.values[0] ]; 56 } 57 } 58 59 this.range = $( "<div></div>" ) 60 .appendTo( this.element ) 61 .addClass( "ui-slider-range" + 62 // note: this isn't the most fittingly semantic framework class for this element, 63 // but worked best visually with a variety of themes 64 " ui-widget-header" + 65 ( ( o.range === "min" || o.range === "max" ) ? " ui-slider-range-" + o.range : "" ) ); 66 } 67 68 for ( var i = existingHandles.length; i < handleCount; i += 1 ) { 69 handles.push( handle ); 70 } 71 72 this.handles = existingHandles.add( $( handles.join( "" ) ).appendTo( self.element ) ); 73 74 this.handle = this.handles.eq( 0 ); 75 76 this.handles.add( this.range ).filter( "a" ) 77 .click(function( event ) { 78 event.preventDefault(); 79 }) 80 .hover(function() { 81 if ( !o.disabled ) { 82 $( this ).addClass( "ui-state-hover" ); 83 } 84 }, function() { 85 $( this ).removeClass( "ui-state-hover" ); 86 }) 87 .focus(function() { 88 if ( !o.disabled ) { 89 $( ".ui-slider .ui-state-focus" ).removeClass( "ui-state-focus" ); 90 $( this ).addClass( "ui-state-focus" ); 91 } else { 92 $( this ).blur(); 93 } 94 }) 95 .blur(function() { 96 $( this ).removeClass( "ui-state-focus" ); 97 }); 98 99 this.handles.each(function( i ) { 100 $( this ).data( "index.ui-slider-handle", i ); 101 }); 102 103 this.handles 104 .keydown(function( event ) { 105 var index = $( this ).data( "index.ui-slider-handle" ), 106 allowed, 107 curVal, 108 newVal, 109 step; 110 111 if ( self.options.disabled ) { 112 return; 113 } 114 115 switch ( event.keyCode ) { 116 case $.ui.keyCode.HOME: 117 case $.ui.keyCode.END: 118 case $.ui.keyCode.PAGE_UP: 119 case $.ui.keyCode.PAGE_DOWN: 120 case $.ui.keyCode.UP: 121 case $.ui.keyCode.RIGHT: 122 case $.ui.keyCode.DOWN: 123 case $.ui.keyCode.LEFT: 124 event.preventDefault(); 125 if ( !self._keySliding ) { 126 self._keySliding = true; 127 $( this ).addClass( "ui-state-active" ); 128 allowed = self._start( event, index ); 129 if ( allowed === false ) { 130 return; 131 } 132 } 133 break; 134 } 135 136 step = self.options.step; 137 if ( self.options.values && self.options.values.length ) { 138 curVal = newVal = self.values( index ); 139 } else { 140 curVal = newVal = self.value(); 141 } 142 143 switch ( event.keyCode ) { 144 case $.ui.keyCode.HOME: 145 newVal = self._valueMin(); 146 break; 147 case $.ui.keyCode.END: 148 newVal = self._valueMax(); 149 break; 150 case $.ui.keyCode.PAGE_UP: 151 newVal = self._trimAlignValue( curVal + ( (self._valueMax() - self._valueMin()) / numPages ) ); 152 break; 153 case $.ui.keyCode.PAGE_DOWN: 154 newVal = self._trimAlignValue( curVal - ( (self._valueMax() - self._valueMin()) / numPages ) ); 155 break; 156 case $.ui.keyCode.UP: 157 case $.ui.keyCode.RIGHT: 158 if ( curVal === self._valueMax() ) { 159 return; 160 } 161 newVal = self._trimAlignValue( curVal + step ); 162 break; 163 case $.ui.keyCode.DOWN: 164 case $.ui.keyCode.LEFT: 165 if ( curVal === self._valueMin() ) { 166 return; 167 } 168 newVal = self._trimAlignValue( curVal - step ); 169 break; 170 } 171 172 self._slide( event, index, newVal ); 173 }) 174 .keyup(function( event ) { 175 var index = $( this ).data( "index.ui-slider-handle" ); 176 177 if ( self._keySliding ) { 178 self._keySliding = false;
vendor: 12,629 bytes, lines 179-649
179 self._stop( event, index ); 180 self._change( event, index ); 181 $( this ).removeClass( "ui-state-active" ); 182 } 183 184 }); 185 186 this._refreshValue(); 187 188 this._animateOff = false; 189 }, 190 191 destroy: function() { 192 this.handles.remove(); 193 this.range.remove(); 194 195 this.element 196 .removeClass( "ui-slider" + 197 " ui-slider-horizontal" + 198 " ui-slider-vertical" + 199 " ui-slider-disabled" + 200 " ui-widget" + 201 " ui-widget-content" + 202 " ui-corner-all" ) 203 .removeData( "slider" ) 204 .unbind( ".slider" ); 205 206 this._mouseDestroy(); 207 208 return this; 209 }, 210 211 _mouseCapture: function( event ) { 212 var o = this.options, 213 position, 214 normValue, 215 distance, 216 closestHandle, 217 self, 218 index, 219 allowed, 220 offset, 221 mouseOverHandle; 222 223 if ( o.disabled ) { 224 return false; 225 } 226 227 this.elementSize = { 228 width: this.element.outerWidth(), 229 height: this.element.outerHeight() 230 }; 231 this.elementOffset = this.element.offset(); 232 233 position = { x: event.pageX, y: event.pageY }; 234 normValue = this._normValueFromMouse( position ); 235 distance = this._valueMax() - this._valueMin() + 1; 236 self = this; 237 this.handles.each(function( i ) { 238 var thisDistance = Math.abs( normValue - self.values(i) ); 239 if ( distance > thisDistance ) { 240 distance = thisDistance; 241 closestHandle = $( this ); 242 index = i; 243 } 244 }); 245 246 // workaround for bug #3736 (if both handles of a range are at 0, 247 // the first is always used as the one with least distance, 248 // and moving it is obviously prevented by preventing negative ranges) 249 if( o.range === true && this.values(1) === o.min ) { 250 index += 1; 251 closestHandle = $( this.handles[index] ); 252 } 253 254 allowed = this._start( event, index ); 255 if ( allowed === false ) { 256 return false; 257 } 258 this._mouseSliding = true; 259 260 self._handleIndex = index; 261 262 closestHandle 263 .addClass( "ui-state-active" ) 264 .focus(); 265 266 offset = closestHandle.offset(); 267 mouseOverHandle = !$( event.target ).parents().andSelf().is( ".ui-slider-handle" ); 268 this._clickOffset = mouseOverHandle ? { left: 0, top: 0 } : { 269 left: event.pageX - offset.left - ( closestHandle.width() / 2 ), 270 top: event.pageY - offset.top - 271 ( closestHandle.height() / 2 ) - 272 ( parseInt( closestHandle.css("borderTopWidth"), 10 ) || 0 ) - 273 ( parseInt( closestHandle.css("borderBottomWidth"), 10 ) || 0) + 274 ( parseInt( closestHandle.css("marginTop"), 10 ) || 0) 275 }; 276 277 if ( !this.handles.hasClass( "ui-state-hover" ) ) { 278 this._slide( event, index, normValue ); 279 } 280 this._animateOff = true; 281 return true; 282 }, 283 284 _mouseStart: function( event ) { 285 return true; 286 }, 287 288 _mouseDrag: function( event ) { 289 var position = { x: event.pageX, y: event.pageY }, 290 normValue = this._normValueFromMouse( position ); 291 292 this._slide( event, this._handleIndex, normValue ); 293 294 return false; 295 }, 296 297 _mouseStop: function( event ) { 298 this.handles.removeClass( "ui-state-active" ); 299 this._mouseSliding = false; 300 301 this._stop( event, this._handleIndex ); 302 this._change( event, this._handleIndex ); 303 304 this._handleIndex = null; 305 this._clickOffset = null; 306 this._animateOff = false; 307 308 return false; 309 }, 310 311 _detectOrientation: function() { 312 this.orientation = ( this.options.orientation === "vertical" ) ? "vertical" : "horizontal"; 313 }, 314 315 _normValueFromMouse: function( position ) { 316 var pixelTotal, 317 pixelMouse, 318 percentMouse, 319 valueTotal, 320 valueMouse; 321 322 if ( this.orientation === "horizontal" ) { 323 pixelTotal = this.elementSize.width; 324 pixelMouse = position.x - this.elementOffset.left - ( this._clickOffset ? this._clickOffset.left : 0 ); 325 } else { 326 pixelTotal = this.elementSize.height; 327 pixelMouse = position.y - this.elementOffset.top - ( this._clickOffset ? this._clickOffset.top : 0 ); 328 } 329 330 percentMouse = ( pixelMouse / pixelTotal ); 331 if ( percentMouse > 1 ) { 332 percentMouse = 1; 333 } 334 if ( percentMouse < 0 ) { 335 percentMouse = 0; 336 } 337 if ( this.orientation === "vertical" ) { 338 percentMouse = 1 - percentMouse; 339 } 340 341 valueTotal = this._valueMax() - this._valueMin(); 342 valueMouse = this._valueMin() + percentMouse * valueTotal; 343 344 return this._trimAlignValue( valueMouse ); 345 }, 346 347 _start: function( event, index ) { 348 var uiHash = { 349 handle: this.handles[ index ], 350 value: this.value() 351 }; 352 if ( this.options.values && this.options.values.length ) { 353 uiHash.value = this.values( index ); 354 uiHash.values = this.values(); 355 } 356 return this._trigger( "start", event, uiHash ); 357 }, 358 359 _slide: function( event, index, newVal ) { 360 var otherVal, 361 newValues, 362 allowed; 363 364 if ( this.options.values && this.options.values.length ) { 365 otherVal = this.values( index ? 0 : 1 ); 366 367 if ( ( this.options.values.length === 2 && this.options.range === true ) && 368 ( ( index === 0 && newVal > otherVal) || ( index === 1 && newVal < otherVal ) ) 369 ) { 370 newVal = otherVal; 371 } 372 373 if ( newVal !== this.values( index ) ) { 374 newValues = this.values(); 375 newValues[ index ] = newVal; 376 // A slide can be canceled by returning false from the slide callback 377 allowed = this._trigger( "slide", event, { 378 handle: this.handles[ index ], 379 value: newVal, 380 values: newValues 381 } ); 382 otherVal = this.values( index ? 0 : 1 ); 383 if ( allowed !== false ) { 384 this.values( index, newVal, true ); 385 } 386 } 387 } else { 388 if ( newVal !== this.value() ) { 389 // A slide can be canceled by returning false from the slide callback 390 allowed = this._trigger( "slide", event, { 391 handle: this.handles[ index ], 392 value: newVal 393 } ); 394 if ( allowed !== false ) { 395 this.value( newVal ); 396 } 397 } 398 } 399 }, 400 401 _stop: function( event, index ) { 402 var uiHash = { 403 handle: this.handles[ index ], 404 value: this.value() 405 }; 406 if ( this.options.values && this.options.values.length ) { 407 uiHash.value = this.values( index ); 408 uiHash.values = this.values(); 409 } 410 411 this._trigger( "stop", event, uiHash ); 412 }, 413 414 _change: function( event, index ) { 415 if ( !this._keySliding && !this._mouseSliding ) { 416 var uiHash = { 417 handle: this.handles[ index ], 418 value: this.value() 419 }; 420 if ( this.options.values && this.options.values.length ) { 421 uiHash.value = this.values( index ); 422 uiHash.values = this.values(); 423 } 424 425 this._trigger( "change", event, uiHash ); 426 } 427 }, 428 429 value: function( newValue ) { 430 if ( arguments.length ) { 431 this.options.value = this._trimAlignValue( newValue ); 432 this._refreshValue(); 433 this._change( null, 0 ); 434 return; 435 } 436 437 return this._value(); 438 }, 439 440 values: function( index, newValue ) { 441 var vals, 442 newValues, 443 i; 444 445 if ( arguments.length > 1 ) { 446 this.options.values[ index ] = this._trimAlignValue( newValue ); 447 this._refreshValue(); 448 this._change( null, index ); 449 return; 450 } 451 452 if ( arguments.length ) { 453 if ( $.isArray( arguments[ 0 ] ) ) { 454 vals = this.options.values; 455 newValues = arguments[ 0 ]; 456 for ( i = 0; i < vals.length; i += 1 ) { 457 vals[ i ] = this._trimAlignValue( newValues[ i ] ); 458 this._change( null, i ); 459 } 460 this._refreshValue(); 461 } else { 462 if ( this.options.values && this.options.values.length ) { 463 return this._values( index ); 464 } else { 465 return this.value(); 466 } 467 } 468 } else { 469 return this._values(); 470 } 471 }, 472 473 _setOption: function( key, value ) { 474 var i, 475 valsLength = 0; 476 477 if ( $.isArray( this.options.values ) ) { 478 valsLength = this.options.values.length; 479 } 480 481 $.Widget.prototype._setOption.apply( this, arguments ); 482 483 switch ( key ) { 484 case "disabled": 485 if ( value ) { 486 this.handles.filter( ".ui-state-focus" ).blur(); 487 this.handles.removeClass( "ui-state-hover" ); 488 this.handles.propAttr( "disabled", true ); 489 this.element.addClass( "ui-disabled" ); 490 } else { 491 this.handles.propAttr( "disabled", false ); 492 this.element.removeClass( "ui-disabled" ); 493 } 494 break; 495 case "orientation": 496 this._detectOrientation(); 497 this.element 498 .removeClass( "ui-slider-horizontal ui-slider-vertical" ) 499 .addClass( "ui-slider-" + this.orientation ); 500 this._refreshValue(); 501 break; 502 case "value": 503 this._animateOff = true; 504 this._refreshValue(); 505 this._change( null, 0 ); 506 this._animateOff = false; 507 break; 508 case "values": 509 this._animateOff = true; 510 this._refreshValue(); 511 for ( i = 0; i < valsLength; i += 1 ) { 512 this._change( null, i ); 513 } 514 this._animateOff = false; 515 break; 516 } 517 }, 518 519 //internal value getter 520 // _value() returns value trimmed by min and max, aligned by step 521 _value: function() { 522 var val = this.options.value; 523 val = this._trimAlignValue( val ); 524 525 return val; 526 }, 527 528 //internal values getter 529 // _values() returns array of values trimmed by min and max, aligned by step 530 // _values( index ) returns single value trimmed by min and max, aligned by step 531 _values: function( index ) { 532 var val, 533 vals, 534 i; 535 536 if ( arguments.length ) { 537 val = this.options.values[ index ]; 538 val = this._trimAlignValue( val ); 539 540 return val; 541 } else { 542 // .slice() creates a copy of the array 543 // this copy gets trimmed by min and max and then returned 544 vals = this.options.values.slice(); 545 for ( i = 0; i < vals.length; i+= 1) { 546 vals[ i ] = this._trimAlignValue( vals[ i ] ); 547 } 548 549 return vals; 550 } 551 }, 552 553 // returns the step-aligned value that val is closest to, between (inclusive) min and max 554 _trimAlignValue: function( val ) { 555 if ( val <= this._valueMin() ) { 556 return this._valueMin(); 557 } 558 if ( val >= this._valueMax() ) { 559 return this._valueMax(); 560 } 561 var step = ( this.options.step > 0 ) ? this.options.step : 1, 562 valModStep = (val - this._valueMin()) % step, 563 alignValue = val - valModStep; 564 565 if ( Math.abs(valModStep) * 2 >= step ) { 566 alignValue += ( valModStep > 0 ) ? step : ( -step ); 567 } 568 569 // Since JavaScript has problems with large floats, round 570 // the final value to 5 digits after the decimal point (see #4124) 571 return parseFloat( alignValue.toFixed(5) ); 572 }, 573 574 _valueMin: function() { 575 return this.options.min; 576 }, 577 578 _valueMax: function() { 579 return this.options.max; 580 }, 581 582 _refreshValue: function() { 583 var oRange = this.options.range, 584 o = this.options, 585 self = this, 586 animate = ( !this._animateOff ) ? o.animate : false, 587 valPercent, 588 _set = {}, 589 lastValPercent, 590 value, 591 valueMin, 592 valueMax; 593 594 if ( this.options.values && this.options.values.length ) { 595 this.handles.each(function( i, j ) { 596 valPercent = ( self.values(i) - self._valueMin() ) / ( self._valueMax() - self._valueMin() ) * 100; 597 _set[ self.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%"; 598 $( this ).stop( 1, 1 )[ animate ? "animate" : "css" ]( _set, o.animate ); 599 if ( self.options.range === true ) { 600 if ( self.orientation === "horizontal" ) { 601 if ( i === 0 ) { 602 self.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { left: valPercent + "%" }, o.animate ); 603 } 604 if ( i === 1 ) { 605 self.range[ animate ? "animate" : "css" ]( { width: ( valPercent - lastValPercent ) + "%" }, { queue: false, duration: o.animate } ); 606 } 607 } else { 608 if ( i === 0 ) { 609 self.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { bottom: ( valPercent ) + "%" }, o.animate ); 610 } 611 if ( i === 1 ) { 612 self.range[ animate ? "animate" : "css" ]( { height: ( valPercent - lastValPercent ) + "%" }, { queue: false, duration: o.animate } ); 613 } 614 } 615 } 616 lastValPercent = valPercent; 617 }); 618 } else { 619 value = this.value(); 620 valueMin = this._valueMin(); 621 valueMax = this._valueMax(); 622 valPercent = ( valueMax !== valueMin ) ? 623 ( value - valueMin ) / ( valueMax - valueMin ) * 100 : 624 0; 625 _set[ self.orientation === "horizontal" ? "left" : "bottom" ] = valPercent + "%"; 626 this.handle.stop( 1, 1 )[ animate ? "animate" : "css" ]( _set, o.animate ); 627 628 if ( oRange === "min" && this.orientation === "horizontal" ) { 629 this.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { width: valPercent + "%" }, o.animate ); 630 } 631 if ( oRange === "max" && this.orientation === "horizontal" ) { 632 this.range[ animate ? "animate" : "css" ]( { width: ( 100 - valPercent ) + "%" }, { queue: false, duration: o.animate } ); 633 } 634 if ( oRange === "min" && this.orientation === "vertical" ) { 635 this.range.stop( 1, 1 )[ animate ? "animate" : "css" ]( { height: valPercent + "%" }, o.animate ); 636 } 637 if ( oRange === "max" && this.orientation === "vertical" ) { 638 this.range[ animate ? "animate" : "css" ]( { height: ( 100 - valPercent ) + "%" }, { queue: false, duration: o.animate } ); 639 } 640 } 641 } 642 643}); 644 645$.extend( $.ui.slider, { 646 version: "1.8.23" 647}); 648 649}(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.