zotero/chrome/chromeFiles/content/scholar/customControls.xml
2006-07-05 17:59:17 +00:00

240 lines
No EOL
6.4 KiB
XML

<?xml version="1.0"?>
<bindings xmlns="http://www.mozilla.org/xbl"
xmlns:xbl="http://www.mozilla.org/xbl"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<binding id="timed-textarea" extends="chrome://global/content/bindings/textbox.xml#textarea">
<implementation>
<field name="_timer">null</field>
<property name="timeout"
onset="this.setAttribute('timeout', val); return val;"
onget="return parseInt(this.getAttribute('timeout')) || 0;"/>
<property name="value">
<getter>
return this.inputField.value;
</getter>
<setter>
<![CDATA[
this.inputField.value = val;
if (this._timer)
clearTimeout(this._timer);
return val;
]]>
</setter>
</property>
<method name="_fireCommand">
<parameter name="me"/>
<body>
<![CDATA[
me._timer = null;
me.doCommand();
]]>
</body>
</method>
</implementation>
<handlers>
<handler event="input">
<![CDATA[
if (this._timer)
clearTimeout(this._timer);
this._timer = this.timeout && setTimeout(this._fireCommand, this.timeout, this);
]]>
</handler>
</handlers>
</binding>
<binding id="note-editor">
<implementation>
<field name="itemRef"/>
<property name="item" onget="return this.itemRef;">
<setter>
<![CDATA[
this.itemRef = val;
var citeLabel = document.getAnonymousNodes(this)[0].childNodes[0];
if(citeLabel.firstChild)
citeLabel.removeChild(citeLabel.firstChild);
if(this.item)
citeLabel.appendChild(document.createTextNode(this.item.getField('title')));
]]>
</setter>
</property>
<field name="noteRef"/>
<property name="note" onget="return this.noteRef;">
<setter>
<![CDATA[
this.noteRef = val;
if(this.note.getNoteSource())
this.item = Scholar.Items.get(this.note.getNoteSource());
document.getAnonymousNodes(this)[0].childNodes[1].setAttribute('value',this.note.getNote());
document.getAnonymousNodes(this)[0].lastChild.firstChild.item = this.note;
this.updateTagsSummary();
]]>
</setter>
</property>
<property name="value" onget="return document.getAnonymousNodes(this)[0].childNodes[1].value;" onset="document.getAnonymousNodes(this)[0].childNodes[1].value = val;"/>
<method name="save">
<body>
<![CDATA[
var noteField = document.getAnonymousNodes(this)[0].childNodes[1];
if(this.note) //Update note
{
this.note.updateNote(noteField.value);
}
else //Create new note
{
if(this.item)
var noteID = Scholar.Notes.add(noteField.value,this.item.getID()); //attached to an item
else
var noteID = Scholar.Notes.add(noteField.value); //independant note
this.note = Scholar.Items.get(noteID);
}
]]>
</body>
</method>
<method name="focus">
<body>
<![CDATA[
document.getAnonymousNodes(this)[0].childNodes[1].focus();
]]>
</body>
</method>
<method name="updateTagsSummary">
<body>
<![CDATA[
var popup = document.getAnonymousNodes(this)[0].lastChild;
var label = popup.previousSibling;
var v = popup.firstChild.summary;
if(!v || v == "")
v = "[click here]";
while(label.hasChildNodes())
label.removeChild(label.firstChild);
label.appendChild(document.createTextNode("Tags: " + v));
]]>
</body>
</method>
</implementation>
<handlers>
</handlers>
<content>
<xul:vbox xbl:inherits="flex">
<xul:label/>
<xul:textbox multiline="true" type="timed" timeout="1000" flex="1" oncommand="this.parentNode.parentNode.save();"/>
<xul:label value="See also: (coming soon)"/>
<xul:label onclick="this.nextSibling.showPopup(this,-1,-1,'popup',0,0);"/>
<xul:popup width="300" onpopuphidden="this.parentNode.parentNode.updateTagsSummary();">
<xul:tagsbox flex="1"/>
</xul:popup>
</xul:vbox>
</content>
</binding>
<binding id="tags-box">
<implementation>
<field name="itemRef"/>
<property name="item" onget="return this.itemRef;">
<setter>
<![CDATA[
this.itemRef = val;
this.reloadTags();
]]>
</setter>
</property>
<property name="summary">
<getter>
<![CDATA[
var r = "";
if(this.item)
{
var tags = this.item.getTags();
for(var i = 0; i < tags.length; i++)
{
r = r + Scholar.Tags.getName(tags[i]) + ", ";
}
r = r.substr(0,r.length-2);
}
return r;
]]>
</getter>
</property>
<method name="reloadTags">
<body>
<![CDATA[
var rows = document.getAnonymousNodes(this)[0].lastChild.lastChild;
while(rows.hasChildNodes())
rows.removeChild(rows.firstChild);
if(this.item)
{
var tags = this.item.getTags();
for(var i = 0; i < tags.length; i++)
{
var icon= document.createElement("image");
icon.setAttribute('src','chrome://scholar/skin/tag.png');
var label = document.createElement("label");
label.setAttribute('value', Scholar.Tags.getName(tags[i]));
label.setAttribute('crop','end');
var remove = document.createElement("label");
remove.setAttribute('value','-');
remove.setAttribute('onclick',"this.parentNode.parentNode.parentNode.parentNode.parentNode.removeTag('"+tags[i]+"');");
remove.setAttribute('class','clicky');
var row = document.createElement("row");
row.appendChild(icon);
row.appendChild(label);
row.appendChild(remove);
rows.appendChild(row);
}
}
]]>
</body>
</method>
<method name="addTag">
<body>
<![CDATA[
t = prompt('Add Tag:');
if(t && this.item)
{
this.item.addTag(t);
this.reloadTags();
}
]]>
</body>
</method>
<method name="removeTag">
<parameter name="id"/>
<body>
<![CDATA[
if(id)
{
this.item.removeTag(id);
this.reloadTags();
}
]]>
</body>
</method>
</implementation>
<content>
<xul:vbox xbl:inherits="flex">
<xul:button label="Add Tag" oncommand="this.parentNode.parentNode.addTag();"/>
<xul:grid>
<xul:columns>
<xul:column/>
<xul:column flex="1"/>
<xul:column/>
</xul:columns>
<xul:rows/>
</xul:grid>
</xul:vbox>
</content>
</binding>
</bindings>