Fix indent rule in ES5

[MAILPOET-1029]
This commit is contained in:
Pavel Dohnal
2017-09-07 15:51:25 +01:00
parent 9fc0ac8c4f
commit 478e60d60e
40 changed files with 1017 additions and 1018 deletions

View File

@ -74,7 +74,6 @@
"keyword-spacing": 0, "keyword-spacing": 0,
"eol-last": 0, "eol-last": 0,
"dot-notation": 0, "dot-notation": 0,
"indent": 0,
"prefer-template": 0, "prefer-template": 0,
"func-names": 0 "func-names": 0
} }

View File

@ -1,6 +1,6 @@
define('admin', [ define('admin', [
'jquery' 'jquery'
], ],
function(jQuery) { function(jQuery) {
jQuery(function($) { jQuery(function($) {
// dom ready // dom ready

View File

@ -16,59 +16,59 @@ define('ajax', ['mailpoet', 'jquery', 'underscore'], function(mp, jQuery, _) {
var MailPoet = mp; var MailPoet = mp;
MailPoet.Ajax = { MailPoet.Ajax = {
version: 0.5, version: 0.5,
options: {}, options: {},
defaults: { defaults: {
url: null, url: null,
api_version: null, api_version: null,
endpoint: null, endpoint: null,
action: null, action: null,
token: null, token: null,
data: {} data: {}
}, },
post: function(options) { post: function(options) {
return this.request('post', options); return this.request('post', options);
}, },
init: function(options) { init: function(options) {
// merge options // merge options
this.options = jQuery.extend({}, this.defaults, options); this.options = jQuery.extend({}, this.defaults, options);
// set default url // set default url
if(this.options.url === null) { if(this.options.url === null) {
this.options.url = ajaxurl; this.options.url = ajaxurl;
} }
// set default token // set default token
if(this.options.token === null) { if(this.options.token === null) {
this.options.token = window.mailpoet_token; this.options.token = window.mailpoet_token;
} }
}, },
getParams: function() { getParams: function() {
return { return {
action: 'mailpoet', action: 'mailpoet',
api_version: this.options.api_version, api_version: this.options.api_version,
token: this.options.token, token: this.options.token,
endpoint: this.options.endpoint, endpoint: this.options.endpoint,
method: this.options.action, method: this.options.action,
data: this.options.data || {} data: this.options.data || {}
}; };
}, },
request: function(method, options) { request: function(method, options) {
// set options // set options
this.init(options); this.init(options);
// set request params // set request params
var params = this.getParams(); var params = this.getParams();
// remove null values from the data object // remove null values from the data object
if (_.isObject(params.data)) { if (_.isObject(params.data)) {
params.data = _.pick(params.data, function(value) { params.data = _.pick(params.data, function(value) {
return (value !== null); return (value !== null);
}); });
} }
// ajax request // ajax request
var deferred = jQuery.post( var deferred = jQuery.post(
this.options.url, this.options.url,
params, params,
null, null,
@ -78,9 +78,9 @@ define('ajax', ['mailpoet', 'jquery', 'underscore'], function(mp, jQuery, _) {
}, _.partial(requestFailed, MailPoet.I18n.t('ajaxFailedErrorMessage'))); }, _.partial(requestFailed, MailPoet.I18n.t('ajaxFailedErrorMessage')));
// clear options // clear options
this.options = {}; this.options = {};
return deferred; return deferred;
} }
}; };
}); });

View File

@ -8,162 +8,162 @@ define('date',
jQuery, jQuery,
Moment Moment
) { ) {
'use strict'; 'use strict';
var MailPoet = mp; var MailPoet = mp;
MailPoet.Date = { MailPoet.Date = {
version: 0.1, version: 0.1,
options: {}, options: {},
defaults: { defaults: {
offset: 0, offset: 0,
format: 'F, d Y H:i:s' format: 'F, d Y H:i:s'
}, },
init: function (opts) { init: function (opts) {
var options = opts || {}; var options = opts || {};
// set UTC offset // set UTC offset
if ( if (
options.offset === undefined options.offset === undefined
&& window.mailpoet_date_offset !== undefined && window.mailpoet_date_offset !== undefined
) { ) {
options.offset = window.mailpoet_date_offset; options.offset = window.mailpoet_date_offset;
} }
// set date format // set date format
if ( if (
options.format === undefined options.format === undefined
&& window.mailpoet_date_format !== undefined && window.mailpoet_date_format !== undefined
) { ) {
options.format = window.mailpoet_date_format; options.format = window.mailpoet_date_format;
}
// merge options
this.options = jQuery.extend({}, this.defaults, options);
return this;
},
format: function(date, opts) {
var options = opts || {};
this.init(options);
var momentDate = Moment(date, this.convertFormat(options.parseFormat));
if (options.offset === 0) momentDate = momentDate.utc();
return momentDate.format(this.convertFormat(this.options.format));
},
toDate: function(date, opts) {
var options = opts || {};
this.init(options);
return Moment(date, this.convertFormat(options.parseFormat)).toDate();
},
short: function(date) {
return this.format(date, {
format: 'F, j Y'
});
},
full: function(date) {
return this.format(date, {
format: 'F, j Y H:i:s'
});
},
time: function(date) {
return this.format(date, {
format: 'H:i:s'
});
},
convertFormat: function(format) {
var format_mappings = {
date: {
d: 'DD',
D: 'ddd',
j: 'D',
l: 'dddd',
N: 'E',
S: 'o',
w: 'e',
z: 'DDD',
W: 'W',
F: 'MMMM',
m: 'MM',
M: 'MMM',
n: 'M',
t: '', // no equivalent
L: '', // no equivalent
o: 'YYYY',
Y: 'YYYY',
y: 'YY',
a: 'a',
A: 'A',
B: '', // no equivalent
g: 'h',
G: 'H',
h: 'hh',
H: 'HH',
i: 'mm',
s: 'ss',
u: 'SSS',
e: 'zz', // deprecated since version 1.6.0 of moment.js
I: '', // no equivalent
O: '', // no equivalent
P: '', // no equivalent
T: '', // no equivalent
Z: '', // no equivalent
c: '', // no equivalent
r: '', // no equivalent
U: 'X'
},
strftime: {
a: 'ddd',
A: 'dddd',
b: 'MMM',
B: 'MMMM',
d: 'DD',
e: 'D',
F: 'YYYY-MM-DD',
H: 'HH',
I: 'hh',
j: 'DDDD',
k: 'H',
l: 'h',
m: 'MM',
M: 'mm',
p: 'A',
S: 'ss',
u: 'E',
w: 'd',
W: 'WW',
y: 'YY',
Y: 'YYYY',
z: 'ZZ',
Z: 'z'
} }
}; // merge options
this.options = jQuery.extend({}, this.defaults, options);
if (!format || format.length <= 0) return format; return this;
},
format: function(date, opts) {
var options = opts || {};
this.init(options);
var replacements = format_mappings['date']; var momentDate = Moment(date, this.convertFormat(options.parseFormat));
if (options.offset === 0) momentDate = momentDate.utc();
return momentDate.format(this.convertFormat(this.options.format));
},
toDate: function(date, opts) {
var options = opts || {};
this.init(options);
var convertedFormat = []; return Moment(date, this.convertFormat(options.parseFormat)).toDate();
var escapeToken = false; },
short: function(date) {
return this.format(date, {
format: 'F, j Y'
});
},
full: function(date) {
return this.format(date, {
format: 'F, j Y H:i:s'
});
},
time: function(date) {
return this.format(date, {
format: 'H:i:s'
});
},
convertFormat: function(format) {
var format_mappings = {
date: {
d: 'DD',
D: 'ddd',
j: 'D',
l: 'dddd',
N: 'E',
S: 'o',
w: 'e',
z: 'DDD',
W: 'W',
F: 'MMMM',
m: 'MM',
M: 'MMM',
n: 'M',
t: '', // no equivalent
L: '', // no equivalent
o: 'YYYY',
Y: 'YYYY',
y: 'YY',
a: 'a',
A: 'A',
B: '', // no equivalent
g: 'h',
G: 'H',
h: 'hh',
H: 'HH',
i: 'mm',
s: 'ss',
u: 'SSS',
e: 'zz', // deprecated since version 1.6.0 of moment.js
I: '', // no equivalent
O: '', // no equivalent
P: '', // no equivalent
T: '', // no equivalent
Z: '', // no equivalent
c: '', // no equivalent
r: '', // no equivalent
U: 'X'
},
strftime: {
a: 'ddd',
A: 'dddd',
b: 'MMM',
B: 'MMMM',
d: 'DD',
e: 'D',
F: 'YYYY-MM-DD',
H: 'HH',
I: 'hh',
j: 'DDDD',
k: 'H',
l: 'h',
m: 'MM',
M: 'mm',
p: 'A',
S: 'ss',
u: 'E',
w: 'd',
W: 'WW',
y: 'YY',
Y: 'YYYY',
z: 'ZZ',
Z: 'z'
}
};
for(var index = 0, token = ''; format.charAt(index); index += 1){ if (!format || format.length <= 0) return format;
token = format.charAt(index);
if (escapeToken === true) { var replacements = format_mappings['date'];
convertedFormat.push('['+token+']');
escapeToken = false; var convertedFormat = [];
} else { var escapeToken = false;
if (token === '\\') {
// Slash escapes the next symbol to be treated as literal for(var index = 0, token = ''; format.charAt(index); index += 1){
escapeToken = true; token = format.charAt(index);
continue; if (escapeToken === true) {
} else if (replacements[token] !== undefined) {
convertedFormat.push(replacements[token]);
} else {
convertedFormat.push('['+token+']'); convertedFormat.push('['+token+']');
escapeToken = false;
} else {
if (token === '\\') {
// Slash escapes the next symbol to be treated as literal
escapeToken = true;
continue;
} else if (replacements[token] !== undefined) {
convertedFormat.push(replacements[token]);
} else {
convertedFormat.push('['+token+']');
}
} }
} }
}
return convertedFormat.join(''); return convertedFormat.join('');
} }
}; };
}); });

View File

@ -1,31 +1,31 @@
define('handlebars_helpers', ['handlebars'], function(Handlebars) { define('handlebars_helpers', ['handlebars'], function(Handlebars) {
// Handlebars helpers // Handlebars helpers
Handlebars.registerHelper('concat', function() { Handlebars.registerHelper('concat', function() {
var size = (arguments.length - 1), var size = (arguments.length - 1),
output = ''; output = '';
for(var i = 0; i < size; i++) { for(var i = 0; i < size; i++) {
output += arguments[i]; output += arguments[i];
} }
return output; return output;
}); });
Handlebars.registerHelper('number_format', function(value, block) { Handlebars.registerHelper('number_format', function(value, block) {
return Number(value).toLocaleString(); return Number(value).toLocaleString();
}); });
Handlebars.registerHelper('date_format', function(timestamp, block) { Handlebars.registerHelper('date_format', function(timestamp, block) {
if(window.moment) { if(window.moment) {
if(timestamp === undefined || isNaN(timestamp) || timestamp <= 0) { if(timestamp === undefined || isNaN(timestamp) || timestamp <= 0) {
return; return;
} }
// set date format // set date format
var f = block.hash.format || 'MMM Do, YYYY'; var f = block.hash.format || 'MMM Do, YYYY';
// check if we passed a timestamp // check if we passed a timestamp
if(parseInt(timestamp, 10) == timestamp) { if(parseInt(timestamp, 10) == timestamp) {
return moment.unix(timestamp).format(f); return moment.unix(timestamp).format(f);
} else { } else {
return moment.utc(timestamp).format(f); return moment.utc(timestamp).format(f);
} }
} else { } else {
return timestamp; return timestamp;
} }
@ -37,81 +37,81 @@ define('handlebars_helpers', ['handlebars'], function(Handlebars) {
}); });
Handlebars.registerHelper('ifCond', function (v1, operator, v2, options) { Handlebars.registerHelper('ifCond', function (v1, operator, v2, options) {
switch (operator) { switch (operator) {
case '==': case '==':
return (v1 == v2) ? options.fn(this) : options.inverse(this); return (v1 == v2) ? options.fn(this) : options.inverse(this);
case '===': case '===':
return (v1 === v2) ? options.fn(this) : options.inverse(this); return (v1 === v2) ? options.fn(this) : options.inverse(this);
case '!=': case '!=':
return (v1 != v2) ? options.fn(this) : options.inverse(this); return (v1 != v2) ? options.fn(this) : options.inverse(this);
case '!==': case '!==':
return (v1 !== v2) ? options.fn(this) : options.inverse(this); return (v1 !== v2) ? options.fn(this) : options.inverse(this);
case '<': case '<':
return (v1 < v2) ? options.fn(this) : options.inverse(this); return (v1 < v2) ? options.fn(this) : options.inverse(this);
case '<=': case '<=':
return (v1 <= v2) ? options.fn(this) : options.inverse(this); return (v1 <= v2) ? options.fn(this) : options.inverse(this);
case '>': case '>':
return (v1 > v2) ? options.fn(this) : options.inverse(this); return (v1 > v2) ? options.fn(this) : options.inverse(this);
case '>=': case '>=':
return (v1 >= v2) ? options.fn(this) : options.inverse(this); return (v1 >= v2) ? options.fn(this) : options.inverse(this);
case '&&': case '&&':
return (v1 && v2) ? options.fn(this) : options.inverse(this); return (v1 && v2) ? options.fn(this) : options.inverse(this);
case '||': case '||':
return (v1 || v2) ? options.fn(this) : options.inverse(this); return (v1 || v2) ? options.fn(this) : options.inverse(this);
case 'in': case 'in':
var values = v2.split(','); var values = v2.split(',');
return (v2.indexOf(v1) !== -1) ? options.fn(this) : options.inverse(this); return (v2.indexOf(v1) !== -1) ? options.fn(this) : options.inverse(this);
default: default:
return options.inverse(this); return options.inverse(this);
} }
}); });
Handlebars.registerHelper('nl2br', function(value, block) { Handlebars.registerHelper('nl2br', function(value, block) {
return value.gsub('\n', '<br />'); return value.gsub('\n', '<br />');
}); });
Handlebars.registerHelper('json_encode', function(value, block) { Handlebars.registerHelper('json_encode', function(value, block) {
return JSON.stringify(value); return JSON.stringify(value);
}); });
Handlebars.registerHelper('json_decode', function(value, block) { Handlebars.registerHelper('json_decode', function(value, block) {
return JSON.parse(value); return JSON.parse(value);
}); });
Handlebars.registerHelper('url', function(value, block) { Handlebars.registerHelper('url', function(value, block) {
var url = window.location.protocol + '//' + window.location.host + window.location.pathname; var url = window.location.protocol + '//' + window.location.host + window.location.pathname;
return url + value; return url + value;
}); });
Handlebars.registerHelper('emailFromMailto', function(value) { Handlebars.registerHelper('emailFromMailto', function(value) {
var mailtoMatchingRegex = /^mailto\:/i; var mailtoMatchingRegex = /^mailto\:/i;
if (typeof value === 'string' && value.match(mailtoMatchingRegex)) { if (typeof value === 'string' && value.match(mailtoMatchingRegex)) {
return value.replace(mailtoMatchingRegex, ''); return value.replace(mailtoMatchingRegex, '');
} else { } else {
return value; return value;
} }
}); });
Handlebars.registerHelper('lookup', function(obj, field, options) { Handlebars.registerHelper('lookup', function(obj, field, options) {
return obj && obj[field]; return obj && obj[field];
}); });
Handlebars.registerHelper('rsa_key', function(value, block) { Handlebars.registerHelper('rsa_key', function(value, block) {
// extract all lines into an array // extract all lines into an array
if(value === undefined) return ''; if(value === undefined) return '';
var lines = value.trim().split('\n'); var lines = value.trim().split('\n');
// remove header & footer // remove header & footer
lines.shift(); lines.shift();
lines.pop(); lines.pop();
// return concatenated lines // return concatenated lines
return lines.join(''); return lines.join('');
}); });
Handlebars.registerHelper('trim', function(value, block) { Handlebars.registerHelper('trim', function(value, block) {
if(value === null || value === undefined) return ''; if(value === null || value === undefined) return '';
return value.trim(); return value.trim();
}); });
/** /**
@ -125,20 +125,20 @@ define('handlebars_helpers', ['handlebars'], function(Handlebars) {
* @return {String} The truncated string. * @return {String} The truncated string.
*/ */
Handlebars.registerHelper('ellipsis', function (str, limit, append) { Handlebars.registerHelper('ellipsis', function (str, limit, append) {
var strAppend = append; var strAppend = append;
if (strAppend === undefined) { if (strAppend === undefined) {
strAppend = ''; strAppend = '';
} }
var sanitized = str.replace(/(<([^>]+)>)/g, ''); var sanitized = str.replace(/(<([^>]+)>)/g, '');
if (sanitized.length > limit) { if (sanitized.length > limit) {
return sanitized.substr(0, limit - strAppend.length) + strAppend; return sanitized.substr(0, limit - strAppend.length) + strAppend;
} else { } else {
return sanitized; return sanitized;
} }
}); });
Handlebars.registerHelper('getNumber', function (string) { Handlebars.registerHelper('getNumber', function (string) {
return parseInt(string, 10); return parseInt(string, 10);
}); });
Handlebars.registerHelper('fontWithFallback', function(font) { Handlebars.registerHelper('fontWithFallback', function(font) {

View File

@ -4,22 +4,22 @@ define('i18n',
], function( ], function(
mp mp
) { ) {
'use strict'; 'use strict';
var MailPoet = mp; var MailPoet = mp;
var translations = {}; var translations = {};
MailPoet.I18n = { MailPoet.I18n = {
add: function(key, value) { add: function(key, value) {
translations[key] = value; translations[key] = value;
}, },
t: function(key) { t: function(key) {
return translations[key] || 'TRANSLATION "%$1s" NOT FOUND'.replace('%$1s', key); return translations[key] || 'TRANSLATION "%$1s" NOT FOUND'.replace('%$1s', key);
}, },
all: function() { all: function() {
return translations; return translations;
} }
}; };
}); });

View File

@ -182,24 +182,24 @@ define('modal', ['mailpoet', 'jquery'],
initOverlay: function(toggle) { initOverlay: function(toggle) {
if(jQuery('#mailpoet_modal_overlay').length === 0) { if(jQuery('#mailpoet_modal_overlay').length === 0) {
// insert overlay into the DOM // insert overlay into the DOM
jQuery('body').append(this.templates.overlay); jQuery('body').append(this.templates.overlay);
// insert loading indicator into overlay // insert loading indicator into overlay
jQuery('#mailpoet_modal_overlay').append(this.templates.loading); jQuery('#mailpoet_modal_overlay').append(this.templates.loading);
} }
return this; return this;
}, },
toggleOverlay: function(toggle) { toggleOverlay: function(toggle) {
if(toggle === true) { if(toggle === true) {
jQuery('#mailpoet_modal_overlay') jQuery('#mailpoet_modal_overlay')
.removeClass('mailpoet_overlay_hidden'); .removeClass('mailpoet_overlay_hidden');
} else { } else {
jQuery('#mailpoet_modal_overlay') jQuery('#mailpoet_modal_overlay')
.addClass('mailpoet_overlay_hidden'); .addClass('mailpoet_overlay_hidden');
} }
return this; return this;
}, },
setupEvents: function() { setupEvents: function() {
// close popup when user clicks on close button // close popup when user clicks on close button
jQuery('#mailpoet_modal_close').on('click', this.cancel.bind(this)); jQuery('#mailpoet_modal_close').on('click', this.cancel.bind(this));
@ -250,39 +250,39 @@ define('modal', ['mailpoet', 'jquery'],
loadTemplate: function() { loadTemplate: function() {
if(this.subpanels.length > 0) { if(this.subpanels.length > 0) {
// hide panel // hide panel
jQuery('.mailpoet_'+this.options.type+'_wrapper').hide(); jQuery('.mailpoet_'+this.options.type+'_wrapper').hide();
// add sub panel wrapper // add sub panel wrapper
jQuery('#mailpoet_'+this.options.type) jQuery('#mailpoet_'+this.options.type)
.append(this.templates['subpanel']); .append(this.templates['subpanel']);
// add sub panel content // add sub panel content
jQuery('.mailpoet_'+this.options.type+'_body').last() jQuery('.mailpoet_'+this.options.type+'_body').last()
.html(this.subpanels[(this.subpanels.length - 1)].element); .html(this.subpanels[(this.subpanels.length - 1)].element);
// focus on sub panel // focus on sub panel
if(this.options.focus) { if(this.options.focus) {
this.focus(); this.focus();
} }
} else if (this.options.element) { } else if (this.options.element) {
jQuery('.mailpoet_'+this.options.type+'_body').empty(); jQuery('.mailpoet_'+this.options.type+'_body').empty();
jQuery('.mailpoet_'+this.options.type+'_body') jQuery('.mailpoet_'+this.options.type+'_body')
.append(this.options.element); .append(this.options.element);
} else { } else {
jQuery('.mailpoet_'+this.options.type+'_body') jQuery('.mailpoet_'+this.options.type+'_body')
.html( .html(
this.options.body_template( this.options.body_template(
this.options.data this.options.data
) )
); );
} }
return this; return this;
}, },
loadUrl: function() { loadUrl: function() {
if(this.options.method === 'get') { if(this.options.method === 'get') {
// make ajax request // make ajax request
jQuery.getJSON(this.options.url, jQuery.getJSON(this.options.url,
function(data) { function(data) {
this.options.data = jQuery.extend({}, this.options.data, data); this.options.data = jQuery.extend({}, this.options.data, data);
// load template using fetched data // load template using fetched data
@ -291,9 +291,9 @@ define('modal', ['mailpoet', 'jquery'],
this.showModal(); this.showModal();
}.bind(this) }.bind(this)
); );
} else if(this.options.method === 'post') { } else if(this.options.method === 'post') {
// make ajax request // make ajax request
jQuery.post(this.options.url, JSON.stringify(this.options.params), jQuery.post(this.options.url, JSON.stringify(this.options.params),
function(data) { function(data) {
this.options.data = jQuery.extend({}, this.options.data, data); this.options.data = jQuery.extend({}, this.options.data, data);
// load template using fetched data // load template using fetched data
@ -303,342 +303,342 @@ define('modal', ['mailpoet', 'jquery'],
}.bind(this), }.bind(this),
'json' 'json'
); );
} }
return this; return this;
}, },
setDimensions: function() { setDimensions: function() {
switch(this.options.type) { switch(this.options.type) {
case 'popup': case 'popup':
// set popup dimensions // set popup dimensions
jQuery('#mailpoet_popup').css({ jQuery('#mailpoet_popup').css({
width: this.options.width, width: this.options.width,
height: this.options.height height: this.options.height
}); });
// set popup wrapper height // set popup wrapper height
jQuery('#mailpoet_popup_wrapper').css({ jQuery('#mailpoet_popup_wrapper').css({
height: this.options.height height: this.options.height
}); });
break; break;
case 'panel': case 'panel':
// set dimensions // set dimensions
if(this.options.position === 'right') { if(this.options.position === 'right') {
jQuery('#mailpoet_panel').css({ jQuery('#mailpoet_panel').css({
width: this.options.width, width: this.options.width,
right: 0, right: 0,
marginRight: '-' + this.options.width, marginRight: '-' + this.options.width,
left: 'auto' left: 'auto'
}); });
} else if(this.options.position === 'left') { } else if(this.options.position === 'left') {
jQuery('#mailpoet_panel').css({ jQuery('#mailpoet_panel').css({
width: this.options.width, width: this.options.width,
left: 0, left: 0,
marginLeft: '-' + this.options.width, marginLeft: '-' + this.options.width,
right: 'auto' right: 'auto'
}); });
} }
jQuery('#mailpoet_panel').css({ minHeight: 'auto' }); jQuery('#mailpoet_panel').css({ minHeight: 'auto' });
break; break;
} }
return this; return this;
}, },
setPosition: function() { setPosition: function() {
switch(this.options.type) { switch(this.options.type) {
case 'popup': case 'popup':
var screenWidth = jQuery(window).width(), var screenWidth = jQuery(window).width(),
screenHeight = jQuery(window).height(), screenHeight = jQuery(window).height(),
modalWidth = jQuery('.mailpoet_'+ this.options.type +'_wrapper').width(), modalWidth = jQuery('.mailpoet_'+ this.options.type +'_wrapper').width(),
modalHeight = jQuery('.mailpoet_'+ this.options.type +'_wrapper').height(); modalHeight = jQuery('.mailpoet_'+ this.options.type +'_wrapper').height();
var top = Math.max(48, parseInt((screenHeight / 2) - (modalHeight / 2))), var top = Math.max(48, parseInt((screenHeight / 2) - (modalHeight / 2))),
left = Math.max(0, parseInt((screenWidth / 2) - (modalWidth / 2))); left = Math.max(0, parseInt((screenWidth / 2) - (modalWidth / 2)));
// set position of popup depending on screen dimensions. // set position of popup depending on screen dimensions.
jQuery('#mailpoet_popup').css({ jQuery('#mailpoet_popup').css({
top: top, top: top,
left: left left: left
}); });
break; break;
case 'panel': case 'panel':
setTimeout(function() { setTimeout(function() {
// set position of popup depending on screen dimensions. // set position of popup depending on screen dimensions.
if(this.options.position === 'right') { if(this.options.position === 'right') {
jQuery('#mailpoet_panel').css({ jQuery('#mailpoet_panel').css({
marginRight: 0 marginRight: 0
}); });
} else if(this.options.position === 'left') { } else if(this.options.position === 'left') {
jQuery('#mailpoet_panel').css({ jQuery('#mailpoet_panel').css({
marginLeft: 0 marginLeft: 0
}); });
} }
}.bind(this), 0); }.bind(this), 0);
break; break;
} }
return this; return this;
}, },
showModal: function() { showModal: function() {
// set modal dimensions // set modal dimensions
this.setDimensions(); this.setDimensions();
// remember the previously focused element // remember the previously focused element
this.prevFocus = jQuery(':focus'); this.prevFocus = jQuery(':focus');
// add a flag on the body so that we can prevent scrolling // add a flag on the body so that we can prevent scrolling
jQuery('body').addClass('mailpoet_modal_opened'); jQuery('body').addClass('mailpoet_modal_opened');
// show popup // show popup
jQuery('#mailpoet_'+this.options.type).show(); jQuery('#mailpoet_'+this.options.type).show();
// display overlay // display overlay
this.showOverlay(); this.showOverlay();
// set modal position // set modal position
this.setPosition(); this.setPosition();
// add class on highlighted elements // add class on highlighted elements
if(this.options.highlight !== null) { if(this.options.highlight !== null) {
if(this.options.highlight.length > 0) { if(this.options.highlight.length > 0) {
this.highlightOn(this.options.highlight); this.highlightOn(this.options.highlight);
}
} }
}
if(this.options.focus) {
this.focus();
}
// set popup as opened
this.opened = true;
// trigger init event if specified
if(this.options.onInit !== null) {
this.options.onInit(this);
}
return this;
},
focus: function() {
if(this.options.type == 'popup') {
jQuery('#mailpoet_'+this.options.type).focus();
} else {
// panel and subpanel
jQuery('#mailpoet_'+this.options.type+' .mailpoet_panel_wrapper')
.filter(':visible').focus();
}
return this;
},
highlightOn: function(element) {
jQuery(element).addClass('mailpoet_modal_highlight');
return this;
},
highlightOff: function() {
jQuery('.mailpoet_modal_highlight')
.removeClass('mailpoet_modal_highlight');
return this;
},
hideModal: function(callback) {
// set modal as closed
this.opened = false;
// hide modal
jQuery('#mailpoet_'+this.options.type).hide();
// remove class on highlighted elements
this.highlightOff();
// remove class from body to let it be scrollable
jQuery('body').removeClass('mailpoet_modal_opened');
return this;
},
showOverlay: function(force) {
jQuery('#mailpoet_modal_overlay').show();
return this;
},
hideOverlay: function() {
jQuery('#mailpoet_modal_overlay').hide();
return this;
},
popup: function(opts) {
// get options
var options = opts || {};
// set modal type
options.type = 'popup';
// set overlay state
options.overlay = options.overlay || true;
// initialize modal
this.init(options);
// open modal
this.open();
return this;
},
panel: function(opts) {
// get options
var options = opts || {};
// reset subpanels
this.subpanels = [];
// set modal type
options.type = 'panel';
// set overlay state
options.overlay = options.overlay || false;
// set highlighted element
options.highlight = options.highlight || null;
// set modal dimensions
options.width = options.width || '40%';
options.height = options.height || 'auto';
// initialize modal
this.init(options);
// open modal
this.open();
return this;
},
subpanel: function(options) {
if(this.opened === false) {
// if no panel is already opened, let's create one instead
this.panel(options);
} else {
// if a panel is already opened, add a sub panel to it
this.subpanels.push(options);
this.loadTemplate();
}
return this;
},
loading: function(toggle) {
// make sure the overlay is initialized and that it's visible
this.initOverlay(true);
if(toggle === true) {
this.showLoading();
} else {
this.hideLoading();
}
return this;
},
showLoading: function() {
jQuery('#mailpoet_loading').show();
// add loading class to overlay
jQuery('#mailpoet_modal_overlay')
.addClass('mailpoet_overlay_loading');
return this;
},
hideLoading: function() {
jQuery('#mailpoet_loading').hide();
// remove loading class from overlay
jQuery('#mailpoet_modal_overlay')
.removeClass('mailpoet_overlay_loading');
return this;
},
open: function() {
// load template if specified
if(this.options.template !== null) {
// check if a url was specified to get extra data
if(this.options.url !== null) {
this.loadUrl();
} else {
// load template
this.loadTemplate();
// show modal window
this.showModal();
}
} else {
this.cancel();
}
return this;
},
success: function() {
if(this.subpanels.length > 0) {
if(this.subpanels[(this.subpanels.length - 1)].onSuccess !== undefined) {
this.subpanels[(this.subpanels.length - 1)].onSuccess(this.subpanels[(this.subpanels.length - 1)].data);
}
} else {
if(this.options.onSuccess !== null) {
this.options.onSuccess(this.options.data);
}
}
this.close();
return this;
},
cancel: function() {
if(this.subpanels.length > 0) {
if(this.subpanels[(this.subpanels.length - 1)].onCancel !== undefined) {
this.subpanels[(this.subpanels.length - 1)].onCancel(this.subpanels[(this.subpanels.length - 1)].data);
}
} else {
if(this.options.onCancel !== null) {
this.options.onCancel(this.options.data);
}
}
this.close();
return this;
},
destroy: function() {
this.hideOverlay();
// remove extra modal
if(jQuery('#mailpoet_'+this.options.type).length > 0) {
jQuery('#mailpoet_'+this.options.type).remove();
}
this.initialized = false;
return this;
},
close: function() {
if(this.isLocked() === true) { return this; }
if(this.subpanels.length > 0) {
// close subpanel
jQuery('.mailpoet_'+this.options.type+'_wrapper').last().remove();
// show previous panel
jQuery('.mailpoet_'+this.options.type+'_wrapper').last().show();
// remove last subpanels
this.subpanels.pop();
// focus on previous panel
if(this.options.focus) { if(this.options.focus) {
this.focus(); this.focus();
} }
// set popup as opened
this.opened = true;
// trigger init event if specified
if(this.options.onInit !== null) {
this.options.onInit(this);
}
return this;
},
focus: function() {
if(this.options.type == 'popup') {
jQuery('#mailpoet_'+this.options.type).focus();
} else {
// panel and subpanel
jQuery('#mailpoet_'+this.options.type+' .mailpoet_panel_wrapper')
.filter(':visible').focus();
}
return this;
},
highlightOn: function(element) {
jQuery(element).addClass('mailpoet_modal_highlight');
return this;
},
highlightOff: function() {
jQuery('.mailpoet_modal_highlight')
.removeClass('mailpoet_modal_highlight');
return this;
},
hideModal: function(callback) {
// set modal as closed
this.opened = false;
// hide modal
jQuery('#mailpoet_'+this.options.type).hide();
// remove class on highlighted elements
this.highlightOff();
// remove class from body to let it be scrollable
jQuery('body').removeClass('mailpoet_modal_opened');
return this;
},
showOverlay: function(force) {
jQuery('#mailpoet_modal_overlay').show();
return this;
},
hideOverlay: function() {
jQuery('#mailpoet_modal_overlay').hide();
return this;
},
popup: function(opts) {
// get options
var options = opts || {};
// set modal type
options.type = 'popup';
// set overlay state
options.overlay = options.overlay || true;
// initialize modal
this.init(options);
// open modal
this.open();
return this;
},
panel: function(opts) {
// get options
var options = opts || {};
// reset subpanels
this.subpanels = [];
// set modal type
options.type = 'panel';
// set overlay state
options.overlay = options.overlay || false;
// set highlighted element
options.highlight = options.highlight || null;
// set modal dimensions
options.width = options.width || '40%';
options.height = options.height || 'auto';
// initialize modal
this.init(options);
// open modal
this.open();
return this;
},
subpanel: function(options) {
if(this.opened === false) {
// if no panel is already opened, let's create one instead
this.panel(options);
} else {
// if a panel is already opened, add a sub panel to it
this.subpanels.push(options);
this.loadTemplate();
}
return this;
},
loading: function(toggle) {
// make sure the overlay is initialized and that it's visible
this.initOverlay(true);
if(toggle === true) {
this.showLoading();
} else {
this.hideLoading();
}
return this;
},
showLoading: function() {
jQuery('#mailpoet_loading').show();
// add loading class to overlay
jQuery('#mailpoet_modal_overlay')
.addClass('mailpoet_overlay_loading');
return this;
},
hideLoading: function() {
jQuery('#mailpoet_loading').hide();
// remove loading class from overlay
jQuery('#mailpoet_modal_overlay')
.removeClass('mailpoet_overlay_loading');
return this;
},
open: function() {
// load template if specified
if(this.options.template !== null) {
// check if a url was specified to get extra data
if(this.options.url !== null) {
this.loadUrl();
} else {
// load template
this.loadTemplate();
// show modal window
this.showModal();
}
} else {
this.cancel();
}
return this;
},
success: function() {
if(this.subpanels.length > 0) {
if(this.subpanels[(this.subpanels.length - 1)].onSuccess !== undefined) {
this.subpanels[(this.subpanels.length - 1)].onSuccess(this.subpanels[(this.subpanels.length - 1)].data);
}
} else {
if(this.options.onSuccess !== null) {
this.options.onSuccess(this.options.data);
}
}
this.close();
return this;
},
cancel: function() {
if(this.subpanels.length > 0) {
if(this.subpanels[(this.subpanels.length - 1)].onCancel !== undefined) {
this.subpanels[(this.subpanels.length - 1)].onCancel(this.subpanels[(this.subpanels.length - 1)].data);
}
} else {
if(this.options.onCancel !== null) {
this.options.onCancel(this.options.data);
}
}
this.close();
return this;
},
destroy: function() {
this.hideOverlay();
// remove extra modal
if(jQuery('#mailpoet_'+this.options.type).length > 0) {
jQuery('#mailpoet_'+this.options.type).remove();
}
this.initialized = false;
return this;
},
close: function() {
if(this.isLocked() === true) { return this; }
if(this.subpanels.length > 0) {
// close subpanel
jQuery('.mailpoet_'+this.options.type+'_wrapper').last().remove();
// show previous panel
jQuery('.mailpoet_'+this.options.type+'_wrapper').last().show();
// remove last subpanels
this.subpanels.pop();
// focus on previous panel
if(this.options.focus) {
this.focus();
}
return this;
}
// remove event handlers
this.removeEvents();
// hide modal window
this.hideModal();
// destroy modal element
this.destroy();
// restore the previously focused element
if(this.prevFocus !== undefined){
this.prevFocus.focus();
}
// reset options
this.options = {
onSuccess: null,
onCancel: null
};
return this; return this;
} }
// remove event handlers
this.removeEvents();
// hide modal window
this.hideModal();
// destroy modal element
this.destroy();
// restore the previously focused element
if(this.prevFocus !== undefined){
this.prevFocus.focus();
}
// reset options
this.options = {
onSuccess: null,
onCancel: null
};
return this;
}
}; };
} }
); );

View File

@ -1,12 +1,12 @@
define([ define([
'backbone', 'backbone',
'backbone.marionette', 'backbone.marionette',
'backbone.radio', 'backbone.radio',
'jquery', 'jquery',
'underscore', 'underscore',
'handlebars', 'handlebars',
'handlebars_helpers' 'handlebars_helpers'
], function(Backbone, Marionette, BackboneRadio, jQuery, _, Handlebars) { ], function(Backbone, Marionette, BackboneRadio, jQuery, _, Handlebars) {
var Radio = BackboneRadio; var Radio = BackboneRadio;
var AppView = Marionette.View.extend({ var AppView = Marionette.View.extend({

View File

@ -5,8 +5,8 @@
* For more check: http://marionettejs.com/docs/marionette.behaviors.html#behaviorslookup * For more check: http://marionettejs.com/docs/marionette.behaviors.html#behaviorslookup
*/ */
define([ define([
'backbone.marionette' 'backbone.marionette'
], function(BackboneMarionette) { ], function(BackboneMarionette) {
var Marionette = BackboneMarionette; var Marionette = BackboneMarionette;
var BehaviorsLookup = {}; var BehaviorsLookup = {};
Marionette.Behaviors.behaviorsLookup = function() { Marionette.Behaviors.behaviorsLookup = function() {

View File

@ -4,11 +4,11 @@
* Adds a color picker integration with the view * Adds a color picker integration with the view
*/ */
define([ define([
'backbone.marionette', 'backbone.marionette',
'newsletter_editor/behaviors/BehaviorsLookup', 'newsletter_editor/behaviors/BehaviorsLookup',
'mailpoet', 'mailpoet',
'spectrum' 'spectrum'
], function(Marionette, BehaviorsLookup, MailPoet, Spectrum) { ], function(Marionette, BehaviorsLookup, MailPoet, Spectrum) {
var BL = BehaviorsLookup; var BL = BehaviorsLookup;
BL.ColorPickerBehavior = Marionette.Behavior.extend({ BL.ColorPickerBehavior = Marionette.Behavior.extend({

View File

@ -6,12 +6,12 @@
* accept droppables * accept droppables
*/ */
define([ define([
'backbone.marionette', 'backbone.marionette',
'underscore', 'underscore',
'jquery', 'jquery',
'newsletter_editor/behaviors/BehaviorsLookup', 'newsletter_editor/behaviors/BehaviorsLookup',
'interact' 'interact'
], function(Marionette, _, jQuery, BL, interact) { ], function(Marionette, _, jQuery, BL, interact) {
var BehaviorsLookup = BL; var BehaviorsLookup = BL;
BehaviorsLookup.ContainerDropZoneBehavior = Marionette.Behavior.extend({ BehaviorsLookup.ContainerDropZoneBehavior = Marionette.Behavior.extend({
@ -21,7 +21,7 @@ define([
onRender: function() { onRender: function() {
var dragAndDropDisabled = _.isObject(this.view.options.renderOptions) && this.view.options.renderOptions.disableDragAndDrop === true; var dragAndDropDisabled = _.isObject(this.view.options.renderOptions) && this.view.options.renderOptions.disableDragAndDrop === true;
if (!dragAndDropDisabled) { if (!dragAndDropDisabled) {
this.addDropZone(); this.addDropZone();
} }
}, },
addDropZone: function(_event) { addDropZone: function(_event) {
@ -196,7 +196,7 @@ define([
if (view.model.get('orientation') === 'horizontal' && droppableModel.get('type') !== 'container') { if (view.model.get('orientation') === 'horizontal' && droppableModel.get('type') !== 'container') {
// Regular blocks always need to be inserted into columns - vertical containers // Regular blocks always need to be inserted into columns - vertical containers
tempCollection = new (EditorApplication.getBlockTypeModel('container'))({ tempCollection = new (EditorApplication.getBlockTypeModel('container'))({
orientation: 'vertical' orientation: 'vertical'
}); });
tempCollection.get('blocks').add(droppableModel); tempCollection.get('blocks').add(droppableModel);
viewCollection.add(tempCollection, {at: index}); viewCollection.add(tempCollection, {at: index});
@ -211,7 +211,7 @@ define([
var tempModel = viewCollection.at(dropPosition.index); var tempModel = viewCollection.at(dropPosition.index);
tempCollection = new (EditorApplication.getBlockTypeModel('container'))({ tempCollection = new (EditorApplication.getBlockTypeModel('container'))({
orientation: (view.model.get('orientation') === 'vertical') ? 'horizontal' : 'vertical' orientation: (view.model.get('orientation') === 'vertical') ? 'horizontal' : 'vertical'
}); });
viewCollection.remove(tempModel); viewCollection.remove(tempModel);
@ -377,14 +377,14 @@ define([
if (eventOffset <= closeOffset + elementDimension / 2) { if (eventOffset <= closeOffset + elementDimension / 2) {
// First half of the element // First half of the element
return { return {
index: index, index: index,
position: 'before' position: 'before'
}; };
} else { } else {
// Second half of the element // Second half of the element
return { return {
index: index, index: index,
position: 'after' position: 'after'
}; };
} }
}, },

View File

@ -5,12 +5,12 @@
* Part of the drag&drop behavior. * Part of the drag&drop behavior.
*/ */
define([ define([
'backbone.marionette', 'backbone.marionette',
'underscore', 'underscore',
'jquery', 'jquery',
'newsletter_editor/behaviors/BehaviorsLookup', 'newsletter_editor/behaviors/BehaviorsLookup',
'interact' 'interact'
], function(Marionette, _, jQuery, BehaviorsLookup, interact) { ], function(Marionette, _, jQuery, BehaviorsLookup, interact) {
var BL = BehaviorsLookup; var BL = BehaviorsLookup;
BL.DraggableBehavior = Marionette.Behavior.extend({ BL.DraggableBehavior = Marionette.Behavior.extend({
@ -33,13 +33,13 @@ define([
}, },
onRender: function() { onRender: function() {
var that = this, var that = this,
interactable; interactable;
// Give instances more control over whether Draggable should be applied // Give instances more control over whether Draggable should be applied
if (!this.options.testAttachToInstance(this.view.model, this.view)) return; if (!this.options.testAttachToInstance(this.view.model, this.view)) return;
interactable = interact(this.$el.get(0), { interactable = interact(this.$el.get(0), {
ignoreFrom: this.options.ignoreSelector ignoreFrom: this.options.ignoreSelector
}).draggable({ }).draggable({
// allow dragging of multple elements at the same time // allow dragging of multple elements at the same time
max: Infinity, max: Infinity,

View File

@ -4,9 +4,9 @@
* Highlights a block that is being edited * Highlights a block that is being edited
*/ */
define([ define([
'backbone.marionette', 'backbone.marionette',
'newsletter_editor/behaviors/BehaviorsLookup' 'newsletter_editor/behaviors/BehaviorsLookup'
], function(Marionette, BehaviorsLookup) { ], function(Marionette, BehaviorsLookup) {
var BL = BehaviorsLookup; var BL = BehaviorsLookup;
BL.HighlightEditingBehavior = Marionette.Behavior.extend({ BL.HighlightEditingBehavior = Marionette.Behavior.extend({

View File

@ -4,10 +4,10 @@
* Allows resizing elements within a block * Allows resizing elements within a block
*/ */
define([ define([
'backbone.marionette', 'backbone.marionette',
'newsletter_editor/behaviors/BehaviorsLookup', 'newsletter_editor/behaviors/BehaviorsLookup',
'interact' 'interact'
], function(Marionette, BehaviorsLookup, interact) { ], function(Marionette, BehaviorsLookup, interact) {
var BL = BehaviorsLookup; var BL = BehaviorsLookup;
BL.ResizableBehavior = Marionette.Behavior.extend({ BL.ResizableBehavior = Marionette.Behavior.extend({
@ -31,7 +31,7 @@ define([
}, },
attachResize: function() { attachResize: function() {
var domElement = (this.options.elementSelector === null) ? this.view.$el.get(0) : this.view.$(this.options.elementSelector).get(0), var domElement = (this.options.elementSelector === null) ? this.view.$el.get(0) : this.view.$(this.options.elementSelector).get(0),
that = this; that = this;
interact(domElement).resizable({ interact(domElement).resizable({
//axis: 'y', //axis: 'y',
edges: { edges: {

View File

@ -4,10 +4,10 @@
* Opens up settings of a BlockView if contents are clicked upon * Opens up settings of a BlockView if contents are clicked upon
*/ */
define([ define([
'backbone.marionette', 'backbone.marionette',
'jquery', 'jquery',
'newsletter_editor/behaviors/BehaviorsLookup' 'newsletter_editor/behaviors/BehaviorsLookup'
], function(Marionette, jQuery, BehaviorsLookup) { ], function(Marionette, jQuery, BehaviorsLookup) {
var BL = BehaviorsLookup; var BL = BehaviorsLookup;
BL.ShowSettingsBehavior = Marionette.Behavior.extend({ BL.ShowSettingsBehavior = Marionette.Behavior.extend({

View File

@ -4,10 +4,10 @@
* Allows sorting elements within a collection * Allows sorting elements within a collection
*/ */
define([ define([
'backbone.marionette', 'backbone.marionette',
'underscore', 'underscore',
'newsletter_editor/behaviors/BehaviorsLookup' 'newsletter_editor/behaviors/BehaviorsLookup'
], function(Marionette, _, BehaviorsLookup) { ], function(Marionette, _, BehaviorsLookup) {
var BL = BehaviorsLookup; var BL = BehaviorsLookup;
BL.SortableBehavior = Marionette.Behavior.extend({ BL.SortableBehavior = Marionette.Behavior.extend({

View File

@ -4,10 +4,10 @@
* Adds TinyMCE text editing capabilities to a view * Adds TinyMCE text editing capabilities to a view
*/ */
define([ define([
'backbone.marionette', 'backbone.marionette',
'underscore', 'underscore',
'newsletter_editor/behaviors/BehaviorsLookup' 'newsletter_editor/behaviors/BehaviorsLookup'
], function(Marionette, _, BehaviorsLookup) { ], function(Marionette, _, BehaviorsLookup) {
var BL = BehaviorsLookup; var BL = BehaviorsLookup;
BL.TextEditorBehavior = Marionette.Behavior.extend({ BL.TextEditorBehavior = Marionette.Behavior.extend({
@ -73,7 +73,7 @@ define([
editor.on('focus', function(e) { editor.on('focus', function(e) {
that.view.triggerMethod('text:editor:focus'); that.view.triggerMethod('text:editor:focus');
that._isActivationClick = true; that._isActivationClick = true;
}); });
editor.on('blur', function(e) { editor.on('blur', function(e) {

View File

@ -7,31 +7,31 @@
* block settings view. * block settings view.
*/ */
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/blocks/base', 'newsletter_editor/blocks/base',
'newsletter_editor/blocks/button', 'newsletter_editor/blocks/button',
'newsletter_editor/blocks/divider', 'newsletter_editor/blocks/divider',
'newsletter_editor/components/communication', 'newsletter_editor/components/communication',
'mailpoet', 'mailpoet',
'backbone.supermodel', 'backbone.supermodel',
'underscore', 'underscore',
'jquery' 'jquery'
], function( ], function(
App, App,
BaseBlock, BaseBlock,
ButtonBlock, ButtonBlock,
DividerBlock, DividerBlock,
CommunicationComponent, CommunicationComponent,
MailPoet, MailPoet,
SuperModel, SuperModel,
_, _,
jQuery jQuery
) { ) {
'use strict'; 'use strict';
var Module = {}, var Module = {},
base = BaseBlock; base = BaseBlock;
Module.ALCSupervisor = SuperModel.extend({ Module.ALCSupervisor = SuperModel.extend({
initialize: function() { initialize: function() {
@ -61,7 +61,7 @@ define([
_.zip(models, renderedBlocks), _.zip(models, renderedBlocks),
function(args) { function(args) {
var model = args[0], var model = args[0],
contents = args[1]; contents = args[1];
model.trigger('refreshPosts', contents); model.trigger('refreshPosts', contents);
} }
); );
@ -350,7 +350,7 @@ define([
}, },
_updateContentTypes: function(postTypes) { _updateContentTypes: function(postTypes) {
var select = this.$('.mailpoet_automated_latest_content_content_type'), var select = this.$('.mailpoet_automated_latest_content_content_type'),
selectedValue = this.model.get('contentType'); selectedValue = this.model.get('contentType');
select.find('option').remove(); select.find('option').remove();
_.each(postTypes, function(type) { _.each(postTypes, function(type) {

View File

@ -5,19 +5,19 @@
* BlockToolsView, BlockSettingsView and BlockWidgetView are optional. * BlockToolsView, BlockSettingsView and BlockWidgetView are optional.
*/ */
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'backbone.marionette', 'backbone.marionette',
'backbone.supermodel', 'backbone.supermodel',
'underscore', 'underscore',
'jquery', 'jquery',
'mailpoet', 'mailpoet',
'modal' 'modal'
], function(App, Marionette, SuperModel, _, jQuery, MailPoet, Modal) { ], function(App, Marionette, SuperModel, _, jQuery, MailPoet, Modal) {
'use strict'; 'use strict';
var Module = {}, var Module = {},
AugmentedView = Marionette.View.extend({}); AugmentedView = Marionette.View.extend({});
Module.BlockModel = SuperModel.extend({ Module.BlockModel = SuperModel.extend({
stale: [], // Attributes to be removed upon saving stale: [], // Attributes to be removed upon saving

View File

@ -2,17 +2,17 @@
* Button content block * Button content block
*/ */
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/blocks/base', 'newsletter_editor/blocks/base',
'mailpoet', 'mailpoet',
'underscore', 'underscore',
'jquery' 'jquery'
], function(App, BaseBlock, MailPoet, _, jQuery) { ], function(App, BaseBlock, MailPoet, _, jQuery) {
'use strict'; 'use strict';
var Module = {}, var Module = {},
base = BaseBlock; base = BaseBlock;
Module.ButtonBlockModel = base.BlockModel.extend({ Module.ButtonBlockModel = base.BlockModel.extend({
defaults: function() { defaults: function() {

View File

@ -4,19 +4,19 @@
* as other containers. * as other containers.
*/ */
define([ define([
'backbone', 'backbone',
'backbone.marionette', 'backbone.marionette',
'underscore', 'underscore',
'jquery', 'jquery',
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/blocks/base' 'newsletter_editor/blocks/base'
], function(Backbone, Marionette, _, jQuery, App, BaseBlock) { ], function(Backbone, Marionette, _, jQuery, App, BaseBlock) {
'use strict'; 'use strict';
var Module = {}, var Module = {},
base = BaseBlock, base = BaseBlock,
BlockCollection; BlockCollection;
BlockCollection = Backbone.Collection.extend({ BlockCollection = Backbone.Collection.extend({
model: base.BlockModel, model: base.BlockModel,

View File

@ -2,17 +2,17 @@
* Divider content block * Divider content block
*/ */
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/blocks/base', 'newsletter_editor/blocks/base',
'underscore', 'underscore',
'jquery', 'jquery',
'mailpoet' 'mailpoet'
], function(App, BaseBlock, _, jQuery, MailPoet) { ], function(App, BaseBlock, _, jQuery, MailPoet) {
'use strict'; 'use strict';
var Module = {}, var Module = {},
base = BaseBlock; base = BaseBlock;
Module.DividerBlockModel = base.BlockModel.extend({ Module.DividerBlockModel = base.BlockModel.extend({
defaults: function() { defaults: function() {

View File

@ -2,15 +2,15 @@
* Footer content block * Footer content block
*/ */
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/blocks/base', 'newsletter_editor/blocks/base',
'underscore' 'underscore'
], function(App, BaseBlock, _) { ], function(App, BaseBlock, _) {
'use strict'; 'use strict';
var Module = {}, var Module = {},
base = BaseBlock; base = BaseBlock;
Module.FooterBlockModel = base.BlockModel.extend({ Module.FooterBlockModel = base.BlockModel.extend({
defaults: function() { defaults: function() {
@ -83,8 +83,8 @@ define([
'change .mailpoet_field_footer_text_size': _.partial(this.changeField, 'styles.text.fontSize'), 'change .mailpoet_field_footer_text_size': _.partial(this.changeField, 'styles.text.fontSize'),
'change #mailpoet_field_footer_link_color': _.partial(this.changeColorField, 'styles.link.fontColor'), 'change #mailpoet_field_footer_link_color': _.partial(this.changeColorField, 'styles.link.fontColor'),
'change #mailpoet_field_footer_link_underline': function(event) { 'change #mailpoet_field_footer_link_underline': function(event) {
this.model.set('styles.link.textDecoration', (event.target.checked) ? event.target.value : 'none'); this.model.set('styles.link.textDecoration', (event.target.checked) ? event.target.value : 'none');
}, },
'change .mailpoet_field_footer_background_color': _.partial(this.changeColorField, 'styles.block.backgroundColor'), 'change .mailpoet_field_footer_background_color': _.partial(this.changeColorField, 'styles.block.backgroundColor'),
'change .mailpoet_field_footer_alignment': _.partial(this.changeField, 'styles.text.textAlign'), 'change .mailpoet_field_footer_alignment': _.partial(this.changeField, 'styles.text.textAlign'),
'click .mailpoet_done_editing': 'close' 'click .mailpoet_done_editing': 'close'

View File

@ -2,15 +2,15 @@
* Header content block * Header content block
*/ */
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/blocks/base', 'newsletter_editor/blocks/base',
'underscore' 'underscore'
], function(App, BaseBlock, _) { ], function(App, BaseBlock, _) {
'use strict'; 'use strict';
var Module = {}, var Module = {},
base = BaseBlock; base = BaseBlock;
Module.HeaderBlockModel = base.BlockModel.extend({ Module.HeaderBlockModel = base.BlockModel.extend({
defaults: function() { defaults: function() {

View File

@ -2,17 +2,17 @@
* Image content block * Image content block
*/ */
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/blocks/base', 'newsletter_editor/blocks/base',
'underscore', 'underscore',
'mailpoet' 'mailpoet'
], function(App, BaseBlock, _, MailPoet) { ], function(App, BaseBlock, _, MailPoet) {
'use strict'; 'use strict';
var Module = {}, var Module = {},
base = BaseBlock, base = BaseBlock,
ImageWidgetView; ImageWidgetView;
Module.ImageBlockModel = base.BlockModel.extend({ Module.ImageBlockModel = base.BlockModel.extend({
defaults: function() { defaults: function() {
@ -176,14 +176,14 @@ define([
this.on('updateExcluded', this.browseContent, this); this.on('updateExcluded', this.browseContent, this);
var handlers = { var handlers = {
content: { content: {
embed: 'embedContent', embed: 'embedContent',
'edit-selection': 'editSelectionContent' 'edit-selection': 'editSelectionContent'
}, },
toolbar: { toolbar: {
'main-insert': 'mainInsertToolbar' 'main-insert': 'mainInsertToolbar'
} }
}; };
_.each(handlers, function(regionHandlers, region) { _.each(handlers, function(regionHandlers, region) {
_.each(regionHandlers, function(callback, handler) { _.each(regionHandlers, function(callback, handler) {
@ -301,9 +301,9 @@ define([
} }
}), }),
that = this; that = this;
this._mediaManager = theFrame; this._mediaManager = theFrame;
this._mediaManager.on('insert', function() { this._mediaManager.on('insert', function() {
// Append media manager image selections to Images tab // Append media manager image selections to Images tab
var selection = theFrame.state().get('selection'); var selection = theFrame.state().get('selection');
selection.each(function(attachment) { selection.each(function(attachment) {

View File

@ -11,36 +11,36 @@
* block settings view. * block settings view.
*/ */
define([ define([
'backbone', 'backbone',
'backbone.marionette', 'backbone.marionette',
'backbone.radio', 'backbone.radio',
'underscore', 'underscore',
'jquery', 'jquery',
'mailpoet', 'mailpoet',
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/components/communication', 'newsletter_editor/components/communication',
'newsletter_editor/blocks/base', 'newsletter_editor/blocks/base',
'newsletter_editor/blocks/button', 'newsletter_editor/blocks/button',
'newsletter_editor/blocks/divider', 'newsletter_editor/blocks/divider',
'select2' 'select2'
], function( ], function(
Backbone, Backbone,
Marionette, Marionette,
Radio, Radio,
_, _,
jQuery, jQuery,
MailPoet, MailPoet,
App, App,
CommunicationComponent, CommunicationComponent,
BaseBlock, BaseBlock,
ButtonBlock, ButtonBlock,
DividerBlock DividerBlock
) { ) {
'use strict'; 'use strict';
var Module = {}, var Module = {},
base = BaseBlock; base = BaseBlock;
Module.PostsBlockModel = base.BlockModel.extend({ Module.PostsBlockModel = base.BlockModel.extend({
stale: ['_selectedPosts', '_availablePosts', '_transformedPosts'], stale: ['_selectedPosts', '_availablePosts', '_transformedPosts'],
@ -414,7 +414,7 @@ define([
}, },
_updateContentTypes: function(postTypes) { _updateContentTypes: function(postTypes) {
var select = this.$('.mailpoet_settings_posts_content_type'), var select = this.$('.mailpoet_settings_posts_content_type'),
selectedValue = this.model.get('contentType'); selectedValue = this.model.get('contentType');
select.find('option').remove(); select.find('option').remove();
_.each(postTypes, function(type) { _.each(postTypes, function(type) {

View File

@ -2,23 +2,23 @@
* Social icons content block * Social icons content block
*/ */
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/blocks/base', 'newsletter_editor/blocks/base',
'backbone', 'backbone',
'backbone.marionette', 'backbone.marionette',
'backbone.supermodel', 'backbone.supermodel',
'underscore', 'underscore',
'jquery' 'jquery'
], function(App, BaseBlock, Backbone, Marionette, SuperModel, _, jQuery) { ], function(App, BaseBlock, Backbone, Marionette, SuperModel, _, jQuery) {
'use strict'; 'use strict';
var Module = {}, var Module = {},
base = BaseBlock, base = BaseBlock,
SocialBlockSettingsIconSelectorView, SocialBlockSettingsIconSelectorView,
SocialBlockSettingsIconView, SocialBlockSettingsIconView,
SocialBlockSettingsIconCollectionView, SocialBlockSettingsIconCollectionView,
SocialBlockSettingsStylesView; SocialBlockSettingsStylesView;
Module.SocialIconModel = SuperModel.extend({ Module.SocialIconModel = SuperModel.extend({
defaults: function() { defaults: function() {

View File

@ -2,15 +2,15 @@
* Spacer content block * Spacer content block
*/ */
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/blocks/base', 'newsletter_editor/blocks/base',
'underscore' 'underscore'
], function(App, BaseBlock, _) { ], function(App, BaseBlock, _) {
'use strict'; 'use strict';
var Module = {}, var Module = {},
base = BaseBlock; base = BaseBlock;
Module.SpacerBlockModel = base.BlockModel.extend({ Module.SpacerBlockModel = base.BlockModel.extend({
defaults: function() { defaults: function() {

View File

@ -2,15 +2,15 @@
* Text content block * Text content block
*/ */
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/blocks/base', 'newsletter_editor/blocks/base',
'underscore' 'underscore'
], function(App, BaseBlock, _) { ], function(App, BaseBlock, _) {
'use strict'; 'use strict';
var Module = {}, var Module = {},
base = BaseBlock; base = BaseBlock;
Module.TextBlockModel = base.BlockModel.extend({ Module.TextBlockModel = base.BlockModel.extend({
defaults: function() { defaults: function() {

View File

@ -1,9 +1,9 @@
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'underscore', 'underscore',
'mailpoet', 'mailpoet',
'ajax' 'ajax'
], function(App, _, MailPoet) { ], function(App, _, MailPoet) {
var Module = {}; var Module = {};

View File

@ -1,7 +1,7 @@
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'backbone.supermodel' 'backbone.supermodel'
], function(App, SuperModel) { ], function(App, SuperModel) {
var Module = {}; var Module = {};

View File

@ -1,9 +1,9 @@
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'backbone.supermodel', 'backbone.supermodel',
'underscore', 'underscore',
'mailpoet' 'mailpoet'
], function(App, SuperModel, _, MailPoet) { ], function(App, SuperModel, _, MailPoet) {
'use strict'; 'use strict';
var Module = {}; var Module = {};
@ -15,7 +15,7 @@ define([
whitelisted: ['id', 'subject', 'preheader'], whitelisted: ['id', 'subject', 'preheader'],
initialize: function(options) { initialize: function(options) {
this.on('change', function() { this.on('change', function() {
App.getChannel().trigger('autoSave'); App.getChannel().trigger('autoSave');
}); });
}, },
toJSON: function() { toJSON: function() {
@ -59,7 +59,7 @@ define([
}; };
Module.getNewsletter = function() { Module.getNewsletter = function() {
return Module.newsletter; return Module.newsletter;
}; };
Module.findModels = function(predicate) { Module.findModels = function(predicate) {

View File

@ -1,10 +1,10 @@
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'backbone', 'backbone',
'backbone.marionette', 'backbone.marionette',
'underscore', 'underscore',
'jquery' 'jquery'
], function(App, Backbone, Marionette, _, jQuery) { ], function(App, Backbone, Marionette, _, jQuery) {
'use strict'; 'use strict';

View File

@ -1,31 +1,31 @@
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/components/communication', 'newsletter_editor/components/communication',
'mailpoet', 'mailpoet',
'notice', 'notice',
'backbone', 'backbone',
'backbone.marionette', 'backbone.marionette',
'jquery', 'jquery',
'blob', 'blob',
'file-saver', 'file-saver',
'html2canvas' 'html2canvas'
], function( ], function(
App, App,
CommunicationComponent, CommunicationComponent,
MailPoet, MailPoet,
Notice, Notice,
Backbone, Backbone,
Marionette, Marionette,
jQuery, jQuery,
Blob, Blob,
FileSaver, FileSaver,
html2canvas html2canvas
) { ) {
'use strict'; 'use strict';
var Module = {}, var Module = {},
saveTimeout; saveTimeout;
// Save editor contents to server // Save editor contents to server
Module.save = function() { Module.save = function() {
@ -73,9 +73,9 @@ define([
// Removes 1px left transparent border from resulting canvas. // Removes 1px left transparent border from resulting canvas.
var oldContext = oldCanvas.getContext('2d'), var oldContext = oldCanvas.getContext('2d'),
newCanvas = document.createElement('canvas'), newCanvas = document.createElement('canvas'),
newContext = newCanvas.getContext('2d'), newContext = newCanvas.getContext('2d'),
leftBorderWidth = 1; leftBorderWidth = 1;
newCanvas.width = oldCanvas.width; newCanvas.width = oldCanvas.width;
newCanvas.height = oldCanvas.height; newCanvas.height = oldCanvas.height;
@ -92,7 +92,7 @@ define([
Module.saveTemplate = function(options) { Module.saveTemplate = function(options) {
var that = this, var that = this,
promise = jQuery.Deferred(); promise = jQuery.Deferred();
promise.then(function(thumbnail) { promise.then(function(thumbnail) {
var data = _.extend(options || {}, { var data = _.extend(options || {}, {
@ -189,8 +189,8 @@ define([
}, },
saveAsTemplate: function() { saveAsTemplate: function() {
var templateName = this.$('.mailpoet_save_as_template_name').val(), var templateName = this.$('.mailpoet_save_as_template_name').val(),
templateDescription = this.$('.mailpoet_save_as_template_description').val(), templateDescription = this.$('.mailpoet_save_as_template_description').val(),
that = this; that = this;
if (templateName === '') { if (templateName === '') {
MailPoet.Notice.error( MailPoet.Notice.error(
@ -245,8 +245,8 @@ define([
}, },
exportTemplate: function() { exportTemplate: function() {
var templateName = this.$('.mailpoet_export_template_name').val(), var templateName = this.$('.mailpoet_export_template_name').val(),
templateDescription = this.$('.mailpoet_export_template_description').val(), templateDescription = this.$('.mailpoet_export_template_description').val(),
that = this; that = this;
if (templateName === '') { if (templateName === '') {
MailPoet.Notice.error( MailPoet.Notice.error(

View File

@ -1,23 +1,23 @@
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/components/communication', 'newsletter_editor/components/communication',
'mailpoet', 'mailpoet',
'backbone', 'backbone',
'backbone.marionette', 'backbone.marionette',
'backbone.supermodel', 'backbone.supermodel',
'underscore', 'underscore',
'jquery', 'jquery',
'sticky-kit' 'sticky-kit'
], function( ], function(
App, App,
CommunicationComponent, CommunicationComponent,
MailPoet, MailPoet,
Backbone, Backbone,
Marionette, Marionette,
SuperModel, SuperModel,
_, _,
jQuery, jQuery,
StickyKit StickyKit
) { ) {
'use strict'; 'use strict';

View File

@ -1,8 +1,8 @@
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'backbone.marionette', 'backbone.marionette',
'backbone.supermodel' 'backbone.supermodel'
], function(App, Marionette, SuperModel) { ], function(App, Marionette, SuperModel) {
'use strict'; 'use strict';

View File

@ -75,7 +75,7 @@ define('notice', ['mailpoet', 'jquery'], function(mp, jQuery) {
// setup onClose callback // setup onClose callback
var onClose = null; var onClose = null;
if (this.options.onClose !== null) { if (this.options.onClose !== null) {
onClose = this.options.onClose; onClose = this.options.onClose;
} }
// listen to remove event // listen to remove event
@ -83,7 +83,7 @@ define('notice', ['mailpoet', 'jquery'], function(mp, jQuery) {
jQuery(this).fadeOut(200, function() { jQuery(this).fadeOut(200, function() {
// on close callback // on close callback
if (onClose !== null) { if (onClose !== null) {
onClose(); onClose();
} }
// remove notice // remove notice
jQuery(this).remove(); jQuery(this).remove();
@ -144,13 +144,13 @@ define('notice', ['mailpoet', 'jquery'], function(mp, jQuery) {
switch (this.options.type) { switch (this.options.type) {
case 'success': case 'success':
this.element.addClass('notice notice-success'); this.element.addClass('notice notice-success');
break; break;
case 'system': case 'system':
this.element.addClass('notice notice-warning'); this.element.addClass('notice notice-warning');
break; break;
case 'error': case 'error':
this.element.addClass('notice notice-error'); this.element.addClass('notice notice-error');
break; break;
} }
// make the notice appear // make the notice appear
@ -167,7 +167,7 @@ define('notice', ['mailpoet', 'jquery'], function(mp, jQuery) {
} else if (this.options.hideClose === false) { } else if (this.options.hideClose === false) {
this.element.append('<a href="javascript:;" class="mailpoet_notice_close"><span class="dashicons dashicons-dismiss"></span></a>'); this.element.append('<a href="javascript:;" class="mailpoet_notice_close"><span class="dashicons dashicons-dismiss"></span></a>');
this.element.find('.mailpoet_notice_close').on('click', function() { this.element.find('.mailpoet_notice_close').on('click', function() {
jQuery(this).trigger('close'); jQuery(this).trigger('close');
}); });
} }

View File

@ -4,19 +4,19 @@ define('num',
], function( ], function(
mp mp
) { ) {
'use strict'; 'use strict';
var MailPoet = mp; var MailPoet = mp;
MailPoet.Num = { MailPoet.Num = {
toLocaleFixed: function (num, precisionOpts) { toLocaleFixed: function (num, precisionOpts) {
var precision = precisionOpts || 0; var precision = precisionOpts || 0;
var factor = Math.pow(10, precision); var factor = Math.pow(10, precision);
return (Math.round(num * factor) / factor) return (Math.round(num * factor) / factor)
.toLocaleString( .toLocaleString(
undefined, undefined,
{minimumFractionDigits: precision, maximumFractionDigits: precision} {minimumFractionDigits: precision, maximumFractionDigits: precision}
); );
} }
}; };
}); });

View File

@ -1,17 +1,17 @@
define( define(
[ [
'underscore', 'underscore',
'jquery', 'jquery',
'mailpoet', 'mailpoet',
'handlebars', 'handlebars',
'select2' 'select2'
], ],
function ( function (
_, _,
jQuery, jQuery,
MailPoet, MailPoet,
Handlebars, Handlebars,
select2 select2
) { ) {
if (!jQuery('#mailpoet_subscribers_export').length) { if (!jQuery('#mailpoet_subscribers_export').length) {
return; return;
@ -28,17 +28,17 @@ define(
// define reusable variables // define reusable variables
var segmentsContainerElement = jQuery('#export_lists'), var segmentsContainerElement = jQuery('#export_lists'),
subscriberFieldsContainerElement = jQuery('#export_columns'), subscriberFieldsContainerElement = jQuery('#export_columns'),
exportConfirmedOptionElement = jQuery(':radio[name="option_confirmed"]'), exportConfirmedOptionElement = jQuery(':radio[name="option_confirmed"]'),
groupBySegmentOptionElement = jQuery(':checkbox[name="option_group_by_list"]'), groupBySegmentOptionElement = jQuery(':checkbox[name="option_group_by_list"]'),
nextStepButton = jQuery('a.mailpoet_export_process'), nextStepButton = jQuery('a.mailpoet_export_process'),
renderSegmentsAndFields = function (container, data) { renderSegmentsAndFields = function (container, data) {
if (container.data('select2')) { if (container.data('select2')) {
container container
.html('') .html('')
.select2('destroy'); .select2('destroy');
} }
container container
.select2({ .select2({
data: data, data: data,
width: '20em', width: '20em',
@ -55,11 +55,11 @@ define(
}) })
.on('select2:selecting', function (selectEvent) { .on('select2:selecting', function (selectEvent) {
var selectElement = this, var selectElement = this,
selectedOptionId = selectEvent.params.args.data.id, selectedOptionId = selectEvent.params.args.data.id,
fieldsToExclude = [ fieldsToExclude = [
'select', 'select',
'deselect' 'deselect'
]; ];
if (_.contains(fieldsToExclude, selectedOptionId)) { if (_.contains(fieldsToExclude, selectedOptionId)) {
selectEvent.preventDefault(); selectEvent.preventDefault();
if (selectedOptionId === 'deselect') { if (selectedOptionId === 'deselect') {
@ -94,7 +94,7 @@ define(
jQuery('.mailpoet_group_by_list').hide(); jQuery('.mailpoet_group_by_list').hide();
} }
}); });
}; };
// set confirmed subscribers export option to false // set confirmed subscribers export option to false
exportData.exportConfirmedOption = false; exportData.exportConfirmedOption = false;
@ -139,39 +139,39 @@ define(
MailPoet.Modal.loading(true); MailPoet.Modal.loading(true);
var exportFormat = jQuery(':radio[name="option_format"]:checked').val(); var exportFormat = jQuery(':radio[name="option_format"]:checked').val();
MailPoet.Ajax.post({ MailPoet.Ajax.post({
api_version: window.mailpoet_api_version, api_version: window.mailpoet_api_version,
endpoint: 'ImportExport', endpoint: 'ImportExport',
action: 'processExport', action: 'processExport',
data: JSON.stringify({ data: JSON.stringify({
export_confirmed_option: exportData.exportConfirmedOption, export_confirmed_option: exportData.exportConfirmedOption,
export_format_option: exportFormat, export_format_option: exportFormat,
group_by_segment_option: (groupBySegmentOptionElement.is(':visible')) ? groupBySegmentOptionElement.prop('checked') : false, group_by_segment_option: (groupBySegmentOptionElement.is(':visible')) ? groupBySegmentOptionElement.prop('checked') : false,
segments: (exportData.segments) ? segmentsContainerElement.val() : false, segments: (exportData.segments) ? segmentsContainerElement.val() : false,
subscriber_fields: subscriberFieldsContainerElement.val() subscriber_fields: subscriberFieldsContainerElement.val()
}) })
}).always(function(response) { }).always(function(response) {
MailPoet.Modal.loading(false); MailPoet.Modal.loading(false);
}).done(function(response) { }).done(function(response) {
resultMessage = MailPoet.I18n.t('exportMessage') resultMessage = MailPoet.I18n.t('exportMessage')
.replace('%1$s', '<strong>' + parseInt(response.data.totalExported).toLocaleString() + '</strong>') .replace('%1$s', '<strong>' + parseInt(response.data.totalExported).toLocaleString() + '</strong>')
.replace('[link]', '<a href="' + response.data.exportFileURL + '" target="_blank" >') .replace('[link]', '<a href="' + response.data.exportFileURL + '" target="_blank" >')
.replace('[/link]', '</a>'); .replace('[/link]', '</a>');
jQuery('#export_result_notice').html('<p>' + resultMessage + '</p>').show(); jQuery('#export_result_notice').html('<p>' + resultMessage + '</p>').show();
window.location.href = response.data.exportFileURL; window.location.href = response.data.exportFileURL;
MailPoet.trackEvent('Subscribers export completed', { MailPoet.trackEvent('Subscribers export completed', {
'Total exported': response.data.totalExported, 'Total exported': response.data.totalExported,
'Only confirmed?': exportData.exportConfirmedOption, 'Only confirmed?': exportData.exportConfirmedOption,
'File Format': exportFormat, 'File Format': exportFormat,
'MailPoet Free version': window.mailpoet_version 'MailPoet Free version': window.mailpoet_version
}); });
}).fail(function(response) { }).fail(function(response) {
if (response.errors.length > 0) { if (response.errors.length > 0) {
MailPoet.Notice.error( MailPoet.Notice.error(
response.errors.map(function(error) { return error.message; }), response.errors.map(function(error) { return error.message; }),
{ scroll: true } { scroll: true }
); );
} }
}); });
}); });
}); });
}); });

View File

@ -1,15 +1,15 @@
define( define(
[ [
'backbone', 'backbone',
'underscore', 'underscore',
'jquery', 'jquery',
'mailpoet', 'mailpoet',
'handlebars', 'handlebars',
'papaparse', 'papaparse',
'asyncqueue', 'asyncqueue',
'moment', 'moment',
'select2' 'select2'
], ],
function ( function (
Backbone, Backbone,
_, _,
@ -69,21 +69,21 @@ define(
// define reusable variables // define reusable variables
var currentStepE = jQuery(location.hash), var currentStepE = jQuery(location.hash),
methodSelectionElement = jQuery('#select_method'), methodSelectionElement = jQuery('#select_method'),
pasteInputElement = jQuery('#paste_input'), pasteInputElement = jQuery('#paste_input'),
pasteInputPlaceholderElement = pasteInputPlaceholderElement =
pasteInputElement.data('placeholder').replace(/\\n/g, '\n'), pasteInputElement.data('placeholder').replace(/\\n/g, '\n'),
pasteProcessButtonElement = pasteProcessButtonElement =
jQuery('#method_paste > div.mailpoet_method_process') jQuery('#method_paste > div.mailpoet_method_process')
.find('a.mailpoet_process'), .find('a.mailpoet_process'),
mailChimpKeyInputElement = jQuery('#mailchimp_key'), mailChimpKeyInputElement = jQuery('#mailchimp_key'),
mailChimpKeyVerifyButtonElement = jQuery('#mailchimp_key_verify'), mailChimpKeyVerifyButtonElement = jQuery('#mailchimp_key_verify'),
mailChimpListsContainerElement = jQuery('#mailchimp_lists'), mailChimpListsContainerElement = jQuery('#mailchimp_lists'),
mailChimpProcessButtonElement = mailChimpProcessButtonElement =
jQuery('#method_mailchimp > div.mailpoet_method_process') jQuery('#method_mailchimp > div.mailpoet_method_process')
.find('a.mailpoet_process'), .find('a.mailpoet_process'),
uploadElement = jQuery('#file_local'), uploadElement = jQuery('#file_local'),
uploadProcessButtonElement = uploadProcessButtonElement =
jQuery('#method_file > div.mailpoet_method_process') jQuery('#method_file > div.mailpoet_method_process')
.find('a.mailpoet_process'); .find('a.mailpoet_process');
@ -91,7 +91,7 @@ define(
methodSelectionElement.change(function () { methodSelectionElement.change(function () {
MailPoet.Notice.hide(); MailPoet.Notice.hide();
var available_methods = jQuery(':radio[name="select_method"]'), var available_methods = jQuery(':radio[name="select_method"]'),
selected_method = selected_method =
available_methods.index(available_methods.filter(':checked')); available_methods.index(available_methods.filter(':checked'));
// hide all methods // hide all methods
currentStepE.find('.inside') currentStepE.find('.inside')
@ -150,11 +150,11 @@ define(
*/ */
uploadElement.change(function () { uploadElement.change(function () {
MailPoet.Notice.hide(); MailPoet.Notice.hide();
var ext = this.value.match(/\.(.+)$/); var ext = this.value.match(/\.(.+)$/);
if (ext === null || ext[1].toLowerCase() !== 'csv') { if (ext === null || ext[1].toLowerCase() !== 'csv') {
this.value = ''; this.value = '';
MailPoet.Notice.error(MailPoet.I18n.t('wrongFileFormat')); MailPoet.Notice.error(MailPoet.I18n.t('wrongFileFormat'));
} }
toggleNextStepButton( toggleNextStepButton(
uploadProcessButtonElement, uploadProcessButtonElement,
@ -295,23 +295,23 @@ define(
function parseCSV(isFile) { function parseCSV(isFile) {
var processedSubscribers = [], var processedSubscribers = [],
parsedEmails = [], parsedEmails = [],
duplicateEmails = [], duplicateEmails = [],
invalidEmails = [], invalidEmails = [],
emailColumnPosition = null, emailColumnPosition = null,
columnCount = null, columnCount = null,
isHeaderFound = false, isHeaderFound = false,
advancedOptionHeader = true, advancedOptionHeader = true,
advancedOptionDelimiter = '', advancedOptionDelimiter = '',
advancedOptionNewline = '', advancedOptionNewline = '',
advancedOptionComments = false, advancedOptionComments = false,
// trim spaces, commas, periods, // trim spaces, commas, periods,
// single/double quotes and convert to lowercase // single/double quotes and convert to lowercase
detectAndCleanupEmail = function (emailString) { detectAndCleanupEmail = function (emailString) {
var test; var test;
// decode HTML entities // decode HTML entities
var email = jQuery('<div />').html(emailString).text(); var email = jQuery('<div />').html(emailString).text();
email = email email = email
.toLowerCase() .toLowerCase()
// left/right trim spaces, punctuation (e.g., " 'email@email.com'; ") // left/right trim spaces, punctuation (e.g., " 'email@email.com'; ")
// right trim non-printable characters (e.g., "email@email.com<6F>") // right trim non-printable characters (e.g., "email@email.com<6F>")
@ -320,22 +320,22 @@ define(
// remove urlencoded characters // remove urlencoded characters
.replace(/\s+|%\d+|,+/g, ''); .replace(/\s+|%\d+|,+/g, '');
// detect e-mails that will be otherwise rejected by email regex // detect e-mails that will be otherwise rejected by email regex
test = /<(.*?)>/.exec(email); test = /<(.*?)>/.exec(email);
if (test) { if (test) {
// is the email inside angle brackets (e.g., 'some@email.com <some@email.com>')? // is the email inside angle brackets (e.g., 'some@email.com <some@email.com>')?
email = test[1].trim(); email = test[1].trim();
} }
test = /mailto:(?:\s+)?(.*)/.exec(email); test = /mailto:(?:\s+)?(.*)/.exec(email);
if (test) { if (test) {
// is the email in 'mailto:email' format? // is the email in 'mailto:email' format?
email = test[1].trim(); email = test[1].trim();
} }
// test for valid characters using WP's rule (https://core.trac.wordpress.org/browser/tags/4.7.3/src/wp-includes/formatting.php#L2902) // test for valid characters using WP's rule (https://core.trac.wordpress.org/browser/tags/4.7.3/src/wp-includes/formatting.php#L2902)
if (!/^[a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.\-@]+$/.test(email) ) { if (!/^[a-zA-Z0-9!#$%&\'*+\/=?^_`{|}~\.\-@]+$/.test(email) ) {
return false; return false;
} }
return email; return email;
}; };
return { return {
skipEmptyLines: true, skipEmptyLines: true,
@ -444,31 +444,31 @@ define(
} }
// define reusable variables // define reusable variables
var nextStepButton = jQuery('#step2_process'), var nextStepButton = jQuery('#step2_process'),
previousStepButton = jQuery('#return_to_step1'), previousStepButton = jQuery('#return_to_step1'),
// create a copy of subscribers object for further manipulation // create a copy of subscribers object for further manipulation
subscribers = jQuery.extend(true, {}, importData.step1), subscribers = jQuery.extend(true, {}, importData.step1),
subscribersDataTemplate = subscribersDataTemplate =
Handlebars Handlebars
.compile(jQuery('#subscribers_data_template') .compile(jQuery('#subscribers_data_template')
.html()), .html()),
subscribersDataTemplatePartial = subscribersDataTemplatePartial =
Handlebars Handlebars
.compile(jQuery('#subscribers_data_template_partial') .compile(jQuery('#subscribers_data_template_partial')
.html()), .html()),
subscribersDataParseResultsTemplate = subscribersDataParseResultsTemplate =
Handlebars Handlebars
.compile(jQuery('#subscribers_data_parse_results_template') .compile(jQuery('#subscribers_data_parse_results_template')
.html()), .html()),
segmentSelectElement = jQuery('#mailpoet_segments_select'), segmentSelectElement = jQuery('#mailpoet_segments_select'),
maxRowsToShow = 10, maxRowsToShow = 10,
filler = '. . .', filler = '. . .',
// create an array of filler data with the same number of // create an array of filler data with the same number of
// elements as in the subscribers' data row // elements as in the subscribers' data row
fillerArray = Array.apply( fillerArray = Array.apply(
null, null,
new Array(subscribers.subscribers[0].length) new Array(subscribers.subscribers[0].length)
).map(String.prototype.valueOf, filler), ).map(String.prototype.valueOf, filler),
fillerPosition; fillerPosition;
showCurrentStep(); showCurrentStep();
@ -643,19 +643,19 @@ define(
'show_and_match_columns', 'show_and_match_columns',
function (subscribers, options) { function (subscribers, options) {
var displayedColumns = [], var displayedColumns = [],
displayedColumnsIds = []; displayedColumnsIds = [];
// go through all elements of the first row in subscribers data // go through all elements of the first row in subscribers data
for (var i in subscribers.subscribers[0]) { for (var i in subscribers.subscribers[0]) {
var columnData = subscribers.subscribers[0][i], var columnData = subscribers.subscribers[0][i],
columnId = 'ignore'; // set default column type columnId = 'ignore'; // set default column type
// if the column is not undefined and has a valid e-mail, set type as email // if the column is not undefined and has a valid e-mail, set type as email
if (columnData % 1 !== 0 && emailRegex.test(columnData)) { if (columnData % 1 !== 0 && emailRegex.test(columnData)) {
columnId = 'email'; columnId = 'email';
} else if (subscribers.header) { } else if (subscribers.header) {
var headerName = subscribers.header[i], var headerName = subscribers.header[i],
headerNameMatch = mailpoetColumns.map(function (el) { headerNameMatch = mailpoetColumns.map(function (el) {
return el.name; return el.name;
}).indexOf(headerName); }).indexOf(headerName);
// set column type using header // set column type using header
if (headerNameMatch !== -1) { if (headerNameMatch !== -1) {
columnId = mailpoetColumns[headerNameMatch].id; columnId = mailpoetColumns[headerNameMatch].id;
@ -734,7 +734,7 @@ define(
}) })
.on('select2:selecting', function (selectEvent) { .on('select2:selecting', function (selectEvent) {
var selectElement = this, var selectElement = this,
selectedOptionId = selectEvent.params.args.data.id; selectedOptionId = selectEvent.params.args.data.id;
// CREATE CUSTOM FIELD // CREATE CUSTOM FIELD
if (selectedOptionId === 'create') { if (selectedOptionId === 'create') {
selectEvent.preventDefault(); selectEvent.preventDefault();
@ -808,7 +808,7 @@ define(
jQuery('select.mailpoet_subscribers_column_data_match') jQuery('select.mailpoet_subscribers_column_data_match')
.each(function () { .each(function () {
var element = this, var element = this,
elementId = jQuery(element).val(); elementId = jQuery(element).val();
// if another column has the same value and it's not an 'ignore', prompt user // if another column has the same value and it's not an 'ignore', prompt user
if (elementId === selectedOptionId if (elementId === selectedOptionId
&& elementId !== 'ignore') { && elementId !== 'ignore') {
@ -825,7 +825,7 @@ define(
}) })
.on('select2:select', function (selectEvent) { .on('select2:select', function (selectEvent) {
var selectElement = this, var selectElement = this,
selectedOptionId = selectEvent.params.data.id; selectedOptionId = selectEvent.params.data.id;
jQuery(selectElement).data('column-id', selectedOptionId); jQuery(selectElement).data('column-id', selectedOptionId);
filterSubscribers(); filterSubscribers();
}); });
@ -836,8 +836,8 @@ define(
'[data-id="notice_invalidEmail"], [data-id="notice_invalidDate"]') '[data-id="notice_invalidEmail"], [data-id="notice_invalidDate"]')
.remove(); .remove();
var subscribersClone = jQuery.extend(true, {}, subscribers), var subscribersClone = jQuery.extend(true, {}, subscribers),
preventNextStep = false, preventNextStep = false,
displayedColumns = jQuery.map( displayedColumns = jQuery.map(
jQuery('.mailpoet_subscribers_column_data_match'), function (element, elementIndex) { jQuery('.mailpoet_subscribers_column_data_match'), function (element, elementIndex) {
var columnId = jQuery(element).data('column-id'); var columnId = jQuery(element).data('column-id');
var validationRule = jQuery(element).data('validation-rule'); var validationRule = jQuery(element).data('validation-rule');
@ -1089,21 +1089,21 @@ define(
Handlebars Handlebars
.compile(jQuery('#subscribers_data_import_results_template') .compile(jQuery('#subscribers_data_import_results_template')
.html()), .html()),
exportMenuElement = jQuery('span.mailpoet_export'), exportMenuElement = jQuery('span.mailpoet_export'),
importResults = { importResults = {
created: (importData.step2.created) created: (importData.step2.created)
? MailPoet.I18n.t('subscribersCreated') ? MailPoet.I18n.t('subscribersCreated')
.replace('%1$s', '<strong>' + importData.step2.created.toLocaleString() + '</strong>') .replace('%1$s', '<strong>' + importData.step2.created.toLocaleString() + '</strong>')
.replace('%2$s', '"' + importData.step2.segments.join('", "') + '"') .replace('%2$s', '"' + importData.step2.segments.join('", "') + '"')
: false, : false,
updated: (importData.step2.updated) updated: (importData.step2.updated)
? MailPoet.I18n.t('subscribersUpdated') ? MailPoet.I18n.t('subscribersUpdated')
.replace('%1$s', '<strong>' + importData.step2.updated.toLocaleString() + '</strong>') .replace('%1$s', '<strong>' + importData.step2.updated.toLocaleString() + '</strong>')
.replace('%2$s', '"' + importData.step2.segments.join('", "') + '"') .replace('%2$s', '"' + importData.step2.segments.join('", "') + '"')
: false, : false,
no_action: (!importData.step2.created && !importData.step2.updated), no_action: (!importData.step2.created && !importData.step2.updated),
added_to_segment_with_welcome_notification: importData.step2.added_to_segment_with_welcome_notification added_to_segment_with_welcome_notification: importData.step2.added_to_segment_with_welcome_notification
}; };
jQuery('#subscribers_data_import_results') jQuery('#subscribers_data_import_results')
.html(subscribersDataImportResultsTemplate(importResults)) .html(subscribersDataImportResultsTemplate(importResults))