Difference between revisions of "MediaWiki:MainMenu.js"

From Tycoon Gaming
m (Css loading doesnt work)
m
Line 3: Line 3:
 
if (mw.config.get('wgPageName') === 'User:Donald/MainMenuTest') {
 
if (mw.config.get('wgPageName') === 'User:Donald/MainMenuTest') {
 
     // Create the search form HTML
 
     // Create the search form HTML
    console.log("test Successful");
 
 
     var searchFormHTML = '<form action="/wiki/index.php" method="get">' +
 
     var searchFormHTML = '<form action="/wiki/index.php" method="get">' +
 
                         '<input type="hidden" name="title" value="Special:Search">' +
 
                         '<input type="hidden" name="title" value="Special:Search">' +
Line 17: Line 16:
 
         pageElement.innerHTML = searchFormHTML;
 
         pageElement.innerHTML = searchFormHTML;
 
     }
 
     }
 +
   
 +
    var MenuInput = '<input id="job-search-input" type="text" style="width: 100%;"></input>';
 +
   
 +
    var pagejobElement = document.getElementById('testaddjobsearchbar'); // Replace 'someElementID' with the actual ID
 +
 +
    // Insert the search form HTML into the identified element
 +
    if (pagejobElement) {
 +
        pagejobElement.innerHTML = MenuInput;
 +
    }
 +
   
 +
    var searchInput = document.getElementById('job-search-input');
 +
 +
if(searchInput) {
 +
        searchInput.addEventListener('input', function() {
 +
            var searchTerm = this.value.toLowerCase();
 +
            var jobsList = document.getElementById('jobs-list');
 +
            var jobs = jobsList.getElementsByClassName('job-item');
 +
 +
            Array.from(jobs).forEach(function(job) {
 +
                var jobName = job.getAttribute('data-jobname').toLowerCase();
 +
                if (searchTerm === '' || jobName.includes(searchTerm)) {
 +
                    job.style.display = ''; // Show all or matching jobs
 +
                } else {
 +
                    job.style.display = 'none'; // Hide non-matching jobs
 +
                }
 +
            });
 +
        });
 +
}
 
}
 
}
 
});
 
});

Revision as of 13:35, 10 November 2023

$( document ).ready(function() {
	// Check if we're on the 'User:Donald/MainMenuTest' page
	if (mw.config.get('wgPageName') === 'User:Donald/MainMenuTest') {
    	// Create the search form HTML
    	var searchFormHTML = '<form action="/wiki/index.php" method="get">' +
                         '<input type="hidden" name="title" value="Special:Search">' +
                         '<input type="text" name="search" placeholder="Search the wiki" />' +
                         '<input type="submit" value="Go" />' +
                         '</form>';

    	// Identify the element where you want to add the search form
    	var pageElement = document.getElementById('testaddsearchbar'); // Replace 'someElementID' with the actual ID

    	// Insert the search form HTML into the identified element
    	if (pageElement) {
        	pageElement.innerHTML = searchFormHTML;
    	}
    	
    	var MenuInput = '<input id="job-search-input" type="text" style="width: 100%;"></input>';
    	
    	var pagejobElement = document.getElementById('testaddjobsearchbar'); // Replace 'someElementID' with the actual ID

    	// Insert the search form HTML into the identified element
    	if (pagejobElement) {
        	pagejobElement.innerHTML = MenuInput;
    	}
    	
    	var searchInput = document.getElementById('job-search-input');

		if(searchInput) {
	        searchInput.addEventListener('input', function() {
	            var searchTerm = this.value.toLowerCase();
	            var jobsList = document.getElementById('jobs-list');
	            var jobs = jobsList.getElementsByClassName('job-item');
	
	            Array.from(jobs).forEach(function(job) {
	                var jobName = job.getAttribute('data-jobname').toLowerCase();
	                if (searchTerm === '' || jobName.includes(searchTerm)) {
	                    job.style.display = ''; // Show all or matching jobs
	                } else {
	                    job.style.display = 'none'; // Hide non-matching jobs
	                }
	            });
	        });
		}
	}
});