mirror of
https://github.com/wassname/HackFlowy.git
synced 2026-07-17 11:23:36 +08:00
143 lines
4.9 KiB
JavaScript
143 lines
4.9 KiB
JavaScript
// 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;
|
|
// }
|
|
|
|
|
|
|
|
// }
|