<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?>
<window id="yourwindow" title="xul json tags autosuggest" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="text/javascript">
<![CDATA[
// put some js code here
var req = new XMLHttpRequest();
function myCode() {
if (req.readyState == 4) {
var doc = eval('(' + req.responseText + ')');
var menuName = document.getElementById('lbl'); // finding a field
menuName.value = doc; // assigning a value to the field
}
}
function getTag(str){
var arrTagtocomplete = str.split(" ");
var tagtocomplete = arrTagtocomplete[arrTagtocomplete .length-1];
req.open("GET", "http://yourhost/project/tagging_xul.php?tag="+ tagtocomplete, true);
req.onreadystatechange = myCode; // the handler
req.send(null);
}
function keyPressed(value){
var txtTags = document.getElementById('your-tags'); // finding a field
if (value==13){
if (txtTags.value.substring(txtTags.value.length-1)!=' '){
var menuName = document.getElementById('lbl'); // finding a field
var strOldString = txtTags.value;
var arrOldString = strOldString .split(" ");
arrOldString[arrOldString.length-1] = getFirstWord(menuName.value);
txtTags.value = arrOldString.join(' ') + ' ';
var menuName = document.getElementById('lbl'); // finding a field
menuName.value = ''; // assigning a value to the field
}
}
}
function getFirstWord(str){
var arrTagtocomplete = str.split(",");
return arrTagtocomplete[0];
}
]]>
</script>
<label id="lbl" value="..."/>
<textbox type="autocomplete" autocompletesearch="history"/>
<vbox>
<label control="your-tags" value="Enter your Tags:"/>
<textbox id="your-tags" value="" oninput="getTag(this.value);" onkeydown="keyPressed(event.which);"/>
</vbox>
</window>
I used:
- Example from "jQuery Tag Suggestion"
- Real time XUL Editor (for testing)
- AviScreen Portable (to make this movie)
No comments:
Post a Comment