1 // Copyright 2013 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.
5 function toggleHelpBox() {
6 var helpBoxOuter = document.getElementById('help-box-outer');
7 helpBoxOuter.classList.toggle('hidden');
8 var detailsButton = document.getElementById('details-button');
9 if (helpBoxOuter.classList.contains('hidden'))
10 detailsButton.innerText = detailsButton.detailsText;
12 detailsButton.innerText = detailsButton.hideDetailsText;
15 function diagnoseErrors() {
16 var extensionId = 'idddmepepmjcgiedknnmlbadcokidhoa';
17 var diagnoseFrame = document.getElementById('diagnose-frame');
18 diagnoseFrame.innerHTML =
19 '<iframe src="chrome-extension://' + extensionId +
20 '/index.html"></iframe>';
23 // Subframes use a different layout but the same html file. This is to make it
24 // easier to support platforms that load the error page via different
25 // mechanisms (Currently just iOS).
26 if (window.top.location != window.location)
27 document.documentElement.setAttribute('subframe', '');
29 // Re-renders the error page using |strings| as the dictionary of values.
30 // Used by NetErrorTabHelper to update DNS error pages with probe results.
31 function updateForDnsProbe(strings) {
32 var context = new JsEvalContext(strings);
33 jstProcess(context, document.getElementById('t'));
36 // Given the classList property of an element, adds an icon class to the list
37 // and removes the previously-
38 function updateIconClass(classList, newClass) {
41 if (classList.hasOwnProperty('last_icon_class')) {
42 oldClass = classList['last_icon_class'];
43 if (oldClass == newClass)
47 classList.add(newClass);
48 if (oldClass !== undefined)
49 classList.remove(oldClass);
51 classList['last_icon_class'] = newClass;
53 if (newClass == 'icon-offline') {
54 document.body.classList.add('offline');
55 new Runner('.interstitial-wrapper');
59 // Does a search using |baseSearchUrl| and the text in the search box.
60 function search(baseSearchUrl) {
61 var searchTextNode = document.getElementById('search-box');
62 document.location = baseSearchUrl + searchTextNode.value;
66 // Use to track clicks on elements generated by the navigation correction
67 // service. If |trackingId| is negative, the element does not come from the
68 // correction service.
69 function trackClick(trackingId) {
70 // This can't be done with XHRs because XHRs are cancelled on navigation
71 // start, and because these are cross-site requests.
72 if (trackingId >= 0 && errorPageController)
73 errorPageController.trackClick(trackingId);
76 // Called when an <a> tag generated by the navigation correction service is
77 // clicked. Separate function from trackClick so the resources don't have to
78 // be updated if new data is added to jstdata.
79 function linkClicked(jstdata) {
80 trackClick(jstdata.trackingId);
83 // Implements button clicks. This function is needed during the transition
84 // between implementing these in trunk chromium and implementing them in
86 function reloadButtonClick(url) {
87 if (window.errorPageController) {
88 errorPageController.reloadButtonClick();
94 function loadStaleButtonClick() {
95 if (window.errorPageController) {
96 errorPageController.loadStaleButtonClick();
100 function detailsButtonClick() {
101 if (window.errorPageController)
102 errorPageController.detailsButtonClick();
105 var primaryControlOnLeft = true;
106 <if expr="is_macosx or is_ios or is_linux or is_android">
107 primaryControlOnLeft = false;
110 function onDocumentLoad() {
111 var buttonsDiv = document.getElementById('buttons');
112 var controlButtonDiv = document.getElementById('control-buttons');
113 var reloadButton = document.getElementById('reload-button');
114 var detailsButton = document.getElementById('details-button');
115 var staleLoadButton = document.getElementById('stale-load-button');
117 var primaryButton = reloadButton;
118 var secondaryButton = staleLoadButton;
120 // Sets up the proper button layout for the current platform.
121 if (primaryControlOnLeft) {
122 buttons.classList.add('suggested-left');
123 controlButtonDiv.insertBefore(primaryButton, secondaryButton);
125 buttons.classList.add('suggested-right');
126 controlButtonDiv.insertBefore(secondaryButton, primaryButton);
129 if (reloadButton.style.display == 'none' &&
130 staleLoadButton.style.display == 'none') {
131 detailsButton.classList.add('singular');
134 // Hide the details button if there are no details to show.
135 if (loadTimeData.valueExists('summary') &&
136 !loadTimeData.getValue('summary').msg) {
137 detailsButton.style.display = 'none';
138 document.getElementById('help-box-outer').style.display = 'block';
141 // Show control buttons.
142 if (loadTimeData.valueExists('reloadButton') &&
143 loadTimeData.getValue('reloadButton').msg ||
144 loadTimeData.valueExists('staleLoadButton') &&
145 loadTimeData.getValue('staleLoadButton').msg) {
146 controlButtonDiv.hidden = false;
149 // Add a main message paragraph.
150 if (loadTimeData.valueExists('primaryParagraph')) {
151 var p = document.querySelector('#main-message p');
152 p.innerHTML = loadTimeData.getString('primaryParagraph');
157 document.addEventListener('DOMContentLoaded', onDocumentLoad);