Created
August 4, 2010 14:35
-
-
Save markupboy/508226 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CPB.module = function() {}; | |
CPB.module.prototype.constructor = CPB.module; | |
CPB.module.prototype.reload = function(event, data) { | |
var module = this; | |
module.lastUpdate = CPB.timestamp(); | |
module.path = data.path; | |
CPB.dispatcher.process(data.path, function(data) { | |
module.render(module.view.reload, data[module.shortName]); | |
}); | |
module.lastUpdate = CPB.timestamp(); | |
}; | |
CPB.module.prototype.render = function(view, data) { | |
view(data); | |
}; | |
CPB.remoteModule = function(shortName, options) { | |
var module = this; | |
// if no shortname is set, throw an error | |
// all event bindings are predicated on this shortname matching the module | |
if(!shortName || shortName == '') { | |
throw 'module shortname can not be blank: ' + this; | |
} | |
// instantiate module variables | |
module.shortName = shortName; | |
module.topicPrefix = options.topicPrefix || CPB.defaults.topicPrefix; | |
module.lastUpdate = CPB.timestamp(); | |
module.updatePath = options.updatePath || CPB.defaults.updatePath.replace(/\{[^\}]*\}/g, function(key) { | |
return module[key.slice(1,-1)]; | |
}); | |
module.updateBindPoint = options.updateBindPoint; | |
module.paginatePath = options.paginatePath || CPB.defaults.paginatePath.replace(/\{[^\}]*\}/g, function(key) { | |
return module[key.slice(1,-1)]; | |
}); | |
module.defaultLoaded = options.defaultLoaded || CPB.defaults.defaultLoaded; | |
module.paginateOffset = module.defaultLoaded; | |
module.paginateLimit = options.paginateLimit || CPB.defaults.paginateLimit; | |
module.paginateBindPoint = options.paginateBindPoint; | |
module.autoUpdate = options.autoUpdate || false; | |
module.autoUpdateInterval = options.autoUpdateInterval || 60000; | |
module.loader = options.loader; | |
if(options.callback && typeof(options.callback) == 'function') { | |
module.initOnReadyCallback = options.callback; | |
} | |
// register module with reload stack | |
CPB.modules.push(this); | |
// set up necessary views and empty partial object | |
module.view = { | |
reload: null, | |
update: null, | |
paginate: null, | |
partial: {} | |
}; | |
// register event listeners for primary methods | |
$(document).bind('reload.'+shortName, function(event, data) { | |
module.reload(event, data); | |
}); | |
$(document).bind('update.'+shortName, function(event, data) { | |
module.update(event, data); | |
}); | |
$(document).bind('paginate.'+shortName, function(event, data) { | |
module.paginate(event, data); | |
}); | |
}; | |
CPB.remoteModule.prototype = new CPB.module; | |
CPB.remoteModule.prototype.constructor = CPB.remoteModule; | |
CPB.remoteModule.prototype.initOnReady = function() { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment