Labs/F1/Modularity/WebMod HOWTO: Difference between revisions

Jump to navigation Jump to search
Line 41: Line 41:


== Implementing a WebMod ==
== Implementing a WebMod ==
The WebMod provider, ShareBook in our fictitious example, must then implement the WebMod functionality by providing an HTML document containing appropriate JavaScript, at the URL <tt>https://sharebook.example.com/webmods/link-share</tt>. This WebMod document will look like:
<html>
<head>
  <script src="jquery.js" />
  <!-- the following script provides WebMod API bindings -->
  <script src="https://webmods.mozilla.org/js/include.js" />
</head>
<body>
  <script>
    // on login
    WebMod.onLogin(function(credentials, callback) {
      // inspect the credentials object and use it to authenticate
      // return basic user data via the callback
      callback({'status': 'ok', 'displayname': 'Bob Smith', 'username' : 'bobsmith'});
    });
    // webmod API call
    WebMod.onCall(function(func_name, args, callback) {
      // implement the function
      // return any expected result via the callback
      callback(result);
    });
   
    // tell the WebMod framework that we're ready to go
    $(document).ready(function() {
      WebMod.ready();
    });
  </script>
</body>
</html>
Note that jQuery is not required, it is used here to simplify the code.
668

edits

Navigation menu