commit 08238aefd0b23c202c6451738286f0a618de4c51
parent 7f732f56df4074a0af7a685481e570cbb3f7a5c4
Author: Simon Kornblith <simon@simonster.com>
Date: Sun, 22 Jul 2012 16:41:27 -0400
Speed up adding/deleting tags:
- Only refresh tag selector once when tags have changed. (The notifier fires both item-tag and tag events when a tag is added to an item.)
- Marginally improve code for generating tag selector.
Diffstat:
1 file changed, 41 insertions(+), 36 deletions(-)
diff --git a/chrome/content/zotero/bindings/tagselector.xml b/chrome/content/zotero/bindings/tagselector.xml
@@ -220,40 +220,37 @@
this._tags = Zotero.Tags.getAll(this._types, this.libraryID);
// Remove children
- while (tagsToggleBox.hasChildNodes()){
- tagsToggleBox.removeChild(tagsToggleBox.firstChild);
- }
+ tagsToggleBox.textContent = "";
- var me = this;
- var i=0;
+ var me = this,
+ onTagClick = function(event) { me.handleTagClick(event, this) },
+ lastTag;
for (var tagID in this._tags) {
+ var tagInfo = this._tags[tagID],
+ tagName = tagInfo.name;
// 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);
-
-
+ if(lastTag && lastTag.value === tagName) {
+ lastTag.setAttribute('tagID', lastTag.getAttribute('tagID') + '-' + tagID);
+ lastTag.setAttribute('tagType', lastTag.getAttribute('tagType') + '-' + tagName.type);
continue;
}
- let label = document.createElement('label');
- label.addEventListener('click', function(event) { me.handleTagClick(event, label) }, false);
- label.className = 'zotero-clicky';
+ lastTag = document.createElement('label');
+ lastTag.addEventListener('click', onTagClick, false);
+ lastTag.className = 'zotero-clicky';
- label.setAttribute('value', this._tags[tagID].name);
- label.setAttribute('tagID', tagID);
- label.setAttribute('tagType', this._tags[tagID].type);
+ lastTag.setAttribute('value', tagName);
+ lastTag.setAttribute('tagID', tagID);
+ lastTag.setAttribute('tagType', tagInfo.type);
if (this.editable) {
- label.setAttribute('context', 'tag-menu');
- label.addEventListener('dragover', this.dragObserver.onDragOver, false);
- label.addEventListener('dragexit', this.dragObserver.onDragExit, false);
- label.addEventListener('drop', this.dragObserver.onDrop, true);
+ lastTag.setAttribute('context', 'tag-menu');
+ lastTag.addEventListener('dragover', this.dragObserver.onDragOver, false);
+ lastTag.addEventListener('dragexit', this.dragObserver.onDragExit, false);
+ lastTag.addEventListener('drop', this.dragObserver.onDrop, true);
}
- tagsToggleBox.appendChild(label);
+ tagsToggleBox.appendChild(lastTag);
}
- i++;
this._dirty = false;
}
@@ -462,7 +459,7 @@
</body>
</method>
-
+ <field name="_notified"/>
<method name="notify">
<parameter name="event"/>
<parameter name="type"/>
@@ -500,19 +497,27 @@
}
}
- // This could be more optimized to insert new/changed tags at the appropriate
- // spot if we cared, but we probably don't
- var t = this.id('tags-search').inputField;
- this.setFilterTags(Zotero.Tags.search(t.value), true);
- this._dirty = true;
- this.doCommand();
+ if(this._notified) return;
- // If no tags visible after a delete, deselect all
- if ((event == 'remove' || event == 'delete') &&
- this._empty && this.getNumSelected()) {
- Zotero.debug('No tags visible after delete -- deselecting all');
- this.clearAll();
- }
+ var me = this;
+ window.setTimeout(function() {
+ me._notified = false;
+
+ // This could be more optimized to insert new/changed tags at the appropriate
+ // spot if we cared, but we probably don't
+ var t = me.id('tags-search').inputField;
+ me.setFilterTags(Zotero.Tags.search(t.value), true);
+ me._dirty = true;
+ me.doCommand();
+
+ // If no tags visible after a delete, deselect all
+ if ((event == 'remove' || event == 'delete') &&
+ me._empty && me.getNumSelected()) {
+ Zotero.debug('No tags visible after delete -- deselecting all');
+ me.clearAll();
+ }
+ }, 0);
+ this._notified = true;
]]>
</body>
</method>