Commit 323c738e166422a55eb39be25eacc4621ab6863c

Authored by Andrew Buss
1 parent c0caaf6738

stop listening for keypresses after leaving the feed

Showing 5 changed files with 39 additions and 36 deletions Side-by-side Diff

scripts/CardListController.js View file @ 323c738
1 1 angular.module('flashy.CardListController', ['ui.router']).
2 2 controller('CardListController', ['$scope', '$state', '$http', '$stateParams',
3   - function ($scope, $state, $http, $stateParams) {
  3 + function($scope, $state, $http, $stateParams) {
4 4 // cards array
5 5 sectionId = $stateParams.sectionId;
6 6 $scope.cards = [];
7 7  
8 8 $http.get('/api/sections/' + sectionId + '/flashcards/').
9   - success(function (data) {
  9 + success(function(data) {
10 10 console.log(data);
11 11 $scope.cards = data;
12 12 }).
13   - error(function (err) {
  13 + error(function(err) {
14 14 console.log('pulling feed failed');
15 15 });
16   - $scope.viewFeed = function () {
  16 + $scope.viewFeed = function() {
17 17 $state.go('feed', {sectionId: sectionId});
18 18 console.log('go to feed');
19 19 };
scripts/DeckController.js View file @ 323c738
1 1 angular.module('flashy.DeckController', ['ui.router']).
2 2  
3 3 controller('DeckController', ['$scope', '$state', '$http', '$stateParams',
4   - function ($scope, $state, $http, $stateParams) {
  4 + function($scope, $state, $http, $stateParams) {
5 5 // cards array
6 6 sectionId = $stateParams.sectionId;
7 7 $scope.sectionId = sectionId;
8 8  
9 9  
10 10  
11 11  
12 12  
... ... @@ -9,26 +9,26 @@
9 9  
10 10 // Populate our page with cards.
11 11 $http.get('/api/sections/' + sectionId + '/deck/').
12   - success(function (data) {
  12 + success(function(data) {
13 13 console.log(data);
14 14 $scope.cards = data;
15 15 }).
16   - error(function (err) {
  16 + error(function(err) {
17 17 console.log('pulling feed failed');
18 18 });
19 19  
20 20 /* Lets page refresh the cards shown on the page. */
21   - $scope.refreshCards = function () {
  21 + $scope.refreshCards = function() {
22 22 var myDelay = 200; // ms
23 23  
24   - setTimeout(function () {
  24 + setTimeout(function() {
25 25 $http.get('/api/sections/' + sectionId + '/deck/').
26   - success(function (data) {
  26 + success(function(data) {
27 27 console.log(data);
28 28 $scope.cards = data;
29 29 console.log('success in refresh cards...');
30 30 }).
31   - error(function (err) {
  31 + error(function(err) {
32 32 console.log('refresh fail');
33 33 });
34 34 }, myDelay);
scripts/FeedController.js View file @ 323c738
1 1 angular.module('flashy.FeedController', ['ui.router']).
2 2  
3   - controller('FeedController', ['$scope', '$stateParams', '$state', '$http', function ($scope, $stateParams, $state, $http) {
  3 + controller('FeedController', ['$scope', '$stateParams', '$state', '$http', function($scope, $stateParams, $state, $http) {
4 4 console.log('Hello from feed');
5 5 sectionId = $stateParams.sectionId;
6 6 $scope.cards = [];
7 7  
8 8 $http.get('/api/sections/' + sectionId + '/feed/').
9   - success(function (data) {
  9 + success(function(data) {
10 10 console.log(data);
11 11 $scope.cards = data;
12 12 }).
13   - error(function (err) {
  13 + error(function(err) {
14 14 console.log('pulling feed failed');
15 15 });
16 16  
17   - $scope.viewDeck = function () {
  17 + $scope.viewDeck = function() {
18 18 $state.go('deck', {sectionId: sectionId});
19 19 console.log('go to deck');
20 20 };
21 21  
22   - $scope.pushCard = function () {
  22 + $scope.pushCard = function() {
23 23 console.log('make! card content:' + $scope.text);
24 24 var pushed = new Date(Date.now());
25 25 console.log(pushed.toString());
26 26  
27 27  
28 28  
29 29  
30 30  
31 31  
... ... @@ -32,34 +32,34 @@
32 32 section: sectionId
33 33 };
34 34 $http.post('/api/flashcards/', myCard).
35   - success(function (data) {
  35 + success(function(data) {
36 36 console.log('pushed a card!');
37 37 $scope.cards.push(myCard); // Add right away
38 38 $scope.refreshCards(); // Refresh list
39 39 listenForC = true;
40 40 }).
41   - error(function (error) {
  41 + error(function(error) {
42 42 console.log('haha, n00b');
43 43 });
44 44  
45 45 $scope.text = '';
46 46 };
47 47  
48   - $scope.refreshCards = function () {
  48 + $scope.refreshCards = function() {
49 49 $http.get('/api/sections/' + sectionId + '/feed/').
50   - success(function (data) {
  50 + success(function(data) {
51 51 console.log(data);
52 52 $scope.cards = data;
53 53 console.log('success in refresh cards...');
54 54 }).
55   - error(function (err) {
  55 + error(function(err) {
56 56 console.log('refresh fail');
57 57 });
58   - }
  58 + };
59 59  
60 60 /* Key bindings for the whole feed window. Hotkey it up! */
61 61 var listenForC = true;
62   - $(document).keydown(function (e) {
  62 + $(document).keydown(function(e) {
63 63 var keyed = e.which;
64 64 if (keyed == 67 && listenForC) { // "c" or "C" for compose
65 65 $('#newCard').openModal();
66 66  
... ... @@ -71,11 +71,10 @@
71 71 }
72 72 });
73 73  
74   -
75 74 $scope.flashcard = '';
76 75 $scope.text = '';
77 76  
78   - $(document).ready(function () {
  77 + $(document).ready(function() {
79 78 // the "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered
80 79 $('.modal-trigger').leanModal({
81 80 dismissible: true, // Modal can be dismissed by clicking outside of the modal
82 81  
83 82  
... ... @@ -84,14 +83,18 @@
84 83 out_duration: 200, // Transition out duration
85 84 ready: function() {
86 85 listenForC = false;
87   - console.log("modal OPENING");
  86 + console.log('modal OPENING');
88 87 },
89 88 complete: function() {
90 89 listenForC = true;
91   - console.log("modal done, closing");
  90 + console.log('modal done, closing');
92 91 }
93 92 }
94 93 );
  94 + });
  95 +
  96 + $scope.$on('$destroy', function() {
  97 + $(document).off('keydown');
95 98 });
96 99  
97 100 }]);
scripts/FlashcardDirective.js View file @ 323c738
... ... @@ -38,33 +38,33 @@
38 38 /* Unpulls card from deck */
39 39 scope.unpullCard = function(flashcard) {
40 40 if ($state.current.name == 'deck') {
41   - console.log('unpulling card...')
  41 + console.log('unpulling card...');
42 42  
43 43 $http.post('/api/flashcards/' + flashcard.id + '/unpull/',
44 44 flashcard).
45 45 success(function(data) {
46   - console.log('card unpull success')
  46 + console.log('card unpull success');
47 47 scope.startShrink = true;
48 48 scope.refresh();
49 49 }).
50 50 error(function(data) {
51   - console.log('card unpull FAILURE')
  51 + console.log('card unpull FAILURE');
52 52 });
53 53 }
54 54 };
55   -
  55 +
56 56 /* Hides card from feed */
57 57 scope.hideCard = function(flashcard) {
58 58 if ($state.current.name == 'feed') {
59 59 $http.post('/api/flashcards/' + flashcard.id + '/hide/',
60 60 flashcard).
61 61 success(function(data) {
62   - console.log('card hide success')
  62 + console.log('card hide success');
63 63 scope.startShrink = true;
64 64 scope.refresh();
65 65 }).
66 66 error(function(data) {
67   - console.log('card hide FAILURE')
  67 + console.log('card hide FAILURE');
68 68 });
69 69 }
70 70 };
scripts/StudyController.js View file @ 323c738
... ... @@ -8,11 +8,11 @@
8 8 // Flashcard content
9 9 $scope.htmlContent = 'sample text here longwordddddddddddddddddddddddddddd hello there from js review ctrl alwkejflakewjflk awjkefjkwefjlkea jfkewjaweajkakwef jk fjeawkafj kaewjf jawekfj akwejfk ';
10 10 //single card
11   - $scope.samples =
  11 + $scope.samples =
12 12 {
13 13 'name': 'lol',
14 14 'text': 'sample text here 111111 woo hoo I think it works',
15   - 'mask': [[0,6],[16,23]]
  15 + 'mask': [[0, 6], [16, 23]]
16 16 };
17 17  
18 18 // get text to display as array
... ... @@ -25,7 +25,7 @@
25 25 $scope.blankText.push($scope.samples.text.substring($scope.samples.mask[i][0], $scope.samples.mask[i][1]));
26 26 start = $scope.samples.mask[i][1];
27 27 }
28   - if (start != $scope.samples.mask.length-1)
  28 + if (start != $scope.samples.mask.length - 1)
29 29 $scope.displayText.push($scope.samples.text.substring(start));
30 30  
31 31 // user entered responses as array