Permalink
Browse files

Added support for breakpoints while keeping single-value function calls.

  • Loading branch information...
RadLikeWhoa committed Jun 21, 2012
1 parent 70158b6 commit a94d7bd5454c7fb47e9a5a5954ed83b313e56787
Showing with 19 additions and 7 deletions.
  1. +19 −7 jquery.baseline.js
View
@@ -10,26 +10,38 @@
*/
(function( $ ) {
- $.fn.baseline = function(target) {
+ $.fn.baseline = function(breakpoints) {
// Set up our variables, like a good little developer
- var tall;
- var newHeight;
+ var tall, newHeight, base;
return this.each(function(){
var $this = $(this); // Set the images as objects
- var setbase = function(target) { // The fun starts here
+ var setbase = function(breakpoints) { // The fun starts here
+
+ // Check if a single value or multiple breakpoints are given
+ if (typeof breakpoints === 'number') {
+ base = breakpoints;
+ } else if (typeof breakpoints === 'object') {
+ // Loop through the breakpoints and check which baseline to apply
+ for (key in breakpoints) {
+ if (document.width > parseInt(key)) {
+ base = breakpoints[key];
+ }
+ }
+ }
+
$this.removeAttr('style'); // Remove old max-height so that we can resize up as well as down
tall = $this.height(); // Grab the height
- newHeight = Math.floor(tall / target) * target; // Make up a new height based on the baseline
+ newHeight = Math.floor(tall / base) * base; // Make up a new height based on the baseline
$this.css('maxHeight', newHeight); // Set it!
}
- setbase(target); // Call on load
+ setbase(breakpoints); // Call on load
$(window).resize(function(){ // And call again on resize.
- setbase(target);
+ setbase(breakpoints);
});
});

0 comments on commit a94d7bd

Please sign in to comment.