Add deprecation notice
[web.git] / js / foundation / foundation.equalizer.js
1 ;
2 (function ($, window, document, undefined) {
3 'use strict';
4
5 Foundation.libs.equalizer = {
6 name: 'equalizer',
7
8 version: '5.5.0',
9
10 settings: {
11 use_tallest: true,
12 before_height_change: $.noop,
13 after_height_change: $.noop,
14 equalize_on_stack: false
15 },
16
17 init: function (scope, method, options) {
18 Foundation.inherit(this, 'image_loaded');
19 this.bindings(method, options);
20 this.reflow();
21 },
22
23 events: function () {
24 this.S(window).off('.equalizer').on('resize.fndtn.equalizer', function (e) {
25 this.reflow();
26 }.bind(this));
27 },
28
29 equalize: function (equalizer) {
30 var isStacked = false,
31 vals = equalizer.find('[' + this.attr_name() + '-watch]:visible'),
32 settings = equalizer.data(this.attr_name(true) + '-init');
33
34 if (vals.length === 0) return;
35 var firstTopOffset = vals.first().offset().top;
36 settings.before_height_change();
37 equalizer.trigger('before-height-change').trigger('before-height-change.fndth.equalizer');
38 vals.height('inherit');
39 vals.each(function () {
40 var el = $(this);
41 if (el.offset().top !== firstTopOffset) {
42 isStacked = true;
43 }
44 });
45
46 if (settings.equalize_on_stack === false) {
47 if (isStacked) return;
48 }
49 ;
50
51 var heights = vals.map(function () {
52 return $(this).outerHeight(false)
53 }).get();
54
55 if (settings.use_tallest) {
56 var max = Math.max.apply(null, heights);
57 vals.css('height', max);
58 } else {
59 var min = Math.min.apply(null, heights);
60 vals.css('height', min);
61 }
62 settings.after_height_change();
63 equalizer.trigger('after-height-change').trigger('after-height-change.fndtn.equalizer');
64 },
65
66 reflow: function () {
67 var self = this;
68
69 this.S('[' + this.attr_name() + ']', this.scope).each(function () {
70 var $eq_target = $(this);
71 self.image_loaded(self.S('img', this), function () {
72 self.equalize($eq_target)
73 });
74 });
75 }
76 };
77 })(jQuery, window, window.document);