Skip to content

Custom commands: why only "title" and "id" attributes are autoupdateble? #209

@sammael1106

Description

@sammael1106

Hi there, I wrote some custom commands with modals and as I noticed that only title and id attributes can be updated automatically after closing the modal window. I also tried alt, href, src and etc. but its weren't updated. Is it some kind of discrimination or I do something wrong? :)

This is an example of my commands:

# HBS template
<li>
   <div class="modal fade" data-wysihtml5-dialog="insertButtonLink">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-body">
                        <input value="" data-wysihtml5-dialog-field="title">
                        <input value="" data-wysihtml5-dialog-field="href">
                </div>
            </div>
        </div>
    </div>
   <a data-wysihtml5-command="insertButtonLink">Insert button</a>
</li>
# Coffee
wysihtml5.commands.insertButtonLink =
  exec: (composer, command, value) ->
    title           = if value then value.title else ''
    url             = if value then value.href else ''
    doc             = composer.doc
    dom             = wysihtml5.dom
    tempClass       = "_wysihtml5-temp-" + (+new Date())
    tempClassRegExp = /non-matching-class/g

    wysihtml5.commands.formatInline.exec composer, undefined, "A", tempClass, tempClassRegExp, undefined, undefined, true, true
    BUTTON = doc.querySelectorAll('A.' + tempClass)[0]

    if BUTTON && title
      BUTTON.removeAttribute 'class'
      BUTTON.setAttribute('title', title)     # button title
      BUTTON.setAttribute('href', url)       # button href
      dom.setTextContent BUTTON, title

  state: (composer) ->
    NODE_NAME    = "A"
    dom       = wysihtml5.dom
    node      = composer.selection.getSelectedNode();
    tag       = undefined
    checkNode = (node) ->
      return node.nodeName == NODE_NAME && node.getAttribute('title') && node.getAttribute('href')
    return unless node

    # if current node is a TEXT
    if node.nodeName == '#text' && node.parentNode.nodeName == NODE_NAME
      node = node.parentNode

    # if current node is a BUTTON
    if node.nodeName == NODE_NAME
      if checkNode(node)
        title = node.getAttribute('title')
        dom.setTextContent node, title
        return node
      else
        node.remove()

So, if i click on my inserted button and and try to change title&href in modal window, only title will be changed. This is my problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions