Skip to content

Commit

Permalink
style: reindent and reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-D committed Apr 9, 2018
1 parent 2d4b8c1 commit 49b4350
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions src/trumbowyg.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,11 +474,15 @@ Object.defineProperty(jQuery.trumbowyg, 'defaultOptions', {
this.btnsDef[btnName] = btnDef;
},

setupUrlPrefix: function() {
setupUrlPrefix: function () {
var protocol = this.o.urlProtocol;
if(!protocol) { return; }
if (!protocol) {
return;
}

if(typeof(protocol) !== 'string') { return 'https://'; }
if (typeof(protocol) !== 'string') {
return 'https://';
}
return /:\/\/$/.test(protocol) ? protocol : protocol + '://';
},

Expand Down Expand Up @@ -1239,7 +1243,9 @@ Object.defineProperty(jQuery.trumbowyg, 'defaultOptions', {

t.openModalInsert(t.lang.createLink, options, function (v) { // v is value
var url = t.prependUrlPrefix(v.url);
if(!url.length) { return false; }
if (!url.length) {
return false;
}

var link = $(['<a href="', v.url, '">', v.text || v.url, '</a>'].join(''));

Expand All @@ -1258,15 +1264,21 @@ Object.defineProperty(jQuery.trumbowyg, 'defaultOptions', {
return true;
});
},
prependUrlPrefix: function(url) {
prependUrlPrefix: function (url) {
var t = this;
if(!t.urlPrefix) { return url; }
if (!t.urlPrefix) {
return url;
}

const VALID_LINK_PREFIX = /^([a-z][-+.a-z0-9]*:|\/|#)/i;
if(VALID_LINK_PREFIX.test(url)) { return url; }
if (VALID_LINK_PREFIX.test(url)) {
return url;
}

const SIMPLE_EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
if(SIMPLE_EMAIL_REGEX.test(url)) { return 'mailto:' + url; }
if (SIMPLE_EMAIL_REGEX.test(url)) {
return 'mailto:' + url;
}

return t.urlPrefix + url;
},
Expand Down

0 comments on commit 49b4350

Please sign in to comment.