diff --git a/.eslintrc.es5.json b/.eslintrc.es5.json index 5644b55172..3f72106ec9 100644 --- a/.eslintrc.es5.json +++ b/.eslintrc.es5.json @@ -54,7 +54,6 @@ "no-unused-vars": 0, "object-shorthand": 0, "new-parens": 0, - "keyword-spacing": 0, "eol-last": 0, "dot-notation": 0, "prefer-template": 0, diff --git a/assets/js/src/ajax.js b/assets/js/src/ajax.js index beae849d01..d2d057ac09 100644 --- a/assets/js/src/ajax.js +++ b/assets/js/src/ajax.js @@ -34,12 +34,12 @@ define('ajax', ['mailpoet', 'jquery', 'underscore'], function (mp, jQuery, _) { this.options = jQuery.extend({}, this.defaults, options); // set default url - if(this.options.url === null) { + if (this.options.url === null) { this.options.url = window.ajaxurl; } // set default token - if(this.options.token === null) { + if (this.options.token === null) { this.options.token = window.mailpoet_token; } }, diff --git a/assets/js/src/date.js b/assets/js/src/date.js index 2f8d26ac49..11956c7306 100644 --- a/assets/js/src/date.js +++ b/assets/js/src/date.js @@ -145,7 +145,7 @@ define('date', var convertedFormat = []; var escapeToken = false; - for(var index = 0, token = ''; format.charAt(index); index += 1) { + for (var index = 0, token = ''; format.charAt(index); index += 1) { token = format.charAt(index); if (escapeToken === true) { convertedFormat.push('[' + token + ']'); diff --git a/assets/js/src/form_editor/form_editor.js b/assets/js/src/form_editor/form_editor.js index c7d66f9186..d3cd159afa 100644 --- a/assets/js/src/form_editor/form_editor.js +++ b/assets/js/src/form_editor/form_editor.js @@ -31,7 +31,7 @@ Object.extend(document, (function () { function destroyWrapper(selector, eventName, handler) { var c = getCacheForSelector(selector); - if(!c[eventName]) return false; + if (!c[eventName]) return false; var wrapper = findWrapper(selector, eventName, handler); c[eventName] = c[eventName].without(wrapper); return wrapper; @@ -39,10 +39,10 @@ Object.extend(document, (function () { function createWrapper(selector, eventName, handler, context) { var wrapper, c = getWrappersForSelector(selector, eventName); - if(c.pluck('handler').include(handler)) return false; + if (c.pluck('handler').include(handler)) return false; wrapper = function (event) { var element = event.findElement(selector); - if(element) handler.call(context || element, event, element); + if (element) handler.call(context || element, event, element); }; wrapper.handler = handler; c.push(wrapper); @@ -51,12 +51,12 @@ Object.extend(document, (function () { return { delegate: function (selector, eventName, handler, context) { var wrapper = createWrapper.apply(null, arguments); - if(wrapper) document.observe(eventName, wrapper); + if (wrapper) document.observe(eventName, wrapper); return document; }, stopDelegating: function (selector, eventName, handler) { var length = arguments.length; - switch(length) { + switch (length) { case 2: getWrappersForSelector(selector, eventName).each(function (wrapper) { document.stopDelegating(selector, eventName, wrapper.handler); @@ -74,7 +74,7 @@ Object.extend(document, (function () { break; default: var wrapper = destroyWrapper.apply(null, arguments); - if(wrapper) document.stopObserving(eventName, wrapper); + if (wrapper) document.stopObserving(eventName, wrapper); } return document; } @@ -84,7 +84,7 @@ Object.extend(document, (function () { var Observable = (function () { function getEventName(nameA, namespace) { var name = nameA.substring(2); - if(namespace) name = namespace + ':' + name; + if (namespace) name = namespace + ':' + name; return name.underscore().split('_').join(':'); } @@ -92,7 +92,7 @@ var Observable = (function () { var proto = klass.prototype, namespace = proto.namespace; return Object.keys(proto).grep(/^on/).inject(window.$H(), function (handlers, name) { - if(name === 'onDomLoaded') return handlers; + if (name === 'onDomLoaded') return handlers; handlers.set(getEventName(name, namespace), getWrapper(proto[name], klass)); return handlers; }); @@ -111,11 +111,11 @@ var Observable = (function () { } return { observe: function (selector) { - if(!this.handlers) this.handlers = {}; - if(this.handlers[selector]) return; + if (!this.handlers) this.handlers = {}; + if (this.handlers[selector]) return; var klass = this; - if(this.prototype.onDomLoaded) { - if(document.loaded) { + if (this.prototype.onDomLoaded) { + if (document.loaded) { onDomLoad(selector, klass); } else { document.observe('dom:loaded', onDomLoad.curry(selector, klass)); @@ -126,7 +126,7 @@ var Observable = (function () { }); }, stopObserving: function (selector) { - if(!this.handlers || !this.handlers[selector]) return; + if (!this.handlers || !this.handlers[selector]) return; this.handlers[selector].each(function (handler) { document.stopDelegating(selector, handler.key, handler.value); }); @@ -138,54 +138,54 @@ var Observable = (function () { // override droppables Object.extend(window.Droppables, { deactivate: window.Droppables.deactivate.wrap(function (proceed, drop, draggable) { - if(drop.onLeave) drop.onLeave(draggable, drop.element); + if (drop.onLeave) drop.onLeave(draggable, drop.element); return proceed(drop); }), activate: window.Droppables.activate.wrap(function (proceed, drop, draggable) { - if(drop.onEnter) drop.onEnter(draggable, drop.element); + if (drop.onEnter) drop.onEnter(draggable, drop.element); return proceed(drop); }), show: function (point, element) { - if(!this.drops.length) return; + if (!this.drops.length) return; var drop, affected = []; this.drops.each(function (drop) { - if(window.Droppables.isAffected(point, element, drop)) affected.push(drop); + if (window.Droppables.isAffected(point, element, drop)) affected.push(drop); }); - if(affected.length > 0) drop = window.Droppables.findDeepestChild(affected); - if(this.last_active && this.last_active !== drop) this.deactivate(this.last_active, element); - if(drop) { + if (affected.length > 0) drop = window.Droppables.findDeepestChild(affected); + if (this.last_active && this.last_active !== drop) this.deactivate(this.last_active, element); + if (drop) { window.Position.within(drop.element, point[0], point[1]); - if(drop.onHover) drop.onHover(element, drop.element, window.Position.overlap(drop.overlap, drop.element)); - if(drop !== this.last_active) window.Droppables.activate(drop, element); + if (drop.onHover) drop.onHover(element, drop.element, window.Position.overlap(drop.overlap, drop.element)); + if (drop !== this.last_active) window.Droppables.activate(drop, element); } }, displayArea: function (draggable) { - if(!this.drops.length) return; + if (!this.drops.length) return; // hide controls when displaying drop areas. WysijaForm.hideBlockControls(); this.drops.each(function (drop, iterator) { - if(drop.element.hasClassName('block_placeholder')) { + if (drop.element.hasClassName('block_placeholder')) { drop.element.addClassName('active'); } }); }, hideArea: function () { - if(!this.drops.length) return; + if (!this.drops.length) return; this.drops.each(function (drop, iterator) { - if(drop.element.hasClassName('block_placeholder')) { + if (drop.element.hasClassName('block_placeholder')) { drop.element.removeClassName('active'); - } else if(drop.element.hasClassName('image_placeholder')) { + } else if (drop.element.hasClassName('image_placeholder')) { drop.element.removeClassName('active'); drop.element.up().removeClassName('active'); - } else if(drop.element.hasClassName('text_placeholder')) { + } else if (drop.element.hasClassName('text_placeholder')) { drop.element.removeClassName('active'); } }); }, reset: function (draggable) { - if(this.last_active) this.deactivate(this.last_active, draggable); + if (this.last_active) this.deactivate(this.last_active, draggable); } }); @@ -203,13 +203,13 @@ var WysijaHistory = { var clone = element.clone(true); // check if the field is unique - if(parseInt(clone.readAttribute('wysija_unique'), 10) === 1) { + if (parseInt(clone.readAttribute('wysija_unique'), 10) === 1) { // check if the field is already in the queue window.$(WysijaHistory.container).select('[wysija_name="' + clone.readAttribute('wysija_name') + '"]').invoke('remove'); } // check history size - if(window.$(WysijaHistory.container).select('> div').length >= WysijaHistory.size) { + if (window.$(WysijaHistory.container).select('> div').length >= WysijaHistory.size) { // remove oldest element (last in the list) window.$(WysijaHistory.container).select('> div').last().remove(); } @@ -223,7 +223,7 @@ var WysijaHistory = { // pop last block off the history var block = window.$(WysijaHistory.container).select('div').first(); - if(block !== undefined) { + if (block !== undefined) { // insert block back into the editor window.$(WysijaForm.options.body).insert({ top: block @@ -277,7 +277,7 @@ var WysijaForm = { // ": fix for FileMerge because the previous line fucks up its syntax coloring }, loading: function (is_loading) { - if(is_loading) { + if (is_loading) { window.$(WysijaForm.options.editor).addClassName('loading'); window.$(WysijaForm.options.toolbar).addClassName('loading'); } else { @@ -292,10 +292,10 @@ var WysijaForm = { }); }, load: function (data) { - if(data === undefined) return; + if (data === undefined) return; // load body - if(data.body !== undefined) { + if (data.body !== undefined) { window.$A(data.body).each(function (block) { // create block WysijaForm.Block.create(block, window.$('block_placeholder')); @@ -305,16 +305,16 @@ var WysijaForm = { var settings_elements = window.$('mailpoet_form_settings').getElements(); settings_elements.each(function (setting) { // skip lists - if(setting.name === 'segments') { + if (setting.name === 'segments') { return true; - } else if(setting.name === 'on_success') { + } else if (setting.name === 'on_success') { // if the input value is equal to the one stored in the settings - if(setting.value === data.settings[setting.name]) { + if (setting.value === data.settings[setting.name]) { // check selected value window.$(setting).checked = true; } - } else if(data.settings[setting.name] !== undefined) { - if(typeof data.settings[setting.name] === 'string') { + } else if (data.settings[setting.name] !== undefined) { + if (typeof data.settings[setting.name] === 'string') { setting.setValue(WysijaForm.decodeHtmlValue(data.settings[setting.name])); } else { setting.setValue(data.settings[setting.name]); @@ -335,7 +335,7 @@ var WysijaForm = { WysijaForm.getBlocks().each(function (b) { var block_data = (typeof (b.block['save']) === 'function') ? b.block.save() : null; - if(block_data !== null) { + if (block_data !== null) { // set block position block_data['position'] = position; @@ -395,7 +395,7 @@ var WysijaForm = { }; // get params (may be empty) - if(element.readAttribute('wysija_params') !== null && element.readAttribute('wysija_params').length > 0) { + if (element.readAttribute('wysija_params') !== null && element.readAttribute('wysija_params').length > 0) { data.params = JSON.parse(element.readAttribute('wysija_params')); } return data; @@ -406,14 +406,14 @@ var WysijaForm = { // loop through each unique field already inserted in the editor and disable its toolbar equivalent window.$$('#' + WysijaForm.options.editor + ' [wysija_unique="1"]').map(function (element) { var field = window.$$('#' + WysijaForm.options.toolbar + ' [wysija_id="' + element.readAttribute('wysija_id') + '"]'); - if(field.length > 0) { + if (field.length > 0) { field.first().addClassName('disabled'); } }); var hasSegmentSelection = WysijaForm.hasSegmentSelection(); - if(hasSegmentSelection) { + if (hasSegmentSelection) { window.$('mailpoet_form_segments').writeAttribute('required', false).disable(); window.$('mailpoet_settings_segment_selection').hide(); } else { @@ -426,7 +426,7 @@ var WysijaForm = { }, isSegmentSelectionValid: function () { var segment_selection = window.$$('#' + WysijaForm.options.editor + ' [wysija_id="segments"]')[0]; - if(segment_selection !== undefined) { + if (segment_selection !== undefined) { var block = WysijaForm.get(segment_selection).block.getData(); return ( (block.params.values !== undefined) @@ -444,26 +444,26 @@ var WysijaForm = { WysijaForm.getBlocks().each(function (container) { container.setPosition(index++); // remove z-index value to avoid issues when resizing images - if(container['block'] !== undefined) { + if (container['block'] !== undefined) { container.block.element.setStyle({ zIndex: '' }); } }); - if(target !== undefined) { + if (target !== undefined) { // get placeholders (previous placeholder matches the placeholder linked to the next block) var block_placeholder = window.$(target.element.readAttribute('wysija_placeholder')), previous_placeholder = target.element.previous('.block_placeholder'); - if(block_placeholder !== null) { + if (block_placeholder !== null) { // put block placeholder before the current block target.element.insert({ before: block_placeholder }); // if the next block is a wysija_block, insert previous placeholder - if(target.element.next() !== undefined && target.element.next().hasClassName('mailpoet_form_block') && previous_placeholder !== undefined) { + if (target.element.next() !== undefined && target.element.next().hasClassName('mailpoet_form_block') && previous_placeholder !== undefined) { target.element.insert({ after: previous_placeholder }); @@ -490,7 +490,7 @@ var WysijaForm = { buttonMargin = 5, relativeTop = buttonMargin; - if(is_visible) { + if (is_visible) { // desired position is set to center of viewport var absoluteTop = parseInt(WysijaForm.scroll.top + ((viewportHeight / 2) - (element.getHeight() / 2)), 10), parentTop = parseInt(parentPos.top - blockPadding, 10), @@ -507,15 +507,15 @@ var WysijaForm = { }); }, initToolbarPosition: function () { - if(WysijaForm.toolbar.top === null) WysijaForm.toolbar.top = parseInt(window.$(WysijaForm.options.container).positionedOffset().top); - if(WysijaForm.toolbar.y === null) WysijaForm.toolbar.y = parseInt(WysijaForm.toolbar.top); + if (WysijaForm.toolbar.top === null) WysijaForm.toolbar.top = parseInt(window.$(WysijaForm.options.container).positionedOffset().top); + if (WysijaForm.toolbar.y === null) WysijaForm.toolbar.y = parseInt(WysijaForm.toolbar.top); - if(window.isRtl) { - if(WysijaForm.toolbar.left === null) WysijaForm.toolbar.left = 0; + if (window.isRtl) { + if (WysijaForm.toolbar.left === null) WysijaForm.toolbar.left = 0; } else { - if(WysijaForm.toolbar.left === null) WysijaForm.toolbar.left = parseInt(window.$(WysijaForm.options.container).positionedOffset().left); + if (WysijaForm.toolbar.left === null) WysijaForm.toolbar.left = parseInt(window.$(WysijaForm.options.container).positionedOffset().left); } - if(WysijaForm.toolbar.x === null) WysijaForm.toolbar.x = parseInt(WysijaForm.toolbar.left + window.$(WysijaForm.options.container).getDimensions().width + 15); + if (WysijaForm.toolbar.x === null) WysijaForm.toolbar.x = parseInt(WysijaForm.toolbar.left + window.$(WysijaForm.options.container).getDimensions().width + 15); }, setToolbarPosition: function () { @@ -526,7 +526,7 @@ var WysijaForm = { visibility: 'visible' }; - if(window.isRtl) { + if (window.isRtl) { position.right = WysijaForm.toolbar.x + 'px'; } else { position.left = WysijaForm.toolbar.x + 'px'; @@ -539,9 +539,9 @@ var WysijaForm = { WysijaForm.initToolbarPosition(); // cancel previous effect - if(WysijaForm.toolbar.effect !== null) WysijaForm.toolbar.effect.cancel(); + if (WysijaForm.toolbar.effect !== null) WysijaForm.toolbar.effect.cancel(); - if(WysijaForm.scroll.top >= (WysijaForm.toolbar.top - 20)) { + if (WysijaForm.scroll.top >= (WysijaForm.toolbar.top - 20)) { WysijaForm.toolbar.y = parseInt(20 + WysijaForm.scroll.top); // start effect WysijaForm.toolbar.effect = new window.Effect.Move(WysijaForm.options.toolbar, { @@ -574,7 +574,7 @@ var WysijaForm = { hideControls: function () { try { return WysijaForm.getBlocks().invoke('hideControls'); - } catch(e) { + } catch (e) { return; } }, @@ -585,7 +585,7 @@ var WysijaForm = { instances: {}, get: function (element, typ) { var type = typ; - if(type === undefined) type = 'block'; + if (type === undefined) type = 'block'; // identify element var id = element.identify(); var instance = WysijaForm.instances[id] || new WysijaForm[type.capitalize().camelize()](id); @@ -626,9 +626,9 @@ var WysijaForm = { return window.$(WysijaForm.options.container).select('.mailpoet_form_block'); }, startBlockPositions: function (event, target) { - if(target.element.hasClassName('mailpoet_form_block')) { + if (target.element.hasClassName('mailpoet_form_block')) { // store block placeholder id for the block that is being repositionned - if(target.element.previous('.block_placeholder') !== undefined) { + if (target.element.previous('.block_placeholder') !== undefined) { target.element.writeAttribute('wysija_placeholder', target.element.previous('.block_placeholder').identify()); } } @@ -639,10 +639,10 @@ var WysijaForm = { var regexp = new RegExp(/^http[s]?:\/\//), protocol = regexp.exec(str); - if(protocol === null) { + if (protocol === null) { // this is not a url so encode the whole thing return encodeURIComponent(str).replace(/[!'()*]/g, escape); - } else if(protocol.length === 1) { + } else if (protocol.length === 1) { // this is a url, so do not encode the protocol return encodeURI(str).replace(/[!'()*]/g, escape); } @@ -650,7 +650,7 @@ var WysijaForm = { updateBlock: function (field) { var hasUpdated = false; WysijaForm.getBlocks().each(function (b) { - if(b.block.getData().id === field.id) { + if (b.block.getData().id === field.id) { hasUpdated = true; b.block.redraw(field); } @@ -661,7 +661,7 @@ var WysijaForm = { removeBlock: function (field, callback) { var hasRemoved = false; WysijaForm.getBlocks().each(function (b) { - if(b.block.getData().id === field.id) { + if (b.block.getData().id === field.id) { hasRemoved = true; b.block.removeBlock(callback); } @@ -743,7 +743,7 @@ WysijaForm.Block = window.Class.create({ this.block.makeBlockDroppable(); // setup events - if(this.block['setup'] !== undefined) { + if (this.block['setup'] !== undefined) { this.block.setup(); } return this; @@ -752,29 +752,29 @@ WysijaForm.Block = window.Class.create({ this.element.writeAttribute('wysija_position', position); }, hideControls: function () { - if(this['getControls']) { + if (this['getControls']) { this.element.removeClassName('hover'); this.getControls().hide(); } }, showControls: function () { - if(this['getControls']) { + if (this['getControls']) { this.element.addClassName('hover'); try { this.getControls().show(); - } catch(e) { + } catch (e) { } } }, makeBlockDroppable: function () { - if(this.isBlockDroppableEnabled() === false) { + if (this.isBlockDroppableEnabled() === false) { var block_placeholder = this.getBlockDroppable(); window.Droppables.add(block_placeholder.identify(), WysijaForm.blockDropOptions); block_placeholder.addClassName('enabled'); } }, removeBlockDroppable: function () { - if(this.isBlockDroppableEnabled()) { + if (this.isBlockDroppableEnabled()) { var block_placeholder = this.getBlockDroppable(); window.Droppables.remove(block_placeholder.identify()); block_placeholder.removeClassName('enabled'); @@ -783,7 +783,7 @@ WysijaForm.Block = window.Class.create({ isBlockDroppableEnabled: function () { // if the block_placeholder does not exist, create it var block_placeholder = this.getBlockDroppable(); - if(block_placeholder === null) { + if (block_placeholder === null) { return this.createBlockDroppable().hasClassName('enabled'); } else { return block_placeholder.hasClassName('enabled'); @@ -797,7 +797,7 @@ WysijaForm.Block = window.Class.create({ return this.element.previous('.block_placeholder'); }, getBlockDroppable: function () { - if(this.element.previous() === undefined || this.element.previous().hasClassName('block_placeholder') === false) { + if (this.element.previous() === undefined || this.element.previous().hasClassName('block_placeholder') === false) { return null; } else { return this.element.previous(); @@ -810,11 +810,11 @@ WysijaForm.Block = window.Class.create({ // enable controls this.controls = this.getControls(); - if(this.controls) { + if (this.controls) { // setup events for block controls this.element.observe('mouseover', function () { // special cases where controls shouldn't be displayed - if(WysijaForm.locks.dragging === true || WysijaForm.locks.selectingColor === true || WysijaForm.locks.showingTools === true) return; + if (WysijaForm.locks.dragging === true || WysijaForm.locks.selectingColor === true || WysijaForm.locks.showingTools === true) return; // set block flag this.element.addClassName('hover'); @@ -823,20 +823,20 @@ WysijaForm.Block = window.Class.create({ this.showControls(); // show settings if present - if(this.element.down('.wysija_settings') !== undefined) { + if (this.element.down('.wysija_settings') !== undefined) { this.element.down('.wysija_settings').show(); } }.bind(this)); this.element.observe('mouseout', function () { // special cases where controls shouldn't hide - if(WysijaForm.locks.dragging === true || WysijaForm.locks.selectingColor === true) return; + if (WysijaForm.locks.dragging === true || WysijaForm.locks.selectingColor === true) return; // hide controls this.hideControls(); // hide settings if present - if(this.element.down('.wysija_settings') !== undefined) { + if (this.element.down('.wysija_settings') !== undefined) { this.element.down('.wysija_settings').hide(); } }.bind(this)); @@ -844,7 +844,7 @@ WysijaForm.Block = window.Class.create({ // setup click event for remove button this.removeButton = this.controls.down('.remove') || null; - if(this.removeButton !== null) { + if (this.removeButton !== null) { this.removeButton.observe('click', function () { this.removeBlock(); this.removeButton.stopObserving('click'); @@ -854,11 +854,11 @@ WysijaForm.Block = window.Class.create({ // setup click event for settings button this.settingsButton = this.element.down('.settings') || null; - if(this.settingsButton !== null) { + if (this.settingsButton !== null) { this.settingsButton.observe('click', function (event) { // TODO: refactor var block = window.$(event.target).up('.mailpoet_form_block') || null; - if(block !== null) { + if (block !== null) { var field = WysijaForm.getFieldData(block); this.editSettings(); } @@ -877,7 +877,7 @@ WysijaForm.Block = window.Class.create({ duration: 0.2, afterFinish: function (effect) { // remove placeholder - if(effect.element.previous('.block_placeholder') !== undefined) { + if (effect.element.previous('.block_placeholder') !== undefined) { effect.element.previous('.block_placeholder').remove(); } @@ -891,7 +891,7 @@ WysijaForm.Block = window.Class.create({ WysijaForm.toggleWidgets(); // optional callback execution after completely removing block - if(callback !== undefined && typeof (callback) === 'function') { + if (callback !== undefined && typeof (callback) === 'function') { callback(); } @@ -905,7 +905,7 @@ WysijaForm.Block = window.Class.create({ /* Invoked on item dropped */ WysijaForm.Block.create = function (createBlock, target) { var block = createBlock; - if(window.$('form_template_' + block.type) === null) { + if (window.$('form_template_' + block.type) === null) { return false; } @@ -914,10 +914,10 @@ WysijaForm.Block.create = function (createBlock, target) { template = window.Handlebars.compile(window.$('form_template_' + block.type).innerHTML), output = ''; - if(block.type === 'segment') { - if(block.params.values === undefined) { + if (block.type === 'segment') { + if (block.params.values === undefined) { var settings_segments = window.jQuery('#mailpoet_form_segments').val(); - if(settings_segments !== null && settings_segments.length > 0) { + if (settings_segments !== null && settings_segments.length > 0) { block.params.values = window.mailpoet_segments.filter(function (segment) { return (settings_segments.indexOf(segment.id) !== -1); }); @@ -931,13 +931,13 @@ WysijaForm.Block.create = function (createBlock, target) { // check if the new block is unique and if there's already an instance // of it in the history. If so, remove its former instance from the history - if(block.unique === 1) { + if (block.unique === 1) { WysijaHistory.remove(block.field); } // if the drop target was the bottom placeholder var element = null; - if(target.identify() === 'block_placeholder') { + if (target.identify() === 'block_placeholder') { // insert block at the bottom element = body.insert(output); // block = body.childElements().last(); @@ -987,7 +987,7 @@ WysijaForm.Widget = window.Class.create(WysijaForm.Block, { info('widget -> save'); var data = this.getData(); - if(data.element !== undefined) { + if (data.element !== undefined) { delete data.element; } @@ -998,7 +998,7 @@ WysijaForm.Widget = window.Class.create(WysijaForm.Block, { params = window.$H(current_data.params).merge(data.params).toObject(); // update type if it changed - if(data.type !== undefined && data.type !== current_data.type) { + if (data.type !== undefined && data.type !== current_data.type) { this.element.writeAttribute('wysija_type', data.type); } @@ -1008,7 +1008,7 @@ WysijaForm.Widget = window.Class.create(WysijaForm.Block, { getData: function () { var data = WysijaForm.getFieldData(this.element); // decode params - if(data.params.length > 0) { + if (data.params.length > 0) { data.params = JSON.parse(data.params); } return data; @@ -1054,23 +1054,23 @@ document.observe('dom:loaded', WysijaForm.init); /* LOGGING */ function info(value) { - if(WysijaForm.options.debug === false) return; + if (WysijaForm.options.debug === false) return; - if(!(window.console && console.log)) { + if (!(window.console && console.log)) { (function () { 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; window.console = {}; var console = {}; - while(length--) { + while (length--) { console[methods[length]] = noop; } }()); } try { console.log('[DEBUG] ' + value); - } catch(e) {} + } catch (e) {} } module.exports = WysijaForm; diff --git a/assets/js/src/handlebars_helpers.js b/assets/js/src/handlebars_helpers.js index 7373d8e7c1..4fe8de2401 100644 --- a/assets/js/src/handlebars_helpers.js +++ b/assets/js/src/handlebars_helpers.js @@ -3,7 +3,7 @@ define('handlebars_helpers', ['handlebars'], function (Handlebars) { Handlebars.registerHelper('concat', function () { var size = (arguments.length - 1), output = ''; - for(var i = 0; i < size; i++) { + for (var i = 0; i < size; i++) { output += arguments[i]; } return output; @@ -13,15 +13,15 @@ define('handlebars_helpers', ['handlebars'], function (Handlebars) { return Number(value).toLocaleString(); }); Handlebars.registerHelper('date_format', function (timestamp, block) { - if(window.moment) { - if(timestamp === undefined || isNaN(timestamp) || timestamp <= 0) { + if (window.moment) { + if (timestamp === undefined || isNaN(timestamp) || timestamp <= 0) { return; } // set date format var f = block.hash.format || 'MMM Do, YYYY'; // check if we passed a timestamp - if(parseInt(timestamp, 10) == timestamp) { + if (parseInt(timestamp, 10) == timestamp) { return window.moment.unix(timestamp).format(f); } else { return window.moment.utc(timestamp).format(f); @@ -97,7 +97,7 @@ define('handlebars_helpers', ['handlebars'], function (Handlebars) { 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'); @@ -110,7 +110,7 @@ define('handlebars_helpers', ['handlebars'], function (Handlebars) { }); Handlebars.registerHelper('trim', function (value, block) { - if(value === null || value === undefined) return ''; + if (value === null || value === undefined) return ''; return value.trim(); }); @@ -142,7 +142,7 @@ define('handlebars_helpers', ['handlebars'], function (Handlebars) { }); Handlebars.registerHelper('fontWithFallback', function (font) { - switch(font) { + switch (font) { case 'Arial': return new Handlebars.SafeString("Arial, 'Helvetica Neue', Helvetica, sans-serif"); case 'Comic Sans MS': return new Handlebars.SafeString("'Comic Sans MS', 'Marker Felt-Thin', Arial, sans-serif"); case 'Courier New': return new Handlebars.SafeString("'Courier New', Courier, 'Lucida Sans Typewriter', 'Lucida Typewriter', monospace"); diff --git a/assets/js/src/iframe.js b/assets/js/src/iframe.js index 0fb0c598c5..8cdcc35905 100644 --- a/assets/js/src/iframe.js +++ b/assets/js/src/iframe.js @@ -5,7 +5,7 @@ define('iframe', ['mailpoet'], function (mp) { MailPoet.Iframe = { marginY: 20, autoSize: function (iframe) { - if(!iframe) return; + if (!iframe) return; this.setSize( iframe, @@ -14,7 +14,7 @@ define('iframe', ['mailpoet'], function (mp) { }, setSize: function (sizeIframe, i) { var iframe = sizeIframe; - if(!iframe) return; + if (!iframe) return; iframe.style.height = ( parseInt(i, 10) + this.marginY diff --git a/assets/js/src/modal.js b/assets/js/src/modal.js index 84268db4df..081652c4e2 100644 --- a/assets/js/src/modal.js +++ b/assets/js/src/modal.js @@ -109,14 +109,14 @@ define('modal', ['mailpoet', 'jquery'], return this; }, compileTemplate: function (template) { - if(this.renderer === 'html') { + if (this.renderer === 'html') { return function () { return template; }; } else { return window.Handlebars.compile(template); } }, init: function (options) { - if(this.initialized === true) { + if (this.initialized === true) { this.close(); } // merge options @@ -131,9 +131,9 @@ define('modal', ['mailpoet', 'jquery'], // toggle overlay this.toggleOverlay(this.options.overlay); - if(this.options.type !== null) { + if (this.options.type !== null) { // insert modal depending on its type - if(this.options.type === 'popup') { + if (this.options.type === 'popup') { var modal = this.compileTemplate( this.templates[this.options.type] ); @@ -143,7 +143,7 @@ define('modal', ['mailpoet', 'jquery'], // set title jQuery('#mailpoet_popup_title h2') .html(this.options.title); - } else if(this.options.type === 'panel') { + } else if (this.options.type === 'panel') { // create panel jQuery('#mailpoet_modal_overlay') .after(this.templates[this.options.type]); @@ -156,12 +156,12 @@ define('modal', ['mailpoet', 'jquery'], } // set "success" callback if specified - if(options.onSuccess !== undefined) { + if (options.onSuccess !== undefined) { this.options.onSuccess = options.onSuccess; } // set "cancel" callback if specified - if(options.onCancel !== undefined) { + if (options.onCancel !== undefined) { this.options.onCancel = options.onCancel; } @@ -179,7 +179,7 @@ define('modal', ['mailpoet', 'jquery'], return this; }, initOverlay: function (toggle) { - if(jQuery('#mailpoet_modal_overlay').length === 0) { + if (jQuery('#mailpoet_modal_overlay').length === 0) { // insert overlay into the DOM jQuery('body').append(this.templates.overlay); // insert loading indicator into overlay @@ -188,7 +188,7 @@ define('modal', ['mailpoet', 'jquery'], return this; }, toggleOverlay: function (toggle) { - if(toggle === true) { + if (toggle === true) { jQuery('#mailpoet_modal_overlay') .removeClass('mailpoet_overlay_hidden'); } else { @@ -207,13 +207,13 @@ define('modal', ['mailpoet', 'jquery'], // we need to make sure that we are actually clicking on the overlay // because when clicking on the popup content, it will trigger // the click event on the overlay - if(e.target.id === 'mailpoet_modal_overlay') { this.cancel(); } + if (e.target.id === 'mailpoet_modal_overlay') { this.cancel(); } }.bind(this)); // close popup when user presses ESC key jQuery(document).on('keyup.mailpoet_modal', function (e) { - if(this.opened === false) { return false; } - if(e.keyCode === 27) { this.cancel(); } + if (this.opened === false) { return false; } + if (e.keyCode === 27) { this.cancel(); } }.bind(this)); // make sure the popup is repositioned when the window is resized @@ -227,7 +227,7 @@ define('modal', ['mailpoet', 'jquery'], jQuery(document).unbind('keyup.mailpoet_modal'); jQuery(window).unbind('resize.mailpoet_modal'); jQuery('#mailpoet_modal_close').off('click'); - if(this.options.overlay === true) { + if (this.options.overlay === true) { jQuery('#mailpoet_modal_overlay').off('click'); } @@ -247,7 +247,7 @@ define('modal', ['mailpoet', 'jquery'], return this.locked; }, loadTemplate: function () { - if(this.subpanels.length > 0) { + if (this.subpanels.length > 0) { // hide panel jQuery('.mailpoet_' + this.options.type + '_wrapper').hide(); @@ -260,7 +260,7 @@ define('modal', ['mailpoet', 'jquery'], .html(this.subpanels[(this.subpanels.length - 1)].element); // focus on sub panel - if(this.options.focus) { + if (this.options.focus) { this.focus(); } } else if (this.options.element) { @@ -279,7 +279,7 @@ define('modal', ['mailpoet', 'jquery'], return this; }, loadUrl: function () { - if(this.options.method === 'get') { + if (this.options.method === 'get') { // make ajax request jQuery.getJSON(this.options.url, function (data) { @@ -290,7 +290,7 @@ 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), function (data) { @@ -307,7 +307,7 @@ define('modal', ['mailpoet', 'jquery'], return this; }, setDimensions: function () { - switch(this.options.type) { + switch (this.options.type) { case 'popup': // set popup dimensions jQuery('#mailpoet_popup').css({ @@ -321,14 +321,14 @@ define('modal', ['mailpoet', 'jquery'], break; case 'panel': // set dimensions - if(this.options.position === 'right') { + 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') { + } else if (this.options.position === 'left') { jQuery('#mailpoet_panel').css({ width: this.options.width, left: 0, @@ -343,7 +343,7 @@ define('modal', ['mailpoet', 'jquery'], return this; }, setPosition: function () { - switch(this.options.type) { + switch (this.options.type) { case 'popup': var screenWidth = jQuery(window).width(), screenHeight = jQuery(window).height(), @@ -362,11 +362,11 @@ define('modal', ['mailpoet', 'jquery'], case 'panel': setTimeout(function () { // set position of popup depending on screen dimensions. - if(this.options.position === 'right') { + if (this.options.position === 'right') { jQuery('#mailpoet_panel').css({ marginRight: 0 }); - } else if(this.options.position === 'left') { + } else if (this.options.position === 'left') { jQuery('#mailpoet_panel').css({ marginLeft: 0 }); @@ -397,13 +397,13 @@ define('modal', ['mailpoet', 'jquery'], this.setPosition(); // add class on highlighted elements - if(this.options.highlight !== null) { - if(this.options.highlight.length > 0) { + if (this.options.highlight !== null) { + if (this.options.highlight.length > 0) { this.highlightOn(this.options.highlight); } } - if(this.options.focus) { + if (this.options.focus) { this.focus(); } @@ -411,14 +411,14 @@ define('modal', ['mailpoet', 'jquery'], this.opened = true; // trigger init event if specified - if(this.options.onInit !== null) { + if (this.options.onInit !== null) { this.options.onInit(this); } return this; }, focus: function () { - if(this.options.type == 'popup') { + if (this.options.type == 'popup') { jQuery('#mailpoet_' + this.options.type).focus(); } else { // panel and subpanel @@ -495,7 +495,7 @@ define('modal', ['mailpoet', 'jquery'], return this; }, subpanel: function (options) { - if(this.opened === false) { + if (this.opened === false) { // if no panel is already opened, let's create one instead this.panel(options); } else { @@ -510,7 +510,7 @@ define('modal', ['mailpoet', 'jquery'], // make sure the overlay is initialized and that it's visible this.initOverlay(true); - if(toggle === true) { + if (toggle === true) { this.showLoading(); } else { this.hideLoading(); @@ -538,9 +538,9 @@ define('modal', ['mailpoet', 'jquery'], }, open: function () { // load template if specified - if(this.options.template !== null) { + if (this.options.template !== null) { // check if a url was specified to get extra data - if(this.options.url !== null) { + if (this.options.url !== null) { this.loadUrl(); } else { // load template @@ -556,12 +556,12 @@ define('modal', ['mailpoet', 'jquery'], return this; }, success: function () { - if(this.subpanels.length > 0) { - if(this.subpanels[(this.subpanels.length - 1)].onSuccess !== undefined) { + 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) { + if (this.options.onSuccess !== null) { this.options.onSuccess(this.options.data); } } @@ -570,12 +570,12 @@ define('modal', ['mailpoet', 'jquery'], return this; }, cancel: function () { - if(this.subpanels.length > 0) { - if(this.subpanels[(this.subpanels.length - 1)].onCancel !== undefined) { + 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) { + if (this.options.onCancel !== null) { this.options.onCancel(this.options.data); } } @@ -587,7 +587,7 @@ define('modal', ['mailpoet', 'jquery'], this.hideOverlay(); // remove extra modal - if(jQuery('#mailpoet_' + this.options.type).length > 0) { + if (jQuery('#mailpoet_' + this.options.type).length > 0) { jQuery('#mailpoet_' + this.options.type).remove(); } @@ -596,9 +596,9 @@ define('modal', ['mailpoet', 'jquery'], return this; }, close: function () { - if(this.isLocked() === true) { return this; } + if (this.isLocked() === true) { return this; } - if(this.subpanels.length > 0) { + if (this.subpanels.length > 0) { // close subpanel jQuery('.mailpoet_' + this.options.type + '_wrapper').last().remove(); @@ -609,7 +609,7 @@ define('modal', ['mailpoet', 'jquery'], this.subpanels.pop(); // focus on previous panel - if(this.options.focus) { + if (this.options.focus) { this.focus(); } @@ -626,7 +626,7 @@ define('modal', ['mailpoet', 'jquery'], this.destroy(); // restore the previously focused element - if(this.prevFocus !== undefined) { + if (this.prevFocus !== undefined) { this.prevFocus.focus(); } diff --git a/assets/js/src/mp2migrator.js b/assets/js/src/mp2migrator.js index 86c4a4b358..2cc5fac7c6 100644 --- a/assets/js/src/mp2migrator.js +++ b/assets/js/src/mp2migrator.js @@ -32,11 +32,11 @@ define('mp2migrator', ['mailpoet', 'jquery'], function (mp, jQuery) { jQuery('#logger').html(''); 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')) { + if (row.substr(0, 7) === '[ERROR]' || row.substr(0, 9) === '[WARNING]' || row === MailPoet.I18n.t('import_stopped_by_user')) { row = '' + row + ''; // Mark the errors in red } // Test if the import is complete - else if(row === MailPoet.I18n.t('import_complete')) { + else if (row === MailPoet.I18n.t('import_complete')) { jQuery('#import-actions').hide(); jQuery('#upgrade-completed').show(); } @@ -45,7 +45,7 @@ define('mp2migrator', ['mailpoet', 'jquery'], function (mp, jQuery) { }); jQuery('#logger').append('' + MailPoet.MP2Migrator.fatal_error + '' + '
\n'); }).always(function () { - if(MailPoet.MP2Migrator.is_logging) { + if (MailPoet.MP2Migrator.is_logging) { MailPoet.MP2Migrator.displayLogs_timeout = setTimeout(MailPoet.MP2Migrator.displayLogs, 1000); } }); @@ -59,17 +59,17 @@ define('mp2migrator', ['mailpoet', 'jquery'], function (mp, jQuery) { }).always(function (result) { // Move the progress bar var progress = 0; - if((result.total !== undefined) && (Number(result.total) !== 0)) { + if ((result.total !== undefined) && (Number(result.total) !== 0)) { progress = Math.round(Number(result.current) / Number(result.total) * 100); } jQuery('#progressbar').progressbar('option', 'value', progress); jQuery('#progresslabel').html(progress + '%'); - if(Number(result.current) !== 0) { + if (Number(result.current) !== 0) { jQuery('#skip-import').hide(); jQuery('#progressbar').show(); jQuery('#logger-container').show(); } - if(MailPoet.MP2Migrator.is_logging) { + if (MailPoet.MP2Migrator.is_logging) { MailPoet.MP2Migrator.updateProgressbar_timeout = setTimeout(MailPoet.MP2Migrator.updateProgressbar, 1000); } }); @@ -100,11 +100,11 @@ define('mp2migrator', ['mailpoet', 'jquery'], function (mp, jQuery) { MailPoet.MP2Migrator.updateDisplay(); // Get the latest information after the import was stopped MailPoet.MP2Migrator.reactivateImportButton(); }).done(function (response) { - if(response) { + if (response) { MailPoet.MP2Migrator.fatal_error = response.data; } }).fail(function (response) { - if(response.errors.length > 0) { + if (response.errors.length > 0) { MailPoet.Notice.error( response.errors.map(function (error) { return error.message; @@ -135,7 +135,7 @@ define('mp2migrator', ['mailpoet', 'jquery'], function (mp, jQuery) { MailPoet.MP2Migrator.reactivateImportButton(); MailPoet.MP2Migrator.updateDisplay(); // Get the latest information after the import was stopped }).fail(function (response) { - if(response.errors.length > 0) { + if (response.errors.length > 0) { MailPoet.Notice.error( response.errors.map(function (error) { return error.message; @@ -158,7 +158,7 @@ define('mp2migrator', ['mailpoet', 'jquery'], function (mp, jQuery) { }).done(function () { MailPoet.MP2Migrator.gotoWelcomePage(); }).fail(function (response) { - if(response.errors.length > 0) { + if (response.errors.length > 0) { MailPoet.Notice.error( response.errors.map(function (error) { return error.message; diff --git a/assets/js/src/newsletter_editor/behaviors/ColorPickerBehavior.js b/assets/js/src/newsletter_editor/behaviors/ColorPickerBehavior.js index 2d74513272..a1408a213b 100644 --- a/assets/js/src/newsletter_editor/behaviors/ColorPickerBehavior.js +++ b/assets/js/src/newsletter_editor/behaviors/ColorPickerBehavior.js @@ -18,7 +18,7 @@ define([ this.view.$('.mailpoet_color').each(function () { var $input = that.view.$(this); var updateColorInput = function (color) { - if(color && color.getAlpha() > 0) { + if (color && color.getAlpha() > 0) { $input.val(color.toString(preferredFormat)); } else { $input.val(''); diff --git a/assets/js/src/newsletter_editor/behaviors/ShowSettingsBehavior.js b/assets/js/src/newsletter_editor/behaviors/ShowSettingsBehavior.js index 9b538de516..d8929c72f1 100644 --- a/assets/js/src/newsletter_editor/behaviors/ShowSettingsBehavior.js +++ b/assets/js/src/newsletter_editor/behaviors/ShowSettingsBehavior.js @@ -18,7 +18,7 @@ define([ 'click .mailpoet_content': 'showSettings' }, showSettings: function (event) { - if(!this.isIgnoredElement(event.target)) { + if (!this.isIgnoredElement(event.target)) { this.view.triggerMethod('showSettings'); } }, diff --git a/assets/js/src/newsletter_editor/blocks/image.js b/assets/js/src/newsletter_editor/blocks/image.js index f5d94264c8..8bc028e9fa 100644 --- a/assets/js/src/newsletter_editor/blocks/image.js +++ b/assets/js/src/newsletter_editor/blocks/image.js @@ -156,7 +156,7 @@ define([ }) ]); - if(window.wp.media.view.settings.post.featuredImageId) { + if (window.wp.media.view.settings.post.featuredImageId) { this.states.add(new window.wp.media.controller.FeaturedImage()); } }, diff --git a/assets/js/src/newsletter_editor/blocks/posts.js b/assets/js/src/newsletter_editor/blocks/posts.js index e1ad1d4259..bbb4707c88 100644 --- a/assets/js/src/newsletter_editor/blocks/posts.js +++ b/assets/js/src/newsletter_editor/blocks/posts.js @@ -124,7 +124,7 @@ define([ postCount = this.get('_availablePosts').length, nextOffset = this.get('offset') + Number(this.get('amount')); - if(postCount === 0 || postCount < nextOffset) { + if (postCount === 0 || postCount < nextOffset) { // No more posts to load return false; } @@ -300,7 +300,7 @@ define([ }, onPostsScroll: function (event) { var $postsBox = jQuery(event.target); - if($postsBox.scrollTop() + $postsBox.innerHeight() >= $postsBox[0].scrollHeight) { + if ($postsBox.scrollTop() + $postsBox.innerHeight() >= $postsBox[0].scrollHeight) { // Load more posts if scrolled to bottom this.blockModel.trigger('loadMorePosts'); } diff --git a/assets/js/src/newsletter_editor/components/save.js b/assets/js/src/newsletter_editor/components/save.js index 55a8e92c89..815d6280f4 100644 --- a/assets/js/src/newsletter_editor/components/save.js +++ b/assets/js/src/newsletter_editor/components/save.js @@ -45,11 +45,11 @@ define([ // save newsletter return CommunicationComponent.saveNewsletter(json).done(function (response) { - if(response.success !== undefined && response.success === true) { + if (response.success !== undefined && response.success === true) { // TODO: Handle translations // MailPoet.Notice.success(""); - } else if(response.error !== undefined) { - if(response.error.length === 0) { + } else if (response.error !== undefined) { + if (response.error.length === 0) { MailPoet.Notice.error( MailPoet.I18n.t('templateSaveFailed'), { @@ -283,7 +283,7 @@ define([ }, next: function () { this.hideOptionContents(); - if(!this.$('.mailpoet_save_next').hasClass('button-disabled')) { + if (!this.$('.mailpoet_save_next').hasClass('button-disabled')) { Module._cancelAutosave(); Module.save().done(function (response) { window.location.href = App.getConfig().get('urls.send'); diff --git a/assets/js/src/public.js b/assets/js/src/public.js index 5b1faf9342..502e804713 100644 --- a/assets/js/src/public.js +++ b/assets/js/src/public.js @@ -25,7 +25,7 @@ function ( form.find('.mailpoet_message > p').hide(); // resize iframe - if(window.frameElement !== null) { + if (window.frameElement !== null) { MailPoet.Iframe.autoSize(window.frameElement); } }); @@ -33,7 +33,7 @@ function ( form.parsley().on('form:submit', function (parsley) { var form_data = form.serializeObject() || {}; // check if we're on the same domain - if(isSameDomain(window.MailPoetForm.ajax_url) === false) { + if (isSameDomain(window.MailPoetForm.ajax_url) === false) { // non ajax post request return true; } else { diff --git a/assets/js/src/settings/tabs.js b/assets/js/src/settings/tabs.js index 0e16b4d26b..54221b5e52 100644 --- a/assets/js/src/settings/tabs.js +++ b/assets/js/src/settings/tabs.js @@ -10,7 +10,7 @@ define( mp ) { var MailPoet = mp; - if(jQuery('#mailpoet_settings').length === 0) { + if (jQuery('#mailpoet_settings').length === 0) { return; } @@ -32,7 +32,7 @@ define( // hide "save settings" button jQuery('.mailpoet_settings_submit').hide(); - if(group === null) { + if (group === null) { // show sending methods jQuery('.mailpoet_sending_methods, .mailpoet_sending_methods_help').fadeIn(); } else { @@ -65,7 +65,7 @@ define( jQuery('a.nav-tab[href="#' + tab + '"]').addClass('nav-tab-active').blur(); // show selected panel - if(jQuery('.mailpoet_panel[data-tab="' + tab + '"]').length > 0) { + if (jQuery('.mailpoet_panel[data-tab="' + tab + '"]').length > 0) { jQuery('.mailpoet_panel[data-tab="' + tab + '"]').show(); }