michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: // This is a content script. It executes inside the context of the Reddit page michael@0: // loaded into the panel and has access to that page's window object and other michael@0: // global objects (although the page does not have access to globals defined by michael@0: // this script unless they are explicitly attached to the window object). michael@0: // michael@0: // This content script is injected into the context of the Reddit page michael@0: // by the Panel API, which is accessed by the main add-on script in lib/main.js. michael@0: // See that script for more information about how the panel is created. michael@0: michael@0: $(window).click(function (event) { michael@0: var t = event.target; michael@0: michael@0: // Don't intercept the click if it isn't on a link. michael@0: if (t.nodeName != "A") michael@0: return; michael@0: michael@0: // Don't intercept the click if it was on one of the links in the header michael@0: // or next/previous footer, since those links should load in the panel itself. michael@0: if ($(t).parents('#header').length || $(t).parents('.nextprev').length) michael@0: return; michael@0: michael@0: // Intercept the click, passing it to the addon, which will load it in a tab. michael@0: event.stopPropagation(); michael@0: event.preventDefault(); michael@0: self.port.emit('click', t.toString()); michael@0: }); michael@0: michael@0: // Panels have an OS-specific background color by default, and the Mac OS X michael@0: // background color is dark grey, but Reddit expects its background to be white michael@0: // and looks odd when it isn't, so set it to white. michael@0: $("body").css("background", "white");