From b124335c5867889866b245f5b686ee05c8b2b3f4 Mon Sep 17 00:00:00 2001 From: Tetranoir Date: Mon, 25 May 2015 19:40:50 -0700 Subject: [PATCH] feedController rows --- scripts/FeedController.js | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/scripts/FeedController.js b/scripts/FeedController.js index 3515ecd..e62dc77 100644 --- a/scripts/FeedController.js +++ b/scripts/FeedController.js @@ -5,8 +5,9 @@ angular.module('flashy.FeedController', ['ui.router']). sectionId = $stateParams.sectionId; $rootScope.currentSection = $rootScope.SectionResource.get({sectionId: sectionId}); $scope.cards = false; + $scope.data = []; $scope.cardCols = []; - $scope.cols = 1; + $scope.cols = 0; /* Handles number of columns */ function calculate_cols() { @@ -16,6 +17,7 @@ angular.module('flashy.FeedController', ['ui.router']). } function createCols(data) { + if (calculate_cols() == $scope.cols) return $scope.cardCols = []; for (i = 0; i < $scope.cols; i++) $scope.cardCols.push([]); var i = 0; @@ -25,7 +27,7 @@ angular.module('flashy.FeedController', ['ui.router']). } } - angular.element($window).bind('resize', $scope.refreshCards); + angular.element($window).bind('resize', $scope.createCols($scope.data)); console.log('cols:' + calculate_cols()); $scope.refreshCards = function() { @@ -41,8 +43,14 @@ angular.module('flashy.FeedController', ['ui.router']). }; $scope.add = function(card) { - var col = Math.floor(Math.random() * $scope.cols); - $scope.cols[col].unshift(card); + for (col in $scope.cardCols) { + if (col.length == 0) { + col.unshift(card); + return; + } + } + var colNum = Math.floor(Math.random() * $scope.cols); + $scope.cardCols[colNum].unshift(card); }; $scope.hide = function(card) { @@ -69,7 +77,8 @@ angular.module('flashy.FeedController', ['ui.router']). return false; } } - createCols(); + $scope.data = data; + createCols(data); console.log('success in refresh cards...'); }). error(function(err) { -- 1.9.1