Fix Ad_Banner Loading Problem (Not complete)

This commit is contained in:
Manson Wang 2013-09-30 21:03:38 +08:00
parent e5ea34d088
commit e2d09c7379
2 changed files with 39 additions and 26 deletions

View File

@ -10,18 +10,9 @@
</div> </div>
</div> </div>
<script type='text/javascript'> <script type='text/javascript'>
$(document).ready(function(){ var banner = {"banner_name":"#slideshow-<%= @ad_banner.title.dehumanize %>",
jQuery(function( $ ){ "banner_fx":"<%= @ad_banner.ad_fx.nil? ? 'fade': @ad_banner.ad_fx %>",
"banner_pager":".banner_nav-<%= @ad_banner.title.dehumanize %>"
$('#slideshow-<%= @ad_banner.title.dehumanize %>').cycle({ };
delay: -1000, banners.push(banner);
fx: "<%= @ad_banner.ad_fx.nil? ? 'fade': @ad_banner.ad_fx %>",
timeoutFn: getTimeout,
pager: '.banner_nav-<%= @ad_banner.title.dehumanize %>',
pagerAnchorBuilder: function(idx, slide) {
return "<li><a href='#'></a></li>";
}
});
});
});
</script> </script>

View File

@ -1,26 +1,48 @@
$(document).ready(function() { var banners = [];
var banner_index = 0;
$(document).ready(function() {
$.each($(".dymanic_load"),function(){ $.each($(".dymanic_load"),function(){
if($(this).attr("path")==''){$(this).html("App setting Failed");} if($(this).attr("path")==''){$(this).html("App setting Failed");}
if($(this).attr("path")!=''){ if($(this).attr("path")!=''){
ajax_load_proc($(this),$(this).attr("path")); if($(this).attr("path").indexOf("show_banner")>0){
ajax_load_proc($(this),$(this).attr("path"),"true");
}else{
ajax_load_proc($(this),$(this).attr("path"),$(this).attr("path"));
} }
} }});
);
$("#main_content").addClass("module"); $("#main_content").addClass("module");
}); });
function ajax_load_proc(wapper,url){ function ajax_load_proc(wapper,url,isBanner){
$.get(encodeURI(url), {}, function(respText,textSta,XML){ $.get(encodeURI(url), {}, function(respText,textSta,XML){
if (textSta == 'success') { if (textSta == 'success') {
if(isBanner=="true"){
wapper.html(respText); wapper.html(respText);
setTimeout("BannerCycle()", 2500);
}else{
wapper.html(respText);
}
}; };
if(textSta == 'error') if(textSta == 'error')
wapper.html("Loading Failed<br/> <a href='"+$(this).attr('path')+"'>Go See</a>"); wapper.html("Loading Failed<br/> <a href='"+$(this).attr('path')+"'>Go See</a>");
}); });
} }
function BannerCycle(){
var banner = banners[banner_index];
banner_index++;
$(banner.banner_name).ready(function() {
$(banner.banner_name).cycle({
delay: -1000,
fx: banner.banner_fx,
timeoutFn: getTimeout,
pager: banner.banner_pager,
pagerAnchorBuilder: function(idx, slide) { return "<li><a href='#'></a></li>"; }
});
});
}
// Ad Banner FX code [start] // Ad Banner FX code [start]
function getTimeout() { function getTimeout() {
return $(this).attr('time_to_next'); return $(this).attr('time_to_next');