jsmenu.cpp
来自「ncbi源码」· C++ 代码 · 共 723 行 · 第 1/2 页
CPP
723 行
// Name is not defined, use attribute numeric value if ( attr_name.empty() ) { attr_name = "with code " + NStr::IntToString(attribute); } ERR_POST(Warning << "CHTMLPopupMenu::GetMenuAttributeName: " << type_name << " menu type does not support attribute " << attr_name); return kEmptyStr;}string CHTMLPopupMenu::ShowMenu(void) const{ switch (m_Type) { case eSmith: return "window.showMenu(window." + m_Name + ");"; case eKurdin: { string align_h = GetAttributeValue(eHTML_PM_alignH); string align_v = GetAttributeValue(eHTML_PM_alignV); string color_border = GetAttributeValue(eHTML_PM_borderColor); string color_title = GetAttributeValue(eHTML_PM_titleColor); string color_back = GetAttributeValue(eHTML_PM_bgColor); string s = "','"; return "PopUpMenu2_Set(" + m_Name + ",'" + align_h + s + align_v + s + color_border + s + color_title + s + color_back + "');"; } case eKurdinConf: return "PopUpMenu2_Set(" + m_Name + ");"; case eKurdinSide: return "<script language=\"JavaScript1.2\">\n<!--\n" \ "document.write(SideMenuType == \"static\" ? " \ "SideMenuStaticHtml : SideMenuDynamicHtml);" \ "\n//-->\n</script>\n"; } _TROUBLE; return kEmptyStr;}string CHTMLPopupMenu::HideMenu(void) const{ switch (m_Type) { case eKurdin: case eKurdinConf: return "PopUpMenu2_Hide(); return false;"; default: ; } return kEmptyStr;}CNcbiOstream& CHTMLPopupMenu::PrintBegin(CNcbiOstream& out, TMode mode){ if ( mode == eHTML ) { string items = GetCodeItems(); if ( !items.empty() ) { out << "<script language=\"JavaScript1.2\">\n<!--\n" << items << "//-->\n</script>\n"; } } return out;}string CHTMLPopupMenu::GetCodeHead(EType type, const string& menu_lib_url){ string url, code; switch (type) { case eSmith: url = menu_lib_url.empty() ? kJSMenuDefaultURL_Smith : menu_lib_url; break; case eKurdin: url = menu_lib_url.empty() ? kJSMenuDefaultURL_Kurdin : menu_lib_url; break; case eKurdinConf: { code = "<script language=\"JavaScript1.2\">\n<!--\n"; code += "var PopUpMenu2_GlobalConfig = [\n"; code += " [\"UseThisGlobalConfig\",\"yes\"]"; // Write properties CHTMLPopupMenu::TAttributes* attrs = GetGlobalAttributesPtr(); ITERATE (TAttributes, i, *attrs) { string name = GetAttributeName(i->first, eKurdinConf); string value = i->second; code += ",\n [\"" + name + "\",\"" + value + "\"]"; } code += "\n]\n//-->\n</script>\n"; url = menu_lib_url.empty() ? kJSMenuDefaultURL_KurdinConf : menu_lib_url; break; } case eKurdinSide: url = menu_lib_url.empty() ? kJSMenuDefaultURL_KurdinSide : menu_lib_url; code = "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + kJSMenuDefaultURL_KurdinSideCSS + "\">\n"; break; } if ( !url.empty() ) { code += "<script language=\"JavaScript1.2\" src=\"" + url + "\"></script>\n"; } return code;}string CHTMLPopupMenu::GetCodeBody(EType type, bool use_dyn_menu){ if ( type != eSmith ) { return kEmptyStr; } string use_dm = use_dyn_menu ? "true" : "false"; return "<script language=\"JavaScript1.2\">\n" "<!--\nfunction onLoad() {\n" "window.useDynamicMenu = " + use_dm + ";\n" "window.defaultjsmenu = new Menu();\n" "defaultjsmenu.addMenuSeparator();\n" "defaultjsmenu.writeMenus();\n" "}\n" "// For IE & NS6\nif (!document.layers) onLoad();\n//-->\n</script>\n";}string CHTMLPopupMenu::GetCodeItems(void) const{ string code; switch (m_Type) { case eSmith: { code = "window." + m_Name + " = new Menu();\n"; // Write menu items ITERATE (TItems, i, m_Items) { if ( (i->title).empty() ) { code += m_Name + ".addMenuSeparator();\n"; } else { code += m_Name + ".addMenuItem(\"" + i->title + "\",\"" + i->action + "\",\"" + i->color + "\",\"" + i->mouseover + "\",\"" + i->mouseout + "\");\n"; } } // Write properties ITERATE (TAttributes, i, m_Attrs) { string name = GetAttributeName(i->first); string value = i->second; code += m_Name + "." + name + " = \"" + value + "\";\n"; } } break; case eKurdin: { code = "var " + m_Name + " = [\n"; // Write menu items ITERATE (TItems, i, m_Items) { if ( i != m_Items.begin()) { code += ",\n"; } code += "[\"" + i->title + "\",\"" + i->action + "\",\"" + i->mouseover + "\",\"" + i->mouseout + "\"]"; } code += "\n]\n"; } break; case eKurdinConf: { if ( m_ConfigName == m_Name ) { code += "var PopUpMenu2_LocalConfig_" + m_Name + " = [\n"; // If local config is disabled if ( m_DisableLocalConfig ) { code += " [\"UseThisLocalConfig\",\"no\"]"; } // Write properties ITERATE (TAttributes, i, m_Attrs) { if ( m_DisableLocalConfig || i != m_Attrs.begin() ) { code += ",\n"; } string name = GetAttributeName(i->first); string value = i->second; code += " [\"" + name + "\",\"" + value + "\"]"; } code += "\n]\n"; } // Write menu only if it have items if ( m_Items.size() ) { code += "var " + m_Name + " = [\n"; if ( !m_ConfigName.empty() ) { code += " [\"UseLocalConfig\",\"" + m_ConfigName + "\",\"\",\"\"]"; } // Write menu items ITERATE (TItems, i, m_Items) { if ( !m_ConfigName.empty() || i != m_Items.begin()) { code += ",\n"; } code += " [\"" + i->title + "\",\"" + i->action + "\",\"" + i->mouseover + "\",\"" + i->mouseout + "\"]"; } code += "\n]\n"; } } break; case eKurdinSide: { // Menu name always is "SideMenuParams" code = "var SideMenuParams = [\n"; // Menu configuration string disable_hide = GetAttributeValue(eHTML_PM_disableHide); string menu_type; if ( disable_hide == "true" ) { menu_type = "static"; } else if ( disable_hide == "false" ) { menu_type = "dynamic"; // else menu_type have default value } string width = GetAttributeValue(eHTML_PM_menuWidth); string peep_offset = GetAttributeValue(eHTML_PM_peepOffset); string top_offset = GetAttributeValue(eHTML_PM_topOffset); code += "[\"\",\"" + menu_type + "\",\"\",\"" + width + "\",\"" + peep_offset + "\",\"" + top_offset + "\",\"\",\"\"]"; // Write menu items ITERATE (TItems, i, m_Items) { code += ",\n[\"" + i->title + "\",\"" + i->action + "\",\"\",\"\"]"; } code += "\n]\n"; } break; } return code;}END_NCBI_SCOPE/* * =========================================================================== * $Log: jsmenu.cpp,v $ * Revision 1000.4 2004/06/01 19:15:41 gouriano * PRODUCTION: UPGRADED [GCC34_MSVC7] Dev-tree R1.31 * * Revision 1.31 2004/05/17 20:59:50 gorelenk * Added include of PCH ncbi_pch.hpp * * Revision 1.30 2004/05/05 13:58:14 ivanov * Added DisableLocalConfig(). Do not print out empty menues. * * Revision 1.29 2004/04/22 15:26:34 ivanov * GetAttributeName(): improved diagnostic messages * * Revision 1.28 2004/04/20 16:16:05 ivanov * eKurdinConf: Remove extra comma if local configuration is not specified * * Revision 1.27 2004/04/05 16:19:57 ivanov * Added support for Sergey Kurdin's popup menu with configurations * * Revision 1.26 2004/01/08 18:36:52 ivanov * Removed _TROUBLE from HideMenu() * * Revision 1.25 2003/12/18 20:14:40 golikov * Added HideMenu * * Revision 1.24 2003/12/12 12:10:38 ivanov * Updated Sergey Kurdin's popup menu to v2.4 * * Revision 1.23 2003/12/10 19:14:16 ivanov * Move adding a string "return false;" to menues JS code call from ShowMenu() * to AttachPopupMenu() * * Revision 1.22 2003/12/03 12:39:24 ivanov * ShowMenu(): finalize JS code for eKurdin type with "return false;" * * Revision 1.21 2003/12/02 14:27:06 ivanov * Removed obsolete functions GetCodeBodyTag[Handler|Action](). * * Revision 1.20 2003/11/03 17:03:08 ivanov * Some formal code rearrangement. Move log to end. * * Revision 1.19 2003/10/02 18:24:38 ivanov * Get rid of compilation warnings; some formal code rearrangement * * Revision 1.18 2003/10/01 15:56:44 ivanov * Added support for Sergey Kurdin's side menu * * Revision 1.17 2003/09/03 20:21:35 ivanov * Updated Sergey Kurdin's popup menu to v2.3 * * Revision 1.16 2003/07/08 17:13:53 gouriano * changed thrown exceptions to CException-derived ones * * Revision 1.15 2003/06/30 21:16:50 ivanov * Updated Sergey Kurdin's popup menu to v2.2 * * Revision 1.14 2003/04/29 18:42:14 ivanov * Fix for previous commit * * Revision 1.13 2003/04/29 17:45:43 ivanov * Changed array with file names for Kurdin's menu to const definitions * * Revision 1.12 2003/04/29 16:28:13 ivanov * Use one JS Script for Kurdin's menu * * Revision 1.11 2003/04/01 16:35:29 ivanov * Changed path for the Kurdin's popup menu * * Revision 1.10 2003/03/11 15:28:57 kuznets * iterate -> ITERATE * * Revision 1.9 2002/12/12 17:20:46 ivanov * Renamed GetAttribute() -> GetMenuAttributeValue, * GetAttributeName() -> GetMenuAttributeName(). * * Revision 1.8 2002/12/09 22:11:59 ivanov * Added support for Sergey Kurdin's popup menu * * Revision 1.7 2002/04/29 18:07:21 ucko * Make GetName const. * * Revision 1.6 2002/02/13 20:16:09 ivanov * Added support of dynamic popup menues. Changed GetCodeBody(). * * Revision 1.5 2001/11/29 16:06:31 ivanov * Changed using menu script name "menu.js" -> "ncbi_menu.js". * Fixed error in using menu script without menu definitions. * * Revision 1.4 2001/10/15 23:16:22 vakatov * + AddItem(const char* title, ...) to avoid "string/CNCBINode" ambiguity * * Revision 1.3 2001/08/15 19:43:13 ivanov * Added AddMenuItem( node, ...) * * Revision 1.2 2001/08/14 16:53:07 ivanov * Changed parent class for CHTMLPopupMenu. * Changed mean for init JavaScript popup menu & add it to HTML document. * * Revision 1.1 2001/07/16 13:41:32 ivanov * Initialization * * =========================================================================== */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?