Projet

Général

Profil

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

root / drupal7 / sites / all / themes / bootstrap / js / bootstrap.admin.js @ 749b8a23

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
        $.ajax({
118
          url: '//api.bootswatch.com/3/',
119
          dataType: 'json',
120
          success: function (json) {
121
            var themes = json.themes;
122
            for (var i = 0, len = themes.length; i < len; i++) {
123
              $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>');
124
            }
125
          },
126
          complete: function () {
127
            $preview.parent().find('select[name="bootstrap_cdn_jsdelivr_theme"]').bind('change', function () {
128
              $preview.find('.bootswatch-preview').addClass('element-invisible');
129
              if ($(this).val().length) {
130
                $preview.find('#bootstrap-theme-preview-' + $(this).val()).removeClass('element-invisible');
131
              }
132
            }).change();
133
          }
134
        });
135
      });
136
    }
137
  };
138

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

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

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

    
181
})(jQuery, Drupal);