Difference between revisions of "MediaWiki:Common.js"

From myViewBoard
Jump to navigation Jump to search
m
m
 
Line 249: Line 249:
 
$('#OChltFilter').click(function(){ FilterList($(this),'health') } );
 
$('#OChltFilter').click(function(){ FilterList($(this),'health') } );
 
$('#OCwksFilter').click(function(){ FilterList($(this),'worksheet') } );
 
$('#OCwksFilter').click(function(){ FilterList($(this),'worksheet') } );
 +
$('#OCrwgFilter').click(function(){ FilterList($(this),'reading') } );
 
$('#OCVinteract').click(function(){ FilterList($(this),'interactive') } );
 
$('#OCVinteract').click(function(){ FilterList($(this),'interactive') } );
 
$('#OCVpresentn').click(function(){ FilterList($(this),'presentation') } );
 
$('#OCVpresentn').click(function(){ FilterList($(this),'presentation') } );

Latest revision as of 15:45, 15 September 2020

/* Any JavaScript here will be loaded for all users on every page load. */

/* For translation */

var _lang = document.documentElement.lang;
var _srvr = mw.config.get('wgServer');
var _page = mw.config.get('wgPageName');
var _titl = mw.config.get('wgTitle');
var _addr = window.location.href;

_titl = _titl.replace(/\s+/g,"_");

var _engl = 'en:' + _titl;
var _eurl = mw.config.get('wgArticlePath').replace('$1', _titl);

var _grmn = 'de:' + _titl;
var _gurl = mw.config.get('wgArticlePath').replace('$1', _grmn);

var _spns = 'es:' + _titl;
var _surl = mw.config.get('wgArticlePath').replace('$1', _spns);

var _tdch = 'tc:' + _titl;
var _turl = mw.config.get('wgArticlePath').replace('$1', _tdch);

var _dtch = 'nl:' + _titl;
var _durl = mw.config.get('wgArticlePath').replace('$1', _dtch);

var _viet = 'vi:' + _titl;
var _vurl = mw.config.get('wgArticlePath').replace('$1', _viet);

var _turk = 'tr:' + _titl;
var _trrl = mw.config.get('wgArticlePath').replace('$1', _turk);

var _japn = 'ja:' + _titl;
var _jurl = mw.config.get('wgArticlePath').replace('$1', _japn);

var _fran = 'fr:' + _titl;
var _furl = mw.config.get('wgArticlePath').replace('$1', _fran);

var _russ = 'ru:' + _titl;
var _rurl = mw.config.get('wgArticlePath').replace('$1', _russ);


function CheckPage(LangCode,LangURL) {
	if ( (_addr.includes(LangCode)) || (_addr.includes("Special:")) || (_addr.includes("MediaWiki:")) || (_addr.includes("action=edit")) ) { console.log('OK ~' + LangCode)} 
	else {window.location.replace(LangURL);}		
}

function CheckIfExists(LangPage,LangCode,LangURL) {

var TCurl = _srvr + '/api.php?action=query&format=json&titles=' + LangPage;
$.getJSON(TCurl, function(data) { console.log(TCurl) });
fetch(TCurl) 
    .then(function(response) { return response.json(); })
    .then(function(data) { 

 var CheckTC = data.query.pages;
     console.log(CheckTC); 
     CheckTC = JSON.stringify(CheckTC);
  if (CheckTC.includes('missing')) { console.log('This page does not exist'); }
else { 
	CheckPage(LangCode,LangURL);
 }
})		
}

var xoxo = _lang;

switch(xoxo) {
case "de": 
	CheckIfExists(_grmn,"de:",_gurl);
	break;

case "es": 
	CheckIfExists(_spns,"es:",_surl);
	break;

case "zh": 
case "zh-Hant": 
case "zh-Hant-TW": 
	CheckIfExists(_tdch,"tc:",_turl);
 	break;

case "nl": 
	CheckIfExists(_dtch,"nl:",_durl)
 	break;

case "vi": 
	CheckIfExists(_viet,"vi:",_vurl)
 	break;

case "tr": 
	CheckIfExists(_turk,"tr:",_trrl)
 	break;

case "ja": 
	CheckIfExists(_japn,"ja:",_jurl)
 	break;

case "fr": 
	CheckIfExists(_fran,"fr:",_furl)
 	break;

case "ru": 
	CheckIfExists(_russ,"ru:",_rurl)
 	break;
	
case "en": 
	if ( /de:|es:|tc:|nl:|vi:|tr:|ja:|fr:|ru:/.test(_page) ) { window.location.replace(_eurl); } 
	else { console.log('nothing to change')} 
	break;
  
default:
	if ( /de:|es:|tc:|nl:|vi:|tr:|ja:|fr:|ru:/.test(_page) ) { window.location.replace(_eurl); }  
	else { console.log('default english')} 
	break;

}



// FOR DEVICE MANAGEMENT

if ( $('#DevMngtFilter').length ) {
hackerList.search('mvbdisplay');

}


// FOR VIDEO-ASSISTED LEARNING

if ( $('#VALrngtFilter').length ) {
hackerList.search('VAL');

}



$(function () {

if ( $('#rod-print-icons').length ) {
 $('#firstHeading').append( $('#rod-print-icons') );
 $('#t-pdfPt a').attr('title','Download one-page PDF');
 $('#t-print a').attr('title','Print this page');
}

}());


$(function () {

if ( $('#rod-original-content').length ) {
$('.mw-wiki-logo').css("background-image", "url('https://wiki.myviewboard.com/images/e/e7/Icon-word-Originals.svg')");
$('.mw-wiki-logo').css("background-size", "150px 150px");
$('.mw-wiki-logo').attr("href","/MyViewBoard_Original_Content");
console.log('logo changed');
}

}());

$(function () {
if ( $('#pt-login').length ) { $('.ForLogOutUsersOnly').css("display", "block"); }
else { $('.ForLogInUsersOnly').css("display", "block"); }
}());

$(function () {
$('.YTthumb').each(function(i, obj) {
var QQQQ = $(this).html();
$(this).html("<img src=https://img.youtube.com/vi/" + QQQQ + "/mqdefault.jpg />");
});
}());


$(function () {
  $('.thumb').find('video').attr('data-lity','true');
  $('.thumb').find('video').css('cursor','pointer');
}());



// FOR ORIGINAL CONTENT

if ( $('#listjs').length ) {

$('.DloadLink').mousedown(function() {

    var DloadFile = $(this).attr("title");
    console.log(DloadFile);
    ga('send', 'event', 'vBoard File', 'Download', DloadFile);

});

}


if ( $('#listjs2').length ) {

$('.DloadLink').mousedown(function() {

    var DloadFile = $(this).attr("title");
    console.log(DloadFile);
    ga('send', 'event', 'vBoard BG', 'Download', DloadFile);

});

}

if ( $('#listjs3').length ) {

$('.DloadLink').mousedown(function() {

    var DloadFile = $(this).attr("title");
    console.log(DloadFile);
    ga('send', 'event', 'vBoard VAL', 'Download', DloadFile);

});

}

$('.image').mousedown(function() {

    var ImageFile = $(this).attr("href");
    console.log(ImageFile);
    ga('send', 'event', 'Image', 'Image viewed', ImageFile);

});


function FilterList(bName,filter) {
$('.zxcv').addClass('zxcv-anim');
hackerList.search(filter);
$('.OC_filter_options').css('background-color','#fff');
bName.css('background-color','#eee');
}

$('#OCallFilter').click(function(){ FilterList($(this),'') });
$('#OCmatFilter').click(function(){ FilterList($(this),'math') });
$('#OCsciFilter').click(function(){ FilterList($(this),'science') });
$('#OCgeoFilter').click(function(){ FilterList($(this),'geography') });
$('#OCorgFilter').click(function(){ FilterList($(this),'organizer') } );
$('#OCgrdFilter').click(function(){ FilterList($(this),'grid') } );
$('#OClinFilter').click(function(){ FilterList($(this),'lines') } );
$('#OCsptFilter').click(function(){ FilterList($(this),'sport') } );
$('#OChdyFilter').click(function(){ FilterList($(this),'holidays') } );
$('#OCiwbFilter').click(function(){ FilterList($(this),'iwb') } );
$('#OCartFilter').click(function(){ FilterList($(this),'art') } );
$('#OChumFilter').click(function(){ FilterList($(this),'humanities') } );
$('#OCmusFilter').click(function(){ FilterList($(this),'music') } );
$('#OChltFilter').click(function(){ FilterList($(this),'health') } );
$('#OCwksFilter').click(function(){ FilterList($(this),'worksheet') } );
$('#OCrwgFilter').click(function(){ FilterList($(this),'reading') } );
$('#OCVinteract').click(function(){ FilterList($(this),'interactive') } );
$('#OCVpresentn').click(function(){ FilterList($(this),'presentation') } );
$('#OCVvideoLng').click(function(){ FilterList($(this),'VAL') } );
$('#OCimgFilter').click(function(){ FilterList($(this),'mediapic') } );
$('#OCvidFilter').click(function(){ FilterList($(this),'mediavid') } );
$('#SearchField').html('<input class="search" placeholder="Search" id="SearchList"/>');

$('#SearchList').on('focus', function() {
$('.zxcv').removeClass('zxcv-anim');
$('.OC_filter_options').css('background-color','#fff');
});

$('#SearchList').on('keyup', function() {
  $('.zxcv').removeClass('zxcv-anim');
  var searchString = $(this).val();
  hackerList.search(searchString);
});

// *** AUTOCOMPLETE FOR DEFAULT SEARCHBOX ***
// document.getElementById('searchform').action = '/index.php';
// document.getElementsByName('search')[0].id = 'searchInput';



$('.LboxTest').click(function(){ LBOX( $(this).find("div") ) });

function LBOX(LBOX) {
lity( LBOX.html() );
}




//START AUTOCOMPLETE

if ( $('#ListOfAllPages').length ) {

var AutoComplete = $('#ListOfAllPages').html();
    AutoComplete = AutoComplete
       .replace(/<li>/g, '<option>')
       .replace(/<\/li>/g, '</option>')
	   .replace(/<ul/g, '<datalist id="" ')
	   .replace(/<\/ul>/g, '</datalist>');
$('#ListOfAllPages').html(AutoComplete);  

var AutoInput = $('.searchbox').html();
    AutoInput = AutoInput
	   .replace(/value/, 'list="datalist" autocomplete="off" ')
$('.searchbox').html(AutoInput);  


var input    = document.querySelector(".searchbox .searchboxInput"), // Selects the input.
    datalist = document.querySelector("datalist"); // Selects the datalist.

input.addEventListener("keyup", function(e) {

    // If input value is longer or equal than 2 chars, adding "users" on ID attribute.
    if (e.target.value.length >= 2) {
        datalist.setAttribute("id", "datalist");
    } else {
        datalist.setAttribute("id", "");
    }
});

}
// END OF AUTOCOMPLETE



// CONTACT FORM


$(function () {
  $('#uncheck').click(function(){ $('#uncheck').css('display','none');  $('#checked').css('display','inline'); });
  $('#checked').click(function(){ $('#uncheck').css('display','inline');$('#checked').css('display','none'); });
}());


$(function () {
	$('#TitleChanger').html('<script>document.title = "myViewBoard Wiki";</script>');
}());




// SIDEPANEL
/* Set the width of the side navigation to 250px and the left margin of the page content to 150px */
function openNav() {
  document.getElementById("mw-panel").style.width = "157.5px";
  document.getElementById("content").style.marginLeft = "164.5px";
  document.getElementById("TOPEN").style.display = "none";
  document.getElementById("TCLOSE").style.display = "inline";
  document.getElementById("footer").style.marginLeft = "157.5px";
  document.getElementById("p-logo").style.display = "inherit";
}

/* Set the width of the side navigation to 0 and the left margin of the page content to 0 */
function closeNav() {
  document.getElementById("mw-panel").style.width = "0";
  document.getElementById("content").style.marginLeft = "0";
  document.getElementById("TOPEN").style.display = "inline";
  document.getElementById("TCLOSE").style.display = "none";
  document.getElementById("footer").style.margin = "0px";
  document.getElementById("p-logo").style.display = "none";
}