// Copyright (c) 2009 NextBio.  All Rights Reserved
// Additional JavaScript subject to other copyrights

function initTagCloud(reset, tabId, lookupSize, cloudSize, el)
{
var tcName=getTagCloudName(el);
if (reset == true || nbRsh.get('$tagCloudState'+tcName) != "true")
{
nbRsh.start();
nbRsh.put("$tagTabId"+tcName, "ALL");
nbRsh.put("$tagLookupSize"+tcName, 50);
nbRsh.put("$tagCloudSize"+tcName, 40);
nbRsh.put("$tagCloudState"+tcName, "true");
nbRsh.finish();
}
}
function initTagCloud1(el) {
initTagCloud(null,null,null,null,el);
}
function _nextbio_onEvent(event, containerId, param)
{
if (event == null || containerId == null)
return;
var container = document.getElementById(containerId);
if (container == null)
return;
if (event.type.toLowerCase() == "click")
{
if (container.nextbioOnClick != null)
container.nextbioOnClick(event, containerId, param, container.nextbioOnClickParam, container.nextbioUrlContext);
}
else if (event.type.toLowerCase() == "mouseover")
{
if (container.nextbioOnMouseOver != null)
container.nextbioOnMouseOver(event, containerId, param, container.nextbioOnMouseOverParam, container.nextbioUrlContext);
}
}
function _nextbio_tagCloudCB(el, success, resp, opt)
{
if (success == false)
return;
}
function digListOnClick(owner, text)
{
if (owner == null)
return;
var currentSelection = $(owner).up(".DigParent").down(".DigCurrent");
owner.style.display = "none";
var currentId = currentSelection.getAttribute("nextbioDigEntry");
if (currentId != null)
{
var currentEntry = document.getElementById(currentId);
if (currentEntry != null)
currentEntry.style.display="inline";
}
currentSelection.setAttribute("nextbioDigEntry", owner.id);
currentSelection.innerHTML = text;
}
function onClickCloudTab(config)
{
if (config == null && nbRsh.get('$tagCloudId') == null)
return false;
if (config && config.signIn)
{
if (!allowAnon && !signInLink())
{
cancelBubble(config.event);
return false;
}
}
nbRsh.start();
var changeDepth = false;
var changeTab = false;
if (config == null)
{
config = {};
}
else
{
initTagCloud1(config.cloudId);
}
var tcName=getTagCloudName(config.cloudId);
if (config.tabId == null)
{
config.tabId = nbRsh.get('$tagTabId'+tcName);
}
else
{
nbRsh.put('$tagTabId'+tcName, config.tabId);
changeTab = true;
}
if (config.lookupSize == null)
{
config.lookupSize = nbRsh.get('$tagLookupSize'+tcName);
}
else
{
nbRsh.put('$tagLookupSize'+tcName, config.lookupSize);
changeDepth = true;
}
if (config.cloudSize == null)
{
config.cloudSize = nbRsh.get('$tagCloudSize'+tcName);
}
else
{
nbRsh.put('$tagCloudSize'+tcName, config.cloudSize);
}
if (config.cloudId == null)
{
config.cloudId = nbRsh.get('$tagCloudId'+tcName);
}
else
{
nbRsh.put('$tagCloudId'+tcName, config.cloudId);
}
if (config.url == null)
{
config.url = nbRsh.get('$tagUrl'+tcName);
}
else
{
nbRsh.put('$tagUrl'+tcName, config.url);
}
if (config.query == null)
{
config.query = nbRsh.get('$tagQuery'+tcName);
}
else
{
nbRsh.put('$tagQuery'+tcName, config.query);
}
if (config.filter == null)
{
config.filter = nbRsh.get('$tagFilter'+tcName);
}
else
{
nbRsh.put('$tagFilter'+tcName, config.filter);
}
if (config.obj == null)
{
typeTabId = $(nbRsh.get('$tagTypeTab'+tcName));
digTabId = $(nbRsh.get('$tagDigTab'+tcName));
if (typeTabId != null)
$(typeTabId).radioClass('Selected');
if (digTabId != null)
{
digListOnClick($(digTabId), config.lookupSize);
}
}
else
{
$(config.obj.parentNode).radioClass('Selected');
var containerId = config.obj.parentNode.id;
if (changeTab == true)
nbRsh.put("$tagTypeTab"+tcName, containerId);
else if (changeDepth == true)
nbRsh.put("$tagDigTab"+tcName, containerId);
}
var params = 'tagType=' + config.tabId + '&tagFilter=' + config.filter + '&tagCloud=true&tagLookupSize=' + config.lookupSize + '&tagCloudSize=' + config.cloudSize;
tfName = getTagCloudName(config.cloudId)+"tf";
var tf = nbApi.normalizeString(nbRsh.get(tfName));
if (tf != null && tf.length > 0)
{
params += "&tf=" + encodeURIComponent(tf);
}
self.loadFromServer
(
{
callback: function(el, success, resp, opt){_nextbio_tagCloudCB(el, success, resp, opt);},
target: config.cloudId + '_tagCloudContainer',
url: config.url,
noResize: true,
query: addParams(config.query, params),
highlight: true
}
);
nbRsh.finish();
return false;
}
document.observe("nb:historyLoaded", function(evt)
{
onClickCloudTab();
});
document.observe("nb:historyChanged2", function(evt)
{
if (evt.memo.oldMap.tf == evt.memo.map.tf)
return;
var cloudArray = $$(".TagCloud");
cloudArray.each(function(cloud)
{
var config = {
cloudId: cloud.id,
url: cloud.getAttribute("nbUrl"),
query: cloud.getAttribute("nbQuery"),
filter: cloud.getAttribute("nbFilter")
};
onClickCloudTab(config);
});
});
document.observe("nb:sortByChanged", function(evt)
{
var cloudArray = $$(".TagCloud");
cloudArray.each(function(cloud)
{
var query = cloud.getAttribute("nbQuery");
var sortBy = evt.memo.sortBy;
if (sortBy != null)
{
query += "&sortBy=" + sortBy;
}
var config = {
cloudId: cloud.id,
url: cloud.getAttribute("nbUrl"),
query: query,
filter: cloud.getAttribute("nbFilter")
};
onClickCloudTab(config);
});
});
function getTagCloudName(el) {
if (!el) {
return "";
}
el=$(el);
var tcaf = el.up(".TagCloudAndFilter");
if (tcaf) {
return tcaf.getAttribute("nbTextFilterName")||'';
}
return "";
}
function setTextFilterTc(s,el) {
var name = getTagCloudName(el);
if (name) {
return setTextFilter(s, "filterText"+name);
}
return setTextFilter(s);
}
document.observe("nb:textFilterChanged", function(evt)
{
var cloudArray = $$(".TagCloud");
cloudArray.each(function(cloud)
{
var config = {
cloudId: cloud.id,
url: cloud.getAttribute("nbUrl"),
query: cloud.getAttribute("nbQuery"),
filter: cloud.getAttribute("nbFilter")
};
onClickCloudTab(config);
});
});
