From: Aleksander Ɓukasz Date: Sun, 8 Dec 2013 22:34:49 +0000 (+0100) Subject: Linting, cleanup, removing unused code X-Git-Url: https://git.mdrn.pl/fnpeditor.git/commitdiff_plain/5c9d3612ac44a2da2624a911c97a4aa563679fed Linting, cleanup, removing unused code --- diff --git a/Gruntfile.js b/Gruntfile.js index 55ee1c8..4d929f6 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,4 +1,7 @@ +/* global module */ + module.exports = function(grunt) { + 'use strict'; grunt.initConfig({ requirejs: { diff --git a/src/editor/modules/documentCanvas/canvas/canvas.js b/src/editor/modules/documentCanvas/canvas/canvas.js index 752b947..6a60f80 100644 --- a/src/editor/modules/documentCanvas/canvas/canvas.js +++ b/src/editor/modules/documentCanvas/canvas/canvas.js @@ -9,30 +9,31 @@ define([ ], function($, _, Backbone, documentElement, keyboard, utils, wlxmlListener) { 'use strict'; +/* global document:false, window:false */ -var TextHandler = function(canvas) {this.canvas = canvas; this.buffer = null}; + +var TextHandler = function(canvas) {this.canvas = canvas; this.buffer = null;}; $.extend(TextHandler.prototype, { handle: function(node, text) { - //console.log('canvas text handler: ' + text); this.setText(text, node); - return; - if(!this.node) { - this.node = node; - } - if(this.node.sameNode(node)) { - this._ping(text); - } else { - this.flush(); - this.node = node; - this._ping(text); - } + // return; + // if(!this.node) { + // this.node = node; + // } + // if(this.node.sameNode(node)) { + // this._ping(text); + // } else { + // this.flush(); + // this.node = node; + // this._ping(text); + // } }, _ping: _.throttle(function(text) { this.buffer = text; this.flush(); }, 1000), flush: function() { - if(this.buffer != null) { + if(this.buffer !== null) { this.setText(this.buffer, this.node); this.buffer = null; } @@ -94,13 +95,14 @@ $.extend(Canvas.prototype, { }); - + /* globals MutationObserver */ var observer = new MutationObserver(function(mutations) { mutations.forEach(function(mutation) { if(documentElement.DocumentTextElement.isContentContainer(mutation.target)) { observer.disconnect(); - if(mutation.target.data === '') + if(mutation.target.data === '') { mutation.target.data = utils.unicode.ZWS; + } else if(mutation.oldValue === utils.unicode.ZWS) { mutation.target.data = mutation.target.data.replace(utils.unicode.ZWS, ''); canvas._moveCaretToTextElement(canvas.getDocumentElement(mutation.target), 'end'); @@ -113,7 +115,7 @@ $.extend(Canvas.prototype, { //textElement.data('wlxmlNode').setText(toSet); //textElement.data('wlxmlNode').document.transform('setText', {node: textElement.data('wlxmlNode'), text: toSet}); - if(textElement.data('wlxmlNode').getText() != toSet) { + if(textElement.data('wlxmlNode').getText() !== toSet) { canvas.textHandler.handle(textElement.data('wlxmlNode'), toSet); } } @@ -125,20 +127,24 @@ $.extend(Canvas.prototype, { this.wrapper.on('mouseover', '[document-node-element], [document-text-element]', function(e) { var el = canvas.getDocumentElement(e.currentTarget); - if(!el) + if(!el) { return; + } e.stopPropagation(); - if(el instanceof documentElement.DocumentTextElement) + if(el instanceof documentElement.DocumentTextElement) { el = el.parent(); + } el.toggleLabel(true); }); this.wrapper.on('mouseout', '[document-node-element], [document-text-element]', function(e) { var el = canvas.getDocumentElement(e.currentTarget); - if(!el) + if(!el) { return; + } e.stopPropagation(); - if(el instanceof documentElement.DocumentTextElement) + if(el instanceof documentElement.DocumentTextElement) { el = el.parent(); + } el.toggleLabel(false); }); @@ -154,8 +160,9 @@ $.extend(Canvas.prototype, { }, doc: function() { - if(this.d === null) + if(this.d === null) { return null; + } return documentElement.DocumentNodeElement.fromHTMLElement(this.d.get(0), this); //{wlxmlTag: this.d.prop('tagName')}; }, @@ -169,6 +176,7 @@ $.extend(Canvas.prototype, { }, getDocumentElement: function(from) { + /* globals HTMLElement, Text */ if(from instanceof HTMLElement || from instanceof Text) { return documentElement.DocumentElement.fromHTMLElement(from, this); } @@ -196,12 +204,14 @@ $.extend(Canvas.prototype, { params = _.extend({caretTo: 'end'}, params); var findFirstDirectTextChild = function(e, nodeToLand) { var byBrowser = this.getCursor().getPosition().element; - if(byBrowser && byBrowser.parent().sameNode(nodeToLand)) + if(byBrowser && byBrowser.parent().sameNode(nodeToLand)) { return byBrowser; + } var children = e.children(); for(var i = 0; i < children.length; i++) { - if(children[i] instanceof documentElement.DocumentTextElement) + if(children[i] instanceof documentElement.DocumentTextElement) { return children[i]; + } } return null; }.bind(this); @@ -210,7 +220,7 @@ $.extend(Canvas.prototype, { this.wrapper.find('.current-text-element').removeClass('current-text-element'); element.dom().addClass('current-text-element'); } else { - this.wrapper.find('.current-node-element').removeClass('current-node-element') + this.wrapper.find('.current-node-element').removeClass('current-node-element'); element._container().addClass('current-node-element'); this.publisher('currentElementChanged', element); } @@ -223,15 +233,18 @@ $.extend(Canvas.prototype, { currentTextElement = this.getCurrentTextElement(), currentNodeElement = this.getCurrentNodeElement(); - if(currentTextElement && !(currentTextElement.sameNode(textElementToLand))) + if(currentTextElement && !(currentTextElement.sameNode(textElementToLand))) { this.wrapper.find('.current-text-element').removeClass('current-text-element'); + } if(textElementToLand) { _markAsCurrent(textElementToLand); - if(params.caretTo || !textElementToLand.sameNode(this.getCursor().getPosition().element)) + if(params.caretTo || !textElementToLand.sameNode(this.getCursor().getPosition().element)) { this._moveCaretToTextElement(textElementToLand, params.caretTo); // as method on element? - if(!(textElementToLand.sameNode(currentTextElement))) + } + if(!(textElementToLand.sameNode(currentTextElement))) { this.publisher('currentTextElementSet', textElementToLand.data('wlxmlNode')); + } } else { document.getSelection().removeAllRanges(); } @@ -254,8 +267,9 @@ $.extend(Canvas.prototype, { } var collapseArg = true; - if(where === 'end') + if(where === 'end') { collapseArg = false; + } range.collapse(collapseArg); var selection = document.getSelection(); @@ -266,8 +280,9 @@ $.extend(Canvas.prototype, { }, setCursorPosition: function(position) { - if(position.element) + if(position.element) { this._moveCaretToTextElement(position.element, position.offset); + } } }); @@ -303,12 +318,14 @@ $.extend(Cursor.prototype, { return this.getSelectionBoundry('focus'); }, getSelectionBoundry: function(which) { + /* globals window */ var selection = window.getSelection(), anchorElement = this.canvas.getDocumentElement(selection.anchorNode), focusElement = this.canvas.getDocumentElement(selection.focusNode); - if((!anchorElement) || (anchorElement instanceof documentElement.DocumentNodeElement) || (!focusElement) || focusElement instanceof documentElement.DocumentNodeElement) + if((!anchorElement) || (anchorElement instanceof documentElement.DocumentNodeElement) || (!focusElement) || focusElement instanceof documentElement.DocumentNodeElement) { return {}; + } if(which === 'anchor') { return { @@ -336,30 +353,30 @@ $.extend(Cursor.prototype, { if(anchorFirst) { if(which === 'start') { element = anchorElement; - offset = selection.anchorOffset + offset = selection.anchorOffset; } else if(which === 'end') { - element = focusElement, - offset = selection.focusOffset + element = focusElement; + offset = selection.focusOffset; } } else { if(which === 'start') { - element = focusElement, - offset = selection.focusOffset + element = focusElement; + offset = selection.focusOffset; } else if(which === 'end') { element = anchorElement; - offset = selection.anchorOffset + offset = selection.anchorOffset; } } } else { // TODO: Handle order via https://developer.mozilla.org/en-US/docs/Web/API/Node.compareDocumentPosition if(which === 'start') { element = anchorElement; - offset = selection.anchorOffset + offset = selection.anchorOffset; } else { element = focusElement; - offset = selection.focusOffset + offset = selection.focusOffset; } } @@ -369,9 +386,9 @@ $.extend(Cursor.prototype, { offset: offset, offsetAtBeginning: offset === 0, offsetAtEnd: nodeLen === offset - } + }; } -}) +}); return { fromXMLDocument: function(wlxmlDocument, publisher) { diff --git a/src/editor/modules/documentCanvas/canvas/documentElement.js b/src/editor/modules/documentCanvas/canvas/documentElement.js index 210c492..a0da233 100644 --- a/src/editor/modules/documentCanvas/canvas/documentElement.js +++ b/src/editor/modules/documentCanvas/canvas/documentElement.js @@ -7,20 +7,22 @@ define([ ], function($, _, utils, widgets, wlxmlManagers) { 'use strict'; +/* global Node:false, document:false */ // DocumentElement represents a text or an element node from WLXML document rendered inside Canvas var DocumentElement = function(htmlElement, canvas) { - if(arguments.length === 0) + if(arguments.length === 0) { return; + } this.canvas = canvas; this._setupDOMHandler(htmlElement); -} +}; var elementTypeFromWlxmlNode = function(wlxmlNode) { return wlxmlNode.nodeType === Node.TEXT_NODE ? DocumentTextElement : DocumentNodeElement; -} +}; $.extend(DocumentElement, { create: function(node, canvas) { @@ -33,10 +35,12 @@ $.extend(DocumentElement, { fromHTMLElement: function(htmlElement, canvas) { var $element = $(htmlElement); - if(htmlElement.nodeType === Node.ELEMENT_NODE && $element.attr('document-node-element') !== undefined) + if(htmlElement.nodeType === Node.ELEMENT_NODE && $element.attr('document-node-element') !== undefined) { return DocumentNodeElement.fromHTMLElement(htmlElement, canvas); - if($element.attr('document-text-element') !== undefined || (htmlElement.nodeType === Node.TEXT_NODE && $element.parent().attr('document-text-element') !== undefined)) + } + if($element.attr('document-text-element') !== undefined || (htmlElement.nodeType === Node.TEXT_NODE && $element.parent().attr('document-text-element') !== undefined)) { return DocumentTextElement.fromHTMLElement(htmlElement, canvas); + } return undefined; } }); @@ -54,14 +58,16 @@ $.extend(DocumentElement.prototype, { data: function() { var dom = this.dom(), args = Array.prototype.slice.call(arguments, 0); - if(args.length === 2 && args[1] === undefined) + if(args.length === 2 && args[1] === undefined) { return dom.removeData(args[0]); + } return dom.data.apply(dom, arguments); }, parent: function() { var parents = this.$element.parents('[document-node-element]'); - if(parents.length) + if(parents.length) { return DocumentElement.fromHTMLElement(parents[0], this.canvas); + } return null; }, @@ -86,15 +92,17 @@ $.extend(DocumentElement.prototype, { getVerticallyFirstTextElement: function() { var toret; this.children().some(function(child) { - if(!child.isVisible()) + if(!child.isVisible()) { return false; // continue + } if(child instanceof DocumentTextElement) { toret = child; return true; // break } else { toret = child.getVerticallyFirstTextElement(); - if(toret) + if(toret) { return true; // break + } } }); return toret; @@ -126,8 +134,9 @@ $.extend(DocumentElement.prototype, { exec: function(method) { var manager = this.data('_wlxmlManager'); - if(manager[method]) + if(manager[method]) { return manager[method].apply(manager, Array.prototype.slice.call(arguments, 1)); + } } }); @@ -166,9 +175,9 @@ $.extend(DocumentNodeElement, { element.setWlxml({tag: wlxmlNode.getTagName(), klass: wlxmlNode.getClass()}); - wlxmlNode.contents().forEach((function(node) { + wlxmlNode.contents().forEach(function(node) { container.append(DocumentElement.create(node).dom()); - }).bind(this)); + }.bind(this)); return dom; } @@ -200,8 +209,9 @@ $.extend(DocumentNodeElement.prototype, { return this; }, append: function(params) { - if(params.tag !== 'span') + if(params.tag !== 'span') { this.data('orig-end', undefined); + } return manipulate(this, params, 'append'); }, prepend: function(params) { @@ -216,21 +226,25 @@ $.extend(DocumentNodeElement.prototype, { }, children: function() { var toret = []; - if(this instanceof DocumentTextElement) + if(this instanceof DocumentTextElement) { return toret; + } var elementContent = this._container().contents(); var element = this; elementContent.each(function(idx) { var childElement = DocumentElement.fromHTMLElement(this, element.canvas); - if(childElement === undefined) + if(childElement === undefined) { return true; - if(idx === 0 && elementContent.length > 1 && elementContent[1].nodeType === Node.ELEMENT_NODE && (childElement instanceof DocumentTextElement) && $.trim($(this).text()) === '') + } + if(idx === 0 && elementContent.length > 1 && elementContent[1].nodeType === Node.ELEMENT_NODE && (childElement instanceof DocumentTextElement) && $.trim($(this).text()) === '') { return true; + } if(idx > 0 && childElement instanceof DocumentTextElement) { - if(toret[toret.length-1] instanceof DocumentNodeElement && $.trim($(this).text()) === '') + if(toret[toret.length-1] instanceof DocumentNodeElement && $.trim($(this).text()) === '') { return true; + } } toret.push(childElement); }); @@ -251,35 +265,44 @@ $.extend(DocumentNodeElement.prototype, { return this._container().attr('wlxml-tag'); }, setWlxmlTag: function(tag) { - if(tag === this.getWlxmlTag()) + if(tag === this.getWlxmlTag()) { return; + } this._container().attr('wlxml-tag', tag); - if(!this.__updatingWlxml) + if(!this.__updatingWlxml) { this._updateWlxmlManager(); + } }, getWlxmlClass: function() { var klass = this._container().attr('wlxml-class'); - if(klass) + if(klass) { return klass.replace(/-/g, '.'); + } return undefined; }, setWlxmlClass: function(klass) { - if(klass === this.getWlxmlClass()) + if(klass === this.getWlxmlClass()) { return; - if(klass) + } + if(klass) { this._container().attr('wlxml-class', klass.replace(/\./g, '-')); - else + } + else { this._container().removeAttr('wlxml-class'); - if(!this.__updatingWlxml) + } + if(!this.__updatingWlxml) { this._updateWlxmlManager(); + } }, setWlxml: function(params) { this.__updatingWlxml = true; - if(params.tag !== undefined) + if(params.tag !== undefined) { this.setWlxmlTag(params.tag); - if(params.klass !== undefined) + } + if(params.klass !== undefined) { this.setWlxmlClass(params.klass); + } this._updateWlxmlManager(); this.__updatingWlxml = false; }, @@ -289,8 +312,9 @@ $.extend(DocumentNodeElement.prototype, { manager.setup(); }, is: function(what) { - if(what === 'list' && _.contains(['list.items', 'list.items.enum'], this.getWlxmlClass())) + if(what === 'list' && _.contains(['list.items', 'list.items.enum'], this.getWlxmlClass())) { return true; + } return false; }, toggleLabel: function(toggle) { @@ -345,10 +369,12 @@ DocumentTextElement.prototype = new DocumentElement(); $.extend(DocumentTextElement.prototype, { _setupDOMHandler: function(htmlElement) { var $element = $(htmlElement); - if(htmlElement.nodeType === Node.TEXT_NODE) + if(htmlElement.nodeType === Node.TEXT_NODE) { this.$element = $element.parent(); - else + } + else { this.$element = $element; + } }, detach: function() { this.dom().detach(); @@ -358,12 +384,6 @@ $.extend(DocumentTextElement.prototype, { setText: function(text) { this.dom().contents()[0].data = text; }, - appendText: function(text) { - this.dom().contents()[0].data += text; - }, - prependText: function(text) { - this.dom().contents()[0].data = text + this.dom().contents()[0].data; - }, getText: function(options) { options = _.extend({raw: false}, options || {}); var toret = this.dom().text(); @@ -377,8 +397,9 @@ $.extend(DocumentTextElement.prototype, { return this.dom().contents()[0].data === utils.unicode.ZWS; }, after: function(params) { - if(params instanceof DocumentTextElement || params.text) + if(params instanceof DocumentTextElement || params.text) { return false; + } var element; if(params instanceof DocumentNodeElement) { element = params; @@ -391,8 +412,9 @@ $.extend(DocumentTextElement.prototype, { return element; }, before: function(params) { - if(params instanceof DocumentTextElement || params.text) + if(params instanceof DocumentTextElement || params.text) { return false; + } var element; if(params instanceof DocumentNodeElement) { element = params; @@ -408,10 +430,12 @@ $.extend(DocumentTextElement.prototype, { divide: function(params) { var myText = this.getText(); - if(params.offset === myText.length) + if(params.offset === myText.length) { return this.after(params); - if(params.offset === 0) + } + if(params.offset === 0) { return this.before(params); + } var lhsText = myText.substr(0, params.offset), rhsText = myText.substr(params.offset), diff --git a/src/editor/modules/documentCanvas/canvas/keyboard.js b/src/editor/modules/documentCanvas/canvas/keyboard.js index e48917c..0b58443 100644 --- a/src/editor/modules/documentCanvas/canvas/keyboard.js +++ b/src/editor/modules/documentCanvas/canvas/keyboard.js @@ -27,10 +27,12 @@ var handleKey = function(event, canvas) { }; var handles = function(handler, event) { - if(handler.key === event.which) + if(handler.key === event.which) { return true; - if(handler.keys && handler.keys.indexOf(event.which) !== -1) + } + if(handler.keys && handler.keys.indexOf(event.which) !== -1) { return true; + } return false; }; @@ -42,12 +44,13 @@ handlers.push({key: KEYS.ENTER, event.preventDefault(); var cursor = canvas.getCursor(), position = cursor.getPosition(), - element = position.element; + element = position.element, + added; if(Object.keys(cursor.getPosition()).length === 0) { var currentElement = canvas.getCurrentNodeElement(); if(currentElement) { - var added = currentElement.data('wlxmlNode').after({ + added = currentElement.data('wlxmlNode').after({ tag: currentElement.getWlxmlTag() || 'div', attrs: {'class': currentElement.getWlxmlClass() || 'p'} }); @@ -62,7 +65,7 @@ handlers.push({key: KEYS.ENTER, if(element instanceof documentElement.DocumentTextElement) { element = element.parent(); } - var added = element.data('wlxmlNode').after( + added = element.data('wlxmlNode').after( {tagName: element.getWlxmlTag() || 'div', attrs: {'class': element.getWlxmlClass() || 'p'}} ); added.append({text: ''}); @@ -100,7 +103,7 @@ handlers.push({key: KEYS.ENTER, gotoOptions = {}; } else { goto = result.second; - gotoOptions = {caretTo: 'start'}; + gotoOptions = {caretTo: 'start'}; } canvas.setCurrentElement(utils.findCanvasElement(goto), gotoOptions); @@ -139,6 +142,7 @@ handlers.push({keys: [KEYS.ARROW_UP, KEYS.ARROW_DOWN, KEYS.ARROW_LEFT, KEYS.ARRO direction = 'below'; caretTo = 'start'; } + /* globals window */ element = canvas.getDocumentElement(utils.nearestInDocumentOrder('[document-text-element]:visible', direction, window.getSelection().focusNode)); } canvas.setCurrentElement(element, {caretTo: caretTo}); @@ -147,15 +151,17 @@ handlers.push({keys: [KEYS.ARROW_UP, KEYS.ARROW_DOWN, KEYS.ARROW_LEFT, KEYS.ARRO var selectsWholeTextElement = function(cursor) { - if(cursor.isSelecting() && cursor.getSelectionStart().offsetAtBeginning && cursor.getSelectionEnd().offsetAtEnd) + if(cursor.isSelecting() && cursor.getSelectionStart().offsetAtBeginning && cursor.getSelectionEnd().offsetAtEnd) { return true; + } return false; -} +}; handlers.push({key: KEYS.X, keydown: function(event, canvas) { - if(event.ctrlKey && selectsWholeTextElement(canvas.getCursor())) + if(event.ctrlKey && selectsWholeTextElement(canvas.getCursor())) { event.preventDefault(); + } } }); @@ -177,7 +183,7 @@ handlers.push({keys: [KEYS.BACKSPACE, KEYS.DELETE], var willDeleteWholeText = function() { return element.getText().length === 1 || selectsWholeTextElement(cursor); - } + }; if(willDeleteWholeText()) { event.preventDefault(); diff --git a/src/editor/modules/documentCanvas/commands.js b/src/editor/modules/documentCanvas/commands.js index 3cecf60..b38c720 100644 --- a/src/editor/modules/documentCanvas/commands.js +++ b/src/editor/modules/documentCanvas/commands.js @@ -32,15 +32,7 @@ commands.register('redo', function(canvas) { }); commands.register('remove-node', function(canvas) { - var cursor = canvas.getCursor(), - selectionStart = cursor.getSelectionStart(), - selectionEnd = cursor.getSelectionEnd(), - parent1 = selectionStart.element.parent() || undefined, - parent2 = selectionEnd.element.parent() || undefined; - -// canvas.wlxmlDocument.transform('detach2', {node:canvas.getCurrentNodeElement().data('wlxmlNode')}); canvas.getCurrentNodeElement().data('wlxmlNode').transform('smartxml.detach'); - }); commands.register('unwrap-node', function(canvas) { @@ -89,6 +81,7 @@ commands.register('wrap-node', function(canvas) { }); commands.register('list', function(canvas, params) { + void(params); var cursor = canvas.getCursor(), selectionStart = cursor.getSelectionStart(), selectionEnd = cursor.getSelectionEnd(), @@ -120,23 +113,23 @@ commands.register('toggle-grid', function(canvas, params) { commands.register('newNodeRequested', function(canvas, params) { var cursor = canvas.getCursor(), selectionStart = cursor.getSelectionStart(), - selectionEnd = cursor.getSelectionEnd(); + selectionEnd = cursor.getSelectionEnd(), + wlxmlNode, caretTo, wrapper, wrapperCanvasElement; if(cursor.isSelecting()) { if(cursor.isSelectingSiblings()) { if(cursor.isSelectingWithinElement()) { - var wlxmlNode = selectionStart.element.data('wlxmlNode'), - caretTo = selectionStart.offset < selectionEnd.offset ? 'start' : 'end', + wlxmlNode = selectionStart.element.data('wlxmlNode'); + caretTo = selectionStart.offset < selectionEnd.offset ? 'start' : 'end'; //wrapper = wlxmlNode.wrapWith({tagName: params.wlxmlTag, attrs: {'class': params.wlxmlClass}, start: selectionStart.offset, end: selectionEnd.offset}), //wrapper = wlxmlNode.transform('smartxml.wrapWith', {tagName: params.wlxmlTag, attrs: {'class': params.wlxmlClass}, start: selectionStart.offset, end: selectionEnd.offset}) - wrapper = wlxmlNode.wrapWith({tagName: params.wlxmlTag, attrs: {'class': params.wlxmlClass}, start: selectionStart.offset, end: selectionEnd.offset}); - ; - var wrapperCanvasElement = utils.findCanvasElement(wrapper); + wrapper = wlxmlNode.wrapWith({tagName: params.wlxmlTag, attrs: {'class': params.wlxmlClass}, start: selectionStart.offset, end: selectionEnd.offset}); + wrapperCanvasElement = utils.findCanvasElement(wrapper); canvas.setCurrentElement(wrapperCanvasElement.children()[0], {caretTo: caretTo}); } else { - var wlxmlNode = selectionStart.element.data('wlxmlNode').parent(), - caretTo = selectionStart.element.sameNode(cursor.getSelectionAnchor().element) ? 'end' : 'start'; + wlxmlNode = selectionStart.element.data('wlxmlNode').parent(); + caretTo = selectionStart.element.sameNode(cursor.getSelectionAnchor().element) ? 'end' : 'start'; // var wrapper = wlxmlNode.wrapText({ // _with: {tagName: params.wlxmlTag, attrs: {'class': params.wlxmlClass}}, @@ -144,12 +137,12 @@ commands.register('newNodeRequested', function(canvas, params) { // offsetEnd: selectionEnd.offset, // textNodeIdx: [wlxmlNode.indexOf(selectionStart.element.data('wlxmlNode')), wlxmlNode.indexOf(selectionEnd.element.data('wlxmlNode'))] //parent.childIndex(selectionEnd.element)] // }), - var wrapper = wlxmlNode.transform('smartxml.wrapText', { + wrapper = wlxmlNode.transform('smartxml.wrapText', { _with: {tagName: params.wlxmlTag, attrs: {'class': params.wlxmlClass}}, offsetStart: selectionStart.offset, offsetEnd: selectionEnd.offset, textNodeIdx: [wlxmlNode.indexOf(selectionStart.element.data('wlxmlNode')), wlxmlNode.indexOf(selectionEnd.element.data('wlxmlNode'))] //parent.childIndex(selectionEnd.element)] - }), + }); wrapperCanvasElement = utils.findCanvasElement(wrapper); canvas.setCurrentElement(wrapperCanvasElement.children()[caretTo === 0 ? 0 : wrapperCanvasElement.children().length - 1], {caretTo: caretTo}); } @@ -172,9 +165,9 @@ commands.register('newNodeRequested', function(canvas, params) { } } } else if(canvas.getCurrentNodeElement()) { - var node = canvas.getCurrentNodeElement().data('wlxmlNode'), + wlxmlNode = canvas.getCurrentNodeElement().data('wlxmlNode'); // wrapper = node.wrapWith({tagName: params.wlxmlTag, attrs: {klass: params.wlxmlClass}}); - wrapper = node.transform('smartxml.wrapWith', {tagName: params.wlxmlTag, attrs: {klass: params.wlxmlClass}}); + wrapper = wlxmlNode.transform('smartxml.wrapWith', {tagName: params.wlxmlTag, attrs: {klass: params.wlxmlClass}}); canvas.setCurrentElement(utils.findCanvasElement(wrapper)); } @@ -182,6 +175,7 @@ commands.register('newNodeRequested', function(canvas, params) { }); commands.register('footnote', function(canvas, params) { + void(params); var cursor = canvas.getCursor(), position = cursor.getPosition(), asideElement; @@ -203,8 +197,9 @@ commands.register('take-away-node', function(canvas) { element = position.element, nodeElement = element ? element.parent() : canvas.getCurrentNodeElement(); - if(!nodeElement || !(nodeElement.parent())) + if(!nodeElement || !(nodeElement.parent())) { return; + } var range = nodeElement.data('wlxmlNode').unwrapContent();