This repository was archived by the owner on May 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjquery.bigBang.js
More file actions
84 lines (68 loc) · 2.32 KB
/
jquery.bigBang.js
File metadata and controls
84 lines (68 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* jQuery bigBang plugin.
*
* This is a small plugin, that will make an entire container link to the href
* of a containing link.
*
* The project and it's documentation is available at
* https://github.com/oddhill/bigBang
*
* Version 1.2.
*
* Development is sponsored by Odd Hill, www.oddhill.se.
*/
(function($) {
$.fn.bigBang = function(options) {
// Merge the default options with the ones provided.
var settings = $.extend({
selector: ".wrapper",
hoverClass: false,
cursor: "pointer",
blankTarget: "auto",
ignore: "a"
}, options);
return this.each(function() {
// Save the href of the anchor.
var href = $(this).attr("href");
// Check to see if the anchor should be opened in a new window.
var blankTarget = settings.blankTarget == "auto" ? $(this).attr("rel") == "_blank" : settings.blankTarget;
// Get the elements to ignore.
var ignore = settings.ignore ? settings.ignore.split(",") : false;
// Find the wrapper that we're looking for, using the specified selector
// from the settings.
var wrapper = $(this).closest(settings.selector);
if (!wrapper.length) {
// If we couldn't find a wrapper, bail out early.
return;
}
// Add the click event to the wrapper.
wrapper.click(function(event) {
// If the triggering element or one of it's parents inside the wrapper
// matches the ones we should be ignoring, don't do anything.
if (ignore && ($.inArray(event.target.tagName.toLowerCase(), ignore) != -1 || $(event.target).parentsUntil(settings.selector, ignore.join(",")).length > 0)) {
return;
}
if (blankTarget) {
// Open the href in a new window.
window.open(href);
}
else {
// Simply go to the href.
window.location = href;
}
});
// Add the specified class on hover.
if (settings.hoverClass) {
wrapper.hover(function() {
$(this).addClass(settings.hoverClass);
}, function() {
$(this).removeClass(settings.hoverClass);
});
}
// Set the specified cursor.
if (settings.cursor) {
wrapper.css("cursor", settings.cursor);
}
});
};
})(jQuery);