From: Aleksander Ɓukasz Date: Tue, 6 May 2014 14:46:06 +0000 (+0200) Subject: editor: auto http:// prefix for links X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/203aece6993ed334171bd43dd88bc68ed9d4e7c1?ds=sidebyside;hp=-c editor: auto http:// prefix for links --- 203aece6993ed334171bd43dd88bc68ed9d4e7c1 diff --git a/src/editor/plugins/core/links/linkElement.js b/src/editor/plugins/core/links/linkElement.js index 0600733..fdb60e1 100644 --- a/src/editor/plugins/core/links/linkElement.js +++ b/src/editor/plugins/core/links/linkElement.js @@ -18,7 +18,7 @@ _.extend(linkElement, { _.bindAll(this, 'changeLink', 'deleteLink'); var linkText = this.wlxmlNode.getAttr('href'), - linkUrl = this.wlxmlNode.document.getUrlForLink(linkText); + linkUrl = this.getUrl(linkText); this.box = $(_.template(boxTemplate)({text: linkText, url: linkUrl})); this.box.find('.change').on('click', this.changeLink); @@ -33,7 +33,7 @@ _.extend(linkElement, { if(event.meta.attr === 'href') { var link = this.box.find('[link]'); link.text(event.meta.newVal); - link.attr('href', this.wlxmlNode.document.getUrlForLink(event.meta.newVal)); + link.attr('href', this.getUrl(event.meta.newVal)); } }, @@ -72,6 +72,14 @@ _.extend(linkElement, { description: gettext('Remove link') } }); + }, + + getUrl: function(link) { + var pattern = /^[a-z]*:\/\//g; + if(!pattern.test(link)) { + link = 'http://' + link; + } + return this.wlxmlNode.document.getUrlForLink(link); } });