ES5 space-before-function-parens

This commit is contained in:
Amine Ben hammou
2017-09-21 08:35:12 +00:00
parent bf1d76a3a7
commit 680446b77e
52 changed files with 871 additions and 872 deletions

View File

@ -9,7 +9,6 @@
},
"rules": {
"import/no-amd": 0,
"space-before-function-paren": 0,
"prefer-arrow-callback": 0,
"key-spacing": 0,
"radix": 0,

View File

@ -1,10 +1,10 @@
define('admin', [
'jquery'
],
function(jQuery) {
jQuery(function($) {
function (jQuery) {
jQuery(function ($) {
// dom ready
$(function() {
$(function () {
});
});

View File

@ -12,7 +12,7 @@ function requestFailed(errorMessage, xhr) {
};
}
define('ajax', ['mailpoet', 'jquery', 'underscore'], function(mp, jQuery, _) {
define('ajax', ['mailpoet', 'jquery', 'underscore'], function (mp, jQuery, _) {
var MailPoet = mp;
MailPoet.Ajax = {
@ -26,10 +26,10 @@ define('ajax', ['mailpoet', 'jquery', 'underscore'], function(mp, jQuery, _) {
token: null,
data: {}
},
post: function(options) {
post: function (options) {
return this.request('post', options);
},
init: function(options) {
init: function (options) {
// merge options
this.options = jQuery.extend({}, this.defaults, options);
@ -43,7 +43,7 @@ define('ajax', ['mailpoet', 'jquery', 'underscore'], function(mp, jQuery, _) {
this.options.token = window.mailpoet_token;
}
},
getParams: function() {
getParams: function () {
return {
action: 'mailpoet',
api_version: this.options.api_version,
@ -53,7 +53,7 @@ define('ajax', ['mailpoet', 'jquery', 'underscore'], function(mp, jQuery, _) {
data: this.options.data || {}
};
},
request: function(method, options) {
request: function (method, options) {
// set options
this.init(options);
@ -62,7 +62,7 @@ define('ajax', ['mailpoet', 'jquery', 'underscore'], function(mp, jQuery, _) {
// remove null values from the data object
if (_.isObject(params.data)) {
params.data = _.pick(params.data, function(value) {
params.data = _.pick(params.data, function (value) {
return (value !== null);
});
}
@ -73,7 +73,7 @@ define('ajax', ['mailpoet', 'jquery', 'underscore'], function(mp, jQuery, _) {
params,
null,
'json'
).then(function(data) {
).then(function (data) {
return data;
}, _.partial(requestFailed, MailPoet.I18n.t('ajaxFailedErrorMessage')));

View File

@ -53,7 +53,7 @@ function cacheEvent(forced, name, data) {
define(
['mailpoet', 'underscore'],
function(mp, _) {
function (mp, _) {
var MailPoet = mp;
function initializeMixpanelWhenLoaded() {

View File

@ -3,7 +3,7 @@ define('date',
'mailpoet',
'jquery',
'moment'
], function(
], function (
mp,
jQuery,
Moment
@ -41,7 +41,7 @@ define('date',
return this;
},
format: function(date, opts) {
format: function (date, opts) {
var options = opts || {};
this.init(options);
@ -49,28 +49,28 @@ define('date',
if (options.offset === 0) momentDate = momentDate.utc();
return momentDate.format(this.convertFormat(this.options.format));
},
toDate: function(date, opts) {
toDate: function (date, opts) {
var options = opts || {};
this.init(options);
return Moment(date, this.convertFormat(options.parseFormat)).toDate();
},
short: function(date) {
short: function (date) {
return this.format(date, {
format: 'F, j Y'
});
},
full: function(date) {
full: function (date) {
return this.format(date, {
format: 'F, j Y H:i:s'
});
},
time: function(date) {
time: function (date) {
return this.format(date, {
format: 'H:i:s'
});
},
convertFormat: function(format) {
convertFormat: function (format) {
var format_mappings = {
date: {
d: 'DD',

View File

@ -8,7 +8,7 @@
'use strict';
Event.cacheDelegated = {};
Object.extend(document, (function() {
Object.extend(document, (function () {
var cache = Event.cacheDelegated;
function getCacheForSelector(selector) {
@ -24,7 +24,7 @@ Object.extend(document, (function() {
function findWrapper(selector, eventName, handler) {
var c = getWrappersForSelector(selector, eventName);
return c.find(function(wrapper) {
return c.find(function (wrapper) {
return wrapper.handler === handler;
});
}
@ -40,7 +40,7 @@ Object.extend(document, (function() {
function createWrapper(selector, eventName, handler, context) {
var wrapper, c = getWrappersForSelector(selector, eventName);
if(c.pluck('handler').include(handler)) return false;
wrapper = function(event) {
wrapper = function (event) {
var element = event.findElement(selector);
if(element) handler.call(context || element, event, element);
};
@ -49,26 +49,26 @@ Object.extend(document, (function() {
return wrapper;
}
return {
delegate: function(selector, eventName, handler, context) {
delegate: function (selector, eventName, handler, context) {
var wrapper = createWrapper.apply(null, arguments);
if(wrapper) document.observe(eventName, wrapper);
return document;
},
stopDelegating: function(selector, eventName, handler) {
stopDelegating: function (selector, eventName, handler) {
var length = arguments.length;
switch(length) {
case 2:
getWrappersForSelector(selector, eventName).each(function(wrapper) {
getWrappersForSelector(selector, eventName).each(function (wrapper) {
document.stopDelegating(selector, eventName, wrapper.handler);
});
break;
case 1:
Object.keys(getCacheForSelector(selector)).each(function(eventName) {
Object.keys(getCacheForSelector(selector)).each(function (eventName) {
document.stopDelegating(selector, eventName);
});
break;
case 0:
Object.keys(cache).each(function(selector) {
Object.keys(cache).each(function (selector) {
document.stopDelegating(selector);
});
break;
@ -81,7 +81,7 @@ Object.extend(document, (function() {
};
})());
var Observable = (function() {
var Observable = (function () {
function getEventName(nameA, namespace) {
var name = nameA.substring(2);
if(namespace) name = namespace + ':' + name;
@ -91,7 +91,7 @@ var Observable = (function() {
function getHandlers(klass) {
var proto = klass.prototype,
namespace = proto.namespace;
return Object.keys(proto).grep(/^on/).inject(window.$H(), function(handlers, name) {
return Object.keys(proto).grep(/^on/).inject(window.$H(), function (handlers, name) {
if(name === 'onDomLoaded') return handlers;
handlers.set(getEventName(name, namespace), getWrapper(proto[name], klass));
return handlers;
@ -99,18 +99,18 @@ var Observable = (function() {
}
function getWrapper(handler, klass) {
return function(event) {
return function (event) {
return handler.call(new klass(this), event, event.memo);
};
}
function onDomLoad(selector, klass) {
window.$$(selector).each(function(element) {
window.$$(selector).each(function (element) {
new klass(element).onDomLoaded();
});
}
return {
observe: function(selector) {
observe: function (selector) {
if(!this.handlers) this.handlers = {};
if(this.handlers[selector]) return;
var klass = this;
@ -121,13 +121,13 @@ var Observable = (function() {
document.observe('dom:loaded', onDomLoad.curry(selector, klass));
}
}
this.handlers[selector] = getHandlers(klass).each(function(handler) {
this.handlers[selector] = getHandlers(klass).each(function (handler) {
document.delegate(selector, handler.key, handler.value);
});
},
stopObserving: function(selector) {
stopObserving: function (selector) {
if(!this.handlers || !this.handlers[selector]) return;
this.handlers[selector].each(function(handler) {
this.handlers[selector].each(function (handler) {
document.stopDelegating(selector, handler.key, handler.value);
});
delete this.handlers[selector];
@ -137,18 +137,18 @@ var Observable = (function() {
// override droppables
Object.extend(window.Droppables, {
deactivate: window.Droppables.deactivate.wrap(function(proceed, drop, draggable) {
deactivate: window.Droppables.deactivate.wrap(function (proceed, drop, draggable) {
if(drop.onLeave) drop.onLeave(draggable, drop.element);
return proceed(drop);
}),
activate: window.Droppables.activate.wrap(function(proceed, drop, draggable) {
activate: window.Droppables.activate.wrap(function (proceed, drop, draggable) {
if(drop.onEnter) drop.onEnter(draggable, drop.element);
return proceed(drop);
}),
show: function(point, element) {
show: function (point, element) {
if(!this.drops.length) return;
var drop, affected = [];
this.drops.each(function(drop) {
this.drops.each(function (drop) {
if(window.Droppables.isAffected(point, element, drop)) affected.push(drop);
});
if(affected.length > 0) drop = window.Droppables.findDeepestChild(affected);
@ -159,21 +159,21 @@ Object.extend(window.Droppables, {
if(drop !== this.last_active) window.Droppables.activate(drop, element);
}
},
displayArea: function(draggable) {
displayArea: function (draggable) {
if(!this.drops.length) return;
// hide controls when displaying drop areas.
WysijaForm.hideBlockControls();
this.drops.each(function(drop, iterator) {
this.drops.each(function (drop, iterator) {
if(drop.element.hasClassName('block_placeholder')) {
drop.element.addClassName('active');
}
});
},
hideArea: function() {
hideArea: function () {
if(!this.drops.length) return;
this.drops.each(function(drop, iterator) {
this.drops.each(function (drop, iterator) {
if(drop.element.hasClassName('block_placeholder')) {
drop.element.removeClassName('active');
} else if(drop.element.hasClassName('image_placeholder')) {
@ -184,7 +184,7 @@ Object.extend(window.Droppables, {
}
});
},
reset: function(draggable) {
reset: function (draggable) {
if(this.last_active) this.deactivate(this.last_active, draggable);
}
});
@ -198,7 +198,7 @@ Object.extend(window.Droppables, {
var WysijaHistory = {
container: 'mailpoet_form_history',
size: 30,
enqueue: function(element) {
enqueue: function (element) {
// create deep clone (includes child elements) of passed element
var clone = element.clone(true);
@ -219,7 +219,7 @@ var WysijaHistory = {
top: clone
});
},
dequeue: function() {
dequeue: function () {
// pop last block off the history
var block = window.$(WysijaHistory.container).select('div').first();
@ -230,10 +230,10 @@ var WysijaHistory = {
});
}
},
clear: function() {
clear: function () {
window.$(WysijaHistory.container).innerHTML = '';
},
remove: function(field) {
remove: function (field) {
window.$(WysijaHistory.container).select('[wysija_name="' + field + '"]').invoke('remove');
}
};
@ -268,15 +268,15 @@ var WysijaForm = {
selectingColor: false,
showingTools: false
},
encodeHtmlValue: function(str) {
encodeHtmlValue: function (str) {
return str.replace(/&/g, '&amp;').replace(/>/g, '&gt;').replace(/</g, '&lt;').replace(/"/g, '&quot;');
// ": fix for FileMerge because the previous line fucks up its syntax coloring
},
decodeHtmlValue: function(str) {
decodeHtmlValue: function (str) {
return str.replace(/&amp;/g, '&').replace(/&gt;/g, '>').replace(/&lt;/g, '<').replace(/&quot;/g, '"');
// ": fix for FileMerge because the previous line fucks up its syntax coloring
},
loading: function(is_loading) {
loading: function (is_loading) {
if(is_loading) {
window.$(WysijaForm.options.editor).addClassName('loading');
window.$(WysijaForm.options.toolbar).addClassName('loading');
@ -285,25 +285,25 @@ var WysijaForm = {
window.$(WysijaForm.options.toolbar).removeClassName('loading');
}
},
loadStatic: function(blocks) {
window.$A(blocks).each(function(block) {
loadStatic: function (blocks) {
window.$A(blocks).each(function (block) {
// create block
WysijaForm.Block.create(block, window.$('block_placeholder'));
});
},
load: function(data) {
load: function (data) {
if(data === undefined) return;
// load body
if(data.body !== undefined) {
window.$A(data.body).each(function(block) {
window.$A(data.body).each(function (block) {
// create block
WysijaForm.Block.create(block, window.$('block_placeholder'));
});
// load settings
var settings_elements = window.$('mailpoet_form_settings').getElements();
settings_elements.each(function(setting) {
settings_elements.each(function (setting) {
// skip lists
if(setting.name === 'segments') {
return true;
@ -323,7 +323,7 @@ var WysijaForm = {
});
}
},
save: function() {
save: function () {
var position = 1,
data = {
name: window.$F('mailpoet_form_name'),
@ -332,7 +332,7 @@ var WysijaForm = {
styles: (window.MailPoet.CodeEditor !== undefined) ? window.MailPoet.CodeEditor.getValue() : null
};
// body
WysijaForm.getBlocks().each(function(b) {
WysijaForm.getBlocks().each(function (b) {
var block_data = (typeof(b.block['save']) === 'function') ? b.block.save() : null;
if(block_data !== null) {
@ -349,7 +349,7 @@ var WysijaForm = {
return data;
},
init: function() {
init: function () {
// set document scroll
info('init -> set scroll offsets');
WysijaForm.setScrollOffsets();
@ -382,7 +382,7 @@ var WysijaForm = {
info('init -> toggle widgets');
WysijaForm.toggleWidgets();
},
getFieldData: function(element) {
getFieldData: function (element) {
// get basic field data
var data = {
type: element.readAttribute('wysija_type'),
@ -400,11 +400,11 @@ var WysijaForm = {
}
return data;
},
toggleWidgets: function() {
toggleWidgets: function () {
window.$$('a[wysija_unique="1"]').invoke('removeClassName', 'disabled');
// loop through each unique field already inserted in the editor and disable its toolbar equivalent
window.$$('#' + WysijaForm.options.editor + ' [wysija_unique="1"]').map(function(element) {
window.$$('#' + WysijaForm.options.editor + ' [wysija_unique="1"]').map(function (element) {
var field = window.$$('#' + WysijaForm.options.toolbar + ' [wysija_id="' + element.readAttribute('wysija_id') + '"]');
if(field.length > 0) {
field.first().addClassName('disabled');
@ -421,10 +421,10 @@ var WysijaForm = {
window.$('mailpoet_settings_segment_selection').show();
}
},
hasSegmentSelection: function() {
hasSegmentSelection: function () {
return (window.$$('#' + WysijaForm.options.editor + ' [wysija_id="segments"]').length > 0);
},
isSegmentSelectionValid: function() {
isSegmentSelectionValid: function () {
var segment_selection = window.$$('#' + WysijaForm.options.editor + ' [wysija_id="segments"]')[0];
if(segment_selection !== undefined) {
var block = WysijaForm.get(segment_selection).block.getData();
@ -436,12 +436,12 @@ var WysijaForm = {
}
return false;
},
setBlockPositions: function(event, target) {
setBlockPositions: function (event, target) {
// release dragging lock
WysijaForm.locks.dragging = false;
var index = 1;
WysijaForm.getBlocks().each(function(container) {
WysijaForm.getBlocks().each(function (container) {
container.setPosition(index++);
// remove z-index value to avoid issues when resizing images
if(container['block'] !== undefined) {
@ -471,18 +471,18 @@ var WysijaForm = {
}
}
},
setScrollOffsets: function() {
setScrollOffsets: function () {
WysijaForm.scroll = document.viewport.getScrollOffsets();
},
hideSettings: function() {
hideSettings: function () {
window.$(WysijaForm.options.container).select('.wysija_settings').invoke('hide');
},
setSettingsPosition: function() {
setSettingsPosition: function () {
// get viewport offsets and dimensions
var viewportHeight = document.viewport.getHeight(),
blockPadding = 5;
window.$(WysijaForm.options.container).select('.wysija_settings').each(function(element) {
window.$(WysijaForm.options.container).select('.wysija_settings').each(function (element) {
// get parent dimensions and position
var parentDim = element.up('.mailpoet_form_block').getDimensions(),
parentPos = element.up('.mailpoet_form_block').cumulativeOffset(),
@ -506,7 +506,7 @@ var WysijaForm = {
});
});
},
initToolbarPosition: function() {
initToolbarPosition: function () {
if(WysijaForm.toolbar.top === null) WysijaForm.toolbar.top = parseInt(window.$(WysijaForm.options.container).positionedOffset().top);
if(WysijaForm.toolbar.y === null) WysijaForm.toolbar.y = parseInt(WysijaForm.toolbar.top);
@ -518,7 +518,7 @@ var WysijaForm = {
if(WysijaForm.toolbar.x === null) WysijaForm.toolbar.x = parseInt(WysijaForm.toolbar.left + window.$(WysijaForm.options.container).getDimensions().width + 15);
},
setToolbarPosition: function() {
setToolbarPosition: function () {
WysijaForm.initToolbarPosition();
var position = {
@ -534,7 +534,7 @@ var WysijaForm = {
window.$(WysijaForm.options.toolbar).setStyle(position);
},
updateToolbarPosition: function() {
updateToolbarPosition: function () {
// init toolbar position (updates scroll and toolbar y)
WysijaForm.initToolbarPosition();
@ -559,31 +559,31 @@ var WysijaForm = {
},
blockDropOptions: {
accept: window.$w('mailpoet_form_field'), // acceptable items (classes array)
onEnter: function(draggable, droppable) {
onEnter: function (draggable, droppable) {
window.$(droppable).addClassName('hover');
},
onLeave: function(draggable, droppable) {
onLeave: function (draggable, droppable) {
window.$(droppable).removeClassName('hover');
},
onDrop: function(draggable, droppable) {
onDrop: function (draggable, droppable) {
// custom data for images
droppable.fire('wjfe:item:drop', WysijaForm.getFieldData(draggable));
window.$(droppable).removeClassName('hover');
}
},
hideControls: function() {
hideControls: function () {
try {
return WysijaForm.getBlocks().invoke('hideControls');
} catch(e) {
return;
}
},
hideTools: function() {
hideTools: function () {
window.$$('.wysija_tools').invoke('hide');
WysijaForm.locks.showingTools = false;
},
instances: {},
get: function(element, typ) {
get: function (element, typ) {
var type = typ;
if(type === undefined) type = 'block';
// identify element
@ -593,10 +593,10 @@ var WysijaForm = {
WysijaForm.instances[id] = instance;
return instance;
},
makeDroppable: function() {
makeDroppable: function () {
window.Droppables.add('block_placeholder', WysijaForm.blockDropOptions);
},
makeSortable: function() {
makeSortable: function () {
var body = window.$(WysijaForm.options.body);
window.Sortable.create(body, {
tag: 'div',
@ -613,19 +613,19 @@ var WysijaForm = {
onEnd: WysijaForm.setBlockPositions
});
},
hideBlockControls: function() {
hideBlockControls: function () {
window.$$('.wysija_controls').invoke('hide');
this.getBlockElements().invoke('removeClassName', 'hover');
},
getBlocks: function() {
return WysijaForm.getBlockElements().map(function(element) {
getBlocks: function () {
return WysijaForm.getBlockElements().map(function (element) {
return WysijaForm.get(element);
});
},
getBlockElements: function() {
getBlockElements: function () {
return window.$(WysijaForm.options.container).select('.mailpoet_form_block');
},
startBlockPositions: function(event, target) {
startBlockPositions: function (event, target) {
if(target.element.hasClassName('mailpoet_form_block')) {
// store block placeholder id for the block that is being repositionned
if(target.element.previous('.block_placeholder') !== undefined) {
@ -634,7 +634,7 @@ var WysijaForm = {
}
WysijaForm.locks.dragging = true;
},
encodeURIComponent: function(str) {
encodeURIComponent: function (str) {
// check if it's a url and if so, prevent encoding of protocol
var regexp = new RegExp(/^http[s]?:\/\//),
protocol = regexp.exec(str);
@ -647,9 +647,9 @@ var WysijaForm = {
return encodeURI(str).replace(/[!'()*]/g, escape);
}
},
updateBlock: function(field) {
updateBlock: function (field) {
var hasUpdated = false;
WysijaForm.getBlocks().each(function(b) {
WysijaForm.getBlocks().each(function (b) {
if(b.block.getData().id === field.id) {
hasUpdated = true;
b.block.redraw(field);
@ -658,9 +658,9 @@ var WysijaForm = {
return hasUpdated;
},
removeBlock: function(field, callback) {
removeBlock: function (field, callback) {
var hasRemoved = false;
WysijaForm.getBlocks().each(function(b) {
WysijaForm.getBlocks().each(function (b) {
if(b.block.getData().id === field.id) {
hasRemoved = true;
b.block.removeBlock(callback);
@ -672,14 +672,14 @@ var WysijaForm = {
};
WysijaForm.DraggableItem = window.Class.create({
initialize: function(element) {
initialize: function (element) {
this.elementType = window.$(element).readAttribute('wysija_type');
this.element = window.$(element).down() || window.$(element);
this.clone = this.cloneElement();
this.insert();
},
STYLES: new window.Template('position: absolute; top: #{top}px; left: #{left}px;'),
cloneElement: function() {
cloneElement: function () {
var clone = this.element.clone(),
offset = this.element.cumulativeOffset(),
list = this.getList(),
@ -694,27 +694,27 @@ WysijaForm.DraggableItem = window.Class.create({
clone.innerHTML = this.element.innerHTML;
return clone;
},
getOffset: function() {
getOffset: function () {
return this.element.offsetTop - this.getList().scrollTop;
},
getList: function() {
getList: function () {
return this.element.up('ul');
},
insert: function() {
insert: function () {
window.$$('body')[0].insert(this.clone);
},
onMousedown: function(event) {
onMousedown: function (event) {
var draggable = new window.Draggable(this.clone, {
scroll: window,
onStart: function() {
onStart: function () {
window.Droppables.displayArea(draggable);
},
onEnd: function(drag) {
onEnd: function (drag) {
drag.destroy();
drag.element.remove();
window.Droppables.hideArea();
},
starteffect: function(element) {
starteffect: function (element) {
new window.Effect.Opacity(element, {
duration: 0.2,
from: element.getOpacity(),
@ -733,7 +733,7 @@ Object.extend(WysijaForm.DraggableItem, Observable).observe('a[class="mailpoet_f
WysijaForm.Block = window.Class.create({
/* Invoked on load */
initialize: function(element) {
initialize: function (element) {
info('block -> init');
this.element = window.$(element);
@ -748,16 +748,16 @@ WysijaForm.Block = window.Class.create({
}
return this;
},
setPosition: function(position) {
setPosition: function (position) {
this.element.writeAttribute('wysija_position', position);
},
hideControls: function() {
hideControls: function () {
if(this['getControls']) {
this.element.removeClassName('hover');
this.getControls().hide();
}
},
showControls: function() {
showControls: function () {
if(this['getControls']) {
this.element.addClassName('hover');
try {
@ -766,21 +766,21 @@ WysijaForm.Block = window.Class.create({
}
}
},
makeBlockDroppable: function() {
makeBlockDroppable: function () {
if(this.isBlockDroppableEnabled() === false) {
var block_placeholder = this.getBlockDroppable();
window.Droppables.add(block_placeholder.identify(), WysijaForm.blockDropOptions);
block_placeholder.addClassName('enabled');
}
},
removeBlockDroppable: function() {
removeBlockDroppable: function () {
if(this.isBlockDroppableEnabled()) {
var block_placeholder = this.getBlockDroppable();
window.Droppables.remove(block_placeholder.identify());
block_placeholder.removeClassName('enabled');
}
},
isBlockDroppableEnabled: function() {
isBlockDroppableEnabled: function () {
// if the block_placeholder does not exist, create it
var block_placeholder = this.getBlockDroppable();
if(block_placeholder === null) {
@ -789,30 +789,30 @@ WysijaForm.Block = window.Class.create({
return block_placeholder.hasClassName('enabled');
}
},
createBlockDroppable: function() {
createBlockDroppable: function () {
info('block -> createBlockDroppable');
this.element.insert({
before: '<div class=\"block_placeholder\">' + window.$('block_placeholder').innerHTML + '</div>'
});
return this.element.previous('.block_placeholder');
},
getBlockDroppable: function() {
getBlockDroppable: function () {
if(this.element.previous() === undefined || this.element.previous().hasClassName('block_placeholder') === false) {
return null;
} else {
return this.element.previous();
}
},
getControls: function() {
getControls: function () {
return this.element.down('.wysija_controls');
},
setupControls: function() {
setupControls: function () {
// enable controls
this.controls = this.getControls();
if(this.controls) {
// setup events for block controls
this.element.observe('mouseover', function() {
this.element.observe('mouseover', function () {
// special cases where controls shouldn't be displayed
if(WysijaForm.locks.dragging === true || WysijaForm.locks.selectingColor === true || WysijaForm.locks.showingTools === true) return;
@ -828,7 +828,7 @@ WysijaForm.Block = window.Class.create({
}
}.bind(this));
this.element.observe('mouseout', function() {
this.element.observe('mouseout', function () {
// special cases where controls shouldn't hide
if(WysijaForm.locks.dragging === true || WysijaForm.locks.selectingColor === true) return;
@ -845,7 +845,7 @@ WysijaForm.Block = window.Class.create({
// setup click event for remove button
this.removeButton = this.controls.down('.remove') || null;
if(this.removeButton !== null) {
this.removeButton.observe('click', function() {
this.removeButton.observe('click', function () {
this.removeBlock();
this.removeButton.stopObserving('click');
}.bind(this));
@ -855,7 +855,7 @@ WysijaForm.Block = window.Class.create({
this.settingsButton = this.element.down('.settings') || null;
if(this.settingsButton !== null) {
this.settingsButton.observe('click', function(event) {
this.settingsButton.observe('click', function (event) {
// TODO: refactor
var block = window.$(event.target).up('.mailpoet_form_block') || null;
if(block !== null) {
@ -867,7 +867,7 @@ WysijaForm.Block = window.Class.create({
}
return this;
},
removeBlock: function(callback) {
removeBlock: function (callback) {
info('block -> removeBlock');
// save block in history
@ -875,7 +875,7 @@ WysijaForm.Block = window.Class.create({
window.Effect.Fade(this.element.identify(), {
duration: 0.2,
afterFinish: function(effect) {
afterFinish: function (effect) {
// remove placeholder
if(effect.element.previous('.block_placeholder') !== undefined) {
effect.element.previous('.block_placeholder').remove();
@ -903,7 +903,7 @@ WysijaForm.Block = window.Class.create({
});
/* Invoked on item dropped */
WysijaForm.Block.create = function(createBlock, target) {
WysijaForm.Block.create = function (createBlock, target) {
var block = createBlock;
if(window.$('form_template_' + block.type) === null) {
return false;
@ -918,7 +918,7 @@ WysijaForm.Block.create = function(createBlock, target) {
if(block.params.values === undefined) {
var settings_segments = window.jQuery('#mailpoet_form_segments').val();
if(settings_segments !== null && settings_segments.length > 0){
block.params.values = window.mailpoet_segments.filter(function(segment) {
block.params.values = window.mailpoet_segments.filter(function (segment) {
return (settings_segments.indexOf(segment.id) !== -1);
});
}
@ -958,7 +958,7 @@ WysijaForm.Block.create = function(createBlock, target) {
WysijaForm.setSettingsPosition();
};
document.observe('wjfe:item:drop', function(event) {
document.observe('wjfe:item:drop', function (event) {
info('create block');
WysijaForm.Block.create(event.memo, event.target);
@ -967,23 +967,23 @@ document.observe('wjfe:item:drop', function(event) {
WysijaForm.hideBlockControls();
// toggle widgets
setTimeout(function() {
setTimeout(function () {
WysijaForm.toggleWidgets();
}, 1);
});
/* Form Widget */
WysijaForm.Widget = window.Class.create(WysijaForm.Block, {
initialize: function(element) {
initialize: function (element) {
info('widget -> init');
this.element = window.$(element);
return this;
},
setup: function() {
setup: function () {
info('widget -> setup');
this.setupControls();
},
save: function() {
save: function () {
info('widget -> save');
var data = this.getData();
@ -993,7 +993,7 @@ WysijaForm.Widget = window.Class.create(WysijaForm.Block, {
return data;
},
setData: function(data) {
setData: function (data) {
var current_data = this.getData(),
params = window.$H(current_data.params).merge(data.params).toObject();
@ -1005,7 +1005,7 @@ WysijaForm.Widget = window.Class.create(WysijaForm.Block, {
// update params
this.element.writeAttribute('wysija_params', JSON.stringify(params));
},
getData: function() {
getData: function () {
var data = WysijaForm.getFieldData(this.element);
// decode params
if(data.params.length > 0) {
@ -1013,13 +1013,13 @@ WysijaForm.Widget = window.Class.create(WysijaForm.Block, {
}
return data;
},
getControls: function() {
getControls: function () {
return this.element.down('.wysija_controls');
},
remove: function() {
remove: function () {
this.removeBlock();
},
redraw: function(data) {
redraw: function (data) {
// set parameters
this.setData(data);
var options = this.getData();
@ -1033,18 +1033,18 @@ WysijaForm.Widget = window.Class.create(WysijaForm.Block, {
WysijaForm.init();
},
editSettings: function() {
editSettings: function () {
window.MailPoet.Modal.popup({
title: window.MailPoet.I18n.t('editFieldSettings'),
template: window.jQuery('#form_template_field_settings').html(),
data: this.getData(),
onSuccess: function() {
onSuccess: function () {
var data = window.jQuery('#form_field_settings').serializeObject();
this.redraw(data);
}.bind(this)
});
},
getSettings: function() {
getSettings: function () {
return this.element.down('.wysija_settings');
}
});
@ -1057,8 +1057,8 @@ function info(value) {
if(WysijaForm.options.debug === false) return;
if(!(window.console && console.log)) {
(function() {
var noop = function() {};
(function () {
var noop = function () {};
var methods = ['assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error', 'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log', 'markTimeline', 'profile', 'profileEnd', 'markTimeline', 'table', 'time', 'timeEnd', 'timeStamp', 'trace', 'warn'];
var length = methods.length;
window.console = {};

View File

@ -1,6 +1,6 @@
define('handlebars_helpers', ['handlebars'], function(Handlebars) {
define('handlebars_helpers', ['handlebars'], function (Handlebars) {
// Handlebars helpers
Handlebars.registerHelper('concat', function() {
Handlebars.registerHelper('concat', function () {
var size = (arguments.length - 1),
output = '';
for(var i = 0; i < size; i++) {
@ -9,10 +9,10 @@ define('handlebars_helpers', ['handlebars'], function(Handlebars) {
return output;
});
Handlebars.registerHelper('number_format', function(value, block) {
Handlebars.registerHelper('number_format', function (value, block) {
return Number(value).toLocaleString();
});
Handlebars.registerHelper('date_format', function(timestamp, block) {
Handlebars.registerHelper('date_format', function (timestamp, block) {
if(window.moment) {
if(timestamp === undefined || isNaN(timestamp) || timestamp <= 0) {
return;
@ -31,7 +31,7 @@ define('handlebars_helpers', ['handlebars'], function(Handlebars) {
}
});
Handlebars.registerHelper('cycle', function(value, block) {
Handlebars.registerHelper('cycle', function (value, block) {
var values = value.split(' ');
return values[block.data.index % (values.length + 1)];
});
@ -66,23 +66,23 @@ define('handlebars_helpers', ['handlebars'], function(Handlebars) {
}
});
Handlebars.registerHelper('nl2br', function(value, block) {
Handlebars.registerHelper('nl2br', function (value, block) {
return value.gsub('\n', '<br />');
});
Handlebars.registerHelper('json_encode', function(value, block) {
Handlebars.registerHelper('json_encode', function (value, block) {
return JSON.stringify(value);
});
Handlebars.registerHelper('json_decode', function(value, block) {
Handlebars.registerHelper('json_decode', function (value, block) {
return JSON.parse(value);
});
Handlebars.registerHelper('url', function(value, block) {
Handlebars.registerHelper('url', function (value, block) {
var url = window.location.protocol + '//' + window.location.host + window.location.pathname;
return url + value;
});
Handlebars.registerHelper('emailFromMailto', function(value) {
Handlebars.registerHelper('emailFromMailto', function (value) {
var mailtoMatchingRegex = /^mailto\:/i;
if (typeof value === 'string' && value.match(mailtoMatchingRegex)) {
return value.replace(mailtoMatchingRegex, '');
@ -90,12 +90,12 @@ define('handlebars_helpers', ['handlebars'], function(Handlebars) {
return value;
}
});
Handlebars.registerHelper('lookup', function(obj, field, options) {
Handlebars.registerHelper('lookup', function (obj, field, options) {
return obj && obj[field];
});
Handlebars.registerHelper('rsa_key', function(value, block) {
Handlebars.registerHelper('rsa_key', function (value, block) {
// extract all lines into an array
if(value === undefined) return '';
@ -109,7 +109,7 @@ define('handlebars_helpers', ['handlebars'], function(Handlebars) {
return lines.join('');
});
Handlebars.registerHelper('trim', function(value, block) {
Handlebars.registerHelper('trim', function (value, block) {
if(value === null || value === undefined) return '';
return value.trim();
});
@ -141,7 +141,7 @@ define('handlebars_helpers', ['handlebars'], function(Handlebars) {
return parseInt(string, 10);
});
Handlebars.registerHelper('fontWithFallback', function(font) {
Handlebars.registerHelper('fontWithFallback', function (font) {
switch(font) {
case 'Arial': return new Handlebars.SafeString("Arial, 'Helvetica Neue', Helvetica, sans-serif");
case 'Comic Sans MS': return new Handlebars.SafeString("'Comic Sans MS', 'Marker Felt-Thin', Arial, sans-serif");

View File

@ -1,7 +1,7 @@
define('i18n',
[
'mailpoet'
], function(
], function (
mp
) {
'use strict';
@ -11,13 +11,13 @@ define('i18n',
var translations = {};
MailPoet.I18n = {
add: function(key, value) {
add: function (key, value) {
translations[key] = value;
},
t: function(key) {
t: function (key) {
return translations[key] || 'TRANSLATION "%$1s" NOT FOUND'.replace('%$1s', key);
},
all: function() {
all: function () {
return translations;
}
};

View File

@ -1,10 +1,10 @@
define('iframe', ['mailpoet'], function(mp) {
define('iframe', ['mailpoet'], function (mp) {
'use strict';
var MailPoet = mp;
MailPoet.Iframe = {
marginY: 20,
autoSize: function(iframe) {
autoSize: function (iframe) {
if(!iframe) return;
this.setSize(
@ -12,7 +12,7 @@ define('iframe', ['mailpoet'], function(mp) {
iframe.contentWindow.document.body.scrollHeight
);
},
setSize: function(sizeIframe, i) {
setSize: function (sizeIframe, i) {
var iframe = sizeIframe;
if(!iframe) return;

View File

@ -2,7 +2,7 @@ define(
[
'jquery'
],
function(
function (
jQuery
) {
var $ = jQuery;
@ -23,12 +23,12 @@ define(
* Dual licensed under the MIT and GPL licenses.
* http://benalman.com/about/license/
*/
$.fn.serializeObject = function(coerce) {
$.fn.serializeObject = function (coerce) {
var obj = {},
coerce_types = { true: !0, false: !1, null: null };
// Iterate over all name=value pairs.
$.each( this.serializeArray(), function(j, v){
$.each( this.serializeArray(), function (j, v){
var key = v.name,
val = v.value,
cur = obj,

View File

@ -1,4 +1,4 @@
define('mailpoet', [], function() {
define('mailpoet', [], function () {
// A placeholder for MailPoet object
var MailPoet = {};

View File

@ -1,5 +1,5 @@
define('modal', ['mailpoet', 'jquery'],
function(mp, jQuery) {
function (mp, jQuery) {
'use strict';
var MailPoet = mp;
@ -101,21 +101,21 @@ define('modal', ['mailpoet', 'jquery'],
'<div class="mailpoet_panel_body clearfix"></div>'+
'</div>'
},
getContentContainer: function() {
getContentContainer: function () {
return jQuery('.mailpoet_'+this.options.type+'_body');
},
setRenderer: function(renderer) {
setRenderer: function (renderer) {
this.renderer = renderer;
return this;
},
compileTemplate: function(template) {
compileTemplate: function (template) {
if(this.renderer === 'html') {
return function() { return template; };
return function () { return template; };
} else {
return window.Handlebars.compile(template);
}
},
init: function(options) {
init: function (options) {
if(this.initialized === true) {
this.close();
}
@ -178,7 +178,7 @@ define('modal', ['mailpoet', 'jquery'],
return this;
},
initOverlay: function(toggle) {
initOverlay: function (toggle) {
if(jQuery('#mailpoet_modal_overlay').length === 0) {
// insert overlay into the DOM
jQuery('body').append(this.templates.overlay);
@ -187,7 +187,7 @@ define('modal', ['mailpoet', 'jquery'],
}
return this;
},
toggleOverlay: function(toggle) {
toggleOverlay: function (toggle) {
if(toggle === true) {
jQuery('#mailpoet_modal_overlay')
.removeClass('mailpoet_overlay_hidden');
@ -198,12 +198,12 @@ define('modal', ['mailpoet', 'jquery'],
return this;
},
setupEvents: function() {
setupEvents: function () {
// close popup when user clicks on close button
jQuery('#mailpoet_modal_close').on('click', this.cancel.bind(this));
// close popup when user clicks on overlay
jQuery('#mailpoet_modal_overlay').on('click', function(e) {
jQuery('#mailpoet_modal_overlay').on('click', function (e) {
// we need to make sure that we are actually clicking on the overlay
// because when clicking on the popup content, it will trigger
// the click event on the overlay
@ -211,19 +211,19 @@ define('modal', ['mailpoet', 'jquery'],
}.bind(this));
// close popup when user presses ESC key
jQuery(document).on('keyup.mailpoet_modal', function(e) {
jQuery(document).on('keyup.mailpoet_modal', function (e) {
if(this.opened === false) { return false; }
if(e.keyCode === 27) { this.cancel(); }
}.bind(this));
// make sure the popup is repositioned when the window is resized
jQuery(window).on('resize.mailpoet_modal', function() {
jQuery(window).on('resize.mailpoet_modal', function () {
this.setPosition();
}.bind(this));
return this;
},
removeEvents: function() {
removeEvents: function () {
jQuery(document).unbind('keyup.mailpoet_modal');
jQuery(window).unbind('resize.mailpoet_modal');
jQuery('#mailpoet_modal_close').off('click');
@ -233,20 +233,20 @@ define('modal', ['mailpoet', 'jquery'],
return this;
},
lock: function() {
lock: function () {
this.locked = true;
return this;
},
unlock: function() {
unlock: function () {
this.locked = false;
return this;
},
isLocked: function() {
isLocked: function () {
return this.locked;
},
loadTemplate: function() {
loadTemplate: function () {
if(this.subpanels.length > 0) {
// hide panel
jQuery('.mailpoet_'+this.options.type+'_wrapper').hide();
@ -278,11 +278,11 @@ define('modal', ['mailpoet', 'jquery'],
return this;
},
loadUrl: function() {
loadUrl: function () {
if(this.options.method === 'get') {
// make ajax request
jQuery.getJSON(this.options.url,
function(data) {
function (data) {
this.options.data = jQuery.extend({}, this.options.data, data);
// load template using fetched data
this.loadTemplate();
@ -293,7 +293,7 @@ define('modal', ['mailpoet', 'jquery'],
} else if(this.options.method === 'post') {
// make ajax request
jQuery.post(this.options.url, JSON.stringify(this.options.params),
function(data) {
function (data) {
this.options.data = jQuery.extend({}, this.options.data, data);
// load template using fetched data
this.loadTemplate();
@ -306,7 +306,7 @@ define('modal', ['mailpoet', 'jquery'],
return this;
},
setDimensions: function() {
setDimensions: function () {
switch(this.options.type) {
case 'popup':
// set popup dimensions
@ -342,7 +342,7 @@ define('modal', ['mailpoet', 'jquery'],
return this;
},
setPosition: function() {
setPosition: function () {
switch(this.options.type) {
case 'popup':
var screenWidth = jQuery(window).width(),
@ -360,7 +360,7 @@ define('modal', ['mailpoet', 'jquery'],
});
break;
case 'panel':
setTimeout(function() {
setTimeout(function () {
// set position of popup depending on screen dimensions.
if(this.options.position === 'right') {
jQuery('#mailpoet_panel').css({
@ -377,7 +377,7 @@ define('modal', ['mailpoet', 'jquery'],
return this;
},
showModal: function() {
showModal: function () {
// set modal dimensions
this.setDimensions();
@ -417,7 +417,7 @@ define('modal', ['mailpoet', 'jquery'],
return this;
},
focus: function() {
focus: function () {
if(this.options.type == 'popup') {
jQuery('#mailpoet_'+this.options.type).focus();
} else {
@ -427,16 +427,16 @@ define('modal', ['mailpoet', 'jquery'],
}
return this;
},
highlightOn: function(element) {
highlightOn: function (element) {
jQuery(element).addClass('mailpoet_modal_highlight');
return this;
},
highlightOff: function() {
highlightOff: function () {
jQuery('.mailpoet_modal_highlight')
.removeClass('mailpoet_modal_highlight');
return this;
},
hideModal: function(callback) {
hideModal: function (callback) {
// set modal as closed
this.opened = false;
@ -451,15 +451,15 @@ define('modal', ['mailpoet', 'jquery'],
return this;
},
showOverlay: function(force) {
showOverlay: function (force) {
jQuery('#mailpoet_modal_overlay').show();
return this;
},
hideOverlay: function() {
hideOverlay: function () {
jQuery('#mailpoet_modal_overlay').hide();
return this;
},
popup: function(opts) {
popup: function (opts) {
// get options
var options = opts || {};
// set modal type
@ -473,7 +473,7 @@ define('modal', ['mailpoet', 'jquery'],
return this;
},
panel: function(opts) {
panel: function (opts) {
// get options
var options = opts || {};
// reset subpanels
@ -494,7 +494,7 @@ define('modal', ['mailpoet', 'jquery'],
return this;
},
subpanel: function(options) {
subpanel: function (options) {
if(this.opened === false) {
// if no panel is already opened, let's create one instead
this.panel(options);
@ -506,7 +506,7 @@ define('modal', ['mailpoet', 'jquery'],
return this;
},
loading: function(toggle) {
loading: function (toggle) {
// make sure the overlay is initialized and that it's visible
this.initOverlay(true);
@ -518,7 +518,7 @@ define('modal', ['mailpoet', 'jquery'],
return this;
},
showLoading: function() {
showLoading: function () {
jQuery('#mailpoet_loading').show();
// add loading class to overlay
@ -527,7 +527,7 @@ define('modal', ['mailpoet', 'jquery'],
return this;
},
hideLoading: function() {
hideLoading: function () {
jQuery('#mailpoet_loading').hide();
// remove loading class from overlay
@ -536,7 +536,7 @@ define('modal', ['mailpoet', 'jquery'],
return this;
},
open: function() {
open: function () {
// load template if specified
if(this.options.template !== null) {
// check if a url was specified to get extra data
@ -555,7 +555,7 @@ define('modal', ['mailpoet', 'jquery'],
return this;
},
success: function() {
success: function () {
if(this.subpanels.length > 0) {
if(this.subpanels[(this.subpanels.length - 1)].onSuccess !== undefined) {
this.subpanels[(this.subpanels.length - 1)].onSuccess(this.subpanels[(this.subpanels.length - 1)].data);
@ -569,7 +569,7 @@ define('modal', ['mailpoet', 'jquery'],
return this;
},
cancel: function() {
cancel: function () {
if(this.subpanels.length > 0) {
if(this.subpanels[(this.subpanels.length - 1)].onCancel !== undefined) {
this.subpanels[(this.subpanels.length - 1)].onCancel(this.subpanels[(this.subpanels.length - 1)].data);
@ -583,7 +583,7 @@ define('modal', ['mailpoet', 'jquery'],
return this;
},
destroy: function() {
destroy: function () {
this.hideOverlay();
// remove extra modal
@ -595,7 +595,7 @@ define('modal', ['mailpoet', 'jquery'],
return this;
},
close: function() {
close: function () {
if(this.isLocked() === true) { return this; }
if(this.subpanels.length > 0) {

View File

@ -1,4 +1,4 @@
define('mp2migrator', ['mailpoet', 'jquery'], function(mp, jQuery) {
define('mp2migrator', ['mailpoet', 'jquery'], function (mp, jQuery) {
'use strict';
var MailPoet = mp;
@ -184,22 +184,22 @@ define('mp2migrator', ['mailpoet', 'jquery'], function(mp, jQuery) {
jQuery('#progressbar').progressbar({value: 0});
// Import button
jQuery('#import').click(function() {
jQuery('#import').click(function () {
MailPoet.MP2Migrator.startImport();
});
// Stop import button
jQuery('#stop-import').click(function() {
jQuery('#stop-import').click(function () {
MailPoet.MP2Migrator.stopImport();
});
// Skip import link
jQuery('#skip-import').click(function() {
jQuery('#skip-import').click(function () {
MailPoet.MP2Migrator.skipImport();
});
// Go to welcome page
jQuery('#goto-welcome').click(function() {
jQuery('#goto-welcome').click(function () {
MailPoet.MP2Migrator.gotoWelcomePage();
});

View File

@ -6,7 +6,7 @@ define([
'underscore',
'handlebars',
'handlebars_helpers'
], function(Backbone, Marionette, BackboneRadio, jQuery, _, Handlebars) {
], function (Backbone, Marionette, BackboneRadio, jQuery, _, Handlebars) {
var Radio = BackboneRadio;
var AppView = Marionette.View.extend({
@ -23,12 +23,12 @@ define([
var EditorApplication = Marionette.Application.extend({
region: '#mailpoet_editor',
onStart: function() {
onStart: function () {
this._appView = new AppView();
this.showView(this._appView);
},
getChannel: function(channel) {
getChannel: function (channel) {
if (channel === undefined) {
return Radio.channel('global');
}

View File

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

View File

@ -8,16 +8,16 @@ define([
'newsletter_editor/behaviors/BehaviorsLookup',
'mailpoet',
'spectrum'
], function(Marionette, BehaviorsLookup, MailPoet, Spectrum) {
], function (Marionette, BehaviorsLookup, MailPoet, Spectrum) {
var BL = BehaviorsLookup;
BL.ColorPickerBehavior = Marionette.Behavior.extend({
onRender: function() {
onRender: function () {
var that = this,
preferredFormat = 'hex6';
this.view.$('.mailpoet_color').each(function () {
var $input = that.view.$(this);
var updateColorInput = function(color) {
var updateColorInput = function (color) {
if(color && color.getAlpha() > 0) {
$input.val(color.toString(preferredFormat));
} else {

View File

@ -12,20 +12,20 @@ define([
'jquery',
'newsletter_editor/behaviors/BehaviorsLookup',
'interact'
], function(Marionette, _, jQuery, BL, interact) {
], function (Marionette, _, jQuery, BL, interact) {
var BehaviorsLookup = BL;
BehaviorsLookup.ContainerDropZoneBehavior = Marionette.Behavior.extend({
defaults: {
columnLimit: 3
},
onRender: function() {
onRender: function () {
var dragAndDropDisabled = _.isObject(this.view.options.renderOptions) && this.view.options.renderOptions.disableDragAndDrop === true;
if (!dragAndDropDisabled) {
this.addDropZone();
}
},
addDropZone: function(_event) {
addDropZone: function (_event) {
var that = this,
view = this.view,
domElement = that.$el.get(0),
@ -47,16 +47,16 @@ define([
interact(domElement).dropzone({
accept: acceptableElementSelector,
overlap: 'pointer', // Mouse pointer denotes location of a droppable
ondragenter: function(event) {
ondragenter: function (event) {
// 1. Visually mark block as active for dropping
view.$el.addClass('mailpoet_drop_active');
},
ondragleave: function(event) {
ondragleave: function (event) {
// 1. Remove visual markings of active dropping container
// 2. Remove visual markings of drop position visualization
that.cleanup();
},
ondropmove: function(event) {
ondropmove: function (event) {
// 1. Compute actual location of the mouse within the container
// 2. Check if insertion is regular (between blocks) or special (with container insertion)
// 3a. If insertion is regular, compute position where insertion should happen
@ -163,7 +163,7 @@ define([
element.append(marker);
},
ondrop: function(event) {
ondrop: function (event) {
// 1. Compute actual location of the mouse
// 2. Check if insertion is regular (between blocks) or special (with container insertion)
// 3a. If insertion is regular
@ -264,14 +264,14 @@ define([
}
});
},
cleanup: function() {
cleanup: function () {
// 1. Remove visual markings of active dropping container
this.view.$el.removeClass('mailpoet_drop_active');
// 2. Remove visual markings of drop position visualization
this.view.$('.mailpoet_drop_marker').remove();
},
getDropPosition: function(eventX, eventY, is_unsafe) {
getDropPosition: function (eventX, eventY, is_unsafe) {
var SPECIAL_AREA_INSERTION_WIDTH = 0.00, // Disable special insertion. Default: 0.3
element = this.view.$el,
@ -353,7 +353,7 @@ define([
position: position // 'inside'|'before'|'after'
};
},
_computeNormalIndex: function(eventX, eventY) {
_computeNormalIndex: function (eventX, eventY) {
// Normal insertion inserts dropModel before target element if
// event happens on the first half of the element and after the
// target element if event happens on the second half of the element.
@ -390,13 +390,13 @@ define([
};
}
},
_computeSpecialIndex: function(eventX, eventY) {
_computeSpecialIndex: function (eventX, eventY) {
return this._computeCellIndex(eventX, eventY);
},
_computeCellIndex: function(eventX, eventY) {
_computeCellIndex: function (eventX, eventY) {
var orientation = this.view.model.get('orientation'),
eventOffset = (orientation === 'vertical') ? eventY : eventX,
resultView = this.getChildren().find(function(view) {
resultView = this.getChildren().find(function (view) {
var element = view.$el,
closeOffset, farOffset;
@ -416,26 +416,26 @@ define([
return index;
},
_canAcceptNormalInsertion: function() {
_canAcceptNormalInsertion: function () {
var orientation = this.view.model.get('orientation'),
depth = this.view.renderOptions.depth,
childCount = this.getChildren().length;
// Note that depth is zero indexed. Root container has depth=0
return orientation === 'vertical' || (orientation === 'horizontal' && depth === 1 && childCount < this.options.columnLimit);
},
_canAcceptSpecialInsertion: function() {
_canAcceptSpecialInsertion: function () {
var orientation = this.view.model.get('orientation'),
depth = this.view.renderOptions.depth,
childCount = this.getChildren().length;
return depth === 0 || (depth === 1 && orientation === 'horizontal' && childCount <= this.options.columnLimit);
},
getCollectionView: function() {
getCollectionView: function () {
return this.view.getChildView('blocks');
},
getChildren: function() {
getChildren: function () {
return this.getCollectionView().children;
},
getCollection: function() {
getCollection: function () {
return this.getCollectionView().collection;
}
});

View File

@ -10,7 +10,7 @@ define([
'jquery',
'newsletter_editor/behaviors/BehaviorsLookup',
'interact'
], function(Marionette, _, jQuery, BehaviorsLookup, interact) {
], function (Marionette, _, jQuery, BehaviorsLookup, interact) {
var BL = BehaviorsLookup;
BL.DraggableBehavior = Marionette.Behavior.extend({
@ -24,14 +24,14 @@ define([
*
* @return Backbone.Model A model that will be passed to the receiver
*/
getDropModel: function() {
getDropModel: function () {
throw "Missing 'drop' function for DraggableBehavior";
},
onDrop: function(model, view) {},
testAttachToInstance: function(model, view) { return true; }
onDrop: function (model, view) {},
testAttachToInstance: function (model, view) { return true; }
},
onRender: function() {
onRender: function () {
var that = this,
interactable;
@ -47,7 +47,7 @@ define([
// Scroll when dragging near edges of a window
autoScroll: true,
onstart: function(startEvent) {
onstart: function (startEvent) {
var event = startEvent;
if (that.options.cloneOriginal === true) {
@ -131,7 +131,7 @@ define([
} else {
interactable.getDropModel = this.view.getDropFunc();
}
interactable.onDrop = function(opts) {
interactable.onDrop = function (opts) {
var options = opts;
if (_.isObject(options)) {
// Inject Draggable behavior if possible

View File

@ -6,7 +6,7 @@
define([
'backbone.marionette',
'newsletter_editor/behaviors/BehaviorsLookup'
], function(Marionette, BehaviorsLookup) {
], function (Marionette, BehaviorsLookup) {
var BL = BehaviorsLookup;
BL.HighlightContainerBehavior = Marionette.Behavior.extend({
@ -14,10 +14,10 @@ define([
'mouseenter @ui.tools': 'enableHighlight',
'mouseleave @ui.tools': 'disableHighlight'
},
enableHighlight: function() {
enableHighlight: function () {
this.$el.addClass('mailpoet_highlight');
},
disableHighlight: function() {
disableHighlight: function () {
if (!this.view._isBeingEdited) {
this.$el.removeClass('mailpoet_highlight');
}

View File

@ -6,7 +6,7 @@
define([
'backbone.marionette',
'newsletter_editor/behaviors/BehaviorsLookup'
], function(Marionette, BehaviorsLookup) {
], function (Marionette, BehaviorsLookup) {
var BL = BehaviorsLookup;
BL.HighlightEditingBehavior = Marionette.Behavior.extend({
@ -14,11 +14,11 @@ define([
startEditing: 'enableHighlight',
stopEditing: 'disableHighlight'
},
enableHighlight: function() {
enableHighlight: function () {
this.view._isBeingEdited = true;
this.$el.addClass('mailpoet_highlight');
},
disableHighlight: function() {
disableHighlight: function () {
this.view._isBeingEdited = false;
this.$el.removeClass('mailpoet_highlight');
}

View File

@ -7,14 +7,14 @@ define([
'backbone.marionette',
'newsletter_editor/behaviors/BehaviorsLookup',
'interact'
], function(Marionette, BehaviorsLookup, interact) {
], function (Marionette, BehaviorsLookup, interact) {
var BL = BehaviorsLookup;
BL.ResizableBehavior = Marionette.Behavior.extend({
defaults: {
elementSelector: null,
resizeHandleSelector: true, // true will use edges of the element itself
transformationFunction: function(y) { return y; },
transformationFunction: function (y) { return y; },
minLength: 0,
modelField: 'styles.block.height'
},
@ -22,14 +22,14 @@ define([
mouseenter: 'showResizeHandle',
mouseleave: 'hideResizeHandle'
},
onRender: function() {
onRender: function () {
this.attachResize();
if (this.isBeingResized !== true) {
this.hideResizeHandle();
}
},
attachResize: function() {
attachResize: function () {
var domElement = (this.options.elementSelector === null) ? this.view.$el.get(0) : this.view.$(this.options.elementSelector).get(0),
that = this;
interact(domElement).resizable({
@ -40,10 +40,10 @@ define([
right: false,
bottom: (typeof this.options.resizeHandleSelector === 'string') ? this.view.$(this.options.resizeHandleSelector).get(0) : this.options.resizeHandleSelector
}
}).on('resizestart', function(event) {
}).on('resizestart', function (event) {
that.isBeingResized = true;
that.$el.addClass('mailpoet_resize_active');
}).on('resizemove', function(event) {
}).on('resizemove', function (event) {
var currentLength = parseFloat(that.view.model.get(that.options.modelField)),
newLength = currentLength + that.options.transformationFunction(event.dy);
@ -51,17 +51,17 @@ define([
that.view.model.set(that.options.modelField, newLength + 'px');
})
.on('resizeend', function(event) {
.on('resizeend', function (event) {
that.isBeingResized = null;
that.$el.removeClass('mailpoet_resize_active');
});
},
showResizeHandle: function() {
showResizeHandle: function () {
if (typeof this.options.resizeHandleSelector === 'string') {
this.view.$(this.options.resizeHandleSelector).removeClass('mailpoet_hidden');
}
},
hideResizeHandle: function() {
hideResizeHandle: function () {
if (typeof this.options.resizeHandleSelector === 'string') {
this.view.$(this.options.resizeHandleSelector).addClass('mailpoet_hidden');
}

View File

@ -7,7 +7,7 @@ define([
'backbone.marionette',
'jquery',
'newsletter_editor/behaviors/BehaviorsLookup'
], function(Marionette, jQuery, BehaviorsLookup) {
], function (Marionette, jQuery, BehaviorsLookup) {
var BL = BehaviorsLookup;
BL.ShowSettingsBehavior = Marionette.Behavior.extend({
@ -17,12 +17,12 @@ define([
events: {
'click .mailpoet_content': 'showSettings'
},
showSettings: function(event) {
showSettings: function (event) {
if(!this.isIgnoredElement(event.target)) {
this.view.triggerMethod('showSettings');
}
},
isIgnoredElement: function(element) {
isIgnoredElement: function (element) {
return this.options.ignoreFrom
&& this.options.ignoreFrom.length > 0
&& jQuery(element).is(this.options.ignoreFrom);

View File

@ -7,23 +7,23 @@ define([
'backbone.marionette',
'underscore',
'newsletter_editor/behaviors/BehaviorsLookup'
], function(Marionette, _, BehaviorsLookup) {
], function (Marionette, _, BehaviorsLookup) {
var BL = BehaviorsLookup;
BL.SortableBehavior = Marionette.Behavior.extend({
onRender: function() {
onRender: function () {
var collection = this.view.collection;
if (_.isFunction(this.$el.sortable)) {
this.$el.sortable({
cursor: 'move',
start: function(event, ui) {
start: function (event, ui) {
ui.item.data('previousIndex', ui.item.index());
},
end: function(event, ui) {
end: function (event, ui) {
ui.item.removeData('previousIndex');
},
update: function(event, ui) {
update: function (event, ui) {
var previousIndex = ui.item.data('previousIndex'),
newIndex = ui.item.index(),
model = collection.at(previousIndex);

View File

@ -7,7 +7,7 @@ define([
'backbone.marionette',
'underscore',
'newsletter_editor/behaviors/BehaviorsLookup'
], function(Marionette, _, BehaviorsLookup) {
], function (Marionette, _, BehaviorsLookup) {
var BL = BehaviorsLookup;
BL.TextEditorBehavior = Marionette.Behavior.extend({
@ -19,9 +19,9 @@ define([
invalidElements: 'script',
blockFormats: 'Paragraph=p',
plugins: 'link textcolor colorpicker mailpoet_shortcodes',
configurationFilter: function(originalConfig) { return originalConfig; }
configurationFilter: function (originalConfig) { return originalConfig; }
},
onDomRefresh: function() {
onDomRefresh: function () {
var that = this;
if (this.view.disableTextEditor === true) {
return;
@ -42,7 +42,7 @@ define([
relative_urls: false,
remove_script_host: false,
convert_urls: true,
urlconverter_callback: function(url, node, on_save, name) {
urlconverter_callback: function (url, node, on_save, name) {
if (url.match(/\[.+\]/g)) {
// Do not convert URLs with shortcodes
return url;
@ -56,12 +56,12 @@ define([
plugins: this.options.plugins,
setup: function(editor) {
editor.on('change', function(e) {
setup: function (editor) {
editor.on('change', function (e) {
that.view.triggerMethod('text:editor:change', editor.getContent());
});
editor.on('click', function(e) {
editor.on('click', function (e) {
editor.focus();
if (that._isActivationClick) {
editor.selection.setRng(
@ -71,12 +71,12 @@ define([
}
});
editor.on('focus', function(e) {
editor.on('focus', function (e) {
that.view.triggerMethod('text:editor:focus');
that._isActivationClick = true;
});
editor.on('blur', function(e) {
editor.on('blur', function (e) {
that.view.triggerMethod('text:editor:blur');
});
}

View File

@ -16,7 +16,7 @@ define([
'backbone.supermodel',
'underscore',
'jquery'
], function(
], function (
App,
BaseBlock,
ButtonBlock,
@ -34,7 +34,7 @@ define([
base = BaseBlock;
Module.ALCSupervisor = SuperModel.extend({
initialize: function() {
initialize: function () {
var DELAY_REFRESH_FOR_MS = 500;
this.listenTo(
App.getChannel(),
@ -42,13 +42,13 @@ define([
_.debounce(this.refresh, DELAY_REFRESH_FOR_MS)
);
},
refresh: function() {
var models = App.findModels(function(model) {
refresh: function () {
var models = App.findModels(function (model) {
return model.get('type') === 'automatedLatestContent';
}) || [];
if (models.length === 0) return;
var blocks = _.map(models, function(model) {
var blocks = _.map(models, function (model) {
return model.toJSON();
});
@ -56,10 +56,10 @@ define([
blocks: blocks
}).then(_.partial(this.refreshBlocks, models));
},
refreshBlocks: function(models, renderedBlocks) {
refreshBlocks: function (models, renderedBlocks) {
_.each(
_.zip(models, renderedBlocks),
function(args) {
function (args) {
var model = args[0],
contents = args[1];
model.trigger('refreshPosts', contents);
@ -70,7 +70,7 @@ define([
Module.AutomatedLatestContentBlockModel = base.BlockModel.extend({
stale: ['_container'],
defaults: function() {
defaults: function () {
return this._getDefaults({
type: 'automatedLatestContent',
amount: '5',
@ -100,14 +100,14 @@ define([
_container: new (App.getBlockTypeModel('container'))()
}, App.getConfig().get('blockDefaults.automatedLatestContent'));
},
relations: function() {
relations: function () {
return {
readMoreButton: App.getBlockTypeModel('button'),
divider: App.getBlockTypeModel('divider'),
_container: App.getBlockTypeModel('container')
};
},
initialize: function() {
initialize: function () {
base.BlockView.prototype.initialize.apply(this, arguments);
this.on('change:amount change:contentType change:terms change:inclusionType change:displayType change:titleFormat change:featuredImagePosition change:titleAlignment change:titleIsLink change:imageFullWidth change:showAuthor change:authorPrecededBy change:showCategories change:categoriesPrecededBy change:readMoreType change:readMoreText change:sortBy change:showDivider', this._scheduleFetchPosts, this);
this.listenTo(this.get('readMoreButton'), 'change', this._scheduleFetchPosts);
@ -115,27 +115,27 @@ define([
this.on('add remove update reset', this._scheduleFetchPosts);
this.on('refreshPosts', this.updatePosts, this);
},
updatePosts: function(posts) {
updatePosts: function (posts) {
this.get('_container.blocks').reset(posts, {parse: true});
},
/**
* Batch more changes during a specific time, instead of fetching
* ALC posts on each model change
*/
_scheduleFetchPosts: function() {
_scheduleFetchPosts: function () {
App.getChannel().trigger('automatedLatestContentRefresh');
}
});
Module.AutomatedLatestContentBlockView = base.BlockView.extend({
className: 'mailpoet_block mailpoet_automated_latest_content_block mailpoet_droppable_block',
initialize: function() {
initialize: function () {
function replaceButtonStylesHandler(data) {
this.model.set({readMoreButton: data});
}
App.getChannel().on('replaceAllButtonStyles', replaceButtonStylesHandler.bind(this));
},
getTemplate: function() { return window.templates.automatedLatestContentBlock; },
getTemplate: function () { return window.templates.automatedLatestContentBlock; },
regions: {
toolsRegion: '.mailpoet_tools',
postsRegion: '.mailpoet_automated_latest_content_block_posts'
@ -148,8 +148,8 @@ define([
events: _.extend(base.BlockView.prototype.events, {
'click .mailpoet_automated_latest_content_block_overlay': 'showSettings'
}),
onDragSubstituteBy: function() { return Module.AutomatedLatestContentWidgetView; },
onRender: function() {
onDragSubstituteBy: function () { return Module.AutomatedLatestContentWidgetView; },
onRender: function () {
var ContainerView = App.getBlockTypeView('container'),
renderOptions = {
disableTextEditor: true,
@ -163,13 +163,13 @@ define([
});
Module.AutomatedLatestContentBlockToolsView = base.BlockToolsView.extend({
getSettingsView: function() { return Module.AutomatedLatestContentBlockSettingsView; }
getSettingsView: function () { return Module.AutomatedLatestContentBlockSettingsView; }
});
// Sidebar view container
Module.AutomatedLatestContentBlockSettingsView = base.BlockSettingsView.extend({
getTemplate: function() { return window.templates.automatedLatestContentBlockSettings; },
events: function() {
getTemplate: function () { return window.templates.automatedLatestContentBlockSettings; },
events: function () {
return {
'click .mailpoet_automated_latest_content_hide_display_options': 'toggleDisplayOptions',
'click .mailpoet_automated_latest_content_show_display_options': 'toggleDisplayOptions',
@ -195,7 +195,7 @@ define([
'click .mailpoet_done_editing': 'close'
};
},
onRender: function() {
onRender: function () {
var that = this;
// Dynamically update available post types
@ -211,17 +211,17 @@ define([
term: params.term
};
},
transport: function(options, success, failure) {
transport: function (options, success, failure) {
var taxonomies;
var promise = CommunicationComponent.getTaxonomies(
that.model.get('contentType')
).then(function(tax) {
).then(function (tax) {
taxonomies = tax;
// Fetch available terms based on the list of taxonomies already fetched
var promise = CommunicationComponent.getTerms({
search: options.data.term,
taxonomies: _.keys(taxonomies)
}).then(function(terms) {
}).then(function (terms) {
return {
taxonomies: taxonomies,
terms: terms
@ -234,12 +234,12 @@ define([
promise.fail(failure);
return promise;
},
processResults: function(data) {
processResults: function (data) {
// Transform taxonomies and terms into select2 compatible format
return {
results: _.map(
data.terms,
function(item) {
function (item) {
return _.defaults({
text: data.taxonomies[item.taxonomy].labels.singular_name + ': ' + item.name,
id: item.term_id
@ -250,13 +250,13 @@ define([
}
}
}).on({
'select2:select': function(event) {
'select2:select': function (event) {
var terms = that.model.get('terms');
terms.add(event.params.data);
// Reset whole model in order for change events to propagate properly
that.model.set('terms', terms.toJSON());
},
'select2:unselect': function(event) {
'select2:unselect': function (event) {
var terms = that.model.get('terms');
terms.remove(event.params.data);
// Reset whole model in order for change events to propagate properly
@ -264,7 +264,7 @@ define([
}
}).trigger( 'change' );
},
toggleDisplayOptions: function(event) {
toggleDisplayOptions: function (event) {
var el = this.$('.mailpoet_automated_latest_content_display_options'),
showControl = this.$('.mailpoet_automated_latest_content_show_display_options');
if (el.hasClass('mailpoet_closed')) {
@ -275,7 +275,7 @@ define([
showControl.removeClass('mailpoet_hidden');
}
},
showButtonSettings: function(event) {
showButtonSettings: function (event) {
var buttonModule = ButtonBlock;
(new buttonModule.ButtonBlockSettingsView({
model: this.model.get('readMoreButton'),
@ -286,7 +286,7 @@ define([
}
})).render();
},
showDividerSettings: function(event) {
showDividerSettings: function (event) {
var dividerModule = DividerBlock;
(new dividerModule.DividerBlockSettingsView({
model: this.model.get('divider'),
@ -296,7 +296,7 @@ define([
}
})).render();
},
changeReadMoreType: function(event) {
changeReadMoreType: function (event) {
var value = jQuery(event.target).val();
if (value == 'link') {
this.$('.mailpoet_automated_latest_content_read_more_text').removeClass('mailpoet_hidden');
@ -307,7 +307,7 @@ define([
}
this.changeField('readMoreType', event);
},
changeDisplayType: function(event) {
changeDisplayType: function (event) {
var value = jQuery(event.target).val();
if (value == 'titleOnly') {
@ -334,7 +334,7 @@ define([
}
this.changeField('displayType', event);
},
changeTitleFormat: function(event) {
changeTitleFormat: function (event) {
var value = jQuery(event.target).val();
if (value == 'ul') {
this.$('.mailpoet_automated_latest_content_non_title_list_options').addClass('mailpoet_hidden');
@ -348,12 +348,12 @@ define([
}
this.changeField('titleFormat', event);
},
_updateContentTypes: function(postTypes) {
_updateContentTypes: function (postTypes) {
var select = this.$('.mailpoet_automated_latest_content_content_type'),
selectedValue = this.model.get('contentType');
select.find('option').remove();
_.each(postTypes, function(type) {
_.each(postTypes, function (type) {
select.append(jQuery('<option>', {
value: type.name,
text: type.label
@ -364,21 +364,21 @@ define([
});
Module.AutomatedLatestContentWidgetView = base.WidgetView.extend({
getTemplate: function() { return window.templates.automatedLatestContentInsertion; },
getTemplate: function () { return window.templates.automatedLatestContentInsertion; },
behaviors: {
DraggableBehavior: {
cloneOriginal: true,
drop: function() {
drop: function () {
return new Module.AutomatedLatestContentBlockModel({}, { parse: true });
},
onDrop: function(options) {
onDrop: function (options) {
options.droppedView.triggerMethod('showSettings');
}
}
}
});
App.on('before:start', function(App, options) {
App.on('before:start', function (App, options) {
App.registerBlockType('automatedLatestContent', {
blockModel: Module.AutomatedLatestContentBlockModel,
blockView: Module.AutomatedLatestContentBlockView
@ -391,7 +391,7 @@ define([
});
});
App.on('start', function(App, options) {
App.on('start', function (App, options) {
var Application = App;
Application._ALCSupervisor = new Module.ALCSupervisor();
Application._ALCSupervisor.refresh();

View File

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

View File

@ -7,7 +7,7 @@ define([
'mailpoet',
'underscore',
'jquery'
], function(App, BaseBlock, MailPoet, _, jQuery) {
], function (App, BaseBlock, MailPoet, _, jQuery) {
'use strict';
@ -15,7 +15,7 @@ define([
base = BaseBlock;
Module.ButtonBlockModel = base.BlockModel.extend({
defaults: function() {
defaults: function () {
return this._getDefaults({
type: 'button',
text: 'Button',
@ -42,31 +42,31 @@ define([
Module.ButtonBlockView = base.BlockView.extend({
className: 'mailpoet_block mailpoet_button_block mailpoet_droppable_block',
getTemplate: function() { return window.templates.buttonBlock; },
onDragSubstituteBy: function() { return Module.ButtonWidgetView; },
getTemplate: function () { return window.templates.buttonBlock; },
onDragSubstituteBy: function () { return Module.ButtonWidgetView; },
behaviors: _.extend({}, base.BlockView.prototype.behaviors, {
ShowSettingsBehavior: {}
}),
initialize: function() {
initialize: function () {
base.BlockView.prototype.initialize.apply(this, arguments);
// Listen for attempts to change all dividers in one go
this._replaceButtonStylesHandler = function(data) { this.model.set(data); }.bind(this);
this._replaceButtonStylesHandler = function (data) { this.model.set(data); }.bind(this);
App.getChannel().on('replaceAllButtonStyles', this._replaceButtonStylesHandler);
},
onRender: function() {
onRender: function () {
this.toolsView = new Module.ButtonBlockToolsView({ model: this.model });
this.showChildView('toolsRegion', this.toolsView);
}
});
Module.ButtonBlockToolsView = base.BlockToolsView.extend({
getSettingsView: function() { return Module.ButtonBlockSettingsView; }
getSettingsView: function () { return Module.ButtonBlockSettingsView; }
});
Module.ButtonBlockSettingsView = base.BlockSettingsView.extend({
getTemplate: function() { return window.templates.buttonBlockSettings; },
events: function() {
getTemplate: function () { return window.templates.buttonBlockSettings; },
events: function () {
return {
'input .mailpoet_field_button_text': _.partial(this.changeField, 'text'),
'input .mailpoet_field_button_url': _.partial(this.changeField, 'url'),
@ -98,20 +98,20 @@ define([
'click .mailpoet_done_editing': 'close'
};
},
templateContext: function() {
templateContext: function () {
return _.extend({}, base.BlockView.prototype.templateContext.apply(this, arguments), {
availableStyles: App.getAvailableStyles().toJSON(),
renderOptions: this.renderOptions
});
},
applyToAll: function() {
applyToAll: function () {
App.getChannel().trigger('replaceAllButtonStyles', _.pick(this.model.toJSON(), 'styles', 'type'));
},
updateValueAndCall: function(fieldToUpdate, callable, event) {
updateValueAndCall: function (fieldToUpdate, callable, event) {
this.$(fieldToUpdate).val(jQuery(event.target).val());
callable(event);
},
changeFontWeight: function(event) {
changeFontWeight: function (event) {
var checked = !!jQuery(event.target).prop('checked');
this.model.set(
'styles.block.fontWeight',
@ -121,18 +121,18 @@ define([
});
Module.ButtonWidgetView = base.WidgetView.extend({
getTemplate: function() { return window.templates.buttonInsertion; },
getTemplate: function () { return window.templates.buttonInsertion; },
behaviors: {
DraggableBehavior: {
cloneOriginal: true,
drop: function() {
drop: function () {
return new Module.ButtonBlockModel();
}
}
}
});
App.on('before:start', function(App, options) {
App.on('before:start', function (App, options) {
App.registerBlockType('button', {
blockModel: Module.ButtonBlockModel,
blockView: Module.ButtonBlockView

View File

@ -10,7 +10,7 @@ define([
'jquery',
'newsletter_editor/App',
'newsletter_editor/blocks/base'
], function(Backbone, Marionette, _, jQuery, App, BaseBlock) {
], function (Backbone, Marionette, _, jQuery, App, BaseBlock) {
'use strict';
@ -20,12 +20,12 @@ define([
BlockCollection = Backbone.Collection.extend({
model: base.BlockModel,
initialize: function() {
this.on('add change remove', function() { App.getChannel().trigger('autoSave'); });
initialize: function () {
this.on('add change remove', function () { App.getChannel().trigger('autoSave'); });
},
parse: function(response) {
parse: function (response) {
var self = this;
return _.map(response, function(block) {
return _.map(response, function (block) {
var Type = App.getBlockTypeModel(block.type);
// TODO: If type has no registered model, use a backup one
return new Type(block, {parse: true});
@ -37,7 +37,7 @@ define([
relations: {
blocks: BlockCollection
},
defaults: function() {
defaults: function () {
return this._getDefaults({
type: 'container',
orientation: 'vertical',
@ -49,14 +49,14 @@ define([
blocks: new BlockCollection()
}, App.getConfig().get('blockDefaults.container'));
},
validate: function() {
validate: function () {
// Recursively propagate validation checks to blocks in the tree
var invalidBlock = this.get('blocks').find(function(block) { return !block.isValid(); });
var invalidBlock = this.get('blocks').find(function (block) { return !block.isValid(); });
if (invalidBlock) {
return invalidBlock.validationError;
}
},
parse: function(response) {
parse: function (response) {
// If container has any blocks - add them to a collection
if (response.type === 'container' && _.has(response, 'blocks')) {
response.blocks = new BlockCollection(response.blocks, {
@ -65,8 +65,8 @@ define([
}
return response;
},
getChildren: function() {
var models = this.get('blocks').map(function(model, index, list) {
getChildren: function () {
var models = this.get('blocks').map(function (model, index, list) {
return [model, model.getChildren()];
});
@ -76,10 +76,10 @@ define([
Module.ContainerBlocksView = Marionette.CollectionView.extend({
className: 'mailpoet_container',
childView: function(model) {
childView: function (model) {
return App.getBlockTypeView(model.get('type'));
},
childViewOptions: function() {
childViewOptions: function () {
var newRenderOptions = _.clone(this.renderOptions);
if (newRenderOptions.depth !== undefined) {
newRenderOptions.depth += 1;
@ -88,9 +88,9 @@ define([
renderOptions: newRenderOptions
};
},
emptyView: function() { return Module.ContainerBlockEmptyView; },
emptyViewOptions: function() { return { renderOptions: this.renderOptions }; },
initialize: function(options) {
emptyView: function () { return Module.ContainerBlockEmptyView; },
emptyViewOptions: function () { return { renderOptions: this.renderOptions }; },
initialize: function (options) {
this.renderOptions = options.renderOptions;
}
});
@ -103,7 +103,7 @@ define([
}
}),
className: 'mailpoet_block mailpoet_container_block mailpoet_droppable_block mailpoet_droppable_layout_block',
getTemplate: function() { return window.templates.containerBlock; },
getTemplate: function () { return window.templates.containerBlock; },
events: _.extend({}, base.BlockView.prototype.events, {
'click .mailpoet_newsletter_layer_selector': 'toggleEditingLayer'
}),
@ -115,12 +115,12 @@ define([
DraggableBehavior: {
cloneOriginal: true,
hideOriginal: true,
onDrop: function(options) {
onDrop: function (options) {
// After a clone of model has been dropped, cleanup
// and destroy self
options.dragBehavior.view.model.destroy();
},
onDragSubstituteBy: function(behavior) {
onDragSubstituteBy: function (behavior) {
var WidgetView, node;
// When block is being dragged, display the widget icon instead.
// This will create an instance of block's widget view and
@ -133,7 +133,7 @@ define([
return node;
}
},
testAttachToInstance: function(model, view) {
testAttachToInstance: function (model, view) {
// Attach Draggable only to layout containers and disable it
// for root and column containers.
return view.renderOptions.depth === 1;
@ -141,7 +141,7 @@ define([
},
HighlightContainerBehavior: {}
}),
onDragSubstituteBy: function() {
onDragSubstituteBy: function () {
// For two and three column layouts display their respective widgets,
// otherwise always default to one column layout widget
if (this.renderOptions.depth === 1) {
@ -151,12 +151,12 @@ define([
return Module.OneColumnContainerWidgetView;
},
initialize: function(options) {
initialize: function (options) {
base.BlockView.prototype.initialize.apply(this, arguments);
this.renderOptions = _.defaults(options.renderOptions || {}, {});
},
onRender: function() {
onRender: function () {
this.toolsView = new Module.ContainerBlockToolsView({
model: this.model,
tools: {
@ -177,31 +177,31 @@ define([
// Sets child container orientation HTML class here, as child CollectionView won't have access to model and will overwrite existing region element instead
this.$('> .mailpoet_container').attr('class', 'mailpoet_container mailpoet_container_' + this.model.get('orientation'));
},
showTools: function() {
showTools: function () {
if (this.renderOptions.depth === 1 && !this.$el.hasClass('mailpoet_container_layer_active')) {
this.$(this.ui.tools).addClass('mailpoet_display_tools');
this.toolsView.triggerMethod('showTools');
}
},
hideTools: function() {
hideTools: function () {
if (this.renderOptions.depth === 1 && !this.$el.hasClass('mailpoet_container_layer_active')) {
this.$(this.ui.tools).removeClass('mailpoet_display_tools');
this.toolsView.triggerMethod('hideTools');
}
},
toggleEditingLayer: function(event) {
toggleEditingLayer: function (event) {
var that = this,
$toggleButton = this.$('> .mailpoet_tools .mailpoet_newsletter_layer_selector'),
$overlay = jQuery('.mailpoet_layer_overlay'),
$container = this.$('> .mailpoet_container'),
enableContainerLayer = function() {
enableContainerLayer = function () {
that.$el.addClass('mailpoet_container_layer_active');
$toggleButton.addClass('mailpoet_container_layer_active');
$container.addClass('mailpoet_layer_highlight');
$overlay.click(disableContainerLayer);
$overlay.show();
},
disableContainerLayer = function() {
disableContainerLayer = function () {
that.$el.removeClass('mailpoet_container_layer_active');
$toggleButton.removeClass('mailpoet_container_layer_active');
$container.removeClass('mailpoet_layer_highlight');
@ -218,11 +218,11 @@ define([
});
Module.ContainerBlockEmptyView = Marionette.View.extend({
getTemplate: function() { return window.templates.containerEmpty; },
initialize: function(options) {
getTemplate: function () { return window.templates.containerEmpty; },
initialize: function (options) {
this.renderOptions = _.defaults(options.renderOptions || {}, {});
},
templateContext: function() {
templateContext: function () {
return {
isRoot: this.renderOptions.depth === 0,
emptyContainerMessage: this.renderOptions.emptyContainerMessage || ''
@ -231,12 +231,12 @@ define([
});
Module.ContainerBlockToolsView = base.BlockToolsView.extend({
getSettingsView: function() { return Module.ContainerBlockSettingsView; }
getSettingsView: function () { return Module.ContainerBlockSettingsView; }
});
Module.ContainerBlockSettingsView = base.BlockSettingsView.extend({
getTemplate: function() { return window.templates.containerBlockSettings; },
events: function() {
getTemplate: function () { return window.templates.containerBlockSettings; },
events: function () {
return {
'change .mailpoet_field_container_background_color': _.partial(this.changeColorField, 'styles.block.backgroundColor'),
'click .mailpoet_done_editing': 'close'
@ -245,21 +245,21 @@ define([
regions: {
columnsSettingsRegion: '.mailpoet_container_columns_settings'
},
initialize: function() {
initialize: function () {
base.BlockSettingsView.prototype.initialize.apply(this, arguments);
this._columnsSettingsView = new (Module.ContainerBlockColumnsSettingsView)({
collection: this.model.get('blocks')
});
},
onRender: function() {
onRender: function () {
this.showChildView('columnsSettingsRegion', this._columnsSettingsView);
}
});
Module.ContainerBlockColumnsSettingsView = Marionette.CollectionView.extend({
childView: function() { return Module.ContainerBlockColumnSettingsView; },
childViewOptions: function(model, index) {
childView: function () { return Module.ContainerBlockColumnSettingsView; },
childViewOptions: function (model, index) {
return {
columnIndex: index
};
@ -267,11 +267,11 @@ define([
});
Module.ContainerBlockColumnSettingsView = Marionette.View.extend({
getTemplate: function() { return window.templates.containerBlockColumnSettings; },
initialize: function(options) {
getTemplate: function () { return window.templates.containerBlockColumnSettings; },
initialize: function (options) {
this.columnNumber = (options.columnIndex || 0) + 1;
},
templateContext: function() {
templateContext: function () {
return {
model: this.model.toJSON(),
columnNumber: this.columnNumber
@ -281,11 +281,11 @@ define([
Module.OneColumnContainerWidgetView = base.WidgetView.extend({
className: base.WidgetView.prototype.className + ' mailpoet_droppable_layout_block',
getTemplate: function() { return window.templates.oneColumnLayoutInsertion; },
getTemplate: function () { return window.templates.oneColumnLayoutInsertion; },
behaviors: {
DraggableBehavior: {
cloneOriginal: true,
drop: function() {
drop: function () {
return new Module.ContainerBlockModel({
orientation: 'horizontal',
blocks: [
@ -299,11 +299,11 @@ define([
Module.TwoColumnContainerWidgetView = base.WidgetView.extend({
className: base.WidgetView.prototype.className + ' mailpoet_droppable_layout_block',
getTemplate: function() { return window.templates.twoColumnLayoutInsertion; },
getTemplate: function () { return window.templates.twoColumnLayoutInsertion; },
behaviors: {
DraggableBehavior: {
cloneOriginal: true,
drop: function() {
drop: function () {
return new Module.ContainerBlockModel({
orientation: 'horizontal',
blocks: [
@ -318,11 +318,11 @@ define([
Module.ThreeColumnContainerWidgetView = base.WidgetView.extend({
className: base.WidgetView.prototype.className + ' mailpoet_droppable_layout_block',
getTemplate: function() { return window.templates.threeColumnLayoutInsertion; },
getTemplate: function () { return window.templates.threeColumnLayoutInsertion; },
behaviors: {
DraggableBehavior: {
cloneOriginal: true,
drop: function() {
drop: function () {
return new Module.ContainerBlockModel({
orientation: 'horizontal',
blocks: [
@ -336,7 +336,7 @@ define([
}
});
App.on('before:start', function(App, options) {
App.on('before:start', function (App, options) {
App.registerBlockType('container', {
blockModel: Module.ContainerBlockModel,
blockView: Module.ContainerBlockView

View File

@ -7,7 +7,7 @@ define([
'underscore',
'jquery',
'mailpoet'
], function(App, BaseBlock, _, jQuery, MailPoet) {
], function (App, BaseBlock, _, jQuery, MailPoet) {
'use strict';
@ -15,7 +15,7 @@ define([
base = BaseBlock;
Module.DividerBlockModel = base.BlockModel.extend({
defaults: function() {
defaults: function () {
return this._getDefaults({
type: 'divider',
styles: {
@ -33,13 +33,13 @@ define([
Module.DividerBlockView = base.BlockView.extend({
className: 'mailpoet_block mailpoet_divider_block mailpoet_droppable_block',
getTemplate: function() { return window.templates.dividerBlock; },
getTemplate: function () { return window.templates.dividerBlock; },
modelEvents: _.omit(base.BlockView.prototype.modelEvents, 'change'),
behaviors: _.defaults({
ResizableBehavior: {
elementSelector: '.mailpoet_content',
resizeHandleSelector: '.mailpoet_resize_handle',
transformationFunction: function(y) { return y / 2; },
transformationFunction: function (y) { return y / 2; },
minLength: 0, // TODO: Move this number to editor configuration
modelField: 'styles.block.padding'
},
@ -47,32 +47,32 @@ define([
ignoreFrom: '.mailpoet_resize_handle'
}
}, base.BlockView.prototype.behaviors),
onDragSubstituteBy: function() { return Module.DividerWidgetView; },
initialize: function() {
onDragSubstituteBy: function () { return Module.DividerWidgetView; },
initialize: function () {
base.BlockView.prototype.initialize.apply(this, arguments);
var that = this;
// Listen for attempts to change all dividers in one go
this._replaceDividerHandler = function(data) { that.model.set(data); that.model.trigger('applyToAll'); };
this._replaceDividerHandler = function (data) { that.model.set(data); that.model.trigger('applyToAll'); };
App.getChannel().on('replaceAllDividers', this._replaceDividerHandler);
this.listenTo(this.model, 'change:src change:styles.block.backgroundColor change:styles.block.borderStyle change:styles.block.borderWidth change:styles.block.borderColor applyToAll', this.render);
this.listenTo(this.model, 'change:styles.block.padding', this.changePadding);
},
templateContext: function() {
templateContext: function () {
return _.extend({
totalHeight: parseInt(this.model.get('styles.block.padding'), 10)*2 + parseInt(this.model.get('styles.block.borderWidth')) + 'px'
}, base.BlockView.prototype.templateContext.apply(this));
},
onRender: function() {
onRender: function () {
this.toolsView = new Module.DividerBlockToolsView({ model: this.model });
this.showChildView('toolsRegion', this.toolsView);
},
onBeforeDestroy: function() {
onBeforeDestroy: function () {
App.getChannel().off('replaceAllDividers', this._replaceDividerHandler);
this.stopListening(this.model);
},
changePadding: function() {
changePadding: function () {
this.$('.mailpoet_content').css('padding-top', this.model.get('styles.block.padding'));
this.$('.mailpoet_content').css('padding-bottom', this.model.get('styles.block.padding'));
this.$('.mailpoet_resize_handle_text').text(parseInt(this.model.get('styles.block.padding'), 10)*2 + parseInt(this.model.get('styles.block.borderWidth')) + 'px');
@ -80,12 +80,12 @@ define([
});
Module.DividerBlockToolsView = base.BlockToolsView.extend({
getSettingsView: function() { return Module.DividerBlockSettingsView; }
getSettingsView: function () { return Module.DividerBlockSettingsView; }
});
Module.DividerBlockSettingsView = base.BlockSettingsView.extend({
getTemplate: function() { return window.templates.dividerBlockSettings; },
events: function() {
getTemplate: function () { return window.templates.dividerBlockSettings; },
events: function () {
return {
'click .mailpoet_field_divider_style': 'changeStyle',
@ -99,47 +99,47 @@ define([
'click .mailpoet_done_editing': 'close'
};
},
modelEvents: function() {
modelEvents: function () {
return {
'change:styles.block.borderColor': 'repaintDividerStyleOptions'
};
},
templateContext: function() {
templateContext: function () {
return _.extend({}, base.BlockView.prototype.templateContext.apply(this, arguments), {
availableStyles: App.getAvailableStyles().toJSON(),
renderOptions: this.renderOptions
});
},
changeStyle: function(event) {
changeStyle: function (event) {
var style = jQuery(event.currentTarget).data('style');
this.model.set('styles.block.borderStyle', style);
this.$('.mailpoet_field_divider_style').removeClass('mailpoet_active_divider_style');
this.$('.mailpoet_field_divider_style[data-style="' + style + '"]').addClass('mailpoet_active_divider_style');
},
repaintDividerStyleOptions: function() {
repaintDividerStyleOptions: function () {
this.$('.mailpoet_field_divider_style > div').css('border-top-color', this.model.get('styles.block.borderColor'));
},
applyToAll: function(event) {
applyToAll: function (event) {
App.getChannel().trigger('replaceAllDividers', this.model.toJSON());
},
updateValueAndCall: function(fieldToUpdate, callable, event) {
updateValueAndCall: function (fieldToUpdate, callable, event) {
this.$(fieldToUpdate).val(jQuery(event.target).val());
callable(event);
}
});
Module.DividerWidgetView = base.WidgetView.extend({
getTemplate: function() { return window.templates.dividerInsertion; },
getTemplate: function () { return window.templates.dividerInsertion; },
behaviors: {
DraggableBehavior: {
cloneOriginal: true,
drop: function() {
drop: function () {
return new Module.DividerBlockModel();
}
}
}
});
App.on('before:start', function(App, options) {
App.on('before:start', function (App, options) {
App.registerBlockType('divider', {
blockModel: Module.DividerBlockModel,
blockView: Module.DividerBlockView

View File

@ -6,7 +6,7 @@ define([
'newsletter_editor/blocks/base',
'underscore',
'mailpoet'
], function(App, BaseBlock, _, MailPoet) {
], function (App, BaseBlock, _, MailPoet) {
'use strict';
@ -14,7 +14,7 @@ define([
base = BaseBlock;
Module.FooterBlockModel = base.BlockModel.extend({
defaults: function() {
defaults: function () {
return this._getDefaults({
type: 'footer',
text: '<a href="[link:subscription_unsubscribe_url]">Unsubscribe</a> | <a href="[link:subscription_manage_url]">Manage subscription</a><br /><b>Add your postal address here!</b>',
@ -39,13 +39,13 @@ define([
Module.FooterBlockView = base.BlockView.extend({
className: 'mailpoet_block mailpoet_footer_block mailpoet_droppable_block',
getTemplate: function() { return window.templates.footerBlock; },
getTemplate: function () { return window.templates.footerBlock; },
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'
}, _.omit(base.BlockView.prototype.modelEvents, 'change')),
behaviors: _.extend({}, base.BlockView.prototype.behaviors, {
TextEditorBehavior: {
configurationFilter: function(originalSettings) {
configurationFilter: function (originalSettings) {
return _.extend({}, originalSettings, {
mailpoet_shortcodes: App.getConfig().get('shortcodes').toJSON(),
mailpoet_shortcodes_window_title: MailPoet.I18n.t('shortcodesWindowTitle')
@ -53,37 +53,37 @@ define([
}
}
}),
onDragSubstituteBy: function() { return Module.FooterWidgetView; },
onRender: function() {
onDragSubstituteBy: function () { return Module.FooterWidgetView; },
onRender: function () {
this.toolsView = new Module.FooterBlockToolsView({ model: this.model });
this.showChildView('toolsRegion', this.toolsView);
},
onTextEditorChange: function(newContent) {
onTextEditorChange: function (newContent) {
this.model.set('text', newContent);
},
onTextEditorFocus: function() {
onTextEditorFocus: function () {
this.disableDragging();
this.disableShowingTools();
},
onTextEditorBlur: function() {
onTextEditorBlur: function () {
this.enableDragging();
this.enableShowingTools();
}
});
Module.FooterBlockToolsView = base.BlockToolsView.extend({
getSettingsView: function() { return Module.FooterBlockSettingsView; }
getSettingsView: function () { return Module.FooterBlockSettingsView; }
});
Module.FooterBlockSettingsView = base.BlockSettingsView.extend({
getTemplate: function() { return window.templates.footerBlockSettings; },
events: function() {
getTemplate: function () { return window.templates.footerBlockSettings; },
events: function () {
return {
'change .mailpoet_field_footer_text_color': _.partial(this.changeColorField, 'styles.text.fontColor'),
'change .mailpoet_field_footer_text_font_family': _.partial(this.changeField, 'styles.text.fontFamily'),
'change .mailpoet_field_footer_text_size': _.partial(this.changeField, 'styles.text.fontSize'),
'change #mailpoet_field_footer_link_color': _.partial(this.changeColorField, 'styles.link.fontColor'),
'change #mailpoet_field_footer_link_underline': function(event) {
'change #mailpoet_field_footer_link_underline': function (event) {
this.model.set('styles.link.textDecoration', (event.target.checked) ? event.target.value : 'none');
},
'change .mailpoet_field_footer_background_color': _.partial(this.changeColorField, 'styles.block.backgroundColor'),
@ -91,7 +91,7 @@ define([
'click .mailpoet_done_editing': 'close'
};
},
templateContext: function() {
templateContext: function () {
return _.extend({}, base.BlockView.prototype.templateContext.apply(this, arguments), {
availableStyles: App.getAvailableStyles().toJSON()
});
@ -99,18 +99,18 @@ define([
});
Module.FooterWidgetView = base.WidgetView.extend({
getTemplate: function() { return window.templates.footerInsertion; },
getTemplate: function () { return window.templates.footerInsertion; },
behaviors: {
DraggableBehavior: {
cloneOriginal: true,
drop: function() {
drop: function () {
return new Module.FooterBlockModel();
}
}
}
});
App.on('before:start', function(App, options) {
App.on('before:start', function (App, options) {
App.registerBlockType('footer', {
blockModel: Module.FooterBlockModel,
blockView: Module.FooterBlockView

View File

@ -6,7 +6,7 @@ define([
'newsletter_editor/blocks/base',
'underscore',
'mailpoet'
], function(App, BaseBlock, _, MailPoet) {
], function (App, BaseBlock, _, MailPoet) {
'use strict';
@ -14,7 +14,7 @@ define([
base = BaseBlock;
Module.HeaderBlockModel = base.BlockModel.extend({
defaults: function() {
defaults: function () {
return this._getDefaults({
type: 'header',
text: 'Display problems? <a href="[link:newsletter_view_in_browser_url]">View it in your browser</a>',
@ -39,13 +39,13 @@ define([
Module.HeaderBlockView = base.BlockView.extend({
className: 'mailpoet_block mailpoet_header_block mailpoet_droppable_block',
getTemplate: function() { return window.templates.headerBlock; },
getTemplate: function () { return window.templates.headerBlock; },
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'
}, _.omit(base.BlockView.prototype.modelEvents, 'change')),
behaviors: _.extend({}, base.BlockView.prototype.behaviors, {
TextEditorBehavior: {
configurationFilter: function(originalSettings) {
configurationFilter: function (originalSettings) {
return _.extend({}, originalSettings, {
mailpoet_shortcodes: App.getConfig().get('shortcodes').toJSON(),
mailpoet_shortcodes_window_title: MailPoet.I18n.t('shortcodesWindowTitle')
@ -53,37 +53,37 @@ define([
}
}
}),
onDragSubstituteBy: function() { return Module.HeaderWidgetView; },
onRender: function() {
onDragSubstituteBy: function () { return Module.HeaderWidgetView; },
onRender: function () {
this.toolsView = new Module.HeaderBlockToolsView({ model: this.model });
this.showChildView('toolsRegion', this.toolsView);
},
onTextEditorChange: function(newContent) {
onTextEditorChange: function (newContent) {
this.model.set('text', newContent);
},
onTextEditorFocus: function() {
onTextEditorFocus: function () {
this.disableDragging();
this.disableShowingTools();
},
onTextEditorBlur: function() {
onTextEditorBlur: function () {
this.enableDragging();
this.enableShowingTools();
}
});
Module.HeaderBlockToolsView = base.BlockToolsView.extend({
getSettingsView: function() { return Module.HeaderBlockSettingsView; }
getSettingsView: function () { return Module.HeaderBlockSettingsView; }
});
Module.HeaderBlockSettingsView = base.BlockSettingsView.extend({
getTemplate: function() { return window.templates.headerBlockSettings; },
events: function() {
getTemplate: function () { return window.templates.headerBlockSettings; },
events: function () {
return {
'change .mailpoet_field_header_text_color': _.partial(this.changeColorField, 'styles.text.fontColor'),
'change .mailpoet_field_header_text_font_family': _.partial(this.changeField, 'styles.text.fontFamily'),
'change .mailpoet_field_header_text_size': _.partial(this.changeField, 'styles.text.fontSize'),
'change #mailpoet_field_header_link_color': _.partial(this.changeColorField, 'styles.link.fontColor'),
'change #mailpoet_field_header_link_underline': function(event) {
'change #mailpoet_field_header_link_underline': function (event) {
this.model.set('styles.link.textDecoration', (event.target.checked) ? event.target.value : 'none');
},
'change .mailpoet_field_header_background_color': _.partial(this.changeColorField, 'styles.block.backgroundColor'),
@ -91,7 +91,7 @@ define([
'click .mailpoet_done_editing': 'close'
};
},
templateContext: function() {
templateContext: function () {
return _.extend({}, base.BlockView.prototype.templateContext.apply(this, arguments), {
availableStyles: App.getAvailableStyles().toJSON()
});
@ -99,18 +99,18 @@ define([
});
Module.HeaderWidgetView = base.WidgetView.extend({
getTemplate: function() { return window.templates.headerInsertion; },
getTemplate: function () { return window.templates.headerInsertion; },
behaviors: {
DraggableBehavior: {
cloneOriginal: true,
drop: function() {
drop: function () {
return new Module.HeaderBlockModel();
}
}
}
});
App.on('before:start', function(App, options) {
App.on('before:start', function (App, options) {
App.registerBlockType('header', {
blockModel: Module.HeaderBlockModel,
blockView: Module.HeaderBlockView

View File

@ -7,7 +7,7 @@ define([
'underscore',
'mailpoet',
'jquery'
], function(App, BaseBlock, _, MailPoet, jQuery) {
], function (App, BaseBlock, _, MailPoet, jQuery) {
'use strict';
@ -16,7 +16,7 @@ define([
ImageWidgetView;
Module.ImageBlockModel = base.BlockModel.extend({
defaults: function() {
defaults: function () {
return this._getDefaults({
type: 'image',
link: '',
@ -36,9 +36,9 @@ define([
Module.ImageBlockView = base.BlockView.extend({
className: 'mailpoet_block mailpoet_image_block mailpoet_droppable_block',
getTemplate: function() { return window.templates.imageBlock; },
onDragSubstituteBy: function() { return Module.ImageWidgetView; },
templateContext: function() {
getTemplate: function () { return window.templates.imageBlock; },
onDragSubstituteBy: function () { return Module.ImageWidgetView; },
templateContext: function () {
return _.extend({
imageMissingSrc: App.getConfig().get('urls.imageMissing')
}, base.BlockView.prototype.templateContext.apply(this));
@ -46,7 +46,7 @@ define([
behaviors: _.extend({}, base.BlockView.prototype.behaviors, {
ShowSettingsBehavior: {}
}),
onRender: function() {
onRender: function () {
this.toolsView = new Module.ImageBlockToolsView({ model: this.model });
this.showChildView('toolsRegion', this.toolsView);
@ -59,11 +59,11 @@ define([
});
Module.ImageBlockToolsView = base.BlockToolsView.extend({
getSettingsView: function() { return Module.ImageBlockSettingsView; }
getSettingsView: function () { return Module.ImageBlockSettingsView; }
});
Module.ImageBlockSettingsView = base.BlockSettingsView.extend({
onRender: function() {
onRender: function () {
MailPoet.helpTooltip.show(document.getElementById('tooltip-designer-full-width'), {
tooltipId: 'tooltip-editor-full-width',
tooltip: MailPoet.I18n.t('helpTooltipDesignerFullWidth')
@ -73,8 +73,8 @@ define([
tooltip: MailPoet.I18n.t('helpTooltipDesignerIdealWidth')
});
},
getTemplate: function() { return window.templates.imageBlockSettings; },
events: function() {
getTemplate: function () { return window.templates.imageBlockSettings; },
events: function () {
return {
'input .mailpoet_field_image_link': _.partial(this.changeField, 'link'),
'input .mailpoet_field_image_address': 'changeAddress',
@ -85,14 +85,14 @@ define([
'click .mailpoet_done_editing': 'close'
};
},
initialize: function(options) {
initialize: function (options) {
base.BlockSettingsView.prototype.initialize.apply(this, arguments);
if (options.showImageManager) {
this.showMediaManager();
}
},
showMediaManager: function() {
showMediaManager: function () {
if (this._mediaManager) {
this._mediaManager.resetSelections();
this._mediaManager.open();
@ -101,7 +101,7 @@ define([
var MediaManager = window.wp.media.view.MediaFrame.Select.extend({
initialize: function() {
initialize: function () {
window.wp.media.view.MediaFrame.prototype.initialize.apply(this, arguments);
_.defaults(this.options, {
@ -119,16 +119,16 @@ define([
this.$el.addClass('hide-title');
},
resetSelections: function() {
resetSelections: function () {
this.state().get('selection').reset();
},
createQuery: function(options) {
createQuery: function (options) {
var query = window.wp.media.query(options);
return query;
},
createStates: function() {
createStates: function () {
var options = this.options;
// Add the default states.
@ -161,7 +161,7 @@ define([
}
},
bindHandlers: function() {
bindHandlers: function () {
// from Select
this.on('router:create:browse', this.createRouter, this);
this.on('router:render:browse', this.browseRouter, this);
@ -186,20 +186,20 @@ define([
}
};
_.each(handlers, function(regionHandlers, region) {
_.each(regionHandlers, function(callback, handler) {
_.each(handlers, function (regionHandlers, region) {
_.each(regionHandlers, function (callback, handler) {
this.on(region + ':render:' + handler, this[callback], this);
}, this);
}, this);
},
uploadContent: function() {
uploadContent: function () {
window.wp.media.view.MediaFrame.Select.prototype.uploadContent.apply(this, arguments);
this.$el.addClass('hide-toolbar');
},
// Content
embedContent: function() {
embedContent: function () {
var view = new window.wp.media.view.Embed({
controller: this,
model: this.state()
@ -209,7 +209,7 @@ define([
view.url.focus();
},
editSelectionContent: function() {
editSelectionContent: function () {
var state = this.state(),
selection = state.get('selection'),
view;
@ -230,7 +230,7 @@ define([
text: 'Return to library',
priority: -100,
click: function() {
click: function () {
this.controller.content.mode('browse');
}
});
@ -240,7 +240,7 @@ define([
},
// Toolbars
selectionStatusToolbar: function(view) {
selectionStatusToolbar: function (view) {
var editable = this.state().get('editable');
view.set('selection', new window.wp.media.view.Selection({
@ -250,13 +250,13 @@ define([
// If the selection is editable, pass the callback to
// switch the content mode.
editable: editable && function() {
editable: editable && function () {
this.controller.content.mode('edit-selection');
}
}).render() );
},
mainInsertToolbar: function(view) {
mainInsertToolbar: function (view) {
var controller = this;
this.selectionStatusToolbar(view);
@ -267,7 +267,7 @@ define([
text: 'Select Image',
requires: { selection: true },
click: function() {
click: function () {
var state = controller.state(),
selection = state.get('selection');
@ -277,7 +277,7 @@ define([
});
},
mainEmbedToolbar: function(toolbar) {
mainEmbedToolbar: function (toolbar) {
var tbar = toolbar;
tbar.view = new window.wp.media.view.Toolbar.Embed({
controller: this,
@ -304,10 +304,10 @@ define([
that = this;
this._mediaManager = theFrame;
this._mediaManager.on('insert', function() {
this._mediaManager.on('insert', function () {
// Append media manager image selections to Images tab
var selection = theFrame.state().get('selection');
selection.each(function(attachment) {
selection.each(function (attachment) {
var sizes = attachment.get('sizes'),
// Following advice from Becs, the target width should
// be a double of one column width to render well on
@ -320,13 +320,13 @@ define([
// Pick the width that is closest to target width
increasingByWidthDifference = _.sortBy(
_.keys(sizes),
function(size) { return Math.abs(targetImageWidth - sizes[size].width); }
function (size) { return Math.abs(targetImageWidth - sizes[size].width); }
),
bestWidth = sizes[_.first(increasingByWidthDifference)].width,
imagesOfBestWidth = _.filter(_.values(sizes), function(size) { return size.width === bestWidth; }),
imagesOfBestWidth = _.filter(_.values(sizes), function (size) { return size.width === bestWidth; }),
// Maximize the height if there are multiple images with same width
mainSize = _.max(imagesOfBestWidth, function(size) { return size.height; });
mainSize = _.max(imagesOfBestWidth, function (size) { return size.height; });
that.model.set({
height: mainSize.height + 'px',
@ -341,11 +341,11 @@ define([
this._mediaManager.open();
},
changeAddress: function(event) {
changeAddress: function (event) {
var src = jQuery(event.target).val();
var image = new Image();
image.onload = function() {
image.onload = function () {
this.model.set({
src: src,
width: image.naturalWidth + 'px',
@ -355,7 +355,7 @@ define([
image.src = src;
},
onBeforeDestroy: function() {
onBeforeDestroy: function () {
base.BlockSettingsView.prototype.onBeforeDestroy.apply(this, arguments);
if (typeof this._mediaManager === 'object') {
this._mediaManager.remove();
@ -364,14 +364,14 @@ define([
});
ImageWidgetView = base.WidgetView.extend({
getTemplate: function() { return window.templates.imageInsertion; },
getTemplate: function () { return window.templates.imageInsertion; },
behaviors: {
DraggableBehavior: {
cloneOriginal: true,
drop: function() {
drop: function () {
return new Module.ImageBlockModel();
},
onDrop: function(options) {
onDrop: function (options) {
options.droppedView.triggerMethod('showSettings', { showImageManager: true });
}
}
@ -379,7 +379,7 @@ define([
});
Module.ImageWidgetView = ImageWidgetView;
App.on('before:start', function(App, options) {
App.on('before:start', function (App, options) {
App.registerBlockType('image', {
blockModel: Module.ImageBlockModel,
blockView: Module.ImageBlockView

View File

@ -23,7 +23,7 @@ define([
'newsletter_editor/blocks/button',
'newsletter_editor/blocks/divider',
'select2'
], function(
], function (
Backbone,
Marionette,
Radio,
@ -44,7 +44,7 @@ define([
Module.PostsBlockModel = base.BlockModel.extend({
stale: ['_selectedPosts', '_availablePosts', '_transformedPosts'],
defaults: function() {
defaults: function () {
return this._getDefaults({
type: 'posts',
amount: '10',
@ -79,7 +79,7 @@ define([
_transformedPosts: new (App.getBlockTypeModel('container'))()
}, App.getConfig().get('blockDefaults.posts'));
},
relations: function() {
relations: function () {
return {
readMoreButton: App.getBlockTypeModel('button'),
divider: App.getBlockTypeModel('divider'),
@ -88,7 +88,7 @@ define([
_transformedPosts: App.getBlockTypeModel('container')
};
},
initialize: function() {
initialize: function () {
var that = this,
POST_REFRESH_DELAY_MS = 500,
refreshAvailablePosts = _.debounce(this.fetchAvailablePosts.bind(this), POST_REFRESH_DELAY_MS),
@ -108,18 +108,18 @@ define([
this.on('insertSelectedPosts', this._insertSelectedPosts, this);
},
fetchAvailablePosts: function() {
fetchAvailablePosts: function () {
var that = this;
this.set('offset', 0);
CommunicationComponent.getPosts(this.toJSON()).done(function(posts) {
CommunicationComponent.getPosts(this.toJSON()).done(function (posts) {
that.get('_availablePosts').reset(posts);
that.get('_selectedPosts').reset(); // Empty out the collection
that.trigger('change:_availablePosts');
}).fail(function() {
}).fail(function () {
MailPoet.Notice.error(MailPoet.I18n.t('failedToFetchAvailablePosts'));
});
},
_loadMorePosts: function() {
_loadMorePosts: function () {
var that = this,
postCount = this.get('_availablePosts').length,
nextOffset = this.get('offset') + Number(this.get('amount'));
@ -131,16 +131,16 @@ define([
this.set('offset', nextOffset);
this.trigger('loadingMorePosts');
CommunicationComponent.getPosts(this.toJSON()).done(function(posts) {
CommunicationComponent.getPosts(this.toJSON()).done(function (posts) {
that.get('_availablePosts').add(posts);
that.trigger('change:_availablePosts');
}).fail(function() {
}).fail(function () {
MailPoet.Notice.error(MailPoet.I18n.t('failedToFetchAvailablePosts'));
}).always(function() {
}).always(function () {
that.trigger('morePostsLoaded');
});
},
_refreshTransformedPosts: function() {
_refreshTransformedPosts: function () {
var that = this,
data = this.toJSON();
@ -151,13 +151,13 @@ define([
return;
}
CommunicationComponent.getTransformedPosts(data).done(function(posts) {
CommunicationComponent.getTransformedPosts(data).done(function (posts) {
that.get('_transformedPosts').get('blocks').reset(posts, {parse: true});
}).fail(function() {
}).fail(function () {
MailPoet.Notice.error(MailPoet.I18n.t('failedToFetchRenderedPosts'));
});
},
_insertSelectedPosts: function() {
_insertSelectedPosts: function () {
var that = this,
data = this.toJSON(),
index = this.collection.indexOf(this),
@ -167,9 +167,9 @@ define([
if (data.posts.length === 0) return;
CommunicationComponent.getTransformedPosts(data).done(function(posts) {
CommunicationComponent.getTransformedPosts(data).done(function (posts) {
collection.add(posts, { at: index });
}).fail(function() {
}).fail(function () {
MailPoet.Notice.error(MailPoet.I18n.t('failedToFetchRenderedPosts'));
});
}
@ -177,19 +177,19 @@ define([
Module.PostsBlockView = base.BlockView.extend({
className: 'mailpoet_block mailpoet_posts_block mailpoet_droppable_block',
getTemplate: function() { return window.templates.postsBlock; },
getTemplate: function () { return window.templates.postsBlock; },
modelEvents: {}, // Forcefully disable all events
regions: _.extend({
postsRegion: '.mailpoet_posts_block_posts'
}, base.BlockView.prototype.regions),
onDragSubstituteBy: function() { return Module.PostsWidgetView; },
initialize: function() {
onDragSubstituteBy: function () { return Module.PostsWidgetView; },
initialize: function () {
base.BlockView.prototype.initialize.apply(this, arguments);
this.toolsView = new Module.PostsBlockToolsView({ model: this.model });
this.model.reply('blockView', this.notifyAboutSelf, this);
},
onRender: function() {
onRender: function () {
if (!this.getRegion('toolsRegion').hasView()) {
this.showChildView('toolsRegion', this.toolsView);
}
@ -203,20 +203,20 @@ define([
};
this.showChildView('postsRegion', new ContainerView({ model: this.model.get('_transformedPosts'), renderOptions: renderOptions }));
},
notifyAboutSelf: function() {
notifyAboutSelf: function () {
return this;
},
onBeforeDestroy: function() {
onBeforeDestroy: function () {
this.model.stopReplying('blockView', this.notifyAboutSelf, this);
}
});
Module.PostsBlockToolsView = base.BlockToolsView.extend({
getSettingsView: function() { return Module.PostsBlockSettingsView; }
getSettingsView: function () { return Module.PostsBlockSettingsView; }
});
Module.PostsBlockSettingsView = base.BlockSettingsView.extend({
getTemplate: function() { return window.templates.postsBlockSettings; },
getTemplate: function () { return window.templates.postsBlockSettings; },
regions: {
selectionRegion: '.mailpoet_settings_posts_selection',
displayOptionsRegion: '.mailpoet_settings_posts_display_options'
@ -226,17 +226,17 @@ define([
'click .mailpoet_settings_posts_show_post_selection': 'switchToPostSelection',
'click .mailpoet_settings_posts_insert_selected': 'insertPosts'
},
templateContext: function() {
templateContext: function () {
return {
model: this.model.toJSON()
};
},
initialize: function() {
initialize: function () {
this.model.trigger('startEditing');
this.selectionView = new PostSelectionSettingsView({ model: this.model });
this.displayOptionsView = new PostsDisplayOptionsSettingsView({ model: this.model });
},
onRender: function() {
onRender: function () {
var that = this,
blockView = this.model.request('blockView');
@ -248,7 +248,7 @@ define([
template: '',
position: 'right',
width: App.getConfig().get('sidepanelWidth'),
onCancel: function() {
onCancel: function () {
// Self destroy the block if the user closes settings modal
that.model.destroy();
}
@ -258,7 +258,7 @@ define([
this.selectionView.triggerMethod('attach');
this.displayOptionsView.triggerMethod('attach');
},
switchToDisplayOptions: function() {
switchToDisplayOptions: function () {
// Switch content view
this.$('.mailpoet_settings_posts_selection').addClass('mailpoet_closed');
this.$('.mailpoet_settings_posts_display_options').removeClass('mailpoet_closed');
@ -267,7 +267,7 @@ define([
this.$('.mailpoet_settings_posts_show_display_options').addClass('mailpoet_hidden');
this.$('.mailpoet_settings_posts_show_post_selection').removeClass('mailpoet_hidden');
},
switchToPostSelection: function() {
switchToPostSelection: function () {
// Switch content view
this.$('.mailpoet_settings_posts_display_options').addClass('mailpoet_closed');
this.$('.mailpoet_settings_posts_selection').removeClass('mailpoet_closed');
@ -276,7 +276,7 @@ define([
this.$('.mailpoet_settings_posts_show_post_selection').addClass('mailpoet_hidden');
this.$('.mailpoet_settings_posts_show_display_options').removeClass('mailpoet_hidden');
},
insertPosts: function() {
insertPosts: function () {
this.model.trigger('insertSelectedPosts');
this.model.destroy();
this.close();
@ -285,20 +285,20 @@ define([
var PostsSelectionCollectionView = Marionette.CollectionView.extend({
className: 'mailpoet_post_scroll_container',
childView: function() { return SinglePostSelectionSettingsView; },
emptyView: function() { return EmptyPostSelectionSettingsView; },
childViewOptions: function() {
childView: function () { return SinglePostSelectionSettingsView; },
emptyView: function () { return EmptyPostSelectionSettingsView; },
childViewOptions: function () {
return {
blockModel: this.blockModel
};
},
initialize: function(options) {
initialize: function (options) {
this.blockModel = options.blockModel;
},
events: {
scroll: 'onPostsScroll'
},
onPostsScroll: function(event) {
onPostsScroll: function (event) {
var $postsBox = jQuery(event.target);
if($postsBox.scrollTop() + $postsBox.innerHeight() >= $postsBox[0].scrollHeight){
// Load more posts if scrolled to bottom
@ -308,11 +308,11 @@ define([
});
var PostSelectionSettingsView = Marionette.View.extend({
getTemplate: function() { return window.templates.postSelectionPostsBlockSettings; },
getTemplate: function () { return window.templates.postSelectionPostsBlockSettings; },
regions: {
posts: '.mailpoet_post_selection_container'
},
events: function() {
events: function () {
return {
'change .mailpoet_settings_posts_content_type': _.partial(this.changeField, 'contentType'),
'change .mailpoet_posts_post_status': _.partial(this.changeField, 'postStatus'),
@ -320,20 +320,20 @@ define([
};
},
modelEvents: {
'change:offset': function(model, value) {
'change:offset': function (model, value) {
// Scroll posts view to top if settings are changed
if (value === 0) {
this.$('.mailpoet_post_scroll_container').scrollTop(0);
}
},
loadingMorePosts: function() {
loadingMorePosts: function () {
this.$('.mailpoet_post_selection_loading').css('visibility', 'visible');
},
morePostsLoaded: function() {
morePostsLoaded: function () {
this.$('.mailpoet_post_selection_loading').css('visibility', 'hidden');
}
},
onRender: function() {
onRender: function () {
// Dynamically update available post types
CommunicationComponent.getPostTypes().done(_.bind(this._updateContentTypes, this));
var postsView = new PostsSelectionCollectionView({
@ -343,7 +343,7 @@ define([
this.showChildView('posts', postsView);
},
onAttach: function() {
onAttach: function () {
var that = this;
this.$('.mailpoet_posts_categories_and_tags').select2({
@ -356,17 +356,17 @@ define([
term: params.term
};
},
transport: function(options, success, failure) {
transport: function (options, success, failure) {
var taxonomies;
var promise = CommunicationComponent.getTaxonomies(
that.model.get('contentType')
).then(function(tax) {
).then(function (tax) {
taxonomies = tax;
// Fetch available terms based on the list of taxonomies already fetched
var promise = CommunicationComponent.getTerms({
search: options.data.term,
taxonomies: _.keys(taxonomies)
}).then(function(terms) {
}).then(function (terms) {
return {
taxonomies: taxonomies,
terms: terms
@ -379,12 +379,12 @@ define([
promise.fail(failure);
return promise;
},
processResults: function(data) {
processResults: function (data) {
// Transform taxonomies and terms into select2 compatible format
return {
results: _.map(
data.terms,
function(item) {
function (item) {
return _.defaults({
text: data.taxonomies[item.taxonomy].labels.singular_name + ': ' + item.name,
id: item.term_id
@ -395,13 +395,13 @@ define([
}
}
}).on({
'select2:select': function(event) {
'select2:select': function (event) {
var terms = that.model.get('terms');
terms.add(event.params.data);
// Reset whole model in order for change events to propagate properly
that.model.set('terms', terms.toJSON());
},
'select2:unselect': function(event) {
'select2:unselect': function (event) {
var terms = that.model.get('terms');
terms.remove(event.params.data);
// Reset whole model in order for change events to propagate properly
@ -409,15 +409,15 @@ define([
}
}).trigger( 'change' );
},
changeField: function(field, event) {
changeField: function (field, event) {
this.model.set(field, jQuery(event.target).val());
},
_updateContentTypes: function(postTypes) {
_updateContentTypes: function (postTypes) {
var select = this.$('.mailpoet_settings_posts_content_type'),
selectedValue = this.model.get('contentType');
select.find('option').remove();
_.each(postTypes, function(type) {
_.each(postTypes, function (type) {
select.append(jQuery('<option>', {
value: type.name,
text: type.label
@ -428,26 +428,26 @@ define([
});
var EmptyPostSelectionSettingsView = Marionette.View.extend({
getTemplate: function() { return window.templates.emptyPostPostsBlockSettings; }
getTemplate: function () { return window.templates.emptyPostPostsBlockSettings; }
});
var SinglePostSelectionSettingsView = Marionette.View.extend({
getTemplate: function() { return window.templates.singlePostPostsBlockSettings; },
events: function() {
getTemplate: function () { return window.templates.singlePostPostsBlockSettings; },
events: function () {
return {
'change .mailpoet_select_post_checkbox': 'postSelectionChange'
};
},
templateContext: function() {
templateContext: function () {
return {
model: this.model.toJSON(),
index: this._index
};
},
initialize: function(options) {
initialize: function (options) {
this.blockModel = options.blockModel;
},
postSelectionChange: function(event) {
postSelectionChange: function (event) {
var checkBox = jQuery(event.target),
selectedPostsCollection = this.blockModel.get('_selectedPosts');
if (checkBox.prop('checked')) {
@ -459,8 +459,8 @@ define([
});
var PostsDisplayOptionsSettingsView = base.BlockSettingsView.extend({
getTemplate: function() { return window.templates.displayOptionsPostsBlockSettings; },
events: function() {
getTemplate: function () { return window.templates.displayOptionsPostsBlockSettings; },
events: function () {
return {
'click .mailpoet_posts_select_button': 'showButtonSettings',
'click .mailpoet_posts_select_divider': 'showDividerSettings',
@ -483,12 +483,12 @@ define([
'change .mailpoet_posts_sort_by': _.partial(this.changeField, 'sortBy')
};
},
templateContext: function() {
templateContext: function () {
return {
model: this.model.toJSON()
};
},
showButtonSettings: function(event) {
showButtonSettings: function (event) {
var buttonModule = ButtonBlock;
(new buttonModule.ButtonBlockSettingsView({
model: this.model.get('readMoreButton'),
@ -499,7 +499,7 @@ define([
}
})).render();
},
showDividerSettings: function(event) {
showDividerSettings: function (event) {
var dividerModule = DividerBlock;
(new dividerModule.DividerBlockSettingsView({
model: this.model.get('divider'),
@ -509,7 +509,7 @@ define([
}
})).render();
},
changeReadMoreType: function(event) {
changeReadMoreType: function (event) {
var value = jQuery(event.target).val();
if (value == 'link') {
this.$('.mailpoet_posts_read_more_text').removeClass('mailpoet_hidden');
@ -520,7 +520,7 @@ define([
}
this.changeField('readMoreType', event);
},
changeDisplayType: function(event) {
changeDisplayType: function (event) {
var value = jQuery(event.target).val();
if (value == 'titleOnly') {
this.$('.mailpoet_posts_title_as_list').removeClass('mailpoet_hidden');
@ -547,7 +547,7 @@ define([
this.changeField('displayType', event);
},
changeTitleFormat: function(event) {
changeTitleFormat: function (event) {
var value = jQuery(event.target).val();
if (value == 'ul') {
this.$('.mailpoet_posts_non_title_list_options').addClass('mailpoet_hidden');
@ -564,18 +564,18 @@ define([
});
Module.PostsWidgetView = base.WidgetView.extend({
getTemplate: function() { return window.templates.postsInsertion; },
getTemplate: function () { return window.templates.postsInsertion; },
behaviors: {
DraggableBehavior: {
cloneOriginal: true,
drop: function() {
drop: function () {
return new Module.PostsBlockModel({}, { parse: true });
}
}
}
});
App.on('before:start', function(App, options) {
App.on('before:start', function (App, options) {
App.registerBlockType('posts', {
blockModel: Module.PostsBlockModel,
blockView: Module.PostsBlockView

View File

@ -9,7 +9,7 @@ define([
'backbone.supermodel',
'underscore',
'jquery'
], function(App, BaseBlock, Backbone, Marionette, SuperModel, _, jQuery) {
], function (App, BaseBlock, Backbone, Marionette, SuperModel, _, jQuery) {
'use strict';
@ -21,7 +21,7 @@ define([
SocialBlockSettingsStylesView;
Module.SocialIconModel = SuperModel.extend({
defaults: function() {
defaults: function () {
var defaultValues = App.getConfig().get('socialIcons.custom');
return {
type: 'socialIcon',
@ -33,10 +33,10 @@ define([
text: defaultValues.get('title')
};
},
initialize: function(options) {
initialize: function (options) {
var that = this;
// Make model swap to default values for that type when iconType changes
this.on('change:iconType', function() {
this.on('change:iconType', function () {
var defaultValues = App.getConfig().get('socialIcons').get(that.get('iconType')),
iconSet = that.collection.iconBlockModel.getIconSet();
this.set({
@ -45,7 +45,7 @@ define([
text: defaultValues.get('title')
});
}, this);
this.on('change', function() { App.getChannel().trigger('autoSave'); });
this.on('change', function () { App.getChannel().trigger('autoSave'); });
}
});
@ -55,7 +55,7 @@ define([
Module.SocialBlockModel = base.BlockModel.extend({
name: 'iconBlockModel',
defaults: function() {
defaults: function () {
return this._getDefaults({
type: 'social',
iconSet: 'default',
@ -65,31 +65,31 @@ define([
relations: {
icons: Module.SocialIconCollectionModel
},
initialize: function() {
initialize: function () {
this.get('icons').on('add remove change', this._iconsChanged, this);
this.on('change:iconSet', this.changeIconSet, this);
},
getIconSet: function() {
getIconSet: function () {
return App.getAvailableStyles().get('socialIconSets').get(this.get('iconSet'));
},
changeIconSet: function() {
changeIconSet: function () {
var iconSet = this.getIconSet();
_.each(this.get('icons').models, function(model) {
_.each(this.get('icons').models, function (model) {
model.set('image', iconSet.get(model.get('iconType')));
});
},
_iconsChanged: function() {
_iconsChanged: function () {
App.getChannel().trigger('autoSave');
}
});
var SocialIconView = Marionette.View.extend({
tagName: 'span',
getTemplate: function() { return window.templates.socialIconBlock; },
getTemplate: function () { return window.templates.socialIconBlock; },
modelEvents: {
change: 'render'
},
templateContext: function() {
templateContext: function () {
var allIconSets = App.getAvailableStyles().get('socialIconSets');
return {
model: this.model.toJSON(),
@ -105,7 +105,7 @@ define([
Module.SocialBlockView = base.BlockView.extend({
className: 'mailpoet_block mailpoet_social_block mailpoet_droppable_block',
getTemplate: function() { return window.templates.socialBlock; },
getTemplate: function () { return window.templates.socialBlock; },
regions: _.extend({}, base.BlockView.prototype.regions, {
icons: '.mailpoet_social'
}),
@ -115,8 +115,8 @@ define([
behaviors: _.extend({}, base.BlockView.prototype.behaviors, {
ShowSettingsBehavior: {}
}),
onDragSubstituteBy: function() { return Module.SocialWidgetView; },
onRender: function() {
onDragSubstituteBy: function () { return Module.SocialWidgetView; },
onRender: function () {
this.toolsView = new Module.SocialBlockToolsView({ model: this.model });
this.showChildView('toolsRegion', this.toolsView);
this.showChildView('icons', new Module.SocialIconCollectionView({
@ -126,28 +126,28 @@ define([
});
Module.SocialBlockToolsView = base.BlockToolsView.extend({
getSettingsView: function() { return Module.SocialBlockSettingsView; }
getSettingsView: function () { return Module.SocialBlockSettingsView; }
});
// Sidebar view container
Module.SocialBlockSettingsView = base.BlockSettingsView.extend({
getTemplate: function() { return window.templates.socialBlockSettings; },
getTemplate: function () { return window.templates.socialBlockSettings; },
regions: {
iconRegion: '#mailpoet_social_icons_selection',
stylesRegion: '#mailpoet_social_icons_styles'
},
events: function() {
events: function () {
return {
'click .mailpoet_done_editing': 'close'
};
},
initialize: function() {
initialize: function () {
base.BlockSettingsView.prototype.initialize.apply(this, arguments);
this._iconSelectorView = new SocialBlockSettingsIconSelectorView({ model: this.model });
this._stylesView = new SocialBlockSettingsStylesView({ model: this.model });
},
onRender: function() {
onRender: function () {
this.showChildView('iconRegion', this._iconSelectorView);
this.showChildView('stylesRegion', this._stylesView);
}
@ -155,8 +155,8 @@ define([
// Single icon settings view, used by the selector view
SocialBlockSettingsIconView = Marionette.View.extend({
getTemplate: function() { return window.templates.socialSettingsIcon; },
events: function() {
getTemplate: function () { return window.templates.socialSettingsIcon; },
events: function () {
return {
'click .mailpoet_delete_block': 'deleteIcon',
'change .mailpoet_social_icon_field_type': _.partial(this.changeField, 'iconType'),
@ -167,17 +167,17 @@ define([
},
modelEvents: {
'change:iconType': 'render',
'change:image': function() {
'change:image': function () {
this.$('.mailpoet_social_icon_image').attr('src', this.model.get('image'));
},
'change:text': function() {
'change:text': function () {
this.$('.mailpoet_social_icon_image').attr('alt', this.model.get('text'));
}
},
templateContext: function() {
templateContext: function () {
var icons = App.getConfig().get('socialIcons'),
// Construct icon type list of format [{iconType: 'type', title: 'Title'}, ...]
availableIconTypes = _.map(_.keys(icons.attributes), function(key) { return { iconType: key, title: icons.get(key).get('title') }; }),
availableIconTypes = _.map(_.keys(icons.attributes), function (key) { return { iconType: key, title: icons.get(key).get('title') }; }),
allIconSets = App.getAvailableStyles().get('socialIconSets');
return _.extend({}, base.BlockView.prototype.templateContext.apply(this, arguments), {
iconTypes: availableIconTypes,
@ -185,17 +185,17 @@ define([
allIconSets: allIconSets.toJSON()
});
},
deleteIcon: function() {
deleteIcon: function () {
this.model.destroy();
},
changeLink: function(event) {
changeLink: function (event) {
if (this.model.get('iconType') === 'email') {
this.model.set('link', 'mailto:' + jQuery(event.target).val());
} else {
return this.changeField('link', event);
}
},
changeField: function(field, event) {
changeField: function (field, event) {
this.model.set(field, jQuery(event.target).val());
}
});
@ -212,7 +212,7 @@ define([
// Select icons section container view
SocialBlockSettingsIconSelectorView = Marionette.View.extend({
getTemplate: function() { return window.templates.socialSettingsIconSelector; },
getTemplate: function () { return window.templates.socialSettingsIconSelector; },
regions: {
icons: '#mailpoet_social_icon_selector_contents'
},
@ -222,11 +222,11 @@ define([
modelEvents: {
'change:iconSet': 'render'
},
addSocialIcon: function() {
addSocialIcon: function () {
// Add a social icon with default values
this.model.get('icons').add({});
},
onRender: function() {
onRender: function () {
this.showChildView('icons', new SocialBlockSettingsIconCollectionView({
collection: this.model.get('icons')
}));
@ -235,17 +235,17 @@ define([
});
SocialBlockSettingsStylesView = Marionette.View.extend({
getTemplate: function() { return window.templates.socialSettingsStyles; },
getTemplate: function () { return window.templates.socialSettingsStyles; },
modelEvents: {
change: 'render'
},
events: {
'click .mailpoet_social_icon_set': 'changeSocialIconSet'
},
initialize: function() {
initialize: function () {
this.listenTo(this.model.get('icons'), 'add remove change', this.render);
},
templateContext: function() {
templateContext: function () {
var allIconSets = App.getAvailableStyles().get('socialIconSets');
return {
activeSet: this.model.get('iconSet'),
@ -254,20 +254,20 @@ define([
availableSocialIcons: this.model.get('icons').pluck('iconType')
};
},
changeSocialIconSet: function(event) {
changeSocialIconSet: function (event) {
this.model.set('iconSet', jQuery(event.currentTarget).data('setname'));
},
onBeforeDestroy: function() {
onBeforeDestroy: function () {
this.model.get('icons').off('add remove', this.render, this);
}
});
Module.SocialWidgetView = base.WidgetView.extend({
getTemplate: function() { return window.templates.socialInsertion; },
getTemplate: function () { return window.templates.socialInsertion; },
behaviors: {
DraggableBehavior: {
cloneOriginal: true,
drop: function() {
drop: function () {
return new Module.SocialBlockModel({
type: 'social',
iconSet: 'default',
@ -297,7 +297,7 @@ define([
}
});
App.on('before:start', function(App, options) {
App.on('before:start', function (App, options) {
App.registerBlockType('social', {
blockModel: Module.SocialBlockModel,
blockView: Module.SocialBlockView

View File

@ -5,7 +5,7 @@ define([
'newsletter_editor/App',
'newsletter_editor/blocks/base',
'underscore'
], function(App, BaseBlock, _) {
], function (App, BaseBlock, _) {
'use strict';
@ -13,7 +13,7 @@ define([
base = BaseBlock;
Module.SpacerBlockModel = base.BlockModel.extend({
defaults: function() {
defaults: function () {
return this._getDefaults({
type: 'spacer',
styles: {
@ -28,7 +28,7 @@ define([
Module.SpacerBlockView = base.BlockView.extend({
className: 'mailpoet_block mailpoet_spacer_block mailpoet_droppable_block',
getTemplate: function() { return window.templates.spacerBlock; },
getTemplate: function () { return window.templates.spacerBlock; },
behaviors: _.defaults({
ResizableBehavior: {
elementSelector: '.mailpoet_spacer',
@ -41,33 +41,33 @@ define([
}
}, base.BlockView.prototype.behaviors),
modelEvents: _.omit(base.BlockView.prototype.modelEvents, 'change'),
onDragSubstituteBy: function() { return Module.SpacerWidgetView; },
initialize: function() {
onDragSubstituteBy: function () { return Module.SpacerWidgetView; },
initialize: function () {
base.BlockView.prototype.initialize.apply(this, arguments);
this.listenTo(this.model, 'change:styles.block.backgroundColor', this.render);
this.listenTo(this.model, 'change:styles.block.height', this.changeHeight);
},
onRender: function() {
onRender: function () {
this.toolsView = new Module.SpacerBlockToolsView({ model: this.model });
this.showChildView('toolsRegion', this.toolsView);
},
changeHeight: function() {
changeHeight: function () {
this.$('.mailpoet_spacer').css('height', this.model.get('styles.block.height'));
this.$('.mailpoet_resize_handle_text').text(this.model.get('styles.block.height'));
},
onBeforeDestroy: function() {
onBeforeDestroy: function () {
this.stopListening(this.model);
}
});
Module.SpacerBlockToolsView = base.BlockToolsView.extend({
getSettingsView: function() { return Module.SpacerBlockSettingsView; }
getSettingsView: function () { return Module.SpacerBlockSettingsView; }
});
Module.SpacerBlockSettingsView = base.BlockSettingsView.extend({
getTemplate: function() { return window.templates.spacerBlockSettings; },
events: function() {
getTemplate: function () { return window.templates.spacerBlockSettings; },
events: function () {
return {
'change .mailpoet_field_spacer_background_color': _.partial(this.changeColorField, 'styles.block.backgroundColor'),
'click .mailpoet_done_editing': 'close'
@ -76,18 +76,18 @@ define([
});
Module.SpacerWidgetView = base.WidgetView.extend({
getTemplate: function() { return window.templates.spacerInsertion; },
getTemplate: function () { return window.templates.spacerInsertion; },
behaviors: {
DraggableBehavior: {
cloneOriginal: true,
drop: function() {
drop: function () {
return new Module.SpacerBlockModel();
}
}
}
});
App.on('before:start', function(App, options) {
App.on('before:start', function (App, options) {
App.registerBlockType('spacer', {
blockModel: Module.SpacerBlockModel,
blockView: Module.SpacerBlockView

View File

@ -6,7 +6,7 @@ define([
'newsletter_editor/blocks/base',
'underscore',
'mailpoet'
], function(App, BaseBlock, _, MailPoet) {
], function (App, BaseBlock, _, MailPoet) {
'use strict';
@ -14,7 +14,7 @@ define([
base = BaseBlock;
Module.TextBlockModel = base.BlockModel.extend({
defaults: function() {
defaults: function () {
return this._getDefaults({
type: 'text',
text: 'Edit this to insert text'
@ -24,7 +24,7 @@ define([
Module.TextBlockView = base.BlockView.extend({
className: 'mailpoet_block mailpoet_text_block mailpoet_droppable_block',
getTemplate: function() { return window.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
behaviors: _.extend({}, base.BlockView.prototype.behaviors, {
TextEditorBehavior: {
@ -34,7 +34,7 @@ define([
invalidElements: 'script',
blockFormats: 'Heading 1=h1;Heading 2=h2;Heading 3=h3;Paragraph=p',
plugins: 'link lists code textcolor colorpicker mailpoet_shortcodes paste',
configurationFilter: function(originalSettings) {
configurationFilter: function (originalSettings) {
return _.extend({}, originalSettings, {
mailpoet_shortcodes: App.getConfig().get('shortcodes').toJSON(),
mailpoet_shortcodes_window_title: MailPoet.I18n.t('shortcodesWindowTitle')
@ -42,7 +42,7 @@ define([
}
}
}),
initialize: function(options) {
initialize: function (options) {
base.BlockView.prototype.initialize.apply(this, arguments);
this.renderOptions = _.defaults(options.renderOptions || {}, {
@ -51,8 +51,8 @@ define([
this.disableTextEditor = this.renderOptions.disableTextEditor;
},
onDragSubstituteBy: function() { return Module.TextWidgetView; },
onRender: function() {
onDragSubstituteBy: function () { return Module.TextWidgetView; },
onRender: function () {
this.toolsView = new Module.TextBlockToolsView({
model: this.model,
tools: {
@ -61,40 +61,40 @@ define([
});
this.showChildView('toolsRegion', this.toolsView);
},
onTextEditorChange: function(newContent) {
onTextEditorChange: function (newContent) {
this.model.set('text', newContent);
},
onTextEditorFocus: function() {
onTextEditorFocus: function () {
this.disableDragging();
this.disableShowingTools();
},
onTextEditorBlur: function() {
onTextEditorBlur: function () {
this.enableDragging();
this.enableShowingTools();
}
});
Module.TextBlockToolsView = base.BlockToolsView.extend({
getSettingsView: function() { return Module.TextBlockSettingsView; }
getSettingsView: function () { return Module.TextBlockSettingsView; }
});
Module.TextBlockSettingsView = base.BlockSettingsView.extend({
getTemplate: function() { return window.templates.textBlockSettings; }
getTemplate: function () { return window.templates.textBlockSettings; }
});
Module.TextWidgetView = base.WidgetView.extend({
getTemplate: function() { return window.templates.textInsertion; },
getTemplate: function () { return window.templates.textInsertion; },
behaviors: {
DraggableBehavior: {
cloneOriginal: true,
drop: function() {
drop: function () {
return new Module.TextBlockModel();
}
}
}
});
App.on('before:start', function(App, options) {
App.on('before:start', function (App, options) {
App.registerBlockType('text', {
blockModel: Module.TextBlockModel,
blockView: Module.TextBlockView

View File

@ -6,9 +6,9 @@
* Courtesy of https://gist.github.com/jmeas/7992474cdb1c5672d88b
*/
(function(root, factory) {
(function (root, factory) {
if (typeof define === 'function' && define.amd) {
define(['backbone.marionette', 'backbone.radio', 'underscore'], function(Marionette, Radio, _) {
define(['backbone.marionette', 'backbone.radio', 'underscore'], function (Marionette, Radio, _) {
return factory(Marionette, Radio, _);
});
}
@ -21,7 +21,7 @@
else {
factory(root.Backbone.Marionette, root.Backbone.Radio, root._);
}
}(this, function(Marionette, Radio, _) {
}(this, function (Marionette, Radio, _) {
'use strict';
var MarionetteApplication = Marionette.Application;

View File

@ -3,11 +3,11 @@ define([
'underscore',
'mailpoet',
'ajax'
], function(App, _, MailPoet) {
], function (App, _, MailPoet) {
var Module = {};
Module._query = function(args) {
Module._query = function (args) {
return MailPoet.Ajax.post({
api_version: window.mailpoet_api_version,
endpoint: 'automatedLatestContent',
@ -17,70 +17,70 @@ define([
};
Module._cachedQuery = _.memoize(Module._query, JSON.stringify);
Module.getNewsletter = function(options) {
Module.getNewsletter = function (options) {
return Module._query({
action: 'get',
options: options
});
};
Module.getPostTypes = function() {
Module.getPostTypes = function () {
return Module._cachedQuery({
action: 'getPostTypes',
options: {}
}).then(function(response) {
}).then(function (response) {
return _.values(response.data);
});
};
Module.getTaxonomies = function(postType) {
Module.getTaxonomies = function (postType) {
return Module._cachedQuery({
action: 'getTaxonomies',
options: {
postType: postType
}
}).then(function(response) {
}).then(function (response) {
return response.data;
});
};
Module.getTerms = function(options) {
Module.getTerms = function (options) {
return Module._cachedQuery({
action: 'getTerms',
options: options
}).then(function(response) {
}).then(function (response) {
return response.data;
});
};
Module.getPosts = function(options) {
Module.getPosts = function (options) {
return Module._cachedQuery({
action: 'getPosts',
options: options
}).then(function(response) {
}).then(function (response) {
return response.data;
});
};
Module.getTransformedPosts = function(options) {
Module.getTransformedPosts = function (options) {
return Module._cachedQuery({
action: 'getTransformedPosts',
options: options
}).then(function(response) {
}).then(function (response) {
return response.data;
});
};
Module.getBulkTransformedPosts = function(options) {
Module.getBulkTransformedPosts = function (options) {
return Module._query({
action: 'getBulkTransformedPosts',
options: options
}).then(function(response) {
}).then(function (response) {
return response.data;
});
};
Module.saveNewsletter = function(options) {
Module.saveNewsletter = function (options) {
return MailPoet.Ajax.post({
api_version: window.mailpoet_api_version,
endpoint: 'newsletters',
@ -89,7 +89,7 @@ define([
});
};
Module.previewNewsletter = function(options) {
Module.previewNewsletter = function (options) {
return MailPoet.Ajax.post({
api_version: window.mailpoet_api_version,
endpoint: 'newsletters',
@ -98,7 +98,7 @@ define([
});
};
App.on('start', function(App, options) {
App.on('start', function (App, options) {
// Prefetch post types
Module.getPostTypes();
});

View File

@ -1,7 +1,7 @@
define([
'newsletter_editor/App',
'backbone.supermodel'
], function(App, SuperModel) {
], function (App, SuperModel) {
var Module = {};
@ -18,13 +18,13 @@ define([
// Global and available styles for access in blocks and their settings
Module._config = {};
Module.getConfig = function() { return Module._config; };
Module.setConfig = function(options) {
Module.getConfig = function () { return Module._config; };
Module.setConfig = function (options) {
Module._config = new Module.ConfigModel(options, { parse: true });
return Module._config;
};
App.on('before:start', function(App, options) {
App.on('before:start', function (App, options) {
var Application = App;
// Expose config methods globally
Application.getConfig = Module.getConfig;

View File

@ -3,7 +3,7 @@ define([
'backbone.supermodel',
'underscore',
'mailpoet'
], function(App, SuperModel, _, MailPoet) {
], function (App, SuperModel, _, MailPoet) {
'use strict';
var Module = {};
@ -13,12 +13,12 @@ define([
// handled by other components.
Module.NewsletterModel = SuperModel.extend({
whitelisted: ['id', 'subject', 'preheader'],
initialize: function(options) {
this.on('change', function() {
initialize: function (options) {
this.on('change', function () {
App.getChannel().trigger('autoSave');
});
},
toJSON: function() {
toJSON: function () {
// Use only whitelisted properties to ensure properties editor
// doesn't control don't change.
return _.pick(SuperModel.prototype.toJSON.call(this), this.whitelisted);
@ -27,17 +27,17 @@ define([
// Content block view and model handlers for different content types
Module._blockTypes = {};
Module.registerBlockType = function(type, data) {
Module.registerBlockType = function (type, data) {
Module._blockTypes[type] = data;
};
Module.getBlockTypeModel = function(type) {
Module.getBlockTypeModel = function (type) {
if (type in Module._blockTypes) {
return Module._blockTypes[type].blockModel;
} else {
throw 'Block type not supported: ' + type;
}
};
Module.getBlockTypeView = function(type) {
Module.getBlockTypeView = function (type) {
if (type in Module._blockTypes) {
return Module._blockTypes[type].blockView;
} else {
@ -45,29 +45,29 @@ define([
}
};
Module.getBody = function() {
Module.getBody = function () {
return {
content: App._contentContainer.toJSON(),
globalStyles: App.getGlobalStyles().toJSON()
};
};
Module.toJSON = function() {
Module.toJSON = function () {
return _.extend({
body: Module.getBody()
}, App.getNewsletter().toJSON());
};
Module.getNewsletter = function() {
Module.getNewsletter = function () {
return Module.newsletter;
};
Module.findModels = function(predicate) {
Module.findModels = function (predicate) {
var blocks = App._contentContainer.getChildren();
return _.filter(blocks, predicate);
};
App.on('before:start', function(Application, options) {
App.on('before:start', function (Application, options) {
var App = Application;
// Expose block methods globally
App.registerBlockType = Module.registerBlockType;
@ -81,7 +81,7 @@ define([
Module.newsletter = new Module.NewsletterModel(_.omit(_.clone(options.newsletter), ['body']));
});
App.on('start', function(Application, options) {
App.on('start', function (Application, options) {
var App = Application;
var body = options.newsletter.body;
var content = (_.has(body, 'content')) ? body.content : {};

View File

@ -5,31 +5,31 @@ define([
'underscore',
'jquery',
'mailpoet'
], function(App, Backbone, Marionette, _, jQuery, MailPoet) {
], function (App, Backbone, Marionette, _, jQuery, MailPoet) {
'use strict';
var Module = {};
Module.HeadingView = Marionette.View.extend({
getTemplate: function() { return window.templates.heading; },
templateContext: function() {
getTemplate: function () { return window.templates.heading; },
templateContext: function () {
return {
model: this.model.toJSON()
};
},
events: function() {
events: function () {
return {
'keyup .mailpoet_input_title': _.partial(this.changeField, 'subject'),
'keyup .mailpoet_input_preheader': _.partial(this.changeField, 'preheader')
};
},
changeField: function(field, event) {
changeField: function (field, event) {
this.model.set(field, jQuery(event.target).val());
}
});
App.on('start', function(App, options) {
App.on('start', function (App, options) {
App._appView.showChildView('headingRegion', new Module.HeadingView({ model: App.getNewsletter() }));
MailPoet.helpTooltip.show(document.getElementById('tooltip-designer-subject-line'), {
tooltipId: 'tooltip-designer-subject-line-ti',

View File

@ -11,7 +11,7 @@ define([
'html2canvas',
'underscore',
'jquery'
], function(
], function (
App,
CommunicationComponent,
MailPoet,
@ -32,7 +32,7 @@ define([
saveTimeout;
// Save editor contents to server
Module.save = function() {
Module.save = function () {
var json = App.toJSON();
@ -44,7 +44,7 @@ define([
App.getChannel().trigger('beforeEditorSave', json);
// save newsletter
return CommunicationComponent.saveNewsletter(json).done(function(response) {
return CommunicationComponent.saveNewsletter(json).done(function (response) {
if(response.success !== undefined && response.success === true) {
// TODO: Handle translations
//MailPoet.Notice.success("<?php _e('Newsletter has been saved.'); ?>");
@ -57,22 +57,22 @@ define([
}
);
} else {
$(response.error).each(function(i, error) {
$(response.error).each(function (i, error) {
MailPoet.Notice.error(error, { scroll: true });
});
}
}
App.getChannel().trigger('afterEditorSave', json, response);
}).fail(function(response) {
}).fail(function (response) {
// TODO: Handle saving errors
App.getChannel().trigger('afterEditorSave', {}, response);
});
};
Module.getThumbnail = function(element, options) {
Module.getThumbnail = function (element, options) {
var promise = html2canvas(element, options || {});
return promise.then(function(oldCanvas) {
return promise.then(function (oldCanvas) {
// Temporary workaround for html2canvas-alpha2.
// Removes 1px left transparent border from resulting canvas.
@ -94,11 +94,11 @@ define([
});
};
Module.saveTemplate = function(options) {
Module.saveTemplate = function (options) {
var that = this,
promise = jQuery.Deferred();
promise.then(function(thumbnail) {
promise.then(function (thumbnail) {
var data = _.extend(options || {}, {
thumbnail: thumbnail.toDataURL('image/jpeg'),
body: JSON.stringify(App.getBody())
@ -114,18 +114,18 @@ define([
Module.getThumbnail(
jQuery('#mailpoet_editor_content > .mailpoet_block').get(0)
).then(function(thumbnail) {
).then(function (thumbnail) {
promise.resolve(thumbnail);
});
return promise;
};
Module.exportTemplate = function(options) {
Module.exportTemplate = function (options) {
var that = this;
return Module.getThumbnail(
jQuery('#mailpoet_editor_content > .mailpoet_block').get(0)
).then(function(thumbnail) {
).then(function (thumbnail) {
var data = _.extend(options || {}, {
thumbnail: thumbnail.toDataURL('image/jpeg'),
body: App.getBody()
@ -143,7 +143,7 @@ define([
};
Module.SaveView = Marionette.View.extend({
getTemplate: function() { return window.templates.save; },
getTemplate: function () { return window.templates.save; },
events: {
'click .mailpoet_save_button': 'save',
'click .mailpoet_save_show_options': 'toggleSaveOptions',
@ -155,43 +155,43 @@ define([
'click .mailpoet_save_export': 'toggleExportTemplate',
'click .mailpoet_export_template': 'exportTemplate'
},
initialize: function(options) {
initialize: function (options) {
App.getChannel().on('beforeEditorSave', this.beforeSave, this);
App.getChannel().on('afterEditorSave', this.afterSave, this);
},
onRender: function() {
onRender: function () {
this.validateNewsletter(App.toJSON());
},
save: function() {
save: function () {
this.hideOptionContents();
App.getChannel().request('save');
},
beforeSave: function() {
beforeSave: function () {
// TODO: Add a loading animation instead
this.$('.mailpoet_autosaved_at').text(MailPoet.I18n.t('saving'));
},
afterSave: function(json, response) {
afterSave: function (json, response) {
this.validateNewsletter(json);
// Update 'Last saved timer'
this.$('.mailpoet_editor_last_saved').removeClass('mailpoet_hidden');
this.$('.mailpoet_autosaved_at').text('');
},
toggleSaveOptions: function() {
toggleSaveOptions: function () {
this.$('.mailpoet_save_options').toggleClass('mailpoet_hidden');
this.$('.mailpoet_save_show_options').toggleClass('mailpoet_save_show_options_active');
},
toggleSaveAsTemplate: function() {
toggleSaveAsTemplate: function () {
this.$('.mailpoet_save_as_template_container').toggleClass('mailpoet_hidden');
this.toggleSaveOptions();
},
showSaveAsTemplate: function() {
showSaveAsTemplate: function () {
this.$('.mailpoet_save_as_template_container').removeClass('mailpoet_hidden');
this.toggleSaveOptions();
},
hideSaveAsTemplate: function() {
hideSaveAsTemplate: function () {
this.$('.mailpoet_save_as_template_container').addClass('mailpoet_hidden');
},
saveAsTemplate: function() {
saveAsTemplate: function () {
var templateName = this.$('.mailpoet_save_as_template_name').val(),
templateDescription = this.$('.mailpoet_save_as_template_description').val(),
that = this;
@ -216,7 +216,7 @@ define([
Module.saveTemplate({
name: templateName,
description: templateDescription
}).done(function() {
}).done(function () {
MailPoet.Notice.success(
MailPoet.I18n.t('templateSaved'),
{
@ -227,7 +227,7 @@ define([
MailPoet.trackEvent('Editor > Template saved', {
'MailPoet Free version': window.mailpoet_version
});
}).fail(function() {
}).fail(function () {
MailPoet.Notice.error(
MailPoet.I18n.t('templateSaveFailed'),
{
@ -240,14 +240,14 @@ define([
}
},
toggleExportTemplate: function() {
toggleExportTemplate: function () {
this.$('.mailpoet_export_template_container').toggleClass('mailpoet_hidden');
this.toggleSaveOptions();
},
hideExportTemplate: function() {
hideExportTemplate: function () {
this.$('.mailpoet_export_template_container').addClass('mailpoet_hidden');
},
exportTemplate: function() {
exportTemplate: function () {
var templateName = this.$('.mailpoet_export_template_name').val(),
templateDescription = this.$('.mailpoet_export_template_description').val(),
that = this;
@ -276,21 +276,21 @@ define([
this.hideExportTemplate();
}
},
hideOptionContents: function() {
hideOptionContents: function () {
this.hideSaveAsTemplate();
this.hideExportTemplate();
this.$('.mailpoet_save_options').addClass('mailpoet_hidden');
},
next: function() {
next: function () {
this.hideOptionContents();
if(!this.$('.mailpoet_save_next').hasClass('button-disabled')) {
Module._cancelAutosave();
Module.save().done(function(response) {
Module.save().done(function (response) {
window.location.href = App.getConfig().get('urls.send');
});
}
},
validateNewsletter: function(jsonObject) {
validateNewsletter: function (jsonObject) {
if (!App._contentContainer.isValid()) {
this.showValidationError(App._contentContainer.validationError);
return;
@ -306,40 +306,40 @@ define([
this.hideValidationError();
},
showValidationError: function(message) {
showValidationError: function (message) {
var $el = this.$('.mailpoet_save_error');
$el.text(message);
$el.removeClass('mailpoet_hidden');
this.$('.mailpoet_save_next').addClass('button-disabled');
},
hideValidationError: function() {
hideValidationError: function () {
this.$('.mailpoet_save_error').addClass('mailpoet_hidden');
this.$('.mailpoet_save_next').removeClass('button-disabled');
}
});
Module.autoSave = function() {
Module.autoSave = function () {
// Delay in saving editor contents, during which a new autosave
// may be requested
var AUTOSAVE_DELAY_DURATION = 1000;
Module._cancelAutosave();
saveTimeout = setTimeout(function() {
App.getChannel().request('save').always(function() {
saveTimeout = setTimeout(function () {
App.getChannel().request('save').always(function () {
Module._cancelAutosave();
});
}, AUTOSAVE_DELAY_DURATION);
};
Module._cancelAutosave = function() {
Module._cancelAutosave = function () {
if (!saveTimeout) return;
clearTimeout(saveTimeout);
saveTimeout = undefined;
};
Module.beforeExitWithUnsavedChanges = function(e) {
Module.beforeExitWithUnsavedChanges = function (e) {
if (saveTimeout) {
var message = MailPoet.I18n.t('unsavedChangesWillBeLost');
var event = e || window.event;
@ -352,7 +352,7 @@ define([
}
};
App.on('before:start', function(App, options) {
App.on('before:start', function (App, options) {
var Application = App;
Application.save = Module.save;
Application.getChannel().on('autoSave', Module.autoSave);
@ -362,7 +362,7 @@ define([
Application.getChannel().reply('save', Application.save);
});
App.on('start', function(App, options) {
App.on('start', function (App, options) {
var saveView = new Module.SaveView();
App._appView.showChildView('bottomRegion', saveView);
});

View File

@ -8,7 +8,7 @@ define([
'underscore',
'jquery',
'sticky-kit'
], function(
], function (
App,
CommunicationComponent,
MailPoet,
@ -35,8 +35,8 @@ define([
}),
comparator: 'priority'
}))();
Module.registerWidget = function(widget) { return Module._contentWidgets.add(widget); };
Module.getWidgets = function() { return Module._contentWidgets; };
Module.registerWidget = function (widget) { return Module._contentWidgets.add(widget); };
Module.getWidgets = function () { return Module._contentWidgets; };
// Layout widget handlers for use to create new layout blocks via drag&drop
Module._layoutWidgets = new (Backbone.Collection.extend({
@ -49,11 +49,11 @@ define([
}),
comparator: 'priority'
}))();
Module.registerLayoutWidget = function(widget) { return Module._layoutWidgets.add(widget); };
Module.getLayoutWidgets = function() { return Module._layoutWidgets; };
Module.registerLayoutWidget = function (widget) { return Module._layoutWidgets.add(widget); };
Module.getLayoutWidgets = function () { return Module._layoutWidgets; };
var SidebarView = Marionette.View.extend({
getTemplate: function() { return window.templates.sidebar; },
getTemplate: function () { return window.templates.sidebar; },
regions: {
contentRegion: '.mailpoet_content_region',
layoutRegion: '.mailpoet_layout_region',
@ -61,7 +61,7 @@ define([
previewRegion: '.mailpoet_preview_region'
},
events: {
'click .mailpoet_sidebar_region h3, .mailpoet_sidebar_region .handlediv': function(event) {
'click .mailpoet_sidebar_region h3, .mailpoet_sidebar_region .handlediv': function (event) {
var $openRegion = this.$el.find('.mailpoet_sidebar_region:not(.closed)'),
$targetRegion = this.$el.find(event.target).closest('.mailpoet_sidebar_region');
@ -70,7 +70,7 @@ define([
{
duration: 250,
easing: 'easeOut',
complete: function() {
complete: function () {
$openRegion.addClass('closed');
}.bind(this)
}
@ -82,7 +82,7 @@ define([
{
duration: 250,
easing: 'easeIn',
complete: function() {
complete: function () {
$targetRegion.removeClass('closed');
}
}
@ -90,12 +90,12 @@ define([
}
}
},
initialize: function(options) {
initialize: function (options) {
jQuery(window)
.on('resize', this.updateHorizontalScroll.bind(this))
.on('scroll', this.updateHorizontalScroll.bind(this));
},
onRender: function() {
onRender: function () {
this.showChildView('contentRegion', new Module.SidebarWidgetsView(
App.getWidgets()
));
@ -108,7 +108,7 @@ define([
}));
this.showChildView('previewRegion', new Module.SidebarPreviewView());
},
updateHorizontalScroll: function() {
updateHorizontalScroll: function () {
// Fixes the sidebar so that on narrower screens the horizontal
// position of the sidebar would be scrollable and not fixed
// partially out of visible screen
@ -125,7 +125,7 @@ define([
}
});
},
onDomRefresh: function() {
onDomRefresh: function () {
this.$el.parent().stick_in_parent({
offset_top: 32
});
@ -140,23 +140,23 @@ define([
* Draggable widget collection view
*/
Module.SidebarWidgetsCollectionView = Marionette.CollectionView.extend({
childView: function(item) { return item.get('widgetView'); }
childView: function (item) { return item.get('widgetView'); }
});
/**
* Responsible for rendering draggable content widgets
*/
Module.SidebarWidgetsView = Marionette.View.extend({
getTemplate: function() { return window.templates.sidebarContent; },
getTemplate: function () { return window.templates.sidebarContent; },
regions: {
widgets: '.mailpoet_region_content'
},
initialize: function(widgets) {
initialize: function (widgets) {
this.widgets = widgets;
},
onRender: function() {
onRender: function () {
this.showChildView('widgets', new Module.SidebarWidgetsCollectionView({
collection: this.widgets
}));
@ -167,68 +167,68 @@ define([
* Responsible for rendering draggable layout widgets
*/
Module.SidebarLayoutWidgetsView = Module.SidebarWidgetsView.extend({
getTemplate: function() { return window.templates.sidebarLayout; }
getTemplate: function () { return window.templates.sidebarLayout; }
});
/**
* Responsible for managing global styles
*/
Module.SidebarStylesView = Marionette.View.extend({
getTemplate: function() { return window.templates.sidebarStyles; },
getTemplate: function () { return window.templates.sidebarStyles; },
behaviors: {
ColorPickerBehavior: {}
},
events: function() {
events: function () {
return {
'change #mailpoet_text_font_color': _.partial(this.changeColorField, 'text.fontColor'),
'change #mailpoet_text_font_family': function(event) {
'change #mailpoet_text_font_family': function (event) {
this.model.set('text.fontFamily', event.target.value);
},
'change #mailpoet_text_font_size': function(event) {
'change #mailpoet_text_font_size': function (event) {
this.model.set('text.fontSize', event.target.value);
},
'change #mailpoet_h1_font_color': _.partial(this.changeColorField, 'h1.fontColor'),
'change #mailpoet_h1_font_family': function(event) {
'change #mailpoet_h1_font_family': function (event) {
this.model.set('h1.fontFamily', event.target.value);
},
'change #mailpoet_h1_font_size': function(event) {
'change #mailpoet_h1_font_size': function (event) {
this.model.set('h1.fontSize', event.target.value);
},
'change #mailpoet_h2_font_color': _.partial(this.changeColorField, 'h2.fontColor'),
'change #mailpoet_h2_font_family': function(event) {
'change #mailpoet_h2_font_family': function (event) {
this.model.set('h2.fontFamily', event.target.value);
},
'change #mailpoet_h2_font_size': function(event) {
'change #mailpoet_h2_font_size': function (event) {
this.model.set('h2.fontSize', event.target.value);
},
'change #mailpoet_h3_font_color': _.partial(this.changeColorField, 'h3.fontColor'),
'change #mailpoet_h3_font_family': function(event) {
'change #mailpoet_h3_font_family': function (event) {
this.model.set('h3.fontFamily', event.target.value);
},
'change #mailpoet_h3_font_size': function(event) {
'change #mailpoet_h3_font_size': function (event) {
this.model.set('h3.fontSize', event.target.value);
},
'change #mailpoet_a_font_color': _.partial(this.changeColorField, 'link.fontColor'),
'change #mailpoet_a_font_underline': function(event) {
'change #mailpoet_a_font_underline': function (event) {
this.model.set('link.textDecoration', (event.target.checked) ? event.target.value : 'none');
},
'change #mailpoet_newsletter_background_color': _.partial(this.changeColorField, 'wrapper.backgroundColor'),
'change #mailpoet_background_color': _.partial(this.changeColorField, 'body.backgroundColor')
};
},
templateContext: function() {
templateContext: function () {
return {
model: this.model.toJSON(),
availableStyles: this.availableStyles.toJSON()
};
},
initialize: function(options) {
initialize: function (options) {
this.availableStyles = options.availableStyles;
},
changeField: function(field, event) {
changeField: function (field, event) {
this.model.set(field, jQuery(event.target).val());
},
changeColorField: function(field, event) {
changeColorField: function (field, event) {
var value = jQuery(event.target).val();
if (value === '') {
value = 'transparent';
@ -238,18 +238,18 @@ define([
});
Module.SidebarPreviewView = Marionette.View.extend({
getTemplate: function() { return window.templates.sidebarPreview; },
getTemplate: function () { return window.templates.sidebarPreview; },
events: {
'click .mailpoet_show_preview': 'showPreview',
'click #mailpoet_send_preview': 'sendPreview'
},
onBeforeDestroy: function() {
onBeforeDestroy: function () {
if (this.previewView) {
this.previewView.destroy();
this.previewView = null;
}
},
showPreview: function() {
showPreview: function () {
var json = App.toJSON();
// Stringify to enable transmission of primitive non-string value types
@ -264,9 +264,9 @@ define([
endpoint: 'newsletters',
action: 'showPreview',
data: json
}).always(function() {
}).always(function () {
MailPoet.Modal.loading(false);
}).done(function(response) {
}).done(function (response) {
this.previewView = new Module.NewsletterPreviewView({
previewUrl: response.meta.preview_url
});
@ -280,7 +280,7 @@ define([
width: '95%',
height: '94%',
title: MailPoet.I18n.t('newsletterPreview'),
onCancel: function() {
onCancel: function () {
this.previewView.destroy();
this.previewView = null;
}.bind(this)
@ -289,16 +289,16 @@ define([
MailPoet.trackEvent('Editor > Browser Preview', {
'MailPoet Free version': window.mailpoet_version
});
}.bind(this)).fail(function(response) {
}.bind(this)).fail(function (response) {
if (response.errors.length > 0) {
MailPoet.Notice.error(
response.errors.map(function(error) { return error.message; }),
response.errors.map(function (error) { return error.message; }),
{ scroll: true }
);
}
});
},
sendPreview: function() {
sendPreview: function () {
// get form data
var $emailField = this.$('#mailpoet_preview_to_email');
var data = {
@ -321,10 +321,10 @@ define([
MailPoet.Modal.loading(true);
// save before sending
App.getChannel().request('save').always(function() {
CommunicationComponent.previewNewsletter(data).always(function() {
App.getChannel().request('save').always(function () {
CommunicationComponent.previewNewsletter(data).always(function () {
MailPoet.Modal.loading(false);
}).done(function(response) {
}).done(function (response) {
MailPoet.Notice.success(
MailPoet.I18n.t('newsletterPreviewSent'),
{ scroll: true }
@ -333,10 +333,10 @@ define([
'MailPoet Free version': window.mailpoet_version,
'Domain name': data.subscriber.substring(data.subscriber.indexOf('@') + 1)
});
}).fail(function(response) {
}).fail(function (response) {
if (response.errors.length > 0) {
MailPoet.Notice.error(
response.errors.map(function(error) { return error.message; }),
response.errors.map(function (error) { return error.message; }),
{ scroll: true, static: true }
);
}
@ -346,15 +346,15 @@ define([
});
Module.NewsletterPreviewView = Marionette.View.extend({
getTemplate: function() { return window.templates.newsletterPreview; },
initialize: function(options) {
getTemplate: function () { return window.templates.newsletterPreview; },
initialize: function (options) {
this.previewUrl = options.previewUrl;
this.width = '100%';
this.height = '100%';
// this.width = App.getConfig().get('newsletterPreview.width');
// this.height = App.getConfig().get('newsletterPreview.height')
},
templateContext: function() {
templateContext: function () {
return {
previewUrl: this.previewUrl,
width: this.width,
@ -363,7 +363,7 @@ define([
}
});
App.on('before:start', function(App, options) {
App.on('before:start', function (App, options) {
var Application = App;
Application.registerWidget = Module.registerWidget;
Application.getWidgets = Module.getWidgets;
@ -371,7 +371,7 @@ define([
Application.getLayoutWidgets = Module.getLayoutWidgets;
});
App.on('start', function(App, options) {
App.on('start', function (App, options) {
var stylesModel = App.getGlobalStyles(),
sidebarView = new SidebarView();

View File

@ -3,7 +3,7 @@ define([
'backbone.marionette',
'backbone.supermodel',
'underscore'
], function(App, Marionette, SuperModel, _) {
], function (App, Marionette, SuperModel, _) {
'use strict';
@ -42,34 +42,34 @@ define([
backgroundColor: '#cccccc'
}
},
initialize: function() {
this.on('change', function() { App.getChannel().trigger('autoSave'); });
initialize: function () {
this.on('change', function () { App.getChannel().trigger('autoSave'); });
}
});
Module.StylesView = Marionette.View.extend({
getTemplate: function() { return window.templates.styles; },
getTemplate: function () { return window.templates.styles; },
modelEvents: {
change: 'render'
},
serializeData: function() {
serializeData: function () {
return this.model.toJSON();
}
});
Module._globalStyles = new SuperModel();
Module.getGlobalStyles = function() {
Module.getGlobalStyles = function () {
return Module._globalStyles;
};
Module.setGlobalStyles = function(options) {
Module.setGlobalStyles = function (options) {
Module._globalStyles = new Module.StylesModel(options);
return Module._globalStyles;
};
Module.getAvailableStyles = function() {
Module.getAvailableStyles = function () {
return App.getConfig().get('availableStyles');
};
App.on('before:start', function(App, options) {
App.on('before:start', function (App, options) {
var Application = App;
// Expose style methods to global application
Application.getGlobalStyles = Module.getGlobalStyles;
@ -81,7 +81,7 @@ define([
this.setGlobalStyles(globalStyles);
});
App.on('start', function(App, options) {
App.on('start', function (App, options) {
var stylesView = new Module.StylesView({ model: App.getGlobalStyles() });
App._appView.showChildView('stylesRegion', stylesView);
});

View File

@ -10,20 +10,20 @@
/*jshint unused:false */
/*global tinymce:true */
tinymce.PluginManager.add('mailpoet_shortcodes', function(editor, url) {
var appendLabelAndClose = function(shortcode) {
tinymce.PluginManager.add('mailpoet_shortcodes', function (editor, url) {
var appendLabelAndClose = function (shortcode) {
editor.insertContent(shortcode);
editor.windowManager.close();
},
generateOnClickFunc = function(shortcode) {
return function() {
generateOnClickFunc = function (shortcode) {
return function () {
appendLabelAndClose(shortcode);
};
};
editor.addButton('mailpoet_shortcodes', {
icon: 'mailpoet_shortcodes',
onclick: function() {
onclick: function () {
var shortcodes = [],
configShortcodes = editor.settings.mailpoet_shortcodes;

View File

@ -1,4 +1,4 @@
define('notice', ['mailpoet', 'jquery'], function(mp, jQuery) {
define('notice', ['mailpoet', 'jquery'], function (mp, jQuery) {
'use strict';
/*==================================================================================================
@ -40,13 +40,13 @@ define('notice', ['mailpoet', 'jquery'], function(mp, jQuery) {
onClose: null
},
options: {},
init: function(options) {
init: function (options) {
// set options
this.options = jQuery.extend({}, this.defaults, options);
return this;
},
createNotice: function() {
createNotice: function () {
// clone element
this.element = jQuery('#mailpoet_notice_'+this.options.type).clone();
@ -79,8 +79,8 @@ define('notice', ['mailpoet', 'jquery'], function(mp, jQuery) {
}
// listen to remove event
jQuery(this.element).on('close', function() {
jQuery(this).fadeOut(200, function() {
jQuery(this.element).on('close', function () {
jQuery(this).fadeOut(200, function () {
// on close callback
if (onClose !== null) {
onClose();
@ -91,19 +91,19 @@ define('notice', ['mailpoet', 'jquery'], function(mp, jQuery) {
}.bind(this.element));
// listen to message event
jQuery(this.element).on('setMessage', function(e, message) {
jQuery(this.element).on('setMessage', function (e, message) {
MailPoet.Notice.setMessage(message);
}.bind(this.element));
return this;
},
updateNotice: function() {
updateNotice: function () {
// update notice's message
jQuery('[data-id="'+this.options.id+'"').first().trigger(
'setMessage', this.options.message
);
},
setMessage: function(message) {
setMessage: function (message) {
var formattedMessage = this.formatMessage(message);
// let's sugar coat the message with a fancy <p>
@ -111,14 +111,14 @@ define('notice', ['mailpoet', 'jquery'], function(mp, jQuery) {
// set message
return this.element.html(formattedMessage);
},
formatMessage: function(message) {
formatMessage: function (message) {
if (Array.isArray(message)) {
return message.join('<br />');
} else {
return message;
}
},
show: function(options) {
show: function (options) {
// initialize
this.init(options);
@ -133,7 +133,7 @@ define('notice', ['mailpoet', 'jquery'], function(mp, jQuery) {
}
this.showNotice();
},
showNotice: function() {
showNotice: function () {
// set message
this.setMessage(this.options.message);
@ -166,7 +166,7 @@ define('notice', ['mailpoet', 'jquery'], function(mp, jQuery) {
this.element.delay(this.options.timeout).trigger('close');
} else if (this.options.hideClose === false) {
this.element.append('<a href="javascript:;" class="mailpoet_notice_close"><span class="dashicons dashicons-dismiss"></span></a>');
this.element.find('.mailpoet_notice_close').on('click', function() {
this.element.find('.mailpoet_notice_close').on('click', function () {
jQuery(this).trigger('close');
});
}
@ -176,7 +176,7 @@ define('notice', ['mailpoet', 'jquery'], function(mp, jQuery) {
this.options.onOpen(this.element);
}
},
hide: function(all) {
hide: function (all) {
if (all !== undefined && all === true) {
// all notices
jQuery('.mailpoet_notice:not([id])').trigger('close');
@ -193,19 +193,19 @@ define('notice', ['mailpoet', 'jquery'], function(mp, jQuery) {
.trigger('close');
}
},
error: function(message, options) {
error: function (message, options) {
this.show(jQuery.extend({}, {
type: 'error',
message: message
}, options));
},
success: function(message, options) {
success: function (message, options) {
this.show(jQuery.extend({}, {
type: 'success',
message: message
}, options));
},
system: function(message, options) {
system: function (message, options) {
this.show(jQuery.extend({}, {
type: 'system',
static: true,

View File

@ -1,7 +1,7 @@
define('num',
[
'mailpoet'
], function(
], function (
mp
) {
'use strict';

View File

@ -3,24 +3,24 @@ define([
'jquery',
'parsleyjs'
],
function(
function (
MailPoet,
jQuery,
Parsley
) {
jQuery(function($) {
jQuery(function ($) {
function isSameDomain(url) {
var link = document.createElement('a');
link.href = url;
return (window.location.hostname === link.hostname);
}
$(function() {
$(function () {
// setup form validation
$('form.mailpoet_form').each(function() {
$('form.mailpoet_form').each(function () {
var form = $(this);
form.parsley().on('form:validated', function(parsley) {
form.parsley().on('form:validated', function (parsley) {
// clear messages
form.find('.mailpoet_message > p').hide();
@ -30,7 +30,7 @@ function(
}
});
form.parsley().on('form:submit', function(parsley) {
form.parsley().on('form:submit', function (parsley) {
var form_data = form.serializeObject() || {};
// check if we're on the same domain
if(isSameDomain(window.MailPoetForm.ajax_url) === false) {
@ -45,13 +45,13 @@ function(
endpoint: 'subscribers',
action: 'subscribe',
data: form_data.data
}).fail(function(response) {
}).fail(function (response) {
form.find('.mailpoet_validate_error').html(
response.errors.map(function(error) {
response.errors.map(function (error) {
return error.message;
}).join('<br />')
).show();
}).done(function(response) {
}).done(function (response) {
// successfully subscribed
if (
response.meta !== undefined

View File

@ -2,7 +2,7 @@ define(
[
'mailpoet'
],
function(
function (
MailPoet
) {

View File

@ -4,7 +4,7 @@ define(
'jquery',
'mailpoet'
],
function(
function (
Backbone,
jQuery,
mp
@ -20,7 +20,7 @@ define(
'mta(/:group)': 'sendingMethodGroup',
'(:tab)': 'tabs'
},
sendingMethodGroup: function(group) {
sendingMethodGroup: function (group) {
// display mta tab
this.tabs('mta');
@ -51,7 +51,7 @@ define(
jQuery('#mailpoet_sending_method_setup').fadeIn();
}
},
tabs: function(tabStr, section) {
tabs: function (tabStr, section) {
// set default tab
var tab = tabStr || 'mta';
@ -82,7 +82,7 @@ define(
}
}));
jQuery(document).ready(function() {
jQuery(document).ready(function () {
if (!Backbone.History.started) Backbone.history.start();
});
}

View File

@ -149,9 +149,9 @@ define(
segments: (window.exportData.segments) ? segmentsContainerElement.val() : false,
subscriber_fields: subscriberFieldsContainerElement.val()
})
}).always(function(response) {
}).always(function (response) {
MailPoet.Modal.loading(false);
}).done(function(response) {
}).done(function (response) {
var resultMessage = MailPoet.I18n.t('exportMessage')
.replace('%1$s', '<strong>' + parseInt(response.data.totalExported).toLocaleString() + '</strong>')
.replace('[link]', '<a href="' + response.data.exportFileURL + '" target="_blank" >')
@ -164,10 +164,10 @@ define(
'File Format': exportFormat,
'MailPoet Free version': window.mailpoet_version
});
}).fail(function(response) {
}).fail(function (response) {
if (response.errors.length > 0) {
MailPoet.Notice.error(
response.errors.map(function(error) { return error.message; }),
response.errors.map(function (error) { return error.message; }),
{ scroll: true }
);
}

View File

@ -197,9 +197,9 @@ define(
data: {
api_key: mailChimpKeyInputElement.val()
}
}).always(function() {
}).always(function () {
MailPoet.Modal.loading(false);
}).done(function(response) {
}).done(function (response) {
jQuery('.mailpoet_mailchimp-key-status')
.html('')
.removeClass()
@ -211,10 +211,10 @@ define(
} else {
displayMailChimpLists(response.data);
}
}).fail(function(response) {
}).fail(function (response) {
if (response.errors.length > 0) {
MailPoet.Notice.error(
response.errors.map(function(error) { return error.message; }),
response.errors.map(function (error) { return error.message; }),
{ scroll: true }
);
}
@ -234,19 +234,19 @@ define(
api_key: mailChimpKeyInputElement.val(),
lists: mailChimpListsContainerElement.find('select').val()
}
}).always(function(response) {
}).always(function (response) {
MailPoet.Modal.loading(false);
}).done(function(response) {
}).done(function (response) {
window.importData.step1 = response.data;
MailPoet.trackEvent('Subscribers import started', {
source: 'MailChimp',
'MailPoet Free version': window.mailpoet_version
});
router.navigate('step2', {trigger: true});
}).fail(function(response) {
}).fail(function (response) {
if (response.errors.length > 0) {
MailPoet.Notice.error(
response.errors.map(function(error) { return error.message; }),
response.errors.map(function (error) { return error.message; }),
{ scroll: true }
);
}
@ -576,12 +576,12 @@ define(
});
}
jQuery('.mailpoet_create_segment').click(function() {
jQuery('.mailpoet_create_segment').click(function () {
MailPoet.Modal.popup({
title: MailPoet.I18n.t('addNewList'),
template: jQuery('#new_segment_template').html()
});
jQuery('#new_segment_name').keypress(function(e) {
jQuery('#new_segment_name').keypress(function (e) {
if (e.which == 13) {
jQuery('#new_segment_process').click();
}
@ -598,7 +598,7 @@ define(
name: segmentName,
description: segmentDescription
}
}).done(function(response) {
}).done(function (response) {
window.mailpoetSegments.push({
id: response.data.id,
name: response.data.name,
@ -617,11 +617,11 @@ define(
jQuery('.mailpoet_segments:hidden').show();
jQuery('.mailpoet_no_segments:visible').hide();
MailPoet.Modal.close();
}).fail(function(response) {
}).fail(function (response) {
if (response.errors.length > 0) {
MailPoet.Notice.hide();
MailPoet.Notice.error(
response.errors.map(function(error) { return error.message; }),
response.errors.map(function (error) { return error.message; }),
{ positionAfter: '#new_segment_name' }
);
}
@ -685,7 +685,7 @@ define(
});
// sanitize unsafe data
Handlebars.registerHelper('sanitize_data', function(data) {
Handlebars.registerHelper('sanitize_data', function (data) {
return (data instanceof Handlebars.SafeString) ?
data :
new Handlebars.SafeString(Handlebars.Utils.escapeExpression(data));
@ -743,7 +743,7 @@ define(
title: MailPoet.I18n.t('addNewField'),
template: jQuery('#form_template_field_form').html()
});
jQuery('#form_field_new').parsley().on('form:submit', function(parsley) {
jQuery('#form_field_new').parsley().on('form:submit', function (parsley) {
// get data
var data = jQuery(this.$element).serializeObject();
@ -753,7 +753,7 @@ define(
endpoint: 'customFields',
action: 'save',
data: data
}).done(function(response) {
}).done(function (response) {
var new_column_data = {
id: response.data.id,
name: response.data.name,
@ -791,10 +791,10 @@ define(
filterSubscribers();
// close popup
MailPoet.Modal.close();
}).fail(function(response) {
}).fail(function (response) {
if (response.errors.length > 0) {
MailPoet.Notice.error(
response.errors.map(function(error) { return error.message; }),
response.errors.map(function (error) { return error.message; }),
{ positionAfter: '#field_name' }
);
}
@ -848,7 +848,7 @@ define(
jQuery.map(window.mailpoetColumns, function (column, columnIndex) {
// check if the column id matches the selected id of one of the
// 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, hide the next button
if (column.id === 'email') {
@ -1009,7 +1009,7 @@ define(
});
_.each(subscribers, function () {
queue.add(function(queue) {
queue.add(function (queue) {
queue.pause();
MailPoet.Ajax.post({
api_version: window.mailpoet_api_version,
@ -1022,17 +1022,17 @@ define(
segments: segmentSelectElement.val(),
updateSubscribers: (jQuery(':radio[name="subscriber_update_option"]:checked').val() === 'yes')
})
}).done(function(response) {
}).done(function (response) {
importResults.created += response.data.created;
importResults.updated += response.data.updated;
importResults.segments = response.data.segments;
importResults.added_to_segment_with_welcome_notification = response.data.added_to_segment_with_welcome_notification;
queue.run();
}).fail(function(response) {
}).fail(function (response) {
MailPoet.Modal.loading(false);
if (response.errors.length > 0) {
MailPoet.Notice.error(
response.errors.map(function(error) { return error.message; }),
response.errors.map(function (error) { return error.message; }),
{ scroll: true }
);
}