Projet

Général

Profil

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

root / drupal7 / sites / all / themes / bootstrap / js / modules / ctools / js / modal.js @ 87dbc3bf

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: .8,
31
        height: .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: .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

    
61
      if (Drupal.CTools.Modal.currentSettings.modalSize.type == 'scale') {
62
        var width = $(window).width() * Drupal.CTools.Modal.currentSettings.modalSize.width;
63
        var height = $(window).height() * Drupal.CTools.Modal.currentSettings.modalSize.height;
64
      }
65
      else {
66
        var width = Drupal.CTools.Modal.currentSettings.modalSize.width;
67
        var height = Drupal.CTools.Modal.currentSettings.modalSize.height;
68
      }
69

    
70
      // Use the additionol pixels for creating the width and height.
71
      $('div.ctools-modal-dialog', context).css({
72
        'width': width + Drupal.CTools.Modal.currentSettings.modalSize.addWidth + 'px',
73
        'height': height + Drupal.CTools.Modal.currentSettings.modalSize.addHeight + 'px'
74
      });
75
      $('div.ctools-modal-dialog .modal-body', context).css({
76
        'width': (width - Drupal.CTools.Modal.currentSettings.modalSize.contentRight) + 'px',
77
        'height': (height - Drupal.CTools.Modal.currentSettings.modalSize.contentBottom) + 'px'
78
      });
79
    }
80

    
81
    if (!Drupal.CTools.Modal.modal) {
82
      Drupal.CTools.Modal.modal = $(Drupal.theme(settings.modalTheme));
83
      if (settings.modalSize.type == 'scale') {
84
        $(window).bind('resize', resize);
85
      }
86
    }
87

    
88
    resize();
89

    
90
    $('.modal-title', Drupal.CTools.Modal.modal).html(Drupal.CTools.Modal.currentSettings.loadingText);
91
    Drupal.CTools.Modal.modalContent(Drupal.CTools.Modal.modal, settings.modalOptions, settings.animation, settings.animationSpeed);
92
    $('#modalContent .modal-body').html(Drupal.theme(settings.throbberTheme));
93
  };
94

    
95
  /**
96
   * Provide the HTML to create the modal dialog in the Bootstrap style.
97
   */
98
  Drupal.theme.prototype.CToolsModalDialog = function () {
99
    var html = ''
100
    html += '  <div id="ctools-modal">'
101
    html += '    <div class="ctools-modal-dialog">'
102
    html += '      <div class="modal-content">'
103
    html += '        <div class="modal-header">';
104
    html += '          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>';
105
    html += '          <h4 id="modal-title" class="modal-title">&nbsp;</h4>';
106
    html += '        </div>';
107
    html += '        <div id="modal-content" class="modal-body">';
108
    html += '        </div>';
109
    html += '      </div>';
110
    html += '    </div>';
111
    html += '  </div>';
112

    
113
    return html;
114
  }
115

    
116
  /**
117
   * Provide the HTML to create a nice looking loading progress bar.
118
   */
119
  Drupal.theme.prototype.CToolsModalThrobber = function () {
120
    var html = '';
121
    html += '  <div class="loading-spinner" style="width: 200px; margin: -20px 0 0 -100px; position: absolute; top: 45%; left: 50%">';
122
    html += '    <div class="progress progress-striped active">';
123
    html += '      <div class="progress-bar" style="width: 100%;"></div>';
124
    html += '    </div>';
125
    html += '  </div>';
126

    
127
    return html;
128
  };
129

    
130

    
131
})(jQuery);