Index: trunk/phase3/resources/jquery/jquery.appear.js |
— | — | @@ -0,0 +1,138 @@ |
| 2 | +/* |
| 3 | + * jQuery.appear |
| 4 | + * http://code.google.com/p/jquery-appear/ |
| 5 | + * |
| 6 | + * Copyright (c) 2009 Michael Hixson |
| 7 | + * Licensed under the MIT license (http://www.opensource.org/licenses/mit-license.php) |
| 8 | +*/ |
| 9 | +(function($) { |
| 10 | + |
| 11 | + $.fn.appear = function(fn, options) { |
| 12 | + |
| 13 | + var settings = $.extend({ |
| 14 | + |
| 15 | + //arbitrary data to pass to fn |
| 16 | + data: undefined, |
| 17 | + |
| 18 | + //call fn only on the first appear? |
| 19 | + one: true |
| 20 | + |
| 21 | + }, options); |
| 22 | + |
| 23 | + return this.each(function() { |
| 24 | + |
| 25 | + var t = $(this); |
| 26 | + |
| 27 | + //whether the element is currently visible |
| 28 | + t.appeared = false; |
| 29 | + |
| 30 | + if (!fn) { |
| 31 | + |
| 32 | + //trigger the custom event |
| 33 | + t.trigger('appear', settings.data); |
| 34 | + return; |
| 35 | + } |
| 36 | + |
| 37 | + var w = $(window); |
| 38 | + |
| 39 | + //fires the appear event when appropriate |
| 40 | + var check = function() { |
| 41 | + |
| 42 | + //is the element hidden? |
| 43 | + if (!t.is(':visible')) { |
| 44 | + |
| 45 | + //it became hidden |
| 46 | + t.appeared = false; |
| 47 | + return; |
| 48 | + } |
| 49 | + |
| 50 | + //is the element inside the visible window? |
| 51 | + var a = w.scrollLeft(); |
| 52 | + var b = w.scrollTop(); |
| 53 | + var o = t.offset(); |
| 54 | + var x = o.left; |
| 55 | + var y = o.top; |
| 56 | + |
| 57 | + if (y + t.height() >= b && |
| 58 | + y <= b + w.height() && |
| 59 | + x + t.width() >= a && |
| 60 | + x <= a + w.width()) { |
| 61 | + |
| 62 | + //trigger the custom event |
| 63 | + if (!t.appeared) t.trigger('appear', settings.data); |
| 64 | + |
| 65 | + } else { |
| 66 | + |
| 67 | + //it scrolled out of view |
| 68 | + t.appeared = false; |
| 69 | + } |
| 70 | + }; |
| 71 | + |
| 72 | + //create a modified fn with some additional logic |
| 73 | + var modifiedFn = function() { |
| 74 | + |
| 75 | + //mark the element as visible |
| 76 | + t.appeared = true; |
| 77 | + |
| 78 | + //is this supposed to happen only once? |
| 79 | + if (settings.one) { |
| 80 | + |
| 81 | + //remove the check |
| 82 | + w.unbind('scroll', check); |
| 83 | + var i = $.inArray(check, $.fn.appear.checks); |
| 84 | + if (i >= 0) $.fn.appear.checks.splice(i, 1); |
| 85 | + } |
| 86 | + |
| 87 | + //trigger the original fn |
| 88 | + fn.apply(this, arguments); |
| 89 | + }; |
| 90 | + |
| 91 | + //bind the modified fn to the element |
| 92 | + if (settings.one) t.one('appear', settings.data, modifiedFn); |
| 93 | + else t.bind('appear', settings.data, modifiedFn); |
| 94 | + |
| 95 | + //check whenever the window scrolls |
| 96 | + w.scroll(check); |
| 97 | + |
| 98 | + //check whenever the dom changes |
| 99 | + $.fn.appear.checks.push(check); |
| 100 | + |
| 101 | + //check now |
| 102 | + (check)(); |
| 103 | + }); |
| 104 | + }; |
| 105 | + |
| 106 | + //keep a queue of appearance checks |
| 107 | + $.extend($.fn.appear, { |
| 108 | + |
| 109 | + checks: [], |
| 110 | + timeout: null, |
| 111 | + |
| 112 | + //process the queue |
| 113 | + checkAll: function() { |
| 114 | + var length = $.fn.appear.checks.length; |
| 115 | + if (length > 0) while (length--) ($.fn.appear.checks[length])(); |
| 116 | + }, |
| 117 | + |
| 118 | + //check the queue asynchronously |
| 119 | + run: function() { |
| 120 | + if ($.fn.appear.timeout) clearTimeout($.fn.appear.timeout); |
| 121 | + $.fn.appear.timeout = setTimeout($.fn.appear.checkAll, 20); |
| 122 | + } |
| 123 | + }); |
| 124 | + |
| 125 | + //run checks when these methods are called |
| 126 | + $.each(['append', 'prepend', 'after', 'before', 'attr', |
| 127 | + 'removeAttr', 'addClass', 'removeClass', 'toggleClass', |
| 128 | + 'remove', 'css', 'show', 'hide'], function(i, n) { |
| 129 | + var old = $.fn[n]; |
| 130 | + if (old) { |
| 131 | + $.fn[n] = function() { |
| 132 | + var r = old.apply(this, arguments); |
| 133 | + $.fn.appear.run(); |
| 134 | + return r; |
| 135 | + } |
| 136 | + } |
| 137 | + }); |
| 138 | + |
| 139 | +})(jQuery); |
\ No newline at end of file |
Property changes on: trunk/phase3/resources/jquery/jquery.appear.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 140 | + native |
Added: svn:mime-type |
2 | 141 | + text/plain |
Index: trunk/phase3/resources/Resources.php |
— | — | @@ -70,6 +70,9 @@ |
71 | 71 | 'jquery.async' => array( |
72 | 72 | 'scripts' => 'resources/jquery/jquery.async.js', |
73 | 73 | ), |
| 74 | + 'jquery.appear' => array( |
| 75 | + 'scripts' => 'resources/jquery/jquery.appear.js', |
| 76 | + ), |
74 | 77 | 'jquery.autoEllipsis' => array( |
75 | 78 | 'scripts' => 'resources/jquery/jquery.autoEllipsis.js', |
76 | 79 | 'dependencies' => 'jquery.highlightText', |