Last active
April 27, 2016 00:20
-
-
Save doublejosh/600ac34a6a73d5cca7beb6aaf3f082e6 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
| /** | |
| * 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