| @@ -1,35 +1,46 @@ | ||
| 1 | -(function ($) { | |
| 2 | - // Open modal and play How To video. | |
| 3 | - $( document ).on( 'click', '#poll-maker-welcome .play-video', function( event ) { | |
| 4 | - event.preventDefault(); | |
| 1 | +// Poll Maker welcome page simple JS | |
| 2 | +(function($){ | |
| 3 | + $(function(){ | |
| 4 | + // Changelog toggle | |
| 5 | + var $toggle = $('#wn-toggle'); | |
| 6 | + var $chg = $('.ays-pm-w-changelog'); | |
| 7 | + $toggle.on('click', function(){ | |
| 8 | + if($chg.hasClass('ays-pm-w-collapsed')){ | |
| 9 | + $chg.removeClass('ays-pm-w-collapsed').addClass('ays-pm-w-expanded'); | |
| 10 | + $('.ays-pm-w-wn-arrow').html('▴'); | |
| 11 | + $toggle.text(poll_maker_ays_welcome.show_less).append($('<span/>',{class:'ays-pm-w-wn-arrow',html:'▴'})); | |
| 12 | + }else{ | |
| 13 | + $chg.removeClass('ays-pm-w-expanded').addClass('ays-pm-w-collapsed'); | |
| 14 | + $('.ays-pm-w-wn-arrow').html('▾'); | |
| 15 | + $toggle.text(poll_maker_ays_welcome.show_more).append($('<span/>',{class:'ays-pm-w-wn-arrow',html:'▾'})); | |
| 16 | + } | |
| 17 | + }); | |
| 5 | 18 | |
| 6 | - var video = '<div class="poll-maker-welcome-video-container"><iframe height="400" loading="lazy" src="https://www.youtube.com/embed/0dfJQdAwdL4" frameborder="0" allowfullscreen></iframe></div>'; | |
| 19 | + // Video lightbox | |
| 20 | + var $lightbox = $('#ays-pm-w-video-lightbox'); | |
| 21 | + var $iframe = $('#ays-pm-w-video-iframe'); | |
| 7 | 22 | |
| 8 | - var modal = $('<div class="poll-maker-welcome-modal"></div>'); | |
| 9 | - var modalContent = $('<div class="poll-maker-welcome-modal-content"></div>'); | |
| 10 | - var closeIcon = $('<span class="poll-maker-welcome-modal-close">×</span>'); | |
| 11 | - | |
| 12 | - modal.append(modalContent); | |
| 13 | - modalContent.append(closeIcon); | |
| 14 | - modalContent.append(video); | |
| 15 | - | |
| 16 | - $('body').append(modal); | |
| 17 | - | |
| 18 | - closeIcon.on('click', function () { | |
| 19 | - modal.remove(); | |
| 23 | + function closeLightbox() { | |
| 24 | + $lightbox.removeClass('ays-pm-w-show'); | |
| 25 | + setTimeout(function() { | |
| 26 | + $iframe.attr('src', ''); | |
| 27 | + }, 300); // Wait for fade out transition | |
| 28 | + } | |
| 29 | + | |
| 30 | + $('.ays-pm-w-video-card').on('click', function(){ | |
| 31 | + var videoId = $(this).data('video-id'); | |
| 32 | + if (videoId) { | |
| 33 | + $iframe.attr('src', 'https://www.youtube.com/embed/' + videoId); | |
| 34 | + $lightbox.addClass('ays-pm-w-show'); | |
| 35 | + } | |
| 20 | 36 | }); |
| 21 | 37 | |
| 22 | - $(document).on('keyup', function (event) { | |
| 23 | - if (event.key === 'Escape') { | |
| 24 | - modal.remove(); | |
| 25 | - } | |
| 26 | - }); | |
| 38 | + $('#ays-pm-w-video-lightbox-close').on('click', closeLightbox); | |
| 27 | 39 | |
| 28 | - modal.on('click', function (event) { | |
| 29 | - if (!$(event.target).closest('.poll-maker-welcome-modal-content').length) { | |
| 30 | - modal.remove(); | |
| 31 | - } | |
| 40 | + $lightbox.on('click', function(e){ | |
| 41 | + if ($(e.target).is($lightbox)) { | |
| 42 | + closeLightbox(); | |
| 43 | + } | |
| 32 | 44 | }); |
| 33 | - | |
| 34 | - } ); | |
| 35 | -})(jQuery); | |
| 45 | + }); | |
| 46 | +})(jQuery); | |