Português
<html> <head> </head> <script language="javascript"> function PageLoad() { /*var meuMenu = new MainMenu('menu','test.xml'); var meuMenu = new MainMenu('menu'); var menuFile = new MenuItem('Arquivo','Arquivo',null,'F'); ("SaveAs")','S'); var menuExit = new MenuItem('Sair','Sair','Sair()','X'); ,null,'E'); var menuView = new MenuItem('View','View',null,'V'); )'); var menuConf = new MenuItem('Conf','Inicializado através do arquivo de configuração','SelectOpt(this)'); new MenuItem('Chk1','Teste: Verifique a opção 1','CheckOpt(this)'); menuHelp = new MenuItem('Ajuda','Ajuda',null,'H'); ','Conteúdo da ajuda',null,'C'); var menuAbout = new MenuItem('About','About MenuItem','alert("MenuItem Ver1.00 por Akira(akira_cn@msn.com)")', 'A'); menuFile.addChild(menuSave); menuView.addLine(); menuChk.addChild(menuChk1); menuChk.addChild(menuChk2); menuHelp.addChild(menuTopics); addItem(menuEdit); meuMenu.addItem(menuView); menuContent.Disable(); .Check(); } function contact() { alert('Entre em contato conosco'); function Exit() { self.opener = self.close(); ('editBox1'); var editBox2 = document.getElementById('editBox2'); if (target.id == 'Conf') { editBox1.style.display = "none"; } else { editBox2.style.display = "none"; editBox1.style.display = "bloco"; style='padding:0 0 0 0;margin:0 0 0 0' onload='PageLoad()'> <textarea id="editBox1" style="width:100%;height:90%"> Inicialize a página principal através do programa Exemplo de menu: <script> var myMenu = new MainMenu('menu var menuFile = new MenuItem('File','File',null,'F'); 'Salvar','document.execCommand("SalvarComo")','S'); ( 'Editar','Editar',null,'E'); var menuView = new MenuItem('Visualizar','Visualizar',null,'V'); script Initialize','SelectOpt(this)'); var menuConf = new MenuItem('Conf','Inicializar através do arquivo de configuração','SelectOpt(this)'); Opção Complexa 1','CheckOpt(this)'); var menuChk2 = new MenuItem('Chk1','Test: Verificar Opção 2','CheckOpt(this)'); Help ',null,'H'); var menuTopics = new MenuItem('Tópicos','Tópico de ajuda',null,'T'); C '); var menuAbout = new MenuItem ('About','AboutMenuItem','alert('MenuItem Ver1.00 por Akira(akira_cn@msn.com)')','A'); ; meuMenu.addItem(menuEdit); meuMenu.addItem(menuView); menuView.addLine(); //Linhas separadas menuView.addChild(menuChk1); menuHelp.addLine(); ; myMenu.Show(); menuEdit.Disable(); menuTopics.Disable(); editBox2" style="width:100%;height:90%;display:none"> Exemplo de inicialização do menu principal através de um arquivo de configuração: <!--xml arquivo de configuração, por exemplo, salve-o como test.xml-- > <?xml versão ="1.0" encoding="gb2312" standalone="yes"?> <MainMenu> <MenuItem id="Arquivo" Text="Arquivo" Accelerator="F"> <MenuItem id="Salvar" Texto ="Salvar" Accelerator ="S" onClick="document.execCommand('SaveAs')"/> <MenuItem id="Exit" Text="Exit" Accelerator="X" onClick="Exit()"/> < /MenuItem> <MenuItem id="Edit" Text="Edit" Accelerator="E" Disabled="true"> </MenuItem> <MenuItem id="View" Text="View" Accelerator="V"> <MenuItem id="Prog" Text="Inicializado através do script do programa" Selected="true" onClick="SelectOpt(this)"/> <MenuItem id="Conf" Text="Inicializado através do arquivo de configuração" onClick="SelectOpt(this) "/> <MenuItem /> <MenuItem id="Chk1" Text="Teste: Verifique a opção 1" Checked="true" onClick="CheckOpt(this)"/> <MenuItem id="Chk2" Text="Teste: Verifique a opção 2" onClick ="CheckOpt(this)"/> </MenuItem> <MenuItem id="Help" Text="Help" Accelerator="H"> <MenuItem id="Topics" Text="Help Topics" Acelerador ="T" Disabled ="true"/> <MenuItem id="Content" Text="Conteúdo de ajuda" Accelerator="C" Disabled="true"/> <MenuItem/> <MenuItem id="Sobre" Text=" Sobre MenuItem" Accelerator= "A" onClick="alert('MenuItem Ver1.00 by Akira(akira_cn@msn.com)')"/> </MenuItem> </MainMenu> <script> var myMenu = new MainMenu(' menu','test .xml'); //Lê as informações do menu do arquivo de configuração test.xml myMenu.Show(); ---- ---------------------------------------------- ---- --------------- Parte principal do programa de controle de menu Versão 1.00 Akira (akira_cn@msn.com) --------------- - ------------------------------------------------- - ---> <linguagem de script = "javascript"> function MenuItem (id, texto, clickEvent, acelerador, subWidth) { this.id = null; this.text = null; if (id == null) { this.id = "menu" + (new Date()).getTime() } else this.id = id; .subWidth = 0 for (var i = 0; this.text != null && i < this.text.length; i++) { this.subWidth = this.subWidth - 0 + (text.charCodeAt(i) > 127 ? 20: 10); //this.subWidth = this.text != null ? this.text.length * 16 : 96;//100 } else this.subWidth = subWidth; onclick = function(){}; else this.onclick = function(){eval(clickEvent);} if (accelerator != null) //Tecla de atalho { this.accelerator = accelerator } this.subMenuItems = new Array ( ); this.visible = true; this.disabled = false; this.visible = false; this.selected = false; "nenhum"; } MenuItem.prototype.Show = function() { this.visible = true; this._span.style.display = "bloco" } MenuItem.prototype.Enable = function() { this.disabled = false ; this._span.EventHandler = this; this._span.onmouseover = function(){this.EventHandler._span_MouseOver(this,event);} this._span.onmouseout = function(){this.EventHandler._span_MouseOut(this,event) );} this._span.onclick = function(){this.EventHandler._span_Click(this,event);} this._span.style.color = "#000000"; MenuItem.prototype.Disable = function() { this. .disabled = true; this._span.onmouseover = function(){} this._span.onmouseout = function(){} this._span.onclick = function(){} this._span.style.color = "#ACA899" ; } MenuItem.prototype.Check = function() { if (!this.checked) { var textObj = document.createElement('b'); textObj.innerText = '√'; (var i = 0; i < this._span.childNodes.length - 1; i++) { this._span.appendChild(this._span.removeChild(this._span.childNodes[i]) } this.checked = true ; this._span.style.paddingLeft = "6px"; else { this._span.removeChild (this._span.childNodes[0]); } } MenuItem.prototype.Select = function() { var parent = this.parent; for (var i = 0; i < parent.subMenuItems.length; i++) { parent.subMenuItems[i]._unselect(); liObj = document.createElement("li"); this._span.appendChild(liObj); for (var i = 0; i < this._span.childNodes.length - 1; i++) { liObj.appendChild(this._span. removeChild(this._span.childNodes[i])); } this.selected = true; //this.subWidth = this.subWidth - 0 + 16; ._unselect = function() { if (this.selected) { var liObj = this._span.removeChild(this._span.childNodes[0]); { this._span.appendChild(liObj.childNodes[i]); this.selected = false; this._span.style.paddingLeft = "18px"; protótipo.addChild = function(menuItem) { this.subMenuItems.push(menuItem.parent = this } MenuItem.prototype.addLine = function() { this.addChild(new MenuItem()); hasChild = function() { return this.subMenuItems.length > 0 } this._span = document.createElement("span"); ; if (this.text == null) { this._span.appendChild(document.createElement("hr")); this._span.style.height = "2px"; ; this._span.style.marginBottom = "2px"; else { if (acelerador! = nulo) { var site = text.indexOf (acelerador). 0, site); var part2 = text.slice(site + 1); var textNode1 = document.createTextNode("font"); .style.textDecoration = "sublinhado"; node.innerText = acelerador; this._span.appendChild(textNode1); this._span.appendChild(node); createTextNode(text + "("); var node = document.createElement("font"); node.style.textDecoration = "underline"; node.innerText = acelerador; this._span.appendChild(textNode); this._span. anexarChild(node); this._span.appendChild(document.createTextNode(")")); this.subWidth = this.subWidth - 0 + 48; .appendChild(textNode); } this._span.style.height = "20px"; this._span.style.marginTop = "2px"; = "12px"; isto._span.style.paddingTop = "5px"; isto._span.style.paddingLeft = "18px"; ._span.onmouseover = function(){this.EventHandler._span_MouseOver(this,event);} this._span.onmouseout = function(){this.EventHandler._span_MouseOut(this,event);} this._span.onclick = função (){this.EventHandler._span_Click(this,event);} } if (acelerador!= null) { this.accelerator = accelerator.charCodeAt(0 } MenuItem.prototype.ShowSubmenu = function() { var pos = this); .getObjPosition(); var subSpan = document.createElement("span"); subSpan.style.position = "absoluto" if(this.parent instanceof MainMenu) { subSpan.style.left = subSpan.style; .top = pos[1] + this._span.clientHeight } else { subSpan.style.left = pos[0] + this._span.clientWidth + 1; style.paddingLeft = "0px"; subSpan.style.width = 0; subSpan.style.backgroundColor = "#FFFFFF"; ; subSpan.className = "subMenu"; subSpan.owner = this.id; //this._span.onmouseout = function(){}; .subMenuItems[i]._span.style.marginTop = 0; this.subMenuItems[i]._span.style.marginBottom = 0; this.subMenuItems[i]._span.style.width = "100%"; .subWidth < this.subMenuItems[i].subWidth) { this.subWidth = this.subMenuItems[i].subWidth } subSpan.appendChild(this.subMenuItems[i]._span } subSpan.style.width = this. subWidth > 96? this.subWidth: 96; //this._span.appendChild(subSpan); document.body.appendChild(subSpan); ) { if (!this.hasChild() || this.clickEvent) { this.hideSubmenu(true); this.onclick(); parent._showSub = true; } if (event.stopPropagation) event.stopProgpagation (); (remetente); if(this.hasChild() && (this.parent._showSub || this.parent instanceof MenuItem)) { this.ShowSubmenu() } } MenuItem.prototype._span_MouseOut = function(remetente, evento) { this; ._cleanMenu(sender); //this.hideSubmenu(); } MenuItem.prototype._activeMenu = function(menuSpan) { menuSpan.style.backgroundColor = "#316AC5"; .prototype._cleanMenu = function(menuSpan) { if (menuSpan.parentNode.className == "subMenu") menuSpan.style.backgroundColor = "#FFFFFF"; color = "#000000"; } MenuItem.prototype.hideSubmenu = function(bHideAll) { var subMenus = document.getElementsByTagName("span"); ) { if (subMenus[i].className == "subMenu" && (bHideAll || !this.isParentOf(subMenus[i].owner))) { if (bHideAll) { var parent = this.parent while (pai; != null) { parent._showSub = false; parent = parent.parent } } this._cleanMenu(this._span); isParentOf = function(owner) { var parent = this.parent; while(parent != null) { if (owner == parent.id) return true; coordenadas MenuItem.prototype.getObjPosition = function() { var obj = this._span; var objLeft = obj.offsetLeft; { objLeft += objParent.offsetLeft; objTop += objParent.offsetTop; objParent.offsetParent } return([objLeft,objTop]); ( this); if (document.body.onkeydown == null) { document.body.onkeydown = function() { for (var i = 0; i < MenuItem.Instances.All.length; i++) { if (MenuItem. Instâncias .All[i].accelerator != null) { if (event.altKey && event.keyCode == MenuItem.Instances.All[i].accelerator) { MenuItem.Instances.All[i]._span_Click.call(MenuItem .Instâncias.All[i],MenuItem.Instances.All[i]._span,event); .Instâncias.All[0].hideSubmenu(true); } MenuItem.Instances = new MenuItem.Instances.All = new Array(); ( ); this.parent = null; this.id = id; MainMenu.prototype._loadCfg = function(src) //Ler do arquivo de configuração { try { var objXMLDoc = new ActiveXObject("Microsoft.XMLDOM"); async = false; objXMLDoc.load(src); if (objXMLDoc.documentElement == null) throw new TypeError("Falha na análise do documento XML! "); return objXMLDoc; } catch(e) { alert("Falha na análise do documento XML!"); throw new TypeError("Falha na análise do documento XML!"); } } MainMenu.prototype._applyCfg = function(element, menuItem) { var id = element.getAttribute("id var text = element.getAttribute("Texto var onClick = element.getAttribute("onClick"); subMenuItem = new MenuItem(id,text,onClick,Accelerator); if(menuItem! = null) menuItem.addChild(subMenuItem else this.addItem(subMenuItem); ; i++) { if (element.childNodes[i].tagName == "MenuItem") { this._applyCfg(element.childNodes[i], subMenuItem). cfgElements = xmlDoc.getElementsByTagName("MenuItem"); for (var i = 0; i < cfgElements.length; i++) { var element = cfgElements[i]; element.getAttribute("Verificado"); var selecionado = element.getAttribute("Selecionado var visível = element.getAttribute("Visível"); null) { continuar; } if (marcado == "true") { MenuItem.Instances[id].Check(); if (visible == "false") { MenuItem.Instances[id].Hide() } if (disabled == "true") { MenuItem.Instances[id].Disable(); menuItem = function(id) { return this._find(id, this.items } MainMenu.prototype._find = function(id, items) { for (var i = 0; i < items.length; i++) { se (items[i].id == id) { return itens[i] } if (items[i].subMenuItems.length > 0) { this._find(id, items[i].subMenuItems); null; } MainMenu.prototype.addItem = function (menuItem) { this.items.push (menuItem); itens); } MainMenu.prototype._delete = function(id, itens) { for (var i = 0; i < itens.length; i++) { if (items[i].id == id) { var item = itens [i]; items.splice(i); return item; if (items[i].subMenuItems.length > 0) { this.find(id, items[i].subMenuItems); ._div = document.createElement("div"); this._div.id = this.id; this._div.style.height = "24px"; .body.appendChild(this._div); if(cfgSrc != null) { var objXMLDoc = this._loadCfg(cfgSrc); O documento XML não é um arquivo legal de configuração do menu principal! (O nome da tag do elemento raiz não é MainMenu)"); throw new TypeError("O documento XML não é um arquivo de configuração legal do menu principal! (O nome da tag do elemento raiz não é MainMenu)"); } for ( var i = 0; i < rootElement .childNodes.length; i++) { if (rootElement.childNodes[i].tagName == "MenuItem") { this._applyCfg(rootElement.childNodes[i]); (objXMLDoc); } MainMenu.prototype .Show = function() { document.body.appendChild(this._div); for (var i = 0; i < document.body.childNodes.length; i++) { if(document. body.childNodes[i].id != this.id) { document.body.appendChild(document.body.removeChild(document.body.childNodes[i])); .items.length; i++) { this._div.appendChild(this.items[i]._span);