From 760d63d033e1f7e45598d2597e9def7aaba5bdab Mon Sep 17 00:00:00 2001 From: Subramanya Sastry Date: Mon, 17 Sep 2012 14:46:44 -0500 Subject: [PATCH] Improved template roundtripping based on WT ranges on DOM nodes. - Fixed several bugs in the DSR computation. - Deleted comment tokens from template output. - Eliminated TSR info from template output. - Rearranged order of DOM post passes. - Updated template encapsulation to use DSR values. - There are still a few missing pieces and scenarios that are not handled properly. Change-Id: I644914902ec1d27418138b107abe765f81178398 --- js/lib/ext.Cite.js | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/js/lib/ext.Cite.js b/js/lib/ext.Cite.js index 09aa9b3db..265b36d34 100644 --- a/js/lib/ext.Cite.js +++ b/js/lib/ext.Cite.js @@ -62,20 +62,24 @@ Cite.prototype.handleRef = function ( tokens ) { var refId = "#mwt" + this.manager.env.generateUID(), text = this.manager.env.text, - start = startTsr[0], - end = endTsr ? endTsr[1] : text.length; - var res = [ - new TagTk('span', [ + span = new TagTk('span', [ new KV('id', linkback), new KV('class', 'reference'), new KV('about', refId), new KV('typeof', 'mw:Object/Ext/Cite') - ], - { - tsr: [start, end], - src: endTsr ? text.substring(start, end) : text.substring(start) - } - ), + ]); + + if (startTsr) { + var start = startTsr[0], + end = endTsr ? endTsr[1] : text.length; + span.dataAttribs = { + tsr: [start, end], + src: endTsr ? text.substring(start, end) : text.substring(start) + }; + } + + var res = [ + span, new TagTk( 'a', [ new KV('href', '#' + ref.target) ] @@ -104,15 +108,15 @@ Cite.prototype.onReferences = function ( token, manager ) { if ( token.constructor === EndTagTk ) { return {}; } - + //console.warn( 'references refGroups:' + JSON.stringify( this.refGroups, null, 2 ) ); var refGroups = this.refGroups; - + var arrow = '↑'; var renderLine = function( ref ) { var out = [ new TagTk('li', [new KV('id', ref.target)] ) ]; - if (ref.linkbacks.length == 1) { + if (ref.linkbacks.length === 1) { out = out.concat([ new TagTk( 'a', [ new KV('href', '#' + ref.linkbacks[0]) @@ -147,7 +151,7 @@ Cite.prototype.onReferences = function ( token, manager ) { //console.warn( 'renderLine res: ' + JSON.stringify( out, null, 2 )); return out; }; - + var res; var options = $.extend({ @@ -217,6 +221,6 @@ Cite.prototype.getRefGroup = function(group) { return refGroups[group]; }; -if (typeof module == "object") { +if (typeof module === "object") { module.exports.Cite = Cite; }