panel.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435
  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. // This is a content script. It executes inside the context of the Reddit page
  5. // loaded into the panel and has access to that page's window object and other
  6. // global objects (although the page does not have access to globals defined by
  7. // this script unless they are explicitly attached to the window object).
  8. //
  9. // This content script is injected into the context of the Reddit page
  10. // by the Panel API, which is accessed by the main add-on script in lib/main.js.
  11. // See that script for more information about how the panel is created.
  12. $(window).click(function (event) {
  13. var t = event.target;
  14. // Don't intercept the click if it isn't on a link.
  15. if (t.nodeName != "A")
  16. return;
  17. // Don't intercept the click if it was on one of the links in the header
  18. // or next/previous footer, since those links should load in the panel itself.
  19. if ($(t).parents('#header').length || $(t).parents('.nextprev').length)
  20. return;
  21. // Intercept the click, passing it to the addon, which will load it in a tab.
  22. event.stopPropagation();
  23. event.preventDefault();
  24. self.port.emit('click', t.toString());
  25. });
  26. // Panels have an OS-specific background color by default, and the Mac OS X
  27. // background color is dark grey, but Reddit expects its background to be white
  28. // and looks odd when it isn't, so set it to white.
  29. $("body").css("background", "white");