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