Bug 20489 Configure illegal file characters https://bugzilla.wikimedia.org/show_bug...
[mediawiki.git] / js2 / mwEmbed / jquery / plugins / jquery.dimensions.js
blob100e60c3a3724b6f73e4a77ad857ef4212aa139b
1 /* Copyright (c) 2007 Paul Bakaus (paul.bakaus@googlemail.com) and Brandon Aaron (brandon.aaron@gmail.com || http://brandonaaron.net)
2  * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
3  * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
4  *
5  * $LastChangedDate: 2007-09-10 19:38:31 -0700 (Mon, 10 Sep 2007) $
6  * $Rev: 3238 $
7  *
8  * Version: @VERSION
9  *
10  * Requires: jQuery 1.2+
11  */
13 (function($){
15 $.dimensions = {
16         version: '@VERSION'
19 // Create innerHeight, innerWidth, outerHeight and outerWidth methods
20 $.each( [ 'Height', 'Width' ], function(i, name){
22         // innerHeight and innerWidth
23         $.fn[ 'inner' + name ] = function() {
24                 if (!this[0]) return;
26                 var torl = name == 'Height' ? 'Top'     : 'Left',  // top or left
27                         borr = name == 'Height' ? 'Bottom' : 'Right'; // bottom or right
29                 return this[ name.toLowerCase() ]() + num(this, 'padding' + torl) + num(this, 'padding' + borr);
30         };
32         // outerHeight and outerWidth
33         $.fn[ 'outer' + name ] = function(options) {
34                 if (!this[0]) return;
36                 var torl = name == 'Height' ? 'Top'     : 'Left',  // top or left
37                         borr = name == 'Height' ? 'Bottom' : 'Right'; // bottom or right
39                 options = $.extend({ margin: false }, options || {});
41                 return this[ name.toLowerCase() ]()
42                                 + num(this, 'border' + torl + 'Width') + num(this, 'border' + borr + 'Width')
43                                 + num(this, 'padding' + torl) + num(this, 'padding' + borr)
44                                 + (options.margin ? (num(this, 'margin' + torl) + num(this, 'margin' + borr)) : 0);
45         };
46 });
48 // Create scrollLeft and scrollTop methods
49 $.each( ['Left', 'Top'], function(i, name) {
50         $.fn[ 'scroll' + name ] = function(val) {
51                 if (!this[0]) return;
53                 return val != undefined ?
55                         // Set the scroll offset
56                         this.each(function() {
57                                 this == window || this == document ?
58                                         window.scrollTo(
59                                                 name == 'Left' ? val : $(window)[ 'scrollLeft' ](),
60                                                 name == 'Top'  ? val : $(window)[ 'scrollTop'  ]()
61                                         ) :
62                                         this[ 'scroll' + name ] = val;
63                         }) :
65                         // Return the scroll offset
66                         this[0] == window || this[0] == document ?
67                                 self[ (name == 'Left' ? 'pageXOffset' : 'pageYOffset') ] ||
68                                         $.boxModel && document.documentElement[ 'scroll' + name ] ||
69                                         document.body[ 'scroll' + name ] :
70                                 this[0][ 'scroll' + name ];
71         };
72 });
74 $.fn.extend({
75         position: function() {
76                 var left = 0, top = 0, elem = this[0], offset, parentOffset, offsetParent, results;
78                 if (elem) {
79                         // Get *real* offsetParent
80                         offsetParent = this.offsetParent();
82                         // Get correct offsets
83                         offset     = this.offset();
84                         parentOffset = offsetParent.offset();
86                         // Subtract element margins
87                         offset.top  -= num(elem, 'marginTop');
88                         offset.left -= num(elem, 'marginLeft');
90                         // Add offsetParent borders
91                         parentOffset.top  += num(offsetParent, 'borderTopWidth');
92                         parentOffset.left += num(offsetParent, 'borderLeftWidth');
94                         // Subtract the two offsets
95                         results = {
96                                 top:  offset.top  - parentOffset.top,
97                                 left: offset.left - parentOffset.left
98                         };
99                 }
101                 return results;
102         },
104         offsetParent: function() {
105                 var offsetParent = this[0].offsetParent;
106                 while ( offsetParent && (!/^body|html$/i.test(offsetParent.tagName) && $.css(offsetParent, 'position') == 'static') )
107                         offsetParent = offsetParent.offsetParent;
108                 return $(offsetParent);
109         }
112 var num = function(el, prop) {
113         return parseInt($.css(el.jquery?el[0]:el,prop))||0;
116 })(jQuery);