MediaWiki:Common.js

From Anthroposophy

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */

   const title = mw.config.get('wgPageName');

   if (title == 'Project:Discussions') {

        mw.loader.load('https://cdn.datatables.net/v/dt/dt-1.11.5/b-2.2.2/b-colvis-2.2.2/b-print-2.2.2/cr-1.5.5/date-1.1.2/fc-4.0.2/fh-3.2.2/kt-2.6.4/r-2.2.9/sc-2.0.5/sb-1.3.2/sp-2.0.0/sl-1.3.4/sr-1.1.0/datatables.min.css', 'text/css');

        $.ajaxSetup({cache: true});

        $.when(mw.loader.getScript('https://cdn.datatables.net/v/dt/dt-1.11.5/b-2.2.2/b-colvis-2.2.2/b-print-2.2.2/cr-1.5.5/date-1.1.2/fc-4.0.2/fh-3.2.2/kt-2.6.4/r-2.2.9/sc-2.0.5/sb-1.3.2/sp-2.0.0/sl-1.3.4/sr-1.1.0/datatables.min.js'))
        
		.then(function () {
           	
			allDiscussionsDt();
				
        });
	}
	
	function allDiscussionsDt() {
        if ($('#alldiscussions').length > 0) {
            var table = $('#alldiscussions').DataTable({
                dom: 'f', 
                retrieve: true, 
                responsive: true,
                columnDefs: [
					{
                    	targets: [2],
                        type: 'date'
					},
					{
                    	targets: [7],
                        type: 'date'
					},
					{
                        targets: [3],
						type: 'num',
						className: 'text-center'
					},
					{
                        targets: [5],
						type: 'num',
						className: 'text-center'
					}
				],
                columns: [
                	{"title": "Discussion"},
                	{"title": "Created by"},
                	{"title": "Created on"},
                	{"title": "Number of participants"},
                	{"title": "Participants"},
                	{"title": "Number of posts"},
                	{"title": "Last edited by"},
                	{"title": "Last edited on"}
                ], 
                order: [[7, 'desc']],
                stripeClasses: [],
                pageLength: 1000, 
                language: {
    			    search: ''
    			},
                initComplete: function () {
                    // Initialization complete callback
                    console.log("DataTable initialized successfully.");
					$('.dataTables_filter input').attr("placeholder", "Search in this table");
                }
            });
        }
	}