Ignore:
Timestamp:
Jul 28, 2012, 8:48:54 PM (12 years ago)
Author:
cljosse
Message:

[extensions] Autosize fix compatibility with 2.4, new options

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/Autosize/js/autosize.dimensions.js

    r16931 r17192  
    4949  *
    5050  */
    51   jQuery.each(['Left', 'Top'],
     51  jQuery.each(['Left', 'Top', 'Right', 'Bottom', 'All'],
    5252    function (i, name) {
     53      //========== scroll =================
    5354      jQuery.fn['scroll' + name] = function (val) {
    5455        if (!this[0]) return;
     
    5859        }) : this[0] == window || this[0] == document ? self[(name == 'Left' ? 'pageXOffset' : 'pageYOffset')] || jQuery.boxModel && document.documentElement['scroll' + name] || document.body['scroll' + name] : this[0]['scroll' + name];
    5960      };
    60       //================================================
    61       jQuery.fn['absolute' + name] = function (val) {
    62         if (!this[0]) return;
     61      //========= Absolute =====================
     62      jQuery.fn['absolute' + name] = function (Args) {
     63        if (!this[0]) return 0;
    6364        a = jQuery(this[0]);
    64         m = 0;
    65         while (a.length > 0) {
    66           val = jQuery(a).infos();
    67           if (val.position != "absolute") {
    68             m += name == 'Left' ? val.left : val.top;
    69             m += name == 'Left' ? val.margin.left : val.margin.top;
    70             m += name == 'Left' ? val.margin.right : val.margin.bottom;
    71             m += name == 'Left' ? val.borderwidth.left : val.borderwidth.top;
    72             //   m += name == 'Left' ? val.borderwidth.right : val.borderwidth.bottom;
    73             //   m += name == 'Left' ? val.padding.left : val.padding.top;
    74             //   m += name == 'Left' ? val.padding.right : val.padding.bottom;
    75             a = jQuery(a).offsetParent();
    76           } else
    77             break;
     65        m = { Left: 0, Top: 0, Right: 0, Bottom: 0,
     66          All: {
     67            Left: 0, Top: 0, Right: 0, Bottom: 0
     68          }
     69        };
     70        pos = jQuery(this).offset();
     71        pos.top = Math.ceil(pos.top);
     72        pos.left = Math.ceil(pos.left);
     73
     74        size = { width: jQuery(this).outerWidth(), height: jQuery(this).outerHeight() };
     75
     76        if (name == "All") {
     77          m[name]['Left'] = pos.left;
     78          m[name]['Top'] = pos.top;
     79          m[name]['Right'] = pos.left + size.width;
     80          m[name]['Bottom'] = pos.top + size.height;
     81        } else {
     82         
     83          if (name == 'Left' || name == 'Top') {
     84            m[name] = name == 'Left' ? pos.left : (pos.top);
     85          } else {
     86            m[name] = name == 'Right' ? pos.left + size.width : pos.top + size.height;
     87          }
     88
    7889
    7990        }
    80         //306
    81 
    82 
    83         return m;
     91
     92
     93        return m[name];
    8494
    8595
     
    91101  jQuery.fn.extend({
    92102
    93     infos: function () {
     103    infos: function (Arguments) {
     104      if (!Arguments) {
     105        Arguments = { pos_absolute: false, pos_externe: false };
     106
     107      }
     108      Args = { pos_absolute: Arguments.pos_absolute || false, pos_externe: Arguments.pos_externe || false };
     109
    94110      var width = 0, height = 0;
    95111      var elem = jQuery(this).get(0);
     
    118134      myposition = "";
    119135      results = {
    120         visible:false ,
     136        visible: false,
    121137        position: "",
    122138        top: 0,
     
    136152          bottom: 0
    137153        },
    138        
     154
    139155        exterieur: {
    140156          width: 0,
     
    143159          bottom: 0
    144160        },
    145    
     161
    146162        general: {
    147163          width: 0,
     
    149165          right: 0,
    150166          bottom: 0,
    151           marges: { height:0,
    152                     top: 0,
    153                     bottom: 0,
    154                     width: 0,
    155                     left: 0,
    156                     right: 0
    157                     }
    158                 },
    159         src:"",
    160         useMap : "" ,
     167          marges: { height: 0,
     168            top: 0,
     169            bottom: 0,
     170            width: 0,
     171            left: 0,
     172            right: 0
     173          }
     174        },
     175        src: "",
     176        useMap: "",
    161177        id: "",
    162178        nodeName: ""
     
    177193          out_width = width;
    178194          out_height = height;
     195          in_width = width; ;
     196          in_height = height;
     197
    179198        } else {
    180199
     
    183202          out_width = jQuery(elem).outerWidth();
    184203          out_height = jQuery(elem).outerHeight();
     204          in_width = jQuery(elem).innerWidth();
     205          in_height = jQuery(elem).innerHeight();
    185206          elem_parent = elem.parentElement;
    186207          if (typeof elem_parent == "undefined") {
    187208            elem_parent = window;
    188209          }
    189           out_width = jQuery(elem).outerWidth();
    190           out_height = jQuery(elem).outerHeight();
    191           in_width = jQuery(elem).innerWidth();
    192           in_height = jQuery(elem).innerHeight();
     210
    193211          if (typeof Css.width != "undefined")
    194212            width = Get_Val_int(Css.width, jQuery(elem_parent).width(), 0);
     
    236254        } else {
    237255          Cl_Position = jQuery(elem).d_position();
     256
     257          /*
     258          margin: 5px;
     259          border: 10px ;
     260          padding: 20px;
     261
     262          */
     263          s_elem = elem;
     264          Left = Cl_Position.left; //  291
     265          Top = Cl_Position.top; // 812
     266          if (Args.pos_absolute == true) {
     267
     268            all = jQuery(elem).absoluteAll();
     269
     270            Top = all.Top;
     271            Left = all.Left;
     272            Args.pos_externe = false;
     273          }
     274
     275          if (Args.pos_externe == true) {
     276            if (elem.tagName != "BODY") {
     277              nodeName = nodeName || "";
     278              L1 = jQuery(elem).position();  // sans les marges ;
     279              L2 = jQuery(elem).position(true); //  296 x 817
     280              Left = L1.left;
     281              Top = L1.top;
     282            }
     283
     284          }
     285
     286          elem = s_elem;
    238287        }
    239         Left = Cl_Position.left;
    240         Top = Cl_Position.top;
    241 
    242288        visible = jQuery(elem).is(':visible');
    243         results = { 
    244           useMap : elem.useMap || "none",
     289        results = {
     290          useMap: elem.useMap || "none",
    245291          src: elem.src || "none",
    246292          visible: visible || false,
     
    279325                      margin.bottom + borderwidth.bottom +
    280326                      padding.bottom,
    281                       top: margin.top +
     327              top: margin.top +
    282328                            borderwidth.top +
    283329                            padding.top,
    284                       bottom: margin.bottom +
     330              bottom: margin.bottom +
    285331                       borderwidth.bottom +
    286332                        padding.bottom,
    287                       width: margin.left +
     333              width: margin.left +
    288334                              borderwidth.left +
    289335                              padding.left +
     
    291337                              borderwidth.right +
    292338                              padding.right,
    293                       left: margin.left +
     339              left: margin.left +
    294340                            borderwidth.left +
    295341                            padding.left,
    296                       right: margin.right +
     342              right: margin.right +
    297343                             borderwidth.right +
    298344                             padding.right
    299                     }
     345            }
    300346          },
    301347          id: id,
    302           nodeName: nodeName
     348          nodeName: nodeName || ""
    303349        };
    304350
     
    350396    */
    351397    offsetParent: function () {
    352       var offsetParent = this[0].offsetParent;
    353       while (offsetParent && (!/^body|html$/i.test(offsetParent.tagName) && jQuery.css(offsetParent, 'position') == 'static'))
    354         offsetParent = offsetParent.offsetParent;
    355       return jQuery(offsetParent);
     398      if (this[0] == window) return;
     399      try {
     400
     401        n1 = this[0].nodeName;
     402        var offsetParent = this[0].offsetParent;
     403
     404        while (offsetParent && (!/^body|html$/i.test(offsetParent.tagName) && jQuery.css(offsetParent, 'position') == 'static'))
     405          offsetParent = offsetParent.offsetParent;
     406        return jQuery(offsetParent);
     407      } catch (e) {
     408        jQuery(offsetParent);
     409      }
    356410    },
    357411    // getStyles(Obj) Récupérer la valeur CSS
     
    485539  };
    486540
    487  // myjQuery = jQuery;
    488  // my$ = $;
     541  // myjQuery = jQuery;
     542  // my$ = $;
    489543
    490544})(jQuery);
Note: See TracChangeset for help on using the changeset viewer.