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('details');
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;
14 // Details appears over the main content on small screens.
16 document.getElementById('main-content').classList.toggle('hidden');
17 var runnerContainer = document.querySelector('.runner-container');
18 if (runnerContainer) {
19 runnerContainer.classList.toggle('hidden');
24 function diagnoseErrors() {
25 var extensionId = 'idddmepepmjcgiedknnmlbadcokidhoa';
26 var diagnoseFrame = document.getElementById('diagnose-frame');
27 diagnoseFrame.innerHTML =
28 '<iframe src="chrome-extension://' + extensionId +
29 '/index.html"></iframe>';
32 // Subframes use a different layout but the same html file. This is to make it
33 // easier to support platforms that load the error page via different
34 // mechanisms (Currently just iOS).
35 if (window.top.location != window.location)
36 document.documentElement.setAttribute('subframe', '');
38 // Re-renders the error page using |strings| as the dictionary of values.
39 // Used by NetErrorTabHelper to update DNS error pages with probe results.
40 function updateForDnsProbe(strings) {
41 var context = new JsEvalContext(strings);
42 jstProcess(context, document.getElementById('t'));
45 // Given the classList property of an element, adds an icon class to the list
46 // and removes the previously-
47 function updateIconClass(classList, newClass) {
50 if (classList.hasOwnProperty('last_icon_class')) {
51 oldClass = classList['last_icon_class'];
52 if (oldClass == newClass)
56 classList.add(newClass);
57 if (oldClass !== undefined)
58 classList.remove(oldClass);
60 classList['last_icon_class'] = newClass;
62 if (newClass == 'icon-offline') {
63 document.body.classList.add('offline');
64 new Runner('.interstitial-wrapper');
66 document.body.classList.add('neterror');
70 // Does a search using |baseSearchUrl| and the text in the search box.
71 function search(baseSearchUrl) {
72 var searchTextNode = document.getElementById('search-box');
73 document.location = baseSearchUrl + searchTextNode.value;
77 // Use to track clicks on elements generated by the navigation correction
78 // service. If |trackingId| is negative, the element does not come from the
79 // correction service.
80 function trackClick(trackingId) {
81 // This can't be done with XHRs because XHRs are cancelled on navigation
82 // start, and because these are cross-site requests.
83 if (trackingId >= 0 && errorPageController)
84 errorPageController.trackClick(trackingId);
87 // Called when an <a> tag generated by the navigation correction service is
88 // clicked. Separate function from trackClick so the resources don't have to
89 // be updated if new data is added to jstdata.
90 function linkClicked(jstdata) {
91 trackClick(jstdata.trackingId);
94 // Implements button clicks. This function is needed during the transition
95 // between implementing these in trunk chromium and implementing them in
97 function reloadButtonClick(url) {
98 if (window.errorPageController) {
99 errorPageController.reloadButtonClick();
105 function showSavedCopyButtonClick() {
106 if (window.errorPageController) {
107 errorPageController.showSavedCopyButtonClick();
111 function detailsButtonClick() {
112 if (window.errorPageController)
113 errorPageController.detailsButtonClick();
116 var primaryControlOnLeft = true;
117 <if expr="is_macosx or is_ios or is_linux or is_android">
118 primaryControlOnLeft = false;
121 function onDocumentLoad() {
122 var buttonsDiv = document.getElementById('buttons');
123 var controlButtonDiv = document.getElementById('control-buttons');
124 var reloadButton = document.getElementById('reload-button');
125 var detailsButton = document.getElementById('details-button');
126 var showSavedCopyButton = document.getElementById('show-saved-copy-button');
128 var primaryButton, secondaryButton;
129 if (showSavedCopyButton.primary) {
130 primaryButton = showSavedCopyButton;
131 secondaryButton = reloadButton;
133 primaryButton = reloadButton;
134 secondaryButton = showSavedCopyButton;
137 // Sets up the proper button layout for the current platform.
138 if (primaryControlOnLeft) {
139 buttons.classList.add('suggested-left');
140 controlButtonDiv.insertBefore(secondaryButton, primaryButton);
142 buttons.classList.add('suggested-right');
143 controlButtonDiv.insertBefore(primaryButton, secondaryButton);
146 if (reloadButton.style.display == 'none' &&
147 showSavedCopyButton.style.display == 'none') {
148 detailsButton.classList.add('singular');
151 <if expr="not chromeos">
152 // Hide the details button if there are no details to show.
153 if (loadTimeData.valueExists('summary') &&
154 !loadTimeData.getValue('summary').msg) {
155 detailsButton.style.display = 'none';
159 // Show control buttons.
160 if (loadTimeData.valueExists('reloadButton') &&
161 loadTimeData.getValue('reloadButton').msg ||
162 loadTimeData.valueExists('showSavedCopyButton') &&
163 loadTimeData.getValue('showSavedCopyButton').msg) {
164 controlButtonDiv.hidden = false;
166 // Set the secondary button state in the cases of two call to actions.
167 if (loadTimeData.valueExists('reloadButton') &&
168 loadTimeData.getValue('reloadButton').msg &&
169 loadTimeData.valueExists('showSavedCopyButton') &&
170 loadTimeData.getValue('showSavedCopyButton').msg) {
171 secondaryButton.classList.add('secondary-button');
175 // Add a main message paragraph.
176 if (loadTimeData.valueExists('primaryParagraph')) {
177 var p = document.querySelector('#main-message p');
178 p.innerHTML = loadTimeData.getString('primaryParagraph');
183 document.addEventListener('DOMContentLoaded', onDocumentLoad);