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

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

Issue 6499942772244480: Reload popover on Safari every time it is shown (Closed)
Left Patch Set: Created Jan. 23, 2014, 10:20 a.m.
Right Patch Set: Addressed comment Created Jan. 23, 2014, 1:59 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 (function() 1 (function()
2 { 2 {
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
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 safari.self.addEventListener("popover", function()
10 {
11 mayResize = false;
12 document.documentElement.style.display = "none";
13 document.location.reload();
14 });
15
16
17 // Safari doesn't adjust the size of the popover automatically to the size 3 // Safari doesn't adjust the size of the popover automatically to the size
18 // of its content, like when the ad counter is expanded/collapsed. So we add 4 // of its content, like when the ad counter is expanded/collapsed. So we add
19 // event listeners to do so. 5 // event listeners to do so.
20 var mayResize = true; 6 var mayResize = true;
21 7
22 var updateSize = function() 8 var updateSize = function()
23 { 9 {
24 if (mayResize) 10 if (mayResize)
25 { 11 {
26 safari.self.width = document.body.offsetWidth; 12 safari.self.width = document.body.offsetWidth;
(...skipping 11 matching lines...) Expand all
38 new MutationObserver(updateSize).observe(document, { 24 new MutationObserver(updateSize).observe(document, {
39 childList: true, attributes: true, 25 childList: true, attributes: true,
40 characterData: true, subtree: true 26 characterData: true, subtree: true
41 }); 27 });
42 } 28 }
43 else 29 else
44 document.addEventListener("DOMSubtreeModified", updateSize); 30 document.addEventListener("DOMSubtreeModified", updateSize);
45 }); 31 });
46 32
47 33
34 // Safari will load the popover once, and then show it everytime the icon is
35 // clicked. While Chrome loads it everytime you click the icon. So in order to
36 // make the popover show the right state and details, we have to emulate the
37 // same behavior as on Chrome, by reloading the popover every time it is shown .
38 safari.self.addEventListener("popover", function()
39 {
40 mayResize = false;
41 document.documentElement.style.display = "none";
42 document.location.reload();
43 });
44
45
48 // Safari doesn't hide popovers automatically, when we change the active tab 46 // Safari doesn't hide popovers automatically, when we change the active tab
49 // programmatically, like when the options link is clicked. So we add an event 47 // programmatically, like when the options link is clicked. So we add an event
50 // listener to do so. 48 // listener to do so.
51 safari.application.addEventListener("activate", function() 49 safari.application.addEventListener("activate", function()
52 { 50 {
53 safari.self.hide(); 51 safari.self.hide();
54 }, true); 52 }, true);
55 53
56 54
57 // import ext into the javascript context of the popover. This code might fail , 55 // import ext into the javascript context of the popover. This code might fail ,
58 // when the background page isn't ready yet. So it is important to put it belo w 56 // when the background page isn't ready yet. So it is important to put it belo w
59 // the reloading code above. 57 // the reloading code above.
60 var backgroundPage = safari.extension.globalPage.contentWindow; 58 var backgroundPage = safari.extension.globalPage.contentWindow;
61 59
62 window.ext = { 60 window.ext = {
63 __proto__: backgroundPage.ext, 61 __proto__: backgroundPage.ext,
64 closePopup: function() 62 closePopup: function()
65 { 63 {
66 safari.self.hide(); 64 safari.self.hide();
67 } 65 }
68 }; 66 };
69 window.TabMap = backgroundPage.TabMap; 67 window.TabMap = backgroundPage.TabMap;
70 })(); 68 })();
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