events.js 944 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* This Source Code Form is subject to the terms of the Mozilla Public
  2. * License, v. 2.0. If a copy of the MPL was not distributed with this
  3. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  4. "use strict";
  5. module.metadata = {
  6. "stability": "unstable"
  7. };
  8. const ON_PREFIX = "on";
  9. const TAB_PREFIX = "Tab";
  10. const EVENTS = {
  11. ready: "DOMContentLoaded",
  12. load: "load", // Used for non-HTML content
  13. pageshow: "pageshow", // Used for cached content
  14. open: "TabOpen",
  15. close: "TabClose",
  16. activate: "TabSelect",
  17. deactivate: null,
  18. pinned: "TabPinned",
  19. unpinned: "TabUnpinned"
  20. }
  21. exports.EVENTS = EVENTS;
  22. Object.keys(EVENTS).forEach(function(name) {
  23. EVENTS[name] = {
  24. name: name,
  25. listener: createListenerName(name),
  26. dom: EVENTS[name]
  27. }
  28. });
  29. function createListenerName (name) {
  30. if (name === 'pageshow')
  31. return 'onPageShow';
  32. else
  33. return ON_PREFIX + name.charAt(0).toUpperCase() + name.substr(1);
  34. }