1/* 2 * jQuery.appear 3 * http://code.google.com/p/jquery-appear/ 4 * 5 * Copyright (c) 2009 Michael Hixson 6 * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php) 7 */ 8(function ($) { 9 $.fn.appear = function (f, o) { 10 var s = $.extend({ one: true }, o); 11 return this.each(function () { 12 var t = $(this); 13 t.appeared = false; 14 if (!f) { 15 t.trigger("appear", s.data); 16 return; 17 } 18 var w = $(window); 19 var c = function () { 20 if (!t.is(":visible")) { 21 t.appeared = false; 22 return; 23 } 24 var a = w.scrollLeft(); 25 var b = w.scrollTop(); 26 var o = t.offset(); 27 var x = o.left; 28 var y = o.top; 29 if ( 30 y + t.height() >= b && 31 y <= b + w.height() && 32 x + t.width() >= a && 33 x <= a + w.width() 34 ) { 35 if (!t.appeared) t.trigger("appear", s.data); 36 } else { 37 t.appeared = false; 38 } 39 }; 40 var m = function () { 41 t.appeared = true; 42 if (s.one) { 43 w.unbind("scroll", c); 44 var i = $.inArray(c, $.fn.appear.checks); 45 if (i >= 0) $.fn.appear.checks.splice(i, 1); 46 } 47 f.apply(this, arguments); 48 }; 49 if (s.one) t.one("appear", s.data, m); 50 else t.bind("appear", s.data, m); 51 w.scroll(c); 52 $.fn.appear.checks.push(c); 53 c(); 54 }); 55 }; 56 $.extend($.fn.appear, { 57 checks: [], 58 timeout: null, 59 checkAll: function() { 60 var length = $.fn.appear.checks.length; 61 if (length > 0) { 62 while (length--) { 63 try { 64 ($.fn.appear.checks[length])(); 65 } catch (e) {} 66 } 67 } 68 }, 69 run: function () { 70 if ($.fn.appear.timeout) clearTimeout($.fn.appear.timeout); 71 $.fn.appear.timeout = setTimeout($.fn.appear.checkAll, 20); 72 }, 73 }); 74 $.each( 75 [ 76 "append", 77 "prepend", 78 "after", 79 "before", 80 "attr", 81 "removeAttr", 82 "addClass", 83 "removeClass", 84 "toggleClass", 85 "remove", 86 "css", 87 "show", 88 "hide", 89 ], 90 function (i, n) { 91 var u = $.fn[n]; 92 if (u) { 93 $.fn[n] = function () { 94 var r = u.apply(this, arguments); 95 $.fn.appear.run(); 96 return r; 97 }; 98 } 99 } 100 ); 101})(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.