Jump to content

User:MZMcBride/scotus.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
/**
 * https://en.wikipedia.org/wiki/Wikipedia:SCOTUS helper code
 * @author MZMcBride
 * Warning: This code is really bad and is shamelessly stolen from
 * https://www.mediawiki.org/wiki/Extension:WikiEditor/Toolbar_customization#Default_sections
 */

var infobox = `
{{Infobox SCOTUS case
  |Litigants=
  |ArgueDate=
  |ArgueYear=
  |DecideDate=
  |DecideYear=
  |FullName=
  |USVol=
  |USPage=
  |ParallelCitations=
  |Prior=
  |Subsequent=
  |Holding=
  |Majority=
  |JoinMajority=
  |Concurrence=
  |JoinConcurrence=
  |Concurrence2=
  |JoinConcurrence2=
  |Concurrence/Dissent=
  |JoinConcurrence/Dissent=
  |Dissent=
  |JoinDissent=
  |Dissent2=
  |JoinDissent2=
  |LawsApplied=
}}`;

var customizeToolbar = function() {
        /* Add a little gavel icon to insert "Infobox SCOTUS case" into an article */
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
        'section': 'main',
        'group': 'insert',
        'tools': {
                'smile': {
                        label: 'Insert "Infobox SCOTUS case"', // or use labelMsg for a localized label, see above
                        type: 'button',
                        icon: 'https://upload.wikimedia.org/wikipedia/commons/6/6e/Font_Awesome_5_solid_gavel.svg',
                        action: {
                                type: 'encapsulate',
                                options: {
                                        pre: infobox + '\n' // text to be inserted
                                }
                        }
                }
        }
} );
};

/* Check if we are in edit mode and the required modules are available and then customize the toolbar */
if ( $.inArray( mw.config.get( 'wgAction' ), ['edit', 'submit'] ) !== -1 ) {
        mw.loader.using( 'user.options', function () {
                if ( mw.user.options.get('usebetatoolbar') ) {
                        mw.loader.using( 'ext.wikiEditor', function () {
                                $(document).ready( customizeToolbar );
                        } );
                }
        } );
}