Merge pull request #1047 from mailpoet/eslint-assignment

Eslint assignment [MAILPOET-1033]
This commit is contained in:
amine-mp
2017-08-22 09:59:35 +02:00
committed by GitHub
57 changed files with 240 additions and 169 deletions

View File

@ -33,10 +33,8 @@
"no-useless-return": 0,
"array-callback-return": 0,
"new-cap": 0,
"no-return-assign": 0,
"no-continue": 0,
"no-new": 0,
"no-cond-assign": 0,
"space-unary-ops": 0,
"no-redeclare": 0,
"no-console": 0,
@ -60,7 +58,6 @@
"space-in-parens": 0,
"semi": 0,
"max-len": 0,
"no-multi-assign": 0,
"no-trailing-spaces": 0,
"global-require": 0,
"no-throw-literal": 0,
@ -85,7 +82,6 @@
"no-unused-vars": 0,
"object-shorthand": 0,
"new-parens": 0,
"no-param-reassign": 0,
"keyword-spacing": 0,
"eol-last": 0,
"dot-notation": 0,

View File

@ -80,7 +80,6 @@
"no-sequences": 0,
"no-extra-boolean-cast": 0,
"dot-notation": 0,
"no-param-reassign": 0,
"no-shadow": 0,
"one-var": 0,
"no-alert": 0,

View File

@ -22,7 +22,6 @@
"semi": 0,
"keyword-spacing": 0,
"no-bitwise": 0,
"no-multi-assign": 0,
"newline-per-chained-call": 0,
"no-spaced-func": 0,
"func-call-spacing": 0,
@ -38,7 +37,6 @@
"vars-on-top": 0,
"space-before-blocks": 0,
"object-curly-spacing": 0,
"no-param-reassign": 0,
"one-var-declaration-per-line": 0,
"func-names": 0,
"space-before-function-paren": 0

View File

@ -12,7 +12,8 @@ function requestFailed(errorMessage, xhr) {
};
}
define('ajax', ['mailpoet', 'jquery', 'underscore'], function(MailPoet, jQuery, _) {
define('ajax', ['mailpoet', 'jquery', 'underscore'], function(mp, jQuery, _) {
var MailPoet = mp;
MailPoet.Ajax = {
version: 0.5,

View File

@ -24,7 +24,8 @@ function track(name, data){
window.mixpanel.track(name, data);
}
function exportMixpanel(MailPoet) {
function exportMixpanel(mp) {
var MailPoet = mp;
MailPoet.forceTrackEvent = track;
if (window.mailpoet_analytics_enabled) {
@ -61,7 +62,8 @@ function cacheEvent(forced, name, data) {
define(
['mailpoet', 'underscore'],
function(MailPoet, _) {
function(mp, _) {
var MailPoet = mp;
MailPoet.trackEvent = _.partial(cacheEvent, false);
MailPoet.forceTrackEvent = _.partial(cacheEvent, true);

View File

@ -4,12 +4,14 @@ define('date',
'jquery',
'moment'
], function(
MailPoet,
mp,
jQuery,
Moment
) {
'use strict';
var MailPoet = mp;
MailPoet.Date = {
version: 0.1,
options: {},
@ -17,8 +19,8 @@ define('date',
offset: 0,
format: 'F, d Y H:i:s'
},
init: function(options) {
options = options || {};
init: function (opts) {
var options = opts || {};
// set UTC offset
if (
@ -39,16 +41,16 @@ define('date',
return this;
},
format: function(date, options) {
options = options || {};
format: function(date, opts) {
var options = opts || {};
this.init(options);
var date = Moment(date, this.convertFormat(options.parseFormat));
if (options.offset === 0) date = date.utc();
return date.format(this.convertFormat(this.options.format));
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, options) {
options = options || {};
toDate: function(date, opts) {
var options = opts || {};
this.init(options);
return Moment(date, this.convertFormat(options.parseFormat)).toDate();
@ -143,7 +145,8 @@ define('date',
var convertedFormat = [];
var escapeToken = false;
for(var index = 0, token = ''; token = format.charAt(index); index++){
for(var index = 0, token = ''; format.charAt(index); index += 1){
token = format.charAt(index);
if (escapeToken === true) {
convertedFormat.push('['+token+']');
escapeToken = false;

View File

@ -28,12 +28,13 @@ define([
}
let field = false;
let dataField = data.field;
if(data.field['field'] !== undefined) {
data.field = jQuery.merge(data.field, data.field.field);
dataField = jQuery.merge(dataField, data.field.field);
}
switch(data.field.type) {
switch(dataField.type) {
case 'text':
field = (<FormFieldText {...data} />);
break;

View File

@ -11,12 +11,14 @@ Object.extend(document, (function() {
var cache = Event.cacheDelegated;
function getCacheForSelector(selector) {
return cache[selector] = cache[selector] || {};
cache[selector] = cache[selector] || {};
return cache[selector];
}
function getWrappersForSelector(selector, eventName) {
var c = getCacheForSelector(selector);
return c[eventName] = c[eventName] || [];
c[eventName] = c[eventName] || [];
return c[eventName];
}
function findWrapper(selector, eventName, handler) {
@ -79,8 +81,8 @@ Object.extend(document, (function() {
})());
var Observable = (function() {
function getEventName(name, namespace) {
name = name.substring(2);
function getEventName(nameA, namespace) {
var name = nameA.substring(2);
if(namespace) name = namespace + ':' + name;
return name.underscore().split('_').join(':');
}
@ -574,7 +576,8 @@ var WysijaForm = {
WysijaForm.locks.showingTools = false;
},
instances: {},
get: function(element, type) {
get: function(element, typ) {
var type = typ;
if(type === undefined) type = 'block';
// identify element
var id = element.identify();
@ -893,7 +896,8 @@ WysijaForm.Block = Class.create({
});
/* Invoked on item dropped */
WysijaForm.Block.create = function(block, target) {
WysijaForm.Block.create = function(createBlock, target) {
var block = createBlock;
if($('form_template_' + block.type) === null) {
return false;
}
@ -1050,7 +1054,8 @@ function info(value) {
var noop = function() {};
var methods = ['assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error', 'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log', 'markTimeline', 'profile', 'profileEnd', 'markTimeline', 'table', 'time', 'timeEnd', 'timeStamp', 'trace', 'warn'];
var length = methods.length;
var console = window.console = {};
window.console = {};
var console = {};
while(length--) {
console[methods[length]] = noop;
}

View File

@ -125,12 +125,13 @@ define('handlebars_helpers', ['handlebars'], function(Handlebars) {
* @return {String} The truncated string.
*/
Handlebars.registerHelper('ellipsis', function (str, limit, append) {
if (append === undefined) {
append = '';
var strAppend = append;
if (strAppend === undefined) {
strAppend = '';
}
var sanitized = str.replace(/(<([^>]+)>)/g, '');
if (sanitized.length > limit) {
return sanitized.substr(0, limit - append.length) + append;
return sanitized.substr(0, limit - strAppend.length) + strAppend;
} else {
return sanitized;
}

View File

@ -2,9 +2,10 @@ define('i18n',
[
'mailpoet'
], function(
MailPoet
mp
) {
'use strict';
var MailPoet = mp;
var translations = {};

View File

@ -1,5 +1,6 @@
define('iframe', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
define('iframe', ['mailpoet'], function(mp) {
'use strict';
var MailPoet = mp;
MailPoet.Iframe = {
marginY: 20,
autoSize: function(iframe) {
@ -10,11 +11,12 @@ define('iframe', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
iframe.contentWindow.document.body.scrollHeight
);
},
setSize: function(iframe, i) {
setSize: function(sizeIframe, i) {
var iframe = sizeIframe;
if(!iframe) return;
iframe.style.height = (
parseInt(i) + this.marginY
parseInt(i, 10) + this.marginY
) + "px";
}
};

View File

@ -3,8 +3,9 @@ define(
'jquery'
],
function(
$
jQuery
) {
var $ = jQuery;
// Combination of jQuery.deparam and jQuery.serializeObject by Ben Alman.
/*!
* jQuery BBQ: Back Button & Query Library - v1.2.1 - 2/17/2010
@ -74,9 +75,10 @@ define(
// * Rinse & repeat.
for ( ; i <= keys_last; i++ ) {
key = keys[i] === '' ? cur.length : keys[i];
cur = cur[key] = i < keys_last
cur[key] = i < keys_last
? cur[key] || ( keys[i+1] && isNaN( keys[i+1] ) ? {} : [] )
: val;
cur = cur[key];
}
} else {

View File

@ -10,8 +10,9 @@ const ListingHeader = React.createClass({
},
render: function () {
const columns = this.props.columns.map((column, index) => {
column.is_primary = (index === 0);
column.sorted = (this.props.sort_by === column.name)
const renderColumn = column;
renderColumn.is_primary = (index === 0);
renderColumn.sorted = (this.props.sort_by === column.name)
? this.props.sort_order
: 'desc';
return (
@ -19,7 +20,7 @@ const ListingHeader = React.createClass({
onSort={this.props.onSort}
sort_by={this.props.sort_by}
key={ 'column-' + index }
column={column} />
column={renderColumn} />
);
});

View File

@ -260,8 +260,9 @@ const ListingItems = React.createClass({
</tr>
{this.props.items.map((item, index) => {
item.id = parseInt(item.id, 10);
item.selected = (this.props.selected_ids.indexOf(item.id) !== -1);
const renderItem = item;
renderItem.id = parseInt(item.id, 10);
renderItem.selected = (this.props.selected_ids.indexOf(renderItem.id) !== -1);
return (
<ListingItem
@ -276,8 +277,8 @@ const ListingItems = React.createClass({
is_selectable={ this.props.is_selectable }
item_actions={ this.props.item_actions }
group={ this.props.group }
key={ `item-${item.id}-${index}` }
item={ item } />
key={ `item-${renderItem.id}-${index}` }
item={ renderItem } />
);
})}
</tbody>
@ -418,16 +419,17 @@ const Listing = React.createClass({
}
},
setBaseUrlParams: function (base_url) {
if (base_url.indexOf(':') !== -1) {
let ret = base_url;
if (ret.indexOf(':') !== -1) {
const params = this.getParams();
Object.keys(params).map((key) => {
if (base_url.indexOf(':'+key) !== -1) {
base_url = base_url.replace(':'+key, params[key]);
if (ret.indexOf(':'+key) !== -1) {
ret = ret.replace(':'+key, params[key]);
}
});
}
return base_url;
return ret;
},
componentDidMount: function () {
if (this.isMounted()) {

View File

@ -1,6 +1,7 @@
define('modal', ['mailpoet', 'jquery'],
function(MailPoet, jQuery) {
function(mp, jQuery) {
'use strict';
var MailPoet = mp;
/***************************************************************************
MailPoet Modal:
@ -459,9 +460,9 @@ define('modal', ['mailpoet', 'jquery'],
jQuery('#mailpoet_modal_overlay').hide();
return this;
},
popup: function(options) {
popup: function(opts) {
// get options
options = options || {};
var options = opts || {};
// set modal type
options.type = 'popup';
// set overlay state
@ -473,9 +474,9 @@ define('modal', ['mailpoet', 'jquery'],
return this;
},
panel: function(options) {
panel: function(opts) {
// get options
options = options || {};
var options = opts || {};
// reset subpanels
this.subpanels = [];
// set modal type

View File

@ -1,5 +1,6 @@
define('mp2migrator', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
define('mp2migrator', ['mailpoet', 'jquery'], function(mp, jQuery) {
'use strict';
var MailPoet = mp;
MailPoet.MP2Migrator = {
fatal_error: '',
@ -28,7 +29,8 @@ define('mp2migrator', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
cache: false
}).done(function (result) {
jQuery("#logger").html('');
result.split("\n").forEach(function (row) {
result.split("\n").forEach(function (resultRow) {
var row = resultRow;
if(row.substr(0, 7) === '[ERROR]' || row.substr(0, 9) === '[WARNING]' || row === MailPoet.I18n.t('import_stopped_by_user')) {
row = '<span class="error_msg">' + row + '</span>'; // Mark the errors in red
}

View File

@ -6,7 +6,8 @@ define([
'underscore',
'handlebars',
'handlebars_helpers'
], function(Backbone, Marionette, Radio, jQuery, _, Handlebars) {
], function(Backbone, Marionette, BackboneRadio, jQuery, _, Handlebars) {
var Radio = BackboneRadio;
var AppView = Marionette.View.extend({
el: '#mailpoet_editor',
@ -28,7 +29,9 @@ define([
},
getChannel: function(channel) {
if (channel === undefined) channel = 'global';
if (channel === undefined) {
return Radio.channel('global');
}
return Radio.channel(channel);
}
});

View File

@ -6,8 +6,8 @@
*/
define([
'backbone.marionette'
], function(Marionette) {
], function(BackboneMarionette) {
var Marionette = BackboneMarionette;
var BehaviorsLookup = {};
Marionette.Behaviors.behaviorsLookup = function() {
return BehaviorsLookup;

View File

@ -9,8 +9,9 @@ define([
'mailpoet',
'spectrum'
], function(Marionette, BehaviorsLookup, MailPoet, Spectrum) {
var BL = BehaviorsLookup;
BehaviorsLookup.ColorPickerBehavior = Marionette.Behavior.extend({
BL.ColorPickerBehavior = Marionette.Behavior.extend({
onRender: function() {
this.view.$('.mailpoet_color').spectrum({
clickoutFiresChange: true,

View File

@ -11,7 +11,8 @@ define([
'jquery',
'newsletter_editor/behaviors/BehaviorsLookup',
'interact'
], function(Marionette, _, jQuery, BehaviorsLookup, interact) {
], function(Marionette, _, jQuery, BL, interact) {
var BehaviorsLookup = BL;
BehaviorsLookup.ContainerDropZoneBehavior = Marionette.Behavior.extend({
defaults: {
@ -268,7 +269,7 @@ define([
// 2. Remove visual markings of drop position visualization
this.view.$('.mailpoet_drop_marker').remove();
},
getDropPosition: function(eventX, eventY, unsafe) {
getDropPosition: function(eventX, eventY, is_unsafe) {
var SPECIAL_AREA_INSERTION_WIDTH = 0.00, // Disable special insertion. Default: 0.3
element = this.view.$el,
@ -290,7 +291,7 @@ define([
insertionType, index, position, indexAndPosition;
unsafe = !!unsafe;
unsafe = !!is_unsafe;
if (this.getCollection().length === 0) {
return {

View File

@ -11,8 +11,9 @@ define([
'newsletter_editor/behaviors/BehaviorsLookup',
'interact'
], function(Marionette, _, jQuery, BehaviorsLookup, interact) {
var BL = BehaviorsLookup;
BehaviorsLookup.DraggableBehavior = Marionette.Behavior.extend({
BL.DraggableBehavior = Marionette.Behavior.extend({
defaults: {
cloneOriginal: false,
hideOriginal: false,
@ -46,7 +47,8 @@ define([
// Scroll when dragging near edges of a window
autoScroll: true,
onstart: function(event) {
onstart: function(startEvent) {
var event = startEvent;
if (that.options.cloneOriginal === true) {
// Use substitution instead of a clone
@ -89,9 +91,8 @@ define([
y = (parseFloat(target.getAttribute('data-y')) || 0) + event.dy;
// translate the element
target.style.webkitTransform =
target.style.transform =
'translate(' + x + 'px, ' + y + 'px)';
target.style.transform = 'translate(' + x + 'px, ' + y + 'px)';
target.style.webkitTransform = target.style.transform;
// update the posiion attributes
target.setAttribute('data-x', x);
@ -99,7 +100,8 @@ define([
},
onend: function (event) {
var target = event.target;
target.style.webkitTransform = target.style.transform = '';
target.style.transform = '';
target.style.webkitTransform = target.style.transform;
target.removeAttribute('data-x');
target.removeAttribute('data-y');
jQuery(event.interaction.element).addClass('mailpoet_droppable_active');
@ -129,7 +131,8 @@ define([
} else {
interactable.getDropModel = this.view.getDropFunc();
}
interactable.onDrop = function(options) {
interactable.onDrop = function(opts) {
var options = opts;
if (_.isObject(options)) {
// Inject Draggable behavior if possible
options.dragBehavior = that;

View File

@ -7,8 +7,9 @@ define([
'backbone.marionette',
'newsletter_editor/behaviors/BehaviorsLookup'
], function(Marionette, BehaviorsLookup) {
var BL = BehaviorsLookup;
BehaviorsLookup.HighlightEditingBehavior = Marionette.Behavior.extend({
BL.HighlightEditingBehavior = Marionette.Behavior.extend({
modelEvents: {
'startEditing': 'enableHighlight',
'stopEditing': 'disableHighlight'

View File

@ -8,8 +8,9 @@ define([
'newsletter_editor/behaviors/BehaviorsLookup',
'interact'
], function(Marionette, BehaviorsLookup, interact) {
var BL = BehaviorsLookup;
BehaviorsLookup.ResizableBehavior = Marionette.Behavior.extend({
BL.ResizableBehavior = Marionette.Behavior.extend({
defaults: {
elementSelector: null,
resizeHandleSelector: true, // true will use edges of the element itself

View File

@ -8,8 +8,9 @@ define([
'jquery',
'newsletter_editor/behaviors/BehaviorsLookup'
], function(Marionette, jQuery, BehaviorsLookup) {
var BL = BehaviorsLookup;
BehaviorsLookup.ShowSettingsBehavior = Marionette.Behavior.extend({
BL.ShowSettingsBehavior = Marionette.Behavior.extend({
defaults: {
ignoreFrom: '' // selector
},

View File

@ -8,8 +8,9 @@ define([
'underscore',
'newsletter_editor/behaviors/BehaviorsLookup'
], function(Marionette, _, BehaviorsLookup) {
var BL = BehaviorsLookup;
BehaviorsLookup.SortableBehavior = Marionette.Behavior.extend({
BL.SortableBehavior = Marionette.Behavior.extend({
onRender: function() {
var collection = this.view.collection;

View File

@ -8,8 +8,9 @@ define([
'underscore',
'newsletter_editor/behaviors/BehaviorsLookup'
], function(Marionette, _, BehaviorsLookup) {
var BL = BehaviorsLookup;
BehaviorsLookup.TextEditorBehavior = Marionette.Behavior.extend({
BL.TextEditorBehavior = Marionette.Behavior.extend({
defaults: {
selector: '.mailpoet_content',
toolbar1: "bold italic link unlink forecolor mailpoet_shortcodes",

View File

@ -392,8 +392,9 @@ define([
});
App.on('start', function(App, options) {
App._ALCSupervisor = new Module.ALCSupervisor();
App._ALCSupervisor.refresh();
var Application = App;
Application._ALCSupervisor = new Module.ALCSupervisor();
Application._ALCSupervisor.refresh();
});
return Module;

View File

@ -194,8 +194,8 @@ define([
move: true
},
getSettingsView: function() { return Module.BlockSettingsView; },
initialize: function(options) {
options = options || {};
initialize: function(opts) {
var options = opts || {};
if (!_.isUndefined(options.tools)) {
// Make a new block specific tool config object
this.tools = jQuery.extend({}, this.tools, options.tools || {});

View File

@ -277,7 +277,8 @@ define([
},
mainEmbedToolbar: function(toolbar) {
toolbar.view = new wp.media.view.Toolbar.Embed({
var tbar = toolbar;
tbar.view = new wp.media.view.Toolbar.Embed({
controller: this,
text: 'Add images'
});
@ -285,7 +286,7 @@ define([
});
var theFrame = this._mediaManager = new MediaManager({
var theFrame = new MediaManager({
id: 'mailpoet-media-manager',
frame: 'select',
title: 'Select image',
@ -300,8 +301,9 @@ define([
}
}),
that = this;
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) {

View File

@ -23,8 +23,8 @@
}
}(this, function(Marionette, Radio, _) {
'use strict';
Marionette.Application.prototype._initChannel = function () {
var MarionetteApplication = Marionette.Application;
MarionetteApplication.prototype._initChannel = function () {
this.channelName = _.result(this, 'channelName') || 'global';
this.channel = _.result(this, 'channel') || Radio.channel(this.channelName);
};

View File

@ -25,11 +25,12 @@ define([
};
App.on('before:start', function(App, options) {
var Application = App;
// Expose config methods globally
App.getConfig = Module.getConfig;
App.setConfig = Module.setConfig;
Application.getConfig = Module.getConfig;
Application.setConfig = Module.setConfig;
App.setConfig(options.config);
Application.setConfig(options.config);
});
return Module;

View File

@ -67,7 +67,8 @@ define([
return _.filter(blocks, predicate);
};
App.on('before:start', function(App, options) {
App.on('before:start', function(Application, options) {
var App = Application;
// Expose block methods globally
App.registerBlockType = Module.registerBlockType;
App.getBlockTypeModel = Module.getBlockTypeModel;
@ -80,7 +81,8 @@ define([
Module.newsletter = new Module.NewsletterModel(_.omit(_.clone(options.newsletter), ['body']));
});
App.on('start', function(App, options) {
App.on('start', function(Application, options) {
var App = Application;
var body = options.newsletter.body;
var content = (_.has(body, 'content')) ? body.content : {};

View File

@ -67,9 +67,10 @@ define([
// For getting a promise after triggering save event
Module.saveAndProvidePromise = function(saveResult) {
var result = saveResult;
var promise = Module.save();
if (saveResult !== undefined) {
saveResult.promise = promise;
result.promise = promise;
}
};
@ -337,10 +338,10 @@ define([
Module.beforeExitWithUnsavedChanges = function(e) {
if (saveTimeout) {
var message = MailPoet.I18n.t('unsavedChangesWillBeLost');
e = e || window.event;
var event = e || window.event;
if (e) {
e.returnValue = message;
if (event) {
event.returnValue = message;
}
return message;
@ -348,12 +349,13 @@ define([
};
App.on('before:start', function(App, options) {
App.save = Module.saveAndProvidePromise;
App.getChannel().on('autoSave', Module.autoSave);
var Application = App;
Application.save = Module.saveAndProvidePromise;
Application.getChannel().on('autoSave', Module.autoSave);
window.onbeforeunload = Module.beforeExitWithUnsavedChanges;
App.getChannel().on('save', function(saveResult) { App.save(saveResult); });
Application.getChannel().on('save', function(saveResult) { Application.save(saveResult); });
});
App.on('start', function(App, options) {

View File

@ -367,10 +367,11 @@ define([
});
App.on('before:start', function(App, options) {
App.registerWidget = Module.registerWidget;
App.getWidgets = Module.getWidgets;
App.registerLayoutWidget = Module.registerLayoutWidget;
App.getLayoutWidgets = Module.getLayoutWidgets;
var Application = App;
Application.registerWidget = Module.registerWidget;
Application.getWidgets = Module.getWidgets;
Application.registerLayoutWidget = Module.registerLayoutWidget;
Application.getLayoutWidgets = Module.getLayoutWidgets;
});
App.on('start', function(App, options) {

View File

@ -69,10 +69,11 @@ define([
};
App.on('before:start', function(App, options) {
var Application = App;
// Expose style methods to global application
App.getGlobalStyles = Module.getGlobalStyles;
App.setGlobalStyles = Module.setGlobalStyles;
App.getAvailableStyles = Module.getAvailableStyles;
Application.getGlobalStyles = Module.getGlobalStyles;
Application.setGlobalStyles = Module.setGlobalStyles;
Application.getAvailableStyles = Module.getAvailableStyles;
var body = options.newsletter.body;
var globalStyles = (_.has(body, 'globalStyles')) ? body.globalStyles : {};

View File

@ -145,13 +145,14 @@ const _QueueMixin = {
const _StatisticsMixin = {
renderStatistics: function (newsletter, is_sent, current_time) {
if (is_sent === undefined) {
let sent = is_sent;
if (sent === undefined) {
// condition for standard and post notification listings
is_sent = newsletter.statistics
sent = newsletter.statistics
&& newsletter.queue
&& newsletter.queue.status !== 'scheduled';
}
if (!is_sent) {
if (!sent) {
return (
<span>{MailPoet.I18n.t('notSentYet')}</span>
);

View File

@ -8,12 +8,14 @@ define(
],
(
React,
jQuery,
jq,
_,
MailPoet,
Hooks
) => {
const jQuery = jq;
const currentTime = window.mailpoet_current_time || '00:00';
const defaultDateTime = window.mailpoet_current_date + ' ' + '00:00:00';
const timeOfDayItems = window.mailpoet_schedule_time_of_day;
@ -84,12 +86,13 @@ define(
const DateText = React.createClass({
onChange: function (event) {
const changeEvent = event;
// Swap display format to storage format
const displayDate = event.target.value;
const displayDate = changeEvent.target.value;
const storageDate = this.getStorageDate(displayDate);
event.target.value = storageDate;
this.props.onChange(event);
changeEvent.target.value = storageDate;
this.props.onChange(changeEvent);
},
componentDidMount: function () {
const $element = jQuery(this.refs.dateInput);
@ -273,8 +276,9 @@ define(
});
},
handleCheckboxChange: function (event) {
event.target.value = this.refs.isScheduled.checked ? '1' : '0';
return this.handleValueChange(event);
const changeEvent = event;
changeEvent.target.value = this.refs.isScheduled.checked ? '1' : '0';
return this.handleValueChange(changeEvent);
},
isScheduled: function () {
return this._getCurrentValue().isScheduled === '1';
@ -419,11 +423,11 @@ define(
return fields;
},
getSendButtonOptions: function (newsletter) {
newsletter = newsletter || {};
const newsletterOptions = newsletter || {};
const isScheduled = (
typeof newsletter.options === 'object'
&& newsletter.options.isScheduled === '1'
typeof newsletterOptions.options === 'object'
&& newsletterOptions.options.isScheduled === '1'
);
const options = {
value: (isScheduled
@ -431,8 +435,8 @@ define(
: MailPoet.I18n.t('send')),
};
if (newsletter.status === 'sent'
|| newsletter.status === 'sending') {
if (newsletterOptions.status === 'sent'
|| newsletterOptions.status === 'sending') {
options['disabled'] = 'disabled';
}

View File

@ -19,7 +19,8 @@ define(
) => {
const ImportTemplate = React.createClass({
saveTemplate: function (template) {
saveTemplate: function (saveTemplate) {
const template = saveTemplate;
// Stringify to enable transmission of primitive non-string value types
if (!_.isUndefined(template.body)) {

View File

@ -1,4 +1,4 @@
define('notice', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
define('notice', ['mailpoet', 'jquery'], function(mp, jQuery) {
"use strict";
/*==================================================================================================
@ -22,7 +22,7 @@ define('notice', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
MailPoet.Notice.system('You need to updated ASAP!');
==================================================================================================*/
var MailPoet = mp;
MailPoet.Notice = {
version: 1.0,
// default options
@ -103,12 +103,12 @@ define('notice', ['mailpoet', 'jquery'], function(MailPoet, jQuery) {
);
},
setMessage: function(message) {
message = this.formatMessage(message);
var formattedMessage = this.formatMessage(message);
// let's sugar coat the message with a fancy <p>
message = '<p>'+message+'</p>';
formattedMessage = '<p>'+formattedMessage+'</p>';
// set message
return this.element.html(message);
return this.element.html(formattedMessage);
},
formatMessage: function(message) {
if (Array.isArray(message)) {

View File

@ -2,13 +2,14 @@ define('num',
[
'mailpoet'
], function(
MailPoet
mp
) {
'use strict';
var MailPoet = mp;
MailPoet.Num = {
toLocaleFixed: function (num, precision) {
precision = precision || 0;
toLocaleFixed: function (num, precisionOpts) {
var precision = precisionOpts || 0;
var factor = Math.pow(10, precision);
return (Math.round(num * factor) / factor)
.toLocaleString(

View File

@ -7,8 +7,9 @@ define(
function(
Backbone,
jQuery,
MailPoet
mp
) {
var MailPoet = mp;
if(jQuery('#mailpoet_settings').length === 0) {
return;
}
@ -50,9 +51,9 @@ define(
jQuery('#mailpoet_sending_method_setup').fadeIn();
}
},
tabs: function(tab, section) {
tabs: function(tabStr, section) {
// set default tab
tab = tab || 'mta';
var tab = tabStr || 'mta';
// reset all active tabs
jQuery('.nav-tab-wrapper a').removeClass('nav-tab-active');

View File

@ -52,8 +52,9 @@ define(
router.on('route:step1', function () {
// set or reset temporary validation rule on all columns
mailpoetColumns = jQuery.map(mailpoetColumns, function (column, columnIndex) {
column.validation_rule = false;
return column;
var col = column;
col.validation_rule = false;
return col;
});
if (typeof (importData.step1) !== 'undefined') {
@ -302,10 +303,10 @@ define(
advancedOptionComments = false,
// trim spaces, commas, periods,
// single/double quotes and convert to lowercase
detectAndCleanupEmail = function (email) {
detectAndCleanupEmail = function (emailString) {
var test;
// decode HTML entities
email = jQuery('<div />').html(email).text();
var email = jQuery('<div />').html(emailString).text();
email = email
.toLowerCase()
// left/right trim spaces, punctuation (e.g., " 'email@email.com'; ")
@ -315,11 +316,13 @@ define(
// remove urlencoded characters
.replace(/\s+|%\d+|,+/g, '');
// detect e-mails that will be otherwise rejected by email regex
if (test = /<(.*?)>/.exec(email)) {
test = /<(.*?)>/.exec(email);
if (test) {
// is the email inside angle brackets (e.g., 'some@email.com <some@email.com>')?
email = test[1].trim();
}
if (test = /mailto:(?:\s+)?(.*)/.exec(email)) {
test = /mailto:(?:\s+)?(.*)/.exec(email);
if (test) {
// is the email in 'mailto:email' format?
email = test[1].trim();
}
@ -534,12 +537,14 @@ define(
data: segments,
width: '20em',
templateResult: function (item) {
item.subscriberCount = parseInt(item.subscriberCount);
return item.name + ' (' + item.subscriberCount.toLocaleString() + ')';
var i = item;
i.subscriberCount = parseInt(i.subscriberCount, 10);
return i.name + ' (' + i.subscriberCount.toLocaleString() + ')';
},
templateSelection: function (item) {
item.subscriberCount = parseInt(item.subscriberCount);
return item.name + ' (' + item.subscriberCount.toLocaleString() + ')';
var i = item;
i.subscriberCount = parseInt(i.subscriberCount, 10);
return i.name + ' (' + i.subscriberCount.toLocaleString() + ')';
}
})
.change(function () {
@ -894,7 +899,8 @@ define(
}
}
}
jQuery.map(subscribersClone.subscribers, function (data, index) {
jQuery.map(subscribersClone.subscribers, function (dataSubscribers, index) {
var data = dataSubscribers;
var rowData = data[matchedColumn.index];
if (index === fillerPosition || rowData.trim() === '') return;
var date = Moment(rowData, testedFormat, true);

View File

@ -3,7 +3,7 @@
"scripts": {
"lint": "npm run lint6 && npm run lint5 && npm run lint-tests",
"lint6": "eslint -c .eslintrc.es6.json --max-warnings 0 'assets/js/src/**/*.jsx'",
"lint5": "eslint -c .eslintrc.es5.json --max-warnings 0 'assets/js/src/**/*.js'",
"lint5": "eslint -c .eslintrc.es5.json --ignore-pattern helpscout.js --max-warnings 0 'assets/js/src/**/*.js'",
"lint-tests": "eslint -c .eslintrc.tests.json --max-warnings 0 'tests/javascript'"
},
"dependencies": {

View File

@ -1,9 +1,9 @@
var fs = require('fs');
module.exports = {
loadFileToContainer: function (path, window, containerTagName, options) {
loadFileToContainer: function (path, window, containerTagName, opts) {
var contents = fs.readFileSync(path),
container = window.document.createElement(containerTagName);
options = options || {};
var options = opts || {};
container.innerHTML = contents;
if (options.type) {
@ -17,9 +17,9 @@ module.exports = {
loadScript: function (scriptPath, window, options) {
this.loadFileToContainer(scriptPath, window, 'script', options);
},
loadTemplate: function (path, window, options) {
loadTemplate: function (path, window, opts) {
var w = window || global.window;
options = options || {};
var options = opts || {};
options.type = "text/x-handlebars-template";
this.loadScript("views/newsletter/templates/" + path, w, options);

View File

@ -28,7 +28,9 @@ if (!global.document || !global.window) {
}
global.testHelpers = require('./loadHelpers.js');
global.$ = global.jQuery = global.window.jQuery = require('jquery');
global.$ = require('jquery');
global.jQuery = require('jquery');
global.window.jQuery = require('jquery');
testHelpers.loadScript('tests/javascript/testBundles/vendor.js', global.window);
global.Handlebars = global.window.Handlebars;
@ -46,27 +48,28 @@ global.interact = function () {
styleCursor: global.interact
};
};
jQuery.fn.spectrum = global.spectrum = function() { return this; };
global.spectrum = function() { return this; };
jQuery.fn.spectrum = global.spectrum;
jQuery.fn.stick_in_parent = function() { return this; };
// Add global stubs for convenience
// TODO: Extract those to a separate file
global.stubChannel = function (EditorApplication, returnObject) {
EditorApplication.getChannel = sinon.stub().returns(_.defaults(returnObject || {}, {
var App = EditorApplication;
App.getChannel = sinon.stub().returns(_.defaults(returnObject || {}, {
trigger: function () {
},
on: function () {
}
}));
};
global.stubConfig = function (EditorApplication, config) {
config = config || {};
EditorApplication.getConfig = sinon.stub().returns(new Backbone.SuperModel(config));
global.stubConfig = function (EditorApplication, opts) {
var App = EditorApplication;
App.getConfig = sinon.stub().returns(new Backbone.SuperModel(opts || {}));
};
global.stubAvailableStyles = function (EditorApplication, styles) {
styles = styles || {};
EditorApplication.getAvailableStyles = sinon.stub().returns(new Backbone.SuperModel(styles));
var App = EditorApplication;
App.getAvailableStyles = sinon.stub().returns(new Backbone.SuperModel(styles || {}));
};
global.stubImage = function(defaultWidth, defaultHeight) {

View File

@ -5,12 +5,14 @@ define([
'amd-inject-loader!newsletter_editor/blocks/automatedLatestContent',
'newsletter_editor/components/communication'
], function(
EditorApplication,
App,
AutomatedLatestContentBlock,
ContainerBlock,
AutomatedLatestContentInjector,
CommunicationComponent
Communication
) {
var EditorApplication = App;
var CommunicationComponent = Communication;
describe('Automated Latest Content Supervisor', function() {
var model;

View File

@ -1,7 +1,8 @@
define([
'newsletter_editor/App',
'newsletter_editor/blocks/button'
], function(EditorApplication, ButtonBlock) {
], function(App, ButtonBlock) {
var EditorApplication = App;
describe("Button", function () {
describe("model", function () {

View File

@ -1,7 +1,8 @@
define([
'newsletter_editor/App',
'newsletter_editor/blocks/container'
], function(EditorApplication, ContainerBlock) {
], function(App, ContainerBlock) {
var EditorApplication = App;
describe('Container', function () {
var ModelClass = ContainerBlock.ContainerBlockModel;

View File

@ -1,7 +1,8 @@
define([
'newsletter_editor/App',
'newsletter_editor/blocks/divider'
], function(EditorApplication, DividerBlock) {
], function(App, DividerBlock) {
var EditorApplication = App;
describe("Divider", function () {
describe("model", function () {

View File

@ -1,7 +1,8 @@
define([
'newsletter_editor/App',
'newsletter_editor/blocks/footer'
], function(EditorApplication, FooterBlock) {
], function(App, FooterBlock) {
var EditorApplication = App;
describe('Footer', function () {
describe('model', function () {

View File

@ -1,7 +1,8 @@
define([
'newsletter_editor/App',
'newsletter_editor/blocks/header'
], function(EditorApplication, HeaderBlock) {
], function(App, HeaderBlock) {
var EditorApplication = App;
describe('Header', function () {
describe('model', function () {

View File

@ -1,7 +1,8 @@
define([
'newsletter_editor/App',
'newsletter_editor/blocks/image'
], function(EditorApplication, ImageBlock) {
], function(App, ImageBlock) {
var EditorApplication = App;
describe('Image', function () {
describe('model', function () {

View File

@ -3,7 +3,9 @@ define([
'newsletter_editor/components/communication',
'newsletter_editor/blocks/posts',
'newsletter_editor/blocks/container'
], function(EditorApplication, CommunicationComponent, PostsBlock, ContainerBlock) {
], function(App, Communication, PostsBlock, ContainerBlock) {
var EditorApplication = App;
var CommunicationComponent = Communication;
describe('Posts', function () {
Backbone.Radio = {

View File

@ -1,7 +1,8 @@
define([
'newsletter_editor/App',
'newsletter_editor/blocks/spacer'
], function(EditorApplication, SpacerBlock) {
], function(App, SpacerBlock) {
var EditorApplication = App;
describe('Spacer', function () {
describe('model', function () {

View File

@ -1,7 +1,8 @@
define([
'newsletter_editor/App',
'newsletter_editor/components/content'
], function(EditorApplication, ContentComponent) {
], function(App, ContentComponent) {
var EditorApplication = App;
describe('Content', function() {
describe('newsletter model', function() {

View File

@ -3,7 +3,8 @@ define([
'newsletter_editor/components/save',
'amd-inject-loader!newsletter_editor/components/save',
'jquery'
], function(EditorApplication, SaveComponent, SaveInjector, jQuery) {
], function(App, SaveComponent, SaveInjector, jQuery) {
var EditorApplication = App;
describe('Save', function() {
describe('save method', function() {

View File

@ -1,7 +1,8 @@
define([
'newsletter_editor/App',
'newsletter_editor/components/styles'
], function(EditorApplication, StylesComponent) {
], function(App, StylesComponent) {
var EditorApplication = App;
describe('Styles', function () {
it('loads and stores globally available styles', function() {