diff --git a/app/assets/javascripts/cycle2/jquery.cycle2.video.min.js b/app/assets/javascripts/cycle2/jquery.cycle2.video.min.js new file mode 100644 index 0000000..c47c840 --- /dev/null +++ b/app/assets/javascripts/cycle2/jquery.cycle2.video.min.js @@ -0,0 +1,2 @@ +/* Plugin for Cycle2; Copyright (c) 2012 M. Alsup; v20141007 */ +!function(a){"use strict";function b(){try{this.playVideo()}catch(a){}}function c(){try{this.pauseVideo()}catch(a){}}var d='
';a.extend(a.fn.cycle.defaults,{youtubeAllowFullScreen:!0,youtubeAutostart:!1,youtubeAutostop:!0}),a(document).on("cycle-bootstrap",function(e,f){f.youtube&&(f.hideNonActive=!1,f.container.find(f.slides).each(function(b){if(void 0!==a(this).attr("href")){var c,e=a(this),g=e.attr("href"),h=f.youtubeAllowFullScreen?"true":"false";g+=(/\?/.test(g)?"&":"?")+"enablejsapi=1",f.youtubeAutostart&&f.startingSlide===b&&(g+="&autoplay=1"),c=f.API.tmpl(d,{url:g,allowFullScreen:h}),e.replaceWith(c)}}),f.slides=f.slides.replace(/(\b>?a\b)/,"div.cycle-youtube"),f.youtubeAutostart&&f.container.on("cycle-initialized cycle-after",function(c,d){var e="cycle-initialized"==c.type?d.currSlide:d.nextSlide;a(d.slides[e]).find("object,embed").each(b)}),f.youtubeAutostop&&f.container.on("cycle-before",function(b,d){a(d.slides[d.currSlide]).find("object,embed").each(c)}))})}(jQuery); \ No newline at end of file diff --git a/app/controllers/ad_banners_controller.rb b/app/controllers/ad_banners_controller.rb index 5c032e6..1e34b6e 100644 --- a/app/controllers/ad_banners_controller.rb +++ b/app/controllers/ad_banners_controller.rb @@ -1,6 +1,17 @@ class AdBannersController < ApplicationController def widget adbanner = Banner.find(OrbitHelper.widget_custom_value) + widget = OrbitHelper.get_current_widget + if widget.widget_type == "ad_banner_widget2_video" + return video_widget(adbanner) + else + return image_widget(adbanner) + end + end + + private + + def image_widget(adbanner) images = [] adbanner.ad_images.can_display.asc(:sort_number,:created_at).each.with_index do |b,i| if b.language_enabled.include?(I18n.locale.to_s) @@ -47,4 +58,47 @@ class AdBannersController < ApplicationController "images" => images } end + + def video_widget(adbanner) + images = [] + adbanner.ad_images.can_display.asc(:sort_number).each_with_index do |ad_b,i| + if ad_b.language_enabled.include?(I18n.locale.to_s) + image_link = OrbitHelper.is_mobile_view ? ad_b.file.mobile.url : ad_b.file.url + alt_text = (ad_b.title.nil? || ad_b.title == "" ? "ad-banner image" : ad_b.title) + caption = i == 0 ? '' : "" + klass = i == 0 ? "active" : "" + if ad_b.exchange_item == "1" + image_html = " " + else ad_b.exchange_item == "2" + youtube_url = format_url(ad_b.youtube,i) + image_html = " " + end + images << { + "html" => image_html + } + end + end + { + "extras" => { + "ad_fx" => adbanner.ad_fx, + "speed" => adbanner.speed, + "title" => adbanner.title, + "timeout" => adbanner.timeout, + "more" => "More" + }, + "images" => images + } + end + + def format_url(url,index) + uri = URI.parse(url) + ps = uri.query.to_s.split("&") + url_params = {} + ps.each do |p| + x = p.split("=") + url_params[x.first] = x.last + end + # url = "http://www.youtube.com/v/#{url_params["v"]}/?version=3&playerapiid=ytplayer#{index}" + url = "https://www.youtube.com/embed/#{url_params["v"]}" + end end diff --git a/app/controllers/admin/ad_images_controller.rb b/app/controllers/admin/ad_images_controller.rb index b590eb4..70aad8d 100644 --- a/app/controllers/admin/ad_images_controller.rb +++ b/app/controllers/admin/ad_images_controller.rb @@ -11,6 +11,8 @@ class Admin::AdImagesController < Admin::AdBannersController def edit @ad_image = AdImage.find(params[:id]) + @item = [[t('image'),"1"],[t('video'),"2"]] + @item_choose = @ad_image.exchange_item if can_edit_or_delete?(@ad_image.banner) @ad_banner = @ad_image.banner else @@ -27,6 +29,7 @@ class Admin::AdImagesController < Admin::AdBannersController def new @ad_image = AdImage.new @ad_banner = Banner.find(params[:banner_id]) + @item = [[t('image'),"1"],[t('video'),"2"]] if can_edit_or_delete?(@ad_banner) @tags = @module_app.tags || [] @ad_image.postdate = Date.today diff --git a/app/models/ad_image.rb b/app/models/ad_image.rb index a57465d..b0ba05f 100644 --- a/app/models/ad_image.rb +++ b/app/models/ad_image.rb @@ -13,15 +13,16 @@ class AdImage field :link_open, type: String field :postdate , :type => DateTime, :default => Time.now field :deadline , :type => DateTime + field :youtube , :type => String field :sort_number, :type => Integer field :language_enabled, :type => Array, :default => ["en","zh_tw"] - + field :exchange_item, :default => "1" LINK_OPEN_TYPES = ["local", "new_window"] belongs_to :banner before_validation :add_http - validates :file, presence: true + # validates :file, presence: true validates :out_link, format: { with: URI::regexp(%w(http https)) }, allow_blank: true # validates :title, presence: true @@ -33,6 +34,28 @@ class AdImage self.deadline