Singpolyma

Archive for October 8th, 2006

Archive for October 8th, 2006

FreshTags as API

Posted on

The new FreshTags system comes with many benefits, such as the WidgetData system and also a more flexible interaction with the code itself.

Some basic example of this are the widgets one can create just using different settings. To include a feed in your sidebar you can add this code in with the other FreshTags settings data:

//feed widget
WidgetData[‘freshtags’][‘freshtags_FeedName‘] = {
‘type’:’posts’,
‘source’:’feed’,
‘feedurl’:’FeedURL‘,
‘rows’:10
};

And this code wherever you want the feed headlines to display:

<div id=”freshtags_FeedName“><i>Loading Feed…</i></div>

Similarly, a minor tweak to that code yeilds ‘Generic FreshTags’ behaviour as existed in the original FreshTags release:

//generic widget
WidgetData[‘freshtags’][‘freshtags_generic’] = {
‘type’:’posts’,
‘source’:’feed’,
‘feedurl’:’http://del.icio.us/rss/tag/%tags%’,
‘rows’:10
};

And:

<div id=”freshtags_generic”><i>Loading del.icio.us…</i></div>

Peek-a-boo headlines functionality also remains:

//Headlines Widget
WidgetData[‘freshtags’][‘BlogNameheadlines’] = {
‘type’:’external’,
‘source’:’del.icio.us’,
‘username’:’del.icio.us username for blog‘,
‘anchor’:’anchor tag for blog‘,
‘feedurl’:’FeedURL for blog‘,
‘tag_list’:’freshtags_tags’,
‘rows’:10
};

And:

<a id=”BlogNamelink” href=”javascript:toggleitem(‘BlogNameheadlines’,’BlogNamelink’,’-‘);freshtags_load(‘BlogNameheadlines’);”>+</a>
<a href=”BlogURL“>BlogName</a>
<div id=”BlogNameheadlines” style=”display:none;”><i>Loading…</i></div>

Note that the following must be included in the <head> section of your blog for this to work:

<script type=”text/javascript”>
function toggleitem(postid,linkid,newtxt,displaytype) {
if(!displaytype) {displaytype = ‘block’;}
var whichpost = document.getElementById(postid);
if (whichpost.style.display != “none”) {
whichpost.style.display = “none”;
} else {
whichpost.style.display = displaytype;
}
if(linkid) {
var lnk = document.getElementById(linkid);
lnk.href = “javascript:toggleitem(‘”+postid+”‘,'”+linkid+”‘,'”+lnk.innerHTML+”‘);”;
lnk.innerHTML = newtxt;
}
}//end function toggleitem
</script>

Below is a list of easily externally accesible functions in FreshTags:

  • freshtags_load – called with no parameter it (re)loads all FreshTags widgets on a page. If you pass it the ID of a widget, just that widget will be (re)loaded (and associated widgets).
  • get_current_tags – takes three optional parameters, a space-separated string of default tags to use if none are found, an object containing a complete list of all tags avaliable for use in the format {‘tag’:count}, and a boolean value specifying whether or not to draw rel-tag data from the page if no tags are detected from the URL/referrer. Returns a plus-separated string of tags found or the null string (”).
  • main_tags_loaded – if you pass it false and teh ID of a FreshTags tag widget it will reload the widget (and associated widgets) without re-calling get_current_tags like freshtags_load does (thus enabling you to set the current tags to whatever you want).
  • listTags – takes the ID of a FreshTags tag widget and returns a string of the renderation to XHTML.
  • listTitles – takes the ID of a FreshTags posts (or external) widget and returns a string of the renderation to XHTML. An optional second parameter specifies whether to hide the widget when there’s no data (false, default) or