X-Git-Url: https://git.mdrn.pl/fnpeditor.git/blobdiff_plain/58d1e96373dee3849af719bdedb3d57c51adc5c3..aa19ea0b08ad083be37ebc43aa9ba3f2bf63a043:/modules/documentCanvas/canvas/documentElement.js diff --git a/modules/documentCanvas/canvas/documentElement.js b/modules/documentCanvas/canvas/documentElement.js index d82f8e4..f2ef09c 100644 --- a/modules/documentCanvas/canvas/documentElement.js +++ b/modules/documentCanvas/canvas/documentElement.js @@ -1,6 +1,7 @@ define([ -'libs/jquery-1.9.1.min' -], function($) { +'libs/jquery-1.9.1.min', +'libs/underscore-min' +], function($, _) { 'use strict'; @@ -12,9 +13,8 @@ var DocumentElement = function(htmlElement, canvas) { this.canvas = canvas; this.$element = $(htmlElement); - var tagNameProp = this.$element.prop('tagName'); - this.wlxmlTag = tagNameProp ? tagNameProp.toLowerCase() : undefined; -}; + this.wlxmlTag = this.$element.attr('wlxml-tag'); +} $.extend(DocumentElement.prototype, { dom: function() { @@ -49,8 +49,10 @@ $.extend(DocumentElement.prototype, { }, wrapWithNodeElement: function(wlxmlNode) { - this.$element.wrap($('<' + wlxmlNode.tag + ' class="' + wlxmlNode.klass + '"">')[0]); - return documentElementFromHTMLElement(this.$element.parent().get(0), this.canvas); + var wrapper = DocumentNodeElement.create({tag: wlxmlNode.tag, klass: wlxmlNode.klass}); + this.$element.replaceWith(wrapper.dom()); + wrapper.append(this); + return wrapper; }, childIndex: function(child) { @@ -104,6 +106,29 @@ $.extend(DocumentNodeElement.prototype, { }, after: function(params) { manipulate(this, params, 'after'); + }, + getWlxmlTag: function() { + return this.$element.attr('wlxml-tag'); + }, + setWlxmlTag: function(tag) { + this.$element.attr('wlxml-tag', tag); + }, + getWlxmlClass: function() { + var klass = this.$element.attr('wlxml-class'); + if(klass) + return klass.replace('-', '.'); + return undefined; + }, + setWlxmlClass: function(klass) { + if(klass) + this.$element.attr('wlxml-class', klass); + else + this.$element.removeAttr('wlxml-class'); + }, + is: function(what) { + if(what === 'list' && _.contains(['list-items', 'list-items-enum'], this.$element.attr('wlxml-class'))) + return true; + return false; } }); @@ -112,9 +137,9 @@ DocumentNodeElement.createDOM = function(params) { if(params.text) { dom = $(document.createTextNode(params.text)); } else { - dom = $('<' + params.tag + '>'); + dom = $('
').attr('wlxml-tag', params.tag); if(params.klass) - dom.attr('class', params.klass); + dom.attr('wlxml-class', params.klass); } return dom; };