1/** 2 * This plug-in for DataTables represents the ultimate option in extensibility 3 * for sorting date / time strings correctly. It uses 4 * [Moment.js](http://momentjs.com) to create automatic type detection and 5 * sorting plug-ins for DataTables based on a given format. This way, DataTables 6 * will automatically detect your temporal information and sort it correctly. 7 * 8 * For usage instructions, please see the DataTables blog 9 * post that [introduces it](//datatables.net/blog/2014-12-18). 10 * 11 * @name Ultimate Date / Time sorting 12 * @summary Sort date and time in any format using Moment.js 13 * @author [Allan Jardine](//datatables.net) 14 * @depends DataTables 1.10+, Moment.js 1.7+ 15 * @deprecated 16 * 17 * @example 18 * $.fn.dataTable.moment( 'HH:mm MMM D, YY' ); 19 * $.fn.dataTable.moment( 'dddd, MMMM Do, YYYY' ); 20 * 21 * $('#example').DataTable(); 22 */ 23 24(function (factory) { 25 if (typeof define === "function" && define.amd) { 26 define(["jquery", "moment", "datatables.net"], factory); 27 } else { 28 factory(jQuery, moment); 29 } 30}(function ($, moment) { 31 32function strip (d) { 33 if ( typeof d === 'string' ) { 34 // Strip HTML tags and newline characters if possible 35 d = d.replace(/(<.*?>)|(\r?\n|\r)/g, ''); 36 37 // Strip out surrounding white space 38 d = d.trim(); 39 } 40 41 return d; 42} 43 44$.fn.dataTable.moment = function ( format, locale, reverseEmpties ) { 45 var types = $.fn.dataTable.ext.type; 46 47 // Add type detection 48 types.detect.unshift( function ( d ) { 49 d = strip(d); 50 51 // Null and empty values are acceptable 52 if ( d === '' || d === null ) { 53 return 'moment-'+format; 54 } 55 56 return moment( d, format, locale, true ).isValid() ? 57 'moment-'+format : 58 null; 59 } ); 60 61 // Add sorting method - use an integer for the sorting 62 types.order[ 'moment-'+format+'-pre' ] = function ( d ) { 63 d = strip(d); 64 65 return !moment(d, format, locale, true).isValid() ? 66 (reverseEmpties ? -Infinity : Infinity) : 67 parseInt( moment( d, format, locale, true ).format( 'x' ), 10 ); 68 }; 69}; 70 71}));
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.