Fix eslint errors and warnings

[MAILPOET-1145]
This commit is contained in:
Pavel Dohnal
2018-02-19 13:23:09 +00:00
parent f98e58eb99
commit 6a8337c67d
4 changed files with 78 additions and 80 deletions

View File

@@ -38,7 +38,6 @@
"eqeqeq": 0, "eqeqeq": 0,
"max-len": 0, "max-len": 0,
"global-require": 0, "global-require": 0,
"no-throw-literal": 0,
"brace-style": 0, "brace-style": 0,
"space-infix-ops": 0 "space-infix-ops": 0
} }

View File

@@ -10,7 +10,7 @@ define([
'jquery', 'jquery',
'newsletter_editor/behaviors/BehaviorsLookup', 'newsletter_editor/behaviors/BehaviorsLookup',
'interact' 'interact'
], function (Marionette, _, jQuery, BehaviorsLookup, interact) { // eslint-disable-line func-names ], function DraggableBehavior(Marionette, _, jQuery, BehaviorsLookup, interact) {
var BL = BehaviorsLookup; var BL = BehaviorsLookup;
BL.DraggableBehavior = Marionette.Behavior.extend({ BL.DraggableBehavior = Marionette.Behavior.extend({
@@ -24,14 +24,14 @@ define([
* *
* @return Backbone.Model A model that will be passed to the receiver * @return Backbone.Model A model that will be passed to the receiver
*/ */
getDropModel: function () { // eslint-disable-line func-names getDropModel: function getDropModel() {
throw "Missing 'drop' function for DraggableBehavior"; throw new Error("Missing 'drop' function for DraggableBehavior");
}, },
onDrop: function () {}, // eslint-disable-line func-names onDrop: function onDrop() {},
testAttachToInstance: function () { return true; } // eslint-disable-line func-names testAttachToInstance: function testAttachToInstance() { return true; }
}, },
onRender: function () { // eslint-disable-line func-names onRender: function onRender() {
var that = this; var that = this;
var interactable; var interactable;
@@ -47,7 +47,7 @@ define([
// Scroll when dragging near edges of a window // Scroll when dragging near edges of a window
autoScroll: true, autoScroll: true,
onstart: function (startEvent) { // eslint-disable-line func-names onstart: function onstart(startEvent) {
var event = startEvent; var event = startEvent;
var centerXOffset; var centerXOffset;
var centerYOffset; var centerYOffset;
@@ -86,7 +86,7 @@ define([
} }
}, },
// call this function on every dragmove event // call this function on every dragmove event
onmove: function (event) { // eslint-disable-line func-names onmove: function onmove(event) {
var target = event.target; var target = event.target;
// keep the dragged position in the data-x/data-y attributes // keep the dragged position in the data-x/data-y attributes
var x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx; var x = (parseFloat(target.getAttribute('data-x')) || 0) + event.dx;
@@ -100,7 +100,7 @@ define([
target.setAttribute('data-x', x); target.setAttribute('data-x', x);
target.setAttribute('data-y', y); target.setAttribute('data-y', y);
}, },
onend: function (event) { // eslint-disable-line func-names onend: function onend(event) {
var target = event.target; var target = event.target;
target.style.transform = ''; target.style.transform = '';
target.style.webkitTransform = target.style.transform; target.style.webkitTransform = target.style.transform;
@@ -119,7 +119,7 @@ define([
}) })
.preventDefault('auto') .preventDefault('auto')
.styleCursor(false) .styleCursor(false)
.actionChecker(function (pointer, event, action) { // eslint-disable-line func-names .actionChecker(function actionChecker(pointer, event, action) {
// Disable dragging with right click // Disable dragging with right click
if (event.button !== 0) { if (event.button !== 0) {
return null; return null;
@@ -133,7 +133,7 @@ define([
} else { } else {
interactable.getDropModel = this.view.getDropFunc(); interactable.getDropModel = this.view.getDropFunc();
} }
interactable.onDrop = function (opts) { // eslint-disable-line func-names interactable.onDrop = function onDrop(opts) {
var options = opts; var options = opts;
if (_.isObject(options)) { if (_.isObject(options)) {
// Inject Draggable behavior if possible // Inject Draggable behavior if possible

View File

@@ -1,4 +1,3 @@
/* eslint-disable func-names */
/** /**
* Defines base classes for actual content blocks to extend. * Defines base classes for actual content blocks to extend.
* Extending content block modules need to at least extend * Extending content block modules need to at least extend
@@ -13,7 +12,7 @@ define([
'jquery', 'jquery',
'mailpoet', 'mailpoet',
'modal' 'modal'
], function (App, Marionette, SuperModel, _, jQuery, MailPoet) { ], function base(App, Marionette, SuperModel, _, jQuery, MailPoet) {
'use strict'; 'use strict';
var Module = {}; var Module = {};
@@ -21,12 +20,12 @@ define([
Module.BlockModel = SuperModel.extend({ Module.BlockModel = SuperModel.extend({
stale: [], // Attributes to be removed upon saving stale: [], // Attributes to be removed upon saving
initialize: function () { initialize: function initialize() {
this.on('change', function () { this.on('change', function onChange() {
App.getChannel().trigger('autoSave'); App.getChannel().trigger('autoSave');
}); });
}, },
_getDefaults: function (blockDefaults, configDefaults) { _getDefaults: function getDefaults(blockDefaults, configDefaults) {
var defaults = (_.isObject(configDefaults) && _.isFunction(configDefaults.toJSON)) ? configDefaults.toJSON() : configDefaults; var defaults = (_.isObject(configDefaults) && _.isFunction(configDefaults.toJSON)) ? configDefaults.toJSON() : configDefaults;
// Patch the resulting JSON object and fix it's constructors to be Object. // Patch the resulting JSON object and fix it's constructors to be Object.
@@ -35,11 +34,11 @@ define([
// TODO: Investigate for a better solution // TODO: Investigate for a better solution
return JSON.parse(JSON.stringify(jQuery.extend(blockDefaults, defaults || {}))); return JSON.parse(JSON.stringify(jQuery.extend(blockDefaults, defaults || {})));
}, },
toJSON: function () { toJSON: function toJSON() {
// Remove stale attributes from resulting JSON object // Remove stale attributes from resulting JSON object
return _.omit(SuperModel.prototype.toJSON.call(this), this.stale); return _.omit(SuperModel.prototype.toJSON.call(this), this.stale);
}, },
getChildren: function () { getChildren: function getChildren() {
return []; return [];
} }
}); });
@@ -61,12 +60,12 @@ define([
DraggableBehavior: { DraggableBehavior: {
cloneOriginal: true, cloneOriginal: true,
hideOriginal: true, hideOriginal: true,
onDrop: function (options) { onDrop: function onDrop(options) {
// After a clone of model has been dropped, cleanup // After a clone of model has been dropped, cleanup
// and destroy self // and destroy self
options.dragBehavior.view.model.destroy(); options.dragBehavior.view.model.destroy();
}, },
onDragSubstituteBy: function (behavior) { onDragSubstituteBy: function onDragSubstituteBy(behavior) {
var WidgetView; var WidgetView;
var node; var node;
// When block is being dragged, display the widget icon instead. // When block is being dragged, display the widget icon instead.
@@ -84,76 +83,76 @@ define([
}, },
HighlightEditingBehavior: {} HighlightEditingBehavior: {}
}, },
templateContext: function () { templateContext: function templateContext() {
return { return {
model: this.model.toJSON(), model: this.model.toJSON(),
viewCid: this.cid viewCid: this.cid
}; };
}, },
constructor: function () { constructor: function constructor() {
AugmentedView.apply(this, arguments); AugmentedView.apply(this, arguments);
this.$el.addClass('mailpoet_editor_view_' + this.cid); this.$el.addClass('mailpoet_editor_view_' + this.cid);
}, },
initialize: function () { initialize: function initialize() {
this.on('showSettings', this.showSettings, this); this.on('showSettings', this.showSettings, this);
this.on('dom:refresh', this.showBlock, this); this.on('dom:refresh', this.showBlock, this);
this._isFirstRender = true; this._isFirstRender = true;
}, },
showTools: function () { showTools: function showTools() {
if (!this.showingToolsDisabled) { if (!this.showingToolsDisabled) {
this.$('> .mailpoet_tools').addClass('mailpoet_display_tools'); this.$('> .mailpoet_tools').addClass('mailpoet_display_tools');
this.toolsView.triggerMethod('showTools'); this.toolsView.triggerMethod('showTools');
} }
}, },
hideTools: function () { hideTools: function hideTools() {
this.$('> .mailpoet_tools').removeClass('mailpoet_display_tools'); this.$('> .mailpoet_tools').removeClass('mailpoet_display_tools');
this.toolsView.triggerMethod('hideTools'); this.toolsView.triggerMethod('hideTools');
}, },
enableShowingTools: function () { enableShowingTools: function enableShowingTools() {
this.showingToolsDisabled = false; this.showingToolsDisabled = false;
}, },
disableShowingTools: function () { disableShowingTools: function disableShowingTools() {
this.showingToolsDisabled = true; this.showingToolsDisabled = true;
this.hideTools(); this.hideTools();
}, },
showSettings: function (options) { showSettings: function showSettings(options) {
this.toolsView.triggerMethod('showSettings', options); this.toolsView.triggerMethod('showSettings', options);
}, },
/** /**
* Defines drop behavior of BlockView instance * Defines drop behavior of BlockView instance
*/ */
getDropFunc: function () { getDropFunc: function getDropFunc() {
return function () { return function getDropFuncClone() {
return this.model.clone(); return this.model.clone();
}.bind(this); }.bind(this);
}, },
disableDragging: function () { disableDragging: function disableDragging() {
this.$el.addClass('mailpoet_ignore_drag'); this.$el.addClass('mailpoet_ignore_drag');
}, },
enableDragging: function () { enableDragging: function enableDragging() {
this.$el.removeClass('mailpoet_ignore_drag'); this.$el.removeClass('mailpoet_ignore_drag');
}, },
showBlock: function () { showBlock: function showBlock() {
if (this._isFirstRender) { if (this._isFirstRender) {
this.transitionIn(); this.transitionIn();
this._isFirstRender = false; this._isFirstRender = false;
} }
}, },
deleteBlock: function () { deleteBlock: function deleteBlock() {
this.transitionOut().then(function () { this.transitionOut().then(function deleteBlockDestroy() {
this.model.destroy(); this.model.destroy();
}.bind(this)); }.bind(this));
}, },
duplicateBlock: function () { duplicateBlock: function duplicateBlock() {
this.model.collection.add(this.model.toJSON(), { at: this.model.collection.findIndex(this.model) }); this.model.collection.add(this.model.toJSON(), { at: this.model.collection.findIndex(this.model) });
}, },
transitionIn: function () { transitionIn: function transitionIn() {
return this._transition('slideDown', 'fadeIn', 'easeOut'); return this._transition('slideDown', 'fadeIn', 'easeOut');
}, },
transitionOut: function () { transitionOut: function transitionOut() {
return this._transition('slideUp', 'fadeOut', 'easeIn'); return this._transition('slideUp', 'fadeOut', 'easeIn');
}, },
_transition: function (slideDirection, fadeDirection, easing) { _transition: function transition(slideDirection, fadeDirection, easing) {
var promise = jQuery.Deferred(); var promise = jQuery.Deferred();
this.$el.velocity( this.$el.velocity(
@@ -161,7 +160,7 @@ define([
{ {
duration: 250, duration: 250,
easing: easing, easing: easing,
complete: function () { complete: function complete() {
promise.resolve(); promise.resolve();
} }
} }
@@ -179,7 +178,7 @@ define([
}); });
Module.BlockToolsView = AugmentedView.extend({ Module.BlockToolsView = AugmentedView.extend({
getTemplate: function () { return window.templates.genericBlockTools; }, getTemplate: function getTemplate() { return window.templates.genericBlockTools; },
events: { events: {
'click .mailpoet_edit_block': 'changeSettings', 'click .mailpoet_edit_block': 'changeSettings',
'click .mailpoet_delete_block_activate': 'showDeletionConfirmation', 'click .mailpoet_delete_block_activate': 'showDeletionConfirmation',
@@ -194,8 +193,8 @@ define([
duplicate: true, duplicate: true,
move: true move: true
}, },
getSettingsView: function () { return Module.BlockSettingsView; }, getSettingsView: function getSettingsView() { return Module.BlockSettingsView; },
initialize: function (opts) { initialize: function initialize(opts) {
var options = opts || {}; var options = opts || {};
if (!_.isUndefined(options.tools)) { if (!_.isUndefined(options.tools)) {
// Make a new block specific tool config object // Make a new block specific tool config object
@@ -206,18 +205,18 @@ define([
this.on('hideTools', this.hideDeletionConfirmation, this); this.on('hideTools', this.hideDeletionConfirmation, this);
this.on('showSettings', this.changeSettings); this.on('showSettings', this.changeSettings);
}, },
templateContext: function () { templateContext: function templateContext() {
return { return {
model: this.model.toJSON(), model: this.model.toJSON(),
viewCid: this.cid, viewCid: this.cid,
tools: this.tools tools: this.tools
}; };
}, },
changeSettings: function (options) { changeSettings: function changeSettings(options) {
var ViewType = this.getSettingsView(); var ViewType = this.getSettingsView();
(new ViewType(_.extend({ model: this.model }, options || {}))).render(); (new ViewType(_.extend({ model: this.model }, options || {}))).render();
}, },
showDeletionConfirmation: function () { showDeletionConfirmation: function showDeletionConfirmation() {
this.$('.mailpoet_delete_block') this.$('.mailpoet_delete_block')
.closest('.mailpoet_block') .closest('.mailpoet_block')
.find('> .mailpoet_block_highlight') .find('> .mailpoet_block_highlight')
@@ -225,7 +224,7 @@ define([
this.$('.mailpoet_delete_block').addClass('mailpoet_delete_block_activated'); this.$('.mailpoet_delete_block').addClass('mailpoet_delete_block_activated');
}, },
hideDeletionConfirmation: function () { hideDeletionConfirmation: function hideDeletionConfirmation() {
this.$('.mailpoet_delete_block') this.$('.mailpoet_delete_block')
.closest('.mailpoet_block') .closest('.mailpoet_block')
.find('> .mailpoet_block_highlight') .find('> .mailpoet_block_highlight')
@@ -233,12 +232,12 @@ define([
this.$('.mailpoet_delete_block').removeClass('mailpoet_delete_block_activated'); this.$('.mailpoet_delete_block').removeClass('mailpoet_delete_block_activated');
}, },
deleteBlock: function (event) { deleteBlock: function deleteBlock(event) {
event.preventDefault(); event.preventDefault();
this.model.trigger('delete'); this.model.trigger('delete');
return false; return false;
}, },
duplicateBlock: function (event) { duplicateBlock: function duplicateBlock(event) {
event.preventDefault(); event.preventDefault();
this.model.trigger('duplicate'); this.model.trigger('duplicate');
return false; return false;
@@ -250,7 +249,7 @@ define([
behaviors: { behaviors: {
ColorPickerBehavior: {} ColorPickerBehavior: {}
}, },
initialize: function (params) { initialize: function initialize(params) {
var panelParams; var panelParams;
this.model.trigger('startEditing'); this.model.trigger('startEditing');
panelParams = { panelParams = {
@@ -258,7 +257,7 @@ define([
template: '', template: '',
position: 'right', position: 'right',
width: App.getConfig().get('sidepanelWidth'), width: App.getConfig().get('sidepanelWidth'),
onCancel: function () { onCancel: function onCancel() {
this.destroy(); this.destroy();
}.bind(this) }.bind(this)
}; };
@@ -269,37 +268,37 @@ define([
MailPoet.Modal.panel(panelParams); MailPoet.Modal.panel(panelParams);
} }
}, },
templateContext: function () { templateContext: function templateContext() {
return { return {
model: this.model.toJSON() model: this.model.toJSON()
}; };
}, },
close: function () { close: function close() {
this.destroy(); this.destroy();
}, },
changeField: function (field, event) { changeField: function changeField(field, event) {
this.model.set(field, jQuery(event.target).val()); this.model.set(field, jQuery(event.target).val());
}, },
changePixelField: function (field, event) { changePixelField: function changePixelField(field, event) {
this.changeFieldWithSuffix(field, event, 'px'); this.changeFieldWithSuffix(field, event, 'px');
}, },
changeFieldWithSuffix: function (field, event, suffix) { changeFieldWithSuffix: function changeFieldWithSuffix(field, event, suffix) {
this.model.set(field, jQuery(event.target).val() + suffix); this.model.set(field, jQuery(event.target).val() + suffix);
}, },
changeBoolField: function (field, event) { changeBoolField: function changeBoolField(field, event) {
this.model.set(field, (jQuery(event.target).val() === 'true')); this.model.set(field, (jQuery(event.target).val() === 'true'));
}, },
changeBoolCheckboxField: function (field, event) { changeBoolCheckboxField: function changeBoolCheckboxField(field, event) {
this.model.set(field, (!!jQuery(event.target).prop('checked'))); this.model.set(field, (!!jQuery(event.target).prop('checked')));
}, },
changeColorField: function (field, event) { changeColorField: function changeColorField(field, event) {
var value = jQuery(event.target).val(); var value = jQuery(event.target).val();
if (value === '') { if (value === '') {
value = 'transparent'; value = 'transparent';
} }
this.model.set(field, value); this.model.set(field, value);
}, },
onBeforeDestroy: function () { onBeforeDestroy: function onBeforeDestroy() {
MailPoet.Modal.close(); MailPoet.Modal.close();
this.model.trigger('stopEditing'); this.model.trigger('stopEditing');
} }
@@ -309,8 +308,8 @@ define([
className: 'mailpoet_widget mailpoet_droppable_block mailpoet_droppable_widget', className: 'mailpoet_widget mailpoet_droppable_block mailpoet_droppable_widget',
behaviors: { behaviors: {
DraggableBehavior: { DraggableBehavior: {
drop: function () { drop: function drop() {
throw 'Unsupported operation'; throw new Error('Unsupported operation');
} }
} }
} }

View File

@@ -5,7 +5,7 @@ define([
'backbone.supermodel', 'backbone.supermodel',
'underscore', 'underscore',
'mailpoet' 'mailpoet'
], function (App, SuperModel, _, MailPoet) { // eslint-disable-line func-names ], function content(App, SuperModel, _, MailPoet) {
var Module = {}; var Module = {};
// Holds newsletter entry fields, such as subject or creation datetime. // Holds newsletter entry fields, such as subject or creation datetime.
@@ -13,12 +13,12 @@ define([
// handled by other components. // handled by other components.
Module.NewsletterModel = SuperModel.extend({ Module.NewsletterModel = SuperModel.extend({
whitelisted: ['id', 'subject', 'preheader', 'type'], whitelisted: ['id', 'subject', 'preheader', 'type'],
initialize: function () { // eslint-disable-line func-names initialize: function initialize() {
this.on('change', function () { // eslint-disable-line func-names this.on('change', function onChange() {
App.getChannel().trigger('autoSave'); App.getChannel().trigger('autoSave');
}); });
}, },
toJSON: function () { // eslint-disable-line func-names toJSON: function toJSON() {
// Use only whitelisted properties to ensure properties editor // Use only whitelisted properties to ensure properties editor
// doesn't control don't change. // doesn't control don't change.
return _.pick(SuperModel.prototype.toJSON.call(this), this.whitelisted); return _.pick(SuperModel.prototype.toJSON.call(this), this.whitelisted);
@@ -27,45 +27,45 @@ define([
// Content block view and model handlers for different content types // Content block view and model handlers for different content types
Module._blockTypes = {}; Module._blockTypes = {};
Module.registerBlockType = function (type, data) { // eslint-disable-line func-names Module.registerBlockType = function registerBlockType(type, data) {
Module._blockTypes[type] = data; Module._blockTypes[type] = data;
}; };
Module.getBlockTypeModel = function (type) { // eslint-disable-line func-names Module.getBlockTypeModel = function getBlockTypeModel(type) {
if (type in Module._blockTypes) { if (type in Module._blockTypes) {
return Module._blockTypes[type].blockModel; return Module._blockTypes[type].blockModel;
} }
throw 'Block type not supported: ' + type; throw new Error('Block type not supported: ' + type);
}; };
Module.getBlockTypeView = function (type) { // eslint-disable-line func-names Module.getBlockTypeView = function getBlockTypeView(type) {
if (type in Module._blockTypes) { if (type in Module._blockTypes) {
return Module._blockTypes[type].blockView; return Module._blockTypes[type].blockView;
} }
throw 'Block type not supported: ' + type; throw new Error('Block type not supported: ' + type);
}; };
Module.getBody = function () { // eslint-disable-line func-names Module.getBody = function getBody() {
return { return {
content: App._contentContainer.toJSON(), content: App._contentContainer.toJSON(),
globalStyles: App.getGlobalStyles().toJSON() globalStyles: App.getGlobalStyles().toJSON()
}; };
}; };
Module.toJSON = function () { // eslint-disable-line func-names Module.toJSON = function toJSON() {
return _.extend({ return _.extend({
body: Module.getBody() body: Module.getBody()
}, App.getNewsletter().toJSON()); }, App.getNewsletter().toJSON());
}; };
Module.getNewsletter = function () { // eslint-disable-line func-names Module.getNewsletter = function getNewsletter() {
return Module.newsletter; return Module.newsletter;
}; };
Module.findModels = function (predicate) { // eslint-disable-line func-names Module.findModels = function findModels(predicate) {
var blocks = App._contentContainer.getChildren(); var blocks = App._contentContainer.getChildren();
return _.filter(blocks, predicate); return _.filter(blocks, predicate);
}; };
App.on('before:start', function (Application, options) { // eslint-disable-line func-names App.on('before:start', function appBeforeStart(Application, options) {
var BeforeStartApp = Application; var BeforeStartApp = Application;
// Expose block methods globally // Expose block methods globally
BeforeStartApp.registerBlockType = Module.registerBlockType; BeforeStartApp.registerBlockType = Module.registerBlockType;
@@ -79,10 +79,10 @@ define([
Module.newsletter = new Module.NewsletterModel(_.omit(_.clone(options.newsletter), ['body'])); Module.newsletter = new Module.NewsletterModel(_.omit(_.clone(options.newsletter), ['body']));
}); });
App.on('start', function (Application, options) { // eslint-disable-line func-names App.on('start', function appOnStart(Application, options) {
var StartApp = Application; var StartApp = Application;
var body = options.newsletter.body; var body = options.newsletter.body;
var content = (_.has(body, 'content')) ? body.content : {}; var bodyContent = (_.has(body, 'content')) ? body.content : {};
if (!_.has(options.newsletter, 'body') || !_.isObject(options.newsletter.body)) { if (!_.has(options.newsletter, 'body') || !_.isObject(options.newsletter.body)) {
MailPoet.Notice.error( MailPoet.Notice.error(
@@ -91,7 +91,7 @@ define([
); );
} }
StartApp._contentContainer = new (StartApp.getBlockTypeModel('container'))(content, { parse: true }); StartApp._contentContainer = new (StartApp.getBlockTypeModel('container'))(bodyContent, { parse: true });
StartApp._contentContainerView = new (StartApp.getBlockTypeView('container'))({ StartApp._contentContainerView = new (StartApp.getBlockTypeView('container'))({
model: StartApp._contentContainer, model: StartApp._contentContainer,
renderOptions: { depth: 0 } renderOptions: { depth: 0 }