|
23 | 23 | this.$element = $(element)
|
24 | 24 | this.options = $.extend({}, Rowlink.DEFAULTS, options)
|
25 | 25 |
|
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)) |
27 | 27 | }
|
28 | 28 |
|
29 | 29 | Rowlink.DEFAULTS = {
|
30 | 30 | target: "a"
|
31 | 31 | }
|
32 | 32 |
|
33 |
| - Rowlink.prototype.click = function(e) { |
| 33 | + Rowlink.prototype.click = function(e, ctrlKey) { |
34 | 34 | var target = $(e.currentTarget).closest('tr').find(this.options.target)[0]
|
| 35 | + |
35 | 36 | if ($(e.target)[0] === target) return
|
| 37 | + if (e.type === 'mouseup' && e.which !== 2) return |
36 | 38 |
|
37 | 39 | e.preventDefault();
|
| 40 | + ctrlKey = ctrlKey || e.ctrlKey || (e.type === 'mouseup' && e.which === 2) |
38 | 41 |
|
39 |
| - if (target.click) { |
| 42 | + if (!ctrlKey && target.click) { |
40 | 43 | target.click()
|
41 | 44 | } else if (document.createEvent) {
|
42 | 45 | 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); |
44 | 47 | target.dispatchEvent(evt);
|
45 | 48 | }
|
46 | 49 | }
|
|
74 | 77 | // ROWLINK DATA-API
|
75 | 78 | // ==================
|
76 | 79 |
|
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 |
78 | 82 | if ($(e.target).closest('.rowlink-skip').length !== 0) return
|
79 | 83 |
|
80 | 84 | var $this = $(this)
|
81 | 85 | if ($this.data('bs.rowlink')) return
|
82 | 86 | $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]) |
84 | 90 | })
|
85 | 91 |
|
86 | 92 | }(window.jQuery);
|
0 commit comments