display empty verses
[wolnelektury.git] / wolnelektury / static / js / jquery.scrollto.js
index 7f42489..c403ab9 100644 (file)
-/**\r
- * jQuery.ScrollTo\r
- * Copyright (c) 2007-2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com\r
- * Dual licensed under MIT and GPL.\r
- * Date: 9/11/2008\r
- *\r
- * @projectDescription Easy element scrolling using jQuery.\r
- * http://flesler.blogspot.com/2007/10/jqueryscrollto.html\r
- * Tested with jQuery 1.2.6. On FF 2/3, IE 6/7, Opera 9.2/5 and Safari 3. on Windows.\r
- *\r
- * @author Ariel Flesler\r
- * @version 1.4\r
- *\r
- * @id jQuery.scrollTo\r
- * @id jQuery.fn.scrollTo\r
- * @param {String, Number, DOMElement, jQuery, Object} target Where to scroll the matched elements.\r
- *       The different options for target are:\r
- *             - A number position (will be applied to all axes).\r
- *             - A string position ('44', '100px', '+=90', etc ) will be applied to all axes\r
- *             - A jQuery/DOM element ( logically, child of the element to scroll )\r
- *             - A string selector, that will be relative to the element to scroll ( 'li:eq(2)', etc )\r
- *             - A hash { top:x, left:y }, x and y can be any kind of number/string like above.\r
- * @param {Number} duration The OVERALL length of the animation, this argument can be the settings object instead.\r
- * @param {Object,Function} settings Optional set of settings or the onAfter callback.\r
- *      @option {String} axis Which axis must be scrolled, use 'x', 'y', 'xy' or 'yx'.\r
- *      @option {Number} duration The OVERALL length of the animation.\r
- *      @option {String} easing The easing method for the animation.\r
- *      @option {Boolean} margin If true, the margin of the target element will be deducted from the final position.\r
- *      @option {Object, Number} offset Add/deduct from the end position. One number for both axes or { top:x, left:y }.\r
- *      @option {Object, Number} over Add/deduct the height/width multiplied by 'over', can be { top:x, left:y } when using both axes.\r
- *      @option {Boolean} queue If true, and both axis are given, the 2nd axis will only be animated after the first one ends.\r
- *      @option {Function} onAfter Function to be called after the scrolling ends. \r
- *      @option {Function} onAfterFirst If queuing is activated, this function will be called after the first scrolling ends.\r
- * @return {jQuery} Returns the same jQuery object, for chaining.\r
- *\r
- * @desc Scroll to a fixed position\r
- * @example $('div').scrollTo( 340 );\r
- *\r
- * @desc Scroll relatively to the actual position\r
- * @example $('div').scrollTo( '+=340px', { axis:'y' } );\r
- *\r
- * @dec Scroll using a selector (relative to the scrolled element)\r
- * @example $('div').scrollTo( 'p.paragraph:eq(2)', 500, { easing:'swing', queue:true, axis:'xy' } );\r
- *\r
- * @ Scroll to a DOM element (same for jQuery object)\r
- * @example var second_child = document.getElementById('container').firstChild.nextSibling;\r
- *                     $('#container').scrollTo( second_child, { duration:500, axis:'x', onAfter:function(){\r
- *                             alert('scrolled!!');                                                                                                                               \r
- *                     }});\r
- *\r
- * @desc Scroll on both axes, to different values\r
- * @example $('div').scrollTo( { top: 300, left:'+=200' }, { axis:'xy', offset:-20 } );\r
- */\r
-;(function( $ ){\r
-       \r
-       var $scrollTo = $.scrollTo = function( target, duration, settings ){\r
-               $(window).scrollTo( target, duration, settings );\r
-       };\r
-\r
-       $scrollTo.defaults = {\r
-               axis:'y',\r
-               duration:1\r
-       };\r
-\r
-       // Returns the element that needs to be animated to scroll the window.\r
-       // Kept for backwards compatibility (specially for localScroll & serialScroll)\r
-       $scrollTo.window = function( scope ){\r
-               return $(window).scrollable();\r
-       };\r
-\r
-       // Hack, hack, hack... stay away!\r
-       // Returns the real elements to scroll (supports window/iframes, documents and regular nodes)\r
-       $.fn.scrollable = function(){\r
-               return this.map(function(){\r
-                       // Just store it, we might need it\r
-                       var win = this.parentWindow || this.defaultView,\r
-                               // If it's a document, get its iframe or the window if it's THE document\r
-                               elem = this.nodeName == '#document' ? win.frameElement || win : this,\r
-                               // Get the corresponding document\r
-                               doc = elem.contentDocument || (elem.contentWindow || elem).document,\r
-                               isWin = elem.setInterval;\r
-\r
-                       return elem.nodeName == 'IFRAME' || isWin && $.browser.safari ? doc.body\r
-                               : isWin ? doc.documentElement\r
-                               : this;\r
-               });\r
-       };\r
-\r
-       $.fn.scrollTo = function( target, duration, settings ){\r
-               if( typeof duration == 'object' ){\r
-                       settings = duration;\r
-                       duration = 0;\r
-               }\r
-               if( typeof settings == 'function' )\r
-                       settings = { onAfter:settings };\r
-                       \r
-               settings = $.extend( {}, $scrollTo.defaults, settings );\r
-               // Speed is still recognized for backwards compatibility\r
-               duration = duration || settings.speed || settings.duration;\r
-               // Make sure the settings are given right\r
-               settings.queue = settings.queue && settings.axis.length > 1;\r
-               \r
-               if( settings.queue )\r
-                       // Let's keep the overall duration\r
-                       duration /= 2;\r
-               settings.offset = both( settings.offset );\r
-               settings.over = both( settings.over );\r
-\r
-               return this.scrollable().each(function(){\r
-                       var elem = this,\r
-                               $elem = $(elem),\r
-                               targ = target, toff, attr = {},\r
-                               win = $elem.is('html,body');\r
-\r
-                       switch( typeof targ ){\r
-                               // A number will pass the regex\r
-                               case 'number':\r
-                               case 'string':\r
-                                       if( /^([+-]=)?\d+(px)?$/.test(targ) ){\r
-                                               targ = both( targ );\r
-                                               // We are done\r
-                                               break;\r
-                                       }\r
-                                       // Relative selector, no break!\r
-                                       targ = $(targ,this);\r
-                               case 'object':\r
-                                       // DOMElement / jQuery\r
-                                       if( targ.is || targ.style )\r
-                                               // Get the real position of the target \r
-                                               toff = (targ = $(targ)).offset();\r
-                       }\r
-                       $.each( settings.axis.split(''), function( i, axis ){\r
-                               var Pos = axis == 'x' ? 'Left' : 'Top',\r
-                                       pos = Pos.toLowerCase(),\r
-                                       key = 'scroll' + Pos,\r
-                                       old = elem[key],\r
-                                       Dim = axis == 'x' ? 'Width' : 'Height',\r
-                                       dim = Dim.toLowerCase();\r
-\r
-                               if( toff ){// jQuery / DOMElement\r
-                                       attr[key] = toff[pos] + ( win ? 0 : old - $elem.offset()[pos] );\r
-\r
-                                       // If it's a dom element, reduce the margin\r
-                                       if( settings.margin ){\r
-                                               attr[key] -= parseInt(targ.css('margin'+Pos)) || 0;\r
-                                               attr[key] -= parseInt(targ.css('border'+Pos+'Width')) || 0;\r
-                                       }\r
-                                       \r
-                                       attr[key] += settings.offset[pos] || 0;\r
-                                       \r
-                                       if( settings.over[pos] )\r
-                                               // Scroll to a fraction of its width/height\r
-                                               attr[key] += targ[dim]() * settings.over[pos];\r
-                               }else\r
-                                       attr[key] = targ[pos];\r
-\r
-                               // Number or 'number'\r
-                               if( /^\d+$/.test(attr[key]) )\r
-                                       // Check the limits\r
-                                       attr[key] = attr[key] <= 0 ? 0 : Math.min( attr[key], max(Dim) );\r
-\r
-                               // Queueing axes\r
-                               if( !i && settings.queue ){\r
-                                       // Don't waste time animating, if there's no need.\r
-                                       if( old != attr[key] )\r
-                                               // Intermediate animation\r
-                                               animate( settings.onAfterFirst );\r
-                                       // Don't animate this axis again in the next iteration.\r
-                                       delete attr[key];\r
-                               }\r
-                       });                     \r
-                       animate( settings.onAfter );                    \r
-\r
-                       function animate( callback ){\r
-                               $elem.animate( attr, duration, settings.easing, callback && function(){\r
-                                       callback.call(this, target, settings);\r
-                               });\r
-                       };\r
-                       function max( Dim ){\r
-                               var attr ='scroll'+Dim,\r
-                                       doc = elem.ownerDocument;\r
-                               \r
-                               return win\r
-                                               ? Math.max( doc.documentElement[attr], doc.body[attr]  )\r
-                                               : elem[attr];\r
-                       };\r
-               }).end();\r
-       };\r
-\r
-       function both( val ){\r
-               return typeof val == 'object' ? val : { top:val, left:val };\r
-       };\r
-\r
+/**
+ * jQuery.ScrollTo
+ * Copyright (c) 2007-2008 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
+ * Dual licensed under MIT and GPL.
+ * Date: 9/11/2008
+ *
+ * @projectDescription Easy element scrolling using jQuery.
+ * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
+ * Tested with jQuery 1.2.6. On FF 2/3, IE 6/7, Opera 9.2/5 and Safari 3. on Windows.
+ *
+ * @author Ariel Flesler
+ * @version 1.4
+ *
+ * @id jQuery.scrollTo
+ * @id jQuery.fn.scrollTo
+ * @param {String, Number, DOMElement, jQuery, Object} target Where to scroll the matched elements.
+ *       The different options for target are:
+ *             - A number position (will be applied to all axes).
+ *             - A string position ('44', '100px', '+=90', etc ) will be applied to all axes
+ *             - A jQuery/DOM element ( logically, child of the element to scroll )
+ *             - A string selector, that will be relative to the element to scroll ( 'li:eq(2)', etc )
+ *             - A hash { top:x, left:y }, x and y can be any kind of number/string like above.
+ * @param {Number} duration The OVERALL length of the animation, this argument can be the settings object instead.
+ * @param {Object,Function} settings Optional set of settings or the onAfter callback.
+ *      @option {String} axis Which axis must be scrolled, use 'x', 'y', 'xy' or 'yx'.
+ *      @option {Number} duration The OVERALL length of the animation.
+ *      @option {String} easing The easing method for the animation.
+ *      @option {Boolean} margin If true, the margin of the target element will be deducted from the final position.
+ *      @option {Object, Number} offset Add/deduct from the end position. One number for both axes or { top:x, left:y }.
+ *      @option {Object, Number} over Add/deduct the height/width multiplied by 'over', can be { top:x, left:y } when using both axes.
+ *      @option {Boolean} queue If true, and both axis are given, the 2nd axis will only be animated after the first one ends.
+ *      @option {Function} onAfter Function to be called after the scrolling ends.
+ *      @option {Function} onAfterFirst If queuing is activated, this function will be called after the first scrolling ends.
+ * @return {jQuery} Returns the same jQuery object, for chaining.
+ *
+ * @desc Scroll to a fixed position
+ * @example $('div').scrollTo( 340 );
+ *
+ * @desc Scroll relatively to the actual position
+ * @example $('div').scrollTo( '+=340px', { axis:'y' } );
+ *
+ * @dec Scroll using a selector (relative to the scrolled element)
+ * @example $('div').scrollTo( 'p.paragraph:eq(2)', 500, { easing:'swing', queue:true, axis:'xy' } );
+ *
+ * @ Scroll to a DOM element (same for jQuery object)
+ * @example var second_child = document.getElementById('container').firstChild.nextSibling;
+ *                     $('#container').scrollTo( second_child, { duration:500, axis:'x', onAfter:function(){
+ *                             alert('scrolled!!');
+ *                     }});
+ *
+ * @desc Scroll on both axes, to different values
+ * @example $('div').scrollTo( { top: 300, left:'+=200' }, { axis:'xy', offset:-20 } );
+ */
+;(function( $ ){
+
+       var $scrollTo = $.scrollTo = function( target, duration, settings ){
+               $(window).scrollTo( target, duration, settings );
+       };
+
+       $scrollTo.defaults = {
+               axis:'y',
+               duration:1
+       };
+
+       // Returns the element that needs to be animated to scroll the window.
+       // Kept for backwards compatibility (specially for localScroll & serialScroll)
+       $scrollTo.window = function( scope ){
+               return $(window).scrollable();
+       };
+
+       // Hack, hack, hack... stay away!
+       // Returns the real elements to scroll (supports window/iframes, documents and regular nodes)
+       $.fn.scrollable = function(){
+               return this.map(function(){
+                       // Just store it, we might need it
+                       var win = this.parentWindow || this.defaultView,
+                               // If it's a document, get its iframe or the window if it's THE document
+                               elem = this.nodeName == '#document' ? win.frameElement || win : this,
+                               // Get the corresponding document
+                               doc = elem.contentDocument || (elem.contentWindow || elem).document,
+                               isWin = elem.setInterval;
+
+                       return elem.nodeName == 'IFRAME' || isWin && $.browser.safari ? doc.body
+                               : isWin ? doc.documentElement
+                               : this;
+               });
+       };
+
+       $.fn.scrollTo = function( target, duration, settings ){
+               if( typeof duration == 'object' ){
+                       settings = duration;
+                       duration = 0;
+               }
+               if( typeof settings == 'function' )
+                       settings = { onAfter:settings };
+
+               settings = $.extend( {}, $scrollTo.defaults, settings );
+               // Speed is still recognized for backwards compatibility
+               duration = duration || settings.speed || settings.duration;
+               // Make sure the settings are given right
+               settings.queue = settings.queue && settings.axis.length > 1;
+
+               if( settings.queue )
+                       // Let's keep the overall duration
+                       duration /= 2;
+               settings.offset = both( settings.offset );
+               settings.over = both( settings.over );
+
+               return this.scrollable().each(function(){
+                       var elem = this,
+                               $elem = $(elem),
+                               targ = target, toff, attr = {},
+                               win = $elem.is('html,body');
+
+                       switch( typeof targ ){
+                               // A number will pass the regex
+                               case 'number':
+                               case 'string':
+                                       if( /^([+-]=)?\d+(px)?$/.test(targ) ){
+                                               targ = both( targ );
+                                               // We are done
+                                               break;
+                                       }
+                                       // Relative selector, no break!
+                                       targ = $(targ,this);
+                               case 'object':
+                                       // DOMElement / jQuery
+                                       if( targ.is || targ.style )
+                                               // Get the real position of the target
+                                               toff = (targ = $(targ)).offset();
+                       }
+                       $.each( settings.axis.split(''), function( i, axis ){
+                               var Pos = axis == 'x' ? 'Left' : 'Top',
+                                       pos = Pos.toLowerCase(),
+                                       key = 'scroll' + Pos,
+                                       old = elem[key],
+                                       Dim = axis == 'x' ? 'Width' : 'Height',
+                                       dim = Dim.toLowerCase();
+
+                               if( toff ){// jQuery / DOMElement
+                                       attr[key] = toff[pos] + ( win ? 0 : old - $elem.offset()[pos] );
+
+                                       // If it's a dom element, reduce the margin
+                                       if( settings.margin ){
+                                               attr[key] -= parseInt(targ.css('margin'+Pos)) || 0;
+                                               attr[key] -= parseInt(targ.css('border'+Pos+'Width')) || 0;
+                                       }
+
+                                       attr[key] += settings.offset[pos] || 0;
+
+                                       if( settings.over[pos] )
+                                               // Scroll to a fraction of its width/height
+                                               attr[key] += targ[dim]() * settings.over[pos];
+                               }else
+                                       attr[key] = targ[pos];
+
+                               // Number or 'number'
+                               if( /^\d+$/.test(attr[key]) )
+                                       // Check the limits
+                                       attr[key] = attr[key] <= 0 ? 0 : Math.min( attr[key], max(Dim) );
+
+                               // Queueing axes
+                               if( !i && settings.queue ){
+                                       // Don't waste time animating, if there's no need.
+                                       if( old != attr[key] )
+                                               // Intermediate animation
+                                               animate( settings.onAfterFirst );
+                                       // Don't animate this axis again in the next iteration.
+                                       delete attr[key];
+                               }
+                       });
+                       animate( settings.onAfter );
+
+                       function animate( callback ){
+                               $elem.animate( attr, duration, settings.easing, callback && function(){
+                                       callback.call(this, target, settings);
+                               });
+                       };
+                       function max( Dim ){
+                               var attr ='scroll'+Dim,
+                                       doc = elem.ownerDocument;
+
+                               return win
+                                               ? Math.max( doc.documentElement[attr], doc.body[attr]  )
+                                               : elem[attr];
+                       };
+               }).end();
+       };
+
+       function both( val ){
+               return typeof val == 'object' ? val : { top:val, left:val };
+       };
+
 })( jQuery );
\ No newline at end of file
 })( jQuery );
\ No newline at end of file