| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
;(function( $ ) { |
| 11 |
'use strict'; |
| 12 |
var undef, |
| 13 |
ts = $.tablesorter; |
| 14 |
|
| 15 |
ts.dragtable = { |
| 16 |
create : function( _this ) { |
| 17 |
var hasAccept, |
| 18 |
$table = _this.originalTable.el, |
| 19 |
handle = _this.options.dragHandle.replace('.', ''); |
| 20 |
$table.children('thead').children().children('th,td').each(function(){ |
| 21 |
var $this = $(this); |
| 22 |
if ( !$this.find( _this.options.dragHandle + ',.' + handle + '-disabled' ).length ) { |
| 23 |
hasAccept = _this.options.dragaccept ? $this.hasClass( _this.options.dragaccept.replace('.', '') ) : true; |
| 24 |
$this |
| 25 |
|
| 26 |
.wrapInner('<div class="' + _this.options.sortClass.replace('.', '') + '"/>') |
| 27 |
|
| 28 |
.prepend('<div class="' + handle + ( hasAccept ? '' : '-disabled' ) + '"></div>'); |
| 29 |
} |
| 30 |
}); |
| 31 |
}, |
| 32 |
start : function( table ) { |
| 33 |
table = $( table )[0]; |
| 34 |
if ( table && table.config ) { |
| 35 |
table.config.widgetOptions.dragtableLast = { |
| 36 |
search : $( table ).data( 'lastSearch' ), |
| 37 |
order : ts.dragtable.getOrder( table ) |
| 38 |
}; |
| 39 |
} |
| 40 |
}, |
| 41 |
update : function( _this ) { |
| 42 |
var t, list, val, |
| 43 |
dragTable = _this.originalTable, |
| 44 |
table = dragTable.el[ 0 ], |
| 45 |
$table = $( table ), |
| 46 |
c = table.config, |
| 47 |
wo = c && c.widgetOptions, |
| 48 |
startIndex = dragTable.startIndex - 1, |
| 49 |
endIndex = dragTable.endIndex - 1, |
| 50 |
columnOrder = ts.dragtable.getOrder( table ) || [], |
| 51 |
hasFilters = ts.hasWidget( $table, 'filter' ) || false, |
| 52 |
last = wo && wo.dragtableLast || {}, |
| 53 |
|
| 54 |
filters = []; |
| 55 |
|
| 56 |
|
| 57 |
if ( ( last.order || [] ).join( '' ) !== columnOrder.join( '' ) ) { |
| 58 |
|
| 59 |
if ( c.sortList.length ) { |
| 60 |
|
| 61 |
list = $.extend( true, [], c.sortList ); |
| 62 |
$.each( columnOrder, function( indx, value ) { |
| 63 |
val = ts.isValueInArray( parseInt( value, 10 ), list ); |
| 64 |
if ( value !== last.order[ indx ] && val >= 0 ) { |
| 65 |
c.sortList[ val ][ 0 ] = indx; |
| 66 |
} |
| 67 |
}); |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
if ( hasFilters ) { |
| 72 |
$.each( last.search || [], function( indx ) { |
| 73 |
filters[ indx ] = last.search[ columnOrder[ indx ] ]; |
| 74 |
}); |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
t = ( ts.hasWidget( c.$table, 'editable' ) || false ) ? wo.editable_columnsArray : false; |
| 79 |
if ( t ) { |
| 80 |
c.widgetOptions.editable_columnsArray = ts.dragtable.reindexArrayItem( t, startIndex, endIndex ); |
| 81 |
} |
| 82 |
|
| 83 |
t = ( ts.hasWidget( c.$table, 'math' ) || false ) ? wo.math_ignore : false; |
| 84 |
if ( t ) { |
| 85 |
c.widgetOptions.math_ignore = ts.dragtable.reindexArrayItem( t, startIndex, endIndex ); |
| 86 |
} |
| 87 |
|
| 88 |
t = ( ts.hasWidget( c.$table, 'resizable' ) || false ) ? wo.resizable_widths : false; |
| 89 |
if ( t ) { |
| 90 |
|
| 91 |
wo.resizable_widths = ts.dragtable.moveArrayItem( t, startIndex, endIndex ); |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
ts.updateAll( c, false, function() { |
| 103 |
if ( hasFilters ) { |
| 104 |
setTimeout( function() { |
| 105 |
|
| 106 |
c.lastCombinedFilter = null; |
| 107 |
c.$table.data('lastSearch', filters); |
| 108 |
ts.setFilters( $table, filters ); |
| 109 |
if ($.isFunction(_this.options.tablesorterComplete)) { |
| 110 |
_this.options.tablesorterComplete( c.table ); |
| 111 |
} |
| 112 |
}, 10 ); |
| 113 |
} |
| 114 |
}); |
| 115 |
} |
| 116 |
}, |
| 117 |
getOrder : function( table ) { |
| 118 |
return $( table ).children( 'thead' ).children( '.' + ts.css.headerRow ).children().map( function() { |
| 119 |
return $( this ).attr( 'data-column' ); |
| 120 |
}).get() || []; |
| 121 |
}, |
| 122 |
|
| 123 |
startColumnMove : function( dragTable ) { |
| 124 |
var $cols, |
| 125 |
c = dragTable.el[ 0 ].config, |
| 126 |
startIndex = dragTable.startIndex - 1, |
| 127 |
endIndex = dragTable.endIndex - 1, |
| 128 |
cols = c.columns - 1, |
| 129 |
pos = endIndex === cols ? false : endIndex <= startIndex, |
| 130 |
$rows = c.$table.children().children( 'tr' ); |
| 131 |
if ( c.debug ) { |
| 132 |
console.log( 'Inserting column ' + startIndex + ( pos ? ' before' : ' after' ) + ' column ' + endIndex ); |
| 133 |
} |
| 134 |
$rows.each( function() { |
| 135 |
$cols = $( this ).children(); |
| 136 |
$cols.eq( startIndex )[ pos ? 'insertBefore' : 'insertAfter' ]( $cols.eq( endIndex ) ); |
| 137 |
}); |
| 138 |
|
| 139 |
$cols = c.$table.children( 'colgroup' ).children(); |
| 140 |
$cols.eq( startIndex )[ pos ? 'insertBefore' : 'insertAfter' ]( $cols.eq( endIndex ) ); |
| 141 |
}, |
| 142 |
swapNodes : function( a, b ) { |
| 143 |
var indx, aparent, asibling, |
| 144 |
len = a.length; |
| 145 |
for ( indx = 0; indx < len; indx++ ) { |
| 146 |
aparent = a[ indx ].parentNode; |
| 147 |
asibling = a[ indx ].nextSibling === b[ indx ] ? a[ indx ] : a[ indx ].nextSibling; |
| 148 |
b[ indx ].parentNode.insertBefore( a[ indx ], b[ indx ] ); |
| 149 |
aparent.insertBefore( b[ indx ], asibling ); |
| 150 |
} |
| 151 |
}, |
| 152 |
|
| 153 |
moveArrayItem : function( array, oldIndex, newIndex ) { |
| 154 |
var indx, len = array.length; |
| 155 |
if ( newIndex >= len ) { |
| 156 |
indx = newIndex - len; |
| 157 |
while ( ( indx-- ) + 1 ) { |
| 158 |
array.push( undef ); |
| 159 |
} |
| 160 |
} |
| 161 |
array.splice( newIndex, 0, array.splice( oldIndex, 1 )[ 0 ] ); |
| 162 |
return array; |
| 163 |
}, |
| 164 |
reindexArrayItem : function( array, oldIndex, newIndex ) { |
| 165 |
var nIndx = $.inArray( newIndex, array ), |
| 166 |
oIndx = $.inArray( oldIndex, array ), |
| 167 |
max = Math.max.apply( Math, array ), |
| 168 |
arry = []; |
| 169 |
|
| 170 |
if ( nIndx >= 0 && oIndx >= 0 ) { |
| 171 |
return array; |
| 172 |
} |
| 173 |
|
| 174 |
$.each( array, function( indx, value ) { |
| 175 |
|
| 176 |
if ( newIndex < oldIndex ) { |
| 177 |
|
| 178 |
if ( value >= newIndex ) { |
| 179 |
|
| 180 |
arry.push( value + ( value < oldIndex ? 1 : 0 ) ); |
| 181 |
} else { |
| 182 |
arry.push( value ); |
| 183 |
} |
| 184 |
} else if ( newIndex > oldIndex ) { |
| 185 |
|
| 186 |
if ( value === oldIndex ) { |
| 187 |
arry.push( newIndex ); |
| 188 |
} else if ( value < newIndex && value >= oldIndex ) { |
| 189 |
arry.push( value - 1 ); |
| 190 |
} else if ( value <= newIndex ) { |
| 191 |
arry.push( value ); |
| 192 |
} else if ( value > oldIndex ) { |
| 193 |
arry.push( value + ( value < newIndex ? 0 : 1 ) ); |
| 194 |
} |
| 195 |
} |
| 196 |
}); |
| 197 |
return arry.sort(); |
| 198 |
} |
| 199 |
}; |
| 200 |
|
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
|
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
$.widget("akottr.dragtable", { |
| 257 |
options: { |
| 258 |
revert: false, |
| 259 |
dragHandle: '.table-handle', |
| 260 |
maxMovingRows: 40, |
| 261 |
excludeFooter: false, |
| 262 |
onlyHeaderThreshold: 100, |
| 263 |
dragaccept: null, |
| 264 |
persistState: null, |
| 265 |
restoreState: null, |
| 266 |
exact: true, |
| 267 |
clickDelay: 10, |
| 268 |
containment: null, |
| 269 |
cursor: 'move', |
| 270 |
cursorAt: false, |
| 271 |
distance: 0, |
| 272 |
tolerance: 'pointer', |
| 273 |
axis: 'x', |
| 274 |
beforeStart: $.noop, |
| 275 |
beforeMoving: $.noop, |
| 276 |
beforeReorganize: $.noop, |
| 277 |
beforeStop: $.noop, |
| 278 |
|
| 279 |
tablesorterComplete: null, |
| 280 |
sortClass : '.sorter' |
| 281 |
}, |
| 282 |
originalTable: { |
| 283 |
el: null, |
| 284 |
selectedHandle: null, |
| 285 |
sortOrder: null, |
| 286 |
startIndex: 0, |
| 287 |
endIndex: 0 |
| 288 |
}, |
| 289 |
sortableTable: { |
| 290 |
el: $(), |
| 291 |
selectedHandle: $(), |
| 292 |
movingRow: $() |
| 293 |
}, |
| 294 |
persistState: function() { |
| 295 |
var _this = this; |
| 296 |
this.originalTable.el.find('th').each(function(i) { |
| 297 |
if (this.id !== '') { |
| 298 |
_this.originalTable.sortOrder[this.id] = i; |
| 299 |
} |
| 300 |
}); |
| 301 |
$.ajax({ |
| 302 |
url: this.options.persistState, |
| 303 |
data: this.originalTable.sortOrder |
| 304 |
}); |
| 305 |
}, |
| 306 |
|
| 307 |
|
| 308 |
|
| 309 |
|
| 310 |
|
| 311 |
|
| 312 |
_restoreState: function(persistObj) { |
| 313 |
for (var n in persistObj) { |
| 314 |
if (n in persistObj) { |
| 315 |
this.originalTable.startIndex = $('#' + n).closest('th').prevAll().length + 1; |
| 316 |
this.originalTable.endIndex = parseInt(persistObj[n], 10) + 1; |
| 317 |
this._bubbleCols(); |
| 318 |
} |
| 319 |
} |
| 320 |
}, |
| 321 |
|
| 322 |
_bubbleCols: function() { |
| 323 |
ts.dragtable.startColumnMove(this.originalTable); |
| 324 |
}, |
| 325 |
_rearrangeTableBackroundProcessing: function() { |
| 326 |
var _this = this; |
| 327 |
return function() { |
| 328 |
_this._bubbleCols(); |
| 329 |
_this.options.beforeStop(_this.originalTable); |
| 330 |
_this.sortableTable.el.remove(); |
| 331 |
restoreTextSelection(); |
| 332 |
ts.dragtable.update(_this); |
| 333 |
|
| 334 |
if ($.isFunction(_this.options.persistState)) { |
| 335 |
_this.options.persistState(_this.originalTable); |
| 336 |
} else { |
| 337 |
_this.persistState(); |
| 338 |
} |
| 339 |
|
| 340 |
}; |
| 341 |
}, |
| 342 |
_rearrangeTable: function() { |
| 343 |
var _this = this; |
| 344 |
return function() { |
| 345 |
|
| 346 |
_this.originalTable.selectedHandle.removeClass('dragtable-handle-selected'); |
| 347 |
|
| 348 |
_this.sortableTable.el.sortable("disable"); |
| 349 |
_this.sortableTable.el.addClass('dragtable-disabled'); |
| 350 |
_this.options.beforeReorganize(_this.originalTable, _this.sortableTable); |
| 351 |
|
| 352 |
|
| 353 |
_this.originalTable.endIndex = _this.sortableTable.movingRow.prevAll().length + 1; |
| 354 |
setTimeout(_this._rearrangeTableBackroundProcessing(), 50); |
| 355 |
}; |
| 356 |
}, |
| 357 |
|
| 358 |
|
| 359 |
|
| 360 |
|
| 361 |
|
| 362 |
_generateSortable: function(e) { |
| 363 |
if (e.cancelBubble) { |
| 364 |
e.cancelBubble = true; |
| 365 |
} else { |
| 366 |
e.stopPropagation(); |
| 367 |
} |
| 368 |
var _this = this; |
| 369 |
|
| 370 |
var attrs = this.originalTable.el[0].attributes; |
| 371 |
var tableAttrsString = ''; |
| 372 |
for (var i = 0; i < attrs.length; i++) { |
| 373 |
if ( (attrs[i].value || attrs[i].nodeValue) && attrs[i].nodeName != 'id' && attrs[i].nodeName != 'width') { |
| 374 |
tableAttrsString += attrs[i].nodeName + '="' + ( attrs[i].value || attrs[i].nodeValue ) + '" '; |
| 375 |
} |
| 376 |
} |
| 377 |
|
| 378 |
var rowAttrsArr = []; |
| 379 |
|
| 380 |
var heightArr = []; |
| 381 |
|
| 382 |
|
| 383 |
_this.originalTable.el.children('thead, tbody').children('tr:visible').slice(0, _this.options.maxMovingRow).each(function() { |
| 384 |
|
| 385 |
var attrs = this.attributes; |
| 386 |
var attrsString = ''; |
| 387 |
for (var j = 0; j < attrs.length; j++) { |
| 388 |
if ( (attrs[j].value || attrs[j].nodeValue ) && attrs[j].nodeName != 'id') { |
| 389 |
attrsString += ' ' + attrs[j].nodeName + '="' + ( attrs[j].value || attrs[j].nodeValue ) + '"'; |
| 390 |
} |
| 391 |
} |
| 392 |
rowAttrsArr.push(attrsString); |
| 393 |
heightArr.push($(this).height()); |
| 394 |
}); |
| 395 |
|
| 396 |
|
| 397 |
var widthArr = []; |
| 398 |
|
| 399 |
var totalWidth = 0; |
| 400 |
|
| 401 |
|
| 402 |
|
| 403 |
var thtb = _this.originalTable.el.children(); |
| 404 |
var headerRows = thtb.filter('thead').children('tr:visible'); |
| 405 |
var visibleRows = thtb.filter('tbody').children('tr:visible'); |
| 406 |
|
| 407 |
headerRows.eq(0).children('th, td').filter(':visible').each(function() { |
| 408 |
var w = $(this).outerWidth(); |
| 409 |
widthArr.push(w); |
| 410 |
totalWidth += w; |
| 411 |
}); |
| 412 |
if(_this.options.exact) { |
| 413 |
var difference = totalWidth - _this.originalTable.el.outerWidth(); |
| 414 |
widthArr[0] -= difference; |
| 415 |
} |
| 416 |
|
| 417 |
totalWidth += 2; |
| 418 |
|
| 419 |
var captionHeight = 0; |
| 420 |
thtb.filter('caption').each(function(){ |
| 421 |
captionHeight += $(this).outerHeight(); |
| 422 |
}); |
| 423 |
|
| 424 |
var sortableHtml = '<ul class="dragtable-sortable" style="position:absolute; width:' + totalWidth + 'px;">'; |
| 425 |
var sortableColumn = []; |
| 426 |
|
| 427 |
|
| 428 |
var rowIndex, |
| 429 |
columns = headerRows.eq(0).children('th, td').length; |
| 430 |
|
| 431 |
for (i = 0; i < columns; i++) { |
| 432 |
var row = headerRows.children(':nth-child(' + (i + 1) + ')'); |
| 433 |
if (row.is(':visible')) { |
| 434 |
rowIndex = 0; |
| 435 |
sortableColumn[i] = '<li style="width:' + row.outerWidth() + 'px;">' + |
| 436 |
'<table ' + tableAttrsString + '>' + |
| 437 |
( captionHeight ? '<caption style="height:' + captionHeight + 'px;"></caption>' : '' ) + |
| 438 |
'<thead>'; |
| 439 |
|
| 440 |
headerRows.each(function(j){ |
| 441 |
sortableColumn[i] += '<tr ' + rowAttrsArr[rowIndex++] + |
| 442 |
( heightArr[j] ? ' style="height:' + heightArr[j] + 'px;"' : '' ) + '>' + |
| 443 |
row[j].outerHTML + '</tr>'; |
| 444 |
}); |
| 445 |
sortableColumn[i] += '</thead><tbody>'; |
| 446 |
|
| 447 |
row = visibleRows.children(':nth-child(' + (i + 1) + ')'); |
| 448 |
if (_this.options.maxMovingRows > 1) { |
| 449 |
row = row.add(visibleRows.children(':nth-child(' + (i + 1) + ')').slice(0, _this.options.maxMovingRows - 1)); |
| 450 |
} |
| 451 |
row.each(function(j) { |
| 452 |
sortableColumn[i] += '<tr ' + rowAttrsArr[rowIndex++] + |
| 453 |
( heightArr[j] ? ' style="height:' + heightArr[j] + 'px;"' : '' ) + '>' + |
| 454 |
this.outerHTML + '</tr>'; |
| 455 |
}); |
| 456 |
sortableColumn[i] += '</tbody>'; |
| 457 |
|
| 458 |
|
| 459 |
if (!_this.options.excludeFooter) { |
| 460 |
sortableColumn[i] += '<tfoot><tr ' + rowAttrsArr[rowIndex++] + '>' + |
| 461 |
thtb.filter('tfoot').children('tr:visible').children()[i].outerHTML + '</tr></tfoot>'; |
| 462 |
} |
| 463 |
sortableColumn[i] += '</table></li>'; |
| 464 |
} |
| 465 |
} |
| 466 |
sortableHtml += sortableColumn.join('') + '</ul>'; |
| 467 |
this.sortableTable.el = this.originalTable.el.before(sortableHtml).prev(); |
| 468 |
|
| 469 |
this.sortableTable.el.find('> li > table').each(function(i) { |
| 470 |
$(this).css('width', widthArr[i] + 'px'); |
| 471 |
}); |
| 472 |
|
| 473 |
|
| 474 |
this.sortableTable.selectedHandle = this.sortableTable.el.find('th .dragtable-handle-selected'); |
| 475 |
|
| 476 |
var items = !this.options.dragaccept ? 'li' : 'li:has(' + this.options.dragaccept + ')'; |
| 477 |
this.sortableTable.el.sortable({ |
| 478 |
items: items, |
| 479 |
stop: this._rearrangeTable(), |
| 480 |
|
| 481 |
revert: this.options.revert, |
| 482 |
tolerance: this.options.tolerance, |
| 483 |
containment: this.options.containment, |
| 484 |
cursor: this.options.cursor, |
| 485 |
cursorAt: this.options.cursorAt, |
| 486 |
distance: this.options.distance, |
| 487 |
axis: this.options.axis |
| 488 |
}); |
| 489 |
|
| 490 |
|
| 491 |
this.originalTable.startIndex = $(e.target).closest('th,td').prevAll().length + 1; |
| 492 |
this.options.beforeMoving(this.originalTable, this.sortableTable); |
| 493 |
|
| 494 |
this.sortableTable.movingRow = this.sortableTable.el.children('li:nth-child(' + this.originalTable.startIndex + ')'); |
| 495 |
|
| 496 |
|
| 497 |
disableTextSelection(); |
| 498 |
|
| 499 |
this.sortableTable.movingRow.trigger($.extend($.Event(e.type), { |
| 500 |
which: 1, |
| 501 |
clientX: e.clientX, |
| 502 |
clientY: e.clientY, |
| 503 |
pageX: e.pageX, |
| 504 |
pageY: e.pageY, |
| 505 |
screenX: e.screenX, |
| 506 |
screenY: e.screenY |
| 507 |
})); |
| 508 |
|
| 509 |
|
| 510 |
var placeholder = this.sortableTable.el.find('.ui-sortable-placeholder'); |
| 511 |
if(placeholder.height() > 0) { |
| 512 |
placeholder.css('height', this.sortableTable.el.find('.ui-sortable-helper').height()); |
| 513 |
} |
| 514 |
|
| 515 |
placeholder.html('<div class="outer" style="height:100%;"><div class="inner" style="height:100%;"></div></div>'); |
| 516 |
}, |
| 517 |
bindTo: {}, |
| 518 |
_create: function() { |
| 519 |
var _this = this; |
| 520 |
_this.originalTable = { |
| 521 |
el: _this.element, |
| 522 |
selectedHandle: $(), |
| 523 |
sortOrder: {}, |
| 524 |
startIndex: 0, |
| 525 |
endIndex: 0 |
| 526 |
}; |
| 527 |
ts.dragtable.create( _this ); |
| 528 |
|
| 529 |
_this.bindTo = '> thead > tr > ' + ( _this.options.dragaccept || 'th, td' ); |
| 530 |
|
| 531 |
if (_this.element.find(_this.bindTo).find(_this.options.dragHandle).length) { |
| 532 |
_this.bindTo += ' ' + _this.options.dragHandle; |
| 533 |
} |
| 534 |
|
| 535 |
if ($.isFunction(_this.options.restoreState)) { |
| 536 |
_this.options.restoreState(_this.originalTable); |
| 537 |
} else { |
| 538 |
_this._restoreState(_this.options.restoreState); |
| 539 |
} |
| 540 |
_this.originalTable.el.on( 'mousedown.dragtable', _this.bindTo, function(evt) { |
| 541 |
|
| 542 |
if (evt.which!==1) return; |
| 543 |
ts.dragtable.start( _this.originalTable.el ); |
| 544 |
if (_this.options.beforeStart(_this.originalTable) === false) { |
| 545 |
return; |
| 546 |
} |
| 547 |
clearTimeout(_this.downTimer); |
| 548 |
_this.downTimer = setTimeout(function() { |
| 549 |
_this.originalTable.selectedHandle = $(_this); |
| 550 |
_this.originalTable.selectedHandle.addClass('dragtable-handle-selected'); |
| 551 |
_this._generateSortable(evt); |
| 552 |
}, _this.options.clickDelay); |
| 553 |
}).on( 'mouseup.dragtable', _this.options.dragHandle,function() { |
| 554 |
clearTimeout(_this.downTimer); |
| 555 |
}); |
| 556 |
}, |
| 557 |
redraw: function(){ |
| 558 |
this.destroy(); |
| 559 |
this._create(); |
| 560 |
}, |
| 561 |
destroy: function() { |
| 562 |
this.originalTable.el.off('mousedown.dragtable mouseup.dragtable', this.bindTo); |
| 563 |
$.Widget.prototype.destroy.apply(this, arguments); |
| 564 |
|
| 565 |
} |
| 566 |
}); |
| 567 |
|
| 568 |
|
| 569 |
var body_onselectstart_save = $(document.body).attr('onselectstart'), |
| 570 |
body_unselectable_save = $(document.body).attr('unselectable'); |
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
function disableTextSelection() { |
| 575 |
|
| 576 |
|
| 577 |
var $style = $('<style id="__dragtable_disable_text_selection__" type="text/css">body { -ms-user-select:none;-moz-user-select:-moz-none;-khtml-user-select:none;-webkit-user-select:none;user-select:none; }</style>'); |
| 578 |
$(document.head).append($style); |
| 579 |
$(document.body).attr('onselectstart', 'return false;').attr('unselectable', 'on'); |
| 580 |
if (window.getSelection) { |
| 581 |
window.getSelection().removeAllRanges(); |
| 582 |
} else { |
| 583 |
document.selection.empty(); |
| 584 |
} |
| 585 |
} |
| 586 |
|
| 587 |
|
| 588 |
function restoreTextSelection() { |
| 589 |
$('#__dragtable_disable_text_selection__').remove(); |
| 590 |
if (body_onselectstart_save) { |
| 591 |
$(document.body).attr('onselectstart', body_onselectstart_save); |
| 592 |
} else { |
| 593 |
$(document.body).removeAttr('onselectstart'); |
| 594 |
} |
| 595 |
if (body_unselectable_save) { |
| 596 |
$(document.body).attr('unselectable', body_unselectable_save); |
| 597 |
} else { |
| 598 |
$(document.body).removeAttr('unselectable'); |
| 599 |
} |
| 600 |
} |
| 601 |
|
| 602 |
})(jQuery); |