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

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

Issue 5115653975441408: Let popup reload when it is shown, after it was programatically closed, on Safari (Closed)
Patch Set: Created Jan. 17, 2014, 11:38 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; 9 var backgroundPage = safari.extension.globalPage.contentWindow;
10 var readyState = backgroundPage.document.readyState; 10 var valid = backgroundPage.document.readyState == "complete";
11 var activeTab = safari.application.activeBrowserWindow.activeTab; 11 var activeTab = safari.application.activeBrowserWindow.activeTab;
12 var stopResizing = function() {}; 12 var stopResizing = function() {};
13 13
14 safari.self.addEventListener("popover", function() 14 safari.self.addEventListener("popover", function()
15 { 15 {
16 if (activeTab != safari.application.activeBrowserWindow.activeTab || readySt ate != "complete") 16 if (!valid || activeTab != safari.application.activeBrowserWindow.activeTab)
17 { 17 {
18 stopResizing(); 18 stopResizing();
19 document.documentElement.style.display = "none"; 19 document.documentElement.style.display = "none";
20 document.location.reload(); 20 document.location.reload();
21 } 21 }
22 }); 22 });
23 23
24 24
25 // Safari doesn't adjust the size of the popover automatically to the size 25 // 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 26 // of its content, like when the ad counter is expanded/collapsed. So we add
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 71
72 72
73 // import ext into the javascript context of the popover. This code might fail , 73 // import ext into the javascript context of the popover. This code might fail ,
74 // when the background page isn't ready yet. So it is important to put it belo w 74 // when the background page isn't ready yet. So it is important to put it belo w
75 // the reloading code above. 75 // the reloading code above.
76 window.ext = { 76 window.ext = {
77 __proto__: backgroundPage.ext, 77 __proto__: backgroundPage.ext,
78 closePopup: function() 78 closePopup: function()
79 { 79 {
80 safari.self.hide(); 80 safari.self.hide();
81 valid = false;
81 } 82 }
82 }; 83 };
83 window.TabMap = backgroundPage.TabMap; 84 window.TabMap = backgroundPage.TabMap;
84 })(); 85 })();
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