editor: fix resolving cursor destination after breaking content at the edge of text...
[fnpeditor.git] / src / wlxml / wlxml.js
index 016f793..a320da3 100644 (file)
@@ -7,6 +7,8 @@ define([
     
 'use strict';
 
+/* globals Node */
+
 // utils
 
 var isMetaAttribute = function(attrName) {
@@ -29,7 +31,7 @@ var installObject = function(instance, klass) {
     _.keys(methods).concat(_.keys(transformations)).forEach(function(key) {
         instance.object[key] = _.bind(instance.object[key], instance);
     });
-}
+};
 
 var WLXMLElementNode = function(nativeNode, document) {
     smartxml.ElementNode.call(this, nativeNode, document);
@@ -42,7 +44,6 @@ $.extend(WLXMLElementNode.prototype, smartxml.ElementNode.prototype, {
         return this.getAttr('class') || '';
     },
     setClass: function(klass) {
-        var methods, object;
         if(klass !== this.klass) {
             installObject(this, klass);
             return this.setAttr('class', klass);
@@ -141,7 +142,7 @@ $.extend(WLXMLElementNode.prototype, smartxml.ElementNode.prototype, {
 
 var WLXMLDocumentNode = function() {
     smartxml.DocumentNode.apply(this, arguments);
-}
+};
 WLXMLDocumentNode.prototype = Object.create(smartxml.DocumentNode.prototype);
 
 var WLXMLDocument = function(xml, options) {
@@ -160,7 +161,11 @@ $.extend(WLXMLDocument.prototype, {
     ElementNodeFactory: WLXMLElementNode,
     loadXML: function(xml) {
         smartxml.Document.prototype.loadXML.call(this, xml, {silent: true});
-        $(this.dom).find(':not(iframe)').addBack().contents()
+        this.trigger('contentSet');
+    },
+
+    normalizeXML: function(nativeNode) {
+        $(nativeNode).find(':not(iframe)').addBack().contents()
             .filter(function() {return this.nodeType === Node.TEXT_NODE;})
             .each(function() {
                 var el = $(this),
@@ -239,10 +244,9 @@ $.extend(WLXMLDocument.prototype, {
                         }
                     //}
                 }
-
+                /* globals document */
                 el.replaceWith(document.createTextNode(text.transformed));
             });
-        this.trigger('contentSet');
     },
 
     registerClassTransformation: function(Transformation, className) {
@@ -250,7 +254,7 @@ $.extend(WLXMLDocument.prototype, {
         thisClassTransformations[Transformation.prototype.name] = function(args) {
             var nodeInstance = this;
             return nodeInstance.transform(Transformation, args);
-        }
+        };
     },
 
     registerClassMethod: function(methodName, method, className) {
@@ -277,7 +281,7 @@ $.extend(WLXMLDocument.prototype, {
                 var name = pair[0],
                     desc = pair[1];
                 doc.registerClassTransformation(transformations.createContextTransformation(desc, name), className);
-            }); 
+            });
         });
 
     }