Index: openacs-4/packages/ajaxhelper/tcl/ajax-yahoo-procs.tcl =================================================================== RCS file: /usr/local/cvsroot/openacs-4/packages/ajaxhelper/tcl/ajax-yahoo-procs.tcl,v diff -u -r1.3 -r1.4 --- openacs-4/packages/ajaxhelper/tcl/ajax-yahoo-procs.tcl 21 Oct 2006 06:14:53 -0000 1.3 +++ openacs-4/packages/ajaxhelper/tcl/ajax-yahoo-procs.tcl 6 Nov 2006 13:15:29 -0000 1.4 @@ -1,71 +1,97 @@ ad_library { Library for Ajax Helper Procs - based on Yahoo's User Interface Libraries + based on Yahoo's User Interface Libraries - @author Hamilton Chua (ham@solutiongrove.com) - @creation-date 2006-01-16 + @author Hamilton Chua (ham@solutiongrove.com) + @creation-date 2006-01-16 } namespace eval ah::yui { } -ad_proc -public ah::yui::js_source_dynamic { - {-js "default"} - {-enclose:boolean} +ad_proc -private ah::yui::load_js_sources { + -source_list } { - Dynamically Loads the Yahoo UI javascript libraries. - WARNING : experimental, use ah::yui::js_sources instead + Accepts a tcl list of sources to load. + This source_list will be the global ajax_helper_yui_js_sources variable. + This script is called in the blank-master template. - @author Hamilton Chua (ham@solutiongrove.com) - @creation-date 2006-04-20 - - @param js Comma separated list of javascript files to load - Valid values include - "default" : loads yui.js and dom.js, the most commonly used - "animation" : loads js for animation - "event" : loads js for event monitoring (e.g. listnern) - "treeview" : loads js for Yahoo's Tree View control - "calendar" : loads js for Yahoo's Calendar Control - "dragdrop" : loads js for Yahoo's Drag and Drop functions - "slider" : loads js for slider functions - + @creation-date 2006-11-05 } { - set ah_base_url [ah::get_url] set script "" - set js_file_list [split $js ","] + set minsuffix "" - foreach x $js_file_list { - switch $x { + if { [parameter::get_from_package_key -package_key "ajaxhelper" -parameter "UseMinifiedJs"] == 1 } { + set minsuffix "-min" + } + + foreach source $source_list { + switch $source { "animation" { - append script [ah::js_include -js_file "${ah_base_url}yui/animation/animation.js"] + append script " \n" } "event" { - append script [ah::js_include -js_file "${ah_base_url}yui/event/event.js"] + append script " \n" } "treeview" { - append script [ah::js_include -js_file "${ah_base_url}yui/treeview/treeview.js"] + append script " \n" + global yahoo_treeview_css + if { [exists_and_not_null yahoo_treeview_css] } { + append script " \n" + } else { + append script " \n" + } } "calendar" { - append script [ah::js_include -js_file "${ah_base_url}yui/calendar/calendar.js"] + append script " \n" } "dragdrop" { - append script [ah::js_include -js_file "${ah_base_url}yui/dragdrop/dragdrop.js"] + append script " \n" } "slider" { - append script [ah::js_include -js_file "${ah_base_url}yui/slider/slider.js"] + append script " \n" } - default { - append script [ah::js_include -js_file "${ah_base_url}yui/yui.js"] - append script [ah::js_include -js_file "${ah_base_url}yui/dom/dom.js"] + "container" { + append script " \n" + append script " \n" } + "dom" { + append script " \n" + } + "connection" { + append script " \n" + } + "yahoo" { + append script " \n" + } } } + return $script +} - if { $enclose_p } { set script [ah::enclose_in_script -script ${script} ] } +ad_proc -private ah::yui::is_js_sources_loaded { + -js_source +} { + This proc will loop thru source_list and check for the presence of js_source. + If found, this proc will return 1 + If not found, this proc will return 0 - return $script + @author Hamilton Chua (ham@solutiongrove.com) + @creation-date 2006-11-05 +} { + global ajax_helper_yui_js_sources + set state 0 + if { [info exists ajax_helper_yui_js_sources] } { + foreach source $ajax_helper_yui_js_sources { + if { [string match $source $js_source] } { + set state 1 + break + } + } + } + return $state } ad_proc -public ah::yui::js_sources { @@ -74,7 +100,7 @@ } { Generates the < script > syntax needed on the head - for yui's User Interface Library + for Yahoo's User Interface Library The code :
[ah::yui::js_sources -default] @@ -93,6 +119,8 @@ "calendar" : loads calendar.js "dragdrop" : loads dragdrop.js "slider" : loads slider.js + "container" : loads container.js + @param min Provide this parameter to use minified versions of the yahoo javascript sources @return @error @@ -101,43 +129,67 @@ set ah_base_url [ah::get_url] set script "" set js_file_list [split $source ","] - if { $min_p } { - set min "-min" - } else { - set min "" + set minsuffix "" + + if { $min_p || [parameter::get_from_package_key -package_key "ajaxhelper" -parameter "UseMinifiedJs"] == 1 } { + set minsuffix "-min" } - foreach x $js_file_list { switch $x { - "animation" { - append script " \n" + "animation" { + if { ![ah::yui::is_js_sources_loaded -js_source "animation"] } { + append script " \n" + } } "event" { - append script " \n" + if { ![ah::yui::is_js_sources_loaded -js_source "event"] } { + append script " \n" + } } "treeview" { - append script " \n" + if { ![ah::yui::is_js_sources_loaded -js_source "treeview"] } { + append script " \n" + } } "calendar" { - append script " \n" + if { ![ah::yui::is_js_sources_loaded -js_source "calendar"] } { + append script " \n" + } } "dragdrop" { - append script " \n" + if { ![ah::yui::is_js_sources_loaded -js_source "dragdrop"] } { + append script " \n" + } } "slider" { - append script " \n" + if { ![ah::yui::is_js_sources_loaded -js_source "slider"] } { + append script " \n" + } } "container" { - append script " \n" - append script " \n" + if { ![ah::yui::is_js_sources_loaded -js_source "container"] } { + append script " \n" + append script " \n" + } } "menu" { - append script " \n" + if { ![ah::yui::is_js_sources_loaded -js_source "menu"] } { + append script " \n" + } } + "connection" { + if { ![ah::yui::is_js_sources_loaded -js_source "connection"] } { + append script " \n" + } + } default { - append script " \n" - append script " \n" + if { ![ah::yui::is_js_sources_loaded -js_source "yahoo"] } { + append script " \n" + } + if { ![ah::yui::is_js_sources_loaded -js_source "dom"] } { + append script " \n" + } } } } @@ -148,22 +200,32 @@ ad_proc -public ah::yui::addlistener { -element:required -event:required - {-scope "''"} - {-callback ""} + -callback:required {-element_is_var:boolean} - {-override:boolean} } { Creates javascript for Yahoo's Event Listener. + http://developer.yahoo.com/yui/event/ + + @author Hamilton Chua (ham@solutiongrove.com) + @creation-date 2006-11-05 + + @param element The element that this function will listen for events. This is the id of an html element (e.g. div or a form) + @param event The event that this function waits for. Values include load, mouseover, mouseout, unload etc. + @param callback The name of the javascript function to execute when the event for the given element has been triggered. } { + + if { ![ah::yui::is_js_sources_loaded -js_source "yahoo"] } { + global ajax_helper_yui_js_sources + lappend ajax_helper_yui_js_sources "yahoo" + if { ![ah::yui::is_js_sources_loaded -js_source "event"] } { + lappend ajax_helper_yui_js_sources "event" + } + } + if { !$element_is_var_p } { set element [ah::isnot_js_var $element] } - if { $override_p } { - set override "true" - } else { - set override "false" - } - return "YAHOO.util.Event.addListener($element,\"$event\",${callback},${scope},${override});\n" + return "YAHOO.util.Event.addListener($element,\"$event\",${callback});\n" } ad_proc -public ah::yui::tooltip { @@ -174,9 +236,96 @@ {-options ""} } { Generates the javascript to create a tooltip using yahoo's user interface javascript library. - For this to work, the default and container sources need to be loaded, see ah::yui::js_sources + http://developer.yahoo.com/yui/container/tooltip/index.html + + @author Hamilton Chua (ham@solutiongrove.com) + @creation-date 2006-11-05 + + @param varname The variable name you want to give to the tooltip + @param element The element where you wish to attache the tooltip + @param message The message that will appear in the tooltip } { + if { ![ah::yui::is_js_sources_loaded -js_source "yahoo"] } { + global ajax_helper_yui_js_sources + lappend ajax_helper_yui_js_sources "yahoo" + if { ![ah::yui::is_js_sources_loaded -js_source "container"] } { + lappend ajax_helper_yui_js_sources "container" + } + } + set script "var $varname = new YAHOO.widget.Tooltip(\"alertTip\", { context:\"$element\", text:\"$message\", $options });" if { $enclose_p } { set script [ah::enclose_in_script -script ${script} ] } return $script +} + +ad_proc -public ah::yui::create_tree { + -element:required + -nodes:required + {-varname "tree"} + {-css ""} +} { + Generates the javascript to create a yahoo tree view control. + http://developer.yahoo.com/yui/treeview/ + + @author Hamilton Chua (ham@solutiongrove.com) + @creation-date 2006-11-05 + + @param element This is the id of the html elment where you want to generate the tree view control. + @param nodes Is list of lists. Each list contains the node information to be passed to ah::yui::create_tree_node to create a node. + @param varname The javascript variable name to give the tree. + +} { + if { ![ah::yui::is_js_sources_loaded -js_source "yahoo"] } { + global ajax_helper_yui_js_sources + lappend ajax_helper_yui_js_sources "yahoo" + if { ![ah::yui::is_js_sources_loaded -js_source "treeview"] } { + lappend ajax_helper_yui_js_sources "treeview" + global yahoo_treeview_css + set yahoo_treeview_css $css + } + } + + + set script "${varname} = new YAHOO.widget.TreeView(\"${element}\"); " + append script "var ${varname}root = ${varname}.getRoot(); " + foreach node $nodes { + append script [ah::yui::create_tree_node -varname [lindex $node 0] \ + -label [lindex $node 1] \ + -treevarname [lindex $node 2] \ + -href [lindex $node 3] \ + -attach_to_node [lindex $node 4] \ + -dynamic_load [lindex $node 5] ] + } + append script "${varname}.draw(); " + return $script +} + +ad_proc -private ah::yui::create_tree_node { + -varname:required + -label:required + -treevarname:required + {-href "javascript:void(0)"} + {-attach_to_node ""} + {-dynamic_load ""} +} { + Generates the javascript to add a node to a yahoo tree view control + http://developer.yahoo.com/yui/treeview/ + + @author Hamilton Chua (ham@solutiongrove.com) + @creation-date 2006-11-05 +} { + set script "var od${varname} = {label: \"${label}\", id: \"${varname}\", href: \"${href}\"}; " + + if { [exists_and_not_null attach_to_node] } { + set rootvar "node" + } else { + set rootvar "${treevarname}root" + } + append script "var nd${varname} = new YAHOO.widget.TextNode(od${varname},${rootvar},false); " + + if { [exists_and_not_null dynamic_load] } { + append script "nd${varname}.setDynamicLoad(${dynamic_load}); " + } + + return $script } \ No newline at end of file