MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
| Line 15: | Line 15: | ||
function listProjects(){ | function listProjects(){ | ||
/** checknode = $('table#listProjects'); | |||
$(checknode).DataTable({ | $(checknode).DataTable({ | ||
| Line 38: | Line 38: | ||
} | } | ||
}); | |||
**/ | |||
$('#listProjects thead tr') | |||
.clone(true) | |||
.addClass('filters') | |||
.appendTo('#listProjects thead'); | |||
var table = $('#listProjects').DataTable({ | |||
dom: '<"top"lif>t<"bottom"p><"clear">', | |||
responsive: true, | |||
order: [[ 0, 'asc' ]], | |||
columns: [ | |||
{ "title": "1" }, | |||
{ "title": "2" }, | |||
{ "title": "3" }, | |||
{ "title": "4" }, | |||
{ "title": "5" }, | |||
{ "title": "6" }, | |||
{ "title": "7" } | |||
], | |||
aoColumns: [], | |||
lengthMenu: [ | |||
[10, 25, 50, -1], [10, 25, 50, "All"] | |||
], | |||
pageLength: 25, | |||
orderCellsTop: true, | |||
fixedHeader: true, | |||
initComplete: function () { | |||
var api = this.api(); | |||
// For each column | |||
api | |||
.columns() | |||
.eq(0) | |||
.each(function (colIdx) { | |||
// Set the header cell to contain the input element | |||
var cell = $('.filters th').eq( | |||
$(api.column(colIdx).header()).index() | |||
); | |||
var title = $(cell).text(); | |||
$(cell).html('<input type="text" placeholder="' + title + '" />'); | |||
// On every keypress in this input | |||
$( | |||
'input', | |||
$('.filters th').eq($(api.column(colIdx).header()).index()) | |||
) | |||
.off('keyup change') | |||
.on('keyup change', function (e) { | |||
e.stopPropagation(); | |||
// Get the search value | |||
$(this).attr('title', $(this).val()); | |||
var regexr = '({search})'; //$(this).parents('th').find('select').val(); | |||
var cursorPosition = this.selectionStart; | |||
// Search the column for that value | |||
api | |||
.column(colIdx) | |||
.search( | |||
this.value != '' | |||
? regexr.replace('{search}', '(((' + this.value + ')))') | |||
: '', | |||
this.value != '', | |||
this.value == '' | |||
) | |||
.draw(); | |||
$(this) | |||
.focus()[0] | |||
.setSelectionRange(cursorPosition, cursorPosition); | |||
}); | |||
}); | |||
}, | |||
}); | }); | ||
} | } | ||
Revision as of 19:30, September 13, 2021
/* Any JavaScript here will be loaded for all users on every page load. */
$(function() {
cDependent();
listProjects();
});
function cDependent(){
if($('.mw-references-wrap').length === 0){
} else {
$('.cdependent').show();
}
}
function listProjects(){
/** checknode = $('table#listProjects');
$(checknode).DataTable({
dom: '<"top"lif>t<"bottom"p><"clear">',
responsive: true,
order: [[ 0, 'asc' ]],
columns: [
{ "title": "1" },
{ "title": "2" },
{ "title": "3" },
{ "title": "4" },
{ "title": "5" },
{ "title": "6" },
{ "title": "7" }
],
aoColumns: [],
lengthMenu: [
[10, 25, 50, -1], [10, 25, 50, "All"]
],
pageLength: 25,
fnInitComplete: function() {
}
});
**/
$('#listProjects thead tr')
.clone(true)
.addClass('filters')
.appendTo('#listProjects thead');
var table = $('#listProjects').DataTable({
dom: '<"top"lif>t<"bottom"p><"clear">',
responsive: true,
order: [[ 0, 'asc' ]],
columns: [
{ "title": "1" },
{ "title": "2" },
{ "title": "3" },
{ "title": "4" },
{ "title": "5" },
{ "title": "6" },
{ "title": "7" }
],
aoColumns: [],
lengthMenu: [
[10, 25, 50, -1], [10, 25, 50, "All"]
],
pageLength: 25,
orderCellsTop: true,
fixedHeader: true,
initComplete: function () {
var api = this.api();
// For each column
api
.columns()
.eq(0)
.each(function (colIdx) {
// Set the header cell to contain the input element
var cell = $('.filters th').eq(
$(api.column(colIdx).header()).index()
);
var title = $(cell).text();
$(cell).html('<input type="text" placeholder="' + title + '" />');
// On every keypress in this input
$(
'input',
$('.filters th').eq($(api.column(colIdx).header()).index())
)
.off('keyup change')
.on('keyup change', function (e) {
e.stopPropagation();
// Get the search value
$(this).attr('title', $(this).val());
var regexr = '({search})'; //$(this).parents('th').find('select').val();
var cursorPosition = this.selectionStart;
// Search the column for that value
api
.column(colIdx)
.search(
this.value != ''
? regexr.replace('{search}', '(((' + this.value + ')))')
: '',
this.value != '',
this.value == ''
)
.draw();
$(this)
.focus()[0]
.setSelectionRange(cursorPosition, cursorPosition);
});
});
},
});
}