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

Side by Side Diff: safari/ext/popup.js

Issue 6499942772244480: Reload popover on Safari every time it is shown (Closed)
Patch Set: Created Jan. 23, 2014, 10:20 a.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 | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 (function() 1 (function()
2 { 2 {
3 // Safari will load the popover once, and then show it everytime the icon is 3 // Safari will load the popover once, and then show it everytime the icon is
4 // clicked. While Chrome loads it everytime you click the icon. So in order to 4 // clicked. While Chrome loads it everytime you click the icon. So in order to
5 // make the popover show the right state and details we have to reload it 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 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 7 // popover when the background page wasn't ready yet, since we have to access
8 // the background page in the popover. 8 // the background page in the popover.
9 var backgroundPage = safari.extension.globalPage.contentWindow;
10 var valid = backgroundPage.document.readyState == "complete";
11 var activeTab = safari.application.activeBrowserWindow.activeTab;
12 var mayResize = true;
13
14 safari.self.addEventListener("popover", function() 9 safari.self.addEventListener("popover", function()
15 { 10 {
16 if (!valid || activeTab != safari.application.activeBrowserWindow.activeTab) 11 mayResize = false;
17 { 12 document.documentElement.style.display = "none";
18 mayResize = false; 13 document.location.reload();
19 document.documentElement.style.display = "none";
20 document.location.reload();
21 }
22 }); 14 });
23 15
24 16
25 // Safari doesn't adjust the size of the popover automatically to the size 17 // Safari doesn't adjust the size of the popover automatically to the size
26 // of its content, like when the ad counter is expanded/collapsed. So we add 18 // of its content, like when the ad counter is expanded/collapsed. So we add
27 // event listeners to do so. 19 // event listeners to do so.
20 var mayResize = true;
21
28 var updateSize = function() 22 var updateSize = function()
29 { 23 {
30 if (mayResize) 24 if (mayResize)
31 { 25 {
32 safari.self.width = document.body.offsetWidth; 26 safari.self.width = document.body.offsetWidth;
33 safari.self.height = document.body.offsetHeight; 27 safari.self.height = document.body.offsetHeight;
34 } 28 }
35 }; 29 };
36 30
37 window.addEventListener("load", function() 31 window.addEventListener("load", function()
(...skipping 18 matching lines...) Expand all
56 // listener to do so. 50 // listener to do so.
57 safari.application.addEventListener("activate", function() 51 safari.application.addEventListener("activate", function()
58 { 52 {
59 safari.self.hide(); 53 safari.self.hide();
60 }, true); 54 }, true);
61 55
62 56
63 // import ext into the javascript context of the popover. This code might fail , 57 // import ext into the javascript context of the popover. This code might fail ,
64 // when the background page isn't ready yet. So it is important to put it belo w 58 // when the background page isn't ready yet. So it is important to put it belo w
65 // the reloading code above. 59 // the reloading code above.
60 var backgroundPage = safari.extension.globalPage.contentWindow;
61
66 window.ext = { 62 window.ext = {
67 __proto__: backgroundPage.ext, 63 __proto__: backgroundPage.ext,
68 closePopup: function() 64 closePopup: function()
69 { 65 {
70 safari.self.hide(); 66 safari.self.hide();
71 valid = false;
72 } 67 }
73 }; 68 };
74 window.TabMap = backgroundPage.TabMap; 69 window.TabMap = backgroundPage.TabMap;
75 })(); 70 })();
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld