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

Added Plugin: Paste link into editor and it'll be replaced by iframe, using noembed API. #711

Merged
merged 4 commits into from
Apr 9, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 27 additions & 12 deletions plugins/pasteurl/trumbowyg.pasteurl.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,43 +20,58 @@
var clipboardData = (pasteEvent.originalEvent || pasteEvent).clipboardData;
var pastedData = clipboardData.getData("Text");
var request = null;

if (pastedData.startsWith("http")) {

pasteEvent.stopPropagation();
pasteEvent.preventDefault();

var url = pastedData;
var query = {
url: url.trim()
url: pastedData.trim()
};
var content = "";
var fails = 0;

if (request && request.transport) request.transport.abort();

request = $.ajax({
crossOrigin: true,
url: "https://noembed.com/embed?nowrap=on",
url2: "https://api.maxmade.nl/url2iframe/embed",
type: "GET",
data: query,
cache: false,
dataType: "json",
dataType: "jsonp",
success: function(res) {
if (res.html) {
fails = 0;
content = res.html;
} else {
fails++;
}
},
error: function(res) {
fails++;
},
complete: function() {
console.log(this.url);
Copy link
Owner

Choose a reason for hiding this comment

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

remove console log please :)

if (fails === 1) {
console.log(fails);
Copy link
Owner

Choose a reason for hiding this comment

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

log

this.url = this.url2;
this.data = query;
$.ajax(this);
}
if (fails === 2) {
console.log(fails);
Copy link
Owner

Choose a reason for hiding this comment

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

log

content = $("<a>", {
href: pastedData,
text: pastedData
}).prop('outerHTML');
}
},
error: function() {
content = $("<a>", {
href: pastedData,
text: pastedData
}).prop('outerHTML');
},
complete: function() {
trumbowyg.execCmd("insertHTML", content);
if (content.length > 0) {
fails = 0;
trumbowyg.execCmd("insertHTML", content);
}
}
});
}
Expand Down