+ wlxmlNode, caretTo, wrapperCanvasElement;
+
+ var insertNode = function(insertion, callback) {
+ var doc = canvas.wlxmlDocument,
+ node, metadata, creator, dialog;
+
+ var execCallback = function(node) {
+ if(callback) {
+ callback(node);
+ }
+ };
+
+ if(params.wlxmlTag === 'aside' && params.wlxmlClass === 'comment') {
+ doc.startTransaction();
+ node = insertion();
+ if(user) {
+ creator = user.name;
+ if(user.email) {
+ creator += ' (' + user.email + ')';
+ }
+ } else {
+ creator = 'anonymous';
+ }
+
+ metadata = node.getMetadata();
+ metadata.add({key: 'creator', value: creator});
+ metadata.add({key: 'date', value: datetime.currentStrfmt()});
+ doc.endTransaction();
+ execCallback(node);
+ } else if(params.wlxmlClass === 'link') {
+ dialog = Dialog.create({
+ title: gettext('Create link'),
+ executeButtonText: gettext('Apply'),
+ cancelButtonText: gettext('Cancel'),
+ fields: [
+ {label: gettext('Link'), name: 'href', type: 'input'}
+ ]
+ });
+ dialog.on('execute', function(event) {
+ doc.startTransaction();
+ node = insertion();
+ node.setAttr('href', event.formData.href);
+ doc.endTransaction();
+ event.success();
+ execCallback(node);
+ });
+ dialog.show();
+ } else {
+ doc.startTransaction();
+ node = insertion();
+ doc.endTransaction();
+ execCallback(node);
+ }
+ };