| 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 var loading = true; | 5 var loading = true; |
| 6 | 6 |
| 7 function updateSimpleSection(id, section) { | 7 function updateSimpleSection(id, section) { |
| 8 if (shownSections & section) | 8 if (shownSections & section) |
| 9 $(id).classList.remove('hidden'); | 9 $(id).classList.remove('hidden'); |
| 10 else | 10 else |
| 11 $(id).classList.add('hidden'); | 11 $(id).classList.add('hidden'); |
| 12 } | 12 } |
| 13 | 13 |
| 14 function getAppsCallback(data) { | |
| 15 logEvent('recieved apps'); | |
| 16 var appsSection = $('apps-section'); | |
| 17 var debugSection = $('debug'); | |
| 18 appsSection.innerHTML = ''; | |
| 19 | |
| 20 data.apps.forEach(function(app) { | |
| 21 appsSection.appendChild(apps.createElement(app)); | |
| 22 }); | |
| 23 | |
| 24 if (data.galleryTitle && data.galleryURL) { | |
| 25 appsSection.appendChild(apps.createGalleryElement( | |
| 26 data.galleryTitle, data.galleryURL)); | |
| 27 } | |
| 28 | |
| 29 // TODO(aa): Figure out what to do with the debug mode when we turn apps on | |
| 30 // for everyone. | |
| 31 if (appsSection.hasChildNodes()) { | |
| 32 appsSection.classList.remove('disabled'); | |
| 33 if (data.showDebugLink) { | |
| 34 debugSection.classList.remove('disabled'); | |
| 35 } | |
| 36 } else { | |
| 37 appsSection.classList.add('disabled'); | |
| 38 debugSection.classList.add('disabled'); | |
| 39 } | |
| 40 } | |
| 41 | |
| 42 var apps = { | |
| 43 /** | |
| 44 * @this {!HTMLAnchorElement} | |
| 45 */ | |
| 46 handleClick_: function() { | |
| 47 var launchType = ''; | |
| 48 var inputElements = document.querySelectorAll( | |
| 49 '#apps-launch-control input'); | |
| 50 for (var i = 0, input; input = inputElements[i]; i++) { | |
| 51 if (input.checked) { | |
| 52 launchType = input.value; | |
| 53 break; | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 // TODO(arv): Handle zoom? | |
| 58 var rect = this.getBoundingClientRect(); | |
| 59 var cs = getComputedStyle(this); | |
| 60 var size = cs.backgroundSize.split(/\s+/); // background-size has the | |
| 61 // format '123px 456px'. | |
| 62 var width = parseInt(size[0], 10); | |
| 63 var height = parseInt(size[1], 10); | |
| 64 // We are using background-position-x 50%. | |
| 65 var left = rect.left + ((rect.width - width) >> 1); // Integer divide by 2. | |
| 66 var top = rect.top + parseInt(cs.backgroundPositionY, 10); | |
| 67 | |
| 68 chrome.send('launchApp', [this.id, launchType, | |
| 69 String(left), String(top), | |
| 70 String(width), String(height)]); | |
| 71 return false; | |
| 72 }, | |
| 73 | |
| 74 createElement: function(app) { | |
| 75 var a = document.createElement('a'); | |
| 76 a.xtitle = a.textContent = app['name']; | |
| 77 a.href = app['launch_url']; | |
| 78 a.id = app['id']; | |
| 79 a.onclick = apps.handleClick_; | |
| 80 a.style.backgroundImage = url(app['icon']); | |
| 81 if (hashParams['app-id'] == app['id']) { | |
| 82 a.setAttribute('new', 'new'); | |
| 83 // Delay changing the attribute a bit to let the page settle down a bit. | |
| 84 setTimeout(function() { | |
| 85 a.setAttribute('new', 'installed'); | |
| 86 }, 500); | |
| 87 } | |
| 88 return a; | |
| 89 }, | |
| 90 | |
| 91 createGalleryElement: function(title, url) { | |
| 92 var a = document.createElement('a'); | |
| 93 a.title = title; | |
| 94 a.href = url; | |
| 95 a.id = 'gallery-entry'; | |
| 96 a.textContent = title; | |
| 97 return a; | |
| 98 } | |
| 99 }; | |
| 100 | |
| 101 var tipCache = {}; | 14 var tipCache = {}; |
| 102 | 15 |
| 103 function tips(data) { | 16 function tips(data) { |
| 104 logEvent('received tips'); | 17 logEvent('received tips'); |
| 105 tipCache = data; | 18 tipCache = data; |
| 106 renderTip(); | 19 renderTip(); |
| 107 } | 20 } |
| 108 | 21 |
| 109 function createTip(data) { | 22 function createTip(data) { |
| 110 if (data.length) { | 23 if (data.length) { |
| (...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1030 window.setTimeout(function() { | 943 window.setTimeout(function() { |
| 1031 mostVisited.ensureSmallGridCorrect(); | 944 mostVisited.ensureSmallGridCorrect(); |
| 1032 document.body.classList.remove('loading'); | 945 document.body.classList.remove('loading'); |
| 1033 }, 1); | 946 }, 1); |
| 1034 | 947 |
| 1035 // Only show the first run notification if first run. | 948 // Only show the first run notification if first run. |
| 1036 if (firstRun) { | 949 if (firstRun) { |
| 1037 showFirstRunNotification(); | 950 showFirstRunNotification(); |
| 1038 } | 951 } |
| 1039 } | 952 } |
| OLD | NEW |