From 203aece6993ed334171bd43dd88bc68ed9d4e7c1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Tue, 6 May 2014 16:46:06 +0200 Subject: [PATCH] editor: auto http:// prefix for links --- src/editor/plugins/core/links/linkElement.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) 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); } }); -- 2.20.1