OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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. |
| 4 |
| 5 /** |
| 6 * Sends 'activate' DOMUI message. |
| 7 */ |
| 8 function sendAction(values) { |
| 9 chrome.send('action', values); |
| 10 } |
| 11 |
| 12 var NetworkMenuItem = cr.ui.define('div'); |
| 13 |
| 14 NetworkMenuItem.prototype = { |
| 15 __proto__: MenuItem.prototype, |
| 16 |
| 17 /** |
| 18 * Internal method to initiailze the MenuItem. |
| 19 * @private |
| 20 */ |
| 21 initMenuItem_: function(leftIconWidth) { |
| 22 // *TODO: eliminate code duplication with menu.js |
| 23 // MenuItem.prototype.initMenuItem_(leftIconWidth); |
| 24 var attrs = this.attrs; |
| 25 this.className = 'menu-item ' + attrs.type; |
| 26 this.menu_.addHandlers(this); |
| 27 if (leftIconWidth > 0) { |
| 28 this.classList.add('left-icon'); |
| 29 |
| 30 var url; |
| 31 if (attrs.type == 'radio') { |
| 32 url = attrs.checked ? |
| 33 this.menu_.config_.radioOnUrl : |
| 34 this.menu_.config_.radioOffUrl; |
| 35 } else if (attrs.icon) { |
| 36 url = attrs.icon; |
| 37 } else if (attrs.type == 'check' && attrs.checked) { |
| 38 url = this.menu_.config_.checkUrl; |
| 39 } |
| 40 if (url) { |
| 41 this.style.backgroundImage = 'url(' + url + ')'; |
| 42 } |
| 43 // TODO(oshima): figure out how to update left padding in rule. |
| 44 // 4 is the padding on left side of icon. |
| 45 var padding = |
| 46 4 + leftIconWidth + this.menu_.config_.icon_to_label_padding; |
| 47 this.style.paddingLeft = padding + 'px'; |
| 48 } |
| 49 var label = document.createElement('div'); |
| 50 |
| 51 label.className = 'menu-label'; |
| 52 |
| 53 //////// NetworkMenuItem specific code: |
| 54 // TODO: Handle specific types of network, connecting icon. |
| 55 if (attrs.status && attrs.status != 'unknown') { |
| 56 label.appendChild(document.createTextNode(attrs.label)); |
| 57 if (attrs.status == 'connected') { |
| 58 // label.appendChild(document.createElement('p')). |
| 59 // appendChild(document.createTextNode(attrs.message)); |
| 60 label.appendChild(document.createElement('p')). |
| 61 appendChild(document.createTextNode(attrs.ip_address)); |
| 62 } else if (attrs.status == 'connecting') { |
| 63 label.appendChild(document.createElement('p')). |
| 64 appendChild(document.createTextNode(attrs.message)); |
| 65 } else { |
| 66 // error |
| 67 label.appendChild(document.createElement('p')). |
| 68 appendChild(document.createTextNode(attrs.message)); |
| 69 // TODO: error icon, reconnect button |
| 70 } |
| 71 // TODO: need_passphrase |
| 72 // TODO: remembered |
| 73 } else { |
| 74 label.textContent = attrs.label; |
| 75 } |
| 76 //////// End NetworkMenuItem specifi code |
| 77 |
| 78 if (attrs.font) { |
| 79 label.style.font = attrs.font; |
| 80 } |
| 81 this.appendChild(label); |
| 82 |
| 83 }, |
| 84 }; |
| 85 |
| 86 |
| 87 var NetworkMenu = cr.ui.define('div'); |
| 88 |
| 89 NetworkMenu.prototype = { |
| 90 __proto__: Menu.prototype, |
| 91 |
| 92 createMenuItem: function(attrs) { |
| 93 if (attrs.type == 'command') { |
| 94 return new NetworkMenuItem(); |
| 95 } else { |
| 96 return new MenuItem(); |
| 97 } |
| 98 }, |
| 99 }; |
OLD | NEW |