adbanner-test/modules/ad_banner/_ad_banner_widget2_video.ht...

358 lines
14 KiB
Plaintext
Raw Normal View History

2021-09-02 02:40:58 +00:00
<div class="w-ad-banner ad-banner-widget-2 w-ba-banner ba-banner-widget-1 ba-banner-widget-youtube">
<div class="w-ad-banner__wrap w-ba-banner__wrap cycle-slideshow"
2021-04-10 15:16:17 +00:00
data-list="images"
data-level="0"
data-cycle-slides=".w-ba-banner__slide"
data-cycle-log="false"
data-overlay=".w-ad-banner__overlay_{{subpart-id}}"
data-overlay-template="<h2><span>{{title}}</span></h2>{{desc}}"
data-cycle-auto-height="{{base_image}}"
data-cycle-speed="{{speed}}"
data-cycle-timeout="{{timeout}}"
data-cycle-fx="{{ad_fx}}"
data-pager=".banner_caption_{{subpart-id}}"
2022-02-04 04:23:11 +00:00
data-pager-template="<li><button title='pager'></button></li>"
2021-04-10 15:16:17 +00:00
data-pager-active-class="active-slide"
data-cycle-youtube="true"
data-cycle-youtube-autostart="false"
data-cycle-swipe="true"
data-cycle-prev=".banner_prev"
data-cycle-next=".banner_next"
data-cycle-pause-on-hover="true"
style="padding-bottom: 56.25%;"
>
{{html}}
</div>
<div class="ad-overlay w-ad-banner__overlay_{{subpart-id}}"></div>
2021-09-02 02:40:58 +00:00
<div class="w-ba-banner__caption w-ad-banner__pager-2 banner-pager banner_caption_{{subpart-id}}"></div>
2022-02-04 04:23:11 +00:00
<ul class="controlplay"><a href="javascript:;" class="resume-slide active" title="<%= I18n.t("ad_banner.resume") %>"><i aria-hidden="true" aria-label="<%= I18n.t("ad_banner.resume") %>"></i></a><a href="javascript:;" class="pause-slide" title="<%= I18n.t("ad_banner.pause") %>"><i aria-hidden="true" aria-label="<%= I18n.t("ad_banner.pause") %>"></i></a></ul>
2021-04-10 15:16:17 +00:00
<ul class="button-mid">
2022-02-16 08:45:55 +00:00
<i class="fa fa-angle-left prev-button" aria-label="<%= I18n.t("ad_banner.prev") %>"></i>
<i class="fa fa-angle-right next-button" aria-label="<%= I18n.t("ad_banner.next") %>"></i>
2021-04-10 15:16:17 +00:00
</ul>
</div>
</div>
<script type="text/javascript">
2021-11-15 06:57:34 +00:00
var ad_trigger_time;
2021-04-10 15:16:17 +00:00
if (typeof ad_banners_count === 'undefined'){
var ad_banners_count = 0;
}
2021-11-14 04:43:46 +00:00
function ad_audio_button(ele,is_stop){
2021-11-15 04:50:02 +00:00
var $self = $(ele);
2021-11-15 08:45:04 +00:00
var button_container = $self.parents('.ba-banner-widget-youtube').eq(0);
2021-11-14 04:43:46 +00:00
if (is_stop){
2021-11-15 09:29:10 +00:00
button_container.find('.jarallax-video-audio').remove();
2021-11-14 04:43:46 +00:00
}else{
2021-11-14 05:12:33 +00:00
var audio_div;
2021-11-15 04:50:02 +00:00
if ($self.hasClass('have-audio')){
2022-02-04 04:44:14 +00:00
audio_div = $('<button title="<%= I18n.t("ad_banner.muted") %>" class="jarallax-video-audio"><i class="fas fa-volume-up" aria-label="<%= I18n.t("ad_banner.muted") %>" aria-hidden="true"></i></button>');
2021-11-14 05:12:33 +00:00
}else{
2022-02-04 04:44:14 +00:00
audio_div = $('<button title="<%= I18n.t("ad_banner.unmuted") %>" class="jarallax-video-audio"><i class="fas fa-volume-mute" aria-label="<%= I18n.t("ad_banner.unmuted") %>" aria-hidden="true"></i></button>');
2021-11-14 05:12:33 +00:00
}
2021-11-15 06:31:09 +00:00
audio_div.click(function(event) {
2021-11-15 06:57:34 +00:00
var currentTime = new Date();
if (ad_trigger_time&&currentTime-ad_trigger_time<500){
return false;
}else{
ad_trigger_time = currentTime;
}
2021-11-15 06:31:09 +00:00
event.stopPropagation();
2021-11-15 06:35:20 +00:00
var $video = $self.find('video');
if ($self.hasClass('have-audio')){
$self.removeClass('have-audio');
2022-02-04 04:44:14 +00:00
$(this).attr('title','<%= I18n.t("ad_banner.unmuted") %>').find('i.fas').attr('class','fas fa-volume-mute').attr('aria-label','<%= I18n.t("ad_banner.unmuted") %>');
2021-11-15 06:35:20 +00:00
}else{
$self.addClass('have-audio');
2022-02-04 04:44:14 +00:00
$(this).attr('title','<%= I18n.t("ad_banner.muted") %>').find('i.fas').attr('class','fas fa-volume-up').attr('aria-label','<%= I18n.t("ad_banner.muted") %>');
2021-11-15 06:35:20 +00:00
}
if ($video.length>0){
$self.jPlayer("mute", !$self.data().jPlayer.options.muted);
}else{//youtube
2021-11-15 07:12:13 +00:00
var player = $self.find('iframe').data("yt_player");
if (player.isMuted()){
player.unMute();
}else{
player.mute();
}
2021-11-15 06:35:20 +00:00
}
2021-11-15 06:31:09 +00:00
});
2021-11-15 08:45:04 +00:00
button_container.find('.jarallax-video-audio').remove();
button_container.append(audio_div);
2021-11-14 04:43:46 +00:00
}
}
2021-04-10 15:16:17 +00:00
if(document.getElementById("youtube-iframe-api") == null){
var tag = document.createElement('script');
tag.setAttribute("id", "youtube-iframe-api");
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
}
$("*[data-yt-binded=0]").each(function(){
$(this).attr("data-yt-binded","1");
var obj = $(this).find("iframe");
obj.attr("id",$(this).data("youtube-id") + "_" + ad_banners_count);
ad_banners_count++;
})
2021-04-10 15:16:17 +00:00
if (typeof onYouTubeIframeAPIReady !== 'function'){
2021-11-15 07:12:13 +00:00
$(document).ready(function() {
2021-11-15 07:55:22 +00:00
$(document).on('touchstart click mousedown',".jarallax-video-audio",function(){
2021-11-15 07:12:13 +00:00
$(this).trigger('click');
});
2021-11-15 06:57:34 +00:00
});
if(window.yt_players == undefined)
window.yt_players = {};
2022-05-19 03:30:49 +00:00
function find_out_yt_event_list_key(yt_player){
var defalt_key = 'o';
2022-05-19 03:35:14 +00:00
var all_keys = Object.keys(yt_player).filter(function(s){return s.length == 1});
2022-05-19 03:30:49 +00:00
var prop_nums_thresh = 6;
if(all_keys.indexOf(defalt_key) != -1){
if((yt_player[defalt_key] instanceof Object) && Object.keys(yt_player[defalt_key]).length > prop_nums_thresh){
return defalt_key;
}
}
var event_key;
all_keys.forEach(function(k){
if((yt_player[k] instanceof Object) && Object.keys(yt_player[k]).length > prop_nums_thresh){
event_key = k;
return false;
}
})
return event_key;
}
function find_out_yt_event_list_count_key(yt_player, event_list_key){
var defalt_key = 'v';
2022-05-19 03:35:14 +00:00
var all_keys = Object.keys(yt_player).filter(function(s){return s.length == 1});
2022-05-19 03:30:49 +00:00
var equal_count = yt_player[event_list_key].length;
if(all_keys.indexOf(defalt_key) != -1){
if(yt_player[defalt_key] == equal_count){
return defalt_key;
}
}
var count_key;
all_keys.forEach(function(k){
if(yt_player[k] == equal_count){
count_key = k;
return false;
}
})
return count_key;
}
function find_out_yt_event_list_array_key(event_dict){
var defalt_key = 'i';
var all_keys = Object.keys(event_dict);
if(all_keys.indexOf(defalt_key) != -1){
if(Array.isArray(event_dict[defalt_key]) && event_dict[defalt_key].indexOf('onStateChange') != -1){
return defalt_key;
}
}
var array_key;
all_keys.forEach(function(k){
if(Array.isArray(event_dict[k]) && event_dict[k].indexOf('onStateChange') != -1){
array_key = k;
return false;
}
})
return array_key;
}
function find_out_yt_event_relation_key(event_dict){
var defalt_key = 'j';
var all_keys = Object.keys(event_dict);
if(all_keys.indexOf(defalt_key) != -1){
if((event_dict[defalt_key] instanceof Object) && event_dict[defalt_key]['onStateChange']){
return defalt_key;
}
}
var relation_key;
all_keys.forEach(function(k){
if((event_dict[k] instanceof Object) && event_dict[k]['onStateChange']){
relation_key = k;
return false;
}
})
return relation_key;
}
2021-04-10 15:16:17 +00:00
function onYouTubeIframeAPIReady(){
$(".w-ba-banner").each(function(i,banner){
var iframes = $(banner).find("iframe");
if(iframes.length > 0){
var id = $(banner).attr("data-subpart-id");
if(yt_players[id] == undefined)
yt_players[id] = {};
var remove_ids = [];
Object.keys(yt_players[id]).forEach(function(k){
var yt_player = yt_players[id][k];
if($(yt_player.getIframe()).length == 0){
yt_player.destroy();
remove_ids.push(k);
}
})
remove_ids.forEach(function(k){
delete yt_players[id][k];
})
iframes.each(function(i,iframe){
var yt_player = yt_players[id][$(iframe).attr("id")];
if(yt_player){
}else{
yt_player = new YT.Player($(iframe).attr("id"), {
events: {
'onReady': function(event){
var height = $(event.target.getIframe()).height();
2021-11-15 08:45:04 +00:00
var banner_wrap = $(iframe).parents('.w-ba-banner__wrap').eq(0);
2022-03-07 11:25:29 +00:00
banner_wrap.height(height).css({"padding-bottom":"","padding-top":""});
banner_wrap.find(".cycle-carousel-wrap").css("top","3em");
2022-03-04 07:51:03 +00:00
try{
delete (event.target.B || event.target.H || event.target.I).onStateChange;
}catch(e){console.log("{onReady: true, onStateChange: true} missing!")};
2022-05-19 03:30:49 +00:00
var event_list_key = find_out_yt_event_list_key(event.target);
if(event_list_key){
var event_dict = event.target[event_list_key];
var array_key = find_out_yt_event_list_array_key(event_dict);
var count_key = find_out_yt_event_list_count_key(event_dict, array_key);
var relation_key = find_out_yt_event_relation_key(event_dict);
var onStateChange_idx = event_dict[relation_key].onStateChange;
onStateChange_idx.reverse();
var event_size = 3;
onStateChange_idx.forEach(function(start_idx){
event_dict[array_key].splice(start_idx,event_size);
});
event_dict[relation_key].onStateChange = [];
event_dict[count_key] = event_dict[array_key].length;
event.target.addEventListener('onStateChange',onPlayerStateChange);
}else{
console.log("YT player changes its variables!")
}
{{extra_ready_script}}
},
'onStateChange': onPlayerStateChange
}
});
yt_players[id][$(iframe).attr("id")] = yt_player;
$(iframe).data("yt_player",yt_player);
}
})
}
2021-04-10 15:16:17 +00:00
})
}
function onPlayerStateChange(event){
2021-04-10 16:34:57 +00:00
var iframe = $(event.target.h),
2021-04-10 15:16:17 +00:00
cyclediv = iframe.parents("div.cycle-slideshow");
var widget = cyclediv.parents('.ba-banner-widget-youtube');
2021-04-10 15:16:17 +00:00
if(event.data == YT.PlayerState.PLAYING || event.data == YT.PlayerState.BUFFERING){
cyclediv[0].need_resume = !(cyclediv.hasClass("cycle-paused"));
2021-04-10 15:16:17 +00:00
cyclediv.cycle("pause");
2021-04-10 16:34:57 +00:00
widget.find('.banner-pager,.controlplay,.button-mid,.ad-overlay').css('visibility','hidden')
2021-11-15 05:08:42 +00:00
ad_audio_button(iframe.parents(".w-ad-banner__slide").eq(0),false);
}else if(event.data == YT.PlayerState.UNSTARTED || event.data == YT.PlayerState.PAUSED || event.data == YT.PlayerState.ENDED){
if(cyclediv[0].need_resume)
cyclediv.cycle("resume");
2021-04-10 16:34:57 +00:00
widget.find('.banner-pager,.controlplay,.button-mid,.ad-overlay').css('visibility','')
2021-11-15 05:08:42 +00:00
ad_audio_button(iframe.parents(".w-ad-banner__slide").eq(0),true);
2021-04-10 15:16:17 +00:00
}
{{extra_state_chnage_script}}
2021-04-10 15:16:17 +00:00
}
2021-10-27 10:15:17 +00:00
}
2021-04-10 15:16:17 +00:00
$(document).ready(function(){
2021-04-10 16:34:57 +00:00
window.onYouTubePlayerAPIReady = function() {
onYouTubeIframeAPIReady.apply(this,arguments);
2021-04-10 16:34:57 +00:00
};
var banner_wrap = $(".w-ba-banner__wrap[data-overlay=\".w-ad-banner__overlay_{{subpart-id}}\"]");
var opts = banner_wrap.data('cycle.opts');
banner_wrap.on('cycle-paused',function(opts){
var controlplay = $(this).nextAll(".controlplay");
if(controlplay.length != 0){
controlplay.find(".resume-slide").removeClass("active");
controlplay.find(".pause-slide").addClass("active");
}
})
banner_wrap.on('cycle-resumed',function(opts){
var controlplay = $(this).nextAll(".controlplay");
if(controlplay.length != 0){
controlplay.find(".resume-slide").addClass("active");
controlplay.find(".pause-slide").removeClass("active");
}
})
2021-10-14 03:14:55 +00:00
/*
var height = opts.slides.filter('.active').height() || opts.slides.height();
2021-10-14 03:14:55 +00:00
banner_wrap.height(height)*/
2022-05-19 05:37:07 +00:00
banner_wrap.css("padding-bottom","");
{{extra_document_ready_script}}
2022-06-14 02:41:44 +00:00
$('[data-subpart-id="{{subpart-id}}"] .pause-slide').click(function(){
2021-04-10 15:16:17 +00:00
$(this).parent("ul").parent('.w-ba-banner').find(".cycle-slideshow").cycle('pause');
$(this).addClass('active');
$(this).parents('.controlplay').eq(0).find('.resume-slide').removeClass('active');
2021-04-10 15:16:17 +00:00
});
2022-06-14 02:41:44 +00:00
$('[data-subpart-id="{{subpart-id}}"] .resume-slide').click(function(){
2021-04-10 15:16:17 +00:00
$(this).parent("ul").parent('.w-ba-banner').find(".cycle-slideshow").cycle('resume');
$(this).addClass('active');
$(this).parents('.controlplay').eq(0).find('.pause-slide').removeClass('active');
2021-04-10 15:16:17 +00:00
});
2022-06-14 02:41:44 +00:00
$('[data-subpart-id="{{subpart-id}}"] .next-button').click(function(){
2021-04-10 15:16:17 +00:00
$(this).parent("ul").parent('.w-ba-banner').find(".cycle-slideshow").cycle("next");
})
2022-06-14 02:41:44 +00:00
$('[data-subpart-id="{{subpart-id}}"] .prev-button').click(function(){
2021-04-10 15:16:17 +00:00
$(this).parent("ul").parent('.w-ba-banner').find(".cycle-slideshow").cycle("prev");
})
var resize_timeout_id;
$(window).resize(function(){
if(resize_timeout_id){
window.clearTimeout(resize_timeout_id);
}
resize_timeout_id = window.setTimeout(function(){
var banner_wrap = $(".w-ba-banner__wrap[data-overlay=\".w-ad-banner__overlay_{{subpart-id}}\"]");
var opts = banner_wrap.data('cycle.opts');
var height = opts.slides.filter('.active').height() || opts.slides.height();
banner_wrap.height(height).css("padding-bottom","");
},300);
})
2021-04-10 15:16:17 +00:00
})
</script>
<style type="text/css">
2021-11-14 04:43:46 +00:00
.jarallax-video-audio{
2021-11-15 08:04:58 +00:00
z-index: 201;
2021-11-14 04:43:46 +00:00
font-size: 36px;
color: #FFF;
text-align: center;
position: absolute;
top: 2%;
right: 2%;
height: 66px;
width: 66px;
border-radius: 50%;
line-height: 1.8;
cursor: pointer;
border: 2px solid rgba(255,255,255,.6);
background-color: rgba(0,0,0,.6);
transition: all 1.2s ease;
}
2021-11-15 06:26:59 +00:00
@media (max-width: 768px){
.jarallax-video-audio{
top: 50%;
}
}
2022-01-21 08:50:50 +00:00
.jarallax-video-audio:hover,.jarallax-video-audio:focus{
2021-11-14 04:43:46 +00:00
color: #FFC500;
transition: all 0.6s ease;
}
2021-08-31 09:31:24 +00:00
.w-ba-banner .controlplay .resume-slide.active i{
2021-04-10 15:16:17 +00:00
color: #32D9C3;
}
2021-08-31 09:31:24 +00:00
.w-ba-banner .controlplay .pause-slide.active i{
2021-04-10 15:16:17 +00:00
color: #ff4500;
}
2021-08-31 09:31:24 +00:00
.w-ba-banner .controlplay{
width: auto;
}
.w-ba-banner .button-mid{
position: absolute;
width: 100%;
height: 100%;
2021-09-02 02:59:37 +00:00
top: 0;
left: 0;
2021-08-31 09:31:24 +00:00
}
.next-button,.prev-button{
cursor: pointer;
}
2021-09-06 15:01:21 +00:00
</style>