/* Designed by J.Tabuchi This software is distributed under "Common Public License". (see for detail infomation) http://www.farfree.cn/ */ /* ### SAMPLE ### --------------------------------------------------- var p = new QrPulldown(_defaultValue, _defaultSize, _name); // Create QrPulldown Object. Any parameters may not be specified. // str = p.getHTML(); // get HTML for inserting this Pulldown; p.render(); // equals to document.write(p.getHTML()); p.set(value); // set value. p.get(); // get value. p.addItem(html,value); // add new Item for this pulldown --------------------------------------------------- link to BOTH the JavaScript code AND the CSS style sheet is needed for using. */ function QrPulldown(_defaultValue, _defaultSize, _Name){ if(!_defaultValue) _defaultValue = ""; if(!_defaultSize) _defaultSize = "16"; if(!_Name) _Name = " name=\""+_Name+"\" "; else _Name = ""; QrXPCOM.init(); this.itemLastId = 0; this.id = QrPulldown.lastid++; this.itemHtml = ""; this.defaultValue = _defaultValue; this.defaultSize = _defaultSize; this.name = _Name; QrPulldown.instanceMap["QrPulldown"+this.id] = this; } QrPulldown.prototype.getHTML = function(){ var html = "\n
\n
"; if(QrXPCOM.isIE()) html=html.replace(/\$IEPoint/,"style=\"margin-top:-1px\""); else html=html.replace(/\$IEPoint/,"");; return html.replace(/\$pulldownId/g,"QrPulldown"+this.id) .replace(/\$defaultSize/g,this.defaultSize) .replace(/\$defaultValue/g,this.defaultValue) .replace(/\$NamePoint/g,this.name); } QrPulldown.prototype.render = function(){ document.write(this.getHTML()); //this.after(); } QrPulldown.prototype.set = function(value){ document.getElementById("QrPulldown"+this.id+"#input").value = value; if(QrPulldown.instanceMap["QrPulldown"+this.id].onChange){ QrPulldown.instanceMap["QrPulldown"+this.id].onChange(value); } } QrPulldown.prototype.get = function(){ return document.getElementById("QrPulldown"+this.id+"#input").value; } QrPulldown.prototype.addItem = function (html,value){ var thisid = this.itemLastId++; var cashhtml = "
$html
"; cashhtml = cashhtml.replace(/\$pulldownId/g,"QrPulldown"+this.id).replace(/\$itemId/g,thisid).replace(/\$html/g,html).replace(/\$value/g,value); this.itemHtml += cashhtml; document.getElementById("QrPulldown"+this.id+"#menuinner").innerHTML = this.itemHtml; } QrPulldown.lastid = 0; QrPulldown.instanceMap = new Array; QrPulldown.onOut = function(id, itemid){ if(document.getElementById(itemid).className == "QrPulldownItemHover"){ document.getElementById(itemid).className = "QrPulldownItem"; } if(QrPulldown.instanceMap[id].onChange){ QrPulldown.instanceMap[id].onChange(document.getElementById(id+"#input").value); } } QrPulldown.onHover = function(id, itemid, value){ if(document.getElementById(itemid).className == "QrPulldownItem"){ document.getElementById(itemid).className = "QrPulldownItemHover"; } if(QrPulldown.instanceMap[id].onChange){ QrPulldown.instanceMap[id].onChange(value); } } QrPulldown.onButtonOut = function(id){ document.getElementById(id+"#img").src = "qrx/pulldown-normal.gif"; } QrPulldown.onButtonHover = function(id){ document.getElementById(id+"#img").src = "qrx/pulldown-down.gif"; } QrPulldown.onClick = function(id){ var p = QrXPCOM.getDivPoint(document.getElementById(id)); var r = QrXPCOM.getDivSize(document.getElementById(id)); if(QrXPCOM.isIE()) QrXPCOM.setDivPoint(document.getElementById(id+"#menu"), p.x+1, p.y+ 22); else QrXPCOM.setDivPoint(document.getElementById(id+"#menu"), p.x+1, p.y+ 22-1); document.getElementById(id+"#menu").style.display = ""; QrXPCOM.onPopup(document.getElementById(id+"#menu")); } QrPulldown.onKeyup = function(id){ if(QrPulldown.instanceMap[id].onChange){ QrPulldown.instanceMap[id].onChange(document.getElementById(id+"#input").value); } } QrPulldown.onSelect = function(id, value){ document.getElementById(id+"#input").value = value; document.getElementById(id+"#menu").style.display = "none"; if(QrPulldown.instanceMap[id].onSelect){ QrPulldown.instanceMap[id].onSelect(value); } if(QrPulldown.instanceMap[id].onChange){ QrPulldown.instanceMap[id].onChange(value); } }