editor: block save button when there is nothing to save
[fnpeditor.git] / src / editor / plugins / core / core.js
1 define(function(require) {
2     
3 'use strict';
4
5 var _ = require('libs/underscore'),
6     plugin = {documentExtension: {textNode: {}}};
7
8
9 plugin.documentExtension.textNode.transformations = {
10     breakContent: {
11         impl: function(args) {
12             var node = this,
13                 newNodes, emptyText;
14             newNodes = node.split({offset: args.offset});
15             [newNodes.first, newNodes.second].some(function(newNode) {
16                 if(!(newNode.contents().length)) {
17                     emptyText = newNode.append({text: ''});
18                     return true; // break
19                 }
20             });
21             return _.extend(newNodes, {emptyText: emptyText});
22         },
23         getChangeRoot: function() {
24             return this.context.parent().parent();
25         }
26     },
27     mergeContentUp: function() {
28         var myPrev = this.prev(),
29             ret;
30
31         if(myPrev) {
32             ret = myPrev.append(this);
33             return {node: ret, offset: ret.sameNode(this) ? null : ret.getText().length - this.getText().length};
34         } else {
35             var range = this.parent().unwrapContent();
36             return {node: range.element1, offset: 0};
37         }
38     }
39 };
40
41 return plugin;
42
43 });