Difference between revisions of "MediaWiki:Common.js"

From Dwaia Wiki
Jump to navigation Jump to search
 
(32 intermediate revisions by the same user not shown)
Line 1: Line 1:
$( function () {
+
overlay        = document.getElementById('overlay');
/**
+
confirmButtons = Array.from(document.getElementsByClassName('button-confirm'));
  * Add custom buttons in the toolbar
+
cancelButtons = Array.from(document.getElementsByClassName('button-cancel'));
*
+
cursors        = Array.from(document.getElementsByClassName('custom-cursor'));
* @source: https://www.mediawiki.org/wiki/Snippets/Custom_buttons_in_the_toolbar
 
* @rev: 2
 
*/
 
  
if ({ edit:1, submit:1 }[mw.config.get('wgAction')]) {
+
goBack        = function(){ history.back() };
mw.loader.using('mediawiki.action.edit', function () {
 
if (mw.toolbar) {
 
  
// Wikitable
+
if(overlay != null){
mw.toolbar.addButton(
+
  hideOverlay = function(){ overlay.style.visibility = 'hidden' };
'//upload.wikimedia.org/wikipedia/commons/0/04/Button_array.png',
+
  cancelButtons.forEach(function(butt){
'Insert a table',
+
    butt.addEventListener('click', goBack);
'{| class="wikitable"\n|-\n',
+
  });
'\n|}',
+
  confirmButtons.forEach(function(butt){
'! header 1\n! header 2\n! header 3\n|-\n| row 1, cell 1\n| row 1, cell 2\n| row 1, cell 3\n|-\n| row 2, cell 1\n| row 2, cell 2\n| row 2, cell 3',
+
    butt.addEventListener('click', hideOverlay );
'mw-editbutton-wikitable'
+
  });
);
+
}
 +
 
 +
tools = document.getElementById('p-tb').children[1].children[0];
 +
 
 +
sideLinks = [
 +
  {'name':'Templates',
 +
  'url' :'https://dwaia.site/wiki/Category:Templates'},
 +
  {'name':'Help expand the lore!',
 +
  'url' :'https://dwaia.site/wiki/Help_expand_the_lore!'}
 +
]
 +
 
 +
sideLinks.forEach(function(link){
 +
  var li = document.createElement('li');
 +
  tools.appendChild(li);
 +
  var a = document.createElement('a');
 +
  li.appendChild(a);
 +
  a.innerText = link.name;
 +
  a.href = link.url;
 +
})
  
// Redirect
+
if(cursors.length > 0){
mw.toolbar.addButton(
+
  document.body.style.cursor = 'none';
'//upload.wikimedia.org/wikipedia/en/c/c8/Button_redirect.png',
+
  cursors.forEach(function(cur){
'Redirect',
+
    cur.style.position = 'fixed';
'#REDIRECT [[',
+
    cur.style.pointerEvents = 'none';
']]',
+
    cur.style.zIndex = '100';
'Insert text',
+
  });
'mw-editbutton-redirect'
+
  document.body.onmousemove = function(event){
);
+
    cursors.forEach(function(cur){
}
+
      cur.style.left = event.clientX-cur.clientWidth/2+'px';
});
+
      cur.style.top  = event.clientY-cur.clientHeight/2+'px';
}
+
    });
} );
+
  };
 +
};
  
 +
title = document.getElementById('firstHeading');
  
window.onload = function(){
+
if(title.innerText == "Main Page"){
  overlay = document.getElementById("overlay");
+
   subtitle = document.getElementsByClassName("MainpageHeading")[0];
   buttonConfirm = document.getElementById("button-confirm");
+
   title.innerHTML = subtitle.innerHTML;
   buttonCancel  = document.getElementById("button-cancel");
+
   subtitle.outerHTML = "";
   if(overlay != null){
+
};
    if(buttonCancel != null){
 
      buttonCancel.addEventListener("click", (e => history.back()));
 
    }
 
    if(buttonConfirm != null){
 
      buttonConfirm.addEventListener("click", (e => overlay.style.visibility = "hidden") );
 
    }
 
  }
 
}
 

Latest revision as of 15:42, 13 August 2020

overlay        = document.getElementById('overlay');
confirmButtons = Array.from(document.getElementsByClassName('button-confirm'));
cancelButtons  = Array.from(document.getElementsByClassName('button-cancel'));
cursors        = Array.from(document.getElementsByClassName('custom-cursor'));

goBack        = function(){ history.back() };

if(overlay != null){
  hideOverlay = function(){ overlay.style.visibility = 'hidden' };
  cancelButtons.forEach(function(butt){
    butt.addEventListener('click', goBack);
  });
  confirmButtons.forEach(function(butt){
    butt.addEventListener('click', hideOverlay );
  });
}

tools = document.getElementById('p-tb').children[1].children[0];

sideLinks = [
  {'name':'Templates',
   'url' :'https://dwaia.site/wiki/Category:Templates'},
  {'name':'Help expand the lore!',
   'url' :'https://dwaia.site/wiki/Help_expand_the_lore!'}
]

sideLinks.forEach(function(link){
  var li = document.createElement('li');
  tools.appendChild(li);
  var a = document.createElement('a');
  li.appendChild(a);
  a.innerText = link.name;
  a.href = link.url;
})

if(cursors.length > 0){
  document.body.style.cursor = 'none';
  cursors.forEach(function(cur){
    cur.style.position = 'fixed';
    cur.style.pointerEvents = 'none';
    cur.style.zIndex = '100';
  });
  document.body.onmousemove = function(event){
    cursors.forEach(function(cur){
      cur.style.left = event.clientX-cur.clientWidth/2+'px';
      cur.style.top  = event.clientY-cur.clientHeight/2+'px';
    });
  };
};

title = document.getElementById('firstHeading');

if(title.innerText == "Main Page"){
  subtitle = document.getElementsByClassName("MainpageHeading")[0];
  title.innerHTML = subtitle.innerHTML;
  subtitle.outerHTML = "";
};