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