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

Delta Between Two Patch Sets: safari/ext/popup.js

Issue 5037474598354944: Only reload the popover in Safari, when itself is shown for a different tab (Closed)
Left Patch Set: Created Dec. 27, 2013, 7:56 p.m.
Right Patch Set: Reload the bubble only when it is shown for a different tab Created Jan. 15, 2014, 5:53 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 with (safari.extension.globalPage.contentWindow) 1 (function()
2 { 2 {
3 this.ext = ext; 3 // Safari will load the popover once, and then show it everytime the icon is
4 this.TabMap = TabMap; 4 // clicked. While Chrome loads it everytime you click the icon. So in order to
5 } 5 // make the popover show the right state and details we have to reload it
6 // everytime it is shown for a different tab. Also we have to reload the
7 // popover when the background page wasn't ready yet, since we have to access
8 // the background page in the popover.
9 var backgroundPage = safari.extension.globalPage.contentWindow;
10 var readyState = backgroundPage.document.readyState;
11 var activeTab = safari.application.activeBrowserWindow.activeTab;
6 12
7 // Safari will load the popover once, and then show it everytime the icon is 13 safari.self.addEventListener("popover", function()
8 // clicked. While Chrome loads it everytime you click the icon. So in order to 14 {
9 // force the same behavior in Safari, we are going to reload the page of the 15 if (activeTab != safari.application.activeBrowserWindow.activeTab || readySt ate != "complete")
10 // bubble everytime it is shown. 16 {
11 safari.self.addEventListener("popover", function() 17 document.documentElement.style.display = "none";
12 { 18 document.location.reload();
13 document.documentElement.style.display = "none"; 19 }
14 document.location.reload(); 20 });
15 });
16 21
17 // Safari doesn't hide popovers automatically, when we change the active tab
18 // programmatically, like when the options link is clicked. So we add an event
19 // listener to do so.
20 safari.application.addEventListener("activate", function()
21 {
22 safari.self.hide();
23 }, true);
24 22
25 // Safari doesn't adjust the size of the popover automatically to the size of 23 // Safari doesn't adjust the size of the popover automatically to the size
26 // its content, like when the ad counter is expanded/collapsed. So we add an 24 // of its content, like when the ad counter is expanded/collapsed. So we add
27 // event listener to do so. 25 // event listeners to do so.
28 document.addEventListener("DOMSubtreeModified", function() 26 var updateSize = function()
29 { 27 {
30 safari.self.width = document.body.offsetWidth; 28 safari.self.width = document.body.offsetWidth;
31 safari.self.height = document.body.offsetHeight; 29 safari.self.height = document.body.offsetHeight;
32 }); 30 };
31
32 window.addEventListener("load", function()
33 {
34 updateSize();
35
36 if ("WebKitMutationObserver" in window)
37 new WebKitMutationObserver(updateSize).observe(document, {
38 childList: true, attributes: true,
39 characterData: true, subtree: true
40 });
41 else
42 document.addEventListener("DOMSubtreeModified", updateSize);
43 });
44
45
46 // Safari doesn't hide popovers automatically, when we change the active tab
47 // programmatically, like when the options link is clicked. So we add an event
48 // listener to do so.
49 safari.application.addEventListener("activate", function()
50 {
51 safari.self.hide();
52 }, true);
53
54
55 // import ext into the javascript context of the popover. This code might fail ,
56 // when the background page isn't ready yet. So it is important to put it belo w
57 // the reloading code above.
58 ext = backgroundPage.ext;
59 TabMap = backgroundPage.TabMap;
60 })();
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld