8,290
edits
m (adjust visibility of secondary image in qud-toggler) |
(Add image carousel toggling code) |
||
Line 66: | Line 66: | ||
// Powers an infobox template (Template:Infobox_image_and_gif) that | // Powers an infobox template (Template:Infobox_image_and_gif) that | ||
// allows users to swap from a static image to preview an animated gif | // allows users to swap from a static image to preview an animated gif | ||
// Also supports "image carousel"-type behavior with multiple images/gifs. | |||
var qudInfoboxImageToggler = qudInfoboxImageToggler || { | var qudInfoboxImageToggler = qudInfoboxImageToggler || { | ||
initialize: function () { | initialize: function () { | ||
$( | $('.qud-toggler > .qud-toggler-initial').show(); | ||
$( | $('.qud-toggler > .qud-toggler-button').show(); | ||
$( | $('.qud-toggler > .qud-toggler-final').hide(); | ||
$( | $('.qud-toggler > .qud-toggler-button').click(function () { | ||
window.qudInfoboxImageToggler.toggle(); | window.qudInfoboxImageToggler.toggle(); | ||
}); | }); | ||
$( | $('.qud-html-details .qud-html-summary').click(function () { | ||
window.qudInfoboxImageToggler.summaryClick(); | window.qudInfoboxImageToggler.summaryClick(); | ||
}); | }); | ||
}, | }, | ||
toggle: function () { | toggle: function () { | ||
$( | $('.qud-toggler > .qud-toggler-initial').hide(); | ||
$( | $('.qud-toggler > .qud-toggler-button').hide(); | ||
$( | $('.qud-toggler > .qud-toggler-final').show(); | ||
}, | }, | ||
summaryClick: function () { | summaryClick: function () { | ||
$( | $('.qud-html-details .qud-html-summary').toggleClass( | ||
'qud-html-summary-open' | |||
); | ); | ||
} | } | ||
}; | }; | ||
Line 98: | Line 95: | ||
$(document).ready(qudInfoboxImageToggler.initialize); | $(document).ready(qudInfoboxImageToggler.initialize); | ||
var qudCarouselGearbox = qudCarouselGearbox || { | |||
initialize: function () { | |||
$('.qud-sprite-carousel > .qud-carousel-item').each(function (idx, elem) { | |||
$(elem).addClass('qud-carousel-item-number-' + idx); | |||
if ($(elem).is(':visible')) { | |||
window.qudCarouselGearbox.currentIndex = idx; | |||
} | |||
}); | |||
$('.qud-sprite-carousel .qud-carousel-btn-left').click(function () { | |||
window.qudCarouselGearbox.removeHighlight(); | |||
window.qudCarouselGearbox.rotate(-1); | |||
}); | |||
$('.qud-sprite-carousel .qud-carousel-btn-right').click(function () { | |||
window.qudCarouselGearbox.removeHighlight(); | |||
window.qudCarouselGearbox.rotate(1); | |||
}); | |||
$('.infobox-title').append('<div class="qud-carousel-title"></div>'); | |||
}, | |||
rotate: function (amount) { | |||
items = $('.qud-sprite-carousel > .qud-carousel-item'); | |||
$(items).each(function (idx, elem) { | |||
$(elem).hide(); | |||
}); | |||
window.qudCarouselGearbox.currentIndex += amount; | |||
end = $(items).length - 1; | |||
if (window.qudCarouselGearbox.currentIndex < 0) { | |||
window.qudCarouselGearbox.currentIndex = end; | |||
} else if (window.qudCarouselGearbox.currentIndex > end) { | |||
window.qudCarouselGearbox.currentIndex = 0; | |||
} | |||
curItem = $( | |||
'.qud-sprite-carousel > .qud-carousel-item-number-' + | |||
window.qudCarouselGearbox.currentIndex | |||
); | |||
curItem.show(); | |||
/* expand infobox title to also show image label */ | |||
carouselTitle = $('.qud-carousel-title'); | |||
carouselTitle.text(curItem.data('label')); | |||
carouselTitle.animate({ height: '25px' }); | |||
}, | |||
removeHighlight: function () { | |||
/* prevents weird highlight selection behavior if buttons are double-clicked */ | |||
if (window.getSelection) window.getSelection().removeAllRanges(); | |||
else if (document.selection) document.selection.empty(); | |||
} | |||
}; | |||
window.qudCarouselGearbox = qudCarouselGearbox; | |||
$(document).ready(qudCarouselGearbox.initialize); | |||
/**************************************** | /**************************************** | ||
/* End Qud infobox image-to-gif swapper * | /* End Qud infobox image-to-gif swapper * | ||
/****************************************/ | /****************************************/ |