Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(718)

Side by Side Diff: chrome/common/extensions/docs/examples/api/tabs/zoom/popup.js

Issue 1051013002: Add default zoom functionality to chrome.tabs Zoom API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview This code supports the popup behaviour of the extension, and 6 * @fileoverview This code supports the popup behaviour of the extension, and
7 * demonstrates how to: 7 * demonstrates how to:
8 * 8 *
9 * 1) Set the zoom for a tab using tabs.setZoom() 9 * 1) Set the zoom for a tab using tabs.setZoom()
10 * 2) Read the current zoom of a tab using tabs.getZoom() 10 * 2) Read the current zoom of a tab using tabs.getZoom()
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 for (var i = 0; i < modeRadios.length; i++) { 42 for (var i = 0; i < modeRadios.length; i++) {
43 if (modeRadios[i].value == zoomSettings.mode) 43 if (modeRadios[i].value == zoomSettings.mode)
44 modeRadios[i].checked = true; 44 modeRadios[i].checked = true;
45 } 45 }
46 46
47 var scopeRadios = document.getElementsByName('scopeRadio'); 47 var scopeRadios = document.getElementsByName('scopeRadio');
48 for (var i = 0; i < scopeRadios.length; i++) { 48 for (var i = 0; i < scopeRadios.length; i++) {
49 if (scopeRadios[i].value == zoomSettings.scope) 49 if (scopeRadios[i].value == zoomSettings.scope)
50 scopeRadios[i].checked = true; 50 scopeRadios[i].checked = true;
51 } 51 }
52
53 var percentDefaultZoom =
54 parseFloat(zoomSettings.default_zoom_factor) * 100;
55 document.getElementById('defaultLabel').textContent =
56 'Default: ' + percentDefaultZoom.toFixed(1) + '%';
52 }); 57 });
53 58
54 chrome.tabs.getZoom(tabId, displayZoomLevel); 59 chrome.tabs.getZoom(tabId, displayZoomLevel);
55 }); 60 });
56 61
57 document.getElementById('increaseButton').onclick = doZoomIn; 62 document.getElementById('increaseButton').onclick = doZoomIn;
58 document.getElementById('decreaseButton').onclick = doZoomOut; 63 document.getElementById('decreaseButton').onclick = doZoomOut;
59 document.getElementById('defaultButton').onclick = doZoomDefault; 64 document.getElementById('defaultButton').onclick = doZoomDefault;
60 document.getElementById('setModeButton').onclick = doSetMode; 65 document.getElementById('setModeButton').onclick = doSetMode;
61 document.getElementById('closeButton').onclick = doClose; 66 document.getElementById('closeButton').onclick = doClose;
(...skipping 23 matching lines...) Expand all
85 } 90 }
86 91
87 function doZoomOut() { 92 function doZoomOut() {
88 changeZoomByFactorDelta(1.0/zoomStep); 93 changeZoomByFactorDelta(1.0/zoomStep);
89 } 94 }
90 95
91 function doZoomDefault() { 96 function doZoomDefault() {
92 if (tabId == -1) 97 if (tabId == -1)
93 return; 98 return;
94 99
95 chrome.tabs.setZoom(tabId, 1.0, function() { 100 chrome.tabs.setZoom(tabId, 'default', function() {
not at google - send to devlin 2015/04/01 20:34:07 Need to update this.
wjmaclean 2015/04/01 21:23:24 Ooops, missed that one, thanks! Done.
96 if (chrome.runtime.lastError) 101 if (chrome.runtime.lastError)
97 console.log('[ZoomDemoExtension] ' + chrome.runtime.lastError.message); 102 console.log('[ZoomDemoExtension] ' + chrome.runtime.lastError.message);
98 }); 103 });
99 } 104 }
100 105
101 function doSetMode() { 106 function doSetMode() {
102 if (tabId == -1) 107 if (tabId == -1)
103 return; 108 return;
104 109
105 var modeVal; 110 var modeVal;
(...skipping 21 matching lines...) Expand all
127 if (chrome.runtime.lastError) { 132 if (chrome.runtime.lastError) {
128 console.log('[ZoomDemoExtension] doSetMode() error: ' + 133 console.log('[ZoomDemoExtension] doSetMode() error: ' +
129 chrome.runtime.lastError.message); 134 chrome.runtime.lastError.message);
130 } 135 }
131 }); 136 });
132 } 137 }
133 138
134 function doClose() { 139 function doClose() {
135 self.close(); 140 self.close();
136 } 141 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698