nicer API namespacing

This commit is contained in:
Sacha Greif 2015-04-24 09:48:36 +09:00
parent 8e5446cc75
commit 36e2d063ce
29 changed files with 72 additions and 72 deletions

View file

@ -10,19 +10,19 @@ Telescope.config.preloadSubscriptions.push('customPublication');
// ------------------------------------------------------------------------------------------- //
// add templates to the primary nav bar
Telescope.registerModule("primaryNav", {
Telescope.modules.register("primaryNav", {
template: 'customNav',
order: 99
});
// add templates to the secondary nav bar
Telescope.registerModule("secondaryNav", {
Telescope.modules.register("secondaryNav", {
template: 'customNav',
order: 99
});
// add items to the admin menu
Telescope.registerModule("adminMenu", {
Telescope.modules.register("adminMenu", {
route: 'customRoute',
label: 'customAdminLink',
description: '' // optional
@ -33,13 +33,13 @@ Telescope.registerModule("adminMenu", {
// ------------------------------------------------------------------------------------------- //
// add templates to the hero zone (before posts list)
Telescope.registerModule("hero", {
Telescope.modules.register("hero", {
template: 'customHero',
order: 99
});
// add templates to the footer (after posts list)
Telescope.registerModule("footer", {
Telescope.modules.register("footer", {
template: 'customFooter',
order: 99
});
@ -49,19 +49,19 @@ Telescope.registerModule("footer", {
// ------------------------------------------------------------------------------------------- //
// add templates to the post items
Telescope.registerModule("postItems", {
Telescope.modules.register("postItems", {
template: 'customModule',
order: 99
});
// add templates to the post heading zone
Telescope.registerModule("postHeading", {
Telescope.modules.register("postHeading", {
template: 'customHeading',
order: 99
});
// add templates to the post meta zone
Telescope.registerModule("postMeta", {
Telescope.modules.register("postMeta", {
template: 'customMeta',
order: 99
});
@ -70,12 +70,12 @@ Telescope.registerModule("postMeta", {
// -------------------------------------- User Profiles -------------------------------------- //
// ------------------------------------------------------------------------------------------- //
Telescope.registerModule("profileDisplay", {
Telescope.modules.register("profileDisplay", {
template: 'customTemplate',
order: 99
});
Telescope.registerModule("profileEdit", {
Telescope.modules.register("profileEdit", {
template: 'customTemplate',
order: 99
});

View file

@ -40,4 +40,4 @@ function afterCommentOperations (comment) {
};
Telescope.registerCallback("commentSubmitAsync", afterCommentOperations);
Telescope.callbacks.register("commentSubmitAsync", afterCommentOperations);

View file

@ -30,7 +30,7 @@ submitComment = function (comment) {
// ------------------------------ Callbacks ------------------------------ //
// run all post submit server callbacks on comment object successively
comment = Telescope.runCallbacks("commentSubmit", comment);
comment = Telescope.callbacks.run("commentSubmit", comment);
// -------------------------------- Insert -------------------------------- //
@ -39,7 +39,7 @@ submitComment = function (comment) {
// --------------------- Server-side Async Callbacks --------------------- //
// run all post submit server callbacks on comment object successively
Telescope.runCallbacks("commentSubmitAsync", comment, true);
Telescope.callbacks.run("commentSubmitAsync", comment, true);
return comment;
}

View file

@ -1,6 +1,6 @@
Template.modules.helpers({
getModules: function () {
var zone = this.toString();
return Telescope.getModules(zone);
return Telescope.modules.get(zone);
}
});

View file

@ -45,7 +45,7 @@ Telescope.upvoteItem = function (collection, item, user) {
// run all upvote callbacks on item successively
item = Telescope.runCallbacks("upvote", item);
item = Telescope.callbacks.run("upvote", item);
// ----------------------------------------------------------------------- //
@ -93,7 +93,7 @@ Telescope.upvoteItem = function (collection, item, user) {
// --------------------- Server-Side Async Callbacks --------------------- //
Telescope.runCallbacks("upvoteAsync", item, true);
Telescope.callbacks.run("upvoteAsync", item, true);
// ----------------------------------------------------------------------- //
}
@ -112,7 +112,7 @@ Telescope.downvoteItem = function (collection, item, user) {
// ------------------------------ Callbacks ------------------------------ //
// run all downvote callbacks on item successively
item = Telescope.runCallbacks("downvote", item);
item = Telescope.callbacks.run("downvote", item);
// ----------------------------------------------------------------------- //
@ -147,7 +147,7 @@ Telescope.downvoteItem = function (collection, item, user) {
// --------------------- Server-Side Async Callbacks --------------------- //
Telescope.runCallbacks("downvoteAsync", item, true);
Telescope.callbacks.run("downvoteAsync", item, true);
// ----------------------------------------------------------------------- //
}
@ -166,7 +166,7 @@ Telescope.cancelUpvote = function (collection, item, user) {
// ------------------------------ Callbacks ------------------------------ //
// run all cancel upvote callbacks on item successively
item = Telescope.runCallbacks("cancelUpvote", item);
item = Telescope.callbacks.run("cancelUpvote", item);
// ----------------------------------------------------------------------- //
@ -194,7 +194,7 @@ Telescope.cancelUpvote = function (collection, item, user) {
// --------------------- Server-Side Async Callbacks --------------------- //
Telescope.runCallbacks("cancelUpvoteAsync", item, true);
Telescope.callbacks.run("cancelUpvoteAsync", item, true);
// ----------------------------------------------------------------------- //
}
@ -214,7 +214,7 @@ Telescope.cancelDownvote = function (collection, item, user) {
// run all cancel downvote callbacks on item successively
item = Telescope.runCallbacks("cancelDownvote", item);
item = Telescope.callbacks.run("cancelDownvote", item);
// ----------------------------------------------------------------------- //
@ -242,7 +242,7 @@ Telescope.cancelDownvote = function (collection, item, user) {
// --------------------- Server-Side Async Callbacks --------------------- //
Telescope.runCallbacks("cancelDownvoteAsync", item, true);
Telescope.callbacks.run("cancelDownvoteAsync", item, true);
// ----------------------------------------------------------------------- //
}

View file

@ -102,4 +102,4 @@ function adminUserCreationNotification (user) {
});
return user;
}
Telescope.registerCallback("userCreated", adminUserCreationNotification)
Telescope.callbacks.register("userCreated", adminUserCreationNotification)

View file

@ -25,7 +25,7 @@ var mediaProperty = {
}
Posts.registerField(mediaProperty);
Telescope.registerModule("postThumbnail", {
Telescope.modules.register("postThumbnail", {
template: 'postThumbnail',
order: 15
});
@ -68,7 +68,7 @@ var thumbnailHeightProperty = {
Settings.addToSchema(thumbnailHeightProperty);
// add callback that adds "has-thumbnail" or "no-thumbnail" CSS classes
Telescope.registerCallback("postClass", function (post, postClass){
Telescope.callbacks.register("postClass", function (post, postClass){
var thumbnailClass = !!post.thumbnailUrl ? "has-thumbnail" : "no-thumbnail";
return postClass + " " + thumbnailClass;
});

View file

@ -83,7 +83,7 @@ var addMediaAfterSubmit = function (post) {
}
return post;
}
Telescope.registerCallback("postSubmitAsync", addMediaAfterSubmit);
Telescope.callbacks.register("postSubmitAsync", addMediaAfterSubmit);
// TODO: find a way to only do this is URL has actually changed?
function updateMediaOnEdit (updateObject) {
@ -95,7 +95,7 @@ function updateMediaOnEdit (updateObject) {
}
return updateObject;
}
Telescope.registerCallback("postEdit", updateMediaOnEdit);
Telescope.callbacks.register("postEdit", updateMediaOnEdit);
Meteor.methods({

View file

@ -28,7 +28,7 @@ Invites.deny({
remove: function(){ return true; }
});
Telescope.registerModule("profileEdit", {
Telescope.modules.register("profileEdit", {
template: 'userInvites',
order: 2
});
@ -38,7 +38,7 @@ Telescope.registerModule("profileEdit", {
user.inviteCount = Settings.get('startInvitesCount', 3);
return user;
}
Telescope.registerCallback("userCreated", setStartingInvites);
Telescope.callbacks.register("userCreated", setStartingInvites);
function checkIfInvited (user) {
// if the new user has been invited
@ -61,4 +61,4 @@ function checkIfInvited (user) {
}
return user;
}
Telescope.registerCallback("userCreated", checkIfInvited);
Telescope.callbacks.register("userCreated", checkIfInvited);

View file

@ -6,7 +6,7 @@ Telescope.callbacks = [];
* @param {String} hook - The name of the hook
* @param {Function} callback - The callback function
*/
Telescope.registerCallback = function (hook, callback) {
Telescope.callbacks.register = function (hook, callback) {
// if callback array doesn't exist yet, initialize it
if (typeof Telescope.callbacks[hook] === "undefined") {
@ -22,7 +22,7 @@ Telescope.registerCallback = function (hook, callback) {
* @param {Object} item - The post, comment, modifier, etc. on which to run the callbacks
* @param {Boolean} async - Whether to run the callback in async mode or not
*/
Telescope.runCallbacks = function (hook, item, async) {
Telescope.callbacks.run = function (hook, item, async) {
var async = typeof async === "undefined" ? false : async; // default to sync
var callbacks = Telescope.callbacks[hook];
@ -49,5 +49,7 @@ Telescope.runCallbacks = function (hook, item, async) {
}
} else { // else, just return the item unchanged
return item;
}
}

View file

@ -8,7 +8,7 @@ Telescope.modules = [];
* @param {string} module.template - The template to include
* @param {number} module.order - The order of the template in the zone
*/
Telescope.registerModule = function (zone, module) {
Telescope.modules.register = function (zone, module) {
// if module zone array doesn't exist yet, initialize it
if (typeof Telescope.modules[zone] === "undefined") {
@ -33,6 +33,6 @@ Telescope.registerModule = function (zone, module) {
* Retrieve an array containing all modules for a zone
* @param {string} zone - The name of the zone
*/
Telescope.getModules = function (zone) {
Telescope.modules.get = function (zone) {
return _.sortBy(Telescope.modules[zone], "order");
}

View file

@ -182,7 +182,7 @@ viewParameters.campaign = function (terms) {
};
}
Telescope.registerModule("hero", {
Telescope.modules.register("hero", {
template: 'newsletterBanner',
order: 10
});
@ -196,4 +196,4 @@ Telescope.registerModule("hero", {
}
return user;
}
Telescope.registerCallback("userCreated", subscribeUserOnCreation);
Telescope.callbacks.register("userCreated", subscribeUserOnCreation);

View file

@ -18,13 +18,13 @@ function postSubmitNotification (post) {
return post;
}
Telescope.registerCallback("postSubmitAsync", postSubmitNotification);
Telescope.callbacks.register("postSubmitAsync", postSubmitNotification);
function postApprovedNotification (post) {
Herald.createNotification(post.userId, {courier: 'postApproved', data: post});
return post;
}
Telescope.registerCallback("postApprovedAsync", postApprovedNotification);
Telescope.callbacks.register("postApprovedAsync", postApprovedNotification);
// add new comment notification callback on comment submit
function addCommentNotification (comment) {
@ -85,7 +85,7 @@ function addCommentNotification (comment) {
}
Telescope.registerCallback("commentSubmitAsync", addCommentNotification);
Telescope.callbacks.register("commentSubmitAsync", addCommentNotification);
var emailNotifications = {
propertyName: 'emailNotifications',
@ -125,4 +125,4 @@ function setNotificationDefaults (user) {
};
return user;
}
Telescope.registerCallback("userCreated", setNotificationDefaults);
Telescope.callbacks.register("userCreated", setNotificationDefaults);

View file

@ -31,4 +31,4 @@ function afterPostSubmitOperations (post) {
Telescope.upvoteItem(Posts, post, postAuthor);
return post;
}
Telescope.registerCallback("postSubmitAsync", afterPostSubmitOperations);
Telescope.callbacks.register("postSubmitAsync", afterPostSubmitOperations);

View file

@ -6,7 +6,7 @@ Template.post_item.created = function () {
Template.post_item.helpers({
postComponents: function () {
return Telescope.getModules("postComponents");
return Telescope.modules.get("postComponents");
},
moduleContext: function () { // not used for now
var module = this;
@ -22,7 +22,7 @@ Template.post_item.helpers({
var postAuthorClass = "author-"+post.author;
var postClass = Telescope.runCallbacks("postClass", postAuthorClass);
var postClass = Telescope.callbacks.run("postClass", postAuthorClass);
return postClass;
}

View file

@ -18,9 +18,7 @@ AutoForm.hooks({
// ------------------------------ Callbacks ------------------------------ //
// run all post submit client callbacks on properties object successively
post = Telescope.callbacks.postSubmitClient.reduce(function(result, currentFunction) {
return currentFunction(result);
}, post);
post = Telescope.callbacks.run("postSubmitClient");
return post;
}

View file

@ -49,7 +49,7 @@ Posts.submit = function (post) {
// ------------------------------ Callbacks ------------------------------ //
// run all post submit server callbacks on post object successively
post = Telescope.runCallbacks("postSubmit", post);
post = Telescope.callbacks.run("postSubmit", post);
// -------------------------------- Insert ------------------------------- //
@ -57,7 +57,7 @@ Posts.submit = function (post) {
// --------------------- Server-Side Async Callbacks --------------------- //
Telescope.runCallbacks("postSubmitAsync", post, true);
Telescope.callbacks.run("postSubmitAsync", post, true);
return post;
}
@ -218,7 +218,7 @@ Meteor.methods({
var result = Posts.update(post._id, {$set: set}, {validate: false});
// --------------------- Server-Side Async Callbacks --------------------- //
Telescope.runCallbacks("postApprovedAsync", post, true);
Telescope.callbacks.run("postApprovedAsync", post, true);
}else{
Messages.flash('You need to be an admin to do that.', "error");

View file

@ -1,10 +1,10 @@
Telescope.registerModule("postListTop", {
Telescope.modules.register("postListTop", {
template: 'postViewsNav',
order: 99
});
Telescope.registerModule("postComponents", [
Telescope.modules.register("postComponents", [
{
template: 'postRank',
order: 1
@ -31,7 +31,7 @@ Telescope.registerModule("postComponents", [
}
]);
Telescope.registerModule("postHeading", [
Telescope.modules.register("postHeading", [
{
template: 'postTitle',
order: 10
@ -42,7 +42,7 @@ Telescope.registerModule("postHeading", [
}
]);
Telescope.registerModule("postMeta", [
Telescope.modules.register("postMeta", [
{
template: 'postAuthor',
order: 10

View file

@ -1,6 +1,6 @@
Releases = new Meteor.Collection('releases');
Telescope.registerModule("hero", {
Telescope.modules.register("hero", {
template: 'currentRelease'
});

View file

@ -1,4 +1,4 @@
Telescope.registerModule("postComponents", {
Telescope.modules.register("postComponents", {
template: 'postShare',
order: 25
});

View file

@ -1,4 +1,4 @@
Telescope.registerModule("thread", {
Telescope.modules.register("thread", {
template: 'postSubscribe',
order: 10
});
@ -29,7 +29,7 @@ Posts.registerField(
}
);
Telescope.registerModule("profileEdit", {
Telescope.modules.register("profileEdit", {
template: 'userSubscribedPosts',
order: 5
});

View file

@ -1,4 +1,4 @@
Telescope.registerModule("postListTop", {
Telescope.modules.register("postListTop", {
template: 'taglineBanner',
order: 1
});

View file

@ -59,7 +59,7 @@ getCategoryUrl = function(slug){
};
// add callback that adds categories CSS classes
Telescope.registerCallback("postClass", function (post, postClass){
Telescope.callbacks.register("postClass", function (post, postClass){
var classArray = _.map(getPostCategories(post), function (category){return "category-"+category.slug});
return postClass + " " + classArray.join(' ');
});

View file

@ -1,22 +1,22 @@
Telescope.registerModule("adminMenu", {
Telescope.modules.register("adminMenu", {
route: 'categories',
label: 'Categories',
description: 'add_and_remove_categories'
});
// push "categories" modules to postHeading
Telescope.registerModule("postHeading", {
Telescope.modules.register("postHeading", {
template: 'postCategories',
order: 30
});
// push "categoriesMenu" template to primaryNav
Telescope.registerModule("primaryNav", {
Telescope.modules.register("primaryNav", {
template: 'categoriesMenu',
order: 50
});
Telescope.registerModule("mobileNav", {
Telescope.modules.register("mobileNav", {
template: 'categoriesMenu',
order: 10
});

View file

@ -18,11 +18,11 @@ function postSubmitCheckCategories (post) {
checkCategories(post);
return post;
}
Telescope.registerCallback("submitPost", postSubmitCheckCategories);
Telescope.callbacks.register("submitPost", postSubmitCheckCategories);
function postEditCheckCategories (updateObject) {
var post = updateObject.$set;
checkCategories(post);
return updateObject;
}
Telescope.registerCallback("submitPost", postEditCheckCategories);
Telescope.callbacks.register("submitPost", postEditCheckCategories);

View file

@ -36,6 +36,6 @@ Meteor.startup(function () {
});
});
Telescope.registerModule("hero", {
Telescope.modules.register("hero", {
template: 'updateBanner'
});

View file

@ -6,4 +6,4 @@
function hasCompletedProfile (user) {
return !!Users.getEmail(user) && !!Users.getUserName(user);
}
Telescope.registerCallback("profileCompletedChecks", hasCompletedProfile);
Telescope.callbacks.register("profileCompletedChecks", hasCompletedProfile);

View file

@ -1,5 +1,5 @@
Telescope.registerModule("profileDisplay", [
Telescope.modules.register("profileDisplay", [
{
template: 'userInfo',
order: 1
@ -22,7 +22,7 @@ Telescope.registerModule("profileDisplay", [
}
]);
Telescope.registerModule("profileEdit", [
Telescope.modules.register("profileEdit", [
{
template: 'userAccount',
order: 1

View file

@ -39,7 +39,7 @@ Accounts.onCreateUser(function(options, user){
// ------------------------------ Callbacks ------------------------------ //
// run all post submit client callbacks on properties object successively
user = Telescope.runCallbacks("userCreated", user);
user = Telescope.callbacks.run("userCreated", user);
// ------------------------------ Analytics ------------------------------ //