vendor: 4,462 bytes, lines 1-157
1/*! 2 * jQuery UI Widget @VERSION 3 * http://jqueryui.com 4 * 5 * Copyright jQuery Foundation and other contributors 6 * Released under the MIT license. 7 * http://jquery.org/license 8 */ 9 10//>>label: Widget 11//>>group: UI Core 12//>>description: Provides a factory for creating stateful widgets with a common API. 13//>>docs: http://api.jqueryui.com/jQuery.widget/ 14//>>demos: http://jqueryui.com/widget/ 15 16( function( factory ) { 17 if ( typeof define === "function" && define.amd ) { 18 19 // AMD. Register as an anonymous module. 20 define( [ "jquery", "./version" ], factory ); 21 } else { 22 23 // Browser globals 24 factory( jQuery ); 25 } 26}( function( $ ) { 27 28var widgetUuid = 0; 29var widgetSlice = Array.prototype.slice; 30 31$.cleanData = ( function( orig ) { 32 return function( elems ) { 33 var events, elem, i; 34 for ( i = 0; ( elem = elems[ i ] ) != null; i++ ) { 35 try { 36 37 // Only trigger remove when necessary to save time 38 events = $._data( elem, "events" ); 39 if ( events && events.remove ) { 40 $( elem ).triggerHandler( "remove" ); 41 } 42 43 // Http://bugs.jquery.com/ticket/8235 44 } catch ( e ) {} 45 } 46 orig( elems ); 47 }; 48} )( $.cleanData ); 49 50$.widget = function( name, base, prototype ) { 51 var existingConstructor, constructor, basePrototype; 52 53 // ProxiedPrototype allows the provided prototype to remain unmodified 54 // so that it can be used as a mixin for multiple widgets (#8876) 55 var proxiedPrototype = {}; 56 57 var namespace = name.split( "." )[ 0 ]; 58 name = name.split( "." )[ 1 ]; 59 var fullName = namespace + "-" + name; 60 61 if ( !prototype ) { 62 prototype = base; 63 base = $.Widget; 64 } 65 66 if ( $.isArray( prototype ) ) { 67 prototype = $.extend.apply( null, [ {} ].concat( prototype ) ); 68 } 69 70 // Create selector for plugin 71 $.expr[ ":" ][ fullName.toLowerCase() ] = function( elem ) { 72 return !!$.data( elem, fullName ); 73 }; 74 75 $[ namespace ] = $[ namespace ] || {}; 76 existingConstructor = $[ namespace ][ name ]; 77 constructor = $[ namespace ][ name ] = function( options, element ) { 78 79 // Allow instantiation without "new" keyword 80 if ( !this._createWidget ) { 81 return new constructor( options, element ); 82 } 83 84 // Allow instantiation without initializing for simple inheritance 85 // must use "new" keyword (the code above always passes args) 86 if ( arguments.length ) { 87 this._createWidget( options, element ); 88 } 89 }; 90 91 // Extend with the existing constructor to carry over any static properties 92 $.extend( constructor, existingConstructor, { 93 version: prototype.version, 94 95 // Copy the object used to create the prototype in case we need to 96 // redefine the widget later 97 _proto: $.extend( {}, prototype ), 98 99 // Track widgets that inherit from this widget in case this widget is 100 // redefined after a widget inherits from it 101 _childConstructors: [] 102 } ); 103 104 basePrototype = new base(); 105 106 // We need to make the options hash a property directly on the new instance 107 // otherwise we'll modify the options hash on the prototype that we're 108 // inheriting from 109 basePrototype.options = $.widget.extend( {}, basePrototype.options ); 110 $.each( prototype, function( prop, value ) { 111 if ( !$.isFunction( value ) ) { 112 proxiedPrototype[ prop ] = value; 113 return; 114 } 115 proxiedPrototype[ prop ] = ( function() { 116 function _super() { 117 return base.prototype[ prop ].apply( this, arguments ); 118 } 119 120 function _superApply( args ) { 121 return base.prototype[ prop ].apply( this, args ); 122 } 123 124 return function() { 125 var __super = this._super; 126 var __superApply = this._superApply; 127 var returnValue; 128 129 this._super = _super; 130 this._superApply = _superApply; 131 132 returnValue = value.apply( this, arguments ); 133 134 this._super = __super; 135 this._superApply = __superApply; 136 137 return returnValue; 138 }; 139 } )(); 140 } ); 141 constructor.prototype = $.widget.extend( basePrototype, { 142 143 // TODO: remove support for widgetEventPrefix 144 // always use the name + a colon as the prefix, e.g., draggable:start 145 // don't prefix for widgets that aren't DOM-based 146 widgetEventPrefix: existingConstructor ? ( basePrototype.widgetEventPrefix || name ) : name 147 }, proxiedPrototype, { 148 constructor: constructor, 149 namespace: namespace, 150 widgetName: name, 151 widgetFullName: fullName 152 } ); 153 154 // If this widget is being redefined then we need to find all widgets that 155 // are inheriting from it and redefine all of them so that they inherit from 156 // the new version of this widget. We're essentially trying to replace one 157 // level in the prototype chain.
vendor: 4,554 bytes, lines 158-339
158 if ( existingConstructor ) { 159 $.each( existingConstructor._childConstructors, function( i, child ) { 160 var childPrototype = child.prototype; 161 162 // Redefine the child widget using the same prototype that was 163 // originally used, but inherit from the new version of the base 164 $.widget( childPrototype.namespace + "." + childPrototype.widgetName, constructor, 165 child._proto ); 166 } ); 167 168 // Remove the list of existing child constructors from the old constructor 169 // so the old child constructors can be garbage collected 170 delete existingConstructor._childConstructors; 171 } else { 172 base._childConstructors.push( constructor ); 173 } 174 175 $.widget.bridge( name, constructor ); 176 177 return constructor; 178}; 179 180$.widget.extend = function( target ) { 181 var input = widgetSlice.call( arguments, 1 ); 182 var inputIndex = 0; 183 var inputLength = input.length; 184 var key; 185 var value; 186 187 for ( ; inputIndex < inputLength; inputIndex++ ) { 188 for ( key in input[ inputIndex ] ) { 189 value = input[ inputIndex ][ key ]; 190 if ( input[ inputIndex ].hasOwnProperty( key ) && value !== undefined ) { 191 192 // Clone objects 193 if ( $.isPlainObject( value ) ) { 194 target[ key ] = $.isPlainObject( target[ key ] ) ? 195 $.widget.extend( {}, target[ key ], value ) : 196 197 // Don't extend strings, arrays, etc. with objects 198 $.widget.extend( {}, value ); 199 200 // Copy everything else by reference 201 } else { 202 target[ key ] = value; 203 } 204 } 205 } 206 } 207 return target; 208}; 209 210$.widget.bridge = function( name, object ) { 211 var fullName = object.prototype.widgetFullName || name; 212 $.fn[ name ] = function( options ) { 213 var isMethodCall = typeof options === "string"; 214 var args = widgetSlice.call( arguments, 1 ); 215 var returnValue = this; 216 217 if ( isMethodCall ) { 218 this.each( function() { 219 var methodValue; 220 var instance = $.data( this, fullName ); 221 222 if ( options === "instance" ) { 223 returnValue = instance; 224 return false; 225 } 226 227 if ( !instance ) { 228 return $.error( "cannot call methods on " + name + " prior to initialization; " + 229 "attempted to call method '" + options + "'" ); 230 } 231 232 if ( !$.isFunction( instance[ options ] ) || options.charAt( 0 ) === "_" ) { 233 return $.error( "no such method '" + options + "' for " + name + " widget instance" ); 234 } 235 236 methodValue = instance[ options ].apply( instance, args ); 237 238 if ( methodValue !== instance && methodValue !== undefined ) { 239 returnValue = methodValue && methodValue.jquery ? 240 returnValue.pushStack( methodValue.get() ) : 241 methodValue; 242 return false; 243 } 244 } ); 245 } else { 246 247 // Allow multiple hashes to be passed on init 248 if ( args.length ) { 249 options = $.widget.extend.apply( null, [ options ].concat( args ) ); 250 } 251 252 this.each( function() { 253 var instance = $.data( this, fullName ); 254 if ( instance ) { 255 instance.option( options || {} ); 256 if ( instance._init ) { 257 instance._init(); 258 } 259 } else { 260 $.data( this, fullName, new object( options, this ) ); 261 } 262 } ); 263 } 264 265 return returnValue; 266 }; 267}; 268 269$.Widget = function( /* options, element */ ) {}; 270$.Widget._childConstructors = []; 271 272$.Widget.prototype = { 273 widgetName: "widget", 274 widgetEventPrefix: "", 275 defaultElement: "<div>", 276 277 options: { 278 classes: {}, 279 disabled: false, 280 281 // Callbacks 282 create: null 283 }, 284 285 _createWidget: function( options, element ) { 286 element = $( element || this.defaultElement || this )[ 0 ]; 287 this.element = $( element ); 288 this.uuid = widgetUuid++; 289 this.eventNamespace = "." + this.widgetName + this.uuid; 290 291 this.bindings = $(); 292 this.hoverable = $(); 293 this.focusable = $(); 294 this.classesElementLookup = {}; 295 296 if ( element !== this ) { 297 $.data( element, this.widgetFullName, this ); 298 this._on( true, this.element, { 299 remove: function( event ) { 300 if ( event.target === element ) { 301 this.destroy(); 302 } 303 } 304 } ); 305 this.document = $( element.style ? 306 307 // Element within the document 308 element.ownerDocument : 309 310 // Element is window or document 311 element.document || element ); 312 this.window = $( this.document[ 0 ].defaultView || this.document[ 0 ].parentWindow ); 313 } 314 315 this.options = $.widget.extend( {}, 316 this.options, 317 this._getCreateOptions(), 318 options ); 319 320 this._create(); 321 322 if ( this.options.disabled ) { 323 this._setOptionDisabled( this.options.disabled ); 324 } 325 326 this._trigger( "create", null, this._getCreateEventData() ); 327 this._init(); 328 }, 329 330 _getCreateOptions: function() { 331 return {}; 332 }, 333 334 _getCreateEventData: $.noop, 335 336 _create: $.noop, 337 338 _init: $.noop, 339
vendor: 4,622 bytes, lines 340-515
340 destroy: function() { 341 var that = this; 342 343 this._destroy(); 344 $.each( this.classesElementLookup, function( key, value ) { 345 that._removeClass( value, key ); 346 } ); 347 348 // We can probably remove the unbind calls in 2.0 349 // all event bindings should go through this._on() 350 this.element 351 .off( this.eventNamespace ) 352 .removeData( this.widgetFullName ); 353 this.widget() 354 .off( this.eventNamespace ) 355 .removeAttr( "aria-disabled" ); 356 357 // Clean up events and states 358 this.bindings.off( this.eventNamespace ); 359 }, 360 361 _destroy: $.noop, 362 363 widget: function() { 364 return this.element; 365 }, 366 367 option: function( key, value ) { 368 var options = key; 369 var parts; 370 var curOption; 371 var i; 372 373 if ( arguments.length === 0 ) { 374 375 // Don't return a reference to the internal hash 376 return $.widget.extend( {}, this.options ); 377 } 378 379 if ( typeof key === "string" ) { 380 381 // Handle nested keys, e.g., "foo.bar" => { foo: { bar: ___ } } 382 options = {}; 383 parts = key.split( "." ); 384 key = parts.shift(); 385 if ( parts.length ) { 386 curOption = options[ key ] = $.widget.extend( {}, this.options[ key ] ); 387 for ( i = 0; i < parts.length - 1; i++ ) { 388 curOption[ parts[ i ] ] = curOption[ parts[ i ] ] || {}; 389 curOption = curOption[ parts[ i ] ]; 390 } 391 key = parts.pop(); 392 if ( arguments.length === 1 ) { 393 return curOption[ key ] === undefined ? null : curOption[ key ]; 394 } 395 curOption[ key ] = value; 396 } else { 397 if ( arguments.length === 1 ) { 398 return this.options[ key ] === undefined ? null : this.options[ key ]; 399 } 400 options[ key ] = value; 401 } 402 } 403 404 this._setOptions( options ); 405 406 return this; 407 }, 408 409 _setOptions: function( options ) { 410 var key; 411 412 for ( key in options ) { 413 this._setOption( key, options[ key ] ); 414 } 415 416 return this; 417 }, 418 419 _setOption: function( key, value ) { 420 if ( key === "classes" ) { 421 this._setOptionClasses( value ); 422 } 423 424 this.options[ key ] = value; 425 426 if ( key === "disabled" ) { 427 this._setOptionDisabled( value ); 428 } 429 430 return this; 431 }, 432 433 _setOptionClasses: function( value ) { 434 var classKey, elements, currentElements; 435 436 for ( classKey in value ) { 437 currentElements = this.classesElementLookup[ classKey ]; 438 if ( value[ classKey ] === this.options.classes[ classKey ] || 439 !currentElements || 440 !currentElements.length ) { 441 continue; 442 } 443 444 // We are doing this to create a new jQuery object because the _removeClass() call 445 // on the next line is going to destroy the reference to the current elements being 446 // tracked. We need to save a copy of this collection so that we can add the new classes 447 // below. 448 elements = $( currentElements.get() ); 449 this._removeClass( currentElements, classKey ); 450 451 // We don't use _addClass() here, because that uses this.options.classes 452 // for generating the string of classes. We want to use the value passed in from 453 // _setOption(), this is the new value of the classes option which was passed to 454 // _setOption(). We pass this value directly to _classes(). 455 elements.addClass( this._classes( { 456 element: elements, 457 keys: classKey, 458 classes: value, 459 add: true 460 } ) ); 461 } 462 }, 463 464 _setOptionDisabled: function( value ) { 465 this._toggleClass( this.widget(), this.widgetFullName + "-disabled", null, !!value ); 466 467 // If the widget is becoming disabled, then nothing is interactive 468 if ( value ) { 469 this._removeClass( this.hoverable, null, "ui-state-hover" ); 470 this._removeClass( this.focusable, null, "ui-state-focus" ); 471 } 472 }, 473 474 enable: function() { 475 return this._setOptions( { disabled: false } ); 476 }, 477 478 disable: function() { 479 return this._setOptions( { disabled: true } ); 480 }, 481 482 _classes: function( options ) { 483 var full = []; 484 var that = this; 485 486 options = $.extend( { 487 element: this.element, 488 classes: this.options.classes || {} 489 }, options ); 490 491 function processClassString( classes, checkOption ) { 492 var current, i; 493 for ( i = 0; i < classes.length; i++ ) { 494 current = that.classesElementLookup[ classes[ i ] ] || $(); 495 if ( options.add ) { 496 current = $( $.unique( current.get().concat( options.element.get() ) ) ); 497 } else { 498 current = $( current.not( options.element ).get() ); 499 } 500 that.classesElementLookup[ classes[ i ] ] = current; 501 full.push( classes[ i ] ); 502 if ( checkOption && options.classes[ classes[ i ] ] ) { 503 full.push( options.classes[ classes[ i ] ] ); 504 } 505 } 506 } 507 508 if ( options.keys ) { 509 processClassString( options.keys.match( /\S+/g ) || [], true ); 510 } 511 if ( options.extra ) { 512 processClassString( options.extra.match( /\S+/g ) || [] ); 513 } 514 515 return full.join( " "
vendor: 5,479 bytes, lines 515-708
515 ); 516 }, 517 518 _removeClass: function( element, keys, extra ) { 519 return this._toggleClass( element, keys, extra, false ); 520 }, 521 522 _addClass: function( element, keys, extra ) { 523 return this._toggleClass( element, keys, extra, true ); 524 }, 525 526 _toggleClass: function( element, keys, extra, add ) { 527 add = ( typeof add === "boolean" ) ? add : extra; 528 var shift = ( typeof element === "string" || element === null ), 529 options = { 530 extra: shift ? keys : extra, 531 keys: shift ? element : keys, 532 element: shift ? this.element : element, 533 add: add 534 }; 535 options.element.toggleClass( this._classes( options ), add ); 536 return this; 537 }, 538 539 _on: function( suppressDisabledCheck, element, handlers ) { 540 var delegateElement; 541 var instance = this; 542 543 // No suppressDisabledCheck flag, shuffle arguments 544 if ( typeof suppressDisabledCheck !== "boolean" ) { 545 handlers = element; 546 element = suppressDisabledCheck; 547 suppressDisabledCheck = false; 548 } 549 550 // No element argument, shuffle and use this.element 551 if ( !handlers ) { 552 handlers = element; 553 element = this.element; 554 delegateElement = this.widget(); 555 } else { 556 element = delegateElement = $( element ); 557 this.bindings = this.bindings.add( element ); 558 } 559 560 $.each( handlers, function( event, handler ) { 561 function handlerProxy() { 562 563 // Allow widgets to customize the disabled handling 564 // - disabled as an array instead of boolean 565 // - disabled class as method for disabling individual parts 566 if ( !suppressDisabledCheck && 567 ( instance.options.disabled === true || 568 $( this ).hasClass( "ui-state-disabled" ) ) ) { 569 return; 570 } 571 return ( typeof handler === "string" ? instance[ handler ] : handler ) 572 .apply( instance, arguments ); 573 } 574 575 // Copy the guid so direct unbinding works 576 if ( typeof handler !== "string" ) { 577 handlerProxy.guid = handler.guid = 578 handler.guid || handlerProxy.guid || $.guid++; 579 } 580 581 var match = event.match( /^([\w:-]*)\s*(.*)$/ ); 582 var eventName = match[ 1 ] + instance.eventNamespace; 583 var selector = match[ 2 ]; 584 585 if ( selector ) { 586 delegateElement.on( eventName, selector, handlerProxy ); 587 } else { 588 element.on( eventName, handlerProxy ); 589 } 590 } ); 591 }, 592 593 _off: function( element, eventName ) { 594 eventName = ( eventName || "" ).split( " " ).join( this.eventNamespace + " " ) + 595 this.eventNamespace; 596 element.off( eventName ).off( eventName ); 597 598 // Clear the stack to avoid memory leaks (#10056) 599 this.bindings = $( this.bindings.not( element ).get() ); 600 this.focusable = $( this.focusable.not( element ).get() ); 601 this.hoverable = $( this.hoverable.not( element ).get() ); 602 }, 603 604 _delay: function( handler, delay ) { 605 function handlerProxy() { 606 return ( typeof handler === "string" ? instance[ handler ] : handler ) 607 .apply( instance, arguments ); 608 } 609 var instance = this; 610 return setTimeout( handlerProxy, delay || 0 ); 611 }, 612 613 _hoverable: function( element ) { 614 this.hoverable = this.hoverable.add( element ); 615 this._on( element, { 616 mouseenter: function( event ) { 617 this._addClass( $( event.currentTarget ), null, "ui-state-hover" ); 618 }, 619 mouseleave: function( event ) { 620 this._removeClass( $( event.currentTarget ), null, "ui-state-hover" ); 621 } 622 } ); 623 }, 624 625 _focusable: function( element ) { 626 this.focusable = this.focusable.add( element ); 627 this._on( element, { 628 focusin: function( event ) { 629 this._addClass( $( event.currentTarget ), null, "ui-state-focus" ); 630 }, 631 focusout: function( event ) { 632 this._removeClass( $( event.currentTarget ), null, "ui-state-focus" ); 633 } 634 } ); 635 }, 636 637 _trigger: function( type, event, data ) { 638 var prop, orig; 639 var callback = this.options[ type ]; 640 641 data = data || {}; 642 event = $.Event( event ); 643 event.type = ( type === this.widgetEventPrefix ? 644 type : 645 this.widgetEventPrefix + type ).toLowerCase(); 646 647 // The original event may come from any element 648 // so we need to reset the target on the new event 649 event.target = this.element[ 0 ]; 650 651 // Copy original event properties over to the new event 652 orig = event.originalEvent; 653 if ( orig ) { 654 for ( prop in orig ) { 655 if ( !( prop in event ) ) { 656 event[ prop ] = orig[ prop ]; 657 } 658 } 659 } 660 661 this.element.trigger( event, data ); 662 return !( $.isFunction( callback ) && 663 callback.apply( this.element[ 0 ], [ event ].concat( data ) ) === false || 664 event.isDefaultPrevented() ); 665 } 666}; 667 668$.each( { show: "fadeIn", hide: "fadeOut" }, function( method, defaultEffect ) { 669 $.Widget.prototype[ "_" + method ] = function( element, options, callback ) { 670 if ( typeof options === "string" ) { 671 options = { effect: options }; 672 } 673 674 var hasOptions; 675 var effectName = !options ? 676 method : 677 options === true || typeof options === "number" ? 678 defaultEffect : 679 options.effect || defaultEffect; 680 681 options = options || {}; 682 if ( typeof options === "number" ) { 683 options = { duration: options }; 684 } 685 686 hasOptions = !$.isEmptyObject( options ); 687 options.complete = callback; 688 689 if ( options.delay ) { 690 element.delay( options.delay ); 691 } 692 693 if ( hasOptions && $.effects && $.effects.effect[ effectName ] ) { 694 element[ method ]( options ); 695 } else if ( effectName !== method && element[ effectName ] ) { 696 element[ effectName ]( options.duration, options.easing, callback ); 697 } else { 698 element.queue( function( next ) { 699 $( this )[ method ](); 700 if ( callback ) { 701 callback.call( element[ 0 ] ); 702 } 703 next(); 704 } ); 705 } 706 }; 707} ); 708
709return $.widget; 710 711} ) );
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.