Tizen 2.1 base
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.2.0 / js / events / throttledresize.js
1 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
2 //>>description: Throttled resize event
3 //>>label: throttledresize
4 //>>group: Events
5
6 define( [ "jquery" ], function( jQuery ) {
7 //>>excludeEnd("jqmBuildExclude");
8
9         // throttled resize event
10         (function( $ ) {
11                 $.event.special.throttledresize = {
12                         setup: function() {
13                                 $( this ).bind( "resize", handler );
14                         },
15                         teardown: function() {
16                                 $( this ).unbind( "resize", handler );
17                         }
18                 };
19
20                 var throttle = 250,
21                         handler = function() {
22                                 curr = ( new Date() ).getTime();
23                                 diff = curr - lastCall;
24
25                                 if ( diff >= throttle ) {
26
27                                         lastCall = curr;
28                                         $( this ).trigger( "throttledresize" );
29
30                                 } else {
31
32                                         if ( heldCall ) {
33                                                 clearTimeout( heldCall );
34                                         }
35
36                                         // Promise a held call will still execute
37                                         heldCall = setTimeout( handler, throttle - diff );
38                                 }
39                         },
40                         lastCall = 0,
41                         heldCall,
42                         curr,
43                         diff;
44         })( jQuery );
45 //>>excludeStart("jqmBuildExclude", pragmas.jqmBuildExclude);
46 });
47 //>>excludeEnd("jqmBuildExclude");