{"size": 1600, "ext": "js", "max_stars_repo_path": "app/assets/javascripts/plugins/movable_list.js", "max_stars_repo_name": "meutley/TrackMyHealth", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "app/assets/javascripts/plugins/movable_list.js", "max_issues_repo_name": "meutley/TrackMyHealth", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "app/assets/javascripts/plugins/movable_list.js", "max_forks_repo_name": "meutley/TrackMyHealth", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 34.0425531915, "max_line_length": 137, "alphanum_fraction": 0.515}
var App = App || {};
App.Plugins = App.Plugins || {};

App.Plugins.MovableList = App.Plugins.MovableList || (function ($) {
    var _init = function ($element, $btnMoveUp, $btnMoveDown) {
        $btnMoveUp.off('click');
        $btnMoveUp.on('click', function (e) {
            e.preventDefault();
            _moveUp($element);
        });

        $btnMoveDown.off('click');
        $btnMoveDown.on('click', function (e) {
            e.preventDefault();
            _moveDown($element);
        });
    }
    
    var _moveUp = function ($element) {
        var $selectedOptions = $element.find('option:selected');
        var $allOptions = $element.find('option');
        $selectedOptions.each(function() {
            var newPos = $allOptions.index(this) - 1;
            if (newPos > -1) {
                $allOptions.eq(newPos).before("<option value=" + $(this).val() + " selected='selected'>" + $(this).text() + "</option>");
                $(this).remove();
            }
        });
    }

    var _moveDown = function ($element) {
        var $selectedOptions = $element.find('option:selected');
        var $allOptions = $element.find('option');
        var countOptions = $allOptions.length;
        $selectedOptions.each(function() {
            var newPos = $allOptions.index(this) + 1;
            if (newPos < countOptions) {
                $allOptions.eq(newPos).after("<option value=" + $(this).val() + " selected='selected'>" + $(this).text() + "</option>");
                $(this).remove();
            }
        });
    }

    return {
        init: _init
    }
})(jQuery);