diff --git a/scripts/FeedController.js b/scripts/FeedController.js index ab232b9..9898424 100644 --- a/scripts/FeedController.js +++ b/scripts/FeedController.js @@ -60,15 +60,20 @@ angular.module('flashy.FeedController', ['ui.router']). }; $scope.add = function(card) { - console.log('adding card'); - for (i = 0; i < $scope.cardCols.length; i++) { - if ($scope.cardCols[i].length == 0) { - $scope.cardCols[i].unshift(card); - return; - } + + var colNum = 0; + while (colNum < $scope.numCols) { + if ($scope.cardCols[colNum].length == 0) break; + colNum++; + } + if (colNum == $scope.numCols) { + colNum = Math.floor(Math.random() * $scope.numCols); } - var colNum = Math.floor(Math.random() * $scope.numCols); - $scope.cardCols[colNum].unshift(card); + console.log('adding card to column ' + colNum); + console.log(card); + $timeout(function() { + $scope.cardCols[colNum].unshift(card); + }); }; $scope.hide = function(card) { @@ -86,18 +91,6 @@ angular.module('flashy.FeedController', ['ui.router']). console.log(card); }; - /* Instance creation */ - $http.get('/api/sections/' + sectionId + '/feed/'). - success(function(data) { - console.log(data); - $scope.cards = data; - $scope.refreshLayout(); - console.log('success in refresh cards...'); - }). - error(function(err) { - console.log('pulling feed failed'); - }); - var loc = window.location, new_uri; if (loc.protocol === 'https:') { new_uri = 'wss:'; @@ -138,9 +131,8 @@ angular.module('flashy.FeedController', ['ui.router']). i += node.data.length; } }); - text = $('#new-card-input').text(); var myCard = { - 'text': text, + 'text': $('#new-card-input').text(), 'mask': blanks, section: sectionId }; @@ -154,8 +146,6 @@ angular.module('flashy.FeedController', ['ui.router']). error(function(error) { console.log('something went wrong pushing a card!'); }); - listenForC = true; - $('#new-card-input').html(''); }; /* Key bindings for the whole feed window. Hotkey it up! */ @@ -183,20 +173,16 @@ angular.module('flashy.FeedController', ['ui.router']). $(document).keydown(function(e) { var keyed = e.which; - if (keyed == 67 && listenForC) { // "c" or "C" for compose + if (keyed == 67 && listenForC) { // "c" for compose $('#newCard').openModal(modal_options); e.preventDefault(); listenForC = false; return false; - } else if (keyed == 27) { // enter or esc, respectively + } else if (keyed == 27) { // clear on ESC listenForC = true; document.getElementById('new-card-input').value = ''; } }); - $scope.flashcard = ''; - $scope.text = ''; - var selected_start = 0; - var selected_end = 0; $(document).ready(function() { $('.tooltipped').tooltip({delay: 50}); // the "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered @@ -205,20 +191,18 @@ angular.module('flashy.FeedController', ['ui.router']). if (e.which == 13) { e.preventDefault(); $scope.pushCard(); + $('#new-card-input').html(''); $('#newCard').closeModal(modal_options); + listenForC = true; return false; } }); - $('#new-card-input').on('mouseup', function() { - console.log('got selection: ' + selected_start); - }); $('button#blank-selected').click(function() { console.log(window.getSelection()); document.execCommand('bold'); }); }); - //$scope.refreshCards(); - //$scope.refreshLayout(); + $scope.refreshCards(); $scope.$on('$destroy', function() { ws.close(); $rootScope.currentSection = {};