Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(82)

Side by Side Diff: mojo/spy/ui/spy.js

Issue 281623007: Add mojo web UI framework based on Nat's TVCM (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: missed a few Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « mojo/spy/ui/spy.html ('k') | mojo/spy/ui/spy_project.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 'use strict';
6
7 tvcm.require('tvcm.utils');
8 tvcm.require('tvcm.ui');
9 tvcm.requireTemplate('ui.spy');
10
11 tvcm.exportTo('ui', function() {
12 /**
13 * @constructor
14 */
15 var LogMessage = tvcm.ui.define('x-spy-log-message');
16
17 LogMessage.prototype = {
18 __proto__: HTMLUnknownElement.prototype,
19
20 decorate: function() {
21 },
22
23 get message() {
24 return message_;
25 },
26
27 set message(message) {
28 this.message_ = message;
29 this.textContent = JSON.stringify(message);
30 }
31 };
32
33
34 /**
35 * @constructor
36 */
37 var Spy = tvcm.ui.define('x-spy');
38
39 Spy.prototype = {
40 __proto__: HTMLUnknownElement.prototype,
41
42 decorate: function() {
43 var node = tvcm.instantiateTemplate('#x-spy-template');
44 this.appendChild(node);
45
46 this.channel_ = undefined;
47 this.onMessage_ = this.onMessage_.bind(this);
48
49 var commandEl = this.querySelector('#command');
50 commandEl.addEventListener('keydown', function(e) {
51 if (e.keyCode == 13) {
52 e.stopPropagation();
53 this.onCommandEntered_();
54 }
55 }.bind(this));
56
57 this.updateDisabledStates_();
58 },
59
60 get channel() {
61 return channel_;
62 },
63
64 set channel(channel) {
65 if (this.channel_)
66 this.channel_.removeEventListener('message', this.onMessage_);
67 this.channel_ = channel;
68 if (this.channel_)
69 this.channel_.addEventListener('message', this.onMessage_);
70 this.updateDisabledStates_();
71 },
72
73 updateDisabledStates_: function() {
74 var connected = this.channel_ !== undefined;
75
76 this.querySelector('#command').disabled = !connected;
77 },
78
79 onCommandEntered_: function(cmd) {
80 var commandEl = this.querySelector('#command');
81 this.channel_.send(JSON.stringify(commandEl.value));
82 commandEl.value = '';
83 },
84
85 onMessage_: function(message) {
86 var messageEl = new LogMessage();
87 messageEl.message = message.data;
88 this.querySelector('messages').appendChild(messageEl);
89 }
90
91 };
92
93 return {
94 Spy: Spy
95 };
96 });
OLDNEW
« no previous file with comments | « mojo/spy/ui/spy.html ('k') | mojo/spy/ui/spy_project.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698