I'm writing a jquery plugin that should handle extra information on links to specify open behavior.

For example, I want to supports markup like :

  1. <a href="somewhere" data-openmode="NewWindow" class="openmode" />
  2. <a href="somewhere" data-openmode="Modal" class="openmode" />
  3. <a href="somewhere" class="openmode" /> <!-- Not specified -->

The first should open in a new window, the second in a modal dialog, the third should open with the native behavior (whatever target has been set on the tag).

I would like to create a plugin for this behavior as generic as possible. I've written by now:

(function ($) {
    $.fn.myOpenMode = function () {
        return this.mousedown(function () {
            var $this = $(this);

            var mode = $this.data("openmode");
            var href = this.href;
            var handled = true;
            if (mode) {
                switch (mode) {
                    case "NewWindow":
                    case "1":
                        window.open(href, "_blank");
                        break;
                    case "Dialog":
                    case "2":
                        openAsDialog(href);
                        break;

                    // Actually, there are other options, but I removed them for clarity

                    default:
                        handled = false;
                }
            }
            else {
                handled = false;
            }
            return !handled;
        });
    };
})(jQuery);

This code allows me to call from any page something like:

$(function(){
    $(".openmode").myOpenMode();
});

This is working for statically generated tags. However, my applications may generate markup dynamically (most of time using jsRender, but this does not matters).

But because this behavi

Edit
Report