From c3d62c5fa444b899a7699fefdebe01cf95a7f64c Mon Sep 17 00:00:00 2001 From: John McLear Date: Tue, 4 Mar 2014 23:14:15 +0000 Subject: [PATCH 1/4] preprocessor for domline attributes --- src/static/js/domline.js | 50 +++++++++++++++++++++++++++++----------- 1 file changed, 36 insertions(+), 14 deletions(-) diff --git a/src/static/js/domline.js b/src/static/js/domline.js index 69508507a..a7aaea0d7 100644 --- a/src/static/js/domline.js +++ b/src/static/js/domline.js @@ -101,6 +101,17 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument) { var listType = /(?:^| )list:(\S+)/.exec(cls); var start = /(?:^| )start:(\S+)/.exec(cls); + + _.map(hooks.callAll("aceDomLinePreProcessLineAttributes", { + domline: domline, + cls: cls + }), function(modifier) + { + preHtml += modifier.preHtml; + postHtml += modifier.postHtml; + processedMarker |= modifier.processedMarker; + }); + if (listType) { listType = listType[1]; @@ -108,8 +119,13 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument) { if(listType.indexOf("number") < 0) { - preHtml = ''; + if(!preHtml){ + preHtml = ''; + }else{ + preHtml += '' + postHtml; + } } else { @@ -117,16 +133,27 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument) if(start[1] == 1){ // if its the first one at this level? lineClass = lineClass + " " + "list-start-" + listType; // Add start class to DIV node } - preHtml = '
  1. '; + if(!preHtml){ + preHtml = '
    1. '; + }else{ + preHtml += '
      1. '; + } }else{ - preHtml = '
        1. '; // Handles pasted contents into existing lists + if(!preHtml){ + preHtml = '
          1. '; // Handles pasted contents into existing lists + }else{ + preHtml += '
            1. '; // Handles pasted contents into existing lists + } + } + if(!postHtml){ + postHtml = '
            '; + }else{ + postHtml = '
          '; } - postHtml = '
        '; } } processedMarker = true; } - _.map(hooks.callAll("aceDomLineProcessLineAttributes", { domline: domline, cls: cls @@ -136,13 +163,10 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument) postHtml += modifier.postHtml; processedMarker |= modifier.processedMarker; }); - if( processedMarker ){ result.lineMarker += txt.length; return; // don't append any text } - - } var href = null; var simpleTags = null; @@ -234,10 +258,9 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument) result.node.innerHTML = curHTML; } if (lineClass !== null) result.node.className = lineClass; - - hooks.callAll("acePostWriteDomLineHTML", { - node: result.node - }); + hooks.callAll("acePostWriteDomLineHTML", { + node: result.node + }); } result.prepareForAdd = writeHTML; result.finishUpdate = writeHTML; @@ -245,7 +268,6 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument) { return curHTML || ''; }; - return result; }; From 432438a40d29eab906a23909ee0294dc9016d1f2 Mon Sep 17 00:00:00 2001 From: John McLear Date: Tue, 4 Mar 2014 23:36:16 +0000 Subject: [PATCH 2/4] fix dintenation --- src/static/js/domline.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/static/js/domline.js b/src/static/js/domline.js index a7aaea0d7..21b6ff333 100644 --- a/src/static/js/domline.js +++ b/src/static/js/domline.js @@ -260,7 +260,7 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument) if (lineClass !== null) result.node.className = lineClass; hooks.callAll("acePostWriteDomLineHTML", { node: result.node - }); + }); } result.prepareForAdd = writeHTML; result.finishUpdate = writeHTML; From df205a4ef47554aae97f24c1f08084f50ad5156e Mon Sep 17 00:00:00 2001 From: John McLear Date: Wed, 5 Mar 2014 21:44:22 +0000 Subject: [PATCH 3/4] docs --- doc/api/hooks_client-side.md | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/doc/api/hooks_client-side.md b/doc/api/hooks_client-side.md index c0a4227a4..b8a58b316 100644 --- a/doc/api/hooks_client-side.md +++ b/doc/api/hooks_client-side.md @@ -10,6 +10,22 @@ nothing This hook proxies the functionality of jQuery's `$(document).ready` event. +## aceDomLinePreProcessLineAttributes +Called from: src/static/js/domline.js + +Things in context: + +1. domline - The current DOM line being processed +2. cls - The class of the current block element (useful for styling) + +This hook is called for elements in the DOM that have the "lineMarkerAttribute" set. You can add elements into this category with the aceRegisterBlockElements hook above. This hook is run BEFORE the numbered and ordered lists logic is applied. + +The return value of this hook should have the following structure: + +`{ preHtml: String, postHtml: String, processedMarker: Boolean }` + +The preHtml and postHtml values will be added to the HTML display of the element, and if processedMarker is true, the engine won't try to process it any more. + ## aceDomLineProcessLineAttributes Called from: src/static/js/domline.js @@ -18,7 +34,7 @@ Things in context: 1. domline - The current DOM line being processed 2. cls - The class of the current block element (useful for styling) -This hook is called for elements in the DOM that have the "lineMarkerAttribute" set. You can add elements into this category with the aceRegisterBlockElements hook above. +This hook is called for elements in the DOM that have the "lineMarkerAttribute" set. You can add elements into this category with the aceRegisterBlockElements hook above. This hook is run AFTER the ordered and numbered lists logic is applied. The return value of this hook should have the following structure: From f5716a3b2600a34623901952d825dfeaa1621691 Mon Sep 17 00:00:00 2001 From: John McLear Date: Wed, 5 Mar 2014 21:44:32 +0000 Subject: [PATCH 4/4] cleaner logic --- src/static/js/domline.js | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/src/static/js/domline.js b/src/static/js/domline.js index 8756a285c..b1927b162 100644 --- a/src/static/js/domline.js +++ b/src/static/js/domline.js @@ -119,13 +119,8 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument) { if(listType.indexOf("number") < 0) { - if(!preHtml){ - preHtml = '
        • '; - postHtml = '
        '; - }else{ - preHtml += '
        • '; - postHtml = '
        ' + postHtml; - } + preHtml += '
        • '; + postHtml = '
        ' + postHtml; } else { @@ -133,23 +128,11 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument) if(start[1] == 1){ // if its the first one at this level? lineClass = lineClass + " " + "list-start-" + listType; // Add start class to DIV node } - if(!preHtml){ - preHtml = '
        1. '; - }else{ - preHtml += '
          1. '; - } + preHtml += '
            1. '; }else{ - if(!preHtml){ - preHtml = '
              1. '; // Handles pasted contents into existing lists - }else{ - preHtml += '
                1. '; // Handles pasted contents into existing lists - } - } - if(!postHtml){ - postHtml = '
                '; - }else{ - postHtml = '
              '; + preHtml += '
              1. '; // Handles pasted contents into existing lists } + postHtml += '
              '; } } processedMarker = true;