app/assets/javascripts/datatables/extensions/ColReorder/dataTables.colReorder.js in jquery-datatables-1.10.13 vs app/assets/javascripts/datatables/extensions/ColReorder/dataTables.colReorder.js in jquery-datatables-1.10.15
- old
+ new
@@ -1,13 +1,13 @@
-/*! ColReorder 1.3.2
+/*! ColReorder 1.3.3
* ©2010-2015 SpryMedia Ltd - datatables.net/license
*/
/**
* @summary ColReorder
* @description Provide the ability to reorder columns in a DataTable
- * @version 1.3.2
+ * @version 1.3.3
* @file dataTables.colReorder.js
* @author SpryMedia Ltd (www.sprymedia.co.uk)
* @contact www.sprymedia.co.uk/contact
* @copyright Copyright 2010-2014 SpryMedia Ltd.
*
@@ -885,14 +885,18 @@
* @private
*/
"_fnMouseListener": function ( i, nTh )
{
var that = this;
- $(nTh).on( 'mousedown.ColReorder', function (e) {
- e.preventDefault();
- that._fnMouseDown.call( that, e, nTh );
- } );
+ $(nTh)
+ .on( 'mousedown.ColReorder', function (e) {
+ e.preventDefault();
+ that._fnMouseDown.call( that, e, nTh );
+ } )
+ .on( 'touchstart.ColReorder', function (e) {
+ that._fnMouseDown.call( that, e, nTh );
+ } );
},
/**
* Mouse down on a TH element in the table header
@@ -913,26 +917,26 @@
if ( idx === undefined ) {
return;
}
- this.s.mouse.startX = e.pageX;
- this.s.mouse.startY = e.pageY;
- this.s.mouse.offsetX = e.pageX - offset.left;
- this.s.mouse.offsetY = e.pageY - offset.top;
+ this.s.mouse.startX = this._fnCursorPosition( e, 'pageX' );
+ this.s.mouse.startY = this._fnCursorPosition( e, 'pageY' );
+ this.s.mouse.offsetX = this._fnCursorPosition( e, 'pageX' ) - offset.left;
+ this.s.mouse.offsetY = this._fnCursorPosition( e, 'pageY' ) - offset.top;
this.s.mouse.target = this.s.dt.aoColumns[ idx ].nTh;//target[0];
this.s.mouse.targetIndex = idx;
this.s.mouse.fromIndex = idx;
this._fnRegions();
/* Add event handlers to the document */
$(document)
- .on( 'mousemove.ColReorder', function (e) {
+ .on( 'mousemove.ColReorder touchmove.ColReorder', function (e) {
that._fnMouseMove.call( that, e );
} )
- .on( 'mouseup.ColReorder', function (e) {
+ .on( 'mouseup.ColReorder touchend.ColReorder', function (e) {
that._fnMouseUp.call( that, e );
} );
},
@@ -952,31 +956,31 @@
/* Only create the drag element if the mouse has moved a specific distance from the start
* point - this allows the user to make small mouse movements when sorting and not have a
* possibly confusing drag element showing up
*/
if ( Math.pow(
- Math.pow(e.pageX - this.s.mouse.startX, 2) +
- Math.pow(e.pageY - this.s.mouse.startY, 2), 0.5 ) < 5 )
+ Math.pow(this._fnCursorPosition( e, 'pageX') - this.s.mouse.startX, 2) +
+ Math.pow(this._fnCursorPosition( e, 'pageY') - this.s.mouse.startY, 2), 0.5 ) < 5 )
{
return;
}
this._fnCreateDragNode();
}
/* Position the element - we respect where in the element the click occured */
this.dom.drag.css( {
- left: e.pageX - this.s.mouse.offsetX,
- top: e.pageY - this.s.mouse.offsetY
+ left: this._fnCursorPosition( e, 'pageX' ) - this.s.mouse.offsetX,
+ top: this._fnCursorPosition( e, 'pageY' ) - this.s.mouse.offsetY
} );
/* Based on the current mouse position, calculate where the insert should go */
var bSet = false;
var lastToIndex = this.s.mouse.toIndex;
for ( var i=1, iLen=this.s.aoTargets.length ; i<iLen ; i++ )
{
- if ( e.pageX < this.s.aoTargets[i-1].x + ((this.s.aoTargets[i].x-this.s.aoTargets[i-1].x)/2) )
+ if ( this._fnCursorPosition(e, 'pageX') < this.s.aoTargets[i-1].x + ((this.s.aoTargets[i].x-this.s.aoTargets[i-1].x)/2) )
{
this.dom.pointer.css( 'left', this.s.aoTargets[i-1].x );
this.s.mouse.toIndex = this.s.aoTargets[i-1].to;
bSet = true;
break;
@@ -1009,11 +1013,11 @@
*/
"_fnMouseUp": function ( e )
{
var that = this;
- $(document).off( 'mousemove.ColReorder mouseup.ColReorder' );
+ $(document).off( '.ColReorder' );
if ( this.dom.drag !== null )
{
/* Remove the guide elements */
this.dom.drag.remove();
@@ -1161,10 +1165,24 @@
"_fnSetColumnIndexes": function ()
{
$.each( this.s.dt.aoColumns, function (i, column) {
$(column.nTh).attr('data-column-index', i);
} );
+ },
+
+
+ /**
+ * Get cursor position regardless of mouse or touch input
+ * @param {Event} e jQuery Event
+ * @param {string} prop Property to get
+ * @return {number} Value
+ */
+ _fnCursorPosition: function ( e, prop ) {
+ if ( e.type.indexOf('touch') !== -1 ) {
+ return e.originalEvent.touches[0][ prop ];
+ }
+ return e[ prop ];
}
} );
@@ -1240,10 +1258,10 @@
* ColReorder version
* @constant version
* @type String
* @default As code
*/
-ColReorder.version = "1.3.2";
+ColReorder.version = "1.3.3";
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* DataTables interfaces