include ad_banner query code. cleaned up parser

This commit is contained in:
Matthew Kaito Juyuan Fu 2012-02-10 10:50:03 +08:00 committed by Christophe Vilayphiou
parent 436f039c1b
commit 8ef2d4b02e
4 changed files with 1372 additions and 21 deletions

View File

@ -68,6 +68,7 @@ module ParserBackEnd
c.define_tag 'javascripts' do |tag| c.define_tag 'javascripts' do |tag|
res = '' res = ''
res << "<script type='text/javascript' src='/static/jquery.js'></script>" res << "<script type='text/javascript' src='/static/jquery.js'></script>"
res << "<script type='text/javascript' src='/static/jquery.cycle.all.latest.js'></script>"
res << "<script type='text/javascript' src='/static/kernel.js'></script>" res << "<script type='text/javascript' src='/static/kernel.js'></script>"
page.design.javascripts.each do |js| page.design.javascripts.each do |js|
res << "<script type='text/javascript' src='#{js.file.url}'></script>" res << "<script type='text/javascript' src='#{js.file.url}'></script>"
@ -75,23 +76,25 @@ module ParserBackEnd
res res
end end
c.define_tag 'adbanner' do |tag| c.define_tag 'adbanner' do |tag|
ret = '' res = ''
ad_banner = AdBanner.first(conditions:{title: tag.attr["name"]}) ad_banner = AdBanner.first(conditions:{title: tag.attr["name"]})
ret << "<script type='text/javascript' src='http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.latest.js'></script>" res << "<script type='text/javascript'>
ret << "<script type='text/javascript'> $(document).ready(function() { $('.slideshow').cycle({ fx: '#{ad_banner.ad_fx.nil?? 'fade': ad_banner.ad_fx}' }); }); </script>" $(document).ready(function(){ $('#slideshow-#{ad_banner.title}').cycle({after: onAfter,timeout:1 ,fx: '#{ad_banner.ad_fx.nil?? 'fade': ad_banner.ad_fx}' }); });
</script>"
ret << "<div id='#{tag.attr['name']}' ad_banner_id='#{ad_banner.id}' class='editable' style='border:solid 1px; margin:5px; padding:5px;'>" res << "<div id='#{tag.attr['name']}' ad_banner_id='#{ad_banner.id}' class='editable' style='border:solid 1px; margin:5px; padding:5px;'>"
ret << "<div class='edit_link' style='display:none'>" res << "<div class='edit_link' style='display:none'>"
ret << " <a href='#{edit_admin_ad_banner_path(ad_banner.id)}' class='nav'>#{t(:edit)}</a>" res << " <a href='#{edit_admin_ad_banner_path(ad_banner.id)}' class='nav'>#{t(:edit)}</a>"
ret << '</div>' res << '</div>'
#================================== #==================================
ret << "<div class='slideshow'>" res << "<div id='slideshow-#{ad_banner.title}'>"
ad_banner.ad_images.each do |ad_image| ad_banner.ad_images.each do |ad_image|
ret << "<img src='#{ad_image.file}' />" res << "<img src='#{ad_image.file}' />"
end end
ret << "</div>" res << "</div>"
#================================== #==================================
ret << "</div>" res << "</div>"
end end
c.define_tag 'layout_part' do |tag| c.define_tag 'layout_part' do |tag|
part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s } part = page.page_parts.detect{ |p| p.name.to_s == tag.attr['name'].to_s }

View File

@ -76,6 +76,7 @@ module ParserFrontEnd
c.define_tag 'javascripts' do |tag| c.define_tag 'javascripts' do |tag|
res = '' res = ''
res << "<script type='text/javascript' src='/static/jquery.js'></script>" res << "<script type='text/javascript' src='/static/jquery.js'></script>"
res << "<script type='text/javascript' src='/static/jquery.cycle.all.latest.js'></script>"
res << "<script type='text/javascript' src='/static/kernel.js'></script>" res << "<script type='text/javascript' src='/static/kernel.js'></script>"
page.design.javascripts.each do |js| page.design.javascripts.each do |js|
res << "<script type='text/javascript' src='#{js.file.url}'></script>" res << "<script type='text/javascript' src='#{js.file.url}'></script>"
@ -86,16 +87,11 @@ module ParserFrontEnd
res = '' res = ''
ad_banner = AdBanner.first(conditions:{title: tag.attr["name"]}) ad_banner = AdBanner.first(conditions:{title: tag.attr["name"]})
if ad_banner.display? if ad_banner.display?
res << "<script type='text/javascript' src='http://cloud.github.com/downloads/malsup/cycle/jquery.cycle.all.latest.js'></script>" res << "<script type='text/javascript'>
res << "<script type='text/javascript'>function onAfter(e) { $(document).ready(function(){ $('#slideshow-#{ad_banner.title}').cycle({after: onAfter,timeout:1 ,fx: '#{ad_banner.ad_fx.nil?? 'fade': ad_banner.ad_fx}' }); });
var parent = $(this).parent(); </script>"
var time_to_next = $(this).attr('time_to_next');
parent.cycle('pause');
setTimeout(function(){parent.cycle('resume')},time_to_next);
} $(document).ready(function() { $('.slideshow').cycle({after: onAfter,timeout:1 ,fx: '#{ad_banner.ad_fx.nil?? 'fade': ad_banner.ad_fx}' }).children('img').click(function(){if($(this).attr('link_open')=='new_window'){window.open($(this).attr('link_url'));} else{document.location.href=$(this).attr('link_url');}});; }); </script>" res << "<div id='slideshow-#{ad_banner.title}'>"
res << "<div class='slideshow'>"
ad_banner.ad_images.each do |ad_image| ad_banner.ad_images.each do |ad_image|
res << "<img src='#{ad_image.file}' " res << "<img src='#{ad_image.file}' "
res << "alt='#{ad_image.picture_intro || ' '}' " res << "alt='#{ad_image.picture_intro || ' '}' "

File diff suppressed because it is too large Load Diff

View File

@ -17,4 +17,25 @@ function ajax_load_proc(wapper,url){
if(textSta == 'error') if(textSta == 'error')
wapper.html("Loading Failed"); wapper.html("Loading Failed");
}); });
} }
// Ad Banner FX code [start]
function onAfter(e) {
var parent = $(this).parent();
var time_to_next = $(this).attr('time_to_next');
parent.cycle('pause');
setTimeout(function(){parent.cycle('resume')},time_to_next);
}
$(document).ready(function() {
$('.slideshow').children('img').click(function()
{
if($(this).attr('link_open')=='new_window')
{
window.open($(this).attr('link_url'));
}
else
{
document.location.href=$(this).attr('link_url')
}
})
});
// Ad Banner FX code [end]