Fix eslint no-undef in ES5

[MAILPOET-1085]
This commit is contained in:
Pavel Dohnal
2017-09-05 17:29:48 +01:00
parent 9e932c9078
commit f77620d649
30 changed files with 284 additions and 299 deletions

View File

@@ -11,7 +11,6 @@
"import/no-amd": 0, "import/no-amd": 0,
"space-before-function-paren": 0, "space-before-function-paren": 0,
"prefer-arrow-callback": 0, "prefer-arrow-callback": 0,
"no-undef": 0,
"key-spacing": 0, "key-spacing": 0,
"radix": 0, "radix": 0,
"no-alert": 0, "no-alert": 0,

View File

@@ -30,15 +30,15 @@ define('ajax', ['mailpoet', 'jquery', 'underscore'], function(mp, jQuery, _) {
return this.request('post', options); return this.request('post', options);
}, },
init: function(options) { init: function(options) {
// merge options // merge options
this.options = jQuery.extend({}, this.defaults, options); this.options = jQuery.extend({}, this.defaults, options);
// set default url // set default url
if(this.options.url === null) { if(this.options.url === null) {
this.options.url = ajaxurl; this.options.url = window.ajaxurl;
} }
// set default token // set default token
if(this.options.token === null) { if(this.options.token === null) {
this.options.token = window.mailpoet_token; this.options.token = window.mailpoet_token;
} }

View File

@@ -43,15 +43,6 @@ function trackCachedEvents() {
}); });
} }
function initializeMixpanelWhenLoaded() {
if (typeof window.mixpanel === 'object') {
exportMixpanel(MailPoet);
trackCachedEvents();
} else {
setTimeout(initializeMixpanelWhenLoaded, 100);
}
}
function cacheEvent(forced, name, data) { function cacheEvent(forced, name, data) {
eventsCache.push({ eventsCache.push({
name: name, name: name,
@@ -65,9 +56,18 @@ define(
function(mp, _) { function(mp, _) {
var MailPoet = mp; var MailPoet = mp;
function initializeMixpanelWhenLoaded() {
if (typeof window.mixpanel === 'object') {
exportMixpanel(MailPoet);
trackCachedEvents();
} else {
setTimeout(initializeMixpanelWhenLoaded, 100);
}
}
MailPoet.trackEvent = _.partial(cacheEvent, false); MailPoet.trackEvent = _.partial(cacheEvent, false);
MailPoet.forceTrackEvent = _.partial(cacheEvent, true); MailPoet.forceTrackEvent = _.partial(cacheEvent, true);
initializeMixpanelWhenLoaded(); initializeMixpanelWhenLoaded(MailPoet);
} }
); );

View File

@@ -91,7 +91,7 @@ var Observable = (function() {
function getHandlers(klass) { function getHandlers(klass) {
var proto = klass.prototype, var proto = klass.prototype,
namespace = proto.namespace; namespace = proto.namespace;
return Object.keys(proto).grep(/^on/).inject($H(), function(handlers, name) { 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)); handlers.set(getEventName(name, namespace), getWrapper(proto[name], klass));
return handlers; return handlers;
@@ -105,7 +105,7 @@ var Observable = (function() {
} }
function onDomLoad(selector, klass) { function onDomLoad(selector, klass) {
$$(selector).each(function(element) { window.$$(selector).each(function(element) {
new klass(element).onDomLoaded(); new klass(element).onDomLoaded();
}); });
} }
@@ -130,12 +130,12 @@ var Observable = (function() {
})(); })();
// override droppables // override droppables
Object.extend(Droppables, { Object.extend(window.Droppables, {
deactivate: Droppables.deactivate.wrap(function(proceed, drop, draggable) { 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); return proceed(drop);
}), }),
activate: Droppables.activate.wrap(function(proceed, drop, draggable) { 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); return proceed(drop);
}), }),
@@ -143,14 +143,14 @@ Object.extend(Droppables, {
if(!this.drops.length) return; if(!this.drops.length) return;
var drop, affected = []; var drop, affected = [];
this.drops.each(function(drop) { this.drops.each(function(drop) {
if(Droppables.isAffected(point, element, drop)) affected.push(drop); if(window.Droppables.isAffected(point, element, drop)) affected.push(drop);
}); });
if(affected.length > 0) drop = Droppables.findDeepestChild(affected); if(affected.length > 0) drop = window.Droppables.findDeepestChild(affected);
if(this.last_active && this.last_active !== drop) this.deactivate(this.last_active, element); if(this.last_active && this.last_active !== drop) this.deactivate(this.last_active, element);
if(drop) { if(drop) {
Position.within(drop.element, point[0], point[1]); window.Position.within(drop.element, point[0], point[1]);
if(drop.onHover) drop.onHover(element, drop.element, Position.overlap(drop.overlap, drop.element)); if(drop.onHover) drop.onHover(element, drop.element, window.Position.overlap(drop.overlap, drop.element));
if(drop !== this.last_active) Droppables.activate(drop, element); if(drop !== this.last_active) window.Droppables.activate(drop, element);
} }
}, },
displayArea: function(draggable) { displayArea: function(draggable) {
@@ -199,36 +199,36 @@ var WysijaHistory = {
// check if the field is unique // 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 // check if the field is already in the queue
$(WysijaHistory.container).select('[wysija_name="' + clone.readAttribute('wysija_name') + '"]').invoke('remove'); window.$(WysijaHistory.container).select('[wysija_name="' + clone.readAttribute('wysija_name') + '"]').invoke('remove');
} }
// check history size // check history size
if($(WysijaHistory.container).select('> div').length >= WysijaHistory.size) { if(window.$(WysijaHistory.container).select('> div').length >= WysijaHistory.size) {
// remove oldest element (last in the list) // remove oldest element (last in the list)
$(WysijaHistory.container).select('> div').last().remove(); window.$(WysijaHistory.container).select('> div').last().remove();
} }
// store block in history // store block in history
$(WysijaHistory.container).insert({ window.$(WysijaHistory.container).insert({
top: clone top: clone
}); });
}, },
dequeue: function() { dequeue: function() {
// pop last block off the history // pop last block off the history
var block = $(WysijaHistory.container).select('div').first(); var block = window.$(WysijaHistory.container).select('div').first();
if(block !== undefined) { if(block !== undefined) {
// insert block back into the editor // insert block back into the editor
$(WysijaForm.options.body).insert({ window.$(WysijaForm.options.body).insert({
top: block top: block
}); });
} }
}, },
clear: function() { clear: function() {
$(WysijaHistory.container).innerHTML = ''; window.$(WysijaHistory.container).innerHTML = '';
}, },
remove: function(field) { remove: function(field) {
$(WysijaHistory.container).select('[wysija_name="' + field + '"]').invoke('remove'); window.$(WysijaHistory.container).select('[wysija_name="' + field + '"]').invoke('remove');
} }
}; };
@@ -272,17 +272,17 @@ var WysijaForm = {
}, },
loading: function(is_loading) { loading: function(is_loading) {
if(is_loading) { if(is_loading) {
$(WysijaForm.options.editor).addClassName('loading'); window.$(WysijaForm.options.editor).addClassName('loading');
$(WysijaForm.options.toolbar).addClassName('loading'); window.$(WysijaForm.options.toolbar).addClassName('loading');
} else { } else {
$(WysijaForm.options.editor).removeClassName('loading'); window.$(WysijaForm.options.editor).removeClassName('loading');
$(WysijaForm.options.toolbar).removeClassName('loading'); window.$(WysijaForm.options.toolbar).removeClassName('loading');
} }
}, },
loadStatic: function(blocks) { loadStatic: function(blocks) {
$A(blocks).each(function(block) { window.$A(blocks).each(function(block) {
// create block // create block
WysijaForm.Block.create(block, $('block_placeholder')); WysijaForm.Block.create(block, window.$('block_placeholder'));
}); });
}, },
load: function(data) { load: function(data) {
@@ -290,13 +290,13 @@ var WysijaForm = {
// load body // load body
if(data.body !== undefined) { if(data.body !== undefined) {
$A(data.body).each(function(block) { window.$A(data.body).each(function(block) {
// create block // create block
WysijaForm.Block.create(block, $('block_placeholder')); WysijaForm.Block.create(block, window.$('block_placeholder'));
}); });
// load settings // load settings
var settings_elements = $('mailpoet_form_settings').getElements(); var settings_elements = window.$('mailpoet_form_settings').getElements();
settings_elements.each(function(setting) { settings_elements.each(function(setting) {
// skip lists // skip lists
if(setting.name === 'segments') { if(setting.name === 'segments') {
@@ -305,7 +305,7 @@ var WysijaForm = {
// if the input value is equal to the one stored in the settings // 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 // check selected value
$(setting).checked = true; window.$(setting).checked = true;
} }
} else if(data.settings[setting.name] !== undefined) { } else if(data.settings[setting.name] !== undefined) {
if(typeof data.settings[setting.name] === 'string') { if(typeof data.settings[setting.name] === 'string') {
@@ -320,10 +320,10 @@ var WysijaForm = {
save: function() { save: function() {
var position = 1, var position = 1,
data = { data = {
name: $F('mailpoet_form_name'), name: window.$F('mailpoet_form_name'),
settings: $('mailpoet_form_settings').serialize(true), settings: window.$('mailpoet_form_settings').serialize(true),
body: [], body: [],
styles: (MailPoet.CodeEditor !== undefined) ? MailPoet.CodeEditor.getValue() : null styles: (window.MailPoet.CodeEditor !== undefined) ? window.MailPoet.CodeEditor.getValue() : null
}; };
// body // body
WysijaForm.getBlocks().each(function(b) { WysijaForm.getBlocks().each(function(b) {
@@ -395,11 +395,11 @@ var WysijaForm = {
return data; return data;
}, },
toggleWidgets: function() { toggleWidgets: function() {
$$('a[wysija_unique="1"]').invoke('removeClassName', 'disabled'); window.$$('a[wysija_unique="1"]').invoke('removeClassName', 'disabled');
// loop through each unique field already inserted in the editor and disable its toolbar equivalent // loop through each unique field already inserted in the editor and disable its toolbar equivalent
$$('#' + WysijaForm.options.editor + ' [wysija_unique="1"]').map(function(element) { window.$$('#' + WysijaForm.options.editor + ' [wysija_unique="1"]').map(function(element) {
var field = $$('#' + WysijaForm.options.toolbar + ' [wysija_id="' + element.readAttribute('wysija_id') + '"]'); var field = window.$$('#' + WysijaForm.options.toolbar + ' [wysija_id="' + element.readAttribute('wysija_id') + '"]');
if(field.length > 0) { if(field.length > 0) {
field.first().addClassName('disabled'); field.first().addClassName('disabled');
} }
@@ -408,18 +408,18 @@ var WysijaForm = {
var hasSegmentSelection = WysijaForm.hasSegmentSelection(); var hasSegmentSelection = WysijaForm.hasSegmentSelection();
if(hasSegmentSelection) { if(hasSegmentSelection) {
$('mailpoet_form_segments').writeAttribute('required', false).disable(); window.$('mailpoet_form_segments').writeAttribute('required', false).disable();
$('mailpoet_settings_segment_selection').hide(); window.$('mailpoet_settings_segment_selection').hide();
} else { } else {
$('mailpoet_form_segments').writeAttribute('required', true).enable(); window.$('mailpoet_form_segments').writeAttribute('required', true).enable();
$('mailpoet_settings_segment_selection').show(); window.$('mailpoet_settings_segment_selection').show();
} }
}, },
hasSegmentSelection: function() { hasSegmentSelection: function() {
return ($$('#' + WysijaForm.options.editor + ' [wysija_id="segments"]').length > 0); return (window.$$('#' + WysijaForm.options.editor + ' [wysija_id="segments"]').length > 0);
}, },
isSegmentSelectionValid: function() { isSegmentSelectionValid: function() {
var segment_selection = $$('#' + WysijaForm.options.editor + ' [wysija_id="segments"]')[0]; 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(); var block = WysijaForm.get(segment_selection).block.getData();
return ( return (
@@ -447,7 +447,7 @@ var WysijaForm = {
if(target !== undefined) { if(target !== undefined) {
// get placeholders (previous placeholder matches the placeholder linked to the next block) // get placeholders (previous placeholder matches the placeholder linked to the next block)
var block_placeholder = $(target.element.readAttribute('wysija_placeholder')), var block_placeholder = window.$(target.element.readAttribute('wysija_placeholder')),
previous_placeholder = target.element.previous('.block_placeholder'); previous_placeholder = target.element.previous('.block_placeholder');
if(block_placeholder !== null) { if(block_placeholder !== null) {
@@ -469,14 +469,14 @@ var WysijaForm = {
WysijaForm.scroll = document.viewport.getScrollOffsets(); WysijaForm.scroll = document.viewport.getScrollOffsets();
}, },
hideSettings: function() { hideSettings: function() {
$(WysijaForm.options.container).select('.wysija_settings').invoke('hide'); window.$(WysijaForm.options.container).select('.wysija_settings').invoke('hide');
}, },
setSettingsPosition: function() { setSettingsPosition: function() {
// get viewport offsets and dimensions // get viewport offsets and dimensions
var viewportHeight = document.viewport.getHeight(), var viewportHeight = document.viewport.getHeight(),
blockPadding = 5; blockPadding = 5;
$(WysijaForm.options.container).select('.wysija_settings').each(function(element) { window.$(WysijaForm.options.container).select('.wysija_settings').each(function(element) {
// get parent dimensions and position // get parent dimensions and position
var parentDim = element.up('.mailpoet_form_block').getDimensions(), var parentDim = element.up('.mailpoet_form_block').getDimensions(),
parentPos = element.up('.mailpoet_form_block').cumulativeOffset(), parentPos = element.up('.mailpoet_form_block').cumulativeOffset(),
@@ -494,22 +494,22 @@ var WysijaForm = {
relativeTop = parseInt((parentDim.height / 2) - (element.getHeight() / 2), 10); relativeTop = parseInt((parentDim.height / 2) - (element.getHeight() / 2), 10);
} }
// set position for button // set position for button
$(element).setStyle({ window.$(element).setStyle({
left: parseInt((parentDim.width / 2) - (element.getWidth() / 2)) + 'px', left: parseInt((parentDim.width / 2) - (element.getWidth() / 2)) + 'px',
top: relativeTop + 'px' top: relativeTop + 'px'
}); });
}); });
}, },
initToolbarPosition: function() { initToolbarPosition: function() {
if(WysijaForm.toolbar.top === null) WysijaForm.toolbar.top = parseInt($(WysijaForm.options.container).positionedOffset().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(WysijaForm.toolbar.y === null) WysijaForm.toolbar.y = parseInt(WysijaForm.toolbar.top);
if(isRtl) { if(window.isRtl) {
if(WysijaForm.toolbar.left === null) WysijaForm.toolbar.left = 0; if(WysijaForm.toolbar.left === null) WysijaForm.toolbar.left = 0;
} else { } else {
if(WysijaForm.toolbar.left === null) WysijaForm.toolbar.left = parseInt($(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 + $(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() { setToolbarPosition: function() {
@@ -520,13 +520,13 @@ var WysijaForm = {
visibility: 'visible' visibility: 'visible'
}; };
if(isRtl) { if(window.isRtl) {
position.right = WysijaForm.toolbar.x + 'px'; position.right = WysijaForm.toolbar.x + 'px';
} else { } else {
position.left = WysijaForm.toolbar.x + 'px'; position.left = WysijaForm.toolbar.x + 'px';
} }
$(WysijaForm.options.toolbar).setStyle(position); window.$(WysijaForm.options.toolbar).setStyle(position);
}, },
updateToolbarPosition: function() { updateToolbarPosition: function() {
// init toolbar position (updates scroll and toolbar y) // init toolbar position (updates scroll and toolbar y)
@@ -538,31 +538,31 @@ var WysijaForm = {
if(WysijaForm.scroll.top >= (WysijaForm.toolbar.top - 20)) { if(WysijaForm.scroll.top >= (WysijaForm.toolbar.top - 20)) {
WysijaForm.toolbar.y = parseInt(20 + WysijaForm.scroll.top); WysijaForm.toolbar.y = parseInt(20 + WysijaForm.scroll.top);
// start effect // start effect
WysijaForm.toolbar.effect = new Effect.Move(WysijaForm.options.toolbar, { WysijaForm.toolbar.effect = new window.Effect.Move(WysijaForm.options.toolbar, {
x: WysijaForm.toolbar.x, x: WysijaForm.toolbar.x,
y: WysijaForm.toolbar.y, y: WysijaForm.toolbar.y,
mode: 'absolute', mode: 'absolute',
duration: 0.2 duration: 0.2
}); });
} else { } else {
$(WysijaForm.options.toolbar).setStyle({ window.$(WysijaForm.options.toolbar).setStyle({
left: WysijaForm.toolbar.x + 'px', left: WysijaForm.toolbar.x + 'px',
top: WysijaForm.toolbar.top + 'px' top: WysijaForm.toolbar.top + 'px'
}); });
} }
}, },
blockDropOptions: { blockDropOptions: {
accept: $w('mailpoet_form_field'), // acceptable items (classes array) accept: window.$w('mailpoet_form_field'), // acceptable items (classes array)
onEnter: function(draggable, droppable) { onEnter: function(draggable, droppable) {
$(droppable).addClassName('hover'); window.$(droppable).addClassName('hover');
}, },
onLeave: function(draggable, droppable) { onLeave: function(draggable, droppable) {
$(droppable).removeClassName('hover'); window.$(droppable).removeClassName('hover');
}, },
onDrop: function(draggable, droppable) { onDrop: function(draggable, droppable) {
// custom data for images // custom data for images
droppable.fire('wjfe:item:drop', WysijaForm.getFieldData(draggable)); droppable.fire('wjfe:item:drop', WysijaForm.getFieldData(draggable));
$(droppable).removeClassName('hover'); window.$(droppable).removeClassName('hover');
} }
}, },
hideControls: function() { hideControls: function() {
@@ -573,7 +573,7 @@ var WysijaForm = {
} }
}, },
hideTools: function() { hideTools: function() {
$$('.wysija_tools').invoke('hide'); window.$$('.wysija_tools').invoke('hide');
WysijaForm.locks.showingTools = false; WysijaForm.locks.showingTools = false;
}, },
instances: {}, instances: {},
@@ -588,11 +588,11 @@ var WysijaForm = {
return instance; return instance;
}, },
makeDroppable: function() { makeDroppable: function() {
Droppables.add('block_placeholder', WysijaForm.blockDropOptions); window.Droppables.add('block_placeholder', WysijaForm.blockDropOptions);
}, },
makeSortable: function() { makeSortable: function() {
var body = $(WysijaForm.options.body); var body = window.$(WysijaForm.options.body);
Sortable.create(body, { window.Sortable.create(body, {
tag: 'div', tag: 'div',
only: 'mailpoet_form_block', only: 'mailpoet_form_block',
scroll: window, scroll: window,
@@ -600,15 +600,15 @@ var WysijaForm = {
constraint: 'vertical' constraint: 'vertical'
}); });
Draggables.removeObserver(body); window.Draggables.removeObserver(body);
Draggables.addObserver({ window.Draggables.addObserver({
element: body, element: body,
onStart: WysijaForm.startBlockPositions, onStart: WysijaForm.startBlockPositions,
onEnd: WysijaForm.setBlockPositions onEnd: WysijaForm.setBlockPositions
}); });
}, },
hideBlockControls: function() { hideBlockControls: function() {
$$('.wysija_controls').invoke('hide'); window.$$('.wysija_controls').invoke('hide');
this.getBlockElements().invoke('removeClassName', 'hover'); this.getBlockElements().invoke('removeClassName', 'hover');
}, },
getBlocks: function() { getBlocks: function() {
@@ -617,7 +617,7 @@ var WysijaForm = {
}); });
}, },
getBlockElements: function() { getBlockElements: function() {
return $(WysijaForm.options.container).select('.mailpoet_form_block'); return window.$(WysijaForm.options.container).select('.mailpoet_form_block');
}, },
startBlockPositions: function(event, target) { startBlockPositions: function(event, target) {
if(target.element.hasClassName('mailpoet_form_block')) { if(target.element.hasClassName('mailpoet_form_block')) {
@@ -665,14 +665,14 @@ var WysijaForm = {
} }
}; };
WysijaForm.DraggableItem = Class.create({ WysijaForm.DraggableItem = window.Class.create({
initialize: function(element) { initialize: function(element) {
this.elementType = $(element).readAttribute('wysija_type'); this.elementType = window.$(element).readAttribute('wysija_type');
this.element = $(element).down() || $(element); this.element = window.$(element).down() || window.$(element);
this.clone = this.cloneElement(); this.clone = this.cloneElement();
this.insert(); this.insert();
}, },
STYLES: new Template('position: absolute; top: #{top}px; left: #{left}px;'), STYLES: new window.Template('position: absolute; top: #{top}px; left: #{left}px;'),
cloneElement: function() { cloneElement: function() {
var clone = this.element.clone(), var clone = this.element.clone(),
offset = this.element.cumulativeOffset(), offset = this.element.cumulativeOffset(),
@@ -695,27 +695,27 @@ WysijaForm.DraggableItem = Class.create({
return this.element.up('ul'); return this.element.up('ul');
}, },
insert: function() { insert: function() {
$$('body')[0].insert(this.clone); window.$$('body')[0].insert(this.clone);
}, },
onMousedown: function(event) { onMousedown: function(event) {
var draggable = new Draggable(this.clone, { var draggable = new window.Draggable(this.clone, {
scroll: window, scroll: window,
onStart: function() { onStart: function() {
Droppables.displayArea(draggable); window.Droppables.displayArea(draggable);
}, },
onEnd: function(drag) { onEnd: function(drag) {
drag.destroy(); drag.destroy();
drag.element.remove(); drag.element.remove();
Droppables.hideArea(); window.Droppables.hideArea();
}, },
starteffect: function(element) { starteffect: function(element) {
new Effect.Opacity(element, { new window.Effect.Opacity(element, {
duration: 0.2, duration: 0.2,
from: element.getOpacity(), from: element.getOpacity(),
to: 0.7 to: 0.7
}); });
}, },
endeffect: Prototype.emptyFunction endeffect: window.Prototype.emptyFunction
}); });
draggable.initDrag(event); draggable.initDrag(event);
draggable.startDrag(event); draggable.startDrag(event);
@@ -725,12 +725,12 @@ WysijaForm.DraggableItem = Class.create({
Object.extend(WysijaForm.DraggableItem, Observable).observe('a[class="mailpoet_form_field"]'); Object.extend(WysijaForm.DraggableItem, Observable).observe('a[class="mailpoet_form_field"]');
WysijaForm.Block = Class.create({ WysijaForm.Block = window.Class.create({
/* Invoked on load */ /* Invoked on load */
initialize: function(element) { initialize: function(element) {
info('block -> init'); info('block -> init');
this.element = $(element); this.element = window.$(element);
this.block = new WysijaForm.Widget(this.element); this.block = new WysijaForm.Widget(this.element);
// enable block placeholder // enable block placeholder
@@ -763,14 +763,14 @@ WysijaForm.Block = Class.create({
makeBlockDroppable: function() { makeBlockDroppable: function() {
if(this.isBlockDroppableEnabled() === false) { if(this.isBlockDroppableEnabled() === false) {
var block_placeholder = this.getBlockDroppable(); var block_placeholder = this.getBlockDroppable();
Droppables.add(block_placeholder.identify(), WysijaForm.blockDropOptions); window.Droppables.add(block_placeholder.identify(), WysijaForm.blockDropOptions);
block_placeholder.addClassName('enabled'); block_placeholder.addClassName('enabled');
} }
}, },
removeBlockDroppable: function() { removeBlockDroppable: function() {
if(this.isBlockDroppableEnabled()) { if(this.isBlockDroppableEnabled()) {
var block_placeholder = this.getBlockDroppable(); var block_placeholder = this.getBlockDroppable();
Droppables.remove(block_placeholder.identify()); window.Droppables.remove(block_placeholder.identify());
block_placeholder.removeClassName('enabled'); block_placeholder.removeClassName('enabled');
} }
}, },
@@ -786,7 +786,7 @@ WysijaForm.Block = Class.create({
createBlockDroppable: function() { createBlockDroppable: function() {
info('block -> createBlockDroppable'); info('block -> createBlockDroppable');
this.element.insert({ this.element.insert({
before: '<div class=\"block_placeholder\">' + $('block_placeholder').innerHTML + '</div>' before: '<div class=\"block_placeholder\">' + window.$('block_placeholder').innerHTML + '</div>'
}); });
return this.element.previous('.block_placeholder'); return this.element.previous('.block_placeholder');
}, },
@@ -851,7 +851,7 @@ WysijaForm.Block = Class.create({
if(this.settingsButton !== null) { if(this.settingsButton !== null) {
this.settingsButton.observe('click', function(event) { this.settingsButton.observe('click', function(event) {
// TODO: refactor // TODO: refactor
var block = $(event.target).up('.mailpoet_form_block') || null; var block = window.$(event.target).up('.mailpoet_form_block') || null;
if(block !== null) { if(block !== null) {
var field = WysijaForm.getFieldData(block); var field = WysijaForm.getFieldData(block);
this.editSettings(); this.editSettings();
@@ -867,7 +867,7 @@ WysijaForm.Block = Class.create({
// save block in history // save block in history
WysijaHistory.enqueue(this.element); WysijaHistory.enqueue(this.element);
Effect.Fade(this.element.identify(), { window.Effect.Fade(this.element.identify(), {
duration: 0.2, duration: 0.2,
afterFinish: function(effect) { afterFinish: function(effect) {
// remove placeholder // remove placeholder
@@ -899,20 +899,20 @@ WysijaForm.Block = Class.create({
/* Invoked on item dropped */ /* Invoked on item dropped */
WysijaForm.Block.create = function(createBlock, target) { WysijaForm.Block.create = function(createBlock, target) {
var block = createBlock; var block = createBlock;
if($('form_template_' + block.type) === null) { if(window.$('form_template_' + block.type) === null) {
return false; return false;
} }
var body = $(WysijaForm.options.body), var body = window.$(WysijaForm.options.body),
block_template = Handlebars.compile($('form_template_block').innerHTML), block_template = window.Handlebars.compile(window.$('form_template_block').innerHTML),
template = Handlebars.compile($('form_template_' + block.type).innerHTML), template = window.Handlebars.compile(window.$('form_template_' + block.type).innerHTML),
output = ''; output = '';
if(block.type === 'segment') { if(block.type === 'segment') {
if(block.params.values === undefined) { if(block.params.values === undefined) {
var settings_segments = jQuery('#mailpoet_form_segments').val(); 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 = mailpoet_segments.filter(function(segment) { block.params.values = window.mailpoet_segments.filter(function(segment) {
return (settings_segments.indexOf(segment.id) !== -1); return (settings_segments.indexOf(segment.id) !== -1);
}); });
} }
@@ -967,10 +967,10 @@ document.observe('wjfe:item:drop', function(event) {
}); });
/* Form Widget */ /* Form Widget */
WysijaForm.Widget = Class.create(WysijaForm.Block, { WysijaForm.Widget = window.Class.create(WysijaForm.Block, {
initialize: function(element) { initialize: function(element) {
info('widget -> init'); info('widget -> init');
this.element = $(element); this.element = window.$(element);
return this; return this;
}, },
setup: function() { setup: function() {
@@ -989,7 +989,7 @@ WysijaForm.Widget = Class.create(WysijaForm.Block, {
}, },
setData: function(data) { setData: function(data) {
var current_data = this.getData(), var current_data = this.getData(),
params = $H(current_data.params).merge(data.params).toObject(); params = window.$H(current_data.params).merge(data.params).toObject();
// update type if it changed // update type if it changed
if(data.type !== undefined && data.type !== current_data.type) { if(data.type !== undefined && data.type !== current_data.type) {
@@ -1018,9 +1018,9 @@ WysijaForm.Widget = Class.create(WysijaForm.Block, {
this.setData(data); this.setData(data);
var options = this.getData(); var options = this.getData();
// redraw block // redraw block
var block_template = Handlebars.compile($('form_template_block').innerHTML), var block_template = window.Handlebars.compile(window.$('form_template_block').innerHTML),
template = Handlebars.compile($('form_template_' + options.type).innerHTML), template = window.Handlebars.compile(window.$('form_template_' + options.type).innerHTML),
data = $H(options).merge({ data = window.$H(options).merge({
template: template(options) template: template(options)
}).toObject(); }).toObject();
this.element.replace(block_template(data)); this.element.replace(block_template(data));
@@ -1028,12 +1028,12 @@ WysijaForm.Widget = Class.create(WysijaForm.Block, {
WysijaForm.init(); WysijaForm.init();
}, },
editSettings: function() { editSettings: function() {
MailPoet.Modal.popup({ window.MailPoet.Modal.popup({
title: MailPoet.I18n.t('editFieldSettings'), title: window.MailPoet.I18n.t('editFieldSettings'),
template: jQuery('#form_template_field_settings').html(), template: window.jQuery('#form_template_field_settings').html(),
data: this.getData(), data: this.getData(),
onSuccess: function() { onSuccess: function() {
var data = jQuery('#form_field_settings').serializeObject(); var data = window.jQuery('#form_field_settings').serializeObject();
this.redraw(data); this.redraw(data);
}.bind(this) }.bind(this)
}); });

View File

@@ -22,9 +22,9 @@ define('handlebars_helpers', ['handlebars'], function(Handlebars) {
var f = block.hash.format || 'MMM Do, YYYY'; var f = block.hash.format || 'MMM Do, YYYY';
// check if we passed a timestamp // check if we passed a timestamp
if(parseInt(timestamp, 10) == timestamp) { if(parseInt(timestamp, 10) == timestamp) {
return moment.unix(timestamp).format(f); return window.moment.unix(timestamp).format(f);
} else { } else {
return moment.utc(timestamp).format(f); return window.moment.utc(timestamp).format(f);
} }
} else { } else {
return timestamp; return timestamp;

View File

@@ -112,7 +112,7 @@ define('modal', ['mailpoet', 'jquery'],
if(this.renderer === 'html') { if(this.renderer === 'html') {
return function() { return template; }; return function() { return template; };
} else { } else {
return Handlebars.compile(template); return window.Handlebars.compile(template);
} }
return false; return false;
}, },

View File

@@ -26,7 +26,7 @@ define('mp2migrator', ['mailpoet', 'jquery'], function(mp, jQuery) {
displayLogs: function () { displayLogs: function () {
jQuery.ajax({ jQuery.ajax({
url: mailpoet_mp2_migrator.log_file_url, url: window.mailpoet_mp2_migrator.log_file_url,
cache: false cache: false
}).done(function (result) { }).done(function (result) {
jQuery('#logger').html(''); jQuery('#logger').html('');
@@ -53,7 +53,7 @@ define('mp2migrator', ['mailpoet', 'jquery'], function(mp, jQuery) {
updateProgressbar: function () { updateProgressbar: function () {
jQuery.ajax({ jQuery.ajax({
url: mailpoet_mp2_migrator.progress_url, url: window.mailpoet_mp2_migrator.progress_url,
cache: false, cache: false,
dataType: 'json' dataType: 'json'
}).always(function (result) { }).always(function (result) {

View File

@@ -1,3 +1,4 @@
/** /**
* ContainerDropZoneBehavior * ContainerDropZoneBehavior
* *
@@ -195,7 +196,8 @@ define([
if (view.model.get('orientation') === 'horizontal' && droppableModel.get('type') !== 'container') { if (view.model.get('orientation') === 'horizontal' && droppableModel.get('type') !== 'container') {
// Regular blocks always need to be inserted into columns - vertical containers // Regular blocks always need to be inserted into columns - vertical containers
tempCollection = new (EditorApplication.getBlockTypeModel('container'))({
tempCollection = new (window.EditorApplication.getBlockTypeModel('container'))({
orientation: 'vertical' orientation: 'vertical'
}); });
tempCollection.get('blocks').add(droppableModel); tempCollection.get('blocks').add(droppableModel);
@@ -210,7 +212,7 @@ define([
// and inserting dropModel into that // and inserting dropModel into that
var tempModel = viewCollection.at(dropPosition.index); var tempModel = viewCollection.at(dropPosition.index);
tempCollection = new (EditorApplication.getBlockTypeModel('container'))({ tempCollection = new (window.EditorApplication.getBlockTypeModel('container'))({
orientation: (view.model.get('orientation') === 'vertical') ? 'horizontal' : 'vertical' orientation: (view.model.get('orientation') === 'vertical') ? 'horizontal' : 'vertical'
}); });
@@ -218,19 +220,19 @@ define([
if (tempCollection.get('orientation') === 'horizontal') { if (tempCollection.get('orientation') === 'horizontal') {
if (dropPosition.position === 'before') { if (dropPosition.position === 'before') {
tempCollection2 = new (EditorApplication.getBlockTypeModel('container'))({ tempCollection2 = new (window.EditorApplication.getBlockTypeModel('container'))({
orientation: 'vertical' orientation: 'vertical'
}); });
tempCollection2.get('blocks').add(droppableModel); tempCollection2.get('blocks').add(droppableModel);
tempCollection.get('blocks').add(tempCollection2); tempCollection.get('blocks').add(tempCollection2);
} }
tempCollection2 = new (EditorApplication.getBlockTypeModel('container'))({ tempCollection2 = new (window.EditorApplication.getBlockTypeModel('container'))({
orientation: 'vertical' orientation: 'vertical'
}); });
tempCollection2.get('blocks').add(tempModel); tempCollection2.get('blocks').add(tempModel);
tempCollection.get('blocks').add(tempCollection2); tempCollection.get('blocks').add(tempCollection2);
if (dropPosition.position === 'after') { if (dropPosition.position === 'after') {
tempCollection2 = new (EditorApplication.getBlockTypeModel('container'))({ tempCollection2 = new (window.EditorApplication.getBlockTypeModel('container'))({
orientation: 'vertical' orientation: 'vertical'
}); });
tempCollection2.get('blocks').add(droppableModel); tempCollection2.get('blocks').add(droppableModel);
@@ -291,7 +293,7 @@ define([
insertionType, index, position, indexAndPosition; insertionType, index, position, indexAndPosition;
unsafe = !!is_unsafe; var unsafe = !!is_unsafe;
if (this.getCollection().length === 0) { if (this.getCollection().length === 0) {
return { return {

View File

@@ -65,7 +65,7 @@ define([
editor.focus(); editor.focus();
if (that._isActivationClick) { if (that._isActivationClick) {
editor.selection.setRng( editor.selection.setRng(
tinymce.dom.RangeUtils.getCaretRangeFromPoint(e.clientX, e.clientY, editor.getDoc()) window.tinymce.dom.RangeUtils.getCaretRangeFromPoint(e.clientX, e.clientY, editor.getDoc())
); );
that._isActivationClick = false; that._isActivationClick = false;
} }

View File

@@ -135,7 +135,7 @@ define([
} }
App.getChannel().on('replaceAllButtonStyles', replaceButtonStylesHandler.bind(this)); App.getChannel().on('replaceAllButtonStyles', replaceButtonStylesHandler.bind(this));
}, },
getTemplate: function() { return templates.automatedLatestContentBlock; }, getTemplate: function() { return window.templates.automatedLatestContentBlock; },
regions: { regions: {
toolsRegion: '.mailpoet_tools', toolsRegion: '.mailpoet_tools',
postsRegion: '.mailpoet_automated_latest_content_block_posts' postsRegion: '.mailpoet_automated_latest_content_block_posts'
@@ -168,7 +168,7 @@ define([
// Sidebar view container // Sidebar view container
Module.AutomatedLatestContentBlockSettingsView = base.BlockSettingsView.extend({ Module.AutomatedLatestContentBlockSettingsView = base.BlockSettingsView.extend({
getTemplate: function() { return templates.automatedLatestContentBlockSettings; }, getTemplate: function() { return window.templates.automatedLatestContentBlockSettings; },
events: function() { events: function() {
return { return {
'click .mailpoet_automated_latest_content_hide_display_options': 'toggleDisplayOptions', 'click .mailpoet_automated_latest_content_hide_display_options': 'toggleDisplayOptions',
@@ -364,7 +364,7 @@ define([
}); });
Module.AutomatedLatestContentWidgetView = base.WidgetView.extend({ Module.AutomatedLatestContentWidgetView = base.WidgetView.extend({
getTemplate: function() { return templates.automatedLatestContentInsertion; }, getTemplate: function() { return window.templates.automatedLatestContentInsertion; },
behaviors: { behaviors: {
DraggableBehavior: { DraggableBehavior: {
cloneOriginal: true, cloneOriginal: true,

View File

@@ -178,7 +178,7 @@ define([
}); });
Module.BlockToolsView = AugmentedView.extend({ Module.BlockToolsView = AugmentedView.extend({
getTemplate: function() { return templates.genericBlockTools; }, getTemplate: function() { 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',

View File

@@ -42,7 +42,7 @@ define([
Module.ButtonBlockView = base.BlockView.extend({ Module.ButtonBlockView = base.BlockView.extend({
className: 'mailpoet_block mailpoet_button_block mailpoet_droppable_block', className: 'mailpoet_block mailpoet_button_block mailpoet_droppable_block',
getTemplate: function() { return templates.buttonBlock; }, getTemplate: function() { return window.templates.buttonBlock; },
onDragSubstituteBy: function() { return Module.ButtonWidgetView; }, onDragSubstituteBy: function() { return Module.ButtonWidgetView; },
behaviors: _.extend({}, base.BlockView.prototype.behaviors, { behaviors: _.extend({}, base.BlockView.prototype.behaviors, {
ShowSettingsBehavior: {} ShowSettingsBehavior: {}
@@ -65,7 +65,7 @@ define([
}); });
Module.ButtonBlockSettingsView = base.BlockSettingsView.extend({ Module.ButtonBlockSettingsView = base.BlockSettingsView.extend({
getTemplate: function() { return templates.buttonBlockSettings; }, getTemplate: function() { return window.templates.buttonBlockSettings; },
events: function() { events: function() {
return { return {
'input .mailpoet_field_button_text': _.partial(this.changeField, 'text'), 'input .mailpoet_field_button_text': _.partial(this.changeField, 'text'),
@@ -121,7 +121,7 @@ define([
}); });
Module.ButtonWidgetView = base.WidgetView.extend({ Module.ButtonWidgetView = base.WidgetView.extend({
getTemplate: function() { return templates.buttonInsertion; }, getTemplate: function() { return window.templates.buttonInsertion; },
behaviors: { behaviors: {
DraggableBehavior: { DraggableBehavior: {
cloneOriginal: true, cloneOriginal: true,

View File

@@ -103,7 +103,7 @@ define([
} }
}), }),
className: 'mailpoet_block mailpoet_container_block mailpoet_droppable_block mailpoet_droppable_layout_block', className: 'mailpoet_block mailpoet_container_block mailpoet_droppable_block mailpoet_droppable_layout_block',
getTemplate: function() { return templates.containerBlock; }, getTemplate: function() { return window.templates.containerBlock; },
events: _.extend({}, base.BlockView.prototype.events, { events: _.extend({}, base.BlockView.prototype.events, {
'click .mailpoet_newsletter_layer_selector': 'toggleEditingLayer' 'click .mailpoet_newsletter_layer_selector': 'toggleEditingLayer'
}), }),
@@ -217,7 +217,7 @@ define([
}); });
Module.ContainerBlockEmptyView = Marionette.View.extend({ Module.ContainerBlockEmptyView = Marionette.View.extend({
getTemplate: function() { return templates.containerEmpty; }, getTemplate: function() { return window.templates.containerEmpty; },
initialize: function(options) { initialize: function(options) {
this.renderOptions = _.defaults(options.renderOptions || {}, {}); this.renderOptions = _.defaults(options.renderOptions || {}, {});
}, },
@@ -234,7 +234,7 @@ define([
}); });
Module.ContainerBlockSettingsView = base.BlockSettingsView.extend({ Module.ContainerBlockSettingsView = base.BlockSettingsView.extend({
getTemplate: function() { return templates.containerBlockSettings; }, getTemplate: function() { return window.templates.containerBlockSettings; },
events: function() { events: function() {
return { return {
'change .mailpoet_field_container_background_color': _.partial(this.changeColorField, 'styles.block.backgroundColor'), 'change .mailpoet_field_container_background_color': _.partial(this.changeColorField, 'styles.block.backgroundColor'),
@@ -266,7 +266,7 @@ define([
}); });
Module.ContainerBlockColumnSettingsView = Marionette.View.extend({ Module.ContainerBlockColumnSettingsView = Marionette.View.extend({
getTemplate: function() { return templates.containerBlockColumnSettings; }, getTemplate: function() { return window.templates.containerBlockColumnSettings; },
initialize: function(options) { initialize: function(options) {
this.columnNumber = (options.columnIndex || 0) + 1; this.columnNumber = (options.columnIndex || 0) + 1;
}, },
@@ -280,7 +280,7 @@ define([
Module.OneColumnContainerWidgetView = base.WidgetView.extend({ Module.OneColumnContainerWidgetView = base.WidgetView.extend({
className: base.WidgetView.prototype.className + ' mailpoet_droppable_layout_block', className: base.WidgetView.prototype.className + ' mailpoet_droppable_layout_block',
getTemplate: function() { return templates.oneColumnLayoutInsertion; }, getTemplate: function() { return window.templates.oneColumnLayoutInsertion; },
behaviors: { behaviors: {
DraggableBehavior: { DraggableBehavior: {
cloneOriginal: true, cloneOriginal: true,
@@ -298,7 +298,7 @@ define([
Module.TwoColumnContainerWidgetView = base.WidgetView.extend({ Module.TwoColumnContainerWidgetView = base.WidgetView.extend({
className: base.WidgetView.prototype.className + ' mailpoet_droppable_layout_block', className: base.WidgetView.prototype.className + ' mailpoet_droppable_layout_block',
getTemplate: function() { return templates.twoColumnLayoutInsertion; }, getTemplate: function() { return window.templates.twoColumnLayoutInsertion; },
behaviors: { behaviors: {
DraggableBehavior: { DraggableBehavior: {
cloneOriginal: true, cloneOriginal: true,
@@ -317,7 +317,7 @@ define([
Module.ThreeColumnContainerWidgetView = base.WidgetView.extend({ Module.ThreeColumnContainerWidgetView = base.WidgetView.extend({
className: base.WidgetView.prototype.className + ' mailpoet_droppable_layout_block', className: base.WidgetView.prototype.className + ' mailpoet_droppable_layout_block',
getTemplate: function() { return templates.threeColumnLayoutInsertion; }, getTemplate: function() { return window.templates.threeColumnLayoutInsertion; },
behaviors: { behaviors: {
DraggableBehavior: { DraggableBehavior: {
cloneOriginal: true, cloneOriginal: true,

View File

@@ -33,7 +33,7 @@ define([
Module.DividerBlockView = base.BlockView.extend({ Module.DividerBlockView = base.BlockView.extend({
className: 'mailpoet_block mailpoet_divider_block mailpoet_droppable_block', className: 'mailpoet_block mailpoet_divider_block mailpoet_droppable_block',
getTemplate: function() { return templates.dividerBlock; }, getTemplate: function() { return window.templates.dividerBlock; },
modelEvents: _.omit(base.BlockView.prototype.modelEvents, 'change'), modelEvents: _.omit(base.BlockView.prototype.modelEvents, 'change'),
behaviors: _.defaults({ behaviors: _.defaults({
ResizableBehavior: { ResizableBehavior: {
@@ -84,7 +84,7 @@ define([
}); });
Module.DividerBlockSettingsView = base.BlockSettingsView.extend({ Module.DividerBlockSettingsView = base.BlockSettingsView.extend({
getTemplate: function() { return templates.dividerBlockSettings; }, getTemplate: function() { return window.templates.dividerBlockSettings; },
events: function() { events: function() {
return { return {
'click .mailpoet_field_divider_style': 'changeStyle', 'click .mailpoet_field_divider_style': 'changeStyle',
@@ -129,7 +129,7 @@ define([
}); });
Module.DividerWidgetView = base.WidgetView.extend({ Module.DividerWidgetView = base.WidgetView.extend({
getTemplate: function() { return templates.dividerInsertion; }, getTemplate: function() { return window.templates.dividerInsertion; },
behaviors: { behaviors: {
DraggableBehavior: { DraggableBehavior: {
cloneOriginal: true, cloneOriginal: true,

View File

@@ -4,8 +4,9 @@
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/blocks/base', 'newsletter_editor/blocks/base',
'underscore' 'underscore',
], function(App, BaseBlock, _) { 'mailpoet'
], function(App, BaseBlock, _, MailPoet) {
'use strict'; 'use strict';
@@ -38,7 +39,7 @@ define([
Module.FooterBlockView = base.BlockView.extend({ Module.FooterBlockView = base.BlockView.extend({
className: 'mailpoet_block mailpoet_footer_block mailpoet_droppable_block', className: 'mailpoet_block mailpoet_footer_block mailpoet_droppable_block',
getTemplate: function() { return templates.footerBlock; }, getTemplate: function() { return window.templates.footerBlock; },
modelEvents: _.extend({ modelEvents: _.extend({
'change:styles.block.backgroundColor change:styles.text.fontColor change:styles.text.fontFamily change:styles.text.fontSize change:styles.text.textAlign change:styles.link.fontColor change:styles.link.textDecoration': 'render' 'change:styles.block.backgroundColor change:styles.text.fontColor change:styles.text.fontFamily change:styles.text.fontSize change:styles.text.textAlign change:styles.link.fontColor change:styles.link.textDecoration': 'render'
}, _.omit(base.BlockView.prototype.modelEvents, 'change')), }, _.omit(base.BlockView.prototype.modelEvents, 'change')),
@@ -75,7 +76,7 @@ define([
}); });
Module.FooterBlockSettingsView = base.BlockSettingsView.extend({ Module.FooterBlockSettingsView = base.BlockSettingsView.extend({
getTemplate: function() { return templates.footerBlockSettings; }, getTemplate: function() { return window.templates.footerBlockSettings; },
events: function() { events: function() {
return { return {
'change .mailpoet_field_footer_text_color': _.partial(this.changeColorField, 'styles.text.fontColor'), 'change .mailpoet_field_footer_text_color': _.partial(this.changeColorField, 'styles.text.fontColor'),
@@ -98,7 +99,7 @@ define([
}); });
Module.FooterWidgetView = base.WidgetView.extend({ Module.FooterWidgetView = base.WidgetView.extend({
getTemplate: function() { return templates.footerInsertion; }, getTemplate: function() { return window.templates.footerInsertion; },
behaviors: { behaviors: {
DraggableBehavior: { DraggableBehavior: {
cloneOriginal: true, cloneOriginal: true,

View File

@@ -4,8 +4,9 @@
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/blocks/base', 'newsletter_editor/blocks/base',
'underscore' 'underscore',
], function(App, BaseBlock, _) { 'mailpoet'
], function(App, BaseBlock, _, MailPoet) {
'use strict'; 'use strict';
@@ -38,7 +39,7 @@ define([
Module.HeaderBlockView = base.BlockView.extend({ Module.HeaderBlockView = base.BlockView.extend({
className: 'mailpoet_block mailpoet_header_block mailpoet_droppable_block', className: 'mailpoet_block mailpoet_header_block mailpoet_droppable_block',
getTemplate: function() { return templates.headerBlock; }, getTemplate: function() { return window.templates.headerBlock; },
modelEvents: _.extend({ modelEvents: _.extend({
'change:styles.block.backgroundColor change:styles.text.fontColor change:styles.text.fontFamily change:styles.text.fontSize change:styles.text.textAlign change:styles.link.fontColor change:styles.link.textDecoration': 'render' 'change:styles.block.backgroundColor change:styles.text.fontColor change:styles.text.fontFamily change:styles.text.fontSize change:styles.text.textAlign change:styles.link.fontColor change:styles.link.textDecoration': 'render'
}, _.omit(base.BlockView.prototype.modelEvents, 'change')), }, _.omit(base.BlockView.prototype.modelEvents, 'change')),
@@ -75,7 +76,7 @@ define([
}); });
Module.HeaderBlockSettingsView = base.BlockSettingsView.extend({ Module.HeaderBlockSettingsView = base.BlockSettingsView.extend({
getTemplate: function() { return templates.headerBlockSettings; }, getTemplate: function() { return window.templates.headerBlockSettings; },
events: function() { events: function() {
return { return {
'change .mailpoet_field_header_text_color': _.partial(this.changeColorField, 'styles.text.fontColor'), 'change .mailpoet_field_header_text_color': _.partial(this.changeColorField, 'styles.text.fontColor'),
@@ -98,7 +99,7 @@ define([
}); });
Module.HeaderWidgetView = base.WidgetView.extend({ Module.HeaderWidgetView = base.WidgetView.extend({
getTemplate: function() { return templates.headerInsertion; }, getTemplate: function() { return window.templates.headerInsertion; },
behaviors: { behaviors: {
DraggableBehavior: { DraggableBehavior: {
cloneOriginal: true, cloneOriginal: true,

View File

@@ -5,8 +5,9 @@ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/blocks/base', 'newsletter_editor/blocks/base',
'underscore', 'underscore',
'mailpoet' 'mailpoet',
], function(App, BaseBlock, _, MailPoet) { 'jquery'
], function(App, BaseBlock, _, MailPoet, jQuery) {
'use strict'; 'use strict';
@@ -35,7 +36,7 @@ define([
Module.ImageBlockView = base.BlockView.extend({ Module.ImageBlockView = base.BlockView.extend({
className: 'mailpoet_block mailpoet_image_block mailpoet_droppable_block', className: 'mailpoet_block mailpoet_image_block mailpoet_droppable_block',
getTemplate: function() { return templates.imageBlock; }, getTemplate: function() { return window.templates.imageBlock; },
onDragSubstituteBy: function() { return Module.ImageWidgetView; }, onDragSubstituteBy: function() { return Module.ImageWidgetView; },
templateContext: function() { templateContext: function() {
return _.extend({ return _.extend({
@@ -72,7 +73,7 @@ define([
tooltip: MailPoet.I18n.t('helpTooltipDesignerIdealWidth') tooltip: MailPoet.I18n.t('helpTooltipDesignerIdealWidth')
}); });
}, },
getTemplate: function() { return templates.imageBlockSettings; }, getTemplate: function() { return window.templates.imageBlockSettings; },
events: function() { events: function() {
return { return {
'input .mailpoet_field_image_link': _.partial(this.changeField, 'link'), 'input .mailpoet_field_image_link': _.partial(this.changeField, 'link'),
@@ -98,10 +99,10 @@ define([
return; return;
} }
var MediaManager = wp.media.view.MediaFrame.Select.extend({ var MediaManager = window.wp.media.view.MediaFrame.Select.extend({
initialize: function() { initialize: function() {
wp.media.view.MediaFrame.prototype.initialize.apply(this, arguments); window.wp.media.view.MediaFrame.prototype.initialize.apply(this, arguments);
_.defaults(this.options, { _.defaults(this.options, {
multiple: true, multiple: true,
@@ -123,7 +124,7 @@ define([
}, },
createQuery: function(options) { createQuery: function(options) {
var query = wp.media.query(options); var query = window.wp.media.query(options);
return query; return query;
}, },
@@ -133,7 +134,7 @@ define([
// Add the default states. // Add the default states.
this.states.add([ this.states.add([
// Main states. // Main states.
new wp.media.controller.Library({ new window.wp.media.controller.Library({
id: 'insert', id: 'insert',
title: 'Add images', title: 'Add images',
priority: 20, priority: 20,
@@ -155,8 +156,8 @@ define([
}) })
]); ]);
if(wp.media.view.settings.post.featuredImageId) { if(window.wp.media.view.settings.post.featuredImageId) {
this.states.add(new wp.media.controller.FeaturedImage()); this.states.add(new window.wp.media.controller.FeaturedImage());
} }
}, },
@@ -193,13 +194,13 @@ define([
}, },
uploadContent: function() { uploadContent: function() {
wp.media.view.MediaFrame.Select.prototype.uploadContent.apply(this, arguments); window.wp.media.view.MediaFrame.Select.prototype.uploadContent.apply(this, arguments);
this.$el.addClass('hide-toolbar'); this.$el.addClass('hide-toolbar');
}, },
// Content // Content
embedContent: function() { embedContent: function() {
var view = new wp.media.view.Embed({ var view = new window.wp.media.view.Embed({
controller: this, controller: this,
model: this.state() model: this.state()
}).render(); }).render();
@@ -213,7 +214,7 @@ define([
selection = state.get('selection'), selection = state.get('selection'),
view; view;
view = new wp.media.view.AttachmentsBrowser({ view = new window.wp.media.view.AttachmentsBrowser({
controller: this, controller: this,
collection: selection, collection: selection,
selection: selection, selection: selection,
@@ -222,7 +223,7 @@ define([
search: false, search: false,
dragInfo: true, dragInfo: true,
AttachmentView: wp.media.view.Attachment.EditSelection AttachmentView: window.wp.media.view.Attachment.EditSelection
}).render(); }).render();
view.toolbar.set('backToLibrary', { view.toolbar.set('backToLibrary', {
@@ -242,7 +243,7 @@ define([
selectionStatusToolbar: function(view) { selectionStatusToolbar: function(view) {
var editable = this.state().get('editable'); var editable = this.state().get('editable');
view.set('selection', new wp.media.view.Selection({ view.set('selection', new window.wp.media.view.Selection({
controller: this, controller: this,
collection: this.state().get('selection'), collection: this.state().get('selection'),
priority: -40, priority: -40,
@@ -278,7 +279,7 @@ define([
mainEmbedToolbar: function(toolbar) { mainEmbedToolbar: function(toolbar) {
var tbar = toolbar; var tbar = toolbar;
tbar.view = new wp.media.view.Toolbar.Embed({ tbar.view = new window.wp.media.view.Toolbar.Embed({
controller: this, controller: this,
text: 'Add images' text: 'Add images'
}); });
@@ -363,7 +364,7 @@ define([
}); });
ImageWidgetView = base.WidgetView.extend({ ImageWidgetView = base.WidgetView.extend({
getTemplate: function() { return templates.imageInsertion; }, getTemplate: function() { return window.templates.imageInsertion; },
behaviors: { behaviors: {
DraggableBehavior: { DraggableBehavior: {
cloneOriginal: true, cloneOriginal: true,

View File

@@ -177,7 +177,7 @@ define([
Module.PostsBlockView = base.BlockView.extend({ Module.PostsBlockView = base.BlockView.extend({
className: 'mailpoet_block mailpoet_posts_block mailpoet_droppable_block', className: 'mailpoet_block mailpoet_posts_block mailpoet_droppable_block',
getTemplate: function() { return templates.postsBlock; }, getTemplate: function() { return window.templates.postsBlock; },
modelEvents: {}, // Forcefully disable all events modelEvents: {}, // Forcefully disable all events
regions: _.extend({ regions: _.extend({
postsRegion: '.mailpoet_posts_block_posts' postsRegion: '.mailpoet_posts_block_posts'
@@ -216,7 +216,7 @@ define([
}); });
Module.PostsBlockSettingsView = base.BlockSettingsView.extend({ Module.PostsBlockSettingsView = base.BlockSettingsView.extend({
getTemplate: function() { return templates.postsBlockSettings; }, getTemplate: function() { return window.templates.postsBlockSettings; },
regions: { regions: {
selectionRegion: '.mailpoet_settings_posts_selection', selectionRegion: '.mailpoet_settings_posts_selection',
displayOptionsRegion: '.mailpoet_settings_posts_display_options' displayOptionsRegion: '.mailpoet_settings_posts_display_options'
@@ -308,7 +308,7 @@ define([
}); });
var PostSelectionSettingsView = Marionette.View.extend({ var PostSelectionSettingsView = Marionette.View.extend({
getTemplate: function() { return templates.postSelectionPostsBlockSettings; }, getTemplate: function() { return window.templates.postSelectionPostsBlockSettings; },
regions: { regions: {
posts: '.mailpoet_post_selection_container' posts: '.mailpoet_post_selection_container'
}, },
@@ -428,11 +428,11 @@ define([
}); });
var EmptyPostSelectionSettingsView = Marionette.View.extend({ var EmptyPostSelectionSettingsView = Marionette.View.extend({
getTemplate: function() { return templates.emptyPostPostsBlockSettings; } getTemplate: function() { return window.templates.emptyPostPostsBlockSettings; }
}); });
var SinglePostSelectionSettingsView = Marionette.View.extend({ var SinglePostSelectionSettingsView = Marionette.View.extend({
getTemplate: function() { return templates.singlePostPostsBlockSettings; }, getTemplate: function() { return window.templates.singlePostPostsBlockSettings; },
events: function() { events: function() {
return { return {
'change .mailpoet_select_post_checkbox': 'postSelectionChange' 'change .mailpoet_select_post_checkbox': 'postSelectionChange'
@@ -459,7 +459,7 @@ define([
}); });
var PostsDisplayOptionsSettingsView = base.BlockSettingsView.extend({ var PostsDisplayOptionsSettingsView = base.BlockSettingsView.extend({
getTemplate: function() { return templates.displayOptionsPostsBlockSettings; }, getTemplate: function() { return window.templates.displayOptionsPostsBlockSettings; },
events: function() { events: function() {
return { return {
'click .mailpoet_posts_select_button': 'showButtonSettings', 'click .mailpoet_posts_select_button': 'showButtonSettings',
@@ -564,7 +564,7 @@ define([
}); });
Module.PostsWidgetView = base.WidgetView.extend({ Module.PostsWidgetView = base.WidgetView.extend({
getTemplate: function() { return templates.postsInsertion; }, getTemplate: function() { return window.templates.postsInsertion; },
behaviors: { behaviors: {
DraggableBehavior: { DraggableBehavior: {
cloneOriginal: true, cloneOriginal: true,

View File

@@ -85,7 +85,7 @@ define([
var SocialIconView = Marionette.View.extend({ var SocialIconView = Marionette.View.extend({
tagName: 'span', tagName: 'span',
getTemplate: function() { return templates.socialIconBlock; }, getTemplate: function() { return window.templates.socialIconBlock; },
modelEvents: { modelEvents: {
change: 'render' change: 'render'
}, },
@@ -105,7 +105,7 @@ define([
Module.SocialBlockView = base.BlockView.extend({ Module.SocialBlockView = base.BlockView.extend({
className: 'mailpoet_block mailpoet_social_block mailpoet_droppable_block', className: 'mailpoet_block mailpoet_social_block mailpoet_droppable_block',
getTemplate: function() { return templates.socialBlock; }, getTemplate: function() { return window.templates.socialBlock; },
regions: _.extend({}, base.BlockView.prototype.regions, { regions: _.extend({}, base.BlockView.prototype.regions, {
icons: '.mailpoet_social' icons: '.mailpoet_social'
}), }),
@@ -131,7 +131,7 @@ define([
// Sidebar view container // Sidebar view container
Module.SocialBlockSettingsView = base.BlockSettingsView.extend({ Module.SocialBlockSettingsView = base.BlockSettingsView.extend({
getTemplate: function() { return templates.socialBlockSettings; }, getTemplate: function() { return window.templates.socialBlockSettings; },
regions: { regions: {
iconRegion: '#mailpoet_social_icons_selection', iconRegion: '#mailpoet_social_icons_selection',
stylesRegion: '#mailpoet_social_icons_styles' stylesRegion: '#mailpoet_social_icons_styles'
@@ -155,7 +155,7 @@ define([
// Single icon settings view, used by the selector view // Single icon settings view, used by the selector view
SocialBlockSettingsIconView = Marionette.View.extend({ SocialBlockSettingsIconView = Marionette.View.extend({
getTemplate: function() { return templates.socialSettingsIcon; }, getTemplate: function() { return window.templates.socialSettingsIcon; },
events: function() { events: function() {
return { return {
'click .mailpoet_delete_block': 'deleteIcon', 'click .mailpoet_delete_block': 'deleteIcon',
@@ -212,7 +212,7 @@ define([
// Select icons section container view // Select icons section container view
SocialBlockSettingsIconSelectorView = Marionette.View.extend({ SocialBlockSettingsIconSelectorView = Marionette.View.extend({
getTemplate: function() { return templates.socialSettingsIconSelector; }, getTemplate: function() { return window.templates.socialSettingsIconSelector; },
regions: { regions: {
icons: '#mailpoet_social_icon_selector_contents' icons: '#mailpoet_social_icon_selector_contents'
}, },
@@ -235,7 +235,7 @@ define([
}); });
SocialBlockSettingsStylesView = Marionette.View.extend({ SocialBlockSettingsStylesView = Marionette.View.extend({
getTemplate: function() { return templates.socialSettingsStyles; }, getTemplate: function() { return window.templates.socialSettingsStyles; },
modelEvents: { modelEvents: {
change: 'render' change: 'render'
}, },
@@ -263,7 +263,7 @@ define([
}); });
Module.SocialWidgetView = base.WidgetView.extend({ Module.SocialWidgetView = base.WidgetView.extend({
getTemplate: function() { return templates.socialInsertion; }, getTemplate: function() { return window.templates.socialInsertion; },
behaviors: { behaviors: {
DraggableBehavior: { DraggableBehavior: {
cloneOriginal: true, cloneOriginal: true,

View File

@@ -28,7 +28,7 @@ define([
Module.SpacerBlockView = base.BlockView.extend({ Module.SpacerBlockView = base.BlockView.extend({
className: 'mailpoet_block mailpoet_spacer_block mailpoet_droppable_block', className: 'mailpoet_block mailpoet_spacer_block mailpoet_droppable_block',
getTemplate: function() { return templates.spacerBlock; }, getTemplate: function() { return window.templates.spacerBlock; },
behaviors: _.defaults({ behaviors: _.defaults({
ResizableBehavior: { ResizableBehavior: {
elementSelector: '.mailpoet_spacer', elementSelector: '.mailpoet_spacer',
@@ -66,7 +66,7 @@ define([
}); });
Module.SpacerBlockSettingsView = base.BlockSettingsView.extend({ Module.SpacerBlockSettingsView = base.BlockSettingsView.extend({
getTemplate: function() { return templates.spacerBlockSettings; }, getTemplate: function() { return window.templates.spacerBlockSettings; },
events: function() { events: function() {
return { return {
'change .mailpoet_field_spacer_background_color': _.partial(this.changeColorField, 'styles.block.backgroundColor'), 'change .mailpoet_field_spacer_background_color': _.partial(this.changeColorField, 'styles.block.backgroundColor'),
@@ -76,7 +76,7 @@ define([
}); });
Module.SpacerWidgetView = base.WidgetView.extend({ Module.SpacerWidgetView = base.WidgetView.extend({
getTemplate: function() { return templates.spacerInsertion; }, getTemplate: function() { return window.templates.spacerInsertion; },
behaviors: { behaviors: {
DraggableBehavior: { DraggableBehavior: {
cloneOriginal: true, cloneOriginal: true,

View File

@@ -4,8 +4,9 @@
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'newsletter_editor/blocks/base', 'newsletter_editor/blocks/base',
'underscore' 'underscore',
], function(App, BaseBlock, _) { 'mailpoet'
], function(App, BaseBlock, _, MailPoet) {
'use strict'; 'use strict';
@@ -23,7 +24,7 @@ define([
Module.TextBlockView = base.BlockView.extend({ Module.TextBlockView = base.BlockView.extend({
className: 'mailpoet_block mailpoet_text_block mailpoet_droppable_block', className: 'mailpoet_block mailpoet_text_block mailpoet_droppable_block',
getTemplate: function() { return templates.textBlock; }, getTemplate: function() { return window.templates.textBlock; },
modelEvents: _.omit(base.BlockView.prototype.modelEvents, 'change'), // Prevent rerendering on model change due to text editor redrawing modelEvents: _.omit(base.BlockView.prototype.modelEvents, 'change'), // Prevent rerendering on model change due to text editor redrawing
behaviors: _.extend({}, base.BlockView.prototype.behaviors, { behaviors: _.extend({}, base.BlockView.prototype.behaviors, {
TextEditorBehavior: { TextEditorBehavior: {
@@ -78,11 +79,11 @@ define([
}); });
Module.TextBlockSettingsView = base.BlockSettingsView.extend({ Module.TextBlockSettingsView = base.BlockSettingsView.extend({
getTemplate: function() { return templates.textBlockSettings; } getTemplate: function() { return window.templates.textBlockSettings; }
}); });
Module.TextWidgetView = base.WidgetView.extend({ Module.TextWidgetView = base.WidgetView.extend({
getTemplate: function() { return templates.textInsertion; }, getTemplate: function() { return window.templates.textInsertion; },
behaviors: { behaviors: {
DraggableBehavior: { DraggableBehavior: {
cloneOriginal: true, cloneOriginal: true,

View File

@@ -3,15 +3,16 @@ define([
'backbone', 'backbone',
'backbone.marionette', 'backbone.marionette',
'underscore', 'underscore',
'jquery' 'jquery',
], function(App, Backbone, Marionette, _, jQuery) { 'mailpoet'
], function(App, Backbone, Marionette, _, jQuery, MailPoet) {
'use strict'; 'use strict';
var Module = {}; var Module = {};
Module.HeadingView = Marionette.View.extend({ Module.HeadingView = Marionette.View.extend({
getTemplate: function() { return templates.heading; }, getTemplate: function() { return window.templates.heading; },
templateContext: function() { templateContext: function() {
return { return {
model: this.model.toJSON() model: this.model.toJSON()

View File

@@ -8,7 +8,9 @@ define([
'jquery', 'jquery',
'blob', 'blob',
'file-saver', 'file-saver',
'html2canvas' 'html2canvas',
'underscore',
'jquery'
], function( ], function(
App, App,
CommunicationComponent, CommunicationComponent,
@@ -19,8 +21,10 @@ define([
jQuery, jQuery,
Blob, Blob,
FileSaver, FileSaver,
html2canvas html2canvas,
) { _,
$
) {
'use strict'; 'use strict';
@@ -139,7 +143,7 @@ define([
}; };
Module.SaveView = Marionette.View.extend({ Module.SaveView = Marionette.View.extend({
getTemplate: function() { return templates.save; }, getTemplate: function() { return window.templates.save; },
events: { events: {
'click .mailpoet_save_button': 'save', 'click .mailpoet_save_button': 'save',
'click .mailpoet_save_show_options': 'toggleSaveOptions', 'click .mailpoet_save_show_options': 'toggleSaveOptions',

View File

@@ -53,7 +53,7 @@ define([
Module.getLayoutWidgets = function() { return Module._layoutWidgets; }; Module.getLayoutWidgets = function() { return Module._layoutWidgets; };
var SidebarView = Marionette.View.extend({ var SidebarView = Marionette.View.extend({
getTemplate: function() { return templates.sidebar; }, getTemplate: function() { return window.templates.sidebar; },
regions: { regions: {
contentRegion: '.mailpoet_content_region', contentRegion: '.mailpoet_content_region',
layoutRegion: '.mailpoet_layout_region', layoutRegion: '.mailpoet_layout_region',
@@ -147,7 +147,7 @@ define([
* Responsible for rendering draggable content widgets * Responsible for rendering draggable content widgets
*/ */
Module.SidebarWidgetsView = Marionette.View.extend({ Module.SidebarWidgetsView = Marionette.View.extend({
getTemplate: function() { return templates.sidebarContent; }, getTemplate: function() { return window.templates.sidebarContent; },
regions: { regions: {
widgets: '.mailpoet_region_content' widgets: '.mailpoet_region_content'
}, },
@@ -167,14 +167,14 @@ define([
* Responsible for rendering draggable layout widgets * Responsible for rendering draggable layout widgets
*/ */
Module.SidebarLayoutWidgetsView = Module.SidebarWidgetsView.extend({ Module.SidebarLayoutWidgetsView = Module.SidebarWidgetsView.extend({
getTemplate: function() { return templates.sidebarLayout; } getTemplate: function() { return window.templates.sidebarLayout; }
}); });
/** /**
* Responsible for managing global styles * Responsible for managing global styles
*/ */
Module.SidebarStylesView = Marionette.View.extend({ Module.SidebarStylesView = Marionette.View.extend({
getTemplate: function() { return templates.sidebarStyles; }, getTemplate: function() { return window.templates.sidebarStyles; },
behaviors: { behaviors: {
ColorPickerBehavior: {} ColorPickerBehavior: {}
}, },
@@ -238,7 +238,7 @@ define([
}); });
Module.SidebarPreviewView = Marionette.View.extend({ Module.SidebarPreviewView = Marionette.View.extend({
getTemplate: function() { return templates.sidebarPreview; }, getTemplate: function() { return window.templates.sidebarPreview; },
events: { events: {
'click .mailpoet_show_preview': 'showPreview', 'click .mailpoet_show_preview': 'showPreview',
'click #mailpoet_send_preview': 'sendPreview' 'click #mailpoet_send_preview': 'sendPreview'
@@ -346,7 +346,7 @@ define([
}); });
Module.NewsletterPreviewView = Marionette.View.extend({ Module.NewsletterPreviewView = Marionette.View.extend({
getTemplate: function() { return templates.newsletterPreview; }, getTemplate: function() { return window.templates.newsletterPreview; },
initialize: function(options) { initialize: function(options) {
this.previewUrl = options.previewUrl; this.previewUrl = options.previewUrl;
this.width = '100%'; this.width = '100%';

View File

@@ -1,8 +1,9 @@
define([ define([
'newsletter_editor/App', 'newsletter_editor/App',
'backbone.marionette', 'backbone.marionette',
'backbone.supermodel' 'backbone.supermodel',
], function(App, Marionette, SuperModel) { 'underscore'
], function(App, Marionette, SuperModel, _) {
'use strict'; 'use strict';
@@ -47,7 +48,7 @@ define([
}); });
Module.StylesView = Marionette.View.extend({ Module.StylesView = Marionette.View.extend({
getTemplate: function() { return templates.styles; }, getTemplate: function() { return window.templates.styles; },
modelEvents: { modelEvents: {
change: 'render' change: 'render'
}, },

View File

@@ -1,27 +0,0 @@
/**
* A sample implementation of template widgets.
* A draggable widget, on drop creates a container with (image|text) block.
*/
ImageAndTextTemplateWidgetView = EditorApplication.module('blocks.base').WidgetView.extend({
getTemplate: function() { return templates.imageAndTextInsertion; },
className: 'mailpoet_droppable_block mailpoet_droppable_widget',
behaviors: {
DraggableBehavior: {
drop: function() {
return new (EditorApplication.getBlockTypeModel('container'))({
type: 'container',
orientation: 'horizontal',
blocks: [
{
type: 'image'
},
{
type: 'text',
text: 'Some random text'
}
]
}, {parse: true});
}
}
}
});

View File

@@ -33,13 +33,13 @@ function(
form.parsley().on('form:submit', function(parsley) { form.parsley().on('form:submit', function(parsley) {
var form_data = form.serializeObject() || {}; var form_data = form.serializeObject() || {};
// check if we're on the same domain // check if we're on the same domain
if(isSameDomain(MailPoetForm.ajax_url) === false) { if(isSameDomain(window.MailPoetForm.ajax_url) === false) {
// non ajax post request // non ajax post request
return true; return true;
} else { } else {
// ajax request // ajax request
MailPoet.Ajax.post({ MailPoet.Ajax.post({
url: MailPoetForm.ajax_url, url: window.MailPoetForm.ajax_url,
token: form_data.token, token: form_data.token,
api_version: form_data.api_version, api_version: form_data.api_version,
endpoint: 'subscribers', endpoint: 'subscribers',

View File

@@ -17,14 +17,14 @@ define(
return; return;
} }
jQuery(document).ready(function () { jQuery(document).ready(function () {
if (!exportData.segments) { if (!window.exportData.segments) {
return; return;
} }
var subscribers_export_template = var subscribers_export_template =
Handlebars.compile(jQuery('#mailpoet_subscribers_export_template').html()); Handlebars.compile(jQuery('#mailpoet_subscribers_export_template').html());
//render template //render template
jQuery('#mailpoet_subscribers_export > div.inside').html(subscribers_export_template(exportData)); jQuery('#mailpoet_subscribers_export > div.inside').html(subscribers_export_template(window.exportData));
// define reusable variables // define reusable variables
var segmentsContainerElement = jQuery('#export_lists'), var segmentsContainerElement = jQuery('#export_lists'),
@@ -77,9 +77,9 @@ define(
} }
}) })
.on('change', function () { .on('change', function () {
if ((exportData.segments && segmentsContainerElement.select2('data').length && subscriberFieldsContainerElement.select2('data').length) if ((window.exportData.segments && segmentsContainerElement.select2('data').length && subscriberFieldsContainerElement.select2('data').length)
|| ||
(!exportData.segments && subscriberFieldsContainerElement.select2('data').length) (!window.exportData.segments && subscriberFieldsContainerElement.select2('data').length)
) { ) {
toggleNextStepButton('on'); toggleNextStepButton('on');
} }
@@ -87,20 +87,20 @@ define(
toggleNextStepButton('off'); toggleNextStepButton('off');
} }
if (segmentsContainerElement.select2('data').length > 1 && exportData.groupBySegmentOption) { if (segmentsContainerElement.select2('data').length > 1 && window.exportData.groupBySegmentOption) {
jQuery('.mailpoet_group_by_list').show(); jQuery('.mailpoet_group_by_list').show();
} }
else if (exportData.groupBySegmentOption) { else if (window.exportData.groupBySegmentOption) {
jQuery('.mailpoet_group_by_list').hide(); jQuery('.mailpoet_group_by_list').hide();
} }
}); });
}; };
// set confirmed subscribers export option to false // set confirmed subscribers export option to false
exportData.exportConfirmedOption = false; window.exportData.exportConfirmedOption = false;
renderSegmentsAndFields(subscriberFieldsContainerElement, subscriberFieldsSelect2); renderSegmentsAndFields(subscriberFieldsContainerElement, window.subscriberFieldsSelect2);
renderSegmentsAndFields(segmentsContainerElement, segments); renderSegmentsAndFields(segmentsContainerElement, window.segments);
subscriberFieldsContainerElement.val([ subscriberFieldsContainerElement.val([
'email', 'email',
@@ -112,12 +112,12 @@ define(
exportConfirmedOptionElement.change(function () { exportConfirmedOptionElement.change(function () {
var selectedSegments = segmentsContainerElement.val(); var selectedSegments = segmentsContainerElement.val();
if (this.value == 1) { if (this.value == 1) {
exportData.exportConfirmedOption = true; window.exportData.exportConfirmedOption = true;
renderSegmentsAndFields(segmentsContainerElement, segmentsWithConfirmedSubscribers); renderSegmentsAndFields(segmentsContainerElement, window.segmentsWithConfirmedSubscribers);
} }
else { else {
exportData.exportConfirmedOption = false; window.exportData.exportConfirmedOption = false;
renderSegmentsAndFields(segmentsContainerElement, segments); renderSegmentsAndFields(segmentsContainerElement, window.segments);
} }
segmentsContainerElement.val(selectedSegments).trigger('change'); segmentsContainerElement.val(selectedSegments).trigger('change');
}); });
@@ -143,24 +143,24 @@ define(
endpoint: 'ImportExport', endpoint: 'ImportExport',
action: 'processExport', action: 'processExport',
data: JSON.stringify({ data: JSON.stringify({
export_confirmed_option: exportData.exportConfirmedOption, export_confirmed_option: window.exportData.exportConfirmedOption,
export_format_option: exportFormat, export_format_option: exportFormat,
group_by_segment_option: (groupBySegmentOptionElement.is(':visible')) ? groupBySegmentOptionElement.prop('checked') : false, group_by_segment_option: (groupBySegmentOptionElement.is(':visible')) ? groupBySegmentOptionElement.prop('checked') : false,
segments: (exportData.segments) ? segmentsContainerElement.val() : false, segments: (window.exportData.segments) ? segmentsContainerElement.val() : false,
subscriber_fields: subscriberFieldsContainerElement.val() subscriber_fields: subscriberFieldsContainerElement.val()
}) })
}).always(function(response) { }).always(function(response) {
MailPoet.Modal.loading(false); MailPoet.Modal.loading(false);
}).done(function(response) { }).done(function(response) {
resultMessage = MailPoet.I18n.t('exportMessage') var resultMessage = MailPoet.I18n.t('exportMessage')
.replace('%1$s', '<strong>' + parseInt(response.data.totalExported).toLocaleString() + '</strong>') .replace('%1$s', '<strong>' + parseInt(response.data.totalExported).toLocaleString() + '</strong>')
.replace('[link]', '<a href="' + response.data.exportFileURL + '" target="_blank" >') .replace('[link]', '<a href="' + response.data.exportFileURL + '" target="_blank" >')
.replace('[/link]', '</a>'); .replace('[/link]', '</a>');
jQuery('#export_result_notice').html('<p>' + resultMessage + '</p>').show(); jQuery('#export_result_notice').html('<p>' + resultMessage + '</p>').show();
window.location.href = response.data.exportFileURL; window.location.href = response.data.exportFileURL;
MailPoet.trackEvent('Subscribers export completed', { MailPoet.trackEvent('Subscribers export completed', {
'Total exported': response.data.totalExported, 'Total exported': response.data.totalExported,
'Only confirmed?': exportData.exportConfirmedOption, 'Only confirmed?': window.exportData.exportConfirmedOption,
'File Format': exportFormat, 'File Format': exportFormat,
'MailPoet Free version': window.mailpoet_version 'MailPoet Free version': window.mailpoet_version
}); });

View File

@@ -27,7 +27,7 @@ define(
jQuery(document).ready(function () { jQuery(document).ready(function () {
jQuery('input[name="select_method"]').attr('checked', false); jQuery('input[name="select_method"]').attr('checked', false);
// configure router // configure router
router = new (Backbone.Router.extend({ var router = new (Backbone.Router.extend({
routes: { routes: {
'': 'home', '': 'home',
step1: 'step1', step1: 'step1',
@@ -51,13 +51,13 @@ define(
*/ */
router.on('route:step1', function () { router.on('route:step1', function () {
// set or reset temporary validation rule on all columns // set or reset temporary validation rule on all columns
mailpoetColumns = jQuery.map(mailpoetColumns, function (column, columnIndex) { window.mailpoetColumns = jQuery.map(window.mailpoetColumns, function (column, columnIndex) {
var col = column; var col = column;
col.validation_rule = false; col.validation_rule = false;
return col; return col;
}); });
if (typeof (importData.step1) !== 'undefined') { if (typeof (window.importData.step1) !== 'undefined') {
showCurrentStep(); showCurrentStep();
return; return;
} }
@@ -134,7 +134,7 @@ define(
MailPoet.Notice.hide(); MailPoet.Notice.hide();
// get an approximate size of textarea paste in bytes // get an approximate size of textarea paste in bytes
var pasteSize = encodeURI(pasteInputElement.val()).split(/%..|./).length - 1; var pasteSize = encodeURI(pasteInputElement.val()).split(/%..|./).length - 1;
if (pasteSize > maxPostSizeBytes) { if (pasteSize > window.maxPostSizeBytes) {
MailPoet.Notice.error(MailPoet.I18n.t('maxPostSizeNotice')); MailPoet.Notice.error(MailPoet.I18n.t('maxPostSizeNotice'));
return; return;
} }
@@ -237,7 +237,7 @@ define(
}).always(function(response) { }).always(function(response) {
MailPoet.Modal.loading(false); MailPoet.Modal.loading(false);
}).done(function(response) { }).done(function(response) {
importData.step1 = response.data; window.importData.step1 = response.data;
MailPoet.trackEvent('Subscribers import started', { MailPoet.trackEvent('Subscribers import started', {
source: 'MailChimp', source: 'MailChimp',
'MailPoet Free version': window.mailpoet_version 'MailPoet Free version': window.mailpoet_version
@@ -368,7 +368,7 @@ define(
for (var column in rowData) { for (var column in rowData) {
var email = detectAndCleanupEmail(rowData[column]); var email = detectAndCleanupEmail(rowData[column]);
if (emailColumnPosition === null if (emailColumnPosition === null
&& emailRegex.test(email)) { && window.emailRegex.test(email)) {
emailColumnPosition = column; emailColumnPosition = column;
parsedEmails[email] = true; // add current e-mail to an object index parsedEmails[email] = true; // add current e-mail to an object index
rowData[column] = email; rowData[column] = email;
@@ -387,7 +387,7 @@ define(
if (_.has(parsedEmails, email)) { if (_.has(parsedEmails, email)) {
duplicateEmails.push(email); duplicateEmails.push(email);
} }
else if (!emailRegex.test(email)) { else if (!window.emailRegex.test(email)) {
invalidEmails.push(rowData[emailColumnPosition]); invalidEmails.push(rowData[emailColumnPosition]);
} }
// if we haven't yet processed this e-mail and it passed // if we haven't yet processed this e-mail and it passed
@@ -410,8 +410,8 @@ define(
) { ) {
// since we assume that the header line is always present, we need // since we assume that the header line is always present, we need
// to detect the header by checking if it contains a valid e-mail address // to detect the header by checking if it contains a valid e-mail address
importData.step1 = { window.importData.step1 = {
header: (!emailRegex.test( header: (!window.emailRegex.test(
processedSubscribers[0][emailColumnPosition]) processedSubscribers[0][emailColumnPosition])
) ? processedSubscribers.shift() : null, ) ? processedSubscribers.shift() : null,
subscribers: processedSubscribers, subscribers: processedSubscribers,
@@ -438,7 +438,7 @@ define(
}); });
router.on('route:step2', function () { router.on('route:step2', function () {
if (typeof (importData.step1) === 'undefined') { if (typeof (window.importData.step1) === 'undefined') {
router.navigate('step1', {trigger: true}); router.navigate('step1', {trigger: true});
return; return;
} }
@@ -446,7 +446,7 @@ define(
var nextStepButton = jQuery('#step2_process'), var nextStepButton = jQuery('#step2_process'),
previousStepButton = jQuery('#return_to_step1'), previousStepButton = jQuery('#return_to_step1'),
// create a copy of subscribers object for further manipulation // create a copy of subscribers object for further manipulation
subscribers = jQuery.extend(true, {}, importData.step1), subscribers = jQuery.extend(true, {}, window.importData.step1),
subscribersDataTemplate = subscribersDataTemplate =
Handlebars Handlebars
.compile(jQuery('#subscribers_data_template') .compile(jQuery('#subscribers_data_template')
@@ -526,7 +526,7 @@ define(
}); });
// show available segments // show available segments
if (mailpoetSegments.length) { if (window.mailpoetSegments.length) {
jQuery('.mailpoet_segments').show(); jQuery('.mailpoet_segments').show();
} }
else { else {
@@ -599,7 +599,7 @@ define(
description: segmentDescription description: segmentDescription
} }
}).done(function(response) { }).done(function(response) {
mailpoetSegments.push({ window.mailpoetSegments.push({
id: response.data.id, id: response.data.id,
name: response.data.name, name: response.data.name,
subscriberCount: 0 subscriberCount: 0
@@ -612,7 +612,7 @@ define(
selected_values.push(response.data.id); selected_values.push(response.data.id);
} }
enableSegmentSelection(mailpoetSegments); enableSegmentSelection(window.mailpoetSegments);
segmentSelectElement.val(selected_values).trigger('change'); segmentSelectElement.val(selected_values).trigger('change');
jQuery('.mailpoet_segments:hidden').show(); jQuery('.mailpoet_segments:hidden').show();
jQuery('.mailpoet_no_segments:visible').hide(); jQuery('.mailpoet_no_segments:visible').hide();
@@ -649,16 +649,16 @@ define(
var columnData = subscribers.subscribers[0][i], var columnData = subscribers.subscribers[0][i],
columnId = 'ignore'; // set default column type columnId = 'ignore'; // set default column type
// if the column is not undefined and has a valid e-mail, set type as email // if the column is not undefined and has a valid e-mail, set type as email
if (columnData % 1 !== 0 && emailRegex.test(columnData)) { if (columnData % 1 !== 0 && window.emailRegex.test(columnData)) {
columnId = 'email'; columnId = 'email';
} else if (subscribers.header) { } else if (subscribers.header) {
var headerName = subscribers.header[i], var headerName = subscribers.header[i],
headerNameMatch = mailpoetColumns.map(function (el) { headerNameMatch = window.mailpoetColumns.map(function (el) {
return el.name; return el.name;
}).indexOf(headerName); }).indexOf(headerName);
// set column type using header // set column type using header
if (headerNameMatch !== -1) { if (headerNameMatch !== -1) {
columnId = mailpoetColumns[headerNameMatch].id; columnId = window.mailpoetColumns[headerNameMatch].id;
}// set column type using header name }// set column type using header name
else if (headerName) { else if (headerName) {
if (/first|first name|given name/i.test(headerName)) { if (/first|first name|given name/i.test(headerName)) {
@@ -723,7 +723,7 @@ define(
// filter displayed data // filter displayed data
jQuery('select.mailpoet_subscribers_column_data_match') jQuery('select.mailpoet_subscribers_column_data_match')
.select2({ .select2({
data: mailpoetColumnsSelect2, data: window.mailpoetColumnsSelect2,
width: '15em', width: '15em',
templateResult: function (item) { templateResult: function (item) {
return item.name; return item.name;
@@ -762,21 +762,21 @@ define(
custom: true custom: true
}; };
// if this is the first custom column, create an "optgroup" // if this is the first custom column, create an "optgroup"
if (mailpoetColumnsSelect2.length === 2) { if (window.mailpoetColumnsSelect2.length === 2) {
mailpoetColumnsSelect2.push({ window.mailpoetColumnsSelect2.push({
name: MailPoet.I18n.t('userColumns'), name: MailPoet.I18n.t('userColumns'),
children: [] children: []
}); });
} }
mailpoetColumnsSelect2[2].children.push(new_column_data); window.mailpoetColumnsSelect2[2].children.push(new_column_data);
mailpoetColumns.push(new_column_data); window.mailpoetColumns.push(new_column_data);
jQuery('select.mailpoet_subscribers_column_data_match') jQuery('select.mailpoet_subscribers_column_data_match')
.each(function () { .each(function () {
jQuery(this) jQuery(this)
.html('') .html('')
.select2('destroy') .select2('destroy')
.select2({ .select2({
data: mailpoetColumnsSelect2, data: window.mailpoetColumnsSelect2,
width: '15em', width: '15em',
templateResult: function (item) { templateResult: function (item) {
return item.name; return item.name;
@@ -845,14 +845,14 @@ define(
return { id: columnId, index: elementIndex, validationRule: validationRule, element: element }; return { id: columnId, index: elementIndex, validationRule: validationRule, element: element };
}); });
// iterate through the object of mailpoet columns // iterate through the object of mailpoet columns
jQuery.map(mailpoetColumns, function (column, columnIndex) { jQuery.map(window.mailpoetColumns, function (column, columnIndex) {
// check if the column id matches the selected id of one of the // check if the column id matches the selected id of one of the
// subscriber's data columns // subscriber's data columns
var matchedColumn = _.find(displayedColumns, function(data) { return data.id === column.id; }); var matchedColumn = _.find(displayedColumns, function(data) { return data.id === column.id; });
// EMAIL filter: if the first value in the column doesn't have a valid // EMAIL filter: if the first value in the column doesn't have a valid
// email, hide the next button // email, hide the next button
if (column.id === 'email') { if (column.id === 'email') {
if (!emailRegex.test(subscribersClone.subscribers[0][matchedColumn.index])) { if (!window.emailRegex.test(subscribersClone.subscribers[0][matchedColumn.index])) {
preventNextStep = true; preventNextStep = true;
if (!jQuery('[data-id="notice_invalidEmail"]').length) { if (!jQuery('[data-id="notice_invalidEmail"]').length) {
MailPoet.Notice.error(MailPoet.I18n.t('columnContainsInvalidElement'), { MailPoet.Notice.error(MailPoet.I18n.t('columnContainsInvalidElement'), {
@@ -996,7 +996,7 @@ define(
return res; return res;
}, []); }, []);
}, },
subscribers = splitSubscribers(importData.step1.subscribers, batchSize); subscribers = splitSubscribers(window.importData.step1.subscribers, batchSize);
_.each(jQuery('select.mailpoet_subscribers_column_data_match'), _.each(jQuery('select.mailpoet_subscribers_column_data_match'),
function (column, columnIndex) { function (column, columnIndex) {
@@ -1050,37 +1050,37 @@ define(
); );
} }
else { else {
mailpoetSegments = importResults.segments; window.mailpoetSegments = importResults.segments;
importResults.segments = _.map(segmentSelectElement.select2('data'), importResults.segments = _.map(segmentSelectElement.select2('data'),
function (data) { function (data) {
return data.name; return data.name;
}); });
importData.step2 = importResults; window.importData.step2 = importResults;
enableSegmentSelection(mailpoetSegments); enableSegmentSelection(window.mailpoetSegments);
router.navigate('step3', {trigger: true}); router.navigate('step3', {trigger: true});
} }
}); });
}); });
filterSubscribers(); filterSubscribers();
enableSegmentSelection(mailpoetSegments); enableSegmentSelection(window.mailpoetSegments);
}); });
router.on('route:step3', function () { router.on('route:step3', function () {
if (typeof (importData.step2) === 'undefined') { if (typeof (window.importData.step2) === 'undefined') {
router.navigate('step2', {trigger: true}); router.navigate('step2', {trigger: true});
return; return;
} }
showCurrentStep(); showCurrentStep();
if (importData.step2.errors.length > 0) { if (window.importData.step2.errors.length > 0) {
MailPoet.Notice.error(_.flatten(importData.step2.errors)); MailPoet.Notice.error(_.flatten(window.importData.step2.errors));
} }
MailPoet.trackEvent('Subscribers import finished', { MailPoet.trackEvent('Subscribers import finished', {
'Subscribers created': importData.step2.created, 'Subscribers created': window.importData.step2.created,
'Subscribers updated': importData.step2.updated, 'Subscribers updated': window.importData.step2.updated,
'MailPoet Free version': window.mailpoet_version 'MailPoet Free version': window.mailpoet_version
}); });
@@ -1091,18 +1091,18 @@ define(
.html()), .html()),
exportMenuElement = jQuery('span.mailpoet_export'), exportMenuElement = jQuery('span.mailpoet_export'),
importResults = { importResults = {
created: (importData.step2.created) created: (window.importData.step2.created)
? MailPoet.I18n.t('subscribersCreated') ? MailPoet.I18n.t('subscribersCreated')
.replace('%1$s', '<strong>' + importData.step2.created.toLocaleString() + '</strong>') .replace('%1$s', '<strong>' + window.importData.step2.created.toLocaleString() + '</strong>')
.replace('%2$s', '"' + importData.step2.segments.join('", "') + '"') .replace('%2$s', '"' + window.importData.step2.segments.join('", "') + '"')
: false, : false,
updated: (importData.step2.updated) updated: (window.importData.step2.updated)
? MailPoet.I18n.t('subscribersUpdated') ? MailPoet.I18n.t('subscribersUpdated')
.replace('%1$s', '<strong>' + importData.step2.updated.toLocaleString() + '</strong>') .replace('%1$s', '<strong>' + window.importData.step2.updated.toLocaleString() + '</strong>')
.replace('%2$s', '"' + importData.step2.segments.join('", "') + '"') .replace('%2$s', '"' + window.importData.step2.segments.join('", "') + '"')
: false, : false,
no_action: (!importData.step2.created && !importData.step2.updated), no_action: (!window.importData.step2.created && !window.importData.step2.updated),
added_to_segment_with_welcome_notification: importData.step2.added_to_segment_with_welcome_notification added_to_segment_with_welcome_notification: window.importData.step2.added_to_segment_with_welcome_notification
}; };
jQuery('#subscribers_data_import_results') jQuery('#subscribers_data_import_results')
@@ -1125,7 +1125,7 @@ define(
} }
// reset previous step's data so that coming back to this step is prevented // reset previous step's data so that coming back to this step is prevented
importData.step2 = undefined; window.importData.step2 = undefined;
}); });
if (!Backbone.History.started) { if (!Backbone.History.started) {

View File

@@ -232,3 +232,4 @@ global.templates = {
textInsertion: Handlebars.compile(jQuery('#newsletter_editor_template_text_widget').html()), textInsertion: Handlebars.compile(jQuery('#newsletter_editor_template_text_widget').html()),
textBlockSettings: Handlebars.compile(jQuery('#newsletter_editor_template_text_settings').html()) textBlockSettings: Handlebars.compile(jQuery('#newsletter_editor_template_text_settings').html())
}; };
global.window.templates = global.templates;