Common.js

From Culture.si

Note: After saving, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Go to Menu → Settings (Opera → Preferences on a Mac) and then to Privacy & security → Clear browsing data → Cached images and files.
/* Any JavaScript here will be loaded for all users on every page load. */

/*
function makeDraftButton() {
    var email=[];
    $('.infobox .ibr-Email a').each(  function(i,e){ email.push($(e).text()); });
    $('.infobox .ibr-Email_1 a').each(function(i,e){ email.push($(e).text()); });
    $('.infobox .ibr-Email_2 a').each(function(i,e){ email.push($(e).text()); });
    $('.infobox .ibr-Email_3 a').each(function(i,e){ email.push($(e).text()); });

   var to = encodeURIComponent(email.shift());
   var cc = encodeURIComponent(email.join(', '));
   var url = '/draft.php?to='+to+'&cc='+cc+'&subject='+wgTitle;
   if(to) {
     $('.track-link').html('<a href="'+url+'">SPAM !!!</a>');
   }
}
*/


function $$(id) { return document.getElementById(id); }
function url_host(url) {
    url=url.replace(/^.*?\/\//,''); url=url.replace(/\/.*$/,'');
    return(url);
}

function windowResized() {
   var w=$(window).width();
   if(w<922) { $('body').addClass('narrow-window'); }
   else { $('body').removeClass('narrow-window'); }
}

$(window).resize(windowResized);

$(window).ready(function() {
  // == add SVG region map widget ==
  // look if region is specified on a page
  var r=$('.infobox .ibr-Region td').text().replace(/\s+$/,'');
  //  var minimap="/static/SI-post.svg";
  var minimap="/static/SI-post.html";
  if(r) { minimap+="?"+r; }
  $('#p-Collections .body').
   append(
    '<iframe src="'+minimap+'" style="overflow: hidden; border: 0;" id="imagemap" width="132" height="95"></iframe>'
//    '<object type="image/svg+xml" data="'+minimap+'" class="svg" style="overflow: hidden" id="svg-map" width="132" height="95"></object>'
   );

   // add embed SVG graphics
   $('.embed-svg').each(function (i,e) {
      var url=$('a.internal',e).attr('href');
      $('a.internal',e).hide();
      var w=640; var h=480;
      $(e).prepend(
       '<object type="image/svg+xml" data="'+url+'"'+
       ' class="svg" style="overflow: visible"'+
//       ' width="'+w+'" height="'+h+'"'+
       '></object>'
      );
   });

   // add embedded abstracts (not used much anymore)
   $('.abstract').each(function (i,e) {
     var url=$(e).text();
     if(url) {
       $(e).html('Querying '+url);
       $(e).hide();
       $.get(url,{}, function(r) {
         $('#abstract',r).each( function(i1,e1) {
           $(e).html(e1);
           $(e).append('<p class="KU_more"><a href="'+url+'" class="more">More</a></p>');
           $(e).fadeIn();
         });
       }, 'html');
     }
   });

  // build pretty timeline display
  var groupa='';
  $('.timeline').each(function(i,e){
     $('table',e).hide();
     $('tr',e).each(function(i1,e1) {
       var d={};
       $('td',e1).each(function(i2,e2) {
         var v=$(e2).html();
         if(i2==1) {d.year=v;}
         if(i2==0) {d.label=v;}
       });
      if(!d.year) return;
      $(e).append(
'<div class="tl-evt">'+
((groupa!=d.year)?
 ('<div class="tl-evt-bul">•&nbsp;'+d.year+'</div>'):'')+
'<div class="tl-evt-lbl">'+d.label+'</div>'+
'</div>');
      groupa=d.year;
     });
   });


  // fix footers on semantic media wiki tables
  $('tr.smwfooter td a').html('<div class="more_go">More</div>');

  // fix links on images for featured articles
  $('.featured-article-horizontal').each(function(i,e){
     var newlink=$('.featured-article-horizontal-h a',e).attr('href');
     $('a.image',e).attr('href',newlink);
  });
  $('.featured-article-column').each(function(i,e){
     var newlink=$('.featured-article-h a',e).attr('href');
     $('a.image',e).attr('href',newlink);
  });

  // make propery cloud
  $('body.page-Special_Properties').each(function(i,e) {
    $('#bodyContent').
      append('<div id="cloud" type="category-cloud"></div>');

    $('ol.special:eq(0) li').
      each(function(i,e){
        var t=$('a:eq(0)',e).text(); 
        if(t=='Has improper value for') { return; }
        var n=$(e).text().match(/\d+/)[0]; 
        $('#cloud').append(
          '<a style="font-size: '+
          Math.floor(12+Math.log(n)*4)+
          'px" class="cloud-propery" title="'+n+
          '" href="/en/Property:'+t+'">'+
          t+
          '</a> '); 
    });

    $('ol.special:eq(0)').hide();
  });

  // TODO: add browse RDF button to properties page
  $('body.mw-special-Browse').each(function(i,e) {
  });


  // change search box to search type for extra fancyness...
  // $('#searchInput').attr('type','search'); // DOESN'T WORK!
  // focus search box, if no other inputs present and no anchor
  if($('input').length==4 && !window.location.hash) {
    $('#searchInput').focus();
  }
/*
  // display only host names for websites in infoboxen
  // this fixes problems with wide infoboxes on msie
  $('.infobox .ibr-Website a').each(function(i,e) {
    $(e).text(url_host($(e).attr('href')));
  });

  // display only host names for websites in contacts
  $('.contact-website a').each(function(i,e) {
    $(e).text(url_host($(e).attr('href')));
  });
*/
  // display notice for articles still in progress
  $('.nifertik').each(function(i,e) {
    if(i==0) {
     $('#ibr-contribute .p1').html('This article is <a href="/en/Culture.si:Still_in_progress">still in progress.</a>');
    }
  });

  // hide redirected-from on new main page
  $('.page-Culture_of_Slovenia #contentSub').html('');

  // hack-fix potentially broken MK logo
  $('#mklogo').html('<a href="/en/MK"><img src="/static/MK.gif" alt="Ministry of Culture of Republic of Slovenia"/></a>');
  // hack-fix broken top-menu, make all links server local
  $('#siteNotice .buttons .internal a').each(function(i,e){
    $(e).attr('href',$(e).attr('href').replace(/^http:\/\/[^\/]+\//,'/'))
  });
  // balance h1 heights on front page
  var h1 = 0;
  $('table.twocolumns h1').each(function(i,e){var h=$(e).height(); if(h>h1) h1=h; });
  $('table.twocolumns h1').each(function(i,e){$(e).height(h1);});

  // fixes for EPK 2012 button
  var e = $('#n-Maribor-ECoC-2012 a');
  e.html('<span style="display: none;">'+e.text()+'</span>');
  e.css('background','url(/static/epk138x24.png)');
  e.css('display','block');
  e.css('height','24px');
  
  // fixes for Festivals 2012 button
  var e = $('#n-Festivals-2012 a');
  e.html('<span style="display: none;">'+e.text()+'</span>');
  e.css('background','url(/static/festivals2012.png)');
  e.css('display','block');
  e.css('height','24px');
  
  
  //makeDraftButton();

  windowResized();
});

var distinguishedCategories =
{ "Academies and faculties" : 1, "Africa" : 1, "African collections" : 1, "Agencies" : 1, "Alpine folk music" : 1, "Animation" : 1, "Animation festivals" : 1, "Architecture" : 1, "Architecture archives & libraries" : 1, "Architecture awards and competitions" : 1, "Architecture course and workshop organisers" : 1, "Architecture & Design" : 1, "Architecture education and research" : 1, "Architecture exhibition organisers" : 1, "Architecture exhibition venues" : 1, "Architecture festival and event organisers" : 1, "Architecture festivals" : 1, "Architecture funding, professional and support services" : 1, "Architecture media" : 1, "Architecture museums" : 1, "Architecture overview" : 1, "Architecture publishers" : 1, "Architecture studios" : 1, "Archival funding, professional and support services" : 1, "Archival institutions" : 1, "Archival & librarian education and research" : 1, "Archival & library course and workshop organisers" : 1, "Archival & library course and workshop organisers" : 1, "Archive periodicals" : 1, "Archives" : 1, "Archives and libraries awards and competitions" : 1, "Archives & Libraries" : 1, "Archives publishers" : 1, "Archive web resources" : 1, "Ballet" : 1, "Bookshops" : 1, "Brass band music" : 1, "Broadcasting" : 1, "Cafés" : 1, "Castles" : 1, "Choral music" : 1, "Church archives" : 1, "Church collections" : 1, "Churches" : 1, "Church libraries" : 1, "Cinemas" : 1, "Clubs" : 1, "Collecting societies" : 1, "Collections" : 1, "Comic art" : 1, "Concert halls" : 1, "Contemporary dance" : 1, "Copyright" : 1, "Course and workshop organisers" : 1, "Courses and workshops" : 1, "Cultural centres" : 1, "Cultural heritage education and research" : 1, "Cultural heritage media" : 1, "Cultural management" : 1, "Cultural policy" : 1, "Dance" : 1, "Dance awards and competitions" : 1, "Dance course and workshop organisers" : 1, "Dance education and research" : 1, "Dance festival and event organisers" : 1, "Dance festivals" : 1, "Dance funding, professional and support services" : 1, "Dance groups" : 1, "Dance overview" : 1, "Dance periodicals" : 1, "Dance producers" : 1, "Dance publishers" : 1, "Dance venues" : 1, "Design" : 1, "Design awards and competitions" : 1, "Design course and workshop organisers" : 1, "Design course and workshop organisers" : 1, "Design education and research" : 1, "Design exhibition and event organisers" : 1, "Design exhibition venues" : 1, "Design festivals" : 1, "Design media" : 1, "Design museums, archives & libraries" : 1, "Design museums, archives & libraries" : 1, "Design overview" : 1, "Design publishers" : 1, "Design studios" : 1, "Development agencies" : 1, "Distributors" : 1, "Education and research" : 1, "Electronic music" : 1, "Embassies and consulates in Slovenia" : 1, "Ethno music" : 1, "EU Culture funding recipient" : 1, "EU funding of Slovene organisations (Culture and MEDIA Programmes)" : 1, "EU MEDIA funding recipient" : 1, "Event organisers" : 1, "Events" : 1, "Exhibition organisers" : 1, "Exhibition venues" : 1, "Experimental music" : 1, "Fairs" : 1, "Fashion design" : 1, "Festival organisers" : 1, "Festivals" : 1, "Film" : 1, "Film archives & libraries" : 1, "Film awards and competitions" : 1, "Film course and workshop organisers" : 1, "Film courses, workshops and residencies" : 1, "Film distributors" : 1, "Film education and research" : 1, "Film event organisers" : 1, "Film festival organisers" : 1, "Film festivals" : 1, "Film history" : 1, "Film media" : 1, "Film museums" : 1, "Film overview" : 1, "Film producers" : 1, "Film publishers" : 1, "Film studios" : 1, "Film venues" : 1, "Folkloric dance" : 1, "Funding" : 1, "Funding web resources" : 1, "Galleries" : 1, "General web resources" : 1, "Graphic design" : 1, "Groups" : 1, "Heritage organisations" : 1, "Heritage overview" : 1, "History" : 1, "History of archives" : 1, "History of dance" : 1, "History of design" : 1, "History of libraries" : 1, "History of literature" : 1, "History of museums" : 1, "History of music" : 1, "History of opera" : 1, "History of theatre" : 1, "Industrial and technical heritage" : 1, "Industrial design" : 1, "Information offices" : 1, "Intangible heritage" : 1, "Intangible heritage festivals" : 1, "Interior design" : 1, "International cultural centres" : 1, "International funding" : 1, "Jazz" : 1, "Journals" : 1, "Libraries" : 1, "Library funding" : 1, "Library funding, professional and support services" : 1, "Library institutions" : 1, "Library online media" : 1, "Library overview" : 1, "Library periodicals" : 1, "Library support services" : 1, "Library web resources" : 1, "Literature" : 1, "Literature awards and competitions" : 1, "Literature course and workshop organisers" : 1, "Literature courses, workshops and residencies" : 1, "Literature education and research" : 1, "Literature event organisers" : 1, "Literature fairs" : 1, "Literature festival organisers" : 1, "Literature festivals" : 1, "Literature funding, professional and support services" : 1, "Literature museums and archives" : 1, "Literature online media" : 1, "Literature overview" : 1, "Literature periodicals" : 1, "Literature publishers" : 1, "Literature venues" : 1, "Literature web resources" : 1, "M3C" : 1, "Magazines" : 1, "Maribor, European Capital of Culture 2012" : 1, "Media" : 1, "Media agencies" : 1, "Media awards and competitions" : 1, "Media education and research" : 1, "Media funding, professional and support services" : 1, "Media studios" : 1, "Mercury mining heritage" : 1, "Monuments and sites" : 1, "Multidisciplinary fairs" : 1, "Multidisciplinary festivals" : 1, "Multimedia centres" : 1, "Municipal archives" : 1, "Municipal cultural institutions" : 1, "Municipal funding" : 1, "Municipal libraries" : 1, "Municipal museums" : 1, "Museum awards and competitions" : 1, "Museum collections" : 1, "Museum courses and workshops" : 1, "Museum funding, professional and support services" : 1, "Museum institutions" : 1, "Museum libraries" : 1, "Museum overview" : 1, "Museum periodicals" : 1, "Museums" : 1, "Music" : 1, "Music agencies" : 1, "Music archives and libraries" : 1, "Music awards and competitions" : 1, "Music course and workshop organisers" : 1, "Music courses, workshops and residencies" : 1, "Music distributors" : 1, "Music education and research" : 1, "Music fairs" : 1, "Music festival and event organisers" : 1, "Music festivals" : 1, "Music funding, professional and support services" : 1, "Music groups, ensembles and orchestras" : 1, "Music media" : 1, "Music museums and collections" : 1, "Music overview" : 1, "Music publishers" : 1, "Music venues" : 1, "National archives" : 1, "National cultural institutions" : 1, "National funding" : 1, "National libraries" : 1, "National museums" : 1, "New media art" : 1, "New media art archives and libraries" : 1, "New media art awards and competitions" : 1, "New media art course and workshop organisers" : 1, "New media art education and research" : 1, "New media art festival and event organisers" : 1, "New media art festivals" : 1, "New media art funding, professional and support services" : 1, "New media art groups" : 1, "New media art history" : 1, "New media art overview" : 1, "New media art producers" : 1, "New media art studios" : 1, "New media art venues" : 1, "Newspapers" : 1, "Online media" : 1, "Opera and music theatre" : 1, "Opera overview" : 1, "Orchestral and chamber music" : 1, "Outdoor venues" : 1, "Overviews" : 1, "Periodicals" : 1, "Photography" : 1, "Plečnik heritage" : 1, "Pop music" : 1, "Private museum collections" : 1, "Producers" : 1, "Professional archival associations" : 1, "Professional associations" : 1, "Professional librarian associations" : 1, "Public entities" : 1, "Publishers" : 1, "Puppetry" : 1, "Puppetry event organisers" : 1, "Puppetry festival and event organisers" : 1, "Puppetry festival organisers" : 1, "Radio" : 1, "Rap and hip hop" : 1, "Recording studios" : 1, "Regional archives" : 1, "Regional libraries" : 1, "Regional museums" : 1, "Residencies" : 1, "Rock" : 1, "Roman archaeological findings" : 1, "Schools" : 1, "Šiška Cultural Quarter" : 1, "Slovene embassies and consulates" : 1, "Slovenian language" : 1, "Specialised archives" : 1, "Specialised libraries" : 1, "Specialised museums" : 1, "Sport (sk8 park, ROG)" : 1, "Street theatre" : 1, "Studios" : 1, "Support services" : 1, "Television" : 1, "Theatre" : 1, "Theatre archives" : 1, "Theatre archives and libraries" : 1, "Theatre awards and competitions" : 1, "Theatre course and workshop organisers" : 1, "Theatre courses, workshops and residencies" : 1, "Theatre education and research" : 1, "Theatre event organisers" : 1, "Theatre festival and event organisers" : 1, "Theatre festival organisers" : 1, "Theatre festivals" : 1, "Theatre funding, professional and support services" : 1, "Theatre groups" : 1, "Theatre houses" : 1, "Theatre houses" : 1, "Theatre media" : 1, "Theatre museums" : 1, "Theatre overview" : 1, "Theatre producers" : 1, "Theatre publishers" : 1, "Theatre venues" : 1, "Tourism" : 1, "Universities" : 1, "University libraries" : 1, "Venues" : 1, "Vernacular Architecture" : 1, "Video" : 1, "Visual arts" : 1, "Visual arts archives and libraries" : 1, "Visual arts awards and competitions" : 1, "Visual arts collections" : 1, "Visual arts commercial galleries" : 1, "Visual arts course and workshop organisers" : 1, "Visual arts education and research" : 1, "Visual arts festival and exhibition organisers" : 1, "Visual arts festivals" : 1, "Visual arts funding, professional and support services" : 1, "Visual arts galleries" : 1, "Visual arts history" : 1, "Visual arts media" : 1, "Visual arts museums" : 1, "Visual arts overview" : 1, "Visual arts private collections" : 1, "Visual arts producers" : 1, "Visual arts publishers" : 1, "Visual arts studios, workshops and residencies" : 1, "Visual arts venues" : 1, "War memorials" : 1, "Web resources" : 1, "World Book Capital Ljubljana 2010" : 1, "World War I" : 1, "World War II" : 1 }
;

// beautify categories
$('.featured-article-column .categories').each(function(i,e){
	var r = '';
	$('> a',e).each(function(i1,e1){
		var c = $(e1).text();
		if(distinguishedCategories[c]) { r += e1.outerHTML+' ' }
	});
	$(e).html(r);
//	console.log(r);
});

var y0;
// add <h2>year</h2> to event listings
$('li.event-item').each(function(i,e){
  var y = $('.year:first',e).text();
  if(y0!=y) {
  	y0=y;
  	$(e).before('<h2>'+y+'</h2>');
//  	$(e).prepend(`<h2>${y}</h2>`);
	console.log('y',y);
  }
});

/* GAnalytics */
//cc.onconsent('analytics', function(){
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-15634418-2', 'auto');
  ga('send', 'pageview');
//});