MediaWiki:Common.js

From Summertime Saga Wiki
Revision as of 22:26, 5 February 2017 by Codeboxhr j08oql03 (talk)
Jump to: navigation, search

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: 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. */

// Test code for youtube embeds -sam9
$(function() {
	// Click handler
	$('#content').on('click', '.yt-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
		$('.yt').each(function(){
			var elm = $(this);
			var ytId = elm.text();
			elm.replaceWith('<a class="yt-embed" href="https://youtube.com/watch?v=' + ytId + '" target="_blank" style="background-image:url(//i.ytimg.com/vi/' + ytId + '/maxresdefault.jpg)" data-ytt="' + ytId + '"></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"/>');

			// Add our own custom CSS, again temporary
			headElm.append('<style type="text/css">.yt-embed { text-decoration: none; display: inline-block; width: 384px; height: 216px; margin-right: 10px; background-size: cover; background-position: center center; border: 1px solid #000; transition: border-color 0.15s ease-in-out; box-shadow: 0 0 10px 3px #191B26;     border-radius: 2px; } .yt-embed:hover { border-color: #777; }</style>');

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