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

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

Issue 5083364310646784: Got rid of strange animation when the bubble is resized while reloading on Safari (Closed)
Left Patch Set: Created Jan. 16, 2014, 11:07 p.m.
Right Patch Set: Addressed comment Created Jan. 17, 2014, noon
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 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 readyState = backgroundPage.document.readyState;
11 var activeTab = safari.application.activeBrowserWindow.activeTab; 11 var activeTab = safari.application.activeBrowserWindow.activeTab;
12 var stopResizing = function() {}; 12 var mayResize = true;
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 (activeTab != safari.application.activeBrowserWindow.activeTab || readySt ate != "complete")
17 { 17 {
18 stopResizing(); 18 mayResize = false;
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
27 // event listeners to do so. 27 // event listeners to do so.
28 var updateSize = function() 28 var updateSize = function()
29 { 29 {
30 safari.self.width = document.body.offsetWidth; 30 if (mayResize)
31 safari.self.height = document.body.offsetHeight; 31 {
32 safari.self.width = document.body.offsetWidth;
33 safari.self.height = document.body.offsetHeight;
34 ]
32 }; 35 };
33 36
34 window.addEventListener("load", function() 37 window.addEventListener("load", function()
35 { 38 {
36 updateSize(); 39 updateSize();
37 40
38 var MutationObserver = window.MutationObserver || window.WebKitMutationObser ver; 41 var MutationObserver = window.MutationObserver || window.WebKitMutationObser ver;
39 if (MutationObserver) 42 if (MutationObserver)
40 { 43 {
41 var mo = new MutationObserver(updateSize); 44 new MutationObserver(updateSize).observe(document, {
42 mo.observe(document, {
43 childList: true, attributes: true, 45 childList: true, attributes: true,
44 characterData: true, subtree: true 46 characterData: true, subtree: true
45 }); 47 });
46
47 stopResizing = function()
48 {
49 mo.disconnect();
50 };
51 } 48 }
52 else 49 else
53 {
54 document.addEventListener("DOMSubtreeModified", updateSize); 50 document.addEventListener("DOMSubtreeModified", updateSize);
55
56 stopResizing = function()
57 {
58 document.removeEventListener("DOMSubtreeModified", updateSize);
59 };
60 }
61 }); 51 });
62 52
63 53
64 // Safari doesn't hide popovers automatically, when we change the active tab 54 // Safari doesn't hide popovers automatically, when we change the active tab
65 // programmatically, like when the options link is clicked. So we add an event 55 // programmatically, like when the options link is clicked. So we add an event
66 // listener to do so. 56 // listener to do so.
67 safari.application.addEventListener("activate", function() 57 safari.application.addEventListener("activate", function()
68 { 58 {
69 safari.self.hide(); 59 safari.self.hide();
70 }, true); 60 }, true);
71 61
72 62
73 // import ext into the javascript context of the popover. This code might fail , 63 // 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 64 // when the background page isn't ready yet. So it is important to put it belo w
75 // the reloading code above. 65 // the reloading code above.
76 window.ext = { 66 window.ext = {
77 __proto__: backgroundPage.ext, 67 __proto__: backgroundPage.ext,
78 closePopup: function() 68 closePopup: function()
79 { 69 {
80 safari.self.hide(); 70 safari.self.hide();
81 } 71 }
82 }; 72 };
83 window.TabMap = backgroundPage.TabMap; 73 window.TabMap = backgroundPage.TabMap;
84 })(); 74 })();
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