Difference between revisions of "MediaWiki:Common.js"
From Summertime Saga Wiki
Line 4: | Line 4: | ||
$(function() { | $(function() { | ||
// Click handler | // Click handler | ||
− | $('#content').on('click', '. | + | $('#content').on('click', '.yt-embed', function(e) { |
e.preventDefault(); | e.preventDefault(); | ||
var elm = $(this); | var elm = $(this); | ||
− | + | $.magnificPopup.open({ | |
− | + | items : [{ | |
− | } | + | src : elm.attr('href') |
+ | }], | ||
+ | gallery : { | ||
+ | enabled : false | ||
+ | } | ||
+ | }); | ||
}); | }); | ||
Line 19: | Line 24: | ||
var elm = $(this); | var elm = $(this); | ||
var ytId = elm.text(); | var ytId = elm.text(); | ||
− | elm.replaceWith('<a class=" | + | elm.replaceWith('<a class="yt-embed" href="https://youtube.com/' + ytId + '" target="_blank" style="background-image:url(//i.ytimg.com/vi/' + ytId + '/maxresdefault.jpg)" data-ytt="' + ytId + '"></a>'); |
}); | }); | ||
}; | }; | ||
− | // Load | + | // Load magnificPopup if it isn't already |
− | if (typeof | + | if (typeof typeof $.magnificPopup === 'undefined') { |
// Temporary work around due to lack of server access | // Temporary work around due to lack of server access | ||
− | $.getScript('// | + | $.getScript('//cdnjs.cloudflare.com/ajax/libs/magnific-popup.js/1.1.0/jquery.magnific-popup.min.js', function() { |
var headElm = $('head'); | var headElm = $('head'); | ||
− | // Load | + | // Load magnificPopup CSS |
− | headElm.append('<link rel="stylesheet" type="text/css" href="// | + | 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 | // Add our own custom CSS, again temporary | ||
− | headElm.append('<style type="text/css">. | + | headElm.append('<style type="text/css">.yt-embed { text-decoration: none; display: block; width: 384px; height: 216px; background-size: cover; background-position: center center;}</style>'); |
// Run our main function | // Run our main function |
Revision as of 23:02, 5 February 2017
/* 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')
}],
gallery : {
enabled : false
}
});
});
// 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/' + 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 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: block; width: 384px; height: 216px; background-size: cover; background-position: center center;}</style>');
// Run our main function
parseTags();
});
} else {
// Run our main function
parseTags();
}
}());