| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // Constants. | 5 // Constants. |
| 6 /** @const */ var FEEDBACK_LANDING_PAGE = | 6 /** @const */ var FEEDBACK_LANDING_PAGE = |
| 7 'http://www.google.com/support/chrome/go/feedback_confirmation'; | 7 'http://www.google.com/support/chrome/go/feedback_confirmation'; |
| 8 | 8 |
| 9 var selectedThumbnailDivId = ''; | 9 var selectedThumbnailDivId = ''; |
| 10 var selectedThumbnailId = ''; | 10 var selectedThumbnailId = ''; |
| 11 var selectedImageUrl; | 11 var selectedImageUrl; |
| 12 | 12 |
| 13 var savedThumbnailIds = []; | 13 var savedThumbnailIds = []; |
| 14 savedThumbnailIds['current-screenshots'] = ''; | 14 savedThumbnailIds['current-screenshots'] = ''; |
| 15 savedThumbnailIds['saved-screenshots'] = ''; | 15 savedThumbnailIds['saved-screenshots'] = ''; |
| 16 | 16 |
| 17 var categoryTag = ''; | 17 var categoryTag = ''; |
| 18 | 18 |
| 19 var localStrings = new LocalStrings(); | |
| 20 | |
| 21 /** | 19 /** |
| 22 * Selects an image thumbnail in the specified div. | 20 * Selects an image thumbnail in the specified div. |
| 23 * @param {string} divId The id of the div to search in. | 21 * @param {string} divId The id of the div to search in. |
| 24 * @param {string} thumbnailId The id of the thumbnail to search for. | 22 * @param {string} thumbnailId The id of the thumbnail to search for. |
| 25 */ | 23 */ |
| 26 function selectImage(divId, thumbnailId) { | 24 function selectImage(divId, thumbnailId) { |
| 27 var thumbnailDivs = $(divId).children; | 25 var thumbnailDivs = $(divId).children; |
| 28 selectedThumbnailDivId = divId; | 26 selectedThumbnailDivId = divId; |
| 29 if (thumbnailDivs.length == 0) { | 27 if (thumbnailDivs.length == 0) { |
| 30 $(divId).hidden = true; | 28 $(divId).hidden = true; |
| 31 return; | 29 return; |
| 32 } | 30 } |
| 31 |
| 33 for (var i = 0; i < thumbnailDivs.length; i++) { | 32 for (var i = 0; i < thumbnailDivs.length; i++) { |
| 33 thumbnailDivs[i].className = 'image-thumbnail-container'; |
| 34 |
| 34 // If the the current div matches the thumbnail id provided, | 35 // If the the current div matches the thumbnail id provided, |
| 35 // or there is no thumbnail id given, and we're at the first thumbnail. | 36 // or there is no thumbnail id given, and we're at the first thumbnail. |
| 36 if ((thumbnailDivs[i].id == thumbnailId) || (!thumbnailId && !i)) { | 37 if (thumbnailDivs[i].id == thumbnailId || (!thumbnailId && !i)) { |
| 37 thumbnailDivs[i].className = 'image-thumbnail-container-selected'; | 38 thumbnailDivs[i].classList.add('image-thumbnail-container-selected'); |
| 38 selectedThumbnailId = thumbnailId; | 39 selectedThumbnailId = thumbnailId; |
| 39 savedThumbnailIds[divId] = thumbnailId; | 40 savedThumbnailIds[divId] = thumbnailId; |
| 40 } else { | |
| 41 thumbnailDivs[i].className = 'image-thumbnail-container'; | |
| 42 } | 41 } |
| 43 } | 42 } |
| 44 } | 43 } |
| 45 | 44 |
| 46 /** | 45 /** |
| 47 * Adds an image thumbnail to the specified div. | 46 * Adds an image thumbnail to the specified div. |
| 48 * @param {string} divId The id of the div to add a screenshot to. | 47 * @param {string} divId The id of the div to add a screenshot to. |
| 49 * @param {string} screenshot The URL of the screenshot being added. | 48 * @param {string} screenshot The URL of the screenshot being added. |
| 50 */ | 49 */ |
| 51 function addScreenshot(divId, screenshot) { | 50 function addScreenshot(divId, screenshot) { |
| 52 var thumbnailDiv = document.createElement('div'); | 51 var thumbnailDiv = document.createElement('div'); |
| 53 thumbnailDiv.className = 'image-thumbnail-container'; | 52 thumbnailDiv.className = 'image-thumbnail-container'; |
| 54 | 53 |
| 55 thumbnailDiv.id = divId + '-thumbnailDiv-' + $(divId).children.length; | 54 thumbnailDiv.id = divId + '-thumbnailDiv-' + $(divId).children.length; |
| 56 thumbnailDiv.onclick = function() { | 55 thumbnailDiv.onclick = function() { |
| 57 selectImage(divId, thumbnailDiv.id); | 56 selectImage(divId, thumbnailDiv.id); |
| 58 }; | 57 }; |
| 59 | 58 |
| 60 var innerDiv = document.createElement('div'); | 59 var innerDiv = document.createElement('div'); |
| 61 if (divId == 'current-screenshots') | 60 innerDiv.className = 'image-thumbnail'; |
| 62 innerDiv.className = 'image-thumbnail-current'; | |
| 63 else | |
| 64 innerDiv.className = 'image-thumbnail'; | |
| 65 | 61 |
| 66 var thumbnail = document.createElement('img'); | 62 var thumbnail = document.createElement('img'); |
| 67 thumbnail.id = thumbnailDiv.id + '-image'; | 63 thumbnail.id = thumbnailDiv.id + '-image'; |
| 68 // We add the ?+timestamp to make sure the image URLs are unique | 64 // We add the ?+timestamp to make sure the image URLs are unique |
| 69 // and Chrome does not load the image from cache. | 65 // and Chrome does not load the image from cache. |
| 70 thumbnail.src = screenshot + '?' + Date.now(); | 66 thumbnail.src = screenshot + '?' + Date.now(); |
| 71 innerDiv.appendChild(thumbnail); | 67 innerDiv.appendChild(thumbnail); |
| 72 | 68 |
| 73 thumbnailDiv.appendChild(innerDiv); | 69 thumbnailDiv.appendChild(innerDiv); |
| 74 $(divId).appendChild(thumbnailDiv); | 70 $(divId).appendChild(thumbnailDiv); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 90 } | 86 } |
| 91 | 87 |
| 92 /** | 88 /** |
| 93 * Sends the report; after the report is sent, we need to be redirected to | 89 * Sends the report; after the report is sent, we need to be redirected to |
| 94 * the landing page, but we shouldn't be able to navigate back, hence | 90 * the landing page, but we shouldn't be able to navigate back, hence |
| 95 * we open the landing page in a new tab and sendReport closes this tab. | 91 * we open the landing page in a new tab and sendReport closes this tab. |
| 96 * @return {boolean} True if the report was sent. | 92 * @return {boolean} True if the report was sent. |
| 97 */ | 93 */ |
| 98 function sendReport() { | 94 function sendReport() { |
| 99 if ($('description-text').value.length == 0) { | 95 if ($('description-text').value.length == 0) { |
| 100 alert(localStrings.getString('no-description')); | 96 alert(loadTimeData.getString('no-description')); |
| 101 return false; | 97 return false; |
| 102 } | 98 } |
| 103 | 99 |
| 104 var imagePath = ''; | 100 var imagePath = ''; |
| 105 if ($('screenshot-checkbox').checked && selectedThumbnailId) | 101 if ($('screenshot-checkbox').checked && selectedThumbnailId) |
| 106 imagePath = $(selectedThumbnailId + '-image').src; | 102 imagePath = $(selectedThumbnailId + '-image').src; |
| 107 var pageUrl = $('page-url-text').value; | 103 var pageUrl = $('page-url-text').value; |
| 108 if (!$('page-url-checkbox').checked) | 104 if (!$('page-url-checkbox').checked) |
| 109 pageUrl = ''; | 105 pageUrl = ''; |
| 110 | 106 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 if (selectedThumbnailDivId != 'current-screenshots') | 146 if (selectedThumbnailDivId != 'current-screenshots') |
| 151 selectImage('current-screenshots', | 147 selectImage('current-screenshots', |
| 152 savedThumbnailIds['current-screenshots']); | 148 savedThumbnailIds['current-screenshots']); |
| 153 } | 149 } |
| 154 | 150 |
| 155 /** | 151 /** |
| 156 * Select the saved screenshots div, restoring the image that was | 152 * Select the saved screenshots div, restoring the image that was |
| 157 * selected when we had this div open previously. | 153 * selected when we had this div open previously. |
| 158 */ | 154 */ |
| 159 function savedSelected() { | 155 function savedSelected() { |
| 160 $('current-screenshots').hidden = true; | |
| 161 | |
| 162 if ($('saved-screenshots').childElementCount == 0) { | 156 if ($('saved-screenshots').childElementCount == 0) { |
| 163 // setupSavedScreenshots will take care of changing visibility | 157 // setupSavedScreenshots will take care of changing visibility |
| 164 chrome.send('refreshSavedScreenshots'); | 158 chrome.send('refreshSavedScreenshots'); |
| 165 } else { | 159 } else { |
| 160 $('current-screenshots').hidden = true; |
| 166 $('saved-screenshots').hidden = false; | 161 $('saved-screenshots').hidden = false; |
| 167 if (selectedThumbnailDivId != 'saved-screenshots') | 162 if (selectedThumbnailDivId != 'saved-screenshots') |
| 168 selectImage('saved-screenshots', savedThumbnailIds['saved-screenshots']); | 163 selectImage('saved-screenshots', savedThumbnailIds['saved-screenshots']); |
| 169 } | 164 } |
| 170 } | 165 } |
| 171 | 166 |
| 172 | |
| 173 /** | 167 /** |
| 174 * Change the type of screenshot we're showing to the user from | 168 * Change the type of screenshot we're showing to the user from |
| 175 * the current screenshot to saved screenshots | 169 * the current screenshot to saved screenshots |
| 176 */ | 170 */ |
| 177 function changeToSaved() { | 171 function changeToSaved() { |
| 178 $('screenshot-label-current').hidden = true; | 172 $('screenshot-label-current').hidden = true; |
| 179 $('screenshot-label-saved').hidden = false; | 173 $('screenshot-label-saved').hidden = false; |
| 180 | 174 |
| 181 // Change the link to say "go to original" | 175 // Change the link to say "go to original" |
| 182 $('screenshot-link-tosaved').hidden = true; | 176 $('screenshot-link-tosaved').hidden = true; |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 chrome.send('refreshCurrentScreenshot'); | 254 chrome.send('refreshCurrentScreenshot'); |
| 261 } | 255 } |
| 262 | 256 |
| 263 function setupCurrentScreenshot(screenshot) { | 257 function setupCurrentScreenshot(screenshot) { |
| 264 addScreenshot('current-screenshots', screenshot); | 258 addScreenshot('current-screenshots', screenshot); |
| 265 } | 259 } |
| 266 | 260 |
| 267 function setupSavedScreenshots(screenshots) { | 261 function setupSavedScreenshots(screenshots) { |
| 268 if (screenshots.length == 0) { | 262 if (screenshots.length == 0) { |
| 269 $('saved-screenshots').textContent = | 263 $('saved-screenshots').textContent = |
| 270 localStrings.getString('no-saved-screenshots'); | 264 loadTimeData.getString('no-saved-screenshots'); |
| 271 | 265 |
| 272 // Make sure we make the display the message. | 266 // Make sure we make the display the message. |
| 267 $('current-screenshots').hidden = true; |
| 273 $('saved-screenshots').hidden = false; | 268 $('saved-screenshots').hidden = false; |
| 274 | 269 |
| 275 // In case the user tries to send now; fail safe, do not send a screenshot | 270 // In case the user tries to send now; fail safe, do not send a screenshot |
| 276 // at all versus sending the current screenshot. | 271 // at all versus sending the current screenshot. |
| 277 selectedThumbnailDivId = ''; | 272 selectedThumbnailDivId = ''; |
| 278 selectedThumbnailId = ''; | 273 selectedThumbnailId = ''; |
| 279 } else { | 274 } else { |
| 280 for (i = 0; i < screenshots.length; ++i) | 275 for (i = 0; i < screenshots.length; ++i) |
| 281 addScreenshot('saved-screenshots', screenshots[i]); | 276 addScreenshot('saved-screenshots', screenshots[i]); |
| 282 | 277 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 302 $('user-email-table').hidden = true; | 297 $('user-email-table').hidden = true; |
| 303 | 298 |
| 304 // this also means we are in privacy mode, so no saved screenshots. | 299 // this also means we are in privacy mode, so no saved screenshots. |
| 305 $('screenshot-link-tosaved').hidden = true; | 300 $('screenshot-link-tosaved').hidden = true; |
| 306 } | 301 } |
| 307 } | 302 } |
| 308 } | 303 } |
| 309 } | 304 } |
| 310 | 305 |
| 311 window.addEventListener('DOMContentLoaded', load); | 306 window.addEventListener('DOMContentLoaded', load); |
| OLD | NEW |