/[drupal]/contributions/modules/better_formats/better_formats_node_type_form.js
ViewVC logotype

Contents of /contributions/modules/better_formats/better_formats_node_type_form.js

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.6 - (show annotations) (download) (as text)
Mon Mar 16 21:48:55 2009 UTC (8 months, 1 week ago) by dragonwize
Branch: MAIN
CVS Tags: HEAD
Changes since 1.5: +8 -8 lines
File MIME type: text/javascript
Meging changes from 6.x-1 branch to head
1 // $Id: better_formats_node_type_form.js,v 1.4.2.2 2009/02/25 06:44:17 dragonwize Exp $
2
3 /**
4 * @file
5 * Enhances the default format selection on content type edit forms.
6 *
7 * Fixes bug that shows weight field when drag and drop is enabled
8 * because the field is hidden by default.
9 * Also hides formats that are not available per the Allowed checkboxes.
10 */
11
12 /**
13 * Initialize Better Formats setttings and defaults.
14 */
15 function better_formats_init() {
16 // Set default settings check for use of global allowed formats.
17 Drupal.settings.better_formats = {"num_checked" : $('input.bf-allowed-formats:checked').length};
18
19 // Collapsing the input format setting after the weight columns have been hidden.
20 $('.input-format-settings > legend > a').click();
21
22 // Add hide/show events for allowed formats.
23 var format_boxes = $('input.bf-allowed-formats');
24 format_boxes.click(function() {
25 better_formats_toggle_formats($(this));
26 });
27 if (Drupal.settings.better_formats.num_checked > 0) {
28 format_boxes.each(function() {
29 better_formats_toggle_formats($(this), true);
30 });
31 }
32 }
33
34 /**
35 * Toggle format display in dropdowns in sync with allowed checkboxes.
36 *
37 * @param el
38 * DOM element of event.
39 * @param init
40 * Boolean value to determine first toggle.
41 */
42 function better_formats_toggle_formats(el, init) {
43 // Hide all formats except site default when the first box is checked.
44 if (Drupal.settings.better_formats.num_checked === 0) {
45 $('select.bf-default-formats option[value != "0"][value != "' + el.val() + '"]').removeAttr('selected').hide();
46 }
47
48 $('select.bf-default-formats option[value = "' + el.val() + '"]').each(function() {
49 var option = $(this);
50 if (el.attr('checked')) {
51 option.show();
52 }
53 else {
54 option.removeAttr('selected').hide();
55 }
56 });
57
58 // Do not modify count on intial run.
59 if ( ! init) {
60 if (el.attr('checked')) {
61 Drupal.settings.better_formats.num_checked += 1;
62 }
63 else if (Drupal.settings.better_formats.num_checked > 0) {
64 // Keep num_checked from going below zero.
65 Drupal.settings.better_formats.num_checked -= 1;
66 }
67 }
68
69 // Show all globally allowed formats if no boxes are checked.
70 if (Drupal.settings.better_formats.num_checked === 0) {
71 // Show global formats available to roles because no format allowed boxes are checked.
72 $('select.bf-default-formats option').show();
73 }
74 }
75
76
77 $(document).ready(better_formats_init);

  ViewVC Help
Powered by ViewVC 1.1.2