Adds tag cloud feature. Use about:config to turn on.

This commit is contained in:
Asa Kusuma 2008-08-08 19:39:06 +00:00
parent fad829635b
commit 005375cc33
2 changed files with 80 additions and 2 deletions

View file

@ -177,19 +177,25 @@
tagsToggleBox.removeChild(tagsToggleBox.firstChild);
}
// Regenerate list
var i=0;
for (var tagID in this._tags) {
// If the last tag was the same, add this tagID and tagType to it
if (tagsToggleBox.lastChild &&
tagsToggleBox.lastChild.getAttribute('value') == this._tags[tagID].name) {
tagsToggleBox.lastChild.setAttribute('tagID', tagsToggleBox.lastChild.getAttribute('tagID') + '-' + tagID);
tagsToggleBox.lastChild.setAttribute('tagType', tagsToggleBox.lastChild.getAttribute('tagType') + '-' + this._tags[tagID].type);
continue;
}
var label = document.createElement('label');
label.setAttribute('onclick', "this.parentNode.parentNode.parentNode.handleTagClick(event, this)");
label.className = 'zotero-clicky';
label.setAttribute('value', this._tags[tagID].name);
label.setAttribute('tagID', tagID);
label.setAttribute('tagType', this._tags[tagID].type);
@ -199,7 +205,7 @@
label.setAttribute('ondragdrop', 'nsDragAndDrop.drop(event, this.parentNode.parentNode.parentNode.dragObserver)');
tagsToggleBox.appendChild(label);
}
i++;
this._dirty = false;
}
@ -282,6 +288,75 @@
}
}
//start tag cloud code
var tagCloud = Zotero.Prefs.get('tagCloud');
if(tagCloud) {
var labels = tagsToggleBox.getElementsByTagName('label');
//loop through displayed labels and find number of linked items
var numlinked= [];
for (var i=0; i<labels.length; i++){
if(labels[i].getAttribute("hidden") != 'true') {
var tagIDs = labels[i].getAttribute('tagID').split('-');
//replace getLinkedItems() with function that gets linked items within the current collection
var linked = this._tags[tagIDs[0]].getLinkedItems();
numlinked.push(parseInt(linked.length));
}
}
//
numlinked.sort();
//Get number of attached items from tag with fewest items
var min = numlinked[0];
//Get number of attached items from tag with most items
var max = numlinked.pop();
numlinked.push(max);
//Create array of possible tag text sizes
var sizes = ["11", "12", "13", "14", "15", "16", "17", "18", "19","20","21","22"];
//Number of possible tag sizes
var categories = sizes.length;
//inc is the size of each size category of tags, in terms of the number of attached items
var inc = Math.ceil((max-min)/categories);
if(inc<1) {
inc = 1;
}
for (var i=0; i<labels.length; i++){
if(labels[i].getAttribute("hidden") != 'true') {
var tagIDs = labels[i].getAttribute('tagID').split('-');
//replace getLinkedItems() with function that gets linked items within the current collection
var linked = this._tags[tagIDs[0]].getLinkedItems();
numlink = linked.length;
//range is the difference between how many items this tag has and how many items the smallest tag has
var range=(numlink-min);
//Divide the range by the size of the categories
s=range/inc;
if(s==categories) {
s=categories-1;
}
var stylestr = 'font-size:'+sizes[s]+'px;';
labels[i].setAttribute('style',stylestr);
}
}
}
//end tag cloud code
this.updateNumSelected();
this._empty = empty;

View file

@ -35,6 +35,9 @@ pref("extensions.zotero.lastAbstractExpand",0);
pref("extensions.zotero.lastRenameAssociatedFile", false);
pref("extensions.zotero.lastViewedFolder", 'L');
//Tag Cloud
pref("extensions.zotero.tagCloud", true);
// Keyboard shortcuts
pref("extensions.zotero.keys.overrideGlobal", false);
pref("extensions.zotero.keys.openZotero", 'Z');