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