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();
117 * Replace the reload button with the Google cached copy suggestion.
119 function setUpCachedButton(buttonStrings) {
120 var reloadButton = document.getElementById('reload-button');
122 reloadButton.textContent = buttonStrings.msg;
123 var url = buttonStrings.cacheUrl;
124 var trackingId = buttonStrings.trackingId;
125 reloadButton.onclick = function(e) {
127 trackClick(trackingId);
130 reloadButton.style.display = '';
131 document.getElementById('control-buttons').hidden = false;
134 var primaryControlOnLeft = true;
135 <if expr="is_macosx or is_ios or is_linux or is_android">
136 primaryControlOnLeft = false;
139 function onDocumentLoad() {
140 var controlButtonDiv = document.getElementById('control-buttons');
141 var reloadButton = document.getElementById('reload-button');
142 var detailsButton = document.getElementById('details-button');
143 var showSavedCopyButton = document.getElementById('show-saved-copy-button');
145 var primaryButton, secondaryButton;
146 if (showSavedCopyButton.primary) {
147 primaryButton = showSavedCopyButton;
148 secondaryButton = reloadButton;
150 primaryButton = reloadButton;
151 secondaryButton = showSavedCopyButton;
154 // Sets up the proper button layout for the current platform.
155 if (primaryControlOnLeft) {
156 buttons.classList.add('suggested-left');
157 controlButtonDiv.insertBefore(secondaryButton, primaryButton);
159 buttons.classList.add('suggested-right');
160 controlButtonDiv.insertBefore(primaryButton, secondaryButton);
163 if (reloadButton.style.display == 'none' &&
164 showSavedCopyButton.style.display == 'none') {
165 detailsButton.classList.add('singular');
168 <if expr="not chromeos">
169 // Hide the details button if there are no details to show.
170 if (loadTimeData.valueExists('summary') &&
171 !loadTimeData.getValue('summary').msg) {
172 detailsButton.style.display = 'none';
176 // Show control buttons.
177 if (loadTimeData.valueExists('reloadButton') &&
178 loadTimeData.getValue('reloadButton').msg ||
179 loadTimeData.valueExists('showSavedCopyButton') &&
180 loadTimeData.getValue('showSavedCopyButton').msg) {
181 controlButtonDiv.hidden = false;
183 // Set the secondary button state in the cases of two call to actions.
184 if (loadTimeData.valueExists('reloadButton') &&
185 loadTimeData.getValue('reloadButton').msg &&
186 loadTimeData.valueExists('showSavedCopyButton') &&
187 loadTimeData.getValue('showSavedCopyButton').msg) {
188 secondaryButton.classList.add('secondary-button');
192 // Add a main message paragraph.
193 if (loadTimeData.valueExists('primaryParagraph')) {
194 var p = document.querySelector('#main-message p');
195 p.innerHTML = loadTimeData.getString('primaryParagraph');
199 // Check for Google cached copy suggestion.
200 if (loadTimeData.valueExists('cacheButton')) {
201 setUpCachedButton(loadTimeData.getValue('cacheButton'));
205 document.addEventListener('DOMContentLoaded', onDocumentLoad);