DEV formatting corrections to last edit

pull/428/head
Colin Marks 6 years ago
parent d6b5dc1729
commit 1cb1d80874

@ -47,48 +47,42 @@
* ); * );
*/ */
(function(window, document, $, undefined) { (function(window, document, $, undefined) {
// Use DataTables' object builder so strings can be used to represent
// nested objects
var setBuilder = $.fn.dataTable.ext.internal._fnSetObjectDataFn;
// Use DataTables' object builder so strings can be used to represent $.fn.dataTable.ext.deepLink = function(whitelist) {
// nested objects var search = location.search.replace(/^\?/, '').split('&');
var setBuilder = $.fn.dataTable.ext.internal._fnSetObjectDataFn; var out = {};
$.fn.dataTable.ext.deepLink = function(whitelist) { for (var i = 0, ien = search.length; i < ien; i++) {
var search = location.search.replace(/^\?/, '').split('&'); var pair = search[i].split('=');
var out = {}; var key = decodeURIComponent(pair[0]);
var value = decodeURIComponent(pair[1]);
console.log('key: ' + key);
console.log('value: ' + value);
for (var i = 0, ien = search.length; i < ien; i++) { // "Casting"
var pair = search[i].split('='); if (value === 'true') {
var key = decodeURIComponent(pair[0]); value = true;
var value = decodeURIComponent(pair[1]); } else if (value === 'false') {
console.log("key: " + key); value = false;
console.log("value: " + value); } else if (!value.match(/[^\d]/) && key !== 'search.search') {
// don't convert if searching or it'll break the search
// "Casting" value = value * 1;
if (value === 'true') { } else if (value.indexOf('{') === 0 || value.indexOf('[') === 0) {
value = true; // Try to JSON parse for arrays and obejcts
} try {
else if (value === 'false') { value = $.parseJSON(value);
value = false; } catch (e) {}
}
else if (!value.match(/[^\d]/) && key !== 'search.search') {
// don't convert if searching or it'll break the search
value = value * 1;
}
else if (value.indexOf('{') === 0 || value.indexOf('[') === 0) {
// Try to JSON parse for arrays and obejcts
try {
value = $.parseJSON( value );
} }
catch(e){}
}
if (whitelist === 'all' || $.inArray(key, whitelist) !== -1) { if (whitelist === 'all' || $.inArray(key, whitelist) !== -1) {
var setter = setBuilder(key); var setter = setBuilder(key);
setter(out, value); setter(out, value);
}
} }
}
return out;
};
return out;
};
})(window, document, jQuery); })(window, document, jQuery);

Loading…
Cancel
Save