(function(factory){
if(typeof define==='function'&&define.amd){
define(['jquery', 'datatables.net'], function($){
return factory($, window, document);
});
}
else if(typeof exports==='object'){
module.exports=function (root, $){
if(! root){
root=window;
}
if(! $||! $.fn.dataTable){
$=require('datatables.net')(root, $).$;
}
return factory($, root, root.document);
};}else{
factory(jQuery, window, document);
}}(function($, window, document, undefined){
'use strict';
var _unique=0;
var _setup=function(values){
if(! $.isArray(values) ){
values=[ values ];
}
var o={
name: 'absoluteOrder'+(_unique++),
alwaysTop: {},
alwaysBottom: {}};
for(var i=0, ien=values.length ; i<ien ; i++){
var conf=values[i];
if(typeof conf==='string'){
o.alwaysTop[ conf ]=true;
}
else if(conf.position===undefined||conf.position==='top'){
o.alwaysTop[ conf.value ]=true;
}else{
o.alwaysBottom[ conf.value ]=true;
}}
o.asc=function(a, b, isNumber){
if(o.alwaysTop[ a ]&&o.alwaysTop[ b ]){
return 0;
}
else if(o.alwaysBottom[ a ]&&o.alwaysBottom[ b ]){
return 0;
}
else if(o.alwaysTop[ a ]||o.alwaysBottom[ b ]){
return -1;
}
else if(o.alwaysBottom[ a ]||o.alwaysTop[ b ]){
return 1;
}
if(isNumber){
if(typeof a==='string'){
a=a.replace(/[^\d\-\.]/g, '') * 1;
}
if(typeof b==='string'){
b=b.replace(/[^\d\-\.]/g, '') * 1;
}}
return ((a < b) ? -1:((a > b) ? 1:0));
};
o.desc=function(a, b, isNumber){
if(o.alwaysTop[ a ]&&o.alwaysTop[ b ]){
return 0;
}
else if(o.alwaysBottom[ a ]&&o.alwaysBottom[ b ]){
return 0;
}
else if(o.alwaysTop[ a ]||o.alwaysBottom[ b ]){
return -1;
}
else if(o.alwaysBottom[ a ]||o.alwaysTop[ b ]){
return 1;
}
if(isNumber){
if(typeof a==='string'){
a=a.replace(/[^\d\-\.]/g, '') * 1;
}
if(typeof b==='string'){
b=b.replace(/[^\d\-\.]/g, '') * 1;
}}
return ((a < b) ? 1:((a > b) ? -1:0));
};
return o;
};
$.fn.dataTable.absoluteOrder=function(values){
var conf=_setup(values);
$.fn.dataTable.ext.type.order[ conf.name+'-asc' ]=conf.asc;
$.fn.dataTable.ext.type.order[ conf.name+'-desc' ]=conf.desc;
return conf.name;
};
$.fn.dataTable.absoluteOrderNumber=function(values){
var conf=_setup(values);
$.fn.dataTable.ext.type.order[ conf.name+'-asc' ]=function(a, b){
return conf.asc(a, b, true);
};
$.fn.dataTable.ext.type.order[ conf.name+'-desc' ]=function(a, b){
return conf.desc(a, b, true);
};
return conf.name;
};}));