Commit b124335c5867889866b245f5b686ee05c8b2b3f4

Authored by Tetranoir
1 parent a276a49eeb

feedController rows

Showing 1 changed file with 14 additions and 5 deletions Side-by-side Diff

scripts/FeedController.js View file @ b124335
... ... @@ -5,8 +5,9 @@
5 5 sectionId = $stateParams.sectionId;
6 6 $rootScope.currentSection = $rootScope.SectionResource.get({sectionId: sectionId});
7 7 $scope.cards = false;
  8 + $scope.data = [];
8 9 $scope.cardCols = [];
9   - $scope.cols = 1;
  10 + $scope.cols = 0;
10 11  
11 12 /* Handles number of columns */
12 13 function calculate_cols() {
... ... @@ -16,6 +17,7 @@
16 17 }
17 18  
18 19 function createCols(data) {
  20 + if (calculate_cols() == $scope.cols) return
19 21 $scope.cardCols = [];
20 22 for (i = 0; i < $scope.cols; i++) $scope.cardCols.push([]);
21 23 var i = 0;
... ... @@ -25,7 +27,7 @@
25 27 }
26 28 }
27 29  
28   - angular.element($window).bind('resize', $scope.refreshCards);
  30 + angular.element($window).bind('resize', $scope.createCols($scope.data));
29 31 console.log('cols:' + calculate_cols());
30 32  
31 33 $scope.refreshCards = function() {
... ... @@ -41,8 +43,14 @@
41 43 };
42 44  
43 45 $scope.add = function(card) {
44   - var col = Math.floor(Math.random() * $scope.cols);
45   - $scope.cols[col].unshift(card);
  46 + for (col in $scope.cardCols) {
  47 + if (col.length == 0) {
  48 + col.unshift(card);
  49 + return;
  50 + }
  51 + }
  52 + var colNum = Math.floor(Math.random() * $scope.cols);
  53 + $scope.cardCols[colNum].unshift(card);
46 54 };
47 55  
48 56 $scope.hide = function(card) {
... ... @@ -69,7 +77,8 @@
69 77 return false;
70 78 }
71 79 }
72   - createCols();
  80 + $scope.data = data;
  81 + createCols(data);
73 82 console.log('success in refresh cards...');
74 83 }).
75 84 error(function(err) {