From cf71a4677eff547c9cedeb1871fc109ae181b0c2 Mon Sep 17 00:00:00 2001 From: tbrehm Date: Sat, 17 Mar 2007 20:30:41 +0000 Subject: [PATCH] Rebuild the complete interface to use ajax. --- interface/lib/app.inc.php | 1 + interface/lib/classes/listform.inc.php | 11 +- .../classes/listform_tpl_generator.inc.php | 297 +- .../lib/classes/tform_tpl_generator.inc.php | 628 +- interface/lib/classes/tpl_ini.inc.php | 230 +- interface/lib/config.inc.php | 10 +- interface/web/admin/form/dbsync.tform.php | 6 +- interface/web/admin/form/filesync.tform.php | 2 +- interface/web/admin/form/server.tform.php | 14 +- interface/web/admin/form/users.tform.php | 2 +- interface/web/admin/groups_del.php | 26 +- interface/web/admin/groups_edit.php | 100 +- interface/web/admin/groups_list.php | 69 +- interface/web/admin/index.php | 53 +- interface/web/admin/lib/lang/en_groups.lng | 2 + interface/web/admin/templates/dbsync_edit.htm | 114 +- interface/web/admin/templates/dbsync_list.htm | 45 +- .../web/admin/templates/filesync_edit.htm | 90 +- .../web/admin/templates/filesync_list.htm | 29 +- interface/web/admin/templates/groups_edit.htm | 30 +- interface/web/admin/templates/groups_list.htm | 23 +- interface/web/admin/templates/index.htm | 28 +- interface/web/admin/templates/paging.tpl.htm | 9 - .../admin/templates/server_edit_services.htm | 32 +- interface/web/admin/templates/server_list.htm | 56 +- .../admin/templates/users_address_edit.htm | 102 +- .../web/admin/templates/users_groups_edit.htm | 42 +- interface/web/admin/templates/users_list.htm | 35 +- .../web/admin/templates/users_user_edit.htm | 94 +- interface/web/admin/users_del.php | 26 +- interface/web/admin/users_edit.php | 100 +- interface/web/admin/users_list.php | 69 +- interface/web/capp.php | 28 +- interface/web/content.php | 79 + interface/web/designer/module_nav_flip.php | 2 +- interface/web/designer/module_show.php | 18 +- .../web/designer/templates/module_edit.htm | 88 +- .../web/designer/templates/module_list.htm | 8 +- .../designer/templates/module_nav_edit.htm | 50 +- .../templates/module_nav_item_edit.htm | 68 +- .../web/designer/templates/module_show.htm | 84 +- interface/web/dns/lib/module.conf.php | 76 +- interface/web/index.php | 3 + interface/web/js/scrigo.js | 182 + interface/web/js/yui/animation/README | 45 + .../web/js/yui/animation/animation-debug.js | 1361 +++ .../web/js/yui/animation/animation-min.js | 75 + interface/web/js/yui/animation/animation.js | 1358 +++ interface/web/js/yui/autocomplete/README | 77 + .../js/yui/autocomplete/autocomplete-debug.js | 3100 ++++++ .../js/yui/autocomplete/autocomplete-min.js | 183 + .../web/js/yui/autocomplete/autocomplete.js | 3071 ++++++ interface/web/js/yui/button/README | 3 + .../web/js/yui/button/assets/background.png | Bin 0 -> 185 bytes interface/web/js/yui/button/assets/button.css | 217 + .../web/js/yui/button/assets/menuarrow.gif | Bin 0 -> 67 bytes .../web/js/yui/button/assets/splitarrow.gif | Bin 0 -> 145 bytes .../yui/button/assets/splitarrow_active.gif | Bin 0 -> 145 bytes .../web/js/yui/button/button-beta-debug.js | 4061 ++++++++ .../web/js/yui/button/button-beta-min.js | 126 + interface/web/js/yui/button/button-beta.js | 3949 ++++++++ interface/web/js/yui/calendar/README | 88 + .../web/js/yui/calendar/assets/calendar.css | 197 + .../web/js/yui/calendar/assets/callt.gif | Bin 0 -> 93 bytes .../web/js/yui/calendar/assets/calrt.gif | Bin 0 -> 94 bytes interface/web/js/yui/calendar/assets/calx.gif | Bin 0 -> 88 bytes .../web/js/yui/calendar/calendar-debug.js | 4331 +++++++++ interface/web/js/yui/calendar/calendar-min.js | 116 + interface/web/js/yui/calendar/calendar.js | 4309 +++++++++ interface/web/js/yui/connection/README | 182 + .../web/js/yui/connection/connection-debug.js | 1082 +++ .../web/js/yui/connection/connection-min.js | 104 + interface/web/js/yui/connection/connection.js | 1054 +++ interface/web/js/yui/container/README | 207 + .../web/js/yui/container/assets/alrt16_1.gif | Bin 0 -> 971 bytes .../web/js/yui/container/assets/blck16_1.gif | Bin 0 -> 591 bytes .../web/js/yui/container/assets/close12_1.gif | Bin 0 -> 85 bytes .../web/js/yui/container/assets/container.css | 230 + .../web/js/yui/container/assets/hlp16_1.gif | Bin 0 -> 928 bytes .../web/js/yui/container/assets/info16_1.gif | Bin 0 -> 601 bytes .../web/js/yui/container/assets/tip16_1.gif | Bin 0 -> 552 bytes .../web/js/yui/container/assets/warn16_1.gif | Bin 0 -> 580 bytes .../web/js/yui/container/container-debug.js | 4752 ++++++++++ .../web/js/yui/container/container-min.js | 159 + interface/web/js/yui/container/container.js | 4727 ++++++++++ .../js/yui/container/container_core-debug.js | 2932 ++++++ .../js/yui/container/container_core-min.js | 109 + .../web/js/yui/container/container_core.js | 2919 ++++++ interface/web/js/yui/datasource/README | 5 + .../yui/datasource/datasource-beta-debug.js | 912 ++ .../js/yui/datasource/datasource-beta-min.js | 59 + .../web/js/yui/datasource/datasource-beta.js | 902 ++ interface/web/js/yui/datatable/README | 9 + .../web/js/yui/datatable/assets/datatable.css | 82 + .../js/yui/datatable/datatable-beta-debug.js | 4956 ++++++++++ .../js/yui/datatable/datatable-beta-min.js | 214 + .../web/js/yui/datatable/datatable-beta.js | 4930 ++++++++++ interface/web/js/yui/dom/README | 79 + interface/web/js/yui/dom/dom-debug.js | 935 ++ interface/web/js/yui/dom/dom-min.js | 59 + interface/web/js/yui/dom/dom.js | 901 ++ interface/web/js/yui/dragdrop/README | 118 + .../web/js/yui/dragdrop/dragdrop-debug.js | 3068 ++++++ interface/web/js/yui/dragdrop/dragdrop-min.js | 93 + interface/web/js/yui/dragdrop/dragdrop.js | 2958 ++++++ interface/web/js/yui/element/README | 7 + .../web/js/yui/element/element-beta-debug.js | 906 ++ .../web/js/yui/element/element-beta-min.js | 30 + interface/web/js/yui/element/element-beta.js | 896 ++ interface/web/js/yui/event/README | 161 + interface/web/js/yui/event/event-debug.js | 2076 ++++ interface/web/js/yui/event/event-min.js | 84 + interface/web/js/yui/event/event.js | 2054 ++++ interface/web/js/yui/fonts/README | 13 + interface/web/js/yui/fonts/fonts-min.css | 7 + interface/web/js/yui/fonts/fonts.css | 29 + interface/web/js/yui/grids/README | 48 + interface/web/js/yui/grids/grids-min.css | 7 + interface/web/js/yui/grids/grids.css | 129 + interface/web/js/yui/history/README | 11 + .../web/js/yui/history/assets/blank.html | 1 + .../yui/history/history-experimental-debug.js | 649 ++ .../yui/history/history-experimental-min.js | 44 + .../js/yui/history/history-experimental.js | 649 ++ interface/web/js/yui/logger/README | 51 + interface/web/js/yui/logger/assets/logger.css | 26 + interface/web/js/yui/logger/logger-debug.js | 1597 ++++ interface/web/js/yui/logger/logger-min.js | 63 + interface/web/js/yui/logger/logger.js | 1597 ++++ interface/web/js/yui/menu/README | 385 + interface/web/js/yui/menu/assets/map.gif | Bin 0 -> 264 bytes interface/web/js/yui/menu/assets/menu.css | 384 + .../js/yui/menu/assets/menuarodwn8_dim_1.gif | Bin 0 -> 53 bytes .../js/yui/menu/assets/menuarodwn8_hov_1.gif | Bin 0 -> 53 bytes .../js/yui/menu/assets/menuarodwn8_nrm_1.gif | Bin 0 -> 53 bytes .../js/yui/menu/assets/menuarorght8_dim_1.gif | Bin 0 -> 54 bytes .../js/yui/menu/assets/menuarorght8_hov_1.gif | Bin 0 -> 54 bytes .../js/yui/menu/assets/menuarorght8_nrm_1.gif | Bin 0 -> 54 bytes .../js/yui/menu/assets/menuaroup8_dim_1.gif | Bin 0 -> 53 bytes .../js/yui/menu/assets/menuaroup8_nrm_1.gif | Bin 0 -> 53 bytes .../web/js/yui/menu/assets/menuchk8_dim_1.gif | Bin 0 -> 65 bytes .../web/js/yui/menu/assets/menuchk8_hov_1.gif | Bin 0 -> 67 bytes .../web/js/yui/menu/assets/menuchk8_nrm_1.gif | Bin 0 -> 67 bytes interface/web/js/yui/menu/menu-debug.js | 8317 +++++++++++++++++ interface/web/js/yui/menu/menu-min.js | 260 + interface/web/js/yui/menu/menu.js | 8265 ++++++++++++++++ interface/web/js/yui/reset-fonts-grids/README | 24 + .../reset-fonts-grids/reset-fonts-grids.css | 9 + interface/web/js/yui/reset/README | 25 + interface/web/js/yui/reset/reset-min.css | 7 + interface/web/js/yui/reset/reset.css | 15 + interface/web/js/yui/slider/README | 69 + interface/web/js/yui/slider/slider-debug.js | 1259 +++ interface/web/js/yui/slider/slider-min.js | 36 + interface/web/js/yui/slider/slider.js | 1222 +++ interface/web/js/yui/tabview/README | 21 + .../web/js/yui/tabview/assets/border_tabs.css | 54 + .../web/js/yui/tabview/assets/tabview.css | 75 + interface/web/js/yui/tabview/tabview-debug.js | 1025 ++ interface/web/js/yui/tabview/tabview-min.js | 35 + interface/web/js/yui/tabview/tabview.js | 1021 ++ interface/web/js/yui/treeview/README | 147 + interface/web/js/yui/treeview/assets/lm.gif | Bin 0 -> 94 bytes interface/web/js/yui/treeview/assets/lmh.gif | Bin 0 -> 106 bytes interface/web/js/yui/treeview/assets/ln.gif | Bin 0 -> 142 bytes .../web/js/yui/treeview/assets/loading.gif | Bin 0 -> 2673 bytes interface/web/js/yui/treeview/assets/lp.gif | Bin 0 -> 130 bytes interface/web/js/yui/treeview/assets/lph.gif | Bin 0 -> 111 bytes interface/web/js/yui/treeview/assets/tm.gif | Bin 0 -> 545 bytes interface/web/js/yui/treeview/assets/tmh.gif | Bin 0 -> 563 bytes interface/web/js/yui/treeview/assets/tn.gif | Bin 0 -> 504 bytes interface/web/js/yui/treeview/assets/tp.gif | Bin 0 -> 539 bytes interface/web/js/yui/treeview/assets/tph.gif | Bin 0 -> 568 bytes interface/web/js/yui/treeview/assets/tree.css | 102 + .../web/js/yui/treeview/assets/vline.gif | Bin 0 -> 503 bytes .../web/js/yui/treeview/treeview-debug.js | 2287 +++++ interface/web/js/yui/treeview/treeview-min.js | 70 + interface/web/js/yui/treeview/treeview.js | 2248 +++++ interface/web/js/yui/utilities/README | 36 + interface/web/js/yui/utilities/utilities.js | 418 + interface/web/js/yui/yahoo-dom-event/README | 35 + .../js/yui/yahoo-dom-event/yahoo-dom-event.js | 144 + interface/web/js/yui/yahoo/README | 64 + interface/web/js/yui/yahoo/yahoo-debug.js | 433 + interface/web/js/yui/yahoo/yahoo-min.js | 15 + interface/web/js/yui/yahoo/yahoo.js | 433 + interface/web/login/_index.php | 84 + interface/web/login/index.php | 207 +- interface/web/login/templates/index.htm | 63 +- .../form/_old_mail_domain_catchall.tform.php | 107 - .../web/mail/lib/lang/en_mail_alias_list.lng | 5 +- .../mail/lib/lang/en_mail_blacklist_list.lng | 30 +- .../lib/lang/en_mail_domain_catchall_list.lng | 27 +- .../mail/lib/lang/en_mail_forward_list.lng | 3 +- .../mail/lib/lang/en_mail_transport_list.lng | 28 +- .../mail/lib/lang/en_mail_whitelist_list.lng | 30 +- .../lib/lang/en_spamfilter_blacklist_list.lng | 28 +- .../lib/lang/en_spamfilter_policy_list.lng | 28 +- .../lib/lang/en_spamfilter_users_list.lng | 30 +- .../lib/lang/en_spamfilter_whitelist_list.lng | 28 +- interface/web/mail/lib/module.conf.php | 6 +- .../web/mail/templates/mail_alias_edit.htm | 56 +- .../web/mail/templates/mail_alias_list.htm | 30 +- .../mail/templates/mail_blacklist_edit.htm | 4 +- .../mail/templates/mail_blacklist_list.htm | 36 +- .../mail/templates/mail_box_mailuser_edit.htm | 70 +- .../templates/mail_domain_catchall_edit.htm | 4 +- .../templates/mail_domain_catchall_list.htm | 30 +- .../web/mail/templates/mail_domain_edit.htm | 58 +- .../web/mail/templates/mail_domain_list.htm | 17 +- .../web/mail/templates/mail_forward_edit.htm | 48 +- .../web/mail/templates/mail_forward_list.htm | 30 +- .../mail/templates/mail_spamfilter_edit.htm | 4 +- .../mail/templates/mail_spamfilter_list.htm | 30 - .../mail/templates/mail_transport_edit.htm | 78 +- .../mail/templates/mail_transport_list.htm | 42 +- .../mail_user_autoresponder_edit.htm | 40 +- .../web/mail/templates/mail_user_list.htm | 24 +- .../mail/templates/mail_user_mailbox_edit.htm | 4 +- .../templates/mail_user_mailuser_edit.htm | 70 +- .../mail/templates/mail_whitelist_edit.htm | 4 +- .../mail/templates/mail_whitelist_list.htm | 36 +- .../templates/spamfilter_blacklist_edit.htm | 4 +- .../templates/spamfilter_blacklist_list.htm | 42 +- .../mail/templates/spamfilter_other_edit.htm | 158 +- .../mail/templates/spamfilter_policy_edit.htm | 142 +- .../mail/templates/spamfilter_policy_list.htm | 42 +- .../templates/spamfilter_quarantine_edit.htm | 70 +- .../templates/spamfilter_taglevel_edit.htm | 94 +- .../mail/templates/spamfilter_users_edit.htm | 4 +- .../mail/templates/spamfilter_users_list.htm | 47 +- .../templates/spamfilter_whitelist_edit.htm | 4 +- .../templates/spamfilter_whitelist_list.htm | 42 +- interface/web/nav.php | 100 + interface/web/test.txt | 26 + interface/web/test/lib/module.conf.php | 40 +- .../web/themes/default/images/button_bg.gif | Bin 0 -> 443 bytes .../web/themes/default/images/button_end.gif | Bin 0 -> 57 bytes interface/web/themes/default/style.css | 545 +- .../themes/default/templates/_form.tpl.htm | 12 + .../web/themes/default/templates/form.tpl.htm | 26 +- .../themes/default/templates/listpage.tpl.htm | 1 + .../web/themes/default/templates/main.tpl.htm | 100 +- .../default/templates/main_prototype.tpl.htm | 166 + .../themes/default/templates/sidenav.tpl.htm | 22 + .../default/templates/tabbed_form.tpl.htm | 118 +- .../themes/default/templates/topnav.tpl.htm | 12 + .../web/themes/grey/templates/_main.tpl.htm | 48 + .../web/themes/grey/templates/form.tpl.htm | 37 +- .../web/themes/grey/templates/main.tpl.htm | 159 +- .../web/themes/grey/templates/sidenav.tpl.htm | 22 + .../web/themes/grey/templates/topnav.tpl.htm | 12 + 252 files changed, 108954 insertions(+), 3100 deletions(-) delete mode 100644 interface/web/admin/templates/paging.tpl.htm create mode 100644 interface/web/content.php create mode 100644 interface/web/js/scrigo.js create mode 100644 interface/web/js/yui/animation/README create mode 100644 interface/web/js/yui/animation/animation-debug.js create mode 100644 interface/web/js/yui/animation/animation-min.js create mode 100644 interface/web/js/yui/animation/animation.js create mode 100644 interface/web/js/yui/autocomplete/README create mode 100644 interface/web/js/yui/autocomplete/autocomplete-debug.js create mode 100644 interface/web/js/yui/autocomplete/autocomplete-min.js create mode 100644 interface/web/js/yui/autocomplete/autocomplete.js create mode 100644 interface/web/js/yui/button/README create mode 100644 interface/web/js/yui/button/assets/background.png create mode 100644 interface/web/js/yui/button/assets/button.css create mode 100644 interface/web/js/yui/button/assets/menuarrow.gif create mode 100644 interface/web/js/yui/button/assets/splitarrow.gif create mode 100644 interface/web/js/yui/button/assets/splitarrow_active.gif create mode 100644 interface/web/js/yui/button/button-beta-debug.js create mode 100644 interface/web/js/yui/button/button-beta-min.js create mode 100644 interface/web/js/yui/button/button-beta.js create mode 100644 interface/web/js/yui/calendar/README create mode 100644 interface/web/js/yui/calendar/assets/calendar.css create mode 100644 interface/web/js/yui/calendar/assets/callt.gif create mode 100644 interface/web/js/yui/calendar/assets/calrt.gif create mode 100644 interface/web/js/yui/calendar/assets/calx.gif create mode 100644 interface/web/js/yui/calendar/calendar-debug.js create mode 100644 interface/web/js/yui/calendar/calendar-min.js create mode 100644 interface/web/js/yui/calendar/calendar.js create mode 100644 interface/web/js/yui/connection/README create mode 100644 interface/web/js/yui/connection/connection-debug.js create mode 100644 interface/web/js/yui/connection/connection-min.js create mode 100644 interface/web/js/yui/connection/connection.js create mode 100644 interface/web/js/yui/container/README create mode 100644 interface/web/js/yui/container/assets/alrt16_1.gif create mode 100644 interface/web/js/yui/container/assets/blck16_1.gif create mode 100644 interface/web/js/yui/container/assets/close12_1.gif create mode 100644 interface/web/js/yui/container/assets/container.css create mode 100644 interface/web/js/yui/container/assets/hlp16_1.gif create mode 100644 interface/web/js/yui/container/assets/info16_1.gif create mode 100644 interface/web/js/yui/container/assets/tip16_1.gif create mode 100644 interface/web/js/yui/container/assets/warn16_1.gif create mode 100644 interface/web/js/yui/container/container-debug.js create mode 100644 interface/web/js/yui/container/container-min.js create mode 100644 interface/web/js/yui/container/container.js create mode 100644 interface/web/js/yui/container/container_core-debug.js create mode 100644 interface/web/js/yui/container/container_core-min.js create mode 100644 interface/web/js/yui/container/container_core.js create mode 100644 interface/web/js/yui/datasource/README create mode 100644 interface/web/js/yui/datasource/datasource-beta-debug.js create mode 100644 interface/web/js/yui/datasource/datasource-beta-min.js create mode 100644 interface/web/js/yui/datasource/datasource-beta.js create mode 100644 interface/web/js/yui/datatable/README create mode 100644 interface/web/js/yui/datatable/assets/datatable.css create mode 100644 interface/web/js/yui/datatable/datatable-beta-debug.js create mode 100644 interface/web/js/yui/datatable/datatable-beta-min.js create mode 100644 interface/web/js/yui/datatable/datatable-beta.js create mode 100644 interface/web/js/yui/dom/README create mode 100644 interface/web/js/yui/dom/dom-debug.js create mode 100644 interface/web/js/yui/dom/dom-min.js create mode 100644 interface/web/js/yui/dom/dom.js create mode 100644 interface/web/js/yui/dragdrop/README create mode 100644 interface/web/js/yui/dragdrop/dragdrop-debug.js create mode 100644 interface/web/js/yui/dragdrop/dragdrop-min.js create mode 100644 interface/web/js/yui/dragdrop/dragdrop.js create mode 100644 interface/web/js/yui/element/README create mode 100644 interface/web/js/yui/element/element-beta-debug.js create mode 100644 interface/web/js/yui/element/element-beta-min.js create mode 100644 interface/web/js/yui/element/element-beta.js create mode 100644 interface/web/js/yui/event/README create mode 100644 interface/web/js/yui/event/event-debug.js create mode 100644 interface/web/js/yui/event/event-min.js create mode 100644 interface/web/js/yui/event/event.js create mode 100644 interface/web/js/yui/fonts/README create mode 100644 interface/web/js/yui/fonts/fonts-min.css create mode 100644 interface/web/js/yui/fonts/fonts.css create mode 100644 interface/web/js/yui/grids/README create mode 100644 interface/web/js/yui/grids/grids-min.css create mode 100644 interface/web/js/yui/grids/grids.css create mode 100644 interface/web/js/yui/history/README create mode 100644 interface/web/js/yui/history/assets/blank.html create mode 100644 interface/web/js/yui/history/history-experimental-debug.js create mode 100644 interface/web/js/yui/history/history-experimental-min.js create mode 100644 interface/web/js/yui/history/history-experimental.js create mode 100644 interface/web/js/yui/logger/README create mode 100644 interface/web/js/yui/logger/assets/logger.css create mode 100644 interface/web/js/yui/logger/logger-debug.js create mode 100644 interface/web/js/yui/logger/logger-min.js create mode 100644 interface/web/js/yui/logger/logger.js create mode 100644 interface/web/js/yui/menu/README create mode 100644 interface/web/js/yui/menu/assets/map.gif create mode 100644 interface/web/js/yui/menu/assets/menu.css create mode 100644 interface/web/js/yui/menu/assets/menuarodwn8_dim_1.gif create mode 100644 interface/web/js/yui/menu/assets/menuarodwn8_hov_1.gif create mode 100644 interface/web/js/yui/menu/assets/menuarodwn8_nrm_1.gif create mode 100644 interface/web/js/yui/menu/assets/menuarorght8_dim_1.gif create mode 100644 interface/web/js/yui/menu/assets/menuarorght8_hov_1.gif create mode 100644 interface/web/js/yui/menu/assets/menuarorght8_nrm_1.gif create mode 100644 interface/web/js/yui/menu/assets/menuaroup8_dim_1.gif create mode 100644 interface/web/js/yui/menu/assets/menuaroup8_nrm_1.gif create mode 100644 interface/web/js/yui/menu/assets/menuchk8_dim_1.gif create mode 100644 interface/web/js/yui/menu/assets/menuchk8_hov_1.gif create mode 100644 interface/web/js/yui/menu/assets/menuchk8_nrm_1.gif create mode 100644 interface/web/js/yui/menu/menu-debug.js create mode 100644 interface/web/js/yui/menu/menu-min.js create mode 100644 interface/web/js/yui/menu/menu.js create mode 100644 interface/web/js/yui/reset-fonts-grids/README create mode 100644 interface/web/js/yui/reset-fonts-grids/reset-fonts-grids.css create mode 100644 interface/web/js/yui/reset/README create mode 100644 interface/web/js/yui/reset/reset-min.css create mode 100644 interface/web/js/yui/reset/reset.css create mode 100644 interface/web/js/yui/slider/README create mode 100644 interface/web/js/yui/slider/slider-debug.js create mode 100644 interface/web/js/yui/slider/slider-min.js create mode 100644 interface/web/js/yui/slider/slider.js create mode 100644 interface/web/js/yui/tabview/README create mode 100644 interface/web/js/yui/tabview/assets/border_tabs.css create mode 100644 interface/web/js/yui/tabview/assets/tabview.css create mode 100644 interface/web/js/yui/tabview/tabview-debug.js create mode 100644 interface/web/js/yui/tabview/tabview-min.js create mode 100644 interface/web/js/yui/tabview/tabview.js create mode 100644 interface/web/js/yui/treeview/README create mode 100644 interface/web/js/yui/treeview/assets/lm.gif create mode 100644 interface/web/js/yui/treeview/assets/lmh.gif create mode 100644 interface/web/js/yui/treeview/assets/ln.gif create mode 100644 interface/web/js/yui/treeview/assets/loading.gif create mode 100644 interface/web/js/yui/treeview/assets/lp.gif create mode 100644 interface/web/js/yui/treeview/assets/lph.gif create mode 100644 interface/web/js/yui/treeview/assets/tm.gif create mode 100644 interface/web/js/yui/treeview/assets/tmh.gif create mode 100644 interface/web/js/yui/treeview/assets/tn.gif create mode 100644 interface/web/js/yui/treeview/assets/tp.gif create mode 100644 interface/web/js/yui/treeview/assets/tph.gif create mode 100644 interface/web/js/yui/treeview/assets/tree.css create mode 100644 interface/web/js/yui/treeview/assets/vline.gif create mode 100644 interface/web/js/yui/treeview/treeview-debug.js create mode 100644 interface/web/js/yui/treeview/treeview-min.js create mode 100644 interface/web/js/yui/treeview/treeview.js create mode 100644 interface/web/js/yui/utilities/README create mode 100644 interface/web/js/yui/utilities/utilities.js create mode 100644 interface/web/js/yui/yahoo-dom-event/README create mode 100644 interface/web/js/yui/yahoo-dom-event/yahoo-dom-event.js create mode 100644 interface/web/js/yui/yahoo/README create mode 100644 interface/web/js/yui/yahoo/yahoo-debug.js create mode 100644 interface/web/js/yui/yahoo/yahoo-min.js create mode 100644 interface/web/js/yui/yahoo/yahoo.js create mode 100644 interface/web/login/_index.php delete mode 100644 interface/web/mail/form/_old_mail_domain_catchall.tform.php delete mode 100644 interface/web/mail/templates/mail_spamfilter_list.htm create mode 100644 interface/web/nav.php create mode 100644 interface/web/test.txt create mode 100644 interface/web/themes/default/images/button_bg.gif create mode 100644 interface/web/themes/default/images/button_end.gif create mode 100644 interface/web/themes/default/templates/_form.tpl.htm create mode 100644 interface/web/themes/default/templates/listpage.tpl.htm create mode 100644 interface/web/themes/default/templates/main_prototype.tpl.htm create mode 100644 interface/web/themes/default/templates/sidenav.tpl.htm create mode 100644 interface/web/themes/default/templates/topnav.tpl.htm create mode 100644 interface/web/themes/grey/templates/_main.tpl.htm create mode 100644 interface/web/themes/grey/templates/sidenav.tpl.htm create mode 100644 interface/web/themes/grey/templates/topnav.tpl.htm diff --git a/interface/lib/app.inc.php b/interface/lib/app.inc.php index 55b821986..fc6f6103b 100644 --- a/interface/lib/app.inc.php +++ b/interface/lib/app.inc.php @@ -169,6 +169,7 @@ class app { } $this->tpl->setVar('app_title',$conf["app_title"]); $this->tpl->setVar('delete_confirmation',$this->lng('delete_confirmation')); + $this->tpl->setVar('app_module',$_SESSION["s"]["module"]["name"]); } diff --git a/interface/lib/classes/listform.inc.php b/interface/lib/classes/listform.inc.php index ea39bee34..492dae0aa 100644 --- a/interface/lib/classes/listform.inc.php +++ b/interface/lib/classes/listform.inc.php @@ -194,7 +194,7 @@ class listform { $pages = intval(($record_count["anzahl"] - 1) / $records_per_page); - $vars["list_file"] = $this->listDef["file"]; + $vars["list_file"] = $_SESSION["s"]["module"]["name"].'/'.$this->listDef["file"]; $vars["page"] = $_SESSION["search"][$list_name]["page"]; $vars["last_page"] = $_SESSION["search"][$list_name]["page"] - 1; $vars["next_page"] = $_SESSION["search"][$list_name]["page"] + 1; @@ -202,6 +202,7 @@ class listform { $vars["max_pages"] = $pages + 1; $vars["records_gesamt"] = $record_count["anzahl"]; $vars["page_params"] = $this->listDef["page_params"]; + //$vars["module"] = $_SESSION["s"]["module"]["name"]; if($_SESSION["search"][$list_name]["page"] > 0) $vars["show_page_back"] = 1; @@ -217,11 +218,11 @@ class listform { function getPagingHTML($vars) { global $app; - $content = '   '; - if($vars["show_page_back"] == 1) $content .= ' '; + $content = '   '; + if($vars["show_page_back"] == 1) $content .= ' '; $content .= ' '.$app->lng('Page').' '.$vars["next_page"].' '.$app->lng('of').' '.$vars["max_pages"].' '; - if($vars["show_page_next"] == 1) $content .= '   '; - $content .= ' '; + if($vars["show_page_next"] == 1) $content .= '   '; + $content .= ' '; return $content; } diff --git a/interface/lib/classes/listform_tpl_generator.inc.php b/interface/lib/classes/listform_tpl_generator.inc.php index 23c38cd2b..8a70373de 100644 --- a/interface/lib/classes/listform_tpl_generator.inc.php +++ b/interface/lib/classes/listform_tpl_generator.inc.php @@ -1,149 +1,150 @@ - -

- - -'; - - $lang["list_head_txt"] = $listDef["name"]; - foreach($listDef["item"] as $field) { - $key = $field["field"]; - $html .= " \r\n"; - $lang[$key."_txt"] = $key; - } - - $html .= ' - - -'; - - foreach($listDef["item"] as $field) { - $key = $field["field"]; - if($field["formtype"] == 'SELECT') { - $html .= " \r\n"; - } else { - $html .= " \r\n"; - } - } - - $html .= ' - - - -'; - - foreach($listDef["item"] as $field) { - $key = $field["field"]; - $html .= " \r\n"; - } - - $html .= " - - -"; - $html .= ' - - - -
 
{tmpl_var name=\"".$key."\"}[{tmpl_var name='delete_txt'}]
-'; - - if($module == '') { - $filename = 'templates/'.$listDef["name"].'_list.htm'; - } else { - $filename = '../'.$module.'/templates/'.$listDef["name"].'_list.htm'; - } - - - // speichere Template - if (!$handle = fopen($filename, 'w')) { - print "Cannot open file ($filename)"; - exit; - } - - if (!fwrite($handle, $html)) { - print "Cannot write to file ($filename)"; - exit; - } - fclose($handle); - - $lang["page_txt"] = 'Page'; - $lang["page_of_txt"] = 'of'; - $lang["page_next_txt"] = 'Next'; - $lang["page_back_txt"] = 'Back'; - $lang["delete_txt"] = 'Delete'; - $lang["filter_txt"] = 'Filter'; - - // speichere language Datei - $this->lng_add($lang,$listDef,$module); - } - - function lng_add($lang,$listDef,$module = '') { - global $go_api, $go_info,$conf; - - if($module == '') { - $lng_file = "lib/lang/".$conf["language"]."_".$listDef['name']."_list.lng"; - } else { - $lng_file = '../'.$module."/lib/lang/en_".$listDef['name']."_list.lng"; - } - - if(is_file($lng_file)) { - include_once($lng_file); - } else { - $wb = array(); - } - - $wb_out = array_merge($wb,$lang); - - if(is_array($wb_out)) { - $fp = fopen ($lng_file, "w"); - fwrite($fp," $val) { - $new_line = '$wb["'.$key.'"] = '."'$val';\r\n"; - fwrite($fp,$new_line); - - } - fwrite($fp,"?>"); - fclose($fp); - } - } -} - +
+


+ + +'; + + $lang["list_head_txt"] = $listDef["name"]; + foreach($listDef["item"] as $field) { + $key = $field["field"]; + $html .= " \r\n"; + $lang[$key."_txt"] = $key; + } + + $html .= ' + + +'; + + foreach($listDef["item"] as $field) { + $key = $field["field"]; + if($field["formtype"] == 'SELECT') { + $html .= " \r\n"; + } else { + $html .= " \r\n"; + } + } + + $html .= ' + + + +'; + + foreach($listDef["item"] as $field) { + $key = $field["field"]; + $html .= " \r\n"; + } + + $html .= " + + +"; + $html .= ' + + + +
 
{tmpl_var name=\"".$key."\"}[{tmpl_var name='delete_txt'}]
'; + + if($module == '') { + $filename = 'templates/'.$listDef["name"].'_list.htm'; + } else { + $filename = '../'.$module.'/templates/'.$listDef["name"].'_list.htm'; + } + + + // speichere Template + if (!$handle = fopen($filename, 'w')) { + print "Cannot open file ($filename)"; + exit; + } + + if (!fwrite($handle, $html)) { + print "Cannot write to file ($filename)"; + exit; + } + fclose($handle); + + $lang["page_txt"] = 'Page'; + $lang["page_of_txt"] = 'of'; + $lang["page_next_txt"] = 'Next'; + $lang["page_back_txt"] = 'Back'; + $lang["delete_txt"] = 'Delete'; + $lang["filter_txt"] = 'Filter'; + + // speichere language Datei + $this->lng_add($lang,$listDef,$module); + } + + function lng_add($lang,$listDef,$module = '') { + global $go_api, $go_info,$conf; + + if($module == '') { + $lng_file = "lib/lang/".$conf["language"]."_".$listDef['name']."_list.lng"; + } else { + $lng_file = '../'.$module."/lib/lang/en_".$listDef['name']."_list.lng"; + } + + if(is_file($lng_file)) { + include_once($lng_file); + } else { + $wb = array(); + } + + $wb_out = array_merge($lang,$wb); + + if(is_array($wb_out)) { + $fp = fopen ($lng_file, "w"); + fwrite($fp," $val) { + $new_line = '$wb["'.$key.'"] = '."'$val';\r\n"; + fwrite($fp,$new_line); + + } + fwrite($fp,"?>"); + fclose($fp); + } + } +} + ?> \ No newline at end of file diff --git a/interface/lib/classes/tform_tpl_generator.inc.php b/interface/lib/classes/tform_tpl_generator.inc.php index dcc92ffbf..7bc994449 100644 --- a/interface/lib/classes/tform_tpl_generator.inc.php +++ b/interface/lib/classes/tform_tpl_generator.inc.php @@ -1,314 +1,316 @@ -'; - $lang = array(); - - foreach($formDef['tabs'][$tab]['fields'] as $key => $field) { - switch ($field['formtype']) { - case 'TEXT': - $html .= " - - {tmpl_var name='".$key."_txt'}: - - "; - break; - case 'TEXTAREA': - $html .= " - - {tmpl_var name='".$key."_txt'}: - - "; - break; - case 'SELECT': - $html .= " - - {tmpl_var name='".$key."_txt'}: - - - - "; - break; - case 'MULTIPLE': - $html .= " - - {tmpl_var name='".$key."_txt'}: - - - - "; - break; - case 'PASSWORD': - $html .= " - - {tmpl_var name='".$key."_txt'}: - - "; - break; - case 'CHECKBOX': - $html .= " - - {tmpl_var name='".$key."_txt'}: - {tmpl_var name='".$key."'} - "; - break; - case 'CHECKBOXARRAY': - $html .= " - - {tmpl_var name='".$key."_txt'}: - {tmpl_var name='".$key."'} - "; - break; - case 'RADIO': - $html .= " - - {tmpl_var name='".$key."_txt'}: - {tmpl_var name='".$key."'} - "; - break; - } - - // Language File Eintrag für "Feld-Titel" anlegen - $lang[$key."_txt"] = $key; - - // language File Eintrag, für error-Text anlegen - if($field["errmsg"] != '') { - $errmsg = $field["errmsg"]; - $lang[$errmsg] = $errmsg; - } - - - } - - $html .= " -   -   - - -   - - - - "; - - $lang['btn_save_txt'] = "Save"; - $lang['btn_cancel_txt'] = "Cancel"; - - $html .= "\r\n\r\n"; - - // speichere Template - if (!$handle = fopen($formDef['tabs'][$tab]['template'], 'w')) { - print "Cannot open file ($filename)"; - exit; - } - - if (!fwrite($handle, $html)) { - print "Cannot write to file ($filename)"; - exit; - } - fclose($handle); - - // speichere language Datei - $this->lng_add($lang,$formDef); - - // überprüfe, ob es die Tabelle schon gibt, - // ansonsten wird sie angelegt - $tables = $app->db->getTables(); - - if(!@in_array($formDef['db_table'],$tables)) { - // Datenbank noch nicht vorhanden - - $columns = array(); - - // füge ID Feld hinzu - $col = array( 'action' => 'add', - 'name' => $formDef["db_table_idx"], - 'type' => 'int64', - 'typeValue' => '', - 'defaultValue' => false, - 'notNull' => true, - 'autoInc' => true, - 'option' => 'primary' - ); - - $columns[] = $col; - $app->db->show_error_messages = true; - - if($formDef["auth"] == 'yes') { - - $col = array( 'action' => 'add', - 'name' => 'sys_userid', - 'type' => 'int32', - 'typeValue' => '', - 'defaultValue' => '0', - 'notNull' => true - ); - $columns[] = $col; - $col = array( 'action' => 'add', - 'name' => 'sys_groupid', - 'type' => 'int32', - 'typeValue' => '', - 'defaultValue' => '0', - 'notNull' => true - ); - $columns[] = $col; - $col = array( 'action' => 'add', - 'name' => 'sys_perm_user', - 'type' => 'varchar', - 'typeValue' => '5', - 'defaultValue' => 'NULL', - 'notNull' => true - ); - $columns[] = $col; - $col = array( 'action' => 'add', - 'name' => 'sys_perm_group', - 'type' => 'varchar', - 'typeValue' => '5', - 'defaultValue' => 'NULL', - 'notNull' => true - ); - $columns[] = $col; - $col = array( 'action' => 'add', - 'name' => 'sys_perm_other', - 'type' => 'varchar', - 'typeValue' => '5', - 'defaultValue' => 'NULL', - 'notNull' => true - ); - $columns[] = $col; - - } - - - foreach($formDef['tabs'] as $tab) { - foreach($tab["fields"] as $name => $field) { - /* - $columns = array(action => add | alter | drop - name => Spaltenname - name_new => neuer Spaltenname, nur bei 'alter' belegt - type => 42go-Meta-Type: int16, int32, int64, double, char, varchar, text, blob - typeValue => Wert z.B. bei Varchar - defaultValue => Default Wert - notNull => true | false - autoInc => true | false - option => unique | primary | index) - - - */ - switch ($field["datatype"]) { - case 'INTEGER': - $type = 'int32'; - $typevalue = ''; - $defaultValue = ($field["default"] != '')?$field["default"]:'0'; - break; - case 'DOUBLE': - $type = 'double'; - $typevalue = ''; - $defaultValue = ($field["default"] != '')?$field["default"]:'0'; - break; - case 'CURRENCY': - $type = 'double'; - $typevalue = ''; - $defaultValue = ($field["default"] != '')?$field["default"]:'0'; - break; - case 'VARCHAR': - $type = 'varchar'; - $typeValue = ($field["maxlength"] > 0 and $field["maxlength"] <= 256)?$field["maxlength"]:255; - // $defaultValue = ($field["default"] != '')?$field["default"]:'NOT NULL'; - $defaultValue = ($field["default"] != '')?$field["default"]:'NULL'; - break; - case 'TEXT': - $type = 'text'; - $typevalue = ''; - $defaultValue = 'NULL'; - break; - case 'DATE': - $type = 'int64'; - $typevalue = ''; - $defaultValue = ($field["default"] != '')?$field["default"]:'0'; - break; - } - - - $col = array( 'action' => 'add', - 'name' => $name, - 'type' => $type, - 'typeValue' => $typeValue, - 'defaultValue' => $defaultValue, - 'notNull' => true - ); - - $columns[] = $col; - } - } - - $app->db->createTable($formDef["db_table"],$columns); - - } - } - - function lng_add($lang,$formDef) { - global $go_api, $go_info,$conf; - - $lng_file = "lib/lang/".$conf["language"]."_".$formDef['name'].".lng"; - if(is_file($lng_file)) { - include($lng_file); - } else { - $wb = array(); - } - - $wb_out = array_merge($wb,$lang); - - if(is_array($wb_out)) { - $fp = fopen ($lng_file, "w"); - fwrite($fp," $val) { - $new_line = '$wb["'.$key.'"] = '."'$val';\r\n"; - fwrite($fp,$new_line); - - } - fwrite($fp,"?>"); - fclose($fp); - } - } -} - +'; + $lang = array(); + + foreach($formDef['tabs'][$tab]['fields'] as $key => $field) { + switch ($field['formtype']) { + case 'TEXT': + $html .= " + + {tmpl_var name='".$key."_txt'}: + + "; + break; + case 'TEXTAREA': + $html .= " + + {tmpl_var name='".$key."_txt'}: + + "; + break; + case 'SELECT': + $html .= " + + {tmpl_var name='".$key."_txt'}: + + + + "; + break; + case 'MULTIPLE': + $html .= " + + {tmpl_var name='".$key."_txt'}: + + + + "; + break; + case 'PASSWORD': + $html .= " + + {tmpl_var name='".$key."_txt'}: + + "; + break; + case 'CHECKBOX': + $html .= " + + {tmpl_var name='".$key."_txt'}: + {tmpl_var name='".$key."'} + "; + break; + case 'CHECKBOXARRAY': + $html .= " + + {tmpl_var name='".$key."_txt'}: + {tmpl_var name='".$key."'} + "; + break; + case 'RADIO': + $html .= " + + {tmpl_var name='".$key."_txt'}: + {tmpl_var name='".$key."'} + "; + break; + } + + // Language File Eintrag für "Feld-Titel" anlegen + $lang[$key."_txt"] = $key; + + // language File Eintrag, für error-Text anlegen + if($field["errmsg"] != '') { + $errmsg = $field["errmsg"]; + $lang[$errmsg] = $errmsg; + } + + + } + + $html .= " +   +   + + +   +
  +
+ + "; + + $lang['btn_save_txt'] = "Save"; + $lang['btn_cancel_txt'] = "Cancel"; + + $html .= "\r\n\r\n"; + + // speichere Template + if (!$handle = fopen($formDef['tabs'][$tab]['template'], 'w')) { + print "Cannot open file ($filename)"; + exit; + } + + if (!fwrite($handle, $html)) { + print "Cannot write to file ($filename)"; + exit; + } + fclose($handle); + + // speichere language Datei + $this->lng_add($lang,$formDef); + + // überprüfe, ob es die Tabelle schon gibt, + // ansonsten wird sie angelegt + $tables = $app->db->getTables(); + + if(!@in_array($formDef['db_table'],$tables)) { + // Datenbank noch nicht vorhanden + + $columns = array(); + + // füge ID Feld hinzu + $col = array( 'action' => 'add', + 'name' => $formDef["db_table_idx"], + 'type' => 'int64', + 'typeValue' => '', + 'defaultValue' => false, + 'notNull' => true, + 'autoInc' => true, + 'option' => 'primary' + ); + + $columns[] = $col; + $app->db->show_error_messages = true; + + if($formDef["auth"] == 'yes') { + + $col = array( 'action' => 'add', + 'name' => 'sys_userid', + 'type' => 'int32', + 'typeValue' => '', + 'defaultValue' => '0', + 'notNull' => true + ); + $columns[] = $col; + $col = array( 'action' => 'add', + 'name' => 'sys_groupid', + 'type' => 'int32', + 'typeValue' => '', + 'defaultValue' => '0', + 'notNull' => true + ); + $columns[] = $col; + $col = array( 'action' => 'add', + 'name' => 'sys_perm_user', + 'type' => 'varchar', + 'typeValue' => '5', + 'defaultValue' => 'NULL', + 'notNull' => true + ); + $columns[] = $col; + $col = array( 'action' => 'add', + 'name' => 'sys_perm_group', + 'type' => 'varchar', + 'typeValue' => '5', + 'defaultValue' => 'NULL', + 'notNull' => true + ); + $columns[] = $col; + $col = array( 'action' => 'add', + 'name' => 'sys_perm_other', + 'type' => 'varchar', + 'typeValue' => '5', + 'defaultValue' => 'NULL', + 'notNull' => true + ); + $columns[] = $col; + + } + + + foreach($formDef['tabs'] as $tab) { + foreach($tab["fields"] as $name => $field) { + /* + $columns = array(action => add | alter | drop + name => Spaltenname + name_new => neuer Spaltenname, nur bei 'alter' belegt + type => 42go-Meta-Type: int16, int32, int64, double, char, varchar, text, blob + typeValue => Wert z.B. bei Varchar + defaultValue => Default Wert + notNull => true | false + autoInc => true | false + option => unique | primary | index) + + + */ + switch ($field["datatype"]) { + case 'INTEGER': + $type = 'int32'; + $typevalue = ''; + $defaultValue = ($field["default"] != '')?$field["default"]:'0'; + break; + case 'DOUBLE': + $type = 'double'; + $typevalue = ''; + $defaultValue = ($field["default"] != '')?$field["default"]:'0'; + break; + case 'CURRENCY': + $type = 'double'; + $typevalue = ''; + $defaultValue = ($field["default"] != '')?$field["default"]:'0'; + break; + case 'VARCHAR': + $type = 'varchar'; + $typeValue = ($field["maxlength"] > 0 and $field["maxlength"] <= 256)?$field["maxlength"]:255; + // $defaultValue = ($field["default"] != '')?$field["default"]:'NOT NULL'; + $defaultValue = ($field["default"] != '')?$field["default"]:'NULL'; + break; + case 'TEXT': + $type = 'text'; + $typevalue = ''; + $defaultValue = 'NULL'; + break; + case 'DATE': + $type = 'int64'; + $typevalue = ''; + $defaultValue = ($field["default"] != '')?$field["default"]:'0'; + break; + } + + + $col = array( 'action' => 'add', + 'name' => $name, + 'type' => $type, + 'typeValue' => $typeValue, + 'defaultValue' => $defaultValue, + 'notNull' => true + ); + + $columns[] = $col; + } + } + + $app->db->createTable($formDef["db_table"],$columns); + + } + } + + function lng_add($lang,$formDef) { + global $go_api, $go_info,$conf; + + $lng_file = "lib/lang/".$conf["language"]."_".$formDef['name'].".lng"; + if(is_file($lng_file)) { + include($lng_file); + } else { + $wb = array(); + } + + $wb_out = array_merge($lang,$wb); + + if(is_array($wb_out)) { + $fp = fopen ($lng_file, "w"); + fwrite($fp," $val) { + $new_line = '$wb["'.$key.'"] = '."'$val';\r\n"; + fwrite($fp,$new_line); + + } + fwrite($fp,"?>"); + fclose($fp); + } + } +} + ?> \ No newline at end of file diff --git a/interface/lib/classes/tpl_ini.inc.php b/interface/lib/classes/tpl_ini.inc.php index 506989514..897211493 100644 --- a/interface/lib/classes/tpl_ini.inc.php +++ b/interface/lib/classes/tpl_ini.inc.php @@ -1,116 +1,116 @@ - | -// +----------------------------------------------------------------------+ -// -// $Id: vlibIni.php,v 1.1 2003/07/08 12:31:10 platinum Exp $ - -/* -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -; This file contains configuration parametres for use ; -; with the vLIB library. [ NOW A CLASS!! ] ; -; ; -; vLIB uses this file so that for future releases, you ; -; will not have to delve through all the php script ; -; again to set your specific variable/properties ..etc ; -; ; -; ---------------------------------------------------- ; -; ATTENTION: Do NOT remove any variable given in the ; -; configurations below as they will probably still be ; -; needed by vLIB. If you do not need a variable simply ; -; let it be. ; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -*/ - -if (!defined('vlibIniClassLoaded')) { - define('vlibIniClassLoaded', 1); - - /** - * vlibIni is a class used to store configuration parameters - * for the vLIB library. - * - * @since 21/07/2002 - * @author Kelvin Jones - * @package vLIB - * @access private - */ - - class vlibIni { - - /** config vars for vlibTemplate */ - function vlibTemplate () { - - global $conf; - - $tpl_dir = $conf["rootpath"]."/web/themes/".$_SESSION["s"]["theme"]."/templates"; - - return array( - - 'TEMPLATE_DIR' => $tpl_dir, // Default directory for your template files (full path) - // leave the '/' or '\' off the end of the directory. - - 'MAX_INCLUDES' => 10, // Drill depth for tmpl_include's - - 'GLOBAL_VARS' => 1, // if set to 1, any variables not found in a - // loop will search for a global var as well - - 'GLOBAL_CONTEXT_VARS' => 1, // if set to 1, vlibTemplate will add global vars - // reflecting the environment. - - 'LOOP_CONTEXT_VARS' => 1, // if set to 1, vlibTemplate will add loop specific vars - // on each row of the loop. - - 'SET_LOOP_VAR' => 1, // Sets a global variable for each top level loops - - 'DEFAULT_ESCAPE' => 'none', // 1 of the following: html, url, sq, dq, none - - 'STRICT' => 0, // Dies when encountering an incorrect tmpl_* - // style tags i.e. tmpl_vae - - 'CASELESS' => 0, // Removes case sensitivity on all variables - - 'UNKNOWNS' => 'ignore', // How to handle unknown variables. - // 1 of the following: ignore, remove, leave,print, comment - // 1 of the following: ignore, remove, leave, print, comment - - 'TIME_PARSE' => '0', // Will enable you to time how long vlibTemplate takes to parse - // your template. You then use the function: getParseTime(). - - 'ENABLE_PHPINCLUDE' => '1', // Will allow template to include a php file using - - - /* the following are only used by the vlibTemplateCache class. */ - - 'CACHE_DIRECTORY' => $conf["template"]["cache_dir"], - // Directory where the cached filesystem - // will be set up (full path, and must be writable) - // '/' or '\' off the end of the directory. - - 'CACHE_LIFETIME' => 604800, // Duration until file is re-cached in seconds (604800 = 1 week) - - 'CACHE_EXTENSION' => 'vtc' // extention to be used by the cached file i.e. index.php will become - // index.vtc (vlibTemplate Compiled) - ); - - } // << end function vlibTemplate - - - - /** config vars for vlibDate */ - function vlibDate () { - - return array( - 'DEFAULT_LANG' => 'de' // default language for the date displays - ); - - }// << end function vlibDate - - - }// << end class vlibIni -} + | +// +----------------------------------------------------------------------+ +// +// $Id: vlibIni.php,v 1.1 2003/07/08 12:31:10 platinum Exp $ + +/* +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; This file contains configuration parametres for use ; +; with the vLIB library. [ NOW A CLASS!! ] ; +; ; +; vLIB uses this file so that for future releases, you ; +; will not have to delve through all the php script ; +; again to set your specific variable/properties ..etc ; +; ; +; ---------------------------------------------------- ; +; ATTENTION: Do NOT remove any variable given in the ; +; configurations below as they will probably still be ; +; needed by vLIB. If you do not need a variable simply ; +; let it be. ; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +*/ + +if (!defined('vlibIniClassLoaded')) { + define('vlibIniClassLoaded', 1); + + /** + * vlibIni is a class used to store configuration parameters + * for the vLIB library. + * + * @since 21/07/2002 + * @author Kelvin Jones + * @package vLIB + * @access private + */ + + class vlibIni { + + /** config vars for vlibTemplate */ + function vlibTemplate () { + + global $conf; + + $tpl_dir = $conf["rootpath"]."/web/themes/".$_SESSION["s"]["theme"]."/templates"; + + return array( + + 'TEMPLATE_DIR' => $tpl_dir, // Default directory for your template files (full path) + // leave the '/' or '\' off the end of the directory. + + 'MAX_INCLUDES' => 10, // Drill depth for tmpl_include's + + 'GLOBAL_VARS' => 1, // if set to 1, any variables not found in a + // loop will search for a global var as well + + 'GLOBAL_CONTEXT_VARS' => 1, // if set to 1, vlibTemplate will add global vars + // reflecting the environment. + + 'LOOP_CONTEXT_VARS' => 1, // if set to 1, vlibTemplate will add loop specific vars + // on each row of the loop. + + 'SET_LOOP_VAR' => 1, // Sets a global variable for each top level loops + + 'DEFAULT_ESCAPE' => 'none', // 1 of the following: html, url, sq, dq, none + + 'STRICT' => 0, // Dies when encountering an incorrect tmpl_* + // style tags i.e. tmpl_vae + + 'CASELESS' => 0, // Removes case sensitivity on all variables + + 'UNKNOWNS' => 'ignore', // How to handle unknown variables. + // 1 of the following: ignore, remove, leave,print, comment + // 1 of the following: ignore, remove, leave, print, comment + + 'TIME_PARSE' => '0', // Will enable you to time how long vlibTemplate takes to parse + // your template. You then use the function: getParseTime(). + + 'ENABLE_PHPINCLUDE' => '1', // Will allow template to include a php file using + + + /* the following are only used by the vlibTemplateCache class. */ + + 'CACHE_DIRECTORY' => $conf["template"]["cache_dir"], + // Directory where the cached filesystem + // will be set up (full path, and must be writable) + // '/' or '\' off the end of the directory. + + 'CACHE_LIFETIME' => 604800, // Duration until file is re-cached in seconds (604800 = 1 week) + + 'CACHE_EXTENSION' => 'vtc' // extention to be used by the cached file i.e. index.php will become + // index.vtc (vlibTemplate Compiled) + ); + + } // << end function vlibTemplate + + + + /** config vars for vlibDate */ + function vlibDate () { + + return array( + 'DEFAULT_LANG' => 'de' // default language for the date displays + ); + + }// << end function vlibDate + + + }// << end class vlibIni +} ?> \ No newline at end of file diff --git a/interface/lib/config.inc.php b/interface/lib/config.inc.php index 3e941906e..a78e5b547 100644 --- a/interface/lib/config.inc.php +++ b/interface/lib/config.inc.php @@ -27,13 +27,17 @@ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +Header("Pragma: no-cache"); +Header("Cache-Control: no-store, no-cache, max-age=0, must-revalidate"); +Header("Content-Type: text/html"); + ini_set('register_globals',0); $conf["app_title"] = "ISPConfig"; $conf["app_version"] = "3.0.0"; -$conf["rootpath"] = "D:\\server\\www\\ispconfig3\\interface"; +$conf["rootpath"] = "D:\\server\\www\\ispconfig3_ajax\\interface"; //$conf["rootpath"] = "D:\\www\\ispconfig3\\interface"; //$conf["rootpath"] = "/home/www/ispconfig3/web/cms"; @@ -43,7 +47,7 @@ $conf["temppath"] = $conf["rootpath"].$conf["fs_div"]."temp"; define("DIR_TRENNER","\\"); -define("SERVER_ROOT","D:\\server\\www\\ispconfig3\\interface"); +define("SERVER_ROOT","D:\\server\\www\\ispconfig3_ajax\\interface"); define("INCLUDE_ROOT",SERVER_ROOT.DIR_TRENNER."lib"); define("CLASSES_ROOT",INCLUDE_ROOT.DIR_TRENNER."classes"); @@ -79,7 +83,7 @@ $conf["programs"]["wput"] = $conf["rootpath"]."\\tools\\wput\\wput.exe"; Themes */ -$conf["theme"] = 'grey'; +$conf["theme"] = 'default'; $conf["html_content_encoding"] = 'text/html; charset=iso-8859-1'; $conf["logo"] = 'themes/default/images/mydnsconfig_logo.gif'; diff --git a/interface/web/admin/form/dbsync.tform.php b/interface/web/admin/form/dbsync.tform.php index 9199a52de..28a256d6f 100644 --- a/interface/web/admin/form/dbsync.tform.php +++ b/interface/web/admin/form/dbsync.tform.php @@ -228,7 +228,7 @@ $form["tabs"]['dbsync'] = array ( 'regex' => '', 'errmsg' => '', 'default' => '', - 'value' => '1', + 'value' => array(0 => 0,1 => 1), 'separator' => '', 'width' => '30', 'maxlength' => '255', @@ -241,7 +241,7 @@ $form["tabs"]['dbsync'] = array ( 'regex' => '', 'errmsg' => '', 'default' => '', - 'value' => '1', + 'value' => array(0 => 0,1 => 1), 'separator' => '', 'width' => '30', 'maxlength' => '255', @@ -254,7 +254,7 @@ $form["tabs"]['dbsync'] = array ( 'regex' => '', 'errmsg' => '', 'default' => '1', - 'value' => '1', + 'value' => array(0 => 0,1 => 1), 'separator' => '', 'width' => '30', 'maxlength' => '255', diff --git a/interface/web/admin/form/filesync.tform.php b/interface/web/admin/form/filesync.tform.php index 969dbe2d3..721fd972c 100644 --- a/interface/web/admin/form/filesync.tform.php +++ b/interface/web/admin/form/filesync.tform.php @@ -189,7 +189,7 @@ $form["tabs"]['filesync'] = array ( 'regex' => '', 'errmsg' => '', 'default' => '1', - 'value' => '1', + 'value' => array(0 => 0,1 => 1), 'separator' => '', 'width' => '30', 'maxlength' => '255', diff --git a/interface/web/admin/form/server.tform.php b/interface/web/admin/form/server.tform.php index baca47ec3..968218076 100644 --- a/interface/web/admin/form/server.tform.php +++ b/interface/web/admin/form/server.tform.php @@ -70,44 +70,46 @@ $form["tabs"]['services'] = array ( 'datatype' => 'INTEGER', 'formtype' => 'CHECKBOX', 'default' => '0', - 'value' => '1' + 'value' => array(0 => 0,1 => 1) ), 'web_server' => array ( 'datatype' => 'INTEGER', 'formtype' => 'CHECKBOX', 'default' => '0', - 'value' => '1' + 'value' => array(0 => 0,1 => 1) ), 'dns_server' => array ( 'datatype' => 'INTEGER', 'formtype' => 'CHECKBOX', 'default' => '0', - 'value' => '1' + 'value' => array(0 => 0,1 => 1) ), 'file_server' => array ( 'datatype' => 'INTEGER', 'formtype' => 'CHECKBOX', 'default' => '0', - 'value' => '1' + 'value' => array(0 => 0,1 => 1) ), 'db_server' => array ( 'datatype' => 'INTEGER', 'formtype' => 'CHECKBOX', 'default' => '0', - 'value' => '1' + 'value' => array(0 => 0,1 => 1) ), 'vserver_server' => array ( 'datatype' => 'INTEGER', 'formtype' => 'CHECKBOX', 'default' => '0', - 'value' => '1' + 'value' => array(0 => 0,1 => 1) ), + /* 'update' => array ( 'datatype' => 'INTEGER', 'formtype' => 'SELECT', 'default' => '1', 'value' => array(0 => 'No', 1 => 'Yes') ), + */ 'active' => array ( 'datatype' => 'INTEGER', 'formtype' => 'SELECT', diff --git a/interface/web/admin/form/users.tform.php b/interface/web/admin/form/users.tform.php index bbe537d87..c099b71c4 100644 --- a/interface/web/admin/form/users.tform.php +++ b/interface/web/admin/form/users.tform.php @@ -214,7 +214,7 @@ $form["tabs"]['users'] = array ( 'regex' => '', 'errmsg' => '', 'default' => '', - 'value' => '1', + 'value' => array(0 => 0,1 => 1), 'separator' => '', 'width' => '30', 'maxlength' => '255', diff --git a/interface/web/admin/groups_del.php b/interface/web/admin/groups_del.php index ba3a922dc..49588c2ce 100644 --- a/interface/web/admin/groups_del.php +++ b/interface/web/admin/groups_del.php @@ -1,6 +1,7 @@ 0) { - if($_SESSION["s"]["user"]["typ"] == "admin") { - $app->db->query("DELETE FROM ".$liste["table"]." WHERE ".$liste["table_idx"]." = $id"); - } else { - $app->db->query("DELETE FROM ".$liste["table"]." WHERE ".$liste["table_idx"]." = $id and userid = ".$_SESSION["s"]["user"]["userid"]); - } -} - +$app->uses("tform_actions"); +$app->tform_actions->onDelete(); -header("Location: ".$liste["file"]."?PHPSESSID=".$_SESSION["s"]["id"]); -exit; ?> \ No newline at end of file diff --git a/interface/web/admin/groups_edit.php b/interface/web/admin/groups_edit.php index f73c16093..d649f4045 100644 --- a/interface/web/admin/groups_edit.php +++ b/interface/web/admin/groups_edit.php @@ -1,6 +1,6 @@ uses('tpl,tform'); -$app->tpl->newTemplate("tabbed_form.tpl.htm"); - -// Tabellendefinition und Formdefinition laden -$app->tform->loadFormDef($tform_def_file); - -// ID importieren -$id = intval($_REQUEST["id"]); - -if(count($_POST) > 1) { - - // Bestimme aktion - if($id > 0) { - $action = 'UPDATE'; - } else { - $action = 'INSERT'; - } - - $sql = $app->tform->getSQL($_POST,$_SESSION["s"]["form"]["tab"],$action,$id,$ext_where); - if($app->tform->errorMessage == '') { - $app->db->query($sql); - if($action == "INSERT") $id = $app->db->insertID(); - - // Liste anzeigen, wenn speichern geklickt wurde - if($_REQUEST["next_tab"] == '') { - header("Location: ".$app->tform->formDef['list_default']); - exit; - } - - } else { - $app->tpl->setVar("error","Fehler:
".$app->tform->errorMessage); - $app->tpl->setVar($_POST); - } -} - -// Welcher Tab wird angezeigt -if($app->tform->errorMessage == '') { - // wenn kein Fehler vorliegt - if($_REQUEST["next_tab"] != '') { - // wenn nächster Tab bekannt - $active_tab = $_REQUEST["next_tab"]; - } else { - // ansonsten ersten tab nehmen - $active_tab = $app->tform->formDef['tab_default']; - } -} else { - // bei Fehlern den gleichen Tab nochmal anzeigen - $active_tab = $_SESSION["s"]["form"]["tab"]; -} - - -if($id > 0) { - // bestehenden Datensatz anzeigen - if($app->tform->errorMessage == '') { - if($app->tform->formDef['auth'] == 'no') { - $sql = "SELECT * FROM ".$app->tform->formDef['db_table']." WHERE ".$app->tform->formDef['db_table_idx']." = $id"; - } else { - $sql = "SELECT * FROM ".$app->tform->formDef['db_table']." WHERE ".$app->tform->formDef['db_table_idx']." = $id AND ".$app->tform->getAuthSQL('u'); - } - if(!$record = $app->db->queryOneRecord($sql)) die("You dont have the permission to view this record or this record does not exist."); - } else { - $record = $app->tform->encode($_POST,$active_tab); - } - - // Userdaten umwandeln - $record = $app->tform->getHTML($record, $active_tab,'EDIT'); - $record['id'] = $id; -} else { - if($app->tform->errorMessage == '') { - $record = array(); - $record = $app->tform->getHTML($record, $app->tform->formDef['tab_default'],'NEW'); - } else { - $record = $app->tform->getHTML($app->tform->encode($_POST,$active_tab),$active_tab,'EDIT'); - } -} - -$app->tpl->setVar($record); - -// Formular und Tabs erzeugen -$app->tform->showForm(); - -// Defaultwerte setzen -$app->tpl_defaults(); +// Loading classes +$app->uses('tpl,tform,tform_actions'); -// Template parsen -$app->tpl->pparse(); +// let tform_actions handle the page +$app->tform_actions->onLoad(); ?> \ No newline at end of file diff --git a/interface/web/admin/groups_list.php b/interface/web/admin/groups_list.php index e07ddd216..3545f04a6 100644 --- a/interface/web/admin/groups_list.php +++ b/interface/web/admin/groups_list.php @@ -1,6 +1,7 @@ uses('tpl,listform'); - -// Listen Definition laden -$app->listform->loadListDef($list_def_file); - -if(!is_file('templates/'.$app->listform->listDef["name"].'_list.htm')) { - $app->uses('listform_tpl_generator'); - $app->listform_tpl_generator->buildHTML($app->listform->listDef); -} - -$app->tpl->newTemplate("form.tpl.htm"); -$app->tpl->setInclude('content_tpl','templates/'.$app->listform->listDef["name"].'_list.htm'); - -// SQL für Suche generieren -if($app->listform->listDef["name"] != 'no') { - if($_SESSION["s"]["user"]["typ"] == "admin") { - $sql_where = ""; - } else { - $sql_where = "userid = ".$_SESSION["s"]["user"]["userid"]." and"; - } -} - -$sql_where = $app->listform->getSearchSQL($sql_where); -$app->tpl->setVar($app->listform->searchValues); - -// SQL für Paging generieren -$limit_sql = $app->listform->getPagingSQL($sql_where); -$app->tpl->setVar("paging",$app->listform->pagingHTML); - -// hole alle Datensätze -$records = $app->db->queryAllRecords("SELECT * FROM ".$app->listform->listDef["table"]." WHERE $sql_where $limit_sql"); - -$bgcolor = "#FFFFFF"; - -if(is_array($records)) { - $idx_key = $app->listform->listDef["table_idx"]; - foreach($records as $rec) { - - $rec = $app->listform->decode($rec); - - // Farbwechsel - $bgcolor = ($bgcolor == "#FFFFFF")?"#EEEEEE":"#FFFFFF"; - $rec["bgcolor"] = $bgcolor; - - // die Variable "id" enthält immer die Index variable - $rec["id"] = $rec[$idx_key]; - - $records_new[] = $rec; - } -} - -$app->tpl->setLoop('records',$records_new); - -// Language File setzen -$lng_file = "lib/lang/".$_SESSION["s"]["language"]."_".$app->listform->listDef['name']."_list.lng"; -include($lng_file); -$app->tpl->setVar($wb); - -$app->tpl_defaults(); -$app->tpl->pparse(); - +$app->uses('listform_actions'); +$app->listform_actions->onLoad(); ?> \ No newline at end of file diff --git a/interface/web/admin/index.php b/interface/web/admin/index.php index 4aef3c02a..6c3d51af2 100644 --- a/interface/web/admin/index.php +++ b/interface/web/admin/index.php @@ -26,14 +26,53 @@ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -require_once('../../lib/config.inc.php'); -require_once('../../lib/app.inc.php'); -$app->uses('tpl'); -$app->tpl->newTemplate("form.tpl.htm"); -$app->tpl->setVar('error',$error); -$app->tpl->setInclude('content_tpl','templates/index.htm'); -$app->tpl->pparse(); +class admin_index { + + var $status = 'OK'; + var $target = ''; + + function render() { + + global $app; + + $app->uses('tpl'); + $app->tpl->newTemplate("form.tpl.htm"); + + $app->tpl->setVar('error',$error); + $app->tpl->setInclude('content_tpl','admin/templates/index.htm'); + return $app->tpl->grab(); + /* + $filename = 'test.txt'; +$somecontent = $app->tpl->grab(); + +// Sichergehen, dass die Datei existiert und beschreibbar ist + + + // Wir öffnen $filename im "Anhänge" - Modus. + // Der Dateizeiger befindet sich am Ende der Datei, und + // dort wird $somecontent später mit fwrite() geschrieben. + if (!$handle = fopen($filename, "w")) { + print "Kann die Datei $filename nicht öffnen"; + exit; + } + + // Schreibe $somecontent in die geöffnete Datei. + if (!fwrite($handle, $somecontent)) { + print "Kann in die Datei $filename nicht schreiben"; + exit; + } + + + fclose($handle); + + + + + return 'dd'; + */ + } +} ?> \ No newline at end of file diff --git a/interface/web/admin/lib/lang/en_groups.lng b/interface/web/admin/lib/lang/en_groups.lng index a504f9913..1cd86e5ca 100644 --- a/interface/web/admin/lib/lang/en_groups.lng +++ b/interface/web/admin/lib/lang/en_groups.lng @@ -2,4 +2,6 @@ $wb["description_txt"] = 'Description'; $wb["name_txt"] = 'Group'; $wb["name_err"] = 'Group must be min 1, max 30 Chars.'; +$wb["btn_save_txt"] = 'Save'; +$wb["btn_cancel_txt"] = 'Cancel' ?> \ No newline at end of file diff --git a/interface/web/admin/templates/dbsync_edit.htm b/interface/web/admin/templates/dbsync_edit.htm index 88b6c9da3..240d15f9e 100644 --- a/interface/web/admin/templates/dbsync_edit.htm +++ b/interface/web/admin/templates/dbsync_edit.htm @@ -1,60 +1,60 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
{tmpl_var name='jobname_txt'}:
{tmpl_var name='sync_interval_minutes_txt'}:
{tmpl_var name='db_type_txt'}: - -
{tmpl_var name='db_host_txt'}:
{tmpl_var name='db_name_txt'}:
{tmpl_var name='db_username_txt'}:
{tmpl_var name='db_password_txt'}:
{tmpl_var name='db_tables_txt'}:{tmpl_var name='db_tables'}
{tmpl_var name='empty_datalog_txt'}:{tmpl_var name='empty_datalog'}
{tmpl_var name='sync_datalog_external_txt'}:{tmpl_var name='sync_datalog_external'}
{tmpl_var name='active_txt'}:{tmpl_var name='active'}
  
  - -
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{tmpl_var name='jobname_txt'}:
{tmpl_var name='sync_interval_minutes_txt'}:
{tmpl_var name='db_type_txt'}: + +
{tmpl_var name='db_host_txt'}:
{tmpl_var name='db_name_txt'}:
{tmpl_var name='db_username_txt'}:
{tmpl_var name='db_password_txt'}:
{tmpl_var name='db_tables_txt'}:{tmpl_var name='db_tables'}
{tmpl_var name='empty_datalog_txt'}:{tmpl_var name='empty_datalog'}
{tmpl_var name='sync_datalog_external_txt'}:{tmpl_var name='sync_datalog_external'}
{tmpl_var name='active_txt'}:{tmpl_var name='active'}
  
 
  +
+
\ No newline at end of file diff --git a/interface/web/admin/templates/dbsync_list.htm b/interface/web/admin/templates/dbsync_list.htm index 150d63ac9..5c2cda3c8 100644 --- a/interface/web/admin/templates/dbsync_list.htm +++ b/interface/web/admin/templates/dbsync_list.htm @@ -1,29 +1,28 @@ -
-

- - +

+


+
+ - - - + + + - - - - - - - - - - - - - - -
 
 
{tmpl_var name="jobname"}{tmpl_var name="db_host"}{tmpl_var name="db_name"}[Löschen]
-
\ No newline at end of file +
+ + + + {tmpl_var name="jobname"} + {tmpl_var name="db_host"} + {tmpl_var name="db_name"} + [{tmpl_var name='delete_txt'}] + + + + + + + \ No newline at end of file diff --git a/interface/web/admin/templates/filesync_edit.htm b/interface/web/admin/templates/filesync_edit.htm index 17bed85fb..f06b20a67 100644 --- a/interface/web/admin/templates/filesync_edit.htm +++ b/interface/web/admin/templates/filesync_edit.htm @@ -1,48 +1,48 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
{tmpl_var name='jobname_txt'}:
{tmpl_var name='sync_interval_minutes_txt'}:
{tmpl_var name='ftp_host_txt'}:
{tmpl_var name='ftp_path_txt'}:
{tmpl_var name='ftp_username_txt'}:
{tmpl_var name='ftp_password_txt'}:
{tmpl_var name='local_path_txt'}:
{tmpl_var name='wput_options_txt'}:
{tmpl_var name='active_txt'}:{tmpl_var name='active'}
  
  - -
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{tmpl_var name='jobname_txt'}:
{tmpl_var name='sync_interval_minutes_txt'}:
{tmpl_var name='ftp_host_txt'}:
{tmpl_var name='ftp_path_txt'}:
{tmpl_var name='ftp_username_txt'}:
{tmpl_var name='ftp_password_txt'}:
{tmpl_var name='local_path_txt'}:
{tmpl_var name='wput_options_txt'}:
{tmpl_var name='active_txt'}:{tmpl_var name='active'}
  
 
  +
+
\ No newline at end of file diff --git a/interface/web/admin/templates/filesync_list.htm b/interface/web/admin/templates/filesync_list.htm index 0d3c60ff9..a33599be4 100644 --- a/interface/web/admin/templates/filesync_list.htm +++ b/interface/web/admin/templates/filesync_list.htm @@ -1,29 +1,28 @@ -

- +


+
- - - + + + - - - - + + + + - - - - + + + + -
 
{tmpl_var name="jobname"}{tmpl_var name="ftp_host"}{tmpl_var name="local_path"}[Delete]{tmpl_var name="jobname"}{tmpl_var name="ftp_host"}{tmpl_var name="local_path"}[{tmpl_var name='delete_txt'}]
-
\ No newline at end of file + \ No newline at end of file diff --git a/interface/web/admin/templates/groups_edit.htm b/interface/web/admin/templates/groups_edit.htm index 362a216e7..acd34315a 100644 --- a/interface/web/admin/templates/groups_edit.htm +++ b/interface/web/admin/templates/groups_edit.htm @@ -1,16 +1,20 @@ - - - - - - - - - - - +
{tmpl_var name='name_txt'}:
{tmpl_var name='description_txt'}:
  - -
+ + + + + + + + + + + + + +
{tmpl_var name='name_txt'}:
{tmpl_var name='description_txt'}:
  
 
  +
+
\ No newline at end of file diff --git a/interface/web/admin/templates/groups_list.htm b/interface/web/admin/templates/groups_list.htm index 9a9163a55..af0cc4a4e 100644 --- a/interface/web/admin/templates/groups_list.htm +++ b/interface/web/admin/templates/groups_list.htm @@ -1,26 +1,25 @@ -

- +


+
- - + + - - - + + + - - - + + + -
 
{tmpl_var name="name"}{tmpl_var name="description"}[Delete]{tmpl_var name="name"}{tmpl_var name="description"}[{tmpl_var name='delete_txt'}]
-
\ No newline at end of file + \ No newline at end of file diff --git a/interface/web/admin/templates/index.htm b/interface/web/admin/templates/index.htm index 92cab2ccd..af992e881 100644 --- a/interface/web/admin/templates/index.htm +++ b/interface/web/admin/templates/index.htm @@ -1,15 +1,13 @@ -

 

-

 

-

 

-

 

-

 

-

 

-

 

-
- - - - - -
  Admin
-
+

 

+

 

+

 

+

 

+

 

+

 

+

 

+ + + + + +
  Admin
diff --git a/interface/web/admin/templates/paging.tpl.htm b/interface/web/admin/templates/paging.tpl.htm deleted file mode 100644 index cb8270404..000000000 --- a/interface/web/admin/templates/paging.tpl.htm +++ /dev/null @@ -1,9 +0,0 @@ -[ |<< ] - - [<< Zurück] - - Seite {tmpl_var name="next_page"} von {tmpl_var name="max_pages"} - - [Weiter >>] - - [ >>| ] \ No newline at end of file diff --git a/interface/web/admin/templates/server_edit_services.htm b/interface/web/admin/templates/server_edit_services.htm index ec2bd5423..1c9e3fd28 100644 --- a/interface/web/admin/templates/server_edit_services.htm +++ b/interface/web/admin/templates/server_edit_services.htm @@ -1,40 +1,32 @@ - - + + - - - - - -
{tmpl_var name='server_name_txt'}:{tmpl_var name='server_name_txt'}:
 
-
Services - + - + - + - + - + - + - -
{tmpl_var name='mail_server_txt'}: {tmpl_var name='mail_server'}{tmpl_var name='mail_server_txt'}
{tmpl_var name='web_server_txt'}: {tmpl_var name='web_server'}{tmpl_var name='web_server_txt'}
{tmpl_var name='dns_server_txt'}: {tmpl_var name='dns_server'}{tmpl_var name='dns_server_txt'}
{tmpl_var name='file_server_txt'}: {tmpl_var name='file_server'}{tmpl_var name='file_server_txt'}
{tmpl_var name='db_server_txt'}: {tmpl_var name='db_server'}{tmpl_var name='db_server_txt'}
{tmpl_var name='vserver_server_txt'}: {tmpl_var name='vserver_server'}{tmpl_var name='vserver_server_txt'}
-
-
 
{tmpl_var name='active_txt'}: @@ -48,9 +40,9 @@
  - +
  +
+ + \ No newline at end of file diff --git a/interface/web/admin/templates/server_list.htm b/interface/web/admin/templates/server_list.htm index 0812fb4b3..80082cca5 100644 --- a/interface/web/admin/templates/server_list.htm +++ b/interface/web/admin/templates/server_list.htm @@ -1,42 +1,40 @@ -

- +


+
- - - - - - - - + + + + + + + - - - - - - - - + + + + + + + + - - - - - - - - + + + + + + + + - + -
 
{tmpl_var name="server_name"}{tmpl_var name="mail_server"}{tmpl_var name="web_server"}{tmpl_var name="dns_server"}{tmpl_var name="file_server"}{tmpl_var name="db_server"}{tmpl_var name="vserver_server"}[{tmpl_var name='delete_txt'}]{tmpl_var name="server_name"}{tmpl_var name="mail_server"}{tmpl_var name="web_server"}{tmpl_var name="dns_server"}{tmpl_var name="file_server"}{tmpl_var name="db_server"}{tmpl_var name="vserver_server"}[{tmpl_var name='delete_txt'}]
-
\ No newline at end of file + \ No newline at end of file diff --git a/interface/web/admin/templates/users_address_edit.htm b/interface/web/admin/templates/users_address_edit.htm index 3ca62fa34..8eff0b96b 100644 --- a/interface/web/admin/templates/users_address_edit.htm +++ b/interface/web/admin/templates/users_address_edit.htm @@ -1,52 +1,56 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
{tmpl_var name='name_txt'}:
{tmpl_var name='vorname_txt'}:
{tmpl_var name='unternehmen_txt'}:
{tmpl_var name='strasse_txt'}:
{tmpl_var name='ort_txt'}:
{tmpl_var name='plz_txt'}:
{tmpl_var name='land_txt'}:
{tmpl_var name='email_txt'}:
{tmpl_var name='url_txt'}:
{tmpl_var name='telefon_txt'}:
{tmpl_var name='fax_txt'}:
  - -
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{tmpl_var name='name_txt'}:
{tmpl_var name='vorname_txt'}:
{tmpl_var name='unternehmen_txt'}:
{tmpl_var name='strasse_txt'}:
{tmpl_var name='ort_txt'}:
{tmpl_var name='plz_txt'}:
{tmpl_var name='land_txt'}:
{tmpl_var name='email_txt'}:
{tmpl_var name='url_txt'}:
{tmpl_var name='telefon_txt'}:
{tmpl_var name='fax_txt'}:
  
 
  +
+
\ No newline at end of file diff --git a/interface/web/admin/templates/users_groups_edit.htm b/interface/web/admin/templates/users_groups_edit.htm index ae72c6499..2fb57fa7f 100644 --- a/interface/web/admin/templates/users_groups_edit.htm +++ b/interface/web/admin/templates/users_groups_edit.htm @@ -1,24 +1,24 @@ - - - - - - - - - - - - - - - +
{tmpl_var name='default_group_txt'}: - -
{tmpl_var name='groups_txt'}:{tmpl_var name='groups'}
  
  - -
+ + + + + + + + + + + + + +
{tmpl_var name='default_group_txt'}: + +
{tmpl_var name='groups_txt'}:{tmpl_var name='groups'}
  
 
  +
+
\ No newline at end of file diff --git a/interface/web/admin/templates/users_list.htm b/interface/web/admin/templates/users_list.htm index 2dee6fdf2..3c4b7e658 100644 --- a/interface/web/admin/templates/users_list.htm +++ b/interface/web/admin/templates/users_list.htm @@ -1,32 +1,31 @@ -

- +


+
- - - - + + + + - - - - - + + + + + - - - - - + + + + + -
 
{tmpl_var name="username"}{tmpl_var name="vorname"}{tmpl_var name="name"}{tmpl_var name="ort"}[Delete]{tmpl_var name="username"}{tmpl_var name="vorname"}{tmpl_var name="name"}{tmpl_var name="ort"}[{tmpl_var name='delete_txt'}]
-
\ No newline at end of file + \ No newline at end of file diff --git a/interface/web/admin/templates/users_user_edit.htm b/interface/web/admin/templates/users_user_edit.htm index 09c9168a3..c8c01d386 100644 --- a/interface/web/admin/templates/users_user_edit.htm +++ b/interface/web/admin/templates/users_user_edit.htm @@ -1,48 +1,52 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
{tmpl_var name='username_txt'}:
{tmpl_var name='passwort_txt'}:
{tmpl_var name='modules_txt'}:{tmpl_var name='modules'}
{tmpl_var name='startmodule_txt'}: - -
{tmpl_var name='app_theme_txt'}:{tmpl_var name='app_theme'}
{tmpl_var name='typ_txt'}:{tmpl_var name='typ'}
{tmpl_var name='active_txt'}:{tmpl_var name='active'}
{tmpl_var name='language_txt'}: - -
  - -
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
{tmpl_var name='username_txt'}:
{tmpl_var name='passwort_txt'}:
{tmpl_var name='modules_txt'}:{tmpl_var name='modules'}
{tmpl_var name='startmodule_txt'}: + +
{tmpl_var name='app_theme_txt'}:{tmpl_var name='app_theme'}
{tmpl_var name='typ_txt'}:{tmpl_var name='typ'}
{tmpl_var name='active_txt'}:{tmpl_var name='active'}
{tmpl_var name='language_txt'}: + +
  
 
  +
+
\ No newline at end of file diff --git a/interface/web/admin/users_del.php b/interface/web/admin/users_del.php index 4fe36df5e..cd3b2792f 100644 --- a/interface/web/admin/users_del.php +++ b/interface/web/admin/users_del.php @@ -1,6 +1,7 @@ 0) { - if($_SESSION["s"]["user"]["typ"] == "admin") { - $app->db->query("DELETE FROM ".$liste["table"]." WHERE ".$liste["table_idx"]." = $id"); - } else { - $app->db->query("DELETE FROM ".$liste["table"]." WHERE ".$liste["table_idx"]." = $id and userid = ".$_SESSION["s"]["user"]["userid"]); - } -} - +$app->uses("tform_actions"); +$app->tform_actions->onDelete(); -header("Location: ".$liste["file"]."?PHPSESSID=".$_SESSION["s"]["id"]); -exit; ?> \ No newline at end of file diff --git a/interface/web/admin/users_edit.php b/interface/web/admin/users_edit.php index 31e07a99a..8dab85828 100644 --- a/interface/web/admin/users_edit.php +++ b/interface/web/admin/users_edit.php @@ -1,6 +1,6 @@ uses('tpl,tform'); -$app->tpl->newTemplate("tabbed_form.tpl.htm"); - -// Tabellendefinition und Formdefinition laden -$app->tform->loadFormDef($tform_def_file); - -// ID importieren -$id = intval($_REQUEST["id"]); - -if(count($_POST) > 1) { - - // Bestimme aktion - if($id > 0) { - $action = 'UPDATE'; - } else { - $action = 'INSERT'; - } - - $sql = $app->tform->getSQL($_POST,$_SESSION["s"]["form"]["tab"],$action,$id,$ext_where); - if($app->tform->errorMessage == '') { - $app->db->query($sql); - if($action == "INSERT") $id = $app->db->insertID(); - - // Liste anzeigen, wenn speichern geklickt wurde - if($_REQUEST["next_tab"] == '') { - header("Location: ".$app->tform->formDef['list_default']); - exit; - } - - } else { - $app->tpl->setVar("error","Fehler:
".$app->tform->errorMessage); - $app->tpl->setVar($_POST); - } -} - -// Welcher Tab wird angezeigt -if($app->tform->errorMessage == '') { - // wenn kein Fehler vorliegt - if($_REQUEST["next_tab"] != '') { - // wenn nächster Tab bekannt - $active_tab = $_REQUEST["next_tab"]; - } else { - // ansonsten ersten tab nehmen - $active_tab = $app->tform->formDef['tab_default']; - } -} else { - // bei Fehlern den gleichen Tab nochmal anzeigen - $active_tab = $_SESSION["s"]["form"]["tab"]; -} - - -if($id > 0) { - // bestehenden Datensatz anzeigen - if($app->tform->errorMessage == '') { - if($app->tform->formDef['auth'] == 'no') { - $sql = "SELECT * FROM ".$app->tform->formDef['db_table']." WHERE ".$app->tform->formDef['db_table_idx']." = $id"; - } else { - $sql = "SELECT * FROM ".$app->tform->formDef['db_table']." WHERE ".$app->tform->formDef['db_table_idx']." = $id AND ".$app->tform->getAuthSQL('u'); - } - if(!$record = $app->db->queryOneRecord($sql)) die("You dont have the permission to view this record or this record does not exist."); - } else { - $record = $app->tform->encode($_POST,$active_tab); - } - - // Userdaten umwandeln - $record = $app->tform->getHTML($record, $active_tab,'EDIT'); - $record['id'] = $id; -} else { - if($app->tform->errorMessage == '') { - $record = array(); - $record = $app->tform->getHTML($record, $app->tform->formDef['tab_default'],'NEW'); - } else { - $record = $app->tform->getHTML($app->tform->encode($_POST,$active_tab),$active_tab,'EDIT'); - } -} - -$app->tpl->setVar($record); - -// Formular und Tabs erzeugen -$app->tform->showForm(); - -// Defaultwerte setzen -$app->tpl_defaults(); +// Loading classes +$app->uses('tpl,tform,tform_actions'); -// Template parsen -$app->tpl->pparse(); +// let tform_actions handle the page +$app->tform_actions->onLoad(); ?> \ No newline at end of file diff --git a/interface/web/admin/users_list.php b/interface/web/admin/users_list.php index 5f7fe0436..105922dfb 100644 --- a/interface/web/admin/users_list.php +++ b/interface/web/admin/users_list.php @@ -1,6 +1,7 @@ uses('tpl,listform'); - -// Listen Definition laden -$app->listform->loadListDef($list_def_file); - -if(!is_file('templates/'.$app->listform->listDef["name"].'_list.htm')) { - $app->uses('listform_tpl_generator'); - $app->listform_tpl_generator->buildHTML($app->listform->listDef); -} - -$app->tpl->newTemplate("form.tpl.htm"); -$app->tpl->setInclude('content_tpl','templates/'.$app->listform->listDef["name"].'_list.htm'); - -// SQL für Suche generieren -if($app->listform->listDef["name"] != 'no') { - if($_SESSION["s"]["user"]["typ"] == "admin") { - $sql_where = ""; - } else { - $sql_where = "userid = ".$_SESSION["s"]["user"]["userid"]." and"; - } -} - -$sql_where = $app->listform->getSearchSQL($sql_where); -$app->tpl->setVar($app->listform->searchValues); - -// SQL für Paging generieren -$limit_sql = $app->listform->getPagingSQL($sql_where); -$app->tpl->setVar("paging",$app->listform->pagingHTML); - -// hole alle Datensätze -$records = $app->db->queryAllRecords("SELECT * FROM ".$app->listform->listDef["table"]." WHERE $sql_where $limit_sql"); - -$bgcolor = "#FFFFFF"; - -if(is_array($records)) { - $idx_key = $app->listform->listDef["table_idx"]; - foreach($records as $rec) { - - $rec = $app->listform->decode($rec); - - // Farbwechsel - $bgcolor = ($bgcolor == "#FFFFFF")?"#EEEEEE":"#FFFFFF"; - $rec["bgcolor"] = $bgcolor; - - // die Variable "id" enthält immer die Index variable - $rec["id"] = $rec[$idx_key]; - - $records_new[] = $rec; - } -} - -$app->tpl->setLoop('records',$records_new); - -// Language File setzen -$lng_file = "lib/lang/".$_SESSION["s"]["language"]."_".$app->listform->listDef['name']."_list.lng"; -include($lng_file); -$app->tpl->setVar($wb); - -$app->tpl_defaults(); -$app->tpl->pparse(); - +$app->uses('listform_actions'); +$app->listform_actions->onLoad(); ?> \ No newline at end of file diff --git a/interface/web/capp.php b/interface/web/capp.php index 68dbda0c0..041e79d26 100644 --- a/interface/web/capp.php +++ b/interface/web/capp.php @@ -46,32 +46,8 @@ if(!in_array($mod,$user_modules)) $app->error($app->lng(301)); if(is_file($mod."/lib/module.conf.php")) { include_once($mod."/lib/module.conf.php"); $_SESSION["s"]["module"] = $module; + echo "HEADER_REDIRECT:".$_SESSION["s"]["module"]["startpage"]; } else { $app->error($app->lng(302)); } - -?> - - - -42go - - - - - - - +?> \ No newline at end of file diff --git a/interface/web/content.php b/interface/web/content.php new file mode 100644 index 000000000..2e9bbc593 --- /dev/null +++ b/interface/web/content.php @@ -0,0 +1,79 @@ +render(); + if($page->status == 'OK') { + echo $content; + } elseif($page->status == 'REDIRECT') { + $target_parts = explode(':',$page->target); + $module = $target_parts[0]; + $page = $target_parts[1]; + if(!preg_match("/^[a-z]{2,20}$/i", $module)) die('target module name contains unallowed chars.'); + if(!preg_match("/^[a-z]{2,20}$/i", $page)) die('target module name contains unallowed chars.'); + + if(is_file("$module/$page.php")) { + include_once("$module/$page.php"); + + $classname = $module.'_'.$page; + $page = new $classname(); + + $content = $page->render(); + if($page->status == 'OK') { + echo $content; + } + } + + } + +} elseif (is_array($_SESSION["s"]['user']) or is_array($_SESSION["s"]["module"])) { + // If the user is logged in, we try to load the default page of the module + die('hhhhh'); + +} else { + die('Page does not exist.'); +} + +?> \ No newline at end of file diff --git a/interface/web/designer/module_nav_flip.php b/interface/web/designer/module_nav_flip.php index 423a52a37..2218402f5 100644 --- a/interface/web/designer/module_nav_flip.php +++ b/interface/web/designer/module_nav_flip.php @@ -88,7 +88,7 @@ if($nav_id != '') { // zu Liste springen - header("Location: module_show.php?id=$module_name"); + echo "HEADER_REDIRECT:designer/module_show.php?id=$module_name"; exit; } ?> \ No newline at end of file diff --git a/interface/web/designer/module_show.php b/interface/web/designer/module_show.php index fb8287106..8ad943509 100644 --- a/interface/web/designer/module_show.php +++ b/interface/web/designer/module_show.php @@ -69,11 +69,11 @@ foreach($navi as $nav_id => $section) { $section[title] - - - - - +
+
+
+
+
"; //$content .= "Bereich:\r\n"; @@ -84,10 +84,10 @@ foreach($navi as $nav_id => $section) { $content .= " $item[title] - - - - +
+
+
+
"; $n2++; diff --git a/interface/web/designer/templates/module_edit.htm b/interface/web/designer/templates/module_edit.htm index 3dceb3592..2cd48a9ea 100644 --- a/interface/web/designer/templates/module_edit.htm +++ b/interface/web/designer/templates/module_edit.htm @@ -1,45 +1,43 @@ -
-

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
:
:
:
:
:
:
  -
  - -
 
- -
\ No newline at end of file +

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
:
:
:
:
:
:
  +
 
+
+
 
+ \ No newline at end of file diff --git a/interface/web/designer/templates/module_list.htm b/interface/web/designer/templates/module_list.htm index 2980c2aa5..1e148f3ee 100644 --- a/interface/web/designer/templates/module_list.htm +++ b/interface/web/designer/templates/module_list.htm @@ -1,4 +1,3 @@ -

@@ -8,13 +7,12 @@ - - + + -
{tmpl_var name="module"}{tmpl_var name="title"}{tmpl_var name="module"}{tmpl_var name="title"} [Delete]
-
\ No newline at end of file + \ No newline at end of file diff --git a/interface/web/designer/templates/module_nav_edit.htm b/interface/web/designer/templates/module_nav_edit.htm index b4c6682b3..3b2007af8 100644 --- a/interface/web/designer/templates/module_nav_edit.htm +++ b/interface/web/designer/templates/module_nav_edit.htm @@ -1,26 +1,24 @@ -
-

- - - - - - - - - - - - - - - - - -
:
  -
  - -
 
- - -
\ No newline at end of file +

+ + + + + + + + + + + + + + + + + +
:
  +
 
+
+
 
+ + \ No newline at end of file diff --git a/interface/web/designer/templates/module_nav_item_edit.htm b/interface/web/designer/templates/module_nav_item_edit.htm index bef32a594..0aee2ca65 100644 --- a/interface/web/designer/templates/module_nav_item_edit.htm +++ b/interface/web/designer/templates/module_nav_item_edit.htm @@ -1,35 +1,33 @@ -
-

- - - - - - - - - - - - - - - - - - - - - - - - - -
:
:
:
  -
  - -
 
- - - -
\ No newline at end of file +

+ + + + + + + + + + + + + + + + + + + + + + + + + +
:
:
:
  +
 
+
+
 
+ + + \ No newline at end of file diff --git a/interface/web/designer/templates/module_show.htm b/interface/web/designer/templates/module_show.htm index 099a8309f..ffdfe9bb8 100644 --- a/interface/web/designer/templates/module_show.htm +++ b/interface/web/designer/templates/module_show.htm @@ -1,53 +1,31 @@ - -
-

-
{tmpl_var name='module_txt'} - - - - - - - - - - - - - - - -
:{tmpl_var name='title'}
:{tmpl_var name='name'}
 
- - -
-
- - - - - - - - -
 
 
-
\ No newline at end of file +

+
{tmpl_var name='module_txt'} + + + + + + + + + + + + + + + +
:{tmpl_var name='title'}
:{tmpl_var name='name'}
 
+
+
+
+
+ + + + + + + + +
 
 
\ No newline at end of file diff --git a/interface/web/dns/lib/module.conf.php b/interface/web/dns/lib/module.conf.php index 527b92734..ea7d08dc0 100644 --- a/interface/web/dns/lib/module.conf.php +++ b/interface/web/dns/lib/module.conf.php @@ -1,55 +1,27 @@ 'dns', - 'title' => 'DNS', - 'template' => 'module.tpl.htm', - 'navframe_page' => '', - 'startpage' => 'dns/soa_list.php', - 'tab_width' => '', - 'nav' => - array ( - 0 => - array ( - 'title' => 'Zones', - 'open' => 1, - 'items' => - array ( - 0 => - array ( - 'title' => 'SOA', - 'target' => 'content', - 'link' => 'dns/soa_list.php', - ), - ), - ), - ), +$module = array ( + 'name' => 'dns', + 'title' => 'DNS', + 'template' => 'module.tpl.htm', + 'navframe_page' => '', + 'startpage' => 'dns/soa_list.php', + 'tab_width' => '', + 'nav' => + array ( + 0 => + array ( + 'title' => 'Zones', + 'open' => 1, + 'items' => + array ( + 0 => + array ( + 'title' => 'SOA', + 'target' => 'content', + 'link' => 'dns/soa_list.php', + ), + ), + ), + ), ) ?> \ No newline at end of file diff --git a/interface/web/index.php b/interface/web/index.php index 28476f2ed..928a1de07 100644 --- a/interface/web/index.php +++ b/interface/web/index.php @@ -34,6 +34,7 @@ require_once('../lib/app.inc.php'); $app->uses('tpl'); $app->tpl->newTemplate("main.tpl.htm"); +/* // Checke User Login and current module if(!is_array($_SESSION["s"]['user']) or !is_array($_SESSION["s"]["module"])) { @@ -91,6 +92,8 @@ $app->tpl->setLoop('nav_left',$nav_translated); $app->tpl->setVar('startpage',$_SESSION["s"]["module"]["startpage"]); $app->tpl->setVar('navframe_page',$_SESSION["s"]["module"]["navframe_page"]); +*/ + $app->tpl_defaults(); $app->tpl->pparse(); ?> \ No newline at end of file diff --git a/interface/web/js/scrigo.js b/interface/web/js/scrigo.js new file mode 100644 index 000000000..b0cba00b3 --- /dev/null +++ b/interface/web/js/scrigo.js @@ -0,0 +1,182 @@ +redirect = ''; + + +function capp(module) { + var cappCallback = { + success: function(o) { + if(o.responseText != '') { + if(o.responseText.indexOf("HEADER_REDIRECT:") > -1) { + var parts = o.responseText.split(":"); + loadContent(parts[1]); + } else { + alert(o.responseText); + } + } + loadMenus(); + }, + failure: function(o) { + alert('Ajax Request was not successful.'); + } + } + var submitFormObj = YAHOO.util.Connect.asyncRequest('GET', 'capp.php?mod='+module, cappCallback); +} + +function submitLoginForm(formname) { + + var submitFormCallback = { + success: function(o) { + if(o.responseText.indexOf("HEADER_REDIRECT:") > -1) { + var parts = o.responseText.split(":"); + //alert(parts[1]); + loadContent(parts[1]); + //redirect = parts[1]; + //window.setTimeout('loadContent(redirect)', 1000); + } else { + document.getElementById('pageContent').innerHTML = o.responseText; + } + loadMenus(); + }, + failure: function(o) { + alert('Ajax Request was not successful.'); + } + } + + YAHOO.util.Connect.setForm(formname); + var submitFormObj = YAHOO.util.Connect.asyncRequest('POST', 'content.php', submitFormCallback); + /* + if(redirect != '') { + loadContent(redirect); + redirect = ''; + } + */ +} + +function submitForm(formname,target) { + + var submitFormCallback = { + success: function(o) { + if(o.responseText.indexOf("HEADER_REDIRECT:") > -1) { + var parts = o.responseText.split(":"); + //alert(parts[1]); + loadContent(parts[1]); + //redirect = parts[1]; + //window.setTimeout('loadContent(redirect)', 1000); + } else { + document.getElementById('pageContent').innerHTML = o.responseText; + } + }, + failure: function(o) { + alert('Ajax Request was not successful. 1'); + } + } + + YAHOO.util.Connect.setForm(formname); + var submitFormObj = YAHOO.util.Connect.asyncRequest('POST', target, submitFormCallback); + /* + if(redirect != '') { + loadContent(redirect); + redirect = ''; + } + */ +} + +function loadContent(pagename) { + var pageContentCallback2 = { + success: function(o) { + //alert(o.responseText); + if(o.responseText.indexOf("HEADER_REDIRECT:") > -1) { + var parts = o.responseText.split(":"); + loadContent(parts[1]); + } else { + document.getElementById('pageContent').innerHTML = o.responseText; + } + }, + failure: function(o) { + alert('Ajax Request was not successful.'); + } + } + + + var pageContentObject2 = YAHOO.util.Connect.asyncRequest('GET', pagename, pageContentCallback2); +} + + +function loadInitContent() { + + var pageContentCallback = { + success: function(o) { + if(o.responseText.indexOf("HEADER_REDIRECT:") > -1) { + var parts = o.responseText.split(":"); + loadContent(parts[1]); + } else { + document.getElementById('pageContent').innerHTML = o.responseText; + } + + /* + var items = document.getElementsByTagName('input'); + for(i=0;i")) { + loadContent(link); + } +} \ No newline at end of file diff --git a/interface/web/js/yui/animation/README b/interface/web/js/yui/animation/README new file mode 100644 index 000000000..a3160f62d --- /dev/null +++ b/interface/web/js/yui/animation/README @@ -0,0 +1,45 @@ +Animation Release Notes + +*** version 2.2.0 ** + +* Fixed AnimMgr.stop() when called without tween + +*** version 0.12.2 *** + +* raised AnimMgr.fps to 1000 + +*** version 0.12.1 *** +* minified version no longer strips line breaks + +*** version 0.12.0 *** + +* added boolean finish argument to Anim.stop() + +*** version 0.11.3 *** + +* no changes + +*** version 0.11.1 *** + +* changed "prototype" shorthand to "proto" (workaround firefox < 1.5 scoping +bug) + +*** version 0.11.0 *** + +* ColorAnim subclass added +* Motion and Scroll now inherit from ColorAnim +* getDefaultUnit method added +* defaultUnit and defaultUnits deprecated +* getDefault and setDefault methods deprecated + +*** version 0.10.0 *** + +* Scroll now handles relative ("by") animation correctly + +* Now converts "auto" values of "from" to appropriate initial values + +*** version 0.9.0 *** + +* Initial release + + diff --git a/interface/web/js/yui/animation/animation-debug.js b/interface/web/js/yui/animation/animation-debug.js new file mode 100644 index 000000000..818c192e0 --- /dev/null +++ b/interface/web/js/yui/animation/animation-debug.js @@ -0,0 +1,1361 @@ +/* +Copyright (c) 2007, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.net/yui/license.txt +version: 2.2.0 +*/ +/* +Copyright (c) 2006, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.net/yui/license.txt +*/ + +/** + * The animation module provides allows effects to be added to HTMLElements. + * @module animation + * @requires yahoo, event, dom + */ + +/** + * + * Base animation class that provides the interface for building animated effects. + *

Usage: var myAnim = new YAHOO.util.Anim(el, { width: { from: 10, to: 100 } }, 1, YAHOO.util.Easing.easeOut);

+ * @class Anim + * @namespace YAHOO.util + * @requires YAHOO.util.AnimMgr + * @requires YAHOO.util.Easing + * @requires YAHOO.util.Dom + * @requires YAHOO.util.Event + * @requires YAHOO.util.CustomEvent + * @constructor + * @param {String | HTMLElement} el Reference to the element that will be animated + * @param {Object} attributes The attribute(s) to be animated. + * Each attribute is an object with at minimum a "to" or "by" member defined. + * Additional optional members are "from" (defaults to current value), "units" (defaults to "px"). + * All attribute names use camelCase. + * @param {Number} duration (optional, defaults to 1 second) Length of animation (frames or seconds), defaults to time-based + * @param {Function} method (optional, defaults to YAHOO.util.Easing.easeNone) Computes the values that are applied to the attributes per frame (generally a YAHOO.util.Easing method) + */ + +YAHOO.util.Anim = function(el, attributes, duration, method) { + if (el) { + this.init(el, attributes, duration, method); + } +}; + +YAHOO.util.Anim.prototype = { + /** + * Provides a readable name for the Anim instance. + * @method toString + * @return {String} + */ + toString: function() { + var el = this.getEl(); + var id = el.id || el.tagName; + return ("Anim " + id); + }, + + patterns: { // cached for performance + noNegatives: /width|height|opacity|padding/i, // keep at zero or above + offsetAttribute: /^((width|height)|(top|left))$/, // use offsetValue as default + defaultUnit: /width|height|top$|bottom$|left$|right$/i, // use 'px' by default + offsetUnit: /\d+(em|%|en|ex|pt|in|cm|mm|pc)$/i // IE may return these, so convert these to offset + }, + + /** + * Returns the value computed by the animation's "method". + * @method doMethod + * @param {String} attr The name of the attribute. + * @param {Number} start The value this attribute should start from for this animation. + * @param {Number} end The value this attribute should end at for this animation. + * @return {Number} The Value to be applied to the attribute. + */ + doMethod: function(attr, start, end) { + return this.method(this.currentFrame, start, end - start, this.totalFrames); + }, + + /** + * Applies a value to an attribute. + * @method setAttribute + * @param {String} attr The name of the attribute. + * @param {Number} val The value to be applied to the attribute. + * @param {String} unit The unit ('px', '%', etc.) of the value. + */ + setAttribute: function(attr, val, unit) { + if ( this.patterns.noNegatives.test(attr) ) { + val = (val > 0) ? val : 0; + } + + YAHOO.util.Dom.setStyle(this.getEl(), attr, val + unit); + }, + + /** + * Returns current value of the attribute. + * @method getAttribute + * @param {String} attr The name of the attribute. + * @return {Number} val The current value of the attribute. + */ + getAttribute: function(attr) { + var el = this.getEl(); + var val = YAHOO.util.Dom.getStyle(el, attr); + + if (val !== 'auto' && !this.patterns.offsetUnit.test(val)) { + return parseFloat(val); + } + + var a = this.patterns.offsetAttribute.exec(attr) || []; + var pos = !!( a[3] ); // top or left + var box = !!( a[2] ); // width or height + + // use offsets for width/height and abs pos top/left + if ( box || (YAHOO.util.Dom.getStyle(el, 'position') == 'absolute' && pos) ) { + val = el['offset' + a[0].charAt(0).toUpperCase() + a[0].substr(1)]; + } else { // default to zero for other 'auto' + val = 0; + } + + return val; + }, + + /** + * Returns the unit to use when none is supplied. + * @method getDefaultUnit + * @param {attr} attr The name of the attribute. + * @return {String} The default unit to be used. + */ + getDefaultUnit: function(attr) { + if ( this.patterns.defaultUnit.test(attr) ) { + return 'px'; + } + + return ''; + }, + + /** + * Sets the actual values to be used during the animation. Should only be needed for subclass use. + * @method setRuntimeAttribute + * @param {Object} attr The attribute object + * @private + */ + setRuntimeAttribute: function(attr) { + var start; + var end; + var attributes = this.attributes; + + this.runtimeAttributes[attr] = {}; + + var isset = function(prop) { + return (typeof prop !== 'undefined'); + }; + + if ( !isset(attributes[attr]['to']) && !isset(attributes[attr]['by']) ) { + return false; // note return; nothing to animate to + } + + start = ( isset(attributes[attr]['from']) ) ? attributes[attr]['from'] : this.getAttribute(attr); + + // To beats by, per SMIL 2.1 spec + if ( isset(attributes[attr]['to']) ) { + end = attributes[attr]['to']; + } else if ( isset(attributes[attr]['by']) ) { + if (start.constructor == Array) { + end = []; + for (var i = 0, len = start.length; i < len; ++i) { + end[i] = start[i] + attributes[attr]['by'][i]; + } + } else { + end = start + attributes[attr]['by']; + } + } + + this.runtimeAttributes[attr].start = start; + this.runtimeAttributes[attr].end = end; + + // set units if needed + this.runtimeAttributes[attr].unit = ( isset(attributes[attr].unit) ) ? attributes[attr]['unit'] : this.getDefaultUnit(attr); + }, + + /** + * Constructor for Anim instance. + * @method init + * @param {String | HTMLElement} el Reference to the element that will be animated + * @param {Object} attributes The attribute(s) to be animated. + * Each attribute is an object with at minimum a "to" or "by" member defined. + * Additional optional members are "from" (defaults to current value), "units" (defaults to "px"). + * All attribute names use camelCase. + * @param {Number} duration (optional, defaults to 1 second) Length of animation (frames or seconds), defaults to time-based + * @param {Function} method (optional, defaults to YAHOO.util.Easing.easeNone) Computes the values that are applied to the attributes per frame (generally a YAHOO.util.Easing method) + */ + init: function(el, attributes, duration, method) { + /** + * Whether or not the animation is running. + * @property isAnimated + * @private + * @type Boolean + */ + var isAnimated = false; + + /** + * A Date object that is created when the animation begins. + * @property startTime + * @private + * @type Date + */ + var startTime = null; + + /** + * The number of frames this animation was able to execute. + * @property actualFrames + * @private + * @type Int + */ + var actualFrames = 0; + + /** + * The element to be animated. + * @property el + * @private + * @type HTMLElement + */ + el = YAHOO.util.Dom.get(el); + + /** + * The collection of attributes to be animated. + * Each attribute must have at least a "to" or "by" defined in order to animate. + * If "to" is supplied, the animation will end with the attribute at that value. + * If "by" is supplied, the animation will end at that value plus its starting value. + * If both are supplied, "to" is used, and "by" is ignored. + * Optional additional member include "from" (the value the attribute should start animating from, defaults to current value), and "unit" (the units to apply to the values). + * @property attributes + * @type Object + */ + this.attributes = attributes || {}; + + /** + * The length of the animation. Defaults to "1" (second). + * @property duration + * @type Number + */ + this.duration = duration || 1; + + /** + * The method that will provide values to the attribute(s) during the animation. + * Defaults to "YAHOO.util.Easing.easeNone". + * @property method + * @type Function + */ + this.method = method || YAHOO.util.Easing.easeNone; + + /** + * Whether or not the duration should be treated as seconds. + * Defaults to true. + * @property useSeconds + * @type Boolean + */ + this.useSeconds = true; // default to seconds + + /** + * The location of the current animation on the timeline. + * In time-based animations, this is used by AnimMgr to ensure the animation finishes on time. + * @property currentFrame + * @type Int + */ + this.currentFrame = 0; + + /** + * The total number of frames to be executed. + * In time-based animations, this is used by AnimMgr to ensure the animation finishes on time. + * @property totalFrames + * @type Int + */ + this.totalFrames = YAHOO.util.AnimMgr.fps; + + + /** + * Returns a reference to the animated element. + * @method getEl + * @return {HTMLElement} + */ + this.getEl = function() { return el; }; + + /** + * Checks whether the element is currently animated. + * @method isAnimated + * @return {Boolean} current value of isAnimated. + */ + this.isAnimated = function() { + return isAnimated; + }; + + /** + * Returns the animation start time. + * @method getStartTime + * @return {Date} current value of startTime. + */ + this.getStartTime = function() { + return startTime; + }; + + this.runtimeAttributes = {}; + + var logger = {}; + logger.log = function() {YAHOO.log.apply(window, arguments)}; + + logger.log('creating new instance of ' + this); + + /** + * Starts the animation by registering it with the animation manager. + * @method animate + */ + this.animate = function() { + if ( this.isAnimated() ) { + return false; + } + + this.currentFrame = 0; + + this.totalFrames = ( this.useSeconds ) ? Math.ceil(YAHOO.util.AnimMgr.fps * this.duration) : this.duration; + + YAHOO.util.AnimMgr.registerElement(this); + }; + + /** + * Stops the animation. Normally called by AnimMgr when animation completes. + * @method stop + * @param {Boolean} finish (optional) If true, animation will jump to final frame. + */ + this.stop = function(finish) { + if (finish) { + this.currentFrame = this.totalFrames; + this._onTween.fire(); + } + YAHOO.util.AnimMgr.stop(this); + }; + + var onStart = function() { + this.onStart.fire(); + + this.runtimeAttributes = {}; + for (var attr in this.attributes) { + this.setRuntimeAttribute(attr); + } + + isAnimated = true; + actualFrames = 0; + startTime = new Date(); + }; + + /** + * Feeds the starting and ending values for each animated attribute to doMethod once per frame, then applies the resulting value to the attribute(s). + * @private + */ + + var onTween = function() { + var data = { + duration: new Date() - this.getStartTime(), + currentFrame: this.currentFrame + }; + + data.toString = function() { + return ( + 'duration: ' + data.duration + + ', currentFrame: ' + data.currentFrame + ); + }; + + this.onTween.fire(data); + + var runtimeAttributes = this.runtimeAttributes; + + for (var attr in runtimeAttributes) { + this.setAttribute(attr, this.doMethod(attr, runtimeAttributes[attr].start, runtimeAttributes[attr].end), runtimeAttributes[attr].unit); + } + + actualFrames += 1; + }; + + var onComplete = function() { + var actual_duration = (new Date() - startTime) / 1000 ; + + var data = { + duration: actual_duration, + frames: actualFrames, + fps: actualFrames / actual_duration + }; + + data.toString = function() { + return ( + 'duration: ' + data.duration + + ', frames: ' + data.frames + + ', fps: ' + data.fps + ); + }; + + isAnimated = false; + actualFrames = 0; + this.onComplete.fire(data); + }; + + /** + * Custom event that fires after onStart, useful in subclassing + * @private + */ + this._onStart = new YAHOO.util.CustomEvent('_start', this, true); + + /** + * Custom event that fires when animation begins + * Listen via subscribe method (e.g. myAnim.onStart.subscribe(someFunction) + * @event onStart + */ + this.onStart = new YAHOO.util.CustomEvent('start', this); + + /** + * Custom event that fires between each frame + * Listen via subscribe method (e.g. myAnim.onTween.subscribe(someFunction) + * @event onTween + */ + this.onTween = new YAHOO.util.CustomEvent('tween', this); + + /** + * Custom event that fires after onTween + * @private + */ + this._onTween = new YAHOO.util.CustomEvent('_tween', this, true); + + /** + * Custom event that fires when animation ends + * Listen via subscribe method (e.g. myAnim.onComplete.subscribe(someFunction) + * @event onComplete + */ + this.onComplete = new YAHOO.util.CustomEvent('complete', this); + /** + * Custom event that fires after onComplete + * @private + */ + this._onComplete = new YAHOO.util.CustomEvent('_complete', this, true); + + this._onStart.subscribe(onStart); + this._onTween.subscribe(onTween); + this._onComplete.subscribe(onComplete); + } +}; + +/** + * Handles animation queueing and threading. + * Used by Anim and subclasses. + * @class AnimMgr + * @namespace YAHOO.util + */ +YAHOO.util.AnimMgr = new function() { + /** + * Reference to the animation Interval. + * @property thread + * @private + * @type Int + */ + var thread = null; + + /** + * The current queue of registered animation objects. + * @property queue + * @private + * @type Array + */ + var queue = []; + + /** + * The number of active animations. + * @property tweenCount + * @private + * @type Int + */ + var tweenCount = 0; + + /** + * Base frame rate (frames per second). + * Arbitrarily high for better x-browser calibration (slower browsers drop more frames). + * @property fps + * @type Int + * + */ + this.fps = 1000; + + /** + * Interval delay in milliseconds, defaults to fastest possible. + * @property delay + * @type Int + * + */ + this.delay = 1; + + /** + * Adds an animation instance to the animation queue. + * All animation instances must be registered in order to animate. + * @method registerElement + * @param {object} tween The Anim instance to be be registered + */ + this.registerElement = function(tween) { + queue[queue.length] = tween; + tweenCount += 1; + tween._onStart.fire(); + this.start(); + }; + + /** + * removes an animation instance from the animation queue. + * All animation instances must be registered in order to animate. + * @method unRegister + * @param {object} tween The Anim instance to be be registered + * @param {Int} index The index of the Anim instance + * @private + */ + this.unRegister = function(tween, index) { + tween._onComplete.fire(); + index = index || getIndex(tween); + if (index != -1) { + queue.splice(index, 1); + } + + tweenCount -= 1; + if (tweenCount <= 0) { + this.stop(); + } + }; + + /** + * Starts the animation thread. + * Only one thread can run at a time. + * @method start + */ + this.start = function() { + if (thread === null) { + thread = setInterval(this.run, this.delay); + } + }; + + /** + * Stops the animation thread or a specific animation instance. + * @method stop + * @param {object} tween A specific Anim instance to stop (optional) + * If no instance given, Manager stops thread and all animations. + */ + this.stop = function(tween) { + if (!tween) { + clearInterval(thread); + + for (var i = 0, len = queue.length; i < len; ++i) { + if ( queue[0].isAnimated() ) { + this.unRegister(queue[0], 0); + } + } + + queue = []; + thread = null; + tweenCount = 0; + } + else { + this.unRegister(tween); + } + }; + + /** + * Called per Interval to handle each animation frame. + * @method run + */ + this.run = function() { + for (var i = 0, len = queue.length; i < len; ++i) { + var tween = queue[i]; + if ( !tween || !tween.isAnimated() ) { continue; } + + if (tween.currentFrame < tween.totalFrames || tween.totalFrames === null) + { + tween.currentFrame += 1; + + if (tween.useSeconds) { + correctFrame(tween); + } + tween._onTween.fire(); + } + else { YAHOO.util.AnimMgr.stop(tween, i); } + } + }; + + var getIndex = function(anim) { + for (var i = 0, len = queue.length; i < len; ++i) { + if (queue[i] == anim) { + return i; // note return; + } + } + return -1; + }; + + /** + * On the fly frame correction to keep animation on time. + * @method correctFrame + * @private + * @param {Object} tween The Anim instance being corrected. + */ + var correctFrame = function(tween) { + var frames = tween.totalFrames; + var frame = tween.currentFrame; + var expected = (tween.currentFrame * tween.duration * 1000 / tween.totalFrames); + var elapsed = (new Date() - tween.getStartTime()); + var tweak = 0; + + if (elapsed < tween.duration * 1000) { // check if falling behind + tweak = Math.round((elapsed / expected - 1) * tween.currentFrame); + } else { // went over duration, so jump to end + tweak = frames - (frame + 1); + } + if (tweak > 0 && isFinite(tweak)) { // adjust if needed + if (tween.currentFrame + tweak >= frames) {// dont go past last frame + tweak = frames - (frame + 1); + } + + tween.currentFrame += tweak; + } + }; +}; +/** + * Used to calculate Bezier splines for any number of control points. + * @class Bezier + * @namespace YAHOO.util + * + */ +YAHOO.util.Bezier = new function() { + /** + * Get the current position of the animated element based on t. + * Each point is an array of "x" and "y" values (0 = x, 1 = y) + * At least 2 points are required (start and end). + * First point is start. Last point is end. + * Additional control points are optional. + * @method getPosition + * @param {Array} points An array containing Bezier points + * @param {Number} t A number between 0 and 1 which is the basis for determining current position + * @return {Array} An array containing int x and y member data + */ + this.getPosition = function(points, t) { + var n = points.length; + var tmp = []; + + for (var i = 0; i < n; ++i){ + tmp[i] = [points[i][0], points[i][1]]; // save input + } + + for (var j = 1; j < n; ++j) { + for (i = 0; i < n - j; ++i) { + tmp[i][0] = (1 - t) * tmp[i][0] + t * tmp[parseInt(i + 1, 10)][0]; + tmp[i][1] = (1 - t) * tmp[i][1] + t * tmp[parseInt(i + 1, 10)][1]; + } + } + + return [ tmp[0][0], tmp[0][1] ]; + + }; +}; +(function() { +/** + * Anim subclass for color transitions. + *

Usage: var myAnim = new Y.ColorAnim(el, { backgroundColor: { from: '#FF0000', to: '#FFFFFF' } }, 1, Y.Easing.easeOut); Color values can be specified with either 112233, #112233, + * [255,255,255], or rgb(255,255,255)

+ * @class ColorAnim + * @namespace YAHOO.util + * @requires YAHOO.util.Anim + * @requires YAHOO.util.AnimMgr + * @requires YAHOO.util.Easing + * @requires YAHOO.util.Bezier + * @requires YAHOO.util.Dom + * @requires YAHOO.util.Event + * @constructor + * @extends YAHOO.util.Anim + * @param {HTMLElement | String} el Reference to the element that will be animated + * @param {Object} attributes The attribute(s) to be animated. + * Each attribute is an object with at minimum a "to" or "by" member defined. + * Additional optional members are "from" (defaults to current value), "units" (defaults to "px"). + * All attribute names use camelCase. + * @param {Number} duration (optional, defaults to 1 second) Length of animation (frames or seconds), defaults to time-based + * @param {Function} method (optional, defaults to YAHOO.util.Easing.easeNone) Computes the values that are applied to the attributes per frame (generally a YAHOO.util.Easing method) + */ + YAHOO.util.ColorAnim = function(el, attributes, duration, method) { + YAHOO.util.ColorAnim.superclass.constructor.call(this, el, attributes, duration, method); + }; + + YAHOO.extend(YAHOO.util.ColorAnim, YAHOO.util.Anim); + + // shorthand + var Y = YAHOO.util; + var superclass = Y.ColorAnim.superclass; + var proto = Y.ColorAnim.prototype; + + proto.toString = function() { + var el = this.getEl(); + var id = el.id || el.tagName; + return ("ColorAnim " + id); + }; + + proto.patterns.color = /color$/i; + proto.patterns.rgb = /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i; + proto.patterns.hex = /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i; + proto.patterns.hex3 = /^#?([0-9A-F]{1})([0-9A-F]{1})([0-9A-F]{1})$/i; + proto.patterns.transparent = /^transparent|rgba\(0, 0, 0, 0\)$/; // need rgba for safari + + /** + * Attempts to parse the given string and return a 3-tuple. + * @method parseColor + * @param {String} s The string to parse. + * @return {Array} The 3-tuple of rgb values. + */ + proto.parseColor = function(s) { + if (s.length == 3) { return s; } + + var c = this.patterns.hex.exec(s); + if (c && c.length == 4) { + return [ parseInt(c[1], 16), parseInt(c[2], 16), parseInt(c[3], 16) ]; + } + + c = this.patterns.rgb.exec(s); + if (c && c.length == 4) { + return [ parseInt(c[1], 10), parseInt(c[2], 10), parseInt(c[3], 10) ]; + } + + c = this.patterns.hex3.exec(s); + if (c && c.length == 4) { + return [ parseInt(c[1] + c[1], 16), parseInt(c[2] + c[2], 16), parseInt(c[3] + c[3], 16) ]; + } + + return null; + }; + + proto.getAttribute = function(attr) { + var el = this.getEl(); + if ( this.patterns.color.test(attr) ) { + var val = YAHOO.util.Dom.getStyle(el, attr); + + if (this.patterns.transparent.test(val)) { // bgcolor default + var parent = el.parentNode; // try and get from an ancestor + val = Y.Dom.getStyle(parent, attr); + + while (parent && this.patterns.transparent.test(val)) { + parent = parent.parentNode; + val = Y.Dom.getStyle(parent, attr); + if (parent.tagName.toUpperCase() == 'HTML') { + val = '#fff'; + } + } + } + } else { + val = superclass.getAttribute.call(this, attr); + } + + return val; + }; + + proto.doMethod = function(attr, start, end) { + var val; + + if ( this.patterns.color.test(attr) ) { + val = []; + for (var i = 0, len = start.length; i < len; ++i) { + val[i] = superclass.doMethod.call(this, attr, start[i], end[i]); + } + + val = 'rgb('+Math.floor(val[0])+','+Math.floor(val[1])+','+Math.floor(val[2])+')'; + } + else { + val = superclass.doMethod.call(this, attr, start, end); + } + + return val; + }; + + proto.setRuntimeAttribute = function(attr) { + superclass.setRuntimeAttribute.call(this, attr); + + if ( this.patterns.color.test(attr) ) { + var attributes = this.attributes; + var start = this.parseColor(this.runtimeAttributes[attr].start); + var end = this.parseColor(this.runtimeAttributes[attr].end); + // fix colors if going "by" + if ( typeof attributes[attr]['to'] === 'undefined' && typeof attributes[attr]['by'] !== 'undefined' ) { + end = this.parseColor(attributes[attr].by); + + for (var i = 0, len = start.length; i < len; ++i) { + end[i] = start[i] + end[i]; + } + } + + this.runtimeAttributes[attr].start = start; + this.runtimeAttributes[attr].end = end; + } + }; +})(); +/* +TERMS OF USE - EASING EQUATIONS +Open source under the BSD License. +Copyright 2001 Robert Penner All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + * Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/** + * Singleton that determines how an animation proceeds from start to end. + * @class Easing + * @namespace YAHOO.util +*/ + +YAHOO.util.Easing = { + + /** + * Uniform speed between points. + * @method easeNone + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @return {Number} The computed value for the current animation frame + */ + easeNone: function (t, b, c, d) { + return c*t/d + b; + }, + + /** + * Begins slowly and accelerates towards end. (quadratic) + * @method easeIn + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @return {Number} The computed value for the current animation frame + */ + easeIn: function (t, b, c, d) { + return c*(t/=d)*t + b; + }, + + /** + * Begins quickly and decelerates towards end. (quadratic) + * @method easeOut + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @return {Number} The computed value for the current animation frame + */ + easeOut: function (t, b, c, d) { + return -c *(t/=d)*(t-2) + b; + }, + + /** + * Begins slowly and decelerates towards end. (quadratic) + * @method easeBoth + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @return {Number} The computed value for the current animation frame + */ + easeBoth: function (t, b, c, d) { + if ((t/=d/2) < 1) { + return c/2*t*t + b; + } + + return -c/2 * ((--t)*(t-2) - 1) + b; + }, + + /** + * Begins slowly and accelerates towards end. (quartic) + * @method easeInStrong + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @return {Number} The computed value for the current animation frame + */ + easeInStrong: function (t, b, c, d) { + return c*(t/=d)*t*t*t + b; + }, + + /** + * Begins quickly and decelerates towards end. (quartic) + * @method easeOutStrong + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @return {Number} The computed value for the current animation frame + */ + easeOutStrong: function (t, b, c, d) { + return -c * ((t=t/d-1)*t*t*t - 1) + b; + }, + + /** + * Begins slowly and decelerates towards end. (quartic) + * @method easeBothStrong + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @return {Number} The computed value for the current animation frame + */ + easeBothStrong: function (t, b, c, d) { + if ((t/=d/2) < 1) { + return c/2*t*t*t*t + b; + } + + return -c/2 * ((t-=2)*t*t*t - 2) + b; + }, + + /** + * Snap in elastic effect. + * @method elasticIn + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @param {Number} a Amplitude (optional) + * @param {Number} p Period (optional) + * @return {Number} The computed value for the current animation frame + */ + + elasticIn: function (t, b, c, d, a, p) { + if (t == 0) { + return b; + } + if ( (t /= d) == 1 ) { + return b+c; + } + if (!p) { + p=d*.3; + } + + if (!a || a < Math.abs(c)) { + a = c; + var s = p/4; + } + else { + var s = p/(2*Math.PI) * Math.asin (c/a); + } + + return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; + }, + + /** + * Snap out elastic effect. + * @method elasticOut + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @param {Number} a Amplitude (optional) + * @param {Number} p Period (optional) + * @return {Number} The computed value for the current animation frame + */ + elasticOut: function (t, b, c, d, a, p) { + if (t == 0) { + return b; + } + if ( (t /= d) == 1 ) { + return b+c; + } + if (!p) { + p=d*.3; + } + + if (!a || a < Math.abs(c)) { + a = c; + var s = p / 4; + } + else { + var s = p/(2*Math.PI) * Math.asin (c/a); + } + + return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b; + }, + + /** + * Snap both elastic effect. + * @method elasticBoth + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @param {Number} a Amplitude (optional) + * @param {Number} p Period (optional) + * @return {Number} The computed value for the current animation frame + */ + elasticBoth: function (t, b, c, d, a, p) { + if (t == 0) { + return b; + } + + if ( (t /= d/2) == 2 ) { + return b+c; + } + + if (!p) { + p = d*(.3*1.5); + } + + if ( !a || a < Math.abs(c) ) { + a = c; + var s = p/4; + } + else { + var s = p/(2*Math.PI) * Math.asin (c/a); + } + + if (t < 1) { + return -.5*(a*Math.pow(2,10*(t-=1)) * + Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; + } + return a*Math.pow(2,-10*(t-=1)) * + Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b; + }, + + + /** + * Backtracks slightly, then reverses direction and moves to end. + * @method backIn + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @param {Number} s Overshoot (optional) + * @return {Number} The computed value for the current animation frame + */ + backIn: function (t, b, c, d, s) { + if (typeof s == 'undefined') { + s = 1.70158; + } + return c*(t/=d)*t*((s+1)*t - s) + b; + }, + + /** + * Overshoots end, then reverses and comes back to end. + * @method backOut + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @param {Number} s Overshoot (optional) + * @return {Number} The computed value for the current animation frame + */ + backOut: function (t, b, c, d, s) { + if (typeof s == 'undefined') { + s = 1.70158; + } + return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b; + }, + + /** + * Backtracks slightly, then reverses direction, overshoots end, + * then reverses and comes back to end. + * @method backBoth + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @param {Number} s Overshoot (optional) + * @return {Number} The computed value for the current animation frame + */ + backBoth: function (t, b, c, d, s) { + if (typeof s == 'undefined') { + s = 1.70158; + } + + if ((t /= d/2 ) < 1) { + return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; + } + return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; + }, + + /** + * Bounce off of start. + * @method bounceIn + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @return {Number} The computed value for the current animation frame + */ + bounceIn: function (t, b, c, d) { + return c - YAHOO.util.Easing.bounceOut(d-t, 0, c, d) + b; + }, + + /** + * Bounces off end. + * @method bounceOut + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @return {Number} The computed value for the current animation frame + */ + bounceOut: function (t, b, c, d) { + if ((t/=d) < (1/2.75)) { + return c*(7.5625*t*t) + b; + } else if (t < (2/2.75)) { + return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b; + } else if (t < (2.5/2.75)) { + return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b; + } + return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b; + }, + + /** + * Bounces off start and end. + * @method bounceBoth + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @return {Number} The computed value for the current animation frame + */ + bounceBoth: function (t, b, c, d) { + if (t < d/2) { + return YAHOO.util.Easing.bounceIn(t*2, 0, c, d) * .5 + b; + } + return YAHOO.util.Easing.bounceOut(t*2-d, 0, c, d) * .5 + c*.5 + b; + } +}; + +(function() { +/** + * Anim subclass for moving elements along a path defined by the "points" + * member of "attributes". All "points" are arrays with x, y coordinates. + *

Usage: var myAnim = new YAHOO.util.Motion(el, { points: { to: [800, 800] } }, 1, YAHOO.util.Easing.easeOut);

+ * @class Motion + * @namespace YAHOO.util + * @requires YAHOO.util.Anim + * @requires YAHOO.util.AnimMgr + * @requires YAHOO.util.Easing + * @requires YAHOO.util.Bezier + * @requires YAHOO.util.Dom + * @requires YAHOO.util.Event + * @requires YAHOO.util.CustomEvent + * @constructor + * @extends YAHOO.util.Anim + * @param {String | HTMLElement} el Reference to the element that will be animated + * @param {Object} attributes The attribute(s) to be animated. + * Each attribute is an object with at minimum a "to" or "by" member defined. + * Additional optional members are "from" (defaults to current value), "units" (defaults to "px"). + * All attribute names use camelCase. + * @param {Number} duration (optional, defaults to 1 second) Length of animation (frames or seconds), defaults to time-based + * @param {Function} method (optional, defaults to YAHOO.util.Easing.easeNone) Computes the values that are applied to the attributes per frame (generally a YAHOO.util.Easing method) + */ + YAHOO.util.Motion = function(el, attributes, duration, method) { + if (el) { // dont break existing subclasses not using YAHOO.extend + YAHOO.util.Motion.superclass.constructor.call(this, el, attributes, duration, method); + } + }; + + YAHOO.extend(YAHOO.util.Motion, YAHOO.util.ColorAnim); + + // shorthand + var Y = YAHOO.util; + var superclass = Y.Motion.superclass; + var proto = Y.Motion.prototype; + + proto.toString = function() { + var el = this.getEl(); + var id = el.id || el.tagName; + return ("Motion " + id); + }; + + proto.patterns.points = /^points$/i; + + proto.setAttribute = function(attr, val, unit) { + if ( this.patterns.points.test(attr) ) { + unit = unit || 'px'; + superclass.setAttribute.call(this, 'left', val[0], unit); + superclass.setAttribute.call(this, 'top', val[1], unit); + } else { + superclass.setAttribute.call(this, attr, val, unit); + } + }; + + proto.getAttribute = function(attr) { + if ( this.patterns.points.test(attr) ) { + var val = [ + superclass.getAttribute.call(this, 'left'), + superclass.getAttribute.call(this, 'top') + ]; + } else { + val = superclass.getAttribute.call(this, attr); + } + + return val; + }; + + proto.doMethod = function(attr, start, end) { + var val = null; + + if ( this.patterns.points.test(attr) ) { + var t = this.method(this.currentFrame, 0, 100, this.totalFrames) / 100; + val = Y.Bezier.getPosition(this.runtimeAttributes[attr], t); + } else { + val = superclass.doMethod.call(this, attr, start, end); + } + return val; + }; + + proto.setRuntimeAttribute = function(attr) { + if ( this.patterns.points.test(attr) ) { + var el = this.getEl(); + var attributes = this.attributes; + var start; + var control = attributes['points']['control'] || []; + var end; + var i, len; + + if (control.length > 0 && !(control[0] instanceof Array) ) { // could be single point or array of points + control = [control]; + } else { // break reference to attributes.points.control + var tmp = []; + for (i = 0, len = control.length; i< len; ++i) { + tmp[i] = control[i]; + } + control = tmp; + } + + if (Y.Dom.getStyle(el, 'position') == 'static') { // default to relative + Y.Dom.setStyle(el, 'position', 'relative'); + } + + if ( isset(attributes['points']['from']) ) { + Y.Dom.setXY(el, attributes['points']['from']); // set position to from point + } + else { Y.Dom.setXY( el, Y.Dom.getXY(el) ); } // set it to current position + + start = this.getAttribute('points'); // get actual top & left + + // TO beats BY, per SMIL 2.1 spec + if ( isset(attributes['points']['to']) ) { + end = translateValues.call(this, attributes['points']['to'], start); + + var pageXY = Y.Dom.getXY(this.getEl()); + for (i = 0, len = control.length; i < len; ++i) { + control[i] = translateValues.call(this, control[i], start); + } + + + } else if ( isset(attributes['points']['by']) ) { + end = [ start[0] + attributes['points']['by'][0], start[1] + attributes['points']['by'][1] ]; + + for (i = 0, len = control.length; i < len; ++i) { + control[i] = [ start[0] + control[i][0], start[1] + control[i][1] ]; + } + } + + this.runtimeAttributes[attr] = [start]; + + if (control.length > 0) { + this.runtimeAttributes[attr] = this.runtimeAttributes[attr].concat(control); + } + + this.runtimeAttributes[attr][this.runtimeAttributes[attr].length] = end; + } + else { + superclass.setRuntimeAttribute.call(this, attr); + } + }; + + var translateValues = function(val, start) { + var pageXY = Y.Dom.getXY(this.getEl()); + val = [ val[0] - pageXY[0] + start[0], val[1] - pageXY[1] + start[1] ]; + + return val; + }; + + var isset = function(prop) { + return (typeof prop !== 'undefined'); + }; +})(); +(function() { +/** + * Anim subclass for scrolling elements to a position defined by the "scroll" + * member of "attributes". All "scroll" members are arrays with x, y scroll positions. + *

Usage: var myAnim = new YAHOO.util.Scroll(el, { scroll: { to: [0, 800] } }, 1, YAHOO.util.Easing.easeOut);

+ * @class Scroll + * @namespace YAHOO.util + * @requires YAHOO.util.Anim + * @requires YAHOO.util.AnimMgr + * @requires YAHOO.util.Easing + * @requires YAHOO.util.Bezier + * @requires YAHOO.util.Dom + * @requires YAHOO.util.Event + * @requires YAHOO.util.CustomEvent + * @extends YAHOO.util.Anim + * @constructor + * @param {String or HTMLElement} el Reference to the element that will be animated + * @param {Object} attributes The attribute(s) to be animated. + * Each attribute is an object with at minimum a "to" or "by" member defined. + * Additional optional members are "from" (defaults to current value), "units" (defaults to "px"). + * All attribute names use camelCase. + * @param {Number} duration (optional, defaults to 1 second) Length of animation (frames or seconds), defaults to time-based + * @param {Function} method (optional, defaults to YAHOO.util.Easing.easeNone) Computes the values that are applied to the attributes per frame (generally a YAHOO.util.Easing method) + */ + YAHOO.util.Scroll = function(el, attributes, duration, method) { + if (el) { // dont break existing subclasses not using YAHOO.extend + YAHOO.util.Scroll.superclass.constructor.call(this, el, attributes, duration, method); + } + }; + + YAHOO.extend(YAHOO.util.Scroll, YAHOO.util.ColorAnim); + + // shorthand + var Y = YAHOO.util; + var superclass = Y.Scroll.superclass; + var proto = Y.Scroll.prototype; + + proto.toString = function() { + var el = this.getEl(); + var id = el.id || el.tagName; + return ("Scroll " + id); + }; + + proto.doMethod = function(attr, start, end) { + var val = null; + + if (attr == 'scroll') { + val = [ + this.method(this.currentFrame, start[0], end[0] - start[0], this.totalFrames), + this.method(this.currentFrame, start[1], end[1] - start[1], this.totalFrames) + ]; + + } else { + val = superclass.doMethod.call(this, attr, start, end); + } + return val; + }; + + proto.getAttribute = function(attr) { + var val = null; + var el = this.getEl(); + + if (attr == 'scroll') { + val = [ el.scrollLeft, el.scrollTop ]; + } else { + val = superclass.getAttribute.call(this, attr); + } + + return val; + }; + + proto.setAttribute = function(attr, val, unit) { + var el = this.getEl(); + + if (attr == 'scroll') { + el.scrollLeft = val[0]; + el.scrollTop = val[1]; + } else { + superclass.setAttribute.call(this, attr, val, unit); + } + }; +})(); +YAHOO.register("animation", YAHOO.util.Anim, {version: "2.2.0", build: "127"}); diff --git a/interface/web/js/yui/animation/animation-min.js b/interface/web/js/yui/animation/animation-min.js new file mode 100644 index 000000000..94ae5582a --- /dev/null +++ b/interface/web/js/yui/animation/animation-min.js @@ -0,0 +1,75 @@ +/* +Copyright (c) 2007, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.net/yui/license.txt +version: 2.2.0 +*/ + +YAHOO.util.Anim=function(el,attributes,duration,method){if(el){this.init(el,attributes,duration,method);}};YAHOO.util.Anim.prototype={toString:function(){var el=this.getEl();var id=el.id||el.tagName;return("Anim "+id);},patterns:{noNegatives:/width|height|opacity|padding/i,offsetAttribute:/^((width|height)|(top|left))$/,defaultUnit:/width|height|top$|bottom$|left$|right$/i,offsetUnit:/\d+(em|%|en|ex|pt|in|cm|mm|pc)$/i},doMethod:function(attr,start,end){return this.method(this.currentFrame,start,end-start,this.totalFrames);},setAttribute:function(attr,val,unit){if(this.patterns.noNegatives.test(attr)){val=(val>0)?val:0;} +YAHOO.util.Dom.setStyle(this.getEl(),attr,val+unit);},getAttribute:function(attr){var el=this.getEl();var val=YAHOO.util.Dom.getStyle(el,attr);if(val!=='auto'&&!this.patterns.offsetUnit.test(val)){return parseFloat(val);} +var a=this.patterns.offsetAttribute.exec(attr)||[];var pos=!!(a[3]);var box=!!(a[2]);if(box||(YAHOO.util.Dom.getStyle(el,'position')=='absolute'&&pos)){val=el['offset'+a[0].charAt(0).toUpperCase()+a[0].substr(1)];}else{val=0;} +return val;},getDefaultUnit:function(attr){if(this.patterns.defaultUnit.test(attr)){return'px';} +return'';},setRuntimeAttribute:function(attr){var start;var end;var attributes=this.attributes;this.runtimeAttributes[attr]={};var isset=function(prop){return(typeof prop!=='undefined');};if(!isset(attributes[attr]['to'])&&!isset(attributes[attr]['by'])){return false;} +start=(isset(attributes[attr]['from']))?attributes[attr]['from']:this.getAttribute(attr);if(isset(attributes[attr]['to'])){end=attributes[attr]['to'];}else if(isset(attributes[attr]['by'])){if(start.constructor==Array){end=[];for(var i=0,len=start.length;i0&&isFinite(tweak)){if(tween.currentFrame+tweak>=frames){tweak=frames-(frame+1);} +tween.currentFrame+=tweak;}};};YAHOO.util.Bezier=new function(){this.getPosition=function(points,t){var n=points.length;var tmp=[];for(var i=0;i0&&!(control[0]instanceof Array)){control=[control];}else{var tmp=[];for(i=0,len=control.length;i0){this.runtimeAttributes[attr]=this.runtimeAttributes[attr].concat(control);} +this.runtimeAttributes[attr][this.runtimeAttributes[attr].length]=end;} +else{superclass.setRuntimeAttribute.call(this,attr);}};var translateValues=function(val,start){var pageXY=Y.Dom.getXY(this.getEl());val=[val[0]-pageXY[0]+start[0],val[1]-pageXY[1]+start[1]];return val;};var isset=function(prop){return(typeof prop!=='undefined');};})();(function(){YAHOO.util.Scroll=function(el,attributes,duration,method){if(el){YAHOO.util.Scroll.superclass.constructor.call(this,el,attributes,duration,method);}};YAHOO.extend(YAHOO.util.Scroll,YAHOO.util.ColorAnim);var Y=YAHOO.util;var superclass=Y.Scroll.superclass;var proto=Y.Scroll.prototype;proto.toString=function(){var el=this.getEl();var id=el.id||el.tagName;return("Scroll "+id);};proto.doMethod=function(attr,start,end){var val=null;if(attr=='scroll'){val=[this.method(this.currentFrame,start[0],end[0]-start[0],this.totalFrames),this.method(this.currentFrame,start[1],end[1]-start[1],this.totalFrames)];}else{val=superclass.doMethod.call(this,attr,start,end);} +return val;};proto.getAttribute=function(attr){var val=null;var el=this.getEl();if(attr=='scroll'){val=[el.scrollLeft,el.scrollTop];}else{val=superclass.getAttribute.call(this,attr);} +return val;};proto.setAttribute=function(attr,val,unit){var el=this.getEl();if(attr=='scroll'){el.scrollLeft=val[0];el.scrollTop=val[1];}else{superclass.setAttribute.call(this,attr,val,unit);}};})();YAHOO.register("animation",YAHOO.util.Anim,{version:"2.2.0",build:"127"}); \ No newline at end of file diff --git a/interface/web/js/yui/animation/animation.js b/interface/web/js/yui/animation/animation.js new file mode 100644 index 000000000..319b618d9 --- /dev/null +++ b/interface/web/js/yui/animation/animation.js @@ -0,0 +1,1358 @@ +/* +Copyright (c) 2007, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.net/yui/license.txt +version: 2.2.0 +*/ +/* +Copyright (c) 2006, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.net/yui/license.txt +*/ + +/** + * The animation module provides allows effects to be added to HTMLElements. + * @module animation + * @requires yahoo, event, dom + */ + +/** + * + * Base animation class that provides the interface for building animated effects. + *

Usage: var myAnim = new YAHOO.util.Anim(el, { width: { from: 10, to: 100 } }, 1, YAHOO.util.Easing.easeOut);

+ * @class Anim + * @namespace YAHOO.util + * @requires YAHOO.util.AnimMgr + * @requires YAHOO.util.Easing + * @requires YAHOO.util.Dom + * @requires YAHOO.util.Event + * @requires YAHOO.util.CustomEvent + * @constructor + * @param {String | HTMLElement} el Reference to the element that will be animated + * @param {Object} attributes The attribute(s) to be animated. + * Each attribute is an object with at minimum a "to" or "by" member defined. + * Additional optional members are "from" (defaults to current value), "units" (defaults to "px"). + * All attribute names use camelCase. + * @param {Number} duration (optional, defaults to 1 second) Length of animation (frames or seconds), defaults to time-based + * @param {Function} method (optional, defaults to YAHOO.util.Easing.easeNone) Computes the values that are applied to the attributes per frame (generally a YAHOO.util.Easing method) + */ + +YAHOO.util.Anim = function(el, attributes, duration, method) { + if (el) { + this.init(el, attributes, duration, method); + } +}; + +YAHOO.util.Anim.prototype = { + /** + * Provides a readable name for the Anim instance. + * @method toString + * @return {String} + */ + toString: function() { + var el = this.getEl(); + var id = el.id || el.tagName; + return ("Anim " + id); + }, + + patterns: { // cached for performance + noNegatives: /width|height|opacity|padding/i, // keep at zero or above + offsetAttribute: /^((width|height)|(top|left))$/, // use offsetValue as default + defaultUnit: /width|height|top$|bottom$|left$|right$/i, // use 'px' by default + offsetUnit: /\d+(em|%|en|ex|pt|in|cm|mm|pc)$/i // IE may return these, so convert these to offset + }, + + /** + * Returns the value computed by the animation's "method". + * @method doMethod + * @param {String} attr The name of the attribute. + * @param {Number} start The value this attribute should start from for this animation. + * @param {Number} end The value this attribute should end at for this animation. + * @return {Number} The Value to be applied to the attribute. + */ + doMethod: function(attr, start, end) { + return this.method(this.currentFrame, start, end - start, this.totalFrames); + }, + + /** + * Applies a value to an attribute. + * @method setAttribute + * @param {String} attr The name of the attribute. + * @param {Number} val The value to be applied to the attribute. + * @param {String} unit The unit ('px', '%', etc.) of the value. + */ + setAttribute: function(attr, val, unit) { + if ( this.patterns.noNegatives.test(attr) ) { + val = (val > 0) ? val : 0; + } + + YAHOO.util.Dom.setStyle(this.getEl(), attr, val + unit); + }, + + /** + * Returns current value of the attribute. + * @method getAttribute + * @param {String} attr The name of the attribute. + * @return {Number} val The current value of the attribute. + */ + getAttribute: function(attr) { + var el = this.getEl(); + var val = YAHOO.util.Dom.getStyle(el, attr); + + if (val !== 'auto' && !this.patterns.offsetUnit.test(val)) { + return parseFloat(val); + } + + var a = this.patterns.offsetAttribute.exec(attr) || []; + var pos = !!( a[3] ); // top or left + var box = !!( a[2] ); // width or height + + // use offsets for width/height and abs pos top/left + if ( box || (YAHOO.util.Dom.getStyle(el, 'position') == 'absolute' && pos) ) { + val = el['offset' + a[0].charAt(0).toUpperCase() + a[0].substr(1)]; + } else { // default to zero for other 'auto' + val = 0; + } + + return val; + }, + + /** + * Returns the unit to use when none is supplied. + * @method getDefaultUnit + * @param {attr} attr The name of the attribute. + * @return {String} The default unit to be used. + */ + getDefaultUnit: function(attr) { + if ( this.patterns.defaultUnit.test(attr) ) { + return 'px'; + } + + return ''; + }, + + /** + * Sets the actual values to be used during the animation. Should only be needed for subclass use. + * @method setRuntimeAttribute + * @param {Object} attr The attribute object + * @private + */ + setRuntimeAttribute: function(attr) { + var start; + var end; + var attributes = this.attributes; + + this.runtimeAttributes[attr] = {}; + + var isset = function(prop) { + return (typeof prop !== 'undefined'); + }; + + if ( !isset(attributes[attr]['to']) && !isset(attributes[attr]['by']) ) { + return false; // note return; nothing to animate to + } + + start = ( isset(attributes[attr]['from']) ) ? attributes[attr]['from'] : this.getAttribute(attr); + + // To beats by, per SMIL 2.1 spec + if ( isset(attributes[attr]['to']) ) { + end = attributes[attr]['to']; + } else if ( isset(attributes[attr]['by']) ) { + if (start.constructor == Array) { + end = []; + for (var i = 0, len = start.length; i < len; ++i) { + end[i] = start[i] + attributes[attr]['by'][i]; + } + } else { + end = start + attributes[attr]['by']; + } + } + + this.runtimeAttributes[attr].start = start; + this.runtimeAttributes[attr].end = end; + + // set units if needed + this.runtimeAttributes[attr].unit = ( isset(attributes[attr].unit) ) ? attributes[attr]['unit'] : this.getDefaultUnit(attr); + }, + + /** + * Constructor for Anim instance. + * @method init + * @param {String | HTMLElement} el Reference to the element that will be animated + * @param {Object} attributes The attribute(s) to be animated. + * Each attribute is an object with at minimum a "to" or "by" member defined. + * Additional optional members are "from" (defaults to current value), "units" (defaults to "px"). + * All attribute names use camelCase. + * @param {Number} duration (optional, defaults to 1 second) Length of animation (frames or seconds), defaults to time-based + * @param {Function} method (optional, defaults to YAHOO.util.Easing.easeNone) Computes the values that are applied to the attributes per frame (generally a YAHOO.util.Easing method) + */ + init: function(el, attributes, duration, method) { + /** + * Whether or not the animation is running. + * @property isAnimated + * @private + * @type Boolean + */ + var isAnimated = false; + + /** + * A Date object that is created when the animation begins. + * @property startTime + * @private + * @type Date + */ + var startTime = null; + + /** + * The number of frames this animation was able to execute. + * @property actualFrames + * @private + * @type Int + */ + var actualFrames = 0; + + /** + * The element to be animated. + * @property el + * @private + * @type HTMLElement + */ + el = YAHOO.util.Dom.get(el); + + /** + * The collection of attributes to be animated. + * Each attribute must have at least a "to" or "by" defined in order to animate. + * If "to" is supplied, the animation will end with the attribute at that value. + * If "by" is supplied, the animation will end at that value plus its starting value. + * If both are supplied, "to" is used, and "by" is ignored. + * Optional additional member include "from" (the value the attribute should start animating from, defaults to current value), and "unit" (the units to apply to the values). + * @property attributes + * @type Object + */ + this.attributes = attributes || {}; + + /** + * The length of the animation. Defaults to "1" (second). + * @property duration + * @type Number + */ + this.duration = duration || 1; + + /** + * The method that will provide values to the attribute(s) during the animation. + * Defaults to "YAHOO.util.Easing.easeNone". + * @property method + * @type Function + */ + this.method = method || YAHOO.util.Easing.easeNone; + + /** + * Whether or not the duration should be treated as seconds. + * Defaults to true. + * @property useSeconds + * @type Boolean + */ + this.useSeconds = true; // default to seconds + + /** + * The location of the current animation on the timeline. + * In time-based animations, this is used by AnimMgr to ensure the animation finishes on time. + * @property currentFrame + * @type Int + */ + this.currentFrame = 0; + + /** + * The total number of frames to be executed. + * In time-based animations, this is used by AnimMgr to ensure the animation finishes on time. + * @property totalFrames + * @type Int + */ + this.totalFrames = YAHOO.util.AnimMgr.fps; + + + /** + * Returns a reference to the animated element. + * @method getEl + * @return {HTMLElement} + */ + this.getEl = function() { return el; }; + + /** + * Checks whether the element is currently animated. + * @method isAnimated + * @return {Boolean} current value of isAnimated. + */ + this.isAnimated = function() { + return isAnimated; + }; + + /** + * Returns the animation start time. + * @method getStartTime + * @return {Date} current value of startTime. + */ + this.getStartTime = function() { + return startTime; + }; + + this.runtimeAttributes = {}; + + + + /** + * Starts the animation by registering it with the animation manager. + * @method animate + */ + this.animate = function() { + if ( this.isAnimated() ) { + return false; + } + + this.currentFrame = 0; + + this.totalFrames = ( this.useSeconds ) ? Math.ceil(YAHOO.util.AnimMgr.fps * this.duration) : this.duration; + + YAHOO.util.AnimMgr.registerElement(this); + }; + + /** + * Stops the animation. Normally called by AnimMgr when animation completes. + * @method stop + * @param {Boolean} finish (optional) If true, animation will jump to final frame. + */ + this.stop = function(finish) { + if (finish) { + this.currentFrame = this.totalFrames; + this._onTween.fire(); + } + YAHOO.util.AnimMgr.stop(this); + }; + + var onStart = function() { + this.onStart.fire(); + + this.runtimeAttributes = {}; + for (var attr in this.attributes) { + this.setRuntimeAttribute(attr); + } + + isAnimated = true; + actualFrames = 0; + startTime = new Date(); + }; + + /** + * Feeds the starting and ending values for each animated attribute to doMethod once per frame, then applies the resulting value to the attribute(s). + * @private + */ + + var onTween = function() { + var data = { + duration: new Date() - this.getStartTime(), + currentFrame: this.currentFrame + }; + + data.toString = function() { + return ( + 'duration: ' + data.duration + + ', currentFrame: ' + data.currentFrame + ); + }; + + this.onTween.fire(data); + + var runtimeAttributes = this.runtimeAttributes; + + for (var attr in runtimeAttributes) { + this.setAttribute(attr, this.doMethod(attr, runtimeAttributes[attr].start, runtimeAttributes[attr].end), runtimeAttributes[attr].unit); + } + + actualFrames += 1; + }; + + var onComplete = function() { + var actual_duration = (new Date() - startTime) / 1000 ; + + var data = { + duration: actual_duration, + frames: actualFrames, + fps: actualFrames / actual_duration + }; + + data.toString = function() { + return ( + 'duration: ' + data.duration + + ', frames: ' + data.frames + + ', fps: ' + data.fps + ); + }; + + isAnimated = false; + actualFrames = 0; + this.onComplete.fire(data); + }; + + /** + * Custom event that fires after onStart, useful in subclassing + * @private + */ + this._onStart = new YAHOO.util.CustomEvent('_start', this, true); + + /** + * Custom event that fires when animation begins + * Listen via subscribe method (e.g. myAnim.onStart.subscribe(someFunction) + * @event onStart + */ + this.onStart = new YAHOO.util.CustomEvent('start', this); + + /** + * Custom event that fires between each frame + * Listen via subscribe method (e.g. myAnim.onTween.subscribe(someFunction) + * @event onTween + */ + this.onTween = new YAHOO.util.CustomEvent('tween', this); + + /** + * Custom event that fires after onTween + * @private + */ + this._onTween = new YAHOO.util.CustomEvent('_tween', this, true); + + /** + * Custom event that fires when animation ends + * Listen via subscribe method (e.g. myAnim.onComplete.subscribe(someFunction) + * @event onComplete + */ + this.onComplete = new YAHOO.util.CustomEvent('complete', this); + /** + * Custom event that fires after onComplete + * @private + */ + this._onComplete = new YAHOO.util.CustomEvent('_complete', this, true); + + this._onStart.subscribe(onStart); + this._onTween.subscribe(onTween); + this._onComplete.subscribe(onComplete); + } +}; + +/** + * Handles animation queueing and threading. + * Used by Anim and subclasses. + * @class AnimMgr + * @namespace YAHOO.util + */ +YAHOO.util.AnimMgr = new function() { + /** + * Reference to the animation Interval. + * @property thread + * @private + * @type Int + */ + var thread = null; + + /** + * The current queue of registered animation objects. + * @property queue + * @private + * @type Array + */ + var queue = []; + + /** + * The number of active animations. + * @property tweenCount + * @private + * @type Int + */ + var tweenCount = 0; + + /** + * Base frame rate (frames per second). + * Arbitrarily high for better x-browser calibration (slower browsers drop more frames). + * @property fps + * @type Int + * + */ + this.fps = 1000; + + /** + * Interval delay in milliseconds, defaults to fastest possible. + * @property delay + * @type Int + * + */ + this.delay = 1; + + /** + * Adds an animation instance to the animation queue. + * All animation instances must be registered in order to animate. + * @method registerElement + * @param {object} tween The Anim instance to be be registered + */ + this.registerElement = function(tween) { + queue[queue.length] = tween; + tweenCount += 1; + tween._onStart.fire(); + this.start(); + }; + + /** + * removes an animation instance from the animation queue. + * All animation instances must be registered in order to animate. + * @method unRegister + * @param {object} tween The Anim instance to be be registered + * @param {Int} index The index of the Anim instance + * @private + */ + this.unRegister = function(tween, index) { + tween._onComplete.fire(); + index = index || getIndex(tween); + if (index != -1) { + queue.splice(index, 1); + } + + tweenCount -= 1; + if (tweenCount <= 0) { + this.stop(); + } + }; + + /** + * Starts the animation thread. + * Only one thread can run at a time. + * @method start + */ + this.start = function() { + if (thread === null) { + thread = setInterval(this.run, this.delay); + } + }; + + /** + * Stops the animation thread or a specific animation instance. + * @method stop + * @param {object} tween A specific Anim instance to stop (optional) + * If no instance given, Manager stops thread and all animations. + */ + this.stop = function(tween) { + if (!tween) { + clearInterval(thread); + + for (var i = 0, len = queue.length; i < len; ++i) { + if ( queue[0].isAnimated() ) { + this.unRegister(queue[0], 0); + } + } + + queue = []; + thread = null; + tweenCount = 0; + } + else { + this.unRegister(tween); + } + }; + + /** + * Called per Interval to handle each animation frame. + * @method run + */ + this.run = function() { + for (var i = 0, len = queue.length; i < len; ++i) { + var tween = queue[i]; + if ( !tween || !tween.isAnimated() ) { continue; } + + if (tween.currentFrame < tween.totalFrames || tween.totalFrames === null) + { + tween.currentFrame += 1; + + if (tween.useSeconds) { + correctFrame(tween); + } + tween._onTween.fire(); + } + else { YAHOO.util.AnimMgr.stop(tween, i); } + } + }; + + var getIndex = function(anim) { + for (var i = 0, len = queue.length; i < len; ++i) { + if (queue[i] == anim) { + return i; // note return; + } + } + return -1; + }; + + /** + * On the fly frame correction to keep animation on time. + * @method correctFrame + * @private + * @param {Object} tween The Anim instance being corrected. + */ + var correctFrame = function(tween) { + var frames = tween.totalFrames; + var frame = tween.currentFrame; + var expected = (tween.currentFrame * tween.duration * 1000 / tween.totalFrames); + var elapsed = (new Date() - tween.getStartTime()); + var tweak = 0; + + if (elapsed < tween.duration * 1000) { // check if falling behind + tweak = Math.round((elapsed / expected - 1) * tween.currentFrame); + } else { // went over duration, so jump to end + tweak = frames - (frame + 1); + } + if (tweak > 0 && isFinite(tweak)) { // adjust if needed + if (tween.currentFrame + tweak >= frames) {// dont go past last frame + tweak = frames - (frame + 1); + } + + tween.currentFrame += tweak; + } + }; +}; +/** + * Used to calculate Bezier splines for any number of control points. + * @class Bezier + * @namespace YAHOO.util + * + */ +YAHOO.util.Bezier = new function() { + /** + * Get the current position of the animated element based on t. + * Each point is an array of "x" and "y" values (0 = x, 1 = y) + * At least 2 points are required (start and end). + * First point is start. Last point is end. + * Additional control points are optional. + * @method getPosition + * @param {Array} points An array containing Bezier points + * @param {Number} t A number between 0 and 1 which is the basis for determining current position + * @return {Array} An array containing int x and y member data + */ + this.getPosition = function(points, t) { + var n = points.length; + var tmp = []; + + for (var i = 0; i < n; ++i){ + tmp[i] = [points[i][0], points[i][1]]; // save input + } + + for (var j = 1; j < n; ++j) { + for (i = 0; i < n - j; ++i) { + tmp[i][0] = (1 - t) * tmp[i][0] + t * tmp[parseInt(i + 1, 10)][0]; + tmp[i][1] = (1 - t) * tmp[i][1] + t * tmp[parseInt(i + 1, 10)][1]; + } + } + + return [ tmp[0][0], tmp[0][1] ]; + + }; +}; +(function() { +/** + * Anim subclass for color transitions. + *

Usage: var myAnim = new Y.ColorAnim(el, { backgroundColor: { from: '#FF0000', to: '#FFFFFF' } }, 1, Y.Easing.easeOut); Color values can be specified with either 112233, #112233, + * [255,255,255], or rgb(255,255,255)

+ * @class ColorAnim + * @namespace YAHOO.util + * @requires YAHOO.util.Anim + * @requires YAHOO.util.AnimMgr + * @requires YAHOO.util.Easing + * @requires YAHOO.util.Bezier + * @requires YAHOO.util.Dom + * @requires YAHOO.util.Event + * @constructor + * @extends YAHOO.util.Anim + * @param {HTMLElement | String} el Reference to the element that will be animated + * @param {Object} attributes The attribute(s) to be animated. + * Each attribute is an object with at minimum a "to" or "by" member defined. + * Additional optional members are "from" (defaults to current value), "units" (defaults to "px"). + * All attribute names use camelCase. + * @param {Number} duration (optional, defaults to 1 second) Length of animation (frames or seconds), defaults to time-based + * @param {Function} method (optional, defaults to YAHOO.util.Easing.easeNone) Computes the values that are applied to the attributes per frame (generally a YAHOO.util.Easing method) + */ + YAHOO.util.ColorAnim = function(el, attributes, duration, method) { + YAHOO.util.ColorAnim.superclass.constructor.call(this, el, attributes, duration, method); + }; + + YAHOO.extend(YAHOO.util.ColorAnim, YAHOO.util.Anim); + + // shorthand + var Y = YAHOO.util; + var superclass = Y.ColorAnim.superclass; + var proto = Y.ColorAnim.prototype; + + proto.toString = function() { + var el = this.getEl(); + var id = el.id || el.tagName; + return ("ColorAnim " + id); + }; + + proto.patterns.color = /color$/i; + proto.patterns.rgb = /^rgb\(([0-9]+)\s*,\s*([0-9]+)\s*,\s*([0-9]+)\)$/i; + proto.patterns.hex = /^#?([0-9A-F]{2})([0-9A-F]{2})([0-9A-F]{2})$/i; + proto.patterns.hex3 = /^#?([0-9A-F]{1})([0-9A-F]{1})([0-9A-F]{1})$/i; + proto.patterns.transparent = /^transparent|rgba\(0, 0, 0, 0\)$/; // need rgba for safari + + /** + * Attempts to parse the given string and return a 3-tuple. + * @method parseColor + * @param {String} s The string to parse. + * @return {Array} The 3-tuple of rgb values. + */ + proto.parseColor = function(s) { + if (s.length == 3) { return s; } + + var c = this.patterns.hex.exec(s); + if (c && c.length == 4) { + return [ parseInt(c[1], 16), parseInt(c[2], 16), parseInt(c[3], 16) ]; + } + + c = this.patterns.rgb.exec(s); + if (c && c.length == 4) { + return [ parseInt(c[1], 10), parseInt(c[2], 10), parseInt(c[3], 10) ]; + } + + c = this.patterns.hex3.exec(s); + if (c && c.length == 4) { + return [ parseInt(c[1] + c[1], 16), parseInt(c[2] + c[2], 16), parseInt(c[3] + c[3], 16) ]; + } + + return null; + }; + + proto.getAttribute = function(attr) { + var el = this.getEl(); + if ( this.patterns.color.test(attr) ) { + var val = YAHOO.util.Dom.getStyle(el, attr); + + if (this.patterns.transparent.test(val)) { // bgcolor default + var parent = el.parentNode; // try and get from an ancestor + val = Y.Dom.getStyle(parent, attr); + + while (parent && this.patterns.transparent.test(val)) { + parent = parent.parentNode; + val = Y.Dom.getStyle(parent, attr); + if (parent.tagName.toUpperCase() == 'HTML') { + val = '#fff'; + } + } + } + } else { + val = superclass.getAttribute.call(this, attr); + } + + return val; + }; + + proto.doMethod = function(attr, start, end) { + var val; + + if ( this.patterns.color.test(attr) ) { + val = []; + for (var i = 0, len = start.length; i < len; ++i) { + val[i] = superclass.doMethod.call(this, attr, start[i], end[i]); + } + + val = 'rgb('+Math.floor(val[0])+','+Math.floor(val[1])+','+Math.floor(val[2])+')'; + } + else { + val = superclass.doMethod.call(this, attr, start, end); + } + + return val; + }; + + proto.setRuntimeAttribute = function(attr) { + superclass.setRuntimeAttribute.call(this, attr); + + if ( this.patterns.color.test(attr) ) { + var attributes = this.attributes; + var start = this.parseColor(this.runtimeAttributes[attr].start); + var end = this.parseColor(this.runtimeAttributes[attr].end); + // fix colors if going "by" + if ( typeof attributes[attr]['to'] === 'undefined' && typeof attributes[attr]['by'] !== 'undefined' ) { + end = this.parseColor(attributes[attr].by); + + for (var i = 0, len = start.length; i < len; ++i) { + end[i] = start[i] + end[i]; + } + } + + this.runtimeAttributes[attr].start = start; + this.runtimeAttributes[attr].end = end; + } + }; +})(); +/* +TERMS OF USE - EASING EQUATIONS +Open source under the BSD License. +Copyright 2001 Robert Penner All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. + * Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +*/ + +/** + * Singleton that determines how an animation proceeds from start to end. + * @class Easing + * @namespace YAHOO.util +*/ + +YAHOO.util.Easing = { + + /** + * Uniform speed between points. + * @method easeNone + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @return {Number} The computed value for the current animation frame + */ + easeNone: function (t, b, c, d) { + return c*t/d + b; + }, + + /** + * Begins slowly and accelerates towards end. (quadratic) + * @method easeIn + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @return {Number} The computed value for the current animation frame + */ + easeIn: function (t, b, c, d) { + return c*(t/=d)*t + b; + }, + + /** + * Begins quickly and decelerates towards end. (quadratic) + * @method easeOut + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @return {Number} The computed value for the current animation frame + */ + easeOut: function (t, b, c, d) { + return -c *(t/=d)*(t-2) + b; + }, + + /** + * Begins slowly and decelerates towards end. (quadratic) + * @method easeBoth + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @return {Number} The computed value for the current animation frame + */ + easeBoth: function (t, b, c, d) { + if ((t/=d/2) < 1) { + return c/2*t*t + b; + } + + return -c/2 * ((--t)*(t-2) - 1) + b; + }, + + /** + * Begins slowly and accelerates towards end. (quartic) + * @method easeInStrong + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @return {Number} The computed value for the current animation frame + */ + easeInStrong: function (t, b, c, d) { + return c*(t/=d)*t*t*t + b; + }, + + /** + * Begins quickly and decelerates towards end. (quartic) + * @method easeOutStrong + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @return {Number} The computed value for the current animation frame + */ + easeOutStrong: function (t, b, c, d) { + return -c * ((t=t/d-1)*t*t*t - 1) + b; + }, + + /** + * Begins slowly and decelerates towards end. (quartic) + * @method easeBothStrong + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @return {Number} The computed value for the current animation frame + */ + easeBothStrong: function (t, b, c, d) { + if ((t/=d/2) < 1) { + return c/2*t*t*t*t + b; + } + + return -c/2 * ((t-=2)*t*t*t - 2) + b; + }, + + /** + * Snap in elastic effect. + * @method elasticIn + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @param {Number} a Amplitude (optional) + * @param {Number} p Period (optional) + * @return {Number} The computed value for the current animation frame + */ + + elasticIn: function (t, b, c, d, a, p) { + if (t == 0) { + return b; + } + if ( (t /= d) == 1 ) { + return b+c; + } + if (!p) { + p=d*.3; + } + + if (!a || a < Math.abs(c)) { + a = c; + var s = p/4; + } + else { + var s = p/(2*Math.PI) * Math.asin (c/a); + } + + return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; + }, + + /** + * Snap out elastic effect. + * @method elasticOut + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @param {Number} a Amplitude (optional) + * @param {Number} p Period (optional) + * @return {Number} The computed value for the current animation frame + */ + elasticOut: function (t, b, c, d, a, p) { + if (t == 0) { + return b; + } + if ( (t /= d) == 1 ) { + return b+c; + } + if (!p) { + p=d*.3; + } + + if (!a || a < Math.abs(c)) { + a = c; + var s = p / 4; + } + else { + var s = p/(2*Math.PI) * Math.asin (c/a); + } + + return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b; + }, + + /** + * Snap both elastic effect. + * @method elasticBoth + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @param {Number} a Amplitude (optional) + * @param {Number} p Period (optional) + * @return {Number} The computed value for the current animation frame + */ + elasticBoth: function (t, b, c, d, a, p) { + if (t == 0) { + return b; + } + + if ( (t /= d/2) == 2 ) { + return b+c; + } + + if (!p) { + p = d*(.3*1.5); + } + + if ( !a || a < Math.abs(c) ) { + a = c; + var s = p/4; + } + else { + var s = p/(2*Math.PI) * Math.asin (c/a); + } + + if (t < 1) { + return -.5*(a*Math.pow(2,10*(t-=1)) * + Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; + } + return a*Math.pow(2,-10*(t-=1)) * + Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b; + }, + + + /** + * Backtracks slightly, then reverses direction and moves to end. + * @method backIn + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @param {Number} s Overshoot (optional) + * @return {Number} The computed value for the current animation frame + */ + backIn: function (t, b, c, d, s) { + if (typeof s == 'undefined') { + s = 1.70158; + } + return c*(t/=d)*t*((s+1)*t - s) + b; + }, + + /** + * Overshoots end, then reverses and comes back to end. + * @method backOut + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @param {Number} s Overshoot (optional) + * @return {Number} The computed value for the current animation frame + */ + backOut: function (t, b, c, d, s) { + if (typeof s == 'undefined') { + s = 1.70158; + } + return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b; + }, + + /** + * Backtracks slightly, then reverses direction, overshoots end, + * then reverses and comes back to end. + * @method backBoth + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @param {Number} s Overshoot (optional) + * @return {Number} The computed value for the current animation frame + */ + backBoth: function (t, b, c, d, s) { + if (typeof s == 'undefined') { + s = 1.70158; + } + + if ((t /= d/2 ) < 1) { + return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; + } + return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; + }, + + /** + * Bounce off of start. + * @method bounceIn + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @return {Number} The computed value for the current animation frame + */ + bounceIn: function (t, b, c, d) { + return c - YAHOO.util.Easing.bounceOut(d-t, 0, c, d) + b; + }, + + /** + * Bounces off end. + * @method bounceOut + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @return {Number} The computed value for the current animation frame + */ + bounceOut: function (t, b, c, d) { + if ((t/=d) < (1/2.75)) { + return c*(7.5625*t*t) + b; + } else if (t < (2/2.75)) { + return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b; + } else if (t < (2.5/2.75)) { + return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b; + } + return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b; + }, + + /** + * Bounces off start and end. + * @method bounceBoth + * @param {Number} t Time value used to compute current value + * @param {Number} b Starting value + * @param {Number} c Delta between start and end values + * @param {Number} d Total length of animation + * @return {Number} The computed value for the current animation frame + */ + bounceBoth: function (t, b, c, d) { + if (t < d/2) { + return YAHOO.util.Easing.bounceIn(t*2, 0, c, d) * .5 + b; + } + return YAHOO.util.Easing.bounceOut(t*2-d, 0, c, d) * .5 + c*.5 + b; + } +}; + +(function() { +/** + * Anim subclass for moving elements along a path defined by the "points" + * member of "attributes". All "points" are arrays with x, y coordinates. + *

Usage: var myAnim = new YAHOO.util.Motion(el, { points: { to: [800, 800] } }, 1, YAHOO.util.Easing.easeOut);

+ * @class Motion + * @namespace YAHOO.util + * @requires YAHOO.util.Anim + * @requires YAHOO.util.AnimMgr + * @requires YAHOO.util.Easing + * @requires YAHOO.util.Bezier + * @requires YAHOO.util.Dom + * @requires YAHOO.util.Event + * @requires YAHOO.util.CustomEvent + * @constructor + * @extends YAHOO.util.Anim + * @param {String | HTMLElement} el Reference to the element that will be animated + * @param {Object} attributes The attribute(s) to be animated. + * Each attribute is an object with at minimum a "to" or "by" member defined. + * Additional optional members are "from" (defaults to current value), "units" (defaults to "px"). + * All attribute names use camelCase. + * @param {Number} duration (optional, defaults to 1 second) Length of animation (frames or seconds), defaults to time-based + * @param {Function} method (optional, defaults to YAHOO.util.Easing.easeNone) Computes the values that are applied to the attributes per frame (generally a YAHOO.util.Easing method) + */ + YAHOO.util.Motion = function(el, attributes, duration, method) { + if (el) { // dont break existing subclasses not using YAHOO.extend + YAHOO.util.Motion.superclass.constructor.call(this, el, attributes, duration, method); + } + }; + + YAHOO.extend(YAHOO.util.Motion, YAHOO.util.ColorAnim); + + // shorthand + var Y = YAHOO.util; + var superclass = Y.Motion.superclass; + var proto = Y.Motion.prototype; + + proto.toString = function() { + var el = this.getEl(); + var id = el.id || el.tagName; + return ("Motion " + id); + }; + + proto.patterns.points = /^points$/i; + + proto.setAttribute = function(attr, val, unit) { + if ( this.patterns.points.test(attr) ) { + unit = unit || 'px'; + superclass.setAttribute.call(this, 'left', val[0], unit); + superclass.setAttribute.call(this, 'top', val[1], unit); + } else { + superclass.setAttribute.call(this, attr, val, unit); + } + }; + + proto.getAttribute = function(attr) { + if ( this.patterns.points.test(attr) ) { + var val = [ + superclass.getAttribute.call(this, 'left'), + superclass.getAttribute.call(this, 'top') + ]; + } else { + val = superclass.getAttribute.call(this, attr); + } + + return val; + }; + + proto.doMethod = function(attr, start, end) { + var val = null; + + if ( this.patterns.points.test(attr) ) { + var t = this.method(this.currentFrame, 0, 100, this.totalFrames) / 100; + val = Y.Bezier.getPosition(this.runtimeAttributes[attr], t); + } else { + val = superclass.doMethod.call(this, attr, start, end); + } + return val; + }; + + proto.setRuntimeAttribute = function(attr) { + if ( this.patterns.points.test(attr) ) { + var el = this.getEl(); + var attributes = this.attributes; + var start; + var control = attributes['points']['control'] || []; + var end; + var i, len; + + if (control.length > 0 && !(control[0] instanceof Array) ) { // could be single point or array of points + control = [control]; + } else { // break reference to attributes.points.control + var tmp = []; + for (i = 0, len = control.length; i< len; ++i) { + tmp[i] = control[i]; + } + control = tmp; + } + + if (Y.Dom.getStyle(el, 'position') == 'static') { // default to relative + Y.Dom.setStyle(el, 'position', 'relative'); + } + + if ( isset(attributes['points']['from']) ) { + Y.Dom.setXY(el, attributes['points']['from']); // set position to from point + } + else { Y.Dom.setXY( el, Y.Dom.getXY(el) ); } // set it to current position + + start = this.getAttribute('points'); // get actual top & left + + // TO beats BY, per SMIL 2.1 spec + if ( isset(attributes['points']['to']) ) { + end = translateValues.call(this, attributes['points']['to'], start); + + var pageXY = Y.Dom.getXY(this.getEl()); + for (i = 0, len = control.length; i < len; ++i) { + control[i] = translateValues.call(this, control[i], start); + } + + + } else if ( isset(attributes['points']['by']) ) { + end = [ start[0] + attributes['points']['by'][0], start[1] + attributes['points']['by'][1] ]; + + for (i = 0, len = control.length; i < len; ++i) { + control[i] = [ start[0] + control[i][0], start[1] + control[i][1] ]; + } + } + + this.runtimeAttributes[attr] = [start]; + + if (control.length > 0) { + this.runtimeAttributes[attr] = this.runtimeAttributes[attr].concat(control); + } + + this.runtimeAttributes[attr][this.runtimeAttributes[attr].length] = end; + } + else { + superclass.setRuntimeAttribute.call(this, attr); + } + }; + + var translateValues = function(val, start) { + var pageXY = Y.Dom.getXY(this.getEl()); + val = [ val[0] - pageXY[0] + start[0], val[1] - pageXY[1] + start[1] ]; + + return val; + }; + + var isset = function(prop) { + return (typeof prop !== 'undefined'); + }; +})(); +(function() { +/** + * Anim subclass for scrolling elements to a position defined by the "scroll" + * member of "attributes". All "scroll" members are arrays with x, y scroll positions. + *

Usage: var myAnim = new YAHOO.util.Scroll(el, { scroll: { to: [0, 800] } }, 1, YAHOO.util.Easing.easeOut);

+ * @class Scroll + * @namespace YAHOO.util + * @requires YAHOO.util.Anim + * @requires YAHOO.util.AnimMgr + * @requires YAHOO.util.Easing + * @requires YAHOO.util.Bezier + * @requires YAHOO.util.Dom + * @requires YAHOO.util.Event + * @requires YAHOO.util.CustomEvent + * @extends YAHOO.util.Anim + * @constructor + * @param {String or HTMLElement} el Reference to the element that will be animated + * @param {Object} attributes The attribute(s) to be animated. + * Each attribute is an object with at minimum a "to" or "by" member defined. + * Additional optional members are "from" (defaults to current value), "units" (defaults to "px"). + * All attribute names use camelCase. + * @param {Number} duration (optional, defaults to 1 second) Length of animation (frames or seconds), defaults to time-based + * @param {Function} method (optional, defaults to YAHOO.util.Easing.easeNone) Computes the values that are applied to the attributes per frame (generally a YAHOO.util.Easing method) + */ + YAHOO.util.Scroll = function(el, attributes, duration, method) { + if (el) { // dont break existing subclasses not using YAHOO.extend + YAHOO.util.Scroll.superclass.constructor.call(this, el, attributes, duration, method); + } + }; + + YAHOO.extend(YAHOO.util.Scroll, YAHOO.util.ColorAnim); + + // shorthand + var Y = YAHOO.util; + var superclass = Y.Scroll.superclass; + var proto = Y.Scroll.prototype; + + proto.toString = function() { + var el = this.getEl(); + var id = el.id || el.tagName; + return ("Scroll " + id); + }; + + proto.doMethod = function(attr, start, end) { + var val = null; + + if (attr == 'scroll') { + val = [ + this.method(this.currentFrame, start[0], end[0] - start[0], this.totalFrames), + this.method(this.currentFrame, start[1], end[1] - start[1], this.totalFrames) + ]; + + } else { + val = superclass.doMethod.call(this, attr, start, end); + } + return val; + }; + + proto.getAttribute = function(attr) { + var val = null; + var el = this.getEl(); + + if (attr == 'scroll') { + val = [ el.scrollLeft, el.scrollTop ]; + } else { + val = superclass.getAttribute.call(this, attr); + } + + return val; + }; + + proto.setAttribute = function(attr, val, unit) { + var el = this.getEl(); + + if (attr == 'scroll') { + el.scrollLeft = val[0]; + el.scrollTop = val[1]; + } else { + superclass.setAttribute.call(this, attr, val, unit); + } + }; +})(); +YAHOO.register("animation", YAHOO.util.Anim, {version: "2.2.0", build: "127"}); diff --git a/interface/web/js/yui/autocomplete/README b/interface/web/js/yui/autocomplete/README new file mode 100644 index 000000000..6ab63439b --- /dev/null +++ b/interface/web/js/yui/autocomplete/README @@ -0,0 +1,77 @@ +AutoComplete Release Notes + +*** version 2.2.0 *** + +* No changes. + + + +*** version 0.12.2 *** + +* No changes. + + + +*** version 0.12.1 *** + +* No longer trigger typeAhead feature when user is backspacing on input text. + + + +*** version 0.12.0 *** + +* The following constants must be defined as static class properties and are no longer +available as instance properties: + +YAHOO.widget.DataSource.ERROR_DATANULL +YAHOO.widget.DataSource.ERROR_DATAPARSE +YAHOO.widget.DS_XHR.TYPE_JSON +YAHOO.widget.DS_XHR.TYPE_XML +YAHOO.widget.DS_XHR.TYPE_FLAT +YAHOO.widget.DS_XHR.ERROR_DATAXHR + +* The property minQueryLength now supports zero and negative number values for +DS_JSFunction and DS_XHR objects, to enable null or empty string queries and to disable +AutoComplete functionality altogether, respectively. + +* Enabling the alwaysShowContainer feature will no longer send containerExpandEvent or +containerCollapseEvent. + + + +**** version 0.11.3 *** + +* The iFrameSrc property has been deprecated. Implementers no longer need to +specify an https URL to avoid IE security warnings when working with sites over +SSL. + + + +*** version 0.11.0 *** + +* The method getListIds() has been deprecated for getListItems(), which returns +an array of DOM references. + +* All classnames have been prefixed with "yui-ac-". + +* Container elements should no longer have CSS property "display" set to "none". + +* The useIFrame property can now be set after instantiation. + +* On some browsers, the unmatchedItemSelectEvent may not be fired properly when +delimiter characters are defined. + +* On some browsers, defining delimiter characters while enabling forceSelection +may result in unexpected behavior. + + + +*** version 0.10.0 *** + +* Initial release + +* In order to enable the useIFrame property, it should be set in the +constructor. + +* On some browsers, defining delimiter characters while enabling forceSelection +may result in unexpected behavior. diff --git a/interface/web/js/yui/autocomplete/autocomplete-debug.js b/interface/web/js/yui/autocomplete/autocomplete-debug.js new file mode 100644 index 000000000..1e48da23d --- /dev/null +++ b/interface/web/js/yui/autocomplete/autocomplete-debug.js @@ -0,0 +1,3100 @@ +/* +Copyright (c) 2007, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.net/yui/license.txt +version: 2.2.0 +*/ + /** + * The AutoComplete control provides the front-end logic for text-entry suggestion and + * completion functionality. + * + * @module autocomplete + * @requires yahoo, dom, event, datasource + * @optional animation, connection + * @namespace YAHOO.widget + * @title AutoComplete Widget + */ + +/****************************************************************************/ +/****************************************************************************/ +/****************************************************************************/ + +/** + * The AutoComplete class provides the customizable functionality of a plug-and-play DHTML + * auto completion widget. Some key features: + *
    + *
  • Navigate with up/down arrow keys and/or mouse to pick a selection
  • + *
  • The drop down container can "roll down" or "fly out" via configurable + * animation
  • + *
  • UI look-and-feel customizable through CSS, including container + * attributes, borders, position, fonts, etc
  • + *
+ * + * @class AutoComplete + * @constructor + * @param elInput {HTMLElement} DOM element reference of an input field. + * @param elInput {String} String ID of an input field. + * @param elContainer {HTMLElement} DOM element reference of an existing DIV. + * @param elContainer {String} String ID of an existing DIV. + * @param oDataSource {YAHOO.widget.DataSource} DataSource instance. + * @param oConfigs {Object} (optional) Object literal of configuration params. + */ +YAHOO.widget.AutoComplete = function(elInput,elContainer,oDataSource,oConfigs) { + if(elInput && elContainer && oDataSource) { + // Validate DataSource + if (oDataSource && (oDataSource instanceof YAHOO.widget.DataSource)) { + this.dataSource = oDataSource; + } + else { + YAHOO.log("Could not instantiate AutoComplete due to an invalid DataSource", "error", this.toString()); + return; + } + + // Validate input element + if(YAHOO.util.Dom.inDocument(elInput)) { + if(typeof elInput == "string") { + this._sName = "instance" + YAHOO.widget.AutoComplete._nIndex + " " + elInput; + this._oTextbox = document.getElementById(elInput); + } + else { + this._sName = (elInput.id) ? + "instance" + YAHOO.widget.AutoComplete._nIndex + " " + elInput.id: + "instance" + YAHOO.widget.AutoComplete._nIndex; + this._oTextbox = elInput; + } + } + else { + YAHOO.log("Could not instantiate AutoComplete due to an invalid input element", "error", this.toString()); + return; + } + + // Validate container element + if(YAHOO.util.Dom.inDocument(elContainer)) { + if(typeof elContainer == "string") { + this._oContainer = document.getElementById(elContainer); + } + else { + this._oContainer = elContainer; + } + if(this._oContainer.style.display == "none") { + YAHOO.log("The container may not display properly if display is set to \"none\" in CSS", "warn", this.toString()); + } + } + else { + YAHOO.log("Could not instantiate AutoComplete due to an invalid container element", "error", this.toString()); + return; + } + + // Set any config params passed in to override defaults + if (typeof oConfigs == "object") { + for(var sConfig in oConfigs) { + if (sConfig) { + this[sConfig] = oConfigs[sConfig]; + } + } + } + + // Initialization sequence + this._initContainer(); + this._initProps(); + this._initList(); + this._initContainerHelpers(); + + // Set up events + var oSelf = this; + var oTextbox = this._oTextbox; + // Events are actually for the content module within the container + var oContent = this._oContainer._oContent; + + // Dom events + YAHOO.util.Event.addListener(oTextbox,"keyup",oSelf._onTextboxKeyUp,oSelf); + YAHOO.util.Event.addListener(oTextbox,"keydown",oSelf._onTextboxKeyDown,oSelf); + YAHOO.util.Event.addListener(oTextbox,"focus",oSelf._onTextboxFocus,oSelf); + YAHOO.util.Event.addListener(oTextbox,"blur",oSelf._onTextboxBlur,oSelf); + YAHOO.util.Event.addListener(oContent,"mouseover",oSelf._onContainerMouseover,oSelf); + YAHOO.util.Event.addListener(oContent,"mouseout",oSelf._onContainerMouseout,oSelf); + YAHOO.util.Event.addListener(oContent,"scroll",oSelf._onContainerScroll,oSelf); + YAHOO.util.Event.addListener(oContent,"resize",oSelf._onContainerResize,oSelf); + if(oTextbox.form) { + YAHOO.util.Event.addListener(oTextbox.form,"submit",oSelf._onFormSubmit,oSelf); + } + YAHOO.util.Event.addListener(oTextbox,"keypress",oSelf._onTextboxKeyPress,oSelf); + + // Custom events + this.textboxFocusEvent = new YAHOO.util.CustomEvent("textboxFocus", this); + this.textboxKeyEvent = new YAHOO.util.CustomEvent("textboxKey", this); + this.dataRequestEvent = new YAHOO.util.CustomEvent("dataRequest", this); + this.dataReturnEvent = new YAHOO.util.CustomEvent("dataReturn", this); + this.dataErrorEvent = new YAHOO.util.CustomEvent("dataError", this); + this.containerExpandEvent = new YAHOO.util.CustomEvent("containerExpand", this); + this.typeAheadEvent = new YAHOO.util.CustomEvent("typeAhead", this); + this.itemMouseOverEvent = new YAHOO.util.CustomEvent("itemMouseOver", this); + this.itemMouseOutEvent = new YAHOO.util.CustomEvent("itemMouseOut", this); + this.itemArrowToEvent = new YAHOO.util.CustomEvent("itemArrowTo", this); + this.itemArrowFromEvent = new YAHOO.util.CustomEvent("itemArrowFrom", this); + this.itemSelectEvent = new YAHOO.util.CustomEvent("itemSelect", this); + this.unmatchedItemSelectEvent = new YAHOO.util.CustomEvent("unmatchedItemSelect", this); + this.selectionEnforceEvent = new YAHOO.util.CustomEvent("selectionEnforce", this); + this.containerCollapseEvent = new YAHOO.util.CustomEvent("containerCollapse", this); + this.textboxBlurEvent = new YAHOO.util.CustomEvent("textboxBlur", this); + + // Finish up + oTextbox.setAttribute("autocomplete","off"); + YAHOO.widget.AutoComplete._nIndex++; + YAHOO.log("AutoComplete initialized","info",this.toString()); + } + // Required arguments were not found + else { + YAHOO.log("Could not instantiate AutoComplete due invalid arguments", "error", this.toString()); + } +}; + +///////////////////////////////////////////////////////////////////////////// +// +// Public member variables +// +///////////////////////////////////////////////////////////////////////////// + +/** + * The DataSource object that encapsulates the data used for auto completion. + * This object should be an inherited object from YAHOO.widget.DataSource. + * + * @property dataSource + * @type YAHOO.widget.DataSource + */ +YAHOO.widget.AutoComplete.prototype.dataSource = null; + +/** + * Number of characters that must be entered before querying for results. A negative value + * effectively turns off the widget. A value of 0 allows queries of null or empty string + * values. + * + * @property minQueryLength + * @type Number + * @default 1 + */ +YAHOO.widget.AutoComplete.prototype.minQueryLength = 1; + +/** + * Maximum number of results to display in results container. + * + * @property maxResultsDisplayed + * @type Number + * @default 10 + */ +YAHOO.widget.AutoComplete.prototype.maxResultsDisplayed = 10; + +/** + * Number of seconds to delay before submitting a query request. If a query + * request is received before a previous one has completed its delay, the + * previous request is cancelled and the new request is set to the delay. + * + * @property queryDelay + * @type Number + * @default 0.5 + */ +YAHOO.widget.AutoComplete.prototype.queryDelay = 0.5; + +/** + * Class name of a highlighted item within results container. + * + * @property highlightClassName + * @type String + * @default "yui-ac-highlight" + */ +YAHOO.widget.AutoComplete.prototype.highlightClassName = "yui-ac-highlight"; + +/** + * Class name of a pre-highlighted item within results container. + * + * @property prehighlightClassName + * @type String + */ +YAHOO.widget.AutoComplete.prototype.prehighlightClassName = null; + +/** + * Query delimiter. A single character separator for multiple delimited + * selections. Multiple delimiter characteres may be defined as an array of + * strings. A null value or empty string indicates that query results cannot + * be delimited. This feature is not recommended if you need forceSelection to + * be true. + * + * @property delimChar + * @type String | String[] + */ +YAHOO.widget.AutoComplete.prototype.delimChar = null; + +/** + * Whether or not the first item in results container should be automatically highlighted + * on expand. + * + * @property autoHighlight + * @type Boolean + * @default true + */ +YAHOO.widget.AutoComplete.prototype.autoHighlight = true; + +/** + * Whether or not the input field should be automatically updated + * with the first query result as the user types, auto-selecting the substring + * that the user has not typed. + * + * @property typeAhead + * @type Boolean + * @default false + */ +YAHOO.widget.AutoComplete.prototype.typeAhead = false; + +/** + * Whether or not to animate the expansion/collapse of the results container in the + * horizontal direction. + * + * @property animHoriz + * @type Boolean + * @default false + */ +YAHOO.widget.AutoComplete.prototype.animHoriz = false; + +/** + * Whether or not to animate the expansion/collapse of the results container in the + * vertical direction. + * + * @property animVert + * @type Boolean + * @default true + */ +YAHOO.widget.AutoComplete.prototype.animVert = true; + +/** + * Speed of container expand/collapse animation, in seconds.. + * + * @property animSpeed + * @type Number + * @default 0.3 + */ +YAHOO.widget.AutoComplete.prototype.animSpeed = 0.3; + +/** + * Whether or not to force the user's selection to match one of the query + * results. Enabling this feature essentially transforms the input field into a + * <select> field. This feature is not recommended with delimiter character(s) + * defined. + * + * @property forceSelection + * @type Boolean + * @default false + */ +YAHOO.widget.AutoComplete.prototype.forceSelection = false; + +/** + * Whether or not to allow browsers to cache user-typed input in the input + * field. Disabling this feature will prevent the widget from setting the + * autocomplete="off" on the input field. When autocomplete="off" + * and users click the back button after form submission, user-typed input can + * be prefilled by the browser from its cache. This caching of user input may + * not be desired for sensitive data, such as credit card numbers, in which + * case, implementers should consider setting allowBrowserAutocomplete to false. + * + * @property allowBrowserAutocomplete + * @type Boolean + * @default true + */ +YAHOO.widget.AutoComplete.prototype.allowBrowserAutocomplete = true; + +/** + * Whether or not the results container should always be displayed. + * Enabling this feature displays the container when the widget is instantiated + * and prevents the toggling of the container to a collapsed state. + * + * @property alwaysShowContainer + * @type Boolean + * @default false + */ +YAHOO.widget.AutoComplete.prototype.alwaysShowContainer = false; + +/** + * Whether or not to use an iFrame to layer over Windows form elements in + * IE. Set to true only when the results container will be on top of a + * <select> field in IE and thus exposed to the IE z-index bug (i.e., + * 5.5 < IE < 7). + * + * @property useIFrame + * @type Boolean + * @default false + */ +YAHOO.widget.AutoComplete.prototype.useIFrame = false; + +/** + * Whether or not the results container should have a shadow. + * + * @property useShadow + * @type Boolean + * @default false + */ +YAHOO.widget.AutoComplete.prototype.useShadow = false; + +///////////////////////////////////////////////////////////////////////////// +// +// Public methods +// +///////////////////////////////////////////////////////////////////////////// + + /** + * Public accessor to the unique name of the AutoComplete instance. + * + * @method toString + * @return {String} Unique name of the AutoComplete instance. + */ +YAHOO.widget.AutoComplete.prototype.toString = function() { + return "AutoComplete " + this._sName; +}; + + /** + * Returns true if container is in an expanded state, false otherwise. + * + * @method isContainerOpen + * @return {Boolean} Returns true if container is in an expanded state, false otherwise. + */ +YAHOO.widget.AutoComplete.prototype.isContainerOpen = function() { + return this._bContainerOpen; +}; + +/** + * Public accessor to the internal array of DOM <li> elements that + * display query results within the results container. + * + * @method getListItems + * @return {HTMLElement[]} Array of <li> elements within the results container. + */ +YAHOO.widget.AutoComplete.prototype.getListItems = function() { + return this._aListItems; +}; + +/** + * Public accessor to the data held in an <li> element of the + * results container. + * + * @method getListItemData + * @return {Object | Object[]} Object or array of result data or null + */ +YAHOO.widget.AutoComplete.prototype.getListItemData = function(oListItem) { + if(oListItem._oResultData) { + return oListItem._oResultData; + } + else { + return false; + } +}; + +/** + * Sets HTML markup for the results container header. This markup will be + * inserted within a <div> tag with a class of "yui-ac-hd". + * + * @method setHeader + * @param sHeader {String} HTML markup for results container header. + */ +YAHOO.widget.AutoComplete.prototype.setHeader = function(sHeader) { + if(sHeader) { + if(this._oContainer._oContent._oHeader) { + this._oContainer._oContent._oHeader.innerHTML = sHeader; + this._oContainer._oContent._oHeader.style.display = "block"; + } + } + else { + this._oContainer._oContent._oHeader.innerHTML = ""; + this._oContainer._oContent._oHeader.style.display = "none"; + } +}; + +/** + * Sets HTML markup for the results container footer. This markup will be + * inserted within a <div> tag with a class of "yui-ac-ft". + * + * @method setFooter + * @param sFooter {String} HTML markup for results container footer. + */ +YAHOO.widget.AutoComplete.prototype.setFooter = function(sFooter) { + if(sFooter) { + if(this._oContainer._oContent._oFooter) { + this._oContainer._oContent._oFooter.innerHTML = sFooter; + this._oContainer._oContent._oFooter.style.display = "block"; + } + } + else { + this._oContainer._oContent._oFooter.innerHTML = ""; + this._oContainer._oContent._oFooter.style.display = "none"; + } +}; + +/** + * Sets HTML markup for the results container body. This markup will be + * inserted within a <div> tag with a class of "yui-ac-bd". + * + * @method setBody + * @param sBody {String} HTML markup for results container body. + */ +YAHOO.widget.AutoComplete.prototype.setBody = function(sBody) { + if(sBody) { + if(this._oContainer._oContent._oBody) { + this._oContainer._oContent._oBody.innerHTML = sBody; + this._oContainer._oContent._oBody.style.display = "block"; + this._oContainer._oContent.style.display = "block"; + } + } + else { + this._oContainer._oContent._oBody.innerHTML = ""; + this._oContainer._oContent.style.display = "none"; + } + this._maxResultsDisplayed = 0; +}; + +/** + * Overridable method that converts a result item object into HTML markup + * for display. Return data values are accessible via the oResultItem object, + * and the key return value will always be oResultItem[0]. Markup will be + * displayed within <li> element tags in the container. + * + * @method formatResult + * @param oResultItem {Object} Result item representing one query result. Data is held in an array. + * @param sQuery {String} The current query string. + * @return {String} HTML markup of formatted result data. + */ +YAHOO.widget.AutoComplete.prototype.formatResult = function(oResultItem, sQuery) { + var sResult = oResultItem[0]; + if(sResult) { + return sResult; + } + else { + return ""; + } +}; + +/** + * Overridable method called before container expands allows implementers to access data + * and DOM elements. + * + * @method doBeforeExpandContainer + * @return {Boolean} Return true to continue expanding container, false to cancel the expand. + */ +YAHOO.widget.AutoComplete.prototype.doBeforeExpandContainer = function(oResultItem, sQuery) { + return true; +}; + +/** + * Makes query request to the DataSource. + * + * @method sendQuery + * @param sQuery {String} Query string. + */ +YAHOO.widget.AutoComplete.prototype.sendQuery = function(sQuery) { + this._sendQuery(sQuery); +}; + +///////////////////////////////////////////////////////////////////////////// +// +// Public events +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Fired when the input field receives focus. + * + * @event textboxFocusEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + */ +YAHOO.widget.AutoComplete.prototype.textboxFocusEvent = null; + +/** + * Fired when the input field receives key input. + * + * @event textboxKeyEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @param nKeycode {Number} The keycode number. + */ +YAHOO.widget.AutoComplete.prototype.textboxKeyEvent = null; + +/** + * Fired when the AutoComplete instance makes a query to the DataSource. + * + * @event dataRequestEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @param sQuery {String} The query string. + */ +YAHOO.widget.AutoComplete.prototype.dataRequestEvent = null; + +/** + * Fired when the AutoComplete instance receives query results from the data + * source. + * + * @event dataReturnEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @param sQuery {String} The query string. + * @param aResults {Object[]} Results array. + */ +YAHOO.widget.AutoComplete.prototype.dataReturnEvent = null; + +/** + * Fired when the AutoComplete instance does not receive query results from the + * DataSource due to an error. + * + * @event dataErrorEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @param sQuery {String} The query string. + */ +YAHOO.widget.AutoComplete.prototype.dataErrorEvent = null; + +/** + * Fired when the results container is expanded. + * + * @event containerExpandEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + */ +YAHOO.widget.AutoComplete.prototype.containerExpandEvent = null; + +/** + * Fired when the input field has been prefilled by the type-ahead + * feature. + * + * @event typeAheadEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @param sQuery {String} The query string. + * @param sPrefill {String} The prefill string. + */ +YAHOO.widget.AutoComplete.prototype.typeAheadEvent = null; + +/** + * Fired when result item has been moused over. + * + * @event itemMouseOverEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @param elItem {HTMLElement} The <li> element item moused to. + */ +YAHOO.widget.AutoComplete.prototype.itemMouseOverEvent = null; + +/** + * Fired when result item has been moused out. + * + * @event itemMouseOutEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @param elItem {HTMLElement} The <li> element item moused from. + */ +YAHOO.widget.AutoComplete.prototype.itemMouseOutEvent = null; + +/** + * Fired when result item has been arrowed to. + * + * @event itemArrowToEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @param elItem {HTMLElement} The <li> element item arrowed to. + */ +YAHOO.widget.AutoComplete.prototype.itemArrowToEvent = null; + +/** + * Fired when result item has been arrowed away from. + * + * @event itemArrowFromEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @param elItem {HTMLElement} The <li> element item arrowed from. + */ +YAHOO.widget.AutoComplete.prototype.itemArrowFromEvent = null; + +/** + * Fired when an item is selected via mouse click, ENTER key, or TAB key. + * + * @event itemSelectEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @param elItem {HTMLElement} The selected <li> element item. + * @param oData {Object} The data returned for the item, either as an object, + * or mapped from the schema into an array. + */ +YAHOO.widget.AutoComplete.prototype.itemSelectEvent = null; + +/** + * Fired when a user selection does not match any of the displayed result items. + * Note that this event may not behave as expected when delimiter characters + * have been defined. + * + * @event unmatchedItemSelectEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @param sQuery {String} The user-typed query string. + */ +YAHOO.widget.AutoComplete.prototype.unmatchedItemSelectEvent = null; + +/** + * Fired if forceSelection is enabled and the user's input has been cleared + * because it did not match one of the returned query results. + * + * @event selectionEnforceEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + */ +YAHOO.widget.AutoComplete.prototype.selectionEnforceEvent = null; + +/** + * Fired when the results container is collapsed. + * + * @event containerCollapseEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + */ +YAHOO.widget.AutoComplete.prototype.containerCollapseEvent = null; + +/** + * Fired when the input field loses focus. + * + * @event textboxBlurEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + */ +YAHOO.widget.AutoComplete.prototype.textboxBlurEvent = null; + +///////////////////////////////////////////////////////////////////////////// +// +// Private member variables +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Internal class variable to index multiple AutoComplete instances. + * + * @property _nIndex + * @type Number + * @default 0 + * @private + */ +YAHOO.widget.AutoComplete._nIndex = 0; + +/** + * Name of AutoComplete instance. + * + * @property _sName + * @type String + * @private + */ +YAHOO.widget.AutoComplete.prototype._sName = null; + +/** + * Text input field DOM element. + * + * @property _oTextbox + * @type HTMLElement + * @private + */ +YAHOO.widget.AutoComplete.prototype._oTextbox = null; + +/** + * Whether or not the input field is currently in focus. If query results come back + * but the user has already moved on, do not proceed with auto complete behavior. + * + * @property _bFocused + * @type Boolean + * @private + */ +YAHOO.widget.AutoComplete.prototype._bFocused = true; + +/** + * Animation instance for container expand/collapse. + * + * @property _oAnim + * @type Boolean + * @private + */ +YAHOO.widget.AutoComplete.prototype._oAnim = null; + +/** + * Container DOM element. + * + * @property _oContainer + * @type HTMLElement + * @private + */ +YAHOO.widget.AutoComplete.prototype._oContainer = null; + +/** + * Whether or not the results container is currently open. + * + * @property _bContainerOpen + * @type Boolean + * @private + */ +YAHOO.widget.AutoComplete.prototype._bContainerOpen = false; + +/** + * Whether or not the mouse is currently over the results + * container. This is necessary in order to prevent clicks on container items + * from being text input field blur events. + * + * @property _bOverContainer + * @type Boolean + * @private + */ +YAHOO.widget.AutoComplete.prototype._bOverContainer = false; + +/** + * Array of <li> elements references that contain query results within the + * results container. + * + * @property _aListItems + * @type HTMLElement[] + * @private + */ +YAHOO.widget.AutoComplete.prototype._aListItems = null; + +/** + * Number of <li> elements currently displayed in results container. + * + * @property _nDisplayedItems + * @type Number + * @private + */ +YAHOO.widget.AutoComplete.prototype._nDisplayedItems = 0; + +/** + * Internal count of <li> elements displayed and hidden in results container. + * + * @property _maxResultsDisplayed + * @type Number + * @private + */ +YAHOO.widget.AutoComplete.prototype._maxResultsDisplayed = 0; + +/** + * Current query string + * + * @property _sCurQuery + * @type String + * @private + */ +YAHOO.widget.AutoComplete.prototype._sCurQuery = null; + +/** + * Past queries this session (for saving delimited queries). + * + * @property _sSavedQuery + * @type String + * @private + */ +YAHOO.widget.AutoComplete.prototype._sSavedQuery = null; + +/** + * Pointer to the currently highlighted <li> element in the container. + * + * @property _oCurItem + * @type HTMLElement + * @private + */ +YAHOO.widget.AutoComplete.prototype._oCurItem = null; + +/** + * Whether or not an item has been selected since the container was populated + * with results. Reset to false by _populateList, and set to true when item is + * selected. + * + * @property _bItemSelected + * @type Boolean + * @private + */ +YAHOO.widget.AutoComplete.prototype._bItemSelected = false; + +/** + * Key code of the last key pressed in textbox. + * + * @property _nKeyCode + * @type Number + * @private + */ +YAHOO.widget.AutoComplete.prototype._nKeyCode = null; + +/** + * Delay timeout ID. + * + * @property _nDelayID + * @type Number + * @private + */ +YAHOO.widget.AutoComplete.prototype._nDelayID = -1; + +/** + * Src to iFrame used when useIFrame = true. Supports implementations over SSL + * as well. + * + * @property _iFrameSrc + * @type String + * @private + */ +YAHOO.widget.AutoComplete.prototype._iFrameSrc = "javascript:false;"; + +/** + * For users typing via certain IMEs, queries must be triggered by intervals, + * since key events yet supported across all browsers for all IMEs. + * + * @property _queryInterval + * @type Object + * @private + */ +YAHOO.widget.AutoComplete.prototype._queryInterval = null; + +/** + * Internal tracker to last known textbox value, used to determine whether or not + * to trigger a query via interval for certain IME users. + * + * @event _sLastTextboxValue + * @type String + * @private + */ +YAHOO.widget.AutoComplete.prototype._sLastTextboxValue = null; + +///////////////////////////////////////////////////////////////////////////// +// +// Private methods +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Updates and validates latest public config properties. + * + * @method __initProps + * @private + */ +YAHOO.widget.AutoComplete.prototype._initProps = function() { + // Correct any invalid values + var minQueryLength = this.minQueryLength; + if(isNaN(minQueryLength) || (minQueryLength < 1)) { + minQueryLength = 1; + } + var maxResultsDisplayed = this.maxResultsDisplayed; + if(isNaN(this.maxResultsDisplayed) || (this.maxResultsDisplayed < 1)) { + this.maxResultsDisplayed = 10; + } + var queryDelay = this.queryDelay; + if(isNaN(this.queryDelay) || (this.queryDelay < 0)) { + this.queryDelay = 0.5; + } + var aDelimChar = (this.delimChar) ? this.delimChar : null; + if(aDelimChar) { + if(typeof aDelimChar == "string") { + this.delimChar = [aDelimChar]; + } + else if(aDelimChar.constructor != Array) { + this.delimChar = null; + } + } + var animSpeed = this.animSpeed; + if((this.animHoriz || this.animVert) && YAHOO.util.Anim) { + if(isNaN(animSpeed) || (animSpeed < 0)) { + animSpeed = 0.3; + } + if(!this._oAnim ) { + oAnim = new YAHOO.util.Anim(this._oContainer._oContent, {}, this.animSpeed); + this._oAnim = oAnim; + } + else { + this._oAnim.duration = animSpeed; + } + } + if(this.forceSelection && this.delimChar) { + YAHOO.log("The forceSelection feature has been enabled with delimChar defined.","warn", this.toString()); + } +}; + +/** + * Initializes the results container helpers if they are enabled and do + * not exist + * + * @method _initContainerHelpers + * @private + */ +YAHOO.widget.AutoComplete.prototype._initContainerHelpers = function() { + if(this.useShadow && !this._oContainer._oShadow) { + var oShadow = document.createElement("div"); + oShadow.className = "yui-ac-shadow"; + this._oContainer._oShadow = this._oContainer.appendChild(oShadow); + } + if(this.useIFrame && !this._oContainer._oIFrame) { + var oIFrame = document.createElement("iframe"); + oIFrame.src = this._iFrameSrc; + oIFrame.frameBorder = 0; + oIFrame.scrolling = "no"; + oIFrame.style.position = "absolute"; + oIFrame.style.width = "100%"; + oIFrame.style.height = "100%"; + oIFrame.tabIndex = -1; + this._oContainer._oIFrame = this._oContainer.appendChild(oIFrame); + } +}; + +/** + * Initializes the results container once at object creation + * + * @method _initContainer + * @private + */ +YAHOO.widget.AutoComplete.prototype._initContainer = function() { + if(!this._oContainer._oContent) { + // The oContent div helps size the iframe and shadow properly + var oContent = document.createElement("div"); + oContent.className = "yui-ac-content"; + oContent.style.display = "none"; + this._oContainer._oContent = this._oContainer.appendChild(oContent); + + var oHeader = document.createElement("div"); + oHeader.className = "yui-ac-hd"; + oHeader.style.display = "none"; + this._oContainer._oContent._oHeader = this._oContainer._oContent.appendChild(oHeader); + + var oBody = document.createElement("div"); + oBody.className = "yui-ac-bd"; + this._oContainer._oContent._oBody = this._oContainer._oContent.appendChild(oBody); + + var oFooter = document.createElement("div"); + oFooter.className = "yui-ac-ft"; + oFooter.style.display = "none"; + this._oContainer._oContent._oFooter = this._oContainer._oContent.appendChild(oFooter); + } + else { + YAHOO.log("Could not initialize the container","warn",this.toString()); + } +}; + +/** + * Clears out contents of container body and creates up to + * YAHOO.widget.AutoComplete#maxResultsDisplayed <li> elements in an + * <ul> element. + * + * @method _initList + * @private + */ +YAHOO.widget.AutoComplete.prototype._initList = function() { + this._aListItems = []; + while(this._oContainer._oContent._oBody.hasChildNodes()) { + var oldListItems = this.getListItems(); + if(oldListItems) { + for(var oldi = oldListItems.length-1; oldi >= 0; i--) { + oldListItems[oldi] = null; + } + } + this._oContainer._oContent._oBody.innerHTML = ""; + } + + var oList = document.createElement("ul"); + oList = this._oContainer._oContent._oBody.appendChild(oList); + for(var i=0; i= 18 && nKeyCode <= 20) || // alt,pause/break,caps lock + (nKeyCode == 27) || // esc + (nKeyCode >= 33 && nKeyCode <= 35) || // page up,page down,end + (nKeyCode >= 36 && nKeyCode <= 38) || // home,left,up + (nKeyCode == 40) || // down + (nKeyCode >= 44 && nKeyCode <= 45)) { // print screen,insert + return true; + } + return false; +}; + +/** + * Makes query request to the DataSource. + * + * @method _sendQuery + * @param sQuery {String} Query string. + * @private + */ +YAHOO.widget.AutoComplete.prototype._sendQuery = function(sQuery) { + // Widget has been effectively turned off + if(this.minQueryLength == -1) { + this._toggleContainer(false); + return; + } + // Delimiter has been enabled + var aDelimChar = (this.delimChar) ? this.delimChar : null; + if(aDelimChar) { + // Loop through all possible delimiters and find the latest one + // A " " may be a false positive if they are defined as delimiters AND + // are used to separate delimited queries + var nDelimIndex = -1; + for(var i = aDelimChar.length-1; i >= 0; i--) { + var nNewIndex = sQuery.lastIndexOf(aDelimChar[i]); + if(nNewIndex > nDelimIndex) { + nDelimIndex = nNewIndex; + } + } + // If we think the last delimiter is a space (" "), make sure it is NOT + // a false positive by also checking the char directly before it + if(aDelimChar[i] == " ") { + for (var j = aDelimChar.length-1; j >= 0; j--) { + if(sQuery[nDelimIndex - 1] == aDelimChar[j]) { + nDelimIndex--; + break; + } + } + } + // A delimiter has been found so extract the latest query + if (nDelimIndex > -1) { + var nQueryStart = nDelimIndex + 1; + // Trim any white space from the beginning... + while(sQuery.charAt(nQueryStart) == " ") { + nQueryStart += 1; + } + // ...and save the rest of the string for later + this._sSavedQuery = sQuery.substring(0,nQueryStart); + // Here is the query itself + sQuery = sQuery.substr(nQueryStart); + } + else if(sQuery.indexOf(this._sSavedQuery) < 0){ + this._sSavedQuery = null; + } + } + + // Don't search queries that are too short + if (sQuery && (sQuery.length < this.minQueryLength) || (!sQuery && this.minQueryLength > 0)) { + if (this._nDelayID != -1) { + clearTimeout(this._nDelayID); + } + this._toggleContainer(false); + return; + } + + sQuery = encodeURIComponent(sQuery); + this._nDelayID = -1; // Reset timeout ID because request has been made + this.dataRequestEvent.fire(this, sQuery); + this.dataSource.getResults(this._populateList, sQuery, this); +}; + +/** + * Populates the array of <li> elements in the container with query + * results. This method is passed to YAHOO.widget.DataSource#getResults as a + * callback function so results from the DataSource instance are returned to the + * AutoComplete instance. + * + * @method _populateList + * @param sQuery {String} The query string. + * @param aResults {Object[]} An array of query result objects from the DataSource. + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._populateList = function(sQuery, aResults, oSelf) { + if(aResults === null) { + oSelf.dataErrorEvent.fire(oSelf, sQuery); + } + if (!oSelf._bFocused || !aResults) { + return; + } + + var isOpera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1); + var contentStyle = oSelf._oContainer._oContent.style; + contentStyle.width = (!isOpera) ? null : ""; + contentStyle.height = (!isOpera) ? null : ""; + + var sCurQuery = decodeURIComponent(sQuery); + oSelf._sCurQuery = sCurQuery; + oSelf._bItemSelected = false; + + if(oSelf._maxResultsDisplayed != oSelf.maxResultsDisplayed) { + oSelf._initList(); + } + + var nItems = Math.min(aResults.length,oSelf.maxResultsDisplayed); + oSelf._nDisplayedItems = nItems; + if (nItems > 0) { + oSelf._initContainerHelpers(); + var aItems = oSelf._aListItems; + + // Fill items with data + for(var i = nItems-1; i >= 0; i--) { + var oItemi = aItems[i]; + var oResultItemi = aResults[i]; + oItemi.innerHTML = oSelf.formatResult(oResultItemi, sCurQuery); + oItemi.style.display = "list-item"; + oItemi._sResultKey = oResultItemi[0]; + oItemi._oResultData = oResultItemi; + + } + + // Empty out remaining items if any + for(var j = aItems.length-1; j >= nItems ; j--) { + var oItemj = aItems[j]; + oItemj.innerHTML = null; + oItemj.style.display = "none"; + oItemj._sResultKey = null; + oItemj._oResultData = null; + } + + if(oSelf.autoHighlight) { + // Go to the first item + var oFirstItem = aItems[0]; + oSelf._toggleHighlight(oFirstItem,"to"); + oSelf.itemArrowToEvent.fire(oSelf, oFirstItem); + oSelf._typeAhead(oFirstItem,sQuery); + } + else { + oSelf._oCurItem = null; + } + + // Expand the container + var ok = oSelf.doBeforeExpandContainer(oSelf._oTextbox, oSelf._oContainer, sQuery, aResults); + oSelf._toggleContainer(ok); + } + else { + oSelf._toggleContainer(false); + } + oSelf.dataReturnEvent.fire(oSelf, sQuery, aResults); +}; + +/** + * When forceSelection is true and the user attempts + * leave the text input box without selecting an item from the query results, + * the user selection is cleared. + * + * @method _clearSelection + * @private + */ +YAHOO.widget.AutoComplete.prototype._clearSelection = function() { + var sValue = this._oTextbox.value; + var sChar = (this.delimChar) ? this.delimChar[0] : null; + var nIndex = (sChar) ? sValue.lastIndexOf(sChar, sValue.length-2) : -1; + if(nIndex > -1) { + this._oTextbox.value = sValue.substring(0,nIndex); + } + else { + this._oTextbox.value = ""; + } + this._sSavedQuery = this._oTextbox.value; + + // Fire custom event + this.selectionEnforceEvent.fire(this); +}; + +/** + * Whether or not user-typed value in the text input box matches any of the + * query results. + * + * @method _textMatchesOption + * @return {Boolean} True if user-input text matches a result, false otherwise. + * @private + */ +YAHOO.widget.AutoComplete.prototype._textMatchesOption = function() { + var foundMatch = false; + + for(var i = this._nDisplayedItems-1; i >= 0 ; i--) { + var oItem = this._aListItems[i]; + var sMatch = oItem._sResultKey.toLowerCase(); + if (sMatch == this._sCurQuery.toLowerCase()) { + foundMatch = true; + break; + } + } + return(foundMatch); +}; + +/** + * Updates in the text input box with the first query result as the user types, + * selecting the substring that the user has not typed. + * + * @method _typeAhead + * @param oItem {HTMLElement} The <li> element item whose data populates the input field. + * @param sQuery {String} Query string. + * @private + */ +YAHOO.widget.AutoComplete.prototype._typeAhead = function(oItem, sQuery) { + // Don't update if turned off + if (!this.typeAhead || (this._nKeyCode == 8)) { + return; + } + + var oTextbox = this._oTextbox; + var sValue = this._oTextbox.value; // any saved queries plus what user has typed + + // Don't update with type-ahead if text selection is not supported + if(!oTextbox.setSelectionRange && !oTextbox.createTextRange) { + return; + } + + // Select the portion of text that the user has not typed + var nStart = sValue.length; + this._updateValue(oItem); + var nEnd = oTextbox.value.length; + this._selectText(oTextbox,nStart,nEnd); + var sPrefill = oTextbox.value.substr(nStart,nEnd); + this.typeAheadEvent.fire(this,sQuery,sPrefill); +}; + +/** + * Selects text in the input field. + * + * @method _selectText + * @param oTextbox {HTMLElement} Text input box element in which to select text. + * @param nStart {Number} Starting index of text string to select. + * @param nEnd {Number} Ending index of text selection. + * @private + */ +YAHOO.widget.AutoComplete.prototype._selectText = function(oTextbox, nStart, nEnd) { + if (oTextbox.setSelectionRange) { // For Mozilla + oTextbox.setSelectionRange(nStart,nEnd); + } + else if (oTextbox.createTextRange) { // For IE + var oTextRange = oTextbox.createTextRange(); + oTextRange.moveStart("character", nStart); + oTextRange.moveEnd("character", nEnd-oTextbox.value.length); + oTextRange.select(); + } + else { + oTextbox.select(); + } +}; + +/** + * Syncs results container with its helpers. + * + * @method _toggleContainerHelpers + * @param bShow {Boolean} True if container is expanded, false if collapsed + * @private + */ +YAHOO.widget.AutoComplete.prototype._toggleContainerHelpers = function(bShow) { + var bFireEvent = false; + var width = this._oContainer._oContent.offsetWidth + "px"; + var height = this._oContainer._oContent.offsetHeight + "px"; + + if(this.useIFrame && this._oContainer._oIFrame) { + bFireEvent = true; + if(bShow) { + this._oContainer._oIFrame.style.width = width; + this._oContainer._oIFrame.style.height = height; + } + else { + this._oContainer._oIFrame.style.width = 0; + this._oContainer._oIFrame.style.height = 0; + } + } + if(this.useShadow && this._oContainer._oShadow) { + bFireEvent = true; + if(bShow) { + this._oContainer._oShadow.style.width = width; + this._oContainer._oShadow.style.height = height; + } + else { + this._oContainer._oShadow.style.width = 0; + this._oContainer._oShadow.style.height = 0; + } + } +}; + +/** + * Animates expansion or collapse of the container. + * + * @method _toggleContainer + * @param bShow {Boolean} True if container should be expanded, false if container should be collapsed + * @private + */ +YAHOO.widget.AutoComplete.prototype._toggleContainer = function(bShow) { + var oContainer = this._oContainer; + + // Implementer has container always open so don't mess with it + if(this.alwaysShowContainer && this._bContainerOpen) { + return; + } + + // Clear contents of container + if(!bShow) { + this._oContainer._oContent.scrollTop = 0; + var aItems = this._aListItems; + + if(aItems && (aItems.length > 0)) { + for(var i = aItems.length-1; i >= 0 ; i--) { + aItems[i].style.display = "none"; + } + } + + if (this._oCurItem) { + this._toggleHighlight(this._oCurItem,"from"); + } + + this._oCurItem = null; + this._nDisplayedItems = 0; + this._sCurQuery = null; + } + + // Container is already closed + if (!bShow && !this._bContainerOpen) { + oContainer._oContent.style.display = "none"; + return; + } + + // If animation is enabled... + var oAnim = this._oAnim; + if (oAnim && oAnim.getEl() && (this.animHoriz || this.animVert)) { + // If helpers need to be collapsed, do it right away... + // but if helpers need to be expanded, wait until after the container expands + if(!bShow) { + this._toggleContainerHelpers(bShow); + } + + if(oAnim.isAnimated()) { + oAnim.stop(); + } + + // Clone container to grab current size offscreen + var oClone = oContainer._oContent.cloneNode(true); + oContainer.appendChild(oClone); + oClone.style.top = "-9000px"; + oClone.style.display = "block"; + + // Current size of the container is the EXPANDED size + var wExp = oClone.offsetWidth; + var hExp = oClone.offsetHeight; + + // Calculate COLLAPSED sizes based on horiz and vert anim + var wColl = (this.animHoriz) ? 0 : wExp; + var hColl = (this.animVert) ? 0 : hExp; + + // Set animation sizes + oAnim.attributes = (bShow) ? + {width: { to: wExp }, height: { to: hExp }} : + {width: { to: wColl}, height: { to: hColl }}; + + // If opening anew, set to a collapsed size... + if(bShow && !this._bContainerOpen) { + oContainer._oContent.style.width = wColl+"px"; + oContainer._oContent.style.height = hColl+"px"; + } + // Else, set it to its last known size. + else { + oContainer._oContent.style.width = wExp+"px"; + oContainer._oContent.style.height = hExp+"px"; + } + + oContainer.removeChild(oClone); + oClone = null; + + var oSelf = this; + var onAnimComplete = function() { + // Finish the collapse + oAnim.onComplete.unsubscribeAll(); + + if(bShow) { + oSelf.containerExpandEvent.fire(oSelf); + } + else { + oContainer._oContent.style.display = "none"; + oSelf.containerCollapseEvent.fire(oSelf); + } + oSelf._toggleContainerHelpers(bShow); + }; + + // Display container and animate it + oContainer._oContent.style.display = "block"; + oAnim.onComplete.subscribe(onAnimComplete); + oAnim.animate(); + this._bContainerOpen = bShow; + } + // Else don't animate, just show or hide + else { + if(bShow) { + oContainer._oContent.style.display = "block"; + this.containerExpandEvent.fire(this); + } + else { + oContainer._oContent.style.display = "none"; + this.containerCollapseEvent.fire(this); + } + this._toggleContainerHelpers(bShow); + this._bContainerOpen = bShow; + } + +}; + +/** + * Toggles the highlight on or off for an item in the container, and also cleans + * up highlighting of any previous item. + * + * @method _toggleHighlight + * @param oNewItem {HTMLElement} The <li> element item to receive highlight behavior. + * @param sType {String} Type "mouseover" will toggle highlight on, and "mouseout" will toggle highlight off. + * @private + */ +YAHOO.widget.AutoComplete.prototype._toggleHighlight = function(oNewItem, sType) { + var sHighlight = this.highlightClassName; + if(this._oCurItem) { + // Remove highlight from old item + YAHOO.util.Dom.removeClass(this._oCurItem, sHighlight); + } + + if((sType == "to") && sHighlight) { + // Apply highlight to new item + YAHOO.util.Dom.addClass(oNewItem, sHighlight); + this._oCurItem = oNewItem; + } +}; + +/** + * Toggles the pre-highlight on or off for an item in the container. + * + * @method _togglePrehighlight + * @param oNewItem {HTMLElement} The <li> element item to receive highlight behavior. + * @param sType {String} Type "mouseover" will toggle highlight on, and "mouseout" will toggle highlight off. + * @private + */ +YAHOO.widget.AutoComplete.prototype._togglePrehighlight = function(oNewItem, sType) { + if(oNewItem == this._oCurItem) { + return; + } + + var sPrehighlight = this.prehighlightClassName; + if((sType == "mouseover") && sPrehighlight) { + // Apply prehighlight to new item + YAHOO.util.Dom.addClass(oNewItem, sPrehighlight); + } + else { + // Remove prehighlight from old item + YAHOO.util.Dom.removeClass(oNewItem, sPrehighlight); + } +}; + +/** + * Updates the text input box value with selected query result. If a delimiter + * has been defined, then the value gets appended with the delimiter. + * + * @method _updateValue + * @param oItem {HTMLElement} The <li> element item with which to update the value. + * @private + */ +YAHOO.widget.AutoComplete.prototype._updateValue = function(oItem) { + var oTextbox = this._oTextbox; + var sDelimChar = (this.delimChar) ? (this.delimChar[0] || this.delimChar) : null; + var sSavedQuery = this._sSavedQuery; + var sResultKey = oItem._sResultKey; + oTextbox.focus(); + + // First clear text field + oTextbox.value = ""; + // Grab data to put into text field + if(sDelimChar) { + if(sSavedQuery) { + oTextbox.value = sSavedQuery; + } + oTextbox.value += sResultKey + sDelimChar; + if(sDelimChar != " ") { + oTextbox.value += " "; + } + } + else { oTextbox.value = sResultKey; } + + // scroll to bottom of textarea if necessary + if(oTextbox.type == "textarea") { + oTextbox.scrollTop = oTextbox.scrollHeight; + } + + // move cursor to end + var end = oTextbox.value.length; + this._selectText(oTextbox,end,end); + + this._oCurItem = oItem; +}; + +/** + * Selects a result item from the container + * + * @method _selectItem + * @param oItem {HTMLElement} The selected <li> element item. + * @private + */ +YAHOO.widget.AutoComplete.prototype._selectItem = function(oItem) { + this._bItemSelected = true; + this._updateValue(oItem); + this._cancelIntervalDetection(this); + this.itemSelectEvent.fire(this, oItem, oItem._oResultData); + this._toggleContainer(false); +}; + +/** + * For values updated by type-ahead, the right arrow key jumps to the end + * of the textbox, otherwise the container is closed. + * + * @method _jumpSelection + * @private + */ +YAHOO.widget.AutoComplete.prototype._jumpSelection = function() { + if(!this.typeAhead) { + return; + } + else { + this._toggleContainer(false); + } +}; + +/** + * Triggered by up and down arrow keys, changes the current highlighted + * <li> element item. Scrolls container if necessary. + * + * @method _moveSelection + * @param nKeyCode {Number} Code of key pressed. + * @private + */ +YAHOO.widget.AutoComplete.prototype._moveSelection = function(nKeyCode) { + if(this._bContainerOpen) { + // Determine current item's id number + var oCurItem = this._oCurItem; + var nCurItemIndex = -1; + + if (oCurItem) { + nCurItemIndex = oCurItem._nItemIndex; + } + + var nNewItemIndex = (nKeyCode == 40) ? + (nCurItemIndex + 1) : (nCurItemIndex - 1); + + // Out of bounds + if (nNewItemIndex < -2 || nNewItemIndex >= this._nDisplayedItems) { + return; + } + + if (oCurItem) { + // Unhighlight current item + this._toggleHighlight(oCurItem, "from"); + this.itemArrowFromEvent.fire(this, oCurItem); + } + if (nNewItemIndex == -1) { + // Go back to query (remove type-ahead string) + if(this.delimChar && this._sSavedQuery) { + if (!this._textMatchesOption()) { + this._oTextbox.value = this._sSavedQuery; + } + else { + this._oTextbox.value = this._sSavedQuery + this._sCurQuery; + } + } + else { + this._oTextbox.value = this._sCurQuery; + } + this._oCurItem = null; + return; + } + if (nNewItemIndex == -2) { + // Close container + this._toggleContainer(false); + return; + } + + var oNewItem = this._aListItems[nNewItemIndex]; + + // Scroll the container if necessary + var oContent = this._oContainer._oContent; + var scrollOn = ((YAHOO.util.Dom.getStyle(oContent,"overflow") == "auto") || + (YAHOO.util.Dom.getStyle(oContent,"overflowY") == "auto")); + if(scrollOn && (nNewItemIndex > -1) && + (nNewItemIndex < this._nDisplayedItems)) { + // User is keying down + if(nKeyCode == 40) { + // Bottom of selected item is below scroll area... + if((oNewItem.offsetTop+oNewItem.offsetHeight) > (oContent.scrollTop + oContent.offsetHeight)) { + // Set bottom of scroll area to bottom of selected item + oContent.scrollTop = (oNewItem.offsetTop+oNewItem.offsetHeight) - oContent.offsetHeight; + } + // Bottom of selected item is above scroll area... + else if((oNewItem.offsetTop+oNewItem.offsetHeight) < oContent.scrollTop) { + // Set top of selected item to top of scroll area + oContent.scrollTop = oNewItem.offsetTop; + + } + } + // User is keying up + else { + // Top of selected item is above scroll area + if(oNewItem.offsetTop < oContent.scrollTop) { + // Set top of scroll area to top of selected item + this._oContainer._oContent.scrollTop = oNewItem.offsetTop; + } + // Top of selected item is below scroll area + else if(oNewItem.offsetTop > (oContent.scrollTop + oContent.offsetHeight)) { + // Set bottom of selected item to bottom of scroll area + this._oContainer._oContent.scrollTop = (oNewItem.offsetTop+oNewItem.offsetHeight) - oContent.offsetHeight; + } + } + } + + this._toggleHighlight(oNewItem, "to"); + this.itemArrowToEvent.fire(this, oNewItem); + if(this.typeAhead) { + this._updateValue(oNewItem); + } + } +}; + +///////////////////////////////////////////////////////////////////////////// +// +// Private event handlers +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Handles <li> element mouseover events in the container. + * + * @method _onItemMouseover + * @param v {HTMLEvent} The mouseover event. + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onItemMouseover = function(v,oSelf) { + if(oSelf.prehighlightClassName) { + oSelf._togglePrehighlight(this,"mouseover"); + } + else { + oSelf._toggleHighlight(this,"to"); + } + + oSelf.itemMouseOverEvent.fire(oSelf, this); +}; + +/** + * Handles <li> element mouseout events in the container. + * + * @method _onItemMouseout + * @param v {HTMLEvent} The mouseout event. + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onItemMouseout = function(v,oSelf) { + if(oSelf.prehighlightClassName) { + oSelf._togglePrehighlight(this,"mouseout"); + } + else { + oSelf._toggleHighlight(this,"from"); + } + + oSelf.itemMouseOutEvent.fire(oSelf, this); +}; + +/** + * Handles <li> element click events in the container. + * + * @method _onItemMouseclick + * @param v {HTMLEvent} The click event. + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onItemMouseclick = function(v,oSelf) { + // In case item has not been moused over + oSelf._toggleHighlight(this,"to"); + oSelf._selectItem(this); +}; + +/** + * Handles container mouseover events. + * + * @method _onContainerMouseover + * @param v {HTMLEvent} The mouseover event. + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onContainerMouseover = function(v,oSelf) { + oSelf._bOverContainer = true; +}; + +/** + * Handles container mouseout events. + * + * @method _onContainerMouseout + * @param v {HTMLEvent} The mouseout event. + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onContainerMouseout = function(v,oSelf) { + oSelf._bOverContainer = false; + // If container is still active + if(oSelf._oCurItem) { + oSelf._toggleHighlight(oSelf._oCurItem,"to"); + } +}; + +/** + * Handles container scroll events. + * + * @method _onContainerScroll + * @param v {HTMLEvent} The scroll event. + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onContainerScroll = function(v,oSelf) { + oSelf._oTextbox.focus(); +}; + +/** + * Handles container resize events. + * + * @method _onContainerResize + * @param v {HTMLEvent} The resize event. + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onContainerResize = function(v,oSelf) { + oSelf._toggleContainerHelpers(oSelf._bContainerOpen); +}; + + +/** + * Handles textbox keydown events of functional keys, mainly for UI behavior. + * + * @method _onTextboxKeyDown + * @param v {HTMLEvent} The keydown event. + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onTextboxKeyDown = function(v,oSelf) { + var nKeyCode = v.keyCode; + + switch (nKeyCode) { + case 9: // tab + if(oSelf.delimChar && (oSelf._nKeyCode != nKeyCode)) { + if(oSelf._bContainerOpen) { + YAHOO.util.Event.stopEvent(v); + } + } + // select an item or clear out + if(oSelf._oCurItem) { + oSelf._selectItem(oSelf._oCurItem); + } + else { + oSelf._toggleContainer(false); + } + break; + case 13: // enter + if(oSelf._nKeyCode != nKeyCode) { + if(oSelf._bContainerOpen) { + YAHOO.util.Event.stopEvent(v); + } + } + if(oSelf._oCurItem) { + oSelf._selectItem(oSelf._oCurItem); + } + else { + oSelf._toggleContainer(false); + } + break; + case 27: // esc + oSelf._toggleContainer(false); + return; + case 39: // right + oSelf._jumpSelection(); + break; + case 38: // up + YAHOO.util.Event.stopEvent(v); + oSelf._moveSelection(nKeyCode); + break; + case 40: // down + YAHOO.util.Event.stopEvent(v); + oSelf._moveSelection(nKeyCode); + break; + default: + break; + } +}; + +/** + * Handles textbox keypress events. + * @method _onTextboxKeyPress + * @param v {HTMLEvent} The keypress event. + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onTextboxKeyPress = function(v,oSelf) { + var nKeyCode = v.keyCode; + + //Expose only to Mac browsers, where stopEvent is ineffective on keydown events (bug 790337) + var isMac = (navigator.userAgent.toLowerCase().indexOf("mac") != -1); + if(isMac) { + switch (nKeyCode) { + case 9: // tab + if(oSelf.delimChar && (oSelf._nKeyCode != nKeyCode)) { + if(oSelf._bContainerOpen) { + YAHOO.util.Event.stopEvent(v); + } + } + break; + case 13: // enter + if(oSelf._nKeyCode != nKeyCode) { + if(oSelf._bContainerOpen) { + YAHOO.util.Event.stopEvent(v); + } + } + break; + case 38: // up + case 40: // down + YAHOO.util.Event.stopEvent(v); + break; + default: + break; + } + } + + //TODO: (?) limit only to non-IE, non-Mac-FF for Korean IME support (bug 811948) + // Korean IME detected + else if(nKeyCode == 229) { + oSelf._queryInterval = setInterval(function() { oSelf._onIMEDetected(oSelf); },500); + } +}; + +/** + * Handles textbox keyup events that trigger queries. + * + * @method _onTextboxKeyUp + * @param v {HTMLEvent} The keyup event. + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onTextboxKeyUp = function(v,oSelf) { + // Check to see if any of the public properties have been updated + oSelf._initProps(); + + var nKeyCode = v.keyCode; + oSelf._nKeyCode = nKeyCode; + var sText = this.value; //string in textbox + + // Filter out chars that don't trigger queries + if (oSelf._isIgnoreKey(nKeyCode) || (sText.toLowerCase() == oSelf._sCurQuery)) { + return; + } + else { + oSelf.textboxKeyEvent.fire(oSelf, nKeyCode); + } + + // Set timeout on the request + if (oSelf.queryDelay > 0) { + var nDelayID = + setTimeout(function(){oSelf._sendQuery(sText);},(oSelf.queryDelay * 1000)); + + if (oSelf._nDelayID != -1) { + clearTimeout(oSelf._nDelayID); + } + + oSelf._nDelayID = nDelayID; + } + else { + // No delay so send request immediately + oSelf._sendQuery(sText); + } +}; + +/** + * Handles text input box receiving focus. + * + * @method _onTextboxFocus + * @param v {HTMLEvent} The focus event. + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onTextboxFocus = function (v,oSelf) { + oSelf._oTextbox.setAttribute("autocomplete","off"); + oSelf._bFocused = true; + oSelf.textboxFocusEvent.fire(oSelf); +}; + +/** + * Handles text input box losing focus. + * + * @method _onTextboxBlur + * @param v {HTMLEvent} The focus event. + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onTextboxBlur = function (v,oSelf) { + // Don't treat as a blur if it was a selection via mouse click + if(!oSelf._bOverContainer || (oSelf._nKeyCode == 9)) { + // Current query needs to be validated + if(!oSelf._bItemSelected) { + if(!oSelf._bContainerOpen || (oSelf._bContainerOpen && !oSelf._textMatchesOption())) { + if(oSelf.forceSelection) { + oSelf._clearSelection(); + } + else { + oSelf.unmatchedItemSelectEvent.fire(oSelf, oSelf._sCurQuery); + } + } + } + + if(oSelf._bContainerOpen) { + oSelf._toggleContainer(false); + } + oSelf._cancelIntervalDetection(oSelf); + oSelf._bFocused = false; + oSelf.textboxBlurEvent.fire(oSelf); + } +}; + +/** + * Handles form submission event. + * + * @method _onFormSubmit + * @param v {HTMLEvent} The submit event. + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onFormSubmit = function(v,oSelf) { + if(oSelf.allowBrowserAutocomplete) { + oSelf._oTextbox.setAttribute("autocomplete","on"); + } + else { + oSelf._oTextbox.setAttribute("autocomplete","off"); + } +}; + +/****************************************************************************/ +/****************************************************************************/ +/****************************************************************************/ + +/** + * The DataSource classes manages sending a request and returning response from a live + * database. Supported data include local JavaScript arrays and objects and databases + * accessible via XHR connections. Supported response formats include JavaScript arrays, + * JSON, XML, and flat-file textual data. + * + * @class DataSource + * @constructor + */ +YAHOO.widget.DataSource = function() { + /* abstract class */ +}; + + +///////////////////////////////////////////////////////////////////////////// +// +// Public constants +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Error message for null data responses. + * + * @property ERROR_DATANULL + * @type String + * @static + * @final + */ +YAHOO.widget.DataSource.ERROR_DATANULL = "Response data was null"; + +/** + * Error message for data responses with parsing errors. + * + * @property ERROR_DATAPARSE + * @type String + * @static + * @final + */ +YAHOO.widget.DataSource.ERROR_DATAPARSE = "Response data could not be parsed"; + + +///////////////////////////////////////////////////////////////////////////// +// +// Public member variables +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Max size of the local cache. Set to 0 to turn off caching. Caching is + * useful to reduce the number of server connections. Recommended only for data + * sources that return comprehensive results for queries or when stale data is + * not an issue. + * + * @property maxCacheEntries + * @type Number + * @default 15 + */ +YAHOO.widget.DataSource.prototype.maxCacheEntries = 15; + +/** + * Use this to equate cache matching with the type of matching done by your live + * data source. If caching is on and queryMatchContains is true, the cache + * returns results that "contain" the query string. By default, + * queryMatchContains is set to false, meaning the cache only returns results + * that "start with" the query string. + * + * @property queryMatchContains + * @type Boolean + * @default false + */ +YAHOO.widget.DataSource.prototype.queryMatchContains = false; + +/** + * Enables query subset matching. If caching is on and queryMatchSubset is + * true, substrings of queries will return matching cached results. For + * instance, if the first query is for "abc" susequent queries that start with + * "abc", like "abcd", will be queried against the cache, and not the live data + * source. Recommended only for DataSources that return comprehensive results + * for queries with very few characters. + * + * @property queryMatchSubset + * @type Boolean + * @default false + * + */ +YAHOO.widget.DataSource.prototype.queryMatchSubset = false; + +/** + * Enables query case-sensitivity matching. If caching is on and + * queryMatchCase is true, queries will only return results for case-sensitive + * matches. + * + * @property queryMatchCase + * @type Boolean + * @default false + */ +YAHOO.widget.DataSource.prototype.queryMatchCase = false; + + +///////////////////////////////////////////////////////////////////////////// +// +// Public methods +// +///////////////////////////////////////////////////////////////////////////// + + /** + * Public accessor to the unique name of the DataSource instance. + * + * @method toString + * @return {String} Unique name of the DataSource instance + */ +YAHOO.widget.DataSource.prototype.toString = function() { + return "DataSource " + this._sName; +}; + +/** + * Retrieves query results, first checking the local cache, then making the + * query request to the live data source as defined by the function doQuery. + * + * @method getResults + * @param oCallbackFn {HTMLFunction} Callback function defined by oParent object to which to return results. + * @param sQuery {String} Query string. + * @param oParent {Object} The object instance that has requested data. + */ +YAHOO.widget.DataSource.prototype.getResults = function(oCallbackFn, sQuery, oParent) { + + // First look in cache + var aResults = this._doQueryCache(oCallbackFn,sQuery,oParent); + + // Not in cache, so get results from server + if(aResults.length === 0) { + this.queryEvent.fire(this, oParent, sQuery); + this.doQuery(oCallbackFn, sQuery, oParent); + } +}; + +/** + * Abstract method implemented by subclasses to make a query to the live data + * source. Must call the callback function with the response returned from the + * query. Populates cache (if enabled). + * + * @method doQuery + * @param oCallbackFn {HTMLFunction} Callback function implemented by oParent to which to return results. + * @param sQuery {String} Query string. + * @param oParent {Object} The object instance that has requested data. + */ +YAHOO.widget.DataSource.prototype.doQuery = function(oCallbackFn, sQuery, oParent) { + /* override this */ +}; + +/** + * Flushes cache. + * + * @method flushCache + */ +YAHOO.widget.DataSource.prototype.flushCache = function() { + if(this._aCache) { + this._aCache = []; + } + if(this._aCacheHelper) { + this._aCacheHelper = []; + } + this.cacheFlushEvent.fire(this); +}; + +///////////////////////////////////////////////////////////////////////////// +// +// Public events +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Fired when a query is made to the live data source. + * + * @event queryEvent + * @param oSelf {Object} The DataSource instance. + * @param oParent {Object} The requesting object. + * @param sQuery {String} The query string. + */ +YAHOO.widget.DataSource.prototype.queryEvent = null; + +/** + * Fired when a query is made to the local cache. + * + * @event cacheQueryEvent + * @param oSelf {Object} The DataSource instance. + * @param oParent {Object} The requesting object. + * @param sQuery {String} The query string. + */ +YAHOO.widget.DataSource.prototype.cacheQueryEvent = null; + +/** + * Fired when data is retrieved from the live data source. + * + * @event getResultsEvent + * @param oSelf {Object} The DataSource instance. + * @param oParent {Object} The requesting object. + * @param sQuery {String} The query string. + * @param aResults {Object[]} Array of result objects. + */ +YAHOO.widget.DataSource.prototype.getResultsEvent = null; + +/** + * Fired when data is retrieved from the local cache. + * + * @event getCachedResultsEvent + * @param oSelf {Object} The DataSource instance. + * @param oParent {Object} The requesting object. + * @param sQuery {String} The query string. + * @param aResults {Object[]} Array of result objects. + */ +YAHOO.widget.DataSource.prototype.getCachedResultsEvent = null; + +/** + * Fired when an error is encountered with the live data source. + * + * @event dataErrorEvent + * @param oSelf {Object} The DataSource instance. + * @param oParent {Object} The requesting object. + * @param sQuery {String} The query string. + * @param sMsg {String} Error message string + */ +YAHOO.widget.DataSource.prototype.dataErrorEvent = null; + +/** + * Fired when the local cache is flushed. + * + * @event cacheFlushEvent + * @param oSelf {Object} The DataSource instance + */ +YAHOO.widget.DataSource.prototype.cacheFlushEvent = null; + +///////////////////////////////////////////////////////////////////////////// +// +// Private member variables +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Internal class variable to index multiple DataSource instances. + * + * @property _nIndex + * @type Number + * @private + * @static + */ +YAHOO.widget.DataSource._nIndex = 0; + +/** + * Name of DataSource instance. + * + * @property _sName + * @type String + * @private + */ +YAHOO.widget.DataSource.prototype._sName = null; + +/** + * Local cache of data result objects indexed chronologically. + * + * @property _aCache + * @type Object[] + * @private + */ +YAHOO.widget.DataSource.prototype._aCache = null; + + +///////////////////////////////////////////////////////////////////////////// +// +// Private methods +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Initializes DataSource instance. + * + * @method _init + * @private + */ +YAHOO.widget.DataSource.prototype._init = function() { + // Validate and initialize public configs + var maxCacheEntries = this.maxCacheEntries; + if(isNaN(maxCacheEntries) || (maxCacheEntries < 0)) { + maxCacheEntries = 0; + } + // Initialize local cache + if(maxCacheEntries > 0 && !this._aCache) { + this._aCache = []; + } + + this._sName = "instance" + YAHOO.widget.DataSource._nIndex; + YAHOO.widget.DataSource._nIndex++; + + this.queryEvent = new YAHOO.util.CustomEvent("query", this); + this.cacheQueryEvent = new YAHOO.util.CustomEvent("cacheQuery", this); + this.getResultsEvent = new YAHOO.util.CustomEvent("getResults", this); + this.getCachedResultsEvent = new YAHOO.util.CustomEvent("getCachedResults", this); + this.dataErrorEvent = new YAHOO.util.CustomEvent("dataError", this); + this.cacheFlushEvent = new YAHOO.util.CustomEvent("cacheFlush", this); +}; + +/** + * Adds a result object to the local cache, evicting the oldest element if the + * cache is full. Newer items will have higher indexes, the oldest item will have + * index of 0. + * + * @method _addCacheElem + * @param oResult {Object} Data result object, including array of results. + * @private + */ +YAHOO.widget.DataSource.prototype._addCacheElem = function(oResult) { + var aCache = this._aCache; + // Don't add if anything important is missing. + if(!aCache || !oResult || !oResult.query || !oResult.results) { + return; + } + + // If the cache is full, make room by removing from index=0 + if(aCache.length >= this.maxCacheEntries) { + aCache.shift(); + } + + // Add to cache, at the end of the array + aCache.push(oResult); +}; + +/** + * Queries the local cache for results. If query has been cached, the callback + * function is called with the results, and the cached is refreshed so that it + * is now the newest element. + * + * @method _doQueryCache + * @param oCallbackFn {HTMLFunction} Callback function defined by oParent object to which to return results. + * @param sQuery {String} Query string. + * @param oParent {Object} The object instance that has requested data. + * @return aResults {Object[]} Array of results from local cache if found, otherwise null. + * @private + */ +YAHOO.widget.DataSource.prototype._doQueryCache = function(oCallbackFn, sQuery, oParent) { + var aResults = []; + var bMatchFound = false; + var aCache = this._aCache; + var nCacheLength = (aCache) ? aCache.length : 0; + var bMatchContains = this.queryMatchContains; + + // If cache is enabled... + if((this.maxCacheEntries > 0) && aCache && (nCacheLength > 0)) { + this.cacheQueryEvent.fire(this, oParent, sQuery); + // If case is unimportant, normalize query now instead of in loops + if(!this.queryMatchCase) { + var sOrigQuery = sQuery; + sQuery = sQuery.toLowerCase(); + } + + // Loop through each cached element's query property... + for(var i = nCacheLength-1; i >= 0; i--) { + var resultObj = aCache[i]; + var aAllResultItems = resultObj.results; + // If case is unimportant, normalize match key for comparison + var matchKey = (!this.queryMatchCase) ? + encodeURIComponent(resultObj.query).toLowerCase(): + encodeURIComponent(resultObj.query); + + // If a cached match key exactly matches the query... + if(matchKey == sQuery) { + // Stash all result objects into aResult[] and stop looping through the cache. + bMatchFound = true; + aResults = aAllResultItems; + + // The matching cache element was not the most recent, + // so now we need to refresh the cache. + if(i != nCacheLength-1) { + // Remove element from its original location + aCache.splice(i,1); + // Add element as newest + this._addCacheElem(resultObj); + } + break; + } + // Else if this query is not an exact match and subset matching is enabled... + else if(this.queryMatchSubset) { + // Loop through substrings of each cached element's query property... + for(var j = sQuery.length-1; j >= 0 ; j--) { + var subQuery = sQuery.substr(0,j); + + // If a substring of a cached sQuery exactly matches the query... + if(matchKey == subQuery) { + bMatchFound = true; + + // Go through each cached result object to match against the query... + for(var k = aAllResultItems.length-1; k >= 0; k--) { + var aRecord = aAllResultItems[k]; + var sKeyIndex = (this.queryMatchCase) ? + encodeURIComponent(aRecord[0]).indexOf(sQuery): + encodeURIComponent(aRecord[0]).toLowerCase().indexOf(sQuery); + + // A STARTSWITH match is when the query is found at the beginning of the key string... + if((!bMatchContains && (sKeyIndex === 0)) || + // A CONTAINS match is when the query is found anywhere within the key string... + (bMatchContains && (sKeyIndex > -1))) { + // Stash a match into aResults[]. + aResults.unshift(aRecord); + } + } + + // Add the subset match result set object as the newest element to cache, + // and stop looping through the cache. + resultObj = {}; + resultObj.query = sQuery; + resultObj.results = aResults; + this._addCacheElem(resultObj); + break; + } + } + if(bMatchFound) { + break; + } + } + } + + // If there was a match, send along the results. + if(bMatchFound) { + this.getCachedResultsEvent.fire(this, oParent, sOrigQuery, aResults); + oCallbackFn(sOrigQuery, aResults, oParent); + } + } + return aResults; +}; + + +/****************************************************************************/ +/****************************************************************************/ +/****************************************************************************/ + +/** + * Implementation of YAHOO.widget.DataSource using XML HTTP requests that return + * query results. + * + * @class DS_XHR + * @extends YAHOO.widget.DataSource + * @requires connection + * @constructor + * @param sScriptURI {String} Absolute or relative URI to script that returns query + * results as JSON, XML, or delimited flat-file data. + * @param aSchema {String[]} Data schema definition of results. + * @param oConfigs {Object} (optional) Object literal of config params. + */ +YAHOO.widget.DS_XHR = function(sScriptURI, aSchema, oConfigs) { + // Set any config params passed in to override defaults + if(typeof oConfigs == "object") { + for(var sConfig in oConfigs) { + this[sConfig] = oConfigs[sConfig]; + } + } + + // Initialization sequence + if(!aSchema || (aSchema.constructor != Array)) { + YAHOO.log("Could not instantiate XHR DataSource due to invalid arguments", "error", this.toString()); + return; + } + else { + this.schema = aSchema; + } + this.scriptURI = sScriptURI; + this._init(); + YAHOO.log("XHR DataSource initialized","info",this.toString()); +}; + +YAHOO.widget.DS_XHR.prototype = new YAHOO.widget.DataSource(); + +///////////////////////////////////////////////////////////////////////////// +// +// Public constants +// +///////////////////////////////////////////////////////////////////////////// + +/** + * JSON data type. + * + * @property TYPE_JSON + * @type Number + * @static + * @final + */ +YAHOO.widget.DS_XHR.TYPE_JSON = 0; + +/** + * XML data type. + * + * @property TYPE_XML + * @type Number + * @static + * @final + */ +YAHOO.widget.DS_XHR.TYPE_XML = 1; + +/** + * Flat-file data type. + * + * @property TYPE_FLAT + * @type Number + * @static + * @final + */ +YAHOO.widget.DS_XHR.TYPE_FLAT = 2; + +/** + * Error message for XHR failure. + * + * @property ERROR_DATAXHR + * @type String + * @static + * @final + */ +YAHOO.widget.DS_XHR.ERROR_DATAXHR = "XHR response failed"; + +///////////////////////////////////////////////////////////////////////////// +// +// Public member variables +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Alias to YUI Connection Manager. Allows implementers to specify their own + * subclasses of the YUI Connection Manager utility. + * + * @property connMgr + * @type Object + * @default YAHOO.util.Connect + */ +YAHOO.widget.DS_XHR.prototype.connMgr = YAHOO.util.Connect; + +/** + * Number of milliseconds the XHR connection will wait for a server response. A + * a value of zero indicates the XHR connection will wait forever. Any value + * greater than zero will use the Connection utility's Auto-Abort feature. + * + * @property connTimeout + * @type Number + * @default 0 + */ +YAHOO.widget.DS_XHR.prototype.connTimeout = 0; + +/** + * Absolute or relative URI to script that returns query results. For instance, + * queries will be sent to <scriptURI>?<scriptQueryParam>=userinput + * + * @property scriptURI + * @type String + */ +YAHOO.widget.DS_XHR.prototype.scriptURI = null; + +/** + * Query string parameter name sent to scriptURI. For instance, queries will be + * sent to <scriptURI>?<scriptQueryParam>=userinput + * + * @property scriptQueryParam + * @type String + * @default "query" + */ +YAHOO.widget.DS_XHR.prototype.scriptQueryParam = "query"; + +/** + * String of key/value pairs to append to requests made to scriptURI. Define + * this string when you want to send additional query parameters to your script. + * When defined, queries will be sent to + * <scriptURI>?<scriptQueryParam>=userinput&<scriptQueryAppend> + * + * @property scriptQueryAppend + * @type String + * @default "" + */ +YAHOO.widget.DS_XHR.prototype.scriptQueryAppend = ""; + +/** + * XHR response data type. Other types that may be defined are YAHOO.widget.DS_XHR.TYPE_XML + * and YAHOO.widget.DS_XHR.TYPE_FLAT. + * + * @property responseType + * @type String + * @default YAHOO.widget.DS_XHR.TYPE_JSON + */ +YAHOO.widget.DS_XHR.prototype.responseType = YAHOO.widget.DS_XHR.TYPE_JSON; + +/** + * String after which to strip results. If the results from the XHR are sent + * back as HTML, the gzip HTML comment appears at the end of the data and should + * be ignored. + * + * @property responseStripAfter + * @type String + * @default "\n<!-" + */ +YAHOO.widget.DS_XHR.prototype.responseStripAfter = "\n 0) { + sUri += "&" + this.scriptQueryAppend; + } + YAHOO.log("DataSource is querying URL " + sUri, "info", this.toString()); + var oResponse = null; + + var oSelf = this; + /* + * Sets up ajax request callback + * + * @param {object} oReq HTTPXMLRequest object + * @private + */ + var responseSuccess = function(oResp) { + // Response ID does not match last made request ID. + if(!oSelf._oConn || (oResp.tId != oSelf._oConn.tId)) { + oSelf.dataErrorEvent.fire(oSelf, oParent, sQuery, YAHOO.widget.DataSource.ERROR_DATANULL); + YAHOO.log(YAHOO.widget.DataSource.ERROR_DATANULL, "error", this.toString()); + return; + } +//DEBUG +/*YAHOO.log(oResp.responseXML.getElementsByTagName("Result"),'warn'); +for(var foo in oResp) { + YAHOO.log(foo + ": "+oResp[foo],'warn'); +} +YAHOO.log('responseXML.xml: '+oResp.responseXML.xml,'warn');*/ + if(!isXML) { + oResp = oResp.responseText; + } + else { + oResp = oResp.responseXML; + } + if(oResp === null) { + oSelf.dataErrorEvent.fire(oSelf, oParent, sQuery, YAHOO.widget.DataSource.ERROR_DATANULL); + YAHOO.log(YAHOO.widget.DataSource.ERROR_DATANULL, "error", oSelf.toString()); + return; + } + + var aResults = oSelf.parseResponse(sQuery, oResp, oParent); + var resultObj = {}; + resultObj.query = decodeURIComponent(sQuery); + resultObj.results = aResults; + if(aResults === null) { + oSelf.dataErrorEvent.fire(oSelf, oParent, sQuery, YAHOO.widget.DataSource.ERROR_DATAPARSE); + YAHOO.log(YAHOO.widget.DataSource.ERROR_DATAPARSE, "error", oSelf.toString()); + aResults = []; + } + else { + oSelf.getResultsEvent.fire(oSelf, oParent, sQuery, aResults); + oSelf._addCacheElem(resultObj); + } + oCallbackFn(sQuery, aResults, oParent); + }; + + var responseFailure = function(oResp) { + oSelf.dataErrorEvent.fire(oSelf, oParent, sQuery, YAHOO.widget.DS_XHR.ERROR_DATAXHR); + YAHOO.log(YAHOO.widget.DS_XHR.ERROR_DATAXHR + ": " + oResp.statusText, "error", oSelf.toString()); + return; + }; + + var oCallback = { + success:responseSuccess, + failure:responseFailure + }; + + if(!isNaN(this.connTimeout) && this.connTimeout > 0) { + oCallback.timeout = this.connTimeout; + } + + if(this._oConn) { + this.connMgr.abort(this._oConn); + } + + oSelf._oConn = this.connMgr.asyncRequest("GET", sUri, oCallback, null); +}; + +/** + * Parses raw response data into an array of result objects. The result data key + * is always stashed in the [0] element of each result object. + * + * @method parseResponse + * @param sQuery {String} Query string. + * @param oResponse {Object} The raw response data to parse. + * @param oParent {Object} The object instance that has requested data. + * @returns {Object[]} Array of result objects. + */ +YAHOO.widget.DS_XHR.prototype.parseResponse = function(sQuery, oResponse, oParent) { + var aSchema = this.schema; + var aResults = []; + var bError = false; + + // Strip out comment at the end of results + var nEnd = ((this.responseStripAfter !== "") && (oResponse.indexOf)) ? + oResponse.indexOf(this.responseStripAfter) : -1; + if(nEnd != -1) { + oResponse = oResponse.substring(0,nEnd); + } + + switch (this.responseType) { + case YAHOO.widget.DS_XHR.TYPE_JSON: + var jsonList; + // Divert KHTML clients from JSON lib + if(window.JSON && (navigator.userAgent.toLowerCase().indexOf('khtml')== -1)) { + // Use the JSON utility if available + var jsonObjParsed = JSON.parse(oResponse); + if(!jsonObjParsed) { + bError = true; + break; + } + else { + try { + // eval is necessary here since aSchema[0] is of unknown depth + jsonList = eval("jsonObjParsed." + aSchema[0]); + } + catch(e) { + bError = true; + break; + } + } + } + else { + // Parse the JSON response as a string + try { + // Trim leading spaces + while (oResponse.substring(0,1) == " ") { + oResponse = oResponse.substring(1, oResponse.length); + } + + // Invalid JSON response + if(oResponse.indexOf("{") < 0) { + bError = true; + break; + } + + // Empty (but not invalid) JSON response + if(oResponse.indexOf("{}") === 0) { + break; + } + + // Turn the string into an object literal... + // ...eval is necessary here + var jsonObjRaw = eval("(" + oResponse + ")"); + if(!jsonObjRaw) { + bError = true; + break; + } + + // Grab the object member that contains an array of all reponses... + // ...eval is necessary here since aSchema[0] is of unknown depth + jsonList = eval("(jsonObjRaw." + aSchema[0]+")"); + } + catch(e) { + bError = true; + break; + } + } + + if(!jsonList) { + bError = true; + break; + } + + if(jsonList.constructor != Array) { + jsonList = [jsonList]; + } + + // Loop through the array of all responses... + for(var i = jsonList.length-1; i >= 0 ; i--) { + var aResultItem = []; + var jsonResult = jsonList[i]; + // ...and loop through each data field value of each response + for(var j = aSchema.length-1; j >= 1 ; j--) { + // ...and capture data into an array mapped according to the schema... + var dataFieldValue = jsonResult[aSchema[j]]; + if(!dataFieldValue) { + dataFieldValue = ""; + } + //YAHOO.log("data: " + i + " value:" +j+" = "+dataFieldValue,"debug",this.toString()); + aResultItem.unshift(dataFieldValue); + } + // If schema isn't well defined, pass along the entire result object + if(aResultItem.length == 1) { + aResultItem.push(jsonResult); + } + // Capture the array of data field values in an array of results + aResults.unshift(aResultItem); + } + break; + case YAHOO.widget.DS_XHR.TYPE_XML: + // Get the collection of results + var xmlList = oResponse.getElementsByTagName(aSchema[0]); + if(!xmlList) { + bError = true; + break; + } + // Loop through each result + for(var k = xmlList.length-1; k >= 0 ; k--) { + var result = xmlList.item(k); + //YAHOO.log("Result"+k+" is "+result.attributes.item(0).firstChild.nodeValue,"debug",this.toString()); + var aFieldSet = []; + // Loop through each data field in each result using the schema + for(var m = aSchema.length-1; m >= 1 ; m--) { + //YAHOO.log(aSchema[m]+" is "+result.attributes.getNamedItem(aSchema[m]).firstChild.nodeValue); + var sValue = null; + // Values may be held in an attribute... + var xmlAttr = result.attributes.getNamedItem(aSchema[m]); + if(xmlAttr) { + sValue = xmlAttr.value; + //YAHOO.log("Attr value is "+sValue,"debug",this.toString()); + } + // ...or in a node + else{ + var xmlNode = result.getElementsByTagName(aSchema[m]); + if(xmlNode && xmlNode.item(0) && xmlNode.item(0).firstChild) { + sValue = xmlNode.item(0).firstChild.nodeValue; + //YAHOO.log("Node value is "+sValue,"debug",this.toString()); + } + else { + sValue = ""; + //YAHOO.log("Value not found","debug",this.toString()); + } + } + // Capture the schema-mapped data field values into an array + aFieldSet.unshift(sValue); + } + // Capture each array of values into an array of results + aResults.unshift(aFieldSet); + } + break; + case YAHOO.widget.DS_XHR.TYPE_FLAT: + if(oResponse.length > 0) { + // Delete the last line delimiter at the end of the data if it exists + var newLength = oResponse.length-aSchema[0].length; + if(oResponse.substr(newLength) == aSchema[0]) { + oResponse = oResponse.substr(0, newLength); + } + var aRecords = oResponse.split(aSchema[0]); + for(var n = aRecords.length-1; n >= 0; n--) { + aResults[n] = aRecords[n].split(aSchema[1]); + } + } + break; + default: + break; + } + sQuery = null; + oResponse = null; + oParent = null; + if(bError) { + return null; + } + else { + return aResults; + } +}; + +///////////////////////////////////////////////////////////////////////////// +// +// Private member variables +// +///////////////////////////////////////////////////////////////////////////// + +/** + * XHR connection object. + * + * @property _oConn + * @type Object + * @private + */ +YAHOO.widget.DS_XHR.prototype._oConn = null; + + +/****************************************************************************/ +/****************************************************************************/ +/****************************************************************************/ + +/** + * Implementation of YAHOO.widget.DataSource using a native Javascript function as + * its live data source. + * + * @class DS_JSFunction + * @constructor + * @extends YAHOO.widget.DataSource + * @param oFunction {HTMLFunction} In-memory Javascript function that returns query results as an array of objects. + * @param oConfigs {Object} (optional) Object literal of config params. + */ +YAHOO.widget.DS_JSFunction = function(oFunction, oConfigs) { + // Set any config params passed in to override defaults + if(typeof oConfigs == "object") { + for(var sConfig in oConfigs) { + this[sConfig] = oConfigs[sConfig]; + } + } + + // Initialization sequence + if(!oFunction || (oFunction.constructor != Function)) { + YAHOO.log("Could not instantiate JSFunction DataSource due to invalid arguments", "error", this.toString()); + return; + } + else { + this.dataFunction = oFunction; + this._init(); + YAHOO.log("JS Function DataSource initialized","info",this.toString()); + } +}; + +YAHOO.widget.DS_JSFunction.prototype = new YAHOO.widget.DataSource(); + +///////////////////////////////////////////////////////////////////////////// +// +// Public member variables +// +///////////////////////////////////////////////////////////////////////////// + +/** + * In-memory Javascript function that returns query results. + * + * @property dataFunction + * @type HTMLFunction + */ +YAHOO.widget.DS_JSFunction.prototype.dataFunction = null; + +///////////////////////////////////////////////////////////////////////////// +// +// Public methods +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Queries the live data source defined by function for results. Results are + * passed back to a callback function. + * + * @method doQuery + * @param oCallbackFn {HTMLFunction} Callback function defined by oParent object to which to return results. + * @param sQuery {String} Query string. + * @param oParent {Object} The object instance that has requested data. + */ +YAHOO.widget.DS_JSFunction.prototype.doQuery = function(oCallbackFn, sQuery, oParent) { + var oFunction = this.dataFunction; + var aResults = []; + + aResults = oFunction(sQuery); + if(aResults === null) { + this.dataErrorEvent.fire(this, oParent, sQuery, YAHOO.widget.DataSource.ERROR_DATANULL); + YAHOO.log(YAHOO.widget.DataSource.ERROR_DATANULL, "error", this.toString()); + return; + } + + var resultObj = {}; + resultObj.query = decodeURIComponent(sQuery); + resultObj.results = aResults; + this._addCacheElem(resultObj); + + this.getResultsEvent.fire(this, oParent, sQuery, aResults); + oCallbackFn(sQuery, aResults, oParent); + return; +}; + +/****************************************************************************/ +/****************************************************************************/ +/****************************************************************************/ + +/** + * Implementation of YAHOO.widget.DataSource using a native Javascript array as + * its live data source. + * + * @class DS_JSArray + * @constructor + * @extends YAHOO.widget.DataSource + * @param aData {String[]} In-memory Javascript array of simple string data. + * @param oConfigs {Object} (optional) Object literal of config params. + */ +YAHOO.widget.DS_JSArray = function(aData, oConfigs) { + // Set any config params passed in to override defaults + if(typeof oConfigs == "object") { + for(var sConfig in oConfigs) { + this[sConfig] = oConfigs[sConfig]; + } + } + + // Initialization sequence + if(!aData || (aData.constructor != Array)) { + YAHOO.log("Could not instantiate JSArray DataSource due to invalid arguments", "error", this.toString()); + return; + } + else { + this.data = aData; + this._init(); + YAHOO.log("JS Array DataSource initialized","info",this.toString()); + } +}; + +YAHOO.widget.DS_JSArray.prototype = new YAHOO.widget.DataSource(); + +///////////////////////////////////////////////////////////////////////////// +// +// Public member variables +// +///////////////////////////////////////////////////////////////////////////// + +/** + * In-memory Javascript array of strings. + * + * @property data + * @type Array + */ +YAHOO.widget.DS_JSArray.prototype.data = null; + +///////////////////////////////////////////////////////////////////////////// +// +// Public methods +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Queries the live data source defined by data for results. Results are passed + * back to a callback function. + * + * @method doQuery + * @param oCallbackFn {HTMLFunction} Callback function defined by oParent object to which to return results. + * @param sQuery {String} Query string. + * @param oParent {Object} The object instance that has requested data. + */ +YAHOO.widget.DS_JSArray.prototype.doQuery = function(oCallbackFn, sQuery, oParent) { + var aData = this.data; // the array + var aResults = []; // container for results + var bMatchFound = false; + var bMatchContains = this.queryMatchContains; + if(sQuery) { + if(!this.queryMatchCase) { + sQuery = sQuery.toLowerCase(); + } + + // Loop through each element of the array... + // which can be a string or an array of strings + for(var i = aData.length-1; i >= 0; i--) { + var aDataset = []; + + if(aData[i]) { + if(aData[i].constructor == String) { + aDataset[0] = aData[i]; + } + else if(aData[i].constructor == Array) { + aDataset = aData[i]; + } + } + + if(aDataset[0] && (aDataset[0].constructor == String)) { + var sKeyIndex = (this.queryMatchCase) ? + encodeURIComponent(aDataset[0]).indexOf(sQuery): + encodeURIComponent(aDataset[0]).toLowerCase().indexOf(sQuery); + + // A STARTSWITH match is when the query is found at the beginning of the key string... + if((!bMatchContains && (sKeyIndex === 0)) || + // A CONTAINS match is when the query is found anywhere within the key string... + (bMatchContains && (sKeyIndex > -1))) { + // Stash a match into aResults[]. + aResults.unshift(aDataset); + } + } + } + } + + this.getResultsEvent.fire(this, oParent, sQuery, aResults); + oCallbackFn(sQuery, aResults, oParent); +}; + +YAHOO.register("autocomplete", YAHOO.widget.AutoComplete, {version: "2.2.0", build: "127"}); diff --git a/interface/web/js/yui/autocomplete/autocomplete-min.js b/interface/web/js/yui/autocomplete/autocomplete-min.js new file mode 100644 index 000000000..014a7ae3f --- /dev/null +++ b/interface/web/js/yui/autocomplete/autocomplete-min.js @@ -0,0 +1,183 @@ +/* +Copyright (c) 2007, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.net/yui/license.txt +version: 2.2.0 +*/ + +YAHOO.widget.AutoComplete=function(elInput,elContainer,oDataSource,oConfigs){if(elInput&&elContainer&&oDataSource){if(oDataSource&&(oDataSource instanceof YAHOO.widget.DataSource)){this.dataSource=oDataSource;} +else{return;} +if(YAHOO.util.Dom.inDocument(elInput)){if(typeof elInput=="string"){this._sName="instance"+YAHOO.widget.AutoComplete._nIndex+" "+elInput;this._oTextbox=document.getElementById(elInput);} +else{this._sName=(elInput.id)?"instance"+YAHOO.widget.AutoComplete._nIndex+" "+elInput.id:"instance"+YAHOO.widget.AutoComplete._nIndex;this._oTextbox=elInput;}} +else{return;} +if(YAHOO.util.Dom.inDocument(elContainer)){if(typeof elContainer=="string"){this._oContainer=document.getElementById(elContainer);} +else{this._oContainer=elContainer;} +if(this._oContainer.style.display=="none"){}} +else{return;} +if(typeof oConfigs=="object"){for(var sConfig in oConfigs){if(sConfig){this[sConfig]=oConfigs[sConfig];}}} +this._initContainer();this._initProps();this._initList();this._initContainerHelpers();var oSelf=this;var oTextbox=this._oTextbox;var oContent=this._oContainer._oContent;YAHOO.util.Event.addListener(oTextbox,"keyup",oSelf._onTextboxKeyUp,oSelf);YAHOO.util.Event.addListener(oTextbox,"keydown",oSelf._onTextboxKeyDown,oSelf);YAHOO.util.Event.addListener(oTextbox,"focus",oSelf._onTextboxFocus,oSelf);YAHOO.util.Event.addListener(oTextbox,"blur",oSelf._onTextboxBlur,oSelf);YAHOO.util.Event.addListener(oContent,"mouseover",oSelf._onContainerMouseover,oSelf);YAHOO.util.Event.addListener(oContent,"mouseout",oSelf._onContainerMouseout,oSelf);YAHOO.util.Event.addListener(oContent,"scroll",oSelf._onContainerScroll,oSelf);YAHOO.util.Event.addListener(oContent,"resize",oSelf._onContainerResize,oSelf);if(oTextbox.form){YAHOO.util.Event.addListener(oTextbox.form,"submit",oSelf._onFormSubmit,oSelf);} +YAHOO.util.Event.addListener(oTextbox,"keypress",oSelf._onTextboxKeyPress,oSelf);this.textboxFocusEvent=new YAHOO.util.CustomEvent("textboxFocus",this);this.textboxKeyEvent=new YAHOO.util.CustomEvent("textboxKey",this);this.dataRequestEvent=new YAHOO.util.CustomEvent("dataRequest",this);this.dataReturnEvent=new YAHOO.util.CustomEvent("dataReturn",this);this.dataErrorEvent=new YAHOO.util.CustomEvent("dataError",this);this.containerExpandEvent=new YAHOO.util.CustomEvent("containerExpand",this);this.typeAheadEvent=new YAHOO.util.CustomEvent("typeAhead",this);this.itemMouseOverEvent=new YAHOO.util.CustomEvent("itemMouseOver",this);this.itemMouseOutEvent=new YAHOO.util.CustomEvent("itemMouseOut",this);this.itemArrowToEvent=new YAHOO.util.CustomEvent("itemArrowTo",this);this.itemArrowFromEvent=new YAHOO.util.CustomEvent("itemArrowFrom",this);this.itemSelectEvent=new YAHOO.util.CustomEvent("itemSelect",this);this.unmatchedItemSelectEvent=new YAHOO.util.CustomEvent("unmatchedItemSelect",this);this.selectionEnforceEvent=new YAHOO.util.CustomEvent("selectionEnforce",this);this.containerCollapseEvent=new YAHOO.util.CustomEvent("containerCollapse",this);this.textboxBlurEvent=new YAHOO.util.CustomEvent("textboxBlur",this);oTextbox.setAttribute("autocomplete","off");YAHOO.widget.AutoComplete._nIndex++;} +else{}};YAHOO.widget.AutoComplete.prototype.dataSource=null;YAHOO.widget.AutoComplete.prototype.minQueryLength=1;YAHOO.widget.AutoComplete.prototype.maxResultsDisplayed=10;YAHOO.widget.AutoComplete.prototype.queryDelay=0.5;YAHOO.widget.AutoComplete.prototype.highlightClassName="yui-ac-highlight";YAHOO.widget.AutoComplete.prototype.prehighlightClassName=null;YAHOO.widget.AutoComplete.prototype.delimChar=null;YAHOO.widget.AutoComplete.prototype.autoHighlight=true;YAHOO.widget.AutoComplete.prototype.typeAhead=false;YAHOO.widget.AutoComplete.prototype.animHoriz=false;YAHOO.widget.AutoComplete.prototype.animVert=true;YAHOO.widget.AutoComplete.prototype.animSpeed=0.3;YAHOO.widget.AutoComplete.prototype.forceSelection=false;YAHOO.widget.AutoComplete.prototype.allowBrowserAutocomplete=true;YAHOO.widget.AutoComplete.prototype.alwaysShowContainer=false;YAHOO.widget.AutoComplete.prototype.useIFrame=false;YAHOO.widget.AutoComplete.prototype.useShadow=false;YAHOO.widget.AutoComplete.prototype.toString=function(){return"AutoComplete "+this._sName;};YAHOO.widget.AutoComplete.prototype.isContainerOpen=function(){return this._bContainerOpen;};YAHOO.widget.AutoComplete.prototype.getListItems=function(){return this._aListItems;};YAHOO.widget.AutoComplete.prototype.getListItemData=function(oListItem){if(oListItem._oResultData){return oListItem._oResultData;} +else{return false;}};YAHOO.widget.AutoComplete.prototype.setHeader=function(sHeader){if(sHeader){if(this._oContainer._oContent._oHeader){this._oContainer._oContent._oHeader.innerHTML=sHeader;this._oContainer._oContent._oHeader.style.display="block";}} +else{this._oContainer._oContent._oHeader.innerHTML="";this._oContainer._oContent._oHeader.style.display="none";}};YAHOO.widget.AutoComplete.prototype.setFooter=function(sFooter){if(sFooter){if(this._oContainer._oContent._oFooter){this._oContainer._oContent._oFooter.innerHTML=sFooter;this._oContainer._oContent._oFooter.style.display="block";}} +else{this._oContainer._oContent._oFooter.innerHTML="";this._oContainer._oContent._oFooter.style.display="none";}};YAHOO.widget.AutoComplete.prototype.setBody=function(sBody){if(sBody){if(this._oContainer._oContent._oBody){this._oContainer._oContent._oBody.innerHTML=sBody;this._oContainer._oContent._oBody.style.display="block";this._oContainer._oContent.style.display="block";}} +else{this._oContainer._oContent._oBody.innerHTML="";this._oContainer._oContent.style.display="none";} +this._maxResultsDisplayed=0;};YAHOO.widget.AutoComplete.prototype.formatResult=function(oResultItem,sQuery){var sResult=oResultItem[0];if(sResult){return sResult;} +else{return"";}};YAHOO.widget.AutoComplete.prototype.doBeforeExpandContainer=function(oResultItem,sQuery){return true;};YAHOO.widget.AutoComplete.prototype.sendQuery=function(sQuery){this._sendQuery(sQuery);};YAHOO.widget.AutoComplete.prototype.textboxFocusEvent=null;YAHOO.widget.AutoComplete.prototype.textboxKeyEvent=null;YAHOO.widget.AutoComplete.prototype.dataRequestEvent=null;YAHOO.widget.AutoComplete.prototype.dataReturnEvent=null;YAHOO.widget.AutoComplete.prototype.dataErrorEvent=null;YAHOO.widget.AutoComplete.prototype.containerExpandEvent=null;YAHOO.widget.AutoComplete.prototype.typeAheadEvent=null;YAHOO.widget.AutoComplete.prototype.itemMouseOverEvent=null;YAHOO.widget.AutoComplete.prototype.itemMouseOutEvent=null;YAHOO.widget.AutoComplete.prototype.itemArrowToEvent=null;YAHOO.widget.AutoComplete.prototype.itemArrowFromEvent=null;YAHOO.widget.AutoComplete.prototype.itemSelectEvent=null;YAHOO.widget.AutoComplete.prototype.unmatchedItemSelectEvent=null;YAHOO.widget.AutoComplete.prototype.selectionEnforceEvent=null;YAHOO.widget.AutoComplete.prototype.containerCollapseEvent=null;YAHOO.widget.AutoComplete.prototype.textboxBlurEvent=null;YAHOO.widget.AutoComplete._nIndex=0;YAHOO.widget.AutoComplete.prototype._sName=null;YAHOO.widget.AutoComplete.prototype._oTextbox=null;YAHOO.widget.AutoComplete.prototype._bFocused=true;YAHOO.widget.AutoComplete.prototype._oAnim=null;YAHOO.widget.AutoComplete.prototype._oContainer=null;YAHOO.widget.AutoComplete.prototype._bContainerOpen=false;YAHOO.widget.AutoComplete.prototype._bOverContainer=false;YAHOO.widget.AutoComplete.prototype._aListItems=null;YAHOO.widget.AutoComplete.prototype._nDisplayedItems=0;YAHOO.widget.AutoComplete.prototype._maxResultsDisplayed=0;YAHOO.widget.AutoComplete.prototype._sCurQuery=null;YAHOO.widget.AutoComplete.prototype._sSavedQuery=null;YAHOO.widget.AutoComplete.prototype._oCurItem=null;YAHOO.widget.AutoComplete.prototype._bItemSelected=false;YAHOO.widget.AutoComplete.prototype._nKeyCode=null;YAHOO.widget.AutoComplete.prototype._nDelayID=-1;YAHOO.widget.AutoComplete.prototype._iFrameSrc="javascript:false;";YAHOO.widget.AutoComplete.prototype._queryInterval=null;YAHOO.widget.AutoComplete.prototype._sLastTextboxValue=null;YAHOO.widget.AutoComplete.prototype._initProps=function(){var minQueryLength=this.minQueryLength;if(isNaN(minQueryLength)||(minQueryLength<1)){minQueryLength=1;} +var maxResultsDisplayed=this.maxResultsDisplayed;if(isNaN(this.maxResultsDisplayed)||(this.maxResultsDisplayed<1)){this.maxResultsDisplayed=10;} +var queryDelay=this.queryDelay;if(isNaN(this.queryDelay)||(this.queryDelay<0)){this.queryDelay=0.5;} +var aDelimChar=(this.delimChar)?this.delimChar:null;if(aDelimChar){if(typeof aDelimChar=="string"){this.delimChar=[aDelimChar];} +else if(aDelimChar.constructor!=Array){this.delimChar=null;}} +var animSpeed=this.animSpeed;if((this.animHoriz||this.animVert)&&YAHOO.util.Anim){if(isNaN(animSpeed)||(animSpeed<0)){animSpeed=0.3;} +if(!this._oAnim){oAnim=new YAHOO.util.Anim(this._oContainer._oContent,{},this.animSpeed);this._oAnim=oAnim;} +else{this._oAnim.duration=animSpeed;}} +if(this.forceSelection&&this.delimChar){}};YAHOO.widget.AutoComplete.prototype._initContainerHelpers=function(){if(this.useShadow&&!this._oContainer._oShadow){var oShadow=document.createElement("div");oShadow.className="yui-ac-shadow";this._oContainer._oShadow=this._oContainer.appendChild(oShadow);} +if(this.useIFrame&&!this._oContainer._oIFrame){var oIFrame=document.createElement("iframe");oIFrame.src=this._iFrameSrc;oIFrame.frameBorder=0;oIFrame.scrolling="no";oIFrame.style.position="absolute";oIFrame.style.width="100%";oIFrame.style.height="100%";oIFrame.tabIndex=-1;this._oContainer._oIFrame=this._oContainer.appendChild(oIFrame);}};YAHOO.widget.AutoComplete.prototype._initContainer=function(){if(!this._oContainer._oContent){var oContent=document.createElement("div");oContent.className="yui-ac-content";oContent.style.display="none";this._oContainer._oContent=this._oContainer.appendChild(oContent);var oHeader=document.createElement("div");oHeader.className="yui-ac-hd";oHeader.style.display="none";this._oContainer._oContent._oHeader=this._oContainer._oContent.appendChild(oHeader);var oBody=document.createElement("div");oBody.className="yui-ac-bd";this._oContainer._oContent._oBody=this._oContainer._oContent.appendChild(oBody);var oFooter=document.createElement("div");oFooter.className="yui-ac-ft";oFooter.style.display="none";this._oContainer._oContent._oFooter=this._oContainer._oContent.appendChild(oFooter);} +else{}};YAHOO.widget.AutoComplete.prototype._initList=function(){this._aListItems=[];while(this._oContainer._oContent._oBody.hasChildNodes()){var oldListItems=this.getListItems();if(oldListItems){for(var oldi=oldListItems.length-1;oldi>=0;i--){oldListItems[oldi]=null;}} +this._oContainer._oContent._oBody.innerHTML="";} +var oList=document.createElement("ul");oList=this._oContainer._oContent._oBody.appendChild(oList);for(var i=0;i=18&&nKeyCode<=20)||(nKeyCode==27)||(nKeyCode>=33&&nKeyCode<=35)||(nKeyCode>=36&&nKeyCode<=38)||(nKeyCode==40)||(nKeyCode>=44&&nKeyCode<=45)){return true;} +return false;};YAHOO.widget.AutoComplete.prototype._sendQuery=function(sQuery){if(this.minQueryLength==-1){this._toggleContainer(false);return;} +var aDelimChar=(this.delimChar)?this.delimChar:null;if(aDelimChar){var nDelimIndex=-1;for(var i=aDelimChar.length-1;i>=0;i--){var nNewIndex=sQuery.lastIndexOf(aDelimChar[i]);if(nNewIndex>nDelimIndex){nDelimIndex=nNewIndex;}} +if(aDelimChar[i]==" "){for(var j=aDelimChar.length-1;j>=0;j--){if(sQuery[nDelimIndex-1]==aDelimChar[j]){nDelimIndex--;break;}}} +if(nDelimIndex>-1){var nQueryStart=nDelimIndex+1;while(sQuery.charAt(nQueryStart)==" "){nQueryStart+=1;} +this._sSavedQuery=sQuery.substring(0,nQueryStart);sQuery=sQuery.substr(nQueryStart);} +else if(sQuery.indexOf(this._sSavedQuery)<0){this._sSavedQuery=null;}} +if(sQuery&&(sQuery.length0)){if(this._nDelayID!=-1){clearTimeout(this._nDelayID);} +this._toggleContainer(false);return;} +sQuery=encodeURIComponent(sQuery);this._nDelayID=-1;this.dataRequestEvent.fire(this,sQuery);this.dataSource.getResults(this._populateList,sQuery,this);};YAHOO.widget.AutoComplete.prototype._populateList=function(sQuery,aResults,oSelf){if(aResults===null){oSelf.dataErrorEvent.fire(oSelf,sQuery);} +if(!oSelf._bFocused||!aResults){return;} +var isOpera=(navigator.userAgent.toLowerCase().indexOf("opera")!=-1);var contentStyle=oSelf._oContainer._oContent.style;contentStyle.width=(!isOpera)?null:"";contentStyle.height=(!isOpera)?null:"";var sCurQuery=decodeURIComponent(sQuery);oSelf._sCurQuery=sCurQuery;oSelf._bItemSelected=false;if(oSelf._maxResultsDisplayed!=oSelf.maxResultsDisplayed){oSelf._initList();} +var nItems=Math.min(aResults.length,oSelf.maxResultsDisplayed);oSelf._nDisplayedItems=nItems;if(nItems>0){oSelf._initContainerHelpers();var aItems=oSelf._aListItems;for(var i=nItems-1;i>=0;i--){var oItemi=aItems[i];var oResultItemi=aResults[i];oItemi.innerHTML=oSelf.formatResult(oResultItemi,sCurQuery);oItemi.style.display="list-item";oItemi._sResultKey=oResultItemi[0];oItemi._oResultData=oResultItemi;} +for(var j=aItems.length-1;j>=nItems;j--){var oItemj=aItems[j];oItemj.innerHTML=null;oItemj.style.display="none";oItemj._sResultKey=null;oItemj._oResultData=null;} +if(oSelf.autoHighlight){var oFirstItem=aItems[0];oSelf._toggleHighlight(oFirstItem,"to");oSelf.itemArrowToEvent.fire(oSelf,oFirstItem);oSelf._typeAhead(oFirstItem,sQuery);} +else{oSelf._oCurItem=null;} +var ok=oSelf.doBeforeExpandContainer(oSelf._oTextbox,oSelf._oContainer,sQuery,aResults);oSelf._toggleContainer(ok);} +else{oSelf._toggleContainer(false);} +oSelf.dataReturnEvent.fire(oSelf,sQuery,aResults);};YAHOO.widget.AutoComplete.prototype._clearSelection=function(){var sValue=this._oTextbox.value;var sChar=(this.delimChar)?this.delimChar[0]:null;var nIndex=(sChar)?sValue.lastIndexOf(sChar,sValue.length-2):-1;if(nIndex>-1){this._oTextbox.value=sValue.substring(0,nIndex);} +else{this._oTextbox.value="";} +this._sSavedQuery=this._oTextbox.value;this.selectionEnforceEvent.fire(this);};YAHOO.widget.AutoComplete.prototype._textMatchesOption=function(){var foundMatch=false;for(var i=this._nDisplayedItems-1;i>=0;i--){var oItem=this._aListItems[i];var sMatch=oItem._sResultKey.toLowerCase();if(sMatch==this._sCurQuery.toLowerCase()){foundMatch=true;break;}} +return(foundMatch);};YAHOO.widget.AutoComplete.prototype._typeAhead=function(oItem,sQuery){if(!this.typeAhead||(this._nKeyCode==8)){return;} +var oTextbox=this._oTextbox;var sValue=this._oTextbox.value;if(!oTextbox.setSelectionRange&&!oTextbox.createTextRange){return;} +var nStart=sValue.length;this._updateValue(oItem);var nEnd=oTextbox.value.length;this._selectText(oTextbox,nStart,nEnd);var sPrefill=oTextbox.value.substr(nStart,nEnd);this.typeAheadEvent.fire(this,sQuery,sPrefill);};YAHOO.widget.AutoComplete.prototype._selectText=function(oTextbox,nStart,nEnd){if(oTextbox.setSelectionRange){oTextbox.setSelectionRange(nStart,nEnd);} +else if(oTextbox.createTextRange){var oTextRange=oTextbox.createTextRange();oTextRange.moveStart("character",nStart);oTextRange.moveEnd("character",nEnd-oTextbox.value.length);oTextRange.select();} +else{oTextbox.select();}};YAHOO.widget.AutoComplete.prototype._toggleContainerHelpers=function(bShow){var bFireEvent=false;var width=this._oContainer._oContent.offsetWidth+"px";var height=this._oContainer._oContent.offsetHeight+"px";if(this.useIFrame&&this._oContainer._oIFrame){bFireEvent=true;if(bShow){this._oContainer._oIFrame.style.width=width;this._oContainer._oIFrame.style.height=height;} +else{this._oContainer._oIFrame.style.width=0;this._oContainer._oIFrame.style.height=0;}} +if(this.useShadow&&this._oContainer._oShadow){bFireEvent=true;if(bShow){this._oContainer._oShadow.style.width=width;this._oContainer._oShadow.style.height=height;} +else{this._oContainer._oShadow.style.width=0;this._oContainer._oShadow.style.height=0;}}};YAHOO.widget.AutoComplete.prototype._toggleContainer=function(bShow){var oContainer=this._oContainer;if(this.alwaysShowContainer&&this._bContainerOpen){return;} +if(!bShow){this._oContainer._oContent.scrollTop=0;var aItems=this._aListItems;if(aItems&&(aItems.length>0)){for(var i=aItems.length-1;i>=0;i--){aItems[i].style.display="none";}} +if(this._oCurItem){this._toggleHighlight(this._oCurItem,"from");} +this._oCurItem=null;this._nDisplayedItems=0;this._sCurQuery=null;} +if(!bShow&&!this._bContainerOpen){oContainer._oContent.style.display="none";return;} +var oAnim=this._oAnim;if(oAnim&&oAnim.getEl()&&(this.animHoriz||this.animVert)){if(!bShow){this._toggleContainerHelpers(bShow);} +if(oAnim.isAnimated()){oAnim.stop();} +var oClone=oContainer._oContent.cloneNode(true);oContainer.appendChild(oClone);oClone.style.top="-9000px";oClone.style.display="block";var wExp=oClone.offsetWidth;var hExp=oClone.offsetHeight;var wColl=(this.animHoriz)?0:wExp;var hColl=(this.animVert)?0:hExp;oAnim.attributes=(bShow)?{width:{to:wExp},height:{to:hExp}}:{width:{to:wColl},height:{to:hColl}};if(bShow&&!this._bContainerOpen){oContainer._oContent.style.width=wColl+"px";oContainer._oContent.style.height=hColl+"px";} +else{oContainer._oContent.style.width=wExp+"px";oContainer._oContent.style.height=hExp+"px";} +oContainer.removeChild(oClone);oClone=null;var oSelf=this;var onAnimComplete=function(){oAnim.onComplete.unsubscribeAll();if(bShow){oSelf.containerExpandEvent.fire(oSelf);} +else{oContainer._oContent.style.display="none";oSelf.containerCollapseEvent.fire(oSelf);} +oSelf._toggleContainerHelpers(bShow);};oContainer._oContent.style.display="block";oAnim.onComplete.subscribe(onAnimComplete);oAnim.animate();this._bContainerOpen=bShow;} +else{if(bShow){oContainer._oContent.style.display="block";this.containerExpandEvent.fire(this);} +else{oContainer._oContent.style.display="none";this.containerCollapseEvent.fire(this);} +this._toggleContainerHelpers(bShow);this._bContainerOpen=bShow;}};YAHOO.widget.AutoComplete.prototype._toggleHighlight=function(oNewItem,sType){var sHighlight=this.highlightClassName;if(this._oCurItem){YAHOO.util.Dom.removeClass(this._oCurItem,sHighlight);} +if((sType=="to")&&sHighlight){YAHOO.util.Dom.addClass(oNewItem,sHighlight);this._oCurItem=oNewItem;}};YAHOO.widget.AutoComplete.prototype._togglePrehighlight=function(oNewItem,sType){if(oNewItem==this._oCurItem){return;} +var sPrehighlight=this.prehighlightClassName;if((sType=="mouseover")&&sPrehighlight){YAHOO.util.Dom.addClass(oNewItem,sPrehighlight);} +else{YAHOO.util.Dom.removeClass(oNewItem,sPrehighlight);}};YAHOO.widget.AutoComplete.prototype._updateValue=function(oItem){var oTextbox=this._oTextbox;var sDelimChar=(this.delimChar)?(this.delimChar[0]||this.delimChar):null;var sSavedQuery=this._sSavedQuery;var sResultKey=oItem._sResultKey;oTextbox.focus();oTextbox.value="";if(sDelimChar){if(sSavedQuery){oTextbox.value=sSavedQuery;} +oTextbox.value+=sResultKey+sDelimChar;if(sDelimChar!=" "){oTextbox.value+=" ";}} +else{oTextbox.value=sResultKey;} +if(oTextbox.type=="textarea"){oTextbox.scrollTop=oTextbox.scrollHeight;} +var end=oTextbox.value.length;this._selectText(oTextbox,end,end);this._oCurItem=oItem;};YAHOO.widget.AutoComplete.prototype._selectItem=function(oItem){this._bItemSelected=true;this._updateValue(oItem);this._cancelIntervalDetection(this);this.itemSelectEvent.fire(this,oItem,oItem._oResultData);this._toggleContainer(false);};YAHOO.widget.AutoComplete.prototype._jumpSelection=function(){if(!this.typeAhead){return;} +else{this._toggleContainer(false);}};YAHOO.widget.AutoComplete.prototype._moveSelection=function(nKeyCode){if(this._bContainerOpen){var oCurItem=this._oCurItem;var nCurItemIndex=-1;if(oCurItem){nCurItemIndex=oCurItem._nItemIndex;} +var nNewItemIndex=(nKeyCode==40)?(nCurItemIndex+1):(nCurItemIndex-1);if(nNewItemIndex<-2||nNewItemIndex>=this._nDisplayedItems){return;} +if(oCurItem){this._toggleHighlight(oCurItem,"from");this.itemArrowFromEvent.fire(this,oCurItem);} +if(nNewItemIndex==-1){if(this.delimChar&&this._sSavedQuery){if(!this._textMatchesOption()){this._oTextbox.value=this._sSavedQuery;} +else{this._oTextbox.value=this._sSavedQuery+this._sCurQuery;}} +else{this._oTextbox.value=this._sCurQuery;} +this._oCurItem=null;return;} +if(nNewItemIndex==-2){this._toggleContainer(false);return;} +var oNewItem=this._aListItems[nNewItemIndex];var oContent=this._oContainer._oContent;var scrollOn=((YAHOO.util.Dom.getStyle(oContent,"overflow")=="auto")||(YAHOO.util.Dom.getStyle(oContent,"overflowY")=="auto"));if(scrollOn&&(nNewItemIndex>-1)&&(nNewItemIndex(oContent.scrollTop+oContent.offsetHeight)){oContent.scrollTop=(oNewItem.offsetTop+oNewItem.offsetHeight)-oContent.offsetHeight;} +else if((oNewItem.offsetTop+oNewItem.offsetHeight)(oContent.scrollTop+oContent.offsetHeight)){this._oContainer._oContent.scrollTop=(oNewItem.offsetTop+oNewItem.offsetHeight)-oContent.offsetHeight;}}} +this._toggleHighlight(oNewItem,"to");this.itemArrowToEvent.fire(this,oNewItem);if(this.typeAhead){this._updateValue(oNewItem);}}};YAHOO.widget.AutoComplete.prototype._onItemMouseover=function(v,oSelf){if(oSelf.prehighlightClassName){oSelf._togglePrehighlight(this,"mouseover");} +else{oSelf._toggleHighlight(this,"to");} +oSelf.itemMouseOverEvent.fire(oSelf,this);};YAHOO.widget.AutoComplete.prototype._onItemMouseout=function(v,oSelf){if(oSelf.prehighlightClassName){oSelf._togglePrehighlight(this,"mouseout");} +else{oSelf._toggleHighlight(this,"from");} +oSelf.itemMouseOutEvent.fire(oSelf,this);};YAHOO.widget.AutoComplete.prototype._onItemMouseclick=function(v,oSelf){oSelf._toggleHighlight(this,"to");oSelf._selectItem(this);};YAHOO.widget.AutoComplete.prototype._onContainerMouseover=function(v,oSelf){oSelf._bOverContainer=true;};YAHOO.widget.AutoComplete.prototype._onContainerMouseout=function(v,oSelf){oSelf._bOverContainer=false;if(oSelf._oCurItem){oSelf._toggleHighlight(oSelf._oCurItem,"to");}};YAHOO.widget.AutoComplete.prototype._onContainerScroll=function(v,oSelf){oSelf._oTextbox.focus();};YAHOO.widget.AutoComplete.prototype._onContainerResize=function(v,oSelf){oSelf._toggleContainerHelpers(oSelf._bContainerOpen);};YAHOO.widget.AutoComplete.prototype._onTextboxKeyDown=function(v,oSelf){var nKeyCode=v.keyCode;switch(nKeyCode){case 9:if(oSelf.delimChar&&(oSelf._nKeyCode!=nKeyCode)){if(oSelf._bContainerOpen){YAHOO.util.Event.stopEvent(v);}} +if(oSelf._oCurItem){oSelf._selectItem(oSelf._oCurItem);} +else{oSelf._toggleContainer(false);} +break;case 13:if(oSelf._nKeyCode!=nKeyCode){if(oSelf._bContainerOpen){YAHOO.util.Event.stopEvent(v);}} +if(oSelf._oCurItem){oSelf._selectItem(oSelf._oCurItem);} +else{oSelf._toggleContainer(false);} +break;case 27:oSelf._toggleContainer(false);return;case 39:oSelf._jumpSelection();break;case 38:YAHOO.util.Event.stopEvent(v);oSelf._moveSelection(nKeyCode);break;case 40:YAHOO.util.Event.stopEvent(v);oSelf._moveSelection(nKeyCode);break;default:break;}};YAHOO.widget.AutoComplete.prototype._onTextboxKeyPress=function(v,oSelf){var nKeyCode=v.keyCode;var isMac=(navigator.userAgent.toLowerCase().indexOf("mac")!=-1);if(isMac){switch(nKeyCode){case 9:if(oSelf.delimChar&&(oSelf._nKeyCode!=nKeyCode)){if(oSelf._bContainerOpen){YAHOO.util.Event.stopEvent(v);}} +break;case 13:if(oSelf._nKeyCode!=nKeyCode){if(oSelf._bContainerOpen){YAHOO.util.Event.stopEvent(v);}} +break;case 38:case 40:YAHOO.util.Event.stopEvent(v);break;default:break;}} +else if(nKeyCode==229){oSelf._queryInterval=setInterval(function(){oSelf._onIMEDetected(oSelf);},500);}};YAHOO.widget.AutoComplete.prototype._onTextboxKeyUp=function(v,oSelf){oSelf._initProps();var nKeyCode=v.keyCode;oSelf._nKeyCode=nKeyCode;var sText=this.value;if(oSelf._isIgnoreKey(nKeyCode)||(sText.toLowerCase()==oSelf._sCurQuery)){return;} +else{oSelf.textboxKeyEvent.fire(oSelf,nKeyCode);} +if(oSelf.queryDelay>0){var nDelayID=setTimeout(function(){oSelf._sendQuery(sText);},(oSelf.queryDelay*1000));if(oSelf._nDelayID!=-1){clearTimeout(oSelf._nDelayID);} +oSelf._nDelayID=nDelayID;} +else{oSelf._sendQuery(sText);}};YAHOO.widget.AutoComplete.prototype._onTextboxFocus=function(v,oSelf){oSelf._oTextbox.setAttribute("autocomplete","off");oSelf._bFocused=true;oSelf.textboxFocusEvent.fire(oSelf);};YAHOO.widget.AutoComplete.prototype._onTextboxBlur=function(v,oSelf){if(!oSelf._bOverContainer||(oSelf._nKeyCode==9)){if(!oSelf._bItemSelected){if(!oSelf._bContainerOpen||(oSelf._bContainerOpen&&!oSelf._textMatchesOption())){if(oSelf.forceSelection){oSelf._clearSelection();} +else{oSelf.unmatchedItemSelectEvent.fire(oSelf,oSelf._sCurQuery);}}} +if(oSelf._bContainerOpen){oSelf._toggleContainer(false);} +oSelf._cancelIntervalDetection(oSelf);oSelf._bFocused=false;oSelf.textboxBlurEvent.fire(oSelf);}};YAHOO.widget.AutoComplete.prototype._onFormSubmit=function(v,oSelf){if(oSelf.allowBrowserAutocomplete){oSelf._oTextbox.setAttribute("autocomplete","on");} +else{oSelf._oTextbox.setAttribute("autocomplete","off");}};YAHOO.widget.DataSource=function(){};YAHOO.widget.DataSource.ERROR_DATANULL="Response data was null";YAHOO.widget.DataSource.ERROR_DATAPARSE="Response data could not be parsed";YAHOO.widget.DataSource.prototype.maxCacheEntries=15;YAHOO.widget.DataSource.prototype.queryMatchContains=false;YAHOO.widget.DataSource.prototype.queryMatchSubset=false;YAHOO.widget.DataSource.prototype.queryMatchCase=false;YAHOO.widget.DataSource.prototype.toString=function(){return"DataSource "+this._sName;};YAHOO.widget.DataSource.prototype.getResults=function(oCallbackFn,sQuery,oParent){var aResults=this._doQueryCache(oCallbackFn,sQuery,oParent);if(aResults.length===0){this.queryEvent.fire(this,oParent,sQuery);this.doQuery(oCallbackFn,sQuery,oParent);}};YAHOO.widget.DataSource.prototype.doQuery=function(oCallbackFn,sQuery,oParent){};YAHOO.widget.DataSource.prototype.flushCache=function(){if(this._aCache){this._aCache=[];} +if(this._aCacheHelper){this._aCacheHelper=[];} +this.cacheFlushEvent.fire(this);};YAHOO.widget.DataSource.prototype.queryEvent=null;YAHOO.widget.DataSource.prototype.cacheQueryEvent=null;YAHOO.widget.DataSource.prototype.getResultsEvent=null;YAHOO.widget.DataSource.prototype.getCachedResultsEvent=null;YAHOO.widget.DataSource.prototype.dataErrorEvent=null;YAHOO.widget.DataSource.prototype.cacheFlushEvent=null;YAHOO.widget.DataSource._nIndex=0;YAHOO.widget.DataSource.prototype._sName=null;YAHOO.widget.DataSource.prototype._aCache=null;YAHOO.widget.DataSource.prototype._init=function(){var maxCacheEntries=this.maxCacheEntries;if(isNaN(maxCacheEntries)||(maxCacheEntries<0)){maxCacheEntries=0;} +if(maxCacheEntries>0&&!this._aCache){this._aCache=[];} +this._sName="instance"+YAHOO.widget.DataSource._nIndex;YAHOO.widget.DataSource._nIndex++;this.queryEvent=new YAHOO.util.CustomEvent("query",this);this.cacheQueryEvent=new YAHOO.util.CustomEvent("cacheQuery",this);this.getResultsEvent=new YAHOO.util.CustomEvent("getResults",this);this.getCachedResultsEvent=new YAHOO.util.CustomEvent("getCachedResults",this);this.dataErrorEvent=new YAHOO.util.CustomEvent("dataError",this);this.cacheFlushEvent=new YAHOO.util.CustomEvent("cacheFlush",this);};YAHOO.widget.DataSource.prototype._addCacheElem=function(oResult){var aCache=this._aCache;if(!aCache||!oResult||!oResult.query||!oResult.results){return;} +if(aCache.length>=this.maxCacheEntries){aCache.shift();} +aCache.push(oResult);};YAHOO.widget.DataSource.prototype._doQueryCache=function(oCallbackFn,sQuery,oParent){var aResults=[];var bMatchFound=false;var aCache=this._aCache;var nCacheLength=(aCache)?aCache.length:0;var bMatchContains=this.queryMatchContains;if((this.maxCacheEntries>0)&&aCache&&(nCacheLength>0)){this.cacheQueryEvent.fire(this,oParent,sQuery);if(!this.queryMatchCase){var sOrigQuery=sQuery;sQuery=sQuery.toLowerCase();} +for(var i=nCacheLength-1;i>=0;i--){var resultObj=aCache[i];var aAllResultItems=resultObj.results;var matchKey=(!this.queryMatchCase)?encodeURIComponent(resultObj.query).toLowerCase():encodeURIComponent(resultObj.query);if(matchKey==sQuery){bMatchFound=true;aResults=aAllResultItems;if(i!=nCacheLength-1){aCache.splice(i,1);this._addCacheElem(resultObj);} +break;} +else if(this.queryMatchSubset){for(var j=sQuery.length-1;j>=0;j--){var subQuery=sQuery.substr(0,j);if(matchKey==subQuery){bMatchFound=true;for(var k=aAllResultItems.length-1;k>=0;k--){var aRecord=aAllResultItems[k];var sKeyIndex=(this.queryMatchCase)?encodeURIComponent(aRecord[0]).indexOf(sQuery):encodeURIComponent(aRecord[0]).toLowerCase().indexOf(sQuery);if((!bMatchContains&&(sKeyIndex===0))||(bMatchContains&&(sKeyIndex>-1))){aResults.unshift(aRecord);}} +resultObj={};resultObj.query=sQuery;resultObj.results=aResults;this._addCacheElem(resultObj);break;}} +if(bMatchFound){break;}}} +if(bMatchFound){this.getCachedResultsEvent.fire(this,oParent,sOrigQuery,aResults);oCallbackFn(sOrigQuery,aResults,oParent);}} +return aResults;};YAHOO.widget.DS_XHR=function(sScriptURI,aSchema,oConfigs){if(typeof oConfigs=="object"){for(var sConfig in oConfigs){this[sConfig]=oConfigs[sConfig];}} +if(!aSchema||(aSchema.constructor!=Array)){return;} +else{this.schema=aSchema;} +this.scriptURI=sScriptURI;this._init();};YAHOO.widget.DS_XHR.prototype=new YAHOO.widget.DataSource();YAHOO.widget.DS_XHR.TYPE_JSON=0;YAHOO.widget.DS_XHR.TYPE_XML=1;YAHOO.widget.DS_XHR.TYPE_FLAT=2;YAHOO.widget.DS_XHR.ERROR_DATAXHR="XHR response failed";YAHOO.widget.DS_XHR.prototype.connMgr=YAHOO.util.Connect;YAHOO.widget.DS_XHR.prototype.connTimeout=0;YAHOO.widget.DS_XHR.prototype.scriptURI=null;YAHOO.widget.DS_XHR.prototype.scriptQueryParam="query";YAHOO.widget.DS_XHR.prototype.scriptQueryAppend="";YAHOO.widget.DS_XHR.prototype.responseType=YAHOO.widget.DS_XHR.TYPE_JSON;YAHOO.widget.DS_XHR.prototype.responseStripAfter="\n0){sUri+="&"+this.scriptQueryAppend;} +var oResponse=null;var oSelf=this;var responseSuccess=function(oResp){if(!oSelf._oConn||(oResp.tId!=oSelf._oConn.tId)){oSelf.dataErrorEvent.fire(oSelf,oParent,sQuery,YAHOO.widget.DataSource.ERROR_DATANULL);return;} +for(var foo in oResp){} +if(!isXML){oResp=oResp.responseText;} +else{oResp=oResp.responseXML;} +if(oResp===null){oSelf.dataErrorEvent.fire(oSelf,oParent,sQuery,YAHOO.widget.DataSource.ERROR_DATANULL);return;} +var aResults=oSelf.parseResponse(sQuery,oResp,oParent);var resultObj={};resultObj.query=decodeURIComponent(sQuery);resultObj.results=aResults;if(aResults===null){oSelf.dataErrorEvent.fire(oSelf,oParent,sQuery,YAHOO.widget.DataSource.ERROR_DATAPARSE);aResults=[];} +else{oSelf.getResultsEvent.fire(oSelf,oParent,sQuery,aResults);oSelf._addCacheElem(resultObj);} +oCallbackFn(sQuery,aResults,oParent);};var responseFailure=function(oResp){oSelf.dataErrorEvent.fire(oSelf,oParent,sQuery,YAHOO.widget.DS_XHR.ERROR_DATAXHR);return;};var oCallback={success:responseSuccess,failure:responseFailure};if(!isNaN(this.connTimeout)&&this.connTimeout>0){oCallback.timeout=this.connTimeout;} +if(this._oConn){this.connMgr.abort(this._oConn);} +oSelf._oConn=this.connMgr.asyncRequest("GET",sUri,oCallback,null);};YAHOO.widget.DS_XHR.prototype.parseResponse=function(sQuery,oResponse,oParent){var aSchema=this.schema;var aResults=[];var bError=false;var nEnd=((this.responseStripAfter!=="")&&(oResponse.indexOf))?oResponse.indexOf(this.responseStripAfter):-1;if(nEnd!=-1){oResponse=oResponse.substring(0,nEnd);} +switch(this.responseType){case YAHOO.widget.DS_XHR.TYPE_JSON:var jsonList;if(window.JSON&&(navigator.userAgent.toLowerCase().indexOf('khtml')==-1)){var jsonObjParsed=JSON.parse(oResponse);if(!jsonObjParsed){bError=true;break;} +else{try{jsonList=eval("jsonObjParsed."+aSchema[0]);} +catch(e){bError=true;break;}}} +else{try{while(oResponse.substring(0,1)==" "){oResponse=oResponse.substring(1,oResponse.length);} +if(oResponse.indexOf("{")<0){bError=true;break;} +if(oResponse.indexOf("{}")===0){break;} +var jsonObjRaw=eval("("+oResponse+")");if(!jsonObjRaw){bError=true;break;} +jsonList=eval("(jsonObjRaw."+aSchema[0]+")");} +catch(e){bError=true;break;}} +if(!jsonList){bError=true;break;} +if(jsonList.constructor!=Array){jsonList=[jsonList];} +for(var i=jsonList.length-1;i>=0;i--){var aResultItem=[];var jsonResult=jsonList[i];for(var j=aSchema.length-1;j>=1;j--){var dataFieldValue=jsonResult[aSchema[j]];if(!dataFieldValue){dataFieldValue="";} +aResultItem.unshift(dataFieldValue);} +if(aResultItem.length==1){aResultItem.push(jsonResult);} +aResults.unshift(aResultItem);} +break;case YAHOO.widget.DS_XHR.TYPE_XML:var xmlList=oResponse.getElementsByTagName(aSchema[0]);if(!xmlList){bError=true;break;} +for(var k=xmlList.length-1;k>=0;k--){var result=xmlList.item(k);var aFieldSet=[];for(var m=aSchema.length-1;m>=1;m--){var sValue=null;var xmlAttr=result.attributes.getNamedItem(aSchema[m]);if(xmlAttr){sValue=xmlAttr.value;} +else{var xmlNode=result.getElementsByTagName(aSchema[m]);if(xmlNode&&xmlNode.item(0)&&xmlNode.item(0).firstChild){sValue=xmlNode.item(0).firstChild.nodeValue;} +else{sValue="";}} +aFieldSet.unshift(sValue);} +aResults.unshift(aFieldSet);} +break;case YAHOO.widget.DS_XHR.TYPE_FLAT:if(oResponse.length>0){var newLength=oResponse.length-aSchema[0].length;if(oResponse.substr(newLength)==aSchema[0]){oResponse=oResponse.substr(0,newLength);} +var aRecords=oResponse.split(aSchema[0]);for(var n=aRecords.length-1;n>=0;n--){aResults[n]=aRecords[n].split(aSchema[1]);}} +break;default:break;} +sQuery=null;oResponse=null;oParent=null;if(bError){return null;} +else{return aResults;}};YAHOO.widget.DS_XHR.prototype._oConn=null;YAHOO.widget.DS_JSFunction=function(oFunction,oConfigs){if(typeof oConfigs=="object"){for(var sConfig in oConfigs){this[sConfig]=oConfigs[sConfig];}} +if(!oFunction||(oFunction.constructor!=Function)){return;} +else{this.dataFunction=oFunction;this._init();}};YAHOO.widget.DS_JSFunction.prototype=new YAHOO.widget.DataSource();YAHOO.widget.DS_JSFunction.prototype.dataFunction=null;YAHOO.widget.DS_JSFunction.prototype.doQuery=function(oCallbackFn,sQuery,oParent){var oFunction=this.dataFunction;var aResults=[];aResults=oFunction(sQuery);if(aResults===null){this.dataErrorEvent.fire(this,oParent,sQuery,YAHOO.widget.DataSource.ERROR_DATANULL);return;} +var resultObj={};resultObj.query=decodeURIComponent(sQuery);resultObj.results=aResults;this._addCacheElem(resultObj);this.getResultsEvent.fire(this,oParent,sQuery,aResults);oCallbackFn(sQuery,aResults,oParent);return;};YAHOO.widget.DS_JSArray=function(aData,oConfigs){if(typeof oConfigs=="object"){for(var sConfig in oConfigs){this[sConfig]=oConfigs[sConfig];}} +if(!aData||(aData.constructor!=Array)){return;} +else{this.data=aData;this._init();}};YAHOO.widget.DS_JSArray.prototype=new YAHOO.widget.DataSource();YAHOO.widget.DS_JSArray.prototype.data=null;YAHOO.widget.DS_JSArray.prototype.doQuery=function(oCallbackFn,sQuery,oParent){var aData=this.data;var aResults=[];var bMatchFound=false;var bMatchContains=this.queryMatchContains;if(sQuery){if(!this.queryMatchCase){sQuery=sQuery.toLowerCase();} +for(var i=aData.length-1;i>=0;i--){var aDataset=[];if(aData[i]){if(aData[i].constructor==String){aDataset[0]=aData[i];} +else if(aData[i].constructor==Array){aDataset=aData[i];}} +if(aDataset[0]&&(aDataset[0].constructor==String)){var sKeyIndex=(this.queryMatchCase)?encodeURIComponent(aDataset[0]).indexOf(sQuery):encodeURIComponent(aDataset[0]).toLowerCase().indexOf(sQuery);if((!bMatchContains&&(sKeyIndex===0))||(bMatchContains&&(sKeyIndex>-1))){aResults.unshift(aDataset);}}}} +this.getResultsEvent.fire(this,oParent,sQuery,aResults);oCallbackFn(sQuery,aResults,oParent);};YAHOO.register("autocomplete",YAHOO.widget.AutoComplete,{version:"2.2.0",build:"127"}); \ No newline at end of file diff --git a/interface/web/js/yui/autocomplete/autocomplete.js b/interface/web/js/yui/autocomplete/autocomplete.js new file mode 100644 index 000000000..2f10829f8 --- /dev/null +++ b/interface/web/js/yui/autocomplete/autocomplete.js @@ -0,0 +1,3071 @@ +/* +Copyright (c) 2007, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.net/yui/license.txt +version: 2.2.0 +*/ + /** + * The AutoComplete control provides the front-end logic for text-entry suggestion and + * completion functionality. + * + * @module autocomplete + * @requires yahoo, dom, event, datasource + * @optional animation, connection + * @namespace YAHOO.widget + * @title AutoComplete Widget + */ + +/****************************************************************************/ +/****************************************************************************/ +/****************************************************************************/ + +/** + * The AutoComplete class provides the customizable functionality of a plug-and-play DHTML + * auto completion widget. Some key features: + *
    + *
  • Navigate with up/down arrow keys and/or mouse to pick a selection
  • + *
  • The drop down container can "roll down" or "fly out" via configurable + * animation
  • + *
  • UI look-and-feel customizable through CSS, including container + * attributes, borders, position, fonts, etc
  • + *
+ * + * @class AutoComplete + * @constructor + * @param elInput {HTMLElement} DOM element reference of an input field. + * @param elInput {String} String ID of an input field. + * @param elContainer {HTMLElement} DOM element reference of an existing DIV. + * @param elContainer {String} String ID of an existing DIV. + * @param oDataSource {YAHOO.widget.DataSource} DataSource instance. + * @param oConfigs {Object} (optional) Object literal of configuration params. + */ +YAHOO.widget.AutoComplete = function(elInput,elContainer,oDataSource,oConfigs) { + if(elInput && elContainer && oDataSource) { + // Validate DataSource + if (oDataSource && (oDataSource instanceof YAHOO.widget.DataSource)) { + this.dataSource = oDataSource; + } + else { + return; + } + + // Validate input element + if(YAHOO.util.Dom.inDocument(elInput)) { + if(typeof elInput == "string") { + this._sName = "instance" + YAHOO.widget.AutoComplete._nIndex + " " + elInput; + this._oTextbox = document.getElementById(elInput); + } + else { + this._sName = (elInput.id) ? + "instance" + YAHOO.widget.AutoComplete._nIndex + " " + elInput.id: + "instance" + YAHOO.widget.AutoComplete._nIndex; + this._oTextbox = elInput; + } + } + else { + return; + } + + // Validate container element + if(YAHOO.util.Dom.inDocument(elContainer)) { + if(typeof elContainer == "string") { + this._oContainer = document.getElementById(elContainer); + } + else { + this._oContainer = elContainer; + } + if(this._oContainer.style.display == "none") { + } + } + else { + return; + } + + // Set any config params passed in to override defaults + if (typeof oConfigs == "object") { + for(var sConfig in oConfigs) { + if (sConfig) { + this[sConfig] = oConfigs[sConfig]; + } + } + } + + // Initialization sequence + this._initContainer(); + this._initProps(); + this._initList(); + this._initContainerHelpers(); + + // Set up events + var oSelf = this; + var oTextbox = this._oTextbox; + // Events are actually for the content module within the container + var oContent = this._oContainer._oContent; + + // Dom events + YAHOO.util.Event.addListener(oTextbox,"keyup",oSelf._onTextboxKeyUp,oSelf); + YAHOO.util.Event.addListener(oTextbox,"keydown",oSelf._onTextboxKeyDown,oSelf); + YAHOO.util.Event.addListener(oTextbox,"focus",oSelf._onTextboxFocus,oSelf); + YAHOO.util.Event.addListener(oTextbox,"blur",oSelf._onTextboxBlur,oSelf); + YAHOO.util.Event.addListener(oContent,"mouseover",oSelf._onContainerMouseover,oSelf); + YAHOO.util.Event.addListener(oContent,"mouseout",oSelf._onContainerMouseout,oSelf); + YAHOO.util.Event.addListener(oContent,"scroll",oSelf._onContainerScroll,oSelf); + YAHOO.util.Event.addListener(oContent,"resize",oSelf._onContainerResize,oSelf); + if(oTextbox.form) { + YAHOO.util.Event.addListener(oTextbox.form,"submit",oSelf._onFormSubmit,oSelf); + } + YAHOO.util.Event.addListener(oTextbox,"keypress",oSelf._onTextboxKeyPress,oSelf); + + // Custom events + this.textboxFocusEvent = new YAHOO.util.CustomEvent("textboxFocus", this); + this.textboxKeyEvent = new YAHOO.util.CustomEvent("textboxKey", this); + this.dataRequestEvent = new YAHOO.util.CustomEvent("dataRequest", this); + this.dataReturnEvent = new YAHOO.util.CustomEvent("dataReturn", this); + this.dataErrorEvent = new YAHOO.util.CustomEvent("dataError", this); + this.containerExpandEvent = new YAHOO.util.CustomEvent("containerExpand", this); + this.typeAheadEvent = new YAHOO.util.CustomEvent("typeAhead", this); + this.itemMouseOverEvent = new YAHOO.util.CustomEvent("itemMouseOver", this); + this.itemMouseOutEvent = new YAHOO.util.CustomEvent("itemMouseOut", this); + this.itemArrowToEvent = new YAHOO.util.CustomEvent("itemArrowTo", this); + this.itemArrowFromEvent = new YAHOO.util.CustomEvent("itemArrowFrom", this); + this.itemSelectEvent = new YAHOO.util.CustomEvent("itemSelect", this); + this.unmatchedItemSelectEvent = new YAHOO.util.CustomEvent("unmatchedItemSelect", this); + this.selectionEnforceEvent = new YAHOO.util.CustomEvent("selectionEnforce", this); + this.containerCollapseEvent = new YAHOO.util.CustomEvent("containerCollapse", this); + this.textboxBlurEvent = new YAHOO.util.CustomEvent("textboxBlur", this); + + // Finish up + oTextbox.setAttribute("autocomplete","off"); + YAHOO.widget.AutoComplete._nIndex++; + } + // Required arguments were not found + else { + } +}; + +///////////////////////////////////////////////////////////////////////////// +// +// Public member variables +// +///////////////////////////////////////////////////////////////////////////// + +/** + * The DataSource object that encapsulates the data used for auto completion. + * This object should be an inherited object from YAHOO.widget.DataSource. + * + * @property dataSource + * @type YAHOO.widget.DataSource + */ +YAHOO.widget.AutoComplete.prototype.dataSource = null; + +/** + * Number of characters that must be entered before querying for results. A negative value + * effectively turns off the widget. A value of 0 allows queries of null or empty string + * values. + * + * @property minQueryLength + * @type Number + * @default 1 + */ +YAHOO.widget.AutoComplete.prototype.minQueryLength = 1; + +/** + * Maximum number of results to display in results container. + * + * @property maxResultsDisplayed + * @type Number + * @default 10 + */ +YAHOO.widget.AutoComplete.prototype.maxResultsDisplayed = 10; + +/** + * Number of seconds to delay before submitting a query request. If a query + * request is received before a previous one has completed its delay, the + * previous request is cancelled and the new request is set to the delay. + * + * @property queryDelay + * @type Number + * @default 0.5 + */ +YAHOO.widget.AutoComplete.prototype.queryDelay = 0.5; + +/** + * Class name of a highlighted item within results container. + * + * @property highlightClassName + * @type String + * @default "yui-ac-highlight" + */ +YAHOO.widget.AutoComplete.prototype.highlightClassName = "yui-ac-highlight"; + +/** + * Class name of a pre-highlighted item within results container. + * + * @property prehighlightClassName + * @type String + */ +YAHOO.widget.AutoComplete.prototype.prehighlightClassName = null; + +/** + * Query delimiter. A single character separator for multiple delimited + * selections. Multiple delimiter characteres may be defined as an array of + * strings. A null value or empty string indicates that query results cannot + * be delimited. This feature is not recommended if you need forceSelection to + * be true. + * + * @property delimChar + * @type String | String[] + */ +YAHOO.widget.AutoComplete.prototype.delimChar = null; + +/** + * Whether or not the first item in results container should be automatically highlighted + * on expand. + * + * @property autoHighlight + * @type Boolean + * @default true + */ +YAHOO.widget.AutoComplete.prototype.autoHighlight = true; + +/** + * Whether or not the input field should be automatically updated + * with the first query result as the user types, auto-selecting the substring + * that the user has not typed. + * + * @property typeAhead + * @type Boolean + * @default false + */ +YAHOO.widget.AutoComplete.prototype.typeAhead = false; + +/** + * Whether or not to animate the expansion/collapse of the results container in the + * horizontal direction. + * + * @property animHoriz + * @type Boolean + * @default false + */ +YAHOO.widget.AutoComplete.prototype.animHoriz = false; + +/** + * Whether or not to animate the expansion/collapse of the results container in the + * vertical direction. + * + * @property animVert + * @type Boolean + * @default true + */ +YAHOO.widget.AutoComplete.prototype.animVert = true; + +/** + * Speed of container expand/collapse animation, in seconds.. + * + * @property animSpeed + * @type Number + * @default 0.3 + */ +YAHOO.widget.AutoComplete.prototype.animSpeed = 0.3; + +/** + * Whether or not to force the user's selection to match one of the query + * results. Enabling this feature essentially transforms the input field into a + * <select> field. This feature is not recommended with delimiter character(s) + * defined. + * + * @property forceSelection + * @type Boolean + * @default false + */ +YAHOO.widget.AutoComplete.prototype.forceSelection = false; + +/** + * Whether or not to allow browsers to cache user-typed input in the input + * field. Disabling this feature will prevent the widget from setting the + * autocomplete="off" on the input field. When autocomplete="off" + * and users click the back button after form submission, user-typed input can + * be prefilled by the browser from its cache. This caching of user input may + * not be desired for sensitive data, such as credit card numbers, in which + * case, implementers should consider setting allowBrowserAutocomplete to false. + * + * @property allowBrowserAutocomplete + * @type Boolean + * @default true + */ +YAHOO.widget.AutoComplete.prototype.allowBrowserAutocomplete = true; + +/** + * Whether or not the results container should always be displayed. + * Enabling this feature displays the container when the widget is instantiated + * and prevents the toggling of the container to a collapsed state. + * + * @property alwaysShowContainer + * @type Boolean + * @default false + */ +YAHOO.widget.AutoComplete.prototype.alwaysShowContainer = false; + +/** + * Whether or not to use an iFrame to layer over Windows form elements in + * IE. Set to true only when the results container will be on top of a + * <select> field in IE and thus exposed to the IE z-index bug (i.e., + * 5.5 < IE < 7). + * + * @property useIFrame + * @type Boolean + * @default false + */ +YAHOO.widget.AutoComplete.prototype.useIFrame = false; + +/** + * Whether or not the results container should have a shadow. + * + * @property useShadow + * @type Boolean + * @default false + */ +YAHOO.widget.AutoComplete.prototype.useShadow = false; + +///////////////////////////////////////////////////////////////////////////// +// +// Public methods +// +///////////////////////////////////////////////////////////////////////////// + + /** + * Public accessor to the unique name of the AutoComplete instance. + * + * @method toString + * @return {String} Unique name of the AutoComplete instance. + */ +YAHOO.widget.AutoComplete.prototype.toString = function() { + return "AutoComplete " + this._sName; +}; + + /** + * Returns true if container is in an expanded state, false otherwise. + * + * @method isContainerOpen + * @return {Boolean} Returns true if container is in an expanded state, false otherwise. + */ +YAHOO.widget.AutoComplete.prototype.isContainerOpen = function() { + return this._bContainerOpen; +}; + +/** + * Public accessor to the internal array of DOM <li> elements that + * display query results within the results container. + * + * @method getListItems + * @return {HTMLElement[]} Array of <li> elements within the results container. + */ +YAHOO.widget.AutoComplete.prototype.getListItems = function() { + return this._aListItems; +}; + +/** + * Public accessor to the data held in an <li> element of the + * results container. + * + * @method getListItemData + * @return {Object | Object[]} Object or array of result data or null + */ +YAHOO.widget.AutoComplete.prototype.getListItemData = function(oListItem) { + if(oListItem._oResultData) { + return oListItem._oResultData; + } + else { + return false; + } +}; + +/** + * Sets HTML markup for the results container header. This markup will be + * inserted within a <div> tag with a class of "yui-ac-hd". + * + * @method setHeader + * @param sHeader {String} HTML markup for results container header. + */ +YAHOO.widget.AutoComplete.prototype.setHeader = function(sHeader) { + if(sHeader) { + if(this._oContainer._oContent._oHeader) { + this._oContainer._oContent._oHeader.innerHTML = sHeader; + this._oContainer._oContent._oHeader.style.display = "block"; + } + } + else { + this._oContainer._oContent._oHeader.innerHTML = ""; + this._oContainer._oContent._oHeader.style.display = "none"; + } +}; + +/** + * Sets HTML markup for the results container footer. This markup will be + * inserted within a <div> tag with a class of "yui-ac-ft". + * + * @method setFooter + * @param sFooter {String} HTML markup for results container footer. + */ +YAHOO.widget.AutoComplete.prototype.setFooter = function(sFooter) { + if(sFooter) { + if(this._oContainer._oContent._oFooter) { + this._oContainer._oContent._oFooter.innerHTML = sFooter; + this._oContainer._oContent._oFooter.style.display = "block"; + } + } + else { + this._oContainer._oContent._oFooter.innerHTML = ""; + this._oContainer._oContent._oFooter.style.display = "none"; + } +}; + +/** + * Sets HTML markup for the results container body. This markup will be + * inserted within a <div> tag with a class of "yui-ac-bd". + * + * @method setBody + * @param sBody {String} HTML markup for results container body. + */ +YAHOO.widget.AutoComplete.prototype.setBody = function(sBody) { + if(sBody) { + if(this._oContainer._oContent._oBody) { + this._oContainer._oContent._oBody.innerHTML = sBody; + this._oContainer._oContent._oBody.style.display = "block"; + this._oContainer._oContent.style.display = "block"; + } + } + else { + this._oContainer._oContent._oBody.innerHTML = ""; + this._oContainer._oContent.style.display = "none"; + } + this._maxResultsDisplayed = 0; +}; + +/** + * Overridable method that converts a result item object into HTML markup + * for display. Return data values are accessible via the oResultItem object, + * and the key return value will always be oResultItem[0]. Markup will be + * displayed within <li> element tags in the container. + * + * @method formatResult + * @param oResultItem {Object} Result item representing one query result. Data is held in an array. + * @param sQuery {String} The current query string. + * @return {String} HTML markup of formatted result data. + */ +YAHOO.widget.AutoComplete.prototype.formatResult = function(oResultItem, sQuery) { + var sResult = oResultItem[0]; + if(sResult) { + return sResult; + } + else { + return ""; + } +}; + +/** + * Overridable method called before container expands allows implementers to access data + * and DOM elements. + * + * @method doBeforeExpandContainer + * @return {Boolean} Return true to continue expanding container, false to cancel the expand. + */ +YAHOO.widget.AutoComplete.prototype.doBeforeExpandContainer = function(oResultItem, sQuery) { + return true; +}; + +/** + * Makes query request to the DataSource. + * + * @method sendQuery + * @param sQuery {String} Query string. + */ +YAHOO.widget.AutoComplete.prototype.sendQuery = function(sQuery) { + this._sendQuery(sQuery); +}; + +///////////////////////////////////////////////////////////////////////////// +// +// Public events +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Fired when the input field receives focus. + * + * @event textboxFocusEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + */ +YAHOO.widget.AutoComplete.prototype.textboxFocusEvent = null; + +/** + * Fired when the input field receives key input. + * + * @event textboxKeyEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @param nKeycode {Number} The keycode number. + */ +YAHOO.widget.AutoComplete.prototype.textboxKeyEvent = null; + +/** + * Fired when the AutoComplete instance makes a query to the DataSource. + * + * @event dataRequestEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @param sQuery {String} The query string. + */ +YAHOO.widget.AutoComplete.prototype.dataRequestEvent = null; + +/** + * Fired when the AutoComplete instance receives query results from the data + * source. + * + * @event dataReturnEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @param sQuery {String} The query string. + * @param aResults {Object[]} Results array. + */ +YAHOO.widget.AutoComplete.prototype.dataReturnEvent = null; + +/** + * Fired when the AutoComplete instance does not receive query results from the + * DataSource due to an error. + * + * @event dataErrorEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @param sQuery {String} The query string. + */ +YAHOO.widget.AutoComplete.prototype.dataErrorEvent = null; + +/** + * Fired when the results container is expanded. + * + * @event containerExpandEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + */ +YAHOO.widget.AutoComplete.prototype.containerExpandEvent = null; + +/** + * Fired when the input field has been prefilled by the type-ahead + * feature. + * + * @event typeAheadEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @param sQuery {String} The query string. + * @param sPrefill {String} The prefill string. + */ +YAHOO.widget.AutoComplete.prototype.typeAheadEvent = null; + +/** + * Fired when result item has been moused over. + * + * @event itemMouseOverEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @param elItem {HTMLElement} The <li> element item moused to. + */ +YAHOO.widget.AutoComplete.prototype.itemMouseOverEvent = null; + +/** + * Fired when result item has been moused out. + * + * @event itemMouseOutEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @param elItem {HTMLElement} The <li> element item moused from. + */ +YAHOO.widget.AutoComplete.prototype.itemMouseOutEvent = null; + +/** + * Fired when result item has been arrowed to. + * + * @event itemArrowToEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @param elItem {HTMLElement} The <li> element item arrowed to. + */ +YAHOO.widget.AutoComplete.prototype.itemArrowToEvent = null; + +/** + * Fired when result item has been arrowed away from. + * + * @event itemArrowFromEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @param elItem {HTMLElement} The <li> element item arrowed from. + */ +YAHOO.widget.AutoComplete.prototype.itemArrowFromEvent = null; + +/** + * Fired when an item is selected via mouse click, ENTER key, or TAB key. + * + * @event itemSelectEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @param elItem {HTMLElement} The selected <li> element item. + * @param oData {Object} The data returned for the item, either as an object, + * or mapped from the schema into an array. + */ +YAHOO.widget.AutoComplete.prototype.itemSelectEvent = null; + +/** + * Fired when a user selection does not match any of the displayed result items. + * Note that this event may not behave as expected when delimiter characters + * have been defined. + * + * @event unmatchedItemSelectEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @param sQuery {String} The user-typed query string. + */ +YAHOO.widget.AutoComplete.prototype.unmatchedItemSelectEvent = null; + +/** + * Fired if forceSelection is enabled and the user's input has been cleared + * because it did not match one of the returned query results. + * + * @event selectionEnforceEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + */ +YAHOO.widget.AutoComplete.prototype.selectionEnforceEvent = null; + +/** + * Fired when the results container is collapsed. + * + * @event containerCollapseEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + */ +YAHOO.widget.AutoComplete.prototype.containerCollapseEvent = null; + +/** + * Fired when the input field loses focus. + * + * @event textboxBlurEvent + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + */ +YAHOO.widget.AutoComplete.prototype.textboxBlurEvent = null; + +///////////////////////////////////////////////////////////////////////////// +// +// Private member variables +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Internal class variable to index multiple AutoComplete instances. + * + * @property _nIndex + * @type Number + * @default 0 + * @private + */ +YAHOO.widget.AutoComplete._nIndex = 0; + +/** + * Name of AutoComplete instance. + * + * @property _sName + * @type String + * @private + */ +YAHOO.widget.AutoComplete.prototype._sName = null; + +/** + * Text input field DOM element. + * + * @property _oTextbox + * @type HTMLElement + * @private + */ +YAHOO.widget.AutoComplete.prototype._oTextbox = null; + +/** + * Whether or not the input field is currently in focus. If query results come back + * but the user has already moved on, do not proceed with auto complete behavior. + * + * @property _bFocused + * @type Boolean + * @private + */ +YAHOO.widget.AutoComplete.prototype._bFocused = true; + +/** + * Animation instance for container expand/collapse. + * + * @property _oAnim + * @type Boolean + * @private + */ +YAHOO.widget.AutoComplete.prototype._oAnim = null; + +/** + * Container DOM element. + * + * @property _oContainer + * @type HTMLElement + * @private + */ +YAHOO.widget.AutoComplete.prototype._oContainer = null; + +/** + * Whether or not the results container is currently open. + * + * @property _bContainerOpen + * @type Boolean + * @private + */ +YAHOO.widget.AutoComplete.prototype._bContainerOpen = false; + +/** + * Whether or not the mouse is currently over the results + * container. This is necessary in order to prevent clicks on container items + * from being text input field blur events. + * + * @property _bOverContainer + * @type Boolean + * @private + */ +YAHOO.widget.AutoComplete.prototype._bOverContainer = false; + +/** + * Array of <li> elements references that contain query results within the + * results container. + * + * @property _aListItems + * @type HTMLElement[] + * @private + */ +YAHOO.widget.AutoComplete.prototype._aListItems = null; + +/** + * Number of <li> elements currently displayed in results container. + * + * @property _nDisplayedItems + * @type Number + * @private + */ +YAHOO.widget.AutoComplete.prototype._nDisplayedItems = 0; + +/** + * Internal count of <li> elements displayed and hidden in results container. + * + * @property _maxResultsDisplayed + * @type Number + * @private + */ +YAHOO.widget.AutoComplete.prototype._maxResultsDisplayed = 0; + +/** + * Current query string + * + * @property _sCurQuery + * @type String + * @private + */ +YAHOO.widget.AutoComplete.prototype._sCurQuery = null; + +/** + * Past queries this session (for saving delimited queries). + * + * @property _sSavedQuery + * @type String + * @private + */ +YAHOO.widget.AutoComplete.prototype._sSavedQuery = null; + +/** + * Pointer to the currently highlighted <li> element in the container. + * + * @property _oCurItem + * @type HTMLElement + * @private + */ +YAHOO.widget.AutoComplete.prototype._oCurItem = null; + +/** + * Whether or not an item has been selected since the container was populated + * with results. Reset to false by _populateList, and set to true when item is + * selected. + * + * @property _bItemSelected + * @type Boolean + * @private + */ +YAHOO.widget.AutoComplete.prototype._bItemSelected = false; + +/** + * Key code of the last key pressed in textbox. + * + * @property _nKeyCode + * @type Number + * @private + */ +YAHOO.widget.AutoComplete.prototype._nKeyCode = null; + +/** + * Delay timeout ID. + * + * @property _nDelayID + * @type Number + * @private + */ +YAHOO.widget.AutoComplete.prototype._nDelayID = -1; + +/** + * Src to iFrame used when useIFrame = true. Supports implementations over SSL + * as well. + * + * @property _iFrameSrc + * @type String + * @private + */ +YAHOO.widget.AutoComplete.prototype._iFrameSrc = "javascript:false;"; + +/** + * For users typing via certain IMEs, queries must be triggered by intervals, + * since key events yet supported across all browsers for all IMEs. + * + * @property _queryInterval + * @type Object + * @private + */ +YAHOO.widget.AutoComplete.prototype._queryInterval = null; + +/** + * Internal tracker to last known textbox value, used to determine whether or not + * to trigger a query via interval for certain IME users. + * + * @event _sLastTextboxValue + * @type String + * @private + */ +YAHOO.widget.AutoComplete.prototype._sLastTextboxValue = null; + +///////////////////////////////////////////////////////////////////////////// +// +// Private methods +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Updates and validates latest public config properties. + * + * @method __initProps + * @private + */ +YAHOO.widget.AutoComplete.prototype._initProps = function() { + // Correct any invalid values + var minQueryLength = this.minQueryLength; + if(isNaN(minQueryLength) || (minQueryLength < 1)) { + minQueryLength = 1; + } + var maxResultsDisplayed = this.maxResultsDisplayed; + if(isNaN(this.maxResultsDisplayed) || (this.maxResultsDisplayed < 1)) { + this.maxResultsDisplayed = 10; + } + var queryDelay = this.queryDelay; + if(isNaN(this.queryDelay) || (this.queryDelay < 0)) { + this.queryDelay = 0.5; + } + var aDelimChar = (this.delimChar) ? this.delimChar : null; + if(aDelimChar) { + if(typeof aDelimChar == "string") { + this.delimChar = [aDelimChar]; + } + else if(aDelimChar.constructor != Array) { + this.delimChar = null; + } + } + var animSpeed = this.animSpeed; + if((this.animHoriz || this.animVert) && YAHOO.util.Anim) { + if(isNaN(animSpeed) || (animSpeed < 0)) { + animSpeed = 0.3; + } + if(!this._oAnim ) { + oAnim = new YAHOO.util.Anim(this._oContainer._oContent, {}, this.animSpeed); + this._oAnim = oAnim; + } + else { + this._oAnim.duration = animSpeed; + } + } + if(this.forceSelection && this.delimChar) { + } +}; + +/** + * Initializes the results container helpers if they are enabled and do + * not exist + * + * @method _initContainerHelpers + * @private + */ +YAHOO.widget.AutoComplete.prototype._initContainerHelpers = function() { + if(this.useShadow && !this._oContainer._oShadow) { + var oShadow = document.createElement("div"); + oShadow.className = "yui-ac-shadow"; + this._oContainer._oShadow = this._oContainer.appendChild(oShadow); + } + if(this.useIFrame && !this._oContainer._oIFrame) { + var oIFrame = document.createElement("iframe"); + oIFrame.src = this._iFrameSrc; + oIFrame.frameBorder = 0; + oIFrame.scrolling = "no"; + oIFrame.style.position = "absolute"; + oIFrame.style.width = "100%"; + oIFrame.style.height = "100%"; + oIFrame.tabIndex = -1; + this._oContainer._oIFrame = this._oContainer.appendChild(oIFrame); + } +}; + +/** + * Initializes the results container once at object creation + * + * @method _initContainer + * @private + */ +YAHOO.widget.AutoComplete.prototype._initContainer = function() { + if(!this._oContainer._oContent) { + // The oContent div helps size the iframe and shadow properly + var oContent = document.createElement("div"); + oContent.className = "yui-ac-content"; + oContent.style.display = "none"; + this._oContainer._oContent = this._oContainer.appendChild(oContent); + + var oHeader = document.createElement("div"); + oHeader.className = "yui-ac-hd"; + oHeader.style.display = "none"; + this._oContainer._oContent._oHeader = this._oContainer._oContent.appendChild(oHeader); + + var oBody = document.createElement("div"); + oBody.className = "yui-ac-bd"; + this._oContainer._oContent._oBody = this._oContainer._oContent.appendChild(oBody); + + var oFooter = document.createElement("div"); + oFooter.className = "yui-ac-ft"; + oFooter.style.display = "none"; + this._oContainer._oContent._oFooter = this._oContainer._oContent.appendChild(oFooter); + } + else { + } +}; + +/** + * Clears out contents of container body and creates up to + * YAHOO.widget.AutoComplete#maxResultsDisplayed <li> elements in an + * <ul> element. + * + * @method _initList + * @private + */ +YAHOO.widget.AutoComplete.prototype._initList = function() { + this._aListItems = []; + while(this._oContainer._oContent._oBody.hasChildNodes()) { + var oldListItems = this.getListItems(); + if(oldListItems) { + for(var oldi = oldListItems.length-1; oldi >= 0; i--) { + oldListItems[oldi] = null; + } + } + this._oContainer._oContent._oBody.innerHTML = ""; + } + + var oList = document.createElement("ul"); + oList = this._oContainer._oContent._oBody.appendChild(oList); + for(var i=0; i= 18 && nKeyCode <= 20) || // alt,pause/break,caps lock + (nKeyCode == 27) || // esc + (nKeyCode >= 33 && nKeyCode <= 35) || // page up,page down,end + (nKeyCode >= 36 && nKeyCode <= 38) || // home,left,up + (nKeyCode == 40) || // down + (nKeyCode >= 44 && nKeyCode <= 45)) { // print screen,insert + return true; + } + return false; +}; + +/** + * Makes query request to the DataSource. + * + * @method _sendQuery + * @param sQuery {String} Query string. + * @private + */ +YAHOO.widget.AutoComplete.prototype._sendQuery = function(sQuery) { + // Widget has been effectively turned off + if(this.minQueryLength == -1) { + this._toggleContainer(false); + return; + } + // Delimiter has been enabled + var aDelimChar = (this.delimChar) ? this.delimChar : null; + if(aDelimChar) { + // Loop through all possible delimiters and find the latest one + // A " " may be a false positive if they are defined as delimiters AND + // are used to separate delimited queries + var nDelimIndex = -1; + for(var i = aDelimChar.length-1; i >= 0; i--) { + var nNewIndex = sQuery.lastIndexOf(aDelimChar[i]); + if(nNewIndex > nDelimIndex) { + nDelimIndex = nNewIndex; + } + } + // If we think the last delimiter is a space (" "), make sure it is NOT + // a false positive by also checking the char directly before it + if(aDelimChar[i] == " ") { + for (var j = aDelimChar.length-1; j >= 0; j--) { + if(sQuery[nDelimIndex - 1] == aDelimChar[j]) { + nDelimIndex--; + break; + } + } + } + // A delimiter has been found so extract the latest query + if (nDelimIndex > -1) { + var nQueryStart = nDelimIndex + 1; + // Trim any white space from the beginning... + while(sQuery.charAt(nQueryStart) == " ") { + nQueryStart += 1; + } + // ...and save the rest of the string for later + this._sSavedQuery = sQuery.substring(0,nQueryStart); + // Here is the query itself + sQuery = sQuery.substr(nQueryStart); + } + else if(sQuery.indexOf(this._sSavedQuery) < 0){ + this._sSavedQuery = null; + } + } + + // Don't search queries that are too short + if (sQuery && (sQuery.length < this.minQueryLength) || (!sQuery && this.minQueryLength > 0)) { + if (this._nDelayID != -1) { + clearTimeout(this._nDelayID); + } + this._toggleContainer(false); + return; + } + + sQuery = encodeURIComponent(sQuery); + this._nDelayID = -1; // Reset timeout ID because request has been made + this.dataRequestEvent.fire(this, sQuery); + this.dataSource.getResults(this._populateList, sQuery, this); +}; + +/** + * Populates the array of <li> elements in the container with query + * results. This method is passed to YAHOO.widget.DataSource#getResults as a + * callback function so results from the DataSource instance are returned to the + * AutoComplete instance. + * + * @method _populateList + * @param sQuery {String} The query string. + * @param aResults {Object[]} An array of query result objects from the DataSource. + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._populateList = function(sQuery, aResults, oSelf) { + if(aResults === null) { + oSelf.dataErrorEvent.fire(oSelf, sQuery); + } + if (!oSelf._bFocused || !aResults) { + return; + } + + var isOpera = (navigator.userAgent.toLowerCase().indexOf("opera") != -1); + var contentStyle = oSelf._oContainer._oContent.style; + contentStyle.width = (!isOpera) ? null : ""; + contentStyle.height = (!isOpera) ? null : ""; + + var sCurQuery = decodeURIComponent(sQuery); + oSelf._sCurQuery = sCurQuery; + oSelf._bItemSelected = false; + + if(oSelf._maxResultsDisplayed != oSelf.maxResultsDisplayed) { + oSelf._initList(); + } + + var nItems = Math.min(aResults.length,oSelf.maxResultsDisplayed); + oSelf._nDisplayedItems = nItems; + if (nItems > 0) { + oSelf._initContainerHelpers(); + var aItems = oSelf._aListItems; + + // Fill items with data + for(var i = nItems-1; i >= 0; i--) { + var oItemi = aItems[i]; + var oResultItemi = aResults[i]; + oItemi.innerHTML = oSelf.formatResult(oResultItemi, sCurQuery); + oItemi.style.display = "list-item"; + oItemi._sResultKey = oResultItemi[0]; + oItemi._oResultData = oResultItemi; + + } + + // Empty out remaining items if any + for(var j = aItems.length-1; j >= nItems ; j--) { + var oItemj = aItems[j]; + oItemj.innerHTML = null; + oItemj.style.display = "none"; + oItemj._sResultKey = null; + oItemj._oResultData = null; + } + + if(oSelf.autoHighlight) { + // Go to the first item + var oFirstItem = aItems[0]; + oSelf._toggleHighlight(oFirstItem,"to"); + oSelf.itemArrowToEvent.fire(oSelf, oFirstItem); + oSelf._typeAhead(oFirstItem,sQuery); + } + else { + oSelf._oCurItem = null; + } + + // Expand the container + var ok = oSelf.doBeforeExpandContainer(oSelf._oTextbox, oSelf._oContainer, sQuery, aResults); + oSelf._toggleContainer(ok); + } + else { + oSelf._toggleContainer(false); + } + oSelf.dataReturnEvent.fire(oSelf, sQuery, aResults); +}; + +/** + * When forceSelection is true and the user attempts + * leave the text input box without selecting an item from the query results, + * the user selection is cleared. + * + * @method _clearSelection + * @private + */ +YAHOO.widget.AutoComplete.prototype._clearSelection = function() { + var sValue = this._oTextbox.value; + var sChar = (this.delimChar) ? this.delimChar[0] : null; + var nIndex = (sChar) ? sValue.lastIndexOf(sChar, sValue.length-2) : -1; + if(nIndex > -1) { + this._oTextbox.value = sValue.substring(0,nIndex); + } + else { + this._oTextbox.value = ""; + } + this._sSavedQuery = this._oTextbox.value; + + // Fire custom event + this.selectionEnforceEvent.fire(this); +}; + +/** + * Whether or not user-typed value in the text input box matches any of the + * query results. + * + * @method _textMatchesOption + * @return {Boolean} True if user-input text matches a result, false otherwise. + * @private + */ +YAHOO.widget.AutoComplete.prototype._textMatchesOption = function() { + var foundMatch = false; + + for(var i = this._nDisplayedItems-1; i >= 0 ; i--) { + var oItem = this._aListItems[i]; + var sMatch = oItem._sResultKey.toLowerCase(); + if (sMatch == this._sCurQuery.toLowerCase()) { + foundMatch = true; + break; + } + } + return(foundMatch); +}; + +/** + * Updates in the text input box with the first query result as the user types, + * selecting the substring that the user has not typed. + * + * @method _typeAhead + * @param oItem {HTMLElement} The <li> element item whose data populates the input field. + * @param sQuery {String} Query string. + * @private + */ +YAHOO.widget.AutoComplete.prototype._typeAhead = function(oItem, sQuery) { + // Don't update if turned off + if (!this.typeAhead || (this._nKeyCode == 8)) { + return; + } + + var oTextbox = this._oTextbox; + var sValue = this._oTextbox.value; // any saved queries plus what user has typed + + // Don't update with type-ahead if text selection is not supported + if(!oTextbox.setSelectionRange && !oTextbox.createTextRange) { + return; + } + + // Select the portion of text that the user has not typed + var nStart = sValue.length; + this._updateValue(oItem); + var nEnd = oTextbox.value.length; + this._selectText(oTextbox,nStart,nEnd); + var sPrefill = oTextbox.value.substr(nStart,nEnd); + this.typeAheadEvent.fire(this,sQuery,sPrefill); +}; + +/** + * Selects text in the input field. + * + * @method _selectText + * @param oTextbox {HTMLElement} Text input box element in which to select text. + * @param nStart {Number} Starting index of text string to select. + * @param nEnd {Number} Ending index of text selection. + * @private + */ +YAHOO.widget.AutoComplete.prototype._selectText = function(oTextbox, nStart, nEnd) { + if (oTextbox.setSelectionRange) { // For Mozilla + oTextbox.setSelectionRange(nStart,nEnd); + } + else if (oTextbox.createTextRange) { // For IE + var oTextRange = oTextbox.createTextRange(); + oTextRange.moveStart("character", nStart); + oTextRange.moveEnd("character", nEnd-oTextbox.value.length); + oTextRange.select(); + } + else { + oTextbox.select(); + } +}; + +/** + * Syncs results container with its helpers. + * + * @method _toggleContainerHelpers + * @param bShow {Boolean} True if container is expanded, false if collapsed + * @private + */ +YAHOO.widget.AutoComplete.prototype._toggleContainerHelpers = function(bShow) { + var bFireEvent = false; + var width = this._oContainer._oContent.offsetWidth + "px"; + var height = this._oContainer._oContent.offsetHeight + "px"; + + if(this.useIFrame && this._oContainer._oIFrame) { + bFireEvent = true; + if(bShow) { + this._oContainer._oIFrame.style.width = width; + this._oContainer._oIFrame.style.height = height; + } + else { + this._oContainer._oIFrame.style.width = 0; + this._oContainer._oIFrame.style.height = 0; + } + } + if(this.useShadow && this._oContainer._oShadow) { + bFireEvent = true; + if(bShow) { + this._oContainer._oShadow.style.width = width; + this._oContainer._oShadow.style.height = height; + } + else { + this._oContainer._oShadow.style.width = 0; + this._oContainer._oShadow.style.height = 0; + } + } +}; + +/** + * Animates expansion or collapse of the container. + * + * @method _toggleContainer + * @param bShow {Boolean} True if container should be expanded, false if container should be collapsed + * @private + */ +YAHOO.widget.AutoComplete.prototype._toggleContainer = function(bShow) { + var oContainer = this._oContainer; + + // Implementer has container always open so don't mess with it + if(this.alwaysShowContainer && this._bContainerOpen) { + return; + } + + // Clear contents of container + if(!bShow) { + this._oContainer._oContent.scrollTop = 0; + var aItems = this._aListItems; + + if(aItems && (aItems.length > 0)) { + for(var i = aItems.length-1; i >= 0 ; i--) { + aItems[i].style.display = "none"; + } + } + + if (this._oCurItem) { + this._toggleHighlight(this._oCurItem,"from"); + } + + this._oCurItem = null; + this._nDisplayedItems = 0; + this._sCurQuery = null; + } + + // Container is already closed + if (!bShow && !this._bContainerOpen) { + oContainer._oContent.style.display = "none"; + return; + } + + // If animation is enabled... + var oAnim = this._oAnim; + if (oAnim && oAnim.getEl() && (this.animHoriz || this.animVert)) { + // If helpers need to be collapsed, do it right away... + // but if helpers need to be expanded, wait until after the container expands + if(!bShow) { + this._toggleContainerHelpers(bShow); + } + + if(oAnim.isAnimated()) { + oAnim.stop(); + } + + // Clone container to grab current size offscreen + var oClone = oContainer._oContent.cloneNode(true); + oContainer.appendChild(oClone); + oClone.style.top = "-9000px"; + oClone.style.display = "block"; + + // Current size of the container is the EXPANDED size + var wExp = oClone.offsetWidth; + var hExp = oClone.offsetHeight; + + // Calculate COLLAPSED sizes based on horiz and vert anim + var wColl = (this.animHoriz) ? 0 : wExp; + var hColl = (this.animVert) ? 0 : hExp; + + // Set animation sizes + oAnim.attributes = (bShow) ? + {width: { to: wExp }, height: { to: hExp }} : + {width: { to: wColl}, height: { to: hColl }}; + + // If opening anew, set to a collapsed size... + if(bShow && !this._bContainerOpen) { + oContainer._oContent.style.width = wColl+"px"; + oContainer._oContent.style.height = hColl+"px"; + } + // Else, set it to its last known size. + else { + oContainer._oContent.style.width = wExp+"px"; + oContainer._oContent.style.height = hExp+"px"; + } + + oContainer.removeChild(oClone); + oClone = null; + + var oSelf = this; + var onAnimComplete = function() { + // Finish the collapse + oAnim.onComplete.unsubscribeAll(); + + if(bShow) { + oSelf.containerExpandEvent.fire(oSelf); + } + else { + oContainer._oContent.style.display = "none"; + oSelf.containerCollapseEvent.fire(oSelf); + } + oSelf._toggleContainerHelpers(bShow); + }; + + // Display container and animate it + oContainer._oContent.style.display = "block"; + oAnim.onComplete.subscribe(onAnimComplete); + oAnim.animate(); + this._bContainerOpen = bShow; + } + // Else don't animate, just show or hide + else { + if(bShow) { + oContainer._oContent.style.display = "block"; + this.containerExpandEvent.fire(this); + } + else { + oContainer._oContent.style.display = "none"; + this.containerCollapseEvent.fire(this); + } + this._toggleContainerHelpers(bShow); + this._bContainerOpen = bShow; + } + +}; + +/** + * Toggles the highlight on or off for an item in the container, and also cleans + * up highlighting of any previous item. + * + * @method _toggleHighlight + * @param oNewItem {HTMLElement} The <li> element item to receive highlight behavior. + * @param sType {String} Type "mouseover" will toggle highlight on, and "mouseout" will toggle highlight off. + * @private + */ +YAHOO.widget.AutoComplete.prototype._toggleHighlight = function(oNewItem, sType) { + var sHighlight = this.highlightClassName; + if(this._oCurItem) { + // Remove highlight from old item + YAHOO.util.Dom.removeClass(this._oCurItem, sHighlight); + } + + if((sType == "to") && sHighlight) { + // Apply highlight to new item + YAHOO.util.Dom.addClass(oNewItem, sHighlight); + this._oCurItem = oNewItem; + } +}; + +/** + * Toggles the pre-highlight on or off for an item in the container. + * + * @method _togglePrehighlight + * @param oNewItem {HTMLElement} The <li> element item to receive highlight behavior. + * @param sType {String} Type "mouseover" will toggle highlight on, and "mouseout" will toggle highlight off. + * @private + */ +YAHOO.widget.AutoComplete.prototype._togglePrehighlight = function(oNewItem, sType) { + if(oNewItem == this._oCurItem) { + return; + } + + var sPrehighlight = this.prehighlightClassName; + if((sType == "mouseover") && sPrehighlight) { + // Apply prehighlight to new item + YAHOO.util.Dom.addClass(oNewItem, sPrehighlight); + } + else { + // Remove prehighlight from old item + YAHOO.util.Dom.removeClass(oNewItem, sPrehighlight); + } +}; + +/** + * Updates the text input box value with selected query result. If a delimiter + * has been defined, then the value gets appended with the delimiter. + * + * @method _updateValue + * @param oItem {HTMLElement} The <li> element item with which to update the value. + * @private + */ +YAHOO.widget.AutoComplete.prototype._updateValue = function(oItem) { + var oTextbox = this._oTextbox; + var sDelimChar = (this.delimChar) ? (this.delimChar[0] || this.delimChar) : null; + var sSavedQuery = this._sSavedQuery; + var sResultKey = oItem._sResultKey; + oTextbox.focus(); + + // First clear text field + oTextbox.value = ""; + // Grab data to put into text field + if(sDelimChar) { + if(sSavedQuery) { + oTextbox.value = sSavedQuery; + } + oTextbox.value += sResultKey + sDelimChar; + if(sDelimChar != " ") { + oTextbox.value += " "; + } + } + else { oTextbox.value = sResultKey; } + + // scroll to bottom of textarea if necessary + if(oTextbox.type == "textarea") { + oTextbox.scrollTop = oTextbox.scrollHeight; + } + + // move cursor to end + var end = oTextbox.value.length; + this._selectText(oTextbox,end,end); + + this._oCurItem = oItem; +}; + +/** + * Selects a result item from the container + * + * @method _selectItem + * @param oItem {HTMLElement} The selected <li> element item. + * @private + */ +YAHOO.widget.AutoComplete.prototype._selectItem = function(oItem) { + this._bItemSelected = true; + this._updateValue(oItem); + this._cancelIntervalDetection(this); + this.itemSelectEvent.fire(this, oItem, oItem._oResultData); + this._toggleContainer(false); +}; + +/** + * For values updated by type-ahead, the right arrow key jumps to the end + * of the textbox, otherwise the container is closed. + * + * @method _jumpSelection + * @private + */ +YAHOO.widget.AutoComplete.prototype._jumpSelection = function() { + if(!this.typeAhead) { + return; + } + else { + this._toggleContainer(false); + } +}; + +/** + * Triggered by up and down arrow keys, changes the current highlighted + * <li> element item. Scrolls container if necessary. + * + * @method _moveSelection + * @param nKeyCode {Number} Code of key pressed. + * @private + */ +YAHOO.widget.AutoComplete.prototype._moveSelection = function(nKeyCode) { + if(this._bContainerOpen) { + // Determine current item's id number + var oCurItem = this._oCurItem; + var nCurItemIndex = -1; + + if (oCurItem) { + nCurItemIndex = oCurItem._nItemIndex; + } + + var nNewItemIndex = (nKeyCode == 40) ? + (nCurItemIndex + 1) : (nCurItemIndex - 1); + + // Out of bounds + if (nNewItemIndex < -2 || nNewItemIndex >= this._nDisplayedItems) { + return; + } + + if (oCurItem) { + // Unhighlight current item + this._toggleHighlight(oCurItem, "from"); + this.itemArrowFromEvent.fire(this, oCurItem); + } + if (nNewItemIndex == -1) { + // Go back to query (remove type-ahead string) + if(this.delimChar && this._sSavedQuery) { + if (!this._textMatchesOption()) { + this._oTextbox.value = this._sSavedQuery; + } + else { + this._oTextbox.value = this._sSavedQuery + this._sCurQuery; + } + } + else { + this._oTextbox.value = this._sCurQuery; + } + this._oCurItem = null; + return; + } + if (nNewItemIndex == -2) { + // Close container + this._toggleContainer(false); + return; + } + + var oNewItem = this._aListItems[nNewItemIndex]; + + // Scroll the container if necessary + var oContent = this._oContainer._oContent; + var scrollOn = ((YAHOO.util.Dom.getStyle(oContent,"overflow") == "auto") || + (YAHOO.util.Dom.getStyle(oContent,"overflowY") == "auto")); + if(scrollOn && (nNewItemIndex > -1) && + (nNewItemIndex < this._nDisplayedItems)) { + // User is keying down + if(nKeyCode == 40) { + // Bottom of selected item is below scroll area... + if((oNewItem.offsetTop+oNewItem.offsetHeight) > (oContent.scrollTop + oContent.offsetHeight)) { + // Set bottom of scroll area to bottom of selected item + oContent.scrollTop = (oNewItem.offsetTop+oNewItem.offsetHeight) - oContent.offsetHeight; + } + // Bottom of selected item is above scroll area... + else if((oNewItem.offsetTop+oNewItem.offsetHeight) < oContent.scrollTop) { + // Set top of selected item to top of scroll area + oContent.scrollTop = oNewItem.offsetTop; + + } + } + // User is keying up + else { + // Top of selected item is above scroll area + if(oNewItem.offsetTop < oContent.scrollTop) { + // Set top of scroll area to top of selected item + this._oContainer._oContent.scrollTop = oNewItem.offsetTop; + } + // Top of selected item is below scroll area + else if(oNewItem.offsetTop > (oContent.scrollTop + oContent.offsetHeight)) { + // Set bottom of selected item to bottom of scroll area + this._oContainer._oContent.scrollTop = (oNewItem.offsetTop+oNewItem.offsetHeight) - oContent.offsetHeight; + } + } + } + + this._toggleHighlight(oNewItem, "to"); + this.itemArrowToEvent.fire(this, oNewItem); + if(this.typeAhead) { + this._updateValue(oNewItem); + } + } +}; + +///////////////////////////////////////////////////////////////////////////// +// +// Private event handlers +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Handles <li> element mouseover events in the container. + * + * @method _onItemMouseover + * @param v {HTMLEvent} The mouseover event. + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onItemMouseover = function(v,oSelf) { + if(oSelf.prehighlightClassName) { + oSelf._togglePrehighlight(this,"mouseover"); + } + else { + oSelf._toggleHighlight(this,"to"); + } + + oSelf.itemMouseOverEvent.fire(oSelf, this); +}; + +/** + * Handles <li> element mouseout events in the container. + * + * @method _onItemMouseout + * @param v {HTMLEvent} The mouseout event. + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onItemMouseout = function(v,oSelf) { + if(oSelf.prehighlightClassName) { + oSelf._togglePrehighlight(this,"mouseout"); + } + else { + oSelf._toggleHighlight(this,"from"); + } + + oSelf.itemMouseOutEvent.fire(oSelf, this); +}; + +/** + * Handles <li> element click events in the container. + * + * @method _onItemMouseclick + * @param v {HTMLEvent} The click event. + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onItemMouseclick = function(v,oSelf) { + // In case item has not been moused over + oSelf._toggleHighlight(this,"to"); + oSelf._selectItem(this); +}; + +/** + * Handles container mouseover events. + * + * @method _onContainerMouseover + * @param v {HTMLEvent} The mouseover event. + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onContainerMouseover = function(v,oSelf) { + oSelf._bOverContainer = true; +}; + +/** + * Handles container mouseout events. + * + * @method _onContainerMouseout + * @param v {HTMLEvent} The mouseout event. + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onContainerMouseout = function(v,oSelf) { + oSelf._bOverContainer = false; + // If container is still active + if(oSelf._oCurItem) { + oSelf._toggleHighlight(oSelf._oCurItem,"to"); + } +}; + +/** + * Handles container scroll events. + * + * @method _onContainerScroll + * @param v {HTMLEvent} The scroll event. + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onContainerScroll = function(v,oSelf) { + oSelf._oTextbox.focus(); +}; + +/** + * Handles container resize events. + * + * @method _onContainerResize + * @param v {HTMLEvent} The resize event. + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onContainerResize = function(v,oSelf) { + oSelf._toggleContainerHelpers(oSelf._bContainerOpen); +}; + + +/** + * Handles textbox keydown events of functional keys, mainly for UI behavior. + * + * @method _onTextboxKeyDown + * @param v {HTMLEvent} The keydown event. + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onTextboxKeyDown = function(v,oSelf) { + var nKeyCode = v.keyCode; + + switch (nKeyCode) { + case 9: // tab + if(oSelf.delimChar && (oSelf._nKeyCode != nKeyCode)) { + if(oSelf._bContainerOpen) { + YAHOO.util.Event.stopEvent(v); + } + } + // select an item or clear out + if(oSelf._oCurItem) { + oSelf._selectItem(oSelf._oCurItem); + } + else { + oSelf._toggleContainer(false); + } + break; + case 13: // enter + if(oSelf._nKeyCode != nKeyCode) { + if(oSelf._bContainerOpen) { + YAHOO.util.Event.stopEvent(v); + } + } + if(oSelf._oCurItem) { + oSelf._selectItem(oSelf._oCurItem); + } + else { + oSelf._toggleContainer(false); + } + break; + case 27: // esc + oSelf._toggleContainer(false); + return; + case 39: // right + oSelf._jumpSelection(); + break; + case 38: // up + YAHOO.util.Event.stopEvent(v); + oSelf._moveSelection(nKeyCode); + break; + case 40: // down + YAHOO.util.Event.stopEvent(v); + oSelf._moveSelection(nKeyCode); + break; + default: + break; + } +}; + +/** + * Handles textbox keypress events. + * @method _onTextboxKeyPress + * @param v {HTMLEvent} The keypress event. + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onTextboxKeyPress = function(v,oSelf) { + var nKeyCode = v.keyCode; + + //Expose only to Mac browsers, where stopEvent is ineffective on keydown events (bug 790337) + var isMac = (navigator.userAgent.toLowerCase().indexOf("mac") != -1); + if(isMac) { + switch (nKeyCode) { + case 9: // tab + if(oSelf.delimChar && (oSelf._nKeyCode != nKeyCode)) { + if(oSelf._bContainerOpen) { + YAHOO.util.Event.stopEvent(v); + } + } + break; + case 13: // enter + if(oSelf._nKeyCode != nKeyCode) { + if(oSelf._bContainerOpen) { + YAHOO.util.Event.stopEvent(v); + } + } + break; + case 38: // up + case 40: // down + YAHOO.util.Event.stopEvent(v); + break; + default: + break; + } + } + + //TODO: (?) limit only to non-IE, non-Mac-FF for Korean IME support (bug 811948) + // Korean IME detected + else if(nKeyCode == 229) { + oSelf._queryInterval = setInterval(function() { oSelf._onIMEDetected(oSelf); },500); + } +}; + +/** + * Handles textbox keyup events that trigger queries. + * + * @method _onTextboxKeyUp + * @param v {HTMLEvent} The keyup event. + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onTextboxKeyUp = function(v,oSelf) { + // Check to see if any of the public properties have been updated + oSelf._initProps(); + + var nKeyCode = v.keyCode; + oSelf._nKeyCode = nKeyCode; + var sText = this.value; //string in textbox + + // Filter out chars that don't trigger queries + if (oSelf._isIgnoreKey(nKeyCode) || (sText.toLowerCase() == oSelf._sCurQuery)) { + return; + } + else { + oSelf.textboxKeyEvent.fire(oSelf, nKeyCode); + } + + // Set timeout on the request + if (oSelf.queryDelay > 0) { + var nDelayID = + setTimeout(function(){oSelf._sendQuery(sText);},(oSelf.queryDelay * 1000)); + + if (oSelf._nDelayID != -1) { + clearTimeout(oSelf._nDelayID); + } + + oSelf._nDelayID = nDelayID; + } + else { + // No delay so send request immediately + oSelf._sendQuery(sText); + } +}; + +/** + * Handles text input box receiving focus. + * + * @method _onTextboxFocus + * @param v {HTMLEvent} The focus event. + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onTextboxFocus = function (v,oSelf) { + oSelf._oTextbox.setAttribute("autocomplete","off"); + oSelf._bFocused = true; + oSelf.textboxFocusEvent.fire(oSelf); +}; + +/** + * Handles text input box losing focus. + * + * @method _onTextboxBlur + * @param v {HTMLEvent} The focus event. + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onTextboxBlur = function (v,oSelf) { + // Don't treat as a blur if it was a selection via mouse click + if(!oSelf._bOverContainer || (oSelf._nKeyCode == 9)) { + // Current query needs to be validated + if(!oSelf._bItemSelected) { + if(!oSelf._bContainerOpen || (oSelf._bContainerOpen && !oSelf._textMatchesOption())) { + if(oSelf.forceSelection) { + oSelf._clearSelection(); + } + else { + oSelf.unmatchedItemSelectEvent.fire(oSelf, oSelf._sCurQuery); + } + } + } + + if(oSelf._bContainerOpen) { + oSelf._toggleContainer(false); + } + oSelf._cancelIntervalDetection(oSelf); + oSelf._bFocused = false; + oSelf.textboxBlurEvent.fire(oSelf); + } +}; + +/** + * Handles form submission event. + * + * @method _onFormSubmit + * @param v {HTMLEvent} The submit event. + * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. + * @private + */ +YAHOO.widget.AutoComplete.prototype._onFormSubmit = function(v,oSelf) { + if(oSelf.allowBrowserAutocomplete) { + oSelf._oTextbox.setAttribute("autocomplete","on"); + } + else { + oSelf._oTextbox.setAttribute("autocomplete","off"); + } +}; + +/****************************************************************************/ +/****************************************************************************/ +/****************************************************************************/ + +/** + * The DataSource classes manages sending a request and returning response from a live + * database. Supported data include local JavaScript arrays and objects and databases + * accessible via XHR connections. Supported response formats include JavaScript arrays, + * JSON, XML, and flat-file textual data. + * + * @class DataSource + * @constructor + */ +YAHOO.widget.DataSource = function() { + /* abstract class */ +}; + + +///////////////////////////////////////////////////////////////////////////// +// +// Public constants +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Error message for null data responses. + * + * @property ERROR_DATANULL + * @type String + * @static + * @final + */ +YAHOO.widget.DataSource.ERROR_DATANULL = "Response data was null"; + +/** + * Error message for data responses with parsing errors. + * + * @property ERROR_DATAPARSE + * @type String + * @static + * @final + */ +YAHOO.widget.DataSource.ERROR_DATAPARSE = "Response data could not be parsed"; + + +///////////////////////////////////////////////////////////////////////////// +// +// Public member variables +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Max size of the local cache. Set to 0 to turn off caching. Caching is + * useful to reduce the number of server connections. Recommended only for data + * sources that return comprehensive results for queries or when stale data is + * not an issue. + * + * @property maxCacheEntries + * @type Number + * @default 15 + */ +YAHOO.widget.DataSource.prototype.maxCacheEntries = 15; + +/** + * Use this to equate cache matching with the type of matching done by your live + * data source. If caching is on and queryMatchContains is true, the cache + * returns results that "contain" the query string. By default, + * queryMatchContains is set to false, meaning the cache only returns results + * that "start with" the query string. + * + * @property queryMatchContains + * @type Boolean + * @default false + */ +YAHOO.widget.DataSource.prototype.queryMatchContains = false; + +/** + * Enables query subset matching. If caching is on and queryMatchSubset is + * true, substrings of queries will return matching cached results. For + * instance, if the first query is for "abc" susequent queries that start with + * "abc", like "abcd", will be queried against the cache, and not the live data + * source. Recommended only for DataSources that return comprehensive results + * for queries with very few characters. + * + * @property queryMatchSubset + * @type Boolean + * @default false + * + */ +YAHOO.widget.DataSource.prototype.queryMatchSubset = false; + +/** + * Enables query case-sensitivity matching. If caching is on and + * queryMatchCase is true, queries will only return results for case-sensitive + * matches. + * + * @property queryMatchCase + * @type Boolean + * @default false + */ +YAHOO.widget.DataSource.prototype.queryMatchCase = false; + + +///////////////////////////////////////////////////////////////////////////// +// +// Public methods +// +///////////////////////////////////////////////////////////////////////////// + + /** + * Public accessor to the unique name of the DataSource instance. + * + * @method toString + * @return {String} Unique name of the DataSource instance + */ +YAHOO.widget.DataSource.prototype.toString = function() { + return "DataSource " + this._sName; +}; + +/** + * Retrieves query results, first checking the local cache, then making the + * query request to the live data source as defined by the function doQuery. + * + * @method getResults + * @param oCallbackFn {HTMLFunction} Callback function defined by oParent object to which to return results. + * @param sQuery {String} Query string. + * @param oParent {Object} The object instance that has requested data. + */ +YAHOO.widget.DataSource.prototype.getResults = function(oCallbackFn, sQuery, oParent) { + + // First look in cache + var aResults = this._doQueryCache(oCallbackFn,sQuery,oParent); + + // Not in cache, so get results from server + if(aResults.length === 0) { + this.queryEvent.fire(this, oParent, sQuery); + this.doQuery(oCallbackFn, sQuery, oParent); + } +}; + +/** + * Abstract method implemented by subclasses to make a query to the live data + * source. Must call the callback function with the response returned from the + * query. Populates cache (if enabled). + * + * @method doQuery + * @param oCallbackFn {HTMLFunction} Callback function implemented by oParent to which to return results. + * @param sQuery {String} Query string. + * @param oParent {Object} The object instance that has requested data. + */ +YAHOO.widget.DataSource.prototype.doQuery = function(oCallbackFn, sQuery, oParent) { + /* override this */ +}; + +/** + * Flushes cache. + * + * @method flushCache + */ +YAHOO.widget.DataSource.prototype.flushCache = function() { + if(this._aCache) { + this._aCache = []; + } + if(this._aCacheHelper) { + this._aCacheHelper = []; + } + this.cacheFlushEvent.fire(this); +}; + +///////////////////////////////////////////////////////////////////////////// +// +// Public events +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Fired when a query is made to the live data source. + * + * @event queryEvent + * @param oSelf {Object} The DataSource instance. + * @param oParent {Object} The requesting object. + * @param sQuery {String} The query string. + */ +YAHOO.widget.DataSource.prototype.queryEvent = null; + +/** + * Fired when a query is made to the local cache. + * + * @event cacheQueryEvent + * @param oSelf {Object} The DataSource instance. + * @param oParent {Object} The requesting object. + * @param sQuery {String} The query string. + */ +YAHOO.widget.DataSource.prototype.cacheQueryEvent = null; + +/** + * Fired when data is retrieved from the live data source. + * + * @event getResultsEvent + * @param oSelf {Object} The DataSource instance. + * @param oParent {Object} The requesting object. + * @param sQuery {String} The query string. + * @param aResults {Object[]} Array of result objects. + */ +YAHOO.widget.DataSource.prototype.getResultsEvent = null; + +/** + * Fired when data is retrieved from the local cache. + * + * @event getCachedResultsEvent + * @param oSelf {Object} The DataSource instance. + * @param oParent {Object} The requesting object. + * @param sQuery {String} The query string. + * @param aResults {Object[]} Array of result objects. + */ +YAHOO.widget.DataSource.prototype.getCachedResultsEvent = null; + +/** + * Fired when an error is encountered with the live data source. + * + * @event dataErrorEvent + * @param oSelf {Object} The DataSource instance. + * @param oParent {Object} The requesting object. + * @param sQuery {String} The query string. + * @param sMsg {String} Error message string + */ +YAHOO.widget.DataSource.prototype.dataErrorEvent = null; + +/** + * Fired when the local cache is flushed. + * + * @event cacheFlushEvent + * @param oSelf {Object} The DataSource instance + */ +YAHOO.widget.DataSource.prototype.cacheFlushEvent = null; + +///////////////////////////////////////////////////////////////////////////// +// +// Private member variables +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Internal class variable to index multiple DataSource instances. + * + * @property _nIndex + * @type Number + * @private + * @static + */ +YAHOO.widget.DataSource._nIndex = 0; + +/** + * Name of DataSource instance. + * + * @property _sName + * @type String + * @private + */ +YAHOO.widget.DataSource.prototype._sName = null; + +/** + * Local cache of data result objects indexed chronologically. + * + * @property _aCache + * @type Object[] + * @private + */ +YAHOO.widget.DataSource.prototype._aCache = null; + + +///////////////////////////////////////////////////////////////////////////// +// +// Private methods +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Initializes DataSource instance. + * + * @method _init + * @private + */ +YAHOO.widget.DataSource.prototype._init = function() { + // Validate and initialize public configs + var maxCacheEntries = this.maxCacheEntries; + if(isNaN(maxCacheEntries) || (maxCacheEntries < 0)) { + maxCacheEntries = 0; + } + // Initialize local cache + if(maxCacheEntries > 0 && !this._aCache) { + this._aCache = []; + } + + this._sName = "instance" + YAHOO.widget.DataSource._nIndex; + YAHOO.widget.DataSource._nIndex++; + + this.queryEvent = new YAHOO.util.CustomEvent("query", this); + this.cacheQueryEvent = new YAHOO.util.CustomEvent("cacheQuery", this); + this.getResultsEvent = new YAHOO.util.CustomEvent("getResults", this); + this.getCachedResultsEvent = new YAHOO.util.CustomEvent("getCachedResults", this); + this.dataErrorEvent = new YAHOO.util.CustomEvent("dataError", this); + this.cacheFlushEvent = new YAHOO.util.CustomEvent("cacheFlush", this); +}; + +/** + * Adds a result object to the local cache, evicting the oldest element if the + * cache is full. Newer items will have higher indexes, the oldest item will have + * index of 0. + * + * @method _addCacheElem + * @param oResult {Object} Data result object, including array of results. + * @private + */ +YAHOO.widget.DataSource.prototype._addCacheElem = function(oResult) { + var aCache = this._aCache; + // Don't add if anything important is missing. + if(!aCache || !oResult || !oResult.query || !oResult.results) { + return; + } + + // If the cache is full, make room by removing from index=0 + if(aCache.length >= this.maxCacheEntries) { + aCache.shift(); + } + + // Add to cache, at the end of the array + aCache.push(oResult); +}; + +/** + * Queries the local cache for results. If query has been cached, the callback + * function is called with the results, and the cached is refreshed so that it + * is now the newest element. + * + * @method _doQueryCache + * @param oCallbackFn {HTMLFunction} Callback function defined by oParent object to which to return results. + * @param sQuery {String} Query string. + * @param oParent {Object} The object instance that has requested data. + * @return aResults {Object[]} Array of results from local cache if found, otherwise null. + * @private + */ +YAHOO.widget.DataSource.prototype._doQueryCache = function(oCallbackFn, sQuery, oParent) { + var aResults = []; + var bMatchFound = false; + var aCache = this._aCache; + var nCacheLength = (aCache) ? aCache.length : 0; + var bMatchContains = this.queryMatchContains; + + // If cache is enabled... + if((this.maxCacheEntries > 0) && aCache && (nCacheLength > 0)) { + this.cacheQueryEvent.fire(this, oParent, sQuery); + // If case is unimportant, normalize query now instead of in loops + if(!this.queryMatchCase) { + var sOrigQuery = sQuery; + sQuery = sQuery.toLowerCase(); + } + + // Loop through each cached element's query property... + for(var i = nCacheLength-1; i >= 0; i--) { + var resultObj = aCache[i]; + var aAllResultItems = resultObj.results; + // If case is unimportant, normalize match key for comparison + var matchKey = (!this.queryMatchCase) ? + encodeURIComponent(resultObj.query).toLowerCase(): + encodeURIComponent(resultObj.query); + + // If a cached match key exactly matches the query... + if(matchKey == sQuery) { + // Stash all result objects into aResult[] and stop looping through the cache. + bMatchFound = true; + aResults = aAllResultItems; + + // The matching cache element was not the most recent, + // so now we need to refresh the cache. + if(i != nCacheLength-1) { + // Remove element from its original location + aCache.splice(i,1); + // Add element as newest + this._addCacheElem(resultObj); + } + break; + } + // Else if this query is not an exact match and subset matching is enabled... + else if(this.queryMatchSubset) { + // Loop through substrings of each cached element's query property... + for(var j = sQuery.length-1; j >= 0 ; j--) { + var subQuery = sQuery.substr(0,j); + + // If a substring of a cached sQuery exactly matches the query... + if(matchKey == subQuery) { + bMatchFound = true; + + // Go through each cached result object to match against the query... + for(var k = aAllResultItems.length-1; k >= 0; k--) { + var aRecord = aAllResultItems[k]; + var sKeyIndex = (this.queryMatchCase) ? + encodeURIComponent(aRecord[0]).indexOf(sQuery): + encodeURIComponent(aRecord[0]).toLowerCase().indexOf(sQuery); + + // A STARTSWITH match is when the query is found at the beginning of the key string... + if((!bMatchContains && (sKeyIndex === 0)) || + // A CONTAINS match is when the query is found anywhere within the key string... + (bMatchContains && (sKeyIndex > -1))) { + // Stash a match into aResults[]. + aResults.unshift(aRecord); + } + } + + // Add the subset match result set object as the newest element to cache, + // and stop looping through the cache. + resultObj = {}; + resultObj.query = sQuery; + resultObj.results = aResults; + this._addCacheElem(resultObj); + break; + } + } + if(bMatchFound) { + break; + } + } + } + + // If there was a match, send along the results. + if(bMatchFound) { + this.getCachedResultsEvent.fire(this, oParent, sOrigQuery, aResults); + oCallbackFn(sOrigQuery, aResults, oParent); + } + } + return aResults; +}; + + +/****************************************************************************/ +/****************************************************************************/ +/****************************************************************************/ + +/** + * Implementation of YAHOO.widget.DataSource using XML HTTP requests that return + * query results. + * + * @class DS_XHR + * @extends YAHOO.widget.DataSource + * @requires connection + * @constructor + * @param sScriptURI {String} Absolute or relative URI to script that returns query + * results as JSON, XML, or delimited flat-file data. + * @param aSchema {String[]} Data schema definition of results. + * @param oConfigs {Object} (optional) Object literal of config params. + */ +YAHOO.widget.DS_XHR = function(sScriptURI, aSchema, oConfigs) { + // Set any config params passed in to override defaults + if(typeof oConfigs == "object") { + for(var sConfig in oConfigs) { + this[sConfig] = oConfigs[sConfig]; + } + } + + // Initialization sequence + if(!aSchema || (aSchema.constructor != Array)) { + return; + } + else { + this.schema = aSchema; + } + this.scriptURI = sScriptURI; + this._init(); +}; + +YAHOO.widget.DS_XHR.prototype = new YAHOO.widget.DataSource(); + +///////////////////////////////////////////////////////////////////////////// +// +// Public constants +// +///////////////////////////////////////////////////////////////////////////// + +/** + * JSON data type. + * + * @property TYPE_JSON + * @type Number + * @static + * @final + */ +YAHOO.widget.DS_XHR.TYPE_JSON = 0; + +/** + * XML data type. + * + * @property TYPE_XML + * @type Number + * @static + * @final + */ +YAHOO.widget.DS_XHR.TYPE_XML = 1; + +/** + * Flat-file data type. + * + * @property TYPE_FLAT + * @type Number + * @static + * @final + */ +YAHOO.widget.DS_XHR.TYPE_FLAT = 2; + +/** + * Error message for XHR failure. + * + * @property ERROR_DATAXHR + * @type String + * @static + * @final + */ +YAHOO.widget.DS_XHR.ERROR_DATAXHR = "XHR response failed"; + +///////////////////////////////////////////////////////////////////////////// +// +// Public member variables +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Alias to YUI Connection Manager. Allows implementers to specify their own + * subclasses of the YUI Connection Manager utility. + * + * @property connMgr + * @type Object + * @default YAHOO.util.Connect + */ +YAHOO.widget.DS_XHR.prototype.connMgr = YAHOO.util.Connect; + +/** + * Number of milliseconds the XHR connection will wait for a server response. A + * a value of zero indicates the XHR connection will wait forever. Any value + * greater than zero will use the Connection utility's Auto-Abort feature. + * + * @property connTimeout + * @type Number + * @default 0 + */ +YAHOO.widget.DS_XHR.prototype.connTimeout = 0; + +/** + * Absolute or relative URI to script that returns query results. For instance, + * queries will be sent to <scriptURI>?<scriptQueryParam>=userinput + * + * @property scriptURI + * @type String + */ +YAHOO.widget.DS_XHR.prototype.scriptURI = null; + +/** + * Query string parameter name sent to scriptURI. For instance, queries will be + * sent to <scriptURI>?<scriptQueryParam>=userinput + * + * @property scriptQueryParam + * @type String + * @default "query" + */ +YAHOO.widget.DS_XHR.prototype.scriptQueryParam = "query"; + +/** + * String of key/value pairs to append to requests made to scriptURI. Define + * this string when you want to send additional query parameters to your script. + * When defined, queries will be sent to + * <scriptURI>?<scriptQueryParam>=userinput&<scriptQueryAppend> + * + * @property scriptQueryAppend + * @type String + * @default "" + */ +YAHOO.widget.DS_XHR.prototype.scriptQueryAppend = ""; + +/** + * XHR response data type. Other types that may be defined are YAHOO.widget.DS_XHR.TYPE_XML + * and YAHOO.widget.DS_XHR.TYPE_FLAT. + * + * @property responseType + * @type String + * @default YAHOO.widget.DS_XHR.TYPE_JSON + */ +YAHOO.widget.DS_XHR.prototype.responseType = YAHOO.widget.DS_XHR.TYPE_JSON; + +/** + * String after which to strip results. If the results from the XHR are sent + * back as HTML, the gzip HTML comment appears at the end of the data and should + * be ignored. + * + * @property responseStripAfter + * @type String + * @default "\n<!-" + */ +YAHOO.widget.DS_XHR.prototype.responseStripAfter = "\n 0) { + sUri += "&" + this.scriptQueryAppend; + } + var oResponse = null; + + var oSelf = this; + /* + * Sets up ajax request callback + * + * @param {object} oReq HTTPXMLRequest object + * @private + */ + var responseSuccess = function(oResp) { + // Response ID does not match last made request ID. + if(!oSelf._oConn || (oResp.tId != oSelf._oConn.tId)) { + oSelf.dataErrorEvent.fire(oSelf, oParent, sQuery, YAHOO.widget.DataSource.ERROR_DATANULL); + return; + } +//DEBUG +for(var foo in oResp) { +} + if(!isXML) { + oResp = oResp.responseText; + } + else { + oResp = oResp.responseXML; + } + if(oResp === null) { + oSelf.dataErrorEvent.fire(oSelf, oParent, sQuery, YAHOO.widget.DataSource.ERROR_DATANULL); + return; + } + + var aResults = oSelf.parseResponse(sQuery, oResp, oParent); + var resultObj = {}; + resultObj.query = decodeURIComponent(sQuery); + resultObj.results = aResults; + if(aResults === null) { + oSelf.dataErrorEvent.fire(oSelf, oParent, sQuery, YAHOO.widget.DataSource.ERROR_DATAPARSE); + aResults = []; + } + else { + oSelf.getResultsEvent.fire(oSelf, oParent, sQuery, aResults); + oSelf._addCacheElem(resultObj); + } + oCallbackFn(sQuery, aResults, oParent); + }; + + var responseFailure = function(oResp) { + oSelf.dataErrorEvent.fire(oSelf, oParent, sQuery, YAHOO.widget.DS_XHR.ERROR_DATAXHR); + return; + }; + + var oCallback = { + success:responseSuccess, + failure:responseFailure + }; + + if(!isNaN(this.connTimeout) && this.connTimeout > 0) { + oCallback.timeout = this.connTimeout; + } + + if(this._oConn) { + this.connMgr.abort(this._oConn); + } + + oSelf._oConn = this.connMgr.asyncRequest("GET", sUri, oCallback, null); +}; + +/** + * Parses raw response data into an array of result objects. The result data key + * is always stashed in the [0] element of each result object. + * + * @method parseResponse + * @param sQuery {String} Query string. + * @param oResponse {Object} The raw response data to parse. + * @param oParent {Object} The object instance that has requested data. + * @returns {Object[]} Array of result objects. + */ +YAHOO.widget.DS_XHR.prototype.parseResponse = function(sQuery, oResponse, oParent) { + var aSchema = this.schema; + var aResults = []; + var bError = false; + + // Strip out comment at the end of results + var nEnd = ((this.responseStripAfter !== "") && (oResponse.indexOf)) ? + oResponse.indexOf(this.responseStripAfter) : -1; + if(nEnd != -1) { + oResponse = oResponse.substring(0,nEnd); + } + + switch (this.responseType) { + case YAHOO.widget.DS_XHR.TYPE_JSON: + var jsonList; + // Divert KHTML clients from JSON lib + if(window.JSON && (navigator.userAgent.toLowerCase().indexOf('khtml')== -1)) { + // Use the JSON utility if available + var jsonObjParsed = JSON.parse(oResponse); + if(!jsonObjParsed) { + bError = true; + break; + } + else { + try { + // eval is necessary here since aSchema[0] is of unknown depth + jsonList = eval("jsonObjParsed." + aSchema[0]); + } + catch(e) { + bError = true; + break; + } + } + } + else { + // Parse the JSON response as a string + try { + // Trim leading spaces + while (oResponse.substring(0,1) == " ") { + oResponse = oResponse.substring(1, oResponse.length); + } + + // Invalid JSON response + if(oResponse.indexOf("{") < 0) { + bError = true; + break; + } + + // Empty (but not invalid) JSON response + if(oResponse.indexOf("{}") === 0) { + break; + } + + // Turn the string into an object literal... + // ...eval is necessary here + var jsonObjRaw = eval("(" + oResponse + ")"); + if(!jsonObjRaw) { + bError = true; + break; + } + + // Grab the object member that contains an array of all reponses... + // ...eval is necessary here since aSchema[0] is of unknown depth + jsonList = eval("(jsonObjRaw." + aSchema[0]+")"); + } + catch(e) { + bError = true; + break; + } + } + + if(!jsonList) { + bError = true; + break; + } + + if(jsonList.constructor != Array) { + jsonList = [jsonList]; + } + + // Loop through the array of all responses... + for(var i = jsonList.length-1; i >= 0 ; i--) { + var aResultItem = []; + var jsonResult = jsonList[i]; + // ...and loop through each data field value of each response + for(var j = aSchema.length-1; j >= 1 ; j--) { + // ...and capture data into an array mapped according to the schema... + var dataFieldValue = jsonResult[aSchema[j]]; + if(!dataFieldValue) { + dataFieldValue = ""; + } + aResultItem.unshift(dataFieldValue); + } + // If schema isn't well defined, pass along the entire result object + if(aResultItem.length == 1) { + aResultItem.push(jsonResult); + } + // Capture the array of data field values in an array of results + aResults.unshift(aResultItem); + } + break; + case YAHOO.widget.DS_XHR.TYPE_XML: + // Get the collection of results + var xmlList = oResponse.getElementsByTagName(aSchema[0]); + if(!xmlList) { + bError = true; + break; + } + // Loop through each result + for(var k = xmlList.length-1; k >= 0 ; k--) { + var result = xmlList.item(k); + var aFieldSet = []; + // Loop through each data field in each result using the schema + for(var m = aSchema.length-1; m >= 1 ; m--) { + var sValue = null; + // Values may be held in an attribute... + var xmlAttr = result.attributes.getNamedItem(aSchema[m]); + if(xmlAttr) { + sValue = xmlAttr.value; + } + // ...or in a node + else{ + var xmlNode = result.getElementsByTagName(aSchema[m]); + if(xmlNode && xmlNode.item(0) && xmlNode.item(0).firstChild) { + sValue = xmlNode.item(0).firstChild.nodeValue; + } + else { + sValue = ""; + } + } + // Capture the schema-mapped data field values into an array + aFieldSet.unshift(sValue); + } + // Capture each array of values into an array of results + aResults.unshift(aFieldSet); + } + break; + case YAHOO.widget.DS_XHR.TYPE_FLAT: + if(oResponse.length > 0) { + // Delete the last line delimiter at the end of the data if it exists + var newLength = oResponse.length-aSchema[0].length; + if(oResponse.substr(newLength) == aSchema[0]) { + oResponse = oResponse.substr(0, newLength); + } + var aRecords = oResponse.split(aSchema[0]); + for(var n = aRecords.length-1; n >= 0; n--) { + aResults[n] = aRecords[n].split(aSchema[1]); + } + } + break; + default: + break; + } + sQuery = null; + oResponse = null; + oParent = null; + if(bError) { + return null; + } + else { + return aResults; + } +}; + +///////////////////////////////////////////////////////////////////////////// +// +// Private member variables +// +///////////////////////////////////////////////////////////////////////////// + +/** + * XHR connection object. + * + * @property _oConn + * @type Object + * @private + */ +YAHOO.widget.DS_XHR.prototype._oConn = null; + + +/****************************************************************************/ +/****************************************************************************/ +/****************************************************************************/ + +/** + * Implementation of YAHOO.widget.DataSource using a native Javascript function as + * its live data source. + * + * @class DS_JSFunction + * @constructor + * @extends YAHOO.widget.DataSource + * @param oFunction {HTMLFunction} In-memory Javascript function that returns query results as an array of objects. + * @param oConfigs {Object} (optional) Object literal of config params. + */ +YAHOO.widget.DS_JSFunction = function(oFunction, oConfigs) { + // Set any config params passed in to override defaults + if(typeof oConfigs == "object") { + for(var sConfig in oConfigs) { + this[sConfig] = oConfigs[sConfig]; + } + } + + // Initialization sequence + if(!oFunction || (oFunction.constructor != Function)) { + return; + } + else { + this.dataFunction = oFunction; + this._init(); + } +}; + +YAHOO.widget.DS_JSFunction.prototype = new YAHOO.widget.DataSource(); + +///////////////////////////////////////////////////////////////////////////// +// +// Public member variables +// +///////////////////////////////////////////////////////////////////////////// + +/** + * In-memory Javascript function that returns query results. + * + * @property dataFunction + * @type HTMLFunction + */ +YAHOO.widget.DS_JSFunction.prototype.dataFunction = null; + +///////////////////////////////////////////////////////////////////////////// +// +// Public methods +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Queries the live data source defined by function for results. Results are + * passed back to a callback function. + * + * @method doQuery + * @param oCallbackFn {HTMLFunction} Callback function defined by oParent object to which to return results. + * @param sQuery {String} Query string. + * @param oParent {Object} The object instance that has requested data. + */ +YAHOO.widget.DS_JSFunction.prototype.doQuery = function(oCallbackFn, sQuery, oParent) { + var oFunction = this.dataFunction; + var aResults = []; + + aResults = oFunction(sQuery); + if(aResults === null) { + this.dataErrorEvent.fire(this, oParent, sQuery, YAHOO.widget.DataSource.ERROR_DATANULL); + return; + } + + var resultObj = {}; + resultObj.query = decodeURIComponent(sQuery); + resultObj.results = aResults; + this._addCacheElem(resultObj); + + this.getResultsEvent.fire(this, oParent, sQuery, aResults); + oCallbackFn(sQuery, aResults, oParent); + return; +}; + +/****************************************************************************/ +/****************************************************************************/ +/****************************************************************************/ + +/** + * Implementation of YAHOO.widget.DataSource using a native Javascript array as + * its live data source. + * + * @class DS_JSArray + * @constructor + * @extends YAHOO.widget.DataSource + * @param aData {String[]} In-memory Javascript array of simple string data. + * @param oConfigs {Object} (optional) Object literal of config params. + */ +YAHOO.widget.DS_JSArray = function(aData, oConfigs) { + // Set any config params passed in to override defaults + if(typeof oConfigs == "object") { + for(var sConfig in oConfigs) { + this[sConfig] = oConfigs[sConfig]; + } + } + + // Initialization sequence + if(!aData || (aData.constructor != Array)) { + return; + } + else { + this.data = aData; + this._init(); + } +}; + +YAHOO.widget.DS_JSArray.prototype = new YAHOO.widget.DataSource(); + +///////////////////////////////////////////////////////////////////////////// +// +// Public member variables +// +///////////////////////////////////////////////////////////////////////////// + +/** + * In-memory Javascript array of strings. + * + * @property data + * @type Array + */ +YAHOO.widget.DS_JSArray.prototype.data = null; + +///////////////////////////////////////////////////////////////////////////// +// +// Public methods +// +///////////////////////////////////////////////////////////////////////////// + +/** + * Queries the live data source defined by data for results. Results are passed + * back to a callback function. + * + * @method doQuery + * @param oCallbackFn {HTMLFunction} Callback function defined by oParent object to which to return results. + * @param sQuery {String} Query string. + * @param oParent {Object} The object instance that has requested data. + */ +YAHOO.widget.DS_JSArray.prototype.doQuery = function(oCallbackFn, sQuery, oParent) { + var aData = this.data; // the array + var aResults = []; // container for results + var bMatchFound = false; + var bMatchContains = this.queryMatchContains; + if(sQuery) { + if(!this.queryMatchCase) { + sQuery = sQuery.toLowerCase(); + } + + // Loop through each element of the array... + // which can be a string or an array of strings + for(var i = aData.length-1; i >= 0; i--) { + var aDataset = []; + + if(aData[i]) { + if(aData[i].constructor == String) { + aDataset[0] = aData[i]; + } + else if(aData[i].constructor == Array) { + aDataset = aData[i]; + } + } + + if(aDataset[0] && (aDataset[0].constructor == String)) { + var sKeyIndex = (this.queryMatchCase) ? + encodeURIComponent(aDataset[0]).indexOf(sQuery): + encodeURIComponent(aDataset[0]).toLowerCase().indexOf(sQuery); + + // A STARTSWITH match is when the query is found at the beginning of the key string... + if((!bMatchContains && (sKeyIndex === 0)) || + // A CONTAINS match is when the query is found anywhere within the key string... + (bMatchContains && (sKeyIndex > -1))) { + // Stash a match into aResults[]. + aResults.unshift(aDataset); + } + } + } + } + + this.getResultsEvent.fire(this, oParent, sQuery, aResults); + oCallbackFn(sQuery, aResults, oParent); +}; + +YAHOO.register("autocomplete", YAHOO.widget.AutoComplete, {version: "2.2.0", build: "127"}); diff --git a/interface/web/js/yui/button/README b/interface/web/js/yui/button/README new file mode 100644 index 000000000..036e33d9c --- /dev/null +++ b/interface/web/js/yui/button/README @@ -0,0 +1,3 @@ +*** Version 2.2.0 *** + +* Button Control introduced \ No newline at end of file diff --git a/interface/web/js/yui/button/assets/background.png b/interface/web/js/yui/button/assets/background.png new file mode 100644 index 0000000000000000000000000000000000000000..87c85b5e539b5c514df107bbb4e298948a016e3d GIT binary patch literal 185 zcmeAS@N?(olHy`uVBq!ia0vp^j6iI}!3HGf{@&OHq*&4&eH|GXuHCreA7KRKOP07s zlmzFem6RtIr7}3C4z5p~n gmGe&ZegFVdQ&MBb@01E{`BLDyZ literal 0 HcmV?d00001 diff --git a/interface/web/js/yui/button/assets/button.css b/interface/web/js/yui/button/assets/button.css new file mode 100644 index 000000000..7e1904720 --- /dev/null +++ b/interface/web/js/yui/button/assets/button.css @@ -0,0 +1,217 @@ +/* +Copyright (c) 2007, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.net/yui/license.txt +version: 2.2.0 +*/ +.yuibutton { + + display:-moz-inline-stack; /* Gecko */ + display:inline-block; /* IE, Opera and Safari */ + + border-width:1px 0; + border-style:solid; + border-color:#999; + + background:#ecece3 url(background.png) left center; + + /* Give the transparent background image to IE 6 */ + _background-image:none; + _filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../../build/button/assets/background.png', sizingMethod = 'scale'); + + margin:auto .25em; + +} + +.yuibutton .first-child { + + display:block; /* Gecko, Opera and Safari */ + *display:inline-block; /* IE */ + + border-width:0 1px; + border-style:solid; + border-color:#999; + + margin:0 -1px; + *position:relative; + *left:-1px; + +} + +.yuibutton button, +.yuibutton a { + + display:block; /* Opera and Safari */ + display:-moz-inline-block; /* Gecko */ + *display:inline-block; /* IE */ + padding:.25em .5em; + border:1px solid #ccc; + +} + +.yuibutton button { + + overflow:visible; /* Remove superfluous padding for IE */ + font-size:100%; /* Makes form controls resizable in IE */ + background-color:transparent; + cursor:pointer; + cursor:hand; + +} + +.yuibutton a { + + text-decoration:none; + color:#000; + +} + +.yuibutton.splitbutton button, +.yuibutton.menubutton button { + + padding-right:20px; + background-position:right center; + background-repeat:no-repeat; + +} + +.yuibutton.menubutton button { + + background-image:url(menuarrow.gif); + +} + +.yuibutton.splitbutton button { + + background-image:url(splitarrow.gif); + +} + + +/* Focus state */ + +.yuibutton.focus { + + border-color:#5e5c95; + +} + +.yuibutton.focus .first-child { + + border-color:#5e5c95; + +} + +.yuibutton.focus button, +.yuibutton.focus a { + + border-color:#cec1fc; + +} + + +/* Hover state */ + +.yuibutton.hover { + + border-color:#406fac; + background-color:#98d5fc; + +} + +.yuibutton.hover .first-child { + + border-color:#406fac; + +} + +.yuibutton.hover button, +.yuibutton.hover a { + + border-color:#7099ce; + +} + + +/* Active state */ + +.yuibutton.active { + + border-color:#7a8180; + background-color:#333; + +} + +.yuibutton.active .first-child { + + border-color:#7a8180; + +} + +.yuibutton.active button, +.yuibutton.active a { + + border-color:#98a09f; + +} + +.yuibutton.splitbutton.activeoption button { + + background-color:transparent; + background-image:url(splitarrow_active.gif); + +} + + + +/* Checked state */ + +.yuibutton.radio.checked, +.yuibutton.checkbox.checked { + + border-color:#7a8180; + background-color:#333; + +} + +.yuibutton.radio.checked .first-child, +.yuibutton.checkbox.checked .first-child { + + border-color:#7a8180; + +} + +.yuibutton.radio.checked button, +.yuibutton.checkbox.checked button { + + border-color:#98a09f; + +} + + + +/* Disabled state */ + +.yuibutton.disabled { + + border-color:#cbcdc5; + background:#ecece3; + + _filter:none; + +} + +.yuibutton.disabled .first-child { + + border-color:#cbcdc5; + +} + +.yuibutton.disabled button, +.yuibutton.disabled a { + + border-color:transparent; + color:#b9b9b9; + cursor:default; + +} \ No newline at end of file diff --git a/interface/web/js/yui/button/assets/menuarrow.gif b/interface/web/js/yui/button/assets/menuarrow.gif new file mode 100644 index 0000000000000000000000000000000000000000..ffa2ba9d25d7ec10438cc1c8ac043c99d4cd7d55 GIT binary patch literal 67 zcmZ?wbhEHb6ky|Ns9CV4(Pug^_`Ql|cu@1F22A-3wdUSxVwHR<{`lNF$F-vEqUn2Y8&$0d-hKG>=h?8FBOG%?}?woIihl=FFK4V4(Pu1x)LJNRV0v<}i=o zJMUhd6kEPVY~7m5?>x^sWoFJ4vs!tbZ4>{Wz3(EXf1kPh_pR*oSZnUBCRWL(;*Za*b6hLhE}Fjgwo%oZ;N6E`f1cgu%fMg_0M=nV82|tP literal 0 HcmV?d00001 diff --git a/interface/web/js/yui/button/button-beta-debug.js b/interface/web/js/yui/button/button-beta-debug.js new file mode 100644 index 000000000..c2c0e094b --- /dev/null +++ b/interface/web/js/yui/button/button-beta-debug.js @@ -0,0 +1,4061 @@ +/* +Copyright (c) 2007, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.net/yui/license.txt +version: 2.2.0 +*/ +/** +* @module button +* @description

The Button Control enables the creation of rich, graphical +* buttons that function like traditional HTML form buttons. Unlike +* tradition HTML form buttons, buttons created with the Button Control can have +* a label that is different from its value. With the inclusion of the optional +* Menu Control, the Button Control can also be +* used to create menu buttons and split buttons, controls that are not +* available natively in HTML. The Button Control can also be thought of as a +* way to create more visually engaging implementations of the browser's +* default radio-button and check-box controls.

+*

The Button Control supports the following types:

+*
+*
button
+*
Basic push button that can execute a user-specified command when +* pressed.
+*
link
+*
Navigates to a specified url when pressed.
+*
submit
+*
Submits the parent form when pressed.
+*
reset
+*
Resets the parent form when pressed.
+*
checkbox
+*
Maintains a "checked" state that can be toggled on and off.
+*
radio
+*
Maintains a "checked" state that can be toggled on and off. Use with +* the ButtonGroup class to create a set of controls that are mutually +* exclusive; checking one button in the set will uncheck all others in +* the group.
+*
menubutton
+*
When pressed will show/hide a menu.
+*
splitbutton
+*
Can execute a user-specified command or display a menu when pressed.
+*
+* @title Button +* @namespace YAHOO.widget +* @requires yahoo, dom, element, event +* @optional container, menu +* @beta +*/ + + +(function() { + +// Shorthard for utilities + +var Dom = YAHOO.util.Dom, + Event = YAHOO.util.Event, + Lang = YAHOO.lang, + + + // Private member variables + + m_oButtons = {}, + m_oFocusedButton = null; + + + +// Constructor + + +/** +* The Button class creates a rich, graphical button. +* @param {String} p_oElement String specifying the id attribute of the +* <input>, <a> or +* <span> element to be used to create the button. +* @param {HTMLInputElement|HTMLElement} p_oElement Object reference for the +* <input>, <a> or +* <span> element to be used to create the button. +* @param {Object} p_oElement Object literal specifying a set of configuration +* attributes used to create the button. +* @param {Object} p_oAttributes Optional. Object literal specifying a set of +* configuration attributes used to create the button. +* @namespace YAHOO.widget +* @class Button +* @constructor +* @extends YAHOO.util.Element +*/ +YAHOO.widget.Button = function(p_oElement, p_oAttributes) { + + var fnSuperClass = YAHOO.widget.Button.superclass.constructor; + + if( + arguments.length == 1 && + !Lang.isString(p_oElement) && + !p_oElement.nodeName + ) { + + if(!p_oElement.id) { + + p_oElement.id = Dom.generateId(); + + YAHOO.log( + "No value specified for the button's \"id\" attribute. " + + "Setting button id to \"" + p_oElement.id + "\".", + "warn" + ); + + } + + this.logger = new YAHOO.widget.LogWriter("Button " + p_oElement.id); + + this.logger.log( + "No source HTML element. " + + "Building the button using the set of configuration attributes." + ); + + fnSuperClass.call( + this, + (this._createButtonElement(p_oElement.type)), + p_oElement + ); + + } + else { + + var oConfig = { + + element: null, + attributes: (p_oAttributes || {}) + + }; + + + if(Lang.isString(p_oElement)) { + + var me = this; + + Event.onAvailable(p_oElement, function() { + + var sTagName = this.tagName.toUpperCase(); + + if(sTagName == me.TAG_NAME) { + + oConfig.attributes.id = this.id; + + } + else if(sTagName == "INPUT" && !oConfig.attributes.id) { + + oConfig.attributes.id = Dom.generateId(); + + YAHOO.log( + "No value specified for the button's \"id\" " + + "attribute. Setting button id to \"" + + oConfig.attributes.id + "\".", + "warn" + ); + + } + + me.logger = new YAHOO.widget.LogWriter( + "Button " + oConfig.attributes.id + ); + + me.logger.log( + "Building the button using an existing HTML " + + "element as a source element." + ); + + + oConfig.attributes.srcelement = this; + + initConfig.call(me, oConfig); + + + if(!oConfig.element) { + + me.logger.log( + "Source element could not be used as is. " + + "Creating a new HTML element for the button." + ); + + oConfig.element = + me._createButtonElement(oConfig.attributes.type); + + } + + fnSuperClass.call(me, oConfig.element, oConfig.attributes); + + }); + + } + else { + + var sTagName = p_oElement.tagName.toUpperCase(); + + if(sTagName == this.TAG_NAME) { + + if(p_oElement.id) { + + oConfig.attributes.id = p_oElement.id; + + } + else { + + oConfig.attributes.id = Dom.generateId(); + + YAHOO.log( + "No value specified for the button's \"id\" " + + "attribute. Setting button id to \"" + + oConfig.attributes.id + "\".", + "warn" + ); + + } + + + } + else if(sTagName == "INPUT" && !oConfig.attributes.id) { + + oConfig.attributes.id = Dom.generateId(); + + YAHOO.log( + "No value specified for the button's \"id\" " + + "attribute. Setting button id to \"" + + oConfig.attributes.id + "\".", + "warn" + ); + + } + + this.logger = + new YAHOO.widget.LogWriter("Button " + oConfig.attributes.id); + + this.logger.log( + "Building the button using an existing HTML element as " + + "a source element." + ); + + + oConfig.attributes.srcelement = p_oElement; + + initConfig.call(this, oConfig); + + + if(!oConfig.element) { + + this.logger.log( + "Source element could not be used as is. " + + "Creating a new HTML element for the button." + ); + + oConfig.element = + this._createButtonElement(oConfig.attributes.type); + + } + + fnSuperClass.call(this, oConfig.element, oConfig.attributes); + + } + + } + +}; + + + +// Private methods + + +/** +* @method getFirstElement +* @description Returns an HTML element's first HTML element node. +* @private +* @param {HTMLElement} p_oElement Object +* reference specifying the element to be evaluated. +* @return {HTMLElement} +*/ +function getFirstElement(p_oElement) { + + var oFirstChild = p_oElement.firstChild; + + if(oFirstChild) { + + if(oFirstChild.nodeType == 1) { + + return oFirstChild; + + } + else { + + var oNextSibling = oFirstChild.nextSibling; + + if(oNextSibling && oNextSibling.nodeType == 1) { + + return oNextSibling; + + } + + } + + } + +} + + +/** +* @method createInputElement +* @description Creates an <input> element of the +* specified type. +* @private +* @param {String} p_sType String specifying the type of +* <input> element to create. +* @param {String} p_sName String specifying the name of +* <input> element to create. +* @param {String} p_sValue String specifying the value of +* <input> element to create. +* @param {String} p_bChecked Boolean specifying if the +* <input> element is to be checked. +* @return {HTMLInputElement} +*/ +function createInputElement(p_sType, p_sName, p_sValue, p_bChecked) { + + var oInput; + + if(navigator.userAgent.indexOf("MSIE") != -1) { + + /* + For IE it is necessary to create the element with the + "type," "name," "value," and "checked" properties set all at once. + */ + + var sInput = "<input> or <a>) that map to +* Button configuration attributes and sets them into a collection that is +* passed to the Button constructor. +* @private +* @param {HTMLInputElement|HTMLAnchorElement} p_oElement Object reference to the HTML +* element (either <input> or <span>) +* used to create the button. +* @param {Object} p_oAttributes Object reference for the collection of +* configuration attributes used to create the button. +*/ +function setAttributesFromSrcElement(p_oElement, p_oAttributes) { + + var me = this; + + /** + * @method setAttributeFromDOMAttribute + * @description Gets the value of the specified DOM attribute and sets it + * into the collection of configuration attributes used to configure + * the button. + * @private + * @param {String} p_sAttribute String representing the name of the + * attribute to retrieve from the DOM element. + */ + function setAttributeFromDOMAttribute(p_sAttribute) { + + if( !(p_sAttribute in p_oAttributes) ) { + + /* + Need to use "getAttributeNode" instead of "getAttribute" + because using "getAttribute," IE will return the innerText of + a <button> for the value attribute rather + than the value of the "value" attribute. + */ + + var oAttribute = p_oElement.getAttributeNode(p_sAttribute); + + + if(oAttribute && ("value" in oAttribute)) { + + me.logger.log( + "Setting attribute \"" + p_sAttribute + "\" using " + + "source element's attribute value of \"" + + oAttribute.value + "\"" + ); + + p_oAttributes[p_sAttribute] = oAttribute.value; + + } + + } + + } + + + /** + * @method setFormElementProperties + * @description Gets the value of the attributes from the form element and + * sets them into the collection of configuration attributes used to + * configure the button. + * @private + */ + function setFormElementProperties() { + + setAttributeFromDOMAttribute("type"); + + if( !("disabled" in p_oAttributes) ) { + + p_oAttributes.disabled = p_oElement.disabled; + + } + + setAttributeFromDOMAttribute("name"); + setAttributeFromDOMAttribute("value"); + setAttributeFromDOMAttribute("title"); + + } + + + var sSrcElementTagName = p_oElement.tagName.toUpperCase(); + + + if( !("label" in p_oAttributes) ) { + + // Set the "label" property + + var sText = sSrcElementTagName == "INPUT" ? + p_oElement.value : p_oElement.innerHTML; + + + if(sText && sText.length > 0) { + + p_oAttributes.label = sText; + + } + + } + + + setAttributeFromDOMAttribute("tabindex"); + setAttributeFromDOMAttribute("accesskey"); + + + switch(sSrcElementTagName) { + + case "A": + + p_oAttributes.type = "link"; + + setAttributeFromDOMAttribute("href"); + setAttributeFromDOMAttribute("target"); + + break; + + case "INPUT": + + setFormElementProperties(); + + if( !("checked" in p_oAttributes) ) { + + p_oAttributes.checked = p_oElement.checked; + + } + + break; + + case "BUTTON": + + setFormElementProperties(); + + var oRootNode = p_oElement.parentNode.parentNode; + + if(Dom.hasClass(oRootNode, "checked")) { + + p_oAttributes.checked = true; + + } + + if(Dom.hasClass(oRootNode, "disabled")) { + + p_oAttributes.disabled = true; + + } + + p_oElement.removeAttribute("name"); + p_oElement.removeAttribute("value"); + + p_oElement.setAttribute("type", "button"); + + break; + + } + +} + + +/** +* @method initConfig +* @description Initializes the set of configuration attributes that are used to +* instantiate the button. +* @private +* @param {Object} Object representing the button's set of +* configuration attributes. +*/ +function initConfig(p_oConfig) { + + var oAttributes = p_oConfig.attributes, + oSrcElement = oAttributes.srcelement, + sSrcElementTagName = oSrcElement.tagName.toUpperCase(); + + + if(sSrcElementTagName == this.TAG_NAME) { + + p_oConfig.element = oSrcElement; + + var oFirstChild = getFirstElement(p_oConfig.element); + + Dom.addClass(oFirstChild, "first-child"); + + if(oFirstChild) { + + var oButton = getFirstElement(oFirstChild); + + + if(oButton) { + + var sButtonTagName = oButton.tagName.toUpperCase(); + + + if(sButtonTagName == "A" || sButtonTagName == "BUTTON") { + + setAttributesFromSrcElement.call( + this, + oButton, + oAttributes + ); + + } + + } + + } + + } + else if(sSrcElementTagName == "INPUT") { + + setAttributesFromSrcElement.call(this, oSrcElement, oAttributes); + + } + +} + + +YAHOO.extend(YAHOO.widget.Button, YAHOO.util.Element, { + + +// Protected properties + + +/** +* @property _button +* @description Object reference to the button's internal +* <a> or <button> element. +* @default null +* @protected +* @type HTMLAnchorElement|HTMLButtonElement +*/ +_button: null, + + +/** +* @property _menu +* @description Object reference to the button's menu. +* @default null +* @protected +* @type YAHOO.widget.Menu +*/ +_menu: null, + + +/** +* @property _onclickAttributeValue +* @description Object reference to the button's current value for the "onclick" +* configuration attribute. +* @default null +* @protected +* @type Object +*/ +_onclickAttributeValue: null, + + +/** +* @property _oninitAttributeValue +* @description Object reference to the button's current value for the "oninit" +* configuration attribute. +* @default null +* @protected +* @type Object +*/ +_oninitAttributeValue: null, + + +/** +* @property _activationKeyPressed +* @description Boolean indicating if the key(s) that toggle the button's +* "active" state have been pressed. +* @default false +* @protected +* @type Boolean +*/ +_activationKeyPressed: false, + + +/** +* @property _activationButtonPressed +* @description Boolean indicating if the mouse button that toggles the button's +* "active" state has been pressed. +* @default false +* @protected +* @type Boolean +*/ +_activationButtonPressed: false, + + +/** +* @property _hasKeyEventHandlers +* @description Boolean indicating if the button's "blur", "keydown" and +* "keyup" event handlers are assigned +* @default false +* @protected +* @type Boolean +*/ +_hasKeyEventHandlers: false, + + +/** +* @property _hasMouseEventHandlers +* @description Boolean indicating if the button's "mouseout" and "mousedown" +* and "mouseup" event handlers are assigned +* @default false +* @protected +* @type Boolean +*/ +_hasMouseEventHandlers: false, + + + +// Constants + + +/** +* @property TAG_NAME +* @description The name of the tag to be used for the button's root element. +* @default "SPAN" +* @final +* @type String +*/ +TAG_NAME: "SPAN", + + +/** +* @property CHECK_ACTIVATION_KEYS +* @description Array of numbers representing keys that (when pressed) toggle +* the button's "checked" attribute. +* @default [32] +* @final +* @type Array +*/ +CHECK_ACTIVATION_KEYS: [32], + + +/** +* @property ACTIVATION_KEYS +* @description Array of numbers representing keys that (when presed) toggle +* the button's "active" state. +* @default [13, 32] +* @final +* @type Array +*/ +ACTIVATION_KEYS: [13, 32], + + +/** +* @property OPTION_AREA_WIDTH +* @description Width (in pixels) of the area of a split button that when +* pressed will display a menu. +* @default 20 +* @final +* @type Number +*/ +OPTION_AREA_WIDTH: 20, + + +/** +* @property CSS_CLASS_NAME +* @description String representing the CSS class(es) to be applied to the +* button's root element. +* @default "yuibutton" +* @final +* @type String +*/ +CSS_CLASS_NAME: "yuibutton", + + +/** +* @property RADIO_DEFAULT_TITLE +* @description String representing the default title applied to buttons of +* type "radio." +* @default "Unchecked. Click to check." +* @final +* @type String +*/ +RADIO_DEFAULT_TITLE: "Unchecked. Click to check.", + + +/** +* @property RADIO_CHECKED_TITLE +* @description String representing the title applied to buttons of type "radio" +* when checked. +* @default "Checked. Click to uncheck." +* @final +* @type String +*/ +RADIO_CHECKED_TITLE: "Checked. Click to uncheck.", + + +/** +* @property CHECKBOX_DEFAULT_TITLE +* @description String representing the default title applied to buttons of +* type "checkbox." +* @default "Unchecked. Click to check." +* @final +* @type String +*/ +CHECKBOX_DEFAULT_TITLE: "Unchecked. Click to check.", + + +/** +* @property CHECKBOX_CHECKED_TITLE +* @description String representing the title applied to buttons of type +* "checkbox" when checked. +* @default "Checked. Click to uncheck." +* @final +* @type String +*/ +CHECKBOX_CHECKED_TITLE: "Checked. Click to uncheck.", + + +/** +* @property MENUBUTTON_DEFAULT_TITLE +* @description String representing the default title applied to buttons of +* type "menubutton." +* @default "Menu collapsed. Click to expand." +* @final +* @type String +*/ +MENUBUTTON_DEFAULT_TITLE: "Menu collapsed. Click to expand.", + + +/** +* @property MENUBUTTON_MENU_VISIBLE_TITLE +* @description String representing the title applied to buttons of type +* "menubutton" when the button's menu is visible. +* @default "Menu expanded. Click or press Esc to collapse." +* @final +* @type String +*/ +MENUBUTTON_MENU_VISIBLE_TITLE: + "Menu expanded. Click or press Esc to collapse.", + + +/** +* @property SPLITBUTTON_DEFAULT_TITLE +* @description String representing the default title applied to buttons of +* type "splitebutton." +* @default "Menu collapsed. Click inside option region or press +* Ctrl + Shift + M to show the menu." +* @final +* @type String +*/ +SPLITBUTTON_DEFAULT_TITLE: + "Menu collapsed. Click inside option region or press Ctrl + Shift + M to show the menu.", + + +/** +* @property SPLITBUTTON_OPTION_VISIBLE_TITLE +* @description String representing the title applied to buttons of type +* "splitbutton" when the button's menu is visible. +* @default "Menu expanded. Press Esc or Ctrl + Shift + M to hide the menu." +* @final +* @type String +*/ +SPLITBUTTON_OPTION_VISIBLE_TITLE: + "Menu expanded. Press Esc or Ctrl + Shift + M to hide the menu.", + + +/** +* @property SUBMIT_TITLE +* @description String representing the title applied to buttons of +* type "submit." +* @default "Click to submit form." +* @final +* @type String +*/ +SUBMIT_TITLE: "Click to submit form.", + + + +// Protected attribute setter methods + + +/** +* @method _setType +* @description Sets the value of the button's "type" attribute. +* @protected +* @param {String} p_sType String indicating the value for the button's +* "type" attribute. +*/ +_setType: function(p_sType) { + + if(p_sType == "splitbutton") { + + this.on("option", this._onOption); + + } + +}, + + +/** +* @method _setLabel +* @description Sets the value of the button's "label" attribute. +* @protected +* @param {String} p_sLabel String indicating the value for the button's +* "label" attribute. +*/ +_setLabel: function(p_sLabel) { + + this._button.innerHTML = p_sLabel; + +}, + + +/** +* @method _setTabIndex +* @description Sets the value of the button's "tabindex" attribute. +* @protected +* @param {Number} p_nTabIndex Number indicating the value for the button's +* "tabindex" attribute. +*/ +_setTabIndex: function(p_nTabIndex) { + + this._button.tabIndex = p_nTabIndex; + +}, + + +/** +* @method _setTitle +* @description Sets the value of the button's "title" attribute. +* @protected +* @param {String} p_nTabIndex Number indicating the value for the button's +* "title" attribute. +*/ +_setTitle: function(p_sTitle) { + + if(this.get("type") != "link") { + + var sTitle = p_sTitle; + + if(!sTitle) { + + + var sType = this.get("type"); + + switch(sType) { + + case "radio": + + sTitle = this.RADIO_DEFAULT_TITLE; + + break; + + case "checkbox": + + sTitle = this.CHECKBOX_DEFAULT_TITLE; + + break; + + case "menubutton": + + sTitle = this.MENUBUTTON_DEFAULT_TITLE; + + break; + + case "splitbutton": + + sTitle = this.SPLITBUTTON_DEFAULT_TITLE; + + break; + + case "submit": + + sTitle = this.SUBMIT_TITLE; + + break; + + } + + } + + this._button.title = sTitle; + + } + +}, + + +/** +* @method _setDisabled +* @description Sets the value of the button's "disabled" attribute. +* @protected +* @param {Boolean} p_bDisabled Boolean indicating the value for the button's +* "disabled" attribute. +*/ +_setDisabled: function(p_bDisabled) { + + if(this.get("type") != "link") { + + if(p_bDisabled) { + + if(this.hasFocus()) { + + this.blur(); + + } + + this._button.setAttribute("disabled", "disabled"); + + this.addClass("disabled"); + + } + else { + + this._button.removeAttribute("disabled"); + + this.removeClass("disabled"); + + } + + } + +}, + + +/** +* @method _setAccessKey +* @description Sets the value of the button's "accesskey" attribute. +* @protected +* @param {String} p_sAccessKey String indicating the value for the button's +* "accesskey" attribute. +*/ +_setAccessKey: function(p_sAccessKey) { + + this._button.accessKey = p_sAccessKey; + +}, + + +/** +* @method _setHref +* @description Sets the value of the button's "href" attribute. +* @protected +* @param {String} p_sHref String indicating the value for the button's +* "href" attribute. +*/ +_setHref: function(p_sHref) { + + if(this.get("type") == "link") { + + this._button.href = p_sHref; + + } + +}, + + +/** +* @method _setTarget +* @description Sets the value of the button's "target" attribute. +* @protected +* @param {String} p_sTarget String indicating the value for the button's +* "target" attribute. +*/ +_setTarget: function(p_sTarget) { + + if(this.get("type") == "link") { + + this._button.setAttribute("target", p_sTarget); + + } + +}, + + +/** +* @method _setChecked +* @description Sets the value of the button's "target" attribute. +* @protected +* @param {Boolean} p_bChecked Boolean indicating the value for the button's +* "checked" attribute. +*/ +_setChecked: function(p_bChecked) { + + var sType = this.get("type"), + sTitle; + + if(sType == "checkbox" || sType == "radio") { + + if(p_bChecked) { + + this.addClass("checked"); + + sTitle = (sType == "radio") ? + this.RADIO_CHECKED_TITLE : + this.CHECKBOX_CHECKED_TITLE; + + } + else { + + this.removeClass("checked"); + + sTitle = (sType == "radio") ? + this.RADIO_DEFAULT_TITLE : + this.CHECKBOX_DEFAULT_TITLE; + + } + + this.set("title", sTitle); + + } + +}, + + +/** +* @method _setMenu +* @description Sets the value of the button's "menu" attribute. +* @protected +* @param {Object} p_oMenu Object indicating the value for the button's +* "menu" attribute. +*/ +_setMenu: function(p_oMenu) { + + var Menu = YAHOO.widget.Menu, + oMenu, + me = this; + + if(!Menu) { + + this.logger.log("YAHOO.widget.Menu dependency not met.", "error"); + + return false; + + } + + + function initMenu() { + + if(oMenu) { + + oMenu.showEvent.subscribe(this._onMenuShow, this, true); + oMenu.hideEvent.subscribe(this._onMenuHide, this, true); + oMenu.keyDownEvent.subscribe(this._onMenuKeyDown, this, true); + oMenu.renderEvent.subscribe(this._onMenuRender, this, true); + oMenu.clickEvent.subscribe(this._onMenuClick, this, true); + oMenu.itemAddedEvent.subscribe(this._onMenuItemAdded, this, true); + + var oSrcElement = oMenu.srcElement; + + if(oSrcElement && oSrcElement.tagName.toUpperCase() == "SELECT") { + + oSrcElement.style.display = "none"; + oSrcElement.parentNode.removeChild(oSrcElement); + + } + + this._menu = oMenu; + + } + else { + + this._menu.destroy(); + this._menu = null; + + } + + } + + + if(p_oMenu instanceof Menu) { + + oMenu = p_oMenu; + + var aItems = oMenu.getItems(), + nItems = aItems.length, + oItem; + + if(nItems > 0) { + + var i = nItems - 1; + + do { + + oItem = aItems[i]; + + if(oItem) { + + oItem.cfg.subscribeToConfigEvent( + "selected", + this._onMenuItemSelected, + oItem, + this + ); + + } + + } + while(i--); + + } + + initMenu.call(this); + + } + else if(Lang.isArray(p_oMenu)) { + + this.on("appendTo", function() { + + oMenu = new Menu( + Dom.generateId(), + { lazyload: true, itemdata: p_oMenu } + ); + + initMenu.call(me); + + }); + + } + else if(Lang.isString(p_oMenu)) { + + Event.onContentReady(p_oMenu, function() { + + oMenu = new Menu(this, { lazyload: true }); + + initMenu.call(me); + + }); + + } + else if(p_oMenu && p_oMenu.nodeName) { + + oMenu = new Menu(p_oMenu, { lazyload: true }); + + initMenu.call(this); + + } + +}, + + +/** +* @method _setOnClick +* @description Sets the value of the button's "onclick" attribute. +* @protected +* @param {Object} p_oObject Object indicating the value for the button's +* "onclick" attribute. +*/ +_setOnClick: function(p_oObject) { + + /* + Remove any existing listeners if a "click" event handler has already + been specified. + */ + + if( + this._onclickAttributeValue && + (this._onclickAttributeValue != p_oObject) + ) { + + this.removeListener("click", this._onclickAttributeValue.fn); + + this._onclickAttributeValue = null; + + } + + + if( + !this._onclickAttributeValue && + Lang.isObject(p_oObject) && + Lang.isFunction(p_oObject.fn) + ) { + + this.on("click", p_oObject.fn, p_oObject.obj, p_oObject.scope); + + this._onclickAttributeValue = p_oObject; + + } + +}, + +/** +* @method _setOnInit +* @description Sets the value of the button's "init" attribute. +* @protected +* @param {Object} p_oObject Object indicating the value for the button's +* "oninit" attribute. +*/ +_setOnInit: function(p_oObject) { + + /* + Remove any existing listeners if a "init" event handler has already + been specified. + */ + + if( + this._oninitAttributeValue && + (this._oninitAttributeValue != p_oObject) + ) { + + this.removeListener("init", this._oninitAttributeValue.fn); + + this._oninitAttributeValue = null; + + } + + + if( + !this._oninitAttributeValue && + Lang.isObject(p_oObject) && + Lang.isFunction(p_oObject.fn) + ) { + + this.on("init", p_oObject.fn, p_oObject.obj, p_oObject.scope); + + this._oninitAttributeValue = p_oObject; + + } + +}, + + + +// Protected methods + + +/** +* @method _createButtonElement +* @description Creates the button's element. +* @protected +* @param {String} p_sType String indicating the type of element to create. +* @return {HTMLElement} +*/ +_createButtonElement: function(p_sType) { + + var sTagName = this.TAG_NAME, + oElement = document.createElement(sTagName); + + oElement.innerHTML = + + "<" + sTagName + " class=\"first-child\">" + + (p_sType == "link" ? "" : "") + + ""; + + return oElement; + +}, + + +/** +* @method _isActivationKey +* @description Determines if the specified keycode is one that toggles the +* button's "active" state. +* @protected +* @param {Number} p_nKeyCode Number representing the keycode to be evaluated. +* @return {Boolean} +*/ +_isActivationKey: function(p_nKeyCode) { + + var sType = this.get("type"), + aKeyCodes = (sType == "checkbox" || sType == "radio") ? + this.CHECK_ACTIVATION_KEYS : this.ACTIVATION_KEYS, + + nKeyCodes = aKeyCodes.length; + + if(nKeyCodes > 0) { + + var i = nKeyCodes - 1; + + do { + + if(p_nKeyCode == aKeyCodes[i]) { + + return true; + + } + + } + while(i--); + + } + +}, + + +/** +* @method _isSplitButtonOptionKey +* @description Determines if the specified keycode is one that toggles the +* display of the split button's menu. +* @param {Event} p_oEvent Object representing the DOM event object passed +* back by the event utility (YAHOO.util.Event). +* @return {Boolean} +*/ +_isSplitButtonOptionKey: function(p_oEvent) { + + return ( + p_oEvent.ctrlKey && + p_oEvent.shiftKey && + Event.getCharCode(p_oEvent) == 77 + ); + +}, + + +_originalMaxHeight: -1, + + +/** +* @method _showMenu +* @description Shows the button's menu. +* @protected +*/ +_showMenu: function() { + + var oMenu = this._menu; + + if(oMenu) { + + YAHOO.widget.MenuManager.hideVisible(); + + oMenu.cfg.applyConfig({ + context:[this.get("id"), "tl", "bl"], + clicktohide: false, + constraintoviewport: false, + visible: true + }); + + oMenu.cfg.fireQueue(); + + var nViewportHeight = Dom.getViewportHeight(), + nMenuHeight = oMenu.element.offsetHeight; + + + if((oMenu.cfg.getProperty("y") + nMenuHeight) > nViewportHeight) { + + this.logger.log("Current menu position will place a portion, or " + + "the entire menu outside the boundary of the viewport. " + + "Repositioning the menu to stay inside the viewport."); + + oMenu.align("bl", "tl"); + + var nY = oMenu.cfg.getProperty("y"), + + nScrollTop = ( + document.documentElement.scrollTop || + document.body.scrollTop + ); + + + if(nScrollTop >= nY) { + + if(this._originalMaxHeight == -1) { + + this._originalMaxHeight = + oMenu.cfg.getProperty("maxheight"); + + } + + oMenu.cfg.setProperty( + "maxheight", + (nMenuHeight - ((nScrollTop - nY) + 20)) + ); + + oMenu.align("bl", "tl"); + + } + + } + + oMenu.cfg.setProperty("constraintoviewport", true); + + } + +}, + + +/** +* @method _hideMenu +* @description Hides the button's menu. +* @protected +*/ +_hideMenu: function() { + + var oMenu = this._menu; + + if(oMenu && oMenu.cfg.getProperty("visible")) { + + oMenu.hide(); + + } + +}, + + +/** +* @method _submitForm +* @description Submits the form to which the button belongs. +* @protected +*/ +_submitForm: function() { + + var oForm = this.getForm(); + + if(oForm) { + + YAHOO.widget.Button.addHiddenFieldsToForm(oForm); + + this.createHiddenField(); + + oForm.submit(); + + } + +}, + + + +// Protected event handlers + + +/** +* @method _onMouseOver +* @description "mouseover" event handler for the button. +* @protected +* @param {Event} p_oEvent Object representing the DOM event object passed +* back by the event utility (YAHOO.util.Event). +*/ +_onMouseOver: function(p_oEvent) { + + if(!this.get("disabled")) { + + if(!this._hasMouseEventHandlers) { + + this.on("mouseout", this._onMouseOut); + this.on("mousedown", this._onMouseDown); + this.on("mouseup", this._onMouseUp); + + this._hasMouseEventHandlers = true; + + } + + this.addClass("hover"); + + if(this._activationButtonPressed) { + + this.addClass("active"); + + } + + + if(this._bOptionPressed) { + + this.addClass("activeoption"); + + } + + } + +}, + + +/** +* @method _onMouseOut +* @description "mouseout" event handler for the button. +* @protected +* @param {Event} p_oEvent Object representing the DOM event object passed +* back by the event utility (YAHOO.util.Event). +*/ +_onMouseOut: function(p_oEvent) { + + if(!this.get("disabled")) { + + this.removeClass("hover"); + + if(this.get("type") != "menubutton") { + + this.removeClass("active"); + + } + + if(this._activationButtonPressed || this._bOptionPressed) { + + Event.on(document, "mouseup", this._onDocumentMouseUp, this, true); + + } + + } + +}, + + +/** +* @method _onDocumentMouseUp +* @description "mouseup" event handler for the button. +* @protected +* @param {Event} p_oEvent Object representing the DOM event object passed +* back by the event utility (YAHOO.util.Event). +* @param {YAHOO.widget.Button} p_oButton Object representing the button. +*/ +_onDocumentMouseUp: function(p_oEvent, p_oButton) { + + this._activationButtonPressed = false; + this._bOptionPressed = false; + + var sType = this.get("type"); + + if(sType == "menubutton" || sType == "splitbutton") { + + this.removeClass((sType == "menubutton" ? "active" : "activeoption")); + + this._hideMenu(); + + } + + Event.removeListener(document, "mouseup", this._onDocumentMouseUp); + +}, + + +/** +* @method _onMouseDown +* @description "mousedown" event handler for the button. +* @protected +* @param {Event} p_oEvent Object representing the DOM event object passed +* back by the event utility (YAHOO.util.Event). +*/ +_onMouseDown: function(p_oEvent) { + + if(!this.get("disabled")) { + + if((p_oEvent.which || p_oEvent.button) == 1) { + + if(!this.hasFocus()) { + + this.focus(); + + } + + + var sType = this.get("type"); + + + if(sType == "splitbutton") { + + var oElement = this.get("element"), + nX = Event.getPageX(p_oEvent) - Dom.getX(oElement); + + if((oElement.offsetWidth - this.OPTION_AREA_WIDTH) < nX) { + + this.fireEvent("option", p_oEvent); + + } + else { + + this.addClass("active"); + + this._activationButtonPressed = true; + + } + + } + else if(sType == "menubutton") { + + if(this.hasClass("active")) { + + this._hideMenu(); + + this._activationButtonPressed = false; + + } + else { + + this._showMenu(); + + this._activationButtonPressed = true; + + } + + } + else { + + this.addClass("active"); + + this._activationButtonPressed = true; + + } + + + + if(sType == "splitbutton" || sType == "menubutton") { + + var me = this; + + + function onMouseUp() { + + me._hideMenu(); + me.removeListener("mouseup", onMouseUp); + + } + + + this._hideMenuTimerId = window.setTimeout(function() { + + me.on("mouseup", onMouseUp); + + }, 250); + + } + + } + + } + +}, + + +/** +* @method _onMouseUp +* @description "mouseup" event handler for the button. +* @protected +* @param {Event} p_oEvent Object representing the DOM event object passed +* back by the event utility (YAHOO.util.Event). +*/ +_onMouseUp: function(p_oEvent) { + + if(!this.get("disabled")) { + + + if(this._hideMenuTimerId) { + + window.clearTimeout(this._hideMenuTimerId); + + } + + var sType = this.get("type"); + + if(sType == "checkbox" || sType == "radio") { + + this.set("checked", !(this.get("checked"))); + + } + + + this._activationButtonPressed = false; + + + if(this.get("type") != "menubutton") { + + this.removeClass("active"); + + } + + } + +}, + + +/** +* @method _onFocus +* @description "focus" event handler for the button. +* @protected +* @param {Event} p_oEvent Object representing the DOM event object passed +* back by the event utility (YAHOO.util.Event). +* @param {YAHOO.widget.Button} p_oButton Object representing the button that +* fired the event. +*/ +_onFocus: function(p_oEvent, p_oButton) { + + if(!this.get("disabled")) { + + this.addClass("focus"); + + if(this._activationKeyPressed) { + + this.addClass("active"); + + } + + m_oFocusedButton = this; + + + if(!this._hasKeyEventHandlers) { + + var oElement = this._button; + + Event.on(oElement, "blur", this._onBlur, this, true); + Event.on(oElement, "keydown", this._onKeyDown, this, true); + Event.on(oElement, "keyup", this._onKeyUp, this, true); + + this._hasKeyEventHandlers = true; + + } + + + this.fireEvent("focus", p_oEvent); + + } + +}, + + +/** +* @method _onBlur +* @description "blur" event handler for the button. +* @protected +* @param {Event} p_oEvent Object representing the DOM event object passed +* back by the event utility (YAHOO.util.Event). +* @param {YAHOO.widget.Button} p_oButton Object representing the button. +*/ +_onBlur: function(p_oEvent, p_oButton) { + + if(!this.get("disabled")) { + + this.removeClass("focus"); + + if(this.get("type") != "menubutton") { + + this.removeClass("active"); + + } + + if(this._activationKeyPressed) { + + Event.on(document, "keyup", this._onDocumentKeyUp, this, true); + + } + + + m_oFocusedButton = null; + + this.fireEvent("blur", p_oEvent); + + } + +}, + + +/** +* @method _onDocumentKeyUp +* @description "keyup" event handler for the document. +* @protected +* @param {Event} p_oEvent Object representing the DOM event object passed +* back by the event utility (YAHOO.util.Event). +* @param {YAHOO.widget.Button} p_oButton Object representing the button. +*/ +_onDocumentKeyUp: function(p_oEvent, p_oButton) { + + if(this._isActivationKey(Event.getCharCode(p_oEvent))) { + + this._activationKeyPressed = false; + + Event.removeListener(document, "keyup", this._onDocumentKeyUp); + + } + +}, + + +/** +* @method _onKeyDown +* @description "keydown" event handler for the button. +* @protected +* @param {Event} p_oEvent Object representing the DOM event object passed +* back by the event utility (YAHOO.util.Event). +* @param {YAHOO.widget.Button} p_oButton Object representing the button. +*/ +_onKeyDown: function(p_oEvent, p_oButton) { + + if(!this.get("disabled")) { + + if( + this.get("type") == "splitbutton" && + this._isSplitButtonOptionKey(p_oEvent) + ) { + + this.fireEvent("option", p_oEvent); + + } + else if(this._isActivationKey(Event.getCharCode(p_oEvent))) { + + if(this.get("type") == "menubutton") { + + this._showMenu(); + + } + else { + + this._activationKeyPressed = true; + + this.addClass("active"); + + } + + } + + + var oMenu = this._menu; + + if( + oMenu && oMenu.cfg.getProperty("visible") && + Event.getCharCode(p_oEvent) == 27 + ) { + + oMenu.hide(); + this.focus(); + + } + + } + +}, + + +/** +* @method _onKeyUp +* @description "keyup" event handler for the button. +* @protected +* @param {Event} p_oEvent Object representing the DOM event object passed +* back by the event utility (YAHOO.util.Event). +* @param {YAHOO.widget.Button} p_oButton Object representing the button. +*/ +_onKeyUp: function(p_oEvent, p_oButton) { + + if(!this.get("disabled")) { + + if(this._isActivationKey(Event.getCharCode(p_oEvent))) { + + var sType = this.get("type"); + + if(sType == "checkbox" || sType == "radio") { + + this.set("checked", !(this.get("checked"))); + + } + + this._activationKeyPressed = false; + + if(this.get("type") != "menubutton") { + + this.removeClass("active"); + + } + + } + + } + +}, + + +/** +* @method _onClick +* @description "click" event handler for the button. +* @protected +* @param {Event} p_oEvent Object representing the DOM event object passed +* back by the event utility (YAHOO.util.Event). +*/ +_onClick: function(p_oEvent) { + + var sType = this.get("type"), + sTitle; + + switch(sType) { + + case "radio": + case "checkbox": + + if(this.get("checked")) { + + sTitle = (sType == "radio") ? + this.RADIO_CHECKED_TITLE : + this.CHECKBOX_CHECKED_TITLE; + + } + else { + + sTitle = (sType == "radio") ? + this.RADIO_DEFAULT_TITLE : + this.CHECKBOX_DEFAULT_TITLE; + + } + + this.set("title", sTitle); + + break; + + case "submit": + + this._submitForm(); + + break; + + case "reset": + + var oForm = this.getForm(); + + if(oForm) { + + oForm.reset(); + + } + + break; + + case "menubutton": + + sTitle = this._menu.cfg.getProperty("visible") ? + this.MENUBUTTON_MENU_VISIBLE_TITLE : + this.MENUBUTTON_DEFAULT_TITLE; + + this.set("title", sTitle); + + break; + + case "splitbutton": + + var oElement = this.get("element"), + nX = Event.getPageX(p_oEvent) - Dom.getX(oElement); + + if((oElement.offsetWidth - this.OPTION_AREA_WIDTH) < nX) { + + return false; + + } + else { + + this._hideMenu(); + + var oSrcElement = this.get("srcelement"); + + if(oSrcElement && oSrcElement.type == "submit") { + + this._submitForm(); + + } + + } + + sTitle = this._menu.cfg.getProperty("visible") ? + this.SPLITBUTTON_OPTION_VISIBLE_TITLE : + this.SPLITBUTTON_DEFAULT_TITLE; + + this.set("title", sTitle); + + break; + + } + +}, + + +/** +* @method _onAppendTo +* @description "appendTo" event handler for the button. +* @protected +* @param {Event} p_oEvent Object representing the DOM event object passed +* back by the event utility (YAHOO.util.Event). +*/ +_onAppendTo: function(p_oEvent) { + + /* + It is necessary to call "getForm" using "setTimeout" to make sure that + the button's "form" property returns a node reference. Sometimes, if + you try to get the reference immediately after appending the field, it + is null. + */ + + var me = this; + + window.setTimeout(function() { + + var oForm = me.getForm(); + + if(oForm) { + + Event.on(oForm, "reset", me._onFormReset, me, true); + Event.on(oForm, "submit", me._onFormSubmit, me, true); + + } + + }, 0); + +}, + + +/** +* @method _onFormSubmit +* @description "submit" event handler for the button's form. +* @protected +* @param {Event} p_oEvent Object representing the DOM event object passed +* back by the event utility (YAHOO.util.Event). +* @param {YAHOO.widget.Button} p_oButton Object representing the button. +*/ +_onFormSubmit: function(p_oEvent, p_oButton) { + + var sType = this.get("type"), + oMenuItem = this.get("selectedMenuItem"), + oForm = this.getForm(); + + + if(sType == "radio" || sType == "checkbox") { + + YAHOO.log("Creating hidden field for button: " + this); + + this.createHiddenField(); + + } + else if(oMenuItem) { + + var oSrcElement = this._menu.srcElement; + + if(oSrcElement && oSrcElement.tagName.toUpperCase() == "SELECT") { + + oForm.appendChild(oSrcElement); + oSrcElement.selectedIndex = oMenuItem.index; + + } + else { + + var oValue = (oMenuItem.value === null || oMenuItem.value === "") ? + oMenuItem.cfg.getProperty("text") : + oMenuItem.value; + + + if(oValue) { + + var oField = createInputElement( + "hidden", + (this.get("name") + "_options"), + oValue + ); + + oForm.appendChild(oField); + + } + + } + + } + +}, + + +/** +* @method _onFormReset +* @description "reset" event handler for the button's form. +* @protected +* @param {Event} p_oEvent Object representing the DOM event object passed +* back by the event utility (YAHOO.util.Event). +* @param {YAHOO.widget.Button} p_oButton Object representing the button. +*/ +_onFormReset: function(p_oEvent, p_oButton) { + + var sType = this.get("type"); + + if(sType == "checkbox" || sType == "radio") { + + this.resetValue("checked"); + + } + + if(this._menu) { + + this.resetValue("selectedMenuItem"); + + } + +}, + + +/** +* @method _onDocumentMouseDown +* @description "mousedown" event handler for the document. +* @protected +* @param {Event} p_oEvent Object representing the DOM event object passed +* back by the event utility (YAHOO.util.Event). +* @param {YAHOO.widget.Button} p_oButton Object representing the button. +*/ +_onDocumentMouseDown: function(p_oEvent, p_oButton) { + + var oTarget = Event.getTarget(p_oEvent), + oButtonElement = this.get("element"), + oMenuElement = this._menu.element; + + if( + oTarget != oButtonElement && + !Dom.isAncestor(oButtonElement, oTarget) && + oTarget != oMenuElement && + !Dom.isAncestor(oMenuElement, oTarget) + ) { + + this._hideMenu(); + + Event.removeListener( + document, + "mousedown", + this._onDocumentMouseDown + ); + + } + +}, + + +/** +* @method _onOption +* @description "option" event handler for the button. +* @protected +* @param {Event} p_oEvent Object representing the DOM event object passed +* back by the event utility (YAHOO.util.Event). +*/ +_onOption: function(p_oEvent) { + + if(this.hasClass("activeoption")) { + + this._hideMenu(); + + this._bOptionPressed = false; + + } + else { + + this._showMenu(); + + this._bOptionPressed = true; + + } + +}, + + +/** +* @method _onMenuShow +* @description "show" event handler for the button's menu. +* @private +* @param {String} p_sType String representing the name of the event that +* was fired. +* @param {Array} p_aArgs Array of arguments sent when the event was fired. +* @param {YAHOO.widget.Button} p_oButton Object representing the button. +*/ +_onMenuShow: function(p_sType, p_aArgs, p_oButton) { + + Event.on(document, "mousedown", this._onDocumentMouseDown, this, true); + + var sTitle, + sClass; + + if(this.get("type") == "splitbutton") { + + sTitle = this.SPLITBUTTON_OPTION_VISIBLE_TITLE; + sClass = "activeoption"; + + } + else { + + sTitle = this.MENUBUTTON_MENU_VISIBLE_TITLE; + sClass = "active"; + + } + + this.addClass(sClass); + this.set("title", sTitle); + +}, + + +/** +* @method _onMenuHide +* @description "hide" event handler for the button's menu. +* @private +* @param {String} p_sType String representing the name of the event that +* was fired. +* @param {Array} p_aArgs Array of arguments sent when the event was fired. +* @param {YAHOO.widget.Button} p_oButton Object representing the button. +*/ +_onMenuHide: function(p_sType, p_aArgs, p_oButton) { + + if(this._originalMaxHeight != -1) { + + this._menu.cfg.setProperty("maxheight", this._originalMaxHeight); + + } + + + var sTitle, + sClass; + + if(this.get("type") == "splitbutton") { + + sTitle = this.SPLITBUTTON_DEFAULT_TITLE; + sClass = "activeoption"; + + } + else { + + sTitle = this.MENUBUTTON_DEFAULT_TITLE; + sClass = "active"; + } + + + this.removeClass(sClass); + this.set("title", sTitle); + +}, + + +/** +* @method _onMenuKeyDown +* @description "keydown" event handler for the button's menu. +* @private +* @param {String} p_sType String representing the name of the event that +* was fired. +* @param {Array} p_aArgs Array of arguments sent when the event was fired. +* @param {YAHOO.widget.Button} p_oButton Object representing the button. +*/ +_onMenuKeyDown: function(p_sType, p_aArgs, p_oButton) { + + var oEvent = p_aArgs[0]; + + if(Event.getCharCode(oEvent) == 27) { + + this.focus(); + + if(this.get("type") == "splitbutton") { + + this._bOptionPressed = false; + + } + + } + +}, + + +/** +* @method _onMenuRender +* @description "render" event handler for the button's menu. +* @private +* @param {String} p_sType String representing the name of the event that +* was fired. +* @param {Array} p_aArgs Array of arguments sent when the event was fired. +* @param {YAHOO.widget.Button} p_oButton Object representing the button. +*/ +_onMenuRender: function(p_sType, p_aArgs, p_oButton) { + + this.get("element").parentNode.appendChild(this._menu.element); + +}, + + +/** +* @method _onMenuItemSelected +* @description "selectedchange" event handler for each item in the +* button's menu. +* @private +* @param {String} p_sType String representing the name of the event that +* was fired. +* @param {Array} p_aArgs Array of arguments sent when the event was fired. +* @param {YAHOO.widget.MenuItem} +* p_oItem Object representing the menu item that subscribed to the event. +*/ +_onMenuItemSelected: function(p_sType, p_aArgs, p_oItem) { + + this.set("selectedMenuItem", p_oItem); + +}, + + +/** +* @method _onMenuItemAdded +* @description "itemadded" event handler for the button's menu. +* @private +* @param {String} p_sType String representing the name of the event that +* was fired. +* @param {Array} p_aArgs Array of arguments sent when the event was fired. +* @param {YAHOO.widget.MenuItem} +* p_oItem Object representing the menu item that subscribed to the event. +*/ +_onMenuItemAdded: function(p_sType, p_aArgs, p_oItem) { + + var oItem = p_aArgs[0]; + + oItem.cfg.subscribeToConfigEvent( + "selected", + this._onMenuItemSelected, + oItem, + this + ); + +}, + + +/** +* @method _onMenuClick +* @description "click" event handler for the button's menu. +* @private +* @param {String} p_sType String representing the name of the event that +* was fired. +* @param {Array} p_aArgs Array of arguments sent when the event was fired. +* @param {YAHOO.widget.Button} p_oButton Object representing the menu's button. +*/ +_onMenuClick: function(p_sType, p_aArgs, p_oButton) { + + var oItem = p_aArgs[0]; + + if(oItem) { + + var oSrcElement = this.get("srcelement"); + + if(oSrcElement && oSrcElement.type == "submit") { + + this._submitForm(); + + } + + this._hideMenu(); + + } + +}, + + + +// Public methods + + +/** +* @method createHiddenField +* @description Creates the button's hidden form field and appends it to its +* parent form. +* @return {HTMLInputElement} +*/ +createHiddenField: function () { + + if(!this.get("disabled")) { + + var sType = this.get("type"), + + bCheckable = (sType == "checkbox" || sType == "radio"), + + oField = createInputElement( + (bCheckable ? this.get("type") : "hidden"), + this.get("name"), + this.get("value"), + this.get("checked") + ), + + oForm = this.getForm(); + + + if(oField && bCheckable) { + + oField.style.display = "none"; + + } + + + if(oForm) { + + oForm.appendChild(oField); + + } + + + return oField; + + } + +}, + + +/** +* @method init +* @description The Button class's initialization method. +* @param {String} p_oElement String specifying the id attribute of the +* <input>, <a> or +* <span> element to be used to create the button. +* @param {HTMLInputElement|HTMLElement} p_oElement Object reference for the +* <input>, <a> or +* <span> element to be used to create the button. +* @param {Object} p_oElement Object literal specifying a set of configuration +* attributes used to create the button. +* @param {Object} p_oAttributes Optional. Object literal specifying a set of +* configuration attributes used to create the button. +*/ +init: function(p_oElement, p_oAttributes) { + + var sTagName = p_oAttributes.type == "link" ? "A" : "BUTTON", + oSrcElement = p_oAttributes.srcelement; + + + this._button = p_oElement.getElementsByTagName(sTagName)[0]; + + + YAHOO.widget.Button.superclass.init.call( + this, p_oElement, + p_oAttributes + ); + + + m_oButtons[this.get("id")] = this; + + + this.addClass(this.CSS_CLASS_NAME); + this.addClass(this.get("type")); + + Event.on(this._button, "focus", this._onFocus, this, true); + this.on("mouseover", this._onMouseOver); + this.on("click", this._onClick); + this.on("appendTo", this._onAppendTo); + + var oContainer = this.get("container"), + oElement = this.get("element"); + + + if(oContainer) { + + if(Lang.isString(oContainer)) { + + var me = this; + + Event.onContentReady(oContainer, function() { + + me.appendTo(this); + + }); + + } + else { + + this.appendTo(oContainer); + + } + + } + else if( + !Dom.inDocument(oElement) && + oSrcElement && + oSrcElement.tagName.toUpperCase() == "INPUT" + ) { + + var oParentNode = oSrcElement.parentNode; + + if(oParentNode) { + + this.fireEvent("beforeAppendTo", { + type: "beforeAppendTo", + target: oParentNode + }); + + oParentNode.replaceChild(oElement, oSrcElement); + + this.fireEvent("appendTo", { + type: "appendTo", + target: oParentNode + }); + + } + + } + else if( + Dom.inDocument(oElement) && + oSrcElement.tagName.toUpperCase() == "SPAN" + ) { + + var oForm = this.getForm(); + + if(oForm) { + + Event.on(oForm, "reset", this._onFormReset, this, true); + Event.on(oForm, "submit", this._onFormSubmit, this, true); + + } + + } + + this.fireEvent("init"); + + this.logger.log("Initialization completed."); + +}, + + +/** +* @method initAttributes +* @description Initializes all of the configuration attributes used to create +* the button. +* @param {Object} p_oAttributes Object literal specifying a set of +* configuration attributes used to create the button. +*/ +initAttributes: function(p_oAttributes) { + + var oAttributes = p_oAttributes || {}; + + YAHOO.widget.Button.superclass.initAttributes.call(this, oAttributes); + + + /** + * @config type + * @description String specifying the button's type. Possible values are: + * "button," "link," "submit," "reset," "checkbox," "radio," "menubutton," + * and "splitbutton." + * @default "button" + * @type String + */ + this.setAttributeConfig("type", { + + value: (oAttributes.type || "button"), + validator: Lang.isString, + writeOnce: true, + method: this._setType + + }); + + + /** + * @config label + * @description String specifying the button's text label or innerHTML. + * @default null + * @type String + */ + this.setAttributeConfig("label", { + + value: oAttributes.label, + validator: Lang.isString, + method: this._setLabel + + }); + + + /** + * @config value + * @description Object specifying the value for the button. + * @default null + * @type Object + */ + this.setAttributeConfig("value", { + + value: oAttributes.value + + }); + + + /** + * @config name + * @description String specifying the name for the button. + * @default null + * @type String + */ + this.setAttributeConfig("name", { + + value: oAttributes.name, + validator: Lang.isString + + }); + + + /** + * @config tabindex + * @description Number specifying the tabindex for the button. + * @default null + * @type Number + */ + this.setAttributeConfig("tabindex", { + + value: oAttributes.tabindex, + validator: Lang.isNumber, + method: this._setTabIndex + + }); + + + /** + * @config title + * @description String specifying the title for the button. + * @default null + * @type String + */ + this.configureAttribute("title", { + + value: oAttributes.title, + validator: Lang.isString, + method: this._setTitle + + }); + + + /** + * @config disabled + * @description Boolean indicating if the button should be disabled. + * (Disabled buttons are dimmed and will not respond to user input + * or fire events.) + * @default false + * @type Boolean + */ + this.setAttributeConfig("disabled", { + + value: (oAttributes.disabled || false), + validator: Lang.isBoolean, + method: this._setDisabled + + }); + + + /** + * @config href + * @description String specifying the href for the button. Applies only to + * buttons of type "link." + * @type String + */ + this.setAttributeConfig("href", { + + value: oAttributes.href, + validator: Lang.isString, + method: this._setHref + + }); + + + /** + * @config target + * @description String specifying the target for the button. Applies only + * to buttons of type "link." + * @type String + */ + this.setAttributeConfig("target", { + + value: oAttributes.target, + validator: Lang.isString, + method: this._setTarget + + }); + + + /** + * @config checked + * @description Boolean indicating if the button is checked. Applies only + * to buttons of type "radio" and "checkbox." + * @default false + * @type Boolean + */ + this.setAttributeConfig("checked", { + + value: (oAttributes.checked || false), + validator: Lang.isBoolean, + method: this._setChecked + + }); + + + /** + * @config container + * @description HTML element reference or string specifying the id + * attribute of the HTML element that the button's markup should be + * rendered into. + * @type HTMLElement|String + * @default null + */ + this.setAttributeConfig("container", { + + value: oAttributes.container + + }); + + + /** + * @config srcelement + * @description Object reference to the HTML element (either + * <input> or <span>) used to + * create the button. + * @type HTMLElement|String + * @default null + */ + this.setAttributeConfig("srcelement", { + + value: oAttributes.srcelement, + writeOnce: true + + }); + + + /** + * @config menu + * @description Object specifying the menu for the button. The value can be + * one of the following: + *
    + *
  • Object specifying a + * YAHOO.widget.Menu instance.
  • + *
  • String specifying the id attribute of the <div> + * element used to create the menu.
  • + *
  • String specifying the id attribute of the + * <select> element used to create the menu.
  • + *
  • Object specifying the <div> element used to + * create the menu.
  • + *
  • Object specifying the <select> element used to + * create the menu.
  • + *
  • Array of object literals, each representing a set of + * YAHOO.widget.MenuItem + * configuration attributes.
  • + *
  • Array of strings representing the text labels for each menu item in + * the menu.
  • + *
+ * @type HTMLElement|String|Array + * @default null + */ + this.setAttributeConfig("menu", { + + value: null, + method: this._setMenu + + }); + + + /** + * @config selectedMenuItem + * @description Reference to the item in the button's menu that is + * currently selected. + * @type YAHOO.widget.MenuItem + * @default null + */ + this.setAttributeConfig("selectedMenuItem", { + + value: null + + }); + + + /** + * @config onclick + * @description Object literal representing the code to be executed when + * the button is clicked. Format:
{
+ * fn: Function, // The handler to call when the + * event fires.
obj: Object, // An object to + * pass back to the handler.
scope: Object // + * The object to use for the scope of the handler.
}
+ * @type Object + * @default null + */ + this.setAttributeConfig("onclick", { + + value: oAttributes.onclick, + method: this._setOnClick + + }); + + + /** + * @config oninit + * @description Object literal representing the code to be executed when + * the button is initialized. Format:
{
+ * fn: Function, // The handler to call when the + * event fires.
obj: Object, // An object to + * pass back to the handler.
scope: Object // + * The object to use for the scope of the handler.
}
+ * @type Object + * @default null + */ + this.setAttributeConfig("oninit", { + + value: oAttributes.oninit, + method: this._setOnInit + + }); + +}, + + +/** +* @method focus +* @description Causes the button to receive the focus and fires the button's +* "focus" event. +*/ +focus: function() { + + if(!this.get("disabled")) { + + this._button.focus(); + + } + +}, + + +/** +* @method blur +* @description Causes the button to lose focus and fires the button's +* "blur" event. +*/ +blur: function() { + + if(!this.get("disabled")) { + + this._button.blur(); + + } + +}, + + +/** +* @method hasFocus +* @description Returns a boolean indicating whether or not the button has focus. +* @return {Boolean} +*/ +hasFocus: function() { + + return (m_oFocusedButton == this); + +}, + + +/** +* @method isActive +* @description Returns a boolean indicating whether or not the button is active. +* @return {Boolean} +*/ +isActive: function() { + + return this.hasClass("active"); + +}, + + +/** +* @method getMenu +* @description Returns a reference to the button's menu. +* @return {YAHOO.widget.Menu} +*/ +getMenu: function() { + + return this._menu; + +}, + + +/** +* @method getForm +* @description Returns a reference to the button's menu. +* @return {HTMLFormElement} +*/ +getForm: function() { + + return this._button.form; + +}, + + +/** +* @method destroy +* @description Removes the button's element from its parent element and +* removes all event handlers. +*/ +destroy: function() { + + this.logger.log("Destroying ..."); + + var oElement = this.get("element"), + oParentNode = oElement.parentNode, + oMenu = this._menu; + + if(oMenu) { + + this.logger.log("Destroying menu."); + + oMenu.destroy(); + + } + + this.logger.log("Removing DOM event handlers."); + + Event.purgeElement(oElement); + Event.purgeElement(this._button); + Event.removeListener(document, "mouseup", this._onDocumentMouseUp); + Event.removeListener(document, "keyup", this._onDocumentKeyUp); + Event.removeListener(document, "mousedown", this._onDocumentMouseDown); + + var oForm = this.getForm(); + + if(oForm) { + + Event.removeListener(oForm, "reset", this._onFormReset); + + } + + + oParentNode.removeChild(oElement); + + this.logger.log("Removing from document."); + + delete m_oButtons[this.get("id")]; + + this.logger.log("Destroyed."); + +}, + + +/** +* @method toString +* @description Returns a string representing the button. +* @return {String} +*/ +toString: function() { + + return ("Button " + this.get("id")); + +} + +}); + + +/** +* @method addHiddenFieldsToForm +* @description Searches the specified form and adds hidden fields for instances +* of YAHOO.widget.Button that are of type "radio," "checkbox," "menubutton," +* and "splitbutton." +* @param {HTMLFormElement} p_oForm Object reference +* for the form to search. +*/ +YAHOO.widget.Button.addHiddenFieldsToForm = function(p_oForm) { + + var aButtons = Dom.getElementsByClassName("yuibutton", "*", p_oForm), + nButtons = aButtons.length; + + + if(nButtons > 0) { + + YAHOO.log("Form contains " + nButtons + " YUI buttons."); + + var oButton = null, + sType = null, + oMenuItem = null, + oMenu = null; + + for(var i=0; i