Skip to content

Instantly share code, notes, and snippets.

@doublejosh
Last active April 27, 2016 00:20
Show Gist options
  • Select an option

  • Save doublejosh/600ac34a6a73d5cca7beb6aaf3f082e6 to your computer and use it in GitHub Desktop.

Select an option

Save doublejosh/600ac34a6a73d5cca7beb6aaf3f082e6 to your computer and use it in GitHub Desktop.
/**
* Example of Behave JS with public and private functions,
* using flexible private function to process results. Shown
* here firing on page load and AJAX submits.
*/
(function ($) {
// Note {only: false} allows AJAX context rather than ready.
var behave = Drupal.behave('myBehavior', {only: false}),
behavior = behave.behavior();
/**
* Available as: Drupal.behaviors.myBehavior.myPublicFunction()
*/
behavior.myPublicFunction = function (callback) {
var data;
callback(data);
};
/**
* Private function.
*/
function myPrivateFunction (data) {
console.log(data);
}
/**
* Implements Drupal behavior.
*/
behave.attach(function (context, settings, $) {
// Fire public function providing internal data process function.
// "Mark the registered events."
behavior.myPublicFunction(myPrivateFunction);
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment