1 | |
---|
2 | Drupal.behaviors.feeds = function() { |
---|
3 | |
---|
4 | // Export form machine-readable JS |
---|
5 | $('.feed-name:not(.processed)').each(function() { |
---|
6 | $('.feed-name') |
---|
7 | .addClass('processed') |
---|
8 | .after(' <small class="feed-id-suffix"> </small>'); |
---|
9 | if ($('.feed-id').val() === $('.feed-name').val().toLowerCase().replace(/[^a-z0-9]+/g, '_').replace(/_+/g, '_') || $('.feed-id').val() === '') { |
---|
10 | $('.feed-id').parents('.form-item').hide(); |
---|
11 | $('.feed-name').keyup(function() { |
---|
12 | var machine = $(this).val().toLowerCase().replace(/[^a-z0-9]+/g, '_').replace(/_+/g, '_'); |
---|
13 | if (machine !== '_' && machine !== '') { |
---|
14 | $('.feed-id').val(machine); |
---|
15 | $('.feed-id-suffix').empty().append(' Machine name: ' + machine + ' [').append($('<a href="#">'+ Drupal.t('Edit') +'</a>').click(function() { |
---|
16 | $('.feed-id').parents('.form-item').show(); |
---|
17 | $('.feed-id-suffix').hide(); |
---|
18 | $('.feed-name').unbind('keyup'); |
---|
19 | return false; |
---|
20 | })).append(']'); |
---|
21 | } |
---|
22 | else { |
---|
23 | $('.feed-id').val(machine); |
---|
24 | $('.feed-id-suffix').text(''); |
---|
25 | } |
---|
26 | }); |
---|
27 | $('.feed-name').keyup(); |
---|
28 | } |
---|
29 | }); |
---|
30 | |
---|
31 | // Hide text in specific input fields. |
---|
32 | $('.hide-text-on-focus').focus(function() { |
---|
33 | $(this).val(''); |
---|
34 | }); |
---|
35 | |
---|
36 | |
---|
37 | // Hide submit buttons of .feeds-ui-hidden-submit class. |
---|
38 | $('input.form-submit.feeds-ui-hidden-submit').hide(); |
---|
39 | |
---|
40 | /** |
---|
41 | * Tune checkboxes on mapping forms. |
---|
42 | * @see feeds_ui_mapping_form() in feeds_ui.admin.inc |
---|
43 | */ |
---|
44 | |
---|
45 | // Attach submit behavior to elements with feeds-ui-trigger-submit class. |
---|
46 | $('.feeds-ui-trigger-submit').click(function() { |
---|
47 | // Use click, not form.submit() - submit() would use the wrong submission |
---|
48 | // handler. |
---|
49 | $('input.form-submit.feeds-ui-hidden-submit').click(); |
---|
50 | }); |
---|
51 | |
---|
52 | // Replace checkbox with .feeds-ui-checkbox-link class with a link. |
---|
53 | $('.feeds-ui-checkbox-link:not(.processed)').each(function(i) { |
---|
54 | $(this).addClass('processed').after( |
---|
55 | '<a href="#" onclick="return false;" class="feeds-ui-trigger-remove">' + $('label', this).text() + '</a>' |
---|
56 | ).hide(); |
---|
57 | }); |
---|
58 | |
---|
59 | // Check the box and then submit. |
---|
60 | $('.feeds-ui-trigger-remove').click(function() { |
---|
61 | // Use click, not form.submit() - submit() would use the wrong submission |
---|
62 | // handler. |
---|
63 | $(this).prev().children().children().children().attr('checked', 1); |
---|
64 | $('input.form-submit.feeds-ui-hidden-submit').click(); |
---|
65 | }); |
---|
66 | |
---|
67 | // Replace radio with .feeds-ui-radio-link class with a link. |
---|
68 | $('.feeds-ui-radio-link:not(.processed)').parent().each(function(i) { |
---|
69 | checked = ''; |
---|
70 | if ($(this).children('input').attr('checked')) { |
---|
71 | checked = ' checked'; |
---|
72 | } |
---|
73 | $(this).addClass('processed').after( |
---|
74 | '<a href="#" onclick="return false;" class="feeds-ui-check-submit' + checked + '" id="' + $(this).children('input').attr('id') + '">' + $(this).parent().text() + '</a>' |
---|
75 | ); |
---|
76 | $(this).hide(); |
---|
77 | }); |
---|
78 | |
---|
79 | // Hide the the radio that is selected. |
---|
80 | $('.feeds-ui-check-submit.checked').parent().hide(); |
---|
81 | |
---|
82 | // Check the radio and then submit. |
---|
83 | $('.feeds-ui-check-submit').click(function() { |
---|
84 | // Use click, not form.submit() - submit() would use the wrong submission |
---|
85 | // handler. |
---|
86 | $('#' + $(this).attr('id')).attr('checked', 1); |
---|
87 | $('input.form-submit.feeds-ui-hidden-submit').click(); |
---|
88 | }); |
---|
89 | }; |
---|