From 3dabfe79fdd4c5f41e0a8e96c8d483dce1482bd3 Mon Sep 17 00:00:00 2001 From: Curtis SerVaas Date: Sat, 11 Oct 2014 09:50:32 -0400 Subject: [PATCH] More misc improvements. Cursor Logic, Screen Width, consoleLogs--, Heroku Renaming --- config/passport.js | 2 +- lib/MessageQueue.js | 5 +- lib/helperLib.js | 1 + models/Node.js | 1 + public/js/app.js | 165 +------------------- public/js/backbone/router.js | 10 +- public/js/backbone/views/listView.js | 1 + public/js/backbone/views/showView.js | 14 +- public/js/libs/myLogic/KeyboardLogic.js | 143 ------------------ public/js/libs/myLogic/addNode.js | 22 +-- public/js/libs/myLogic/keydownHandler.js | 185 +++++++++++++++++++++++ public/js/libs/myLogic/removeNode.js | 27 +++- views/index.ejs | 2 +- 13 files changed, 246 insertions(+), 332 deletions(-) delete mode 100644 public/js/libs/myLogic/KeyboardLogic.js create mode 100644 public/js/libs/myLogic/keydownHandler.js diff --git a/config/passport.js b/config/passport.js index c1781a8..254d8a9 100644 --- a/config/passport.js +++ b/config/passport.js @@ -5,7 +5,7 @@ var GoogleStrategy = require('passport-google-oauth').OAuth2Strategy; // load up the user model -var User = require('../models/user'); +var User = require('../models/User.js'); // load the auth variables var configAuth = require('./auth'); diff --git a/lib/MessageQueue.js b/lib/MessageQueue.js index a5f4652..9c14e04 100644 --- a/lib/MessageQueue.js +++ b/lib/MessageQueue.js @@ -32,6 +32,7 @@ function executeOperation(operation){ var type = operation[0]; var data = operation[1]; var socket = operation[2]; + // console.log("executeOperation"); switch(type){ case "newNode": @@ -62,8 +63,10 @@ function removeNode(data, socket){ var parId = data[2]; var author = data[3]; // data[3] = null; //improve efficiency. + var curtisId = "53e4079cd7dbc73d16c87c53"; + // console.log("MessageQueue.RemoveNode"); - Node.removeNode(thisId, thisIndex, parId, author._id); + Node.removeNode(thisId, thisIndex, parId, curtisId); } diff --git a/lib/helperLib.js b/lib/helperLib.js index 86ffe18..699c113 100644 --- a/lib/helperLib.js +++ b/lib/helperLib.js @@ -154,6 +154,7 @@ function attachLogInListeners(socket){ socket.on("removeNode", function(data, timestampData){ + console.log("removeNode", data); var queueData = ['removeNode', data, socket]; var emitData = ["removeNode", data]; syncValidation(data, timestampData, queueData, emitData); diff --git a/models/Node.js b/models/Node.js index ced97fe..ef0d19f 100644 --- a/models/Node.js +++ b/models/Node.js @@ -138,6 +138,7 @@ function moveNode(ids, arrays, authorId){ function removeNode(thisId, thisIndex, parId, authorId){ var now = Date.now(); + console.log("removing Node"); MyNode.findById(parId, null, function(err, parNode){ if(err || parNode == null){ diff --git a/public/js/app.js b/public/js/app.js index f449f9a..7cfa7a0 100644 --- a/public/js/app.js +++ b/public/js/app.js @@ -10,6 +10,8 @@ $(function(){ setTimeout(function(){ $(".toggleSidebar").click(); }, 2); + + }); @@ -74,10 +76,11 @@ voInitializer = function(that, event){ vo.hitTab = (event.which ==9); vo.atEnd = ( $(that).getSelection().end == $(that).val().length); vo.atBeg = ( $(that).getSelection().start == 0); + //cursor = $(this).getSelection().start; vo.hitBack = (event.which ==8); vo.empty = ($(that).val().length ==0); - //vo.thisLen = $() + vo.highLighted = !vo.empty && ( $(that).getSelection().end != $(that).getSelection().start ) vo.rootLevel = $(that).closest("ul").is(".root") vo.lastBullet = ( $(that).closest("li").is(":first-child") && vo.rootLevel); @@ -95,17 +98,14 @@ voInitializer = function(that, event){ vo.siblingId = vo.siblingLI.attr("data-id"); vo.siblingModel = nodesCollection.findWhere({_id: vo.siblingId}); - console.log(nodesCollection); - console.log(vo.thisModel); + // console.log(nodesCollection); + // console.log(vo.thisModel); // if(!editing){ // // alert("editing!"); // socket.emit("editing", [vo.thisId, CurrentUser.google.name]); // editing=true; // } - - - if(vo.rootLevel){ vo.parentLI = undefined; @@ -127,6 +127,8 @@ voInitializer = function(that, event){ } vo.grandParentModel = nodesCollection.findWhere({_id: vo.grandParentId}); vo.parentModel = nodesCollection.findWhere({_id: vo.parentId}); + + vo.cursorHack = false; } //(vo-initializer) @@ -137,157 +139,6 @@ voInitializer = function(that, event){ -keydownHandler = function(event){ //the entire body is wrapped in this. - var that = this; - console.log("keyDownHandler"); - // - if(event.which == undefined){ console.log("ABORTED- event.which==undefined"); return; } - if(!CurrentUser){ alert("only logged in users can edit"); return;}//prevent non-logged in users from editing. - - if(!INPUT_PROCESSED){console.log("ABORT- INPUT_PROCESSED=false"); return;}//hitting-enter too quickly causes bugs. Need to make sure nodes have been added. - if(event.which == 13){event.preventDefault();} - - voInitializer(that, event); - console.log("ABOUT TO PROCESS INPUT"); - - INPUT_PROCESSED = false; - - //event.preventDefault(); - //http://stackoverflow.com/questions/20964729/run-keydown-event-handler-after-the-value-of-a-textarea-has-been-changed - //keyupp fixes this, but causes other problems. - if( !(vo.hitTab || vo.hitEnter || (vo.hitBack && vo.empty))){ - //The reason this isn't syncing perfectly between bullets is that... - //... the text-area val hasn't updated at this point. - vo.thisModel.set("text", $(that).val()); - _.each(vo.thisModel.get("views"), function(view){ - view.updateText() - }); - INPUT_PROCESSED = true; - return; - } - - if(vo.hitEnter){ - event.preventDefault(); - - if(event.shiftKey){ - _.each(vo.thisModel.get("views"), function(view){ - view.collapse(); - }); - event.preventDefault(); - alert("Temporarily is used for expand/collapse (instead of clicking)") - } - - if(!event.shiftKey){ - event.preventDefault(); - - if(vo.empty){ - addNode(""); - return; - }//if(empty) - else{//!empty - if(vo.atEnd){ - //alert("CORRECT!") - addNode(""); - return; - }// - if(!vo.atEnd && !vo.atBeg){ //split bullet - var topStr = ''; - var botStr = ''; - splitText(that, botStr, topStr, addNode); - return; - //addNode(botStr, topStr); - } - if(!vo.atEnd && vo.atBeg){//addNode (before). (equivalent to splitting bullet) - var topStr = ''; - var botStr = ''; - splitText(that, botStr, topStr, addNode); - return; - //addNode(botStr, topStr); - } - }//!empty - - } - } //hitEnter - - if(vo.hitBack && vo.empty){ - event.preventDefault(); - removeNode(vo); - return; - }//hitBack. - - // // START ON HIT TAB -// if (vo.hitTab) { - -// event.preventDefault(); - -// if (event.shiftKey) { -// event.preventDefault(); - - -// if (($(this).parent().parent().parent().hasClass("root"))) { -// // do nothing. //alert() //IT USED TO BE ID = 'ROOT' // we use 'root SubList' because it has two classes. -// } -// else { // OUTDENT!! -// var newIndex = $(this).parent().parent().parent().closest("li").index(); -// debugger; -// moveNode(vo.thisModel, vo.thisIndex, vo.parentModel, vo.grandParentModel, newIndex+1, true); -// } -// } -// var hasAboveSibling = (vo.thisIndex != 0); -// if(!event.shiftKey && (hasAboveSibling) ){ -// var newIndex = vo.siblingModel.get("children").length; // no need for a + 1, because 0 index + insert (duh) -// moveNode(vo.thisModel, vo.thisIndex, vo.parentModel, vo.siblingModel, newIndex, true); -// } -// }// END ON HIT TAB -if((vo.hitTab && !event.shiftKey) || (event.keyCode == 39 && event.shiftKey)){ //INDENT - event.preventDefault(); - var hasAboveSibling = (vo.thisIndex != 0); - if(hasAboveSibling){ - var newIndex = vo.siblingModel.get("children").length; // no need for a + 1, because 0 index + insert (duh) - moveNode(vo.thisModel, vo.thisIndex, vo.parentModel, vo.siblingModel, newIndex, true); - setTimeout(function(){ - - }, 100); - } -} -if((vo.hitTab && event.shiftKey) || (event.keyCode == 37 && event.shiftKey)){// OUTDENT!! - if (($(this).parent().parent().parent().hasClass("root"))) { - // do nothing. //alert() //IT USED TO BE ID = 'ROOT' // we use 'root SubList' because it has two classes. - } - else { - - var newSiblingUL = $(this).parent().parent().parent(); - var newIndex = newSiblingUL.closest("li").index(); - moveNode(vo.thisModel, vo.thisIndex, vo.parentModel, vo.grandParentModel, newIndex+1, true); - setTimeout(function(){ //(MoveNode is asynchronous, so you need to wait a little bit.). - newSiblingUL.parent().next().children().children("textarea").focus(); - }, 100); - - - } -} - - if(event.keyCode == 38 && event.shiftKey && !vo.thisLI.is(":first-child")) { - moveNode(vo.thisModel, vo.thisIndex, vo.parentModel, vo.parentModel, vo.thisIndex-1, true); - return; - } - if(event.keyCode == 40 && event.shiftKey && !vo.thisLI.is(":last-child")) { - moveNode(vo.thisModel, vo.thisIndex, vo.parentModel, vo.parentModel, vo.thisIndex+1, true); - return; - } - - - -}//keyboardHandler - - - - - - - - - diff --git a/public/js/backbone/router.js b/public/js/backbone/router.js index c06f8d9..62af0f8 100644 --- a/public/js/backbone/router.js +++ b/public/js/backbone/router.js @@ -26,7 +26,7 @@ var AppRouter = Backbone.Router.extend({ complete: function(){ }, success: function(data){ - console.log("AjaxLoginDATA"); + // console.log("AjaxLoginDATA"); if(typeof data == "string"){ $("textarea").attr("disabled", true); } //User is not logged in. @@ -40,8 +40,8 @@ var AppRouter = Backbone.Router.extend({ data.google.email = null; CurrentUser = data; - console.log("CURRENT USER"); - console.log(CurrentUser); + // console.log("CURRENT USER"); + // console.log(CurrentUser); } }, @@ -98,7 +98,7 @@ setUpSocket: function(){ var that = this; socket.emitWrapper = function(eventName, data){ - console.log(this); + // console.log(this); if(this.socket.connected){ if(eventName=="newNode" || eventName=="movedNode" || eventName=="removeNode"){ var oldTime = CURRENT_TIMESTAMP; @@ -116,7 +116,7 @@ socket.emitWrapper = function(eventName, data){ socket.on('nodeData', function(data, SERVER_TIMESTAMP){ //alert("data"); CURRENT_TIMESTAMP = SERVER_TIMESTAMP; - console.log(data); + // console.log(data); nodesCollection = new NodesCollection(data); var id = nodesCollection.findWhere({text: "0root"}).get("_id"); // if(otherID){ diff --git a/public/js/backbone/views/listView.js b/public/js/backbone/views/listView.js index aa97003..d5ef037 100644 --- a/public/js/backbone/views/listView.js +++ b/public/js/backbone/views/listView.js @@ -103,6 +103,7 @@ var listView = Backbone.View.extend({ that.childViews.insert(index , newView); cur = true; if(cur){ + if(vo.cursorHack){ return newView; } newLI.children().children("textarea").focus(); } else{ diff --git a/public/js/backbone/views/showView.js b/public/js/backbone/views/showView.js index 1c04b2c..0f85f25 100644 --- a/public/js/backbone/views/showView.js +++ b/public/js/backbone/views/showView.js @@ -45,7 +45,7 @@ var showView = Backbone.View.extend({ that.$el.children().children("textarea").prop("disabled", true); that.$el.addClass("snapLI"); } - console.log("about to render textarea") + // console.log("about to render textarea") that.renderChildren(); @@ -73,12 +73,12 @@ var showView = Backbone.View.extend({ alert("bleh"); }, - //Moved to app.js to handle bubbling issues. - // collapse: function(){ - // var that = this; - // that.$el.children("ul").slideToggle(110); - // that.$el.children(".zoomButton").toggleClass("collapsed"); - // }, + // Moved to app.js to handle bubbling issues. + collapse: function(){ + var that = this; + that.$el.children("ul").slideToggle(110); + that.$el.children(".zoomButton").toggleClass("collapsed"); + }, createUIBullet: function( id , text, depth) { var that = this; diff --git a/public/js/libs/myLogic/KeyboardLogic.js b/public/js/libs/myLogic/KeyboardLogic.js deleted file mode 100644 index 5a3607b..0000000 --- a/public/js/libs/myLogic/KeyboardLogic.js +++ /dev/null @@ -1,143 +0,0 @@ -// keydownHandler = function(event){ //the entire body is wrapped in this. -// var that = this; -// console.log("keyDownHandler"); -// // -// if(event.which == undefined){ console.log("ABORTED- event.which==undefined"); return; } -// if(!CurrentUser){ alert("only logged in users can edit"); return;}//prevent non-logged in users from editing. - -// if(!INPUT_PROCESSED){console.log("ABORT- INPUT_PROCESSED=false"); return;}//hitting-enter too quickly causes bugs. Need to make sure nodes have been added. -// if(event.which == 13){event.preventDefault();} - -// voInitializer(that, event); -// console.log("ABOUT TO PROCESS INPUT"); - -// INPUT_PROCESSED = false; - -// //event.preventDefault(); -// //http://stackoverflow.com/questions/20964729/run-keydown-event-handler-after-the-value-of-a-textarea-has-been-changed -// //keyupp fixes this, but causes other problems. -// if( !(vo.hitTab || vo.hitEnter || (vo.hitBack && vo.empty))){ -// //The reason this isn't syncing perfectly between bullets is that... -// //... the text-area val hasn't updated at this point. -// vo.thisModel.set("text", $(that).val()); -// _.each(vo.thisModel.get("views"), function(view){ -// view.updateText() -// }); -// socket.emit("blurred", [id, text, CurrentUser]); -// INPUT_PROCESSED = true; -// return; -// } - -// if(vo.hitEnter){ -// event.preventDefault(); - -// if(event.shiftKey){ -// _.each(vo.thisModel.get("views"), function(view){ -// view.collapse(); -// }); -// event.preventDefault(); -// alert("Temporarily is used for expand/collapse (instead of clicking)") -// } - -// if(!event.shiftKey){ -// event.preventDefault(); - -// if(vo.empty){ -// addNode(""); -// return; -// }//if(empty) -// else{//!empty -// if(vo.atEnd){ -// //alert("CORRECT!") -// addNode(""); -// return; -// }// -// if(!vo.atEnd && !vo.atBeg){ //split bullet -// var topStr = ''; -// var botStr = ''; -// splitText(that, botStr, topStr, addNode); -// return; -// //addNode(botStr, topStr); -// } -// if(!vo.atEnd && vo.atBeg){//addNode (before). (equivalent to splitting bullet) -// var topStr = ''; -// var botStr = ''; -// splitText(that, botStr, topStr, addNode); -// return; -// //addNode(botStr, topStr); -// } -// }//!empty - -// } -// } //hitEnter - -// if(vo.hitBack && vo.empty){ -// event.preventDefault(); -// removeNode(vo); -// return; -// }//hitBack. - -// // // START ON HIT TAB -// // if (vo.hitTab) { - -// // event.preventDefault(); - -// // if (event.shiftKey) { -// // event.preventDefault(); - - -// // if (($(this).parent().parent().parent().hasClass("root"))) { -// // // do nothing. //alert() //IT USED TO BE ID = 'ROOT' // we use 'root SubList' because it has two classes. -// // } -// // else { // OUTDENT!! -// // var newIndex = $(this).parent().parent().parent().closest("li").index(); -// // debugger; -// // moveNode(vo.thisModel, vo.thisIndex, vo.parentModel, vo.grandParentModel, newIndex+1, true); -// // } -// // } -// // var hasAboveSibling = (vo.thisIndex != 0); -// // if(!event.shiftKey && (hasAboveSibling) ){ -// // var newIndex = vo.siblingModel.get("children").length; // no need for a + 1, because 0 index + insert (duh) -// // moveNode(vo.thisModel, vo.thisIndex, vo.parentModel, vo.siblingModel, newIndex, true); -// // } -// // }// END ON HIT TAB -// if((vo.hitTab && !event.shiftKey) || (event.keyCode == 39 && event.shiftKey)){ //INDENT -// event.preventDefault(); -// var hasAboveSibling = (vo.thisIndex != 0); -// if(hasAboveSibling){ -// var newIndex = vo.siblingModel.get("children").length; // no need for a + 1, because 0 index + insert (duh) -// moveNode(vo.thisModel, vo.thisIndex, vo.parentModel, vo.siblingModel, newIndex, true); -// setTimeout(function(){ - -// }, 100); -// } -// } -// if((vo.hitTab && event.shiftKey) || (event.keyCode == 37 && event.shiftKey)){// OUTDENT!! -// if (($(this).parent().parent().parent().hasClass("root"))) { -// // do nothing. //alert() //IT USED TO BE ID = 'ROOT' // we use 'root SubList' because it has two classes. -// } -// else { - -// var newSiblingUL = $(this).parent().parent().parent(); -// var newIndex = newSiblingUL.closest("li").index(); -// moveNode(vo.thisModel, vo.thisIndex, vo.parentModel, vo.grandParentModel, newIndex+1, true); -// setTimeout(function(){ //(MoveNode is asynchronous, so you need to wait a little bit.). -// newSiblingUL.parent().next().children().children("textarea").focus(); -// }, 100); - - -// } -// } - -// if(event.keyCode == 38 && event.shiftKey && !vo.thisLI.is(":first-child")) { -// moveNode(vo.thisModel, vo.thisIndex, vo.parentModel, vo.parentModel, vo.thisIndex-1, true); -// return; -// } -// if(event.keyCode == 40 && event.shiftKey && !vo.thisLI.is(":last-child")) { -// moveNode(vo.thisModel, vo.thisIndex, vo.parentModel, vo.parentModel, vo.thisIndex+1, true); -// return; -// } - - - -// } \ No newline at end of file diff --git a/public/js/libs/myLogic/addNode.js b/public/js/libs/myLogic/addNode.js index 0293562..4f589a3 100644 --- a/public/js/libs/myLogic/addNode.js +++ b/public/js/libs/myLogic/addNode.js @@ -16,7 +16,7 @@ addNode = function(botStr, topStr){ }; - if(topStr){ + if(topStr || topStr==""){ console.log("TOPSTR IS"); console.log(topStr); vo.thisModel.set("text", topStr); @@ -42,19 +42,24 @@ addNode = function(botStr, topStr){ _.each(parentViews, function(parentView){ parentView.addNode(newNode, tempIndex, true); }); - vo.thisLI.next().children().children("textarea").focus(); + // vo.thisLI.next().children().children("textarea").focus(); INPUT_PROCESSED=true; console.log("FINISHED- ADD NODE") -} -//topStr is to the left. (also, the bottom part will be to the right. ) -splitText = function(that, botStr, topStr, callback){ +} +/* +topStr is to the left. (also, the bottom part will be to the right. ) +before: Textarea= topStr + botStr +after: +-T1: TopStr +-T2: BotStr +*/ +splitText = function(that, callback){ + var topStr = ''; var botStr=''; var cur = $(that).getSelection().start; var cur1 = cur; var len = $(that).val().length; var bigStr = $(that).val(); - // var botStr = ''; - // var topStr = ''; var x =0; //this is the first half of the string. @@ -68,8 +73,7 @@ splitText = function(that, botStr, topStr, callback){ botStr += bigStr[cur]; cur++; } - - callback(botStr, topStr); //addNode(); + callback(botStr, topStr); //addNode(botStr, topStr); } transclude = function(){ diff --git a/public/js/libs/myLogic/keydownHandler.js b/public/js/libs/myLogic/keydownHandler.js new file mode 100644 index 0000000..88dd49f --- /dev/null +++ b/public/js/libs/myLogic/keydownHandler.js @@ -0,0 +1,185 @@ +keydownHandler = function(event){ //the entire body is wrapped in this. + var that = this; + // console.log("keyDownHandler"); + INPUT_PROCESSED=true; + + if(event.which == undefined){ console.log("ABORTED- event.which==undefined"); return; } + if(!CurrentUser){ alert("only logged in users can edit"); return;}//prevent non-logged in users from editing. + + if(!INPUT_PROCESSED){console.log("ABORT- INPUT_PROCESSED=false"); return;}//hitting-enter too quickly causes bugs. Need to make sure nodes have been added. + if(event.which == 13){event.preventDefault();} + + voInitializer(that, event); + console.log("ABOUT TO PROCESS INPUT"); + + /* + // INPUT_PROCESSED = false; + I was having trouble figuring out all the places I needed to set it back to true, SO, + I just got rid of this constraint. It actually seems to work just fine. + */ + + //event.preventDefault(); + //http://stackoverflow.com/questions/20964729/run-keydown-event-handler-after-the-value-of-a-textarea-has-been-changed + //keyupp fixes this, but causes other problems. + var moveOperation = (vo.hitTab || vo.hitEnter || (vo.hitBack && vo.atBeg && !vo.highLighted)); + var arrowOperation = (event.keyCode <= 40 && event.keyCode >= 37) + if( !(moveOperation || arrowOperation) ){ + //The reason this isn't syncing perfectly between bullets is that... + //... the text-area val hasn't updated at this point. + vo.thisModel.set("text", $(that).val()); + _.each(vo.thisModel.get("views"), function(view){ + view.updateText() + }); + INPUT_PROCESSED = true; + return; + } + + if(vo.hitEnter){ + event.preventDefault(); + + if(event.shiftKey){ //(expand/collapse) + _.each(vo.thisModel.get("views"), function(view){ + view.collapse(); + }); + event.preventDefault(); + INPUT_PROCESSED=true; + return; + } + + if(!event.shiftKey){ + event.preventDefault(); + + if(vo.empty){ + addNode(""); + return; + }//if(empty) + + else{//!empty + if(vo.atEnd){ + addNode(""); + return; + }// + if(!vo.atEnd && !vo.atBeg){ //split bullet(Works correctly) + // var topStr = ''; + // var botStr = ''; + splitText(that, /*botStr, topStr,*/ addNode); + return; + //addNode(botStr, topStr); + } + if(!vo.atEnd && vo.atBeg){//addNode (before). (equivalent to splitting bullet) + vo.thisIndex--; //a hack that works. + //var myLI = vo.thisLI; + // setTimeout(function(){myLI.children().children("textarea").focus()}, 3); + vo.cursorHack=true; + addNode(""); + + return; + } + }//!empty + + } + } //hitEnter + + if(vo.hitBack && vo.empty){ + if(vo.thisModel.get('children').length != 0){INPUT_PROCESSED=true; return;} + event.preventDefault(); + removeNode(vo); + return; + }//hitBack. + if(vo.hitBack && vo.atBeg && !vo.highLighted){ + event.preventDefault(); + if(vo.siblingModel.get("text")==""){ + if(vo.siblingModel.get('children').length != 0){INPUT_PROCESSED=true; return;} + var tempVo = {}; + tempVo.thisId = vo.siblingModel.get("_id"); + tempVo.thisIndex = vo.thisIndex-1; + tempVo.thisModel = vo.siblingModel; + tempVo.thisLI = vo.siblingLI; + tempVo.parentModel = vo.parentModel; + tempVo.parentId = vo.parentId; + tempVo.cursorHack = true; + removeNode(tempVo); + } + + } + + // // START ON HIT TAB +// if (vo.hitTab) { + +// event.preventDefault(); + +// if (event.shiftKey) { +// event.preventDefault(); + + +// if (($(this).parent().parent().parent().hasClass("root"))) { +// // do nothing. //alert() //IT USED TO BE ID = 'ROOT' // we use 'root SubList' because it has two classes. +// } +// else { // OUTDENT!! +// var newIndex = $(this).parent().parent().parent().closest("li").index(); +// debugger; +// moveNode(vo.thisModel, vo.thisIndex, vo.parentModel, vo.grandParentModel, newIndex+1, true); +// } +// } +// var hasAboveSibling = (vo.thisIndex != 0); +// if(!event.shiftKey && (hasAboveSibling) ){ +// var newIndex = vo.siblingModel.get("children").length; // no need for a + 1, because 0 index + insert (duh) +// moveNode(vo.thisModel, vo.thisIndex, vo.parentModel, vo.siblingModel, newIndex, true); +// } +// }// END ON HIT TAB +if((vo.hitTab && !event.shiftKey) || (event.keyCode == 39 && event.shiftKey)){ //INDENT + event.preventDefault(); + var hasAboveSibling = (vo.thisIndex != 0); + if(hasAboveSibling){ + var newIndex = vo.siblingModel.get("children").length; // no need for a + 1, because 0 index + insert (duh) + moveNode(vo.thisModel, vo.thisIndex, vo.parentModel, vo.siblingModel, newIndex, true); + setTimeout(function(){ + + }, 100); + } +} +if((vo.hitTab && event.shiftKey) || (event.keyCode == 37 && event.shiftKey)){// OUTDENT!! + if (($(this).parent().parent().parent().hasClass("root"))) { + // do nothing. //alert() //IT USED TO BE ID = 'ROOT' // we use 'root SubList' because it has two classes. + } + else { + + var newSiblingUL = $(this).parent().parent().parent(); + var newIndex = newSiblingUL.closest("li").index(); + moveNode(vo.thisModel, vo.thisIndex, vo.parentModel, vo.grandParentModel, newIndex+1, true); + setTimeout(function(){ //(MoveNode is asynchronous, so you need to wait a little bit.). + newSiblingUL.parent().next().children().children("textarea").focus(); + }, 100); + + + } +} + + if(event.keyCode == 38 && event.shiftKey) { + if(vo.thisLI.is(":first-child")){return;}//don't factor this out into the above if-statement + moveNode(vo.thisModel, vo.thisIndex, vo.parentModel, vo.parentModel, vo.thisIndex-1, true); + return; + } + if(event.keyCode == 40 && event.shiftKey) { + if(vo.thisLI.is(":last-child")){return;} + moveNode(vo.thisModel, vo.thisIndex, vo.parentModel, vo.parentModel, vo.thisIndex+1, true); + return; + } + + if(event.keyCode == 38){//up + if(vo.thisLI.is(":first-child")){ + vo.thisLI.parent().parent().children().children("textarea").focus(); + } + else{ + vo.thisLI.prev().children().children("textarea").focus(); + } + } + if(event.keyCode == 40){ + vo.thisLI.next().children().children("textarea").focus(); + } + + // if(event.keyCode) + + + +}//keyboardHandler \ No newline at end of file diff --git a/public/js/libs/myLogic/removeNode.js b/public/js/libs/myLogic/removeNode.js index 08a603e..042b7ad 100644 --- a/public/js/libs/myLogic/removeNode.js +++ b/public/js/libs/myLogic/removeNode.js @@ -1,4 +1,5 @@ var removeNode = function(vo, broadcast) { + // debugger; upDateParentModelViews(vo, broadcast); //#TODO => This won't work for transcluded nodes with the same parent... if( hasDuplicates(vo.thisModel.get("parents"))){ //later. @@ -25,15 +26,25 @@ var upDateParentModelViews = function(vo, broadcast){ if(!broadcast){ //broadCast=true means we received this update from somebody else. //UI STUFF - console.log("what"); - if( !vo.thisLI.is(":first-child") ){ - var len = vo.thisLI.prev().children().children("textarea").val().length; - vo.thisLI.prev().children().children("textarea").focus(); - vo.thisLI.prev().children().children("textarea").setSelection(len, len); + // console.log("what"); + if( vo.thisLI.is(":first-child") ){ + if(vo.thisLI.attr('data-depth')!=0){ + var len = vo.thisLI.parent().parent().children().children("textarea").val().length; + vo.thisLI.parent().parent().children().children("textarea").focus(); + vo.thisLI.parent().parent().children().children("textarea").setSelection(len, len); + } + else{ + vo.thisLI.next().children().children('textarea').focus(); + } }else{ - var len = vo.thisLI.parent().parent().children().children("textarea").val().length; - vo.thisLI.parent().parent().children().children("textarea").focus(); - vo.thisLI.parent().parent().children().children("textarea").setSelection(len, len); + if(!vo.cursorHack){ + var len = vo.thisLI.prev().children().children("textarea").val().length; + vo.thisLI.prev().children().children("textarea").focus(); + vo.thisLI.prev().children().children("textarea").setSelection(len, len); + } + else{ + vo.thisLI.next().children().children('textarea').focus(); + } } } diff --git a/views/index.ejs b/views/index.ejs index 1204c9c..7140cdf 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -26,7 +26,7 @@ - +