r87728 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r87727‎ | r87728 | r87729 >
Date:16:11, 9 May 2011
Author:catrope
Status:ok
Tags:
Comment:
1.17wmf1: MFT r87472
Modified paths:
  • /branches/wmf/1.17wmf1/resources/Resources.php (modified) (history)
  • /branches/wmf/1.17wmf1/resources/jquery/jquery.appear.js (added) (history)

Diff [purge]

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
1140 + native
Added: svn:mime-type
2141 + text/plain
Index: branches/wmf/1.17wmf1/resources/Resources.php
@@ -34,6 +34,9 @@
3535 'jquery.async' => array(
3636 'scripts' => 'resources/jquery/jquery.async.js'
3737 ),
 38+ 'jquery.appear' => array(
 39+ 'scripts' => 'resources/jquery/jquery.appear.js',
 40+ ),
3841 'jquery.autoEllipsis' => array(
3942 'scripts' => 'resources/jquery/jquery.autoEllipsis.js',
4043 'dependencies' => 'jquery.highlightText',
Property changes on: branches/wmf/1.17wmf1/resources/Resources.php
___________________________________________________________________
Modified: svn:mergeinfo
4144 Merged /trunk/phase3/resources/Resources.php:r87472

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r87472Added jquery.appear, which adds a new event which fires the first time someth...tparscal23:26, 4 May 2011

Status & tagging log