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