xref: /plugin/addnewpage/script.js (revision 641f0487ea9954b1ef223b55832d3664c320d4e3)
1jQuery(function () {
2    jQuery(".addnewpage form").each(function () {
3        var $form = jQuery(this);
4        var $ns = $form.find("[name='np_cat']");
5        var $title = $form.find("input[name='title']");
6        var $id = $form.find("input[name='id']");
7        var $submit = $form.find(':submit');
8
9        // disable submit unless something is in input or input is disabled
10        if ($title.attr('type') === 'text') {
11            $submit.attr('disabled', 'disabled');
12            $title.on('input', function () {
13                if ($title.val().length > 0) {
14                    $submit.removeAttr('disabled');
15                } else {
16                    $submit.attr('disabled', 'disabled');
17                }
18            });
19        }
20
21        // Change the form's page-ID field on submit
22        $form.submit(function () {
23            // Build the new page ID and save in hidden form field
24            var id = $ns.val().replace('@INPUT@', $title.val());
25            $id.val(id);
26
27            // Clean up the form vars, just to make the resultant URL a bit nicer
28            $ns.prop("disabled", true);
29            $title.prop("disabled", true);
30
31            return true;
32        });
33
34    });
35});
36