User:Wookipan/Sandbox/Page.js
< User:Wookipan | Sandbox
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 / Edge: 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.
/* var embedHeroVid = { init: function () { var $container = $('.mp-event-container'); var $image = $('.mp-event-image'); var isVideo = !!($container.data('mpEventVideo')); if ($image[0] && isVideo) { console.log('Running'); var _video = $('<video/>', { muted: true, autoplay: true, loop: true, class: 'mp-event-video' }); embedHeroVid.getSource($container) .done(function (url) { var extension = url[1]; _video.insertAfter($image); $('<source/>', { src: url[0], type: 'video/' + extension }).appendTo(_video); _video[0].oncanplaythrough = function () { $image.remove(); $container.attr('data-video-url', null); }; }); } }, getSource: function (source) { var deferred = $.Deferred(); var url = source.attr('data-video-url'); if (typeof url === 'undefined' || url === '') { throw new Error('Video URL is undefined. If it\'s blank, it is due to the internal file name being incorrect or that the "video-url" parameter is unset.'); } var extension = url.split('/').reverse()[0].split('.')[1]; $.get(url) .done(function () { deferred.resolve([url, extension]); }) .fail(function () { throw new Error('Whoops, invalid video! Please ensure the URL is right\nVideo URL: ' + url); }); return deferred.promise(); } }; $(embedHeroVid.init); */ var wikiTooltip = { init: function() { var $tooltips = $('.wiki-tooltip .wiki-tooltip-content'); if ($tooltips[0]) { $tooltips.each(function() { var $this = $(this); function handler() { // Check for links and handle them on handheld devices if (!!$this.closest('a').attr('href')) { $this.closest('a').removeAttr('title'); widthRect <= 1000 ? wikiTooltip.hasLink($this) : wikiTooltip.removeAnchor($this); } // Prevent tooltips from overflowing the viewport edgeRect = $this.width() + $this[0].getBoundingClientRect().left; widthRect = $(window).innerWidth(); if (edgeRect > (widthRect || $(body).clientWidth)) { $this.css('left', ''); $this.css('right', '100%'); } else { $this.css('right', ''); $this.css('left', '100%'); } } $(handler); setTimeout(function() { $(window).on('resize', handler); }, 250); }); } }, hasLink: function(tooltip) { if (tooltip.find('a').length < 1) { var $a = $('<a>'); var url = tooltip.closest('a'); var href = url.attr('href'); $a.attr('href', href); url.attr('href', 'javascript:void(0);'); tooltip.append($a); } }, removeAnchor: function(tooltip) { var url = tooltip.closest('a'); var href = url.attr('href'); innerLink = tooltip.find('a').attr('href'); if (innerLink) { href = innerLink; url.attr('href', href); tooltip.find('a').remove(); } else { return; } } }; $(wikiTooltip.init);