| OLD | NEW | 
| (Empty) |  | 
 |    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 | 
 |    3 // found in the LICENSE file. | 
 |    4  | 
 |    5 function getAppsCallback(data) { | 
 |    6   logEvent('recieved apps'); | 
 |    7   var appsSection = $('apps-section'); | 
 |    8   var debugSection = $('debug'); | 
 |    9   appsSection.textContent = ''; | 
 |   10  | 
 |   11   data.apps.forEach(function(app) { | 
 |   12     appsSection.appendChild(apps.createElement(app)); | 
 |   13   }); | 
 |   14  | 
 |   15  | 
 |   16   // TODO(aa): Figure out what to do with the debug mode when we turn apps on | 
 |   17   // for everyone. | 
 |   18   if (appsSection.hasChildNodes()) { | 
 |   19     appsSection.classList.remove('disabled'); | 
 |   20     if (data.showDebugLink) { | 
 |   21       debugSection.classList.remove('disabled'); | 
 |   22     } | 
 |   23   } else { | 
 |   24     appsSection.classList.add('disabled'); | 
 |   25     debugSection.classList.add('disabled'); | 
 |   26   } | 
 |   27 } | 
 |   28  | 
 |   29 var apps = { | 
 |   30   /** | 
 |   31    * @this {!HTMLAnchorElement} | 
 |   32    */ | 
 |   33   handleClick_: function() { | 
 |   34     var launchType = ''; | 
 |   35     var inputElements = document.querySelectorAll( | 
 |   36         '#apps-launch-control input'); | 
 |   37     for (var i = 0, input; input = inputElements[i]; i++) { | 
 |   38       if (input.checked) { | 
 |   39         launchType = input.value; | 
 |   40         break; | 
 |   41       } | 
 |   42     } | 
 |   43  | 
 |   44     // TODO(arv): Handle zoom? | 
 |   45     var rect = this.getBoundingClientRect(); | 
 |   46     var cs = getComputedStyle(this); | 
 |   47     var size = cs.backgroundSize.split(/\s+/);  // background-size has the | 
 |   48                                                 // format '123px 456px'. | 
 |   49     var width = parseInt(size[0], 10); | 
 |   50     var height = parseInt(size[1], 10); | 
 |   51     // We are using background-position-x 50%. | 
 |   52     var left = rect.left + ((rect.width - width) >> 1);  // Integer divide by 2. | 
 |   53     var top = rect.top + parseInt(cs.backgroundPositionY, 10); | 
 |   54  | 
 |   55     chrome.send('launchApp', [this.id, launchType, | 
 |   56                               String(left), String(top), | 
 |   57                               String(width), String(height)]); | 
 |   58     return false; | 
 |   59   }, | 
 |   60  | 
 |   61   createElement: function(app) { | 
 |   62     var div = document.createElement('div'); | 
 |   63     div.className = 'app'; | 
 |   64  | 
 |   65     var front = div.appendChild(document.createElement('div')); | 
 |   66     front.className = 'front'; | 
 |   67  | 
 |   68     var a = front.appendChild(document.createElement('a')); | 
 |   69     a.id = app['id']; | 
 |   70     a.xtitle = a.textContent = app['name']; | 
 |   71     a.href = app['launch_url']; | 
 |   72  | 
 |   73     a.onclick = apps.handleClick_; | 
 |   74     a.style.backgroundImage = url(app['icon']); | 
 |   75     if (hashParams['app-id'] == app['id']) { | 
 |   76       div.setAttribute('new', 'new'); | 
 |   77       // Delay changing the attribute a bit to let the page settle down a bit. | 
 |   78       setTimeout(function() { | 
 |   79         div.setAttribute('new', 'installed'); | 
 |   80       }, 500); | 
 |   81     } | 
 |   82  | 
 |   83     var settingsButton = front.appendChild(document.createElement('button')); | 
 |   84     settingsButton.className = 'flip'; | 
 |   85     settingsButton.title = localStrings.getString('appsettings'); | 
 |   86  | 
 |   87     var back = div.appendChild(document.createElement('div')); | 
 |   88     back.className = 'back'; | 
 |   89  | 
 |   90     var header = back.appendChild(document.createElement('h2')); | 
 |   91     header.textContent = app['name']; | 
 |   92  | 
 |   93     var optionsButton = back.appendChild(document.createElement('button')); | 
 |   94     optionsButton.textContent = localStrings.getString('appoptions'); | 
 |   95     optionsButton.disabled = !app['options_url']; | 
 |   96     optionsButton.onclick = function() { | 
 |   97       window.location = app['options_url']; | 
 |   98     }; | 
 |   99  | 
 |  100     var uninstallButton = back.appendChild(document.createElement('button')); | 
 |  101     uninstallButton.textContent = uninstallButton.xtitle = | 
 |  102         localStrings.getString('appuninstall'); | 
 |  103     uninstallButton.onclick = function() { | 
 |  104       chrome.send('uninstallApp', [app['id']]); | 
 |  105     }; | 
 |  106  | 
 |  107     var closeButton = back.appendChild(document.createElement('button')); | 
 |  108     closeButton.title = localStrings.getString('close'); | 
 |  109     closeButton.className = 'flip'; | 
 |  110     closeButton.onclick = settingsButton.onclick = function() { | 
 |  111       div.classList.toggle('config'); | 
 |  112     }; | 
 |  113  | 
 |  114     return div; | 
 |  115   } | 
 |  116 }; | 
| OLD | NEW |