diff options
author | Matthias Bartelmeß <mba@fourplusone.de> | 2012-04-07 02:12:42 +0200 |
---|---|---|
committer | Matthias Bartelmeß <mba@fourplusone.de> | 2012-04-07 02:12:42 +0200 |
commit | 6507614e459dac868d3c76355ca013d13132bc79 (patch) | |
tree | 48fd43b767ef95f3d5d345a164c65f56db21ba74 | |
parent | 9efe838a325ca05dc5413fc131d98267a51a535a (diff) | |
download | etherpad-lite-6507614e459dac868d3c76355ca013d13132bc79.zip |
made domline and content collector lineAttributes compatible
-rw-r--r-- | src/static/js/contentcollector.js | 53 | ||||
-rw-r--r-- | src/static/js/domline.js | 31 |
2 files changed, 62 insertions, 22 deletions
diff --git a/src/static/js/contentcollector.js b/src/static/js/contentcollector.js index 7f642cb2..219976d3 100644 --- a/src/static/js/contentcollector.js +++ b/src/static/js/contentcollector.js @@ -27,6 +27,7 @@ var _MAX_LIST_LEVEL = 8; var Changeset = require('./Changeset'); var hooks = require('./pluginfw/hooks'); +var _ = require('./underscore'); function sanitizeUnicode(s) { @@ -182,7 +183,7 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class { var ln = lines.length() - 1; var chr = lines.textOfLine(ln).length; - if (chr == 0 && state.listType && state.listType != 'none') + if (chr == 0 && !_.isEmpty(state.lineAttributes)) { chr += 1; // listMarker } @@ -234,25 +235,30 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class function _enterList(state, listType) { - var oldListType = state.listType; - state.listLevel = (state.listLevel || 0) + 1; + var oldListType = state.lineAttributes['list']; if (listType != 'none') { state.listNesting = (state.listNesting || 0) + 1; } - state.listType = listType; + + if(listType === 'none' || !listType ){ + delete state.lineAttributes['list']; + } + else{ + state.lineAttributes['list'] = listType; + } + _recalcAttribString(state); return oldListType; } function _exitList(state, oldListType) { - state.listLevel--; - if (state.listType != 'none') + if (state.lineAttributes['list']) { state.listNesting--; } - state.listType = oldListType; + if(oldListType) state.lineAttributes['list'] = oldListType; _recalcAttribString(state); } @@ -295,21 +301,29 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class state.attribString = Changeset.makeAttribsString('+', lst, apool); } - function _produceListMarker(state) + function _produceLineAttributesMarker(state) { - lines.appendText('*', Changeset.makeAttribsString('+', [ - ['list', state.listType], + // TODO: This has to go to AttributeManager. + var attributes = [ + ['lmkr', '1'], ['insertorder', 'first'] - ], apool)); + ].concat( + _.map(state.lineAttributes,function(value,key){ + console.log([key, value]) + return [key, value]; + }) + ); + + lines.appendText('*', Changeset.makeAttribsString('+', attributes , apool)); } cc.startNewLine = function(state) { if (state) { var atBeginningOfLine = lines.textOfLine(lines.length() - 1).length == 0; - if (atBeginningOfLine && state.listType && state.listType != 'none') + if (atBeginningOfLine && !_.isEmpty(state.lineAttributes)) { - _produceListMarker(state); + _produceLineAttributesMarker(state); } } lines.startNew(); @@ -339,7 +353,14 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class localAttribs: null, attribs: { /*name -> nesting counter*/ }, - attribString: '' + attribString: '', + // lineAttributes maintain a map from attributes to attribute values set on a line + lineAttributes: { + /* + example: + 'list': 'bullet1', + */ + } }; } var localAttribs = state.localAttribs; @@ -401,9 +422,9 @@ function makeContentCollector(collectStyles, browser, apool, domInterface, class // newlines in the source mustn't become spaces at beginning of line box txt2 = txt2.replace(/^\n*/, ''); } - if (atBeginningOfLine && state.listType && state.listType != 'none') + if (atBeginningOfLine && !_.isEmpty(state.lineAttributes)) { - _produceListMarker(state); + _produceLineAttributesMarker(state); } lines.appendText(textify(txt2), state.attribString); x += consumed; diff --git a/src/static/js/domline.js b/src/static/js/domline.js index d4f52a3c..5d8bb719 100644 --- a/src/static/js/domline.js +++ b/src/static/js/domline.js @@ -29,7 +29,7 @@ var Security = require('./security'); var hooks = require('./pluginfw/hooks'); var _ = require('./underscore'); - +var lineAttributeMarker = require('./linestylefilter').lineAttributeMarker; var Ace2Common = require('./ace2_common'); var noop = Ace2Common.noop; @@ -82,7 +82,8 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument) } var html = []; - var preHtml, postHtml; + var preHtml = '', + postHtml = ''; var curHTML = null; function processSpaces(s) @@ -95,7 +96,9 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument) var lineClass = 'ace-line'; result.appendSpan = function(txt, cls) { - if (cls.indexOf('list') >= 0) + var processedMarker = false; + // Handle lineAttributeMarker, if present + if (cls.indexOf(lineAttributeMarker) >= 0) { var listType = /(?:^| )list:(\S+)/.exec(cls); var start = /(?:^| )start:(\S+)/.exec(cls); @@ -115,10 +118,26 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument) preHtml = '<ol '+start+' class="list-' + Security.escapeHTMLAttribute(listType) + '"><li>'; postHtml = '</li></ol>'; } - } + } + processedMarker = true; + } + + _.map(hooks.callAll("aceDomLineProcessLineAttributes", { + domline: domline, + cls: cls + }), function(modifier) + { + preHtml += modifier.preHtml; + postHtml += modifier.postHtml; + processedMarker |= modifier.processedMarker; + }); + + if( processedMarker ){ result.lineMarker += txt.length; return; // don't append any text - } + } + + } var href = null; var simpleTags = null; @@ -203,7 +222,7 @@ domline.createDomLine = function(nonEmpty, doesWrap, optBrowser, optDocument) { newHTML = (preHtml || '') + newHTML + (postHtml || ''); } - html = preHtml = postHtml = null; // free memory + html = preHtml = postHtml = ''; // free memory if (newHTML !== curHTML) { curHTML = newHTML; |