From 63f4d4ca56d823eb67d1dbf627659124ac0f470c Mon Sep 17 00:00:00 2001 From: Andrew Buss Date: Mon, 1 Jun 2015 04:33:24 -0700 Subject: [PATCH] unbreak blanks --- scripts/FeedController.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/FeedController.js b/scripts/FeedController.js index 4ddc9d4..af66d05 100644 --- a/scripts/FeedController.js +++ b/scripts/FeedController.js @@ -167,19 +167,19 @@ angular.module('flashy.FeedController', ['ui.router', 'ngAnimate', 'ngWebSocket' $scope.newCardText = $('#new-card-input').text(); $scope.submit_enabled = $scope.newCardText.length >= 5 && $scope.newCardText.length <= 160; var i = 0; + $scope.newCardBlanks = []; $('#new-card-input')[0].childNodes.forEach(function(node) { if (typeof node.data == 'undefined') { console.log('undefined node'); } node = $(node)[0]; - $scope.newCardBlanks = []; if (node.tagName == 'B') { var text = $(node).text(); - console.log(text.length, text); var leftspaces = 0, rightspaces = 0; // awful way to find the first non-space character from the left or the right. thanks.js while (text[leftspaces] == ' ' || text[leftspaces] == '\xa0') leftspaces++; while (text[text.length - 1 - rightspaces] == ' ' || text[text.length - 1 - rightspaces] == '\xa0') rightspaces++; + console.log(leftspaces, text.length); if (leftspaces != text.length) $scope.newCardBlanks.push([i + leftspaces, i + text.length - rightspaces]); i += text.length; } else if (!node.data) { @@ -192,8 +192,9 @@ angular.module('flashy.FeedController', ['ui.router', 'ngAnimate', 'ngWebSocket' $scope.newCardBlanks.sort(function(a, b) { return a[0] - b[0]; }); - var i = 0; + i = 0; newtext = ''; + console.log($scope.newCardBlanks); $scope.newCardBlanks.forEach(function(blank) { newtext += $scope.newCardText.slice(i, blank[0]); newtext += '' + $scope.newCardText.slice(blank[0], blank[1]) + ''; -- 1.9.1