<?xml version="1.0" encoding="UTF-8"?>
<Module>
  <ModulePrefs title="__UP_title__"
    description="__MSG_mod_description__"
    author="Mark Wu"
    author_email="wuhsinyee@hotmail.com"
    author_affiliation="Markplace.Net"
    author_location="Taiwan"
    category="news"
    thumbnail="http://blog.markplace.net/ishare/images/thumbnail.png"
    screenshot="http://blog.markplace.net/ishare/images/screenshot.png"
    directory_title="__MSG_mod_title__"
    >
    <Locale lang="zh-TW" messages="http://blog.markplace.net/ishare/ishare_tw.xml" />
    <Locale country="tw" messages="http://blog.markplace.net/ishare/ishare_tw.xml" />
    <Locale messages="http://blog.markplace.net/ishare/ishare_tw.xml"/>
    <Require feature="setprefs"/>
    <Require feature="tabs"/>
    <Require feature="dynamic-height"/>
  </ModulePrefs>
  <UserPref name="title" display_name="__MSG_title__" datatype="string" default_value="__MSG_mod_title__" />
  <UserPref name="items" display_name="__MSG_items_to_display__" datatype="enum" default_value="10">
    <EnumValue value="5" />
    <EnumValue value="6" /> 
    <EnumValue value="7" /> 
    <EnumValue value="8" /> 
    <EnumValue value="9" /> 
    <EnumValue value="10" /> 
  </UserPref>
  <UserPref name="feeds" display_name="__MSG_feeds__" datatype="list" default_value="__MSG_default_feeds__" />
  <Content type="html">
  <![CDATA[

<style type="text/css">
.tablib_content_container__MODULE_ID__ {padding:4px}

#tl___MODULE_ID__ {
}

#tl___MODULE_ID__ .col {
}
#tl___MODULE_ID__ .clear {
    clear:left;
}

#tl___MODULE_ID__ .col ul {
    font-size:12px;
    list-style-position: inside;
	list-style-image: url('http://blog.markplace.net/ishare/images/myshare_list13.gif');
    margin:5px 10px 5px 0px;
    padding: 0px;
}

#tl___MODULE_ID__ .commentblock {
	display: inline-block;
}

#tl___MODULE_ID__ .comment {
    background-color: #D5FF80;
    display:table-cell;
	text-align: center;
	width: 45px;
}

#tl___MODULE_ID__ .comment a {
	text-decoration: none;
	color: #000000;
}

#tl___MODULE_ID__ .comment img {
	border: 0px;
}

#tl___MODULE_ID__ .push {
	font-size:14px;
	background-color: #669900;
	color: #000000;
	display: inline;
	font-weight: bold;
}

#tl___MODULE_ID__ .push a {
	text-decoration: none;
	color: #FFFFFF;
}

#tl___MODULE_ID__ .bookmark {
	color: #666666;
}

#tl___MODULE_ID__ .bookmark a {
	color: #666666;
	text-decoration: none;
}

#tl___MODULE_ID__ .bookmark a:hover {
	background-color: #D5FF80;
}
</style>
<script>
/**
 * @author rack
 */
(function(){

// Get userprefs
var prefs = new _IG_Prefs(__MODULE_ID__);
var FEEDS = prefs.getArray("feeds");
for (var i=0; i<FEEDS.length; i++) {
    var fe = FEEDS[i].split(",");
    if (fe.length==2) {
        FEEDS[i] = fe;
    }else {
        FEEDS[i] = ["FEED"+(i+1), fe[0]];
    }

}
var ITEMS = 20;
var SUMMARY = true;
var UACCT = prefs.getString('uacct');
var myshareRSSURL = 'http://myshare.url.com.tw/index.php?func=feed&class=popular&limit=20&cate=';
var myshareURL = 'http://myshare.url.com.tw/';

// Cache feed for 10 mins
var cache = [];
var CACHE_FOR = 10*60*1000;
var cache_feeds = [];
// Feeds Tabs
var tabs;
var dialogContainer = null;


function getFeeds(tabId, feed_url, idx) {

  // Check the last time the feed is fetched
  var t = cache[idx];
  var n = new Date().getTime();
  if (!t || ((n - t) > CACHE_FOR)) {
    showMessage(tabId, "__MSG_loading__");
    feed_url = _trim(feed_url);
    if(!feed_url.match(/^http/)) feed_url = myshareRSSURL + feed_url;
    _IG_FetchFeedAsJSON(feed_url, function(feed) {
      if (feed && feed.Entry) {
        cache[idx] = new Date().getTime();
        cache_feeds[idx] = feed;
      }
      renderFeeds(tabId, idx);
    }, 20, true);
  }else {
    renderFeeds(tabId, idx);
  }
}
function showMessage(tabId, msg) {
  _gel(tabId).innerHTML = '<div class="newsmsg__MODULE_ID__">' + msg + '</div>';
}

function renderFeeds(tabId, idx) {

    var feed = (cache_feeds[idx]) ? cache_feeds[idx] : null;
    if ((feed == null) || !feed.Entry) {
    showMessage(tabId, "Feed Error");
    return;
    }

    var show_item_max = prefs.getInt("items");
	if( feed.Entry.length < show_item_max )
		show_item_max = feed.Entry.length;

    var container = _gel(tabId);
    removeAllChild(container);

    var colContainer = document.createElement('div');
    colContainer.className = 'col';

    var clearContainer = document.createElement('div');
    clearContainer.className = 'clear';

        var rightHTML = '<a target="_blank" href="'+myshareURL+'"><img src="http://blog.markplace.net/ishare/images/myshare_logo.gif" border="0"/></a>';
        rightHTML += '<ul>';
        for (var i = 0; i < show_item_max; i++) {
            var html = createItem(feed.Entry[i]);
            rightHTML += html;
        }
        rightHTML += '</ul>';
        colContainer.innerHTML = rightHTML;
        container.appendChild(colContainer);
        container.appendChild(clearContainer);

        _IG_AdjustIFrameHeight();

}

function createItem(e) {
var e_title = e.Title ;
var e_link = e.Link;
var e_summary = e.Summary;

var html ='<li class="title">';
html += '<span class="bookmark">&nbsp;<a href="'+e_link+'" target="_blank">'+e_title+'</a></span>&nbsp;';
html += '</li>';
return html;


}


function removeAllChild(element) {
  while (element.firstChild)
   {
      element.removeChild(element.firstChild);
   }
}

function insertAfter(newElement, targetElement) {
 var parent = targetElement.parentNode;
 if(parent.lastChild == targetElement) {
  parent.appendChild(newElement);
 } else {
  parent.insertBefore(newElement, targetElement.nextSibling);
 }
}


function init() {
  // Initialize tabs.
  tabs = new _IG_Tabs(__MODULE_ID__);
  for (var i = 0; i < FEEDS.length; i++) {
      tabs.addTab('<div style="overflow:hidden">' + FEEDS[i][0] + '</div>', {
        callback: _IG_Callback(getFeeds, FEEDS[i][1], i),
        tooltip: FEEDS[i][0]
      });
  }

}

// Call init function to initialize and display tabs.
_IG_RegisterOnloadHandler(init);

})()</script>]]>
  </Content>
</Module>
