From edd85d12e3446e6d30ecb3b67519d53933a3b621 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Thu, 20 Jun 2013 11:08:48 +0200 Subject: [PATCH] canvas api wip: refactoring --- modules/documentCanvas/canvas.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/modules/documentCanvas/canvas.js b/modules/documentCanvas/canvas.js index 44f88a9..dc64cac 100644 --- a/modules/documentCanvas/canvas.js +++ b/modules/documentCanvas/canvas.js @@ -70,38 +70,38 @@ Canvas.prototype.insertNode = function(options) { Canvas.prototype.splitNode = function(options) { options = _.extend({textNodeIdx: 0}, options); - var element = $(this.content.find('#' + options.node.id).get(0)); + var nodeToSplit = $(this.content.find('#' + options.node.id).get(0)); - var elementContents = element.contents(); - if(elementContents.length === 0 || - elementContents.length - 1 < options.textNodeIdx || - elementContents.get(options.textNodeIdx).nodeType != 3) + var nodeContents = nodeToSplit.contents(); + if(nodeContents.length === 0 || + nodeContents.length - 1 < options.textNodeIdx || + nodeContents.get(options.textNodeIdx).nodeType != 3) return false; - var textElement = elementContents.get(options.textNodeIdx); + var textNode = $(nodeContents.get(options.textNodeIdx)); var succeedingNodes = []; var passed = false; - elementContents.each(function() { + nodeContents.each(function() { var node = this; if(passed) succeedingNodes.push(node); - if(node.isSameNode(textElement)) + if(node.isSameNode(textNode.get(0))) passed = true; }); - var prefix = textElement.data.substr(0, options.offset); - var suffix = textElement.data.substr(options.offset); + var prefix = textNode.text().substr(0, options.offset); + var suffix = textNode.text().substr(options.offset); - var $textElement = $(textElement); - $textElement.before(prefix); - $textElement.remove(); - var newNode = this._createNode(element.attr('wlxml-tag'), element.attr('wlxml-class')); + textNode.before(prefix); + textNode.remove(); + + var newNode = this._createNode(nodeToSplit.attr('wlxml-tag'), nodeToSplit.attr('wlxml-class')); newNode.append(suffix); succeedingNodes.forEach(function(node) { newNode.append(node) }); - element.after(newNode); + nodeToSplit.after(newNode); } Canvas.prototype.createList = function(options) { -- 2.20.1