| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 /** | 5 /** |
| 6 * @typedef {{afterHighlight: string, | 6 * @typedef {{afterHighlight: string, |
| 7 * beforeHighlight: string, | 7 * beforeHighlight: string, |
| 8 * highlight: string, | 8 * highlight: string, |
| 9 * title: string}} | 9 * title: string}} |
| 10 */ | 10 */ |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 * both before and after this portion. The title is the error message, | 36 * both before and after this portion. The title is the error message, |
| 37 * which will be the mouseover hint for the highlighted region. These | 37 * which will be the mouseover hint for the highlighted region. These |
| 38 * may be empty. | 38 * may be empty. |
| 39 * @param {string} emptyMessage The message to display if the code | 39 * @param {string} emptyMessage The message to display if the code |
| 40 * object is empty (e.g., 'could not load code'). | 40 * object is empty (e.g., 'could not load code'). |
| 41 */ | 41 */ |
| 42 populate: function(code, emptyMessage) { | 42 populate: function(code, emptyMessage) { |
| 43 // Clear any remnant content, so we don't have multiple code listed. | 43 // Clear any remnant content, so we don't have multiple code listed. |
| 44 this.clear(); | 44 this.clear(); |
| 45 | 45 |
| 46 // If there's no code, then display an appropriate message. |
| 47 if (!code || |
| 48 (!code.highlight && !code.beforeHighlight && !code.afterHighlight)) { |
| 49 var span = document.createElement('span'); |
| 50 span.classList.add('extension-code-empty'); |
| 51 span.textContent = emptyMessage; |
| 52 this.appendChild(span); |
| 53 return; |
| 54 } |
| 55 |
| 46 var sourceDiv = document.createElement('div'); | 56 var sourceDiv = document.createElement('div'); |
| 47 sourceDiv.classList.add('extension-code-source'); | 57 sourceDiv.classList.add('extension-code-source'); |
| 48 this.appendChild(sourceDiv); | 58 this.appendChild(sourceDiv); |
| 49 | 59 |
| 50 // If there's no code, then display an appropriate message. | |
| 51 if (!code || | |
| 52 (!code.highlight && !code.beforeHighlight && !code.afterHighlight)) { | |
| 53 var span = document.createElement('span'); | |
| 54 span.textContent = emptyMessage; | |
| 55 sourceDiv.appendChild(span); | |
| 56 return; | |
| 57 } | |
| 58 | |
| 59 var lineCount = 0; | 60 var lineCount = 0; |
| 60 var createSpan = function(source, isHighlighted) { | 61 var createSpan = function(source, isHighlighted) { |
| 61 lineCount += source.split('\n').length - 1; | 62 lineCount += source.split('\n').length - 1; |
| 62 var span = document.createElement('span'); | 63 var span = document.createElement('span'); |
| 63 span.className = isHighlighted ? 'extension-code-highlighted-source' : | 64 span.className = isHighlighted ? 'extension-code-highlighted-source' : |
| 64 'extension-code-normal-source'; | 65 'extension-code-normal-source'; |
| 65 span.textContent = source; | 66 span.textContent = source; |
| 66 return span; | 67 return span; |
| 67 }; | 68 }; |
| 68 | 69 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 if (errorSpan) | 110 if (errorSpan) |
| 110 this.scrollTop = errorSpan.offsetTop - this.clientHeight / 2; | 111 this.scrollTop = errorSpan.offsetTop - this.clientHeight / 2; |
| 111 } | 112 } |
| 112 }; | 113 }; |
| 113 | 114 |
| 114 // Export | 115 // Export |
| 115 return { | 116 return { |
| 116 ExtensionCode: ExtensionCode | 117 ExtensionCode: ExtensionCode |
| 117 }; | 118 }; |
| 118 }); | 119 }); |
| OLD | NEW |