Sha256: 1114c65865191961622a651f65703fa60ef3933467a9a04739d81ae268a16623

Contents?: true

Size: 1.5 KB

Versions: 14

Compression:

Stored size: 1.5 KB

Contents

/* hjq-sortable-input-many */
(function($) {
    var methods = {
        init: function(annotations) {
            var options = $.extend({update: methods.update}, this.hjq('getOptions', annotations));
            this.sortable(options);
            this.on('rapid:change', methods.countChanged);
        },

        countChanged: function() {
            // added or removed a field
            var that = $(this);
            return that.hjq_sortable_input_many('updatePositions');
        },

        update: function() {
            // fields are reordered
            var that = $(this);
            that.hjq_input_many('updateNames');
            that.hjq_input_many('updateVisibility');
            return that.hjq_sortable_input_many('updatePositions');
        },

        updatePositions: function() {
            var that=$(this);
            var annotations=that.data('rapid')['sortable-input-many'];
            that.find("li:visible input.sortable-position").each(function(index) {
                $(this).val(index+1);
            });
            return that;
        }

    };


    $.fn.hjq_sortable_input_many = 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_sortable_input_many' );
        }
    };

})( jQuery );

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
hobo_jquery_ui-2.2.6 vendor/assets/javascripts/hobo-jquery-ui/hjq-sortable-input-many.js
hobo_jquery_ui-2.2.5 vendor/assets/javascripts/hobo-jquery-ui/hjq-sortable-input-many.js
hobo_jquery_ui-2.2.4 vendor/assets/javascripts/hobo-jquery-ui/hjq-sortable-input-many.js
hobo_jquery_ui-2.2.3 vendor/assets/javascripts/hobo-jquery-ui/hjq-sortable-input-many.js
hobo_jquery_ui-2.2.2 vendor/assets/javascripts/hobo-jquery-ui/hjq-sortable-input-many.js
hobo_jquery_ui-2.2.1 vendor/assets/javascripts/hobo-jquery-ui/hjq-sortable-input-many.js
hobo_jquery_ui-2.2.0 vendor/assets/javascripts/hobo-jquery-ui/hjq-sortable-input-many.js
hobo_jquery_ui-2.1.2 vendor/assets/javascripts/hobo-jquery-ui/hjq-sortable-input-many.js
hobo_jquery_ui-2.1.1 vendor/assets/javascripts/hobo-jquery-ui/hjq-sortable-input-many.js
hobo_jquery_ui-2.1.0 vendor/assets/javascripts/hobo-jquery-ui/hjq-sortable-input-many.js
hobo_jquery_ui-2.1.0.pre4 vendor/assets/javascripts/hobo-jquery-ui/hjq-sortable-input-many.js
hobo_jquery_ui-2.1.0.pre3 vendor/assets/javascripts/hobo-jquery-ui/hjq-sortable-input-many.js
hobo_jquery_ui-2.1.0.pre2 vendor/assets/javascripts/hobo-jquery-ui/hjq-sortable-input-many.js
hobo_jquery_ui-2.1.0.pre1 vendor/assets/javascripts/hobo-jquery-ui/hjq-sortable-input-many.js