|
|
| (27 intermediate revisions by the same user not shown) |
| Line 1: |
Line 1: |
| mw.loader.load('https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.js'); | | mw.hook('wikipage.content').add(function () { |
| mw.loader.load('https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.css', 'text/css');
| | const el = document.getElementById('article-countdown'); |
| mw.loader.load('https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick-theme.css', 'text/css');
| | console.log('countdown hook fired; element is:', el); |
| mw.loader.load('/extensions/JavascriptSlideshow/js/slideshow.js');
| |
|
| |
|
| mw.hook('wikipage.content').add(function($content) {
| | if (!el) return; |
| $content.find('.mw-jsslideshow').each(function() {
| | el.textContent = '✅ Countdown JS is running…'; |
| const $slideshowContainer = $(this);
| |
| const $slideshow = $('<div class="slideshow"></div>');
| |
|
| |
|
| // Find all images inside mw-jsslideshow, including [[File:]] images
| | const apiUrl = mw.util.wikiScript('api') + |
| $slideshowContainer.find('img').each(function() {
| | '?action=query&meta=siteinfo&siprop=statistics&format=json&origin=*'; |
| const $img = $(this);
| |
| const $slide = $('<div></div>').append($img.clone()); // Wrap in slide div
| |
| $slideshow.append($slide);
| |
| });
| |
|
| |
|
| // Replace old content with the new slick-ready slideshow
| | fetch(apiUrl) |
| $slideshowContainer.empty().append($slideshow);
| | .then(r => r.json()) |
| | .then(d => { |
| | const current = d.query.statistics.articles; |
| | const goal = 1000; |
| | const left = goal - current; |
|
| |
|
| // Initialize slick
| | el.innerHTML = left > 0 |
| $slideshow.slick({ | | ? `🚧 Only <strong>${left}</strong> articles to go until 1000!` |
| infinite: true,
| | : `🎯 We've reached 1000 articles! Let's Go Boyz and Girlz!`; |
| slidesToShow: 1,
| | }) |
| slidesToScroll: 1,
| | .catch(err => { |
| autoplay: true,
| | el.textContent = 'API request failed (see console).'; |
| autoplaySpeed: 5000,
| | console.error(err); |
| arrows: true,
| |
| dots: true,
| |
| adaptiveHeight: true
| |
| });
| |
| | |
| // Fix positioning on resize
| |
| $(window).on('resize', function() {
| |
| $slideshow.slick('setPosition');
| |
| });
| |
| }); | | }); |
| }); | | }); |
|
| |
|
| $(document).ready(function() {
| |
| var counter = 1;
| |
|
| |
| $('.slideshow').each(function() {
| |
| var $this = $(this);
| |
| if (!$this.attr('id')) {
| |
| // Assign an auto id if missing
| |
| var newId = 'slideshow-auto-' + (counter++);
| |
| $this.attr('id', newId);
| |
|
| |
| // Add the missing spacer
| |
| if ($('#' + newId + '-spacer').length === 0) {
| |
| $('<div>')
| |
| .attr('id', newId + '-spacer')
| |
| .insertAfter($this);
| |
| }
| |
|
| |
|
| // Force JavascriptSlideshow to initialize this slideshow
| | // MediaWiki:Common.js |
| startSlideshow(newId);
| | mw.hook('rcfilters.ui.initialized').add(function () { |
| }
| | document.documentElement.classList.add('rcfilters-ready'); |
| });
| |
| }); | | }); |