From: Aleksander Ɓukasz Date: Tue, 6 May 2014 14:40:05 +0000 (+0200) Subject: editor: links - proper linking to document attachments X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/34c9285ef29074d0c13cea81fbb05e93eb369b4a editor: links - proper linking to document attachments --- diff --git a/src/editor/modules/data/data.js b/src/editor/modules/data/data.js index 38a80a9..8b8851a 100644 --- a/src/editor/modules/data/data.js +++ b/src/editor/modules/data/data.js @@ -37,7 +37,7 @@ return function(sandbox) { var loadDocument = function(text, isDraft, draftTimestamp) { logger.debug('loading document'); try { - wlxmlDocument = wlxml.WLXMLDocumentFromXML(text, {}, Document); + wlxmlDocument = wlxml.WLXMLDocumentFromXML(text, {editorConfig: sandbox.getConfig()}, Document); } catch(e) { logger.exception(e); alert(gettext('This document contains errors and can\'t be loaded. :(')); // TODO diff --git a/src/editor/modules/data/document.js b/src/editor/modules/data/document.js index 0dbff14..db2b7a8 100644 --- a/src/editor/modules/data/document.js +++ b/src/editor/modules/data/document.js @@ -38,6 +38,13 @@ _.extend(Document.prototype, { }); }.bind(this); return wlxml.WLXMLDocument.prototype.transaction.call(this, body, params); + }, + getUrlForLink: function(link) { + var cfg = this.options.editorConfig; + if(link.substr(0, 7) === 'file://' && cfg && cfg.documentAttachmentUrl) { + link = cfg.documentAttachmentUrl(link.substr(7)); + } + return link; } }); diff --git a/src/editor/plugins/core/links/box.html b/src/editor/plugins/core/links/box.html index d4594a7..6cf2200 100644 --- a/src/editor/plugins/core/links/box.html +++ b/src/editor/plugins/core/links/box.html @@ -1,5 +1,5 @@
- <%= href %> -- + <%= text %> -- <%= gettext('change') %> | <%= gettext('remove') %> diff --git a/src/editor/plugins/core/links/linkElement.js b/src/editor/plugins/core/links/linkElement.js index 1214e95..0600733 100644 --- a/src/editor/plugins/core/links/linkElement.js +++ b/src/editor/plugins/core/links/linkElement.js @@ -17,7 +17,10 @@ _.extend(linkElement, { genericElement.init.call(this); _.bindAll(this, 'changeLink', 'deleteLink'); - this.box = $(_.template(boxTemplate)({href: this.wlxmlNode.getAttr('href')})); + var linkText = this.wlxmlNode.getAttr('href'), + linkUrl = this.wlxmlNode.document.getUrlForLink(linkText); + + this.box = $(_.template(boxTemplate)({text: linkText, url: linkUrl})); this.box.find('.change').on('click', this.changeLink); this.box.find('.delete').on('click', this.deleteLink); this.box.hide(); @@ -30,7 +33,7 @@ _.extend(linkElement, { if(event.meta.attr === 'href') { var link = this.box.find('[link]'); link.text(event.meta.newVal); - link.attr('href', event.meta.newVal); + link.attr('href', this.wlxmlNode.document.getUrlForLink(event.meta.newVal)); } },