This site requires Javascript to run properly. Javascript is currently Disabled in your browser.

To learn how to enable Javascript, click here.

MediaWiki: Common.js

From The Shoulders of Giants
Jump to: navigation, search
(13 intermediate revisions by the same user not shown)
Line 113: Line 113:
 
   });
 
   });
 
});
 
});
 +
 +
/* Customize WikiEditor */
 +
var customizeToolbar = function () {
 +
  $('#wpTextbox1').wikiEditor('addToToolbar', {
 +
section: 'main',
 +
group: 'format',
 +
tools: {
 +
"strikethrough": {
 +
label: 'Strike',
 +
type: 'button',
 +
icon: '/images/ui/WikiEditor/strikethrough.png',
 +
action: {
 +
type: 'encapsulate',
 +
options: {
 +
pre: "<s>",
 +
post: "</s>"
 +
}
 +
}
 +
}
 +
}
 +
});
 +
 +
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
 +
section: 'main',
 +
group: 'format',
 +
tools: {
 +
"hline": {
 +
label: 'Horizontal line',
 +
type: 'button',
 +
icon: '/images/ui/WikiEditor/section.png',
 +
action: {
 +
type: 'encapsulate',
 +
options: {
 +
pre: "----",
 +
ownline: true
 +
}
 +
}
 +
}
 +
}
 +
} );
 +
 +
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
 +
section: 'main',
 +
group: 'format',
 +
tools: {
 +
"comment": {
 +
label: 'Comment',
 +
type: 'button',
 +
icon: '/images/ui/WikiEditor/comment.png',
 +
action: {
 +
type: 'encapsulate',
 +
options: {
 +
pre: "<!-- ",
 +
post: " -->"
 +
}
 +
}
 +
}
 +
}
 +
} );
 +
 +
$( '#wpTextbox1' ).wikiEditor( 'removeFromToolbar', {
 +
'section': 'main',
 +
'group': 'insert',
 +
'tool': 'reference'
 +
});
 +
 +
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
 +
section: 'main',
 +
group: 'insert',
 +
tools: {
 +
"comment": {
 +
label: 'Reference',
 +
type: 'button',
 +
icon: '/images/ui/WikiEditor/reference.png',
 +
action: {
 +
type: 'encapsulate',
 +
options: {
 +
pre: "[[CiteRef::",
 +
periMsg: "Reference ID",
 +
post: "]]"
 +
}
 +
}
 +
}
 +
}
 +
} );
 +
 +
       
 +
};
 +
 +
/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */
 +
if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -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 );
 +
}
 +
} );
 +
}

Revision as of 20:53, June 30, 2020

$.ajaxSetup({ cache: false });	

function getQueryVariable(variable) {
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i=0;i<vars.length;i++) {
       var pair = vars[i].split("=");
       if(pair[0] == variable){return pair[1];}
    }
    return(false);
}

mw.loader.implement( 'ConfigMenus', [ '/w/index.php?title=MediaWiki:Config_Menus.js&action=raw&ctype=text/javascript' ] );
mw.loader.implement( 'CookieNotice', [ '/w/index.php?title=MediaWiki:Cookie_Notice.js&action=raw&ctype=text/javascript' ] );
mw.loader.implement( 'ChatLauncher', [ '/w/index.php?title=MediaWiki:Chat_Launcher.js&action=raw&ctype=text/javascript' ] );
mw.loader.implement( 'ResponsiveTabs', [ '/w/index.php?title=MediaWiki:Responsive_Tabs.js&action=raw&ctype=text/javascript' ] );
mw.loader.implement( 'FormElements', [ '/w/index.php?title=MediaWiki:Form_Elements.js&action=raw&ctype=text/javascript' ] );
mw.loader.implement( 'Countries', [ '/w/index.php?title=MediaWiki:Countries.js&action=raw&ctype=text/javascript' ] );
mw.loader.implement( 'AdminSponsors', [ '/w/index.php?title=MediaWiki:Admin_Sponsors.js&action=raw&ctype=text/javascript' ] );
mw.loader.implement( 'PatronsOnly', [ '/w/index.php?title=MediaWiki:Patrons_Only.js&action=raw&ctype=text/javascript' ] );
mw.loader.implement( 'JoinTSoG', [ '/w/index.php?title=MediaWiki:Join_TSoG.js&action=raw&ctype=text/javascript' ] );
mw.loader.implement( 'LoadDashboard', [ '/w/index.php?title=MediaWiki:Load_Dashboard.js&action=raw&ctype=text/javascript' ] );
mw.loader.implement( 'ProofOfID', [ '/w/index.php?title=MediaWiki:Proof_of_ID.js&action=raw&ctype=text/javascript' ] );
mw.loader.implement( 'EmbedSponsorshipInquiryForm', [ '/w/index.php?title=MediaWiki:Embed_Sponsorship_Inquiry_Form.js&action=raw&ctype=text/javascript' ] );
mw.loader.implement( 'AdminUser', [ '/w/index.php?title=MediaWiki:Admin_User.js&action=raw&ctype=text/javascript' ] );
mw.loader.implement( 'AdminPatronFiles', [ '/w/index.php?title=MediaWiki:Admin_Patron_Files.js&action=raw&ctype=text/javascript' ] );
mw.loader.implement( 'HexGrid', [ '/w/index.php?title=MediaWiki:Hex_Grid.js&action=raw&ctype=text/javascript' ] );
mw.loader.implement( 'Gantt', [ '/w/index.php?title=MediaWiki:Gantt.js&action=raw&ctype=text/javascript' ] );

mw.loader.load( 'https://www.tsogiants.org/scripts/dhtmlx-gantt/skins/custom.css', 'text/css' );
mw.loader.implement( 'DhtmlxGantt', [ 'https://www.tsogiants.org/scripts/dhtmlx-gantt/dhtmlxgantt.js?v=7.0.5' ] );
mw.loader.using('DhtmlxGantt', function() {
   mw.loader.using('Gantt', function() {
      loadGantt();
   });
});

mw.loader.load( 'https://cdn.jsdelivr.net/npm/sortablejs@latest/Sortable.min.js' );

mw.loader.using('ConfigMenus', function() {
   configMenus();
});

mw.loader.using('CookieNotice', function() {
   siteNotice();
});

mw.loader.using('ChatLauncher', function() {
   createChat();
});

mw.loader.using('ResponsiveTabs', function() {
   $('.nav-tabs').responsiveTabs();
});

var embed = document.getElementById("hex-grid-embed");
if(embed) {
   mw.loader.using('HexGrid', function() {
      loadHexGrid(embed);
   });
}

mw.loader.using('FormElements', function() {
   mw.loader.using('Countries', function() {
      if ( mw.config.get( 'wgPageName' ) === 'Join_TSoG' ) {
         mw.loader.using('JoinTSoG', function() {
            loadJoinTSoG();
         });         
      }

      mw.loader.using('LoadDashboard', function() {
         if ( mw.config.get( 'wgPageName' ) === 'Dashboard' ) {
            loadDashboard();
         } else {
            var dashboard = loadDashboardMin();
            dashboard.then(function(result) {

               if ( mw.config.get( 'wgPageName' ) === 'Proof_of_Identity' ) {
                  mw.loader.using('ProofOfID', function() {
                     loadProofOfIdentity(result);
                  });
               }

               if ( mw.config.get( 'wgPageName' ) === 'Corporate_Sponsorship' ) {
                  mw.loader.using('EmbedSponsorshipInquiryForm', function() {
                     embedSponsorshipInquiry(result);
                  });
               }

               if ( mw.config.get( 'wgPageName' ) === 'Admin:User' ) {
                  mw.loader.using('AdminUser', function() {
                     loadAdminUser();
                  });
               }

               if ( mw.config.get( 'wgPageName' ) === 'Admin:Patron_Files' ) {
                  mw.loader.using('AdminPatronFiles', function() {
                     loadAdminPatronFiles();
                  });
               }

               mw.loader.using('AdminSponsors', function() {
                  embedSponsors();
                  adminSponsors();
               });

               mw.loader.using('PatronsOnly', function() {
                  patronsOnly();
               });
            }, function(err) {});
         }
      });
   });
});

/* Customize WikiEditor */
var customizeToolbar = function () {
	   $('#wpTextbox1').wikiEditor('addToToolbar', {
		section: 'main',
		group: 'format',
		tools: {
			"strikethrough": {
				label: 'Strike',
				type: 'button',
				icon: '/images/ui/WikiEditor/strikethrough.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "<s>",
						post: "</s>"
					}
				}
			}
		}
	});

	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		section: 'main',
		group: 'format',
		tools: {
			"hline": {
				label: 'Horizontal line',
				type: 'button',
				icon: '/images/ui/WikiEditor/section.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "----",
						ownline: true
					}
				}
			}
		}
	} );

	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		section: 'main',
		group: 'format',
		tools: {
			"comment": {
				label: 'Comment',
				type: 'button',
				icon: '/images/ui/WikiEditor/comment.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "<!-- ",
						post: " -->"
					}
				}
			}
		}
	} );

	$( '#wpTextbox1' ).wikiEditor( 'removeFromToolbar', {
		'section': 'main',
		'group': 'insert',
		'tool': 'reference'
	});

	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		section: 'main',
		group: 'insert',
		tools: {
			"comment": {
				label: 'Reference',
				type: 'button',
				icon: '/images/ui/WikiEditor/reference.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "[[CiteRef::",
						periMsg: "Reference ID",
						post: "]]"
					}
				}
			}
		}
	} );
	
        
};

/* Check if view is in edit mode and that the required modules are available. Then, customize the toolbar … */
if ( [ 'edit', 'submit' ].indexOf( mw.config.get( 'wgAction' ) ) !== -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 );
		}
	} );
}