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

Side by Side Diff: samples/pond/editors.js

Issue 10204007: Remove many things that depend on frog. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « samples/pond/editors.dart ('k') | samples/pond/editors_stub.dart » ('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 (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4
5 var ERROR_KIND = 1;
6 var WARNING_KIND = 2;
7 var ERROR_CLASSNAME = "compile_error";
8 var WARNING_CLASSNAME = "compile_warning";
9
10 var editors = {};
11 var markers = [];
12
13 function newEditor(id, type, listener) {
14 editors[id] = CodeMirror(document.getElementById(id), {
15 mode: type,
16 tabSize: 2,
17 lineNumbers: true,
18 gutter: true,
19 onChange: listener
20 });
21 }
22
23 function changeListener(id) {
24 return function(editor, textChanges) {
25 window.postMessage(['js-to-dart', 'update', id], '*');
26 }
27 }
28
29 function newMark(editorId, startLine, startCol, endLine, endCol, kind) {
30 var className = "";
31 if (kind == ERROR_KIND) {
32 className = ERROR_CLASSNAME;
33 } else if (kind == WARNING_KIND) {
34 className = WARNING_CLASSNAME;
35 }
36 var marker = editors[editorId].markText(
37 {line: startLine, ch: startCol}, {line: endLine, ch: endCol}, className);
38 var markerId = markers.length;
39 markers.push(marker);
40 return markerId;
41 }
42
43 function messageDispatcher(envelope) {
44 if (envelope[0] != 'dart-to-js') return;
45 var returnId = envelope[1];
46 var message = envelope[2];
47 var command = message[0];
48 var args = message[1];
49 var reply = null;
50 switch (command) {
51 case "newEditor":
52 newEditor(args[0], args[1], (args[2] ? changeListener(args[0]): null));
53 break;
54 case "getText":
55 reply = editors[args[0]].getValue();
56 break;
57 case "setText":
58 editors[args[0]].setValue(args[1]);
59 break;
60 case "refresh":
61 editors[args[0]].showLine(0);
62 break;
63 case "mark":
64 var reply = newMark(
65 args[0], // editor
66 args[1], args[2], // start line & column
67 args[3], args[4], // end line & column
68 args[5]); // kind
69 break;
70 case "clearMark":
71 markers[args[0]].clear();
72 break;
73 }
74 window.postMessage(['js-to-dart-reply', returnId, reply], '*');
75 }
76
77 window.addEventListener('message',
78 function (e) { messageDispatcher(e.data); }, false);
OLDNEW
« no previous file with comments | « samples/pond/editors.dart ('k') | samples/pond/editors_stub.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698