From da401512a192023aebbec40fbadede5871edc39f Mon Sep 17 00:00:00 2001 From: Sean Date: Sat, 15 Oct 2016 22:05:31 -0700 Subject: [PATCH 1/5] Update concord.js Added ability to prototype how list items are created. Added keyup listener so that finished text is able to be sent to service if needed. --- concord.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/concord.js b/concord.js index b931be5..0662073 100644 --- a/concord.js +++ b/concord.js @@ -677,6 +677,12 @@ function ConcordEditor(root, concordInstance) { level = 1; } var node = $("
  • "); + + // allow outside callback function to manipulate dom + if (this.createNodeFromOutlineItem) { + node = this.createNodeFromOutlineItem($(outline[0].attributes)); + } + node.addClass("concord-node"); node.addClass("concord-level-"+level); var attributes = {}; @@ -2728,6 +2734,19 @@ function Op(opmltext){ $.fn.concord = function(options) { return new ConcordOutline($(this), options); }; + + // signal key up on node text + $(document).on("keyup", function(event) { + var focusRoot = concord.getFocusRoot(); + if(focusRoot==null){ + return; + } + var context = focusRoot; + var concordInstance = new ConcordOutline(context.parent()); + concordInstance.fireCallback("opKeyUp", event); + }); + + $(document).on("keydown", function(event) { if(!concord.handleEvents){ return; From c6efc62b445449eb74e50950de27908a15c167af Mon Sep 17 00:00:00 2001 From: Sean Date: Sat, 15 Oct 2016 22:27:59 -0700 Subject: [PATCH 2/5] Update concord.js added more callbacks to handle demoting and promoting --- concord.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/concord.js b/concord.js index 0662073..8192c42 100644 --- a/concord.js +++ b/concord.js @@ -1548,6 +1548,7 @@ function ConcordOp(root, concordInstance, _cursor) { }); concordInstance.editor.recalculateLevels(node.find(".concord-node")); this.markChanged(); + } }; this.expand = function(triggerCallbacks) { @@ -2147,6 +2148,7 @@ function ConcordOp(root, concordInstance, _cursor) { clonedMove.insertAfter(parent); concordInstance.editor.recalculateLevels(parent.nextAll(".concord-node")); ableToMoveInDirection = true; + concordInstance.fireCallback("opDemote", clonedMove); } break; case right: @@ -2179,6 +2181,7 @@ function ConcordOp(root, concordInstance, _cursor) { prev.removeClass("collapsed"); concordInstance.editor.recalculateLevels(prev.find(".concord-node")); ableToMoveInDirection = true; + concordInstance.fireCallback("opPromote", clonedMove); } break; } From 3f2131a8a0c3393d77c35c49aaee7e21eb7ed83b Mon Sep 17 00:00:00 2001 From: Sean Date: Mon, 17 Oct 2016 15:42:09 -0700 Subject: [PATCH 3/5] Update concord.js More callback triggers and a true working "Expand all" --- concord.js | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/concord.js b/concord.js index 8192c42..e3b0234 100644 --- a/concord.js +++ b/concord.js @@ -1465,6 +1465,7 @@ function ConcordOp(root, concordInstance, _cursor) { } }; this.deleteLine = function() { + this.saveState(); if(this.inTextMode()){ var cursor = this.getCursor(); @@ -1472,6 +1473,7 @@ function ConcordOp(root, concordInstance, _cursor) { if(p.length==0){ p = cursor.parents(".concord-node:first"); } + cursor.remove(); if(p.length==1) { this.setCursor(p); @@ -1484,6 +1486,21 @@ function ConcordOp(root, concordInstance, _cursor) { } }else{ var selected = root.find(".selected"); + + // get attributes for each element + // since they may not be referencable once deleted + var nodeAttribues = [] + selected.each(function(){ + var attribs = {} + for (var i = 0; i < this.attributes.length; i++) { + var attrib = this.attributes[i]; + attribs[attrib.name] = attrib.value; + } + nodeAttribues.push(attribs); + }); + + concordInstance.fireCallback("opDeleteLine", nodeAttribues); + if(selected.length == 1) { var p = selected.prev(); if(p.length==0){ @@ -1523,6 +1540,7 @@ function ConcordOp(root, concordInstance, _cursor) { var node = this.insert("", down); this.setCursor(node); } + this.markChanged(); }; this.deleteSubs = function() { @@ -1536,6 +1554,7 @@ function ConcordOp(root, concordInstance, _cursor) { this.markChanged(); }; this.demote = function() { + console.log("Demote was called.", 1539); var node = this.getCursor(); var movedSiblings = false; if(node.nextAll().length>0){ @@ -1584,11 +1603,13 @@ function ConcordOp(root, concordInstance, _cursor) { } }; this.expandAllLevels = function() { - var node = this.getCursor(); - if(node.length == 1) { - node.removeClass("collapsed"); - node.find(".concord-node").removeClass("collapsed"); - } + root.find(".concord-node").removeClass("collapsed"); + // if expand all levels then why are you only expanding based on cursor? + // var node = this.getCursor(); + // if(node.length == 1) { + // node.removeClass("collapsed"); + // node.find(".concord-node").removeClass("collapsed"); + // } }; this.focusCursor = function(){ this.getCursor().children(".concord-wrapper").children(".concord-text").focus(); @@ -2746,6 +2767,9 @@ function Op(opmltext){ } var context = focusRoot; var concordInstance = new ConcordOutline(context.parent()); + if ( !((event.which>=37) && (event.which <=40)) && !(event.which == 9 || event.which == 16) ){ + concordInstance.fireCallback("opTextChange", event); + } concordInstance.fireCallback("opKeyUp", event); }); From 73ea03b225eb8789af50f03406ce098fe91bd196 Mon Sep 17 00:00:00 2001 From: Sean Date: Tue, 18 Oct 2016 11:29:56 -0700 Subject: [PATCH 4/5] listeners should not listen to entire doc Concord listeners should only listen to selected concord outline and not entire doc --- concord.js | 54 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/concord.js b/concord.js index e3b0234..1b9b572 100644 --- a/concord.js +++ b/concord.js @@ -2754,27 +2754,33 @@ function Op(opmltext){ fakeDom.concord().op.xmlToOutline(opmltext); return fakeDom.concord().op; } + +/************************ +* +* LISTENERS +* +*******************/ + (function($) { $.fn.concord = function(options) { - return new ConcordOutline($(this), options); - }; - - // signal key up on node text - $(document).on("keyup", function(event) { - var focusRoot = concord.getFocusRoot(); - if(focusRoot==null){ - return; + + + // signal key up on node text + $(this).on("keyup", ".concord-node",function(event) { + var focusRoot = concord.getFocusRoot(); + if(focusRoot==null){ + return; + } + var context = focusRoot; + var concordInstance = new ConcordOutline(context.parent()); + if ( !((event.which>=37) && (event.which <=40)) && !(event.which == 9 || event.which == 16) ){ + concordInstance.fireCallback("opTextChange", event); } - var context = focusRoot; - var concordInstance = new ConcordOutline(context.parent()); - if ( !((event.which>=37) && (event.which <=40)) && !(event.which == 9 || event.which == 16) ){ - concordInstance.fireCallback("opTextChange", event); - } - concordInstance.fireCallback("opKeyUp", event); - }); - + concordInstance.fireCallback("opKeyUp", event); + }); - $(document).on("keydown", function(event) { + $(this).on("keydown", function(event) { + if(!concord.handleEvents){ return; } @@ -3154,7 +3160,7 @@ function Op(opmltext){ } } }); - $(document).on("mouseup", function(event) { + $(this).on("mouseup", function(event) { if(!concord.handleEvents){ return; } @@ -3174,21 +3180,25 @@ function Op(opmltext){ var focusRoot = concord.getFocusRoot(); } }); - $(document).on("click", concord.updateFocusRootEvent); - $(document).on("dblclick", concord.updateFocusRootEvent); - $(document).on('show', function(e){ + $(this).on("click", concord.updateFocusRootEvent); + $(this).on("dblclick", concord.updateFocusRootEvent); + $(this).on('show', function(e){ if($(e.target).is(".modal")){ if($(e.target).attr("concord-events") != "true"){ concord.stopListening(); } } }); - $(document).on('hidden', function(e){ + $(this).on('hidden', function(e){ if($(e.target).is(".modal")){ if($(e.target).attr("concord-events") != "true"){ concord.resumeListening(); } } }); + + return new ConcordOutline($(this), options); + }; // should be part of init function + concord.ready=true; })(jQuery); From cf9f905a4e4095fae3eeb285faeb2da388048b99 Mon Sep 17 00:00:00 2001 From: Sean Date: Mon, 24 Oct 2016 17:09:52 -0700 Subject: [PATCH 5/5] Reverse some changes and add backspace function So it turns out some listeners need to listen to the whole document. Switched these back. Also, not being able to backspace out of text mode into selection mode so that a keystroke can delete was annoying. Fixes that too. --- concord.js | 72 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 48 insertions(+), 24 deletions(-) diff --git a/concord.js b/concord.js index 1b9b572..38ab6b0 100644 --- a/concord.js +++ b/concord.js @@ -548,19 +548,31 @@ function ConcordEditor(root, concordInstance) { } var subheads; + if (!flsubsonly) { //8/5/13 by DW opml += '")){ event.preventDefault(); @@ -2826,6 +2840,15 @@ function Op(opmltext){ concordInstance.op.saveState(); concordInstance.op.getCursor().addClass("dirty"); } + + // if user is backspacing in an empty node + // switch to select mode so they may use backspace again + // to delete the node + if (concordInstance.op.getLineText() == "") { + + concordInstance.op.setTextMode(false) + } + }else{ keyCaptured = true; event.preventDefault(); @@ -2884,11 +2907,12 @@ function Op(opmltext){ break; case 82: //CMD+R - if(commandKey) { - keyCaptured = true; - event.preventDefault(); - concordInstance.op.reorg(right); - } + //this ruins refresh on most browsers + // if(commandKey) { + // keyCaptured = true; + // event.preventDefault(); + // concordInstance.op.reorg(right); + // } break; case 219: //CMD+[ @@ -3160,7 +3184,7 @@ function Op(opmltext){ } } }); - $(this).on("mouseup", function(event) { + $(document).on("mouseup", function(event) { if(!concord.handleEvents){ return; } @@ -3180,25 +3204,25 @@ function Op(opmltext){ var focusRoot = concord.getFocusRoot(); } }); - $(this).on("click", concord.updateFocusRootEvent); - $(this).on("dblclick", concord.updateFocusRootEvent); - $(this).on('show', function(e){ + $(document).on("click", concord.updateFocusRootEvent); + $(document).on("dblclick", concord.updateFocusRootEvent); + $(document).on('show', function(e){ if($(e.target).is(".modal")){ if($(e.target).attr("concord-events") != "true"){ concord.stopListening(); } } }); - $(this).on('hidden', function(e){ + $(document).on('hidden', function(e){ if($(e.target).is(".modal")){ if($(e.target).attr("concord-events") != "true"){ concord.resumeListening(); } } }); + + - return new ConcordOutline($(this), options); - }; // should be part of init function concord.ready=true; })(jQuery);