Difference between revisions of "MediaWiki:Common.js"

From Summertime Saga Wiki
Jump to: navigation, search
 
(32 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', '.fresco-embed', function(e) {
+
return String(str).replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
e.preventDefault();
+
};
 
 
var elm = $(this);
 
Fresco.show([{
 
url : elm.attr('href')
 
}]);
 
});
 
  
// Main parsing function
+
if ($('body').hasClass('page-Summertime_Saga_Wiki') && $('body').hasClass('action-view') && $('body').hasClass('skin-vector') && $('#ajax-posts').length && $('#ajax-version').length) {
var parseTags = function() {
+
var maxPosts = 5;
// Loop through our tags
 
$('.yt').each(function(){
 
var elm = $(this);
 
var ytId = elm.text();
 
elm.replaceWith('<a class="fresco-embed" href="https://youtube.com/' + ytId + '" target="_blank" style="background-image:url(//i.ytimg.com/vi/' + ytId + '/maxresdefault.jpg)" data-ytt="' + ytId + '"></a>');
 
});
 
};
 
  
// Load Fresco if it isn't already
+
$.getJSON('/ssdata.json', function(data) {
if (typeof Fresco === 'undefined') {
+
$('#ajax-version').text(data.version);
// Temporary work around due to lack of server access
+
$('#ajax-posts').html('');
$.getScript('//awesomo.tk/assets/vendor/fresco/js/fresco.js', function() {
 
var headElm = $('head');
 
// Load Fresco CSS
 
headElm.append('<link rel="stylesheet" type="text/css" href="//awesomo.tk/assets/vendor/fresco/css/fresco.css"/>');
 
  
// Add our own custom CSS, again temporary
+
data.posts.forEach(function(post, i) {
headElm.append('<style type="text/css">.fresco-embed { text-decoration: none; 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>');
			});
		});
	}
}());