Skip to content

Instantly share code, notes, and snippets.

@edelbalso
Forked from uhhuhyeah/widget.js
Last active December 11, 2015 23:28
Show Gist options
  • Save edelbalso/4676875 to your computer and use it in GitHub Desktop.
Save edelbalso/4676875 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
 var setupGrid = function(opts) {
   this.containerWidth = opts.containerWidth;
   calculateColumnCount();
   calculateColumnWidth();
   calculateScaleFactor();
 };
 
 // Private Interface
 var calculateColumnCount = function() {
 
   var columns = Math.floor( this.containerWidth / this.idealColumnWidth );
   if (columns < 1) {
     columns = 1;
   };
   this.numberOfColumns = columns;
 };
 
 var calculateScaleFactor = function() {
   this.scaleFactor = this.columnWidth / this.idealColumnWidth
 };
 
 var calculateColumnWidth = function() {
   this.columnWidth = Math.floor(
     (this.containerWidth / this.numberOfColumns) - this.marginHoriz/2
   );
 }
 
 var exports = {
   setupGrid: setupGrid,
   numberOfColumns: numberOfColumns,
   scaleFactor: scaleFactor
 }
 return exports;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment