Commit efc77eb59bfd5126ee0a6615f6592f9e0b8a4cce
1 parent
a06a0c4566
Exists in
master
and in
1 other branch
blanks kinda work
Showing 5 changed files with 48 additions and 28 deletions Side-by-side Diff
config.js
View file @
efc77eb
... | ... | @@ -20,6 +20,15 @@ |
20 | 20 | $httpProvider.defaults.withCredentials = true; |
21 | 21 | $httpProvider.defaults.xsrfCookieName = 'csrftoken'; |
22 | 22 | $httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken'; |
23 | + | |
24 | + var arrayMethods = Object.getOwnPropertyNames(Array.prototype); | |
25 | + arrayMethods.forEach(attachArrayMethodsToNodeList); | |
26 | + function attachArrayMethodsToNodeList(methodName) { | |
27 | + if (methodName !== 'length') { | |
28 | + NodeList.prototype[methodName] = Array.prototype[methodName]; | |
29 | + } | |
30 | + }; | |
31 | + | |
23 | 32 | $httpProvider.interceptors.push(function($q) { |
24 | 33 | return { |
25 | 34 | 'responseError': function(rejection) { |
scripts/FeedController.js
View file @
efc77eb
... | ... | @@ -3,7 +3,6 @@ |
3 | 3 | controller('FeedController', ['$scope', '$stateParams', '$state', '$http', function($scope, $stateParams, $state, $http) { |
4 | 4 | |
5 | 5 | |
6 | - | |
7 | 6 | console.log('Hello from feed'); |
8 | 7 | sectionId = $stateParams.sectionId; |
9 | 8 | $scope.cards = []; |
10 | 9 | |
11 | 10 | |
12 | 11 | |
... | ... | @@ -46,15 +45,26 @@ |
46 | 45 | }; |
47 | 46 | |
48 | 47 | $scope.pushCard = function() { |
49 | - console.log('make! card content:' + $scope.text); | |
50 | 48 | var pushed = new Date(Date.now()); |
51 | - console.log(pushed.toString()); | |
52 | - text = $scope.text; | |
53 | - // attempt to make card :( | |
49 | + var i = 0; | |
50 | + var blanks = []; | |
51 | + $('#new-card-input')[0].childNodes.forEach(function(node) { | |
52 | + node = $(node)[0]; | |
53 | + console.log(node); | |
54 | + if (node.tagName == 'B') { | |
55 | + text = $(node).text(); | |
56 | + blanks.push([i, i + text.length]); | |
57 | + i += text.length; | |
58 | + } else { | |
59 | + i += node.data.length; | |
60 | + } | |
61 | + }); | |
62 | + console.log(blanks); | |
63 | + text = $('#new-card-input').text(); | |
54 | 64 | var myCard = { |
55 | - 'text': $scope.text, | |
65 | + 'text': text, | |
56 | 66 | 'material_date': pushed, |
57 | - 'mask': '[]', | |
67 | + 'mask': JSON.stringify(blanks), | |
58 | 68 | section: sectionId |
59 | 69 | }; |
60 | 70 | $http.post('/api/flashcards/', myCard). |
... | ... | @@ -66,7 +76,7 @@ |
66 | 76 | console.log('something went wrong pushing a card!'); |
67 | 77 | }); |
68 | 78 | |
69 | - $scope.text = ''; | |
79 | + $('#new-card-input').html(''); | |
70 | 80 | }; |
71 | 81 | |
72 | 82 | $scope.refreshCards = function() { |
73 | 83 | |
... | ... | @@ -111,12 +121,11 @@ |
111 | 121 | e.preventDefault(); |
112 | 122 | listenForC = false; |
113 | 123 | return false; |
114 | - } else if (keyed == 13 || keyed == 27) { // enter or esc, respectively | |
124 | + } else if (keyed == 27) { // enter or esc, respectively | |
115 | 125 | listenForC = true; |
116 | 126 | document.getElementById('new-card-input').value = ''; |
117 | 127 | } |
118 | 128 | }); |
119 | - | |
120 | 129 | $scope.flashcard = ''; |
121 | 130 | $scope.text = ''; |
122 | 131 | var selected_start = 0; |
123 | 132 | |
124 | 133 | |
... | ... | @@ -124,18 +133,20 @@ |
124 | 133 | $(document).ready(function() { |
125 | 134 | // the "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered |
126 | 135 | $('.modal-trigger').leanModal(modal_options); |
136 | + $('#new-card-input').on('keydown', function(e) { | |
137 | + if (e.which == 13) { | |
138 | + e.preventDefault(); | |
139 | + $scope.pushCard(); | |
140 | + $('#newCard').closeModal(modal_options); | |
141 | + return false; | |
142 | + } | |
143 | + }); | |
127 | 144 | $('#new-card-input').on('mouseup', function() { |
128 | - selected_start = this.selectionStart; | |
129 | - selected_end = this.selectionEnd; | |
145 | + console.log('got selection: ' + selected_start); | |
130 | 146 | }); |
131 | 147 | $('button#blank-selected').click(function() { |
132 | - document.execCommand('bold', false, null); | |
133 | - console.log('blanking ' + selected_start + ' to ' + selected_end); | |
134 | - var pre = $('#new-card-input').val().substring(0, selected_start); | |
135 | - var word = $('#new-card-input').val().substring(selected_start, selected_end); | |
136 | - var post = $('#new-card-input').val().substring(selected_end); | |
137 | - console.log(word); | |
138 | - //$('#new-card-input').val(pre + '<span style="font-weight:900">' + word + '</span>' + post); | |
148 | + console.log(window.getSelection()); | |
149 | + document.execCommand('bold'); | |
139 | 150 | }); |
140 | 151 | }); |
141 | 152 |
styles/flashy.css
View file @
efc77eb
... | ... | @@ -38,8 +38,8 @@ |
38 | 38 | } |
39 | 39 | |
40 | 40 | /*.container .row {*/ |
41 | - /*margin-left: 0;*/ | |
42 | - /*margin-right: 0;*/ | |
41 | +/*margin-left: 0;*/ | |
42 | +/*margin-right: 0;*/ | |
43 | 43 | /*}*/ |
44 | 44 | |
45 | 45 | /* Flashcard directive css */ |
... | ... | @@ -85,7 +85,7 @@ |
85 | 85 | } |
86 | 86 | |
87 | 87 | .center-me:hover i { |
88 | - text-shadow: 0 0 15px rgba(255,255,255,0.7); | |
88 | + text-shadow: 0 0 15px rgba(255, 255, 255, 0.7); | |
89 | 89 | } |
90 | 90 | |
91 | 91 | .card:hover .card-overlay { |
templates/feed.html
View file @
efc77eb
... | ... | @@ -17,16 +17,17 @@ |
17 | 17 | </a> |
18 | 18 | </div> |
19 | 19 | |
20 | -<form> | |
20 | +<form id="new-card-form"> | |
21 | 21 | <div id="newCard" class="modal bottom-sheet"> |
22 | 22 | <div class="modal-content"> |
23 | 23 | <div class="input-field"> |
24 | - <label id="newCardSign" for="newCard">New Flashcard Text</label> | |
25 | - <input id="new-card-input" class="materialize-textarea" ng-model="text" type="text" maxlength="255"/> | |
24 | + <!--<label id="newCardSign" for="newCard">New Flashcard Text</label>--> | |
25 | + <div id="new-card-input" contenteditable> | |
26 | + | |
27 | + </div> | |
26 | 28 | </div> |
27 | 29 | </div> |
28 | 30 | <div class="modal-footer"> |
29 | - | |
30 | 31 | <button class="btn modal-close" type="submit" ng-click="pushCard()">Submit |
31 | 32 | <i class="mdi-content-send right"></i> |
32 | 33 | </button> |