Skip to content

Commit 1ee0865

Browse files
committed
Allow open rowlink with ctrl/middle-mouse click (fixes #422)
1 parent c34f648 commit 1ee0865

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

js/rowlink.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,27 @@
2323
this.$element = $(element)
2424
this.options = $.extend({}, Rowlink.DEFAULTS, options)
2525

26-
this.$element.on('click.bs.rowlink', 'td:not(.rowlink-skip)', $.proxy(this.click, this))
26+
this.$element.on('click.bs.rowlink mouseup.bs.rowlink', 'td:not(.rowlink-skip)', $.proxy(this.click, this))
2727
}
2828

2929
Rowlink.DEFAULTS = {
3030
target: "a"
3131
}
3232

33-
Rowlink.prototype.click = function(e) {
33+
Rowlink.prototype.click = function(e, ctrlKey) {
3434
var target = $(e.currentTarget).closest('tr').find(this.options.target)[0]
35+
3536
if ($(e.target)[0] === target) return
37+
if (e.type === 'mouseup' && e.which !== 2) return
3638

3739
e.preventDefault();
40+
ctrlKey = ctrlKey || e.ctrlKey || (e.type === 'mouseup' && e.which === 2)
3841

39-
if (target.click) {
42+
if (!ctrlKey && target.click) {
4043
target.click()
4144
} else if (document.createEvent) {
4245
var evt = document.createEvent("MouseEvents");
43-
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
46+
evt.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, ctrlKey, false, false, false, 0, null);
4447
target.dispatchEvent(evt);
4548
}
4649
}
@@ -74,13 +77,16 @@
7477
// ROWLINK DATA-API
7578
// ==================
7679

77-
$(document).on('click.bs.rowlink.data-api', '[data-link="row"]', function (e) {
80+
$(document).on('click.bs.rowlink.data-api mouseup.bs.rowlink.data-api', '[data-link="row"]', function (e) {
81+
if (e.type === 'mouseup' && e.which !== 2) return
7882
if ($(e.target).closest('.rowlink-skip').length !== 0) return
7983

8084
var $this = $(this)
8185
if ($this.data('bs.rowlink')) return
8286
$this.rowlink($this.data())
83-
$(e.target).trigger('click.bs.rowlink')
87+
88+
var ctrlKey = e.ctrlKey || e.which === 2
89+
$(e.target).trigger('click.bs.rowlink', [ctrlKey])
8490
})
8591

8692
}(window.jQuery);

0 commit comments

Comments
 (0)