﻿<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs 
title="__UP_title__"
title_url="http://newbooks.lib.ntu.edu.tw/" 
directory_title="NTU New Books Feeds"
description="臺大圖書館新書推薦服務小工具，提供臺大圖書館最新圖書資訊。想知道更多，請至 http://beta.lib.ntu.edu.tw/?p=47 查看這個小工具的介紹。"
author="NTU Library"
author_email="libsys@ntu.edu.tw"
author_link="http://beta.lib.ntu.edu.tw/"
author_location="TW" 
author_affiliation="NTU Lib. TW"
author_photo="http://beta.lib.ntu.edu.tw/wp-content/uploads/Logo.png"
author_aboutme="National Taiwan University Library. Only gadgets on http://beta.lib.ntu.edu.tw/ are officially released version. Others are just being tested and may be removed in short time."
screenshot="http://beta.lib.ntu.edu.tw/wp-content/uploads/NTU-New-Books-Feeds.png"
thumbnail="http://beta.lib.ntu.edu.tw/wp-content/uploads/NTU-New-Books-Feeds.png"
scrolling="true"
singleton="true"
width="400" height="200">
<Require feature="setprefs"/>
<Require feature="tabs"/>
<Require feature="analytics" />
</ModulePrefs>
<UserPref name="title" display_name="&#x5C0F;&#x5DE5;&#x5177;&#x6A19;&#x984C;" default_value="臺大圖書館新書推薦"/>
<UserPref name="entries" display_name="&#x986F;&#x793A;&#x7BC7;&#x6578;" datatype="enum" default_value="10">
<EnumValue value="5"/>
<EnumValue value="10"/>
<EnumValue value="15"/>
<EnumValue value="20"/>
</UserPref>
<UserPref name="summaries" display_name="&#x6587;&#x7AE0;&#x986F;&#x793A;&#x65B9;&#x5F0F;" datatype="enum" default_value="1">
<EnumValue value="-1" display_value="&#x6A19;&#x984C;"/>
<EnumValue value="1" display_value="&#x9996;&#x6BB5;"/>
<EnumValue value="2" display_value="&#x5168;&#x6587;"/>
</UserPref>
<UserPref name="showFeedDesc" display_name="&#x986F;&#x793A;blog&#x6558;&#x8FF0;?" datatype="bool" default_value="true"/>
<UserPref name="showTimestamp" display_name="&#x986F;&#x793A;&#x6587;&#x7AE0;&#x6642;&#x9593;?" datatype="bool" default_value="true"/>
<UserPref name="selectedTab" datatype="hidden"/>
<Content type="html"><![CDATA[
<style type="text/css">
.tablib_table {
font-size: 0.85em;
}
.tablib_selected, .tablib_unselected {
font-weight: normal;
width: 23%;
}

.statusLabel {
font-size: 0.85em;
font-style: italic;
padding-top: 10px;
text-align: center;
}
.feedHeader {
padding-top: 5px;
font-size: 0.8em;
}
.feedHeader .feedTitle {
font-weight: normal;
font-size: 0.8em;
}

.feedList {
font-size: 0.8em;
margin-top: 5px;
padding: 5px 0px 5px 0px;
border-bottom: 1px solid #aaaaaa;
}
.feedList li {
margin-top: 5px;
padding: 3px 3px 0px 3px;
border-top: 1px solid #aaaaaa;
}
.feedList li div.entryTitle a {
font-weight: bold;
}
.feedList li div.entryTimestamp {
font-size: 0.75em;
font-style: italic;
color: #676767;
}
img{
width: 60px;
height: 85px;
}
</style>

<script>
// Global variables
var prefs = new _IG_Prefs(__MODULE_ID__);
var tabs = new _IG_Tabs(__MODULE_ID__);

/**
* Initialize tabs when page loads.
* Create tab for each userpref only if userpref is not empty.
*/
function init() {
var f1 = "http://newbooks.lib.ntu.edu.tw/?feed=rss2";
var ft1 = "&#x65B0;&#x66F8;&#x63A8;&#x85A6;";

if (f1 != "") {
tabs.addDynamicTab(((ft1 == "") ? "Feed 1" : ft1), _IG_Callback(callbackTab, f1));
}
};

/**
* Fetches an Atom or RSS feed and generates content inside the
* selected tab's content container. This function is called whenever
* a tab is selected.
*/
function callbackTab(tabId, feedUrl) {
var showFeedDesc = prefs.getBool("showFeedDesc");
var summaries = prefs.getInt("summaries");
var entries = prefs.getInt("entries");
var showTimestamp = prefs.getBool("showTimestamp");
var container = _gel(tabId);

// Display loading message before fetching feed.
container.innerHTML = '<div class="statusLabel">Loading...</div>';

// Fetch feed and return it as a JSON object.
// Callback function is defined within local scope.
_IG_FetchFeedAsJSON(
feedUrl,
function(feed) {
if (typeof feed == "undefined" || typeof feed.Entry == "undefined") {
container.innerHTML = '<div class="statusLabel">Invalid feed URL:<br>' + feedUrl + '</div>';
} else {
// Fetch feed successful. Generate HTML content from returned JSON object.
// Create feed header containing title and description.
var html = new Array();
html.push('<div class="feedHeader">');
//html.push('<div class="feedTitle">');
//html.push((feed.Link != "") ? '<a target="_blank" href="' + _hesc(feed.Link) + '">' + _hesc(feed.Title) + '</a>' : _hesc(feed.Title));
//html.push('</div>');
if (showFeedDesc) {
html.push('<div class="feedDesc">' + _hesc(feed.Description) + '</div>');
}
html.push('</div>');

// Iterate through each feed entry and generate list of content.
html.push('<div class="feedList">');
for (var n = 0; n < feed.Entry.length; n++) {
var short = true;
var entry = feed.Entry[n];
html.push('<div>');
html.push('<a target="_blank" href="' + entry.Link + '"><b>' + _hesc(entry.Title) + '</b></a>');
if (typeof entry.Summary != "undefined" && entry.Summary != "") {
var summary = document.createElement("div");
if(summaries==1){
if (entry.Summary.match("&#x5167;&#x5BB9;")) summary.innerHTML = entry.Summary.substr(0, entry.Summary.indexOf("&#x5167;&#x5BB9;")) + "";
else {
summary.innerHTML = entry.Summary.substr(0,entry.Summary.indexOf(/館藏地[^\n]* /.exec(entry.Summary))).replace(/<br[^\>]*\>/, "");
short = false;
}
}
else{
summary.innerHTML =entry.Summary;
short = false;
}
html.push('<div class="entrySummary">');
html.push(summary.innerHTML);
if ((summaries==1)&&(short==true)) html.push('<br><a target="_blank" href="' + entry.Link + '">&#x95B1;&#x8B80;&#x5168;&#x6587;</a>')
//html.push(_hesc(summary.innerHTML));
html.push('</div>');
}
if (!isNaN(entry.Date) && showTimestamp) {
//html.push('<div class="entryTimestamp">[' + new Date(entry.Date * 1000).toLocaleString() + ']</div>');
}
html.push('</div>');
html.push('<br/>');
}
html.push('</div>');
container.innerHTML = html.join("");
}

// Resize iframe height to fit content.
//_IG_AdjustIFrameHeight();
},
entries,
(summaries > -1)
);
}

// Set onload event handler to call init()
_IG_RegisterOnloadHandler(init);
_IG_Analytics("UA-414096-10", "iGoogle: NTU-New-Books-Feeds");
</script>
]]>
</Content>
</Module>