From 76ba7087b2848775fe0dddc4317a5080b6ad3c8e Mon Sep 17 00:00:00 2001 From: Manson Wang Date: Tue, 15 Oct 2013 19:33:31 +0800 Subject: [PATCH] Fix Ad_Banner frontend for IE8 Fix backend bug in editing banner Translation Added --- app/assets/javascripts/kernel.js | 64 +++++++++++++------ .../admin/ad_banners_controller.rb | 1 + app/views/admin/ad_banners/_edit.html.erb | 56 ++++++++-------- app/views/admin/ad_banners/_index.html.erb | 10 ++- app/views/admin/ad_banners/_new.html.erb | 56 ++++++++-------- app/views/front/show_banner.html.erb | 25 +++----- .../ad_banner/config/locales/en.yml | 6 ++ .../ad_banner/config/locales/zh_tw.yml | 6 ++ 8 files changed, 134 insertions(+), 90 deletions(-) diff --git a/app/assets/javascripts/kernel.js b/app/assets/javascripts/kernel.js index a05a7f40..6821079f 100644 --- a/app/assets/javascripts/kernel.js +++ b/app/assets/javascripts/kernel.js @@ -1,30 +1,58 @@ +var banners = []; +var banner_index = 0; + $(document).ready(function() { - $.each($(".dymanic_load"),function(){ - if($(this).attr("path")==''){$(this).html("App setting Failed");} - - if($(this).attr("path")!=''){ - ajax_load_proc($(this),$(this).attr("path")); - } + if($(this).attr("path")==''){ + $(this).html("App setting Failed"); + }else{ + // Check if this App is AD_Banner + 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"); + } }); -function ajax_load_proc(wapper,url){ + $("#main_content").addClass("module"); +}); + +function ajax_load_proc(wapper,url,isBanner){ $.get(encodeURI(url), {}, function(respText,textSta,XML){ - if (textSta == 'success') { - wapper.html(respText); - }; - if(textSta == 'error') - wapper.html("Loading Failed
Go See"); + if (textSta == 'success') { + if(isBanner=="true"){ + wapper.html(respText); + var banner = banners[banner_index]; + $(banner.banner_name+" > img").each(function(){ + $(this).load(function(){ banner.image_loaded++; }); + }); + BannerCycle(banner_index); + banner_index++; + }else{ + wapper.html(respText); + } + }; + if(textSta == 'error') + wapper.html("Loading Failed
Go See"); }); } -// Ad Banner FX code [start] -function getTimeout() { - return $(this).attr('time_to_next'); -} +function BannerCycle(banner_index){ + var banner = banners[banner_index]; + // Wait untill all images are loaded + if (banner.image_loaded==$(banner.banner_name+" img").length){ + $(banner.banner_name).cycle({ + delay: -1000, + fx: banner.banner_fx, + timeout: banner.time_to_next, + pager: banner.banner_pager, + pagerAnchorBuilder: function(idx, slide) { return "
  • "; } + }); + }else{ + setTimeout("BannerCycle("+banner_index+")",500); + } +} $(document).ready(function() { $(document).on('click', '.slideshow img', function() diff --git a/app/controllers/admin/ad_banners_controller.rb b/app/controllers/admin/ad_banners_controller.rb index 48e8f00e..989eb0eb 100644 --- a/app/controllers/admin/ad_banners_controller.rb +++ b/app/controllers/admin/ad_banners_controller.rb @@ -40,6 +40,7 @@ class Admin::AdBannersController < OrbitBackendController def edit @ad_banner = AdBanner.find(params[:id]) + render layout: false end def update diff --git a/app/views/admin/ad_banners/_edit.html.erb b/app/views/admin/ad_banners/_edit.html.erb index 88e88231..91557d2c 100644 --- a/app/views/admin/ad_banners/_edit.html.erb +++ b/app/views/admin/ad_banners/_edit.html.erb @@ -1,25 +1,31 @@ -
    - <%= form_for(:ad_banner, :url => admin_ad_banner_path(:ad_banner), :remote => true) do |f| %> -
    - Ad Banner - - <%= f.text_field :title, :class=>"input-large", :placeholder=>"Banner Name" %> - Banner Name only english - - <%= f.text_field :transition_sec, :class => 'input-large', :placeholder => 'Time' %> - Please enter the number of seconds - - <%= f.text_field :best_size, :class=>"input-large", :placeholder=>"Banner Size" %> - Best Size EX:120x30 - - <%= f.select :ad_fx ,AdBanner::FX_TYPES %> -
    - <%= image_tag "slideshow_preview_A.png", :width=>220 %> - <%= image_tag "slideshow_preview_B.png", :width=>220 %> -
    - Effect - <%= t(:cancel) %> -<%= f.submit t(:create_), class: 'btn btn-primary btn-small' %> -
    - <% end %> -
    \ No newline at end of file +<%= form_for @ad_banner, url: admin_ad_banner_path(@ad_banner), remote: true do |f| %> +
    + <%= t("ad_banner.banner") %> + + <%= f.text_field :title, :class=>"input-large", :placeholder=>"Banner Name" %> + <%= t("ad_banner.banner_name_note") %> + + <%= f.text_field :transition_sec, :class => 'input-large', :placeholder => 'Time' %> + <%= t("ad_banner.ste_note") %> + + <%= f.text_field :best_size, :class=>"input-large", :placeholder=>"Banner Size" %> + <%= t("ad_banner.best_size") %> EX:120x30 + + <%= f.select :ad_fx ,AdBanner::FX_TYPES %> +
    + <%= image_tag "slideshow_preview_A.png", :width=>220 %> + <%= image_tag "slideshow_preview_B.png", :width=>220 %> +
    + <%= t("ad_banner.effect") %> + <%= t(:cancel) %> + <%= f.submit t(:update_), class: 'btn btn-primary btn-small' %> +
    +<% end %> + \ No newline at end of file diff --git a/app/views/admin/ad_banners/_index.html.erb b/app/views/admin/ad_banners/_index.html.erb index c6072cfe..9c7b155f 100644 --- a/app/views/admin/ad_banners/_index.html.erb +++ b/app/views/admin/ad_banners/_index.html.erb @@ -1,3 +1,5 @@ +<%= javascript_include_tag "lib/jquery.cycle.all.latest.js"%> + @@ -13,7 +15,7 @@