UNPKG

2.01 kBJavaScriptView Raw
1(function ($) {
2 // register namespace
3 $.extend(true, window, {
4 "Slick": {
5 "CellRangeDecorator": CellRangeDecorator
6 }
7 });
8
9 /***
10 * Displays an overlay on top of a given cell range.
11 *
12 * TODO:
13 * Currently, it blocks mouse events to DOM nodes behind it.
14 * Use FF and WebKit-specific "pointer-events" CSS style, or some kind of event forwarding.
15 * Could also construct the borders separately using 4 individual DIVs.
16 *
17 * @param {Grid} grid
18 * @param {Object} options
19 */
20 function CellRangeDecorator(grid, options) {
21 var _elem;
22 var _defaults = {
23 selectionCssClass: 'slick-range-decorator',
24 selectionCss: {
25 "zIndex": "9999",
26 "border": "2px dashed red"
27 },
28 offset: {
29 top: -1,
30 left: -1,
31 height: -2,
32 width: -2
33 }
34 };
35
36 options = $.extend(true, {}, _defaults, options);
37
38
39 function show(range) {
40 if (!_elem) {
41 _elem = $("<div></div>", {css: options.selectionCss})
42 .addClass(options.selectionCssClass)
43 .css("position", "absolute")
44 .appendTo(grid.getActiveCanvasNode());
45 }
46
47 var from = grid.getCellNodeBox(range.fromRow, range.fromCell);
48 var to = grid.getCellNodeBox(range.toRow, range.toCell);
49
50 if (from && to && options && options.offset) {
51 _elem.css({
52 top: from.top + options.offset.top,
53 left: from.left + options.offset.left,
54 height: to.bottom - from.top + options.offset.height,
55 width: to.right - from.left + options.offset.width
56 });
57 }
58
59 return _elem;
60 }
61
62 function destroy() {
63 hide();
64 }
65
66 function hide() {
67 if (_elem) {
68 _elem.remove();
69 _elem = null;
70 }
71 }
72
73 $.extend(this, {
74 "pluginName": "CellRangeDecorator",
75 "show": show,
76 "hide": hide,
77 "destroy": destroy
78 });
79 }
80})(jQuery);