vendor: 3,561 bytes, lines 1-144
1/** 2 * Bridget makes jQuery widgets 3 * v2.0.0 4 * MIT license 5 */ 6 7/* jshint browser: true, strict: true, undef: true, unused: true */ 8 9( function( window, factory ) { 10 'use strict'; 11 /* globals define: false, module: false, require: false */ 12 13 if ( typeof define == 'function' && define.amd ) { 14 // AMD 15 define( [ 'jquery' ], function( jQuery ) { 16 factory( window, jQuery ); 17 }); 18 } else if ( typeof module == 'object' && module.exports ) { 19 // CommonJS 20 module.exports = factory( 21 window, 22 require('jquery') 23 ); 24 } else { 25 // browser global 26 window.jQueryBridget = factory( 27 window, 28 window.jQuery 29 ); 30 } 31 32}( window, function factory( window, jQuery ) { 33'use strict'; 34 35// ----- utils ----- // 36 37var arraySlice = Array.prototype.slice; 38 39// helper function for logging errors 40// $.error breaks jQuery chaining 41var console = window.console; 42var logError = typeof console == 'undefined' ? function() {} : 43 function( message ) { 44 console.error( message ); 45 }; 46 47// ----- jQueryBridget ----- // 48 49function jQueryBridget( namespace, PluginClass, $ ) { 50 $ = $ || jQuery || window.jQuery; 51 if ( !$ ) { 52 return; 53 } 54 55 // add option method -> $().plugin('option', {...}) 56 if ( !PluginClass.prototype.option ) { 57 // option setter 58 PluginClass.prototype.option = function( opts ) { 59 // bail out if not an object 60 if ( !$.isPlainObject( opts ) ){ 61 return; 62 } 63 this.options = $.extend( true, this.options, opts ); 64 }; 65 } 66 67 // make jQuery plugin 68 $.fn[ namespace ] = function( arg0 /*, arg1 */ ) { 69 if ( typeof arg0 == 'string' ) { 70 // method call $().plugin( 'methodName', { options } ) 71 // shift arguments by 1 72 var args = arraySlice.call( arguments, 1 ); 73 return methodCall( this, arg0, args ); 74 } 75 // just $().plugin({ options }) 76 plainCall( this, arg0 ); 77 return this; 78 }; 79 80 // $().plugin('methodName') 81 function methodCall( $elems, methodName, args ) { 82 var returnValue; 83 var pluginMethodStr = '$().' + namespace + '("' + methodName + '")'; 84 85 $elems.each( function( i, elem ) { 86 // get instance 87 var instance = $.data( elem, namespace ); 88 if ( !instance ) { 89 logError( namespace + ' not initialized. Cannot call methods, i.e. ' + 90 pluginMethodStr ); 91 return; 92 } 93 94 var method = instance[ methodName ]; 95 if ( !method || methodName.charAt(0) == '_' ) { 96 logError( pluginMethodStr + ' is not a valid method' ); 97 return; 98 } 99 100 // apply method, get return value 101 var value = method.apply( instance, args ); 102 // set return value if value is returned, use only first value 103 returnValue = returnValue === undefined ? value : returnValue; 104 }); 105 106 return returnValue !== undefined ? returnValue : $elems; 107 } 108 109 function plainCall( $elems, options ) { 110 $elems.each( function( i, elem ) { 111 var instance = $.data( elem, namespace ); 112 if ( instance ) { 113 // set options & init 114 instance.option( options ); 115 instance._init(); 116 } else { 117 // initialize new instance 118 instance = new PluginClass( elem, options ); 119 $.data( elem, namespace, instance ); 120 } 121 }); 122 } 123 124 updateJQuery( $ ); 125 126} 127 128// ----- updateJQuery ----- // 129 130// set $.bridget for v1 backwards compatibility 131function updateJQuery( $ ) { 132 if ( !$ || ( $ && $.bridget ) ) { 133 return; 134 } 135 $.bridget = jQueryBridget; 136} 137 138updateJQuery( jQuery || window.jQuery ); 139 140// ----- ----- // 141 142return jQueryBridget; 143 144}));
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.