mirror of
https://github.com/wassname/HackFlowy.git
synced 2026-06-27 16:00:04 +08:00
More misc improvements. Cursor Logic, Screen Width, consoleLogs--, Heroku Renaming
This commit is contained in:
+1
-1
@@ -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');
|
||||
|
||||
+4
-1
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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){
|
||||
|
||||
+8
-157
@@ -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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -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){
|
||||
|
||||
@@ -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{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// }
|
||||
@@ -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(){
|
||||
|
||||
@@ -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
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@
|
||||
<script src="socket.io/socket.io.js"></script>
|
||||
<script src="js/libs/myLogic/addNode.js"></script>
|
||||
<script src="js/libs/myLogic/removeNode.js"></script>
|
||||
<script src="js/libs/myLogic/KeyBoardLogic.js"></script>
|
||||
<script src="js/libs/myLogic/keydownHandler.js"></script>
|
||||
<script src="js/libs/myLogic/moveNode.js"></script>
|
||||
<script src="js/libs/myLogic/revControl.js"></script>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user