Custom menu instances in the Web window

Source: Internet
Author: User

<! Doctype HTML public "-// W3C // dtd html 4.0 transitional // en">
<HTML>
<Head>
<Title> agetimemenu demo </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312">
<Style>
. Agetime_bar {
Position: absolute; top: 0px; left: 0px; Height: 22px; width: 100%; Border: 1px outset; Background-color: RGB (212,208,200); Z-index: 98;
}
. Agetime_baritem {
Width: 60px; Height: 20px; Border: 1px solid RGB (212,208,200); text-align: Left; padding-left: 10px;
Background: RGB (212,208,200); color: #000000; font-size: 9pt;
}
. Agetime_baritemdown {
Width: 60px; Height: 20px; Border: 1px inset RGB (212,208,200); text-align: Left; padding-left: 10px;
Background: # f0f0f0; color: #000000; font-size: 9pt;
}
. Agetime_baritemhover {
Width: 60px; Height: 20px; Border: 1 outset; text-align: Left; padding-left: 10px;
Background: # f0f0f0; color: #000000; font-size: 9pt;
}
. Agetime_pad {
Cursor: default; font-size: 9pt; width: 100%;
}
. Agetime_paditem {
Width: 100%; Height: 18px; Border: 1px solid RGB (212,208,200); text-align: Left; padding-left: 10px;
Background: RGB (212,208,200); color: #000000; font-size: 9pt;
}
. Agetime_paditemfalse {
Padding-left: 10px; font-size: 9pt; color: #808080;
}
. Agetime_paditemfalsehover {
Padding-left: 10px; font-size: 9pt; color: #808080; Background-color: #333366;
}
. Agetime_paditemhover {
Width: 100%; Height: 18px; text-align: Left; padding-left: 10px;
Background-color: #333366; color: # ffffff; font-size: 9pt;
}
. Agetime_paditemdown {
Width: 100%; Height: 18px; text-align: Left; padding-left: 10px; Border: 1px inset;
Background-color: # 9999cc; color: # ffffff; font-size: 9pt;
}
. Agetime_hr {
Border: 1px inset;
}
. Agetime_board {
Background-color: RGB (212,208,200); Border: 2px outset;
}
</Style>
</Head>
<Body>
<Script language = "JavaScript">
VaR menu = agetimemenu ("agetime ",
[
[
["File", null, null, true, "Open File"], // display text, method, command, status, text in the text bar
["Open", null, null, false, "Open File"],
["--"],
["Hello", "JS", "alert ('hello')", true, "Greetings"],
["New window", "ABC", "about: blank", true, "pop-up ABC window"],
["Blank", null, "about: blank", true, "blank page displayed in current window"]
],
[
["Edit", null, null, false, "Open File"],
["Undo", null, null, true, "Open File"],
["Redo", null, null, true, "Open File"]
],
[
["File", "JS", "alert ('no submenus ')", true, "Open File"]
]
]
);
// When the method is "JS", the command is a javascript statement. If it is not a "JS" value, the command is a URL, the target location of the URL is the window specified by the method;
// ["Hello", "JS", "alert ('hello'), true," greeting "];
// The displayed text is "--", indicating that the button is a separator;
Function agetimemenu (ID, array ){
VaR menu = this;
Menu. Pad = NULL; // load each sub-menu
Menu. baritems = []; // buttons of the menu bar
Menu. pads = []; // each sub-menu stores a table on menu. pad;
Menu. selectedindex =-1; // index value of the selected button in the menu bar
Menu. Board = NULL; // sub-menu panel

// Create a menu bar
This. crtmenubar = function (){
VaR Len = array. length;
Menu. bar = Document. Body. appendchild (document. createelement ('div '));
Menu. Bar. classname = ID + "_ BAR ";
For (VAR I = 0; I <Len; I ++ ){
Menu. baritems [I] = menu. addmenubaritem (array [I] [0], I );
Menu. addmenupad (array [I], I );
}
}

// Submenu
This. addmenupad = function (ary, index ){
VaR Len = ary. length;
VaR pad = menu. crtelement ("table", menu. Pad );
Pad. cellspacing = 1; pad. cellpadding = 0;
Pad. classname = ID + "_ pad ";
Pad. style. Display = "NONE ";
For (VAR I = 1; I <Len; I ++ ){
VaR ROW = pad. insertrow (I-1 );
Menu. addmenupaditem (ary [I], row );
}
Menu. pads [Index] = pad;
}

// Submenu buttons
This. addmenupaditem = function (ary, row ){
VaR cell = row. insertcell (0 );
If (ary [0]! = "--"){
Cell. innertext = ary [0];
If (ary [3]) {// valid state;
Cell. classname = ID + "_ paditem ";
Cell. onmouseover = function (){
Cell. classname = ID + "_ paditemhover ";
Window. Status = ary [4];
}
Cell. onmouseout = function (){
Cell. classname = ID + "_ paditem ";
Window. Status = "";
}
Cell. onmousedown = function () {Cell. classname = ID + "_ paditemdown ";}
Cell. onmouseup = function (){
Cell. classname = ID + "_ paditemhover ";
Menu. hidemenu ();
Menu.exe cute (ary );
}
}
Else {// The button is invalid;
Cell. classname = ID + "_ paditemfalse ";
Cell. onmouseover = function (){
Cell. classname = ID + "_ paditemfalsehover ";
Window. Status = ary [4];
}
Cell. onmouseout = function (){
Cell. classname = ID + "_ paditemfalse ";
Window. Status = "";
}
}
}
Else {
VaR hR = menu. crtelement ("HR", cell );
HR. classname = ID + "_ hr ";
}
Cell. onclick = function (){
Event. cancelbubble = true;
}
}

// Button of the menu bar
This. addmenubaritem = function (ary, index ){
VaR item = menu. crtelement ("button", menu. bar );
Item. value = ary [0];
Item. Disabled =! Ary [3];
Item. classname = ID + "_ baritem ";
Item. onmouseover = function (){
If (menu. selectedindex =-1 ){
Item. classname = ID + "_ baritemhover ";
}
Else {
Menu. baritems [selectedindex]. classname = ID + "_ baritem ";
Item. classname = ID + "_ baritemdown ";
Menu. showmenu (INDEX );
}
Window. Status = ary [4];
}
Item. onmouseout = function (){
If (menu. selectedindex =-1) item. classname = ID + "_ baritem ";
Window. Status = "";
}
Item. onclick = function (){
Event. cancelbubble = true;
If (menu. selectedindex =-1 ){
Item. classname = ID + "_ baritemdown ";
Menu. showmenu (INDEX );
}
Else {
Menu. hidemenu ();
Item. classname = ID + "_ baritemhover ";
}
Menu.exe cute (ary );
Item. Blur ();
}
Return item;
}
// Display sub-menu
This. showmenu = function (INDEX ){
If (menu. selectedindex! =-1) menu. pads [selectedindex]. style. Display = "NONE ";
Menu. Board. style. pixelleft = menu. baritems [Index]. offsetleft + 2;
// Menu. Board. style. pixelheight = "";
If (menu. pads [Index]. Rows. length> 0) menu. Board. style. Display = "";
Else menu. Board. style. Display = "NONE ";
Menu. pads [Index]. style. Display = "";
Menu. selectedindex = index;
}
// Hide the sub-menu
This. hidemenu = function (){
If (menu. selectedindex =-1) return;
Menu. baritems [menu. selectedindex]. classname = ID + "_ baritem ";
Menu. pads [selectedindex]. style. Display = "NONE ";
Menu. selectedindex =-1;
Menu. Board. style. Display = "NONE ";
}

// Execute the menu command;
This.exe cute = function (ary ){
If (ary [2] = NULL) return;
If (ary [1] = "JS") {eval (ary [2]); menu. hidemenu ();}
Else if (ary [1] = NULL | ary [1]. tolowercase = "_ Self") location. href = ary [2];
Else {var x = Window. Open (ary [2], Ary [1]); X. Focus ();}
}

// Create a sub-menu display panel
This. crtmenuboard = function (){
Document. Write (
"<Div id = '" + ID + "_ board 'style = 'position: absolute; width: 160px; Height: 10px; left: 0px; top: 20px; background-color: #666666; Z-index: 99; display: none; '> "+
"<Div style = 'position: absolute; width: 100%; Height: 100%; left: 0px; top: 0px; '>" +
"<IFRAME id = '" + ID + "_ frame 'name ='" + ID + "_ frame 'width = '000000' Height = '000000' frameborder = '0' scrolling = 'no'> </iframe> "+
"</Div>" +
"<Div id = '" + ID + "_ pad 'style = 'position: absolute; width: 100%; Height: 100%; left: 0px; top: 0px; '> </div> "+
"</Div>"
);
Menu. Board = Document. getelementbyid (ID + "_ Board ");
Menu. Pad = Document. getelementbyid (ID + "_ pad ");
Menu. Pad. classname = ID + "_ board ";
Menu. Pad. onselectstart = function () {return false ;}
}

// Add a child element of the object
This. crtelement = function (El, p ){
Return P. appendchild (document. createelement (EL ));
}

// Installation menu;
This. Setup = function (){
Menu. crtmenuboard ();
Menu. crtmenubar ();
Document. attachevent ("onclick", menu. hidemenu );
}

Menu. Setup ();
}
</SCRIPT>
</Body>
</Html>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.