| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 function getAppsCallback(data) { | 5 function getAppsCallback(data) { |
| 6 logEvent('received apps'); | 6 logEvent('received apps'); |
| 7 var appsSection = $('apps'); | 7 var appsSection = $('apps'); |
| 8 var appsSectionContent = $('apps-maxiview'); | 8 var appsSectionContent = $('apps-maxiview'); |
| 9 var appsMiniview = appsSection.getElementsByClassName('miniview')[0]; | 9 var appsMiniview = appsSection.getElementsByClassName('miniview')[0]; |
| 10 appsSectionContent.textContent = ''; | 10 appsSectionContent.textContent = ''; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 apps.loaded = true; | 30 apps.loaded = true; |
| 31 maybeDoneLoading(); | 31 maybeDoneLoading(); |
| 32 | 32 |
| 33 if (data.apps.length > 0 && isDoneLoading()) { | 33 if (data.apps.length > 0 && isDoneLoading()) { |
| 34 updateMiniviewClipping(appsMiniview); | 34 updateMiniviewClipping(appsMiniview); |
| 35 layoutSections(); | 35 layoutSections(); |
| 36 } | 36 } |
| 37 } | 37 } |
| 38 | 38 |
| 39 function appsPrefChangeCallback(data) { |
| 40 // Currently the only pref that is watched is the launch type. |
| 41 data.apps.forEach(function(app) { |
| 42 var appLink = document.querySelector('.app a[app-id=' + app['id'] + ']'); |
| 43 if (appLink) |
| 44 appLink.setAttribute('launch-type', app['launch_type']); |
| 45 }); |
| 46 } |
| 47 |
| 39 var apps = (function() { | 48 var apps = (function() { |
| 40 | 49 |
| 41 function createElement(app) { | 50 function createElement(app) { |
| 42 var div = document.createElement('div'); | 51 var div = document.createElement('div'); |
| 43 div.className = 'app'; | 52 div.className = 'app'; |
| 44 | 53 |
| 45 var a = div.appendChild(document.createElement('a')); | 54 var a = div.appendChild(document.createElement('a')); |
| 46 a.setAttribute('app-id', app['id']); | 55 a.setAttribute('app-id', app['id']); |
| 56 a.setAttribute('launch-type', app['launch_type']); |
| 47 a.xtitle = a.textContent = app['name']; | 57 a.xtitle = a.textContent = app['name']; |
| 48 a.href = app['launch_url']; | 58 a.href = app['launch_url']; |
| 49 | 59 |
| 50 return div; | 60 return div; |
| 51 } | 61 } |
| 52 | 62 |
| 53 function createContextMenu(app) { | 63 function createContextMenu(app) { |
| 54 var menu = new cr.ui.Menu; | 64 var menu = new cr.ui.Menu; |
| 55 var button = document.createElement(button); | 65 var button = document.createElement(button); |
| 56 } | 66 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 | 102 |
| 93 /** | 103 /** |
| 94 * @this {!HTMLAnchorElement} | 104 * @this {!HTMLAnchorElement} |
| 95 */ | 105 */ |
| 96 function handleClick(e) { | 106 function handleClick(e) { |
| 97 var appId = e.currentTarget.getAttribute('app-id'); | 107 var appId = e.currentTarget.getAttribute('app-id'); |
| 98 launchApp(appId); | 108 launchApp(appId); |
| 99 return false; | 109 return false; |
| 100 } | 110 } |
| 101 | 111 |
| 112 // Keep in sync with LaunchType in extension_prefs.h |
| 113 var LaunchType = { |
| 114 LAUNCH_PINNED: 0, |
| 115 LAUNCH_REGULAR: 1, |
| 116 LAUNCH_FULLSCREEN: 2 |
| 117 }; |
| 118 |
| 119 // Keep in sync with LaunchContainer in extension.h |
| 120 var LaunchContainer = { |
| 121 LAUNCH_WINDOW: 0, |
| 122 LAUNCH_PANEL: 1, |
| 123 LAUNCH_TAB: 2 |
| 124 }; |
| 125 |
| 102 var currentApp; | 126 var currentApp; |
| 103 | 127 |
| 104 function addContextMenu(el, app) { | 128 function addContextMenu(el, app) { |
| 105 el.addEventListener('contextmenu', cr.ui.contextMenuHandler); | 129 el.addEventListener('contextmenu', cr.ui.contextMenuHandler); |
| 106 el.addEventListener('keydown', cr.ui.contextMenuHandler); | 130 el.addEventListener('keydown', cr.ui.contextMenuHandler); |
| 107 el.addEventListener('keyup', cr.ui.contextMenuHandler); | 131 el.addEventListener('keyup', cr.ui.contextMenuHandler); |
| 108 | 132 |
| 109 Object.defineProperty(el, 'contextMenu', { | 133 Object.defineProperty(el, 'contextMenu', { |
| 110 get: function() { | 134 get: function() { |
| 111 currentApp = app; | 135 currentApp = app; |
| 112 | 136 |
| 113 $('apps-launch-command').label = app['name']; | 137 $('apps-launch-command').label = app['name']; |
| 114 $('apps-options-command').canExecuteChange(); | 138 $('apps-options-command').canExecuteChange(); |
| 115 | 139 |
| 140 var appLinkSel = '.app a[app-id=' + app['id'] + ']'; |
| 141 var launchType = |
| 142 el.querySelector(appLinkSel).getAttribute('launch-type'); |
| 143 |
| 144 var launchContainer = app['launch_container']; |
| 145 var isPanel = launchContainer == LaunchContainer.LAUNCH_PANEL; |
| 146 |
| 147 // Update the commands related to the launch type. |
| 148 var launchTypeIds = ['apps-launch-type-pinned', |
| 149 'apps-launch-type-regular', |
| 150 'apps-launch-type-fullscreen']; |
| 151 launchTypeIds.forEach(function(id) { |
| 152 var command = $(id); |
| 153 command.disabled = isPanel; |
| 154 command.checked = !isPanel && |
| 155 launchType == command.getAttribute('launch-type'); |
| 156 }); |
| 157 |
| 116 return $('app-context-menu'); | 158 return $('app-context-menu'); |
| 117 } | 159 } |
| 118 }); | 160 }); |
| 119 } | 161 } |
| 120 | 162 |
| 121 document.addEventListener('command', function(e) { | 163 document.addEventListener('command', function(e) { |
| 122 if (!currentApp) | 164 if (!currentApp) |
| 123 return; | 165 return; |
| 124 | 166 |
| 125 switch (e.command.id) { | 167 var commandId = e.command.id; |
| 168 switch (commandId) { |
| 126 case 'apps-options-command': | 169 case 'apps-options-command': |
| 127 window.location = currentApp['options_url']; | 170 window.location = currentApp['options_url']; |
| 128 break; | 171 break; |
| 129 case 'apps-launch-command': | 172 case 'apps-launch-command': |
| 130 launchApp(currentApp['id']); | 173 launchApp(currentApp['id']); |
| 131 break; | 174 break; |
| 132 case 'apps-uninstall-command': | 175 case 'apps-uninstall-command': |
| 133 chrome.send('uninstallApp', [currentApp['id']]); | 176 chrome.send('uninstallApp', [currentApp['id']]); |
| 134 break; | 177 break; |
| 178 case 'apps-launch-type-pinned': |
| 179 case 'apps-launch-type-regular': |
| 180 case 'apps-launch-type-fullscreen': |
| 181 chrome.send('setLaunchType', |
| 182 [currentApp['id'], e.command.getAttribute('launch-type')]); |
| 183 break; |
| 135 } | 184 } |
| 136 }); | 185 }); |
| 137 | 186 |
| 138 document.addEventListener('canExecute', function(e) { | 187 document.addEventListener('canExecute', function(e) { |
| 139 switch (e.command.id) { | 188 switch (e.command.id) { |
| 140 case 'apps-options-command': | 189 case 'apps-options-command': |
| 141 e.canExecute = currentApp && currentApp['options_url']; | 190 e.canExecute = currentApp && currentApp['options_url']; |
| 142 break; | 191 break; |
| 143 case 'apps-launch-command': | 192 case 'apps-launch-command': |
| 144 case 'apps-uninstall-command': | 193 case 'apps-uninstall-command': |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 204 | 253 |
| 205 createWebStoreElement: function() { | 254 createWebStoreElement: function() { |
| 206 return createElement({ | 255 return createElement({ |
| 207 'id': 'web-store-entry', | 256 'id': 'web-store-entry', |
| 208 'name': localStrings.getString('web_store_title'), | 257 'name': localStrings.getString('web_store_title'), |
| 209 'launch_url': localStrings.getString('web_store_url') | 258 'launch_url': localStrings.getString('web_store_url') |
| 210 }); | 259 }); |
| 211 } | 260 } |
| 212 }; | 261 }; |
| 213 })(); | 262 })(); |
| OLD | NEW |