Issue #1804Opened February 18, 2019by AkibDeraiya1230 reactions

Applying two different traits on same html tag but applies only one

Question

Hello @artf ,

If we need to initialize two traits on same HTML tag then it's possible or not? Actually i define two different traits on same tag(on link/a tag).

Let me describe you in little bit brief. Suppose i have one group of links which contains class is like not-drag-drop.

So, it's HTML code is like

<ul>
    <li>
        <a class="not-drag-drop" href="index.html">Home 1</a>
    </li>
    <li>
        <a class="not-drag-drop" href="index2.html">Home 2</a>
    </li>
    <li>
        <a class="not-drag-drop" href="index3.html">Home 3</a>
    </li>
</ul>

So for above class not-drag-drop i want to add one traits like,

var domComponents = editor.DomComponents
    var defaultType = domComponents.getType('default')
    var dModel = defaultType.model;
    var dView = defaultType.view;
    
    domComponents.addType('not-drag-drop', {
      model: dModel.extend(
        {
          defaults: Object.assign(
            {},
            dModel.prototype.defaults,
            {
              badgable: false,
              copyable: false,
              draggable: false,
              droppable: false,
              highlightable: false,
              hoverable: false,
              movable: false,
              removable: false,
              stylable: false,
              propagate: ['badgable', 'droppable', 'highlightable']
            }
          )
        },
        {
          isComponent: function(el) {
            if (el.classList && el.classList.contains('not-drag-drop')) {
              return {type: 'not-drag-drop'};
            }
          },
        }
      ),
      view: dView,
    });

and for all the links i want to one more traits like,

var dType = editor.DomComponents.getType('link');
var dModel = dType.model;
var dView = dType.view;

editor.DomComponents.addType('link', {
        model: dModel.extend({
          defaults: Object.assign({}, dModel.prototype.defaults, {
            traits: [
              // strings are automatically converted to text types
              // title,
              {
                type: 'select',
                label: 'Target',
                name: 'target',
                options: [
                  { value: '', name: 'This window' },
                  { value: '_blank', name: 'New window' }
                ]
              },
              {
                type: 'select',
                label: 'Href',
                name: 'href',
                options: opts
              }
            ],
          }),
        }, {
          isComponent: function(el) {
            if(el.tagName == 'A'){
              return {type: 'link'};
            }
          },
        }),
    
        view: dView,
      });

But when i click on link which contains class not-drag-drop then only traits apply not-drag-drop, not applies link trait, So, when i am going to change this link's href i am not getting the links dropdown just showing the input-box.

Can you please help me how can i figure it out this issue?

Answers (3)

artfFebruary 21, 20190 reactions

The HTML code is already loaded in canvas? Did you try to execute your custom component definition via a plugin? Otherwise you're trying to see changes on already loaded components

no-response[bot]March 3, 20190 reactions

This issue has been automatically closed because there has been no response to our request for more information from the original author. With only the information that is currently in the issue, we don't have enough information to take action. Please reach out if you have or find the answers we need so that we can investigate further.

lock[bot]March 10, 20200 reactions

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.