From 6a30b0a1e47b460854dd5ff5a2a206f06c7d0803 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Tue, 28 Feb 2012 18:29:13 +0800 Subject: [PATCH] Add RSS event --- app/assets/javascripts/event.js | 122 ++++++++++++++++++ app/views/admin/page_parts/_edit.html.erb | 2 - app/views/admin/page_parts/_text.html.erb | 2 +- lib/parsers/parser_back_end.rb | 1 + lib/parsers/parser_front_end.rb | 1 + public/static/Other.xml | 144 ++++++++++++++++++++++ 6 files changed, 269 insertions(+), 3 deletions(-) create mode 100644 app/assets/javascripts/event.js create mode 100644 public/static/Other.xml diff --git a/app/assets/javascripts/event.js b/app/assets/javascripts/event.js new file mode 100644 index 00000000..afe558d8 --- /dev/null +++ b/app/assets/javascripts/event.js @@ -0,0 +1,122 @@ +$(document).ready(function(){ + var result = '', + title_text = '', + link_text = '', + summary_text = '', + startDate_text = '', + startMon_text = '', + startDay_text = '', + endDate_text = '', + time_text = '', + selet = 0, + xmlLength = '', + indexA = '', + indexB = '', + indexC = '', + month = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'], + checking = 1, + $events = $('.events'), + $mon = $('.events .mon'), + $day = $('.events .day'), + $link_text = $('.events .event_name'), + $time = $('.events .event_info'), + $next = $('.events .links_next'), + $prev = $('.events .links_prev'), + objLength = $events.find('ul > li').length; + $next.on("click", function(){ + if (checking&&selet < xmlLength) { + $('.links_prev').removeClass('disabled') + selet+=objLength; + $events.find('ul').fadeOut("fast", function () { + resetText() + $events.find('ul').fadeIn("fast" ,getEvent(selet)); + }); + if ((xmlLength-selet) == objLength) { + $('.links_next').addClass('disabled') + checking = 0; + } else if ((xmlLength-selet) < objLength) { + $('.links_next').addClass('disabled') + checking = 0; + } + } + return false; + }); + $prev.on("click", function(){ + if (selet > 0) { + $('.links_next').removeClass('disabled') + checking = 1; + selet-=objLength; + $events.find('ul').fadeOut("fast", function () { + $events.find('ul').fadeIn("fast" ,getEvent(selet)); + }); + if ((xmlLength-selet) == xmlLength ) { + $('.links_prev').addClass('disabled') + } + } + return false; + }); + getEvent(selet); + function resetText() { + $events.find('li').find($mon).html(''); + $events.find('li').find($day).html(''); + $events.find('li').find($link_text).html(''); + $events.find('li').find($link_text).attr('href', ''); + $events.find('li').find($time).html(''); + } + function getEvent(selet){ + $.ajax({ + type: "GET", + url: "/static/Other.xml", + dataType: "xml", + timeout: 1000, + error: function(xml){ + $events.find('.links_next').addClass('disabled') + $events.find('.error_mag').show(); + $events.find('ul').hide(); + $events.find('.error_mag').html("讀取錯誤"); + }, + success: function(xml) { + xmlLength = $(xml).find('entry').length; + $(xml).find('entry').slice(selet, selet+objLength).each(function(i){ + title_text = $(this).find('title').text() + link_text = $(this).find('link').attr('href') + summary_text = $(this).find('summary').text() + indexA = summary_text.indexOf("-"); + indexB = summary_text.indexOf(" "); + indexC = summary_text.indexOf("/"); + //清除前後空白字元 + summary_text = jQuery.trim(summary_text); + //篩選標題 + title_text = title_text.slice(0, 16) + if (summary_text.length == 31) { + startDate_text = summary_text.slice(0, indexA); + startMon_text = startDate_text.slice((indexC+1), (indexC+3)); + startDay_text = startDate_text.slice(7); + endDate_text = summary_text.slice((indexA+1), indexB); + time_text = summary_text.slice((indexB+1)); + } else { + startDate_text = summary_text.slice(0, indexB); + startMon_text = startDate_text.slice((indexC+1), (indexC+3)); + startDay_text = startDate_text.slice(7); + endDate_text = ''; + time_text = summary_text.slice((indexB+1)); + } + if(startMon_text.slice(0, 1) == '0'){ + startMon_text = month[startMon_text.slice(1)-1]; + } else { + startMon_text = month[startMon_text-1]; + } + $events.find('li').eq(i).find($mon).html(startMon_text); + $events.find('li').eq(i).find($day).html(startDay_text); + $events.find('li').eq(i).find($link_text).html(title_text+"…"); + $events.find('li').eq(i).find($link_text).attr('href', link_text); + $events.find('li').eq(i).find($time).html('時間:'+time_text); + //console.log(); + /*$('
  • ') + .html('
    '+startMon_text+''+startDay_text+'
    ') + .appendTo('.events ul');*/ + });//close each( + } + }); //close $.ajax( + } +}); \ No newline at end of file diff --git a/app/views/admin/page_parts/_edit.html.erb b/app/views/admin/page_parts/_edit.html.erb index b5e298cb..ec99c555 100644 --- a/app/views/admin/page_parts/_edit.html.erb +++ b/app/views/admin/page_parts/_edit.html.erb @@ -1,5 +1,3 @@ -<%= @part.inspect %>

    - <%= form_for @part, :url => admin_page_part_path(@part) do |f| %> <% LIST[:page_part_kinds].each do |kind| %> diff --git a/app/views/admin/page_parts/_text.html.erb b/app/views/admin/page_parts/_text.html.erb index 8cd03d58..cc6264a5 100644 --- a/app/views/admin/page_parts/_text.html.erb +++ b/app/views/admin/page_parts/_text.html.erb @@ -2,7 +2,7 @@ <% @site_valid_locales.each do |locale| %>
    <%= I18nVariable.from_locale(locale) %> - <%= f.text_field locale %> + <%= f.text_area locale %>
    <% end %> <% end %> \ No newline at end of file diff --git a/lib/parsers/parser_back_end.rb b/lib/parsers/parser_back_end.rb index 4b8fbd27..dea65b6a 100644 --- a/lib/parsers/parser_back_end.rb +++ b/lib/parsers/parser_back_end.rb @@ -64,6 +64,7 @@ module ParserBackEnd res << "" res << "" res << "" + res << "" page.design.javascripts.each do |js| res << "" end diff --git a/lib/parsers/parser_front_end.rb b/lib/parsers/parser_front_end.rb index 008a265c..d1334b06 100644 --- a/lib/parsers/parser_front_end.rb +++ b/lib/parsers/parser_front_end.rb @@ -79,6 +79,7 @@ module ParserFrontEnd res << "" res << "" res << "" + res << "" page.design.javascripts.each do |js| res << "" end diff --git a/public/static/Other.xml b/public/static/Other.xml new file mode 100644 index 00000000..22c41bbb --- /dev/null +++ b/public/static/Other.xml @@ -0,0 +1,144 @@ + + + 國立政治大學校園活動行事曆 + + 其他類別-最新活動 + zh-tw + + 國立政治大學101學年度碩士班暨碩士在職專班招生考試 + + + + + 101/02/25-101/02/26 07:00-17:00 + + + 國立中正大學101學年度碩士班招生考試 + + + + + 101/03/10 07:00-17:00 + + + 「樂活飲食•健康之鑰」系列活動--膳食纖維的功用及食物來源 + + + + + 101/02/29 12:00-14:00 + + + 「樂活飲食•健康之鑰」系列活動-美味的代價與健康問題之探討 + + + + + 101/03/08 12:00-14:00 + + + 「樂活飲食•健康之鑰」系列活動--代謝症候群與檢康飲食 + + + + + 101/03/22 12:00-14:00 + + + 「學生健康體位控制班」 + + + + + 101/03/01-101/05/03 18:00-20:30 + + + 學生大使志工團- 2012 Field Trip-Must Sea+ FUN舟趣 + + + + + 101/03/17-101/03/18 08:00-20:00 + + + 職場勞資關係講座-你知道自己的權益嗎? + + + + + 101/03/05 18:30-21:00 + + + 職場「面面」觀 - 談職場趨勢與面試 + + + + + 101/03/06 18:30-21:00 + + + 「自」銷不要「滯」銷~一窺自我行銷術的秘密 + + + + + 101/03/07 18:30-21:00 + + + 職涯經驗談-開創職涯的一片天 + + + + + 101/03/08 18:30-21:00 + + + 2012徵政好企業說明會--花旗銀行 + + + + + 101/03/05 12:15-14:00 + + + 2012徵政好企業說明會--日商野村總合研究所 + + + + + 101/03/09 12:15-14:00 + + + 2012徵政好企業說明會--渣打銀行 + + + + + 101/03/06 12:15-14:00 + + + 2012徵政好企業說明會--台新金控 + + + + + 101/03/07 12:15-14:00 + + + 2012徵政好企業說明會--第一銀行 + + + + + 101/03/08 12:15-14:00 + + + 101年生命教育師資培訓課程研習會 + + + + + 101/03/24-101/03/25 07:30-17:40 + + +