'use strict'; $(document).on('page_ready', function() { var searchForm = $('#search_form'), table = $('#search_results'), tableOptions; if (table.length) { tableOptions = {ajax: {url: 'search.php' + ((args.site) ? '?site=' + args.site : ''), method: 'POST', data: function() { var data = table.data(); data.datatable = '1'; data.csrf_token = getCSRFToken(); return data; }}}; tableOptions.columnDefs = getTypes(table); tableOptions.buttons = [ { extend: 'colvis' }, { text: '', action: function (e, dt, node, config) { var data = $('#search_form').serializeArray(); data.push({name: 'ics', value: 1}); $.post({ url: window.location.href, data: data, success: function(blob, status, xhr) { var contentType = xhr.getResponseHeader('Content-Type'); var contentTypeRegex = /^[^;]*/; var matches = contentType.match(contentTypeRegex); var type = (matches === null) ? '' : matches[0]; var filename = ""; var disposition = xhr.getResponseHeader('Content-Disposition'); if (disposition && disposition.indexOf('attachment') !== -1) { var filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/; matches = filenameRegex.exec(disposition); if (matches != null && matches[1]) filename = matches[1].replace(/['"]/g, ''); } if (typeof window.navigator.msSaveBlob !== 'undefined') { // IE workaround for "HTML7007: One or more blob URLs were revoked by closing the blob for which they were created. These URLs will no longer resolve as the data backing the URL has been freed." window.navigator.msSaveBlob(blob, filename); } else { var URL = window.URL || window.webkitURL; var downloadUrl = URL.createObjectURL(new Blob([blob], {type: type})); if (filename) { // use HTML5 a[download] attribute to specify filename var a = document.createElement("a"); // safari doesn't support this yet if (typeof a.download === 'undefined') { window.location.href = downloadUrl; } else { a.href = downloadUrl; a.download = filename; document.body.appendChild(a); a.click(); } } else { window.location.href = downloadUrl; } setTimeout(function () { URL.revokeObjectURL(downloadUrl); }, 100); // cleanup } } }); } } ] makeDataTable('#search_results', tableOptions, {"leftColumns": 1}); } });