More jquery js files referenced by bonescript
[beagleboard.org.git] / static / jquery.dimensions.js
blob422924104ab185d4de041d2b935ec9dedd95ead5
1 // JavaScript Document
2 /* Copyright (c) 2007 Paul Bakaus (paul.bakaus@googlemail.com) and Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
3  * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
4  * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
5  *
6  * $LastChangedDate$
7  * $Rev$
8  *
9  * Version: @VERSION
10  *
11  * Requires: jQuery 1.2+
12  */
14 (function($){
15        
16 $.dimensions = {
17         version: '@VERSION'
20 // Create innerHeight, innerWidth, outerHeight and outerWidth methods
21 $.each( [ 'Height', 'Width' ], function(i, name){
22        
23         // innerHeight and innerWidth
24         $.fn[ 'inner' + name ] = function() {
25                 if (!this[0]) return;
26                
27                 var torl = name == 'Height' ? 'Top'    : 'Left',  // top or left
28                     borr = name == 'Height' ? 'Bottom' : 'Right'; // bottom or right
29                
30                 return this.css('display') != 'none' ? this[0]['client' + name] : num( this, name.toLowerCase() ) + num(this, 'padding' + torl) + num(this, 'padding' + borr);
31         };
32        
33         // outerHeight and outerWidth
34         $.fn[ 'outer' + name ] = function(options) {
35                 if (!this[0]) return;
36                
37                 var torl = name == 'Height' ? 'Top'    : 'Left',  // top or left
38                     borr = name == 'Height' ? 'Bottom' : 'Right'; // bottom or right
39                
40                 options = $.extend({ margin: false }, options || {});
41                
42                 var val = this.css('display') != 'none' ?
43                                 this[0]['offset' + name] :
44                                 num( this, name.toLowerCase() )
45                                         + num(this, 'border' + torl + 'Width') + num(this, 'border' + borr + 'Width')
46                                         + num(this, 'padding' + torl) + num(this, 'padding' + borr);
47                
48                 return val + (options.margin ? (num(this, 'margin' + torl) + num(this, 'margin' + borr)) : 0);
49         };
50 });
52 // Create scrollLeft and scrollTop methods
53 $.each( ['Left', 'Top'], function(i, name) {
54         $.fn[ 'scroll' + name ] = function(val) {
55                 if (!this[0]) return;
56                
57                 return val != undefined ?
58                
59                         // Set the scroll offset
60                         this.each(function() {
61                                 this == window || this == document ?
62                                         window.scrollTo(
63                                                 name == 'Left' ? val : $(window)[ 'scrollLeft' ](),
64                                                 name == 'Top'  ? val : $(window)[ 'scrollTop'  ]()
65                                         ) :
66                                         this[ 'scroll' + name ] = val;
67                         }) :
68                        
69                         // Return the scroll offset
70                         this[0] == window || this[0] == document ?
71                                 self[ (name == 'Left' ? 'pageXOffset' : 'pageYOffset') ] ||
72                                         $.boxModel && document.documentElement[ 'scroll' + name ] ||
73                                         document.body[ 'scroll' + name ] :
74                                 this[0][ 'scroll' + name ];
75         };
76 });
78 $.fn.extend({
79         position: function() {
80                 var left = 0, top = 0, elem = this[0], offset, parentOffset, offsetParent, results;
81                
82                 if (elem) {
83                         // Get *real* offsetParent
84                         offsetParent = this.offsetParent();
85                        
86                         // Get correct offsets
87                         offset       = this.offset();
88                         parentOffset = offsetParent.offset();
89                        
90                         // Subtract element margins
91                         offset.top  -= num(elem, 'marginTop');
92                         offset.left -= num(elem, 'marginLeft');
93                        
94                         // Add offsetParent borders
95                         parentOffset.top  += num(offsetParent, 'borderTopWidth');
96                         parentOffset.left += num(offsetParent, 'borderLeftWidth');
97                        
98                         // Subtract the two offsets
99                         results = {
100                                 top:  offset.top  - parentOffset.top,
101                                 left: offset.left - parentOffset.left
102                         };
103                 }
104                
105                 return results;
106         },
107        
108         offsetParent: function() {
109                 var offsetParent = this[0].offsetParent;
110                 while ( offsetParent && (!/^body|html$/i.test(offsetParent.tagName) && $.css(offsetParent, 'position') == 'static') )
111                         offsetParent = offsetParent.offsetParent;
112                 return $(offsetParent);
113         }
116 function num(el, prop) {
117         return parseInt($.curCSS(el.jquery?el[0]:el,prop,true))||0;
120 })(jQuery);