Last active
August 2, 2016 11:34
-
-
Save serefyarar/3d5533ccb6a75a0edf3dc876330f6a70 to your computer and use it in GitHub Desktop.
IMA SDK Custom Skip Button
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
player.on('ads.started',function(e){ | |
skipButton(player.ima.getAdsManager(),{ | |
'remaining' : 5, | |
'target' : '.video-js', | |
'btn_style' : { | |
'position': 'absolute', | |
'background': 'rgba(0, 0, 0, 0.85)', | |
'color': 'white', | |
'z-index': '9999999', | |
'border': '1px solid rgba(255,255,255,0.50)', | |
'padding': '10px 20px', | |
'margin': '0px 25px 25px 0px', | |
'bottom': '0px', | |
'right': '0px' | |
} | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var skipButton = function(manager,config){ | |
var remaining = config.remaining; | |
var currentAd = manager.getCurrentAd(); | |
if(!currentAd.isLinear()){ | |
return; | |
} | |
if(manager.getAdSkippableState()){ | |
return; | |
} | |
if(!(manager && manager.g && manager.g.b && manager.g.b.skippable)){ | |
return; | |
} | |
manager.addEventListener(google.ima.AdEvent.Type.ALL_ADS_COMPLETED, function (){ | |
$(".btn_skip").remove(); | |
}); | |
$(config.target).append('<button disabled type="button" class="btn_skip"><span>'+ remaining +'</span> saniye sonra reklamı geçebilirsiniz</button>'); | |
$(".btn_skip").css(config.btn_style).on('click',function(){ | |
var attr = $(this).attr('disabled'); | |
if (typeof attr !== typeof undefined && attr !== false) { | |
// Element has this attribute | |
}else{ | |
manager.stop(); | |
} | |
}); | |
function skipCheck(remaining){ | |
if(remaining < 1){ | |
$(".btn_skip").html("Reklamı geç").removeAttr('disabled'); | |
}else{ | |
$(".btn_skip span").text(remaining); | |
setTimeout(function(){ | |
skipCheck(remaining -1); | |
},1000); | |
} | |
} | |
skipCheck(remaining); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment