Projet

Général

Profil

Paste
Télécharger (1,42 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / colorbox / js / colorbox_load.js @ a2bb1a14

1
(function ($) {
2

    
3
Drupal.behaviors.initColorboxLoad = {
4
  attach: function (context, settings) {
5
    if (!$.isFunction($.colorbox) || typeof settings.colorbox === 'undefined') {
6
      return;
7
    }
8

    
9
    if (settings.colorbox.mobiledetect && window.matchMedia) {
10
      // Disable Colorbox for small screens.
11
      var mq = window.matchMedia("(max-device-width: " + settings.colorbox.mobiledevicewidth + ")");
12
      if (mq.matches) {
13
        return;
14
      }
15
    }
16

    
17
    $.urlParams = function (url) {
18
      var p = {},
19
          e,
20
          a = /\+/g,  // Regex for replacing addition symbol with a space
21
          r = /([^&=]+)=?([^&]*)/g,
22
          d = function (s) { return decodeURIComponent(s.replace(a, ' ')); },
23
          q = url.split('?');
24
      while (e = r.exec(q[1])) {
25
        e[1] = d(e[1]);
26
        e[2] = d(e[2]);
27
        switch (e[2].toLowerCase()) {
28
          case 'true':
29
          case 'yes':
30
            e[2] = true;
31
            break;
32
          case 'false':
33
          case 'no':
34
            e[2] = false;
35
            break;
36
        }
37
        if (e[1] == 'width') { e[1] = 'innerWidth'; }
38
        if (e[1] == 'height') { e[1] = 'innerHeight'; }
39
        p[e[1]] = e[2];
40
      }
41
      return p;
42
    };
43
    $('.colorbox-load', context)
44
      .once('init-colorbox-load', function () {
45
        var params = $.urlParams($(this).attr('href'));
46
        $(this).colorbox($.extend({}, settings.colorbox, params));
47
      });
48
  }
49
};
50

    
51
})(jQuery);