editor: links - proper linking to document attachments
authorAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 6 May 2014 14:40:05 +0000 (16:40 +0200)
committerAleksander Łukasz <aleksander.lukasz@nowoczesnapolska.org.pl>
Tue, 6 May 2014 14:51:58 +0000 (16:51 +0200)
src/editor/modules/data/data.js
src/editor/modules/data/document.js
src/editor/plugins/core/links/box.html
src/editor/plugins/core/links/linkElement.js

index 38a80a9..8b8851a 100644 (file)
@@ -37,7 +37,7 @@ return function(sandbox) {
     var loadDocument = function(text, isDraft, draftTimestamp) {
         logger.debug('loading document');
         try {
     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
         } catch(e) {
             logger.exception(e);
             alert(gettext('This document contains errors and can\'t be loaded. :(')); // TODO
index 0dbff14..db2b7a8 100644 (file)
@@ -38,6 +38,13 @@ _.extend(Document.prototype, {
             });
         }.bind(this);
         return wlxml.WLXMLDocument.prototype.transaction.call(this, body, params);
             });
         }.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;
     }
 });
 
     }
 });
 
index d4594a7..6cf2200 100644 (file)
@@ -1,5 +1,5 @@
 <div contenteditable="false" link-box style="white-space: nowrap">
 <div contenteditable="false" link-box style="white-space: nowrap">
-    <a link target="blank" href="<%= href %>"><%= href %></a> --
+    <a link target="blank" href="<%= url %>"><%= text %></a> --
     <span>
         <a class="change" href="#"><%= gettext('change') %></a> |
         <a class="delete" href="#"><%= gettext('remove') %></a>
     <span>
         <a class="change" href="#"><%= gettext('change') %></a> |
         <a class="delete" href="#"><%= gettext('remove') %></a>
index 1214e95..0600733 100644 (file)
@@ -17,7 +17,10 @@ _.extend(linkElement, {
         genericElement.init.call(this);
         _.bindAll(this, 'changeLink', 'deleteLink');
 
         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();
         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);
         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));
         }
     },
 
         }
     },