MediaWiki:Common.js: Difference between revisions

From The Jolly Contrarian
Jump to navigation Jump to search
m Reverted edits by Amwelladmin (talk) to last revision by Root
No edit summary
 
(85 intermediate revisions by the same user not shown)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
var customizeToolbar = function() {
/* Good source of edit buttons: http://commons.wikimedia.org/wiki/Mediawiki_edit_toolbar */
 
if (mwCustomEditButtons) {
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'sections': {
'manual': {
  mwCustomEditButtons[mwCustomEditButtons.length] = {
'type': 'toolbar', // Can also be 'booklet'
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/e/eb/Button_plantilla.png",
'label': 'Manual'
    "speedTip": "template {{ }}",
// or 'labelMsg': 'section-manual-label' for a localized label
    "tagOpen": "{{",
}
    "tagClose": "}}",
}
    "sampleText": "text"}
} );
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
'section': 'manual',
'groups': {
'tags': {
'label': 'Tags' // or use labelMsg for a localized label, see above
}
}
} );
 
$('#wpTextbox1').wikiEditor('addToToolbar', {
section: 'advanced',
group: 'format',
tools: {
"template": {
label: 'long dash',
type: 'button',
icon: 'https://jollycontrarian.com/images/5/55/Dash.png',
action: {
type: 'encapsulate',
options: {
pre: "—",
post: ""
}
}
}
}
});
$('#wpTextbox1').wikiEditor('addToToolbar', {
section: 'advanced',
group: 'format',
tools: {
"template": {
label: 'scarequotes',
type: 'button',
icon: 'https://jollycontrarian.com/images/b/ba/Scare.png',
action: {
type: 'encapsulate',
options: {
pre: "“",
post: "”"
}
}
}
}
});
$('#wpTextbox1').wikiEditor('addToToolbar', {
section: 'advanced',
group: 'format',
tools: {
"template": {
label: 'apostrophe',
type: 'button',
icon: 'https://jollycontrarian.com/images/5/5b/Apo.png',
action: {
type: 'encapsulate',
options: {
pre: "’",
post: ""
}
}
}
}
});
 
$('#wpTextbox1').wikiEditor('addToToolbar', {
section: 'advanced',
group: 'format',
tools: {
"template": {
label: '{{ - }}',
type: 'button',
icon: 'https://jollycontrarian.com/images/3/30/Template.png',
action: {
type: 'encapsulate',
options: {
pre: "{{",
post: "}}"
}
}
}
}
});
 
$('#wpTextbox1').wikiEditor('addToToolbar', {
section: 'advanced',
group: 'format',
tools: {
"Substitute": {
label: 'subst:',
type: 'button',
icon: 'https://jollycontrarian.com/images/0/03/Sbs.png',
action: {
type: 'encapsulate',
options: {
pre: "{{subst:",
post: "}}"
}
}
}
}
});
 
$('#wpTextbox1').wikiEditor('addToToolbar', {
section: 'advanced',
group: 'format',
tools: {
"redirect": {
label: '==>',
type: 'button',
icon: 'https://jollycontrarian.com/images/9/91/Redirect.png',
action: {
type: 'encapsulate',
options: {
pre: "#redirect[[",
post: "]]"
}
}
}
}
});
 
$('#wpTextbox1').wikiEditor('addToToolbar', {
section: 'advanced',
group: 'format',
tools: {
"template": {
label: 'tag',
type: 'button',
icon: 'https://jollycontrarian.com/images/7/76/Tag.png',
action: {
type: 'encapsulate',
options: {
pre: "{{t|",
post: "}}"
}
}
}
}
});
 
$('#wpTextbox1').wikiEditor('addToToolbar', {
section: 'advanced',
group: 'format',
tools: {
"Prov": {
label: 'isdaprov',
type: 'button',
icon: 'https://jollycontrarian.com/images/5/50/Isd.png',
action: {
type: 'encapsulate',
options: {
pre: "{{isdaprov|",
post: "}}"
}
}
}
}
});
 
$('#wpTextbox1').wikiEditor('addToToolbar', {
section: 'advanced',
group: 'format',
tools: {
"Prov": {
label: 'euaprov',
type: 'button',
icon: 'https://jollycontrarian.com/images/5/50/eua.png',
action: {
type: 'encapsulate',
options: {
pre: "{{euaprov|",
post: "}}"
}
}
}
}
});
$('#wpTextbox1').wikiEditor('addToToolbar', {
section: 'advanced',
group: 'format',
tools: {
"ietaprov": {
label: 'ietaprov',
type: 'button',
icon: 'https://jollycontrarian.com/images/e/e9/Gms.png',
action: {
type: 'encapsulate',
options: {
pre: "{{ietaprov|",
post: "}}"
}
}
}
}
});
 
$('#wpTextbox1').wikiEditor('addToToolbar', {
section: 'advanced',
group: 'format',
tools: {
"gmraprov": {
label: '{{{1}}}|',
type: 'button',
icon: 'https://jollycontrarian.com/images/4/49/blank.png',
action: {
type: 'encapsulate',
options: {
pre: "{{{{{1}}}|",
post: "}}"
}
}
}
}
});
 
$('#wpTextbox1').wikiEditor('addToToolbar', {
section: 'advanced',
group: 'format',
tools: {
"Equity Derivs": {
label: 'eqderivprov',
type: 'button',
icon: 'https://jollycontrarian.com/images/c/c3/Eqd.png',
action: {
type: 'encapsulate',
options: {
pre: "{{eqderivprov|",
post: "}}"
}
}
}
}
});


  mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/1/16/Button_fairuse.png",
    "speedTip": "{{tag|xxx}}",
    "tagOpen": "{{tag|",
    "tagClose": "}}",
    "sampleText": "text"}


  mwCustomEditButtons[mwCustomEditButtons.length] = {
$('#wpTextbox1').wikiEditor('addToToolbar', {
    "imageFile": "http://localhost/mediawiki/images/h1.png",
section: 'advanced',
    "speedTip": "h1",
group: 'format',
    "tagOpen": "{{h1|",
tools: {
    "tagClose": "}}",
"template": {
    "sampleText": "text"}
label: 'vmcsaprov',
type: 'button',
icon: 'https://jollycontrarian.com/images/3/37/Csa.png',
action: {
type: 'encapsulate',
options: {
pre: "{{vmcsaprov|",
post: "}}"
}
}
}
}
});


  mwCustomEditButtons[mwCustomEditButtons.length] = {
$('#wpTextbox1').wikiEditor('addToToolbar', {
    "imageFile": "http://localhost/mediawiki/images/h2.png",
section: 'advanced',
    "speedTip": "h2",
group: 'format',
    "tagOpen": "{{h2|",
tools: {
    "tagClose": "}}",
"template": {
    "sampleText": "text"}
label: 'hotlink',
type: 'button',
icon: 'https://jollycontrarian.com/images/3/37/Csa.png',
action: {
type: 'encapsulate',
options: {
pre: "{{pjchotlink|}}<li>{{pjchotlink|}}<li>{{pjchotlink|}}<li>{{pjchotlink|}}<li>{{pjchotlink|}}<li>",
post: "{{pjchotlink|}}"
}
}
}
}
});


  mwCustomEditButtons[mwCustomEditButtons.length] = {
};
    "imageFile": "http://localhost/mediawiki/images/h3.png",
    "speedTip": "h3",
    "tagOpen": "{{h3|",
    "tagClose": "}}",
    "sampleText": "text"}


  mwCustomEditButtons[mwCustomEditButtons.length] = {
if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 ) {
    "imageFile": "http://localhost/mediawiki/images/h4.png",
mw.loader.using( 'user.options' ).then( function () {
    "speedTip": "h4",
if ( mw.user.options.get( 'usebetatoolbar' ) == 1 ) {
    "tagOpen": "{{h4|",
$.when(
    "tagClose": "}}",
mw.loader.using( 'ext.wikiEditor' ), $.ready
    "sampleText": "text"}
).then( customizeToolbar );
}
} );
}


  mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://localhost/mediawiki/images/c.png",
    "speedTip": "1 category",
    "tagOpen": "{{c|",
    "tagClose": "}}",
    "sampleText": "text"}


  mwCustomEditButtons[mwCustomEditButtons.length] = {
// Add the customizations to LiquidThreads' edit toolbar, if available
    "imageFile": "http://localhost/mediawiki/images/c2.png",
mw.hook( 'ext.lqt.textareaCreated' ).add( customizeToolbar );
    "speedTip": "2 categories",
    "tagOpen": "{{c2|",
    "tagClose": "|}}",
    "sampleText": "text"}


  mwCustomEditButtons[mwCustomEditButtons.length] = {
/* Any JavaScript here will be loaded for all users on every page load. */
    "imageFile": "http://localhost/mediawiki/images/c3.png",
    "speedTip": "3 categories",
    "tagOpen": "{{c3|",
    "tagClose": "||}}",
    "sampleText": "text"}


  mwCustomEditButtons[mwCustomEditButtons.length] = {
// JavaScript to dynamically adjust table layout
    "imageFile": "http://localhost/mediawiki/images/c4.png",
function adjustTableLayout() {
    "speedTip": "4 categories",
    var staticTable = document.getElementById('static-table');
    "tagOpen": "{{c4|",
    var adaptiveTable = document.getElementById('adaptive-table');
    "tagClose": "|||}}",
    "sampleText": "text"}


  mwCustomEditButtons[mwCustomEditButtons.length] = {
    if (!staticTable || !adaptiveTable) return;
    "imageFile": "http://localhost/mediawiki/images/b1.png",
    "speedTip": "b1",
    "tagOpen": "{{b1|",
    "tagClose": "}}",
    "sampleText": "text"}


  mwCustomEditButtons[mwCustomEditButtons.length] = {
    // Get the bounding rectangles of the tables
    "imageFile": "http://localhost/mediawiki/images/b2.png",
    var staticRect = staticTable.getBoundingClientRect();
    "speedTip": "b2",
    var adaptiveRect = adaptiveTable.getBoundingClientRect();
    "tagOpen": "{{b2|",
    "tagClose": "}}",
    "sampleText": "text"}


  mwCustomEditButtons[mwCustomEditButtons.length] = {
    // Check if the adaptive table is below the static table
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/c/c8/Button_redirect.png",
    if (adaptiveRect.top >= staticRect.bottom) {
    "speedTip": "redirect",
        adaptiveTable.classList.add('stacked');
    "tagOpen": "#redirect[[",
    } else {
    "tagClose": "]]",
        adaptiveTable.classList.remove('stacked');
    "sampleText": "pagename"}
    }
}


  mwCustomEditButtons[mwCustomEditButtons.length] = {
// Function to request a reflow and check layout
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/a/a0/Button_references_alt.png",
function checkLayout() {
    "speedTip": "falcon head",
    requestAnimationFrame(function() {
    "tagOpen": "{{falconrat|",
        adjustTableLayout();
    "tagClose": "}}",
    });
    "sampleText": "text"}
}


  mwCustomEditButtons[mwCustomEditButtons.length] = {
// Initial adjustment
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/e/e1/Button_smiley.png",
checkLayout();
    "speedTip": "Arabella Story Tag",
    "tagOpen": "{{Arabella|",
    "tagClose": "}}",
    "sampleText": "text"}


  mwCustomEditButtons[mwCustomEditButtons.length] = {
// Adjust on window resize
    "imageFile": "http://upload.wikimedia.org/wikipedia/en/f/fd/Button_blockquote.png",
window.addEventListener('resize', checkLayout);
    "speedTip": "Arabella Page Tag",
    "tagOpen": "{{Arabellastory}}",
    "tagClose": "",
    "sampleText": ""}


  mwCustomEditButtons[mwCustomEditButtons.length] = {
// Adjust on content changes
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/b/bc/Button_guillemet.png",
document.addEventListener('DOMContentLoaded', checkLayout);
    "speedTip": "Nextprev",
    "tagOpen": "{{nextprev|",
    "tagClose": "}}",
    "sampleText": "{{Arabella|}}|{{Arabella|}}"}


  mwCustomEditButtons[mwCustomEditButtons.length] = {
/* DIALOGUE MALARKEY */
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/1/16/Button_fairuse.png",
    "speedTip": "orcacle",
    "tagOpen": "{{oracle|",
    "tagClose": "}}",
    "sampleText": ""}
    mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://localhost/mediawiki/images/a/a9/Fender_button.png",
    "speedTip": "guitar",
    "tagOpen": "{{g|",
    "tagClose": "}}",
    "sampleText": ""}


    mwCustomEditButtons[mwCustomEditButtons.length] = {
document.addEventListener("DOMContentLoaded", function() {
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/3/3f/Button_attendre.png",
    document.querySelectorAll('.dialogue').forEach(dialogue => {
    "speedTip": "guitar",
        const character = dialogue.querySelector('.character');
    "tagOpen": "{{c|Oracle Timeline}} <small>''[http://localhost/mediawiki/index.php?title=Template: _ _ _-_Oracle&action=edit edit template]''</small><br>",
        const text = dialogue.querySelector('.text');
    "tagClose": "",
        const characterWidth = character.offsetWidth;
    "sampleText": ""}
        text.style.marginLeft = `${characterWidth + 30}px`;
    });
}
});

Latest revision as of 17:50, 10 September 2024

var customizeToolbar = function() {

$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
	'sections': {
		'manual': {
			'type': 'toolbar', // Can also be 'booklet'
			'label': 'Manual'
			// or 'labelMsg': 'section-manual-label' for a localized label
		}
	}
} );
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
	'section': 'manual',
	'groups': {
		'tags': {
			'label': 'Tags' // or use labelMsg for a localized label, see above
		}
	}
} );

$('#wpTextbox1').wikiEditor('addToToolbar', {
	section: 'advanced',
	group: 'format',
	tools: {
		"template": {
			label: 'long dash',
			type: 'button',
			icon: 'https://jollycontrarian.com/images/5/55/Dash.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "—",
					post: ""
				}
			}
		}
	}
});
$('#wpTextbox1').wikiEditor('addToToolbar', {
	section: 'advanced',
	group: 'format',
	tools: {
		"template": {
			label: 'scarequotes',
			type: 'button',
			icon: 'https://jollycontrarian.com/images/b/ba/Scare.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "“",
					post: "”"
				}
			}
		}
	}
});	
$('#wpTextbox1').wikiEditor('addToToolbar', {
	section: 'advanced',
	group: 'format',
	tools: {
		"template": {
			label: 'apostrophe',
			type: 'button',
			icon: 'https://jollycontrarian.com/images/5/5b/Apo.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "’",
					post: ""
				}
			}
		}
	}
});

$('#wpTextbox1').wikiEditor('addToToolbar', {
	section: 'advanced',
	group: 'format',
	tools: {
		"template": {
			label: '{{ - }}',
			type: 'button',
			icon: 'https://jollycontrarian.com/images/3/30/Template.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{",
					post: "}}"
				}
			}
		}
	}
});	

$('#wpTextbox1').wikiEditor('addToToolbar', {
	section: 'advanced',
	group: 'format',
	tools: {
		"Substitute": {
			label: 'subst:',
			type: 'button',
			icon: 'https://jollycontrarian.com/images/0/03/Sbs.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{subst:",
					post: "}}"
				}
			}
		}
	}
});	

$('#wpTextbox1').wikiEditor('addToToolbar', {
	section: 'advanced',
	group: 'format',
	tools: {
		"redirect": {
			label: '==>',
			type: 'button',
			icon: 'https://jollycontrarian.com/images/9/91/Redirect.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "#redirect[[",
					post: "]]"
				}
			}
		}
	}
});	
	

$('#wpTextbox1').wikiEditor('addToToolbar', {
	section: 'advanced',
	group: 'format',
	tools: {
		"template": {
			label: 'tag',
			type: 'button',
			icon: 'https://jollycontrarian.com/images/7/76/Tag.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{t|",
					post: "}}"
				}
			}
		}
	}
});	

$('#wpTextbox1').wikiEditor('addToToolbar', {
	section: 'advanced',
	group: 'format',
	tools: {
		"Prov": {
			label: 'isdaprov',
			type: 'button',
			icon: 'https://jollycontrarian.com/images/5/50/Isd.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{isdaprov|",
					post: "}}"
				}
			}
		}
	}
});

$('#wpTextbox1').wikiEditor('addToToolbar', {
	section: 'advanced',
	group: 'format',
	tools: {
		"Prov": {
			label: 'euaprov',
			type: 'button',
			icon: 'https://jollycontrarian.com/images/5/50/eua.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{euaprov|",
					post: "}}"
				}
			}
		}
	}
});	
$('#wpTextbox1').wikiEditor('addToToolbar', {
	section: 'advanced',
	group: 'format',
	tools: {
		"ietaprov": {
			label: 'ietaprov',
			type: 'button',
			icon: 'https://jollycontrarian.com/images/e/e9/Gms.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{ietaprov|",
					post: "}}"
				}
			}
		}
	}
});	

$('#wpTextbox1').wikiEditor('addToToolbar', {
	section: 'advanced',
	group: 'format',
	tools: {
		"gmraprov": {
			label: '{{{1}}}|',
			type: 'button',
			icon: 'https://jollycontrarian.com/images/4/49/blank.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{{{{1}}}|",
					post: "}}"
				}
			}
		}
	}
});	

$('#wpTextbox1').wikiEditor('addToToolbar', {
	section: 'advanced',
	group: 'format',
	tools: {
		"Equity Derivs": {
			label: 'eqderivprov',
			type: 'button',
			icon: 'https://jollycontrarian.com/images/c/c3/Eqd.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{eqderivprov|",
					post: "}}"
				}
			}
		}
	}
});	


$('#wpTextbox1').wikiEditor('addToToolbar', {
	section: 'advanced',
	group: 'format',
	tools: {
		"template": {
			label: 'vmcsaprov',
			type: 'button',
			icon: 'https://jollycontrarian.com/images/3/37/Csa.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{vmcsaprov|",
					post: "}}"
				}
			}
		}
	}
});

$('#wpTextbox1').wikiEditor('addToToolbar', {
	section: 'advanced',
	group: 'format',
	tools: {
		"template": {
			label: 'hotlink',
			type: 'button',
			icon: 'https://jollycontrarian.com/images/3/37/Csa.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{pjchotlink|}}<li>{{pjchotlink|}}<li>{{pjchotlink|}}<li>{{pjchotlink|}}<li>{{pjchotlink|}}<li>",
					post: "{{pjchotlink|}}"
				}
			}
		}
	}
});

};

if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -1 ) {
	mw.loader.using( 'user.options' ).then( function () {
		if ( mw.user.options.get( 'usebetatoolbar' ) == 1 ) {
			$.when(
				mw.loader.using( 'ext.wikiEditor' ), $.ready
			).then( customizeToolbar );
		}
	} );
}


// Add the customizations to LiquidThreads' edit toolbar, if available
mw.hook( 'ext.lqt.textareaCreated' ).add( customizeToolbar );

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

// JavaScript to dynamically adjust table layout
function adjustTableLayout() {
    var staticTable = document.getElementById('static-table');
    var adaptiveTable = document.getElementById('adaptive-table');

    if (!staticTable || !adaptiveTable) return;

    // Get the bounding rectangles of the tables
    var staticRect = staticTable.getBoundingClientRect();
    var adaptiveRect = adaptiveTable.getBoundingClientRect();

    // Check if the adaptive table is below the static table
    if (adaptiveRect.top >= staticRect.bottom) {
        adaptiveTable.classList.add('stacked');
    } else {
        adaptiveTable.classList.remove('stacked');
    }
}

// Function to request a reflow and check layout
function checkLayout() {
    requestAnimationFrame(function() {
        adjustTableLayout();
    });
}

// Initial adjustment
checkLayout();

// Adjust on window resize
window.addEventListener('resize', checkLayout);

// Adjust on content changes
document.addEventListener('DOMContentLoaded', checkLayout);

/* DIALOGUE MALARKEY */

document.addEventListener("DOMContentLoaded", function() {
    document.querySelectorAll('.dialogue').forEach(dialogue => {
        const character = dialogue.querySelector('.character');
        const text = dialogue.querySelector('.text');
        const characterWidth = character.offsetWidth;
        text.style.marginLeft = `${characterWidth + 30}px`;
    });
});