Binding JQuery Handlers
Overview[edit]
Documentation describing how to set up JQuery handlers for CMS pages.
JavaScript libraries[edit]
Location[edit]
- As much as possible, re-use the generic handlers found in
cms.js. - Code specific to a particular content type should go in
[SECTION_BASE_DIR]_scripts/[SECTION_NAME].js. - Code should be compressed before uploading to production.
- Uncompressed code should be stored in
[SECTION_BASE_DIR]_scripts/[SECTION_NAME]-source.jswhich is on the local server but not uploaded to production.
Binding routines[edit]
- Binding routines are defined as JQuery plugins.
(function ($) {
var methods = {
bindListingsHandlers: function() {
return this.each(function() {
/* binding logic goes here... */
});
},
bindListingsButtons: function() {
return this.each(function() {
/* binding logic goes here... */
});
}
};
$.fn.[CONTENT_NAMESPACE] = function( method ) {
/* method calling logic */
if (methods[method]) {
return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
}
else if ( typeof method === 'object' || !method ) {
return methods.init.apply(this, arguments);
}
else {
$.error('Method ' + method + ' does not exist on jQuery.[CONTENT_NAMESPACE].');
}
return (false);
};
}) ( jQuery );
- The routines are then attached to page elements after the document content is loaded:
$(document).ready(function() {
$('#listings-container').[CONTENT_NAMESPACE]('bindListingsHandlers');
});