MediaWiki:Common.js: Difference between revisions
MikeSaunders (talk | contribs) No edit summary |
MikeSaunders (talk | contribs) No edit summary Tag: Reverted |
||
| Line 78: | Line 78: | ||
} | } | ||
}); | }); | ||
///////////////////////////////////////////////////////// | |||
// Code snippet to make your sidebar items expandable. | |||
// Use this code ONLY for the Monobook skin. | |||
///////////////////////////////////////////////////////// | |||
$( document ).ready( function() { | |||
// Set the default expanded items by their headline | |||
var defaultExpandItems = ['Navigation', 'Orga']; | |||
// Set the basic-name for the cookies, which save the current state of expanding | |||
var expandCookieName = 'disdance_project_wiki_nav_expanded_'; | |||
var maxHeights = []; | |||
var expandeds = []; | |||
var labels = []; | |||
initNav(); | |||
}); | |||
function initNav() { | |||
$( '#p-logo' ).css({'position': 'relative', 'display': 'block'}); | |||
$( '.generated-sidebar h5,#p-tb h5 ').each( function( i ) { | |||
var id = $( this ).parent().attr( 'id' ); | |||
maxHeights[id] = $( this ).next( 'div' ).height(); | |||
var str = $( this ).html(); | |||
labels[id] = str; | |||
if ( $.cookie( expandCookieName + id ) == 'false' ) { | |||
expandeds[id] = false; | |||
minimize( $( this ) ); | |||
} else if ( $.cookie( expandCookieName + id ) == 'true' ) { | |||
expandeds[id] = true; | |||
maximize( $( this ) ); | |||
} else if ( defaultExpandItems.indexOf( str ) == -1 ) { | |||
expandeds[id] = false; | |||
minimize( $( this ) ); | |||
} else { | |||
expandeds[id] = true; | |||
maximize( $( this ) ); | |||
} | |||
$( this ).css({'cursor': 'pointer'}); | |||
$( this ).click( toggleNav ); | |||
} ); | |||
} | |||
function minimize( target ) { | |||
var id = $( target ).parent().attr( 'id' ); | |||
// You can change the expires parameter to save the cookie longer/shorter than 7 days like in this code | |||
$.cookie( expandCookieName + id, 'false', { expires: 7} ); | |||
var str = labels[id] + ' ►'; | |||
$( target ).next( 'div' ).animate({'height': '0px'}); | |||
$( target ).html( str ); | |||
} | |||
function maximize( target ) { | |||
var id = $( target ).parent().attr( 'id' ); | |||
// You can change the expires parameter to save the cookie longer/shorter than 7 days like in this code | |||
$.cookie( expandCookieName + id, 'true', { expires: 7} ); | |||
var str = labels[id] + ' ▼'; | |||
var newHeight = maxHeights[id]; | |||
$( target ).next( 'div' ).animate({'height': newHeight + 'px'}); | |||
$( target ).html( str ); | |||
} | |||
function toggleNav( e ) { | |||
var id = $(e.target ).parent().attr( 'id' ); | |||
expandeds[id] = !expandeds[id]; | |||
if( expandeds[id] == true ) { | |||
maximize( e.target ); | |||
} else { | |||
minimize( e.target ); | |||
} | |||
} | |||
/////////////////////////////////////////////////////// | |||
/////////////////////////////////////////////////////// | |||
Revision as of 08:51, 6 December 2023
//datatables
//styles
$('head').append( $('<link rel="stylesheet" type="text/css" />').attr('href', 'https://cdn.datatables.net/1.13.7/css/jquery.dataTables.css') );
$('head').append( $('<link rel="stylesheet" type="text/css" />').attr('href', 'https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.13.2/themes/base/jquery-ui.min.css') );
$('head').append( $('<link rel="stylesheet" type="text/css" />').attr('href', 'https://cdn.datatables.net/v/ju/jszip-3.10.1/dt-1.13.7/b-2.4.2/b-html5-2.4.2/fh-3.4.0/kt-2.11.0/sp-2.2.0/sl-1.7.0/datatables.min.css') );
//scripts
$.when(
mw.loader.getScript( 'https://cdn.datatables.net/1.13.7/js/jquery.dataTables.js' ),
mw.loader.getScript( 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/pdfmake.min.js' ),
mw.loader.getScript( 'https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.2.7/vfs_fonts.js' ),
mw.loader.getScript( 'https://cdn.datatables.net/v/ju/jszip-3.10.1/dt-1.13.7/b-2.4.2/b-html5-2.4.2/fh-3.4.0/kt-2.11.0/sp-2.2.0/sl-1.7.0/datatables.min.js' ),
mw.loader.getScript( 'https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.13.2/jquery-ui.min.js' )
)
.then(
function () {
// implement datatable
$(document).ready(function(){
$('#table').DataTable( {
paging: false,
ordering: false,
fixedHeader: true,
keys: true,
dom: 'fPBrtip',
"language": {
"search": "Search this table: _INPUT_"
},
buttons: [
'excelHtml5',
'csvHtml5',
'pdfHtml5'
],
columnDefs: [
{
searchPanes: {
initCollapsed: true,
show: true
},
targets: [2]
},
{
searchPanes: {
show: false
},
targets: [0,1,3]
}
]
} );
$("div#table_filter").after( $("<div id='search_explain'>You can use terms from multiple columns in the same search, eg: 'African 1800'</div>") );
} );
},
function ( e ) {
// A script failed, and is not available
mw.log.error( e.message ); // => "Failed to load script"
}
);
// add a search box (commendted out after datatable search)
//$(document).ready(function(){
// $("#bodySearchInputsearchInput").on("keyup", function() {
// var value = $(this).val().toLowerCase();
// $("#table tr").filter(function() {
// $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
// });
// });
//});
$(document).ready(function(){
// Remove the action from the Inputbox search form
$("#bodySearchsearchInput").attr('action', 'javascript:void(0);');
});
// content warning message
$(function() {
if (localStorage.getItem("firstTime") == null) {
document.getElementById("siteNotice").style.display = "block";
localStorage.setItem("firstTime", "done");
}
});
/////////////////////////////////////////////////////////
// Code snippet to make your sidebar items expandable.
// Use this code ONLY for the Monobook skin.
/////////////////////////////////////////////////////////
$( document ).ready( function() {
// Set the default expanded items by their headline
var defaultExpandItems = ['Navigation', 'Orga'];
// Set the basic-name for the cookies, which save the current state of expanding
var expandCookieName = 'disdance_project_wiki_nav_expanded_';
var maxHeights = [];
var expandeds = [];
var labels = [];
initNav();
});
function initNav() {
$( '#p-logo' ).css({'position': 'relative', 'display': 'block'});
$( '.generated-sidebar h5,#p-tb h5 ').each( function( i ) {
var id = $( this ).parent().attr( 'id' );
maxHeights[id] = $( this ).next( 'div' ).height();
var str = $( this ).html();
labels[id] = str;
if ( $.cookie( expandCookieName + id ) == 'false' ) {
expandeds[id] = false;
minimize( $( this ) );
} else if ( $.cookie( expandCookieName + id ) == 'true' ) {
expandeds[id] = true;
maximize( $( this ) );
} else if ( defaultExpandItems.indexOf( str ) == -1 ) {
expandeds[id] = false;
minimize( $( this ) );
} else {
expandeds[id] = true;
maximize( $( this ) );
}
$( this ).css({'cursor': 'pointer'});
$( this ).click( toggleNav );
} );
}
function minimize( target ) {
var id = $( target ).parent().attr( 'id' );
// You can change the expires parameter to save the cookie longer/shorter than 7 days like in this code
$.cookie( expandCookieName + id, 'false', { expires: 7} );
var str = labels[id] + ' ►';
$( target ).next( 'div' ).animate({'height': '0px'});
$( target ).html( str );
}
function maximize( target ) {
var id = $( target ).parent().attr( 'id' );
// You can change the expires parameter to save the cookie longer/shorter than 7 days like in this code
$.cookie( expandCookieName + id, 'true', { expires: 7} );
var str = labels[id] + ' ▼';
var newHeight = maxHeights[id];
$( target ).next( 'div' ).animate({'height': newHeight + 'px'});
$( target ).html( str );
}
function toggleNav( e ) {
var id = $(e.target ).parent().attr( 'id' );
expandeds[id] = !expandeds[id];
if( expandeds[id] == true ) {
maximize( e.target );
} else {
minimize( e.target );
}
}
///////////////////////////////////////////////////////
///////////////////////////////////////////////////////