12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- ;(function ($, window, document, undefined) {
- 'use strict';
- Foundation.libs.equalizer = {
- name : 'equalizer',
- version : '5.1.1',
- settings : {
- use_tallest: true,
- before_height_change: $.noop,
- after_height_change: $.noop
- },
- init : function (scope, method, options) {
- this.bindings(method, options);
- this.reflow();
- },
- events : function () {
- this.S(window).off('.equalizer').on('resize.fndtn.equalizer', function(e){
- this.reflow();
- }.bind(this));
- },
- equalize: function(equalizer) {
- var isStacked = false,
- vals = equalizer.find('[' + this.attr_name() + '-watch]'),
- firstTopOffset = vals.first().offset().top,
- settings = equalizer.data(this.attr_name(true)+'-init');
-
- if (vals.length === 0) return;
- settings.before_height_change();
- equalizer.trigger('before-height-change');
- vals.height('inherit');
- vals.each(function(){
- var el = $(this);
- if (el.offset().top !== firstTopOffset) {
- isStacked = true;
- }
- });
- if (isStacked) return;
-
- var heights = vals.map(function(){ return $(this).outerHeight() });
- if (settings.use_tallest) {
- var max = Math.max.apply(null, heights);
- vals.height(max);
- } else {
- var min = Math.min.apply(null, heights);
- vals.height(min);
- }
- settings.after_height_change();
- equalizer.trigger('after-height-change');
- },
- reflow : function () {
- var self = this;
- this.S('[' + this.attr_name() + ']', this.scope).each(function(){
- self.equalize($(this));
- });
- }
- };
- }(jQuery, this, this.document));
|