slickgrid 2.3.16

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +20 -0
  4. data/README.md +30 -0
  5. data/lib/slickgrid.rb +6 -0
  6. data/lib/slickgrid/version.rb +3 -0
  7. data/slickgrid.gemspec +20 -0
  8. data/vendor/assets/images/slickgrid/CheckboxN.png +0 -0
  9. data/vendor/assets/images/slickgrid/CheckboxY.png +0 -0
  10. data/vendor/assets/images/slickgrid/GrpCheckboxN.png +0 -0
  11. data/vendor/assets/images/slickgrid/GrpCheckboxY.png +0 -0
  12. data/vendor/assets/images/slickgrid/actions.gif +0 -0
  13. data/vendor/assets/images/slickgrid/ajax-loader-small.gif +0 -0
  14. data/vendor/assets/images/slickgrid/arrow-right.gif +0 -0
  15. data/vendor/assets/images/slickgrid/arrow_redo.png +0 -0
  16. data/vendor/assets/images/slickgrid/arrow_right_peppermint.png +0 -0
  17. data/vendor/assets/images/slickgrid/arrow_right_spearmint.png +0 -0
  18. data/vendor/assets/images/slickgrid/arrow_undo.png +0 -0
  19. data/vendor/assets/images/slickgrid/bullet_blue.png +0 -0
  20. data/vendor/assets/images/slickgrid/bullet_star.png +0 -0
  21. data/vendor/assets/images/slickgrid/bullet_toggle_minus.png +0 -0
  22. data/vendor/assets/images/slickgrid/bullet_toggle_plus.png +0 -0
  23. data/vendor/assets/images/slickgrid/calendar.gif +0 -0
  24. data/vendor/assets/images/slickgrid/collapse.gif +0 -0
  25. data/vendor/assets/images/slickgrid/comment_yellow.gif +0 -0
  26. data/vendor/assets/images/slickgrid/delete.png +0 -0
  27. data/vendor/assets/images/slickgrid/down.gif +0 -0
  28. data/vendor/assets/images/slickgrid/drag-handle.png +0 -0
  29. data/vendor/assets/images/slickgrid/editor-helper-bg.gif +0 -0
  30. data/vendor/assets/images/slickgrid/expand.gif +0 -0
  31. data/vendor/assets/images/slickgrid/header-bg.gif +0 -0
  32. data/vendor/assets/images/slickgrid/header-columns-bg.gif +0 -0
  33. data/vendor/assets/images/slickgrid/header-columns-over-bg.gif +0 -0
  34. data/vendor/assets/images/slickgrid/help.png +0 -0
  35. data/vendor/assets/images/slickgrid/info.gif +0 -0
  36. data/vendor/assets/images/slickgrid/listview.gif +0 -0
  37. data/vendor/assets/images/slickgrid/pencil.gif +0 -0
  38. data/vendor/assets/images/slickgrid/row-over-bg.gif +0 -0
  39. data/vendor/assets/images/slickgrid/sort-asc.gif +0 -0
  40. data/vendor/assets/images/slickgrid/sort-asc.png +0 -0
  41. data/vendor/assets/images/slickgrid/sort-desc.gif +0 -0
  42. data/vendor/assets/images/slickgrid/sort-desc.png +0 -0
  43. data/vendor/assets/images/slickgrid/stripes.png +0 -0
  44. data/vendor/assets/images/slickgrid/tag_red.png +0 -0
  45. data/vendor/assets/images/slickgrid/tick.png +0 -0
  46. data/vendor/assets/images/slickgrid/user_identity.gif +0 -0
  47. data/vendor/assets/images/slickgrid/user_identity_plus.gif +0 -0
  48. data/vendor/assets/javascripts/slickgrid.js +5 -0
  49. data/vendor/assets/javascripts/slickgrid/controls/columnpicker.js +221 -0
  50. data/vendor/assets/javascripts/slickgrid/controls/gridmenu.js +429 -0
  51. data/vendor/assets/javascripts/slickgrid/controls/pager.js +154 -0
  52. data/vendor/assets/javascripts/slickgrid/core.js +493 -0
  53. data/vendor/assets/javascripts/slickgrid/dataview.js +1220 -0
  54. data/vendor/assets/javascripts/slickgrid/editors.js +640 -0
  55. data/vendor/assets/javascripts/slickgrid/formatters.js +65 -0
  56. data/vendor/assets/javascripts/slickgrid/grid.js +3990 -0
  57. data/vendor/assets/javascripts/slickgrid/groupitemmetadataprovider.js +172 -0
  58. data/vendor/assets/javascripts/slickgrid/plugins/autotooltips.js +83 -0
  59. data/vendor/assets/javascripts/slickgrid/plugins/cellcopymanager.js +88 -0
  60. data/vendor/assets/javascripts/slickgrid/plugins/cellexternalcopymanager.js +452 -0
  61. data/vendor/assets/javascripts/slickgrid/plugins/cellrangedecorator.js +72 -0
  62. data/vendor/assets/javascripts/slickgrid/plugins/cellrangeselector.js +123 -0
  63. data/vendor/assets/javascripts/slickgrid/plugins/cellselectionmodel.js +168 -0
  64. data/vendor/assets/javascripts/slickgrid/plugins/checkboxselectcolumn.js +202 -0
  65. data/vendor/assets/javascripts/slickgrid/plugins/draggablegrouping.js +207 -0
  66. data/vendor/assets/javascripts/slickgrid/plugins/headerbuttons.js +177 -0
  67. data/vendor/assets/javascripts/slickgrid/plugins/headermenu.js +296 -0
  68. data/vendor/assets/javascripts/slickgrid/plugins/rowdetailview.js +455 -0
  69. data/vendor/assets/javascripts/slickgrid/plugins/rowmovemanager.js +138 -0
  70. data/vendor/assets/javascripts/slickgrid/plugins/rowselectionmodel.js +191 -0
  71. data/vendor/assets/javascripts/slickgrid/remotemodel.js +169 -0
  72. data/vendor/assets/stylesheets/slickgrid.scss +1 -0
  73. data/vendor/assets/stylesheets/slickgrid/controls/columnpicker.css +46 -0
  74. data/vendor/assets/stylesheets/slickgrid/controls/gridmenu.css +113 -0
  75. data/vendor/assets/stylesheets/slickgrid/controls/pager.css +41 -0
  76. data/vendor/assets/stylesheets/slickgrid/default-theme.css +132 -0
  77. data/vendor/assets/stylesheets/slickgrid/grid.css +189 -0
  78. data/vendor/assets/stylesheets/slickgrid/plugins/headerbuttons.css +39 -0
  79. data/vendor/assets/stylesheets/slickgrid/plugins/headermenu.css +59 -0
  80. data/vendor/assets/stylesheets/slickgrid/plugins/rowdetailview.css +39 -0
  81. metadata +165 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 7467c2c1a0ed4d6ec9ea2bd605c227eb93d70b85
4
+ data.tar.gz: 0c682a3a226ea448f5e9f85c0017e25ad1162805
5
+ SHA512:
6
+ metadata.gz: 646d2fec1b237c76ce9098fca639b88571fe9e7aa6d4d23adce2f2b93c17d957122a1381f34d04d679d80a82a2f46a266ca7c0de7dcd6eb57eaef63c03f7e841
7
+ data.tar.gz: f41524941cc583cc6aba484aaed4ae64588b998aa65fb547a066291d9e58ed70b3398af50f087ec39f711cd757b228a139e32b42830fd4941efe7d9d68096e19
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+ gemspec
3
+
4
+ gem 'jquery-plugins-rails'
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,30 @@
1
+ # SlickGrid (6pac fork) Rails gem
2
+
3
+ Adds SlickGrid vendor assets to your Rails app. Tested on 5.1 but should work on 4+.
4
+
5
+ This uses the [6pac fork](https://github.com/6pac/SlickGrid) which is the most active fork of SlickGrid.
6
+
7
+
8
+ ## Installation
9
+
10
+ Add this to the Gemfile:
11
+
12
+ gem 'slickgrid'
13
+
14
+ Run
15
+
16
+ bundle
17
+
18
+ ## Usage
19
+
20
+ Add this to your application.js file
21
+
22
+ //= require slickgrid
23
+
24
+
25
+ If you need plugins or dataview or something else you can add it manually.
26
+
27
+ Examples:
28
+
29
+ //= require slickgrid/dataview
30
+ //= require slickgrid/controls/columnpicker
@@ -0,0 +1,6 @@
1
+ require "slickgrid/version"
2
+ require "jquery-plugins-rails"
3
+
4
+ module SlickGrid
5
+ class Engine < ::Rails::Engine; end
6
+ end
@@ -0,0 +1,3 @@
1
+ module SlickGrid
2
+ VERSION = '2.3.16'
3
+ end
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.name = "slickgrid"
3
+ gem.version = "2.3.16"
4
+ gem.authors = ["Erlingur Þorsteinsson"]
5
+ gem.email = ["erlingur@rsf.is"]
6
+ gem.description = %q{SlickGrid (6pac fork) gem for Rails}
7
+ gem.summary = %q{SlickGrid (6pac fork) gem for Rails}
8
+ gem.homepage = "https://github.com/Reiknistofa/slickgrid"
9
+ gem.license = "MIT"
10
+
11
+ gem.add_dependency "railties", ">= 3.0"
12
+
13
+ gem.add_dependency "jquery-plugins-rails", '~>0.2'
14
+ gem.add_dependency "jquery-rails", '~>4.0'
15
+
16
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ gem.files = `git ls-files`.split("\n")
18
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ gem.require_paths = ["lib"]
20
+ end
@@ -0,0 +1,5 @@
1
+ //= require jquery
2
+ //= require jquery/event/drag
3
+ //= require jquery/event/drop
4
+ //= require slickgrid/core
5
+ //= require slickgrid/grid
@@ -0,0 +1,221 @@
1
+ /***
2
+ * A control to add a Column Picker (right+click on any column header to reveal the column picker)
3
+ *
4
+ * USAGE:
5
+ *
6
+ * Add the slick.columnpicker.(js|css) files and register it with the grid.
7
+ *
8
+ * Available options, by defining a columnPicker object:
9
+ *
10
+ * var options = {
11
+ * enableCellNavigation: true,
12
+ * columnPicker: {
13
+ * columnTitle: "Columns", // default to empty string
14
+ *
15
+ * // the last 2 checkboxes titles
16
+ * hideForceFitButton: false, // show/hide checkbox near the end "Force Fit Columns" (default:false)
17
+ * hideSyncResizeButton: false, // show/hide checkbox near the end "Synchronous Resize" (default:false)
18
+ * forceFitTitle: "Force fit columns", // default to "Force fit columns"
19
+ * syncResizeTitle: "Synchronous resize", // default to "Synchronous resize"
20
+ * }
21
+ * };
22
+ *
23
+ * @class Slick.Controls.ColumnPicker
24
+ * @constructor
25
+ */
26
+
27
+ 'use strict';
28
+
29
+ (function ($) {
30
+ function SlickColumnPicker(columns, grid, options) {
31
+ var $list;
32
+ var $menu;
33
+ var columnCheckboxes;
34
+ var onColumnsChanged = new Slick.Event();
35
+
36
+ var defaults = {
37
+ fadeSpeed: 250,
38
+
39
+ // the last 2 checkboxes titles
40
+ hideForceFitButton: false,
41
+ hideSyncResizeButton: false,
42
+ forceFitTitle: "Force fit columns",
43
+ syncResizeTitle: "Synchronous resize"
44
+ };
45
+
46
+ function init() {
47
+ grid.onHeaderContextMenu.subscribe(handleHeaderContextMenu);
48
+ grid.onColumnsReordered.subscribe(updateColumnOrder);
49
+ options = $.extend({}, defaults, options);
50
+
51
+ $menu = $("<div class='slick-columnpicker' style='display:none' />").appendTo(document.body);
52
+ var $close = $("<button type='button' class='close' data-dismiss='slick-columnpicker' aria-label='Close'><span class='close' aria-hidden='true'>&times;</span></button>").appendTo($menu);
53
+
54
+ // user could pass a title on top of the columns list
55
+ if(options.columnPickerTitle || (options.columnPicker && options.columnPicker.columnTitle)) {
56
+ var columnTitle = options.columnPickerTitle || options.columnPicker.columnTitle;
57
+ var $title = $("<div class='title'/>").append(columnTitle);
58
+ $title.appendTo($menu);
59
+ }
60
+
61
+ $menu.on("click", updateColumn);
62
+ $list = $("<span class='slick-columnpicker-list' />");
63
+
64
+ // Hide the menu on outside click.
65
+ $(document.body).on("mousedown", handleBodyMouseDown);
66
+
67
+ // destroy the picker if user leaves the page
68
+ $(window).on("beforeunload", destroy);
69
+ }
70
+
71
+ function destroy() {
72
+ grid.onHeaderContextMenu.unsubscribe(handleHeaderContextMenu);
73
+ grid.onColumnsReordered.unsubscribe(updateColumnOrder);
74
+ $(document.body).off("mousedown", handleBodyMouseDown);
75
+ $("div.slick-columnpicker").hide(options.fadeSpeed);
76
+ $menu.remove();
77
+ }
78
+
79
+ function handleBodyMouseDown(e) {
80
+ if (($menu && $menu[0] != e.target && !$.contains($menu[0], e.target)) || e.target.className == "close") {
81
+ $menu.hide(options.fadeSpeed);
82
+ }
83
+ }
84
+
85
+ function handleHeaderContextMenu(e, args) {
86
+ e.preventDefault();
87
+ $list.empty();
88
+ updateColumnOrder();
89
+ columnCheckboxes = [];
90
+
91
+ var $li, $input;
92
+ for (var i = 0; i < columns.length; i++) {
93
+ $li = $("<li />").appendTo($list);
94
+ $input = $("<input type='checkbox' />").data("column-id", columns[i].id);
95
+ columnCheckboxes.push($input);
96
+
97
+ if (grid.getColumnIndex(columns[i].id) != null) {
98
+ $input.attr("checked", "checked");
99
+ }
100
+
101
+ $("<label />")
102
+ .html(columns[i].name)
103
+ .prepend($input)
104
+ .appendTo($li);
105
+ }
106
+
107
+ if (options.columnPicker && (!options.columnPicker.hideForceFitButton || !options.columnPicker.hideSyncResizeButton)) {
108
+ $("<hr/>").appendTo($list);
109
+ }
110
+
111
+ if (!(options.columnPicker && options.columnPicker.hideForceFitButton)) {
112
+ var forceFitTitle = (options.columnPicker && options.columnPicker.forceFitTitle) || options.forceFitTitle;
113
+ $li = $("<li />").appendTo($list);
114
+ $input = $("<input type='checkbox' />").data("option", "autoresize");
115
+ $("<label />")
116
+ .text(forceFitTitle)
117
+ .prepend($input)
118
+ .appendTo($li);
119
+ if (grid.getOptions().forceFitColumns) {
120
+ $input.attr("checked", "checked");
121
+ }
122
+ }
123
+
124
+ if (!(options.columnPicker && options.columnPicker.hideSyncResizeButton)) {
125
+ var syncResizeTitle = (options.columnPicker && options.columnPicker.syncResizeTitle) || options.syncResizeTitle;
126
+ $li = $("<li />").appendTo($list);
127
+ $input = $("<input type='checkbox' />").data("option", "syncresize");
128
+ $("<label />")
129
+ .text(syncResizeTitle)
130
+ .prepend($input)
131
+ .appendTo($li);
132
+ if (grid.getOptions().syncColumnCellResize) {
133
+ $input.attr("checked", "checked");
134
+ }
135
+ }
136
+
137
+ $menu
138
+ .css("top", e.pageY - 10)
139
+ .css("left", e.pageX - 10)
140
+ .css("max-height", $(window).height() - e.pageY -10)
141
+ .fadeIn(options.fadeSpeed);
142
+
143
+ $list.appendTo($menu);
144
+ }
145
+
146
+ function updateColumnOrder() {
147
+ // Because columns can be reordered, we have to update the `columns`
148
+ // to reflect the new order, however we can't just take `grid.getColumns()`,
149
+ // as it does not include columns currently hidden by the picker.
150
+ // We create a new `columns` structure by leaving currently-hidden
151
+ // columns in their original ordinal position and interleaving the results
152
+ // of the current column sort.
153
+ var current = grid.getColumns().slice(0);
154
+ var ordered = new Array(columns.length);
155
+ for (var i = 0; i < ordered.length; i++) {
156
+ if ( grid.getColumnIndex(columns[i].id) === undefined ) {
157
+ // If the column doesn't return a value from getColumnIndex,
158
+ // it is hidden. Leave it in this position.
159
+ ordered[i] = columns[i];
160
+ } else {
161
+ // Otherwise, grab the next visible column.
162
+ ordered[i] = current.shift();
163
+ }
164
+ }
165
+ columns = ordered;
166
+ }
167
+
168
+ function updateColumn(e) {
169
+ if ($(e.target).data("option") == "autoresize") {
170
+ if (e.target.checked) {
171
+ grid.setOptions({forceFitColumns:true});
172
+ grid.autosizeColumns();
173
+ } else {
174
+ grid.setOptions({forceFitColumns:false});
175
+ }
176
+ return;
177
+ }
178
+
179
+ if ($(e.target).data("option") == "syncresize") {
180
+ if (e.target.checked) {
181
+ grid.setOptions({syncColumnCellResize:true});
182
+ } else {
183
+ grid.setOptions({syncColumnCellResize:false});
184
+ }
185
+ return;
186
+ }
187
+
188
+ if ($(e.target).is(":checkbox")) {
189
+ var visibleColumns = [];
190
+ $.each(columnCheckboxes, function (i, e) {
191
+ if ($(this).is(":checked")) {
192
+ visibleColumns.push(columns[i]);
193
+ }
194
+ });
195
+
196
+ if (!visibleColumns.length) {
197
+ $(e.target).attr("checked", "checked");
198
+ return;
199
+ }
200
+
201
+ grid.setColumns(visibleColumns);
202
+ onColumnsChanged.notify({columns: visibleColumns, grid: grid});
203
+ }
204
+ }
205
+
206
+ function getAllColumns() {
207
+ return columns;
208
+ }
209
+
210
+ init();
211
+
212
+ return {
213
+ "getAllColumns": getAllColumns,
214
+ "destroy": destroy,
215
+ "onColumnsChanged": onColumnsChanged
216
+ };
217
+ }
218
+
219
+ // Slick.Controls.ColumnPicker
220
+ $.extend(true, window, { Slick:{ Controls:{ ColumnPicker:SlickColumnPicker }}});
221
+ })(jQuery);
@@ -0,0 +1,429 @@
1
+ /***
2
+ * A control to add a Grid Menu (hambuger menu on top-right of the grid)
3
+ *
4
+ * USAGE:
5
+ *
6
+ * Add the slick.gridmenu.(js|css) files and register it with the grid.
7
+ *
8
+ * To specify a menu in a column header, extend the column definition like so:
9
+ * var gridMenuControl = new Slick.Controls.GridMenu(columns, grid, options);
10
+ *
11
+ * Available grid options, by defining a gridMenu object:
12
+ *
13
+ * var options = {
14
+ * enableCellNavigation: true,
15
+ * gridMenu: {
16
+ * customTitle: "Custom Menus", // default to empty string
17
+ * columnTitle: "Columns", // default to empty string
18
+ * iconImage: "../slickgrid/drag-handle.png", // this is the Grid Menu icon (hamburger icon)
19
+ * iconCssClass: "fa fa-bars", // you can provide iconImage OR iconCssClass
20
+ * leaveOpen: false, // do we want to leave the Grid Menu open after a command execution? (false by default)
21
+ * menuWidth: 18, // width that will be use to resize the column header container (18 by default)
22
+ * resizeOnShowHeaderRow: true, // true by default
23
+ *
24
+ * // the last 2 checkboxes titles
25
+ * hideForceFitButton: false, // show/hide checkbox near the end "Force Fit Columns"
26
+ * hideSyncResizeButton: false, // show/hide checkbox near the end "Synchronous Resize"
27
+ * forceFitTitle: "Force fit columns", // default to "Force fit columns"
28
+ * syncResizeTitle: "Synchronous resize", // default to "Synchronous resize"
29
+ *
30
+ * customItems: [
31
+ * {
32
+ * // custom menu item options
33
+ * },
34
+ * {
35
+ * // custom menu item options
36
+ * }
37
+ * ]
38
+ * }
39
+ * };
40
+ *
41
+ *
42
+ * Available custom menu item options:
43
+ * title: Menu item text.
44
+ * disabled: Whether the item is disabled.
45
+ * tooltip: Item tooltip.
46
+ * command: A command identifier to be passed to the onCommand event handlers.
47
+ * iconCssClass: A CSS class to be added to the menu item icon.
48
+ * iconImage: A url to the icon image.
49
+ *
50
+ *
51
+ * The plugin exposes the following events:
52
+ * onBeforeMenuShow: Fired before the menu is shown. You can customize the menu or dismiss it by returning false.
53
+ * * ONLY works with a jQuery event (as per slick.core code), so we cannot notify when it's a button event (when grid menu is attached to an external button, not the hamburger menu)
54
+ * Event args:
55
+ * grid: Reference to the grid.
56
+ * column: Column definition.
57
+ * menu: Menu options. Note that you can change the menu items here.
58
+ *
59
+ * onMenuClose: Fired when the menu is closing.
60
+ * Event args:
61
+ * grid: Reference to the grid.
62
+ * column: Column definition.
63
+ * menu: Menu options. Note that you can change the menu items here.
64
+ *
65
+ * onCommand: Fired on menu item click for buttons with 'command' specified.
66
+ * Event args:
67
+ * grid: Reference to the grid.
68
+ * column: Column definition.
69
+ * command: Button command identified.
70
+ * button: Button options. Note that you can change the button options in your
71
+ * event handler, and the column header will be automatically updated to
72
+ * reflect them. This is useful if you want to implement something like a
73
+ * toggle button.
74
+ *
75
+ *
76
+ * @param options {Object} Options:
77
+ * buttonCssClass: an extra CSS class to add to the menu button
78
+ * buttonImage: a url to the menu button image (default '../slickgrid/down.gif')
79
+ * @class Slick.Controls.GridMenu
80
+ * @constructor
81
+ */
82
+
83
+ 'use strict';
84
+
85
+ (function ($) {
86
+ // register namespace
87
+ $.extend(true, window, {
88
+ "Slick": {
89
+ "Controls": {
90
+ "GridMenu": SlickGridMenu
91
+ }
92
+ }
93
+ });
94
+
95
+ function SlickGridMenu(columns, grid, options) {
96
+ var _grid = grid;
97
+ var _isMenuOpen = false;
98
+ var _options = options;
99
+ var _self = this;
100
+ var $list;
101
+ var $menu;
102
+ var columnCheckboxes;
103
+ var _defaults = {
104
+ hideForceFitButton: false,
105
+ hideSyncResizeButton: false,
106
+ fadeSpeed: 250,
107
+ forceFitTitle: "Force fit columns",
108
+ menuWidth: 18,
109
+ resizeOnShowHeaderRow: false,
110
+ syncResizeTitle: "Synchronous resize"
111
+ };
112
+
113
+ function init(grid) {
114
+ var gridMenuWidth = (_options.gridMenu && _options.gridMenu.menuWidth) || _defaults.menuWidth;
115
+ var $header = $('.slick-header');
116
+ $header.attr('style', 'width: calc(100% - ' + gridMenuWidth +'px)');
117
+
118
+ // if header row is enabled, we need to resize it's width also
119
+ var enableResizeHeaderRow = (_options.gridMenu && _options.gridMenu.resizeOnShowHeaderRow != undefined) ? _options.gridMenu.resizeOnShowHeaderRow : _defaults.resizeOnShowHeaderRow;
120
+ if(enableResizeHeaderRow) {
121
+ var $headerrow = $('.slick-headerrow');
122
+ $headerrow.attr('style', 'width: calc(100% - ' + gridMenuWidth +'px)');
123
+ }
124
+
125
+ var $button = $('<button class="slick-gridmenu-button"/>');
126
+ if (_options.gridMenu && _options.gridMenu.iconCssClass) {
127
+ $button.addClass(_options.gridMenu.iconCssClass);
128
+ } else {
129
+ var iconImage = (_options.gridMenu && _options.gridMenu.iconImage) ? _options.gridMenu.iconImage :"../slickgrid/drag-handle.png";
130
+ var $btnImage = $('<img src="' + iconImage + '"/>');
131
+ $btnImage.appendTo($button);
132
+ }
133
+ $button.insertBefore($header);
134
+
135
+ $menu = $('<div class="slick-gridmenu" style="display: none" />').appendTo(document.body);
136
+ var $close = $('<button type="button" class="close" data-dismiss="slick-gridmenu" aria-label="Close"><span class="close" aria-hidden="true">&times;</span></button>').appendTo($menu);
137
+
138
+ var $customMenu = $('<div class="slick-gridmenu-custom" />');
139
+ $customMenu.appendTo($menu);
140
+
141
+ // user could pass a title on top of the custom section
142
+ if(_options.gridMenu && _options.gridMenu.customTitle) {
143
+ var $title = $('<div class="title"/>').append(_options.gridMenu.customTitle);
144
+ $title.appendTo($customMenu);
145
+ }
146
+
147
+ populateCustomMenus(_options, $customMenu);
148
+ populateColumnPicker();
149
+
150
+ // Hide the menu on outside click.
151
+ $(document.body).on("mousedown", handleBodyMouseDown);
152
+
153
+ // destroy the picker if user leaves the page
154
+ $(window).on("beforeunload", destroy);
155
+
156
+ // add on click handler for the Grid Menu itself
157
+ $button.on("click", showGridMenu);
158
+ }
159
+
160
+ function destroy() {
161
+ _self.onBeforeMenuShow.unsubscribe();
162
+ _self.onMenuClose.unsubscribe();
163
+ _self.onCommand.unsubscribe();
164
+ _self.onColumnsChanged.unsubscribe();
165
+ _grid.onColumnsReordered.unsubscribe(updateColumnOrder);
166
+ $(document.body).off("mousedown", handleBodyMouseDown);
167
+ $("div.slick-gridmenu").hide(_options.fadeSpeed);
168
+ $menu.remove();
169
+ }
170
+
171
+ function populateCustomMenus(options, $customMenu) {
172
+ // Construct the custom menu items.
173
+ if(!options.gridMenu || !options.gridMenu.customItems) {
174
+ return;
175
+ }
176
+ for (var i = 0, ln = options.gridMenu.customItems.length; i < ln; i++) {
177
+ var item = options.gridMenu.customItems[i];
178
+
179
+ var $li = $("<div class='slick-gridmenu-item'></div>")
180
+ .data("command", item.command || '')
181
+ .data("item", item)
182
+ .on("click", handleMenuItemClick)
183
+ .appendTo($customMenu);
184
+
185
+ if (item.disabled) {
186
+ $li.addClass("slick-gridmenu-item-disabled");
187
+ }
188
+
189
+ if (item.tooltip) {
190
+ $li.attr("title", item.tooltip);
191
+ }
192
+
193
+ var $icon = $("<div class='slick-gridmenu-icon'></div>")
194
+ .appendTo($li);
195
+
196
+ if (item.iconCssClass) {
197
+ $icon.addClass(item.iconCssClass);
198
+ }
199
+
200
+ if (item.iconImage) {
201
+ $icon.css("background-image", "url(" + item.iconImage + ")");
202
+ }
203
+
204
+ var $content = $("<span class='slick-gridmenu-content'></span>")
205
+ .text(item.title)
206
+ .appendTo($li);
207
+ }
208
+ }
209
+
210
+ /** Build the column picker, the code comes almost untouched from the file "slick.columnpicker.js" */
211
+ function populateColumnPicker() {
212
+ _grid.onColumnsReordered.subscribe(updateColumnOrder);
213
+ _options = $.extend({}, _defaults, _options);
214
+
215
+ // user could pass a title on top of the columns list
216
+ if(_options.gridMenu && _options.gridMenu.columnTitle) {
217
+ var $title = $('<div class="title"/>').append(_options.gridMenu.columnTitle);
218
+ $title.appendTo($menu);
219
+ }
220
+
221
+ $menu.on("click", updateColumn);
222
+ $list = $('<span class="slick-gridmenu-list" />');
223
+ }
224
+
225
+ function showGridMenu(e) {
226
+ e.preventDefault();
227
+ $list.empty();
228
+
229
+ updateColumnOrder();
230
+ columnCheckboxes = [];
231
+
232
+ // notify of the onBeforeMenuShow only works when it's a jQuery event (as per slick.core code)
233
+ // this mean that we cannot notify when the grid menu is attach to a button event
234
+ if(typeof e.isPropagationStopped === "function") {
235
+ if (_self.onBeforeMenuShow.notify({
236
+ "grid": _grid,
237
+ "menu": $menu
238
+ }, e, _self) == false) {
239
+ return;
240
+ }
241
+ }
242
+
243
+ var $li, $input;
244
+ for (var i = 0; i < columns.length; i++) {
245
+ $li = $("<li />").appendTo($list);
246
+ $input = $("<input type='checkbox' />").data("column-id", columns[i].id);
247
+ columnCheckboxes.push($input);
248
+
249
+ if (_grid.getColumnIndex(columns[i].id) != null) {
250
+ $input.attr("checked", "checked");
251
+ }
252
+
253
+ $("<label />")
254
+ .html(columns[i].name)
255
+ .prepend($input)
256
+ .appendTo($li);
257
+ }
258
+
259
+ if (_options.gridMenu && (!_options.gridMenu.hideForceFitButton || !_options.gridMenu.hideSyncResizeButton)) {
260
+ $("<hr/>").appendTo($list);
261
+ }
262
+
263
+ if (!(_options.gridMenu && _options.gridMenu.hideForceFitButton)) {
264
+ var forceFitTitle = (_options.gridMenu && _options.gridMenu.forceFitTitle) || _defaults.forceFitTitle;
265
+ $li = $("<li />").appendTo($list);
266
+ $input = $("<input type='checkbox' />").data("option", "autoresize");
267
+ $("<label />")
268
+ .text(forceFitTitle)
269
+ .prepend($input)
270
+ .appendTo($li);
271
+ if (_grid.getOptions().forceFitColumns) {
272
+ $input.attr("checked", "checked");
273
+ }
274
+ }
275
+
276
+ if (!(_options.gridMenu && _options.gridMenu.hideSyncResizeButton)) {
277
+ var syncResizeTitle = (_options.gridMenu && _options.gridMenu.syncResizeTitle) || _defaults.syncResizeTitle;
278
+ $li = $("<li />").appendTo($list);
279
+ $input = $("<input type='checkbox' />").data("option", "syncresize");
280
+ $("<label />")
281
+ .text(syncResizeTitle)
282
+ .prepend($input)
283
+ .appendTo($li);
284
+ if (_grid.getOptions().syncColumnCellResize) {
285
+ $input.attr("checked", "checked");
286
+ }
287
+ }
288
+
289
+ var gridMenuWidth = $menu.width();
290
+
291
+ $menu
292
+ .css("top", e.pageY + 10)
293
+ .css("left", e.pageX - $menu.width())
294
+ .css("max-height", $(window).height() - e.pageY -10)
295
+ .fadeIn(_options.fadeSpeed);
296
+
297
+ $list.appendTo($menu);
298
+ }
299
+
300
+ function handleBodyMouseDown(e) {
301
+ if (($menu && $menu[0] != e.target && !$.contains($menu[0], e.target) && _isMenuOpen) || e.target.className == "close") {
302
+ hideMenu(e);
303
+ } else {
304
+ _isMenuOpen = true;
305
+ }
306
+ }
307
+
308
+ function handleMenuItemClick(e) {
309
+ var command = $(this).data("command");
310
+ var item = $(this).data("item");
311
+
312
+ if (item.disabled) {
313
+ return;
314
+ }
315
+
316
+ // does the user want to leave open the Grid Menu after executing a command?
317
+ var leaveOpen = (_options.gridMenu && _options.gridMenu.leaveOpen) ? true : false;
318
+ if(!leaveOpen) {
319
+ hideMenu(e);
320
+ }
321
+
322
+ if (command != null && command != '') {
323
+ _self.onCommand.notify({
324
+ "grid": _grid,
325
+ "command": command,
326
+ "item": item
327
+ }, e, _self);
328
+ }
329
+
330
+ // Stop propagation so that it doesn't register as a header click event.
331
+ e.preventDefault();
332
+ e.stopPropagation();
333
+ }
334
+
335
+ function hideMenu(e) {
336
+ if ($menu) {
337
+ $menu.hide(_options.fadeSpeed);
338
+ _isMenuOpen = false;
339
+
340
+ if (_self.onMenuClose.notify({
341
+ "grid": _grid,
342
+ "menu": $menu
343
+ }, e, _self) == false) {
344
+ return;
345
+ }
346
+ }
347
+ }
348
+
349
+ function updateColumnOrder() {
350
+ // Because columns can be reordered, we have to update the `columns`
351
+ // to reflect the new order, however we can't just take `grid.getColumns()`,
352
+ // as it does not include columns currently hidden by the picker.
353
+ // We create a new `columns` structure by leaving currently-hidden
354
+ // columns in their original ordinal position and interleaving the results
355
+ // of the current column sort.
356
+ var current = _grid.getColumns().slice(0);
357
+ var ordered = new Array(columns.length);
358
+ for (var i = 0; i < ordered.length; i++) {
359
+ if ( _grid.getColumnIndex(columns[i].id) === undefined ) {
360
+ // If the column doesn't return a value from getColumnIndex,
361
+ // it is hidden. Leave it in this position.
362
+ ordered[i] = columns[i];
363
+ } else {
364
+ // Otherwise, grab the next visible column.
365
+ ordered[i] = current.shift();
366
+ }
367
+ }
368
+ columns = ordered;
369
+ }
370
+
371
+ function updateColumn(e) {
372
+ if ($(e.target).data("option") == "autoresize") {
373
+ if (e.target.checked) {
374
+ _grid.setOptions({forceFitColumns:true});
375
+ _grid.autosizeColumns();
376
+ } else {
377
+ _grid.setOptions({forceFitColumns:false});
378
+ }
379
+ return;
380
+ }
381
+
382
+ if ($(e.target).data("option") == "syncresize") {
383
+ if (e.target.checked) {
384
+ _grid.setOptions({syncColumnCellResize:true});
385
+ } else {
386
+ _grid.setOptions({syncColumnCellResize:false});
387
+ }
388
+ return;
389
+ }
390
+
391
+ if ($(e.target).is(":checkbox")) {
392
+ var visibleColumns = [];
393
+ $.each(columnCheckboxes, function (i, e) {
394
+ if ($(this).is(":checked")) {
395
+ visibleColumns.push(columns[i]);
396
+ }
397
+ });
398
+
399
+ if (!visibleColumns.length) {
400
+ $(e.target).attr("checked", "checked");
401
+ return;
402
+ }
403
+
404
+ _grid.setColumns(visibleColumns);
405
+ _self.onColumnsChanged.notify({
406
+ "grid": _grid,
407
+ "columns": visibleColumns
408
+ }, e, _self);
409
+ }
410
+ }
411
+
412
+ init(_grid);
413
+
414
+ function getAllColumns() {
415
+ return columns;
416
+ }
417
+
418
+ $.extend(this, {
419
+ "init": init,
420
+ "getAllColumns": getAllColumns,
421
+ "destroy": destroy,
422
+ "showGridMenu": showGridMenu,
423
+ "onBeforeMenuShow": new Slick.Event(),
424
+ "onMenuClose": new Slick.Event(),
425
+ "onCommand": new Slick.Event(),
426
+ "onColumnsChanged": new Slick.Event()
427
+ });
428
+ }
429
+ })(jQuery);