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 cr.define('options', function() { | 5 cr.define('options', function() { |
6 /** @const */ var OptionsPage = options.OptionsPage; | 6 /** @const */ var OptionsPage = options.OptionsPage; |
7 | 7 |
8 /** | 8 /** |
9 * Encapsulated handling of a search bubble. | 9 * Encapsulated handling of a search bubble. |
10 * @constructor | 10 * @constructor |
11 */ | 11 */ |
12 function SearchBubble(text) { | 12 function SearchBubble(text) { |
13 var el = cr.doc.createElement('div'); | 13 var el = cr.doc.createElement('div'); |
14 SearchBubble.decorate(el); | 14 SearchBubble.decorate(el); |
15 el.textContent = text; | 15 el.content = text; |
16 return el; | 16 return el; |
17 } | 17 } |
18 | 18 |
19 SearchBubble.decorate = function(el) { | 19 SearchBubble.decorate = function(el) { |
20 el.__proto__ = SearchBubble.prototype; | 20 el.__proto__ = SearchBubble.prototype; |
21 el.decorate(); | 21 el.decorate(); |
22 }; | 22 }; |
23 | 23 |
24 SearchBubble.prototype = { | 24 SearchBubble.prototype = { |
25 __proto__: HTMLDivElement.prototype, | 25 __proto__: HTMLDivElement.prototype, |
26 | 26 |
27 decorate: function() { | 27 decorate: function() { |
28 this.className = 'search-bubble'; | 28 this.className = 'search-bubble'; |
29 | 29 |
| 30 this.innards_ = cr.doc.createElement('div'); |
| 31 this.innards_.className = 'search-bubble-innards'; |
| 32 this.appendChild(this.innards_); |
| 33 |
30 // We create a timer to periodically update the position of the bubbles. | 34 // We create a timer to periodically update the position of the bubbles. |
31 // While this isn't all that desirable, it's the only sure-fire way of | 35 // While this isn't all that desirable, it's the only sure-fire way of |
32 // making sure the bubbles stay in the correct location as sections | 36 // making sure the bubbles stay in the correct location as sections |
33 // may dynamically change size at any time. | 37 // may dynamically change size at any time. |
34 this.intervalId = setInterval(this.updatePosition.bind(this), 250); | 38 this.intervalId = setInterval(this.updatePosition.bind(this), 250); |
35 }, | 39 }, |
36 | 40 |
37 /** | 41 /** |
38 * Attach the bubble to the element. | 42 * Sets the text message in the bubble. |
39 */ | 43 * @param {string} text The text the bubble will show. |
| 44 */ |
| 45 set content(text) { |
| 46 this.innards_.textContent = text; |
| 47 }, |
| 48 |
| 49 /** |
| 50 * Attach the bubble to the element. |
| 51 */ |
40 attachTo: function(element) { | 52 attachTo: function(element) { |
41 var parent = element.parentElement; | 53 var parent = element.parentElement; |
42 if (!parent) | 54 if (!parent) |
43 return; | 55 return; |
44 if (parent.tagName == 'TD') { | 56 if (parent.tagName == 'TD') { |
45 // To make absolute positioning work inside a table cell we need | 57 // To make absolute positioning work inside a table cell we need |
46 // to wrap the bubble div into another div with position:relative. | 58 // to wrap the bubble div into another div with position:relative. |
47 // This only works properly if the element is the first child of the | 59 // This only works properly if the element is the first child of the |
48 // table cell which is true for all options pages. | 60 // table cell which is true for all options pages. |
49 this.wrapper = cr.doc.createElement('div'); | 61 this.wrapper = cr.doc.createElement('div'); |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 // Trim beginning and ending whitespace. | 570 // Trim beginning and ending whitespace. |
559 return text.replace(/^\s+|\s+$/g, ''); | 571 return text.replace(/^\s+|\s+$/g, ''); |
560 }; | 572 }; |
561 | 573 |
562 // Export | 574 // Export |
563 return { | 575 return { |
564 SearchPage: SearchPage | 576 SearchPage: SearchPage |
565 }; | 577 }; |
566 | 578 |
567 }); | 579 }); |
OLD | NEW |