Home | History | Annotate | Download | only in resources
      1 // Copyright (c) 2011 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 reload() {
      6   if (document.getElementById('helpTooltip'))
      7     return;
      8   history.go(0);
      9 }
     10 
     11 function formatNumber(str) {
     12   str += '';
     13   if (str == '0') {
     14     return 'N/A ';
     15   }
     16   var x = str.split('.');
     17   var x1 = x[0];
     18   var x2 = x.length > 1 ? '.' + x[1] : '';
     19   var regex = /(\d+)(\d{3})/;
     20   while (regex.test(x1)) {
     21     x1 = x1.replace(regex, '$1' + ',' + '$2');
     22   }
     23   return x1;
     24 }
     25 
     26 function addToSum(id, value) {
     27   var target = document.getElementById(id);
     28   var sum = parseInt(target.innerHTML);
     29   sum += parseInt(value);
     30   target.innerHTML = sum;
     31 }
     32 
     33 function handleHelpTooltipMouseOver(event) {
     34   var el = document.createElement('div');
     35   el.id = 'helpTooltip';
     36   el.innerHTML = event.toElement.getElementsByTagName('div')[0].innerHTML;
     37   el.style.top = 0;
     38   el.style.left = 0;
     39   el.style.visibility = 'hidden';
     40   document.body.appendChild(el);
     41 
     42   var width = el.offsetWidth;
     43   var height = el.offsetHeight;
     44 
     45   if (event.pageX - width - 50 + document.body.scrollLeft >= 0 ) {
     46     el.style.left = (event.pageX - width - 20) + 'px';
     47   } else {
     48     el.style.left = (event.pageX + 20) + 'px';
     49   }
     50 
     51 
     52   if (event.pageY - height - 50 + document.body.scrollTop >= 0) {
     53     el.style.top = (event.pageY - height - 20) + 'px';
     54   } else {
     55     el.style.top = (event.pageY + 20) + 'px';
     56   }
     57 
     58   el.style.visibility = 'visible';
     59 }
     60 
     61 function handleHelpTooltipMouseOut(event) {
     62   var el = document.getElementById('helpTooltip');
     63   el.parentNode.removeChild(el);
     64 }
     65 
     66 function enableHelpTooltips() {
     67   var helpEls = document.getElementsByClassName('help');
     68 
     69   for (var i = 0, helpEl; helpEl = helpEls[i]; i++) {
     70     helpEl.onmouseover = handleHelpTooltipMouseOver;
     71     helpEl.onmouseout = handleHelpTooltipMouseOut;
     72   }
     73 }
     74 
     75 document.addEventListener('DOMContentLoaded', function () {
     76   // This is the javascript code that processes the template:
     77   var input = new JsEvalContext(loadTimeData.getValue('jstemplateData'));
     78   var output = document.getElementById('t');
     79   jstProcess(input, output);
     80 
     81   enableHelpTooltips();
     82 });
     83 
     84