MediaWiki:Common.js: Difference between revisions

From The Jolly Contrarian
Jump to navigation Jump to search
No edit summary
No edit summary
 
(120 intermediate revisions by the same user not shown)
Line 1: Line 1:
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. */
/* Any JavaScript here will be loaded for all users on every page load. */


/* Any JavaScript here will be loaded for all users on every page load. */
// JavaScript to dynamically adjust table layout
/* Good site for buttons: http://commons.wikimedia.org/wiki/Mediawiki_edit_toolbar */
function adjustTableLayout() {
    var staticTable = document.getElementById('static-table');
if (mwCustomEditButtons) {
    var adaptiveTable = document.getElementById('adaptive-table');
 
  mwCustomEditButtons[mwCustomEditButtons.length] = {
    if (!staticTable || !adaptiveTable) return;
    "imageFile": "https://jollycontrarian.com/images/e/e2/Button_Tag.PNG",
 
    "speedTip": "tag (links and categorises)",
    // Get the bounding rectangles of the tables
    "tagOpen": "{{tag|",
    var staticRect = staticTable.getBoundingClientRect();
    "tagClose": "}}",
    var adaptiveRect = adaptiveTable.getBoundingClientRect();
    "sampleText": "text"}
 
    // Check if the adaptive table is below the static table
  mwCustomEditButtons[mwCustomEditButtons.length] = {
    if (adaptiveRect.top >= staticRect.bottom) {
    "imageFile": "https://jollycontrarian.com/images/b/b8/Button_Tg2.PNG",
        adaptiveTable.classList.add('stacked');
    "speedTip": "tag (links and categorises and allows a short name)",
    } else {
    "tagOpen": "{{t2|",
        adaptiveTable.classList.remove('stacked');
    "tagClose": "}}",
    }
    "sampleText": "LongText|Shorttext"}
}
 
  mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://images.wikia.com/central/images/c/c8/Button_redirect.png",
    "speedTip": "Redirect",
    "tagOpen": "#REDIRECT [[",
    "tagClose": "]]",
    "sampleText": "Insert text"};
  mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "https://jollycontrarian.com/images/e/ed/Button_I.PNG",
    "speedTip": "isdaprov",
    "tagOpen": "{{isdaprov|",
    "tagClose": "}}",
    "sampleText": "provision"};
  mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "https://jollycontrarian.com/images/5/56/Button_Ia.PNG",
    "speedTip": "isdaprov",
    "tagOpen": "{{isdaanatomy",
    "tagClose": "}}",
    "sampleText": ""};


  mwCustomEditButtons[mwCustomEditButtons.length] = {
// Function to request a reflow and check layout
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/2/29/Button_double_angle_quotes_with_ellipsis.png",
function checkLayout() {
    "speedTip": "isdaquote",
    requestAnimationFrame(function() {
    "tagOpen": "{{isdaquote|",
        adjustTableLayout();
    "tagClose": "|SECTION|2002}}",
    });
    "sampleText": "Provision"};
}
  mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "https://jollycontrarian.com/images/5/55/Button_GTMA.PNG",
    "speedTip": "GTMAclause",
    "tagOpen": "{{GTMAclause|",
    "tagClose": "}}",
    "sampleText": "clause no"};
  mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "https://jollycontrarian.com/images/a/a7/Button_G.PNG",
    "speedTip": "gtmaaprov",
    "tagOpen": "{{gtmaprov|",
    "tagClose": "}}",
    "sampleText": "provision"};
  mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/1/18/Button_quotes_2.png",
    "speedTip": "gtmaquote",
    "tagOpen": "{{gtmaquote|",
    "tagClose": "}}",
    "sampleText": "provision"};


  mwCustomEditButtons[mwCustomEditButtons.length] = {
// Initial adjustment
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/9/94/Vector_toolbar_insert_new_line_button.png",
checkLayout();
    "speedTip": "linebreak",
    "tagOpen": "<br",
    "tagClose": ">",
    "sampleText": ""};
  mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "https://jollycontrarian.com/images/b/ba/Clausebutton.png",
    "speedTip": "clause",
    "tagOpen": "{{clause|",
    "tagClose": "}}",
    "sampleText": "SHORTNAME|AGREEMENT|EDITION|CLAUSE"};
  mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "https://jollycontrarian.com/images/3/3e/Efet_Button.PNG",
    "speedTip": "EFETprov",
    "tagOpen": "{{efetprov|",
    "tagClose": "}}",
    "sampleText": "text"};


  mwCustomEditButtons[mwCustomEditButtons.length] = {
// Adjust on window resize
    "imageFile": "https://jollycontrarian.com/images/d/d6/Button_ccp.PNG",
window.addEventListener('resize', checkLayout);
    "speedTip": "ccp",
    "tagOpen": "{{ccp|",
    "tagClose": "}}",
    "sampleText": "text"};


  mwCustomEditButtons[mwCustomEditButtons.length] = {
// Adjust on content changes
    "imageFile": "https://jollycontrarian.com/images/c/cd/Button_cdea.PNG",
document.addEventListener('DOMContentLoaded', checkLayout);
    "speedTip": "cassprov",
    "tagOpen": "{{cassprov|",
    "tagClose": "}}",
    "sampleText": "text"};


  mwCustomEditButtons[mwCustomEditButtons.length] = {
/* DIALOGUE MALARKEY */
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/5/50/Vector_toolbar_italic_C_button.png",
    "speedTip": "csaprov",
    "tagOpen": "{{csaprov|",
    "tagClose": "}}",
    "sampleText": "text"};
  mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/7/74/Button_API_%C9%9B.png",
    "speedTip": "eqderivprov",
    "tagOpen": "{{eqderivprov|",
    "tagClose": "}}",
    "sampleText": "text"};
  mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/9/94/Subst-button-bg.png",
    "speedTip": "subst",
    "tagOpen": "{{subst:",
    "tagClose": "}}",
    "sampleText": "text"};
  mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/0/01/Button_enum.gif",
    "speedTip": "TOC",
    "tagOpen": "{{YEAR AGREEMENT Section NUMBER TOC}}",
    "tagClose": "",
    "sampleText": ""};
  mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/1/17/Button_small_2.png",
    "speedTip": "FCA Rulebook term",
    "tagOpen": "{{fcaprov|",
    "tagClose": "}}",
    "sampleText": ""};
 
  mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/a/a4/Vector_toolbar_bold_G_button.png",
    "speedTip": "GMSLAprov",
    "tagOpen": "{{gmslaprov|",
    "tagClose": "}}",
    "sampleText": ""};
 
mwCustomEditButtons[mwCustomEditButtons.length] = {
    "imageFile": "http://upload.wikimedia.org/wikipedia/commons/7/77/Button_cyrillic_capital_fita.png",
    "speedTip": "Oracle",
    "tagOpen": "{{oracle|",
    "tagClose": "}}",
    "sampleText": ""};


  }
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`;
    });
});

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`;
    });
});