From 058d6f3448085c6f1d513691f8f2d5a12ae1d10a Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Fri, 6 Dec 2013 12:38:25 +0100 Subject: [PATCH 1/1] wip: extracting core transformations continued - detfineDocumentProperties from core --- src/smartxml/core.js | 2 +- src/smartxml/smartxml.js | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/smartxml/core.js b/src/smartxml/core.js index b5f8c44..bab584e 100644 --- a/src/smartxml/core.js +++ b/src/smartxml/core.js @@ -95,7 +95,7 @@ var elementNodeTransformations = { node.setData(this.getData()); if(this.sameNode(this.document.root)) { - defineDocumentProperties(this.document, node._$); + this.document._defineDocumentProperties(node._$); } this._$.replaceWith(node._$); this._setNativeNode(node._$[0]); diff --git a/src/smartxml/smartxml.js b/src/smartxml/smartxml.js index d74ec13..2ed9c47 100644 --- a/src/smartxml/smartxml.js +++ b/src/smartxml/smartxml.js @@ -305,7 +305,7 @@ $.extend(Document.prototype, Backbone.Events, { loadXML: function(xml, options) { options = options || {}; - defineDocumentProperties(this, $(parseXML(xml))); + this._defineDocumentProperties($(parseXML(xml))); if(!options.silent) { this.trigger('contentSet'); } @@ -452,18 +452,19 @@ $.extend(Document.prototype, Backbone.Events, { toret = toret.contents()[idx]; }); return toret; + }, + + _defineDocumentProperties: function($document) { + var doc = this; + Object.defineProperty(doc, 'root', {get: function() { + return doc.createDocumentNode($document[0]); + }, configurable: true}); + Object.defineProperty(doc, 'dom', {get: function() { + return $document[0]; + }, configurable: true}); } }); -var defineDocumentProperties = function(doc, $document) { - Object.defineProperty(doc, 'root', {get: function() { - return doc.createDocumentNode($document[0]); - }, configurable: true}); - Object.defineProperty(doc, 'dom', {get: function() { - return $document[0]; - }, configurable: true}); -}; - return { documentFromXML: function(xml) { -- 2.20.1