3 * Some basic behaviors and utility functions for Views.
10 * jQuery UI tabs, Views integration component
12 Drupal
.behaviors
.viewsTabs
= {
13 attach: function (context
) {
14 if ($.viewsUi
&& $.viewsUi
.tabs
) {
15 $('#views-tabset').once('views-processed').viewsTabs({
16 selectedClass
: 'active'
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();
27 * Here is to handle display deletion
28 * (checking in the hidden checkbox and hiding out the row)
30 $('a.display-remove-link')
31 .addClass('display-processed')
33 var id
= $(this).attr('id').replace('display-remove-link-', '');
34 $('#display-row-' + id
).hide();
35 $('#display-removed-' + id
).attr('checked', true);
42 * Helper function to parse a querystring.
44 Drupal
.Views
.parseQueryString = function (query
) {
46 var pos
= query
.indexOf('?');
48 query
= query
.substring(pos
+ 1);
50 var pairs
= query
.split('&');
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, ' '));
64 * Helper function to return a view's arguments based on a path.
66 Drupal
.Views
.parseViewArgs = function (href
, viewPath
) {
68 // Provide language prefix.
69 if (Drupal
.settings
.pathPrefix
) {
70 var viewPath
= Drupal
.settings
.pathPrefix
+ viewPath
;
73 var path
= Drupal
.Views
.getPath(href
);
74 // Ensure we have a correct path.
75 if (viewPath
&& path
.substring(0, viewPath
.length
+ 1) == viewPath
+ '/') {
76 var args
= decodeURIComponent(path
.substring(viewPath
.length
+ 1, path
.length
));
77 returnObj
.view_args
= args
;
78 returnObj
.view_path
= path
;
84 * Strip off the protocol plus domain from an href.
86 Drupal
.Views
.pathPortion = function (href
) {
87 // Remove e.g. http://example.com if present.
88 var protocol
= window
.location
.protocol
;
89 if (href
.substring(0, protocol
.length
) == protocol
) {
90 // 2 is the length of the '//' that normally follows the protocol
91 href
= href
.substring(href
.indexOf('/', protocol
.length
+ 2));
97 * Return the Drupal path portion of an href.
99 Drupal
.Views
.getPath = function (href
) {
100 href
= Drupal
.Views
.pathPortion(href
);
101 href
= href
.substring(Drupal
.settings
.basePath
.length
, href
.length
);
102 // 3 is the length of the '?q=' added to the url without clean urls.
103 if (href
.substring(0, 3) == '?q=') {
104 href
= href
.substring(3, href
.length
);
106 var chars
= ['#', '?', '&'];
108 if (href
.indexOf(chars
[i
]) > -1) {
109 href
= href
.substr(0, href
.indexOf(chars
[i
]));