Difference between revisions of "MediaWiki:Common.js"

From Summertime Saga Wiki
Jump to: navigation, search
Line 1: Line 1:
 
/* Any JavaScript here will be loaded for all users on every page load. */
 
/* Any JavaScript here will be loaded for all users on every page load. */
 
// Google Analytics -Filip
 
(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','https://www.google-analytics.com/analytics.js','ga');
 
 
ga('create', 'UA-19057746-5', 'auto');
 
ga('send', 'pageview');
 
ga('set', 'contentGroup1', 'wiki');
 
  
 
// Wait for document ready
 
// Wait for document ready

Revision as of 17:51, 4 September 2017

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

// Wait for document ready
$(function() {
	// Set progress bar
	var issueProgress = $('.issue-progress');
	if (issueProgress.length !== 0) {
		issueProgress.html('<img src="http://summertimesaga.com/api/build/progress/img.png?width=500&color=eaeced&nc=' + Math.random() + '" alt="" border="0"/>');
	}

	// Test code for youtube embeds -sam9
	// Example tag: <span class="vid" data-id="YT_ID">VID_TITLE</span>
	var vidTags = $('.vid');

	// Check to make sure vid tags exist
	if (vidTags.length !== 0) {
		// Click handler
		$('#content').on('click', '.vid-embed', function(e) {
			e.preventDefault();

			var elm = $(this);
			$.magnificPopup.open({
				items: {
					src : elm.attr('href'),
					type : 'iframe'
				}
			});
		});

		// Main parsing function
		var parseTags = function() {
			// Loop through our tags
			vidTags.each(function() {
				var elm = $(this);
				var vidId = elm.data('id');
				var title = elm.text();

//				i.ytimg.com/vi/' + vidId + '/maxresdefault.jpg
				elm.replaceWith('<a class="vid-embed" href="https://youtube.com/watch?v=' + vidId + '" target="_blank" title="' + title + '" style="background-image:url(//img.youtube.com/vi/' + vidId + '/mqdefault.jpg)"><div class="vid-mask"><span class="vid-embed-title">' + title + '</span><div class="vid-play"></div></div></a>');
			});
		};

		// Load magnificPopup if it isn't already
		if (typeof $.magnificPopup === 'undefined') {
			// Temporary work around due to lack of server access
			$.getScript('//cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js', function() {
				var headElm = $('head');
				// Load magnificPopup CSS
				headElm.append('<link rel="stylesheet" type="text/css" href="//cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/magnific-popup.min.css"/>');

				// Run our main function
				parseTags();
			});
		} else {
			// Run our main function
			parseTags();
		}
	}
}());