Difference between revisions of "MediaWiki:Common.js"

From Summertime Saga Wiki
Jump to: navigation, search
 
(15 intermediate revisions by 2 users not shown)
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. */
  
// Test code for youtube embeds -sam9
+
// Wait for document ready
 
$(function() {
 
$(function() {
// Click handler
+
var htmle = function(str) {
$('#content').on('click', '.vid-embed', function(e) {
+
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
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();
 
 
 
elm.replaceWith('<a class="vid-embed" href="https://youtube.com/watch?v=' + vidId + '" target="_blank" style="background-image:url(//i.ytimg.com/vi/' + vidId + '/maxresdefault.jpg)"><span class="vid-embed-title">' + title + '</span></a>');
 
});
 
 
};
 
};
  
var vidTags = $('.vid');
+
if ($('body').hasClass('page-Summertime_Saga_Wiki') && $('body').hasClass('action-view') && $('body').hasClass('skin-vector') && $('#ajax-posts').length && $('#ajax-version').length) {
 +
var maxPosts = 5;
  
// Load magnificPopup if it isn't already
+
$.getJSON('/ssdata.json', function(data) {
if (vidTags.length !== 0 && typeof $.magnificPopup === 'undefined') {
+
$('#ajax-version').text(data.version);
// Temporary work around due to lack of server access
+
$('#ajax-posts').html('');
$.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
+
data.posts.forEach(function(post, i) {
headElm.append('<style type="text/css">a.vid-embed { position: relative; text-decoration: none; display: inline-block; width: 384px; height: 216px; margin: 0 10px 10px 0; 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; } a.vid-embed:hover { border-color: #777; text-decoration: none; } a.vid-embed:focus { outline: 0; } span.vid-embed-title { color: #bbb; text-align: left; margin: 8px 0 0 12px; font-size: 16px; display: block; }</style>');
+
if (i >= maxPosts) {
 +
return;
 +
}
  
// Run our main function
+
$('#ajax-posts').append('<dd><b>▪ ' + htmle(post.date) + ':</b> <a rel="nofollow" class="external text" href="https://www.patreon.com' + htmle(post.url) + '">' + htmle(post.title) + '</a></dd>');
parseTags();
+
});
 
});
 
});
} else {
 
// Run our main function
 
parseTags();
 
 
}
 
}
 
}());
 
}());

Latest revision as of 12:21, 14 June 2019

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

// Wait for document ready
$(function() {
	var htmle = function(str) {
		return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
	};

	if ($('body').hasClass('page-Summertime_Saga_Wiki') && $('body').hasClass('action-view') && $('body').hasClass('skin-vector') && $('#ajax-posts').length && $('#ajax-version').length) {
		var maxPosts = 5;

		$.getJSON('/ssdata.json', function(data) {
			$('#ajax-version').text(data.version);
			$('#ajax-posts').html('');

			data.posts.forEach(function(post, i) {
				if (i >= maxPosts) {
					return;
				}

				$('#ajax-posts').append('<dd><b>▪ ' + htmle(post.date) + ':</b> <a rel="nofollow" class="external text" href="https://www.patreon.com' + htmle(post.url) + '">' + htmle(post.title) + '</a></dd>');
			});
		});
	}
}());