From d85313d7ac6ab318a237df3987ea92f0e42d41c7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Aleksander=20=C5=81ukasz?= Date: Wed, 17 Apr 2013 10:31:39 +0200 Subject: [PATCH] Visual Editor: Moving wlxml information to its own attribute --- editor.css | 6 +++--- modules/visualEditor.js | 11 ++++++----- modules/visualEditor.transformations.js | 6 +++--- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/editor.css b/editor.css index 667db19..a6691f2 100644 --- a/editor.css +++ b/editor.css @@ -65,20 +65,20 @@ body { height: 500px; } -.rng { +[wlxml-tag] { float: none !important; /* temporaty workaround for Bootstrap's influence via [class*="span"] { float: left; } */ border-color: white; border-style:solid; border-width:1px; } -.rng-header { +[wlxml-tag=header] { font-size: 19px; font-style: bold; margin-bottom: 10px; } -.rng-section { +[wlxml-tag=section] { margin-top: 10px; margin-bottom: 10px; } diff --git a/modules/visualEditor.js b/modules/visualEditor.js index 38f3302..132c70f 100644 --- a/modules/visualEditor.js +++ b/modules/visualEditor.js @@ -14,9 +14,10 @@ rng.modules.visualEditor = function(sandbox) { isDirty = true; }); - this.node.on('mouseover', '.rng', function(e) { $(e.target).addClass('rng-hover')}); - this.node.on('mouseout', '.rng', function(e) { $(e.target).removeClass('rng-hover')}); - this.node.on('click', '.rng', function(e) { + this.node.on('mouseover', '[wlxml-tag]', function(e) { $(e.target).addClass('rng-hover')}); + this.node.on('mouseout', '[wlxml-tag]', function(e) { $(e.target).removeClass('rng-hover')}); + this.node.on('click', '[wlxml-tag]', function(e) { + console.log('clicked node type: '+e.target.nodeType); view._markSelected($(e.target)); }); @@ -24,7 +25,7 @@ rng.modules.visualEditor = function(sandbox) { var anchor = $(window.getSelection().anchorNode); if(anchor[0].nodeType === Node.TEXT_NODE) anchor = anchor.parent(); - if(!anchor.hasClass('rng')) + if(!anchor.is('[wlxml-tag]')) return; view._markSelected(anchor); }); @@ -54,7 +55,7 @@ rng.modules.visualEditor = function(sandbox) { return this.node.find('#rng-visualEditor-content').html(); }, _markSelected: function(node) { - this.node.find('.rng').removeClass('rng-current'); + this.node.find('.rng-current').removeClass('rng-current'); node.addClass('rng-current'); } }; diff --git a/modules/visualEditor.transformations.js b/modules/visualEditor.transformations.js index cfb5877..c2b0d3a 100644 --- a/modules/visualEditor.transformations.js +++ b/modules/visualEditor.transformations.js @@ -21,7 +21,7 @@ if(typeof module !== 'undefined' && module.exports) { console.log('running ' + tagName); toret.find(tagName).replaceWith(function() { var suffix = tagName !== 'div' ? tagName : 'block'; - return $('
').addClass('rng rng-' + suffix).append($(this).contents()); + return $('
').attr('wlxml-tag', suffix).append($(this).contents()); }); }); @@ -29,7 +29,7 @@ if(typeof module !== 'undefined' && module.exports) { tagName = tagName.toLowerCase(); toret.find(tagName).replaceWith(function() { var node = this; - return $('').addClass('rng rng-' + tagName).append($(this).contents()); + return $('').attr('wlxml-tag', tagName).append($(this).contents()); }); }); return toret.children(); @@ -59,7 +59,7 @@ if(typeof module !== 'undefined' && module.exports) { toret.find('div, span').replaceWith(function() { var div = $(this); - var tagName = div.attr('class').split('rng-')[1]; + var tagName = div.attr('wlxml-tag'); return $('<'+tagName+'>').append(div.contents()); }); -- 2.20.1