2015-05-07 18:00:23 +09:00
|
|
|
/**
|
|
|
|
* Template modules let you insert templates in specific zones in the app's layout.
|
|
|
|
* @namespace Telescope.modules
|
|
|
|
*/
|
2015-04-23 17:45:37 +09:00
|
|
|
|
2015-04-27 10:10:52 +09:00
|
|
|
Telescope.modules = {};
|
2015-04-23 17:45:37 +09:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a module to a template zone
|
|
|
|
* @param {string} zone - The name of the zone
|
|
|
|
* @param {Object|Object[]} module - The module object (or an array of modules)
|
|
|
|
* @param {string} module.template - The template to include
|
|
|
|
* @param {number} module.order - The order of the template in the zone
|
2015-05-10 13:37:42 +09:00
|
|
|
*
|
|
|
|
* @example
|
2015-05-17 15:38:02 +09:00
|
|
|
* Telescope.modules.add("hero", {
|
2015-05-10 13:37:42 +09:00
|
|
|
* template: "newsletterBanner",
|
|
|
|
* order: 10
|
|
|
|
* });
|
2015-04-23 17:45:37 +09:00
|
|
|
*/
|
2015-05-17 15:38:02 +09:00
|
|
|
Telescope.modules.add = function (zone, module) {
|
2015-05-01 18:22:00 +02:00
|
|
|
|
2015-04-23 17:45:37 +09:00
|
|
|
// if module zone array doesn't exist yet, initialize it
|
|
|
|
if (typeof Telescope.modules[zone] === "undefined") {
|
|
|
|
Telescope.modules[zone] = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Array.isArray(module)) {
|
|
|
|
|
|
|
|
var modules = module; // we're dealing with an Array, so let's add an "s"
|
|
|
|
modules.forEach( function (module) {
|
|
|
|
Telescope.modules[zone].push(module);
|
|
|
|
});
|
2015-05-01 18:22:00 +02:00
|
|
|
|
2015-04-23 17:45:37 +09:00
|
|
|
} else {
|
2015-05-01 18:22:00 +02:00
|
|
|
|
2015-04-23 17:45:37 +09:00
|
|
|
Telescope.modules[zone].push(module);
|
2015-05-01 18:22:00 +02:00
|
|
|
|
2015-04-23 17:45:37 +09:00
|
|
|
}
|
2015-05-01 18:22:00 +02:00
|
|
|
};
|
2015-04-23 17:45:37 +09:00
|
|
|
|
2015-04-27 10:10:52 +09:00
|
|
|
/**
|
|
|
|
* Remove a module from a zone
|
|
|
|
* @param {string} zone - The name of the zone
|
|
|
|
* @param {string} template - The name of the template to remove
|
|
|
|
*/
|
|
|
|
Telescope.modules.remove = function (zone, template) {
|
|
|
|
Telescope.modules[zone] = _.reject(Telescope.modules[zone], function (module) {
|
|
|
|
return module.template === template;
|
|
|
|
});
|
2015-05-01 18:22:00 +02:00
|
|
|
};
|
2015-04-27 10:10:52 +09:00
|
|
|
|
2015-05-16 17:49:16 +09:00
|
|
|
/**
|
|
|
|
* Removes all modules from a zone
|
|
|
|
* @param {string} zone - The name of the zone
|
|
|
|
*/
|
|
|
|
Telescope.modules.removeAll = function (zone) {
|
|
|
|
Telescope.modules[zone] = [];
|
|
|
|
};
|
|
|
|
|
2015-04-23 17:45:37 +09:00
|
|
|
/**
|
|
|
|
* Retrieve an array containing all modules for a zone
|
|
|
|
* @param {string} zone - The name of the zone
|
2015-05-07 18:00:23 +09:00
|
|
|
* @returns {Object[]} Returns a sorted array of the zone's modules
|
2015-04-23 17:45:37 +09:00
|
|
|
*/
|
2015-04-24 09:48:36 +09:00
|
|
|
Telescope.modules.get = function (zone) {
|
2015-04-23 17:45:37 +09:00
|
|
|
return _.sortBy(Telescope.modules[zone], "order");
|
2015-05-01 18:22:00 +02:00
|
|
|
};
|