+ 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.transaction(function() {
+ 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()});
+ });
+ 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.transaction(function() {
+ node = insertion();
+ node.setAttr('href', event.formData.href);
+ event.success();
+ });
+ execCallback(node);
+ });
+ dialog.show();
+ } else {
+ doc.transaction(function() {
+ node = insertion();
+ });
+ execCallback(node);
+ }
+ };