zotero/chrome/chromeFiles/content/scholar/bindings/searchtextbox.xml
Dan Stillman a972a035c7 Closes #260, Add auto-complete to search window
And fixed a bug that caused the text of some search conditions to not display when editing a previously saved search

Also added autocomplete to more fields in metadata pane:

- creator
- publisher
- place
- publicationTitle
- journalAbbreviation
- seriesTitle
- seriesText

It should also do the type and medium fields, but they need to be separated out first--e.g. artworkType, interviewMedium--since they're describing different data
2006-10-01 08:09:53 +00:00

160 lines
4.2 KiB
XML

<?xml version="1.0"?>
<!--
Zotero
Copyright (C) 2006 Center for History and New Media, George Mason University, Fairfax, VA
http://chnm.gmu.edu/
-->
<!DOCTYPE bindings SYSTEM "chrome://scholar/locale/searchbox.dtd">
<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="zotero-search-textbox">
<implementation>
<property name="value"
onget="return document.getAnonymousNodes(this)[0].value"
onset="document.getAnonymousNodes(this)[0].setAttribute('value', val); return val"/>
<property name="mode">
<getter>
<![CDATA[
if (this.getAttribute('hasOptions')!='true'){
return false;
}
var button = this.id('textbox-button');
var menu = this.id(button.popup);
var selectedIndex = -1;
for (var i=0; i<menu.childNodes.length; i++){
if (menu.childNodes[i].getAttribute('checked')=='true'){
selectedIndex = i;
break;
}
}
switch (button.popup){
case 'textbox-fulltext-menu':
switch (selectedIndex){
case 0:
return false;
case 1:
return 'phraseBinary';
case 2:
return 'regexp';
case 3:
return 'regexpCS';
}
break;
}
throw('Invalid search textbox popup');
]]>
</getter>
</property>
<method name="update">
<parameter name="condition"/>
<parameter name="mode"/>
<body>
<![CDATA[
var button = this.id('textbox-button');
switch (condition){
case 'fulltextContent':
button.popup = 'textbox-fulltext-menu';
button.setAttribute('popup', 'textbox-fulltext-menu');
var menu = this.id(button.popup);
this.setAttribute('hasOptions', true);
var selectedIndex = 0;
if (mode){
switch (mode){
case 'phrase':
selectedIndex = 0;
break;
case 'phraseBinary':
selectedIndex = 1;
break;
case 'regexp':
selectedIndex = 2;
break;
case 'regexpCS':
selectedIndex = 3;
break;
}
}
menu.childNodes[selectedIndex].setAttribute('checked', true);
break;
default:
this.setAttribute('hasOptions', false);
// Set textbox to autocomplete mode
switch (condition)
{
// Skip autocomplete for these fields
case 'note':
case 'extra':
break;
default:
var textbox = document.getAnonymousNodes(this)[0];
textbox.setAttribute('type', 'autocomplete');
textbox.setAttribute('autocompletesearch', 'zotero');
if (condition=='creator')
{
// 2 searches both single- and double-field creators
var autocompleteCondition = condition + '/2'
}
else
{
var autocompleteCondition = condition;
}
textbox.setAttribute('autocompletesearchparam', autocompleteCondition);
}
}
if (!autocompleteCondition)
{
var textbox = document.getAnonymousNodes(this)[0];
textbox.removeAttribute('type');
}
]]>
</body>
</method>
<method name="id">
<parameter name="id"/>
<body>
<![CDATA[
return document.getAnonymousNodes(this)[0].getElementsByAttribute('id',id)[0];
]]>
</body>
</method>
</implementation>
<content>
<xul:textbox xbl:inherits="flex">
<xul:popupset>
<xul:menupopup id="textbox-fulltext-menu">
<xul:menuitem type="radio" checked="true" label="&scholar.search.textModes.phrase;"/>
<xul:menuitem type="radio" label="&scholar.search.textModes.phraseBinary;"/>
<xul:menuitem type="radio" label="&scholar.search.textModes.regexp;"/>
<xul:menuitem type="radio" label="&scholar.search.textModes.regexpCS;"/>
</xul:menupopup>
</xul:popupset>
<xul:toolbarbutton id="textbox-button" type="menu"/>
</xul:textbox>
</content>
</binding>
</bindings>