Wrap existing JS modules in AMD module style
This commit is contained in:
@@ -1,6 +1,14 @@
|
|||||||
jQuery(function($) {
|
define('admin', [
|
||||||
|
'./ajax',
|
||||||
|
'notice.js',
|
||||||
|
'modal.js',
|
||||||
|
'lib/handlebars.min.js',
|
||||||
|
'handlebars_helpers.js'
|
||||||
|
], function() {
|
||||||
|
jQuery(function($) {
|
||||||
// dom ready
|
// dom ready
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
/**
|
define('ajax', ['./mailpoet', 'jquery'], function(MailPoet, jQuery) {
|
||||||
* MailPoet Ajax
|
|
||||||
**/
|
|
||||||
(function() {
|
|
||||||
"use strict";
|
"use strict";
|
||||||
|
/**
|
||||||
|
* MailPoet Ajax
|
||||||
|
**/
|
||||||
|
|
||||||
MailPoet.Ajax = {
|
MailPoet.Ajax = {
|
||||||
version: 0.1,
|
version: 0.1,
|
||||||
@@ -64,4 +64,4 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})(window.MailPoet = window.MailPoet || {}, jQuery);
|
});
|
||||||
|
@@ -1,17 +1,18 @@
|
|||||||
// Handlebars helpers
|
define('handlebars_helpers', ['lib/handlebars.min.js'], function(Handlebars) {
|
||||||
Handlebars.registerHelper('concat', function() {
|
// Handlebars helpers
|
||||||
|
Handlebars.registerHelper('concat', function() {
|
||||||
var size = (arguments.length - 1),
|
var size = (arguments.length - 1),
|
||||||
output = '';
|
output = '';
|
||||||
for(var i = 0; i < size; i++) {
|
for(var i = 0; i < size; i++) {
|
||||||
output += arguments[i];
|
output += arguments[i];
|
||||||
};
|
};
|
||||||
return output;
|
return output;
|
||||||
});
|
});
|
||||||
|
|
||||||
Handlebars.registerHelper('number_format', function(value, block) {
|
Handlebars.registerHelper('number_format', function(value, block) {
|
||||||
return Number(value).toLocaleString();
|
return Number(value).toLocaleString();
|
||||||
});
|
});
|
||||||
Handlebars.registerHelper('date_format', function(timestamp, block) {
|
Handlebars.registerHelper('date_format', function(timestamp, block) {
|
||||||
if(window.moment) {
|
if(window.moment) {
|
||||||
if(timestamp === undefined || isNaN(timestamp) || timestamp <= 0) {
|
if(timestamp === undefined || isNaN(timestamp) || timestamp <= 0) {
|
||||||
return;
|
return;
|
||||||
@@ -28,14 +29,14 @@ Handlebars.registerHelper('date_format', function(timestamp, block) {
|
|||||||
} else {
|
} else {
|
||||||
return timestamp;
|
return timestamp;
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
Handlebars.registerHelper('cycle', function(value, block) {
|
Handlebars.registerHelper('cycle', function(value, block) {
|
||||||
var values = value.split(' ');
|
var values = value.split(' ');
|
||||||
return values[block.data.index % (values.length + 1)];
|
return values[block.data.index % (values.length + 1)];
|
||||||
});
|
});
|
||||||
|
|
||||||
Handlebars.registerHelper('ifCond', function (v1, operator, v2, options) {
|
Handlebars.registerHelper('ifCond', function (v1, operator, v2, options) {
|
||||||
switch (operator) {
|
switch (operator) {
|
||||||
case '==':
|
case '==':
|
||||||
return (v1 == v2) ? options.fn(this) : options.inverse(this);
|
return (v1 == v2) ? options.fn(this) : options.inverse(this);
|
||||||
@@ -63,38 +64,38 @@ Handlebars.registerHelper('ifCond', function (v1, operator, v2, options) {
|
|||||||
default:
|
default:
|
||||||
return options.inverse(this);
|
return options.inverse(this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Handlebars.registerHelper('nl2br', function(value, block) {
|
Handlebars.registerHelper('nl2br', function(value, block) {
|
||||||
return value.gsub("\n", "<br />");
|
return value.gsub("\n", "<br />");
|
||||||
});
|
});
|
||||||
|
|
||||||
Handlebars.registerHelper('json_encode', function(value, block) {
|
Handlebars.registerHelper('json_encode', function(value, block) {
|
||||||
return JSON.stringify(value);
|
return JSON.stringify(value);
|
||||||
});
|
});
|
||||||
|
|
||||||
Handlebars.registerHelper('json_decode', function(value, block) {
|
Handlebars.registerHelper('json_decode', function(value, block) {
|
||||||
return JSON.parse(value);
|
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;
|
var url = window.location.protocol + "//" + window.location.host + window.location.pathname;
|
||||||
|
|
||||||
return url + value;
|
return url + value;
|
||||||
});
|
});
|
||||||
Handlebars.registerHelper('emailFromMailto', function(value) {
|
Handlebars.registerHelper('emailFromMailto', function(value) {
|
||||||
var mailtoMatchingRegex = /^mailto\:/i;
|
var mailtoMatchingRegex = /^mailto\:/i;
|
||||||
if (typeof value === 'string' && value.match(mailtoMatchingRegex)) {
|
if (typeof value === 'string' && value.match(mailtoMatchingRegex)) {
|
||||||
return value.replace(mailtoMatchingRegex, '');
|
return value.replace(mailtoMatchingRegex, '');
|
||||||
} else {
|
} else {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
Handlebars.registerHelper('lookup', function(obj, field, options) {
|
Handlebars.registerHelper('lookup', function(obj, field, options) {
|
||||||
return obj && obj[field];
|
return obj && obj[field];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
Handlebars.registerHelper('rsa_key', function(value, block) {
|
Handlebars.registerHelper('rsa_key', function(value, block) {
|
||||||
// extract all lines into an array
|
// extract all lines into an array
|
||||||
if(value === undefined) return '';
|
if(value === undefined) return '';
|
||||||
|
|
||||||
@@ -106,14 +107,14 @@ Handlebars.registerHelper('rsa_key', function(value, block) {
|
|||||||
|
|
||||||
// return concatenated lines
|
// return concatenated lines
|
||||||
return lines.join('');
|
return lines.join('');
|
||||||
});
|
});
|
||||||
|
|
||||||
Handlebars.registerHelper('trim', function(value, block) {
|
Handlebars.registerHelper('trim', function(value, block) {
|
||||||
if(value === null || value === undefined) return '';
|
if(value === null || value === undefined) return '';
|
||||||
return value.trim();
|
return value.trim();
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {{ellipsis}}
|
* {{ellipsis}}
|
||||||
* From: https://github.com/assemble/handlebars-helpers
|
* From: https://github.com/assemble/handlebars-helpers
|
||||||
* @author: Jon Schlinkert <http://github.com/jonschlinkert>
|
* @author: Jon Schlinkert <http://github.com/jonschlinkert>
|
||||||
@@ -123,7 +124,7 @@ Handlebars.registerHelper('trim', function(value, block) {
|
|||||||
* @param {String} append The string to append if charaters are omitted.
|
* @param {String} append The string to append if charaters are omitted.
|
||||||
* @return {String} The truncated string.
|
* @return {String} The truncated string.
|
||||||
*/
|
*/
|
||||||
Handlebars.registerHelper('ellipsis', function (str, limit, append) {
|
Handlebars.registerHelper('ellipsis', function (str, limit, append) {
|
||||||
if (append === undefined) {
|
if (append === undefined) {
|
||||||
append = '';
|
append = '';
|
||||||
}
|
}
|
||||||
@@ -133,8 +134,9 @@ Handlebars.registerHelper('ellipsis', function (str, limit, append) {
|
|||||||
} else {
|
} else {
|
||||||
return sanitized;
|
return sanitized;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Handlebars.registerHelper('getNumber', function (string) {
|
Handlebars.registerHelper('getNumber', function (string) {
|
||||||
return parseInt(string, 10);
|
return parseInt(string, 10);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
9
assets/js/mailpoet.js
Normal file
9
assets/js/mailpoet.js
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
define('mailpoet', [], function() {
|
||||||
|
// A placeholder for MailPoet object
|
||||||
|
var MailPoet = {};
|
||||||
|
|
||||||
|
// Expose MailPoet globally
|
||||||
|
window.MailPoet = MailPoet;
|
||||||
|
|
||||||
|
return MailPoet;
|
||||||
|
});
|
@@ -1,4 +1,6 @@
|
|||||||
/*==================================================================================================
|
define('modal', ['./mailpoet', 'jquery'], function(MailPoet, jQuery) {
|
||||||
|
"use strict";
|
||||||
|
/*==================================================================================================
|
||||||
|
|
||||||
MailPoet Modal:
|
MailPoet Modal:
|
||||||
|
|
||||||
@@ -73,9 +75,7 @@
|
|||||||
MailPoet.Modal.loading(true); // displays loading indicator
|
MailPoet.Modal.loading(true); // displays loading indicator
|
||||||
MailPoet.Modal.loading(false); // hides loading indicator
|
MailPoet.Modal.loading(false); // hides loading indicator
|
||||||
|
|
||||||
==================================================================================================*/
|
==================================================================================================*/
|
||||||
(function() {
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
MailPoet.Modal = {
|
MailPoet.Modal = {
|
||||||
version: 0.8,
|
version: 0.8,
|
||||||
@@ -636,4 +636,4 @@
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})(window.MailPoet = window.MailPoet || {}, jQuery);
|
});
|
||||||
|
@@ -1,4 +1,6 @@
|
|||||||
/*==================================================================================================
|
define('notice', ['./mailpoet', 'jquery'], function(MailPoet, jQuery) {
|
||||||
|
"use strict";
|
||||||
|
/*==================================================================================================
|
||||||
|
|
||||||
MailPoet Notice:
|
MailPoet Notice:
|
||||||
|
|
||||||
@@ -36,9 +38,7 @@
|
|||||||
}, 400);
|
}, 400);
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
==================================================================================================*/
|
==================================================================================================*/
|
||||||
(function(){
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
MailPoet.Notice = {
|
MailPoet.Notice = {
|
||||||
version: 0.2,
|
version: 0.2,
|
||||||
@@ -172,4 +172,4 @@
|
|||||||
}, options));
|
}, options));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
})(window.MailPoet = window.MailPoet || {}, jQuery);
|
});
|
||||||
|
1166
assets/js/src/admin.js
Normal file
1166
assets/js/src/admin.js
Normal file
File diff suppressed because one or more lines are too long
@@ -23,11 +23,7 @@
|
|||||||
|
|
||||||
<!-- javascripts -->
|
<!-- javascripts -->
|
||||||
<%= javascript(
|
<%= javascript(
|
||||||
'ajax.js',
|
'src/admin.js'
|
||||||
'notice.js',
|
|
||||||
'modal.js',
|
|
||||||
'lib/handlebars.min.js',
|
|
||||||
'handlebars_helpers.js'
|
|
||||||
)%>
|
)%>
|
||||||
|
|
||||||
<!-- handlebars templates -->
|
<!-- handlebars templates -->
|
||||||
|
@@ -5,7 +5,7 @@ var path = require('path'),
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
context: __dirname ,
|
context: __dirname ,
|
||||||
entry: {
|
entry: {
|
||||||
mailpoet: './assets/js/mailpoet',
|
admin: './assets/js/admin.js',
|
||||||
},
|
},
|
||||||
output: {
|
output: {
|
||||||
path: './assets/js/src',
|
path: './assets/js/src',
|
||||||
@@ -41,5 +41,8 @@ module.exports = {
|
|||||||
alias: {
|
alias: {
|
||||||
'hbs': 'handlebars-loader'
|
'hbs': 'handlebars-loader'
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
externals: {
|
||||||
|
'jquery': 'jQuery',
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user