+ wlxmlNode, caretTo, wrapperCanvasElement;
+
+ var insertNode = function(insertion, callback) {
+ var doc = canvas.wlxmlDocument,
+ metadata, creator, dialog;
+
+ var execCallback = function(node) {
+ if(callback) {
+ callback(node);
+ }
+ };
+
+ if(params.wlxmlTag === 'aside' && params.wlxmlClass === 'comment') {
+ doc.transaction(function() {
+ var 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()});
+ return node;
+ }, {
+ success: execCallback
+ });
+ } 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() {
+ var node = insertion();
+ node.setAttr('href', event.formData.href);
+ event.success();
+ return node;
+ }, {
+ success: execCallback
+ });
+ });
+ dialog.show();
+ } else {
+ doc.transaction(function() {
+ return insertion();
+ }, {success: execCallback});
+ }
+ };