Index: branches/wmf/1.17wmf1/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: branches/wmf/1.17wmf1/resources/jquery/jquery.appear.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 140 | + native |
Added: svn:mime-type |
2 | 141 | + text/plain |
Index: branches/wmf/1.17wmf1/resources/Resources.php |
— | — | @@ -34,6 +34,9 @@ |
35 | 35 | 'jquery.async' => array( |
36 | 36 | 'scripts' => 'resources/jquery/jquery.async.js' |
37 | 37 | ), |
| 38 | + 'jquery.appear' => array( |
| 39 | + 'scripts' => 'resources/jquery/jquery.appear.js', |
| 40 | + ), |
38 | 41 | 'jquery.autoEllipsis' => array( |
39 | 42 | 'scripts' => 'resources/jquery/jquery.autoEllipsis.js', |
40 | 43 | 'dependencies' => 'jquery.highlightText', |
Property changes on: branches/wmf/1.17wmf1/resources/Resources.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
41 | 44 | Merged /trunk/phase3/resources/Resources.php:r87472 |