datatables.net-rowreorder
Advanced tools
Comparing version 1.3.3 to 1.4.0
@@ -1,2 +0,2 @@ | ||
/*! RowReorder 1.3.3 | ||
/*! RowReorder 1.4.0 | ||
* © SpryMedia Ltd - datatables.net/license | ||
@@ -21,3 +21,3 @@ */ | ||
if (typeof window !== 'undefined') { | ||
if (typeof window === 'undefined') { | ||
module.exports = function (root, $) { | ||
@@ -56,3 +56,3 @@ if ( ! root ) { | ||
* @description Row reordering extension for DataTables | ||
* @version 1.3.3 | ||
* @version 1.4.0 | ||
* @file dataTables.rowReorder.js | ||
@@ -87,3 +87,3 @@ * @author SpryMedia Ltd | ||
* initialisation. | ||
* | ||
* | ||
* @class | ||
@@ -95,5 +95,5 @@ * @param {object} settings DataTables settings object for the host table | ||
*/ | ||
var RowReorder = function ( dt, opts ) { | ||
var RowReorder = function (dt, opts) { | ||
// Sanity check that we are using DataTables 1.10 or newer | ||
if ( ! DataTable.versionCheck || ! DataTable.versionCheck( '1.10.8' ) ) { | ||
if (!DataTable.versionCheck || !DataTable.versionCheck('1.10.8')) { | ||
throw 'DataTables RowReorder requires DataTables 1.10.8 or newer'; | ||
@@ -103,7 +103,3 @@ } | ||
// User and defaults configuration object | ||
this.c = $.extend( true, {}, | ||
DataTable.defaults.rowReorder, | ||
RowReorder.defaults, | ||
opts | ||
); | ||
this.c = $.extend(true, {}, DataTable.defaults.rowReorder, RowReorder.defaults, opts); | ||
@@ -116,6 +112,6 @@ // Internal settings | ||
/** @type {DataTable.Api} DataTables' API instance */ | ||
dt: new DataTable.Api( dt ), | ||
dt: new DataTable.Api(dt), | ||
/** @type {function} Data fetch function */ | ||
getDataFn: DataTable.ext.oApi._fnGetObjectDataFn( this.c.dataSrc ), | ||
getDataFn: DataTable.ext.oApi._fnGetObjectDataFn(this.c.dataSrc), | ||
@@ -132,3 +128,3 @@ /** @type {array} Pixel positions for row insertion calculation */ | ||
/** @type {function} Data set function */ | ||
setDataFn: DataTable.ext.oApi._fnSetObjectDataFn( this.c.dataSrc ), | ||
setDataFn: DataTable.ext.oApi._fnSetObjectDataFn(this.c.dataSrc), | ||
@@ -141,3 +137,4 @@ /** @type {Object} Mouse down information */ | ||
offsetLeft: 0, | ||
nodes: [] | ||
nodes: [], | ||
rowIndex: 0 | ||
}, | ||
@@ -152,3 +149,6 @@ | ||
/** @type {integer} DOM clone outer height cached value */ | ||
domCloneOuterHeight: 0 | ||
domCloneOuterHeight: 0, | ||
/** @type {integer} Flag used for signing if the drop is enabled or not */ | ||
dropAllowed: true | ||
}; | ||
@@ -170,8 +170,8 @@ | ||
if ( exisiting ) { | ||
if (exisiting) { | ||
return exisiting; | ||
} | ||
if ( !this.dom.dtScroll.length ) { | ||
this.dom.dtScroll = $(this.s.dt.table().container(), 'tbody') | ||
if (!this.dom.dtScroll.length) { | ||
this.dom.dtScroll = $(this.s.dt.table().container(), 'tbody'); | ||
} | ||
@@ -183,4 +183,3 @@ | ||
$.extend( RowReorder.prototype, { | ||
$.extend(RowReorder.prototype, { | ||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | ||
@@ -195,11 +194,10 @@ * Constructor | ||
*/ | ||
_constructor: function () | ||
{ | ||
_constructor: function () { | ||
var that = this; | ||
var dt = this.s.dt; | ||
var table = $( dt.table().node() ); | ||
var table = $(dt.table().node()); | ||
// Need to be able to calculate the row positions relative to the table | ||
if ( table.css('position') === 'static' ) { | ||
table.css( 'position', 'relative' ); | ||
if (table.css('position') === 'static') { | ||
table.css('position', 'relative'); | ||
} | ||
@@ -213,38 +211,43 @@ | ||
// otherwise it only works once... | ||
$(dt.table().container()).on( 'mousedown.rowReorder touchstart.rowReorder', this.c.selector, function (e) { | ||
if ( ! that.c.enable ) { | ||
return; | ||
} | ||
$(dt.table().container()).on( | ||
'mousedown.rowReorder touchstart.rowReorder', | ||
this.c.selector, | ||
function (e) { | ||
if (!that.c.enable) { | ||
return; | ||
} | ||
// Ignore excluded children of the selector | ||
if ( $(e.target).is(that.c.excludedChildren) ) { | ||
return true; | ||
} | ||
// Ignore excluded children of the selector | ||
if ($(e.target).is(that.c.excludedChildren)) { | ||
return true; | ||
} | ||
var tr = $(this).closest('tr'); | ||
var row = dt.row( tr ); | ||
var tr = $(this).closest('tr'); | ||
var row = dt.row(tr); | ||
// Double check that it is a DataTable row | ||
if ( row.any() ) { | ||
that._emitEvent( 'pre-row-reorder', { | ||
node: row.node(), | ||
index: row.index() | ||
} ); | ||
// Double check that it is a DataTable row | ||
if (row.any()) { | ||
that._emitEvent('pre-row-reorder', { | ||
node: row.node(), | ||
index: row.index() | ||
}); | ||
that._mouseDown( e, tr ); | ||
return false; | ||
that._mouseDown(e, tr); | ||
return false; | ||
} | ||
} | ||
} ); | ||
); | ||
dt.on( 'destroy.rowReorder', function () { | ||
$(dt.table().container()).off( '.rowReorder' ); | ||
dt.off( '.rowReorder' ); | ||
} ); | ||
dt.on('destroy.rowReorder', function () { | ||
$(dt.table().container()).off('.rowReorder'); | ||
dt.off('.rowReorder'); | ||
}); | ||
this._keyup = this._keyup.bind(this); | ||
}, | ||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * | ||
* Private methods | ||
*/ | ||
/** | ||
@@ -256,4 +259,3 @@ * Cache the measurements that RowReorder needs in the mouse move handler | ||
*/ | ||
_cachePositions: function () | ||
{ | ||
_cachePositions: function () { | ||
var dt = this.s.dt; | ||
@@ -264,3 +266,3 @@ | ||
// for that | ||
var headerHeight = $( dt.table().node() ).find('thead').outerHeight(); | ||
var headerHeight = $(dt.table().node()).find('thead').outerHeight(); | ||
@@ -270,16 +272,16 @@ // Need to pass the nodes through jQuery to get them in document order, | ||
// order | ||
var nodes = $.unique( dt.rows( { page: 'current' } ).nodes().toArray() ); | ||
var middles = $.map( nodes, function ( node, i ) { | ||
var nodes = $.unique(dt.rows({ page: 'current' }).nodes().toArray()); | ||
var middles = $.map(nodes, function (node, i) { | ||
var top = $(node).position().top - headerHeight; | ||
return (top + top + $(node).outerHeight() ) / 2; | ||
} ); | ||
return (top + top + $(node).outerHeight()) / 2; | ||
}); | ||
this.s.middles = middles; | ||
this.s.bodyTop = $( dt.table().body() ).offset().top; | ||
this.s.bodyTop = $(dt.table().body()).offset().top; | ||
this.s.windowHeight = $(window).height(); | ||
this.s.documentOuterHeight = $(document).outerHeight(); | ||
this.s.bodyArea = this._calcBodyArea(); | ||
}, | ||
/** | ||
@@ -291,9 +293,8 @@ * Clone a row so it can be floated around the screen | ||
*/ | ||
_clone: function ( target ) | ||
{ | ||
_clone: function (target) { | ||
var dt = this.s.dt; | ||
var clone = $( dt.table().node().cloneNode(false) ) | ||
.addClass( 'dt-rowReorder-float' ) | ||
var clone = $(dt.table().node().cloneNode(false)) | ||
.addClass('dt-rowReorder-float') | ||
.append('<tbody/>') | ||
.append( target.clone( false ) ); | ||
.append(target.clone(false)); | ||
@@ -307,12 +308,14 @@ // Match the table and column widths - read all sizes before setting | ||
var scrollLeft = scrollBody.scrollLeft(); | ||
var sizes = target.children().map( function () { | ||
var sizes = target.children().map(function () { | ||
return $(this).width(); | ||
} ); | ||
}); | ||
clone | ||
.width( tableWidth ) | ||
.height( tableHeight ) | ||
.find('tr').children().each( function (i) { | ||
this.style.width = sizes[i]+'px'; | ||
} ); | ||
.width(tableWidth) | ||
.height(tableHeight) | ||
.find('tr') | ||
.children() | ||
.each(function (i) { | ||
this.style.width = sizes[i] + 'px'; | ||
}); | ||
@@ -323,3 +326,3 @@ var cloneParent = $('<div>') | ||
.append(clone) | ||
.appendTo( 'body' ) | ||
.appendTo('body') | ||
.scrollLeft(scrollLeft); | ||
@@ -334,3 +337,2 @@ | ||
/** | ||
@@ -342,7 +344,6 @@ * Update the cloned item's position in the document | ||
*/ | ||
_clonePosition: function ( e ) | ||
{ | ||
_clonePosition: function (e) { | ||
var start = this.s.start; | ||
var topDiff = this._eventToPage( e, 'Y' ) - start.top; | ||
var leftDiff = this._eventToPage( e, 'X' ) - start.left; | ||
var topDiff = this._eventToPage(e, 'Y') - start.top; | ||
var leftDiff = this._eventToPage(e, 'X') - start.left; | ||
var snap = this.c.snapX; | ||
@@ -352,6 +353,6 @@ var left; | ||
if ( snap === true ) { | ||
if (snap === true) { | ||
left = start.offsetLeft; | ||
} | ||
else if ( typeof snap === 'number' ) { | ||
else if (typeof snap === 'number') { | ||
left = start.offsetLeft + snap; | ||
@@ -363,16 +364,15 @@ } | ||
if(top < 0) { | ||
top = 0 | ||
if (top < 0) { | ||
top = 0; | ||
} | ||
else if(top + this.s.domCloneOuterHeight > this.s.documentOuterHeight) { | ||
else if (top + this.s.domCloneOuterHeight > this.s.documentOuterHeight) { | ||
top = this.s.documentOuterHeight - this.s.domCloneOuterHeight; | ||
} | ||
this.dom.cloneParent.css( { | ||
this.dom.cloneParent.css({ | ||
top: top, | ||
left: left | ||
} ); | ||
}); | ||
}, | ||
/** | ||
@@ -385,10 +385,8 @@ * Emit an event on the DataTable for listeners | ||
*/ | ||
_emitEvent: function ( name, args ) | ||
{ | ||
this.s.dt.iterator( 'table', function ( ctx, i ) { | ||
$(ctx.nTable).triggerHandler( name+'.dt', args ); | ||
} ); | ||
_emitEvent: function (name, args) { | ||
this.s.dt.iterator('table', function (ctx, i) { | ||
$(ctx.nTable).triggerHandler(name + '.dt', args); | ||
}); | ||
}, | ||
/** | ||
@@ -402,12 +400,10 @@ * Get pageX/Y position from an event, regardless of if it is a mouse or | ||
*/ | ||
_eventToPage: function ( e, pos ) | ||
{ | ||
if ( e.type.indexOf( 'touch' ) !== -1 ) { | ||
return e.originalEvent.touches[0][ 'page'+pos ]; | ||
_eventToPage: function (e, pos) { | ||
if (e.type.indexOf('touch') !== -1) { | ||
return e.originalEvent.touches[0]['page' + pos]; | ||
} | ||
return e[ 'page'+pos ]; | ||
return e['page' + pos]; | ||
}, | ||
/** | ||
@@ -421,34 +417,37 @@ * Mouse down event handler. Read initial positions and add event handlers | ||
*/ | ||
_mouseDown: function ( e, target ) | ||
{ | ||
_mouseDown: function (e, target) { | ||
var that = this; | ||
var dt = this.s.dt; | ||
var start = this.s.start; | ||
var cancelable = this.c.cancelable; | ||
var offset = target.offset(); | ||
start.top = this._eventToPage( e, 'Y' ); | ||
start.left = this._eventToPage( e, 'X' ); | ||
start.top = this._eventToPage(e, 'Y'); | ||
start.left = this._eventToPage(e, 'X'); | ||
start.offsetTop = offset.top; | ||
start.offsetLeft = offset.left; | ||
start.nodes = $.unique( dt.rows( { page: 'current' } ).nodes().toArray() ); | ||
start.nodes = $.unique(dt.rows({ page: 'current' }).nodes().toArray()); | ||
this._cachePositions(); | ||
this._clone( target ); | ||
this._clonePosition( e ); | ||
this._clone(target); | ||
this._clonePosition(e); | ||
var bodyY = this._eventToPage(e, 'Y') - this.s.bodyTop; | ||
start.rowIndex = this._calcRowIndexByPos(bodyY); | ||
this.dom.target = target; | ||
target.addClass( 'dt-rowReorder-moving' ); | ||
target.addClass('dt-rowReorder-moving'); | ||
$( document ) | ||
.on( 'mouseup.rowReorder touchend.rowReorder', function (e) { | ||
$(document) | ||
.on('mouseup.rowReorder touchend.rowReorder', function (e) { | ||
that._mouseUp(e); | ||
} ) | ||
.on( 'mousemove.rowReorder touchmove.rowReorder', function (e) { | ||
}) | ||
.on('mousemove.rowReorder touchmove.rowReorder', function (e) { | ||
that._mouseMove(e); | ||
} ); | ||
}); | ||
// Check if window is x-scrolling - if not, disable it for the duration | ||
// of the drag | ||
if ( $(window).width() === $(document).width() ) { | ||
$(document.body).addClass( 'dt-rowReorder-noOverflow' ); | ||
if ($(window).width() === $(document).width()) { | ||
$(document.body).addClass('dt-rowReorder-noOverflow'); | ||
} | ||
@@ -462,11 +461,15 @@ | ||
windowHeight: $(window).height(), | ||
windowWidth: $(window).width(), | ||
dtTop: scrollWrapper.length ? scrollWrapper.offset().top : null, | ||
dtLeft: scrollWrapper.length ? scrollWrapper.offset().left : null, | ||
dtHeight: scrollWrapper.length ? scrollWrapper.outerHeight() : null, | ||
dtWidth: scrollWrapper.length ? scrollWrapper.outerWidth() : null | ||
windowWidth: $(window).width(), | ||
dtTop: scrollWrapper.length ? scrollWrapper.offset().top : null, | ||
dtLeft: scrollWrapper.length ? scrollWrapper.offset().left : null, | ||
dtHeight: scrollWrapper.length ? scrollWrapper.outerHeight() : null, | ||
dtWidth: scrollWrapper.length ? scrollWrapper.outerWidth() : null | ||
}; | ||
// Add keyup handler if dragging is cancelable | ||
if (cancelable) { | ||
$(document).on('keyup', this._keyup); | ||
} | ||
}, | ||
/** | ||
@@ -479,16 +482,27 @@ * Mouse move event handler - move the cloned row and shuffle the table's | ||
*/ | ||
_mouseMove: function ( e ) | ||
{ | ||
this._clonePosition( e ); | ||
_mouseMove: function (e) { | ||
this._clonePosition(e); | ||
var start = this.s.start; | ||
var cancelable = this.c.cancelable; | ||
if (cancelable) { | ||
var bodyArea = this.s.bodyArea; | ||
var cloneArea = this._calcCloneParentArea(); | ||
this.s.dropAllowed = this._rectanglesIntersect(bodyArea, cloneArea); | ||
this.s.dropAllowed | ||
? $(this.dom.cloneParent).removeClass('drop-not-allowed') | ||
: $(this.dom.cloneParent).addClass('drop-not-allowed'); | ||
} | ||
// Transform the mouse position into a position in the table's body | ||
var bodyY = this._eventToPage( e, 'Y' ) - this.s.bodyTop; | ||
var bodyY = this._eventToPage(e, 'Y') - this.s.bodyTop; | ||
var middles = this.s.middles; | ||
var insertPoint = null; | ||
var dt = this.s.dt; | ||
// Determine where the row should be inserted based on the mouse | ||
// position | ||
for ( var i=0, ien=middles.length ; i<ien ; i++ ) { | ||
if ( bodyY < middles[i] ) { | ||
for (var i = 0, ien = middles.length; i < ien; i++) { | ||
if (bodyY < middles[i]) { | ||
insertPoint = i; | ||
@@ -499,26 +513,21 @@ break; | ||
if ( insertPoint === null ) { | ||
if (insertPoint === null) { | ||
insertPoint = middles.length; | ||
} | ||
// Perform the DOM shuffle if it has changed from last time | ||
if ( this.s.lastInsert === null || this.s.lastInsert !== insertPoint ) { | ||
var nodes = $.unique( dt.rows( { page: 'current' } ).nodes().toArray() ); | ||
if ( insertPoint > this.s.lastInsert ) { | ||
this.dom.target.insertAfter( nodes[ insertPoint-1 ] ); | ||
if (cancelable) { | ||
if (!this.s.dropAllowed) { | ||
// Move the row back to its original position becasuse the drop is not allowed | ||
insertPoint = | ||
start.rowIndex > this.s.lastInsert ? start.rowIndex + 1 : start.rowIndex; | ||
} | ||
else { | ||
this.dom.target.insertBefore( nodes[ insertPoint ] ); | ||
} | ||
this._cachePositions(); | ||
this.s.lastInsert = insertPoint; | ||
this.dom.target.toggleClass('dt-rowReorder-moving', this.s.dropAllowed); | ||
} | ||
this._shiftScroll( e ); | ||
this._moveTargetIntoPosition(insertPoint); | ||
this._shiftScroll(e); | ||
}, | ||
/** | ||
@@ -531,4 +540,3 @@ * Mouse up event handler - release the event handlers and perform the | ||
*/ | ||
_mouseUp: function ( e ) | ||
{ | ||
_mouseUp: function (e) { | ||
var that = this; | ||
@@ -538,20 +546,15 @@ var dt = this.s.dt; | ||
var dataSrc = this.c.dataSrc; | ||
var dropAllowed = this.s.dropAllowed; | ||
this.dom.clone.remove(); | ||
this.dom.cloneParent.remove(); | ||
this.dom.clone = null; | ||
this.dom.cloneParent = null; | ||
if (!dropAllowed) { | ||
that._cancel(); | ||
return; | ||
} | ||
this.dom.target.removeClass( 'dt-rowReorder-moving' ); | ||
//this.dom.target = null; | ||
// Remove cloned elements, handlers, etc | ||
this._cleanupDragging(); | ||
$(document).off( '.rowReorder' ); | ||
$(document.body).removeClass( 'dt-rowReorder-noOverflow' ); | ||
clearInterval( this.s.scrollInterval ); | ||
this.s.scrollInterval = null; | ||
// Calculate the difference | ||
var startNodes = this.s.start.nodes; | ||
var endNodes = $.unique( dt.rows( { page: 'current' } ).nodes().toArray() ); | ||
var endNodes = $.unique(dt.rows({ page: 'current' }).nodes().toArray()); | ||
var idDiff = {}; | ||
@@ -563,56 +566,59 @@ var fullDiff = []; | ||
for ( i=0, ien=startNodes.length ; i<ien ; i++ ) { | ||
if ( startNodes[i] !== endNodes[i] ) { | ||
var id = dt.row( endNodes[i] ).id(); | ||
var endRowData = dt.row( endNodes[i] ).data(); | ||
var startRowData = dt.row( startNodes[i] ).data(); | ||
for (i = 0, ien = startNodes.length; i < ien; i++) { | ||
if (startNodes[i] !== endNodes[i]) { | ||
var id = dt.row(endNodes[i]).id(); | ||
var endRowData = dt.row(endNodes[i]).data(); | ||
var startRowData = dt.row(startNodes[i]).data(); | ||
if ( id ) { | ||
idDiff[ id ] = getDataFn( startRowData ); | ||
if (id) { | ||
idDiff[id] = getDataFn(startRowData); | ||
} | ||
fullDiff.push( { | ||
fullDiff.push({ | ||
node: endNodes[i], | ||
oldData: getDataFn( endRowData ), | ||
newData: getDataFn( startRowData ), | ||
oldData: getDataFn(endRowData), | ||
newData: getDataFn(startRowData), | ||
newPosition: i, | ||
oldPosition: $.inArray( endNodes[i], startNodes ) | ||
} ); | ||
oldPosition: $.inArray(endNodes[i], startNodes) | ||
}); | ||
diffNodes.push( endNodes[i] ); | ||
diffNodes.push(endNodes[i]); | ||
} | ||
} | ||
// Create event args | ||
var eventArgs = [ fullDiff, { | ||
dataSrc: dataSrc, | ||
nodes: diffNodes, | ||
values: idDiff, | ||
triggerRow: dt.row( this.dom.target ), | ||
originalEvent: e | ||
} ]; | ||
var eventArgs = [ | ||
fullDiff, | ||
{ | ||
dataSrc: dataSrc, | ||
nodes: diffNodes, | ||
values: idDiff, | ||
triggerRow: dt.row(this.dom.target), | ||
originalEvent: e | ||
} | ||
]; | ||
// Emit event | ||
this._emitEvent( 'row-reorder', eventArgs ); | ||
this._emitEvent('row-reorder', eventArgs); | ||
var update = function () { | ||
if ( that.c.update ) { | ||
for ( i=0, ien=fullDiff.length ; i<ien ; i++ ) { | ||
var row = dt.row( fullDiff[i].node ); | ||
if (that.c.update) { | ||
for (i = 0, ien = fullDiff.length; i < ien; i++) { | ||
var row = dt.row(fullDiff[i].node); | ||
var rowData = row.data(); | ||
setDataFn( rowData, fullDiff[i].newData ); | ||
setDataFn(rowData, fullDiff[i].newData); | ||
// Invalidate the cell that has the same data source as the dataSrc | ||
dt.columns().every( function () { | ||
if ( this.dataSrc() === dataSrc ) { | ||
dt.cell( fullDiff[i].node, this.index() ).invalidate( 'data' ); | ||
dt.columns().every(function () { | ||
if (this.dataSrc() === dataSrc) { | ||
dt.cell(fullDiff[i].node, this.index()).invalidate('data'); | ||
} | ||
} ); | ||
}); | ||
} | ||
// Trigger row reordered event | ||
that._emitEvent( 'row-reordered', eventArgs ); | ||
that._emitEvent('row-reordered', eventArgs); | ||
dt.draw( false ); | ||
dt.draw(false); | ||
} | ||
@@ -622,3 +628,3 @@ }; | ||
// Editor interface | ||
if ( this.c.editor ) { | ||
if (this.c.editor) { | ||
// Disable user interaction while Editor is submitting | ||
@@ -628,23 +634,19 @@ this.c.enable = false; | ||
this.c.editor | ||
.edit( | ||
diffNodes, | ||
false, | ||
$.extend( {submit: 'changed'}, this.c.formOptions ) | ||
) | ||
.multiSet( dataSrc, idDiff ) | ||
.one( 'preSubmitCancelled.rowReorder', function () { | ||
.edit(diffNodes, false, $.extend({ submit: 'changed' }, this.c.formOptions)) | ||
.multiSet(dataSrc, idDiff) | ||
.one('preSubmitCancelled.rowReorder', function () { | ||
that.c.enable = true; | ||
that.c.editor.off( '.rowReorder' ); | ||
dt.draw( false ); | ||
} ) | ||
.one( 'submitUnsuccessful.rowReorder', function () { | ||
dt.draw( false ); | ||
} ) | ||
.one( 'submitSuccess.rowReorder', function () { | ||
that.c.editor.off('.rowReorder'); | ||
dt.draw(false); | ||
}) | ||
.one('submitUnsuccessful.rowReorder', function () { | ||
dt.draw(false); | ||
}) | ||
.one('submitSuccess.rowReorder', function () { | ||
update(); | ||
} ) | ||
.one( 'submitComplete', function () { | ||
}) | ||
.one('submitComplete', function () { | ||
that.c.enable = true; | ||
that.c.editor.off( '.rowReorder' ); | ||
} ) | ||
that.c.editor.off('.rowReorder'); | ||
}) | ||
.submit(); | ||
@@ -657,4 +659,66 @@ } | ||
/** | ||
* Moves the current target into the given position within the table | ||
* and caches the new positions | ||
* | ||
* @param {integer} insertPoint Position | ||
* @private | ||
*/ | ||
_moveTargetIntoPosition: function (insertPoint) { | ||
var dt = this.s.dt; | ||
// Perform the DOM shuffle if it has changed from last time | ||
if (this.s.lastInsert === null || this.s.lastInsert !== insertPoint) { | ||
var nodes = $.unique(dt.rows({ page: 'current' }).nodes().toArray()); | ||
var insertPlacement = ''; | ||
if (insertPoint > this.s.lastInsert) { | ||
this.dom.target.insertAfter(nodes[insertPoint - 1]); | ||
insertPlacement = 'after'; | ||
} | ||
else { | ||
this.dom.target.insertBefore(nodes[insertPoint]); | ||
insertPlacement = 'before'; | ||
} | ||
this._cachePositions(); | ||
this.s.lastInsert = insertPoint; | ||
this._emitEvent('row-reorder-changed', { | ||
insertPlacement, | ||
insertPoint, | ||
row: dt.row(this.dom.target) | ||
}); | ||
} | ||
}, | ||
/** | ||
* Removes the cloned elements, event handlers, scrolling intervals, etc | ||
* | ||
* @private | ||
*/ | ||
_cleanupDragging: function () { | ||
var cancelable = this.c.cancelable; | ||
this.dom.clone.remove(); | ||
this.dom.cloneParent.remove(); | ||
this.dom.clone = null; | ||
this.dom.cloneParent = null; | ||
this.dom.target.removeClass('dt-rowReorder-moving'); | ||
//this.dom.target = null; | ||
$(document).off('.rowReorder'); | ||
$(document.body).removeClass('dt-rowReorder-noOverflow'); | ||
clearInterval(this.s.scrollInterval); | ||
this.s.scrollInterval = null; | ||
if (cancelable) { | ||
$(document).off('keyup', this._keyup); | ||
} | ||
}, | ||
/** | ||
* Move the window and DataTables scrolling during a drag to scroll new | ||
@@ -669,4 +733,3 @@ * content into view. | ||
*/ | ||
_shiftScroll: function ( e ) | ||
{ | ||
_shiftScroll: function (e) { | ||
var that = this; | ||
@@ -678,4 +741,3 @@ var dt = this.s.dt; | ||
var buffer = 65; | ||
var | ||
windowY = e.pageY - document.body.scrollTop, | ||
var windowY = e.pageY - document.body.scrollTop, | ||
windowVert, | ||
@@ -686,6 +748,6 @@ dtVert; | ||
// regardless of scrolling | ||
if ( windowY < $(window).scrollTop() + buffer ) { | ||
if (windowY < $(window).scrollTop() + buffer) { | ||
windowVert = scrollSpeed * -1; | ||
} | ||
else if ( windowY > scroll.windowHeight + $(window).scrollTop() - buffer ) { | ||
else if (windowY > scroll.windowHeight + $(window).scrollTop() - buffer) { | ||
windowVert = scrollSpeed; | ||
@@ -696,6 +758,6 @@ } | ||
// the document and the mouse position on the page | ||
if ( scroll.dtTop !== null && e.pageY < scroll.dtTop + buffer ) { | ||
if (scroll.dtTop !== null && e.pageY < scroll.dtTop + buffer) { | ||
dtVert = scrollSpeed * -1; | ||
} | ||
else if ( scroll.dtTop !== null && e.pageY > scroll.dtTop + scroll.dtHeight - buffer ) { | ||
else if (scroll.dtTop !== null && e.pageY > scroll.dtTop + scroll.dtHeight - buffer) { | ||
dtVert = scrollSpeed; | ||
@@ -712,3 +774,3 @@ } | ||
// wouldn't be the ones that are used by an already existing interval! | ||
if ( windowVert || dtVert ) { | ||
if (windowVert || dtVert) { | ||
scroll.windowVert = windowVert; | ||
@@ -718,5 +780,5 @@ scroll.dtVert = dtVert; | ||
} | ||
else if ( this.s.scrollInterval ) { | ||
else if (this.s.scrollInterval) { | ||
// Don't need to scroll - remove any existing timer | ||
clearInterval( this.s.scrollInterval ); | ||
clearInterval(this.s.scrollInterval); | ||
this.s.scrollInterval = null; | ||
@@ -727,13 +789,13 @@ } | ||
// interval (if there is an existing one, it will continue to run) | ||
if ( ! this.s.scrollInterval && runInterval ) { | ||
this.s.scrollInterval = setInterval( function () { | ||
if (!this.s.scrollInterval && runInterval) { | ||
this.s.scrollInterval = setInterval(function () { | ||
// Don't need to worry about setting scroll <0 or beyond the | ||
// scroll bound as the browser will just reject that. | ||
if ( scroll.windowVert ) { | ||
if (scroll.windowVert) { | ||
var top = $(document).scrollTop(); | ||
$(document).scrollTop(top + scroll.windowVert); | ||
if ( top !== $(document).scrollTop() ) { | ||
var move = parseFloat(that.dom.cloneParent.css("top")); | ||
that.dom.cloneParent.css("top", move + scroll.windowVert); | ||
if (top !== $(document).scrollTop()) { | ||
var move = parseFloat(that.dom.cloneParent.css('top')); | ||
that.dom.cloneParent.css('top', move + scroll.windowVert); | ||
} | ||
@@ -743,16 +805,125 @@ } | ||
// DataTables scrolling | ||
if ( scroll.dtVert ) { | ||
if (scroll.dtVert) { | ||
var scroller = that.dom.dtScroll[0]; | ||
if ( scroll.dtVert ) { | ||
if (scroll.dtVert) { | ||
scroller.scrollTop += scroll.dtVert; | ||
} | ||
} | ||
}, 20 ); | ||
}, 20); | ||
} | ||
} | ||
} ); | ||
}, | ||
/** | ||
* Calculates the current area of the table body and returns it as a rectangle | ||
* | ||
* @private | ||
*/ | ||
_calcBodyArea: function (e) { | ||
var dt = this.s.dt; | ||
var offset = $(dt.table().body()).offset(); | ||
var area = { | ||
left: offset.left, | ||
top: offset.top, | ||
right: offset.left + $(dt.table().body()).width(), | ||
bottom: offset.top + $(dt.table().body()).height() | ||
}; | ||
return area; | ||
}, | ||
/** | ||
* Calculates the current area of the cloned parent element and returns it as a rectangle | ||
* | ||
* @private | ||
*/ | ||
_calcCloneParentArea: function (e) { | ||
var dt = this.s.dt; | ||
var offset = $(this.dom.cloneParent).offset(); | ||
var area = { | ||
left: offset.left, | ||
top: offset.top, | ||
right: offset.left + $(this.dom.cloneParent).width(), | ||
bottom: offset.top + $(this.dom.cloneParent).height() | ||
}; | ||
return area; | ||
}, | ||
/** | ||
* Returns whether the given reactangles intersect or not | ||
* | ||
* @private | ||
*/ | ||
_rectanglesIntersect: function (a, b) { | ||
var noOverlap = | ||
a.left >= b.right || b.left >= a.right || a.top >= b.bottom || b.top >= a.bottom; | ||
return !noOverlap; | ||
}, | ||
/** | ||
* Calculates the index of the row which lays under the given Y position or | ||
* returns -1 if no such row | ||
* | ||
* @param {integer} insertPoint Position | ||
* @private | ||
*/ | ||
_calcRowIndexByPos: function (bodyY) { | ||
// Determine where the row is located based on the mouse | ||
// position | ||
var dt = this.s.dt; | ||
var nodes = $.unique(dt.rows({ page: 'current' }).nodes().toArray()); | ||
var rowIndex = -1; | ||
var headerHeight = $(dt.table().node()).find('thead').outerHeight(); | ||
$.each(nodes, function (i, node) { | ||
var top = $(node).position().top - headerHeight; | ||
var bottom = top + $(node).outerHeight(); | ||
if (bodyY >= top && bodyY <= bottom) { | ||
rowIndex = i; | ||
} | ||
}); | ||
return rowIndex; | ||
}, | ||
/** | ||
* Handles key up events and cancels the dragging if ESC key is pressed | ||
* | ||
* @param {object} e Mouse move event object | ||
* @private | ||
*/ | ||
_keyup: function (e) { | ||
var cancelable = this.c.cancelable; | ||
if (cancelable && e.which === 27) { | ||
// ESC key is up | ||
e.preventDefault(); | ||
this._cancel(); | ||
} | ||
}, | ||
/** | ||
* Cancels the dragging, moves target back into its original position | ||
* and cleans up the dragging | ||
* | ||
* @param {object} e Mouse move event object | ||
* @private | ||
*/ | ||
_cancel: function () { | ||
var start = this.s.start; | ||
var insertPoint = start.rowIndex > this.s.lastInsert ? start.rowIndex + 1 : start.rowIndex; | ||
this._moveTargetIntoPosition(insertPoint); | ||
this._cleanupDragging(); | ||
// Emit event | ||
this._emitEvent('row-reorder-canceled', [this.s.start.rowIndex]); | ||
} | ||
}); | ||
/** | ||
@@ -825,6 +996,12 @@ * RowReorder default settings for initialisation | ||
*/ | ||
excludedChildren: 'a' | ||
excludedChildren: 'a', | ||
/** | ||
* Enable / disable the canceling of the drag & drop interaction | ||
* | ||
* @type {Boolean} | ||
*/ | ||
cancelable: false | ||
}; | ||
/* | ||
@@ -836,27 +1013,26 @@ * API | ||
// Doesn't do anything - work around for a bug in DT... Not documented | ||
Api.register( 'rowReorder()', function () { | ||
Api.register('rowReorder()', function () { | ||
return this; | ||
} ); | ||
}); | ||
Api.register( 'rowReorder.enable()', function ( toggle ) { | ||
if ( toggle === undefined ) { | ||
Api.register('rowReorder.enable()', function (toggle) { | ||
if (toggle === undefined) { | ||
toggle = true; | ||
} | ||
return this.iterator( 'table', function ( ctx ) { | ||
if ( ctx.rowreorder ) { | ||
return this.iterator('table', function (ctx) { | ||
if (ctx.rowreorder) { | ||
ctx.rowreorder.c.enable = toggle; | ||
} | ||
} ); | ||
} ); | ||
}); | ||
}); | ||
Api.register( 'rowReorder.disable()', function () { | ||
return this.iterator( 'table', function ( ctx ) { | ||
if ( ctx.rowreorder ) { | ||
Api.register('rowReorder.disable()', function () { | ||
return this.iterator('table', function (ctx) { | ||
if (ctx.rowreorder) { | ||
ctx.rowreorder.c.enable = false; | ||
} | ||
} ); | ||
} ); | ||
}); | ||
}); | ||
/** | ||
@@ -868,5 +1044,4 @@ * Version information | ||
*/ | ||
RowReorder.version = '1.3.3'; | ||
RowReorder.version = '1.4.0'; | ||
$.fn.dataTable.RowReorder = RowReorder; | ||
@@ -877,4 +1052,4 @@ $.fn.DataTable.RowReorder = RowReorder; | ||
// events so we can automatically initialise | ||
$(document).on( 'init.dt.dtr', function (e, settings, json) { | ||
if ( e.namespace !== 'dt' ) { | ||
$(document).on('init.dt.dtr', function (e, settings, json) { | ||
if (e.namespace !== 'dt') { | ||
return; | ||
@@ -886,10 +1061,10 @@ } | ||
if ( init || defaults ) { | ||
var opts = $.extend( {}, init, defaults ); | ||
if (init || defaults) { | ||
var opts = $.extend({}, init, defaults); | ||
if ( init !== false ) { | ||
new RowReorder( settings, opts ); | ||
if (init !== false) { | ||
new RowReorder(settings, opts); | ||
} | ||
} | ||
} ); | ||
}); | ||
@@ -896,0 +1071,0 @@ |
@@ -1,4 +0,4 @@ | ||
/*! RowReorder 1.3.3 | ||
/*! RowReorder 1.4.0 | ||
* © SpryMedia Ltd - datatables.net/license | ||
*/ | ||
!function(o){var r,n;"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function(t){return o(t,window,document)}):"object"==typeof exports?(r=require("jquery"),n=function(t,e){e.fn.dataTable||require("datatables.net")(t,e)},"undefined"!=typeof window?module.exports=function(t,e){return t=t||window,e=e||r(t),n(t,e),o(e,t,t.document)}:(n(window,r),module.exports=o(r,window,window.document))):o(jQuery,window,document)}(function(v,d,b,t){"use strict";function n(t,e){if(!s.versionCheck||!s.versionCheck("1.10.8"))throw"DataTables RowReorder requires DataTables 1.10.8 or newer";if(this.c=v.extend(!0,{},s.defaults.rowReorder,n.defaults,e),this.s={bodyTop:null,dt:new s.Api(t),getDataFn:s.ext.oApi._fnGetObjectDataFn(this.c.dataSrc),middles:null,scroll:{},scrollInterval:null,setDataFn:s.ext.oApi._fnSetObjectDataFn(this.c.dataSrc),start:{top:0,left:0,offsetTop:0,offsetLeft:0,nodes:[]},windowHeight:0,documentOuterHeight:0,domCloneOuterHeight:0},this.dom={clone:null,cloneParent:null,dtScroll:v("div.dataTables_scrollBody",this.s.dt.table().container())},e=this.s.dt.settings()[0],t=e.rowreorder)return t;this.dom.dtScroll.length||(this.dom.dtScroll=v(this.s.dt.table().container(),"tbody")),(e.rowreorder=this)._constructor()}var s=v.fn.dataTable,e=(v.extend(n.prototype,{_constructor:function(){var r=this,n=this.s.dt,t=v(n.table().node());"static"===t.css("position")&&t.css("position","relative"),v(n.table().container()).on("mousedown.rowReorder touchstart.rowReorder",this.c.selector,function(t){var e,o;if(r.c.enable)return!!v(t.target).is(r.c.excludedChildren)||(e=v(this).closest("tr"),(o=n.row(e)).any()?(r._emitEvent("pre-row-reorder",{node:o.node(),index:o.index()}),r._mouseDown(t,e),!1):void 0)}),n.on("destroy.rowReorder",function(){v(n.table().container()).off(".rowReorder"),n.off(".rowReorder")})},_cachePositions:function(){var t=this.s.dt,r=v(t.table().node()).find("thead").outerHeight(),e=v.unique(t.rows({page:"current"}).nodes().toArray()),e=v.map(e,function(t,e){var o=v(t).position().top-r;return(o+o+v(t).outerHeight())/2});this.s.middles=e,this.s.bodyTop=v(t.table().body()).offset().top,this.s.windowHeight=v(d).height(),this.s.documentOuterHeight=v(b).outerHeight()},_clone:function(t){var e=this.s.dt,e=v(e.table().node().cloneNode(!1)).addClass("dt-rowReorder-float").append("<tbody/>").append(t.clone(!1)),o=t.outerWidth(),r=t.outerHeight(),n=v(v(this.s.dt.table().node()).parent()),s=n.width(),n=n.scrollLeft(),i=t.children().map(function(){return v(this).width()}),t=(e.width(o).height(r).find("tr").children().each(function(t){this.style.width=i[t]+"px"}),v("<div>").addClass("dt-rowReorder-float-parent").width(s).append(e).appendTo("body").scrollLeft(n));this.dom.clone=e,this.dom.cloneParent=t,this.s.domCloneOuterHeight=e.outerHeight()},_clonePosition:function(t){var e=this.s.start,o=this._eventToPage(t,"Y")-e.top,t=this._eventToPage(t,"X")-e.left,r=this.c.snapX,o=o+e.offsetTop,r=!0===r?e.offsetLeft:"number"==typeof r?e.offsetLeft+r:t+e.offsetLeft+this.dom.cloneParent.scrollLeft();o<0?o=0:o+this.s.domCloneOuterHeight>this.s.documentOuterHeight&&(o=this.s.documentOuterHeight-this.s.domCloneOuterHeight),this.dom.cloneParent.css({top:o,left:r})},_emitEvent:function(o,r){this.s.dt.iterator("table",function(t,e){v(t.nTable).triggerHandler(o+".dt",r)})},_eventToPage:function(t,e){return(-1!==t.type.indexOf("touch")?t.originalEvent.touches[0]:t)["page"+e]},_mouseDown:function(t,e){var o=this,r=this.s.dt,n=this.s.start,s=e.offset(),s=(n.top=this._eventToPage(t,"Y"),n.left=this._eventToPage(t,"X"),n.offsetTop=s.top,n.offsetLeft=s.left,n.nodes=v.unique(r.rows({page:"current"}).nodes().toArray()),this._cachePositions(),this._clone(e),this._clonePosition(t),(this.dom.target=e).addClass("dt-rowReorder-moving"),v(b).on("mouseup.rowReorder touchend.rowReorder",function(t){o._mouseUp(t)}).on("mousemove.rowReorder touchmove.rowReorder",function(t){o._mouseMove(t)}),v(d).width()===v(b).width()&&v(b.body).addClass("dt-rowReorder-noOverflow"),this.dom.dtScroll);this.s.scroll={windowHeight:v(d).height(),windowWidth:v(d).width(),dtTop:s.length?s.offset().top:null,dtLeft:s.length?s.offset().left:null,dtHeight:s.length?s.outerHeight():null,dtWidth:s.length?s.outerWidth():null}},_mouseMove:function(t){this._clonePosition(t);for(var e=this._eventToPage(t,"Y")-this.s.bodyTop,o=this.s.middles,r=null,n=this.s.dt,s=0,i=o.length;s<i;s++)if(e<o[s]){r=s;break}null===r&&(r=o.length),null!==this.s.lastInsert&&this.s.lastInsert===r||(n=v.unique(n.rows({page:"current"}).nodes().toArray()),r>this.s.lastInsert?this.dom.target.insertAfter(n[r-1]):this.dom.target.insertBefore(n[r]),this._cachePositions(),this.s.lastInsert=r),this._shiftScroll(t)},_mouseUp:function(t){for(var e,o,r,n=this,s=this.s.dt,i=this.c.dataSrc,d=(this.dom.clone.remove(),this.dom.cloneParent.remove(),this.dom.clone=null,this.dom.cloneParent=null,this.dom.target.removeClass("dt-rowReorder-moving"),v(b).off(".rowReorder"),v(b.body).removeClass("dt-rowReorder-noOverflow"),clearInterval(this.s.scrollInterval),this.s.scrollInterval=null,this.s.start.nodes),l=v.unique(s.rows({page:"current"}).nodes().toArray()),a={},c=[],h=[],u=this.s.getDataFn,f=this.s.setDataFn,w=0,p=d.length;w<p;w++)d[w]!==l[w]&&(e=s.row(l[w]).id(),o=s.row(l[w]).data(),r=s.row(d[w]).data(),e&&(a[e]=u(r)),c.push({node:l[w],oldData:u(o),newData:u(r),newPosition:w,oldPosition:v.inArray(l[w],d)}),h.push(l[w]));function m(){if(n.c.update){for(w=0,p=c.length;w<p;w++){var t=s.row(c[w].node).data();f(t,c[w].newData),s.columns().every(function(){this.dataSrc()===i&&s.cell(c[w].node,this.index()).invalidate("data")})}n._emitEvent("row-reordered",g),s.draw(!1)}}var g=[c,{dataSrc:i,nodes:h,values:a,triggerRow:s.row(this.dom.target),originalEvent:t}];this._emitEvent("row-reorder",g);this.c.editor?(this.c.enable=!1,this.c.editor.edit(h,!1,v.extend({submit:"changed"},this.c.formOptions)).multiSet(i,a).one("preSubmitCancelled.rowReorder",function(){n.c.enable=!0,n.c.editor.off(".rowReorder"),s.draw(!1)}).one("submitUnsuccessful.rowReorder",function(){s.draw(!1)}).one("submitSuccess.rowReorder",function(){m()}).one("submitComplete",function(){n.c.enable=!0,n.c.editor.off(".rowReorder")}).submit()):m()},_shiftScroll:function(t){var e,o,r=this,n=(this.s.dt,this.s.scroll),s=!1,i=t.pageY-b.body.scrollTop;i<v(d).scrollTop()+65?e=-5:i>n.windowHeight+v(d).scrollTop()-65&&(e=5),null!==n.dtTop&&t.pageY<n.dtTop+65?o=-5:null!==n.dtTop&&t.pageY>n.dtTop+n.dtHeight-65&&(o=5),e||o?(n.windowVert=e,n.dtVert=o,s=!0):this.s.scrollInterval&&(clearInterval(this.s.scrollInterval),this.s.scrollInterval=null),!this.s.scrollInterval&&s&&(this.s.scrollInterval=setInterval(function(){var t;n.windowVert&&(t=v(b).scrollTop(),v(b).scrollTop(t+n.windowVert),t!==v(b).scrollTop()&&(t=parseFloat(r.dom.cloneParent.css("top")),r.dom.cloneParent.css("top",t+n.windowVert))),n.dtVert&&(t=r.dom.dtScroll[0],n.dtVert&&(t.scrollTop+=n.dtVert))},20))}}),n.defaults={dataSrc:0,editor:null,enable:!0,formOptions:{},selector:"td:first-child",snapX:!1,update:!0,excludedChildren:"a"},v.fn.dataTable.Api);return e.register("rowReorder()",function(){return this}),e.register("rowReorder.enable()",function(e){return e===t&&(e=!0),this.iterator("table",function(t){t.rowreorder&&(t.rowreorder.c.enable=e)})}),e.register("rowReorder.disable()",function(){return this.iterator("table",function(t){t.rowreorder&&(t.rowreorder.c.enable=!1)})}),n.version="1.3.3",v.fn.dataTable.RowReorder=n,v.fn.DataTable.RowReorder=n,v(b).on("init.dt.dtr",function(t,e,o){var r;"dt"===t.namespace&&(t=e.oInit.rowReorder,r=s.defaults.rowReorder,(t||r)&&(r=v.extend({},t,r),!1!==t&&new n(e,r)))}),s}); | ||
!function(o){var r,n;"function"==typeof define&&define.amd?define(["jquery","datatables.net"],function(t){return o(t,window,document)}):"object"==typeof exports?(r=require("jquery"),n=function(t,e){e.fn.dataTable||require("datatables.net")(t,e)},"undefined"==typeof window?module.exports=function(t,e){return t=t||window,e=e||r(t),n(t,e),o(e,t,t.document)}:(n(window,r),module.exports=o(r,window,window.document))):o(jQuery,window,document)}(function(v,d,a,t){"use strict";function n(t,e){if(!s.versionCheck||!s.versionCheck("1.10.8"))throw"DataTables RowReorder requires DataTables 1.10.8 or newer";if(this.c=v.extend(!0,{},s.defaults.rowReorder,n.defaults,e),this.s={bodyTop:null,dt:new s.Api(t),getDataFn:s.ext.oApi._fnGetObjectDataFn(this.c.dataSrc),middles:null,scroll:{},scrollInterval:null,setDataFn:s.ext.oApi._fnSetObjectDataFn(this.c.dataSrc),start:{top:0,left:0,offsetTop:0,offsetLeft:0,nodes:[],rowIndex:0},windowHeight:0,documentOuterHeight:0,domCloneOuterHeight:0,dropAllowed:!0},this.dom={clone:null,cloneParent:null,dtScroll:v("div.dataTables_scrollBody",this.s.dt.table().container())},e=this.s.dt.settings()[0],t=e.rowreorder)return t;this.dom.dtScroll.length||(this.dom.dtScroll=v(this.s.dt.table().container(),"tbody")),(e.rowreorder=this)._constructor()}var s=v.fn.dataTable,e=(v.extend(n.prototype,{_constructor:function(){var r=this,n=this.s.dt,t=v(n.table().node());"static"===t.css("position")&&t.css("position","relative"),v(n.table().container()).on("mousedown.rowReorder touchstart.rowReorder",this.c.selector,function(t){var e,o;if(r.c.enable)return!!v(t.target).is(r.c.excludedChildren)||(e=v(this).closest("tr"),(o=n.row(e)).any()?(r._emitEvent("pre-row-reorder",{node:o.node(),index:o.index()}),r._mouseDown(t,e),!1):void 0)}),n.on("destroy.rowReorder",function(){v(n.table().container()).off(".rowReorder"),n.off(".rowReorder")}),this._keyup=this._keyup.bind(this)},_cachePositions:function(){var t=this.s.dt,r=v(t.table().node()).find("thead").outerHeight(),e=v.unique(t.rows({page:"current"}).nodes().toArray()),e=v.map(e,function(t,e){var o=v(t).position().top-r;return(o+o+v(t).outerHeight())/2});this.s.middles=e,this.s.bodyTop=v(t.table().body()).offset().top,this.s.windowHeight=v(d).height(),this.s.documentOuterHeight=v(a).outerHeight(),this.s.bodyArea=this._calcBodyArea()},_clone:function(t){var e=this.s.dt,e=v(e.table().node().cloneNode(!1)).addClass("dt-rowReorder-float").append("<tbody/>").append(t.clone(!1)),o=t.outerWidth(),r=t.outerHeight(),n=v(v(this.s.dt.table().node()).parent()),s=n.width(),n=n.scrollLeft(),i=t.children().map(function(){return v(this).width()}),t=(e.width(o).height(r).find("tr").children().each(function(t){this.style.width=i[t]+"px"}),v("<div>").addClass("dt-rowReorder-float-parent").width(s).append(e).appendTo("body").scrollLeft(n));this.dom.clone=e,this.dom.cloneParent=t,this.s.domCloneOuterHeight=e.outerHeight()},_clonePosition:function(t){var e=this.s.start,o=this._eventToPage(t,"Y")-e.top,t=this._eventToPage(t,"X")-e.left,r=this.c.snapX,o=o+e.offsetTop,r=!0===r?e.offsetLeft:"number"==typeof r?e.offsetLeft+r:t+e.offsetLeft+this.dom.cloneParent.scrollLeft();o<0?o=0:o+this.s.domCloneOuterHeight>this.s.documentOuterHeight&&(o=this.s.documentOuterHeight-this.s.domCloneOuterHeight),this.dom.cloneParent.css({top:o,left:r})},_emitEvent:function(o,r){this.s.dt.iterator("table",function(t,e){v(t.nTable).triggerHandler(o+".dt",r)})},_eventToPage:function(t,e){return(-1!==t.type.indexOf("touch")?t.originalEvent.touches[0]:t)["page"+e]},_mouseDown:function(t,e){var o=this,r=this.s.dt,n=this.s.start,s=this.c.cancelable,i=e.offset(),i=(n.top=this._eventToPage(t,"Y"),n.left=this._eventToPage(t,"X"),n.offsetTop=i.top,n.offsetLeft=i.left,n.nodes=v.unique(r.rows({page:"current"}).nodes().toArray()),this._cachePositions(),this._clone(e),this._clonePosition(t),this._eventToPage(t,"Y")-this.s.bodyTop),r=(n.rowIndex=this._calcRowIndexByPos(i),(this.dom.target=e).addClass("dt-rowReorder-moving"),v(a).on("mouseup.rowReorder touchend.rowReorder",function(t){o._mouseUp(t)}).on("mousemove.rowReorder touchmove.rowReorder",function(t){o._mouseMove(t)}),v(d).width()===v(a).width()&&v(a.body).addClass("dt-rowReorder-noOverflow"),this.dom.dtScroll);this.s.scroll={windowHeight:v(d).height(),windowWidth:v(d).width(),dtTop:r.length?r.offset().top:null,dtLeft:r.length?r.offset().left:null,dtHeight:r.length?r.outerHeight():null,dtWidth:r.length?r.outerWidth():null},s&&v(a).on("keyup",this._keyup)},_mouseMove:function(t){this._clonePosition(t);for(var e,o,r=this.s.start,n=this.c.cancelable,s=(n&&(e=this.s.bodyArea,o=this._calcCloneParentArea(),this.s.dropAllowed=this._rectanglesIntersect(e,o),this.s.dropAllowed?v(this.dom.cloneParent).removeClass("drop-not-allowed"):v(this.dom.cloneParent).addClass("drop-not-allowed")),this._eventToPage(t,"Y")-this.s.bodyTop),i=this.s.middles,d=null,a=0,l=i.length;a<l;a++)if(s<i[a]){d=a;break}null===d&&(d=i.length),n&&(this.s.dropAllowed||(d=r.rowIndex>this.s.lastInsert?r.rowIndex+1:r.rowIndex),this.dom.target.toggleClass("dt-rowReorder-moving",this.s.dropAllowed)),this._moveTargetIntoPosition(d),this._shiftScroll(t)},_mouseUp:function(t){var e=this,o=this.s.dt,r=this.c.dataSrc;if(this.s.dropAllowed){this._cleanupDragging();for(var n,s,i,d=this.s.start.nodes,a=v.unique(o.rows({page:"current"}).nodes().toArray()),l={},c=[],h=[],u=this.s.getDataFn,f=this.s.setDataFn,w=0,p=d.length;w<p;w++)d[w]!==a[w]&&(n=o.row(a[w]).id(),s=o.row(a[w]).data(),i=o.row(d[w]).data(),n&&(l[n]=u(i)),c.push({node:a[w],oldData:u(s),newData:u(i),newPosition:w,oldPosition:v.inArray(a[w],d)}),h.push(a[w]));var g=[c,{dataSrc:r,nodes:h,values:l,triggerRow:o.row(this.dom.target),originalEvent:t}],m=(this._emitEvent("row-reorder",g),function(){if(e.c.update){for(w=0,p=c.length;w<p;w++){var t=o.row(c[w].node).data();f(t,c[w].newData),o.columns().every(function(){this.dataSrc()===r&&o.cell(c[w].node,this.index()).invalidate("data")})}e._emitEvent("row-reordered",g),o.draw(!1)}});this.c.editor?(this.c.enable=!1,this.c.editor.edit(h,!1,v.extend({submit:"changed"},this.c.formOptions)).multiSet(r,l).one("preSubmitCancelled.rowReorder",function(){e.c.enable=!0,e.c.editor.off(".rowReorder"),o.draw(!1)}).one("submitUnsuccessful.rowReorder",function(){o.draw(!1)}).one("submitSuccess.rowReorder",function(){m()}).one("submitComplete",function(){e.c.enable=!0,e.c.editor.off(".rowReorder")}).submit()):m()}else e._cancel()},_moveTargetIntoPosition:function(t){var e,o,r=this.s.dt;null!==this.s.lastInsert&&this.s.lastInsert===t||(e=v.unique(r.rows({page:"current"}).nodes().toArray()),o="",o=t>this.s.lastInsert?(this.dom.target.insertAfter(e[t-1]),"after"):(this.dom.target.insertBefore(e[t]),"before"),this._cachePositions(),this.s.lastInsert=t,this._emitEvent("row-reorder-changed",{insertPlacement:o,insertPoint:t,row:r.row(this.dom.target)}))},_cleanupDragging:function(){var t=this.c.cancelable;this.dom.clone.remove(),this.dom.cloneParent.remove(),this.dom.clone=null,this.dom.cloneParent=null,this.dom.target.removeClass("dt-rowReorder-moving"),v(a).off(".rowReorder"),v(a.body).removeClass("dt-rowReorder-noOverflow"),clearInterval(this.s.scrollInterval),this.s.scrollInterval=null,t&&v(a).off("keyup",this._keyup)},_shiftScroll:function(t){var e,o,r=this,n=(this.s.dt,this.s.scroll),s=!1,i=t.pageY-a.body.scrollTop;i<v(d).scrollTop()+65?e=-5:i>n.windowHeight+v(d).scrollTop()-65&&(e=5),null!==n.dtTop&&t.pageY<n.dtTop+65?o=-5:null!==n.dtTop&&t.pageY>n.dtTop+n.dtHeight-65&&(o=5),e||o?(n.windowVert=e,n.dtVert=o,s=!0):this.s.scrollInterval&&(clearInterval(this.s.scrollInterval),this.s.scrollInterval=null),!this.s.scrollInterval&&s&&(this.s.scrollInterval=setInterval(function(){var t;n.windowVert&&(t=v(a).scrollTop(),v(a).scrollTop(t+n.windowVert),t!==v(a).scrollTop()&&(t=parseFloat(r.dom.cloneParent.css("top")),r.dom.cloneParent.css("top",t+n.windowVert))),n.dtVert&&(t=r.dom.dtScroll[0],n.dtVert&&(t.scrollTop+=n.dtVert))},20))},_calcBodyArea:function(t){var e=this.s.dt,o=v(e.table().body()).offset();return{left:o.left,top:o.top,right:o.left+v(e.table().body()).width(),bottom:o.top+v(e.table().body()).height()}},_calcCloneParentArea:function(t){this.s.dt;var e=v(this.dom.cloneParent).offset();return{left:e.left,top:e.top,right:e.left+v(this.dom.cloneParent).width(),bottom:e.top+v(this.dom.cloneParent).height()}},_rectanglesIntersect:function(t,e){return!(t.left>=e.right||e.left>=t.right||t.top>=e.bottom||e.top>=t.bottom)},_calcRowIndexByPos:function(r){var t=this.s.dt,e=v.unique(t.rows({page:"current"}).nodes().toArray()),n=-1,s=v(t.table().node()).find("thead").outerHeight();return v.each(e,function(t,e){var o=v(e).position().top-s,e=o+v(e).outerHeight();o<=r&&r<=e&&(n=t)}),n},_keyup:function(t){this.c.cancelable&&27===t.which&&(t.preventDefault(),this._cancel())},_cancel:function(){var t=this.s.start,t=t.rowIndex>this.s.lastInsert?t.rowIndex+1:t.rowIndex;this._moveTargetIntoPosition(t),this._cleanupDragging(),this._emitEvent("row-reorder-canceled",[this.s.start.rowIndex])}}),n.defaults={dataSrc:0,editor:null,enable:!0,formOptions:{},selector:"td:first-child",snapX:!1,update:!0,excludedChildren:"a",cancelable:!1},v.fn.dataTable.Api);return e.register("rowReorder()",function(){return this}),e.register("rowReorder.enable()",function(e){return e===t&&(e=!0),this.iterator("table",function(t){t.rowreorder&&(t.rowreorder.c.enable=e)})}),e.register("rowReorder.disable()",function(){return this.iterator("table",function(t){t.rowreorder&&(t.rowreorder.c.enable=!1)})}),n.version="1.4.0",v.fn.dataTable.RowReorder=n,v.fn.DataTable.RowReorder=n,v(a).on("init.dt.dtr",function(t,e,o){var r;"dt"===t.namespace&&(t=e.oInit.rowReorder,r=s.defaults.rowReorder,(t||r)&&(r=v.extend({},t,r),!1!==t&&new n(e,r)))}),s}); |
@@ -7,3 +7,3 @@ { | ||
"types": "./types/types.d.ts", | ||
"version": "1.3.3", | ||
"version": "1.4.0", | ||
"files": [ | ||
@@ -24,3 +24,3 @@ "js/**/*.js", | ||
"dependencies": { | ||
"datatables.net": ">=1.12.1", | ||
"datatables.net": ">=1.13.4", | ||
"jquery": ">=1.7" | ||
@@ -27,0 +27,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
78676
1811
Updateddatatables.net@>=1.13.4