Projet

Général

Profil

Paste
Télécharger (7,15 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / themes / bootstrap / js / bootstrap.admin.js @ 7547bb19

1
(function ($, Drupal) {
2
  /*global jQuery:false */
3
  /*global Drupal:false */
4
  "use strict";
5

    
6
  /**
7
   * Provide vertical tab summaries for Bootstrap settings.
8
   */
9
  Drupal.behaviors.bootstrapSettingSummaries = {
10
    attach: function (context) {
11
      var $context = $(context);
12

    
13
      // General.
14
      $context.find('#edit-general').drupalSetSummary(function () {
15
        var summary = [];
16
        // Buttons.
17
        var size = $context.find('select[name="bootstrap_button_size"] :selected');
18
        if (size.val()) {
19
          summary.push(Drupal.t('@size Buttons', {
20
            '@size': size.text()
21
          }));
22
        }
23

    
24
        // Images.
25
        var shape = $context.find('select[name="bootstrap_image_shape"] :selected');
26
        if (shape.val()) {
27
          summary.push(Drupal.t('@shape Images', {
28
            '@shape': shape.text()
29
          }));
30
        }
31
        if ($context.find(':input[name="bootstrap_image_responsive"]').is(':checked')) {
32
          summary.push(Drupal.t('Responsive Images'));
33
        }
34

    
35
        // Tables.
36
        if ($context.find(':input[name="bootstrap_table_responsive"]').is(':checked')) {
37
          summary.push(Drupal.t('Responsive Tables'));
38
        }
39

    
40
        return summary.join(', ');
41

    
42
      });
43

    
44
      // Components.
45
      $context.find('#edit-components').drupalSetSummary(function () {
46
        var summary = [];
47
        // Breadcrumbs.
48
        var breadcrumb = parseInt($context.find('select[name="bootstrap_breadcrumb"]').val(), 10);
49
        if (breadcrumb) {
50
          summary.push(Drupal.t('Breadcrumbs'));
51
        }
52
        // Navbar.
53
        var navbar = 'Navbar: ' + $context.find('select[name="bootstrap_navbar_position"] :selected').text();
54
        if ($context.find('input[name="bootstrap_navbar_inverse"]').is(':checked')) {
55
          navbar += ' (' + Drupal.t('Inverse') + ')';
56
        }
57
        summary.push(navbar);
58
        return summary.join(', ');
59
      });
60

    
61
      // Javascript.
62
      $context.find('#edit-javascript').drupalSetSummary(function () {
63
        var summary = [];
64
        if ($context.find('input[name="bootstrap_anchors_fix"]').is(':checked')) {
65
          summary.push(Drupal.t('Anchors'));
66
        }
67
        if ($context.find('input[name="bootstrap_popover_enabled"]').is(':checked')) {
68
          summary.push(Drupal.t('Popovers'));
69
        }
70
        if ($context.find('input[name="bootstrap_tooltip_enabled"]').is(':checked')) {
71
          summary.push(Drupal.t('Tooltips'));
72
        }
73
        return summary.join(', ');
74
      });
75

    
76
      // Advanced.
77
      $context.find('#edit-advanced').drupalSetSummary(function () {
78
        var summary = [];
79
        var $cdnProvider = $context.find('select[name="bootstrap_cdn_provider"] :selected');
80
        var cdnProvider = $cdnProvider.val();
81
        if ($cdnProvider.length && cdnProvider.length) {
82
          summary.push(Drupal.t('CDN provider: %provider', { '%provider': $cdnProvider.text() }));
83

    
84
          // jsDelivr CDN.
85
          if (cdnProvider === 'jsdelivr') {
86
            var $jsDelivrVersion = $context.find('select[name="bootstrap_cdn_jsdelivr_version"] :selected');
87
            if ($jsDelivrVersion.length && $jsDelivrVersion.val().length) {
88
              summary.push($jsDelivrVersion.text());
89
            }
90
            var $jsDelivrTheme = $context.find('select[name="bootstrap_cdn_jsdelivr_theme"] :selected');
91
            if ($jsDelivrTheme.length && $jsDelivrTheme.val() !== 'bootstrap') {
92
              summary.push($jsDelivrTheme.text());
93
            }
94
          }
95
        }
96
        return summary.join(', ');
97
      });
98
    }
99
  };
100

    
101
  /**
102
   * Provide BootstrapCDN (via jsDelivr) theme preview.
103
   */
104
  Drupal.behaviors.bootstrapThemePreview = {
105
    attach: function (context) {
106
      var $context = $(context);
107
      var $preview = $context.find('#bootstrap-theme-preview');
108
      $preview.once('bootstrap-theme-preview', function () {
109
        // Construct the "Bootstrap Theme" preview here since it's not actually
110
        // a Bootswatch theme, but rather one provided by Bootstrap itself.
111
        // Unfortunately getbootstrap.com does not have HTTPS enabled, so the
112
        // preview image cannot be protocol relative.
113
        // @todo Make protocol relative if/when Bootstrap enables HTTPS.
114
        $preview.append('<a id="bootstrap-theme-preview-bootstrap_theme" class="bootswatch-preview element-invisible" href="http://getbootstrap.com/examples/theme/" target="_blank"><img class="img-responsive" src="http://getbootstrap.com/examples/screenshots/theme.jpg" alt="' + Drupal.t('Preview of the Bootstrap theme') + '" /></a>');
115

    
116
        // Retrieve the Bootswatch theme preview images.
117
        // @todo This should be moved into PHP.
118
        $.ajax({
119
          url: 'https://bootswatch.com/api/3.json',
120
          dataType: 'json',
121
          success: function (json) {
122
            var themes = json.themes;
123
            for (var i = 0, len = themes.length; i < len; i++) {
124
              $preview.append('<a id="bootstrap-theme-preview-' + themes[i].name.toLowerCase() + '" class="bootswatch-preview element-invisible" href="' + themes[i].preview + '" target="_blank"><img class="img-responsive" src="' + themes[i].thumbnail.replace(/^http:/, 'https:') + '" alt="' + Drupal.t('Preview of the @title Bootswatch theme', { '@title': themes[i].name }) + '" /></a>');
125
            }
126
          },
127
          complete: function () {
128
            $preview.parent().find('select[name="bootstrap_cdn_jsdelivr_theme"]').bind('change', function () {
129
              $preview.find('.bootswatch-preview').addClass('element-invisible');
130
              if ($(this).val().length) {
131
                $preview.find('#bootstrap-theme-preview-' + $(this).val()).removeClass('element-invisible');
132
              }
133
            }).change();
134
          }
135
        });
136
      });
137
    }
138
  };
139

    
140
  /**
141
   * Provide Bootstrap navbar preview.
142
   */
143
  Drupal.behaviors.bootstrapNavbarPreview = {
144
    attach: function (context) {
145
      var $context = $(context);
146
      var $preview = $context.find('#edit-navbar');
147
      $preview.once('navbar', function () {
148
        var $body = $context.find('body');
149
        var $navbar = $context.find('#navbar.navbar');
150
        $preview.find('select[name="bootstrap_navbar_position"]').bind('change', function () {
151
          var $position = $(this).find(':selected').val();
152
          $navbar.removeClass('navbar-fixed-bottom navbar-fixed-top navbar-static-top container');
153
          if ($position.length) {
154
            $navbar.addClass('navbar-'+ $position);
155
          }
156
          else {
157
            $navbar.addClass('container');
158
          }
159
          // Apply appropriate classes to body.
160
          $body.removeClass('navbar-is-fixed-top navbar-is-fixed-bottom navbar-is-static-top');
161
          switch ($position) {
162
            case 'fixed-top':
163
              $body.addClass('navbar-is-fixed-top');
164
              break;
165

    
166
            case 'fixed-bottom':
167
              $body.addClass('navbar-is-fixed-bottom');
168
              break;
169

    
170
            case 'static-top':
171
              $body.addClass('navbar-is-static-top');
172
              break;
173
          }
174
        });
175
        $preview.find('input[name="bootstrap_navbar_inverse"]').bind('change', function () {
176
          $navbar.toggleClass('navbar-inverse navbar-default');
177
        });
178
      });
179
    }
180
  };
181

    
182
})(jQuery, Drupal);