diff --git a/.eslintrc.es5.json b/.eslintrc.es5.json index 636092f0c9..4a8aba5869 100644 --- a/.eslintrc.es5.json +++ b/.eslintrc.es5.json @@ -74,7 +74,6 @@ "keyword-spacing": 0, "eol-last": 0, "dot-notation": 0, - "indent": 0, "prefer-template": 0, "func-names": 0 } diff --git a/assets/js/src/admin.js b/assets/js/src/admin.js index 854f7757aa..7c6c2fe90f 100644 --- a/assets/js/src/admin.js +++ b/assets/js/src/admin.js @@ -1,6 +1,6 @@ define('admin', [ - 'jquery' - ], + 'jquery' +], function(jQuery) { jQuery(function($) { // dom ready diff --git a/assets/js/src/ajax.js b/assets/js/src/ajax.js index 70f216ca5e..a878874844 100644 --- a/assets/js/src/ajax.js +++ b/assets/js/src/ajax.js @@ -16,59 +16,59 @@ define('ajax', ['mailpoet', 'jquery', 'underscore'], function(mp, jQuery, _) { var MailPoet = mp; MailPoet.Ajax = { - version: 0.5, - options: {}, - defaults: { - url: null, - api_version: null, - endpoint: null, - action: null, - token: null, - data: {} - }, - post: function(options) { - return this.request('post', options); - }, - init: function(options) { + version: 0.5, + options: {}, + defaults: { + url: null, + api_version: null, + endpoint: null, + action: null, + token: null, + data: {} + }, + post: function(options) { + return this.request('post', options); + }, + init: function(options) { // merge options - this.options = jQuery.extend({}, this.defaults, options); + this.options = jQuery.extend({}, this.defaults, options); // set default url - if(this.options.url === null) { - this.options.url = ajaxurl; - } + if(this.options.url === null) { + this.options.url = ajaxurl; + } // set default token - if(this.options.token === null) { - this.options.token = window.mailpoet_token; - } - }, - getParams: function() { - return { - action: 'mailpoet', - api_version: this.options.api_version, - token: this.options.token, - endpoint: this.options.endpoint, - method: this.options.action, - data: this.options.data || {} - }; - }, - request: function(method, options) { + if(this.options.token === null) { + this.options.token = window.mailpoet_token; + } + }, + getParams: function() { + return { + action: 'mailpoet', + api_version: this.options.api_version, + token: this.options.token, + endpoint: this.options.endpoint, + method: this.options.action, + data: this.options.data || {} + }; + }, + request: function(method, options) { // set options - this.init(options); + this.init(options); // set request params - var params = this.getParams(); + var params = this.getParams(); // remove null values from the data object - if (_.isObject(params.data)) { - params.data = _.pick(params.data, function(value) { - return (value !== null); - }); - } + if (_.isObject(params.data)) { + params.data = _.pick(params.data, function(value) { + return (value !== null); + }); + } // ajax request - var deferred = jQuery.post( + var deferred = jQuery.post( this.options.url, params, null, @@ -78,9 +78,9 @@ define('ajax', ['mailpoet', 'jquery', 'underscore'], function(mp, jQuery, _) { }, _.partial(requestFailed, MailPoet.I18n.t('ajaxFailedErrorMessage'))); // clear options - this.options = {}; + this.options = {}; - return deferred; - } + return deferred; + } }; }); diff --git a/assets/js/src/date.js b/assets/js/src/date.js index bafdbecbc9..615ba9f5cd 100644 --- a/assets/js/src/date.js +++ b/assets/js/src/date.js @@ -8,162 +8,162 @@ define('date', jQuery, Moment ) { - 'use strict'; + 'use strict'; - var MailPoet = mp; + var MailPoet = mp; - MailPoet.Date = { - version: 0.1, - options: {}, - defaults: { - offset: 0, - format: 'F, d Y H:i:s' - }, - init: function (opts) { - var options = opts || {}; + MailPoet.Date = { + version: 0.1, + options: {}, + defaults: { + offset: 0, + format: 'F, d Y H:i:s' + }, + init: function (opts) { + var options = opts || {}; // set UTC offset - if ( + if ( options.offset === undefined && window.mailpoet_date_offset !== undefined ) { - options.offset = window.mailpoet_date_offset; - } + options.offset = window.mailpoet_date_offset; + } // set date format - if ( + if ( options.format === undefined && window.mailpoet_date_format !== undefined ) { - 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' + options.format = window.mailpoet_date_format; } - }; + // 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 = []; - var escapeToken = false; + 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' + } + }; - for(var index = 0, token = ''; format.charAt(index); index += 1){ - token = format.charAt(index); - if (escapeToken === true) { - 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 { + if (!format || format.length <= 0) return format; + + var replacements = format_mappings['date']; + + var convertedFormat = []; + var escapeToken = false; + + for(var index = 0, token = ''; format.charAt(index); index += 1){ + token = format.charAt(index); + if (escapeToken === true) { 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(''); + } + }; + }); diff --git a/assets/js/src/handlebars_helpers.js b/assets/js/src/handlebars_helpers.js index 1b2c731abd..05e9795185 100644 --- a/assets/js/src/handlebars_helpers.js +++ b/assets/js/src/handlebars_helpers.js @@ -1,31 +1,31 @@ define('handlebars_helpers', ['handlebars'], function(Handlebars) { // Handlebars helpers Handlebars.registerHelper('concat', function() { - var size = (arguments.length - 1), - output = ''; - for(var i = 0; i < size; i++) { - output += arguments[i]; - } - return output; + var size = (arguments.length - 1), + output = ''; + for(var i = 0; i < size; i++) { + output += arguments[i]; + } + return output; }); Handlebars.registerHelper('number_format', function(value, block) { - return Number(value).toLocaleString(); + return Number(value).toLocaleString(); }); Handlebars.registerHelper('date_format', function(timestamp, block) { if(window.moment) { - if(timestamp === undefined || isNaN(timestamp) || timestamp <= 0) { - return; - } + if(timestamp === undefined || isNaN(timestamp) || timestamp <= 0) { + return; + } // 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 - if(parseInt(timestamp, 10) == timestamp) { - return moment.unix(timestamp).format(f); - } else { - return moment.utc(timestamp).format(f); - } + if(parseInt(timestamp, 10) == timestamp) { + return moment.unix(timestamp).format(f); + } else { + return moment.utc(timestamp).format(f); + } } else { return timestamp; } @@ -37,81 +37,81 @@ define('handlebars_helpers', ['handlebars'], function(Handlebars) { }); Handlebars.registerHelper('ifCond', function (v1, operator, v2, options) { - switch (operator) { - case '==': - return (v1 == v2) ? options.fn(this) : options.inverse(this); - case '===': - return (v1 === v2) ? options.fn(this) : options.inverse(this); - case '!=': - return (v1 != v2) ? options.fn(this) : options.inverse(this); - case '!==': - return (v1 !== v2) ? options.fn(this) : options.inverse(this); - case '<': - return (v1 < v2) ? options.fn(this) : options.inverse(this); - case '<=': - return (v1 <= v2) ? options.fn(this) : options.inverse(this); - case '>': - return (v1 > v2) ? options.fn(this) : options.inverse(this); - case '>=': - return (v1 >= v2) ? options.fn(this) : options.inverse(this); - case '&&': - return (v1 && v2) ? options.fn(this) : options.inverse(this); - case '||': - return (v1 || v2) ? options.fn(this) : options.inverse(this); - case 'in': - var values = v2.split(','); - return (v2.indexOf(v1) !== -1) ? options.fn(this) : options.inverse(this); - default: - return options.inverse(this); - } + switch (operator) { + case '==': + return (v1 == v2) ? options.fn(this) : options.inverse(this); + case '===': + return (v1 === v2) ? options.fn(this) : options.inverse(this); + case '!=': + return (v1 != v2) ? options.fn(this) : options.inverse(this); + case '!==': + return (v1 !== v2) ? options.fn(this) : options.inverse(this); + case '<': + return (v1 < v2) ? options.fn(this) : options.inverse(this); + case '<=': + return (v1 <= v2) ? options.fn(this) : options.inverse(this); + case '>': + return (v1 > v2) ? options.fn(this) : options.inverse(this); + case '>=': + return (v1 >= v2) ? options.fn(this) : options.inverse(this); + case '&&': + return (v1 && v2) ? options.fn(this) : options.inverse(this); + case '||': + return (v1 || v2) ? options.fn(this) : options.inverse(this); + case 'in': + var values = v2.split(','); + return (v2.indexOf(v1) !== -1) ? options.fn(this) : options.inverse(this); + default: + return options.inverse(this); + } }); Handlebars.registerHelper('nl2br', function(value, block) { - return value.gsub('\n', '
'); + return value.gsub('\n', '
'); }); Handlebars.registerHelper('json_encode', function(value, block) { - return JSON.stringify(value); + return JSON.stringify(value); }); Handlebars.registerHelper('json_decode', function(value, block) { - return JSON.parse(value); + return JSON.parse(value); }); 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) { - var mailtoMatchingRegex = /^mailto\:/i; - if (typeof value === 'string' && value.match(mailtoMatchingRegex)) { - return value.replace(mailtoMatchingRegex, ''); - } else { - return value; - } + var mailtoMatchingRegex = /^mailto\:/i; + if (typeof value === 'string' && value.match(mailtoMatchingRegex)) { + return value.replace(mailtoMatchingRegex, ''); + } else { + return value; + } }); Handlebars.registerHelper('lookup', function(obj, field, options) { - return obj && obj[field]; + return obj && obj[field]; }); Handlebars.registerHelper('rsa_key', function(value, block) { // 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 - lines.shift(); - lines.pop(); + lines.shift(); + lines.pop(); // return concatenated lines - return lines.join(''); + return lines.join(''); }); Handlebars.registerHelper('trim', function(value, block) { - if(value === null || value === undefined) return ''; - return value.trim(); + if(value === null || value === undefined) return ''; + return value.trim(); }); /** @@ -125,20 +125,20 @@ define('handlebars_helpers', ['handlebars'], function(Handlebars) { * @return {String} The truncated string. */ Handlebars.registerHelper('ellipsis', function (str, limit, append) { - var strAppend = append; - if (strAppend === undefined) { - strAppend = ''; - } - var sanitized = str.replace(/(<([^>]+)>)/g, ''); - if (sanitized.length > limit) { - return sanitized.substr(0, limit - strAppend.length) + strAppend; - } else { - return sanitized; - } + var strAppend = append; + if (strAppend === undefined) { + strAppend = ''; + } + var sanitized = str.replace(/(<([^>]+)>)/g, ''); + if (sanitized.length > limit) { + return sanitized.substr(0, limit - strAppend.length) + strAppend; + } else { + return sanitized; + } }); Handlebars.registerHelper('getNumber', function (string) { - return parseInt(string, 10); + return parseInt(string, 10); }); Handlebars.registerHelper('fontWithFallback', function(font) { diff --git a/assets/js/src/i18n.js b/assets/js/src/i18n.js index a22b4a837e..bb3d19400c 100644 --- a/assets/js/src/i18n.js +++ b/assets/js/src/i18n.js @@ -4,22 +4,22 @@ define('i18n', ], function( mp ) { - 'use strict'; + 'use strict'; - var MailPoet = mp; + var MailPoet = mp; - var translations = {}; + var translations = {}; - MailPoet.I18n = { - add: function(key, value) { - translations[key] = value; - }, - t: function(key) { - return translations[key] || 'TRANSLATION "%$1s" NOT FOUND'.replace('%$1s', key); - }, - all: function() { - return translations; - } - }; + MailPoet.I18n = { + add: function(key, value) { + translations[key] = value; + }, + t: function(key) { + return translations[key] || 'TRANSLATION "%$1s" NOT FOUND'.replace('%$1s', key); + }, + all: function() { + return translations; + } + }; -}); + }); diff --git a/assets/js/src/modal.js b/assets/js/src/modal.js index 550fddd0d2..998a34e917 100644 --- a/assets/js/src/modal.js +++ b/assets/js/src/modal.js @@ -182,24 +182,24 @@ define('modal', ['mailpoet', 'jquery'], initOverlay: function(toggle) { if(jQuery('#mailpoet_modal_overlay').length === 0) { // insert overlay into the DOM - jQuery('body').append(this.templates.overlay); + jQuery('body').append(this.templates.overlay); // insert loading indicator into overlay - jQuery('#mailpoet_modal_overlay').append(this.templates.loading); - } - return this; - }, - toggleOverlay: function(toggle) { - if(toggle === true) { - jQuery('#mailpoet_modal_overlay') + jQuery('#mailpoet_modal_overlay').append(this.templates.loading); + } + return this; + }, + toggleOverlay: function(toggle) { + if(toggle === true) { + jQuery('#mailpoet_modal_overlay') .removeClass('mailpoet_overlay_hidden'); - } else { - jQuery('#mailpoet_modal_overlay') + } else { + jQuery('#mailpoet_modal_overlay') .addClass('mailpoet_overlay_hidden'); - } + } - return this; - }, - setupEvents: function() { + return this; + }, + setupEvents: function() { // close popup when user clicks on close button jQuery('#mailpoet_modal_close').on('click', this.cancel.bind(this)); @@ -250,39 +250,39 @@ define('modal', ['mailpoet', 'jquery'], loadTemplate: function() { if(this.subpanels.length > 0) { // hide panel - jQuery('.mailpoet_'+this.options.type+'_wrapper').hide(); + jQuery('.mailpoet_'+this.options.type+'_wrapper').hide(); // add sub panel wrapper - jQuery('#mailpoet_'+this.options.type) + jQuery('#mailpoet_'+this.options.type) .append(this.templates['subpanel']); // 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); // focus on sub panel - if(this.options.focus) { - this.focus(); - } - } else if (this.options.element) { - jQuery('.mailpoet_'+this.options.type+'_body').empty(); - jQuery('.mailpoet_'+this.options.type+'_body') + if(this.options.focus) { + this.focus(); + } + } else if (this.options.element) { + jQuery('.mailpoet_'+this.options.type+'_body').empty(); + jQuery('.mailpoet_'+this.options.type+'_body') .append(this.options.element); - } else { - jQuery('.mailpoet_'+this.options.type+'_body') + } else { + jQuery('.mailpoet_'+this.options.type+'_body') .html( this.options.body_template( this.options.data ) ); - } + } - return this; - }, - loadUrl: function() { - if(this.options.method === 'get') { + return this; + }, + loadUrl: function() { + if(this.options.method === 'get') { // make ajax request - jQuery.getJSON(this.options.url, + jQuery.getJSON(this.options.url, function(data) { this.options.data = jQuery.extend({}, this.options.data, data); // load template using fetched data @@ -291,9 +291,9 @@ define('modal', ['mailpoet', 'jquery'], this.showModal(); }.bind(this) ); - } else if(this.options.method === 'post') { + } else if(this.options.method === 'post') { // 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) { this.options.data = jQuery.extend({}, this.options.data, data); // load template using fetched data @@ -303,342 +303,342 @@ define('modal', ['mailpoet', 'jquery'], }.bind(this), 'json' ); - } + } - return this; - }, - setDimensions: function() { - switch(this.options.type) { - case 'popup': + return this; + }, + setDimensions: function() { + switch(this.options.type) { + case 'popup': // set popup dimensions - jQuery('#mailpoet_popup').css({ - width: this.options.width, - height: this.options.height - }); + jQuery('#mailpoet_popup').css({ + width: this.options.width, + height: this.options.height + }); // set popup wrapper height - jQuery('#mailpoet_popup_wrapper').css({ - height: this.options.height - }); + jQuery('#mailpoet_popup_wrapper').css({ + height: this.options.height + }); break; - case 'panel': + case 'panel': // set dimensions - if(this.options.position === 'right') { - jQuery('#mailpoet_panel').css({ - width: this.options.width, - right: 0, - marginRight: '-' + this.options.width, - left: 'auto' - }); - } else if(this.options.position === 'left') { - jQuery('#mailpoet_panel').css({ - width: this.options.width, - left: 0, - marginLeft: '-' + this.options.width, - right: 'auto' - }); - } - jQuery('#mailpoet_panel').css({ minHeight: 'auto' }); + if(this.options.position === 'right') { + jQuery('#mailpoet_panel').css({ + width: this.options.width, + right: 0, + marginRight: '-' + this.options.width, + left: 'auto' + }); + } else if(this.options.position === 'left') { + jQuery('#mailpoet_panel').css({ + width: this.options.width, + left: 0, + marginLeft: '-' + this.options.width, + right: 'auto' + }); + } + jQuery('#mailpoet_panel').css({ minHeight: 'auto' }); break; - } + } - return this; - }, - setPosition: function() { - switch(this.options.type) { - case 'popup': - var screenWidth = jQuery(window).width(), + return this; + }, + setPosition: function() { + switch(this.options.type) { + case 'popup': + var screenWidth = jQuery(window).width(), screenHeight = jQuery(window).height(), modalWidth = jQuery('.mailpoet_'+ this.options.type +'_wrapper').width(), 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))); // set position of popup depending on screen dimensions. - jQuery('#mailpoet_popup').css({ - top: top, - left: left - }); + jQuery('#mailpoet_popup').css({ + top: top, + left: left + }); break; - case 'panel': - setTimeout(function() { + case 'panel': + setTimeout(function() { // set position of popup depending on screen dimensions. - if(this.options.position === 'right') { - jQuery('#mailpoet_panel').css({ - marginRight: 0 - }); - } else if(this.options.position === 'left') { - jQuery('#mailpoet_panel').css({ - marginLeft: 0 - }); - } - }.bind(this), 0); + if(this.options.position === 'right') { + jQuery('#mailpoet_panel').css({ + marginRight: 0 + }); + } else if(this.options.position === 'left') { + jQuery('#mailpoet_panel').css({ + marginLeft: 0 + }); + } + }.bind(this), 0); break; - } + } - return this; - }, - showModal: function() { + return this; + }, + showModal: function() { // set modal dimensions - this.setDimensions(); + this.setDimensions(); // 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 - jQuery('body').addClass('mailpoet_modal_opened'); + jQuery('body').addClass('mailpoet_modal_opened'); // show popup - jQuery('#mailpoet_'+this.options.type).show(); + jQuery('#mailpoet_'+this.options.type).show(); // display overlay - this.showOverlay(); + this.showOverlay(); // set modal position - this.setPosition(); + this.setPosition(); // add class on highlighted elements - if(this.options.highlight !== null) { - if(this.options.highlight.length > 0) { - this.highlightOn(this.options.highlight); - } + if(this.options.highlight !== null) { + if(this.options.highlight.length > 0) { + 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) { 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; } + + // 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; + } }; } ); diff --git a/assets/js/src/newsletter_editor/App.js b/assets/js/src/newsletter_editor/App.js index ac79777987..bd0c0192f0 100644 --- a/assets/js/src/newsletter_editor/App.js +++ b/assets/js/src/newsletter_editor/App.js @@ -1,12 +1,12 @@ define([ - 'backbone', - 'backbone.marionette', - 'backbone.radio', - 'jquery', - 'underscore', - 'handlebars', - 'handlebars_helpers' - ], function(Backbone, Marionette, BackboneRadio, jQuery, _, Handlebars) { + 'backbone', + 'backbone.marionette', + 'backbone.radio', + 'jquery', + 'underscore', + 'handlebars', + 'handlebars_helpers' +], function(Backbone, Marionette, BackboneRadio, jQuery, _, Handlebars) { var Radio = BackboneRadio; var AppView = Marionette.View.extend({ diff --git a/assets/js/src/newsletter_editor/behaviors/BehaviorsLookup.js b/assets/js/src/newsletter_editor/behaviors/BehaviorsLookup.js index 5a2d350a5e..1c6c0e5ec3 100644 --- a/assets/js/src/newsletter_editor/behaviors/BehaviorsLookup.js +++ b/assets/js/src/newsletter_editor/behaviors/BehaviorsLookup.js @@ -5,8 +5,8 @@ * For more check: http://marionettejs.com/docs/marionette.behaviors.html#behaviorslookup */ define([ - 'backbone.marionette' - ], function(BackboneMarionette) { + 'backbone.marionette' +], function(BackboneMarionette) { var Marionette = BackboneMarionette; var BehaviorsLookup = {}; Marionette.Behaviors.behaviorsLookup = function() { diff --git a/assets/js/src/newsletter_editor/behaviors/ColorPickerBehavior.js b/assets/js/src/newsletter_editor/behaviors/ColorPickerBehavior.js index 24a2a95cf0..4188ca4be6 100644 --- a/assets/js/src/newsletter_editor/behaviors/ColorPickerBehavior.js +++ b/assets/js/src/newsletter_editor/behaviors/ColorPickerBehavior.js @@ -4,11 +4,11 @@ * Adds a color picker integration with the view */ define([ - 'backbone.marionette', - 'newsletter_editor/behaviors/BehaviorsLookup', - 'mailpoet', - 'spectrum' - ], function(Marionette, BehaviorsLookup, MailPoet, Spectrum) { + 'backbone.marionette', + 'newsletter_editor/behaviors/BehaviorsLookup', + 'mailpoet', + 'spectrum' +], function(Marionette, BehaviorsLookup, MailPoet, Spectrum) { var BL = BehaviorsLookup; BL.ColorPickerBehavior = Marionette.Behavior.extend({ diff --git a/assets/js/src/newsletter_editor/behaviors/ContainerDropZoneBehavior.js b/assets/js/src/newsletter_editor/behaviors/ContainerDropZoneBehavior.js index bc8611c6a3..f83861a1a5 100644 --- a/assets/js/src/newsletter_editor/behaviors/ContainerDropZoneBehavior.js +++ b/assets/js/src/newsletter_editor/behaviors/ContainerDropZoneBehavior.js @@ -6,12 +6,12 @@ * accept droppables */ define([ - 'backbone.marionette', - 'underscore', - 'jquery', - 'newsletter_editor/behaviors/BehaviorsLookup', - 'interact' - ], function(Marionette, _, jQuery, BL, interact) { + 'backbone.marionette', + 'underscore', + 'jquery', + 'newsletter_editor/behaviors/BehaviorsLookup', + 'interact' +], function(Marionette, _, jQuery, BL, interact) { var BehaviorsLookup = BL; BehaviorsLookup.ContainerDropZoneBehavior = Marionette.Behavior.extend({ @@ -21,7 +21,7 @@ define([ onRender: function() { var dragAndDropDisabled = _.isObject(this.view.options.renderOptions) && this.view.options.renderOptions.disableDragAndDrop === true; if (!dragAndDropDisabled) { - this.addDropZone(); + this.addDropZone(); } }, addDropZone: function(_event) { @@ -196,7 +196,7 @@ define([ if (view.model.get('orientation') === 'horizontal' && droppableModel.get('type') !== 'container') { // Regular blocks always need to be inserted into columns - vertical containers tempCollection = new (EditorApplication.getBlockTypeModel('container'))({ - orientation: 'vertical' + orientation: 'vertical' }); tempCollection.get('blocks').add(droppableModel); viewCollection.add(tempCollection, {at: index}); @@ -211,7 +211,7 @@ define([ var tempModel = viewCollection.at(dropPosition.index); tempCollection = new (EditorApplication.getBlockTypeModel('container'))({ - orientation: (view.model.get('orientation') === 'vertical') ? 'horizontal' : 'vertical' + orientation: (view.model.get('orientation') === 'vertical') ? 'horizontal' : 'vertical' }); viewCollection.remove(tempModel); @@ -377,14 +377,14 @@ define([ if (eventOffset <= closeOffset + elementDimension / 2) { // First half of the element return { - index: index, - position: 'before' + index: index, + position: 'before' }; } else { // Second half of the element return { - index: index, - position: 'after' + index: index, + position: 'after' }; } }, diff --git a/assets/js/src/newsletter_editor/behaviors/DraggableBehavior.js b/assets/js/src/newsletter_editor/behaviors/DraggableBehavior.js index 41053e5fbe..16e32ce0e1 100644 --- a/assets/js/src/newsletter_editor/behaviors/DraggableBehavior.js +++ b/assets/js/src/newsletter_editor/behaviors/DraggableBehavior.js @@ -5,12 +5,12 @@ * Part of the drag&drop behavior. */ define([ - 'backbone.marionette', - 'underscore', - 'jquery', - 'newsletter_editor/behaviors/BehaviorsLookup', - 'interact' - ], function(Marionette, _, jQuery, BehaviorsLookup, interact) { + 'backbone.marionette', + 'underscore', + 'jquery', + 'newsletter_editor/behaviors/BehaviorsLookup', + 'interact' +], function(Marionette, _, jQuery, BehaviorsLookup, interact) { var BL = BehaviorsLookup; BL.DraggableBehavior = Marionette.Behavior.extend({ @@ -33,13 +33,13 @@ define([ }, onRender: function() { var that = this, - interactable; + interactable; // Give instances more control over whether Draggable should be applied if (!this.options.testAttachToInstance(this.view.model, this.view)) return; interactable = interact(this.$el.get(0), { - ignoreFrom: this.options.ignoreSelector + ignoreFrom: this.options.ignoreSelector }).draggable({ // allow dragging of multple elements at the same time max: Infinity, diff --git a/assets/js/src/newsletter_editor/behaviors/HighlightEditingBehavior.js b/assets/js/src/newsletter_editor/behaviors/HighlightEditingBehavior.js index 05cdf1ffc5..0adc89a689 100644 --- a/assets/js/src/newsletter_editor/behaviors/HighlightEditingBehavior.js +++ b/assets/js/src/newsletter_editor/behaviors/HighlightEditingBehavior.js @@ -4,9 +4,9 @@ * Highlights a block that is being edited */ define([ - 'backbone.marionette', - 'newsletter_editor/behaviors/BehaviorsLookup' - ], function(Marionette, BehaviorsLookup) { + 'backbone.marionette', + 'newsletter_editor/behaviors/BehaviorsLookup' +], function(Marionette, BehaviorsLookup) { var BL = BehaviorsLookup; BL.HighlightEditingBehavior = Marionette.Behavior.extend({ diff --git a/assets/js/src/newsletter_editor/behaviors/ResizableBehavior.js b/assets/js/src/newsletter_editor/behaviors/ResizableBehavior.js index 7503709ce9..058d323cf8 100644 --- a/assets/js/src/newsletter_editor/behaviors/ResizableBehavior.js +++ b/assets/js/src/newsletter_editor/behaviors/ResizableBehavior.js @@ -4,10 +4,10 @@ * Allows resizing elements within a block */ define([ - 'backbone.marionette', - 'newsletter_editor/behaviors/BehaviorsLookup', - 'interact' - ], function(Marionette, BehaviorsLookup, interact) { + 'backbone.marionette', + 'newsletter_editor/behaviors/BehaviorsLookup', + 'interact' +], function(Marionette, BehaviorsLookup, interact) { var BL = BehaviorsLookup; BL.ResizableBehavior = Marionette.Behavior.extend({ @@ -31,7 +31,7 @@ define([ }, attachResize: function() { 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({ //axis: 'y', edges: { diff --git a/assets/js/src/newsletter_editor/behaviors/ShowSettingsBehavior.js b/assets/js/src/newsletter_editor/behaviors/ShowSettingsBehavior.js index eb0b875b8b..dc988333b0 100644 --- a/assets/js/src/newsletter_editor/behaviors/ShowSettingsBehavior.js +++ b/assets/js/src/newsletter_editor/behaviors/ShowSettingsBehavior.js @@ -4,10 +4,10 @@ * Opens up settings of a BlockView if contents are clicked upon */ define([ - 'backbone.marionette', - 'jquery', - 'newsletter_editor/behaviors/BehaviorsLookup' - ], function(Marionette, jQuery, BehaviorsLookup) { + 'backbone.marionette', + 'jquery', + 'newsletter_editor/behaviors/BehaviorsLookup' +], function(Marionette, jQuery, BehaviorsLookup) { var BL = BehaviorsLookup; BL.ShowSettingsBehavior = Marionette.Behavior.extend({ diff --git a/assets/js/src/newsletter_editor/behaviors/SortableBehavior.js b/assets/js/src/newsletter_editor/behaviors/SortableBehavior.js index bc6e93ff9d..5085bde306 100644 --- a/assets/js/src/newsletter_editor/behaviors/SortableBehavior.js +++ b/assets/js/src/newsletter_editor/behaviors/SortableBehavior.js @@ -4,10 +4,10 @@ * Allows sorting elements within a collection */ define([ - 'backbone.marionette', - 'underscore', - 'newsletter_editor/behaviors/BehaviorsLookup' - ], function(Marionette, _, BehaviorsLookup) { + 'backbone.marionette', + 'underscore', + 'newsletter_editor/behaviors/BehaviorsLookup' +], function(Marionette, _, BehaviorsLookup) { var BL = BehaviorsLookup; BL.SortableBehavior = Marionette.Behavior.extend({ diff --git a/assets/js/src/newsletter_editor/behaviors/TextEditorBehavior.js b/assets/js/src/newsletter_editor/behaviors/TextEditorBehavior.js index bbbd2d0865..dcf62e448c 100644 --- a/assets/js/src/newsletter_editor/behaviors/TextEditorBehavior.js +++ b/assets/js/src/newsletter_editor/behaviors/TextEditorBehavior.js @@ -4,10 +4,10 @@ * Adds TinyMCE text editing capabilities to a view */ define([ - 'backbone.marionette', - 'underscore', - 'newsletter_editor/behaviors/BehaviorsLookup' - ], function(Marionette, _, BehaviorsLookup) { + 'backbone.marionette', + 'underscore', + 'newsletter_editor/behaviors/BehaviorsLookup' +], function(Marionette, _, BehaviorsLookup) { var BL = BehaviorsLookup; BL.TextEditorBehavior = Marionette.Behavior.extend({ @@ -73,7 +73,7 @@ define([ editor.on('focus', function(e) { that.view.triggerMethod('text:editor:focus'); - that._isActivationClick = true; + that._isActivationClick = true; }); editor.on('blur', function(e) { diff --git a/assets/js/src/newsletter_editor/blocks/automatedLatestContent.js b/assets/js/src/newsletter_editor/blocks/automatedLatestContent.js index a5e1181846..dc6ae3a5e0 100644 --- a/assets/js/src/newsletter_editor/blocks/automatedLatestContent.js +++ b/assets/js/src/newsletter_editor/blocks/automatedLatestContent.js @@ -7,31 +7,31 @@ * block settings view. */ define([ - 'newsletter_editor/App', - 'newsletter_editor/blocks/base', - 'newsletter_editor/blocks/button', - 'newsletter_editor/blocks/divider', - 'newsletter_editor/components/communication', - 'mailpoet', - 'backbone.supermodel', - 'underscore', - 'jquery' - ], function( - App, - BaseBlock, - ButtonBlock, - DividerBlock, - CommunicationComponent, - MailPoet, - SuperModel, - _, - jQuery + 'newsletter_editor/App', + 'newsletter_editor/blocks/base', + 'newsletter_editor/blocks/button', + 'newsletter_editor/blocks/divider', + 'newsletter_editor/components/communication', + 'mailpoet', + 'backbone.supermodel', + 'underscore', + 'jquery' +], function( + App, + BaseBlock, + ButtonBlock, + DividerBlock, + CommunicationComponent, + MailPoet, + SuperModel, + _, + jQuery ) { 'use strict'; var Module = {}, - base = BaseBlock; + base = BaseBlock; Module.ALCSupervisor = SuperModel.extend({ initialize: function() { @@ -61,7 +61,7 @@ define([ _.zip(models, renderedBlocks), function(args) { var model = args[0], - contents = args[1]; + contents = args[1]; model.trigger('refreshPosts', contents); } ); @@ -350,7 +350,7 @@ define([ }, _updateContentTypes: function(postTypes) { var select = this.$('.mailpoet_automated_latest_content_content_type'), - selectedValue = this.model.get('contentType'); + selectedValue = this.model.get('contentType'); select.find('option').remove(); _.each(postTypes, function(type) { diff --git a/assets/js/src/newsletter_editor/blocks/base.js b/assets/js/src/newsletter_editor/blocks/base.js index 484cf11445..f7e28fce54 100644 --- a/assets/js/src/newsletter_editor/blocks/base.js +++ b/assets/js/src/newsletter_editor/blocks/base.js @@ -5,19 +5,19 @@ * BlockToolsView, BlockSettingsView and BlockWidgetView are optional. */ define([ - 'newsletter_editor/App', - 'backbone.marionette', - 'backbone.supermodel', - 'underscore', - 'jquery', - 'mailpoet', - 'modal' - ], function(App, Marionette, SuperModel, _, jQuery, MailPoet, Modal) { + 'newsletter_editor/App', + 'backbone.marionette', + 'backbone.supermodel', + 'underscore', + 'jquery', + 'mailpoet', + 'modal' +], function(App, Marionette, SuperModel, _, jQuery, MailPoet, Modal) { 'use strict'; var Module = {}, - AugmentedView = Marionette.View.extend({}); + AugmentedView = Marionette.View.extend({}); Module.BlockModel = SuperModel.extend({ stale: [], // Attributes to be removed upon saving diff --git a/assets/js/src/newsletter_editor/blocks/button.js b/assets/js/src/newsletter_editor/blocks/button.js index 1db19f50c2..ebf68d8f43 100644 --- a/assets/js/src/newsletter_editor/blocks/button.js +++ b/assets/js/src/newsletter_editor/blocks/button.js @@ -2,17 +2,17 @@ * Button content block */ define([ - 'newsletter_editor/App', - 'newsletter_editor/blocks/base', - 'mailpoet', - 'underscore', - 'jquery' - ], function(App, BaseBlock, MailPoet, _, jQuery) { + 'newsletter_editor/App', + 'newsletter_editor/blocks/base', + 'mailpoet', + 'underscore', + 'jquery' +], function(App, BaseBlock, MailPoet, _, jQuery) { 'use strict'; var Module = {}, - base = BaseBlock; + base = BaseBlock; Module.ButtonBlockModel = base.BlockModel.extend({ defaults: function() { diff --git a/assets/js/src/newsletter_editor/blocks/container.js b/assets/js/src/newsletter_editor/blocks/container.js index 2a010fe9b3..803ab09cf1 100644 --- a/assets/js/src/newsletter_editor/blocks/container.js +++ b/assets/js/src/newsletter_editor/blocks/container.js @@ -4,19 +4,19 @@ * as other containers. */ define([ - 'backbone', - 'backbone.marionette', - 'underscore', - 'jquery', - 'newsletter_editor/App', - 'newsletter_editor/blocks/base' - ], function(Backbone, Marionette, _, jQuery, App, BaseBlock) { + 'backbone', + 'backbone.marionette', + 'underscore', + 'jquery', + 'newsletter_editor/App', + 'newsletter_editor/blocks/base' +], function(Backbone, Marionette, _, jQuery, App, BaseBlock) { 'use strict'; var Module = {}, - base = BaseBlock, - BlockCollection; + base = BaseBlock, + BlockCollection; BlockCollection = Backbone.Collection.extend({ model: base.BlockModel, diff --git a/assets/js/src/newsletter_editor/blocks/divider.js b/assets/js/src/newsletter_editor/blocks/divider.js index 12fd064f0c..3bf6bcf4b6 100644 --- a/assets/js/src/newsletter_editor/blocks/divider.js +++ b/assets/js/src/newsletter_editor/blocks/divider.js @@ -2,17 +2,17 @@ * Divider content block */ define([ - 'newsletter_editor/App', - 'newsletter_editor/blocks/base', - 'underscore', - 'jquery', - 'mailpoet' - ], function(App, BaseBlock, _, jQuery, MailPoet) { + 'newsletter_editor/App', + 'newsletter_editor/blocks/base', + 'underscore', + 'jquery', + 'mailpoet' +], function(App, BaseBlock, _, jQuery, MailPoet) { 'use strict'; var Module = {}, - base = BaseBlock; + base = BaseBlock; Module.DividerBlockModel = base.BlockModel.extend({ defaults: function() { diff --git a/assets/js/src/newsletter_editor/blocks/footer.js b/assets/js/src/newsletter_editor/blocks/footer.js index bc7f0602fb..eca25b9db7 100644 --- a/assets/js/src/newsletter_editor/blocks/footer.js +++ b/assets/js/src/newsletter_editor/blocks/footer.js @@ -2,15 +2,15 @@ * Footer content block */ define([ - 'newsletter_editor/App', - 'newsletter_editor/blocks/base', - 'underscore' - ], function(App, BaseBlock, _) { + 'newsletter_editor/App', + 'newsletter_editor/blocks/base', + 'underscore' +], function(App, BaseBlock, _) { 'use strict'; var Module = {}, - base = BaseBlock; + base = BaseBlock; Module.FooterBlockModel = base.BlockModel.extend({ defaults: function() { @@ -83,8 +83,8 @@ define([ '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_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_alignment': _.partial(this.changeField, 'styles.text.textAlign'), 'click .mailpoet_done_editing': 'close' diff --git a/assets/js/src/newsletter_editor/blocks/header.js b/assets/js/src/newsletter_editor/blocks/header.js index b5def662d3..14825dccf6 100644 --- a/assets/js/src/newsletter_editor/blocks/header.js +++ b/assets/js/src/newsletter_editor/blocks/header.js @@ -2,15 +2,15 @@ * Header content block */ define([ - 'newsletter_editor/App', - 'newsletter_editor/blocks/base', - 'underscore' - ], function(App, BaseBlock, _) { + 'newsletter_editor/App', + 'newsletter_editor/blocks/base', + 'underscore' +], function(App, BaseBlock, _) { 'use strict'; var Module = {}, - base = BaseBlock; + base = BaseBlock; Module.HeaderBlockModel = base.BlockModel.extend({ defaults: function() { diff --git a/assets/js/src/newsletter_editor/blocks/image.js b/assets/js/src/newsletter_editor/blocks/image.js index 12c76b2d34..56ba32b558 100644 --- a/assets/js/src/newsletter_editor/blocks/image.js +++ b/assets/js/src/newsletter_editor/blocks/image.js @@ -2,17 +2,17 @@ * Image content block */ define([ - 'newsletter_editor/App', - 'newsletter_editor/blocks/base', - 'underscore', - 'mailpoet' - ], function(App, BaseBlock, _, MailPoet) { + 'newsletter_editor/App', + 'newsletter_editor/blocks/base', + 'underscore', + 'mailpoet' +], function(App, BaseBlock, _, MailPoet) { 'use strict'; var Module = {}, - base = BaseBlock, - ImageWidgetView; + base = BaseBlock, + ImageWidgetView; Module.ImageBlockModel = base.BlockModel.extend({ defaults: function() { @@ -176,14 +176,14 @@ define([ this.on('updateExcluded', this.browseContent, this); var handlers = { - content: { - embed: 'embedContent', - 'edit-selection': 'editSelectionContent' - }, - toolbar: { - 'main-insert': 'mainInsertToolbar' - } - }; + content: { + embed: 'embedContent', + 'edit-selection': 'editSelectionContent' + }, + toolbar: { + 'main-insert': 'mainInsertToolbar' + } + }; _.each(handlers, function(regionHandlers, region) { _.each(regionHandlers, function(callback, handler) { @@ -301,9 +301,9 @@ define([ } }), 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 var selection = theFrame.state().get('selection'); selection.each(function(attachment) { diff --git a/assets/js/src/newsletter_editor/blocks/posts.js b/assets/js/src/newsletter_editor/blocks/posts.js index 3050adb207..137485c75c 100644 --- a/assets/js/src/newsletter_editor/blocks/posts.js +++ b/assets/js/src/newsletter_editor/blocks/posts.js @@ -11,36 +11,36 @@ * block settings view. */ define([ - 'backbone', - 'backbone.marionette', - 'backbone.radio', - 'underscore', - 'jquery', - 'mailpoet', - 'newsletter_editor/App', - 'newsletter_editor/components/communication', - 'newsletter_editor/blocks/base', - 'newsletter_editor/blocks/button', - 'newsletter_editor/blocks/divider', - 'select2' - ], function( - Backbone, - Marionette, - Radio, - _, - jQuery, - MailPoet, - App, - CommunicationComponent, - BaseBlock, - ButtonBlock, - DividerBlock + 'backbone', + 'backbone.marionette', + 'backbone.radio', + 'underscore', + 'jquery', + 'mailpoet', + 'newsletter_editor/App', + 'newsletter_editor/components/communication', + 'newsletter_editor/blocks/base', + 'newsletter_editor/blocks/button', + 'newsletter_editor/blocks/divider', + 'select2' +], function( + Backbone, + Marionette, + Radio, + _, + jQuery, + MailPoet, + App, + CommunicationComponent, + BaseBlock, + ButtonBlock, + DividerBlock ) { 'use strict'; var Module = {}, - base = BaseBlock; + base = BaseBlock; Module.PostsBlockModel = base.BlockModel.extend({ stale: ['_selectedPosts', '_availablePosts', '_transformedPosts'], @@ -414,7 +414,7 @@ define([ }, _updateContentTypes: function(postTypes) { var select = this.$('.mailpoet_settings_posts_content_type'), - selectedValue = this.model.get('contentType'); + selectedValue = this.model.get('contentType'); select.find('option').remove(); _.each(postTypes, function(type) { diff --git a/assets/js/src/newsletter_editor/blocks/social.js b/assets/js/src/newsletter_editor/blocks/social.js index 80e812fb93..bbf92ceb55 100644 --- a/assets/js/src/newsletter_editor/blocks/social.js +++ b/assets/js/src/newsletter_editor/blocks/social.js @@ -2,23 +2,23 @@ * Social icons content block */ define([ - 'newsletter_editor/App', - 'newsletter_editor/blocks/base', - 'backbone', - 'backbone.marionette', - 'backbone.supermodel', - 'underscore', - 'jquery' - ], function(App, BaseBlock, Backbone, Marionette, SuperModel, _, jQuery) { + 'newsletter_editor/App', + 'newsletter_editor/blocks/base', + 'backbone', + 'backbone.marionette', + 'backbone.supermodel', + 'underscore', + 'jquery' +], function(App, BaseBlock, Backbone, Marionette, SuperModel, _, jQuery) { 'use strict'; var Module = {}, - base = BaseBlock, - SocialBlockSettingsIconSelectorView, - SocialBlockSettingsIconView, - SocialBlockSettingsIconCollectionView, - SocialBlockSettingsStylesView; + base = BaseBlock, + SocialBlockSettingsIconSelectorView, + SocialBlockSettingsIconView, + SocialBlockSettingsIconCollectionView, + SocialBlockSettingsStylesView; Module.SocialIconModel = SuperModel.extend({ defaults: function() { diff --git a/assets/js/src/newsletter_editor/blocks/spacer.js b/assets/js/src/newsletter_editor/blocks/spacer.js index 9e0f1f23d7..59ffd90b9b 100644 --- a/assets/js/src/newsletter_editor/blocks/spacer.js +++ b/assets/js/src/newsletter_editor/blocks/spacer.js @@ -2,15 +2,15 @@ * Spacer content block */ define([ - 'newsletter_editor/App', - 'newsletter_editor/blocks/base', - 'underscore' - ], function(App, BaseBlock, _) { + 'newsletter_editor/App', + 'newsletter_editor/blocks/base', + 'underscore' +], function(App, BaseBlock, _) { 'use strict'; var Module = {}, - base = BaseBlock; + base = BaseBlock; Module.SpacerBlockModel = base.BlockModel.extend({ defaults: function() { diff --git a/assets/js/src/newsletter_editor/blocks/text.js b/assets/js/src/newsletter_editor/blocks/text.js index 86997daa89..a52653a077 100644 --- a/assets/js/src/newsletter_editor/blocks/text.js +++ b/assets/js/src/newsletter_editor/blocks/text.js @@ -2,15 +2,15 @@ * Text content block */ define([ - 'newsletter_editor/App', - 'newsletter_editor/blocks/base', - 'underscore' - ], function(App, BaseBlock, _) { + 'newsletter_editor/App', + 'newsletter_editor/blocks/base', + 'underscore' +], function(App, BaseBlock, _) { 'use strict'; var Module = {}, - base = BaseBlock; + base = BaseBlock; Module.TextBlockModel = base.BlockModel.extend({ defaults: function() { diff --git a/assets/js/src/newsletter_editor/components/communication.js b/assets/js/src/newsletter_editor/components/communication.js index 5af5bc951c..53abb48549 100644 --- a/assets/js/src/newsletter_editor/components/communication.js +++ b/assets/js/src/newsletter_editor/components/communication.js @@ -1,9 +1,9 @@ define([ - 'newsletter_editor/App', - 'underscore', - 'mailpoet', - 'ajax' - ], function(App, _, MailPoet) { + 'newsletter_editor/App', + 'underscore', + 'mailpoet', + 'ajax' +], function(App, _, MailPoet) { var Module = {}; diff --git a/assets/js/src/newsletter_editor/components/config.js b/assets/js/src/newsletter_editor/components/config.js index 32e4fe3e9d..82347780f2 100644 --- a/assets/js/src/newsletter_editor/components/config.js +++ b/assets/js/src/newsletter_editor/components/config.js @@ -1,7 +1,7 @@ define([ - 'newsletter_editor/App', - 'backbone.supermodel' - ], function(App, SuperModel) { + 'newsletter_editor/App', + 'backbone.supermodel' +], function(App, SuperModel) { var Module = {}; diff --git a/assets/js/src/newsletter_editor/components/content.js b/assets/js/src/newsletter_editor/components/content.js index f5d466782c..5987880fe5 100644 --- a/assets/js/src/newsletter_editor/components/content.js +++ b/assets/js/src/newsletter_editor/components/content.js @@ -1,9 +1,9 @@ define([ - 'newsletter_editor/App', - 'backbone.supermodel', - 'underscore', - 'mailpoet' - ], function(App, SuperModel, _, MailPoet) { + 'newsletter_editor/App', + 'backbone.supermodel', + 'underscore', + 'mailpoet' +], function(App, SuperModel, _, MailPoet) { 'use strict'; var Module = {}; @@ -15,7 +15,7 @@ define([ whitelisted: ['id', 'subject', 'preheader'], initialize: function(options) { this.on('change', function() { - App.getChannel().trigger('autoSave'); + App.getChannel().trigger('autoSave'); }); }, toJSON: function() { @@ -59,7 +59,7 @@ define([ }; Module.getNewsletter = function() { - return Module.newsletter; + return Module.newsletter; }; Module.findModels = function(predicate) { diff --git a/assets/js/src/newsletter_editor/components/heading.js b/assets/js/src/newsletter_editor/components/heading.js index 0b9dcd0add..f6a2b96c38 100644 --- a/assets/js/src/newsletter_editor/components/heading.js +++ b/assets/js/src/newsletter_editor/components/heading.js @@ -1,10 +1,10 @@ define([ - 'newsletter_editor/App', - 'backbone', - 'backbone.marionette', - 'underscore', - 'jquery' - ], function(App, Backbone, Marionette, _, jQuery) { + 'newsletter_editor/App', + 'backbone', + 'backbone.marionette', + 'underscore', + 'jquery' +], function(App, Backbone, Marionette, _, jQuery) { 'use strict'; diff --git a/assets/js/src/newsletter_editor/components/save.js b/assets/js/src/newsletter_editor/components/save.js index 3ab873a2ef..a11fe7a429 100644 --- a/assets/js/src/newsletter_editor/components/save.js +++ b/assets/js/src/newsletter_editor/components/save.js @@ -1,31 +1,31 @@ define([ - 'newsletter_editor/App', - 'newsletter_editor/components/communication', - 'mailpoet', - 'notice', - 'backbone', - 'backbone.marionette', - 'jquery', - 'blob', - 'file-saver', - 'html2canvas' - ], function( - App, - CommunicationComponent, - MailPoet, - Notice, - Backbone, - Marionette, - jQuery, - Blob, - FileSaver, - html2canvas + 'newsletter_editor/App', + 'newsletter_editor/components/communication', + 'mailpoet', + 'notice', + 'backbone', + 'backbone.marionette', + 'jquery', + 'blob', + 'file-saver', + 'html2canvas' +], function( + App, + CommunicationComponent, + MailPoet, + Notice, + Backbone, + Marionette, + jQuery, + Blob, + FileSaver, + html2canvas ) { 'use strict'; var Module = {}, - saveTimeout; + saveTimeout; // Save editor contents to server Module.save = function() { @@ -73,9 +73,9 @@ define([ // Removes 1px left transparent border from resulting canvas. var oldContext = oldCanvas.getContext('2d'), - newCanvas = document.createElement('canvas'), - newContext = newCanvas.getContext('2d'), - leftBorderWidth = 1; + newCanvas = document.createElement('canvas'), + newContext = newCanvas.getContext('2d'), + leftBorderWidth = 1; newCanvas.width = oldCanvas.width; newCanvas.height = oldCanvas.height; @@ -92,7 +92,7 @@ define([ Module.saveTemplate = function(options) { var that = this, - promise = jQuery.Deferred(); + promise = jQuery.Deferred(); promise.then(function(thumbnail) { var data = _.extend(options || {}, { @@ -189,8 +189,8 @@ define([ }, saveAsTemplate: function() { var templateName = this.$('.mailpoet_save_as_template_name').val(), - templateDescription = this.$('.mailpoet_save_as_template_description').val(), - that = this; + templateDescription = this.$('.mailpoet_save_as_template_description').val(), + that = this; if (templateName === '') { MailPoet.Notice.error( @@ -245,8 +245,8 @@ define([ }, exportTemplate: function() { var templateName = this.$('.mailpoet_export_template_name').val(), - templateDescription = this.$('.mailpoet_export_template_description').val(), - that = this; + templateDescription = this.$('.mailpoet_export_template_description').val(), + that = this; if (templateName === '') { MailPoet.Notice.error( diff --git a/assets/js/src/newsletter_editor/components/sidebar.js b/assets/js/src/newsletter_editor/components/sidebar.js index 535394a3a5..adbbd24814 100644 --- a/assets/js/src/newsletter_editor/components/sidebar.js +++ b/assets/js/src/newsletter_editor/components/sidebar.js @@ -1,23 +1,23 @@ define([ - 'newsletter_editor/App', - 'newsletter_editor/components/communication', - 'mailpoet', - 'backbone', - 'backbone.marionette', - 'backbone.supermodel', - 'underscore', - 'jquery', - 'sticky-kit' - ], function( - App, - CommunicationComponent, - MailPoet, - Backbone, - Marionette, - SuperModel, - _, - jQuery, - StickyKit + 'newsletter_editor/App', + 'newsletter_editor/components/communication', + 'mailpoet', + 'backbone', + 'backbone.marionette', + 'backbone.supermodel', + 'underscore', + 'jquery', + 'sticky-kit' +], function( + App, + CommunicationComponent, + MailPoet, + Backbone, + Marionette, + SuperModel, + _, + jQuery, + StickyKit ) { 'use strict'; diff --git a/assets/js/src/newsletter_editor/components/styles.js b/assets/js/src/newsletter_editor/components/styles.js index 7efa5adf7f..26474eb732 100644 --- a/assets/js/src/newsletter_editor/components/styles.js +++ b/assets/js/src/newsletter_editor/components/styles.js @@ -1,8 +1,8 @@ define([ - 'newsletter_editor/App', - 'backbone.marionette', - 'backbone.supermodel' - ], function(App, Marionette, SuperModel) { + 'newsletter_editor/App', + 'backbone.marionette', + 'backbone.supermodel' +], function(App, Marionette, SuperModel) { 'use strict'; diff --git a/assets/js/src/notice.js b/assets/js/src/notice.js index b52c36edbe..eef5ea4e7e 100644 --- a/assets/js/src/notice.js +++ b/assets/js/src/notice.js @@ -75,7 +75,7 @@ define('notice', ['mailpoet', 'jquery'], function(mp, jQuery) { // setup onClose callback var onClose = null; if (this.options.onClose !== null) { - onClose = this.options.onClose; + onClose = this.options.onClose; } // listen to remove event @@ -83,7 +83,7 @@ define('notice', ['mailpoet', 'jquery'], function(mp, jQuery) { jQuery(this).fadeOut(200, function() { // on close callback if (onClose !== null) { - onClose(); + onClose(); } // remove notice jQuery(this).remove(); @@ -144,13 +144,13 @@ define('notice', ['mailpoet', 'jquery'], function(mp, jQuery) { switch (this.options.type) { case 'success': this.element.addClass('notice notice-success'); - break; + break; case 'system': this.element.addClass('notice notice-warning'); - break; + break; case 'error': this.element.addClass('notice notice-error'); - break; + break; } // make the notice appear @@ -167,7 +167,7 @@ define('notice', ['mailpoet', 'jquery'], function(mp, jQuery) { } else if (this.options.hideClose === false) { this.element.append(''); this.element.find('.mailpoet_notice_close').on('click', function() { - jQuery(this).trigger('close'); + jQuery(this).trigger('close'); }); } diff --git a/assets/js/src/num.js b/assets/js/src/num.js index 5ad4b39510..f6e80808a1 100644 --- a/assets/js/src/num.js +++ b/assets/js/src/num.js @@ -4,19 +4,19 @@ define('num', ], function( mp ) { - 'use strict'; + 'use strict'; - var MailPoet = mp; - MailPoet.Num = { - toLocaleFixed: function (num, precisionOpts) { - var precision = precisionOpts || 0; - var factor = Math.pow(10, precision); - return (Math.round(num * factor) / factor) + var MailPoet = mp; + MailPoet.Num = { + toLocaleFixed: function (num, precisionOpts) { + var precision = precisionOpts || 0; + var factor = Math.pow(10, precision); + return (Math.round(num * factor) / factor) .toLocaleString( undefined, {minimumFractionDigits: precision, maximumFractionDigits: precision} ); - } - }; + } + }; -}); + }); diff --git a/assets/js/src/subscribers/importExport/export.js b/assets/js/src/subscribers/importExport/export.js index 05412f8c42..813b5f1c37 100644 --- a/assets/js/src/subscribers/importExport/export.js +++ b/assets/js/src/subscribers/importExport/export.js @@ -1,17 +1,17 @@ define( - [ - 'underscore', - 'jquery', - 'mailpoet', - 'handlebars', - 'select2' - ], + [ + 'underscore', + 'jquery', + 'mailpoet', + 'handlebars', + 'select2' + ], function ( - _, - jQuery, - MailPoet, - Handlebars, - select2 + _, + jQuery, + MailPoet, + Handlebars, + select2 ) { if (!jQuery('#mailpoet_subscribers_export').length) { return; @@ -28,17 +28,17 @@ define( // define reusable variables var segmentsContainerElement = jQuery('#export_lists'), - subscriberFieldsContainerElement = jQuery('#export_columns'), - exportConfirmedOptionElement = jQuery(':radio[name="option_confirmed"]'), - groupBySegmentOptionElement = jQuery(':checkbox[name="option_group_by_list"]'), - nextStepButton = jQuery('a.mailpoet_export_process'), - renderSegmentsAndFields = function (container, data) { - if (container.data('select2')) { - container + subscriberFieldsContainerElement = jQuery('#export_columns'), + exportConfirmedOptionElement = jQuery(':radio[name="option_confirmed"]'), + groupBySegmentOptionElement = jQuery(':checkbox[name="option_group_by_list"]'), + nextStepButton = jQuery('a.mailpoet_export_process'), + renderSegmentsAndFields = function (container, data) { + if (container.data('select2')) { + container .html('') .select2('destroy'); - } - container + } + container .select2({ data: data, width: '20em', @@ -55,11 +55,11 @@ define( }) .on('select2:selecting', function (selectEvent) { var selectElement = this, - selectedOptionId = selectEvent.params.args.data.id, - fieldsToExclude = [ - 'select', - 'deselect' - ]; + selectedOptionId = selectEvent.params.args.data.id, + fieldsToExclude = [ + 'select', + 'deselect' + ]; if (_.contains(fieldsToExclude, selectedOptionId)) { selectEvent.preventDefault(); if (selectedOptionId === 'deselect') { @@ -94,7 +94,7 @@ define( jQuery('.mailpoet_group_by_list').hide(); } }); - }; + }; // set confirmed subscribers export option to false exportData.exportConfirmedOption = false; @@ -139,39 +139,39 @@ define( MailPoet.Modal.loading(true); var exportFormat = jQuery(':radio[name="option_format"]:checked').val(); MailPoet.Ajax.post({ - api_version: window.mailpoet_api_version, - endpoint: 'ImportExport', - action: 'processExport', - data: JSON.stringify({ - export_confirmed_option: exportData.exportConfirmedOption, - export_format_option: exportFormat, - group_by_segment_option: (groupBySegmentOptionElement.is(':visible')) ? groupBySegmentOptionElement.prop('checked') : false, - segments: (exportData.segments) ? segmentsContainerElement.val() : false, - subscriber_fields: subscriberFieldsContainerElement.val() - }) - }).always(function(response) { - MailPoet.Modal.loading(false); - }).done(function(response) { - resultMessage = MailPoet.I18n.t('exportMessage') + api_version: window.mailpoet_api_version, + endpoint: 'ImportExport', + action: 'processExport', + data: JSON.stringify({ + export_confirmed_option: exportData.exportConfirmedOption, + export_format_option: exportFormat, + group_by_segment_option: (groupBySegmentOptionElement.is(':visible')) ? groupBySegmentOptionElement.prop('checked') : false, + segments: (exportData.segments) ? segmentsContainerElement.val() : false, + subscriber_fields: subscriberFieldsContainerElement.val() + }) + }).always(function(response) { + MailPoet.Modal.loading(false); + }).done(function(response) { + resultMessage = MailPoet.I18n.t('exportMessage') .replace('%1$s', '' + parseInt(response.data.totalExported).toLocaleString() + '') .replace('[link]', '') .replace('[/link]', ''); - jQuery('#export_result_notice').html('

' + resultMessage + '

').show(); - window.location.href = response.data.exportFileURL; - MailPoet.trackEvent('Subscribers export completed', { - 'Total exported': response.data.totalExported, - 'Only confirmed?': exportData.exportConfirmedOption, - 'File Format': exportFormat, - 'MailPoet Free version': window.mailpoet_version - }); - }).fail(function(response) { - if (response.errors.length > 0) { - MailPoet.Notice.error( + jQuery('#export_result_notice').html('

' + resultMessage + '

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