| 1 |
// $Id: base.js,v 1.10 2009/01/27 22:11:26 merlinofchaos Exp $
|
| 2 |
/**
|
| 3 |
* @file base.js
|
| 4 |
*
|
| 5 |
* Some basic behaviors and utility functions for Views.
|
| 6 |
*/
|
| 7 |
|
| 8 |
Drupal.Views = {};
|
| 9 |
|
| 10 |
/**
|
| 11 |
* jQuery UI tabs, Views integration component
|
| 12 |
*/
|
| 13 |
Drupal.behaviors.viewsTabs = function (context) {
|
| 14 |
if ($.ui && $.ui.tabs) {
|
| 15 |
$('#views-tabset:not(.views-processed)').addClass('views-processed').tabs({
|
| 16 |
selectedClass: 'active'
|
| 17 |
});
|
| 18 |
}
|
| 19 |
|
| 20 |
$('a.views-remove-link')
|
| 21 |
.addClass('views-processed')
|
| 22 |
.click(function() {
|
| 23 |
var id = $(this).attr('id').replace('views-remove-link-', '');
|
| 24 |
$('#views-row-' + id).hide();
|
| 25 |
$('#views-removed-' + id).attr('checked', true);
|
| 26 |
return false;
|
| 27 |
});
|
| 28 |
}
|
| 29 |
|
| 30 |
/**
|
| 31 |
* For IE, attach some javascript so that our hovers do what they're supposed
|
| 32 |
* to do.
|
| 33 |
*/
|
| 34 |
Drupal.behaviors.viewsHoverlinks = function() {
|
| 35 |
if ($.browser.msie) {
|
| 36 |
// If IE, attach a hover event so we can see our admin links.
|
| 37 |
$("div.view:not(.views-hover-processed)").addClass('views-hover-processed').hover(
|
| 38 |
function() {
|
| 39 |
$('div.views-hide', this).addClass("views-hide-hover"); return true;
|
| 40 |
},
|
| 41 |
function(){
|
| 42 |
$('div.views-hide', this).removeClass("views-hide-hover"); return true;
|
| 43 |
}
|
| 44 |
);
|
| 45 |
$("div.views-admin-links:not(.views-hover-processed)")
|
| 46 |
.addClass('views-hover-processed')
|
| 47 |
.hover(
|
| 48 |
function() {
|
| 49 |
$(this).addClass("views-admin-links-hover"); return true;
|
| 50 |
},
|
| 51 |
function(){
|
| 52 |
$(this).removeClass("views-admin-links-hover"); return true;
|
| 53 |
}
|
| 54 |
);
|
| 55 |
}
|
| 56 |
}
|
| 57 |
|
| 58 |
/**
|
| 59 |
* Helper function to parse a querystring.
|
| 60 |
*/
|
| 61 |
Drupal.Views.parseQueryString = function (query) {
|
| 62 |
var args = {};
|
| 63 |
var pos = query.indexOf('?');
|
| 64 |
if (pos != -1) {
|
| 65 |
query = query.substring(pos + 1);
|
| 66 |
}
|
| 67 |
var pairs = query.split('&');
|
| 68 |
for(var i in pairs) {
|
| 69 |
var pair = pairs[i].split('=');
|
| 70 |
// Ignore the 'q' path argument, if present.
|
| 71 |
if (pair[0] != 'q' && pair[1]) {
|
| 72 |
args[pair[0]] = decodeURIComponent(pair[1].replace(/\+/g, ' '));
|
| 73 |
}
|
| 74 |
}
|
| 75 |
return args;
|
| 76 |
};
|
| 77 |
|
| 78 |
/**
|
| 79 |
* Helper function to return a view's arguments based on a path.
|
| 80 |
*/
|
| 81 |
Drupal.Views.parseViewArgs = function (href, viewPath) {
|
| 82 |
var returnObj = {};
|
| 83 |
var path = Drupal.Views.getPath(href);
|
| 84 |
// Ensure we have a correct path.
|
| 85 |
if (viewPath && path.substring(0, viewPath.length + 1) == viewPath + '/') {
|
| 86 |
var args = decodeURIComponent(path.substring(viewPath.length + 1, path.length));
|
| 87 |
returnObj.view_args = args;
|
| 88 |
returnObj.view_path = path;
|
| 89 |
}
|
| 90 |
return returnObj;
|
| 91 |
};
|
| 92 |
|
| 93 |
/**
|
| 94 |
* Strip off the protocol plus domain from an href.
|
| 95 |
*/
|
| 96 |
Drupal.Views.pathPortion = function (href) {
|
| 97 |
// Remove e.g. http://example.com if present.
|
| 98 |
var protocol = window.location.protocol;
|
| 99 |
if (href.substring(0, protocol.length) == protocol) {
|
| 100 |
// 2 is the length of the '//' that normally follows the protocol
|
| 101 |
href = href.substring(href.indexOf('/', protocol.length + 2));
|
| 102 |
}
|
| 103 |
return href;
|
| 104 |
};
|
| 105 |
|
| 106 |
/**
|
| 107 |
* Return the Drupal path portion of an href.
|
| 108 |
*/
|
| 109 |
Drupal.Views.getPath = function (href) {
|
| 110 |
href = Drupal.Views.pathPortion(href);
|
| 111 |
href = href.substring(Drupal.settings.basePath.length, href.length);
|
| 112 |
// 3 is the length of the '?q=' added to the url without clean urls.
|
| 113 |
if (href.substring(0, 3) == '?q=') {
|
| 114 |
href = href.substring(3, href.length);
|
| 115 |
}
|
| 116 |
var chars = ['#', '?', '&'];
|
| 117 |
for (i in chars) {
|
| 118 |
if (href.indexOf(chars[i]) > -1) {
|
| 119 |
href = href.substr(0, href.indexOf(chars[i]));
|
| 120 |
}
|
| 121 |
}
|
| 122 |
return href;
|
| 123 |
};
|