diff options
| author | Fabien Meghazi <fme@openerp.com> | 2011-11-09 12:57:44 +0100 |
|---|---|---|
| committer | Fabien Meghazi <fme@openerp.com> | 2011-11-09 12:57:44 +0100 |
| commit | f975258f0f88eec867827c318bb27ed5ec50e8e8 (patch) | |
| tree | 5271a1debb9e27e8b607ed6890c4d392b89408ee /addons/web/static/lib/jquery.scrollTo | |
| parent | 1104277a61f528cd2af133b821d274076ed69016 (diff) | |
[ADD] Added jquery.scrollTo
bzr revid: fme@openerp.com-20111109115744-m20vq3szt3hak3lf
Diffstat (limited to 'addons/web/static/lib/jquery.scrollTo')
3 files changed, 317 insertions, 0 deletions
diff --git a/addons/web/static/lib/jquery.scrollTo/changes.txt b/addons/web/static/lib/jquery.scrollTo/changes.txt new file mode 100644 index 00000000000..4b2933f6667 --- /dev/null +++ b/addons/web/static/lib/jquery.scrollTo/changes.txt @@ -0,0 +1,91 @@ +1.4.2
+[Feature]
+- The plugin support percentages as target ('50%' or {top:'50%', left:'45%'})
+- Exposed the max() calculation as $.scrollTo.max
+[Enhancement]
+- Renamed $.fn.scrollable to $.fn._scrollable to avoid conflicts with other plugins
+[Fix]
+- Fixing max calculations for regular DOM elements
+
+1.4.1
+[Feature]
+- The target can be 'max' to scroll to the end while keeping it elegant.
+[Enhancement]
+- Default duration is 0 for jquery +1.3. Means sync animation
+- The plugin works on all major browsers, on compat & quirks modes, including iframes.
+- In addition to window/document, if html or body are received, the plugin will choose the right one.
+[Fix]
+- The plugin accepts floating numbers, Thanks Ramin
+- Using jQuery.nodeName where neccessary so that this works on xml+xhtml
+- The max() internal function wasn't completely accurrate, now it is 98% (except for IE on quirks mode and it's not too noticeable).
+
+1.4
+[Fix]
+- Fixed the problem when scrolling the window to absolute positioned elements on Safari.
+- Fixed the problem on Opera 9.5 when scrolling the window. That it always scrolls to 0.
+[Feature]
+- Added the settings object as 2nd argument to the onAfter callback.
+- The 3rd argument of scrollTo can be just a function and it's used as the onAfter.
+- Added full support for iframes (even max scroll calculation).
+- Instead of $.scrollTo, $(window).scrollTo() and $(document).scrollTo() can be used.
+- Added $().scrollable() that returns the real element to scroll, f.e: $(window).scrollable() == [body|html], works for iframes.
+[Enhancement]
+- Cleaned the code a bit, specially the comments
+
+1.3.3
+[Change]
+- Changed the licensing from GPL to GPL+MIT.
+
+1.3.2
+[Enhancement]
+- Small improvements to make the code shorter.
+[Change]
+- Removed the last argument received by onAfter as it was the same as the 'this' but jqueryfied.
+
+1.3.1
+[Feature]
+- Exposed $.scrollTo.window() to get the element that needs to be animated, to scroll the window.
+- Added option 'over'.
+[Enhancement]
+- Made the code as short as possible.
+[Change]
+- Changed the arguments received by onAfter
+
+1.3
+[Enhancement]
+- Added semicolon to the start, for safe file concatenation
+- Added a limit check, values below 0 or over the maximum are fixed.
+- Now it should work faster, only one of html or body go through all the processing, instead of both for all browsers.
+[Fix]
+- Fixed the behavior for Opera, which seemed to react to both changes on <html> and <body>.
+- The border is also reduced, when 'margin' is set to true.
+[Change]
+- The option speed has been renamed to duration.
+[Feature]
+- The duration can be specified with a number as 2nd argument, and the rest of the settings as the third ( like $().animate )
+- Remade the demo
+
+1.2.4
+[Enhancement]
+- The target can be in the form of { top:x, left:y } allowing different position for each axis.
+[Feature]
+- The option 'offset' has been added, to scroll behind or past the target. Can be a number(both axes) or { top:x, left:y }.
+
+1.2.3
+[Feature]
+- Exposed the defaults.
+[Enhancement]
+- Made the callback functions receive more parameters.
+
+1.2.2
+[Fix]
+- Fixed a bug, I didn't have to add the scrolled amount if it was body or html.
+
+1.2
+[Change]
+- The option 'onafter' is now called 'onAfter'.
+[Feature]
+- Two axes can be scrolled together, this is set with the option 'axis'.
+- In case 2 axes are chosen, the scrolling can be queued: one scrolls, and then the other.
+- There's an intermediary event, 'onAfterFirst' called in case the axes are queued, after the first ends.
+- If the option 'margin' is set to true, the plugin will take in account, the margin of the target(no use if target is a value).
\ No newline at end of file diff --git a/addons/web/static/lib/jquery.scrollTo/jquery.scrollTo-min.js b/addons/web/static/lib/jquery.scrollTo/jquery.scrollTo-min.js new file mode 100644 index 00000000000..73a334184e4 --- /dev/null +++ b/addons/web/static/lib/jquery.scrollTo/jquery.scrollTo-min.js @@ -0,0 +1,11 @@ +/**
+ * jQuery.ScrollTo - Easy element scrolling using jQuery.
+ * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
+ * Dual licensed under MIT and GPL.
+ * Date: 5/25/2009
+ * @author Ariel Flesler
+ * @version 1.4.2
+ *
+ * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
+ */
+;(function(d){var k=d.scrollTo=function(a,i,e){d(window).scrollTo(a,i,e)};k.defaults={axis:'xy',duration:parseFloat(d.fn.jquery)>=1.3?0:1};k.window=function(a){return d(window)._scrollable()};d.fn._scrollable=function(){return this.map(function(){var a=this,i=!a.nodeName||d.inArray(a.nodeName.toLowerCase(),['iframe','#document','html','body'])!=-1;if(!i)return a;var e=(a.contentWindow||a).document||a.ownerDocument||a;return d.browser.safari||e.compatMode=='BackCompat'?e.body:e.documentElement})};d.fn.scrollTo=function(n,j,b){if(typeof j=='object'){b=j;j=0}if(typeof b=='function')b={onAfter:b};if(n=='max')n=9e9;b=d.extend({},k.defaults,b);j=j||b.speed||b.duration;b.queue=b.queue&&b.axis.length>1;if(b.queue)j/=2;b.offset=p(b.offset);b.over=p(b.over);return this._scrollable().each(function(){var q=this,r=d(q),f=n,s,g={},u=r.is('html,body');switch(typeof f){case'number':case'string':if(/^([+-]=)?\d+(\.\d+)?(px|%)?$/.test(f)){f=p(f);break}f=d(f,this);case'object':if(f.is||f.style)s=(f=d(f)).offset()}d.each(b.axis.split(''),function(a,i){var e=i=='x'?'Left':'Top',h=e.toLowerCase(),c='scroll'+e,l=q[c],m=k.max(q,i);if(s){g[c]=s[h]+(u?0:l-r.offset()[h]);if(b.margin){g[c]-=parseInt(f.css('margin'+e))||0;g[c]-=parseInt(f.css('border'+e+'Width'))||0}g[c]+=b.offset[h]||0;if(b.over[h])g[c]+=f[i=='x'?'width':'height']()*b.over[h]}else{var o=f[h];g[c]=o.slice&&o.slice(-1)=='%'?parseFloat(o)/100*m:o}if(/^\d+$/.test(g[c]))g[c]=g[c]<=0?0:Math.min(g[c],m);if(!a&&b.queue){if(l!=g[c])t(b.onAfterFirst);delete g[c]}});t(b.onAfter);function t(a){r.animate(g,j,b.easing,a&&function(){a.call(this,n,b)})}}).end()};k.max=function(a,i){var e=i=='x'?'Width':'Height',h='scroll'+e;if(!d(a).is('html,body'))return a[h]-d(a)[e.toLowerCase()]();var c='client'+e,l=a.ownerDocument.documentElement,m=a.ownerDocument.body;return Math.max(l[h],m[h])-Math.min(l[c],m[c])};function p(a){return typeof a=='object'?a:{top:a,left:a}}})(jQuery);
\ No newline at end of file diff --git a/addons/web/static/lib/jquery.scrollTo/jquery.scrollTo.js b/addons/web/static/lib/jquery.scrollTo/jquery.scrollTo.js new file mode 100644 index 00000000000..eec31e191cb --- /dev/null +++ b/addons/web/static/lib/jquery.scrollTo/jquery.scrollTo.js @@ -0,0 +1,215 @@ +/**
+ * jQuery.ScrollTo
+ * Copyright (c) 2007-2009 Ariel Flesler - aflesler(at)gmail(dot)com | http://flesler.blogspot.com
+ * Dual licensed under MIT and GPL.
+ * Date: 5/25/2009
+ *
+ * @projectDescription Easy element scrolling using jQuery.
+ * http://flesler.blogspot.com/2007/10/jqueryscrollto.html
+ * Works with jQuery +1.2.6. Tested on FF 2/3, IE 6/7/8, Opera 9.5/6, Safari 3, Chrome 1 on WinXP.
+ *
+ * @author Ariel Flesler
+ * @version 1.4.2
+ *
+ * @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.
+* - A percentage of the container's dimension/s, for example: 50% to go to the middle.
+ * - The string 'max' for go-to-end.
+ * @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:'xy',
+ duration: parseFloat($.fn.jquery) >= 1.3 ? 0 : 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 :)
+ // Returns the real elements to scroll (supports window/iframes, documents and regular nodes)
+ $.fn._scrollable = function(){
+ return this.map(function(){
+ var elem = this,
+ isWin = !elem.nodeName || $.inArray( elem.nodeName.toLowerCase(), ['iframe','#document','html','body'] ) != -1;
+
+ if( !isWin )
+ return elem;
+
+ var doc = (elem.contentWindow || elem).document || elem.ownerDocument || elem;
+
+ return $.browser.safari || doc.compatMode == 'BackCompat' ?
+ doc.body :
+ doc.documentElement;
+ });
+ };
+
+ $.fn.scrollTo = function( target, duration, settings ){
+ if( typeof duration == 'object' ){
+ settings = duration;
+ duration = 0;
+ }
+ if( typeof settings == 'function' )
+ settings = { onAfter:settings };
+
+ if( target == 'max' )
+ target = 9e9;
+
+ 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+(\.\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],
+ max = $scrollTo.max(elem, axis);
+
+ 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[axis=='x'?'width':'height']() * settings.over[pos];
+ }else{
+ var val = targ[pos];
+ // Handle percentage values
+ attr[key] = val.slice && val.slice(-1) == '%' ?
+ parseFloat(val) / 100 * max
+ : val;
+ }
+
+ // Number or 'number'
+ if( /^\d+$/.test(attr[key]) )
+ // Check the limits
+ attr[key] = attr[key] <= 0 ? 0 : Math.min( attr[key], max );
+
+ // 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);
+ });
+ };
+
+ }).end();
+ };
+
+ // Max scrolling position, works on quirks mode
+ // It only fails (not too badly) on IE, quirks mode.
+ $scrollTo.max = function( elem, axis ){
+ var Dim = axis == 'x' ? 'Width' : 'Height',
+ scroll = 'scroll'+Dim;
+
+ if( !$(elem).is('html,body') )
+ return elem[scroll] - $(elem)[Dim.toLowerCase()]();
+
+ var size = 'client' + Dim,
+ html = elem.ownerDocument.documentElement,
+ body = elem.ownerDocument.body;
+
+ return Math.max( html[scroll], body[scroll] )
+ - Math.min( html[size] , body[size] );
+
+ };
+
+ function both( val ){
+ return typeof val == 'object' ? val : { top:val, left:val };
+ };
+
+})( jQuery );
\ No newline at end of file |
