MediaWiki:Common.js: Difference between revisions

From Hollywood in Pixels Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(32 intermediate revisions by the same user not shown)
Line 4: Line 4:
$(function() {
$(function() {
cDependent();
cDependent();
$('#listProjects thead tr')
        .clone()
        .addClass('filters')
        .appendTo('#listProjects thead');
listProjects();
});
});


function cDependent(){
function cDependent(){
if($('.mw-references-wrap').length === 0){
if($('.mw-references-wrap').length > 0){
} else {
$('.cdependent').show();
$('.cdependent').show();
}
}
}
}


function listProjects(){
/**
* Creating a datatable
* @example <>
*/
 
var selectors = [
    'table#listProjects',
];
 
var found = false;
for (var i = 0; i < selectors.length; i++) {
    if (document.querySelector(selectors[i])) {
        found = true;
        break;
    }
}
 
if (found === true) {
    const dtsource =
        'https://cdn.datatables.net/v/dt/moment-2.29.4/dt-2.3.7/b-3.2.6/b-colvis-3.2.6/b-html5-3.2.6/b-print-3.2.6/cc-1.2.0/date-1.6.3/fh-4.0.5/r-3.0.8/sc-2.4.3/sb-1.8.4/sp-2.3.5/sl-3.1.3/sr-1.4.3/datatables.min.css';
 
    if (!document.querySelector('link[href*="datatables.min.css"]')) {
        $('<link/>', { rel: 'stylesheet', href: dtsource }).appendTo('head');
    }
 
    $.ajaxSetup({ cache: true });
 
    $.when(
        mw.loader.getScript(
            'https://cdn.datatables.net/v/dt/moment-2.29.4/dt-2.3.7/b-3.2.6/b-colvis-3.2.6/b-html5-3.2.6/b-print-3.2.6/cc-1.2.0/date-1.6.3/fh-4.0.5/r-3.0.8/sc-2.4.3/sb-1.8.4/sp-2.3.5/sl-3.1.3/sr-1.4.3/datatables.min.js'
        )
    ).then(
        () => {
            window.datatablesLoaded = true;
            initDataTable();
        },
        e => mw.log.error(e.message) // Failed to load script
    );
}
 
function initDataTable() {


   
     var table = $('#listProjects').DataTable({
     var table = $('#listProjects').DataTable({
    // dom: '<"top"lif>t<"bottom"p><"clear">',
layout: {
        searchPanes: {
topStart: null,
        layout: 'columns-2'
topEnd: null,
    },
    top2: {
    dom: 'Pfrtip',
                searchPanes: {
                    cascadePanes: true,
                    initCollapsed: true
                }
            },
            top1: {
                search: {
                    className: "mx-0 w-100"
                }
            },
    bottomStart: 'info',
    bottomEnd: 'paging'
},
responsive: true,
responsive: true,
colReorder: true,
colReorder: true,
     order: [[ 0, 'asc' ]],
     order: [[ 0, 'asc' ]],
     columns: [
     columns: [
         { "title": "Film" },
         { title: "Film" },
         { "title": "Year" },
         { title: "Released" },
         { "title": "Studio" },
         {  
{ "title": "Agency" },
        title: "Studio",
{ "title": "Functions, Assets and Awards" },
        render: {
{ "title": "Audience" },
                    display: function (data, type, row) {
{ "title": "Media Partner" }
                        return data;  // normal data for table
                    },
                    sp: function (data, type, row) {
                        return data ? data.split(/\s*,\s*/).map(v => v.trim()) : [];
                    }
                },
                searchPanes: {
                orthogonal: 'sp',
                cascadePanes: true,
                },
        },
{ title: "Agency" },
{ title: "Project" },
{
title: "Type",
        render: {
                    display: function (data, type, row) {
                        return data;  // normal data for table
                    },
                    sp: function (data, type, row) {
                        return data ? data.split(/\s*,\s*/).map(v => v.trim()) : [];
                    }
                },
                searchPanes: {
                orthogonal: 'sp',
                cascadePanes: true,
                },
},
{ title: "Asset" },
{ title: "Awards" },
],
],
columnDefs: [{
searchPanes: {
show: true
},
targets: [0, 1, 2, 3]
}],
         aoColumns: [],
         aoColumns: [],
         lengthMenu: [
         lengthMenu: [
Line 54: Line 120:
         orderCellsTop: true,
         orderCellsTop: true,
         fixedHeader: true,
         fixedHeader: true,
        searchBuilder: {
        greyscale: true
    },
         initComplete: function () {
         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);
                        });
                });
         },
     });
     });
}
}

Latest revision as of 17:03, February 15, 2026

/* Any JavaScript here will be loaded for all users on every page load. */

        
$(function() {
	cDependent();
});

function cDependent(){
	if($('.mw-references-wrap').length > 0){
		$('.cdependent').show();
	}
}

/**
 * Creating a datatable
 * @example <>
 */

var selectors = [
    'table#listProjects',
];

var found = false;
for (var i = 0; i < selectors.length; i++) {
    if (document.querySelector(selectors[i])) {
        found = true;
        break;
    }
}

if (found === true) {
    const dtsource =
        'https://cdn.datatables.net/v/dt/moment-2.29.4/dt-2.3.7/b-3.2.6/b-colvis-3.2.6/b-html5-3.2.6/b-print-3.2.6/cc-1.2.0/date-1.6.3/fh-4.0.5/r-3.0.8/sc-2.4.3/sb-1.8.4/sp-2.3.5/sl-3.1.3/sr-1.4.3/datatables.min.css';

    if (!document.querySelector('link[href*="datatables.min.css"]')) {
        $('<link/>', { rel: 'stylesheet', href: dtsource }).appendTo('head');
    }

    $.ajaxSetup({ cache: true });

    $.when(
        mw.loader.getScript(
            'https://cdn.datatables.net/v/dt/moment-2.29.4/dt-2.3.7/b-3.2.6/b-colvis-3.2.6/b-html5-3.2.6/b-print-3.2.6/cc-1.2.0/date-1.6.3/fh-4.0.5/r-3.0.8/sc-2.4.3/sb-1.8.4/sp-2.3.5/sl-3.1.3/sr-1.4.3/datatables.min.js'
        )
    ).then(
        () => {
            window.datatablesLoaded = true;
            initDataTable();
        },
        e => mw.log.error(e.message) // Failed to load script
    );
}

function initDataTable() {

    var table = $('#listProjects').DataTable({
		layout: {
			topStart: null,
			topEnd: null,
    		top2: {
                searchPanes: {
                    cascadePanes: true,
                    initCollapsed: true
                }
            },
            top1: {
                search: {
                    className: "mx-0 w-100"
                }
            },
    		bottomStart: 'info',
    		bottomEnd: 'paging'
		},
		responsive: true,
		colReorder: true,
    	order: [[ 0, 'asc' ]],
    	columns: [
        	{ title: "Film" },
        	{ title: "Released" },
        	{ 
        		title: "Studio",
        		render: {
                    display: function (data, type, row) {
                        return data;   // normal data for table
                    },
                    sp: function (data, type, row) {
                        return data ? data.split(/\s*,\s*/).map(v => v.trim()) : [];
                    }
                },
                searchPanes: { 
                	orthogonal: 'sp', 
                	cascadePanes: true,
                },
        	},
			{ title: "Agency" },
			{ title: "Project" },
			{ 
				title: "Type",
        		render: {
                    display: function (data, type, row) {
                        return data;   // normal data for table
                    },
                    sp: function (data, type, row) {
                        return data ? data.split(/\s*,\s*/).map(v => v.trim()) : [];
                    }
                },
                searchPanes: { 
                	orthogonal: 'sp', 
                	cascadePanes: true,
                },
			},
			{ title: "Asset" },
			{ title: "Awards" },
		],
        aoColumns: [],
        lengthMenu: [
                [10, 25, 50, -1], [10, 25, 50, "All"]
        ],
        pageLength: 25,
        orderCellsTop: true,
        fixedHeader: true,
        searchBuilder: {
        	greyscale: true
    	},
        initComplete: function () {
        }
    });
}