1/* 2 * debouncedresize: special jQuery event that happens once after a window resize 3 * 4 * latest version and complete README available on Github: 5 * https://github.com/louisremi/jquery-smartresize 6 * 7 * Copyright 2012 @louis_remi 8 * Licensed under the MIT license. 9 */ 10(function($) { 11 "use strict"; 12 13 var $event = $.event, 14 $special, 15 resizeTimeout; 16 17 $special = $event.special.debouncedresize = { 18 setup: function() { 19 $( this ).on( "resize", $special.handler ); 20 }, 21 teardown: function() { 22 $( this ).off( "resize", $special.handler ); 23 }, 24 handler: function( event, execAsap ) { 25 // Save the context 26 var context = this, 27 args = arguments, 28 dispatch = function() { 29 // set correct event type 30 event.type = "debouncedresize"; 31 $event.dispatch.apply( context, args ); 32 }; 33 34 if ( resizeTimeout ) { 35 clearTimeout( resizeTimeout ); 36 } 37 38 execAsap ? 39 dispatch() : 40 resizeTimeout = setTimeout( dispatch, $special.threshold ); 41 }, 42 threshold: 150 43 }; 44 45})(jQuery); 46 47 48/** 49 * Simple throttle function 50 */ 51(function($) { 52 "use strict"; 53 54 $.throttle = function(cb, threshold) { 55 var last = null, 56 threshold = threshold || 200; 57 return function() { 58 if( null == last ) { 59 last = +new Date; 60 cb.call(this, arguments); 61 }else { 62 var now = +new Date; 63 if( last + threshold < now ) { 64 last = now; 65 cb.call(this, arguments); 66 } 67 } 68 } 69 } 70})(jQuery); 71 72 73/** 74 * Simple Debounce function 75 */ 76(function($) { 77 "use strict"; 78 79 $.debounce = function debounce(func, wait, immediate) { 80 var timeout; 81 return function() { 82 var context = this, args = arguments; 83 var later = function() { 84 timeout = null; 85 if (!immediate) func.apply(context, args); 86 }; 87 var callNow = immediate && !timeout; 88 clearTimeout(timeout); 89 timeout = setTimeout(later, wait); 90 if (callNow) func.apply(context, args); 91 }; 92 }; 93})(jQuery); 94 95/** 96 * youtube player api 97 */ 98(function($) { 99 "use strict"; 100 101 if( jQuery('.be-youtube-embed').length ){ 102 var tag = document.createElement('script'); 103 tag.src = "https://www.youtube.com/iframe_api"; 104 var firstScriptTag = document.getElementsByTagName('script')[0]; 105 firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); 106 var previousAPIReadyCallback = window.onYouTubeIframeAPIReady; 107 window.onYouTubeIframeAPIReady = function() { 108 if( 'function' == typeof previousAPIReadyCallback ) { 109 previousAPIReadyCallback(); 110 } 111 $(document).trigger( 'YTAPIReady' ); 112 } 113 } 114})(jQuery); 115 116 117/** 118 * Checks if element is inside viewport 119 */ 120(function( $ ) { 121 "use strict"; 122 var $window = $(window); 123 $.fn.isVisible = function( threshold ) { 124 var $el = $(this), 125 wt = $window.scrollTop(), 126 wb = wt + window.innerHeight, 127 et = $el.offset().top, 128 eb = et + $el.height(), 129 topThreshold = wt - threshold, 130 bottomThreshold = wb + threshold; 131 return ( eb >= topThreshold && eb <= bottomThreshold ) || ( et <= bottomThreshold && et >= topThreshold ); 132 }; 133})( jQuery ); 134 135/** 136 * Lazy load 137 */ 138(function( $ ){ 139 "use strict"; 140 var imagesToLoad = $( '.be-lazy-load' ), 141 add = function( images ) { 142 if( null != images && 0 < images.length ) { 143 imagesToLoad = imagesToLoad.add( images ); 144 } 145 }, 146 lazyLoad = function() { 147 if( 0 < imagesToLoad.length ) { 148 var visibleImages = imagesToLoad.filter( function(i, el) { 149 return $(this).isVisible( 200 ); 150 }); 151 if( 0 < visibleImages.length ) { 152 visibleImages.one( 'load', function() { 153 $(this).addClass( 'be-lazy-loaded' ); 154 }).each( function( el ) { 155 var curEl = $(this); 156 curEl.attr( 'src', curEl.attr( 'data-src' ) ); 157 }); 158 imagesToLoad = imagesToLoad.not( visibleImages ); 159 } 160 } 161 }; 162 $(window).on( 'scroll', function() { 163 lazyLoad(); 164 }); 165 window.BeLazyLoad = { 166 add : add, 167 lazyLoad : lazyLoad 168 }; 169 $(function(){ 170 imagesToLoad = $( '.be-lazy-load' ); 171 lazyLoad(); 172 }); 173}(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.