MediaWiki:Common.js : Différence entre versions

De Canard Wiki
Sauter à la navigation Sauter à la recherche
Ligne 1 : Ligne 1 :
 +
 +
MediaWiki:Common.js
 +
 
var customizeToolbar = function () {
 
var customizeToolbar = function () {
 
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
 
$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
section: 'advanced',
+
section: 'advanced',
group: 'format',
+
group: 'format',
tools: {
+
tools: {
"youtube": {
+
"youtube": {
label: 'youtube',
+
label: 'youtube',
type: 'button',
+
type: 'button',
icon: 'https://canards-fantasy.fr/mediawiki/resources/assets/youtube.png',
+
icon: 'https://canards-fantasy.fr/mediawiki/resources/assets/youtube.png',
action: {
+
action: {
type: 'encapsulate',
+
type: 'encapsulate',
options: {
+
options: {
pre: "<youtube>",
+
pre: "<youtube>",
post: "</youtube>"
+
post: "</youtube>"
 +
}
 
}
 
}
}
+
},
},
+
"pageLink": {
                "pageLink": {
+
label: 'Lien vers une page',
label: 'Lien vers une page',
+
type: 'button',
type: 'button',
+
icon: 'https://canards-fantasy.fr/mediawiki/resources/assets/pageLink.jpg',
icon: 'https://canards-fantasy.fr/mediawiki/resources/assets/pageLink.jpg',
+
action: {
action: {
+
type: 'encapsulate',
type: 'encapsulate',
+
options: {
options: {
+
pre: "[[Titre de la page|Texte du lien]]",
pre: "[[Titre de la page|Texte du lien]]",
+
post: ""
post: ""
+
}
 +
}
 +
},
 +
"alertBlock": {
 +
label: 'Bloc d\'alert',
 +
type: 'button',
 +
icon: 'https://canards-fantasy.fr/mediawiki/resources/assets/alertblock.png',
 +
action: {
 +
type: 'encapsulate',
 +
options: {
 +
pre: "<div class='alertBlock'>",
 +
post: "</div>"
 +
}
 
}
 
}
}
+
},
},
+
"infoBlock": {
                "alertBlock": {
+
label: 'Bloc d\'info',
label: 'Bloc d\'alert',
+
type: 'button',
type: 'button',
+
icon: 'https://canards-fantasy.fr/mediawiki/resources/assets/info.png',
icon: 'https://canards-fantasy.fr/mediawiki/resources/assets/alertblock.png',
+
action: {
action: {
+
type: 'encapsulate',
type: 'encapsulate',
+
options: {
options: {
+
pre: "<div class='alertInfo'>",
pre: "<div class='alertBlock'>",
+
post: "</div>"
post: "</div>"
+
}
 
}
 
}
}
+
},
},
+
"successBlock": {
                "infoBlock": {
+
label: 'Bloc de succès (vert)',
label: 'Bloc d\'info',
+
type: 'button',
type: 'button',
+
icon: 'https://canards-fantasy.fr/mediawiki/resources/assets/success.png',
icon: 'https://canards-fantasy.fr/mediawiki/resources/assets/info.png',
+
action: {
action: {
+
type: 'encapsulate',
type: 'encapsulate',
+
options: {
options: {
+
pre: "<div class='alertSuccess'>",
pre: "<div class='alertInfo'>",
+
post: "</div>"
post: "</div>"
+
}
 
}
 
}
}
+
},
},
+
"spoiler": {
                "successBlock": {
+
label: 'Spoiler',
label: 'Bloc de succès (vert)',
+
type: 'button',
type: 'button',
+
icon: 'https://canards-fantasy.fr/mediawiki/resources/assets/spoiler.jpg',
icon: 'https://canards-fantasy.fr/mediawiki/resources/assets/success.png',
+
action: {
action: {
+
type: 'encapsulate',
type: 'encapsulate',
+
options: {
options: {
+
pre: "<div class='spoiler'><span class='toggler'>Afficher</span><div class='spoiler-content'> ",
pre: "<div class='alertSuccess'>",
+
post: " </div></div>"
post: "</div>"
+
}
 
}
 
}
 
}
 
}
 
}
 
}
}
+
} );
} );
 
 
};
 
};
  
Ligne 75 : Ligne 90 :
 
$.when(
 
$.when(
 
mw.loader.using( 'ext.wikiEditor' ), $.ready
 
mw.loader.using( 'ext.wikiEditor' ), $.ready
).then( customizeToolbar );
+
).then( customizeToolbar );
 
}
 
}
 
} );
 
} );

Version du 26 mars 2018 à 08:12

	
MediaWiki:Common.js

var customizeToolbar = function () {
	$( '#wpTextbox1' ).wikiEditor( 'addToToolbar', {
		section: 'advanced',
		group: 'format',
		tools: {
			"youtube": {
				label: 'youtube',
				type: 'button',
				icon: 'https://canards-fantasy.fr/mediawiki/resources/assets/youtube.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "<youtube>",
						post: "</youtube>"
					}
				}
			},
			"pageLink": {
				label: 'Lien vers une page',
				type: 'button',
				icon: 'https://canards-fantasy.fr/mediawiki/resources/assets/pageLink.jpg',
				action: {
					type: 'encapsulate',
					options: {
						pre: "[[Titre de la page|Texte du lien]]",
						post: ""
					}
				}
			},
			"alertBlock": {
				label: 'Bloc d\'alert',
				type: 'button',
				icon: 'https://canards-fantasy.fr/mediawiki/resources/assets/alertblock.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "<div class='alertBlock'>",
						post: "</div>"
					}
				}
			},
			"infoBlock": {
				label: 'Bloc d\'info',
				type: 'button',
				icon: 'https://canards-fantasy.fr/mediawiki/resources/assets/info.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "<div class='alertInfo'>",
						post: "</div>"
					}
				}
			},
			"successBlock": {
				label: 'Bloc de succès (vert)',
				type: 'button',
				icon: 'https://canards-fantasy.fr/mediawiki/resources/assets/success.png',
				action: {
					type: 'encapsulate',
					options: {
						pre: "<div class='alertSuccess'>",
						post: "</div>"
					}
				}
			},
			"spoiler": {
				label: 'Spoiler',
				type: 'button',
				icon: 'https://canards-fantasy.fr/mediawiki/resources/assets/spoiler.jpg',
				action: {
					type: 'encapsulate',
					options: {
						pre: "<div class='spoiler'><span class='toggler'>Afficher</span><div class='spoiler-content'> ",
						post: " </div></div>"
					}
				}
			}
		}
	} );
};

/* 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 );
		}
	} );
}

$(document).on("click",".toggler",function(e){
	$(e.target).parents(".spoiler").children(".spoiler-content").toggle();
	$(e.target).text() === "Afficher" ? $(e.target).text("Cacher") : $(e.target).text("Afficher");
});