Commit b430835f authored by christian.zenker's avatar christian.zenker

- bugfix from last commit

- encapsulated the init JS for banner rotation in a function to make it easily work with banners that are in the sourcecode and not loaded via ajax


git-svn-id: http://svn.t3o.typo3.org/extensions/projects/t3org/randombanners/trunk@1739 e8cb78a8-64f2-4011-8042-bd1ea5058d47
parent 9ca92883
......@@ -75,7 +75,15 @@ class Tx_Randombanners_Controller_BannerController extends Tx_Extbase_MVC_Contro
public function listAction($numberOfBannersShown=0) {
// initialization
$banners = $this->bannerRepository->findRandomBanners();
foreach ($banners as $banner) {
if (!($banner->getLogo() instanceof Tx_Extbase_Domain_Model_Dam)) {
$banner->setLogo(Tx_ExtbaseDam_Utility_Dam::getOne('tx_randombanners_domain_model_banner', $banner->getUid(), 'tx_randombanner_dam_images'));
}
// increment the displayed counter
$banner->setDisplayedThisMonth($banner->getDisplayedThisMonth() + 1); // seems rather useless when caching is enabled
}
$this->view->assign('banners', $banners);
}
......
......@@ -8,58 +8,51 @@ function clickBanner(el) {
});
}
$(document).ready(function() {
if ($('#randombanners').length > 0) {
$.ajax({
url: 'index.php?type=69&tx_randombanners_list[action]=list&tx_randombanners_list[controller]=Banner&tx_randombanners_list[numberOfBannersShown]=' + parseInt($('#randombannersNumber').html()),
success: function(html) {
$('#randombanners').append(html);
/* platin members at the left navigation */
if($(".d.navigationbanners .tx-randombanners").length > 0) {
$(".d.navigationbanners .tx-randombanners-item").each(function(){
if($(this).index() > 1)
$(this).css("display","none");
});
$(".d.navigationbanners .tx-randombanners-item:eq(0), .d.navigationbanners .tx-randombanners-item:eq(1)").addClass("shown");
}
/* platin members at the homepage */
if($(".gc .tx-randombanners").length > 0) {
for(var banneri = 0; banneri < 4; banneri++) {
banner_position_array[banneri] = banneri;
}
for(var bannerfields = 0; bannerfields < 3; bannerfields++)
$(".gc .tx-randombanners:eq(0)").clone().insertAfter(".tx-randombanners:eq(0)");
for(var bannerfields = 0; bannerfields < 4; bannerfields++){
if(bannerfields%2 != 0)
$(".gc .tx-randombanners:eq("+bannerfields+")").addClass("rightbanner");
$(".gc .tx-randombanners:eq("+bannerfields+")").children(".tx-randombanners-item").addClass("banner"+((bannerfields)));
}
function initBanners() {
/* platin members at the left navigation */
if($(".d.navigationbanners .tx-randombanners").length > 0) {
$(".d.navigationbanners .tx-randombanners-item").each(function(){
if($(this).index() > 1)
$(this).css("display","none");
});
$(".d.navigationbanners .tx-randombanners-item:eq(0), .d.navigationbanners .tx-randombanners-item:eq(1)").addClass("shown");
}
/* platin members at the homepage */
if($(".gc .tx-randombanners").length > 0) {
for(var banneri = 0; banneri < 4; banneri++) {
banner_position_array[banneri] = banneri;
}
for(var bannerfields = 0; bannerfields < 3; bannerfields++)
$(".gc .tx-randombanners:eq(0)").clone().insertAfter(".tx-randombanners:eq(0)");
$(".gc .tx-randombanners-item").each(function(){
$(this).css("display","none");
});
$(".gc .tx-randombanners:eq(0) .tx-randombanners-item:eq(0), .gc .tx-randombanners:eq(1) .tx-randombanners-item:eq(1), .gc .tx-randombanners:eq(2) .tx-randombanners-item:eq(2), .gc .tx-randombanners:eq(3) .tx-randombanners-item:eq(3)").addClass("shown").fadeIn("slow", function() {
for(var bannerfields = 0; bannerfields < 4; bannerfields++){
if(bannerfields%2 != 0)
$(".gc .tx-randombanners:eq("+bannerfields+")").addClass("rightbanner");
$(".gc .tx-randombanners:eq("+bannerfields+")").children(".tx-randombanners-item").addClass("banner"+((bannerfields)));
}
});
$(".gc .tx-randombanners-item").each(function(){
$(this).css("display","none");
});
$(".gc .tx-randombanners:eq(0) .tx-randombanners-item:eq(0), .gc .tx-randombanners:eq(1) .tx-randombanners-item:eq(1), .gc .tx-randombanners:eq(2) .tx-randombanners-item:eq(2), .gc .tx-randombanners:eq(3) .tx-randombanners-item:eq(3)").addClass("shown").fadeIn("slow", function() {
banner_amount = $(".gc .tx-randombanners:first .tx-randombanners-item").length;
var rotateNext = function() {
var banneri = $(this).data('no');
var next = (banneri + 1)%4;
current_banner = banner_position_array[banneri];
new_banner = banner_position_array[banneri] = (banner_position_array[banneri]-1+banner_amount)%banner_amount;
$(".banner"+banneri+":eq("+current_banner+")").data('banners', {banneri: banneri, new_banner: new_banner}).fadeOut("slow", function() {
$(".banner"+$(this).data('banners').banneri+":eq("+$(this).data('banners').new_banner+")").fadeIn("slow", function() { $(this).addClass("shown")});
});
$('.gc .tx-randombanners:eq(' + next + ')').data('no', next).oneTime('1s', 'premiumbanner', rotateNext);
}
$('.gc .tx-randombanners:eq(0)').data('no', 0).oneTime('1s', 'premiumbanner', rotateNext);
}
}
});
banner_amount = $(".gc .tx-randombanners:first .tx-randombanners-item").length;
var rotateNext = function() {
var banneri = $(this).data('no');
var next = (banneri + 1)%4;
current_banner = banner_position_array[banneri];
new_banner = banner_position_array[banneri] = (banner_position_array[banneri]-1+banner_amount)%banner_amount;
$(".banner"+banneri+":eq("+current_banner+")").data('banners', {banneri: banneri, new_banner: new_banner}).fadeOut("slow", function() {
$(".banner"+$(this).data('banners').banneri+":eq("+$(this).data('banners').new_banner+")").fadeIn("slow", function() { $(this).addClass("shown")});
});
$('.gc .tx-randombanners:eq(' + next + ')').data('no', next).oneTime('1s', 'premiumbanner', rotateNext);
}
$('.gc .tx-randombanners:eq(0)').data('no', 0).oneTime('1s', 'premiumbanner', rotateNext);
}
$(document).everyTime(5000,function(){
$(document).everyTime(5000,function(){
if($(".d.navigationbanners .tx-randombanners").length > 0) {
var first_shown = $(".d.navigationbanners #randombanners .shown:first").index(".tx-randombanners-item");
var last_shown = $(".d.navigationbanners #randombanners .shown:last").index(".tx-randombanners-item");
......@@ -81,4 +74,23 @@ $(document).ready(function() {
});
}
});
}
$(document).ready(function() {
if ($('#randombanners').length > 0) {
if($('#randombannersNumber')) {
// if: load via ajax should be done
$.ajax({
url: 'index.php?type=69&tx_randombanners_list[action]=list&tx_randombanners_list[controller]=Banner&tx_randombanners_list[numberOfBannersShown]=' + parseInt($('#randombannersNumber').html()),
success: function(html) {
$('#randombanners').append(html);
initBanners();
}
});
} else {
initBanners();
}
}
});
\ No newline at end of file
......@@ -11,7 +11,7 @@
),
array(
'Banner' => 'list',
'Banner' => 'list,show',
)
);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment