Annotation of modules/damieng/graphical_editor/loncapa_daxe/web/loncapa_daxe.dart, revision 1.17
1.1 damieng 1: /*
2: This file is part of LON-CAPA.
3:
4: LON-CAPA is free software: you can redistribute it and/or modify
5: it under the terms of the GNU General Public License as published by
6: the Free Software Foundation, either version 3 of the License, or
7: (at your option) any later version.
8:
9: LON-CAPA is distributed in the hope that it will be useful,
10: but WITHOUT ANY WARRANTY; without even the implied warranty of
11: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: GNU General Public License for more details.
13:
14: You should have received a copy of the GNU General Public License
15: along with LON-CAPA. If not, see <http://www.gnu.org/licenses/>.
16: */
17:
18: library loncapa_daxe;
19:
20: import 'dart:async';
21: import 'dart:collection';
22: import 'dart:html' as h;
23: import 'package:daxe/daxe.dart';
24: import 'package:daxe/src/xmldom/xmldom.dart' as x;
25: import 'package:daxe/src/strings.dart';
1.14 damieng 26: import 'package:daxe/src/nodes/nodes.dart' show DNCData, DNText, SimpleTypeControl, ParentUpdatingDNText, DNHiddenP, DNString;
1.1 damieng 27: import 'dart:js' as js;
28:
29: import 'lcd_strings.dart';
30: part 'nodes/lcd_block.dart';
31: part 'nodes/lcd_parameter.dart';
32: part 'nodes/tex_mathjax.dart';
33: part 'nodes/lm.dart';
1.14 damieng 34: part 'nodes/chem.dart';
1.2 damieng 35: part 'nodes/numerical_response.dart';
1.3 damieng 36: part 'nodes/formula_response.dart';
37: part 'nodes/string_response.dart';
1.11 damieng 38: part 'nodes/essay_response.dart';
39: part 'nodes/textfield.dart';
1.1 damieng 40: part 'nodes/radio_response.dart';
41: part 'nodes/radio_foilgroup.dart';
42: part 'nodes/radio_foil.dart';
43: part 'nodes/option_response.dart';
44: part 'nodes/option_foilgroup.dart';
45: part 'nodes/option_foil.dart';
1.6 damieng 46: part 'nodes/match_response.dart';
47: part 'nodes/match_foilgroup.dart';
48: part 'nodes/match_foil.dart';
49: part 'nodes/itemgroup.dart';
50: part 'nodes/match_item.dart';
1.1 damieng 51: part 'nodes/rank_response.dart';
52: part 'nodes/rank_foilgroup.dart';
53: part 'nodes/rank_foil.dart';
1.10 damieng 54: part 'nodes/math_response.dart';
55: part 'nodes/math_answer.dart';
1.13 damieng 56: part 'nodes/organic_response.dart';
57: part 'nodes/jsme_dialog.dart';
58: part 'nodes/reaction_response.dart';
1.5 damieng 59: part 'nodes/textline.dart';
1.1 damieng 60: part 'nodes/hintgroup.dart';
61: part 'nodes/simple_ui_text.dart';
62: part 'nodes/script_block.dart';
1.2 damieng 63: part 'nodes/simple_ui_exception.dart';
1.7 damieng 64: part 'nodes/gnuplot.dart';
65: part 'nodes/fake_attribute_element.dart';
66: part 'nodes/plot_axis.dart';
67: part 'nodes/plot_curve.dart';
1.17 ! damieng 68: part 'nodes/section.dart';
! 69: part 'nodes/h1.dart';
1.1 damieng 70: part 'lcd_button.dart';
71:
72:
73: void main() {
74: NodeFactory.addCoreDisplayTypes();
75:
76: addDisplayType('lcdblock',
77: (x.Element ref) => new LCDBlock.fromRef(ref),
78: (x.Node node, DaxeNode parent) => new LCDBlock.fromNode(node, parent)
79: );
80:
81: addDisplayType('texmathjax',
82: (x.Element ref) => new TeXMathJax.fromRef(ref),
83: (x.Node node, DaxeNode parent) => new TeXMathJax.fromNode(node, parent)
84: );
85:
86: addDisplayType('lm',
87: (x.Element ref) => new Lm.fromRef(ref),
88: (x.Node node, DaxeNode parent) => new Lm.fromNode(node, parent)
89: );
90:
1.14 damieng 91: addDisplayType('chem',
92: (x.Element ref) => new Chem.fromRef(ref),
93: (x.Node node, DaxeNode parent) => new Chem.fromNode(node, parent)
94: );
95:
1.1 damieng 96: addDisplayType('script',
97: (x.Element ref) => new ScriptBlock.fromRef(ref),
98: (x.Node node, DaxeNode parent) => new ScriptBlock.fromNode(node, parent)
99: );
100:
101: addDisplayType('parameter',
102: (x.Element ref) => new LCDParameter.fromRef(ref),
103: (x.Node node, DaxeNode parent) => new LCDParameter.fromNode(node, parent)
104: );
105:
1.2 damieng 106: addDisplayType('numericalresponse',
107: (x.Element ref) => new NumericalResponse.fromRef(ref),
108: (x.Node node, DaxeNode parent) => new NumericalResponse.fromNode(node, parent)
109: );
110:
1.3 damieng 111: addDisplayType('formularesponse',
112: (x.Element ref) => new FormulaResponse.fromRef(ref),
113: (x.Node node, DaxeNode parent) => new FormulaResponse.fromNode(node, parent)
114: );
115:
116: addDisplayType('stringresponse',
117: (x.Element ref) => new StringResponse.fromRef(ref),
118: (x.Node node, DaxeNode parent) => new StringResponse.fromNode(node, parent)
119: );
120:
1.11 damieng 121: addDisplayType('essayresponse',
122: (x.Element ref) => new EssayResponse.fromRef(ref),
123: (x.Node node, DaxeNode parent) => new EssayResponse.fromNode(node, parent)
124: );
125:
1.1 damieng 126: addDisplayType('radioresponse',
127: (x.Element ref) => new RadioResponse.fromRef(ref),
128: (x.Node node, DaxeNode parent) => new RadioResponse.fromNode(node, parent)
129: );
130:
131: addDisplayType('optionresponse',
132: (x.Element ref) => new OptionResponse.fromRef(ref),
133: (x.Node node, DaxeNode parent) => new OptionResponse.fromNode(node, parent)
134: );
135:
1.6 damieng 136: addDisplayType('matchresponse',
137: (x.Element ref) => new MatchResponse.fromRef(ref),
138: (x.Node node, DaxeNode parent) => new MatchResponse.fromNode(node, parent)
139: );
140:
1.1 damieng 141: addDisplayType('rankresponse',
142: (x.Element ref) => new RankResponse.fromRef(ref),
143: (x.Node node, DaxeNode parent) => new RankResponse.fromNode(node, parent)
144: );
145:
1.10 damieng 146: addDisplayType('mathresponse',
147: (x.Element ref) => new MathResponse.fromRef(ref),
148: (x.Node node, DaxeNode parent) => new MathResponse.fromNode(node, parent)
149: );
150:
1.13 damieng 151: addDisplayType('organicresponse',
152: (x.Element ref) => new OrganicResponse.fromRef(ref),
153: (x.Node node, DaxeNode parent) => new OrganicResponse.fromNode(node, parent)
154: );
155:
156: addDisplayType('reactionresponse',
157: (x.Element ref) => new ReactionResponse.fromRef(ref),
158: (x.Node node, DaxeNode parent) => new ReactionResponse.fromNode(node, parent)
159: );
160:
1.1 damieng 161: addDisplayType('foilgroup',
162: (x.Element ref) {
163: if (ref.getAttribute('type') == 'radiobuttonresponse--foilgroup')
164: return new RadioFoilgroup.fromRef(ref);
165: else if (ref.getAttribute('type') == 'optionresponse--foilgroup')
166: return new OptionFoilgroup.fromRef(ref);
1.6 damieng 167: else if (ref.getAttribute('type') == 'matchresponse--foilgroup')
168: return new MatchFoilgroup.fromRef(ref);
1.1 damieng 169: else if (ref.getAttribute('type') == 'rankresponse--foilgroup')
170: return new RankFoilgroup.fromRef(ref);
171: return new LCDBlock.fromRef(ref);
172: },
173: (x.Node node, DaxeNode parent) {
174: if (parent is RadioResponse)
175: return new RadioFoilgroup.fromNode(node, parent);
176: else if (parent is OptionResponse)
177: return new OptionFoilgroup.fromNode(node, parent);
1.6 damieng 178: else if (parent is MatchResponse)
179: return new MatchFoilgroup.fromNode(node, parent);
1.1 damieng 180: else if (parent is RankResponse)
181: return new RankFoilgroup.fromNode(node, parent);
182: return new LCDBlock.fromNode(node, parent);
183: }
184: );
185:
186: addDisplayType('foil',
187: (x.Element ref) {
188: if (ref.getAttribute('type') == 'radiobuttonresponse--foil')
189: return new RadioFoil.fromRef(ref);
190: else if (ref.getAttribute('type') == 'optionresponse--foil')
191: return new OptionFoil.fromRef(ref);
1.6 damieng 192: else if (ref.getAttribute('type') == 'matchresponse--foil')
193: return new MatchFoil.fromRef(ref);
1.1 damieng 194: else if (ref.getAttribute('type') == 'rankresponse--foil')
195: return new RankFoil.fromRef(ref);
196: return new LCDBlock.fromRef(ref);
197: },
198: (x.Node node, DaxeNode parent) {
199: if (parent is RadioFoilgroup)
200: return new RadioFoil.fromNode(node, parent);
201: else if (parent is OptionFoilgroup)
202: return new OptionFoil.fromNode(node, parent);
1.6 damieng 203: else if (parent is MatchFoilgroup)
204: return new MatchFoil.fromNode(node, parent);
1.1 damieng 205: else if (parent is RankFoilgroup)
206: return new RankFoil.fromNode(node, parent);
207: return new LCDBlock.fromNode(node, parent);
208: }
209: );
210:
1.6 damieng 211: addDisplayType('itemgroup',
212: (x.Element ref) => new Itemgroup.fromRef(ref),
213: (x.Node node, DaxeNode parent) => new Itemgroup.fromNode(node, parent)
214: );
215:
216: addDisplayType('matchitem',
217: (x.Element ref) => new MatchItem.fromRef(ref),
218: (x.Node node, DaxeNode parent) => new MatchItem.fromNode(node, parent)
219: );
220:
1.5 damieng 221: addDisplayType('textline',
222: (x.Element ref) => new Textline.fromRef(ref),
223: (x.Node node, DaxeNode parent) => new Textline.fromNode(node, parent)
224: );
225:
1.11 damieng 226: addDisplayType('textfield',
227: (x.Element ref) => new Textfield.fromRef(ref),
228: (x.Node node, DaxeNode parent) => new Textfield.fromNode(node, parent)
229: );
230:
1.1 damieng 231: addDisplayType('hintgroup',
232: (x.Element ref) => new Hintgroup.fromRef(ref),
233: (x.Node node, DaxeNode parent) => new Hintgroup.fromNode(node, parent)
234: );
235:
1.10 damieng 236: addDisplayType('answer',
237: (x.Element ref) {
238: if (ref.getAttribute('type') == 'mathresponse--answer')
239: return new MathAnswer.fromRef(ref);
240: return new LCDBlock.fromRef(ref);
241: },
242: (x.Node node, DaxeNode parent) {
243: if (parent is MathResponse)
244: return new MathAnswer.fromNode(node, parent);
245: return new LCDBlock.fromNode(node, parent);
246: }
247: );
248:
1.7 damieng 249: addDisplayType('gnuplot',
250: (x.Element ref) => new Gnuplot.fromRef(ref),
251: (x.Node node, DaxeNode parent) => new Gnuplot.fromNode(node, parent)
252: );
253:
254: addDisplayType('fakeattribute',
255: (x.Element ref) {
256: if (doc.cfg.elementName(ref) != 'title' || ref.getAttribute('type') == 'lonplot--title')
257: return new FakeAttributeElement.fromRef(ref);
258: return new LCDBlock.fromRef(ref);
259: },
260: (x.Node node, DaxeNode parent) {
261: if (parent is Gnuplot || parent is PlotCurve)
262: return new FakeAttributeElement.fromNode(node, parent);
263: return new LCDBlock.fromNode(node, parent);
264: }
265: );
266:
267: addDisplayType('plotaxis',
268: (x.Element ref) => new PlotAxis.fromRef(ref),
269: (x.Node node, DaxeNode parent) => new PlotAxis.fromNode(node, parent)
270: );
271:
272: addDisplayType('plotcurve',
273: (x.Element ref) => new PlotCurve.fromRef(ref),
274: (x.Node node, DaxeNode parent) => new PlotCurve.fromNode(node, parent)
275: );
276:
1.17 ! damieng 277: addDisplayType('section',
! 278: (x.Element ref) => new Section.fromRef(ref),
! 279: (x.Node node, DaxeNode parent) => new Section.fromNode(node, parent)
! 280: );
! 281:
! 282: addDisplayType('h1',
! 283: (x.Element ref) => new H1.fromRef(ref),
! 284: (x.Node node, DaxeNode parent) => new H1.fromNode(node, parent)
! 285: );
! 286:
1.1 damieng 287: Future.wait([Strings.load(), LCDStrings.load(), _readTemplates('templates.xml')]).then((List responses) {
1.16 damieng 288: initDaxe().then((v) {
1.1 damieng 289: // add things to the toolbar
290: ToolbarMenu sectionMenu = _makeSectionMenu();
291: if (sectionMenu != null)
292: page.toolbar.add(sectionMenu);
293: x.Element texRef = doc.cfg.elementReference('m');
294: if (texRef != null) {
295: ToolbarBox insertBox = new ToolbarBox();
296: ToolbarButton texButton = new ToolbarButton(
297: LCDStrings.get('tex_equation'), 'images/tex.png',
298: () => doc.insertNewNode(texRef, 'element'), Toolbar.insertButtonUpdate,
299: data:new ToolbarStyleInfo([texRef], null, null));
300: insertBox.add(texButton);
301: page.toolbar.add(insertBox);
302: }
303: h.Element tbh = h.querySelector('.toolbar');
304: tbh.replaceWith(page.toolbar.html());
305: page.adjustPositionsUnderToolbar();
306: page.updateAfterPathChange();
307: // add things to the menubar
308: if (responses[2] is x.Document) {
309: // at this point the menubar html is already in the document, so we have to fix the HTML
310: h.Element menubarDiv = h.document.getElementsByClassName('menubar')[0];
1.4 damieng 311: if (doc.filePath != null && doc.filePath.indexOf('&url=') != -1) { // otherwise we are not on LON-CAPA
1.1 damieng 312: MenuItem item = new MenuItem(Strings.get('menu.save'), () => save(), shortcut: 'S');
313: Menu fileMenu = page.mbar.menus[0];
314: fileMenu.add(item);
315: menubarDiv.firstChild.replaceWith(page.mbar.createMenuDiv(fileMenu));
316: }
317: Menu m = _makeTemplatesMenu(responses[2]);
318: page.mbar.add(m);
319: menubarDiv.append(page.mbar.createMenuDiv(m));
320: page.updateAfterPathChange();
321: } else
322: print("Error reading templates file, could not build the menu.");
1.15 damieng 323: }).catchError((e) {
324: h.document.body.appendText('Initialization error: ' + e);
1.1 damieng 325: });
1.15 damieng 326: }).catchError((e) {
327: h.document.body.appendText('Initialization error: ' + e);
1.1 damieng 328: });
329: }
330:
331: void save() {
332: saveOnLONCAPA().then((_) {
333: h.window.alert(Strings.get('save.success'));
334: }, onError: (DaxeException ex) {
335: h.window.alert(Strings.get('save.error') + ': ' + ex.message);
336: });
337: }
338:
339: /**
340: * Send the document with a POST request to LON-CAPA.
341: */
342: Future saveOnLONCAPA() {
343: int ind = doc.filePath.indexOf('&url=');
344: if (ind == -1)
345: return(new Future.error(new DaxeException('bad URL')));
346: String path = doc.filePath.substring(ind+5);
347: path = Uri.decodeQueryComponent(path);
348: ind = path.lastIndexOf('/');
349: String filename;
350: if (ind == -1)
351: filename = path;
352: else {
353: filename = path.substring(ind+1);
354: path = path.substring(0, ind+1);
355: }
356: Completer completer = new Completer();
357: String bound = 'AaB03x';
358: h.HttpRequest request = new h.HttpRequest();
359: request.onLoad.listen((h.ProgressEvent event) {
360: completer.complete(); // TODO: check for something, status is sometimes wrongly OK
361: });
362: request.onError.listen((h.ProgressEvent event) {
363: completer.completeError(new DaxeException(request.status.toString()));
364: });
365: request.open('POST', '/upload_file');
366: request.setRequestHeader('Content-Type', "multipart/form-data; boundary=$bound");
367:
368: StringBuffer sb = new StringBuffer();
369: sb.write("--$bound\r\n");
370: sb.write('Content-Disposition: form-data; name="uploads_path"\r\n');
371: sb.write('Content-type: text/plain; charset=UTF-8\r\n');
372: sb.write('Content-transfer-encoding: 8bit\r\n\r\n');
373: sb.write(path);
374: sb.write("\r\n--$bound\r\n");
375: sb.write('Content-Disposition: form-data; name="uploads"; filename="$filename"\r\n');
376: sb.write('Content-Type: application/octet-stream\r\n\r\n');
377: doc.dndoc.xmlEncoding = 'UTF-8'; // the document is forced to use UTF-8
378: sb.write(doc.toString());
379: sb.write('\r\n--$bound--\r\n\r\n');
380: request.send(sb.toString());
381: return(completer.future);
382: }
383:
384: ToolbarMenu _makeSectionMenu() {
385: Menu menu = new Menu(LCDStrings.get('Section'));
386: List<x.Element> sectionRefs = doc.cfg.elementReferences('section');
387: if (sectionRefs == null || sectionRefs.length == 0)
388: return(null);
389: x.Element h1Ref = doc.cfg.elementReference('h1');
1.17 ! damieng 390: for (String role in ['activity', 'advice', 'bibliography', 'citation',
! 391: 'conclusion', 'definition', 'demonstration', 'example',
! 392: 'explanation', 'introduction', 'method', 'more_information',
! 393: 'objectives', 'prerequisites', 'remark', 'reminder',
! 394: 'summary', 'syntax', 'warning']) {
1.1 damieng 395: MenuItem menuItem = new MenuItem(LCDStrings.get(role), null,
396: data:new ToolbarStyleInfo(sectionRefs, null, null));
397: menuItem.action = () {
398: ToolbarStyleInfo info = menuItem.data;
399: x.Element sectionRef = info.validRef;
1.17 ! damieng 400: Section section = NodeFactory.create(sectionRef);
1.1 damieng 401: section.state = 1;
402: section.setAttribute('class', 'role-' + role);
1.17 ! damieng 403: H1 h1 = NodeFactory.create(h1Ref);
1.1 damieng 404: h1.state = 1;
1.9 damieng 405: section.appendChild(h1);
406: x.Element hiddenp = doc.cfg.findSubElement(sectionRef, doc.hiddenParaRefs);
407: DNHiddenP p = NodeFactory.create(hiddenp);
408: section.appendChild(p);
1.17 ! damieng 409: section.setupSimpleUI();
1.1 damieng 410: if (doc.insert2(section, page.getSelectionStart())) {
411: page.cursor.moveTo(new Position(h1, 0));
412: page.updateAfterPathChange();
413: }
414: };
415: menu.add(menuItem);
416: }
417: ToolbarMenu tbmenu = new ToolbarMenu(menu, Toolbar.insertMenuUpdate, page.toolbar);
418: return(tbmenu);
419: }
420:
421: Future<x.Document> _readTemplates(String templatesPath) {
422: x.DOMParser dp = new x.DOMParser();
423: return(dp.parseFromURL(templatesPath));
424: }
425:
426: Menu _makeTemplatesMenu(x.Document templatesDoc) {
427: Menu menu = new Menu(LCDStrings.get('Templates'));
428: x.Element templates = templatesDoc.documentElement;
429: for (x.Node child in templates.childNodes) {
430: if (child.nodeType == x.Node.ELEMENT_NODE && child.nodeName == 'menu') {
431: menu.add(_makeMenu(child));
432: }
433: }
434: return(menu);
435: }
436:
437: Menu _makeMenu(x.Element el) {
438: String locale = LCDStrings.systemLocale;
439: String defaultLocale = LCDStrings.defaultLocale;
440: String title;
441: for (x.Node child in el.childNodes) {
442: if (child.nodeType == x.Node.ELEMENT_NODE && child.nodeName == 'title') {
443: if (child.firstChild != null && child.firstChild.nodeType == x.Node.TEXT_NODE) {
444: if ((child as x.Element).getAttribute('lang') == locale) {
445: title = child.firstChild.nodeValue;
446: break;
447: } else if ((child as x.Element).getAttribute('lang') == defaultLocale) {
448: title = child.firstChild.nodeValue;
449: }
450: }
451: }
452: }
453: if (title == null)
454: title = '?';
455: Menu menu = new Menu(title);
456: for (x.Node child in el.childNodes) {
457: if (child.nodeType == x.Node.ELEMENT_NODE) {
458: if (child.nodeName == 'menu') {
459: menu.add(_makeMenu(child));
460: } else if (child.nodeName == 'item') {
461: menu.add(_makeItem(child));
462: }
463: }
464: }
465: return(menu);
466: }
467:
468: MenuItem _makeItem(x.Element item) {
469: String locale = LCDStrings.systemLocale;
470: String defaultLocale = LCDStrings.defaultLocale;
471: String path, type, title, help;
472: for (x.Node child in item.childNodes) {
473: if (child.nodeType == x.Node.ELEMENT_NODE) {
474: if (child.nodeName == 'title') {
475: if (child.firstChild != null && child.firstChild.nodeType == x.Node.TEXT_NODE) {
476: if ((child as x.Element).getAttribute('lang') == locale) {
477: title = child.firstChild.nodeValue;
478: } else if (title == null && (child as x.Element).getAttribute('lang') == defaultLocale) {
479: title = child.firstChild.nodeValue;
480: }
481: }
482: } else if (child.nodeName == 'path' && child.firstChild != null && child.firstChild.nodeType == x.Node.TEXT_NODE) {
483: path = child.firstChild.nodeValue;
484: } else if (child.nodeName == 'type' && child.firstChild != null && child.firstChild.nodeType == x.Node.TEXT_NODE) {
485: type = child.firstChild.nodeValue;
486: } else if (child.nodeName == 'help') {
487: if (child.firstChild != null && child.firstChild.nodeType == x.Node.TEXT_NODE) {
488: if ((child as x.Element).getAttribute('lang') == locale) {
489: help = child.firstChild.nodeValue;
490: } else if (help == null && (child as x.Element).getAttribute('lang') == defaultLocale) {
491: help = child.firstChild.nodeValue;
492: }
493: }
494: }
495: }
496: }
497: if (type == null) {
498: print("Warning: missing type for template $title\n");
499: type = 'problem';
500: }
501: x.Element refElement = doc.cfg.elementReference(type);
502: MenuItem menuItem = new MenuItem(title, () => _insertTemplate(path), data: refElement);
503: if (help != null)
504: menuItem.toolTipText = help;
505: return menuItem;
506: }
507:
508: void _insertTemplate(String filePath) {
509: try {
510: x.DOMParser dp = new x.DOMParser();
511: dp.parseFromURL(filePath).then((x.Document templateDoc) {
512: x.Element root = templateDoc.documentElement;
513: if (root == null)
514: return;
515: doc.removeWhitespace(root);
516: DaxeNode dnRoot = NodeFactory.createFromNode(root, null);
517: UndoableEdit edit;
518: Position pos = page.getSelectionStart();
519: if (dnRoot.nodeName == 'loncapa' && doc.getRootElement() != null)
520: edit = doc.insertChildrenEdit(dnRoot, pos, checkValidity:true);
1.12 damieng 521: else {
522: DaxeNode parent = pos.dn;
523: if (parent is DNText)
524: parent = parent.parent;
525: if (parent is DNHiddenP && !doc.cfg.isSubElement(parent.ref, dnRoot.ref)) {
526: // The node must be inserted outside of the paragraph.
527: // If there is something in the paragraph to the right of the cursor, it must be
528: // moved into a new paragraph after the inserted node.
529: // (as in DaxeDocument.insert2)
530: DNHiddenP p = parent;
531: edit = new UndoableEdit.compound(Strings.get('undo.insert_element'));
532: Position pend = new Position(p, p.offsetLength);
533: pend.moveInsideTextNodeIfPossible();
534: if (pos < pend) {
535: DaxeNode clone = doc.cloneBetween(pos, pend);
536: edit.addSubEdit(doc.removeBetweenEdit(pos, pend));
537: DNHiddenP newp = NodeFactory.create(p.ref);
538: edit.addSubEdit(new UndoableEdit.insertNode(
539: new Position(p.parent, p.parent.offsetOf(p) + 1), newp));
540: edit.addSubEdit(doc.insertChildrenEdit(clone, new Position(newp, 0)));
541: }
542: edit.addSubEdit(new UndoableEdit.insertNode(
543: new Position(p.parent, p.parent.offsetOf(p)+1), dnRoot));
544: } else
545: edit = new UndoableEdit.insertNode(pos, dnRoot);
546: }
1.1 damieng 547: doc.doNewEdit(edit);
548: page.updateAfterPathChange();
1.8 damieng 549: if (dnRoot.nodeName != 'loncapa')
550: page.scrollToNode(dnRoot);
1.1 damieng 551: });
552: } on x.DOMException catch(ex) {
553: h.window.alert(ex.toString());
554: }
555: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>