| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 cr.define('extensions', function() { | 5 cr.define('extensions', function() { |
| 6 'use strict'; | 6 'use strict'; |
| 7 | 7 |
| 8 var CodeSection = Polymer({ | 8 var CodeSection = Polymer({ |
| 9 is: 'extensions-code-section', | 9 is: 'extensions-code-section', |
| 10 | 10 |
| 11 properties: { | 11 properties: { |
| 12 /** | 12 /** |
| 13 * The code this object is displaying. | 13 * The code this object is displaying. |
| 14 * @type {?chrome.developerPrivate.RequestFileSourceResponse} | 14 * @type {?chrome.developerPrivate.RequestFileSourceResponse} |
| 15 */ | 15 */ |
| 16 code: { | 16 code: { |
| 17 type: Object, | 17 type: Object, |
| 18 // We initialize to null so that Polymer sees it as defined and calls | 18 // We initialize to null so that Polymer sees it as defined and calls |
| 19 // isMainHidden_(). | 19 // isMainHidden_(). |
| 20 value: null, | 20 value: null, |
| 21 }, | 21 }, |
| 22 | 22 |
| 23 /** | 23 /** |
| 24 * The string to display if no code is set. | 24 * The string to display if no |code| is set (e.g. because we couldn't |
| 25 * load the relevant source file). |
| 25 * @type {string} | 26 * @type {string} |
| 26 */ | 27 */ |
| 27 noCodeError: String, | 28 couldNotDisplayCode: String, |
| 28 }, | 29 }, |
| 29 | 30 |
| 30 /** | 31 /** |
| 32 * Returns true if no code could be displayed (e.g. because the file could |
| 33 * not be loaded). |
| 34 * @return {boolean} |
| 35 */ |
| 36 isEmpty: function() { |
| 37 return !this.code || |
| 38 (!this.code.beforeHighlight && !this.code.highlight && |
| 39 !this.code.afterHighlight); |
| 40 }, |
| 41 |
| 42 /** |
| 31 * Computes the content of the line numbers span, which basically just | 43 * Computes the content of the line numbers span, which basically just |
| 32 * contains 1\n2\n3\n... for the number of lines. | 44 * contains 1\n2\n3\n... for the number of lines. |
| 33 * @return {string} | 45 * @return {string} |
| 34 * @private | 46 * @private |
| 35 */ | 47 */ |
| 36 computeLineNumbersContent_: function() { | 48 computeLineNumbersContent_: function() { |
| 37 if (!this.code) | 49 if (!this.code) |
| 38 return ''; | 50 return ''; |
| 39 | 51 |
| 40 var lines = [this.code.beforeHighlight, | 52 var lines = [this.code.beforeHighlight, |
| 41 this.code.highlight, | 53 this.code.highlight, |
| 42 this.code.afterHighlight].join('').match(/\n/g); | 54 this.code.afterHighlight].join('').match(/\n/g); |
| 43 var lineCount = lines ? lines.length : 0; | 55 var lineCount = lines ? lines.length : 0; |
| 44 var textContent = ''; | 56 var textContent = ''; |
| 45 for (var i = 1; i <= lineCount; ++i) | 57 for (var i = 1; i <= lineCount; ++i) |
| 46 textContent += i + '\n'; | 58 textContent += i + '\n'; |
| 47 return textContent; | 59 return textContent; |
| 48 }, | 60 }, |
| 49 | |
| 50 /** | |
| 51 * @return {boolean} | |
| 52 * @private | |
| 53 */ | |
| 54 isMainHidden_: function() { | |
| 55 return !this.code; | |
| 56 }, | |
| 57 }); | 61 }); |
| 58 | 62 |
| 59 return {CodeSection: CodeSection}; | 63 return {CodeSection: CodeSection}; |
| 60 }); | 64 }); |
| OLD | NEW |