Projet

Général

Profil

Paste
Télécharger (3,01 ko) Statistiques
| Branche: | Révision:

root / htmltest / sites / all / modules / views / js / base.js @ a5572547

1
/**
2
 * @file
3
 * Some basic behaviors and utility functions for Views.
4
 */
5
(function ($) {
6

    
7
Drupal.Views = {};
8

    
9
/**
10
 * jQuery UI tabs, Views integration component
11
 */
12
Drupal.behaviors.viewsTabs = {
13
  attach: function (context) {
14
    if ($.viewsUi && $.viewsUi.tabs) {
15
      $('#views-tabset').once('views-processed').viewsTabs({
16
        selectedClass: 'active'
17
      });
18
    }
19

    
20
    $('a.views-remove-link').once('views-processed').click(function(event) {
21
      var id = $(this).attr('id').replace('views-remove-link-', '');
22
      $('#views-row-' + id).hide();
23
      $('#views-removed-' + id).attr('checked', true);
24
      event.preventDefault();
25
   });
26
  /**
27
    * Here is to handle display deletion
28
    * (checking in the hidden checkbox and hiding out the row)
29
    */
30
  $('a.display-remove-link')
31
    .addClass('display-processed')
32
    .click(function() {
33
      var id = $(this).attr('id').replace('display-remove-link-', '');
34
      $('#display-row-' + id).hide();
35
      $('#display-removed-' + id).attr('checked', true);
36
      return false;
37
  });
38
  }
39
};
40

    
41
/**
42
 * Helper function to parse a querystring.
43
 */
44
Drupal.Views.parseQueryString = function (query) {
45
  var args = {};
46
  var pos = query.indexOf('?');
47
  if (pos != -1) {
48
    query = query.substring(pos + 1);
49
  }
50
  var pairs = query.split('&');
51
  for(var i in pairs) {
52
    if (typeof(pairs[i]) == 'string') {
53
      var pair = pairs[i].split('=');
54
      // Ignore the 'q' path argument, if present.
55
      if (pair[0] != 'q' && pair[1]) {
56
        args[decodeURIComponent(pair[0].replace(/\+/g, ' '))] = decodeURIComponent(pair[1].replace(/\+/g, ' '));
57
      }
58
    }
59
  }
60
  return args;
61
};
62

    
63
/**
64
 * Helper function to return a view's arguments based on a path.
65
 */
66
Drupal.Views.parseViewArgs = function (href, viewPath) {
67
  var returnObj = {};
68
  var path = Drupal.Views.getPath(href);
69
  // Ensure we have a correct path.
70
  if (viewPath && path.substring(0, viewPath.length + 1) == viewPath + '/') {
71
    var args = decodeURIComponent(path.substring(viewPath.length + 1, path.length));
72
    returnObj.view_args = args;
73
    returnObj.view_path = path;
74
  }
75
  return returnObj;
76
};
77

    
78
/**
79
 * Strip off the protocol plus domain from an href.
80
 */
81
Drupal.Views.pathPortion = function (href) {
82
  // Remove e.g. http://example.com if present.
83
  var protocol = window.location.protocol;
84
  if (href.substring(0, protocol.length) == protocol) {
85
    // 2 is the length of the '//' that normally follows the protocol
86
    href = href.substring(href.indexOf('/', protocol.length + 2));
87
  }
88
  return href;
89
};
90

    
91
/**
92
 * Return the Drupal path portion of an href.
93
 */
94
Drupal.Views.getPath = function (href) {
95
  href = Drupal.Views.pathPortion(href);
96
  href = href.substring(Drupal.settings.basePath.length, href.length);
97
  // 3 is the length of the '?q=' added to the url without clean urls.
98
  if (href.substring(0, 3) == '?q=') {
99
    href = href.substring(3, href.length);
100
  }
101
  var chars = ['#', '?', '&'];
102
  for (i in chars) {
103
    if (href.indexOf(chars[i]) > -1) {
104
      href = href.substr(0, href.indexOf(chars[i]));
105
    }
106
  }
107
  return href;
108
};
109

    
110
})(jQuery);