slickgrid added to third-party
[myslice.git] / third-party / slickgrid-2.1 / plugins / slick.cellrangedecorator.js
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       selectionCss: {
24         "zIndex": "9999",
25         "border": "2px dashed red"
26       }
27     };
28
29     options = $.extend(true, {}, _defaults, options);
30
31
32     function show(range) {
33       if (!_elem) {
34         _elem = $("<div></div>", {css: options.selectionCss})
35             .css("position", "absolute")
36             .appendTo(grid.getCanvasNode());
37       }
38
39       var from = grid.getCellNodeBox(range.fromRow, range.fromCell);
40       var to = grid.getCellNodeBox(range.toRow, range.toCell);
41
42       _elem.css({
43         top: from.top - 1,
44         left: from.left - 1,
45         height: to.bottom - from.top - 2,
46         width: to.right - from.left - 2
47       });
48
49       return _elem;
50     }
51
52     function hide() {
53       if (_elem) {
54         _elem.remove();
55         _elem = null;
56       }
57     }
58
59     $.extend(this, {
60       "show": show,
61       "hide": hide
62     });
63   }
64 })(jQuery);