<commit_before>zeit.cms.MasterSlaveDropDown = Class.extend({
    
    construct: function(master, slave, update_url) {
        this.master = $(master);
        this.slave = $(slave);
        this.update_url = update_url;

        if (this.master == null || this.slave == null) {
            return
        }
        connect(master, 'onchange', this, 'update');
        this.update();
    },

    update: function(event) {
        var othis = this;
        var d = doSimpleXMLHttpRequest(
            this.update_url, {master_token: this.master.value});
        d.addCallback(function(result) {
            var data = evalJSONRequest(result)
            var selected = othis.slave.value;
            othis.slave.options.length = 1
            forEach(data, function(new_option) {
                var label = new_option[0]
                var value = new_option[1]
                var option = new Option(label, value)
                if (value == selected) {
                    option.selected = true;
                }
                othis.slave.options[othis.slave.options.length] = option;
            });
        });
    },
})


connect(window, 'onload', function(event) {
    var path = window.location.pathname.split('/').slice(0, -1) 
    path.push('@@subnavigationupdater.json')
    path = path.join('/')
    new zeit.cms.MasterSlaveDropDown(
        'form.ressort', 'form.sub_ressort', path)
});<commit_msg>Re #5937: extract ressort-dropdown setup into own function so we can call it from the SubPageForm's after-reload event<commit_after>zeit.cms.MasterSlaveDropDown = Class.extend({
    
    construct: function(master, slave, update_url) {
        this.master = $(master);
        this.slave = $(slave);
        this.update_url = update_url;

        if (this.master == null || this.slave == null) {
            return
        }
        connect(master, 'onchange', this, 'update');
        this.update();
    },

    update: function(event) {
        var othis = this;
        var d = doSimpleXMLHttpRequest(
            this.update_url, {master_token: this.master.value});
        d.addCallback(function(result) {
            var data = evalJSONRequest(result)
            var selected = othis.slave.value;
            othis.slave.options.length = 1
            forEach(data, function(new_option) {
                var label = new_option[0]
                var value = new_option[1]
                var option = new Option(label, value)
                if (value == selected) {
                    option.selected = true;
                }
                othis.slave.options[othis.slave.options.length] = option;
            });
        });
    },
})


zeit.cms.configure_ressort_dropdown = function() {
    var path = window.location.pathname.split('/').slice(0, -1);
    path.push('@@subnavigationupdater.json');
    path = path.join('/');
    new zeit.cms.MasterSlaveDropDown(
        'form.ressort', 'form.sub_ressort', path);
};

MochiKit.Signal.connect(window, 'onload', function(event) {
    zeit.cms.configure_ressort_dropdown();
});
{'fraction_non_alphanumeric': 0.12958115183246074, 'fraction_numerical': 0.004581151832460733, 'mean_word_length': 2.0207509881422925, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7144587', 'n_tokens_mistral': 908, 'n_tokens_neox': 874, 'n_words': 176}