Sha256: 4891851b03b08fc4a9c36247cbb2e184fcdbc3e4a96d42ffbbd4b60829909fbc

Contents?: true

Size: 1.78 KB

Versions: 33

Compression:

Stored size: 1.78 KB

Contents

/* formlet */
(function($) {
    var methods = {
        init: function(annotations) {
            this.find('input[type=submit]').on('click', methods.submit);
        },

        // you should be able to call this externally:
        // $(foo).hjq('submit');   It can be called on the formlet or any
        // child of the formlet
        submit: function(extra_callbacks, extra_options) {
            var formlet = $(this).closest(".formlet");
            if(formlet.length==0) return false;
            var annotations = formlet.data('rapid').formlet;

            // make sure we don't serialize any nested forms
            var data = formlet.find(":input").
                not(formlet.find("form :input")).
                not(formlet.find(".formlet :input")).
                serialize();

            var roptions = formlet.hjq('buildRequest',
                                       {type: annotations.form_attrs.method,
                                        attrs: annotations.ajax_attrs,
                                        extra_options: extra_options,
                                        extra_callbacks: extra_callbacks
                                       });
            if(!roptions) return false;

            roptions.data = $.param(roptions.data) + "&" + data;

            $.ajax(annotations.form_attrs.action, roptions);

            return false;
        }
    };

    $.fn.hjq_formlet = function( method ) {

        if ( methods[method] ) {
            return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
        } else if ( typeof method === 'object' || ! method ) {
            return methods.init.apply( this, arguments );
        } else {
            $.error( 'Method ' +  method + ' does not exist on hjq_formlet' );
        }
    };

})( jQuery );

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
hobo_jquery-2.2.6 vendor/assets/javascripts/hobo-jquery/hjq-formlet.js
hobo_jquery-2.2.5 vendor/assets/javascripts/hobo-jquery/hjq-formlet.js
hobo_jquery-2.2.4 vendor/assets/javascripts/hobo-jquery/hjq-formlet.js
hobo_jquery-2.2.3 vendor/assets/javascripts/hobo-jquery/hjq-formlet.js
hobo_jquery-2.2.2 vendor/assets/javascripts/hobo-jquery/hjq-formlet.js
hobo_jquery-2.2.1 vendor/assets/javascripts/hobo-jquery/hjq-formlet.js
hobo_jquery-2.2.0 vendor/assets/javascripts/hobo-jquery/hjq-formlet.js
hobo_jquery-2.1.2 vendor/assets/javascripts/hobo-jquery/hjq-formlet.js
hobo_jquery-2.1.1 vendor/assets/javascripts/hobo-jquery/hjq-formlet.js
hobo_jquery-2.1.0 vendor/assets/javascripts/hobo-jquery/hjq-formlet.js
hobo_jquery-2.1.0.pre4 vendor/assets/javascripts/hobo-jquery/hjq-formlet.js
hobo_jquery-2.1.0.pre3 vendor/assets/javascripts/hobo-jquery/hjq-formlet.js
hobo_jquery-2.1.0.pre2 vendor/assets/javascripts/hobo-jquery/hjq-formlet.js
hobo_jquery-2.1.0.pre1 vendor/assets/javascripts/hobo-jquery/hjq-formlet.js
hobo_jquery-2.0.1 vendor/assets/javascripts/hobo-jquery/hjq-formlet.js
hobo_jquery-2.0.0 vendor/assets/javascripts/hobo-jquery/hjq-formlet.js
hobo_jquery-2.0.0.pre10 vendor/assets/javascripts/hobo-jquery/hjq-formlet.js
hobo_jquery-2.0.0.pre9 vendor/assets/javascripts/hobo-jquery/hjq-formlet.js
hobo_jquery-2.0.0.pre8 vendor/assets/javascripts/hobo-jquery/hjq-formlet.js
hobo_jquery-2.0.0.pre7 vendor/assets/javascripts/hobo-jquery/hjq-formlet.js