Skip to content

Instantly share code, notes, and snippets.

@Sitebase
Created October 7, 2014 08:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Sitebase/70f61a885349be2d0dc9 to your computer and use it in GitHub Desktop.
Save Sitebase/70f61a885349be2d0dc9 to your computer and use it in GitHub Desktop.
Example of a custom JavaScript module for the BuboBox widget. This module will add an extra popup menu item with some custom text.
/**
* This is an example BBBX widget module
* It can be used to add additional functionallity to the BuboBox platform in a modularized way
*/
window.bbbx_modules = window.bbbx_modules || []; // Make modules array if not yet exists
window.bbbx_modules.push(function(sandbox, $) {
var NAME = 'custommodule';
/**
* Add a stack item to the recorder/player popup
* name can be pre/post or name of a stack item + pre/post
* For example "form.pre" or "terms.post"
*/
function addItem( e ) {
e.stack.itemReady({
name: 'pre',
view: {
title: 'Thank you',
body: 'Thanks for joining this challenge.',
footer: '<button class="bbbx-button" data-bbbx-trigger="stack.next">Next</button>'
}
});
}
var exports = {
NAME: NAME,
/**
* Module is registered inside the BuboBox widget
*/
init: function() {
console.error('Custom module initialized');
},
/**
* All modules are loaded
*/
ready: function() {
console.error('Custom module ready, all other modules are also loaded at this point');
},
/**
* Add listeners for certain actions that happen
* in the BuboBox widgets
*/
bind: function() {
this.subscribe('stack.add.pre', addItem);
},
/**
* Remove listeners we create in the bind function
*/
unbind: function() {
sandbox.unsubscribe(['stack.add.pre', addItem]);
},
/**
* Clean up all stuff this module has created
* - DOM elements
* - Bindings
*/
destroy: function() {
this.unbind();
// remove some left over DOM elments
}
};
return exports;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment