Browse Source

Make use of isTaggableNode

pull/2062/head
Artur Arseniev 8 years ago
parent
commit
2d146ca147
  1. 5
      src/commands/view/SelectComponent.js
  2. 4
      src/style_manager/view/SectorsView.js
  3. 14
      src/utils/mixins.js

5
src/commands/view/SelectComponent.js

@ -1,5 +1,5 @@
import { bindAll, isElement, isUndefined } from 'underscore';
import { on, off, getUnitFromValue, isTextNode } from 'utils/mixins';
import { on, off, getUnitFromValue, isTaggableNode } from 'utils/mixins';
const ToolbarView = require('dom_components/view/ToolbarView');
const Toolbar = require('dom_components/model/Toolbar');
@ -355,10 +355,9 @@ module.exports = {
const editor = em ? em.get('Editor') : '';
const config = em ? em.get('Config') : '';
const pfx = config.stylePrefix || '';
const attrName = `data-${pfx}handler`;
const resizeClass = `${pfx}resizing`;
const model =
!isElement(elem) && !isTextNode(elem) ? elem : em.getSelected();
!isElement(elem) && isTaggableNode(elem) ? elem : em.getSelected();
const resizable = model.get('resizable');
const el = isElement(elem) ? elem : model.getEl();
let options = {};

4
src/style_manager/view/SectorsView.js

@ -1,6 +1,6 @@
import Backbone from 'backbone';
import { extend, isString } from 'underscore';
import { isTextNode } from 'utils/mixins';
import { isTaggableNode } from 'utils/mixins';
const SectorView = require('./SectorView');
@ -55,7 +55,7 @@ module.exports = Backbone.View.extend({
pt.helper = null;
// Create computed style container
if (el && !isTextNode(el)) {
if (el && isTaggableNode(el)) {
const stateStr = state ? `:${state}` : null;
pt.computed = window.getComputedStyle(el, stateStr);
}

14
src/utils/mixins.js

@ -117,6 +117,20 @@ const getElement = el => {
*/
const isTextNode = el => el && el.nodeType === 3;
/**
* Check if element is a comment node
* @param {HTMLElement} el
* @return {Boolean}
*/
export const isCommentNode = el => el && el.nodeType === 8;
/**
* Check if element is a comment node
* @param {HTMLElement} el
* @return {Boolean}
*/
export const isTaggableNode = el => el && !isTextNode(el) && !isCommentNode(el);
/**
* Ensure to fetch the model from the input argument
* @param {HTMLElement|Component} el Component or HTML element

Loading…
Cancel
Save