git version 1.9.1 & version 2.1.2 I had some changes in a tracked file that I wanted to discard. Instead of using checkout, I instead used `git reset --hard HEAD` to reset. Git returned the message `HEAD is now at <sha> <commit-message>` I then went `git status` and it showed me that I still have changes to commit I expected there to be no changes in my working directory as a result of doing a `git reset --hard` I did a little more fiddling around and still yielded the same results. - `$ touch file.md` - `$ git add file.md` - `$ git commit -m 'empty file'` - `$ echo 'text' > file.md` At this point git reported that I had uncommited changes for both file.md and the troublesome file in question (jquery.datatables.js) `$ git reset --hard HEAD` Git now no longer reports and untracked changes for file.md but still for jquery.datatables.js `$ git reset --hard HEAD~1` Git still reports untracked changes for jquery.datatables.js I have included a copy of the diff of the jquery.datatables.js
diff --git a/vendor/assets/javascripts/jquery.datatables.js b/vendor/assets/javascripts/jquery.datatables.js index b9044f1..4aab04b 100644 --- a/vendor/assets/javascripts/jquery.datatables.js +++ b/vendor/assets/javascripts/jquery.datatables.js @@ -1,11 +1,11 @@ -/*! DataTables 1.10.1 - * ©2008-2014 SpryMedia Ltd - datatables.net/license +/*! DataTables 1.10.3 + * ©2008-2014 SpryMedia Ltd - datatables.net/license */ /** * @summary DataTables * @description Paginate, search and order HTML tables - * @version 1.10.1 + * @version 1.10.3 * @file jquery.dataTables.js * @author SpryMedia Ltd (www.sprymedia.co.uk) * @contact www.sprymedia.co.uk/contact @@ -113,7 +113,7 @@ // U+2009 is thin space and U+202F is narrow no-break space, both used in many // standards as thousands separators - var _re_formatted_numeric = /[',$£€¥%\u2009\u202F]/g; + var _re_formatted_numeric = /[',$£€¥%\u2009\u202F]/g; var _empty = function ( d ) { @@ -133,7 +133,7 @@ if ( ! _re_dic[ decimalPoint ] ) { _re_dic[ decimalPoint ] = new RegExp( _fnEscapeRegex( decimalPoint ), 'g' ); } - return typeof num === 'string' ? + return typeof num === 'string' && decimalPoint !== '.' ? num.replace( /\./g, '' ).replace( _re_dic[ decimalPoint ], '.' ) : num; }; @@ -310,7 +310,6 @@ newKey = key.replace( match[0], match[2].toLowerCase() ); map[ newKey ] = key; - //console.log( key, match ); if ( match[1] === 'o' ) { _fnHungarianMap( o[key] ); @@ -673,6 +672,12 @@ return _fnSetObjectDataFn( mDataSrc )( rowData, val, meta ); }; + // Indicate if DataTables should read DOM data as an object or array + // Used in _fnGetRowElements + if ( typeof mDataSrc !== 'number' ) { + oSettings._rowReadObject = true; + } + /* Feature sorting overrides column specific when off */ if ( !oSettings.oFeatures.bSort ) { @@ -1498,19 +1503,22 @@ function _fnGetRowElements( settings, row ) { var - d = [], tds = [], td = row.firstChild, name, col, o, i=0, contents, - columns = settings.aoColumns; + columns = settings.aoColumns, + objectRead = settings._rowReadObject; - var attr = function ( str, data, td ) { + var d = objectRead ? {} : []; + + var attr = function ( str, td ) { if ( typeof str === 'string' ) { var idx = str.indexOf('@'); if ( idx !== -1 ) { - var src = str.substring( idx+1 ); - o[ '@'+src ] = td.getAttribute( src ); + var attr = str.substring( idx+1 ); + var setter = _fnSetObjectDataFn( str ); + setter( d, td.getAttribute( attr ) ); } } }; @@ -1520,18 +1528,26 @@ contents = $.trim(cell.innerHTML); if ( col && col._bAttrSrc ) { - o = { - display: contents - }; + var setter = _fnSetObjectDataFn( col.mData._ ); + setter( d, contents ); - attr( col.mData.sort, o, cell ); - attr( col.mData.type, o, cell ); - attr( col.mData.filter, o, cell ); - - d.push( o ); + attr( col.mData.sort, cell ); + attr( col.mData.type, cell ); + attr( col.mData.filter, cell ); } else { - d.push( contents ); + // Depending on the `data` option for the columns the data can be + // read to either an object or an array. + if ( objectRead ) { + if ( ! col._setter ) { + // Cache the setter function + col._setter = _fnSetObjectDataFn( col.mData ); + } + col._setter( d, contents ); + } + else { + d.push( contents ); + } } i++; @@ -1950,7 +1966,9 @@ } } - /* Row callback functions - might want to manipulate the row */ + // Row callback functions - might want to manipulate the row + // iRowCount and j are not currently documented. Are they at all + // useful? _fnCallbackFire( oSettings, 'aoRowCallback', null, [nRow, aoData._aData, iRowCount, j] ); @@ -2695,13 +2713,20 @@ _fnDraw( settings ); } }; + + var searchDelay = settings.searchDelay !== null ? + settings.searchDelay : + _fnDataSource( settings ) === 'ssp' ? + 400 : + 0; + var jqFilter = $('input', filter) .val( previousSearch.sSearch ) .attr( 'placeholder', language.sSearchPlaceholder ) .bind( 'keyup.DT search.DT input.DT paste.DT cut.DT', - _fnDataSource( settings ) === 'ssp' ? - _fnThrottle( searchFn, 400 ): + searchDelay ? + _fnThrottle( searchFn, searchDelay ) : searchFn ) .bind( 'keypress.DT', function(e) { @@ -2924,9 +2949,12 @@ * ^(?=.*?\bone\b)(?=.*?\btwo three\b)(?=.*?\bfour\b).*$ */ var a = $.map( search.match( /"[^"]+"|[^ ]+/g ) || '', function ( word ) { - return word.charAt(0) === '"' ? - word.match( /^"(.*)"$/ )[1] : - word; + if ( word.charAt(0) === '"' ) { + var m = word.match( /^"(.*)"$/ ); + word = m ? m[1] : word; + } + + return word.replace('"', ''); } ); search = '^(?=.*?'+a.join( ')(?=.*?' )+').*$'; @@ -2973,34 +3001,40 @@ if ( column.bSearchable ) { cellData = _fnGetCellData( settings, i, j, 'filter' ); - cellData = fomatters[ column.sType ] ? - fomatters[ column.sType ]( cellData ) : - cellData !== null ? - cellData : - ''; + if ( fomatters[ column.sType ] ) { + cellData = fomatters[ column.sType ]( cellData ); + } + + // Search in DataTables 1.10 is string based. In 1.11 this + // should be altered to also allow strict type checking. + if ( cellData === null ) { + cellData = ''; + } + + if ( typeof cellData !== 'string' && cellData.toString ) { + cellData = cellData.toString(); + } } else { cellData = ''; } - if ( cellData ) { - // If it looks like there is an HTML entity in the string, - // attempt to decode it so sorting works as expected. Note that - // we could use a single line of jQuery to do this, but the DOM - // method used here is much faster http://jsperf.com/html-decode - if ( cellData.indexOf && cellData.indexOf('&') !== -1 ) { - __filter_div.innerHTML = cellData; - cellData = __filter_div_textContent ? - __filter_div.textContent : - __filter_div.innerText; - } - - if ( cellData.replace ) { - cellData = cellData.replace(/[\r\n]/g, ''); - } + // If it looks like there is an HTML entity in the string, + // attempt to decode it so sorting works as expected. Note that + // we could use a single line of jQuery to do this, but the DOM + // method used here is much faster http://jsperf.com/html-decode + if ( cellData.indexOf && cellData.indexOf('&') !== -1 ) { + __filter_div.innerHTML = cellData; + cellData = __filter_div_textContent ? + __filter_div.textContent : + __filter_div.innerText; + } - filterData.push( cellData ); + if ( cellData.replace ) { + cellData = cellData.replace(/[\r\n]/g, ''); } + + filterData.push( cellData ); } row._aFilterData = filterData; @@ -4162,7 +4196,7 @@ */ function _fnThrottle( fn, freq ) { var - frequency = freq || 200, + frequency = freq !== undefined ? freq : 200, last, timer; @@ -4403,11 +4437,15 @@ iCol = aDataSort[k]; sType = aoColumns[ iCol ].sType || 'string'; + if ( nestedSort[i]._idx === undefined ) { + nestedSort[i]._idx = $.inArray( nestedSort[i][1], aoColumns[iCol].asSorting ); + } + aSort.push( { src: srcCol, col: iCol, dir: nestedSort[i][1], - index: nestedSort[i][2], + index: nestedSort[i]._idx, type: sType, formatter: DataTable.ext.type.order[ sType+"-pre" ] } ); @@ -4610,13 +4648,17 @@ var sorting = settings.aaSorting; var asSorting = col.asSorting; var nextSortIdx; - var next = function ( a ) { + var next = function ( a, overflow ) { var idx = a._idx; if ( idx === undefined ) { idx = $.inArray( a[1], asSorting ); } - return idx+1 >= asSorting.length ? 0 : idx+1; + return idx+1 < asSorting.length ? + idx+1 : + overflow ? + null : + 0; }; // Convert to 2D array if needed @@ -4631,10 +4673,15 @@ if ( sortIdx !== -1 ) { // Yes, modify the sort - nextSortIdx = next( sorting[sortIdx] ); + nextSortIdx = next( sorting[sortIdx], true ); - sorting[sortIdx][1] = asSorting[ nextSortIdx ]; - sorting[sortIdx]._idx = nextSortIdx; + if ( nextSortIdx === null ) { + sorting.splice( sortIdx, 1 ); + } + else { + sorting[sortIdx][1] = asSorting[ nextSortIdx ]; + sorting[sortIdx]._idx = nextSortIdx; + } } else { // No sort on this column yet @@ -5113,7 +5160,7 @@ len = settings._iDisplayLength; /* If we have space to show extra rows (backing up from the end point - then do so */ - if ( end === settings.fnRecordsDisplay() ) + if (start >= end) { start = end - len; } @@ -6089,6 +6136,7 @@ "fnStateLoadCallback", "fnStateSaveCallback", "renderer", + "searchDelay", [ "iCookieDuration", "iStateDuration" ], // backwards compat [ "oSearch", "oPreviousSearch" ], [ "aoSearchCols", "aoPreSearchCols" ], @@ -6719,8 +6767,10 @@ } for ( i=0, ien=context.length ; i<ien ; i++ ) { + var apiInst = new _Api( context[i] ); + if ( type === 'table' ) { - ret = fn( context[i], i ); + ret = fn.call( apiInst, context[i], i ); if ( ret !== undefined ) { a.push( ret ); @@ -6728,7 +6778,7 @@ } else if ( type === 'columns' || type === 'rows' ) { // this has same length as context - one entry for each table - ret = fn( context[i], this[i], i ); + ret = fn.call( apiInst, context[i], this[i], i ); if ( ret !== undefined ) { a.push( ret ); @@ -6747,10 +6797,10 @@ item = items[j]; if ( type === 'cell' ) { - ret = fn( context[i], item.row, item.column, i, j ); + ret = fn.call( apiInst, context[i], item.row, item.column, i, j ); } else { - ret = fn( context[i], item, i, j, rows ); + ret = fn.call( apiInst, context[i], item, i, j, rows ); } if ( ret !== undefined ) { @@ -7387,11 +7437,12 @@ { var out = [], res, - a, i, ien, j, jen; + a, i, ien, j, jen, + selectorType = typeof selector; // Can't just check for isArray here, as an API or jQuery instance might be // given with their array like look - if ( ! selector || typeof selector === 'string' || selector.length === undefined ) { + if ( ! selector || selectorType === 'string' || selectorType === 'function' || selector.length === undefined ) { selector = [ selector ]; } @@ -7529,6 +7580,7 @@ { return _selector_run( selector, function ( sel ) { var selInt = _intVal( sel ); + var i, ien; // Short cut - selector is a number and no options provided (default is // all records, so no need to check if the index is in there, since it @@ -7548,14 +7600,19 @@ return rows; } - // Get nodes in the order from the `rows` array (can't use `pluck`) @todo - use pluck_order - var nodes = []; - for ( var i=0, ien=rows.length ; i<ien ; i++ ) { - nodes.push( settings.aoData[ rows[i] ].nTr ); + // Get nodes in the order from the `rows` array + var nodes = _pluck_order( settings.aoData, rows, 'nTr' ); + + // Selector - function + if ( typeof sel === 'function' ) { + return $.map( rows, function (idx) { + var row = settings.aoData[ idx ]; + return sel( idx, row._aData, row.nTr ) ? idx : null; + } ); } + // Selector - node if ( sel.nodeName ) { - // Selector - node if ( $.inArray( sel, nodes ) !== -1 ) { return [ sel._DT_RowIndex ];// sel is a TR node that is in the table // and DataTables adds a prop for fast lookup @@ -7794,12 +7851,12 @@ }; - var __details_remove = function ( api ) + var __details_remove = function ( api, idx ) { var ctx = api.context; - if ( ctx.length && api.length ) { - var row = ctx[0].aoData[ api[0] ]; + if ( ctx.length ) { + var row = ctx[0].aoData[ idx !== undefined ? idx : api[0] ]; if ( row._details ) { row._details.remove(); @@ -7888,7 +7945,7 @@ for ( var i=0, ien=data.length ; i<ien ; i++ ) { if ( data[i]._details ) { - __details_remove( data[i] ); + __details_remove( api, i ); } } } ); @@ -7983,7 +8040,19 @@ // can be an array of these items, comma separated list, or an array of comma // separated lists - var __re_column_selector = /^(.*):(name|visIdx|visible)$/; + var __re_column_selector = /^(.+):(name|visIdx|visible)$/; + + + // r1 and r2 are redundant - but it means that the parameters match for the + // iterator callback in columns().data() + var __columnData = function ( settings, column, r1, r2, rows ) { + var a = []; + for ( var row=0, ien=rows.length ; row<ien ; row++ ) { + a.push( _fnGetCellData( settings, rows[row], column ) ); + } + return a; + }; + var __column_selector = function ( settings, selector, opts ) { @@ -7995,63 +8064,74 @@ return _selector_run( selector, function ( s ) { var selInt = _intVal( s ); + // Selector - all if ( s === '' ) { - // All columns return _range( columns.length ); } - else if ( selInt !== null ) { - // Integer selector + + // Selector - index + if ( selInt !== null ) { return [ selInt >= 0 ? selInt : // Count from left columns.length + selInt // Count from right (+ because its a negative value) ]; } - else { - var match = typeof s === 'string' ? - s.match( __re_column_selector ) : - ''; - - if ( match ) { - switch( match[2] ) { - case 'visIdx': - case 'visible': - var idx = parseInt( match[1], 10 ); - // Visible index given, convert to column index - if ( idx < 0 ) { - // Counting from the right - var visColumns = $.map( columns, function (col,i) { - return col.bVisible ? i : null; - } ); - return [ visColumns[ visColumns.length + idx ] ]; - } - // Counting from the left - return [ _fnVisibleToColumnIndex( settings, idx ) ]; + + // Selector = function + if ( typeof s === 'function' ) { + var rows = _selector_row_indexes( settings, opts ); + + return $.map( columns, function (col, idx) { + return s( + idx, + __columnData( settings, idx, 0, 0, rows ), + nodes[ idx ] + ) ? idx : null; + } ); + } - case 'name': - // match by name. `names` is column index complete and in order - return $.map( names, function (name, i) { - return name === match[1] ? i : null; + // jQuery or string selector + var match = typeof s === 'string' ? + s.match( __re_column_selector ) : + ''; + + if ( match ) { + switch( match[2] ) { + case 'visIdx': + case 'visible': + var idx = parseInt( match[1], 10 ); + // Visible index given, convert to column index + if ( idx < 0 ) { + // Counting from the right + var visColumns = $.map( columns, function (col,i) { + return col.bVisible ? i : null; } ); - } - } - else { - // jQuery selector on the TH elements for the columns - return $( nodes ) - .filter( s ) - .map( function () { - return $.inArray( this, nodes ); // `nodes` is column index complete and in order - } ) - .toArray(); + return [ visColumns[ visColumns.length + idx ] ]; + } + // Counting from the left + return [ _fnVisibleToColumnIndex( settings, idx ) ]; + + case 'name': + // match by name. `names` is column index complete and in order + return $.map( names, function (name, i) { + return name === match[1] ? i : null; + } ); } } + else { + // jQuery selector on the TH elements for the columns + return $( nodes ) + .filter( s ) + .map( function () { + return $.inArray( this, nodes ); // `nodes` is column index complete and in order + } ) + .toArray(); + } } ); }; - - - - var __setColumnVis = function ( settings, column, vis ) { + var __setColumnVis = function ( settings, column, vis, recalc ) { var cols = settings.aoColumns, col = cols[ column ], @@ -8094,12 +8174,14 @@ _fnDrawHead( settings, settings.aoHeader ); _fnDrawHead( settings, settings.aoFooter ); - // Automatically adjust column sizing - _fnAdjustColumnSizing( settings ); + if ( recalc === undefined || recalc ) { + // Automatically adjust column sizing + _fnAdjustColumnSizing( settings ); - // Realign columns for scrolling - if ( settings.oScroll.sX || settings.oScroll.sY ) { - _fnScrollDraw( settings ); + // Realign columns for scrolling + if ( settings.oScroll.sX || settings.oScroll.sY ) { + _fnScrollDraw( settings ); + } } _fnCallbackFire( settings, null, 'column-visibility', [settings, column, vis] ); @@ -8159,12 +8241,13 @@ * */ _api_registerPlural( 'columns().data()', 'column().data()', function () { - return this.iterator( 'column-rows', function ( settings, column, i, j, rows ) { - var a = []; - for ( var row=0, ien=rows.length ; row<ien ; row++ ) { - a.push( _fnGetCellData( settings, rows[row], column, '' ) ); - } - return a; + return this.iterator( 'column-rows', __columnData ); + } ); + + + _api_registerPlural( 'columns().dataSrc()', 'column().dataSrc()', function () { + return this.iterator( 'column', function ( settings, column ) { + return settings.aoColumns[column].mData; } ); } ); @@ -8186,11 +8269,11 @@ - _api_registerPlural( 'columns().visible()', 'column().visible()', function ( vis ) { + _api_registerPlural( 'columns().visible()', 'column().visible()', function ( vis, calc ) { return this.iterator( 'column', function ( settings, column ) { return vis === undefined ? settings.aoColumns[ column ].bVisible : - __setColumnVis( settings, column, vis ); + __setColumnVis( settings, column, vis, calc ); } ); } ); @@ -8255,31 +8338,48 @@ var allCells = $( [].concat.apply([], cells) ); var row; var columns = settings.aoColumns.length; - var a, i, ien, j; + var a, i, ien, j, o, host; return _selector_run( selector, function ( s ) { - if ( s === null || s === undefined ) { - // All cells + var fnSelector = typeof s === 'function'; + + if ( s === null || s === undefined || fnSelector ) { + // All cells and function selectors a = []; for ( i=0, ien=rows.length ; i<ien ; i++ ) { row = rows[i]; for ( j=0 ; j<columns ; j++ ) { - a.push( { + o = { row: row, column: j - } ); + }; + + if ( fnSelector ) { + // Selector - function + host = settings.aoData[ row ]; + + if ( s( o, _fnGetCellData(settings, row, j), host.anCells[j] ) ) { + a.push( o ); + } + } + else { + // Selector - all + a.push( o ); + } } } return a; } - else if ( $.isPlainObject( s ) ) { + + // Selector - index + if ( $.isPlainObject( s ) ) { return [s]; } - // jQuery filtered cells + // Selector - jQuery filtered cells return allCells .filter( s ) .map( function (i, el) { @@ -8375,6 +8475,13 @@ } ); + _api_registerPlural( 'cells().render()', 'cell().render()', function ( type ) { + return this.iterator( 'cell', function ( settings, row, column ) { + return _fnGetCellData( settings, row, column, type ); + } ); + } ); + + _api_registerPlural( 'cells().indexes()', 'cell().index()', function () { return this.iterator( 'cell', function ( settings, row, column ) { return { @@ -8547,33 +8654,34 @@ } ); - _api_register( [ + _api_registerPlural( 'columns().search()', - 'column().search()' - ], function ( input, regex, smart, caseInsen ) { - return this.iterator( 'column', function ( settings, column ) { - var preSearch = settings.aoPreSearchCols; + 'column().search()', + function ( input, regex, smart, caseInsen ) { + return this.iterator( 'column', function ( settings, column ) { + var preSearch = settings.aoPreSearchCols; + + if ( input === undefined ) { + // get + return preSearch[ column ].sSearch; + } - if ( input === undefined ) { - // get - return preSearch[ column ].sSearch; - } + // set + if ( ! settings.oFeatures.bFilter ) { + return; + } - // set - if ( ! settings.oFeatures.bFilter ) { - return; - } + $.extend( preSearch[ column ], { + "sSearch": input+"", + "bRegex": regex === null ? false : regex, + "bSmart": smart === null ? true : smart, + "bCaseInsensitive": caseInsen === null ? true : caseInsen + } ); - $.extend( preSearch[ column ], { - "sSearch": input+"", - "bRegex": regex === null ? false : regex, - "bSmart": smart === null ? true : smart, - "bCaseInsensitive": caseInsen === null ? true : caseInsen + _fnFilterComplete( settings, settings.oPreviousSearch, 1 ); } ); - - _fnFilterComplete( settings, settings.oPreviousSearch, 1 ); - } ); - } ); + } + ); /* * State API methods @@ -8704,6 +8812,29 @@ /** + * DataTables utility methods + * + * This namespace provides helper methods that DataTables uses internally to + * create a DataTable, but which are not exclusively used only for DataTables. + * These methods can be used by extension authors to save the duplication of + * code. + * + * @namespace + */ + DataTable.util = { + /** + * Throttle the calls to a function. Arguments and context are maintained + * for the throttled function. + * + * @param {function} fn Function to be called + * @param {integer} freq Call frequency in mS + * @return {function} Wrapped function + */ + throttle: _fnThrottle + }; + + + /** * Convert from camel case parameters to Hungarian notation. This is made public * for the extensions to provide the same ability as DataTables core to accept * either the 1.9 style Hungarian notation, or the 1.10+ style camelCase @@ -8882,7 +9013,7 @@ * @type string * @default Version number */ - DataTable.version = "1.10.1"; + DataTable.version = "1.10.3"; /** * Private data store, containing all of the settings objects that are @@ -11323,6 +11454,26 @@ /** + * Search delay option. This will throttle full table searches that use the + * DataTables provided search input element (it does not effect calls to + * `dt-api search()`, providing a delay before the search is made. + * @type integer + * @default 0 + * + * @dtopt Options + * @name DataTable.defaults.searchDelay + * + * @example + * $(document).ready( function() { + * $('#example').dataTable( { + * "searchDelay": 200 + * } ); + * } ) + */ + "searchDelay": null, + + + /** * DataTables features four different built-in options for the buttons to * display for pagination control: * @@ -12839,6 +12990,13 @@ "sDom": null, /** + * Search delay (in mS) + * @type integer + * @default null + */ + "searchDelay": null, + + /** * Which type of pagination should be used. * Note that this parameter will be set by the initialisation routine. To * set a default use {@link DataTable.defaults}. @@ -13987,7 +14145,7 @@ var __numericReplace = function ( d, decimalPlace, re1, re2 ) { - if ( !d || d === '-' ) { + if ( d !== 0 && (!d || d === '-') ) { return -Infinity; } @@ -14107,7 +14265,7 @@ // V8 will remove any unknown characters at the start and end of the // expression, leading to false matches such as `$245.12` or `10%` being // a valid date. See forum thread 18941 for detail. - if ( d && ( ! _re_date_start.test(d) || ! _re_date_end.test(d) ) ) { + if ( d && !(d instanceof Date) && ( ! _re_date_start.test(d) || ! _re_date_end.test(d) ) ) { return null; } var parsed = Date.parse(d); @@ -14201,8 +14359,6 @@ }, jqueryui: function ( settings, cell, column, classes ) { - var colIdx = column.idx; - $('<div/>') .addClass( classes.sSortJUIWrapper ) .append( cell.contents() ) @@ -14217,6 +14373,8 @@ return; } + var colIdx = column.idx; + cell .removeClass( classes.sSortAsc +" "+classes.sSortDesc ) .addClass( columns[ colIdx ] == 'asc' ? @@ -14610,3 +14768,4 @@ })); }(window, document)); +