fixing url
This commit is contained in:
@@ -10,7 +10,7 @@ import html2canvas from 'html2canvas';
|
||||
*/
|
||||
export const fromDom = element =>
|
||||
html2canvas(element, {
|
||||
allowTaint: true,
|
||||
allowTaint: false,
|
||||
useCORS: true,
|
||||
foreignObjectRendering: true,
|
||||
logging: false,
|
||||
@@ -25,19 +25,19 @@ export const fromDom = element =>
|
||||
export const fromUrl = url =>
|
||||
new Promise((resolve, reject) => {
|
||||
const iframe = document.createElement('iframe');
|
||||
const protocol = location.href.startsWith('https://') ? 'https' : 'http';
|
||||
iframe.src = protocol + url.replace(/^https?/, '');
|
||||
const protocol = location.href.startsWith('https://') ? 'https:' : 'http:';
|
||||
iframe.src = protocol + url.replace(/^https?:/, '');
|
||||
iframe.style.opacity = 0;
|
||||
iframe.onload = () => {
|
||||
fromDom(iframe.contentDocument.documentElement)
|
||||
.then((image) => {
|
||||
document.body.removeChild(iframe);
|
||||
resolve(image);
|
||||
})
|
||||
.catch(() => {
|
||||
document.body.removeChild(iframe);
|
||||
reject(MailPoet.I18n.t('errorWhileTakingScreenshot'));
|
||||
});
|
||||
.then((image) => {
|
||||
document.body.removeChild(iframe);
|
||||
resolve(image);
|
||||
})
|
||||
.catch(() => {
|
||||
document.body.removeChild(iframe);
|
||||
reject(MailPoet.I18n.t('errorWhileTakingScreenshot'));
|
||||
});
|
||||
};
|
||||
const onError = () => {
|
||||
document.body.removeChild(iframe);
|
||||
|
@@ -73,43 +73,43 @@ define([
|
||||
|
||||
Module.saveTemplate = function (options) {
|
||||
return Thumbnail.fromNewsletter(App.toJSON())
|
||||
.then(function (thumbnail) {
|
||||
var data = _.extend(options || {}, {
|
||||
thumbnail: thumbnail,
|
||||
body: JSON.stringify(App.getBody()),
|
||||
categories: JSON.stringify([
|
||||
'saved',
|
||||
App.getNewsletter().get('type')
|
||||
])
|
||||
});
|
||||
.then(function (thumbnail) {
|
||||
var data = _.extend(options || {}, {
|
||||
thumbnail: thumbnail,
|
||||
body: JSON.stringify(App.getBody()),
|
||||
categories: JSON.stringify([
|
||||
'saved',
|
||||
App.getNewsletter().get('type')
|
||||
])
|
||||
});
|
||||
|
||||
return MailPoet.Ajax.post({
|
||||
api_version: window.mailpoet_api_version,
|
||||
endpoint: 'newsletterTemplates',
|
||||
action: 'save',
|
||||
data: data
|
||||
return MailPoet.Ajax.post({
|
||||
api_version: window.mailpoet_api_version,
|
||||
endpoint: 'newsletterTemplates',
|
||||
action: 'save',
|
||||
data: data
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Module.exportTemplate = function (options) {
|
||||
return Thumbnail.fromNewsletter(App.toJSON())
|
||||
.then(function (thumbnail) {
|
||||
var data = _.extend(options || {}, {
|
||||
thumbnail: thumbnail,
|
||||
body: App.getBody(),
|
||||
categories: JSON.stringify(['saved', App.getNewsletter().get('type')])
|
||||
});
|
||||
var blob = new Blob(
|
||||
[JSON.stringify(data)],
|
||||
{ type: 'application/json;charset=utf-8' }
|
||||
);
|
||||
.then(function (thumbnail) {
|
||||
var data = _.extend(options || {}, {
|
||||
thumbnail: thumbnail,
|
||||
body: App.getBody(),
|
||||
categories: JSON.stringify(['saved', App.getNewsletter().get('type')])
|
||||
});
|
||||
var blob = new Blob(
|
||||
[JSON.stringify(data)],
|
||||
{ type: 'application/json;charset=utf-8' }
|
||||
);
|
||||
|
||||
FileSaver.saveAs(blob, 'template.json');
|
||||
MailPoet.trackEvent('Editor > Template exported', {
|
||||
'MailPoet Free version': window.mailpoet_version
|
||||
FileSaver.saveAs(blob, 'template.json');
|
||||
MailPoet.trackEvent('Editor > Template exported', {
|
||||
'MailPoet Free version': window.mailpoet_version
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
Module.SaveView = Marionette.View.extend({
|
||||
|
@@ -92,22 +92,22 @@ define(
|
||||
},
|
||||
saveTemplate: function (response, done) {
|
||||
Thumbnail.fromUrl(response.meta.preview_url)
|
||||
.then(function (thumbnail) {
|
||||
MailPoet.Ajax.post({
|
||||
api_version: window.mailpoet_api_version,
|
||||
endpoint: 'newsletterTemplates',
|
||||
action: 'save',
|
||||
data: {
|
||||
newsletter_id: response.data.id,
|
||||
name: response.data.subject,
|
||||
description: response.data.preheader,
|
||||
thumbnail: thumbnail,
|
||||
body: JSON.stringify(response.data.body),
|
||||
categories: '["recent"]',
|
||||
},
|
||||
}).then(done).fail(this.showError);
|
||||
})
|
||||
.catch(err => this.showError({ errors: [err] }));
|
||||
.then(function (thumbnail) {
|
||||
MailPoet.Ajax.post({
|
||||
api_version: window.mailpoet_api_version,
|
||||
endpoint: 'newsletterTemplates',
|
||||
action: 'save',
|
||||
data: {
|
||||
newsletter_id: response.data.id,
|
||||
name: response.data.subject,
|
||||
description: response.data.preheader,
|
||||
thumbnail: thumbnail,
|
||||
body: JSON.stringify(response.data.body),
|
||||
categories: '["recent"]',
|
||||
},
|
||||
}).then(done).fail(this.showError);
|
||||
})
|
||||
.catch(err => this.showError({ errors: [err] }));
|
||||
},
|
||||
handleSend: function (e) {
|
||||
e.preventDefault();
|
||||
|
Reference in New Issue
Block a user