/**
 * Small Javascript Snippet that allows links to fire POST requests
 *
 * Add data-method="POST" to links you want to POST.
 *
 * @author Visual Media
 */

(function() {

    $(function() {

        $(document.body).on('click', 'a[data-method="POST"]', function(event) {

            var $this = $(this),
                form;

            event.preventDefault();

            if (($this.attr('data-confirm') != '') && ($this.attr('data-confirm') != null)) {
                if (!confirm($this.attr('data-confirm'))) {
                    return;
                }
            }

            // Create form
            form = $('<form />')
                    .attr('action', $this.attr('href'))
                    .attr('method', 'POST');


            if ($this.is('[target]')) {
                form.attr('target', $this.attr('target'));
            }

            // Append it to the body
            $('body').append(form);

            // And submit
            form.trigger('submit');


        });

    });


})(jQuery);