Projet

Général

Profil

Paste
Télécharger (4,91 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / themes / bootstrap / js / modules / ctools / js / modal.js @ 4eeb3b46

1
/**
2
 * @file
3
 *
4
 * Overrides for ctools modal.
5
 *
6
 */
7

    
8
(function ($) {
9
  /**
10
   * Override CTools modal show function so it can recognize the Bootstrap modal classes correctly
11
   */
12
  Drupal.CTools.Modal.show = function(choice) {
13
    var opts = {};
14

    
15
    if (choice && typeof choice === 'string' && Drupal.settings[choice]) {
16
      // This notation guarantees we are actually copying it.
17
      $.extend(true, opts, Drupal.settings[choice]);
18
    }
19
    else if (choice) {
20
      $.extend(true, opts, choice);
21
    }
22

    
23
    var defaults = {
24
      modalTheme: 'CToolsModalDialog',
25
      throbberTheme: 'CToolsModalThrobber',
26
      animation: 'show',
27
      animationSpeed: 'fast',
28
      modalSize: {
29
        type: 'scale',
30
        width: 0.8,
31
        height: 0.8,
32
        addWidth: 0,
33
        addHeight: 0,
34
        // How much to remove from the inner content to make space for the
35
        // theming.
36
        contentRight: 25,
37
        contentBottom: 45
38
      },
39
      modalOptions: {
40
        opacity: 0.55,
41
        background: '#fff'
42
      }
43
    };
44

    
45
    var settings = {};
46
    $.extend(true, settings, defaults, Drupal.settings.CToolsModal, opts);
47

    
48
    if (Drupal.CTools.Modal.currentSettings && Drupal.CTools.Modal.currentSettings !== settings) {
49
      Drupal.CTools.Modal.modal.remove();
50
      Drupal.CTools.Modal.modal = null;
51
    }
52

    
53
    Drupal.CTools.Modal.currentSettings = settings;
54

    
55
    var resize = function(e) {
56
      // When creating the modal, it actually exists only in a theoretical
57
      // place that is not in the DOM. But once the modal exists, it is in the
58
      // DOM so the context must be set appropriately.
59
      var context = e ? document : Drupal.CTools.Modal.modal;
60
      var width = 0;
61
      var height = 0;
62

    
63
      //  Handle fixed navbars. Grab the body top offset in pixels.
64
      var topOffset = parseInt($('body').css("padding-top"), 10);
65

    
66
      if (Drupal.CTools.Modal.currentSettings.modalSize.type === 'scale') {
67
        width = $(window).width() * Drupal.CTools.Modal.currentSettings.modalSize.width;
68
        height = ($(window).height() - topOffset) * Drupal.CTools.Modal.currentSettings.modalSize.height;
69
      }
70
      else {
71
        width = Drupal.CTools.Modal.currentSettings.modalSize.width;
72
        height = Drupal.CTools.Modal.currentSettings.modalSize.height;
73
      }
74

    
75
      // Add padding for the offset.
76
      $('#modalContent').css('padding-top', topOffset + 'px');
77

    
78
      // Use the additionol pixels for creating the width and height.
79
      $('div.ctools-modal-dialog', context).css({
80
        'width': width + Drupal.CTools.Modal.currentSettings.modalSize.addWidth + 'px',
81
        'height': height + Drupal.CTools.Modal.currentSettings.modalSize.addHeight + 'px'
82
      });
83

    
84
      $('div.ctools-modal-dialog .modal-body', context).css({
85
        'width': (width - Drupal.CTools.Modal.currentSettings.modalSize.contentRight) + 'px',
86
        'max-height': (height - Drupal.CTools.Modal.currentSettings.modalSize.contentBottom) + 'px'
87
      });
88
    };
89

    
90
    if (!Drupal.CTools.Modal.modal) {
91
      Drupal.CTools.Modal.modal = $(Drupal.theme(settings.modalTheme));
92
      if (settings.modalSize.type === 'scale') {
93
        $(window).bind('resize', resize);
94
      }
95
    }
96

    
97
    $('body').addClass('modal-open');
98

    
99
    resize();
100

    
101
    $('.modal-title', Drupal.CTools.Modal.modal).html(Drupal.CTools.Modal.currentSettings.loadingText);
102
    Drupal.CTools.Modal.modalContent(Drupal.CTools.Modal.modal, settings.modalOptions, settings.animation, settings.animationSpeed);
103
    $('#modalContent .modal-body').html(Drupal.theme(settings.throbberTheme));
104
  };
105

    
106
  /**
107
   * Remove modal class from body when closing modal.
108
   */
109
  $(document).on('CToolsDetachBehaviors', function() {
110
    $('body').removeClass('modal-open');
111
  });
112

    
113
  /**
114
   * Provide the HTML to create the modal dialog in the Bootstrap style.
115
   */
116
  Drupal.theme.prototype.CToolsModalDialog = function () {
117
    var html = '';
118
    html += '<div id="ctools-modal">';
119
    html += '  <div class="ctools-modal-dialog modal-dialog">';
120
    html += '    <div class="modal-content">';
121
    html += '      <div class="modal-header">';
122
    html += '        <button type="button" class="close ctools-close-modal" aria-hidden="true">&times;</button>';
123
    html += '        <h4 id="modal-title" class="modal-title">&nbsp;</h4>';
124
    html += '      </div>';
125
    html += '      <div id="modal-content" class="modal-body">';
126
    html += '      </div>';
127
    html += '    </div>';
128
    html += '  </div>';
129
    html += '</div>';
130

    
131
    return html;
132
  };
133

    
134
  /**
135
   * Provide the HTML to create a nice looking loading progress bar.
136
   */
137
  Drupal.theme.prototype.CToolsModalThrobber = function () {
138
    var html = '';
139
    html += '<div class="loading-spinner" style="width: 200px; margin: -20px 0 0 -100px; position: absolute; top: 45%; left: 50%">';
140
    html += '  <div class="progress progress-striped active">';
141
    html += '    <div class="progress-bar" style="width: 100%;"></div>';
142
    html += '  </div>';
143
    html += '</div>';
144

    
145
    return html;
146
  };
147

    
148

    
149
})(jQuery);