Index: openacs-4/packages/xowiki/tcl/menu-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/xowiki/tcl/menu-procs.tcl,v diff -u -N -r1.7 -r1.8 --- openacs-4/packages/xowiki/tcl/menu-procs.tcl 29 Jul 2013 09:05:02 -0000 1.7 +++ openacs-4/packages/xowiki/tcl/menu-procs.tcl 27 Oct 2014 16:42:05 -0000 1.8 @@ -35,7 +35,7 @@ {id "[my html_id]"} CSSclass } - + Menu ad_instproc render {} {doku} { html::ul [my get_attributes id {CSSclass class}] { foreach menuitem [my children] {$menuitem render} @@ -56,10 +56,10 @@ style linkclass target - {group ""} + {group ""} } - - + + MenuItem ad_instproc init args {doku} { next # Use computed default values when not specified @@ -81,243 +81,19 @@ my set linkclass [string tolower [namespace tail [my info class]]]label } } - + MenuItem ad_instproc render {} {doku} { html::li [my get_attributes id {CSSclass class}] { html::a [my get_attributes title href target] { html::t [my text] } } } - - - ::xo::tdom::Class YUIMenuItemList \ - -superclass Menu \ - -parameter { - header - } - - YUIMenuItemList ad_instproc render {} {} { - if {[my exists header]} { - html::h6 { - html::t [my header] - } - } - next - } - - ################################################### - # - # YUIMenu - # - ::xo::tdom::Class create YUIMenu \ - -superclass Menu \ - -parameter { - header - footer - shadow - {autorender false} - {configuration {{}}} - } - - YUIMenu instproc init {} { - ::xowiki::Includelet require_YUI_CSS -ajaxhelper 1 "menu/assets/skins/sam/menu.css" - ::xowiki::Includelet require_YUI_JS -ajaxhelper 1 "yahoo-dom-event/yahoo-dom-event.js" - ::xowiki::Includelet require_YUI_JS -ajaxhelper 1 "container/container_core-min.js" - ::xowiki::Includelet require_YUI_JS -ajaxhelper 1 "menu/menu-min.js" - next - } - YUIMenu instproc split_menu_groups {list} { - # - # split the list of entries into groups, which will be separated - # with lines in the rendering - # - set result [list] - if {[llength $list] < 1} {return $result} - set group_name [[lindex $list 0] group] - set group_list [list] - foreach e $list { - set gn [$e group] - if {$gn ne $group_name} { - lappend result $group_list - set group_name $gn - set group_list [list] - } - lappend group_list $e - } - lappend result $group_list - return $result - } - YUIMenu ad_instproc render {} { - http://developer.yahoo.com/yui/menu/ - } { - my append CSSclass " yuimenu" - - # I want the menu to show up when JS is disabled - # This gets overridden by JS, so its only relevant for the non-JS version - #my set style "visibility: visible; position: relative;" - - html::div [my get_attributes {CSSclass class} id style] { - # Header - html::t \n - if {[my exists header]} { - html::div -class "hd" { - html::t [my header] - } - } - # Body - html::t \n - html::div -class "bd" { - foreach group [my split_menu_groups [my children]] { - html::ul { - foreach menuitemlist $group {$menuitemlist render} - } - } - } - # Footer - if {[my exists footer]} { - html::div -class "ft" { - html::t [my footer] - } - } - # Shadow - if {[my exists shadow]} { - html::div -class "yui-menu-shadow" {} - } - # JavaScript - # only "root-level" menus need JS - # TODO: is this parent-check sufficient / future-safe? - if {![my exists __parent]} { - html::script -type "text/javascript" { - html::t "var [my js_name] = new YAHOO.widget.Menu(\"[my id]\", [my set configuration]);" - html::t " - [my js_name].render(); - [my js_name].show(); - " - } - } - } - } - # - # YUIMenuItem - # - ::xo::tdom::Class create YUIMenuItem \ - -superclass MenuItem \ - -parameter { - {href "#"} - helptext - } - - YUIMenuItem ad_instproc render {} {doku} { - html::li [my get_attributes id {CSSclass class} style] { - # if we have no href, mark entry as disabled - if {![my exists href] || [my href] eq ""} {my append linkclass " disabled"} - html::a [my get_attributes target href {linkclass class} title] { - html::t [my text] - if {[my exists helptext]} { - html::em { - html::t [my helptext] - } - } - } - foreach menu [my children] {$menu render} - } - html::t \n - } - - - # - # YUIMenuBar - # - ::xo::tdom::Class create YUIMenuBar \ - -superclass YUIMenu \ - -parameter { - {navbar true} - } - - YUIMenuBar ad_instproc render {} { - http://developer.yahoo.com/yui/menu/#menubar - MenuBar looks best without a header and with one MenuItemList only - } { - my append CSSclass " yuimenubar" - if {[my navbar]} {my append CSSclass " yuimenubarnav"} - html::div [my get_attributes id {CSSclass class}] { - html::div -class "bd" { - html::t \n - html::ul -class "first-of-type" { - foreach li [my children] {$li render} - } - html::t \n - } - html::t \n - ::xo::Page set_property body class "yui-skin-sam" - ::xo::Page requireJS "YAHOO.util.Event.onDOMReady(function () { - var [my js_name] = new YAHOO.widget.MenuBar('[my id]', [my set configuration]); - [my js_name].render(); - });" - } - } - - # - # YUIMenuBarItem - # - ::xo::tdom::Class create YUIMenuBarItem \ - -superclass YUIMenuItem - - YUIMenuBarItem ad_instproc init {} {} { - #goto YUIMenuItem and set all those nice defaults - next - my append CSSclass " first-of-type" - if {![my exists href]} { - # If not set to #, the title of the menubaritems wont expand the submenu (only the arrow) - my set href "#" - } - } - - - # - # YUIContextMenu - # - - # TODO: Support for Multiple Element IDs/Refs as Trigger - - ::xo::tdom::Class YUIContextMenu \ - -superclass YUIMenu \ - -parameter { - {trigger "document"} - {triggertype "reference"} - } - - YUIContextMenu ad_instproc render {} { - http://developer.yahoo.com/yui/menu/#contextmenu - } { - my append CSSclass " yuimenu" - html::div [my get_attributes id {CSSclass class}] { - html::div -class "bd" { - html::ul { - foreach li [my children] {$li render} - } - } - html::script -type "text/javascript" { - html::t "var [my js_name] = new YAHOO.widget.ContextMenu('[my id]', { trigger: '[my set trigger]' } );" - html::t "[my js_name].render(document.body);" - } - } - } - - # - # YUIContextMenuItem - # - ::xo::tdom::Class YUIContextMenuItem \ - -superclass YUIMenuItem - - - # # Simple Generic MenuBar - # + # # Class for creating and updating Menubars in an incremental # fashion. Menu handling works as following: # @@ -330,11 +106,11 @@ # provided name determines the menu to which the entry is # added. The following example adds a menu entry "StartPage" to # the menu "Package": - # + # # $mb add_menu_item -name Package.Startpage \ - # -item [list text #xowiki.index# url $index_link] + # -item [list text #xowiki.index# url $index_link] # - # 4) After all updates are performed, use "render-yui" to obtain + # 4) After all updates are performed, use "render-preferred" to obtain # the HTML rendering of the menu. # # Follow the following nameing conventions: @@ -354,19 +130,19 @@ id } - if {[info command ::dict] ne ""} { - ::xowiki::MenuBar instproc get_prop {dict key {default ""}} { + if {[info commands ::dict] ne ""} { + ::xowiki::MenuBar instproc get_prop {dict key {default ""}} { if {![dict exists $dict $key]} { - return $default - } + return $default + } return [dict get $dict $key] } } else { - ::xowiki::MenuBar instproc get_prop {dict key {default ""}} { + ::xowiki::MenuBar instproc get_prop {dict key {default ""}} { array set "" $dict if {![info exists ($key)]} { - return $default - } + return $default + } return [set ($key)] } } @@ -375,7 +151,7 @@ my set Menues [list] my destroy_on_cleanup } - + ::xowiki::MenuBar instproc add_menu {-name {-label ""}} { my instvar Menues if {$name in $Menues} { @@ -458,46 +234,48 @@ } { # A folder page can contain extra menu entries (sample # below). Iterate of the extra_menu property and add according - # menu entries. - #{form_link -name New.Page -label #xowiki.new# -form en:page.form} - + # menu entries. Sample: + # + # {clear_menu -menu New} + # {entry -name New.Page -label #xowiki.new# -form en:page.form} + foreach me $items { array unset "" set kind [lindex $me 0] if {[string range $kind 0 0] eq "#"} continue + set properties [lrange $me 1 end] + switch $kind { - clear_menu { - # sample entry: clear_menu -menu New - array set "" [lrange $me 1 end] - my clear_menu -menu $(-menu) - } - - form_link - - entry { - # sample entry: entry -name New.YouTubeLink -label YouTube -form en:YouTube.form - if {$kind eq "form_link"} { - my log "$me, name 'form_link' is deprecated, use 'entry' instead" - } - array set "" [lrange $me 1 end] - if {[info exists (-form)]} { - set link [$package_id make_form_link -form $(-form) \ - -parent_id $parent_id \ - -nls_language $nls_language -return_url $return_url] - } elseif {[info exists (-object_type)]} { - set link [$package_id make_link -with_entities 0 \ - $package_id edit-new \ - [list object_type $(-object_type)] \ - parent_id return_url autoname template_file] - } else { - my log "Warning: no link specified" - set link "" - } - set item [list url $link] - if {[info exists (-label)]} {lappend item text $(-label)} - my add_menu_item -name $(-name) -item $item - } - - default { error "unknown kind of menu entry: $kind" } + clear_menu { + my clear_menu -menu [dict get $properties -menu] + } + + form_link - + entry { + # sample entry: entry -name New.YouTubeLink -label YouTube -form en:YouTube.form + if {$kind eq "form_link"} { + my log "$me, name 'form_link' is deprecated, use 'entry' instead" + } + if {[dict exists $properties -form]} { + set link [$package_id make_form_link \ + -form [dict get $properties -form] \ + -parent_id $parent_id \ + -nls_language $nls_language -return_url $return_url] + } elseif {[dict exists $properties -object_type]} { + set link [$package_id make_link -with_entities 0 \ + $package_id edit-new \ + [list object_type [dict get $properties -object_type]] \ + parent_id return_url autoname template_file] + } else { + my log "Warning: no link specified" + set link "" + } + set item [list url $link] + if {[dict exists $properties -label]} {lappend item text [dict get $properties -label]} + my add_menu_item -name [dict get $properties -name] -item $item + } + + default { error "unknown kind of menu entry: $kind" } } } } @@ -510,35 +288,23 @@ return $result } - ::xowiki::MenuBar instproc render-yui {} { - set M [my content] - set mb [::xowiki::YUIMenuBar -id [my get_prop $M id] -configuration { - {autosubmenudisplay: false, keepopen: true, lazyload: false} - } { - foreach {menu_att menu} $M { - if {$menu_att eq "id"} continue - ::xowiki::YUIMenuBarItem -text [my get_prop $menu text] { - ::xowiki::YUIMenu { - foreach {item_att item} $menu { - if {[string match {[a-z]*} $item_att]} continue - set text [my get_prop $item text] - set url [my get_prop $item url] - set group [my get_prop $item group] - #my msg "ia=$item_att group '$group' // t=$text item=$item" - ::xowiki::YUIMenuItem -text $text -href $url -group $group {} - } - } - } - } - }] - return [$mb asHTML] + ::xowiki::MenuBar instproc render-preferred {} { + switch [parameter::get_global_value -package_key xowiki -parameter PreferredCSSToolkit -default yui] { + bootstrap {set menuBarRenderer render-bootstrap} + default {set menuBarRenderer render-yui} + } + my $menuBarRenderer } - namespace export Menu - namespace export YUIMenuBar YUIMenuBarItem - namespace export YUIMenu YUIMenuItem YUIMenuItemList - namespace export YUIContextMenu YUIContextMenuItem -# end of namespace + + namespace export Menu + # end of namespace } -::xo::library source_dependent +::xo::library source_dependent +# +# Local variables: +# mode: tcl +# tcl-indent-level: 2 +# indent-tabs-mode: nil +# End: