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 <if expr
="not chromeos">
26 if (window
.errorPageController
)
27 errorPageController
.diagnoseErrorsButtonClick();
30 var extensionId
= 'idddmepepmjcgiedknnmlbadcokidhoa';
31 var diagnoseFrame
= document
.getElementById('diagnose-frame');
32 diagnoseFrame
.innerHTML
=
33 '<iframe src="chrome-extension://' + extensionId
+
34 '/index.html"></iframe>';
38 // Subframes use a different layout but the same html file. This is to make it
39 // easier to support platforms that load the error page via different
40 // mechanisms (Currently just iOS).
41 if (window
.top
.location
!= window
.location
)
42 document
.documentElement
.setAttribute('subframe', '');
44 // Re-renders the error page using |strings| as the dictionary of values.
45 // Used by NetErrorTabHelper to update DNS error pages with probe results.
46 function updateForDnsProbe(strings
) {
47 var context
= new JsEvalContext(strings
);
48 jstProcess(context
, document
.getElementById('t'));
51 // Given the classList property of an element, adds an icon class to the list
52 // and removes the previously-
53 function updateIconClass(classList
, newClass
) {
56 if (classList
.hasOwnProperty('last_icon_class')) {
57 oldClass
= classList
['last_icon_class'];
58 if (oldClass
== newClass
)
62 classList
.add(newClass
);
63 if (oldClass
!== undefined)
64 classList
.remove(oldClass
);
66 classList
['last_icon_class'] = newClass
;
68 if (newClass
== 'icon-offline') {
69 document
.body
.classList
.add('offline');
70 new Runner('.interstitial-wrapper');
72 document
.body
.classList
.add('neterror');
76 // Does a search using |baseSearchUrl| and the text in the search box.
77 function search(baseSearchUrl
) {
78 var searchTextNode
= document
.getElementById('search-box');
79 document
.location
= baseSearchUrl
+ searchTextNode
.value
;
83 // Use to track clicks on elements generated by the navigation correction
84 // service. If |trackingId| is negative, the element does not come from the
85 // correction service.
86 function trackClick(trackingId
) {
87 // This can't be done with XHRs because XHRs are cancelled on navigation
88 // start, and because these are cross-site requests.
89 if (trackingId
>= 0 && errorPageController
)
90 errorPageController
.trackClick(trackingId
);
93 // Called when an <a> tag generated by the navigation correction service is
94 // clicked. Separate function from trackClick so the resources don't have to
95 // be updated if new data is added to jstdata.
96 function linkClicked(jstdata
) {
97 trackClick(jstdata
.trackingId
);
100 // Implements button clicks. This function is needed during the transition
101 // between implementing these in trunk chromium and implementing them in
103 function reloadButtonClick(url
) {
104 if (window
.errorPageController
) {
105 errorPageController
.reloadButtonClick();
111 function showSavedCopyButtonClick() {
112 if (window
.errorPageController
) {
113 errorPageController
.showSavedCopyButtonClick();
117 function detailsButtonClick() {
118 if (window
.errorPageController
)
119 errorPageController
.detailsButtonClick();
123 * Replace the reload button with the Google cached copy suggestion.
125 function setUpCachedButton(buttonStrings
) {
126 var reloadButton
= document
.getElementById('reload-button');
128 reloadButton
.textContent
= buttonStrings
.msg
;
129 var url
= buttonStrings
.cacheUrl
;
130 var trackingId
= buttonStrings
.trackingId
;
131 reloadButton
.onclick = function(e
) {
133 trackClick(trackingId
);
134 if (window
.errorPageController
) {
135 errorPageController
.trackCachedCopyButtonClick();
139 reloadButton
.style
.display
= '';
140 document
.getElementById('control-buttons').hidden
= false;
143 var primaryControlOnLeft
= true;
144 <if expr
="is_macosx or is_ios or is_linux or is_android">
145 primaryControlOnLeft
= false;
148 function onDocumentLoad() {
149 var controlButtonDiv
= document
.getElementById('control-buttons');
150 var reloadButton
= document
.getElementById('reload-button');
151 var detailsButton
= document
.getElementById('details-button');
152 var showSavedCopyButton
= document
.getElementById('show-saved-copy-button');
154 var primaryButton
, secondaryButton
;
155 if (showSavedCopyButton
.primary
) {
156 primaryButton
= showSavedCopyButton
;
157 secondaryButton
= reloadButton
;
159 primaryButton
= reloadButton
;
160 secondaryButton
= showSavedCopyButton
;
163 // Sets up the proper button layout for the current platform.
164 if (primaryControlOnLeft
) {
165 buttons
.classList
.add('suggested-left');
166 controlButtonDiv
.insertBefore(secondaryButton
, primaryButton
);
168 buttons
.classList
.add('suggested-right');
169 controlButtonDiv
.insertBefore(primaryButton
, secondaryButton
);
172 // Check for Google cached copy suggestion.
173 if (loadTimeData
.valueExists('cacheButton')) {
174 setUpCachedButton(loadTimeData
.getValue('cacheButton'));
177 if (reloadButton
.style
.display
== 'none' &&
178 showSavedCopyButton
.style
.display
== 'none') {
179 detailsButton
.classList
.add('singular');
182 <if expr
="not chromeos">
183 // Hide the details button if there are no details to show.
184 if (loadTimeData
.valueExists('summary') &&
185 !loadTimeData
.getValue('summary').msg
) {
186 detailsButton
.style
.display
= 'none';
190 // Show control buttons.
191 if (loadTimeData
.valueExists('reloadButton') &&
192 loadTimeData
.getValue('reloadButton').msg
||
193 loadTimeData
.valueExists('showSavedCopyButton') &&
194 loadTimeData
.getValue('showSavedCopyButton').msg
) {
195 controlButtonDiv
.hidden
= false;
197 // Set the secondary button state in the cases of two call to actions.
198 if (loadTimeData
.valueExists('reloadButton') &&
199 loadTimeData
.getValue('reloadButton').msg
&&
200 loadTimeData
.valueExists('showSavedCopyButton') &&
201 loadTimeData
.getValue('showSavedCopyButton').msg
) {
202 secondaryButton
.classList
.add('secondary-button');
206 // Add a main message paragraph.
207 if (loadTimeData
.valueExists('primaryParagraph')) {
208 var p
= document
.querySelector('#main-message p');
209 p
.innerHTML
= loadTimeData
.getString('primaryParagraph');
214 document
.addEventListener('DOMContentLoaded', onDocumentLoad
);