Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add options for minimal links and auto-prefixing http protocol #727

Merged
merged 14 commits into from
Apr 9, 2018
Merged
16 changes: 5 additions & 11 deletions src/trumbowyg.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,16 +480,10 @@ Object.defineProperty(jQuery.trumbowyg, 'defaultOptions', {

if(!protocol) { return; }

if(typeof(protocol) === 'boolean') {
return 'https://'
} else if(typeof(protocol) === 'string') {
if(/^https?:\/\/$/.test(protocol)) { return protocol; }

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a lot of code to just get https:// or http:// :/

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about others protocols? If I want put some ftp:// or whatever?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Alex-D.

Would you prefer to allow any string value in the option, and append :// if it's missing?

So:

  • a true value defaults to https://
  • a string without the correct suffix has :// appended to it
  • a string with the correct suffix is prepended as is

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yep I think it could be cool :)

},

buildEditor: function () {
var t = this,
Expand Down Expand Up @@ -1230,7 +1224,7 @@ Object.defineProperty(jQuery.trumbowyg, 'defaultOptions', {
},
text: {
label: t.lang.text,
value: new XMLSerializer().serializeToString(documentSelection.getRangeAt(0).cloneContents())
value: text
}
};
if (!t.o.minimalLinks) {
Expand Down