Jump to content

[Javascript] Multiple invocation


motomac

Recommended Posts

Posted

Hi!

I'm making a small plugin which adds buttons to every post in the topic:

<li data-controller="plugins.coolAction">
  <button data-action="someAction" data-name="{$comment->author_name}">Make an action</button>
</li>

In the coolAction.js I'm catching a click event:

;(function($, _, undefined){
  "use strict";

  ips.controller.register('plugins.coolAction', {

    initialize: function () {
      this.on( document, 'click', '[data-action="someAction"]', this.mention );
    },

    mention: function (e) {
      e.preventDefault();

      alert($( e.currentTarget ).attr('data-name'));
    }

  });
}(jQuery, _));

But this action is invocated multiple times when I click on a button. Why?

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...