1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/addon-sdk/source/examples/reddit-panel/data/panel.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,35 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +// This is a content script. It executes inside the context of the Reddit page 1.9 +// loaded into the panel and has access to that page's window object and other 1.10 +// global objects (although the page does not have access to globals defined by 1.11 +// this script unless they are explicitly attached to the window object). 1.12 +// 1.13 +// This content script is injected into the context of the Reddit page 1.14 +// by the Panel API, which is accessed by the main add-on script in lib/main.js. 1.15 +// See that script for more information about how the panel is created. 1.16 + 1.17 +$(window).click(function (event) { 1.18 + var t = event.target; 1.19 + 1.20 + // Don't intercept the click if it isn't on a link. 1.21 + if (t.nodeName != "A") 1.22 + return; 1.23 + 1.24 + // Don't intercept the click if it was on one of the links in the header 1.25 + // or next/previous footer, since those links should load in the panel itself. 1.26 + if ($(t).parents('#header').length || $(t).parents('.nextprev').length) 1.27 + return; 1.28 + 1.29 + // Intercept the click, passing it to the addon, which will load it in a tab. 1.30 + event.stopPropagation(); 1.31 + event.preventDefault(); 1.32 + self.port.emit('click', t.toString()); 1.33 +}); 1.34 + 1.35 +// Panels have an OS-specific background color by default, and the Mac OS X 1.36 +// background color is dark grey, but Reddit expects its background to be white 1.37 +// and looks odd when it isn't, so set it to white. 1.38 +$("body").css("background", "white");