[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-messages/js/autocomplete/ -> jquery.dimensions.js (source)

   1  /*!
   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: 2007-09-11 05:38:31 +0300 (Вт, 11 сен 2007) $
   7   * $Rev: 3238 $
   8   *
   9   * Version: @VERSION
  10   *
  11   * Requires: jQuery 1.2+
  12   */
  13  
  14  (function($){
  15  
  16  $.dimensions = {
  17      version: '@VERSION'
  18  };
  19  
  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[ 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          return this[ name.toLowerCase() ]()
  43                  + num(this, 'border' + torl + 'Width') + num(this, 'border' + borr + 'Width')
  44                  + num(this, 'padding' + torl) + num(this, 'padding' + borr)
  45                  + (options.margin ? (num(this, 'margin' + torl) + num(this, 'margin' + borr)) : 0);
  46      };
  47  });
  48  
  49  // Create scrollLeft and scrollTop methods
  50  $.each( ['Left', 'Top'], function(i, name) {
  51      $.fn[ 'scroll' + name ] = function(val) {
  52          if (!this[0]) return;
  53  
  54          return val != undefined ?
  55  
  56              // Set the scroll offset
  57              this.each(function() {
  58                  this == window || this == document ?
  59                      window.scrollTo(
  60                          name == 'Left' ? val : $(window)[ 'scrollLeft' ](),
  61                          name == 'Top'  ? val : $(window)[ 'scrollTop'  ]()
  62                      ) :
  63                      this[ 'scroll' + name ] = val;
  64              }) :
  65  
  66              // Return the scroll offset
  67              this[0] == window || this[0] == document ?
  68                  self[ (name == 'Left' ? 'pageXOffset' : 'pageYOffset') ] ||
  69                      $.boxModel && document.documentElement[ 'scroll' + name ] ||
  70                      document.body[ 'scroll' + name ] :
  71                  this[0][ 'scroll' + name ];
  72      };
  73  });
  74  
  75  $.fn.extend({
  76      position: function() {
  77          var left = 0, top = 0, elem = this[0], offset, parentOffset, offsetParent, results;
  78  
  79          if (elem) {
  80              // Get *real* offsetParent
  81              offsetParent = this.offsetParent();
  82  
  83              // Get correct offsets
  84              offset       = this.offset();
  85              parentOffset = offsetParent.offset();
  86  
  87              // Subtract element margins
  88              offset.top  -= num(elem, 'marginTop');
  89              offset.left -= num(elem, 'marginLeft');
  90  
  91              // Add offsetParent borders
  92              parentOffset.top  += num(offsetParent, 'borderTopWidth');
  93              parentOffset.left += num(offsetParent, 'borderLeftWidth');
  94  
  95              // Subtract the two offsets
  96              results = {
  97                  top:  offset.top  - parentOffset.top,
  98                  left: offset.left - parentOffset.left
  99              };
 100          }
 101  
 102          return results;
 103      },
 104  
 105      offsetParent: function() {
 106          var offsetParent = this[0].offsetParent;
 107          while ( offsetParent && (!/^body|html$/i.test(offsetParent.tagName) && $.css(offsetParent, 'position') == 'static') )
 108              offsetParent = offsetParent.offsetParent;
 109          return $(offsetParent);
 110      }
 111  });
 112  
 113  var num = function(el, prop) {
 114      return parseInt($.css(el.jquery?el[0]:el,prop))||0;
 115  };
 116  
 117  })(jQuery);


Generated: Fri Nov 22 01:00:56 2024 Cross-referenced by PHPXref 0.7.1