1/** 2 * jquery.resizestop (and resizestart) 3 * by: Fatih Kadir Akın 4 * https://github.com/f/jquery.resizestop 5 * License is CC0, published to the public domain. 6 * @param {jQuery} $ 7 */ 8// Used by datepicker when position is top or bottom of the screen 9( function( $ ) { 10 'use strict'; 11 // Slice shortcut 12 var slice = Array.prototype.slice; 13 14 // Special event definition 15 $.extend( $.event.special, { 16 // resize stop special event. 17 resizestop: { 18 add: function( handle ) { 19 // shortcut to the event handler. 20 var handler = handle.handler; 21 22 // event modifying 23 $( this ).on( 'resize', function( e ) { 24 var _proxy; 25 // every resize event clears handler's timer. 26 // and every handler must have a timer. 27 clearTimeout( handler._timer ); 28 // change event type text. 29 e.type = 'resizestop'; 30 // push the "resize" event to the handler. 31 _proxy = $.proxy( handler, this, e ); 32 // if no resize event fired for a time that we decide, 33 // then it means its stopped. 34 handler._timer = setTimeout( _proxy, handle.data || 200 ); 35 } ); 36 } 37 }, 38 // resize start special event 39 resizestart: { 40 add: function( handle ) { 41 // shortcut to the event handler. 42 var handler = handle.handler; 43 44 // event modifying 45 $( this ).on( 'resize', function( e ) { 46 // every resize event clears handler's timer. 47 // and every handler must have a timer. 48 clearTimeout( handler._timer ); 49 // we suddenly fire the event, then we can put 50 // a flag with name _started knows if it's already fired. 51 if ( ! handler._started ) { 52 e.type = 'resizestart'; 53 handler.apply( this, arguments ); 54 // after firing the handler, put the flag with the value "true" 55 handler._started = true; 56 } 57 handler._timer = setTimeout( 58 $.proxy( function() { 59 // after a while, it will make the flag false. 60 handler._started = false; 61 }, this ), 62 handle.data || 300 63 ); 64 } ); 65 } 66 } 67 } ); 68 // binding and currying the shortcuts. 69 $.extend( $.fn, { 70 // $(window).resizestop instead of $(window).on('resizestop') 71 resizestop: function() { 72 // will push the "resizestop" argument at the beginning of arguments 73 $( this ).on.apply( this, [ 'resizestop' ].concat( slice.call( arguments ) ) ); 74 }, 75 // $(window).resizestart instead of $(window).on('resizestart') 76 resizestart: function() { 77 // will push the "resizestart" argument at the beginning of arguments 78 $( this ).on.apply( this, [ 'resizestart' ].concat( slice.call( arguments ) ) ); 79 } 80 } ); 81}( window.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.