X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/c782c7a4d11b830dd1c6efed0b382e33b56a790b..b9715b04ece107e8febac4105c4720461cf66c9c:/src/smartxml/smartxml.js?ds=sidebyside diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index dcecc64..749d4f4 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -4,8 +4,9 @@ define([ 'libs/backbone', 'smartxml/events', 'smartxml/transformations', - 'smartxml/core' -], function($, _, Backbone, events, transformations, coreTransformations) { + 'smartxml/core', + 'smartxml/fragments' +], function($, _, Backbone, events, transformations, coreTransformations, fragments) { 'use strict'; /* globals Node */ @@ -78,6 +79,10 @@ $.extend(DocumentNode.prototype, { return this.document.root.sameNode(this); }, + isInDocument: function() { + return this.document.containsNode(this); + }, + isSiblingOf: function(node) { return node && this.parent().sameNode(node.parent()); }, @@ -117,10 +122,18 @@ $.extend(DocumentNode.prototype, { return myIdx < parentContents.length - 1 ? parentContents[myIdx+1] : null; }, - isSurroundedByTextElements: function() { - var prev = this.prev(), - next = this.next(); - return prev && (prev.nodeType === Node.TEXT_NODE) && next && (next.nodeType === Node.TEXT_NODE); + isSurroundedByTextNodes: function() { + return this.isPrecededByTextNode() && this.isFollowedByTextNode(); + }, + + isPrecededByTextNode: function() { + var prev = this.prev(); + return prev && prev.nodeType === Node.TEXT_NODE; + }, + + isFollowedByTextNode: function() { + var next = this.next(); + return next && next.nodeType === Node.TEXT_NODE; }, triggerChangeEvent: function(type, metaData, origParent, nodeWasContained) { @@ -218,6 +231,22 @@ $.extend(ElementNode.prototype, { return node && (node.nativeNode === this.nativeNode || node._$.parents().index(this._$) !== -1); }, + getLastTextNode: function() { + var contents = this.contents(), + toret; + + contents.reverse().some(function(node) { + if(node.nodeType === Node.TEXT_NODE) { + toret = node; + return true; + } + toret = node.getLastTextNode(); + return !!toret; + }); + + return toret; + }, + toXML: function() { var wrapper = $('