MediaWiki:Gadget-TemplateScript.js: Difference between revisions

MediaWiki interface page
No edit summary
No edit summary
 
(18 intermediate revisions by the same user not shown)
Line 5: Line 5:
  */
  */
// <nowiki>
// <nowiki>
mw.config.set('userjs-templatescript', { regexEditor: false });
// on page load we want to run this:
$.ajax('//tools-static.wmflabs.org/meta/scripts/pathoschild.templatescript.js', { dataType:'script', cache:true }).then(function() {
// ------------------------------------------------------------
var containers = document.getElementsByClassName("ts-inner");
// check if we have anything set in session
var sessionToggleWidth = sessionStorage.getItem("setToggleWidth");
// if we do have session width then we want to apply it to all containers
if(sessionToggleWidth) {
  Object.keys(containers).forEach(function (key) {
      containers[key].style.maxWidth = sessionToggleWidth;
});
}
mw.config.set('userjs-templatescriptthe', { regexEditor: false });
$.ajax('//themidnight.wiki/images/8/8d/Templatescript.js', { dataType:'script', cache:true }).then(function() {
pathoschild.TemplateScript.add({
pathoschild.TemplateScript.add({
name:'Toggle width',
name:'Toggle width',
forActions: '*',
forActions: '*',
script: function myFunction() {
script: function myFunction() {
  var x = document.getElementsByClassName("ts-inner");
var toggleWidth = containers[0].style.maxWidth === "none" ? "115em" : "none";
  for (i in x) {
  sessionStorage.setItem("setToggleWidth", toggleWidth);
  if (x[i].style.maxWidth === "none") {
   Object.keys(containers).forEach(function (key) {
    x[i].style.maxWidth = "115em";
      containers[key].style.maxWidth = toggleWidth;  
   } else {
});
    x[i].style.maxWidth = "none";
  }
}
}
}
});
});
});
});
// </nowiki>
// </nowiki>

Latest revision as of 11:16, 27 March 2024

/**
 * TemplateScript adds configurable templates and scripts to the sidebar, and adds an example regex editor.
 * @see https://meta.wikimedia.org/wiki/TemplateScript
 * @update-token [[File:Pathoschild/templatescript.js]]
 */
// <nowiki>
// on page load we want to run this:
// ------------------------------------------------------------
var containers = document.getElementsByClassName("ts-inner");
// check if we have anything set in session
var sessionToggleWidth = sessionStorage.getItem("setToggleWidth");
// if we do have session width then we want to apply it to all containers
if(sessionToggleWidth) {
  Object.keys(containers).forEach(function (key) {
       containers[key].style.maxWidth = sessionToggleWidth; 
});
}
mw.config.set('userjs-templatescriptthe', { regexEditor: false });
$.ajax('//themidnight.wiki/images/8/8d/Templatescript.js', { dataType:'script', cache:true }).then(function() {
pathoschild.TemplateScript.add({
	name:'Toggle width',
	forActions: '*',
	script: function myFunction() {
	var toggleWidth = containers[0].style.maxWidth === "none" ? "115em" : "none";
  sessionStorage.setItem("setToggleWidth", toggleWidth);
  Object.keys(containers).forEach(function (key) {
       containers[key].style.maxWidth = toggleWidth; 
});
}
});
});
// </nowiki>