1/*! 2 * Pause jQuery plugin v0.1 3 * 4 * Copyright 2010 by Tobia Conforto <[email protected]> 5 * 6 * Based on Pause-resume-animation jQuery plugin by Joe Weitzel 7 * 8 * This program is free software; you can redistribute it and/or modify it 9 * under the terms of the GNU General Public License as published by the Free 10 * Software Foundation; either version 2 of the License, or(at your option) 11 * any later version. 12 * 13 * This program is distributed in the hope that it will be useful, but WITHOUT 14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 16 * more details. 17 * 18 * You should have received a copy of the GNU General Public License along with 19 * this program; if not, write to the Free Software Foundation, Inc., 51 20 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 */ 22/* Changelog: 23 * 24 * 0.1 2010-06-13 Initial release 25 */ 26(function() { 27 var $ = jQuery, 28 pauseId = 'jQuery.pause', 29 uuid = 1, 30 oldAnimate = $.fn.animate, 31 anims = {}; 32 33 function now() { return new Date().getTime(); } 34 35 $.fn.animate = function(prop, speed, easing, callback) { 36 var optall = $.speed(speed, easing, callback); 37 optall.complete = optall.old; // unwrap callback 38 return this.each(function() { 39 // check pauseId 40 if (! this[pauseId]) 41 this[pauseId] = uuid++; 42 // start animation 43 var opt = $.extend({}, optall); 44 oldAnimate.apply($(this), [prop, $.extend({}, opt)]); 45 // store data 46 anims[this[pauseId]] = { 47 run: true, 48 prop: prop, 49 opt: opt, 50 start: now(), 51 done: 0 52 }; 53 }); 54 }; 55 56 $.fn.pause = function() { 57 return this.each(function() { 58 // check pauseId 59 if (! this[pauseId]) 60 this[pauseId] = uuid++; 61 // fetch data 62 var data = anims[this[pauseId]]; 63 if (data && data.run) { 64 data.done += now() - data.start; 65 if (data.done > data.opt.duration) { 66 // remove stale entry 67 delete anims[this[pauseId]]; 68 } else { 69 // pause animation 70 $(this).stop(); 71 data.run = false; 72 } 73 } 74 }); 75 }; 76 77 $.fn.resume = function() { 78 return this.each(function() { 79 // check pauseId 80 if (! this[pauseId]) 81 this[pauseId] = uuid++; 82 // fetch data 83 var data = anims[this[pauseId]]; 84 if (data && ! data.run) { 85 // resume animation 86 data.opt.duration -= data.done; 87 data.done = 0; 88 data.run = true; 89 data.start = now(); 90 oldAnimate.apply($(this), [data.prop, $.extend({}, data.opt)]); 91 } 92 }); 93 }; 94})();
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.