UNPKG

datatables.net-plugins

Version:

Various small plug-ins for DataTables including feature, ordering, search and internationalisation plug-ins.

71 lines (62 loc) 1.81 kB
/*! © SpryMedia Ltd - datatables.net/license */ (function( factory ){ if ( typeof define === 'function' && define.amd ) { // AMD define( ['jquery', 'datatables.net'], function ( $ ) { return factory( $, window, document ); } ); } else if ( typeof exports === 'object' ) { // CommonJS var jq = require('jquery'); var cjsRequires = function (root, $) { if ( ! $.fn.dataTable ) { require('datatables.net')(root, $); } }; if (typeof window === 'undefined') { module.exports = function (root, $) { if ( ! root ) { // CommonJS environments without a window global must pass a // root. This will give an error otherwise root = window; } if ( ! $ ) { $ = jq( root ); } cjsRequires( root, $ ); return factory( $, root, root.document ); }; } else { cjsRequires( window, jq ); module.exports = factory( jq, window, window.document ); } } else { // Browser factory( jQuery, window, document ); } }(function( $, window, document, undefined ) { 'use strict'; var DataTable = $.fn.dataTable; /** * Detect file size type columns automatically. Commonly used for computer * file sizes, this can allow sorting to take the order of magnitude indicated * by the label (GB etc) into account. * * @name File size * @summary Detect abbreviated file size data (8MB, 4KB, 3B, etc) * @author Allan Jardine - datatables.net */ DataTable.ext.type.detect.unshift(function (data) { if (typeof data !== 'string') { return null; } var matches = data.match(/^(\d+(?:\.\d+)?)\s*([a-z]+)/i); var units = ['b', 'kb', 'mb', 'gb', 'tb', 'pb']; var is_file_size = matches && units.indexOf(matches[2].toLowerCase()) !== -1; return is_file_size ? 'file-size' : null; }); return DataTable; }));