Skip to content

Instantly share code, notes, and snippets.

@uhhuhyeah
Created January 30, 2013 20:52
Show Gist options
  • Save uhhuhyeah/4676837 to your computer and use it in GitHub Desktop.
Save uhhuhyeah/4676837 to your computer and use it in GitHub Desktop.
window.utils = window.utils || {};
utils.Grid = function() {
 // Defaults
 var that = this;
 this.idealColumnWidth = 320;
 this.marginHoriz = 15;
   
 // Public Interface
 this.setupGrid = function(opts) {
   this.containerWidth = opts.containerWidth;
   this.calculateColumnCount();
   this.calculateColumnWidth();
   this.calculateScaleFactor();
 };
 
 // Private Interface
 this.calculateColumnCount = function() {
 
   var columns = Math.floor( this.containerWidth / this.idealColumnWidth );
   if (columns < 1) {
     columns = 1;
   };
   this.numberOfColumns = columns;
 };
 
 this.calculateScaleFactor = function() {
   this.scaleFactor = this.columnWidth / this.idealColumnWidth
 };
 
 this.calculateColumnWidth = function() {
   this.columnWidth = Math.floor(
     (this.containerWidth / this.numberOfColumns) - this.marginHoriz/2
   );
 }
 
 var exports = {
   setupGrid: this.setupGrid,
   numberOfColumns: this.numberOfColumns,
   scaleFactor: this.scaleFactor
 }
 return exports;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment