jquery-datatables 1.10.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (143) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +27 -0
  5. data/README.md +118 -0
  6. data/Rakefile +166 -0
  7. data/app/assets/images/datatables/sort_asc.png +0 -0
  8. data/app/assets/images/datatables/sort_asc_disabled.png +0 -0
  9. data/app/assets/images/datatables/sort_both.png +0 -0
  10. data/app/assets/images/datatables/sort_desc.png +0 -0
  11. data/app/assets/images/datatables/sort_desc_disabled.png +0 -0
  12. data/app/assets/javascripts/datatables/dataTables.bootstrap.js +182 -0
  13. data/app/assets/javascripts/datatables/dataTables.bootstrap4.js +184 -0
  14. data/app/assets/javascripts/datatables/dataTables.foundation.js +174 -0
  15. data/app/assets/javascripts/datatables/dataTables.jqueryui.js +164 -0
  16. data/app/assets/javascripts/datatables/dataTables.material.js +191 -0
  17. data/app/assets/javascripts/datatables/dataTables.semanticui.js +208 -0
  18. data/app/assets/javascripts/datatables/dataTables.uikit.js +176 -0
  19. data/app/assets/javascripts/datatables/extensions/AutoFill/autoFill.bootstrap.js +43 -0
  20. data/app/assets/javascripts/datatables/extensions/AutoFill/autoFill.bootstrap4.js +43 -0
  21. data/app/assets/javascripts/datatables/extensions/AutoFill/autoFill.foundation.js +43 -0
  22. data/app/assets/javascripts/datatables/extensions/AutoFill/autoFill.jqueryui.js +43 -0
  23. data/app/assets/javascripts/datatables/extensions/AutoFill/autoFill.semanticui.js +43 -0
  24. data/app/assets/javascripts/datatables/extensions/AutoFill/dataTables.autoFill.js +1036 -0
  25. data/app/assets/javascripts/datatables/extensions/Buttons/buttons.bootstrap.js +68 -0
  26. data/app/assets/javascripts/datatables/extensions/Buttons/buttons.bootstrap4.js +60 -0
  27. data/app/assets/javascripts/datatables/extensions/Buttons/buttons.colVis.js +199 -0
  28. data/app/assets/javascripts/datatables/extensions/Buttons/buttons.flash.js +1325 -0
  29. data/app/assets/javascripts/datatables/extensions/Buttons/buttons.foundation.js +85 -0
  30. data/app/assets/javascripts/datatables/extensions/Buttons/buttons.html5.js +1322 -0
  31. data/app/assets/javascripts/datatables/extensions/Buttons/buttons.jqueryui.js +62 -0
  32. data/app/assets/javascripts/datatables/extensions/Buttons/buttons.print.js +172 -0
  33. data/app/assets/javascripts/datatables/extensions/Buttons/buttons.semanticui.js +57 -0
  34. data/app/assets/javascripts/datatables/extensions/Buttons/dataTables.buttons.js +1634 -0
  35. data/app/assets/javascripts/datatables/extensions/ColReorder/dataTables.colReorder.js +1335 -0
  36. data/app/assets/javascripts/datatables/extensions/FixedColumns/dataTables.fixedColumns.js +1623 -0
  37. data/app/assets/javascripts/datatables/extensions/FixedHeader/dataTables.fixedHeader.js +672 -0
  38. data/app/assets/javascripts/datatables/extensions/KeyTable/dataTables.keyTable.js +883 -0
  39. data/app/assets/javascripts/datatables/extensions/Responsive/dataTables.responsive.js +1232 -0
  40. data/app/assets/javascripts/datatables/extensions/Responsive/responsive.bootstrap.js +81 -0
  41. data/app/assets/javascripts/datatables/extensions/Responsive/responsive.bootstrap4.js +81 -0
  42. data/app/assets/javascripts/datatables/extensions/Responsive/responsive.foundation.js +62 -0
  43. data/app/assets/javascripts/datatables/extensions/Responsive/responsive.jqueryui.js +63 -0
  44. data/app/assets/javascripts/datatables/extensions/Responsive/responsive.semanticui.js +77 -0
  45. data/app/assets/javascripts/datatables/extensions/RowReorder/dataTables.rowReorder.js +709 -0
  46. data/app/assets/javascripts/datatables/extensions/Scroller/dataTables.scroller.js +1349 -0
  47. data/app/assets/javascripts/datatables/extensions/Select/dataTables.select.js +1109 -0
  48. data/app/assets/javascripts/datatables/jquery.dataTables.js +15278 -0
  49. data/app/assets/media/swf/flashExport.swf +0 -0
  50. data/app/assets/stylesheets/datatables/dataTables.bootstrap.css +185 -0
  51. data/app/assets/stylesheets/datatables/dataTables.bootstrap4.css +193 -0
  52. data/app/assets/stylesheets/datatables/dataTables.foundation.css +116 -0
  53. data/app/assets/stylesheets/datatables/dataTables.jqueryui.css +481 -0
  54. data/app/assets/stylesheets/datatables/dataTables.material.css +87 -0
  55. data/app/assets/stylesheets/datatables/dataTables.semanticui.css +103 -0
  56. data/app/assets/stylesheets/datatables/dataTables.uikit.css +146 -0
  57. data/app/assets/stylesheets/datatables/extensions/AutoFill/autoFill.bootstrap.css +81 -0
  58. data/app/assets/stylesheets/datatables/extensions/AutoFill/autoFill.bootstrap4.css +81 -0
  59. data/app/assets/stylesheets/datatables/extensions/AutoFill/autoFill.dataTables.css +92 -0
  60. data/app/assets/stylesheets/datatables/extensions/AutoFill/autoFill.foundation.css +85 -0
  61. data/app/assets/stylesheets/datatables/extensions/AutoFill/autoFill.jqueryui.css +85 -0
  62. data/app/assets/stylesheets/datatables/extensions/AutoFill/autoFill.semanticui.css +81 -0
  63. data/app/assets/stylesheets/datatables/extensions/Buttons/buttons.bootstrap.css +102 -0
  64. data/app/assets/stylesheets/datatables/extensions/Buttons/buttons.bootstrap4.css +163 -0
  65. data/app/assets/stylesheets/datatables/extensions/Buttons/buttons.dataTables.css +298 -0
  66. data/app/assets/stylesheets/datatables/extensions/Buttons/buttons.foundation.css +129 -0
  67. data/app/assets/stylesheets/datatables/extensions/Buttons/buttons.jqueryui.css +162 -0
  68. data/app/assets/stylesheets/datatables/extensions/Buttons/buttons.semanticui.css +114 -0
  69. data/app/assets/stylesheets/datatables/extensions/Buttons/common.scss +27 -0
  70. data/app/assets/stylesheets/datatables/extensions/Buttons/mixins.scss +89 -0
  71. data/app/assets/stylesheets/datatables/extensions/ColReorder/colReorder.bootstrap.css +11 -0
  72. data/app/assets/stylesheets/datatables/extensions/ColReorder/colReorder.bootstrap4.css +11 -0
  73. data/app/assets/stylesheets/datatables/extensions/ColReorder/colReorder.dataTables.css +11 -0
  74. data/app/assets/stylesheets/datatables/extensions/ColReorder/colReorder.foundation.css +11 -0
  75. data/app/assets/stylesheets/datatables/extensions/ColReorder/colReorder.jqueryui.css +11 -0
  76. data/app/assets/stylesheets/datatables/extensions/ColReorder/colReorder.semanticui.css +11 -0
  77. data/app/assets/stylesheets/datatables/extensions/FixedColumns/fixedColumns.bootstrap.css +44 -0
  78. data/app/assets/stylesheets/datatables/extensions/FixedColumns/fixedColumns.bootstrap4.css +44 -0
  79. data/app/assets/stylesheets/datatables/extensions/FixedColumns/fixedColumns.dataTables.css +18 -0
  80. data/app/assets/stylesheets/datatables/extensions/FixedColumns/fixedColumns.foundation.css +27 -0
  81. data/app/assets/stylesheets/datatables/extensions/FixedColumns/fixedColumns.jqueryui.css +8 -0
  82. data/app/assets/stylesheets/datatables/extensions/FixedColumns/fixedColumns.semanticui.css +16 -0
  83. data/app/assets/stylesheets/datatables/extensions/FixedHeader/fixedHeader.bootstrap.css +20 -0
  84. data/app/assets/stylesheets/datatables/extensions/FixedHeader/fixedHeader.bootstrap4.css +20 -0
  85. data/app/assets/stylesheets/datatables/extensions/FixedHeader/fixedHeader.dataTables.css +19 -0
  86. data/app/assets/stylesheets/datatables/extensions/FixedHeader/fixedHeader.foundation.css +20 -0
  87. data/app/assets/stylesheets/datatables/extensions/FixedHeader/fixedHeader.jqueryui.css +15 -0
  88. data/app/assets/stylesheets/datatables/extensions/FixedHeader/fixedHeader.semanticui.css +14 -0
  89. data/app/assets/stylesheets/datatables/extensions/KeyTable/keyTable.bootstrap.css +5 -0
  90. data/app/assets/stylesheets/datatables/extensions/KeyTable/keyTable.bootstrap4.css +5 -0
  91. data/app/assets/stylesheets/datatables/extensions/KeyTable/keyTable.dataTables.css +5 -0
  92. data/app/assets/stylesheets/datatables/extensions/KeyTable/keyTable.foundation.css +5 -0
  93. data/app/assets/stylesheets/datatables/extensions/KeyTable/keyTable.jqueryui.css +5 -0
  94. data/app/assets/stylesheets/datatables/extensions/KeyTable/keyTable.semanticui.css +5 -0
  95. data/app/assets/stylesheets/datatables/extensions/Responsive/responsive.bootstrap.css +181 -0
  96. data/app/assets/stylesheets/datatables/extensions/Responsive/responsive.bootstrap4.css +181 -0
  97. data/app/assets/stylesheets/datatables/extensions/Responsive/responsive.dataTables.css +178 -0
  98. data/app/assets/stylesheets/datatables/extensions/Responsive/responsive.foundation.css +181 -0
  99. data/app/assets/stylesheets/datatables/extensions/Responsive/responsive.jqueryui.css +178 -0
  100. data/app/assets/stylesheets/datatables/extensions/Responsive/responsive.semanticui.css +181 -0
  101. data/app/assets/stylesheets/datatables/extensions/RowReorder/rowReorder.bootstrap.css +22 -0
  102. data/app/assets/stylesheets/datatables/extensions/RowReorder/rowReorder.bootstrap4.css +22 -0
  103. data/app/assets/stylesheets/datatables/extensions/RowReorder/rowReorder.dataTables.css +22 -0
  104. data/app/assets/stylesheets/datatables/extensions/RowReorder/rowReorder.foundation.css +22 -0
  105. data/app/assets/stylesheets/datatables/extensions/RowReorder/rowReorder.jqueryui.css +22 -0
  106. data/app/assets/stylesheets/datatables/extensions/RowReorder/rowReorder.semanticui.css +22 -0
  107. data/app/assets/stylesheets/datatables/extensions/RowReorder/semanticui.scss +5 -0
  108. data/app/assets/stylesheets/datatables/extensions/Scroller/scroller.bootstrap.css +24 -0
  109. data/app/assets/stylesheets/datatables/extensions/Scroller/scroller.bootstrap4.css +24 -0
  110. data/app/assets/stylesheets/datatables/extensions/Scroller/scroller.dataTables.css +20 -0
  111. data/app/assets/stylesheets/datatables/extensions/Scroller/scroller.foundation.css +17 -0
  112. data/app/assets/stylesheets/datatables/extensions/Scroller/scroller.jqueryui.css +20 -0
  113. data/app/assets/stylesheets/datatables/extensions/Scroller/scroller.semanticui.css +20 -0
  114. data/app/assets/stylesheets/datatables/extensions/Select/select.bootstrap.css +110 -0
  115. data/app/assets/stylesheets/datatables/extensions/Select/select.bootstrap4.css +110 -0
  116. data/app/assets/stylesheets/datatables/extensions/Select/select.dataTables.css +100 -0
  117. data/app/assets/stylesheets/datatables/extensions/Select/select.foundation.css +112 -0
  118. data/app/assets/stylesheets/datatables/extensions/Select/select.jqueryui.css +100 -0
  119. data/app/assets/stylesheets/datatables/extensions/Select/select.semanticui.css +105 -0
  120. data/app/assets/stylesheets/datatables/jquery.dataTables.css +452 -0
  121. data/app/assets/stylesheets/datatables/jquery.dataTables_themeroller.css +416 -0
  122. data/jquery-datatables.gemspec +27 -0
  123. data/lib/generators/jquery/datatables/install_generator.rb +63 -0
  124. data/lib/generators/jquery/datatables/templates/bootstrap.css.tt +15 -0
  125. data/lib/generators/jquery/datatables/templates/bootstrap.js.tt +22 -0
  126. data/lib/generators/jquery/datatables/templates/bootstrap4.css.tt +15 -0
  127. data/lib/generators/jquery/datatables/templates/bootstrap4.js.tt +22 -0
  128. data/lib/generators/jquery/datatables/templates/foundation.css.tt +15 -0
  129. data/lib/generators/jquery/datatables/templates/foundation.js.tt +24 -0
  130. data/lib/generators/jquery/datatables/templates/jqueryui.css.tt +15 -0
  131. data/lib/generators/jquery/datatables/templates/jqueryui.js.tt +18 -0
  132. data/lib/generators/jquery/datatables/templates/material.css.tt +15 -0
  133. data/lib/generators/jquery/datatables/templates/material.js.tt +19 -0
  134. data/lib/generators/jquery/datatables/templates/regular.css.tt +15 -0
  135. data/lib/generators/jquery/datatables/templates/regular.js.tt +18 -0
  136. data/lib/generators/jquery/datatables/templates/semanticui.css.tt +16 -0
  137. data/lib/generators/jquery/datatables/templates/semanticui.js.tt +22 -0
  138. data/lib/generators/jquery/datatables/templates/uikit.css.tt +15 -0
  139. data/lib/generators/jquery/datatables/templates/uikit.js.tt +19 -0
  140. data/lib/jquery-datatables.rb +26 -0
  141. data/lib/jquery-datatables/engine.rb +11 -0
  142. data/lib/jquery-datatables/version.rb +6 -0
  143. metadata +269 -0
@@ -0,0 +1,1335 @@
1
+ /*! ColReorder 1.3.2
2
+ * ©2010-2015 SpryMedia Ltd - datatables.net/license
3
+ */
4
+
5
+ /**
6
+ * @summary ColReorder
7
+ * @description Provide the ability to reorder columns in a DataTable
8
+ * @version 1.3.2
9
+ * @file dataTables.colReorder.js
10
+ * @author SpryMedia Ltd (www.sprymedia.co.uk)
11
+ * @contact www.sprymedia.co.uk/contact
12
+ * @copyright Copyright 2010-2014 SpryMedia Ltd.
13
+ *
14
+ * This source file is free software, available under the following license:
15
+ * MIT license - http://datatables.net/license/mit
16
+ *
17
+ * This source file is distributed in the hope that it will be useful, but
18
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
19
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the license files for details.
20
+ *
21
+ * For details please refer to: http://www.datatables.net
22
+ */
23
+ (function( factory ){
24
+ if ( typeof define === 'function' && define.amd ) {
25
+ // AMD
26
+ define( ['jquery', 'datatables.net'], function ( $ ) {
27
+ return factory( $, window, document );
28
+ } );
29
+ }
30
+ else if ( typeof exports === 'object' ) {
31
+ // CommonJS
32
+ module.exports = function (root, $) {
33
+ if ( ! root ) {
34
+ root = window;
35
+ }
36
+
37
+ if ( ! $ || ! $.fn.dataTable ) {
38
+ $ = require('datatables.net')(root, $).$;
39
+ }
40
+
41
+ return factory( $, root, root.document );
42
+ };
43
+ }
44
+ else {
45
+ // Browser
46
+ factory( jQuery, window, document );
47
+ }
48
+ }(function( $, window, document, undefined ) {
49
+ 'use strict';
50
+ var DataTable = $.fn.dataTable;
51
+
52
+
53
+ /**
54
+ * Switch the key value pairing of an index array to be value key (i.e. the old value is now the
55
+ * key). For example consider [ 2, 0, 1 ] this would be returned as [ 1, 2, 0 ].
56
+ * @method fnInvertKeyValues
57
+ * @param array aIn Array to switch around
58
+ * @returns array
59
+ */
60
+ function fnInvertKeyValues( aIn )
61
+ {
62
+ var aRet=[];
63
+ for ( var i=0, iLen=aIn.length ; i<iLen ; i++ )
64
+ {
65
+ aRet[ aIn[i] ] = i;
66
+ }
67
+ return aRet;
68
+ }
69
+
70
+
71
+ /**
72
+ * Modify an array by switching the position of two elements
73
+ * @method fnArraySwitch
74
+ * @param array aArray Array to consider, will be modified by reference (i.e. no return)
75
+ * @param int iFrom From point
76
+ * @param int iTo Insert point
77
+ * @returns void
78
+ */
79
+ function fnArraySwitch( aArray, iFrom, iTo )
80
+ {
81
+ var mStore = aArray.splice( iFrom, 1 )[0];
82
+ aArray.splice( iTo, 0, mStore );
83
+ }
84
+
85
+
86
+ /**
87
+ * Switch the positions of nodes in a parent node (note this is specifically designed for
88
+ * table rows). Note this function considers all element nodes under the parent!
89
+ * @method fnDomSwitch
90
+ * @param string sTag Tag to consider
91
+ * @param int iFrom Element to move
92
+ * @param int Point to element the element to (before this point), can be null for append
93
+ * @returns void
94
+ */
95
+ function fnDomSwitch( nParent, iFrom, iTo )
96
+ {
97
+ var anTags = [];
98
+ for ( var i=0, iLen=nParent.childNodes.length ; i<iLen ; i++ )
99
+ {
100
+ if ( nParent.childNodes[i].nodeType == 1 )
101
+ {
102
+ anTags.push( nParent.childNodes[i] );
103
+ }
104
+ }
105
+ var nStore = anTags[ iFrom ];
106
+
107
+ if ( iTo !== null )
108
+ {
109
+ nParent.insertBefore( nStore, anTags[iTo] );
110
+ }
111
+ else
112
+ {
113
+ nParent.appendChild( nStore );
114
+ }
115
+ }
116
+
117
+
118
+ /**
119
+ * Plug-in for DataTables which will reorder the internal column structure by taking the column
120
+ * from one position (iFrom) and insert it into a given point (iTo).
121
+ * @method $.fn.dataTableExt.oApi.fnColReorder
122
+ * @param object oSettings DataTables settings object - automatically added by DataTables!
123
+ * @param int iFrom Take the column to be repositioned from this point
124
+ * @param int iTo and insert it into this point
125
+ * @param bool drop Indicate if the reorder is the final one (i.e. a drop)
126
+ * not a live reorder
127
+ * @param bool invalidateRows speeds up processing if false passed
128
+ * @returns void
129
+ */
130
+ $.fn.dataTableExt.oApi.fnColReorder = function ( oSettings, iFrom, iTo, drop, invalidateRows )
131
+ {
132
+ var i, iLen, j, jLen, jen, iCols=oSettings.aoColumns.length, nTrs, oCol;
133
+ var attrMap = function ( obj, prop, mapping ) {
134
+ if ( ! obj[ prop ] || typeof obj[ prop ] === 'function' ) {
135
+ return;
136
+ }
137
+
138
+ var a = obj[ prop ].split('.');
139
+ var num = a.shift();
140
+
141
+ if ( isNaN( num*1 ) ) {
142
+ return;
143
+ }
144
+
145
+ obj[ prop ] = mapping[ num*1 ]+'.'+a.join('.');
146
+ };
147
+
148
+ /* Sanity check in the input */
149
+ if ( iFrom == iTo )
150
+ {
151
+ /* Pointless reorder */
152
+ return;
153
+ }
154
+
155
+ if ( iFrom < 0 || iFrom >= iCols )
156
+ {
157
+ this.oApi._fnLog( oSettings, 1, "ColReorder 'from' index is out of bounds: "+iFrom );
158
+ return;
159
+ }
160
+
161
+ if ( iTo < 0 || iTo >= iCols )
162
+ {
163
+ this.oApi._fnLog( oSettings, 1, "ColReorder 'to' index is out of bounds: "+iTo );
164
+ return;
165
+ }
166
+
167
+ /*
168
+ * Calculate the new column array index, so we have a mapping between the old and new
169
+ */
170
+ var aiMapping = [];
171
+ for ( i=0, iLen=iCols ; i<iLen ; i++ )
172
+ {
173
+ aiMapping[i] = i;
174
+ }
175
+ fnArraySwitch( aiMapping, iFrom, iTo );
176
+ var aiInvertMapping = fnInvertKeyValues( aiMapping );
177
+
178
+
179
+ /*
180
+ * Convert all internal indexing to the new column order indexes
181
+ */
182
+ /* Sorting */
183
+ for ( i=0, iLen=oSettings.aaSorting.length ; i<iLen ; i++ )
184
+ {
185
+ oSettings.aaSorting[i][0] = aiInvertMapping[ oSettings.aaSorting[i][0] ];
186
+ }
187
+
188
+ /* Fixed sorting */
189
+ if ( oSettings.aaSortingFixed !== null )
190
+ {
191
+ for ( i=0, iLen=oSettings.aaSortingFixed.length ; i<iLen ; i++ )
192
+ {
193
+ oSettings.aaSortingFixed[i][0] = aiInvertMapping[ oSettings.aaSortingFixed[i][0] ];
194
+ }
195
+ }
196
+
197
+ /* Data column sorting (the column which the sort for a given column should take place on) */
198
+ for ( i=0, iLen=iCols ; i<iLen ; i++ )
199
+ {
200
+ oCol = oSettings.aoColumns[i];
201
+ for ( j=0, jLen=oCol.aDataSort.length ; j<jLen ; j++ )
202
+ {
203
+ oCol.aDataSort[j] = aiInvertMapping[ oCol.aDataSort[j] ];
204
+ }
205
+
206
+ // Update the column indexes
207
+ oCol.idx = aiInvertMapping[ oCol.idx ];
208
+ }
209
+
210
+ // Update 1.10 optimised sort class removal variable
211
+ $.each( oSettings.aLastSort, function (i, val) {
212
+ oSettings.aLastSort[i].src = aiInvertMapping[ val.src ];
213
+ } );
214
+
215
+ /* Update the Get and Set functions for each column */
216
+ for ( i=0, iLen=iCols ; i<iLen ; i++ )
217
+ {
218
+ oCol = oSettings.aoColumns[i];
219
+
220
+ if ( typeof oCol.mData == 'number' ) {
221
+ oCol.mData = aiInvertMapping[ oCol.mData ];
222
+ }
223
+ else if ( $.isPlainObject( oCol.mData ) ) {
224
+ // HTML5 data sourced
225
+ attrMap( oCol.mData, '_', aiInvertMapping );
226
+ attrMap( oCol.mData, 'filter', aiInvertMapping );
227
+ attrMap( oCol.mData, 'sort', aiInvertMapping );
228
+ attrMap( oCol.mData, 'type', aiInvertMapping );
229
+ }
230
+ }
231
+
232
+ /*
233
+ * Move the DOM elements
234
+ */
235
+ if ( oSettings.aoColumns[iFrom].bVisible )
236
+ {
237
+ /* Calculate the current visible index and the point to insert the node before. The insert
238
+ * before needs to take into account that there might not be an element to insert before,
239
+ * in which case it will be null, and an appendChild should be used
240
+ */
241
+ var iVisibleIndex = this.oApi._fnColumnIndexToVisible( oSettings, iFrom );
242
+ var iInsertBeforeIndex = null;
243
+
244
+ i = iTo < iFrom ? iTo : iTo + 1;
245
+ while ( iInsertBeforeIndex === null && i < iCols )
246
+ {
247
+ iInsertBeforeIndex = this.oApi._fnColumnIndexToVisible( oSettings, i );
248
+ i++;
249
+ }
250
+
251
+ /* Header */
252
+ nTrs = oSettings.nTHead.getElementsByTagName('tr');
253
+ for ( i=0, iLen=nTrs.length ; i<iLen ; i++ )
254
+ {
255
+ fnDomSwitch( nTrs[i], iVisibleIndex, iInsertBeforeIndex );
256
+ }
257
+
258
+ /* Footer */
259
+ if ( oSettings.nTFoot !== null )
260
+ {
261
+ nTrs = oSettings.nTFoot.getElementsByTagName('tr');
262
+ for ( i=0, iLen=nTrs.length ; i<iLen ; i++ )
263
+ {
264
+ fnDomSwitch( nTrs[i], iVisibleIndex, iInsertBeforeIndex );
265
+ }
266
+ }
267
+
268
+ /* Body */
269
+ for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ )
270
+ {
271
+ if ( oSettings.aoData[i].nTr !== null )
272
+ {
273
+ fnDomSwitch( oSettings.aoData[i].nTr, iVisibleIndex, iInsertBeforeIndex );
274
+ }
275
+ }
276
+ }
277
+
278
+ /*
279
+ * Move the internal array elements
280
+ */
281
+ /* Columns */
282
+ fnArraySwitch( oSettings.aoColumns, iFrom, iTo );
283
+
284
+ // regenerate the get / set functions
285
+ for ( i=0, iLen=iCols ; i<iLen ; i++ ) {
286
+ oSettings.oApi._fnColumnOptions( oSettings, i, {} );
287
+ }
288
+
289
+ /* Search columns */
290
+ fnArraySwitch( oSettings.aoPreSearchCols, iFrom, iTo );
291
+
292
+ /* Array array - internal data anodes cache */
293
+ for ( i=0, iLen=oSettings.aoData.length ; i<iLen ; i++ )
294
+ {
295
+ var data = oSettings.aoData[i];
296
+ var cells = data.anCells;
297
+
298
+ if ( cells ) {
299
+ fnArraySwitch( cells, iFrom, iTo );
300
+
301
+ // Longer term, should this be moved into the DataTables' invalidate
302
+ // methods?
303
+ for ( j=0, jen=cells.length ; j<jen ; j++ ) {
304
+ if ( cells[j] && cells[j]._DT_CellIndex ) {
305
+ cells[j]._DT_CellIndex.column = j;
306
+ }
307
+ }
308
+ }
309
+
310
+ // For DOM sourced data, the invalidate will reread the cell into
311
+ // the data array, but for data sources as an array, they need to
312
+ // be flipped
313
+ if ( data.src !== 'dom' && $.isArray( data._aData ) ) {
314
+ fnArraySwitch( data._aData, iFrom, iTo );
315
+ }
316
+ }
317
+
318
+ /* Reposition the header elements in the header layout array */
319
+ for ( i=0, iLen=oSettings.aoHeader.length ; i<iLen ; i++ )
320
+ {
321
+ fnArraySwitch( oSettings.aoHeader[i], iFrom, iTo );
322
+ }
323
+
324
+ if ( oSettings.aoFooter !== null )
325
+ {
326
+ for ( i=0, iLen=oSettings.aoFooter.length ; i<iLen ; i++ )
327
+ {
328
+ fnArraySwitch( oSettings.aoFooter[i], iFrom, iTo );
329
+ }
330
+ }
331
+
332
+ if ( invalidateRows || invalidateRows === undefined )
333
+ {
334
+ $.fn.dataTable.Api( oSettings ).rows().invalidate();
335
+ }
336
+
337
+ /*
338
+ * Update DataTables' event handlers
339
+ */
340
+
341
+ /* Sort listener */
342
+ for ( i=0, iLen=iCols ; i<iLen ; i++ )
343
+ {
344
+ $(oSettings.aoColumns[i].nTh).off('click.DT');
345
+ this.oApi._fnSortAttachListener( oSettings, oSettings.aoColumns[i].nTh, i );
346
+ }
347
+
348
+
349
+ /* Fire an event so other plug-ins can update */
350
+ $(oSettings.oInstance).trigger( 'column-reorder.dt', [ oSettings, {
351
+ from: iFrom,
352
+ to: iTo,
353
+ mapping: aiInvertMapping,
354
+ drop: drop,
355
+
356
+ // Old style parameters for compatibility
357
+ iFrom: iFrom,
358
+ iTo: iTo,
359
+ aiInvertMapping: aiInvertMapping
360
+ } ] );
361
+ };
362
+
363
+ /**
364
+ * ColReorder provides column visibility control for DataTables
365
+ * @class ColReorder
366
+ * @constructor
367
+ * @param {object} dt DataTables settings object
368
+ * @param {object} opts ColReorder options
369
+ */
370
+ var ColReorder = function( dt, opts )
371
+ {
372
+ var settings = new $.fn.dataTable.Api( dt ).settings()[0];
373
+
374
+ // Ensure that we can't initialise on the same table twice
375
+ if ( settings._colReorder ) {
376
+ return settings._colReorder;
377
+ }
378
+
379
+ // Allow the options to be a boolean for defaults
380
+ if ( opts === true ) {
381
+ opts = {};
382
+ }
383
+
384
+ // Convert from camelCase to Hungarian, just as DataTables does
385
+ var camelToHungarian = $.fn.dataTable.camelToHungarian;
386
+ if ( camelToHungarian ) {
387
+ camelToHungarian( ColReorder.defaults, ColReorder.defaults, true );
388
+ camelToHungarian( ColReorder.defaults, opts || {} );
389
+ }
390
+
391
+
392
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
393
+ * Public class variables
394
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
395
+
396
+ /**
397
+ * @namespace Settings object which contains customisable information for ColReorder instance
398
+ */
399
+ this.s = {
400
+ /**
401
+ * DataTables settings object
402
+ * @property dt
403
+ * @type Object
404
+ * @default null
405
+ */
406
+ "dt": null,
407
+
408
+ /**
409
+ * Initialisation object used for this instance
410
+ * @property init
411
+ * @type object
412
+ * @default {}
413
+ */
414
+ "init": $.extend( true, {}, ColReorder.defaults, opts ),
415
+
416
+ /**
417
+ * Number of columns to fix (not allow to be reordered)
418
+ * @property fixed
419
+ * @type int
420
+ * @default 0
421
+ */
422
+ "fixed": 0,
423
+
424
+ /**
425
+ * Number of columns to fix counting from right (not allow to be reordered)
426
+ * @property fixedRight
427
+ * @type int
428
+ * @default 0
429
+ */
430
+ "fixedRight": 0,
431
+
432
+ /**
433
+ * Callback function for once the reorder has been done
434
+ * @property reorderCallback
435
+ * @type function
436
+ * @default null
437
+ */
438
+ "reorderCallback": null,
439
+
440
+ /**
441
+ * @namespace Information used for the mouse drag
442
+ */
443
+ "mouse": {
444
+ "startX": -1,
445
+ "startY": -1,
446
+ "offsetX": -1,
447
+ "offsetY": -1,
448
+ "target": -1,
449
+ "targetIndex": -1,
450
+ "fromIndex": -1
451
+ },
452
+
453
+ /**
454
+ * Information which is used for positioning the insert cusor and knowing where to do the
455
+ * insert. Array of objects with the properties:
456
+ * x: x-axis position
457
+ * to: insert point
458
+ * @property aoTargets
459
+ * @type array
460
+ * @default []
461
+ */
462
+ "aoTargets": []
463
+ };
464
+
465
+
466
+ /**
467
+ * @namespace Common and useful DOM elements for the class instance
468
+ */
469
+ this.dom = {
470
+ /**
471
+ * Dragging element (the one the mouse is moving)
472
+ * @property drag
473
+ * @type element
474
+ * @default null
475
+ */
476
+ "drag": null,
477
+
478
+ /**
479
+ * The insert cursor
480
+ * @property pointer
481
+ * @type element
482
+ * @default null
483
+ */
484
+ "pointer": null
485
+ };
486
+
487
+
488
+ /* Constructor logic */
489
+ this.s.dt = settings;
490
+ this.s.dt._colReorder = this;
491
+ this._fnConstruct();
492
+
493
+ return this;
494
+ };
495
+
496
+
497
+
498
+ $.extend( ColReorder.prototype, {
499
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
500
+ * Public methods
501
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
502
+
503
+ /**
504
+ * Reset the column ordering to the original ordering that was detected on
505
+ * start up.
506
+ * @return {this} Returns `this` for chaining.
507
+ *
508
+ * @example
509
+ * // DataTables initialisation with ColReorder
510
+ * var table = $('#example').dataTable( {
511
+ * "sDom": 'Rlfrtip'
512
+ * } );
513
+ *
514
+ * // Add click event to a button to reset the ordering
515
+ * $('#resetOrdering').click( function (e) {
516
+ * e.preventDefault();
517
+ * $.fn.dataTable.ColReorder( table ).fnReset();
518
+ * } );
519
+ */
520
+ "fnReset": function ()
521
+ {
522
+ this._fnOrderColumns( this.fnOrder() );
523
+
524
+ return this;
525
+ },
526
+
527
+ /**
528
+ * `Deprecated` - Get the current order of the columns, as an array.
529
+ * @return {array} Array of column identifiers
530
+ * @deprecated `fnOrder` should be used in preference to this method.
531
+ * `fnOrder` acts as a getter/setter.
532
+ */
533
+ "fnGetCurrentOrder": function ()
534
+ {
535
+ return this.fnOrder();
536
+ },
537
+
538
+ /**
539
+ * Get the current order of the columns, as an array. Note that the values
540
+ * given in the array are unique identifiers for each column. Currently
541
+ * these are the original ordering of the columns that was detected on
542
+ * start up, but this could potentially change in future.
543
+ * @return {array} Array of column identifiers
544
+ *
545
+ * @example
546
+ * // Get column ordering for the table
547
+ * var order = $.fn.dataTable.ColReorder( dataTable ).fnOrder();
548
+ *//**
549
+ * Set the order of the columns, from the positions identified in the
550
+ * ordering array given. Note that ColReorder takes a brute force approach
551
+ * to reordering, so it is possible multiple reordering events will occur
552
+ * before the final order is settled upon.
553
+ * @param {array} [set] Array of column identifiers in the new order. Note
554
+ * that every column must be included, uniquely, in this array.
555
+ * @return {this} Returns `this` for chaining.
556
+ *
557
+ * @example
558
+ * // Swap the first and second columns
559
+ * $.fn.dataTable.ColReorder( dataTable ).fnOrder( [1, 0, 2, 3, 4] );
560
+ *
561
+ * @example
562
+ * // Move the first column to the end for the table `#example`
563
+ * var curr = $.fn.dataTable.ColReorder( '#example' ).fnOrder();
564
+ * var first = curr.shift();
565
+ * curr.push( first );
566
+ * $.fn.dataTable.ColReorder( '#example' ).fnOrder( curr );
567
+ *
568
+ * @example
569
+ * // Reverse the table's order
570
+ * $.fn.dataTable.ColReorder( '#example' ).fnOrder(
571
+ * $.fn.dataTable.ColReorder( '#example' ).fnOrder().reverse()
572
+ * );
573
+ */
574
+ "fnOrder": function ( set, original )
575
+ {
576
+ var a = [], i, ien, j, jen;
577
+ var columns = this.s.dt.aoColumns;
578
+
579
+ if ( set === undefined ){
580
+ for ( i=0, ien=columns.length ; i<ien ; i++ ) {
581
+ a.push( columns[i]._ColReorder_iOrigCol );
582
+ }
583
+
584
+ return a;
585
+ }
586
+
587
+ // The order given is based on the original indexes, rather than the
588
+ // existing ones, so we need to translate from the original to current
589
+ // before then doing the order
590
+ if ( original ) {
591
+ var order = this.fnOrder();
592
+
593
+ for ( i=0, ien=set.length ; i<ien ; i++ ) {
594
+ a.push( $.inArray( set[i], order ) );
595
+ }
596
+
597
+ set = a;
598
+ }
599
+
600
+ this._fnOrderColumns( fnInvertKeyValues( set ) );
601
+
602
+ return this;
603
+ },
604
+
605
+
606
+ /**
607
+ * Convert from the original column index, to the original
608
+ *
609
+ * @param {int|array} idx Index(es) to convert
610
+ * @param {string} dir Transpose direction - `fromOriginal` / `toCurrent`
611
+ * or `'toOriginal` / `fromCurrent`
612
+ * @return {int|array} Converted values
613
+ */
614
+ fnTranspose: function ( idx, dir )
615
+ {
616
+ if ( ! dir ) {
617
+ dir = 'toCurrent';
618
+ }
619
+
620
+ var order = this.fnOrder();
621
+ var columns = this.s.dt.aoColumns;
622
+
623
+ if ( dir === 'toCurrent' ) {
624
+ // Given an original index, want the current
625
+ return ! $.isArray( idx ) ?
626
+ $.inArray( idx, order ) :
627
+ $.map( idx, function ( index ) {
628
+ return $.inArray( index, order );
629
+ } );
630
+ }
631
+ else {
632
+ // Given a current index, want the original
633
+ return ! $.isArray( idx ) ?
634
+ columns[idx]._ColReorder_iOrigCol :
635
+ $.map( idx, function ( index ) {
636
+ return columns[index]._ColReorder_iOrigCol;
637
+ } );
638
+ }
639
+ },
640
+
641
+
642
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
643
+ * Private methods (they are of course public in JS, but recommended as private)
644
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
645
+
646
+ /**
647
+ * Constructor logic
648
+ * @method _fnConstruct
649
+ * @returns void
650
+ * @private
651
+ */
652
+ "_fnConstruct": function ()
653
+ {
654
+ var that = this;
655
+ var iLen = this.s.dt.aoColumns.length;
656
+ var table = this.s.dt.nTable;
657
+ var i;
658
+
659
+ /* Columns discounted from reordering - counting left to right */
660
+ if ( this.s.init.iFixedColumns )
661
+ {
662
+ this.s.fixed = this.s.init.iFixedColumns;
663
+ }
664
+
665
+ if ( this.s.init.iFixedColumnsLeft )
666
+ {
667
+ this.s.fixed = this.s.init.iFixedColumnsLeft;
668
+ }
669
+
670
+ /* Columns discounted from reordering - counting right to left */
671
+ this.s.fixedRight = this.s.init.iFixedColumnsRight ?
672
+ this.s.init.iFixedColumnsRight :
673
+ 0;
674
+
675
+ /* Drop callback initialisation option */
676
+ if ( this.s.init.fnReorderCallback )
677
+ {
678
+ this.s.reorderCallback = this.s.init.fnReorderCallback;
679
+ }
680
+
681
+ /* Add event handlers for the drag and drop, and also mark the original column order */
682
+ for ( i = 0; i < iLen; i++ )
683
+ {
684
+ if ( i > this.s.fixed-1 && i < iLen - this.s.fixedRight )
685
+ {
686
+ this._fnMouseListener( i, this.s.dt.aoColumns[i].nTh );
687
+ }
688
+
689
+ /* Mark the original column order for later reference */
690
+ this.s.dt.aoColumns[i]._ColReorder_iOrigCol = i;
691
+ }
692
+
693
+ /* State saving */
694
+ this.s.dt.oApi._fnCallbackReg( this.s.dt, 'aoStateSaveParams', function (oS, oData) {
695
+ that._fnStateSave.call( that, oData );
696
+ }, "ColReorder_State" );
697
+
698
+ /* An initial column order has been specified */
699
+ var aiOrder = null;
700
+ if ( this.s.init.aiOrder )
701
+ {
702
+ aiOrder = this.s.init.aiOrder.slice();
703
+ }
704
+
705
+ /* State loading, overrides the column order given */
706
+ if ( this.s.dt.oLoadedState && typeof this.s.dt.oLoadedState.ColReorder != 'undefined' &&
707
+ this.s.dt.oLoadedState.ColReorder.length == this.s.dt.aoColumns.length )
708
+ {
709
+ aiOrder = this.s.dt.oLoadedState.ColReorder;
710
+ }
711
+
712
+ /* If we have an order to apply - do so */
713
+ if ( aiOrder )
714
+ {
715
+ /* We might be called during or after the DataTables initialisation. If before, then we need
716
+ * to wait until the draw is done, if after, then do what we need to do right away
717
+ */
718
+ if ( !that.s.dt._bInitComplete )
719
+ {
720
+ var bDone = false;
721
+ $(table).on( 'draw.dt.colReorder', function () {
722
+ if ( !that.s.dt._bInitComplete && !bDone )
723
+ {
724
+ bDone = true;
725
+ var resort = fnInvertKeyValues( aiOrder );
726
+ that._fnOrderColumns.call( that, resort );
727
+ }
728
+ } );
729
+ }
730
+ else
731
+ {
732
+ var resort = fnInvertKeyValues( aiOrder );
733
+ that._fnOrderColumns.call( that, resort );
734
+ }
735
+ }
736
+ else {
737
+ this._fnSetColumnIndexes();
738
+ }
739
+
740
+ // Destroy clean up
741
+ $(table).on( 'destroy.dt.colReorder', function () {
742
+ $(table).off( 'destroy.dt.colReorder draw.dt.colReorder' );
743
+ $(that.s.dt.nTHead).find( '*' ).off( '.ColReorder' );
744
+
745
+ $.each( that.s.dt.aoColumns, function (i, column) {
746
+ $(column.nTh).removeAttr('data-column-index');
747
+ } );
748
+
749
+ that.s.dt._colReorder = null;
750
+ that.s = null;
751
+ } );
752
+ },
753
+
754
+
755
+ /**
756
+ * Set the column order from an array
757
+ * @method _fnOrderColumns
758
+ * @param array a An array of integers which dictate the column order that should be applied
759
+ * @returns void
760
+ * @private
761
+ */
762
+ "_fnOrderColumns": function ( a )
763
+ {
764
+ var changed = false;
765
+
766
+ if ( a.length != this.s.dt.aoColumns.length )
767
+ {
768
+ this.s.dt.oInstance.oApi._fnLog( this.s.dt, 1, "ColReorder - array reorder does not "+
769
+ "match known number of columns. Skipping." );
770
+ return;
771
+ }
772
+
773
+ for ( var i=0, iLen=a.length ; i<iLen ; i++ )
774
+ {
775
+ var currIndex = $.inArray( i, a );
776
+ if ( i != currIndex )
777
+ {
778
+ /* Reorder our switching array */
779
+ fnArraySwitch( a, currIndex, i );
780
+
781
+ /* Do the column reorder in the table */
782
+ this.s.dt.oInstance.fnColReorder( currIndex, i, true, false );
783
+
784
+ changed = true;
785
+ }
786
+ }
787
+
788
+ $.fn.dataTable.Api( this.s.dt ).rows().invalidate();
789
+
790
+ this._fnSetColumnIndexes();
791
+
792
+ // Has anything actually changed? If not, then nothing else to do
793
+ if ( ! changed ) {
794
+ return;
795
+ }
796
+
797
+ /* When scrolling we need to recalculate the column sizes to allow for the shift */
798
+ if ( this.s.dt.oScroll.sX !== "" || this.s.dt.oScroll.sY !== "" )
799
+ {
800
+ this.s.dt.oInstance.fnAdjustColumnSizing( false );
801
+ }
802
+
803
+ /* Save the state */
804
+ this.s.dt.oInstance.oApi._fnSaveState( this.s.dt );
805
+
806
+ if ( this.s.reorderCallback !== null )
807
+ {
808
+ this.s.reorderCallback.call( this );
809
+ }
810
+ },
811
+
812
+
813
+ /**
814
+ * Because we change the indexes of columns in the table, relative to their starting point
815
+ * we need to reorder the state columns to what they are at the starting point so we can
816
+ * then rearrange them again on state load!
817
+ * @method _fnStateSave
818
+ * @param object oState DataTables state
819
+ * @returns string JSON encoded cookie string for DataTables
820
+ * @private
821
+ */
822
+ "_fnStateSave": function ( oState )
823
+ {
824
+ var i, iLen, aCopy, iOrigColumn;
825
+ var oSettings = this.s.dt;
826
+ var columns = oSettings.aoColumns;
827
+
828
+ oState.ColReorder = [];
829
+
830
+ /* Sorting */
831
+ if ( oState.aaSorting ) {
832
+ // 1.10.0-
833
+ for ( i=0 ; i<oState.aaSorting.length ; i++ ) {
834
+ oState.aaSorting[i][0] = columns[ oState.aaSorting[i][0] ]._ColReorder_iOrigCol;
835
+ }
836
+
837
+ var aSearchCopy = $.extend( true, [], oState.aoSearchCols );
838
+
839
+ for ( i=0, iLen=columns.length ; i<iLen ; i++ )
840
+ {
841
+ iOrigColumn = columns[i]._ColReorder_iOrigCol;
842
+
843
+ /* Column filter */
844
+ oState.aoSearchCols[ iOrigColumn ] = aSearchCopy[i];
845
+
846
+ /* Visibility */
847
+ oState.abVisCols[ iOrigColumn ] = columns[i].bVisible;
848
+
849
+ /* Column reordering */
850
+ oState.ColReorder.push( iOrigColumn );
851
+ }
852
+ }
853
+ else if ( oState.order ) {
854
+ // 1.10.1+
855
+ for ( i=0 ; i<oState.order.length ; i++ ) {
856
+ oState.order[i][0] = columns[ oState.order[i][0] ]._ColReorder_iOrigCol;
857
+ }
858
+
859
+ var stateColumnsCopy = $.extend( true, [], oState.columns );
860
+
861
+ for ( i=0, iLen=columns.length ; i<iLen ; i++ )
862
+ {
863
+ iOrigColumn = columns[i]._ColReorder_iOrigCol;
864
+
865
+ /* Columns */
866
+ oState.columns[ iOrigColumn ] = stateColumnsCopy[i];
867
+
868
+ /* Column reordering */
869
+ oState.ColReorder.push( iOrigColumn );
870
+ }
871
+ }
872
+ },
873
+
874
+
875
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
876
+ * Mouse drop and drag
877
+ */
878
+
879
+ /**
880
+ * Add a mouse down listener to a particluar TH element
881
+ * @method _fnMouseListener
882
+ * @param int i Column index
883
+ * @param element nTh TH element clicked on
884
+ * @returns void
885
+ * @private
886
+ */
887
+ "_fnMouseListener": function ( i, nTh )
888
+ {
889
+ var that = this;
890
+ $(nTh).on( 'mousedown.ColReorder', function (e) {
891
+ e.preventDefault();
892
+ that._fnMouseDown.call( that, e, nTh );
893
+ } );
894
+ },
895
+
896
+
897
+ /**
898
+ * Mouse down on a TH element in the table header
899
+ * @method _fnMouseDown
900
+ * @param event e Mouse event
901
+ * @param element nTh TH element to be dragged
902
+ * @returns void
903
+ * @private
904
+ */
905
+ "_fnMouseDown": function ( e, nTh )
906
+ {
907
+ var that = this;
908
+
909
+ /* Store information about the mouse position */
910
+ var target = $(e.target).closest('th, td');
911
+ var offset = target.offset();
912
+ var idx = parseInt( $(nTh).attr('data-column-index'), 10 );
913
+
914
+ if ( idx === undefined ) {
915
+ return;
916
+ }
917
+
918
+ this.s.mouse.startX = e.pageX;
919
+ this.s.mouse.startY = e.pageY;
920
+ this.s.mouse.offsetX = e.pageX - offset.left;
921
+ this.s.mouse.offsetY = e.pageY - offset.top;
922
+ this.s.mouse.target = this.s.dt.aoColumns[ idx ].nTh;//target[0];
923
+ this.s.mouse.targetIndex = idx;
924
+ this.s.mouse.fromIndex = idx;
925
+
926
+ this._fnRegions();
927
+
928
+ /* Add event handlers to the document */
929
+ $(document)
930
+ .on( 'mousemove.ColReorder', function (e) {
931
+ that._fnMouseMove.call( that, e );
932
+ } )
933
+ .on( 'mouseup.ColReorder', function (e) {
934
+ that._fnMouseUp.call( that, e );
935
+ } );
936
+ },
937
+
938
+
939
+ /**
940
+ * Deal with a mouse move event while dragging a node
941
+ * @method _fnMouseMove
942
+ * @param event e Mouse event
943
+ * @returns void
944
+ * @private
945
+ */
946
+ "_fnMouseMove": function ( e )
947
+ {
948
+ var that = this;
949
+
950
+ if ( this.dom.drag === null )
951
+ {
952
+ /* Only create the drag element if the mouse has moved a specific distance from the start
953
+ * point - this allows the user to make small mouse movements when sorting and not have a
954
+ * possibly confusing drag element showing up
955
+ */
956
+ if ( Math.pow(
957
+ Math.pow(e.pageX - this.s.mouse.startX, 2) +
958
+ Math.pow(e.pageY - this.s.mouse.startY, 2), 0.5 ) < 5 )
959
+ {
960
+ return;
961
+ }
962
+ this._fnCreateDragNode();
963
+ }
964
+
965
+ /* Position the element - we respect where in the element the click occured */
966
+ this.dom.drag.css( {
967
+ left: e.pageX - this.s.mouse.offsetX,
968
+ top: e.pageY - this.s.mouse.offsetY
969
+ } );
970
+
971
+ /* Based on the current mouse position, calculate where the insert should go */
972
+ var bSet = false;
973
+ var lastToIndex = this.s.mouse.toIndex;
974
+
975
+ for ( var i=1, iLen=this.s.aoTargets.length ; i<iLen ; i++ )
976
+ {
977
+ if ( e.pageX < this.s.aoTargets[i-1].x + ((this.s.aoTargets[i].x-this.s.aoTargets[i-1].x)/2) )
978
+ {
979
+ this.dom.pointer.css( 'left', this.s.aoTargets[i-1].x );
980
+ this.s.mouse.toIndex = this.s.aoTargets[i-1].to;
981
+ bSet = true;
982
+ break;
983
+ }
984
+ }
985
+
986
+ // The insert element wasn't positioned in the array (less than
987
+ // operator), so we put it at the end
988
+ if ( !bSet )
989
+ {
990
+ this.dom.pointer.css( 'left', this.s.aoTargets[this.s.aoTargets.length-1].x );
991
+ this.s.mouse.toIndex = this.s.aoTargets[this.s.aoTargets.length-1].to;
992
+ }
993
+
994
+ // Perform reordering if realtime updating is on and the column has moved
995
+ if ( this.s.init.bRealtime && lastToIndex !== this.s.mouse.toIndex ) {
996
+ this.s.dt.oInstance.fnColReorder( this.s.mouse.fromIndex, this.s.mouse.toIndex, false );
997
+ this.s.mouse.fromIndex = this.s.mouse.toIndex;
998
+ this._fnRegions();
999
+ }
1000
+ },
1001
+
1002
+
1003
+ /**
1004
+ * Finish off the mouse drag and insert the column where needed
1005
+ * @method _fnMouseUp
1006
+ * @param event e Mouse event
1007
+ * @returns void
1008
+ * @private
1009
+ */
1010
+ "_fnMouseUp": function ( e )
1011
+ {
1012
+ var that = this;
1013
+
1014
+ $(document).off( 'mousemove.ColReorder mouseup.ColReorder' );
1015
+
1016
+ if ( this.dom.drag !== null )
1017
+ {
1018
+ /* Remove the guide elements */
1019
+ this.dom.drag.remove();
1020
+ this.dom.pointer.remove();
1021
+ this.dom.drag = null;
1022
+ this.dom.pointer = null;
1023
+
1024
+ /* Actually do the reorder */
1025
+ this.s.dt.oInstance.fnColReorder( this.s.mouse.fromIndex, this.s.mouse.toIndex, true );
1026
+ this._fnSetColumnIndexes();
1027
+
1028
+ /* When scrolling we need to recalculate the column sizes to allow for the shift */
1029
+ if ( this.s.dt.oScroll.sX !== "" || this.s.dt.oScroll.sY !== "" )
1030
+ {
1031
+ this.s.dt.oInstance.fnAdjustColumnSizing( false );
1032
+ }
1033
+
1034
+ /* Save the state */
1035
+ this.s.dt.oInstance.oApi._fnSaveState( this.s.dt );
1036
+
1037
+ if ( this.s.reorderCallback !== null )
1038
+ {
1039
+ this.s.reorderCallback.call( this );
1040
+ }
1041
+ }
1042
+ },
1043
+
1044
+
1045
+ /**
1046
+ * Calculate a cached array with the points of the column inserts, and the
1047
+ * 'to' points
1048
+ * @method _fnRegions
1049
+ * @returns void
1050
+ * @private
1051
+ */
1052
+ "_fnRegions": function ()
1053
+ {
1054
+ var aoColumns = this.s.dt.aoColumns;
1055
+
1056
+ this.s.aoTargets.splice( 0, this.s.aoTargets.length );
1057
+
1058
+ this.s.aoTargets.push( {
1059
+ "x": $(this.s.dt.nTable).offset().left,
1060
+ "to": 0
1061
+ } );
1062
+
1063
+ var iToPoint = 0;
1064
+ var total = this.s.aoTargets[0].x;
1065
+
1066
+ for ( var i=0, iLen=aoColumns.length ; i<iLen ; i++ )
1067
+ {
1068
+ /* For the column / header in question, we want it's position to remain the same if the
1069
+ * position is just to it's immediate left or right, so we only increment the counter for
1070
+ * other columns
1071
+ */
1072
+ if ( i != this.s.mouse.fromIndex )
1073
+ {
1074
+ iToPoint++;
1075
+ }
1076
+
1077
+ if ( aoColumns[i].bVisible && aoColumns[i].nTh.style.display !=='none' )
1078
+ {
1079
+ total += $(aoColumns[i].nTh).outerWidth();
1080
+
1081
+ this.s.aoTargets.push( {
1082
+ "x": total,
1083
+ "to": iToPoint
1084
+ } );
1085
+ }
1086
+ }
1087
+
1088
+ /* Disallow columns for being reordered by drag and drop, counting right to left */
1089
+ if ( this.s.fixedRight !== 0 )
1090
+ {
1091
+ this.s.aoTargets.splice( this.s.aoTargets.length - this.s.fixedRight );
1092
+ }
1093
+
1094
+ /* Disallow columns for being reordered by drag and drop, counting left to right */
1095
+ if ( this.s.fixed !== 0 )
1096
+ {
1097
+ this.s.aoTargets.splice( 0, this.s.fixed );
1098
+ }
1099
+ },
1100
+
1101
+
1102
+ /**
1103
+ * Copy the TH element that is being drags so the user has the idea that they are actually
1104
+ * moving it around the page.
1105
+ * @method _fnCreateDragNode
1106
+ * @returns void
1107
+ * @private
1108
+ */
1109
+ "_fnCreateDragNode": function ()
1110
+ {
1111
+ var scrolling = this.s.dt.oScroll.sX !== "" || this.s.dt.oScroll.sY !== "";
1112
+
1113
+ var origCell = this.s.dt.aoColumns[ this.s.mouse.targetIndex ].nTh;
1114
+ var origTr = origCell.parentNode;
1115
+ var origThead = origTr.parentNode;
1116
+ var origTable = origThead.parentNode;
1117
+ var cloneCell = $(origCell).clone();
1118
+
1119
+ // This is a slightly odd combination of jQuery and DOM, but it is the
1120
+ // fastest and least resource intensive way I could think of cloning
1121
+ // the table with just a single header cell in it.
1122
+ this.dom.drag = $(origTable.cloneNode(false))
1123
+ .addClass( 'DTCR_clonedTable' )
1124
+ .append(
1125
+ $(origThead.cloneNode(false)).append(
1126
+ $(origTr.cloneNode(false)).append(
1127
+ cloneCell[0]
1128
+ )
1129
+ )
1130
+ )
1131
+ .css( {
1132
+ position: 'absolute',
1133
+ top: 0,
1134
+ left: 0,
1135
+ width: $(origCell).outerWidth(),
1136
+ height: $(origCell).outerHeight()
1137
+ } )
1138
+ .appendTo( 'body' );
1139
+
1140
+ this.dom.pointer = $('<div></div>')
1141
+ .addClass( 'DTCR_pointer' )
1142
+ .css( {
1143
+ position: 'absolute',
1144
+ top: scrolling ?
1145
+ $('div.dataTables_scroll', this.s.dt.nTableWrapper).offset().top :
1146
+ $(this.s.dt.nTable).offset().top,
1147
+ height : scrolling ?
1148
+ $('div.dataTables_scroll', this.s.dt.nTableWrapper).height() :
1149
+ $(this.s.dt.nTable).height()
1150
+ } )
1151
+ .appendTo( 'body' );
1152
+ },
1153
+
1154
+
1155
+ /**
1156
+ * Add a data attribute to the column headers, so we know the index of
1157
+ * the row to be reordered. This allows fast detection of the index, and
1158
+ * for this plug-in to work with FixedHeader which clones the nodes.
1159
+ * @private
1160
+ */
1161
+ "_fnSetColumnIndexes": function ()
1162
+ {
1163
+ $.each( this.s.dt.aoColumns, function (i, column) {
1164
+ $(column.nTh).attr('data-column-index', i);
1165
+ } );
1166
+ }
1167
+ } );
1168
+
1169
+
1170
+
1171
+
1172
+
1173
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1174
+ * Static parameters
1175
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1176
+
1177
+
1178
+ /**
1179
+ * ColReorder default settings for initialisation
1180
+ * @namespace
1181
+ * @static
1182
+ */
1183
+ ColReorder.defaults = {
1184
+ /**
1185
+ * Predefined ordering for the columns that will be applied automatically
1186
+ * on initialisation. If not specified then the order that the columns are
1187
+ * found to be in the HTML is the order used.
1188
+ * @type array
1189
+ * @default null
1190
+ * @static
1191
+ */
1192
+ aiOrder: null,
1193
+
1194
+ /**
1195
+ * Redraw the table's column ordering as the end user draws the column
1196
+ * (`true`) or wait until the mouse is released (`false` - default). Note
1197
+ * that this will perform a redraw on each reordering, which involves an
1198
+ * Ajax request each time if you are using server-side processing in
1199
+ * DataTables.
1200
+ * @type boolean
1201
+ * @default false
1202
+ * @static
1203
+ */
1204
+ bRealtime: true,
1205
+
1206
+ /**
1207
+ * Indicate how many columns should be fixed in position (counting from the
1208
+ * left). This will typically be 1 if used, but can be as high as you like.
1209
+ * @type int
1210
+ * @default 0
1211
+ * @static
1212
+ */
1213
+ iFixedColumnsLeft: 0,
1214
+
1215
+ /**
1216
+ * As `iFixedColumnsRight` but counting from the right.
1217
+ * @type int
1218
+ * @default 0
1219
+ * @static
1220
+ */
1221
+ iFixedColumnsRight: 0,
1222
+
1223
+ /**
1224
+ * Callback function that is fired when columns are reordered. The `column-
1225
+ * reorder` event is preferred over this callback
1226
+ * @type function():void
1227
+ * @default null
1228
+ * @static
1229
+ */
1230
+ fnReorderCallback: null
1231
+ };
1232
+
1233
+
1234
+
1235
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1236
+ * Constants
1237
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1238
+
1239
+ /**
1240
+ * ColReorder version
1241
+ * @constant version
1242
+ * @type String
1243
+ * @default As code
1244
+ */
1245
+ ColReorder.version = "1.3.2";
1246
+
1247
+
1248
+
1249
+ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1250
+ * DataTables interfaces
1251
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1252
+
1253
+ // Expose
1254
+ $.fn.dataTable.ColReorder = ColReorder;
1255
+ $.fn.DataTable.ColReorder = ColReorder;
1256
+
1257
+
1258
+ // Register a new feature with DataTables
1259
+ if ( typeof $.fn.dataTable == "function" &&
1260
+ typeof $.fn.dataTableExt.fnVersionCheck == "function" &&
1261
+ $.fn.dataTableExt.fnVersionCheck('1.10.8') )
1262
+ {
1263
+ $.fn.dataTableExt.aoFeatures.push( {
1264
+ "fnInit": function( settings ) {
1265
+ var table = settings.oInstance;
1266
+
1267
+ if ( ! settings._colReorder ) {
1268
+ var dtInit = settings.oInit;
1269
+ var opts = dtInit.colReorder || dtInit.oColReorder || {};
1270
+
1271
+ new ColReorder( settings, opts );
1272
+ }
1273
+ else {
1274
+ table.oApi._fnLog( settings, 1, "ColReorder attempted to initialise twice. Ignoring second" );
1275
+ }
1276
+
1277
+ return null; /* No node for DataTables to insert */
1278
+ },
1279
+ "cFeature": "R",
1280
+ "sFeature": "ColReorder"
1281
+ } );
1282
+ }
1283
+ else {
1284
+ alert( "Warning: ColReorder requires DataTables 1.10.8 or greater - www.datatables.net/download");
1285
+ }
1286
+
1287
+
1288
+ // Attach a listener to the document which listens for DataTables initialisation
1289
+ // events so we can automatically initialise
1290
+ $(document).on( 'preInit.dt.colReorder', function (e, settings) {
1291
+ if ( e.namespace !== 'dt' ) {
1292
+ return;
1293
+ }
1294
+
1295
+ var init = settings.oInit.colReorder;
1296
+ var defaults = DataTable.defaults.colReorder;
1297
+
1298
+ if ( init || defaults ) {
1299
+ var opts = $.extend( {}, init, defaults );
1300
+
1301
+ if ( init !== false ) {
1302
+ new ColReorder( settings, opts );
1303
+ }
1304
+ }
1305
+ } );
1306
+
1307
+
1308
+ // API augmentation
1309
+ $.fn.dataTable.Api.register( 'colReorder.reset()', function () {
1310
+ return this.iterator( 'table', function ( ctx ) {
1311
+ ctx._colReorder.fnReset();
1312
+ } );
1313
+ } );
1314
+
1315
+ $.fn.dataTable.Api.register( 'colReorder.order()', function ( set, original ) {
1316
+ if ( set ) {
1317
+ return this.iterator( 'table', function ( ctx ) {
1318
+ ctx._colReorder.fnOrder( set, original );
1319
+ } );
1320
+ }
1321
+
1322
+ return this.context.length ?
1323
+ this.context[0]._colReorder.fnOrder() :
1324
+ null;
1325
+ } );
1326
+
1327
+ $.fn.dataTable.Api.register( 'colReorder.transpose()', function ( idx, dir ) {
1328
+ return this.context.length && this.context[0]._colReorder ?
1329
+ this.context[0]._colReorder.fnTranspose( idx, dir ) :
1330
+ idx;
1331
+ } );
1332
+
1333
+
1334
+ return ColReorder;
1335
+ }));