MediaWiki:Common.js

From Wikicarpedia
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
var customizeToolbar = function () {
/* --------------------------------------------------------------------------- */

$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
	'sections': {
		'WICA': {
			'type': 'toolbar', // Can also be 'booklet'
			'label': 'WICA'
			// or 'labelMsg': 'section-emoticons-label' for a localized label
		}
	}
} );

$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
	'section': 'WICA',
	'groups': {
		'icons': {
			'label': '' // or use labelMsg for a localized label, see above
		}
	}
} );


$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
	'section': 'WICA',
	'group': 'icons',
	'tools': {
		'ref': {
			label: '<ref>', 
			type: 'button',
			icon: '/images/7/77/Toolbar_ref.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "<ref>",
                                        peri: "",
                                        post: "</ref>"
				}
			}
		}
	}
} );

$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
	'section': 'WICA',
	'group': 'icons',
	'tools': {
		'smile': {
			label: 'Padlock', 
			type: 'button',
			icon: '/images/thumb/7/7b/Icon_Locked_Red.png/16px-Icon_Locked_Red.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{IconPadlock}}" // text to be inserted
				}
			}
		}
	}
} );

$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
	'section': 'WICA',
	'group': 'icons',
	'tools': {
		'houserule': {
			label: 'House rule', 
			type: 'button',
			icon: '/images/thumb/f/fb/Icon_House_Black.png/16px-Icon_House_Black.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{IconHouse}}" // text to be inserted
				}
			}
		}
	}
} );

$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
	'section': 'WICA',
	'group': 'icons',
	'tools': {
		'arrow': {
			label: 'arrow', 
			type: 'button',
			icon: '/images/thumb/6/6d/Icon_Double_Arrow_Black.png/16px-Icon_Double_Arrow_Black.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{IconArrow}}" // text to be inserted
				}
			}
		}
	}
} );

$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
	'section': 'WICA',
	'group': 'icons',
	'tools': {
		'book': {
			label: 'book', 
			type: 'button',
			icon: '/images/thumb/e/ea/Icon_Open_Book.png/16px-Icon_Open_Book.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{IconBook}}" // text to be inserted
				}
			}
		}
	}
} );

$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
	'section': 'WICA',
	'group': 'icons',
	'tools': {
		'world': {
			label: 'World', 
			type: 'button',
			icon: '/images/thumb/7/73/Icon_World_Black.png/16px-Icon_World_Black.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{IconWorld}}" // text to be inserted
				}
			}
		}
	}
} );

$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
	'section': 'WICA',
	'group': 'icons',
	'tools': {
		'world': {
			label: 'Community Rule', 
			type: 'button',
			icon: '/thumb.php?f=Icon_Community.png&width=16',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{IconCommunity}}" // text to be inserted
				}
			}
		}
	}
} );


$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
	'section': 'WICA',
	'group': 'icons',
	'tools': {
		'yellow': {
			label: 'yellow', 
			type: 'button',
			icon: '/images/2/2d/Toolbar_yellow.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{ColorYellow|",
                                        peri: "",
                                        post: "}}"
				}
			}
		}
	}
} );

$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
	'section': 'WICA',
	'group': 'icons',
	'tools': {
		'red': {
			label: 'red', 
			type: 'button',
			icon: '/images/1/1b/Toolbar_red.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{ColorRed|",
                                        peri: "",
                                        post: "}}"
				}
			}
		}
	}
} );

$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
	'section': 'WICA',
	'group': 'icons',
	'tools': {
		'blue': {
			label: 'blue', 
			type: 'button',
			icon: '/images/e/e2/Toolbar_blue.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{ColorBlue|",
                                        peri: "",
                                        post: "}}"
				}
			}
		}
	}
} );

$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
	'section': 'WICA',
	'group': 'icons',
	'tools': {
		'black': {
			label: 'black', 
			type: 'button',
			icon: '/images/8/8b/Toolbar_black.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{ColorBlack|",
                                        peri: "",
                                        post: "}}"
				}
			}
		}
	}
} );

$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
	'section': 'WICA',
	'group': 'icons',
	'tools': {
		'green': {
			label: 'green', 
			type: 'button',
			icon: '/images/5/55/Toolbar_green.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{ColorGreen|",
                                        peri: "",
                                        post: "}}"
				}
			}
		}
	}
} );

$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
	'section': 'WICA',
	'group': 'icons',
	'tools': {
		'gray': {
			label: 'gray', 
			type: 'button',
			icon: '/images/4/41/Toolbar_grey.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{ColorGray|",
                                        peri: "",
                                        post: "}}"
				}
			}
		}
	}
} );

$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
	'section': 'WICA',
	'group': 'icons',
	'tools': {
		'white': {
			label: 'white', 
			type: 'button',
			icon: '/images/7/7a/Toolbar_white.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{ColorWhite|",
                                        peri: "",
                                        post: "}}"
				}
			}
		}
	}
} );

$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
	'section': 'WICA',
	'group': 'icons',
	'tools': {
		'pink': {
			label: 'pink', 
			type: 'button',
			icon: '/images/1/15/Toolbar_pink.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{ColorPink|",
                                        peri: "",
                                        post: "}}"
				}
			}
		}
	}
} );

$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
	'section': 'WICA',
	'group': 'icons',
	'tools': {
		'calendar': {
			label: 'calendar', 
			type: 'button',
			icon: '/images/9/9e/Toolbar_calendar.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{Year|",
                                        peri: "",
                                        post: "}}"
				}
			}
		}
	}
} );


$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
	'section': 'WICA',
	'group': 'icons',
	'tools': {
		'footer': {
			label: 'footer', 
			type: 'button',
			icon: '/images/f/f7/Toolbar_footer.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{FootnoteIconPara}}"
				}
			}
		}
	}
} );

$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
	'section': 'WICA',
	'group': 'icons',
	'tools': {
		'disclaimer': {
			label: 'encapsulate', 
			type: 'button',
			icon: '/images/6/6c/Toolbar_disclaimer.png',
			action: {
				type: 'encapsulate',
				options: {
					pre: "{{Disclaimer|",
                                        peri: "",
                                        post: "}}"
				}
			}
		}
	}
} );



/* --------------------------------------------------------------------------- */

};


/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */
if ( $.inArray( mw.config.get( 'wgAction' ), [ 'edit', 'submit' ] ) !== -1 ) {
	mw.loader.using( 'user.options' ).then( function () {
		// This can be the string "0" if the user disabled the preference ([[phab:T54542#555387]])
		if ( mw.user.options.get( 'usebetatoolbar' ) == 1 ) {
			$.when(
				mw.loader.using( 'ext.wikiEditor' ), $.ready
			).then( customizeToolbar );
		}
	} );
}

/* 
==========================================
 @meepledrone - Dynamic text selection 
==========================================
*/


var NO_SELECTOR = 0,
    REFERENCE_PAGE_SELECTOR = 1,
    TILE_REFERENCE_SELECTOR = 2,
    EXPANSION_LIST_SELECTOR = 3,
    LAND_SURVEYORS_SIMULATOR = 4,
    REFERENCE_PAGE_SELECTOR_AND_BANNER = 5;
 
var arrReferencePages = 
[
  {
    pageName: "Assembled_Game_Reference",
    pageType: REFERENCE_PAGE_SELECTOR_AND_BANNER ,
  },

  { 
    pageName: "Carcassonne_Consolidated_Clarifications",
    pageType: REFERENCE_PAGE_SELECTOR_AND_BANNER ,
  },
  { 
    pageName: "Consolidated_Clarifications",
    pageType: REFERENCE_PAGE_SELECTOR_AND_BANNER ,
  },
/*
  { 
    pageName: "Consolidated_Clarifications_(1st_edition)",
    pageType: REFERENCE_PAGE_SELECTOR_AND_BANNER ,
  },
*/
  { 
    pageName: "Carcassonne_Game_Reference",
    pageType: REFERENCE_PAGE_SELECTOR,
  },
  { 
    pageName: "Game_Reference",
    pageType: REFERENCE_PAGE_SELECTOR,
  },
  { 
    pageName: "Game_Reference_(1st_edition)",
    pageType: REFERENCE_PAGE_SELECTOR,
  },
  { 
    pageName: "Winter_Game_Reference",
    pageType: REFERENCE_PAGE_SELECTOR,
  },

  { 
    pageName: "Carcassonne_Order_of_Play",
    pageType: REFERENCE_PAGE_SELECTOR,
  },
  { 
    pageName: "Order_of_Play",
    pageType: REFERENCE_PAGE_SELECTOR,
  },
  { 
    pageName: "Order_of_Play_(1st_edition)",
    pageType: REFERENCE_PAGE_SELECTOR,
  },
  { 
    pageName: "Winter_Order_of_Play",
    pageType: REFERENCE_PAGE_SELECTOR,
  },

  { 
    pageName: "Carcassonne_Scoring_During_the_Game",
    pageType: REFERENCE_PAGE_SELECTOR,
  },
  { 
    pageName: "Scoring_During_the_Game",
    pageType: REFERENCE_PAGE_SELECTOR,
  },
  { 
    pageName: "Scoring_During_the_Game_(1st_edition)",
    pageType: REFERENCE_PAGE_SELECTOR,
  },
  { 
    pageName: "Winter_Scoring_During_the_Game",
    pageType: REFERENCE_PAGE_SELECTOR,
  },

  { 
    pageName: "Carcassonne_Scoring_After_the_Game",
    pageType: REFERENCE_PAGE_SELECTOR,
  },

  { 
    pageName: "Scoring_After_the_Game",
    pageType: REFERENCE_PAGE_SELECTOR,
  },
  { 
    pageName: "Scoring_After_the_Game_(1st_edition)",
    pageType: REFERENCE_PAGE_SELECTOR,
  },
  { 
    pageName: "Winter_Scoring_After_the_Game",
    pageType: REFERENCE_PAGE_SELECTOR,
  },

  { 
    pageName: "Carcassonne_Game_Figures",
    pageType: REFERENCE_PAGE_SELECTOR,
  },
  { 
    pageName: "Game_Figures",
    pageType: REFERENCE_PAGE_SELECTOR,
  },
  { 
    pageName: "Game_Figures_(1st_edition)",
    pageType: REFERENCE_PAGE_SELECTOR,
  },
  { 
    pageName: "Winter_Game_Figures",
    pageType: REFERENCE_PAGE_SELECTOR,
  },

  { 
    pageName: "Carcassonne_Scoring_During_Turn_Sequence",
    pageType: REFERENCE_PAGE_SELECTOR,
  },
  { 
    pageName: "Scoring_During_Turn_Sequence",
    pageType: REFERENCE_PAGE_SELECTOR,
  },
  { 
    pageName: "Scoring_During_Turn_Sequence_(1st_edition)",
    pageType: REFERENCE_PAGE_SELECTOR,
  },
  { 
    pageName: "Winter_Scoring_During_Turn_Sequence",
    pageType: REFERENCE_PAGE_SELECTOR,
  },
  { 
    pageName: "Template:ExpansionSelectorcs",
    pageType: REFERENCE_PAGE_SELECTOR,
  },
  { 
    pageName: "Notes_on_the_Czech_translation",
    pageType: REFERENCE_PAGE_SELECTOR,
  },


  // Tile Reference
  {
    pageName: "Tile_Reference",
    pageType: TILE_REFERENCE_SELECTOR,
  },
  {
    pageName: "Tile_Reference_(1st_edition)",
    pageType: TILE_REFERENCE_SELECTOR,
  },
  {
    pageName: "Tile_Reference_(2nd_edition)",
    pageType: TILE_REFERENCE_SELECTOR,
  },
  {
    pageName: "Tile_Reference_(3rd_edition)",
    pageType: TILE_REFERENCE_SELECTOR,
  },
  {
    pageName: "Winter_Tile_Reference",
    pageType: TILE_REFERENCE_SELECTOR,
  },
  {
    pageName: "Carcassonne_Tile_Reference",
    pageType: TILE_REFERENCE_SELECTOR,
  },

  {
    pageName: "The_Land_Surveyors_Simulator",
    pageType: LAND_SURVEYORS_SIMULATOR,
  },


  // Test pages

  { 
    pageName: "Template:Scoring.*",
    pageType: REFERENCE_PAGE_SELECTOR,
  },

  { 
    pageName: "User_talk:Wolnic",
    pageType: REFERENCE_PAGE_SELECTOR,
  },
  { 
    pageName: "User_talk:Meepledrone",
    pageType: REFERENCE_PAGE_SELECTOR,
  },
  { 
    pageName: "User:Bumsakalaka",
    pageType: REFERENCE_PAGE_SELECTOR,
  },
  { 
    pageName: ".*_(Fan_Expansion)",
    pageType: REFERENCE_PAGE_SELECTOR,
  },

  { 
    pageName: "Talk:Fan_Expansions",
    pageType: REFERENCE_PAGE_SELECTOR,
  },
  { 
    pageName: "Template:ExpansionSelector",
    pageType: REFERENCE_PAGE_SELECTOR,
  },
  { 
    pageName: "User:Bumsakalaka/.*",
    pageType: REFERENCE_PAGE_SELECTOR,
  },

  { 
    pageName: "Notes_on_the_Czech_translation",
    pageType: REFERENCE_PAGE_SELECTOR,
  },

  /* --- */
  { 
    pageName: "Carcassonne_Order_of_Play_for_Discussion",
    pageType: REFERENCE_PAGE_SELECTOR,
  },

  { 
    pageName: "Expansion_List_-_Test",
    pageType: EXPANSION_LIST_SELECTOR,
  },
  { 
    pageName: "Expansion_List_-_Test2",
    pageType: EXPANSION_LIST_SELECTOR,
  },
  { 
    pageName: "User:Murphy013/Expansion_List",
    pageType: EXPANSION_LIST_SELECTOR,
  },
  { 
    pageName: "User:Wolnic",
    pageType: EXPANSION_LIST_SELECTOR,
  },
  { 
    pageName: "Expansion_List_-_Selector",
    pageType: EXPANSION_LIST_SELECTOR,
  },


  { 
    pageName: "Carcassonne_Visual_Turn_Sequence",
    pageType: REFERENCE_PAGE_SELECTOR,
  },
  { 
    pageName: "Template:ScoringRow",
    pageType: REFERENCE_PAGE_SELECTOR,
  },

];


function doSetup()
{
  var strPageName = mw.config.get( 'wgPageName' );
  console.log ( "Displaying page:" + strPageName );

  var nPageType = NO_SELECTOR;

  for ( var iEntry in arrReferencePages )
  {
    var oEntry = arrReferencePages[ iEntry ];

    var strRegExp = oEntry.pageName;
    strRegExp = strRegExp.replace( /\(/g, "\\(" );
    strRegExp = strRegExp.replace( /\)/g, "\\)" );
    strRegExp = "^" + strRegExp + "(/[a-z][a-z])?$";

    var oRegExp = new RegExp( strRegExp );

    var bOk = strPageName.match( oRegExp ); 
    if ( bOk )
    {
      nPageType = oEntry.pageType;
      break;
    }
  }

  switch ( nPageType )
  {
    case NO_SELECTOR:
      {
        mw.loader.load( '/index.php?title=MediaWiki:SectionStyling.js&action=raw&ctype=text/javascript' );
        mw.loader.load( '/index.php?title=MediaWiki:Timeline.css&action=raw&ctype=text/css', 'text/css' );
      }
      break;

    case REFERENCE_PAGE_SELECTOR_AND_BANNER:
      {
        $.when(

          //mw.loader.using( ['jquery.ui.tabs'] ),
          mw.loader.using( [ 'mediawiki.cookie', 'mediawiki.util' ] ),
          mw.loader.load( '/index.php?title=MediaWiki:SectionStyling.js&action=raw&ctype=text/javascript' ),
          mw.loader.load( '/index.php?title=MediaWiki:JQueryUI.js&action=raw&ctype=text/javascript' ),
          mw.loader.load( '/index.php?title=MediaWiki:JQueryUI.css&action=raw&ctype=text/css', 'text/css' ),
          mw.loader.load( '/index.php?title=MediaWiki:ExpansionData.js&action=raw&ctype=text/javascript' ),
          mw.loader.load( '/index.php?title=MediaWiki:ExpansionSelector.css&action=raw&ctype=text/css', 'text/css' ),
          //mw.loader.load( '/index.php?title=MediaWiki:SectionStyling.js&action=raw&ctype=text/javascript' ),
          $.ready
        ).then( function ( ) {

          mw.loader.load( '/index.php?title=MediaWiki:ExpansionSelector.js&action=raw&ctype=text/javascript' );
          // $( document ).ready( doWrapInit );
        } );
      }
      break;

    case REFERENCE_PAGE_SELECTOR:
      {
        $.when(

          //mw.loader.using( ['jquery.ui.tabs'] ),
          mw.loader.using( [ 'mediawiki.cookie', 'mediawiki.util' ] ),
          mw.loader.load( '/index.php?title=MediaWiki:JQueryUI.js&action=raw&ctype=text/javascript' ),
          mw.loader.load( '/index.php?title=MediaWiki:JQueryUI.css&action=raw&ctype=text/css', 'text/css' ),
          mw.loader.load( '/index.php?title=MediaWiki:ExpansionData.js&action=raw&ctype=text/javascript' ),
          mw.loader.load( '/index.php?title=MediaWiki:ExpansionSelector.css&action=raw&ctype=text/css', 'text/css' ),
          mw.loader.load( '/index.php?title=MediaWiki:SectionStyling.js&action=raw&ctype=text/javascript' ),
          $.ready
        ).then( function ( ) {

          mw.loader.load( '/index.php?title=MediaWiki:ExpansionSelector.js&action=raw&ctype=text/javascript' );
          // $( document ).ready( doWrapInit );
        } );
      }
      break;

    case EXPANSION_LIST_SELECTOR:
      {
        $.when(

          //mw.loader.using( ['jquery.ui.tabs'] ),
          mw.loader.using( [ 'mediawiki.cookie', 'mediawiki.util' ] ),
          mw.loader.load( '/index.php?title=MediaWiki:JQueryUI.js&action=raw&ctype=text/javascript' ),
          mw.loader.load( '/index.php?title=MediaWiki:JQueryUI.css&action=raw&ctype=text/css', 'text/css' ),
          mw.loader.load( '/index.php?title=MediaWiki:ExpansionCategoryData.js&action=raw&ctype=text/javascript' ),
          mw.loader.load( '/index.php?title=MediaWiki:ExpansionSelector.css&action=raw&ctype=text/css', 'text/css' ),
          //mw.loader.load( '/index.php?title=MediaWiki:SectionStyling.js&action=raw&ctype=text/javascript' ),
          $.ready
        ).then( function ( ) {

          mw.loader.load( '/index.php?title=MediaWiki:ExpansionCategorySelector.js&action=raw&ctype=text/javascript' );
          // $( document ).ready( doWrapInit );
        } );
      }
      break;

    case TILE_REFERENCE_SELECTOR:
      {
         $.when(

          //mw.loader.using( ['jquery.ui.tabs'] ),
          mw.loader.using( [ 'mediawiki.cookie', 'mediawiki.util' ] ),
          mw.loader.load( '/index.php?title=MediaWiki:JQueryUI.js&action=raw&ctype=text/javascript' ),
          mw.loader.load( '/index.php?title=MediaWiki:JQueryUI.css&action=raw&ctype=text/css', 'text/css' ),
          mw.loader.load( '/index.php?title=MediaWiki:TileData.js&action=raw&ctype=text/javascript' ),
          mw.loader.load( '/index.php?title=MediaWiki:TileInfoMaps.js&action=raw&ctype=text/javascript' ),
          mw.loader.load( '/index.php?title=MediaWiki:TileSelectorUtils.js&action=raw&ctype=text/javascript' ),
          mw.loader.load( '/index.php?title=MediaWiki:TileSelector.css&action=raw&ctype=text/css', 'text/css' ),
          mw.loader.load( '/index.php?title=MediaWiki:ExpansionSelector.css&action=raw&ctype=text/css', 'text/css' ),
          //mw.loader.load( '/index.php?title=MediaWiki:SectionStyling.js&action=raw&ctype=text/javascript' ),
          $.ready
        ).then( function ( ) {

          mw.loader.load( '/index.php?title=MediaWiki:TileSelector.js&action=raw&ctype=text/javascript' );
          // $( document ).ready( doWrapInit );
        } );
      }
      break;

    case LAND_SURVEYORS_SIMULATOR:
      {
        $.when(

          mw.loader.using( [ 'mediawiki.cookie', 'mediawiki.util' ] ),
          //mw.loader.load( '/index.php?title=MediaWiki:SectionStyling.js&action=raw&ctype=text/javascript' ),
          $.ready
        ).then( function ( ) {

          mw.loader.load( '/index.php?title=MediaWiki:LandSurveyorsSimulator.js&action=raw&ctype=text/javascript' );
        } );
      }
      break;
  }
}

doSetup();