Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Make sure Object.create is available in the browser (for our prototypal inheritance)
- // Courtesy of Papa Crockford
- // Note this is not entirely equal to native Object.create, but compatible with our use-case
- if (typeof Object.create !== 'function') {
- Object.create = function (o) {
- function F() {} // optionally move this outside the declaration and into a closure if you need more speed.
- F.prototype = o;
- return new F();
- };
- }
- ;(function($, window, document, undefined) {
- var EqualHeights = {
- init: function(options, elems) {
- var self = this;
- self.elems = elems;
- self.$elems = $(elems);
- self.options = $.extend( {}, $.fn.equalHeights.options, options );
- $(window).on('load resize orientationchange', function() {
- if (self.checkExecution()) {
- // We need to reset the heights no matter what
- self.resetHeights();
- self.hh = 0;
- self.$elems.each(function(){
- if ($(this).innerHeight() > self.hh) {
- self.hh = $(this).innerHeight();
- }
- });
- self.setHeights(self.hh);
- }
- else {
- self.resetHeights();
- }
- });
- },
- // Based on min and max values we figure out if we should execute
- checkExecution: function() {
- var self = this;
- var ww = $(window).width();
- return (ww >= self.options.min && ww < self.options.max);
- },
- resetHeights: function() {
- var self = this;
- var height = {};
- height[self.options.property] = '';
- self.$elems.css(height);
- },
- setHeights: function(hh) {
- var self = this;
- var height = {};
- height[self.options.property] = hh;
- self.$elems.css(height);
- }
- };
- $.fn.equalHeights = function(options) {
- var equalHeights = Object.create(EqualHeights);
- equalHeights.init(options, this);
- return this;
- };
- $.fn.equalHeights.options = {
- min: 0,
- max: 10000,
- property: 'min-height'
- };
- })(jQuery, window, document);
Advertisement
Add Comment
Please, Sign In to add comment