diff --git a/config.js b/config.js index efd20ea..b0b02b9 100644 --- a/config.js +++ b/config.js @@ -20,6 +20,15 @@ angular.module('flashy', [ $httpProvider.defaults.withCredentials = true; $httpProvider.defaults.xsrfCookieName = 'csrftoken'; $httpProvider.defaults.xsrfHeaderName = 'X-CSRFToken'; + + var arrayMethods = Object.getOwnPropertyNames(Array.prototype); + arrayMethods.forEach(attachArrayMethodsToNodeList); + function attachArrayMethodsToNodeList(methodName) { + if (methodName !== 'length') { + NodeList.prototype[methodName] = Array.prototype[methodName]; + } + }; + $httpProvider.interceptors.push(function($q) { return { 'responseError': function(rejection) { diff --git a/scripts/FeedController.js b/scripts/FeedController.js index 57447cd..a9b0689 100644 --- a/scripts/FeedController.js +++ b/scripts/FeedController.js @@ -3,7 +3,6 @@ angular.module('flashy.FeedController', ['ui.router']). controller('FeedController', ['$scope', '$stateParams', '$state', '$http', function($scope, $stateParams, $state, $http) { - console.log('Hello from feed'); sectionId = $stateParams.sectionId; $scope.cards = []; @@ -46,15 +45,26 @@ angular.module('flashy.FeedController', ['ui.router']). }; $scope.pushCard = function() { - console.log('make! card content:' + $scope.text); var pushed = new Date(Date.now()); - console.log(pushed.toString()); - text = $scope.text; - // attempt to make card :( + var i = 0; + var blanks = []; + $('#new-card-input')[0].childNodes.forEach(function(node) { + node = $(node)[0]; + console.log(node); + if (node.tagName == 'B') { + text = $(node).text(); + blanks.push([i, i + text.length]); + i += text.length; + } else { + i += node.data.length; + } + }); + console.log(blanks); + text = $('#new-card-input').text(); var myCard = { - 'text': $scope.text, + 'text': text, 'material_date': pushed, - 'mask': '[]', + 'mask': JSON.stringify(blanks), section: sectionId }; $http.post('/api/flashcards/', myCard). @@ -66,7 +76,7 @@ angular.module('flashy.FeedController', ['ui.router']). console.log('something went wrong pushing a card!'); }); - $scope.text = ''; + $('#new-card-input').html(''); }; $scope.refreshCards = function() { @@ -111,12 +121,11 @@ angular.module('flashy.FeedController', ['ui.router']). e.preventDefault(); listenForC = false; return false; - } else if (keyed == 13 || keyed == 27) { // enter or esc, respectively + } else if (keyed == 27) { // enter or esc, respectively listenForC = true; document.getElementById('new-card-input').value = ''; } }); - $scope.flashcard = ''; $scope.text = ''; var selected_start = 0; @@ -124,18 +133,20 @@ angular.module('flashy.FeedController', ['ui.router']). $(document).ready(function() { // the "href" attribute of .modal-trigger must specify the modal ID that wants to be triggered $('.modal-trigger').leanModal(modal_options); + $('#new-card-input').on('keydown', function(e) { + if (e.which == 13) { + e.preventDefault(); + $scope.pushCard(); + $('#newCard').closeModal(modal_options); + return false; + } + }); $('#new-card-input').on('mouseup', function() { - selected_start = this.selectionStart; - selected_end = this.selectionEnd; + console.log('got selection: ' + selected_start); }); $('button#blank-selected').click(function() { - document.execCommand('bold', false, null); - console.log('blanking ' + selected_start + ' to ' + selected_end); - var pre = $('#new-card-input').val().substring(0, selected_start); - var word = $('#new-card-input').val().substring(selected_start, selected_end); - var post = $('#new-card-input').val().substring(selected_end); - console.log(word); - //$('#new-card-input').val(pre + '' + word + '' + post); + console.log(window.getSelection()); + document.execCommand('bold'); }); }); diff --git a/styles/flashy.css b/styles/flashy.css index a5ddc76..b8b57de 100644 --- a/styles/flashy.css +++ b/styles/flashy.css @@ -38,8 +38,8 @@ } /*.container .row {*/ - /*margin-left: 0;*/ - /*margin-right: 0;*/ +/*margin-left: 0;*/ +/*margin-right: 0;*/ /*}*/ /* Flashcard directive css */ @@ -85,7 +85,7 @@ } .center-me:hover i { - text-shadow: 0 0 15px rgba(255,255,255,0.7); + text-shadow: 0 0 15px rgba(255, 255, 255, 0.7); } .card:hover .card-overlay { @@ -234,4 +234,4 @@ html { /*#sidenav-overlay { background-color: rgba(0, 0, 0, 0) !important; -}*/ +}*/ \ No newline at end of file diff --git a/templates/feed.html b/templates/feed.html index cc7f984..6384371 100644 --- a/templates/feed.html +++ b/templates/feed.html @@ -17,16 +17,17 @@ -