bootstrap-wysiwyg / bootstrap3-wysiwyg

Simple, beautiful wysiwyg editor
http://bootstrap-wysiwyg.github.io/bootstrap3-wysiwyg/
MIT License
834 stars 264 forks source link

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

Open Sammael1106 opened 6 years ago

Sammael1106 commented 6 years ago

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.