/* * SPL - The SPL Programming Language * Copyright (C) 2004, 2005 Clifford Wolf * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * mod_wsf_menu.spl: WSF Menu Component */ /** * A module which implements a WSF Component for DHTML menus. */ load "wsf"; /** * This WSF Component adds a DHTML menu to the application window. It should * be the first child of the root component and the root component shouldn't * add any content before the html code created by this component. Otherwise * it is possible that the dynamic module is rendered over that content and * covers it. * * Derived from [[wsf:WsfComponent]] */ object WsfMenu WsfComponent { var __WsfMenu_data; var __WsfMenu_data_idx; var __WsfMenu_data_action; /** * Create boring non-javascript menus if this is set to '1'. * Passing 'nojsmenu: 1' to the constructor sets this this variable. */ var nojsmenu = 0; /** * The width of a menu item. * * Only adjust this if you have extraordinary long descriptions of your * menu items. */ var size_x = 200; /** * The height of a menu element. * * Usuall you do not need to change this to another value; */ var size_y = 25; method __WsfMenu_menu_data_to_html(xpos, ypos, zpos, name, data) { var subs_html = ''; var this_html = ' :
  • ${xml::name}
  • ; } else { html ~= <:> :
  • ${xml::name}
  • : \n'; } return html; } /** * The overloaded [[wsf:WsfComponent.main()]]. */ method main() { task_co_return(); if (declared cgi.param.action and defined __WsfMenu_data_action[cgi.param.action]) __WsfMenu_data_action[cgi.param.action](); dirty = 1; } /** * The overloaded [[wsf:WsfComponent.get_html()]]. */ method get_html() { __WsfMenu_data_idx = 0; __WsfMenu_data_action = undef; if (nojsmenu) { var html = '
    \n'; } var html = '
    \n'; var xpos = 0; foreach i (__WsfMenu_data) { __WsfMenu_data_idx++; html ~= __WsfMenu_menu_data_to_html(xpos, 0, 100, i, __WsfMenu_data[i]); xpos += size_x; } html ~= '
     
    \n'; html ~= '
     
    \n'; return html ~ '\n'; } /** * The constructor. * * The parameter is a pointer to a hash with the menu structure. The * hash key is the description HTML text of the entry (encode it with * [[xml:encode_xml()]] if needed) and the value is a function pointer * for regular menu entries and hashes again for submenus. E.g.: * * function get_menu_action(text) { * return function() { * debug text; * }; * } * * var menu_data = [ * 'Menu 1' => [ * 'Entry #1' => function() { * debug "Hello World!"; * }, * 'Entry #2' => function() { * debug "This is a small demo!"; * } * ], * 'Menu 2' => [ * 'Closure Example #1' => * get_menu_action("Hello World!"), * 'Closure Example #2' => * get_menu_action("Another Test!") * ], * 'About' => function() { * debug "This is a demo program!"; * } * ]; * * var menu = new WsfMenu(menu_data); * * SPL has support for closures. In this example, the get_menu_action() * function is using the concept of closures for storing additional * data with the function pointers assigned to the items in 'Menu 2'. * * Right now, 'nojsmenu: 1' is the only supported option. It sets the * [[.nojsmenu]] variable. */ method init(menu_data, %options) { __WsfMenu_data = menu_data; if (declared options.nojsmenu) nojsmenu = options.nojsmenu; return *WsfComponent.init(); } }