Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: common.js

Issue 29321336: Issue 2381 - Added share overlay to options page (Closed)
Patch Set: Rebased to 312559088567 Created July 16, 2015, 1:41 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « README.md ('k') | firstRun.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH
4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation.
8 *
9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 (function(global)
19 {
20 global.E = function E(id)
21 {
22 return document.getElementById(id);
23 }
24
25 global.getDocLink = function(link, callback)
26 {
27 ext.backgroundPage.sendMessage({
28 type: "app.get",
29 what: "doclink",
30 link: link
31 }, callback);
32 }
33
34 global.checkShareResource = function(url, callback)
35 {
36 ext.backgroundPage.sendMessage(
37 {
38 type: "filters.blocked",
39 url: url,
40 requestType: "SCRIPT",
41 docDomain: "adblockplus.org",
42 thirdParty: true
43 }, callback);
44 }
45
46 global.openSharePopup = function(url)
47 {
48 var glassPane = E("glass-pane");
49 if (!glassPane)
50 {
51 glassPane = document.createElement("div");
52 glassPane.setAttribute("id", "glass-pane");
53 document.body.appendChild(glassPane);
54 }
55 var iframe = E("share-popup");
56 if (!iframe)
57 {
58 iframe = document.createElement("iframe");
59 iframe.setAttribute("id", "share-popup");
60 iframe.setAttribute("scrolling", "no");
61 glassPane.appendChild(iframe);
62 }
63 var popupMessageReceived = false;
64
65 var popupMessageListener = function(event)
66 {
67 if (!/[.\/]adblockplus\.org$/.test(event.origin)
68 || !("width" in event.data)
69 || !("height" in event.data))
70 return;
71
72 var width = event.data.width;
73 var height = event.data.height;
74 iframe.width = width;
75 iframe.height = height;
76 iframe.style.marginTop = -height/2 + "px";
77 iframe.style.marginLeft = -width/2 + "px";
78 popupMessageReceived = true;
79 window.removeEventListener("message", popupMessageListener);
80 };
81 // Firefox requires last parameter to be true to be triggered by unprivilege d pages
82 window.addEventListener("message", popupMessageListener, false, true);
83
84 var popupLoadListener = function()
85 {
86 if (popupMessageReceived)
87 {
88 iframe.className = "visible";
89
90 var popupCloseListener = function()
91 {
92 iframe.className = glassPane.className = "";
93 document.removeEventListener("click", popupCloseListener);
94 };
95 document.addEventListener("click", popupCloseListener, false);
96 }
97 else
98 {
99 glassPane.className = "";
100 window.removeEventListener("message", popupMessageListener);
101 }
102
103 iframe.removeEventListener("load", popupLoadListener);
104 };
105 iframe.addEventListener("load", popupLoadListener, false);
106
107 iframe.src = url;
108 glassPane.className = "visible";
109 }
110 })(this);
OLDNEW
« no previous file with comments | « README.md ('k') | firstRun.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld