At last, I will summarize some small problems in the example. Nothing is too important, mainly for better UI.
The style filter is used to support the display of special effects,Code:
Menu. Prototype. fadeineffect = function (effect) # Region Menu. Prototype. fadeineffect = function (effect)
Menu. Prototype. fadeineffect = Function (Effect)
{
If ( ! This . M_popup | ! This . M_popup.isopen)
{
Return ;
}
VaR Menuhtml = This .M_popup.doc ument. getelementbyid ('menu ');
If ( ! Menuhtml)
{
Return ;
}
VaR Filterstring = 'Progid: DXImageTransform. Microsoft .';
Switch (Effect)
{
Case 'Gradientwipeleft2right ':
{
Filterstring + = " Gradientwipe (duration = '0. 5', gradientsize = '0. 75', motion = 'forward ') " ;
Break ;
}
Case 'Gradientwipeup2low ':
{
Filterstring + = " Gradientwipe (duration = '0. 5', gradientsize = '0. 25', motion = 'forward ', wipestyle = '1 ') " ;
Break ;
}
Case 'Revealtrans ':
{
Filterstring + = " Revealtrans (duration = '0. 5', transition = '12 ') " ;
Break ;
}
Case 'Fade ':
{
Filterstring + = 'Fade ()';
Break ;
}
Default :
{
Filterstring = ''; // No effect
Break ;
}
}
If (Filterstring)
{
Menuhtml. style. Visibility = 'Ddn ';
Menuhtml. style. Filter = Filterstring;
Menuhtml. Filters [ 0 ]. Apply ();
Menuhtml. style. Visibility = 'Visible ';
Menuhtml. Filters [ 0 ]. Play ( 0.25 );
}
};
# Endregion
The text on the menu entry is too long to be displayed with... truncation. The Code is as follows:
Menu. Prototype. _ isellipsis = function (menuobj, menuhtml) # Region Menu. Prototype. _ isellipsis = function (menuobj, menuhtml)
Menu. Prototype. _ isellipsis = Function (Menuobj, menuhtml)
{
If (Menuhtml. offsetwidth > Menu. Attributes. maxmenuitemtextwidth)
{
For ( VaR I = 0 ; I < Menuhtml. Rows. length; ++ I)
{
VaR Tr = Menuhtml. Rows (I );
If ( ! Tr. Type | Tr. Type ! = 'Normal ')
{
Continue ;
}
VaR TD = Tr. cells ( 2 );
VaR Span = TD. childnodes [ 0 ];
If (Span. scrollwidth > Menu. Attributes. maxmenuitemtextwidth)
{
TD. style. fontweight = 'Bold ';
VaR Doc = Menuobj.m_popup.doc ument;
VaR TBL = Doc. createelement ('table ');
TBL. Border = 0 ;
TBL. cellpadding = 0 ;
TBL. cellspacing = 0 ;
TBL. style. textoverflow = 'Ellipsis ';
TBL. style. tablelayout = 'Fixed ';
TBL. style. Color = Menu. Attributes. normalmenuforecolor;
VaR Tbody = Doc. createelement ('tbody ');
TBL. appendchild (tbody );
VaR Tr = Doc. createelement ('tr ');
Tbody. appendchild (TR );
VaR TD = Doc. createelement ('td ');
Tr. appendchild (TD );
TD. innerhtml = Span. innerhtml;
Menuhtml. Rows (I). cells ( 2 ). Innerhtml = '';
Menuhtml. Rows (I). cells ( 2 ). Appendchild (TBL );
TBL. style. lineheight = ' 85 % ';
TD. style. Width = ' 100 % ';
TD. style. Overflow = 'Ddn ';
TD. style. whitespace = 'Nowre ';
TD. style. textoverflow = 'Ellipsis ';
TBL. Title = TD. innertext;
}
}
Menuhtml. style. Width = Menu. Attributes. maxmenuitemtextwidth;
}
Return Menuhtml. offsetwidth;
};
# Endregion
Menu. attributes. maxmenuitemtextwidth is the maximum width of text on the preset menuitem. If this width is exceeded, a table element is used to wrap the text and then CSS is used to generate "... "effect. Use text-overflow: Ellipsis of CSS to generate "... "effect, here are a few points to note: you must use a table to pack, the table CSS should be set to table-layout as fixed, and the HTML element outside the text (in this example, TD) the style sheet must be set to overflow: hidden; white-space: nowrap; text-overflow: ellipsis;. If you have any inherited CSS attributes, you can.
|
Effect of text Truncation in the menu |
For example, to display the following results:
|
Menuitem 1234567890 1234567890 1234567890 |
|
The HTML code is:
< Table Style = "Table-layout: fixed ;" Width = "200" >
< Tr >
< TD Style = "Overflow: hidden; white-space: nowrap; text-overflow: ellipsis;
Border: solid 1px red ;" > Menuitem 1234567890 1234567890 1234567890
</ TD >
</ Tr >
</ Table >
When our text is displayed as "..." overflow style, we can also query this status and add tooltip to such entries. We only need to compare the clientwidth and scrollwidth of the TD element. If they are not equal, that is, scrollwidth> clientwidth, it means that the text is not fully displayed (of course, this comparison is also true when the scroll bar is displayed ).
When a sub-menu is displayed, if the screen space on the right is insufficient for the menu width, the menu will pop up from the left of the parent menu, using the following code:
Subpop. Show ( 0 , 0 , 1 , 1 );
VaR Menuhtml = Subpop.doc ument. getelementbyid ('menu ');
VaR X, Y, W, h;
X = Mihtml. offsetwidth - 2 ;
Y = 0 ;
W = Menuhtml. offsetwidth;
W = This . _ Isellipsis (submenuobj, menuhtml );
H = Menuhtml. offsetheight;
VaR Availablescreenwidth = Window. Screen. width;
VaR Factwidth = Popup.doc ument. parentwindow. screenleft + Menuobj. m_bounds.width + W;
If (Factwidth > Availablescreenwidth)
{
X = - W + 2 ;
}
Subpop. Show (X, Y, W, H, mihtml );
Submenuobj. fadeineffect (menu. Attributes. showmenueffect );
The fadeineffect and _ isellipsis methods mentioned above are called at the preceding position.
If you have any questions about creating an unlimited webpage menu for popup, or if you have any suggestions, please feel free to discuss them.
The end.