MediaWiki:Gadget-GallerySlideshow.js
Aus Matura Wiki
Hinweis: Leere nach dem Speichern den Browser-Cache, um die Änderungen sehen zu können.
- Firefox/Safari: Umschalttaste drücken und gleichzeitig Aktualisieren anklicken oder entweder Strg+F5 oder Strg+R (⌘+R auf dem Mac) drücken
- Google Chrome: Umschalttaste+Strg+R (⌘+Umschalttaste+R auf dem Mac) drücken
- Internet Explorer: Strg+F5 drücken oder Strg drücken und gleichzeitig Aktualisieren anklicken
- Opera: Extras → Internetspuren löschen … → Individuelle Auswahl → Den kompletten Cache löschen
/** * Installer Script for Gallery-Slideshow * Loads big code on demand * This code is jshint-valid! */ /*global $:false, mw:false*/ /*jshint curly:false*/ launch = function() { 'use strict'; var getMessage, $c = mw.util.$content.parent(); if ($('.gallery', $c).find('li').length < 2 || mw.config.get('wgNamespaceNumber') === -1 || mw.util.getParamValue('printable')) return; // no need for a gallery with a few images // Preparation for i18n and [[:mw:ResourceLoader/Version 2 Design Specification]] - using MediaWiki messages to translate // When Gadget 2 got ready, please revert to https://commons.wikimedia.org/w/index.php?oldid=101463143 var msgs = (function () { var translations = { en: { "gs-label-start": "Slideshow (all images)", "gs-label-gallery": "Gallery Slideshow", "gs-label-started": "Show Slideshow", "gs-label-category": "Category Slideshow", "gs-label-continue": "Resume", "gs-title-start": "Start a slideshow of all images (alphabetical by file name)", "gs-title-gallery": "Start a slideshow made from the images in the gallery of this page", "gs-title-started": "Reopen slideshow pane", "gs-title-category": "Start a category slideshow (alphabetical by sortkey, starting with the first file of the category)", "gs-title-continue": "Continue Slideshow where you had left it last time you visited this page." }, cs: { "gs-label-start": "Prezentace (všechny obrázky)", "gs-label-gallery": "Prezentace galerie", "gs-label-started": "Zobrazit prezentaci", "gs-label-category": "Prezentace kategorie", "gs-label-continue": "Pokračovat", "gs-title-start": "Spustit prezentaci všech obrázků (abecedně podle jména souboru)", "gs-title-gallery": "Spustit prezentaci všech obrázků v galerii na této stránce", "gs-title-started": "Znovuotevřít panel s prezentací", "gs-title-category": "Spustit prezentaci kategorie (abecedně podle řadicího klíče počínaje prvním souborem v kategorii)", "gs-title-continue": "Pokračovat v prezentaci od místa, kde jste skončili při poslední návštěvě této stránky." }, fa: { "gs-label-start": "اسلایدشو (همه تصاویر)", "gs-label-gallery": "اسلایدشو برای نگارخانه", "gs-label-started": "نمایش اسلایدشو", "gs-label-category": "اسلایدشوی رده", "gs-label-continue": "ادامه", "gs-title-start": "شروع یک اسلایدشوی برای همهٔ تصاویر (الفبایی بنا به نام پرونده)", "gs-title-gallery": "شروع یک اسلایدشوی ساخته\u200cشده از تصاویر نگارخانهٔ این صفحه", "gs-title-started": "بازکردن مجدد قاب اسلایدشو", "gs-title-category": "شروع یک اسلایدشوی رده (الفبایی مرتب\u200cشده، شروع با اولین پرونده)", "gs-title-continue": "ادامهٔ اسلایدشو از آنجایی که دفعهٔ قبلی که این صفحه را بازدید کردید رها کرده\u200cاید." } }, languageNameParts = mw.config.get('wgUserLanguage').split('-'), lang; translations.no = translations.nb; if (languageNameParts[1] === 'hans' || languageNameParts[1] === 'cn' || languageNameParts[1] === 'sg' || languageNameParts[1] === 'my') { lang = 'zh-hans'; } else if (languageNameParts[1] === 'hant' || languageNameParts[1] === 'hk' || languageNameParts[1] === 'tw' || languageNameParts[1] === 'mo') { lang = 'zh-hant'; } else if (translations[languageNameParts[0]]) { lang = languageNameParts[0]; } else { lang = 'en'; } return $.extend(true, translations.en, translations[lang]); }()); mw.messages.set(msgs); getMessage = function(msg) { msg = mw.message('gs-' + msg); return (msg.exists() ? msg.toString() : msg); }; // These dependencies must remain here! The gadget is also used as withJS // withCSS // Of course one could introduce a withGadget - URL query param into common.js mw.loader.using(['jquery.cookie', 'mediawiki.util', 'jquery.ui.button', 'jquery.hoverIntent'], function() { var isCategory = mw.config.get('wgNamespaceNumber') === 14, $gButtons = $('<div>', { id: 'GallerySlideStartButtons' }), $gButtonsInner = $('<div>', { id: 'GallerySlideStartButtonsInner' }) .appendTo($gButtons); if (isCategory) { $('#mw-category-media', $c).prepend($gButtons); } else { $(mw.util.$content, $c).find('#firstHeading').before($gButtons); } var startSlideshow = function(o, cont, screenread) { if (cont) o.cont = cont; if (screenread) { o.readFromScreen = true; o.remoteUse = true; } o.start(); }; var loadSlideshowAndStart = function(cont, screenread) { $startButton.button({ label: getMessage('label-started') }) .attr('title', getMessage('title-started')); if ('object' === typeof window.GallerySlide) { startSlideshow(window.GallerySlide, cont, screenread); } else { $(document).bind('slideshow', function(e, st, o) { // If the code requires debugging, you can uncomment the following line // console.log('evt: ' + st); if ('codeLoaded' === st && o) { startSlideshow(o, cont, screenread); } }); window.importScriptURI( mw.config.get('wgServer') + mw.config.get('wgScript') + '?' + $.param({ title: 'MediaWiki:GallerySlideshow.js', action: 'raw', ctype: 'text/javascript', dummy: 8 })); } }; var createButton = function(type, msg) { return $('<button>', { role: 'button', id: 'GallerySlide' + type, title: getMessage('title-' + (msg || type)), text: getMessage('label-' + (msg || type)) }); }, $startButton = createButton('start', isCategory ? 'category' : 'gallery').button({ icons: { secondary: 'ui-icon-slideshow' } }) .addClass('ui-button-green').click(function() { if (isCategory) { // In categories, have an option for the whole category loadSlideshowAndStart(); } else { // In galleries/ on user pages, only files in a gallery should be displayed // (often there are lots of little icon files that aren't important) and just cause noise loadSlideshowAndStart(0, true); } }); // This does not make sense in categories since they should not contain additional galleries // But if they contain >200 files, thus "consisting of multiple pages" // it might be useful to start at the current offset if ($('#mw-category-media .gallery', $c).prevAll('a').length) { $gButtonsInner.append( createButton('gallery').button({ icons: { primary: 'ui-icon-image' } }) .click(function() { loadSlideshowAndStart(0, true); })); } var lastQuery = $.cookie('gs' + mw.config.get('wgPageName').replace('Category:', '1:').replace('Commons:', '2:')); if (lastQuery) { $gButtonsInner.append(createButton('continue').button({ icons: { primary: 'ui-icon-seek-next' } }).click(function() { loadSlideshowAndStart(lastQuery); })); } $startButton.appendTo($gButtonsInner); $gButtons.buttonset(); $(document).triggerHandler('slideshow', ['loadedInstaller', $gButtons]); // For external scripts var autoStart = mw.util.getParamValue('gsAutoStart'); if (({ '1': 1, 'true': 1, 'yes': 1, '-1': 1 }[autoStart])) { loadSlideshowAndStart(); } // TODO: Make a dropdown like Flickr has (more usable) // Save space and make it non-intusive: The slideshow button is only partially visible var $buttons = $gButtons.find('button'), _switchToIcon = function($b) { $b.removeClass('ui-button-text-icon-secondary') .removeClass('ui-button-text-icon-primary').addClass('ui-button-icon-only'); }; $buttons.each(function(i, b) { var $b = $(b), oldClass = $b.attr('class'), $t = $b.find('span.ui-button-text'), tw = $t.width(); $b.hoverIntent(function() { var hasOldClass = false; $t.stop(true).delay(200).animate({ width: tw, opacity: 1 }, { duration: 'fast', easing: 'linear', step: function() { if (hasOldClass) return; $b.attr('class', oldClass); hasOldClass = true; } }); }, function() { $t.delay(800).animate({ width: 0, opacity: 0 }, function() { _switchToIcon($b); }); }); _switchToIcon($b); $t.width(0).fadeTo(0, 0); }); }); }; mw.hook('wikipage.content').add(launch);