OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2014 The Native Client Authors. All rights reserved. | 2 * Copyright (c) 2014 The Native Client Authors. All rights reserved. |
3 * Use of this source code is governed by a BSD-style license that can be | 3 * Use of this source code is governed by a BSD-style license that can be |
4 * found in the LICENSE file. | 4 * found in the LICENSE file. |
5 */ | 5 */ |
6 | 6 |
| 7 'use strict'; |
| 8 |
7 /* | 9 /* |
8 * This plugin allows clients to include a DevEnvWidget in a web page, which | 10 * This plugin allows clients to include a DevEnvWidget in a web page, which |
9 * uses GCC in the NaCl Development Environment extension to compile and run | 11 * uses GCC in the NaCl Development Environment extension to compile and run |
10 * the contents of a text input. | 12 * the contents of a text input. |
11 * | 13 * |
12 * Example usage: | 14 * Example usage: |
13 * var widget = new DevEnvWidget({ | 15 * var widget = new DevEnvWidget({ |
14 * source: document.getElementById('source'), // <textarea> | 16 * source: document.getElementById('source'), // <textarea> |
15 * run: document.getElementById('run'), // <button> or other clickable | 17 * run: document.getElementById('run'), // <button> or other clickable |
16 * status: document.getElementById('status'), // <div> or other output area | 18 * status: document.getElementById('status'), // <div> or other output area |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 var handleMessage = function(response) { | 226 var handleMessage = function(response) { |
225 if (!response) { | 227 if (!response) { |
226 return; | 228 return; |
227 } else if (response.name === replyName) { | 229 } else if (response.name === replyName) { |
228 self.port.onMessage.removeListener(handleMessage); | 230 self.port.onMessage.removeListener(handleMessage); |
229 resolve(response); | 231 resolve(response); |
230 } else if (response.name === errorName) { | 232 } else if (response.name === errorName) { |
231 self.port.onMessage.removeListener(handleMessage); | 233 self.port.onMessage.removeListener(handleMessage); |
232 reject(new Error(response.error)); | 234 reject(new Error(response.error)); |
233 } | 235 } |
234 } | 236 }; |
235 self.port.postMessage(msg); | 237 self.port.postMessage(msg); |
236 self.port.onMessage.addListener(handleMessage); | 238 self.port.onMessage.addListener(handleMessage); |
237 }); | 239 }); |
238 }; | 240 }; |
239 | 241 |
240 // WidgetView controls the HTML elements that comprise the Widget. | 242 // WidgetView controls the HTML elements that comprise the Widget. |
241 function WidgetView(args) { | 243 function WidgetView(args) { |
242 this.source = args.source; | 244 this.source = args.source; |
243 this.run = args.run; | 245 this.run = args.run; |
244 this.status = args.status; | 246 this.status = args.status; |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 if (this.output) { | 330 if (this.output) { |
329 this.output.classList.remove(WidgetView.STATUS_CSS_NOERROR); | 331 this.output.classList.remove(WidgetView.STATUS_CSS_NOERROR); |
330 this.output.classList.remove(WidgetView.STATUS_CSS_ERROR); | 332 this.output.classList.remove(WidgetView.STATUS_CSS_ERROR); |
331 this.output.classList.add(view.cssClass); | 333 this.output.classList.add(view.cssClass); |
332 } | 334 } |
333 }; | 335 }; |
334 | 336 |
335 // Expose Widget to the outside. | 337 // Expose Widget to the outside. |
336 global['DevEnvWidget'] = Widget; | 338 global['DevEnvWidget'] = Widget; |
337 })(window); | 339 })(window); |
OLD | NEW |