Rebuild the complete interface to use ajax.
3 files deleted
92 files modified
157 files added
| | |
| | | } |
| | | $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"]); |
| | | |
| | | } |
| | | |
| | |
| | | $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; |
| | |
| | | $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; |
| | |
| | | |
| | | function getPagingHTML($vars) { |
| | | global $app; |
| | | $content = '<a href="'.$vars["list_file"].'?page=0'.$vars["page_params"].'"><img src="../themes/grey/images/btn_left.png" border="0"></a> '; |
| | | if($vars["show_page_back"] == 1) $content .= '<a href="'.$vars["list_file"].'?page='.$vars["last_page"].$vars["page_params"].'"><img src="../themes/grey/images/btn_back.png" border="0"></a> '; |
| | | $content = '<a href="'."javascript:loadContent('".$vars["list_file"].'?page=0'.$vars["page_params"]."');".'"><img src="themes/grey/images/btn_left.png" border="0"></a> '; |
| | | if($vars["show_page_back"] == 1) $content .= '<a href="'."javascript:loadContent('".$vars["list_file"].'?page='.$vars["last_page"].$vars["page_params"]."');".'"><img src="themes/grey/images/btn_back.png" border="0"></a> '; |
| | | $content .= ' '.$app->lng('Page').' '.$vars["next_page"].' '.$app->lng('of').' '.$vars["max_pages"].' '; |
| | | if($vars["show_page_next"] == 1) $content .= '<a href="'.$vars["list_file"].'?page='.$vars["next_page"].$vars["page_params"].'"><img src="../themes/grey/images/btn_next.png" border="0"></a> '; |
| | | $content .= '<a href="'.$vars["list_file"].'?page='.$vars["pages"].$vars["page_params"].'"> <img src="../themes/grey/images/btn_right.png" border="0"></a>'; |
| | | if($vars["show_page_next"] == 1) $content .= '<a href="'."javascript:loadContent('".$vars["list_file"].'?page='.$vars["next_page"].$vars["page_params"]."');".'"><img src="themes/grey/images/btn_next.png" border="0"></a> '; |
| | | $content .= '<a href="'."javascript:loadContent('".$vars["list_file"].'?page='.$vars["pages"].$vars["page_params"]."');".'"> <img src="themes/grey/images/btn_right.png" border="0"></a>'; |
| | | |
| | | return $content; |
| | | } |
| | |
| | |
|
| | | global $app;
|
| | |
|
| | | if($module == '') $module = $_SESSION["s"]["module"]["name"]; |
| | | |
| | | $lang = array();
|
| | | $html = '<form name="myform" action="'.$listDef["file"].'" method="POST">
|
| | | <div class="frmTextHead"><tmpl_var name="list_head_txt"></div><br />
|
| | | <table width="100%" border="0" cellspacing="0" cellpadding="4">
|
| | | $html = '<div class="frmTextHead"><tmpl_var name="list_head_txt"></div><br /> |
| | | <input type="button" value="{tmpl_var name="add_new_record_txt"}" class="button" onClick="'."loadContent('".$module."/".$listDef["edit_file"]."');".'" /><div class="buttonEnding"></div><br /><br /> |
| | | <table width="100%" border="0" cellspacing="0" cellpadding="4" class="listTable"> |
| | | <tr>
|
| | | ';
|
| | |
|
| | |
| | | foreach($listDef["item"] as $field) {
|
| | | $key = $field["field"];
|
| | | if($field["formtype"] == 'SELECT') {
|
| | | $html .= " <td class=\"frmText11\"><select name=\"".$listDef["search_prefix"].$key."\" onChange=\"document.myform.submit();\">{tmpl_var name='".$listDef["search_prefix"].$key."'}</select></td>\r\n";
|
| | | $html .= " <td class=\"frmText11\"><select name=\"".$listDef["search_prefix"].$key."\" onChange=\"submitForm('pageForm','".$module."/".$listDef["file"]."');\">{tmpl_var name='".$listDef["search_prefix"].$key."'}</select></td>\r\n"; |
| | | } else {
|
| | | $html .= " <td class=\"frmText11\"><input type=\"text\" name=\"".$listDef["search_prefix"].$key."\" value=\"{tmpl_var name='".$listDef["search_prefix"].$key."'}\" class=\"text\" /></td>\r\n";
|
| | | }
|
| | | }
|
| | |
|
| | | $html .= ' <td class="frmText11" align="right"><input name="Filter" type="submit" id="Filter" value="{tmpl_var name="filter_txt"}"></td>
|
| | | $html .= ' <td class="frmText11" align="right"><input name="Filter" type="button" id="Filter" value="{tmpl_var name="filter_txt"}" class="button" onClick="'."submitForm('pageForm','".$module."/".$listDef["file"]."');".'"><div class="buttonEnding"></div></td> |
| | | </tr>
|
| | | <tmpl_loop name="records">
|
| | | <tr bgcolor="{tmpl_var name="bgcolor"}">
|
| | |
| | |
|
| | | foreach($listDef["item"] as $field) {
|
| | | $key = $field["field"];
|
| | | $html .= " <td class=\"frmText11\"><a href=\"".$listDef["edit_file"]."?id={tmpl_var name='id'}\" class=\"frmText11\">{tmpl_var name=\"".$key."\"}</a></td>\r\n";
|
| | | $html .= " <td class=\"frmText11\"><a href=\"#\" onClick=\"loadContent('".$module."/".$listDef["edit_file"]."?id={tmpl_var name='id'}');\" class=\"frmText11\">{tmpl_var name=\"".$key."\"}</a></td>\r\n"; |
| | | }
|
| | |
|
| | | $html .= " <td class=\"frmText11\" align=\"right\">[<a href=\"javascript: del_record('".$listDef["delete_file"]."?id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}');\" class=\"frmText11\">{tmpl_var name='delete_txt'}</a>]</td>
|
| | | $html .= " <td class=\"frmText11\" align=\"right\">[<a href=\"javascript: del_record('".$module."/".$listDef["delete_file"]."?id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}');\" class=\"frmText11\">{tmpl_var name='delete_txt'}</a>]</td> |
| | | </tr>
|
| | | </tmpl_loop>
|
| | | ";
|
| | |
| | | <tr>
|
| | | <td colspan="'.(count($listDef["item"])+1).'" height="40" align="center" class="tblFooter"><tmpl_var name="paging"></td>
|
| | | </tr>
|
| | | </table>
|
| | | </form>';
|
| | | </table>'; |
| | |
|
| | | if($module == '') {
|
| | | $filename = 'templates/'.$listDef["name"].'_list.htm';
|
| | |
| | | $wb = array();
|
| | | }
|
| | |
|
| | | $wb_out = array_merge($wb,$lang);
|
| | | $wb_out = array_merge($lang,$wb); |
| | |
|
| | | if(is_array($wb_out)) {
|
| | | $fp = fopen ($lng_file, "w");
|
| | |
| | |
|
| | | global $app;
|
| | |
|
| | | $module = $_SESSION["s"]["module"]["name"]; |
| | | |
| | | $html = '<table width="500" border="0" cellspacing="0" cellpadding="2">';
|
| | | $lang = array();
|
| | |
|
| | |
| | | </tr>
|
| | | <tr>
|
| | | <td> </td>
|
| | | <td><input name=\"btn_save\" type=\"submit\" class=\"button\" value=\"{tmpl_var name='btn_save_txt'}\">
|
| | | <input name=\"btn_cancel\" type=\"button\" class=\"button\" value=\"{tmpl_var name='btn_cancel_txt'}\" onClick=\"self.location.href='".$formDef["list_default"]."';\">
|
| | | <td><input name=\"btn_save\" type=\"button\" class=\"button\" value=\"{tmpl_var name='btn_save_txt'}\" onClick=\"submitForm('pageForm','".$module."/".$formDef["action"]."');\"><div class=\"buttonEnding\"></div> |
| | | <input name=\"btn_cancel\" type=\"button\" class=\"button\" value=\"{tmpl_var name='btn_cancel_txt'}\" onClick=\"loadContent('".$module."/".$formDef["list_default"]."');\"><div class=\"buttonEnding\"></div> |
| | | </td>
|
| | | </tr>";
|
| | |
|
| | |
| | | $wb = array();
|
| | | }
|
| | |
|
| | | $wb_out = array_merge($wb,$lang);
|
| | | $wb_out = array_merge($lang,$wb); |
| | |
|
| | | if(is_array($wb_out)) {
|
| | | $fp = fopen ($lng_file, "w");
|
| | |
| | | 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"; |
| | | |
| | |
| | | |
| | | |
| | | 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"); |
| | | |
| | |
| | | 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'; |
| | | |
| | |
| | | 'regex' => '', |
| | | 'errmsg' => '', |
| | | 'default' => '', |
| | | 'value' => '1', |
| | | 'value' => array(0 => 0,1 => 1), |
| | | 'separator' => '', |
| | | 'width' => '30', |
| | | 'maxlength' => '255', |
| | |
| | | 'regex' => '', |
| | | 'errmsg' => '', |
| | | 'default' => '', |
| | | 'value' => '1', |
| | | 'value' => array(0 => 0,1 => 1), |
| | | 'separator' => '', |
| | | 'width' => '30', |
| | | 'maxlength' => '255', |
| | |
| | | 'regex' => '', |
| | | 'errmsg' => '', |
| | | 'default' => '1', |
| | | 'value' => '1', |
| | | 'value' => array(0 => 0,1 => 1), |
| | | 'separator' => '', |
| | | 'width' => '30', |
| | | 'maxlength' => '255', |
| | |
| | | 'regex' => '', |
| | | 'errmsg' => '', |
| | | 'default' => '1', |
| | | 'value' => '1', |
| | | 'value' => array(0 => 0,1 => 1), |
| | | 'separator' => '', |
| | | 'width' => '30', |
| | | 'maxlength' => '255', |
| | |
| | | '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', |
| | |
| | | 'regex' => '', |
| | | 'errmsg' => '', |
| | | 'default' => '', |
| | | 'value' => '1', |
| | | 'value' => array(0 => 0,1 => 1), |
| | | 'separator' => '', |
| | | 'width' => '30', |
| | | 'maxlength' => '255', |
| | |
| | | <?php |
| | | |
| | | /* |
| | | Copyright (c) 2005, Till Brehm, projektfarm Gmbh |
| | | Copyright (c) 2007, Till Brehm, projektfarm Gmbh |
| | | All rights reserved. |
| | | |
| | | Redistribution and use in source and binary forms, with or without modification, |
| | |
| | | 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'); |
| | | |
| | | /****************************************** |
| | | * Begin Form configuration |
| | | ******************************************/ |
| | | |
| | | $list_def_file = "list/groups.list.php"; |
| | | $tform_def_file = "form/groups.tform.php"; |
| | | |
| | | /****************************************** |
| | | * End Form configuration |
| | | ******************************************/ |
| | | |
| | | require_once('../../lib/config.inc.php'); |
| | | require_once('../../lib/app.inc.php'); |
| | | |
| | | // Checke Berechtigungen für Modul |
| | | if(!stristr($_SESSION["s"]["user"]["modules"],$_SESSION["s"]["module"]["name"])) { |
| | |
| | | exit; |
| | | } |
| | | |
| | | include_once($list_def_file); |
| | | $app->uses("tform_actions"); |
| | | $app->tform_actions->onDelete(); |
| | | |
| | | // ID importieren |
| | | $id = intval($_REQUEST["id"]); |
| | | |
| | | if($id > 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"]); |
| | | } |
| | | } |
| | | |
| | | |
| | | header("Location: ".$liste["file"]."?PHPSESSID=".$_SESSION["s"]["id"]); |
| | | exit; |
| | | ?> |
| | |
| | | <?php |
| | | /* |
| | | Copyright (c) 2005, Till Brehm, projektfarm Gmbh |
| | | Copyright (c) 2007, Till Brehm, projektfarm Gmbh |
| | | All rights reserved. |
| | | |
| | | Redistribution and use in source and binary forms, with or without modification, |
| | |
| | | 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'); |
| | | |
| | | |
| | | /****************************************** |
| | | * Begin Form configuration |
| | |
| | | * End Form configuration |
| | | ******************************************/ |
| | | |
| | | // Checke Berechtigungen für Modul |
| | | require_once('../../lib/config.inc.php'); |
| | | require_once('../../lib/app.inc.php'); |
| | | |
| | | // Checking module permissions |
| | | if(!stristr($_SESSION["s"]["user"]["modules"],$_SESSION["s"]["module"]["name"])) { |
| | | header("Location: ../index.php"); |
| | | exit; |
| | | } |
| | | |
| | | // Lade Template |
| | | $app->uses('tpl,tform'); |
| | | $app->tpl->newTemplate("tabbed_form.tpl.htm"); |
| | | // Loading classes |
| | | $app->uses('tpl,tform,tform_actions'); |
| | | |
| | | // 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","<b>Fehler:</b><br>".$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(); |
| | | |
| | | // Template parsen |
| | | $app->tpl->pparse(); |
| | | // let tform_actions handle the page |
| | | $app->tform_actions->onLoad(); |
| | | |
| | | ?> |
| | |
| | | <?php |
| | | |
| | | /* |
| | | Copyright (c) 2005, Till Brehm, projektfarm Gmbh |
| | | Copyright (c) 2007, Till Brehm, projektfarm Gmbh |
| | | All rights reserved. |
| | | |
| | | Redistribution and use in source and binary forms, with or without modification, |
| | |
| | | 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'); |
| | | |
| | |
| | | * End Form configuration |
| | | ******************************************/ |
| | | |
| | | // Checke Berechtigungen für Modul |
| | | // Checking module permissions |
| | | if(!stristr($_SESSION["s"]["user"]["modules"],$_SESSION["s"]["module"]["name"])) { |
| | | header("Location: ../index.php"); |
| | | exit; |
| | | } |
| | | |
| | | $app->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(); |
| | | |
| | | |
| | | ?> |
| | |
| | | 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'); |
| | | |
| | | |
| | | 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','templates/index.htm'); |
| | | $app->tpl->pparse(); |
| | | $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'; |
| | | */ |
| | | } |
| | | } |
| | | |
| | | ?> |
| | |
| | | $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' |
| | | ?> |
| | |
| | | <table width="500" border="0" cellspacing="0" cellpadding="2">
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='jobname_txt'}:</td>
|
| | | <td width="366" class="frmText11"><input name="jobname" type="text" class="text" value="{tmpl_var name='jobname'}" size="15" maxlength="255"></td>
|
| | | <td class="frmText11">{tmpl_var name='jobname_txt'}:</td> |
| | | <td class="frmText11"><input name="jobname" type="text" class="text" value="{tmpl_var name='jobname'}" size="15" maxlength="255"></td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='sync_interval_minutes_txt'}:</td>
|
| | | <td width="366" class="frmText11"><input name="sync_interval_minutes" type="text" class="text" value="{tmpl_var name='sync_interval_minutes'}" size="15" maxlength="255"></td>
|
| | | <td class="frmText11">{tmpl_var name='sync_interval_minutes_txt'}:</td> |
| | | <td class="frmText11"><input name="sync_interval_minutes" type="text" class="text" value="{tmpl_var name='sync_interval_minutes'}" size="15" maxlength="255"></td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='db_type_txt'}:</td>
|
| | | <td width="366" class="frmText11">
|
| | | <td class="frmText11">{tmpl_var name='db_type_txt'}:</td> |
| | | <td class="frmText11"> |
| | | <select name="db_type" class="text">
|
| | | {tmpl_var name='db_type'}
|
| | | </select>
|
| | | </td>
|
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='db_host_txt'}:</td>
|
| | | <td width="366" class="frmText11"><input name="db_host" type="text" class="text" value="{tmpl_var name='db_host'}" size="30" maxlength="255"></td>
|
| | | <td class="frmText11">{tmpl_var name='db_host_txt'}:</td> |
| | | <td class="frmText11"><input name="db_host" type="text" class="text" value="{tmpl_var name='db_host'}" size="30" maxlength="255"></td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='db_name_txt'}:</td>
|
| | | <td width="366" class="frmText11"><input name="db_name" type="text" class="text" value="{tmpl_var name='db_name'}" size="30" maxlength="255"></td>
|
| | | <td class="frmText11">{tmpl_var name='db_name_txt'}:</td> |
| | | <td class="frmText11"><input name="db_name" type="text" class="text" value="{tmpl_var name='db_name'}" size="30" maxlength="255"></td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='db_username_txt'}:</td>
|
| | | <td width="366" class="frmText11"><input name="db_username" type="text" class="text" value="{tmpl_var name='db_username'}" size="30" maxlength="255"></td>
|
| | | <td class="frmText11">{tmpl_var name='db_username_txt'}:</td> |
| | | <td class="frmText11"><input name="db_username" type="text" class="text" value="{tmpl_var name='db_username'}" size="30" maxlength="255"></td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='db_password_txt'}:</td>
|
| | | <td width="366" class="frmText11"><input name="db_password" type="text" class="text" value="{tmpl_var name='db_password'}" size="30" maxlength="255"></td>
|
| | | <td class="frmText11">{tmpl_var name='db_password_txt'}:</td> |
| | | <td class="frmText11"><input name="db_password" type="text" class="text" value="{tmpl_var name='db_password'}" size="30" maxlength="255"></td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='db_tables_txt'}:</td>
|
| | | <td width="366" class="frmText11">{tmpl_var name='db_tables'}</td>
|
| | | <td class="frmText11">{tmpl_var name='db_tables_txt'}:</td> |
| | | <td class="frmText11">{tmpl_var name='db_tables'}</td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='empty_datalog_txt'}:</td>
|
| | | <td width="366" class="frmText11">{tmpl_var name='empty_datalog'}</td>
|
| | | <td class="frmText11">{tmpl_var name='empty_datalog_txt'}:</td> |
| | | <td class="frmText11">{tmpl_var name='empty_datalog'}</td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='sync_datalog_external_txt'}:</td>
|
| | | <td width="366" class="frmText11">{tmpl_var name='sync_datalog_external'}</td>
|
| | | <td class="frmText11">{tmpl_var name='sync_datalog_external_txt'}:</td> |
| | | <td class="frmText11">{tmpl_var name='sync_datalog_external'}</td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='active_txt'}:</td>
|
| | | <td width="366" class="frmText11">{tmpl_var name='active'}</td>
|
| | | <td class="frmText11">{tmpl_var name='active_txt'}:</td> |
| | | <td class="frmText11">{tmpl_var name='active'}</td> |
| | | </tr> <tr>
|
| | | <td class="frmText11"> </td>
|
| | | <td class="frmText11"> </td>
|
| | | </tr>
|
| | | <tr>
|
| | | <td> </td>
|
| | | <td><input name="Speichern" type="submit" class="button" value="Speichern">
|
| | | <input name="Abbrechen" type="button" class="button" value="Abbrechen" onClick="self.location.href='dbsync_list.php';">
|
| | | <td><input name="btn_save" type="button" class="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitForm('pageForm','admin/dbsync_edit.php');"><div class="buttonEnding"></div> |
| | | <input name="btn_cancel" type="button" class="button" value="{tmpl_var name='btn_cancel_txt'}" onClick="loadContent('admin/dbsync_list.php');"><div class="buttonEnding"></div> |
| | | </td>
|
| | | </tr>
|
| | | </table>
|
| | |
| | | <form name="myform" action="dbsync_list.php" method="POST">
|
| | | <div class="frmTextHead"><tmpl_var name="list_head_txt"></div><br />
|
| | | <table width="100%" border="0" cellspacing="0" cellpadding="4">
|
| | | <input type="button" value="{tmpl_var name="add_new_record_txt"}" class="button" onClick="loadContent('admin/dbsync_edit.php');" /><div class="buttonEnding"></div><br /><br /> |
| | | <table width="100%" border="0" cellspacing="0" cellpadding="4" class="listTable"> |
| | | <tr>
|
| | | <td class="tblHead"><tmpl_var name="jobname_txt"></td>
|
| | | <td class="tblHead"><tmpl_var name="db_host_txt"></td>
|
| | |
| | | <td class="frmText11"><input type="text" name="search_jobname" value="{tmpl_var name='search_jobname'}" class="text" /></td>
|
| | | <td class="frmText11"><input type="text" name="search_db_host" value="{tmpl_var name='search_db_host'}" class="text" /></td>
|
| | | <td class="frmText11"><input type="text" name="search_db_name" value="{tmpl_var name='search_db_name'}" class="text" /></td>
|
| | | <td class="frmText11" align="right"><input name="Filter" type="submit" id="Filter" value="Filter"></td>
|
| | | <td class="frmText11" align="right"><input name="Filter" type="button" id="Filter" value="{tmpl_var name="filter_txt"}" class="button" onClick="submitForm('pageForm','admin/dbsync_list.php');"><div class="buttonEnding"></div></td> |
| | | </tr>
|
| | | <tmpl_loop name="records">
|
| | | <tr bgcolor="{tmpl_var name="bgcolor"}">
|
| | | <td class="frmText11"><a href="dbsync_edit.php?id={tmpl_var name='id'}" class="frmText11">{tmpl_var name="jobname"}</a></td>
|
| | | <td class="frmText11"><a href="dbsync_edit.php?id={tmpl_var name='id'}" class="frmText11">{tmpl_var name="db_host"}</a></td>
|
| | | <td class="frmText11"><a href="dbsync_edit.php?id={tmpl_var name='id'}" class="frmText11">{tmpl_var name="db_name"}</a></td>
|
| | | <td class="frmText11" align="right">[<a href="javascript: del_record('dbsync_del.php?id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}');" class="frmText11">Löschen</a>]</td>
|
| | | <td class="frmText11"><a href="#" onClick="loadContent('admin/dbsync_edit.php?id={tmpl_var name='id'}');" class="frmText11">{tmpl_var name="jobname"}</a></td>
|
| | | <td class="frmText11"><a href="#" onClick="loadContent('admin/dbsync_edit.php?id={tmpl_var name='id'}');" class="frmText11">{tmpl_var name="db_host"}</a></td>
|
| | | <td class="frmText11"><a href="#" onClick="loadContent('admin/dbsync_edit.php?id={tmpl_var name='id'}');" class="frmText11">{tmpl_var name="db_name"}</a></td>
|
| | | <td class="frmText11" align="right">[<a href="javascript: del_record('admin/dbsync_del.php?id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}');" class="frmText11">{tmpl_var name='delete_txt'}</a>]</td> |
| | | </tr>
|
| | | </tmpl_loop>
|
| | |
|
| | |
| | | <td colspan="4" height="40" align="center" class="tblFooter"><tmpl_var name="paging"></td>
|
| | | </tr>
|
| | | </table>
|
| | | </form> |
| | |
| | | <table width="500" border="0" cellspacing="0" cellpadding="2">
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='jobname_txt'}:</td>
|
| | | <td width="366" class="frmText11"><input name="jobname" type="text" class="text" value="{tmpl_var name='jobname'}" size="15" maxlength="255"></td>
|
| | | <td class="frmText11">{tmpl_var name='jobname_txt'}:</td> |
| | | <td class="frmText11"><input name="jobname" type="text" class="text" value="{tmpl_var name='jobname'}" size="15" maxlength="255"></td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='sync_interval_minutes_txt'}:</td>
|
| | | <td width="366" class="frmText11"><input name="sync_interval_minutes" type="text" class="text" value="{tmpl_var name='sync_interval_minutes'}" size="15" maxlength="255"></td>
|
| | | <td class="frmText11">{tmpl_var name='sync_interval_minutes_txt'}:</td> |
| | | <td class="frmText11"><input name="sync_interval_minutes" type="text" class="text" value="{tmpl_var name='sync_interval_minutes'}" size="15" maxlength="255"></td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='ftp_host_txt'}:</td>
|
| | | <td width="366" class="frmText11"><input name="ftp_host" type="text" class="text" value="{tmpl_var name='ftp_host'}" size="30" maxlength="255"></td>
|
| | | <td class="frmText11">{tmpl_var name='ftp_host_txt'}:</td> |
| | | <td class="frmText11"><input name="ftp_host" type="text" class="text" value="{tmpl_var name='ftp_host'}" size="30" maxlength="255"></td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='ftp_path_txt'}:</td>
|
| | | <td width="366" class="frmText11"><input name="ftp_path" type="text" class="text" value="{tmpl_var name='ftp_path'}" size="30" maxlength="255"></td>
|
| | | <td class="frmText11">{tmpl_var name='ftp_path_txt'}:</td> |
| | | <td class="frmText11"><input name="ftp_path" type="text" class="text" value="{tmpl_var name='ftp_path'}" size="30" maxlength="255"></td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='ftp_username_txt'}:</td>
|
| | | <td width="366" class="frmText11"><input name="ftp_username" type="text" class="text" value="{tmpl_var name='ftp_username'}" size="30" maxlength="255"></td>
|
| | | <td class="frmText11">{tmpl_var name='ftp_username_txt'}:</td> |
| | | <td class="frmText11"><input name="ftp_username" type="text" class="text" value="{tmpl_var name='ftp_username'}" size="30" maxlength="255"></td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='ftp_password_txt'}:</td>
|
| | | <td width="366" class="frmText11"><input name="ftp_password" type="text" class="text" value="{tmpl_var name='ftp_password'}" size="30" maxlength="255"></td>
|
| | | <td class="frmText11">{tmpl_var name='ftp_password_txt'}:</td> |
| | | <td class="frmText11"><input name="ftp_password" type="text" class="text" value="{tmpl_var name='ftp_password'}" size="30" maxlength="255"></td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='local_path_txt'}:</td>
|
| | | <td width="366" class="frmText11"><input name="local_path" type="text" class="text" value="{tmpl_var name='local_path'}" size="30" maxlength="255"></td>
|
| | | <td class="frmText11">{tmpl_var name='local_path_txt'}:</td> |
| | | <td class="frmText11"><input name="local_path" type="text" class="text" value="{tmpl_var name='local_path'}" size="30" maxlength="255"></td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='wput_options_txt'}:</td>
|
| | | <td width="366" class="frmText11"><input name="wput_options" type="text" class="text" value="{tmpl_var name='wput_options'}" size="30" maxlength="255"></td>
|
| | | <td class="frmText11">{tmpl_var name='wput_options_txt'}:</td> |
| | | <td class="frmText11"><input name="wput_options" type="text" class="text" value="{tmpl_var name='wput_options'}" size="30" maxlength="255"></td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='active_txt'}:</td>
|
| | | <td width="366" class="frmText11">{tmpl_var name='active'}</td>
|
| | | <td class="frmText11">{tmpl_var name='active_txt'}:</td> |
| | | <td class="frmText11">{tmpl_var name='active'}</td> |
| | | </tr> <tr>
|
| | | <td class="frmText11"> </td>
|
| | | <td class="frmText11"> </td>
|
| | | </tr>
|
| | | <tr>
|
| | | <td> </td>
|
| | | <td><input name="Speichern" type="submit" class="button" value="Speichern">
|
| | | <input name="Abbrechen" type="button" class="button" value="Abbrechen" onClick="self.location.href='filesync_list.php';">
|
| | | <td><input name="btn_save" type="button" class="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitForm('pageForm','admin/filesync_edit.php');"><div class="buttonEnding"></div> |
| | | <input name="btn_cancel" type="button" class="button" value="{tmpl_var name='btn_cancel_txt'}" onClick="loadContent('admin/filesync_list.php');"><div class="buttonEnding"></div> |
| | | </td>
|
| | | </tr>
|
| | | </table>
|
| | |
| | | <form name="myform" action="filesync_list.php" method="POST"> |
| | | <div class="frmTextHead"><tmpl_var name="list_head_txt"></div><br /> |
| | | <table width="100%" border="0" cellspacing="0" cellpadding="4"> |
| | | <input type="button" value="{tmpl_var name="add_new_record_txt"}" class="button" onClick="loadContent('admin/filesync_edit.php');" /><div class="buttonEnding"></div><br /><br /> |
| | | <table width="100%" border="0" cellspacing="0" cellpadding="4" class="listTable"> |
| | | <tr> |
| | | <td class="tblHead"><tmpl_var name="jobname_txt"></td> |
| | | <td class="tblHead"><tmpl_var name="ftp_host_txt"></td> |
| | |
| | | <td class="frmText11"><input type="text" name="search_jobname" value="{tmpl_var name='search_jobname'}" class="text" /></td> |
| | | <td class="frmText11"><input type="text" name="search_ftp_host" value="{tmpl_var name='search_ftp_host'}" class="text" /></td> |
| | | <td class="frmText11"><input type="text" name="search_local_path" value="{tmpl_var name='search_local_path'}" class="text" /></td> |
| | | <td class="frmText11" align="right"><input name="Filter" type="submit" id="Filter" value="Filter"></td> |
| | | <td class="frmText11" align="right"><input name="Filter" type="button" id="Filter" value="{tmpl_var name="filter_txt"}" class="button" onClick="submitForm('pageForm','admin/filesync_list.php');"><div class="buttonEnding"></div></td> |
| | | </tr> |
| | | <tmpl_loop name="records"> |
| | | <tr bgcolor="{tmpl_var name="bgcolor"}"> |
| | | <td class="frmText11"><a href="filesync_edit.php?id={tmpl_var name='id'}" class="frmText11">{tmpl_var name="jobname"}</a></td> |
| | | <td class="frmText11"><a href="filesync_edit.php?id={tmpl_var name='id'}" class="frmText11">{tmpl_var name="ftp_host"}</a></td> |
| | | <td class="frmText11"><a href="filesync_edit.php?id={tmpl_var name='id'}" class="frmText11">{tmpl_var name="local_path"}</a></td> |
| | | <td class="frmText11" align="right">[<a href="javascript: del_record('filesync_del.php?id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}');" class="frmText11">Delete</a>]</td> |
| | | <td class="frmText11"><a href="#" onClick="loadContent('admin/filesync_edit.php?id={tmpl_var name='id'}');" class="frmText11">{tmpl_var name="jobname"}</a></td>
|
| | | <td class="frmText11"><a href="#" onClick="loadContent('admin/filesync_edit.php?id={tmpl_var name='id'}');" class="frmText11">{tmpl_var name="ftp_host"}</a></td>
|
| | | <td class="frmText11"><a href="#" onClick="loadContent('admin/filesync_edit.php?id={tmpl_var name='id'}');" class="frmText11">{tmpl_var name="local_path"}</a></td>
|
| | | <td class="frmText11" align="right">[<a href="javascript: del_record('admin/filesync_del.php?id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}');" class="frmText11">{tmpl_var name='delete_txt'}</a>]</td> |
| | | </tr> |
| | | </tmpl_loop> |
| | | |
| | |
| | | <td colspan="4" height="40" align="center" class="tblFooter"><tmpl_var name="paging"></td> |
| | | </tr> |
| | | </table> |
| | | </form> |
| | |
| | | <table width="500" border="0" cellspacing="0" cellpadding="2">
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='name_txt'}:</td>
|
| | | <td width="366" class="frmText11"><input name="name" type="text" class="text" value="{tmpl_var name='name'}" size="30" maxlength="255"></td>
|
| | | <td class="frmText11">{tmpl_var name='name_txt'}:</td> |
| | | <td class="frmText11"><input name="name" type="text" class="text" value="{tmpl_var name='name'}" size="30" maxlength="255"></td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='description_txt'}:</td>
|
| | | <td width="366" class="frmText11"><textarea name='description' cols='30' rows='5'>{tmpl_var name='description'}</textarea></td>
|
| | | <td class="frmText11">{tmpl_var name='description_txt'}:</td> |
| | | <td class="frmText11"><textarea name='description' cols='30' rows='5'>{tmpl_var name='description'}</textarea></td> |
| | | </tr><tr>
|
| | | <td class="frmText11"> </td> |
| | | <td class="frmText11"> </td> |
| | | </tr> |
| | | <tr> |
| | | <td> </td>
|
| | | <td><input name="Speichern" type="submit" class="button" value="Speichern">
|
| | | <input name="Abbrechen" type="button" class="button" value="Abbrechen" onClick="self.location.href='groups_list.php';">
|
| | | <td><input name="btn_save" type="button" class="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitForm('pageForm','admin/groups_edit.php');"><div class="buttonEnding"></div> |
| | | <input name="btn_cancel" type="button" class="button" value="{tmpl_var name='btn_cancel_txt'}" onClick="loadContent('admin/groups_list.php');"><div class="buttonEnding"></div> |
| | | </td>
|
| | | </tr>
|
| | | </table>
|
| | |
| | | <form name="myform" action="groups_list.php" method="POST"> |
| | | <div class="frmTextHead"><tmpl_var name="list_head_txt"></div><br /> |
| | | <table width="100%" border="0" cellspacing="0" cellpadding="4"> |
| | | <input type="button" value="{tmpl_var name="add_new_record_txt"}" class="button" onClick="loadContent('admin/groups_edit.php');" /><div class="buttonEnding"></div><br /><br /> |
| | | <table width="100%" border="0" cellspacing="0" cellpadding="4" class="listTable"> |
| | | <tr> |
| | | <td class="tblHead"><tmpl_var name="name_txt"></td> |
| | | <td class="tblHead"><tmpl_var name="description_txt"></td> |
| | |
| | | <tr> |
| | | <td class="frmText11"><input type="text" name="search_name" value="{tmpl_var name='search_name'}" class="text" /></td> |
| | | <td class="frmText11"><input type="text" name="search_description" value="{tmpl_var name='search_description'}" class="text" /></td> |
| | | <td class="frmText11" align="right"><input name="Filter" type="submit" id="Filter" value="Filter"></td> |
| | | <td class="frmText11" align="right"><input name="Filter" type="button" id="Filter" value="{tmpl_var name="filter_txt"}" class="button" onClick="submitForm('pageForm','admin/groups_list.php');"><div class="buttonEnding"></div></td> |
| | | </tr> |
| | | <tmpl_loop name="records"> |
| | | <tr bgcolor="{tmpl_var name="bgcolor"}"> |
| | | <td class="frmText11"><a href="groups_edit.php?id={tmpl_var name='id'}" class="frmText11">{tmpl_var name="name"}</a></td> |
| | | <td class="frmText11"><a href="groups_edit.php?id={tmpl_var name='id'}" class="frmText11">{tmpl_var name="description"}</a></td> |
| | | <td class="frmText11" align="right">[<a href="javascript: del_record('groups_del.php?id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}');" class="frmText11">Delete</a>]</td> |
| | | <td class="frmText11"><a href="#" onClick="loadContent('admin/groups_edit.php?id={tmpl_var name='id'}');" class="frmText11">{tmpl_var name="name"}</a></td>
|
| | | <td class="frmText11"><a href="#" onClick="loadContent('admin/groups_edit.php?id={tmpl_var name='id'}');" class="frmText11">{tmpl_var name="description"}</a></td>
|
| | | <td class="frmText11" align="right">[<a href="javascript: del_record('admin/groups_del.php?id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}');" class="frmText11">{tmpl_var name='delete_txt'}</a>]</td> |
| | | </tr> |
| | | </tmpl_loop> |
| | | |
| | |
| | | <td colspan="3" height="40" align="center" class="tblFooter"><tmpl_var name="paging"></td> |
| | | </tr> |
| | | </table> |
| | | </form> |
| | |
| | | <p> </p>
|
| | | <p> </p>
|
| | | <p> </p>
|
| | | <form action="index.php" method="post" name="login" target="_self" id="login">
|
| | | <table width="288" border="0" align="center" cellpadding="4" cellspacing="0">
|
| | | <tr>
|
| | | <td> </td>
|
| | | <td> Admin</td>
|
| | | </tr>
|
| | | </table>
|
| | | </form>
|
| | |
| | | <table width="500" border="0" cellspacing="0" cellpadding="2"> |
| | | <tr> |
| | | <td width="100" class="frmText11">{tmpl_var name='server_name_txt'}:</td> |
| | | <td class="frmText11"><input name="server_name" type="text" class="text" value="{tmpl_var name='server_name'}" size="15" maxlength="255"></td> |
| | | <td class="frmText11">{tmpl_var name='server_name_txt'}:</td> |
| | | <td class="frmText11"><input name="server_name" type="text" class="text" value="{tmpl_var name='server_name'}" size="30" maxlength="255"></td> |
| | | </tr> |
| | | <tr><td colspan="2"> </td></tr> |
| | | <tr><td colspan="2"> |
| | | <fieldset style="width:205px;"><legend class="frmText11"><b>Services</b></legend> |
| | | <table border="0" cellspacing="0" cellpadding="2"> |
| | | <tr> |
| | | <td class="frmText11">{tmpl_var name='mail_server_txt'}:</td> |
| | | <td class="frmText11">{tmpl_var name='mail_server'}</td> |
| | | <td class="frmText11">{tmpl_var name='mail_server_txt'}</td> |
| | | </tr> |
| | | <tr> |
| | | <td class="frmText11">{tmpl_var name='web_server_txt'}:</td> |
| | | <td class="frmText11">{tmpl_var name='web_server'}</td> |
| | | <td class="frmText11">{tmpl_var name='web_server_txt'}</td> |
| | | </tr> |
| | | <tr> |
| | | <td class="frmText11">{tmpl_var name='dns_server_txt'}:</td> |
| | | <td class="frmText11">{tmpl_var name='dns_server'}</td> |
| | | <td class="frmText11">{tmpl_var name='dns_server_txt'}</td> |
| | | </tr> |
| | | <tr> |
| | | <td class="frmText11">{tmpl_var name='file_server_txt'}:</td> |
| | | <td class="frmText11">{tmpl_var name='file_server'}</td> |
| | | <td class="frmText11">{tmpl_var name='file_server_txt'}</td> |
| | | </tr> |
| | | <tr> |
| | | <td class="frmText11">{tmpl_var name='db_server_txt'}:</td> |
| | | <td class="frmText11">{tmpl_var name='db_server'}</td> |
| | | <td class="frmText11">{tmpl_var name='db_server_txt'}</td> |
| | | </tr> |
| | | <tr> |
| | | <td class="frmText11">{tmpl_var name='vserver_server_txt'}:</td> |
| | | <td class="frmText11">{tmpl_var name='vserver_server'}</td> |
| | | <td class="frmText11">{tmpl_var name='vserver_server_txt'}</td> |
| | | </tr> |
| | | </table> |
| | | </fieldset> |
| | | </td></tr> |
| | | <tr><td colspan="2"> </td></tr> |
| | | <tr> |
| | | <td class="frmText11">{tmpl_var name='active_txt'}:</td> |
| | | <td class="frmText11"> |
| | |
| | | </tr> |
| | | <tr> |
| | | <td> </td> |
| | | <td><input name="btn_save" type="submit" class="button" value="{tmpl_var name='btn_save_txt'}"> |
| | | <input name="btn_cancel" type="button" class="button" value="{tmpl_var name='btn_cancel_txt'}" onClick="self.location.href='server_list.php';"> |
| | | <td><input name="btn_save" type="button" class="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitForm('pageForm','admin/server_edit.php');"><div class="buttonEnding"></div> |
| | | <input name="btn_cancel" type="button" class="button" value="{tmpl_var name='btn_cancel_txt'}" onClick="loadContent('admin/server_list.php');"><div class="buttonEnding"></div> |
| | | </td> |
| | | </tr> |
| | | </table> |
| | |
| | | <form name="myform" action="server_list.php" method="POST"> |
| | | <div class="frmTextHead"><tmpl_var name="list_head_txt"></div><br /> |
| | | <table width="100%" border="0" cellspacing="0" cellpadding="4"> |
| | | <input type="button" value="{tmpl_var name="add_new_record_txt"}" class="button" onClick="loadContent('admin/server_edit.php');" /><div class="buttonEnding"></div><br /><br /> |
| | | <table width="100%" border="0" cellspacing="0" cellpadding="4" class="listTable"> |
| | | <tr> |
| | | <td class="tblHead"><tmpl_var name="server_name_txt"></td> |
| | | <td class="tblHead"><tmpl_var name="mail_server_txt"></td> |
| | | <td class="tblHead"><tmpl_var name="web_server_txt"></td> |
| | | <td class="tblHead"><tmpl_var name="dns_server_txt"></td> |
| | | <td class="tblHead"><tmpl_var name="file_server_txt"></td> |
| | | <td class="tblHead"><tmpl_var name="mysql_server_txt"></td> |
| | | <td class="tblHead"><tmpl_var name="postgresql_server_txt"></td> |
| | | <td class="tblHead"><tmpl_var name="firebird_server_txt"></td> |
| | | <td class="tblHead"><tmpl_var name="db_server_txt"></td>
|
| | | <td class="tblHead"><tmpl_var name="vserver_server_txt"></td>
|
| | | <td class="tblHead"> </td> |
| | | </tr> |
| | | <tr> |
| | | <td class="frmText11"><input type="text" name="search_server_name" value="{tmpl_var name='search_server_name'}" class="text" /></td> |
| | | <td class="frmText11"><input type="text" name="search_mail_server" value="{tmpl_var name='search_mail_server'}" class="text" size="2" /></td> |
| | | <td class="frmText11"><input type="text" name="search_web_server" value="{tmpl_var name='search_web_server'}" class="text" size="2" /></td> |
| | | <td class="frmText11"><input type="text" name="search_dns_server" value="{tmpl_var name='search_dns_server'}" class="text" size="2" /></td> |
| | | <td class="frmText11"><input type="text" name="search_file_server" value="{tmpl_var name='search_file_server'}" class="text" size="2" /></td> |
| | | <td class="frmText11"><input type="text" name="search_mysql_server" value="{tmpl_var name='search_db_server'}" class="text" size="2" /></td> |
| | | <td class="frmText11"><input type="text" name="search_postgresql_server" value="{tmpl_var name='search_vserver_server'}" class="text" size="2" /></td> |
| | | <td class="frmText11" align="right"><input name="Filter" type="submit" id="Filter" value="{tmpl_var name="filter_txt"}"></td> |
| | | <td class="frmText11"><input type="text" name="search_mail_server" value="{tmpl_var name='search_mail_server'}" class="text" /></td>
|
| | | <td class="frmText11"><input type="text" name="search_web_server" value="{tmpl_var name='search_web_server'}" class="text" /></td>
|
| | | <td class="frmText11"><input type="text" name="search_dns_server" value="{tmpl_var name='search_dns_server'}" class="text" /></td>
|
| | | <td class="frmText11"><input type="text" name="search_file_server" value="{tmpl_var name='search_file_server'}" class="text" /></td>
|
| | | <td class="frmText11"><input type="text" name="search_db_server" value="{tmpl_var name='search_db_server'}" class="text" /></td>
|
| | | <td class="frmText11"><input type="text" name="search_vserver_server" value="{tmpl_var name='search_vserver_server'}" class="text" /></td>
|
| | | <td class="frmText11" align="right"><input name="Filter" type="button" id="Filter" value="{tmpl_var name="filter_txt"}" class="button" onClick="submitForm('pageForm','admin/server_list.php');"><div class="buttonEnding"></div></td> |
| | | </tr> |
| | | <tmpl_loop name="records"> |
| | | <tr bgcolor="{tmpl_var name="bgcolor"}"> |
| | | <td class="frmText11"><a href="server_edit.php?id={tmpl_var name='id'}" class="frmText11">{tmpl_var name="server_name"}</a></td> |
| | | <td class="frmText11"><a href="server_edit.php?id={tmpl_var name='id'}" class="frmText11">{tmpl_var name="mail_server"}</a></td> |
| | | <td class="frmText11"><a href="server_edit.php?id={tmpl_var name='id'}" class="frmText11">{tmpl_var name="web_server"}</a></td> |
| | | <td class="frmText11"><a href="server_edit.php?id={tmpl_var name='id'}" class="frmText11">{tmpl_var name="dns_server"}</a></td> |
| | | <td class="frmText11"><a href="server_edit.php?id={tmpl_var name='id'}" class="frmText11">{tmpl_var name="file_server"}</a></td> |
| | | <td class="frmText11"><a href="server_edit.php?id={tmpl_var name='id'}" class="frmText11">{tmpl_var name="db_server"}</a></td> |
| | | <td class="frmText11"><a href="server_edit.php?id={tmpl_var name='id'}" class="frmText11">{tmpl_var name="vserver_server"}</a></td> |
| | | <td class="frmText11" align="right">[<a href="javascript: del_record('server_del.php?id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}');" class="frmText11">{tmpl_var name='delete_txt'}</a>]</td> |
| | | <td class="frmText11"><a href="#" onClick="loadContent('admin/server_edit.php?id={tmpl_var name='id'}');" class="frmText11">{tmpl_var name="server_name"}</a></td>
|
| | | <td class="frmText11"><a href="#" onClick="loadContent('admin/server_edit.php?id={tmpl_var name='id'}');" class="frmText11">{tmpl_var name="mail_server"}</a></td>
|
| | | <td class="frmText11"><a href="#" onClick="loadContent('admin/server_edit.php?id={tmpl_var name='id'}');" class="frmText11">{tmpl_var name="web_server"}</a></td>
|
| | | <td class="frmText11"><a href="#" onClick="loadContent('admin/server_edit.php?id={tmpl_var name='id'}');" class="frmText11">{tmpl_var name="dns_server"}</a></td>
|
| | | <td class="frmText11"><a href="#" onClick="loadContent('admin/server_edit.php?id={tmpl_var name='id'}');" class="frmText11">{tmpl_var name="file_server"}</a></td>
|
| | | <td class="frmText11"><a href="#" onClick="loadContent('admin/server_edit.php?id={tmpl_var name='id'}');" class="frmText11">{tmpl_var name="db_server"}</a></td>
|
| | | <td class="frmText11"><a href="#" onClick="loadContent('admin/server_edit.php?id={tmpl_var name='id'}');" class="frmText11">{tmpl_var name="vserver_server"}</a></td>
|
| | | <td class="frmText11" align="right">[<a href="javascript: del_record('admin/server_del.php?id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}');" class="frmText11">{tmpl_var name='delete_txt'}</a>]</td> |
| | | </tr> |
| | | </tmpl_loop> |
| | | |
| | | <tr> |
| | | <td colspan="9" height="40" align="center" class="tblFooter"><tmpl_var name="paging"></td> |
| | | <td colspan="8" height="40" align="center" class="tblFooter"><tmpl_var name="paging"></td> |
| | | </tr> |
| | | </table> |
| | | </form> |
| | |
| | | <table width="500" border="0" cellspacing="0" cellpadding="2">
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='name_txt'}:</td>
|
| | | <td width="366" class="frmText11"><input name="name" type="text" class="text" value="{tmpl_var name='name'}" size="30" maxlength="255"></td>
|
| | | <td class="frmText11">{tmpl_var name='name_txt'}:</td> |
| | | <td class="frmText11"><input name="name" type="text" class="text" value="{tmpl_var name='name'}" size="30" maxlength="255"></td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='vorname_txt'}:</td>
|
| | | <td width="366" class="frmText11"><input name="vorname" type="text" class="text" value="{tmpl_var name='vorname'}" size="30" maxlength="255"></td>
|
| | | <td class="frmText11">{tmpl_var name='vorname_txt'}:</td> |
| | | <td class="frmText11"><input name="vorname" type="text" class="text" value="{tmpl_var name='vorname'}" size="30" maxlength="255"></td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='unternehmen_txt'}:</td>
|
| | | <td width="366" class="frmText11"><input name="unternehmen" type="text" class="text" value="{tmpl_var name='unternehmen'}" size="30" maxlength="255"></td>
|
| | | <td class="frmText11">{tmpl_var name='unternehmen_txt'}:</td> |
| | | <td class="frmText11"><input name="unternehmen" type="text" class="text" value="{tmpl_var name='unternehmen'}" size="30" maxlength="255"></td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='strasse_txt'}:</td>
|
| | | <td width="366" class="frmText11"><input name="strasse" type="text" class="text" value="{tmpl_var name='strasse'}" size="30" maxlength="255"></td>
|
| | | <td class="frmText11">{tmpl_var name='strasse_txt'}:</td> |
| | | <td class="frmText11"><input name="strasse" type="text" class="text" value="{tmpl_var name='strasse'}" size="30" maxlength="255"></td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='ort_txt'}:</td>
|
| | | <td width="366" class="frmText11"><input name="ort" type="text" class="text" value="{tmpl_var name='ort'}" size="30" maxlength="255"></td>
|
| | | <td class="frmText11">{tmpl_var name='ort_txt'}:</td> |
| | | <td class="frmText11"><input name="ort" type="text" class="text" value="{tmpl_var name='ort'}" size="30" maxlength="255"></td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='plz_txt'}:</td>
|
| | | <td width="366" class="frmText11"><input name="plz" type="text" class="text" value="{tmpl_var name='plz'}" size="30" maxlength="255"></td>
|
| | | <td class="frmText11">{tmpl_var name='plz_txt'}:</td> |
| | | <td class="frmText11"><input name="plz" type="text" class="text" value="{tmpl_var name='plz'}" size="30" maxlength="255"></td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='land_txt'}:</td>
|
| | | <td width="366" class="frmText11"><input name="land" type="text" class="text" value="{tmpl_var name='land'}" size="30" maxlength="255"></td>
|
| | | <td class="frmText11">{tmpl_var name='land_txt'}:</td> |
| | | <td class="frmText11"><input name="land" type="text" class="text" value="{tmpl_var name='land'}" size="30" maxlength="255"></td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='email_txt'}:</td>
|
| | | <td width="366" class="frmText11"><input name="email" type="text" class="text" value="{tmpl_var name='email'}" size="30" maxlength="255"></td>
|
| | | <td class="frmText11">{tmpl_var name='email_txt'}:</td> |
| | | <td class="frmText11"><input name="email" type="text" class="text" value="{tmpl_var name='email'}" size="30" maxlength="255"></td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='url_txt'}:</td>
|
| | | <td width="366" class="frmText11"><input name="url" type="text" class="text" value="{tmpl_var name='url'}" size="30" maxlength="255"></td>
|
| | | <td class="frmText11">{tmpl_var name='url_txt'}:</td> |
| | | <td class="frmText11"><input name="url" type="text" class="text" value="{tmpl_var name='url'}" size="30" maxlength="255"></td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='telefon_txt'}:</td>
|
| | | <td width="366" class="frmText11"><input name="telefon" type="text" class="text" value="{tmpl_var name='telefon'}" size="30" maxlength="255"></td>
|
| | | <td class="frmText11">{tmpl_var name='telefon_txt'}:</td> |
| | | <td class="frmText11"><input name="telefon" type="text" class="text" value="{tmpl_var name='telefon'}" size="30" maxlength="255"></td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='fax_txt'}:</td>
|
| | | <td width="366" class="frmText11"><input name="fax" type="text" class="text" value="{tmpl_var name='fax'}" size="30" maxlength="255"></td>
|
| | | <td class="frmText11">{tmpl_var name='fax_txt'}:</td> |
| | | <td class="frmText11"><input name="fax" type="text" class="text" value="{tmpl_var name='fax'}" size="30" maxlength="255"></td> |
| | | </tr><tr>
|
| | | <td class="frmText11"> </td> |
| | | <td class="frmText11"> </td> |
| | | </tr> |
| | | <tr> |
| | | <td> </td>
|
| | | <td><input name="Speichern" type="submit" class="button" value="Speichern">
|
| | | <input name="Abbrechen" type="button" class="button" value="Abbrechen" onClick="self.location.href='users_list.php';">
|
| | | <td><input name="btn_save" type="button" class="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitForm('pageForm','admin/users_edit.php');"><div class="buttonEnding"></div> |
| | | <input name="btn_cancel" type="button" class="button" value="{tmpl_var name='btn_cancel_txt'}" onClick="loadContent('admin/users_list.php');"><div class="buttonEnding"></div> |
| | | </td>
|
| | | </tr>
|
| | | </table>
|
| | |
| | | <table width="500" border="0" cellspacing="0" cellpadding="2">
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='default_group_txt'}:</td>
|
| | | <td width="366" class="frmText11">
|
| | | <td class="frmText11">{tmpl_var name='default_group_txt'}:</td> |
| | | <td class="frmText11"> |
| | | <select name="default_group" class="text">
|
| | | {tmpl_var name='default_group'}
|
| | | </select>
|
| | | </td>
|
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='groups_txt'}:</td>
|
| | | <td width="366" class="frmText11">{tmpl_var name='groups'}</td>
|
| | | <td class="frmText11">{tmpl_var name='groups_txt'}:</td> |
| | | <td class="frmText11">{tmpl_var name='groups'}</td> |
| | | </tr> <tr>
|
| | | <td class="frmText11"> </td>
|
| | | <td class="frmText11"> </td>
|
| | | </tr>
|
| | | <tr>
|
| | | <td> </td>
|
| | | <td><input name="Speichern" type="submit" class="button" value="Speichern">
|
| | | <input name="Abbrechen" type="button" class="button" value="Abbrechen" onClick="self.location.href='users_list.php';">
|
| | | <td><input name="btn_save" type="button" class="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitForm('pageForm','admin/users_edit.php');"><div class="buttonEnding"></div> |
| | | <input name="btn_cancel" type="button" class="button" value="{tmpl_var name='btn_cancel_txt'}" onClick="loadContent('admin/users_list.php');"><div class="buttonEnding"></div> |
| | | </td>
|
| | | </tr>
|
| | | </table>
|
| | |
| | | <form name="myform" action="users_list.php" method="POST"> |
| | | <div class="frmTextHead"><tmpl_var name="list_head_txt"></div><br /> |
| | | <table width="100%" border="0" cellspacing="0" cellpadding="4"> |
| | | <input type="button" value="{tmpl_var name="add_new_record_txt"}" class="button" onClick="loadContent('admin/users_edit.php');" /><div class="buttonEnding"></div><br /><br /> |
| | | <table width="100%" border="0" cellspacing="0" cellpadding="4" class="listTable"> |
| | | <tr> |
| | | <td class="tblHead"><tmpl_var name="username_txt"></td> |
| | | <td class="tblHead"><tmpl_var name="vorname_txt"></td> |
| | |
| | | <td class="frmText11"><input type="text" name="search_vorname" value="{tmpl_var name='search_vorname'}" class="text" /></td> |
| | | <td class="frmText11"><input type="text" name="search_name" value="{tmpl_var name='search_name'}" class="text" /></td> |
| | | <td class="frmText11"><input type="text" name="search_ort" value="{tmpl_var name='search_ort'}" class="text" /></td> |
| | | <td class="frmText11" align="right"><input name="Filter" type="submit" id="Filter" value="Filter"></td> |
| | | <td class="frmText11" align="right"><input name="Filter" type="button" id="Filter" value="{tmpl_var name="filter_txt"}" class="button" onClick="submitForm('pageForm','admin/users_list.php');"><div class="buttonEnding"></div></td> |
| | | </tr> |
| | | <tmpl_loop name="records"> |
| | | <tr bgcolor="{tmpl_var name="bgcolor"}"> |
| | | <td class="frmText11"><a href="users_edit.php?id={tmpl_var name='id'}" class="frmText11">{tmpl_var name="username"}</a></td> |
| | | <td class="frmText11"><a href="users_edit.php?id={tmpl_var name='id'}" class="frmText11">{tmpl_var name="vorname"}</a></td> |
| | | <td class="frmText11"><a href="users_edit.php?id={tmpl_var name='id'}" class="frmText11">{tmpl_var name="name"}</a></td> |
| | | <td class="frmText11"><a href="users_edit.php?id={tmpl_var name='id'}" class="frmText11">{tmpl_var name="ort"}</a></td> |
| | | <td class="frmText11" align="right">[<a href="javascript: del_record('users_del.php?id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}');" class="frmText11">Delete</a>]</td> |
| | | <td class="frmText11"><a href="#" onClick="loadContent('admin/users_edit.php?id={tmpl_var name='id'}');" class="frmText11">{tmpl_var name="username"}</a></td>
|
| | | <td class="frmText11"><a href="#" onClick="loadContent('admin/users_edit.php?id={tmpl_var name='id'}');" class="frmText11">{tmpl_var name="vorname"}</a></td>
|
| | | <td class="frmText11"><a href="#" onClick="loadContent('admin/users_edit.php?id={tmpl_var name='id'}');" class="frmText11">{tmpl_var name="name"}</a></td>
|
| | | <td class="frmText11"><a href="#" onClick="loadContent('admin/users_edit.php?id={tmpl_var name='id'}');" class="frmText11">{tmpl_var name="ort"}</a></td>
|
| | | <td class="frmText11" align="right">[<a href="javascript: del_record('admin/users_del.php?id={tmpl_var name='id'}&phpsessid={tmpl_var name='phpsessid'}');" class="frmText11">{tmpl_var name='delete_txt'}</a>]</td> |
| | | </tr> |
| | | </tmpl_loop> |
| | | |
| | |
| | | <td colspan="5" height="40" align="center" class="tblFooter"><tmpl_var name="paging"></td> |
| | | </tr> |
| | | </table> |
| | | </form> |
| | |
| | | <table width="500" border="0" cellspacing="0" cellpadding="2">
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='username_txt'}:</td>
|
| | | <td width="366" class="frmText11"><input name="username" type="text" class="text" value="{tmpl_var name='username'}" size="15" maxlength="30"></td>
|
| | | <td class="frmText11">{tmpl_var name='username_txt'}:</td> |
| | | <td class="frmText11"><input name="username" type="text" class="text" value="{tmpl_var name='username'}" size="15" maxlength="30"></td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='passwort_txt'}:</td>
|
| | | <td width="366" class="frmText11"><input name="passwort" type="password" class="text" value="{tmpl_var name='passwort'}" size="15" maxlength="100"></td>
|
| | | <td class="frmText11">{tmpl_var name='passwort_txt'}:</td> |
| | | <td class="frmText11"><input name="passwort" type="password" class="text" value="{tmpl_var name='passwort'}" size="15" maxlength="100"></td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='modules_txt'}:</td>
|
| | | <td width="366" class="frmText11">{tmpl_var name='modules'}</td>
|
| | | <td class="frmText11">{tmpl_var name='modules_txt'}:</td> |
| | | <td class="frmText11">{tmpl_var name='modules'}</td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='startmodule_txt'}:</td>
|
| | | <td width="366" class="frmText11">
|
| | | <td class="frmText11">{tmpl_var name='startmodule_txt'}:</td> |
| | | <td class="frmText11"> |
| | | <select name="startmodule" class="text">
|
| | | {tmpl_var name='startmodule'}
|
| | | </select>
|
| | | </td>
|
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11" valign="top">{tmpl_var name='app_theme_txt'}:</td>
|
| | | <td width="366" class="frmText11">{tmpl_var name='app_theme'}</td>
|
| | | <td class="frmText11">{tmpl_var name='app_theme_txt'}:</td> |
| | | <td class="frmText11">{tmpl_var name='app_theme'}</td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11" valign="top">{tmpl_var name='typ_txt'}:</td>
|
| | | <td width="366" class="frmText11">{tmpl_var name='typ'}</td>
|
| | | <td class="frmText11">{tmpl_var name='typ_txt'}:</td> |
| | | <td class="frmText11">{tmpl_var name='typ'}</td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='active_txt'}:</td>
|
| | | <td width="366" class="frmText11">{tmpl_var name='active'}</td>
|
| | | <td class="frmText11">{tmpl_var name='active_txt'}:</td> |
| | | <td class="frmText11">{tmpl_var name='active'}</td> |
| | | </tr>
|
| | | <tr>
|
| | | <td width="126" class="frmText11">{tmpl_var name='language_txt'}:</td>
|
| | | <td width="366" class="frmText11">
|
| | | <td class="frmText11">{tmpl_var name='language_txt'}:</td> |
| | | <td class="frmText11"> |
| | | <select name="language" class="text">
|
| | | {tmpl_var name='language'}
|
| | | </select>
|
| | | </td>
|
| | | </tr><tr>
|
| | | <td class="frmText11"> </td> |
| | | <td class="frmText11"> </td> |
| | | </tr> |
| | | <tr> |
| | | <td> </td>
|
| | | <td><input name="Speichern" type="submit" class="button" value="Speichern">
|
| | | <input name="Abbrechen" type="button" class="button" value="Abbrechen" onClick="self.location.href='users_list.php';">
|
| | | <td><input name="btn_save" type="button" class="button" value="{tmpl_var name='btn_save_txt'}" onClick="submitForm('pageForm','admin/users_edit.php');"><div class="buttonEnding"></div> |
| | | <input name="btn_cancel" type="button" class="button" value="{tmpl_var name='btn_cancel_txt'}" onClick="loadContent('admin/users_list.php');"><div class="buttonEnding"></div> |
| | | </td>
|
| | | </tr>
|
| | | </table>
|
| | |
| | | <?php |
| | | |
| | | /* |
| | | Copyright (c) 2005, Till Brehm, projektfarm Gmbh |
| | | Copyright (c) 2007, Till Brehm, projektfarm Gmbh |
| | | All rights reserved. |
| | | |
| | | Redistribution and use in source and binary forms, with or without modification, |
| | |
| | | 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'); |
| | | |
| | | /****************************************** |
| | | * Begin Form configuration |
| | | ******************************************/ |
| | | |
| | | $list_def_file = "list/users.list.php"; |
| | | $tform_def_file = "form/users.tform.php"; |
| | | |
| | | /****************************************** |
| | | * End Form configuration |
| | | ******************************************/ |
| | | |
| | | require_once('../../lib/config.inc.php'); |
| | | require_once('../../lib/app.inc.php'); |
| | | |
| | | // Checke Berechtigungen für Modul |
| | | if(!stristr($_SESSION["s"]["user"]["modules"],$_SESSION["s"]["module"]["name"])) { |
| | |
| | | exit; |
| | | } |
| | | |
| | | include_once($list_def_file); |
| | | $app->uses("tform_actions"); |
| | | $app->tform_actions->onDelete(); |
| | | |
| | | // ID importieren |
| | | $id = intval($_REQUEST["id"]); |
| | | |
| | | if($id > 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"]); |
| | | } |
| | | } |
| | | |
| | | |
| | | header("Location: ".$liste["file"]."?PHPSESSID=".$_SESSION["s"]["id"]); |
| | | exit; |
| | | ?> |
| | |
| | | <?php |
| | | /* |
| | | Copyright (c) 2005, Till Brehm, projektfarm Gmbh |
| | | Copyright (c) 2007, Till Brehm, projektfarm Gmbh |
| | | All rights reserved. |
| | | |
| | | Redistribution and use in source and binary forms, with or without modification, |
| | |
| | | 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'); |
| | | |
| | | |
| | | /****************************************** |
| | | * Begin Form configuration |
| | |
| | | * End Form configuration |
| | | ******************************************/ |
| | | |
| | | // Checke Berechtigungen für Modul |
| | | require_once('../../lib/config.inc.php'); |
| | | require_once('../../lib/app.inc.php'); |
| | | |
| | | // Checking module permissions |
| | | if(!stristr($_SESSION["s"]["user"]["modules"],$_SESSION["s"]["module"]["name"])) { |
| | | header("Location: ../index.php"); |
| | | exit; |
| | | } |
| | | |
| | | // Lade Template |
| | | $app->uses('tpl,tform'); |
| | | $app->tpl->newTemplate("tabbed_form.tpl.htm"); |
| | | // Loading classes |
| | | $app->uses('tpl,tform,tform_actions'); |
| | | |
| | | // 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","<b>Fehler:</b><br>".$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(); |
| | | |
| | | // Template parsen |
| | | $app->tpl->pparse(); |
| | | // let tform_actions handle the page |
| | | $app->tform_actions->onLoad(); |
| | | |
| | | ?> |
| | |
| | | <?php |
| | | |
| | | /* |
| | | Copyright (c) 2005, Till Brehm, projektfarm Gmbh |
| | | Copyright (c) 2007, Till Brehm, projektfarm Gmbh |
| | | All rights reserved. |
| | | |
| | | Redistribution and use in source and binary forms, with or without modification, |
| | |
| | | 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'); |
| | | |
| | |
| | | * End Form configuration |
| | | ******************************************/ |
| | | |
| | | // Checke Berechtigungen für Modul |
| | | // Checking module permissions |
| | | if(!stristr($_SESSION["s"]["user"]["modules"],$_SESSION["s"]["module"]["name"])) { |
| | | header("Location: ../index.php"); |
| | | exit; |
| | | } |
| | | |
| | | $app->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(); |
| | | |
| | | |
| | | ?> |
| | |
| | | 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)); |
| | | } |
| | | |
| | | ?> |
| | | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
| | | <html> |
| | | <head> |
| | | <title>42go</title> |
| | | <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
| | | <script language= "JavaScript"> |
| | | <!--Break out of frames |
| | | function breakout() { |
| | | if (top.frames.length > 0) |
| | | { |
| | | top.location='index.php?phpsessid=<? echo $_SESSION["s"]["id"]?>'; |
| | | } |
| | | else |
| | | { |
| | | window.location='index.php?phpsessid=<? echo $_SESSION["s"]["id"]?>'; |
| | | } |
| | | } |
| | | //--> |
| | | </script> |
| | | </head> |
| | | |
| | | <body onLoad="breakout()"> |
| | | </body> |
| | | </html> |
New file |
| | |
| | | <?php |
| | | |
| | | /* |
| | | Copyright (c) 2005, Till Brehm, projektfarm Gmbh |
| | | 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 ISPConfig nor the names of its 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. |
| | | */ |
| | | |
| | | require_once('../lib/config.inc.php'); |
| | | require_once('../lib/app.inc.php'); |
| | | |
| | | $module = $_REQUEST["s_mod"]; |
| | | $page = $_REQUEST["s_pg"]; |
| | | |
| | | if(!preg_match("/^[a-z]{0,20}$/i", $module)) die('module name contains unallowed chars.'); |
| | | if(!preg_match("/^[a-z]{0,20}$/i", $page)) die('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($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.'); |
| | | } |
| | | |
| | | ?> |
| | |
| | | |
| | | |
| | | // zu Liste springen |
| | | header("Location: module_show.php?id=$module_name"); |
| | | echo "HEADER_REDIRECT:designer/module_show.php?id=$module_name"; |
| | | exit; |
| | | } |
| | | ?> |
| | |
| | | <tr> |
| | | <td class='tblHead'>$section[title]</td> |
| | | <td class='tblHead' width='280' align='right'> |
| | | <input type=\"button\" name=\"bt1$n2\" value=\"$wb[edit_txt]\" onClick=\"location.href='module_nav_edit.php?module_name=$module_name&nav_id=$nav_id'\" class=\"button\" /> |
| | | <input type=\"button\" name=\"bt2$n2\" value=\"$wb[delete_txt]\" onClick=\"del_menu('module_nav_del.php?module_name=$module_name&nav_id=$nav_id');\" class=\"button\" /> |
| | | <input type=\"button\" name=\"bt3$n2\" value=\"$wb[new_txt]\" onClick=\"location.href='module_nav_item_edit.php?module_name=$module_name&nav_id=$nav_id'\" class=\"button\" /> |
| | | <input type=\"button\" name=\"bt4$n2\" value=\"$wb[up_txt]\" onClick=\"location.href='module_nav_flip.php?module_name=$module_name&nav_id=$nav_id&dir=up'\" class=\"button\" /> |
| | | <input type=\"button\" name=\"bt5$n2\" value=\"$wb[down_txt]\" onClick=\"location.href='module_nav_flip.php?module_name=$module_name&nav_id=$nav_id&dir=down'\" class=\"button\" /> |
| | | <input type=\"button\" name=\"bt1$n2\" value=\"$wb[edit_txt]\" onClick=\"loadContent('designer/module_nav_edit.php?module_name=$module_name&nav_id=$nav_id');\" class=\"button\" /><div class=\"buttonEnding\"></div> |
| | | <input type=\"button\" name=\"bt2$n2\" value=\"$wb[delete_txt]\" onClick=\"del_record('designer/module_nav_del.php?module_name=$module_name&nav_id=$nav_id');\" class=\"button\" /><div class=\"buttonEnding\"></div> |
| | | <input type=\"button\" name=\"bt3$n2\" value=\"$wb[new_txt]\" onClick=\"loadContent('designer/module_nav_item_edit.php?module_name=$module_name&nav_id=$nav_id');\" class=\"button\" /><div class=\"buttonEnding\"></div> |
| | | <input type=\"button\" name=\"bt4$n2\" value=\"$wb[up_txt]\" onClick=\"loadContent('designer/module_nav_flip.php?module_name=$module_name&nav_id=$nav_id&dir=up');\" class=\"button\" /><div class=\"buttonEnding\"></div> |
| | | <input type=\"button\" name=\"bt5$n2\" value=\"$wb[down_txt]\" onClick=\"loadContent('designer/module_nav_flip.php?module_name=$module_name&nav_id=$nav_id&dir=down');\" class=\"button\" /><div class=\"buttonEnding\"></div> |
| | | </td> |
| | | </tr>"; |
| | | //$content .= "<tr><td bgcolor='#EEEEEE' class='frmText11'>Bereich:</td><td class='frmText11' bgcolor='#EEEEEE'><input name=\"module[nav][$n1][title]\" type=\"text\" class=\"text\" value=\"$section[title]\" size=\"30\" maxlength=\"255\"><input name=\"module[nav][$n1][open]\" type=\"hidden\" value=\"$section[open]\"></td></tr>\r\n"; |
| | |
| | | $content .= "<tr> |
| | | <td class='frmText11'>$item[title]</td> |
| | | <td class='frmText11' width='280' align='right'> |
| | | <input type=\"button\" name=\"bt6$n2\" value=\"$wb[edit_txt]\" onClick=\"location.href='module_nav_item_edit.php?module_name=$module_name&nav_id=$nav_id&item_id=$item_id'\" class=\"button\" /> |
| | | <input type=\"button\" name=\"bt7$n2\" value=\"$wb[delete_txt]\" onClick=\"del_menuitem('module_nav_item_del.php?module_name=$module_name&nav_id=$nav_id&item_id=$item_id');\" class=\"button\" /> |
| | | <input type=\"button\" name=\"bt8$n2\" value=\"$wb[up_txt]\" onClick=\"location.href='module_nav_item_flip.php?module_name=$module_name&nav_id=$nav_id&item_id=$item_id&dir=up'\" class=\"button\" /> |
| | | <input type=\"button\" name=\"bt9$n2\" value=\"$wb[down_txt]\" onClick=\"location.href='module_nav_item_flip.php?module_name=$module_name&nav_id=$nav_id&item_id=$item_id&dir=down'\" class=\"button\" /> |
| | | <input type=\"button\" name=\"bt6$n2\" value=\"$wb[edit_txt]\" onClick=\"loadContent('designer/module_nav_item_edit.php?module_name=$module_name&nav_id=$nav_id&item_id=$item_id');\" class=\"button\" /><div class=\"buttonEnding\"></div> |
| | | <input type=\"button\" name=\"bt7$n2\" value=\"$wb[delete_txt]\" onClick=\"del_record('designer/module_nav_item_del.php?module_name=$module_name&nav_id=$nav_id&item_id=$item_id');\" class=\"button\" /><div class=\"buttonEnding\"></div> |
| | | <input type=\"button\" name=\"bt8$n2\" value=\"$wb[up_txt]\" onClick=\"loadContent('designer/module_nav_item_flip.php?module_name=$module_name&nav_id=$nav_id&item_id=$item_id&dir=up');\" class=\"button\" /><div class=\"buttonEnding\"></div> |
| | | <input type=\"button\" name=\"bt9$n2\" value=\"$wb[down_txt]\" onClick=\"loadContent('designer/module_nav_item_flip.php?module_name=$module_name&nav_id=$nav_id&item_id=$item_id&dir=down');\" class=\"button\" /><div class=\"buttonEnding\"></div> |
| | | </td> |
| | | </tr>"; |
| | | $n2++; |
| | |
| | | <form method="POST" action="module_edit.php">
|
| | | <div class="frmTextHead"><tmpl_var name="header_txt"></div><br />
|
| | | <table width="500" border="0" cellspacing="0" cellpadding="2">
|
| | | <tr>
|
| | |
| | | </tr>
|
| | | <tr>
|
| | | <td> </td>
|
| | | <td><input name="Speichern" type="submit" class="button" value="{tmpl_var name='save_txt'}">
|
| | | <input name="Abbrechen" type="button" class="button" value="{tmpl_var name='cancel_txt'}" onClick="self.location.href='module_list.php';">
|
| | | <td><input name="Speichern" type="button" class="button" value="{tmpl_var name='save_txt'}" onClick="submitForm('pageForm','designer/module_edit.php');"><div class="buttonEnding"></div> |
| | | <input name="Abbrechen" type="button" class="button" value="{tmpl_var name='cancel_txt'}" onClick="loadContent('designer/module_list.php');"><div class="buttonEnding"></div> |
| | | </td>
|
| | | </tr>
|
| | | <tr>
|
| | |
| | | </tr>
|
| | | </table>
|
| | | <input type="hidden" name="id" value="{tmpl_var name='id'}">
|
| | | </form> |
| | |
| | | <form name="myform" action="module_list.php" method="POST"> |
| | | <div class="frmTextHead"><tmpl_var name="list_head_txt"></div><br /> |
| | | <table width="100%" border="0" cellspacing="0" cellpadding="4"> |
| | | <tr> |
| | |
| | | </tr> |
| | | <tmpl_loop name="records"> |
| | | <tr bgcolor="{tmpl_var name="bgcolor"}"> |
| | | <td class="frmText11"><a href="module_show.php?id={tmpl_var name='module'}" class="frmText11">{tmpl_var name="module"}</a></td> |
| | | <td class="frmText11"><a href="module_show.php?id={tmpl_var name='module'}" class="frmText11">{tmpl_var name="title"}</a></td> |
| | | <td class="frmText11"><a href="javascript:loadContent('designer/module_show.php?id={tmpl_var name='module'}');" class="frmText11">{tmpl_var name="module"}</a></td> |
| | | <td class="frmText11"><a href="javascript:loadContent('designer/module_show.php?id={tmpl_var name='module'}');" class="frmText11">{tmpl_var name="title"}</a></td> |
| | | <td class="frmText11" align="right">[<a href="javascript: del_record('module_del.php?id={tmpl_var name='module'}&phpsessid={tmpl_var name='phpsessid'}');" class="frmText11">Delete</a>]</td> |
| | | </tr> |
| | | </tmpl_loop> |
| | |
| | | <td colspan="5" height="40" align="center" class="tblFooter"><tmpl_var name="paging"></td> |
| | | </tr> |
| | | </table> |
| | | </form> |
| | |
| | | <form method="POST" action="module_nav_edit.php">
|
| | | <div class="frmTextHead"><tmpl_var name="header_txt"></div><br />
|
| | | <table width="500" border="0" cellspacing="0" cellpadding="2">
|
| | | <tr>
|
| | |
| | | </tr>
|
| | | <tr>
|
| | | <td> </td>
|
| | | <td><input name="Speichern" type="submit" class="button" value="{tmpl_var name='save_txt'}">
|
| | | <input name="Abbrechen" type="button" class="button" value="{tmpl_var name='cancel_txt'}" onClick="self.location.href='module_list.php';">
|
| | | <td><input name="Speichern" type="button" class="button" value="{tmpl_var name='save_txt'}" onClick="submitForm('pageForm','designer/module_nav_edit.php');"><div class="buttonEnding"></div> |
| | | <input name="Abbrechen" type="button" class="button" value="{tmpl_var name='cancel_txt'}" onClick="loadContent('designer/module_list.php');"><div class="buttonEnding"></div> |
| | | </td>
|
| | | </tr>
|
| | | <tr>
|
| | |
| | | </table>
|
| | | <input type="hidden" name="nav_id" value="{tmpl_var name='nav_id'}">
|
| | | <input type="hidden" name="module_name" value="{tmpl_var name='module_name'}">
|
| | | </form> |
| | |
| | | <form method="POST" action="module_nav_item_edit.php">
|
| | | <div class="frmTextHead"><tmpl_var name="header_txt"></div><br />
|
| | | <table width="500" border="0" cellspacing="0" cellpadding="2">
|
| | | <tr>
|
| | |
| | | </tr>
|
| | | <tr>
|
| | | <td> </td>
|
| | | <td><input name="Speichern" type="submit" class="button" value="{tmpl_var name='save_txt'}">
|
| | | <input name="Abbrechen" type="button" class="button" value="{tmpl_var name='cancel_txt'}" onClick="self.location.href='module_list.php';">
|
| | | <td><input name="Speichern" type="button" class="button" value="{tmpl_var name='save_txt'}" onClick="submitForm('pageForm','designer/module_nav_item_edit.php');"><div class="buttonEnding"></div> |
| | | <input name="Abbrechen" type="button" class="button" value="{tmpl_var name='cancel_txt'}" onClick="loadContent('designer/module_list.php');"><div class="buttonEnding"></div> |
| | | </td>
|
| | | </tr>
|
| | | <tr>
|
| | |
| | | <input type="hidden" name="item_id" value="{tmpl_var name='item_id'}">
|
| | | <input type="hidden" name="nav_id" value="{tmpl_var name='nav_id'}">
|
| | | <input type="hidden" name="module_name" value="{tmpl_var name='module_name'}">
|
| | | </form> |
| | |
| | | <script language="JavaScript">
|
| | | <!--
|
| | | function del_module(link) {
|
| | | if(window.confirm("{tmpl_var name='module_del_txt'}")) {
|
| | | location.href = link;
|
| | | }
|
| | | }
|
| | | function del_menu(link) {
|
| | | if(window.confirm("{tmpl_var name='menu_del_txt'}")) {
|
| | | location.href = link;
|
| | | }
|
| | | }
|
| | | function del_menuitem(link) {
|
| | | if(window.confirm("{tmpl_var name='item_del_txt'}")) {
|
| | | location.href = link;
|
| | | }
|
| | | }
|
| | |
|
| | | //-->
|
| | | </script>
|
| | | <form name="myform" action="module_show.php" method="POST">
|
| | | <div class="frmTextHead"><tmpl_var name="header_txt"></div><br />
|
| | | <fieldset style="width:250px;"><legend class="frmText11"><b>{tmpl_var name='module_txt'}</b></legend>
|
| | | <table border="0" cellspacing="0" cellpadding="2">
|
| | |
| | | </tr>
|
| | | <tr>
|
| | | <td colspan="2" class="frmText11">
|
| | | <input type="button" name="ed1" value="{tmpl_var name='properties_txt'}" onClick="location.href='module_edit.php?id={tmpl_var name='name'}'" class="button" />
|
| | | <input type="button" name="ed2" value="{tmpl_var name='delete_txt'}" onClick="del_module('module_del.php?id={tmpl_var name='name'}');" class="button" />
|
| | | <input type="button" name="ed3" value="{tmpl_var name='new_menu_txt'}" onClick="location.href='module_nav_edit.php?module_name={tmpl_var name='name'}'" class="button" /></td>
|
| | | <input type="button" name="ed1" value="{tmpl_var name='properties_txt'}" onClick="loadContent('designer/module_edit.php?id={tmpl_var name='name'}')" class="button" /><div class="buttonEnding"></div> |
| | | <input type="button" name="ed2" value="{tmpl_var name='delete_txt'}" onClick="del_record('designer/module_del.php?id={tmpl_var name='name'}');" class="button" /><div class="buttonEnding"></div> |
| | | <input type="button" name="ed3" value="{tmpl_var name='new_menu_txt'}" onClick="loadContent('designer/module_nav_edit.php?module_name={tmpl_var name='name'}')" class="button" /><div class="buttonEnding"></div></td> |
| | | </tr>
|
| | | </table>
|
| | | </fieldset>
|
| | |
| | | <td colspan="2" class="frmText11"> </td>
|
| | | </tr>
|
| | | </table>
|
| | | </form> |
| | |
| | | <?php
|
| | | /*
|
| | | Copyright (c) 2005, Till Brehm, Falko Timme, projektfarm Gmbh
|
| | | 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 ISPConfig nor the names of its 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.
|
| | | */
|
| | |
|
| | | $module = array (
|
| | | 'name' => 'dns',
|
| | | 'title' => 'DNS',
|
| | |
| | | $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"])) { |
| | |
| | | $app->tpl->setVar('startpage',$_SESSION["s"]["module"]["startpage"]); |
| | | $app->tpl->setVar('navframe_page',$_SESSION["s"]["module"]["navframe_page"]); |
| | | |
| | | */ |
| | | |
| | | $app->tpl_defaults(); |
| | | $app->tpl->pparse(); |
| | | ?> |
New file |
| | |
| | | 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<items.length;i++) { |
| | | //var oButton = new YAHOO.widget.Button(items[i].id); |
| | | if(items[i].type == 'button') { |
| | | //alert(items[i].id); |
| | | var oButton = new YAHOO.widget.Button(items[i].id); |
| | | oButton.addListener("click",submitLoginForm); |
| | | } |
| | | } |
| | | //var oButton = new YAHOO.widget.Button("submit"); |
| | | */ |
| | | }, |
| | | failure: function(o) { |
| | | alert('Ajax Request was not successful.'); |
| | | } |
| | | } |
| | | |
| | | var pageContentObject = YAHOO.util.Connect.asyncRequest('GET', 'content.php?s_mod=login&s_pg=index', pageContentCallback); |
| | | |
| | | loadMenus(); |
| | | |
| | | } |
| | | |
| | | function loadMenus() { |
| | | |
| | | var sideNavCallback = { |
| | | success: function(o) { |
| | | document.getElementById('sideNav').innerHTML = o.responseText; |
| | | }, |
| | | failure: function(o) { |
| | | alert('Ajax Request was not successful.'); |
| | | } |
| | | } |
| | | |
| | | var sideNavObject = YAHOO.util.Connect.asyncRequest('GET', 'nav.php?nav=side', sideNavCallback); |
| | | |
| | | var topNavCallback = { |
| | | success: function(o) { |
| | | document.getElementById('topNav').innerHTML = o.responseText; |
| | | }, |
| | | failure: function(o) { |
| | | alert('Ajax Request was not successful.'); |
| | | } |
| | | } |
| | | |
| | | var topNavObject = YAHOO.util.Connect.asyncRequest('GET', 'nav.php?nav=top', topNavCallback); |
| | | |
| | | } |
| | | |
| | | function changeTab(tab,target) { |
| | | //document.forms[0].next_tab.value = tab; |
| | | document.pageForm.next_tab.value = tab; |
| | | submitForm('pageForm',target); |
| | | } |
| | | |
| | | |
| | | |
| | | function reportError(request) |
| | | { |
| | | alert('Sorry. There was an error.'); |
| | | } |
| | | |
| | | function del_record(link) { |
| | | if(window.confirm("<tmpl_var name='delete_confirmation'>")) { |
| | | loadContent(link); |
| | | } |
| | | } |
New file |
| | |
| | | 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 |
| | | |
| | | |
New file |
| | |
| | | /* |
| | | 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. |
| | | * <p>Usage: var myAnim = new YAHOO.util.Anim(el, { width: { from: 10, to: 100 } }, 1, YAHOO.util.Easing.easeOut);</p> |
| | | * @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. |
| | | * <p>Usage: <code>var myAnim = new Y.ColorAnim(el, { backgroundColor: { from: '#FF0000', to: '#FFFFFF' } }, 1, Y.Easing.easeOut);</code> Color values can be specified with either 112233, #112233, |
| | | * [255,255,255], or rgb(255,255,255)</p> |
| | | * @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. |
| | | * <p>Usage: <code>var myAnim = new YAHOO.util.Motion(el, { points: { to: [800, 800] } }, 1, YAHOO.util.Easing.easeOut);</code></p> |
| | | * @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. |
| | | * <p>Usage: <code>var myAnim = new YAHOO.util.Scroll(el, { scroll: { to: [0, 800] } }, 1, YAHOO.util.Easing.easeOut);</code></p> |
| | | * @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"}); |
New file |
| | |
| | | /* |
| | | 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;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;this.runtimeAttributes[attr].unit=(isset(attributes[attr].unit))?attributes[attr]['unit']:this.getDefaultUnit(attr);},init:function(el,attributes,duration,method){var isAnimated=false;var startTime=null;var actualFrames=0;el=YAHOO.util.Dom.get(el);this.attributes=attributes||{};this.duration=duration||1;this.method=method||YAHOO.util.Easing.easeNone;this.useSeconds=true;this.currentFrame=0;this.totalFrames=YAHOO.util.AnimMgr.fps;this.getEl=function(){return el;};this.isAnimated=function(){return isAnimated;};this.getStartTime=function(){return startTime;};this.runtimeAttributes={};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);};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();};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);};this._onStart=new YAHOO.util.CustomEvent('_start',this,true);this.onStart=new YAHOO.util.CustomEvent('start',this);this.onTween=new YAHOO.util.CustomEvent('tween',this);this._onTween=new YAHOO.util.CustomEvent('_tween',this,true);this.onComplete=new YAHOO.util.CustomEvent('complete',this);this._onComplete=new YAHOO.util.CustomEvent('_complete',this,true);this._onStart.subscribe(onStart);this._onTween.subscribe(onTween);this._onComplete.subscribe(onComplete);}};YAHOO.util.AnimMgr=new function(){var thread=null;var queue=[];var tweenCount=0;this.fps=1000;this.delay=1;this.registerElement=function(tween){queue[queue.length]=tween;tweenCount+=1;tween._onStart.fire();this.start();};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();}};this.start=function(){if(thread===null){thread=setInterval(this.run,this.delay);}};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);}};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;}} |
| | | return-1;};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){tweak=Math.round((elapsed/expected-1)*tween.currentFrame);}else{tweak=frames-(frame+1);} |
| | | if(tweak>0&&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;i<n;++i){tmp[i]=[points[i][0],points[i][1]];} |
| | | 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(){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);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\)$/;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)){var parent=el.parentNode;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);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;}};})();YAHOO.util.Easing={easeNone:function(t,b,c,d){return c*t/d+b;},easeIn:function(t,b,c,d){return c*(t/=d)*t+b;},easeOut:function(t,b,c,d){return-c*(t/=d)*(t-2)+b;},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;},easeInStrong:function(t,b,c,d){return c*(t/=d)*t*t*t+b;},easeOutStrong:function(t,b,c,d){return-c*((t=t/d-1)*t*t*t-1)+b;},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;},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;},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;},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;},backIn:function(t,b,c,d,s){if(typeof s=='undefined'){s=1.70158;} |
| | | return c*(t/=d)*t*((s+1)*t-s)+b;},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;},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;},bounceIn:function(t,b,c,d){return c-YAHOO.util.Easing.bounceOut(d-t,0,c,d)+b;},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;},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(){YAHOO.util.Motion=function(el,attributes,duration,method){if(el){YAHOO.util.Motion.superclass.constructor.call(this,el,attributes,duration,method);}};YAHOO.extend(YAHOO.util.Motion,YAHOO.util.ColorAnim);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)){control=[control];}else{var tmp=[];for(i=0,len=control.length;i<len;++i){tmp[i]=control[i];} |
| | | control=tmp;} |
| | | if(Y.Dom.getStyle(el,'position')=='static'){Y.Dom.setStyle(el,'position','relative');} |
| | | if(isset(attributes['points']['from'])){Y.Dom.setXY(el,attributes['points']['from']);} |
| | | else{Y.Dom.setXY(el,Y.Dom.getXY(el));} |
| | | start=this.getAttribute('points');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(){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"}); |
New file |
| | |
| | | /* |
| | | 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. |
| | | * <p>Usage: var myAnim = new YAHOO.util.Anim(el, { width: { from: 10, to: 100 } }, 1, YAHOO.util.Easing.easeOut);</p> |
| | | * @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. |
| | | * <p>Usage: <code>var myAnim = new Y.ColorAnim(el, { backgroundColor: { from: '#FF0000', to: '#FFFFFF' } }, 1, Y.Easing.easeOut);</code> Color values can be specified with either 112233, #112233, |
| | | * [255,255,255], or rgb(255,255,255)</p> |
| | | * @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. |
| | | * <p>Usage: <code>var myAnim = new YAHOO.util.Motion(el, { points: { to: [800, 800] } }, 1, YAHOO.util.Easing.easeOut);</code></p> |
| | | * @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. |
| | | * <p>Usage: <code>var myAnim = new YAHOO.util.Scroll(el, { scroll: { to: [0, 800] } }, 1, YAHOO.util.Easing.easeOut);</code></p> |
| | | * @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"}); |
New file |
| | |
| | | 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. |
New file |
| | |
| | | /* |
| | | 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: |
| | | * <ul> |
| | | * <li>Navigate with up/down arrow keys and/or mouse to pick a selection</li> |
| | | * <li>The drop down container can "roll down" or "fly out" via configurable |
| | | * animation</li> |
| | | * <li>UI look-and-feel customizable through CSS, including container |
| | | * attributes, borders, position, fonts, etc</li> |
| | | * </ul> |
| | | * |
| | | * @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<this.maxResultsDisplayed; i++) { |
| | | var oItem = document.createElement("li"); |
| | | oItem = oList.appendChild(oItem); |
| | | this._aListItems[i] = oItem; |
| | | this._initListItem(oItem, i); |
| | | } |
| | | this._maxResultsDisplayed = this.maxResultsDisplayed; |
| | | }; |
| | | |
| | | /** |
| | | * Initializes each <li> element in the container list. |
| | | * |
| | | * @method _initListItem |
| | | * @param oItem {HTMLElement} The <li> DOM element. |
| | | * @param nItemIndex {Number} The index of the element. |
| | | * @private |
| | | */ |
| | | YAHOO.widget.AutoComplete.prototype._initListItem = function(oItem, nItemIndex) { |
| | | var oSelf = this; |
| | | oItem.style.display = "none"; |
| | | oItem._nItemIndex = nItemIndex; |
| | | |
| | | oItem.mouseover = oItem.mouseout = oItem.onclick = null; |
| | | YAHOO.util.Event.addListener(oItem,"mouseover",oSelf._onItemMouseover,oSelf); |
| | | YAHOO.util.Event.addListener(oItem,"mouseout",oSelf._onItemMouseout,oSelf); |
| | | YAHOO.util.Event.addListener(oItem,"click",oSelf._onItemMouseclick,oSelf); |
| | | }; |
| | | |
| | | /** |
| | | * Enables interval detection for Korean IME support. |
| | | * |
| | | * @method _onIMEDetected |
| | | * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. |
| | | * @private |
| | | */ |
| | | YAHOO.widget.AutoComplete.prototype._onIMEDetected = function(oSelf) { |
| | | oSelf._enableIntervalDetection(); |
| | | }; |
| | | |
| | | /** |
| | | * Enables query triggers based on text input detection by intervals (rather |
| | | * than by key events). |
| | | * |
| | | * @method _enableIntervalDetection |
| | | * @private |
| | | */ |
| | | YAHOO.widget.AutoComplete.prototype._enableIntervalDetection = function() { |
| | | var currValue = this._oTextbox.value; |
| | | var lastValue = this._sLastTextboxValue; |
| | | if(currValue != lastValue) { |
| | | this._sLastTextboxValue = currValue; |
| | | this._sendQuery(currValue); |
| | | } |
| | | }; |
| | | |
| | | |
| | | /** |
| | | * Cancels text input detection by intervals. |
| | | * |
| | | * @method _cancelIntervalDetection |
| | | * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. |
| | | * @private |
| | | */ |
| | | YAHOO.widget.AutoComplete.prototype._cancelIntervalDetection = function(oSelf) { |
| | | if(oSelf._queryInterval) { |
| | | clearInterval(oSelf._queryInterval); |
| | | } |
| | | }; |
| | | |
| | | |
| | | /** |
| | | * Whether or not key is functional or should be ignored. Note that the right |
| | | * arrow key is NOT an ignored key since it triggers queries for certain intl |
| | | * charsets. |
| | | * |
| | | * @method _isIgnoreKey |
| | | * @param nKeycode {Number} Code of key pressed. |
| | | * @return {Boolean} True if key should be ignored, false otherwise. |
| | | * @private |
| | | */ |
| | | YAHOO.widget.AutoComplete.prototype._isIgnoreKey = function(nKeyCode) { |
| | | if ((nKeyCode == 9) || (nKeyCode == 13) || // tab, enter |
| | | (nKeyCode == 16) || (nKeyCode == 17) || // shift, ctl |
| | | (nKeyCode >= 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<!-"; |
| | | |
| | | ///////////////////////////////////////////////////////////////////////////// |
| | | // |
| | | // Public methods |
| | | // |
| | | ///////////////////////////////////////////////////////////////////////////// |
| | | |
| | | /** |
| | | * Queries the live data source defined by scriptURI 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_XHR.prototype.doQuery = function(oCallbackFn, sQuery, oParent) { |
| | | var isXML = (this.responseType == YAHOO.widget.DS_XHR.TYPE_XML); |
| | | var sUri = this.scriptURI+"?"+this.scriptQueryParam+"="+sQuery; |
| | | if(this.scriptQueryAppend.length > 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"}); |
New file |
| | |
| | | /* |
| | | 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<this.maxResultsDisplayed;i++){var oItem=document.createElement("li");oItem=oList.appendChild(oItem);this._aListItems[i]=oItem;this._initListItem(oItem,i);} |
| | | this._maxResultsDisplayed=this.maxResultsDisplayed;};YAHOO.widget.AutoComplete.prototype._initListItem=function(oItem,nItemIndex){var oSelf=this;oItem.style.display="none";oItem._nItemIndex=nItemIndex;oItem.mouseover=oItem.mouseout=oItem.onclick=null;YAHOO.util.Event.addListener(oItem,"mouseover",oSelf._onItemMouseover,oSelf);YAHOO.util.Event.addListener(oItem,"mouseout",oSelf._onItemMouseout,oSelf);YAHOO.util.Event.addListener(oItem,"click",oSelf._onItemMouseclick,oSelf);};YAHOO.widget.AutoComplete.prototype._onIMEDetected=function(oSelf){oSelf._enableIntervalDetection();};YAHOO.widget.AutoComplete.prototype._enableIntervalDetection=function(){var currValue=this._oTextbox.value;var lastValue=this._sLastTextboxValue;if(currValue!=lastValue){this._sLastTextboxValue=currValue;this._sendQuery(currValue);}};YAHOO.widget.AutoComplete.prototype._cancelIntervalDetection=function(oSelf){if(oSelf._queryInterval){clearInterval(oSelf._queryInterval);}};YAHOO.widget.AutoComplete.prototype._isIgnoreKey=function(nKeyCode){if((nKeyCode==9)||(nKeyCode==13)||(nKeyCode==16)||(nKeyCode==17)||(nKeyCode>=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.length<this.minQueryLength)||(!sQuery&&this.minQueryLength>0)){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<this._nDisplayedItems)){if(nKeyCode==40){if((oNewItem.offsetTop+oNewItem.offsetHeight)>(oContent.scrollTop+oContent.offsetHeight)){oContent.scrollTop=(oNewItem.offsetTop+oNewItem.offsetHeight)-oContent.offsetHeight;} |
| | | else if((oNewItem.offsetTop+oNewItem.offsetHeight)<oContent.scrollTop){oContent.scrollTop=oNewItem.offsetTop;}} |
| | | else{if(oNewItem.offsetTop<oContent.scrollTop){this._oContainer._oContent.scrollTop=oNewItem.offsetTop;} |
| | | else if(oNewItem.offsetTop>(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="\n<!-";YAHOO.widget.DS_XHR.prototype.doQuery=function(oCallbackFn,sQuery,oParent){var isXML=(this.responseType==YAHOO.widget.DS_XHR.TYPE_XML);var sUri=this.scriptURI+"?"+this.scriptQueryParam+"="+sQuery;if(this.scriptQueryAppend.length>0){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"}); |
New file |
| | |
| | | /* |
| | | 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: |
| | | * <ul> |
| | | * <li>Navigate with up/down arrow keys and/or mouse to pick a selection</li> |
| | | * <li>The drop down container can "roll down" or "fly out" via configurable |
| | | * animation</li> |
| | | * <li>UI look-and-feel customizable through CSS, including container |
| | | * attributes, borders, position, fonts, etc</li> |
| | | * </ul> |
| | | * |
| | | * @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<this.maxResultsDisplayed; i++) { |
| | | var oItem = document.createElement("li"); |
| | | oItem = oList.appendChild(oItem); |
| | | this._aListItems[i] = oItem; |
| | | this._initListItem(oItem, i); |
| | | } |
| | | this._maxResultsDisplayed = this.maxResultsDisplayed; |
| | | }; |
| | | |
| | | /** |
| | | * Initializes each <li> element in the container list. |
| | | * |
| | | * @method _initListItem |
| | | * @param oItem {HTMLElement} The <li> DOM element. |
| | | * @param nItemIndex {Number} The index of the element. |
| | | * @private |
| | | */ |
| | | YAHOO.widget.AutoComplete.prototype._initListItem = function(oItem, nItemIndex) { |
| | | var oSelf = this; |
| | | oItem.style.display = "none"; |
| | | oItem._nItemIndex = nItemIndex; |
| | | |
| | | oItem.mouseover = oItem.mouseout = oItem.onclick = null; |
| | | YAHOO.util.Event.addListener(oItem,"mouseover",oSelf._onItemMouseover,oSelf); |
| | | YAHOO.util.Event.addListener(oItem,"mouseout",oSelf._onItemMouseout,oSelf); |
| | | YAHOO.util.Event.addListener(oItem,"click",oSelf._onItemMouseclick,oSelf); |
| | | }; |
| | | |
| | | /** |
| | | * Enables interval detection for Korean IME support. |
| | | * |
| | | * @method _onIMEDetected |
| | | * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. |
| | | * @private |
| | | */ |
| | | YAHOO.widget.AutoComplete.prototype._onIMEDetected = function(oSelf) { |
| | | oSelf._enableIntervalDetection(); |
| | | }; |
| | | |
| | | /** |
| | | * Enables query triggers based on text input detection by intervals (rather |
| | | * than by key events). |
| | | * |
| | | * @method _enableIntervalDetection |
| | | * @private |
| | | */ |
| | | YAHOO.widget.AutoComplete.prototype._enableIntervalDetection = function() { |
| | | var currValue = this._oTextbox.value; |
| | | var lastValue = this._sLastTextboxValue; |
| | | if(currValue != lastValue) { |
| | | this._sLastTextboxValue = currValue; |
| | | this._sendQuery(currValue); |
| | | } |
| | | }; |
| | | |
| | | |
| | | /** |
| | | * Cancels text input detection by intervals. |
| | | * |
| | | * @method _cancelIntervalDetection |
| | | * @param oSelf {YAHOO.widget.AutoComplete} The AutoComplete instance. |
| | | * @private |
| | | */ |
| | | YAHOO.widget.AutoComplete.prototype._cancelIntervalDetection = function(oSelf) { |
| | | if(oSelf._queryInterval) { |
| | | clearInterval(oSelf._queryInterval); |
| | | } |
| | | }; |
| | | |
| | | |
| | | /** |
| | | * Whether or not key is functional or should be ignored. Note that the right |
| | | * arrow key is NOT an ignored key since it triggers queries for certain intl |
| | | * charsets. |
| | | * |
| | | * @method _isIgnoreKey |
| | | * @param nKeycode {Number} Code of key pressed. |
| | | * @return {Boolean} True if key should be ignored, false otherwise. |
| | | * @private |
| | | */ |
| | | YAHOO.widget.AutoComplete.prototype._isIgnoreKey = function(nKeyCode) { |
| | | if ((nKeyCode == 9) || (nKeyCode == 13) || // tab, enter |
| | | (nKeyCode == 16) || (nKeyCode == 17) || // shift, ctl |
| | | (nKeyCode >= 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<!-"; |
| | | |
| | | ///////////////////////////////////////////////////////////////////////////// |
| | | // |
| | | // Public methods |
| | | // |
| | | ///////////////////////////////////////////////////////////////////////////// |
| | | |
| | | /** |
| | | * Queries the live data source defined by scriptURI 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_XHR.prototype.doQuery = function(oCallbackFn, sQuery, oParent) { |
| | | var isXML = (this.responseType == YAHOO.widget.DS_XHR.TYPE_XML); |
| | | var sUri = this.scriptURI+"?"+this.scriptQueryParam+"="+sQuery; |
| | | if(this.scriptQueryAppend.length > 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"}); |
New file |
| | |
| | | *** Version 2.2.0 *** |
| | | |
| | | * Button Control introduced |
New file |
| | |
| | | /* |
| | | 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; |
| | | |
| | | } |
New file |
| | |
| | | /* |
| | | 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 |
| | | */ |
| | | |
| | | (function(){var Dom=YAHOO.util.Dom,Event=YAHOO.util.Event,Lang=YAHOO.lang,m_oButtons={},m_oFocusedButton=null;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();} |
| | | 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();} |
| | | oConfig.attributes.srcelement=this;initConfig.call(me,oConfig);if(!oConfig.element){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();}} |
| | | else if(sTagName=="INPUT"&&!oConfig.attributes.id){oConfig.attributes.id=Dom.generateId();} |
| | | oConfig.attributes.srcelement=p_oElement;initConfig.call(this,oConfig);if(!oConfig.element){oConfig.element=this._createButtonElement(oConfig.attributes.type);} |
| | | fnSuperClass.call(this,oConfig.element,oConfig.attributes);}}};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;}}}} |
| | | function createInputElement(p_sType,p_sName,p_sValue,p_bChecked){var oInput;if(navigator.userAgent.indexOf("MSIE")!=-1){var sInput="<input type=\""+p_sType+"\" name=\""+p_sName+"\"";if(p_bChecked){sInput+=" checked";} |
| | | sInput+=">";oInput=document.createElement(sInput);} |
| | | else{oInput=document.createElement("input");oInput.name=p_sName;oInput.type=p_sType;if(p_bChecked){oInput.checked=true;}} |
| | | oInput.value=p_sValue;return oInput;} |
| | | function setAttributesFromSrcElement(p_oElement,p_oAttributes){var me=this;function setAttributeFromDOMAttribute(p_sAttribute){if(!(p_sAttribute in p_oAttributes)){var oAttribute=p_oElement.getAttributeNode(p_sAttribute);if(oAttribute&&("value"in oAttribute)){p_oAttributes[p_sAttribute]=oAttribute.value;}}} |
| | | 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)){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;}} |
| | | 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,{_button:null,_menu:null,_onclickAttributeValue:null,_oninitAttributeValue:null,_activationKeyPressed:false,_activationButtonPressed:false,_hasKeyEventHandlers:false,_hasMouseEventHandlers:false,TAG_NAME:"SPAN",CHECK_ACTIVATION_KEYS:[32],ACTIVATION_KEYS:[13,32],OPTION_AREA_WIDTH:20,CSS_CLASS_NAME:"yuibutton",RADIO_DEFAULT_TITLE:"Unchecked. Click to check.",RADIO_CHECKED_TITLE:"Checked. Click to uncheck.",CHECKBOX_DEFAULT_TITLE:"Unchecked. Click to check.",CHECKBOX_CHECKED_TITLE:"Checked. Click to uncheck.",MENUBUTTON_DEFAULT_TITLE:"Menu collapsed. Click to expand.",MENUBUTTON_MENU_VISIBLE_TITLE:"Menu expanded. Click or press Esc to collapse.",SPLITBUTTON_DEFAULT_TITLE:"Menu collapsed. Click inside option region or press Ctrl + Shift + M to show the menu.",SPLITBUTTON_OPTION_VISIBLE_TITLE:"Menu expanded. Press Esc or Ctrl + Shift + M to hide the menu.",SUBMIT_TITLE:"Click to submit form.",_setType:function(p_sType){if(p_sType=="splitbutton"){this.on("option",this._onOption);}},_setLabel:function(p_sLabel){this._button.innerHTML=p_sLabel;},_setTabIndex:function(p_nTabIndex){this._button.tabIndex=p_nTabIndex;},_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;}},_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");}}},_setAccessKey:function(p_sAccessKey){this._button.accessKey=p_sAccessKey;},_setHref:function(p_sHref){if(this.get("type")=="link"){this._button.href=p_sHref;}},_setTarget:function(p_sTarget){if(this.get("type")=="link"){this._button.setAttribute("target",p_sTarget);}},_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);}},_setMenu:function(p_oMenu){var Menu=YAHOO.widget.Menu,oMenu,me=this;if(!Menu){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);}},_setOnClick:function(p_oObject){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;}},_setOnInit:function(p_oObject){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;}},_createButtonElement:function(p_sType){var sTagName=this.TAG_NAME,oElement=document.createElement(sTagName);oElement.innerHTML="<"+sTagName+" class=\"first-child\">"+ |
| | | (p_sType=="link"?"<a></a>":"<button type=\"button\"></button>")+"</"+sTagName+">";return oElement;},_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--);}},_isSplitButtonOptionKey:function(p_oEvent){return(p_oEvent.ctrlKey&&p_oEvent.shiftKey&&Event.getCharCode(p_oEvent)==77);},_originalMaxHeight:-1,_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){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);}},_hideMenu:function(){var oMenu=this._menu;if(oMenu&&oMenu.cfg.getProperty("visible")){oMenu.hide();}},_submitForm:function(){var oForm=this.getForm();if(oForm){YAHOO.widget.Button.addHiddenFieldsToForm(oForm);this.createHiddenField();oForm.submit();}},_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");}}},_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);}}},_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);},_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);}}}},_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");}}},_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);}},_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);}},_onDocumentKeyUp:function(p_oEvent,p_oButton){if(this._isActivationKey(Event.getCharCode(p_oEvent))){this._activationKeyPressed=false;Event.removeListener(document,"keyup",this._onDocumentKeyUp);}},_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();}}},_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");}}}},_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;}},_onAppendTo:function(p_oEvent){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);},_onFormSubmit:function(p_oEvent,p_oButton){var sType=this.get("type"),oMenuItem=this.get("selectedMenuItem"),oForm=this.getForm();if(sType=="radio"||sType=="checkbox"){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);}}}},_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");}},_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);}},_onOption:function(p_oEvent){if(this.hasClass("activeoption")){this._hideMenu();this._bOptionPressed=false;} |
| | | else{this._showMenu();this._bOptionPressed=true;}},_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);},_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);},_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;}}},_onMenuRender:function(p_sType,p_aArgs,p_oButton){this.get("element").parentNode.appendChild(this._menu.element);},_onMenuItemSelected:function(p_sType,p_aArgs,p_oItem){this.set("selectedMenuItem",p_oItem);},_onMenuItemAdded:function(p_sType,p_aArgs,p_oItem){var oItem=p_aArgs[0];oItem.cfg.subscribeToConfigEvent("selected",this._onMenuItemSelected,oItem,this);},_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();}},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;}},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");},initAttributes:function(p_oAttributes){var oAttributes=p_oAttributes||{};YAHOO.widget.Button.superclass.initAttributes.call(this,oAttributes);this.setAttributeConfig("type",{value:(oAttributes.type||"button"),validator:Lang.isString,writeOnce:true,method:this._setType});this.setAttributeConfig("label",{value:oAttributes.label,validator:Lang.isString,method:this._setLabel});this.setAttributeConfig("value",{value:oAttributes.value});this.setAttributeConfig("name",{value:oAttributes.name,validator:Lang.isString});this.setAttributeConfig("tabindex",{value:oAttributes.tabindex,validator:Lang.isNumber,method:this._setTabIndex});this.configureAttribute("title",{value:oAttributes.title,validator:Lang.isString,method:this._setTitle});this.setAttributeConfig("disabled",{value:(oAttributes.disabled||false),validator:Lang.isBoolean,method:this._setDisabled});this.setAttributeConfig("href",{value:oAttributes.href,validator:Lang.isString,method:this._setHref});this.setAttributeConfig("target",{value:oAttributes.target,validator:Lang.isString,method:this._setTarget});this.setAttributeConfig("checked",{value:(oAttributes.checked||false),validator:Lang.isBoolean,method:this._setChecked});this.setAttributeConfig("container",{value:oAttributes.container});this.setAttributeConfig("srcelement",{value:oAttributes.srcelement,writeOnce:true});this.setAttributeConfig("menu",{value:null,method:this._setMenu});this.setAttributeConfig("selectedMenuItem",{value:null});this.setAttributeConfig("onclick",{value:oAttributes.onclick,method:this._setOnClick});this.setAttributeConfig("oninit",{value:oAttributes.oninit,method:this._setOnInit});},focus:function(){if(!this.get("disabled")){this._button.focus();}},blur:function(){if(!this.get("disabled")){this._button.blur();}},hasFocus:function(){return(m_oFocusedButton==this);},isActive:function(){return this.hasClass("active");},getMenu:function(){return this._menu;},getForm:function(){return this._button.form;},destroy:function(){var oElement=this.get("element"),oParentNode=oElement.parentNode,oMenu=this._menu;if(oMenu){oMenu.destroy();} |
| | | 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);delete m_oButtons[this.get("id")];},toString:function(){return("Button "+this.get("id"));}});YAHOO.widget.Button.addHiddenFieldsToForm=function(p_oForm){var aButtons=Dom.getElementsByClassName("yuibutton","*",p_oForm),nButtons=aButtons.length;if(nButtons>0){var oButton=null,sType=null,oMenuItem=null,oMenu=null;for(var i=0;i<nButtons;i++){oButton=m_oButtons[aButtons[i].id];if(oButton){sType=oButton.get("type");oMenuItem=oButton.get("selectedMenuItem");if(sType=="radio"||sType=="checkbox"){oButton.createHiddenField();} |
| | | else if(oMenuItem){oMenu=oButton.getMenu();var oSrcElement=oMenu.srcElement;if(oSrcElement&&oSrcElement.tagName.toUpperCase()=="SELECT"){oButton.getForm().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",(oButton.get("name")+"_options"),oValue);oButton.getForm().appendChild(oField);}}}}}}};})();(function(){var Dom=YAHOO.util.Dom,Event=YAHOO.util.Event,Lang=YAHOO.lang,Button=YAHOO.widget.Button;m_oButtons={};YAHOO.widget.ButtonGroup=function(p_oElement,p_oAttributes){var fnSuperClass=YAHOO.widget.ButtonGroup.superclass.constructor;if(arguments.length==1&&!Lang.isString(p_oElement)&&!p_oElement.nodeName){if(!p_oElement.id){var sId=Dom.generateId();p_oElement.id=sId;} |
| | | fnSuperClass.call(this,(this._createGroupElement()),p_oElement);} |
| | | else if(Lang.isString(p_oElement)){var me=this;Event.onContentReady(p_oElement,function(){if(this.nodeName.toUpperCase()==me.TAG_NAME){fnSuperClass.call(me,this,p_oAttributes);}});} |
| | | else{var sNodeName=p_oElement.nodeName;if(sNodeName&&sNodeName==this.TAG_NAME){if(!p_oElement.id){p_oElement.id=Dom.generateId();} |
| | | fnSuperClass.call(this,p_oElement,p_oAttributes);}}};YAHOO.extend(YAHOO.widget.ButtonGroup,YAHOO.util.Element,{_buttons:null,_oninitAttributeValue:null,TAG_NAME:"DIV",CSS_CLASS_NAME:"yuibuttongroup",_createGroupElement:function(){var oElement=document.createElement(this.TAG_NAME);oElement.className=this.CSS_CLASS_NAME;return oElement;},_setDisabled:function(p_bDisabled){var nButtons=this.getCount();if(nButtons>0){var i=nButtons-1;do{this._buttons[i].set("disabled",p_bDisabled);} |
| | | while(i--);}},_setOnInit:function(p_oObject){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;}},_onKeyDown:function(p_oEvent){var oTarget=Event.getTarget(p_oEvent),nCharCode=Event.getCharCode(p_oEvent),sId=oTarget.parentNode.parentNode.id,oButton=m_oButtons[sId],nIndex=-1;if(nCharCode==37||nCharCode==38){nIndex=(oButton.index===0)?(this._buttons.length-1):(oButton.index-1);} |
| | | else if(nCharCode==39||nCharCode==40){nIndex=(oButton.index===(this._buttons.length-1))?0:(oButton.index+1);} |
| | | if(nIndex>-1){this.check(nIndex);this.getButton(nIndex).focus();}},_onAppendTo:function(p_oEvent){var aButtons=this._buttons,nButtons=aButtons.length;for(var i=0;i<nButtons;i++){aButtons[i].appendTo(this.get("element"));}},_onButtonCheckedChange:function(p_oEvent,p_oButton){var bChecked=p_oEvent.newValue,oCheckedButton=this.get("checkedButton");if(bChecked&&oCheckedButton!=p_oButton){if(oCheckedButton){oCheckedButton.set("checked",false,true);} |
| | | this.set("checkedButton",p_oButton);this.set("value",p_oButton.get("value"));} |
| | | else if(oCheckedButton&&!oCheckedButton.set("checked")){oCheckedButton.set("checked",true,true);}},init:function(p_oElement,p_oAttributes){this._buttons=[];YAHOO.widget.ButtonGroup.superclass.init.call(this,p_oElement,p_oAttributes);var aButtons=this.getElementsByClassName("yuibutton");if(aButtons.length>0){this.addButtons(aButtons);} |
| | | function isRadioButton(p_oElement){return(p_oElement.type=="radio");} |
| | | aButtons=Dom.getElementsBy(isRadioButton,"input",this.get("element"));if(aButtons.length>0){this.addButtons(aButtons);} |
| | | this.on("keydown",this._onKeyDown);this.on("appendTo",this._onAppendTo);var oContainer=this.get("container");if(oContainer){if(Lang.isString(oContainer)){var me=this;Event.onContentReady(oContainer,function(){me.appendTo(this);});} |
| | | else{this.appendTo(oContainer);}} |
| | | this.fireEvent("init");},initAttributes:function(p_oAttributes){var oAttributes=p_oAttributes||{};YAHOO.widget.ButtonGroup.superclass.initAttributes.call(this,oAttributes);this.setAttributeConfig("name",{value:oAttributes.name,validator:Lang.isString});this.setAttributeConfig("disabled",{value:(oAttributes.disabled||false),validator:Lang.isBoolean,method:this._setDisabled});this.setAttributeConfig("value",{value:oAttributes.value});this.setAttributeConfig("container",{value:oAttributes.container});this.setAttributeConfig("checkedButton",{value:null});this.setAttributeConfig("oninit",{value:oAttributes.oninit,method:this._setOnInit});},addButton:function(p_oButton){var oButton;if(p_oButton instanceof Button&&p_oButton.get("type")=="radio"){oButton=p_oButton;} |
| | | else if(!Lang.isString(p_oButton)&&!p_oButton.nodeName){p_oButton.type="radio";oButton=new Button(p_oButton);} |
| | | else{oButton=new Button(p_oButton,{type:"radio"});} |
| | | if(oButton){var nIndex=this._buttons.length,sButtonName=oButton.get("name"),sGroupName=this.get("name");oButton.index=nIndex;this._buttons[nIndex]=oButton;m_oButtons[oButton.get("id")]=oButton;if(sButtonName!=sGroupName){oButton.set("name",sGroupName);} |
| | | if(this.get("disabled")){oButton.set("disabled",true);} |
| | | if(oButton.get("checked")){this.set("checkedButton",oButton);} |
| | | oButton.on("checkedChange",this._onButtonCheckedChange,oButton,this);return oButton;}},addButtons:function(p_aButtons){if(Lang.isArray(p_aButtons)){var nButtons=p_aButtons.length,oButton,aButtons=[];if(nButtons>0){for(var i=0;i<nButtons;i++){oButton=this.addButton(p_aButtons[i]);if(oButton){aButtons[aButtons.length]=oButton;}} |
| | | if(aButtons.length>0){return aButtons;}}}},removeButton:function(p_nIndex){var oButton=this.getButton(p_nIndex);if(oButton){this._buttons.splice(p_nIndex,1);delete m_oButtons[oButton.get("id")];oButton.removeListener("checkedChange",this._onButtonCheckedChange);oButton.destroy();var nButtons=this._buttons.length;if(nButtons>0){var i=this._buttons.length-1;do{this._buttons[i].index=i;} |
| | | while(i--);}}},getButton:function(p_nIndex){if(Lang.isNumber(p_nIndex)){return this._buttons[p_nIndex];}},getButtons:function(){return this._buttons;},getCount:function(){return this._buttons.length;},focus:function(p_nIndex){var oButton;if(Lang.isNumber(p_nIndex)){oButton=this._buttons[p_nIndex];if(oButton){oButton.focus();}} |
| | | else{var nButtons=this.getCount();for(var i=0;i<nButtons;i++){oButton=this._buttons[i];if(!oButton.get("disabled")){oButton.focus();break;}}}},check:function(p_nIndex){var oButton=this.getButton(p_nIndex);if(oButton){oButton.set("checked",true);}},destroy:function(){var nButtons=this._buttons.length,oElement=this.get("element"),oParentNode=oElement.parentNode;if(nButtons>0){var i=this._buttons.length-1;do{this._buttons[i].destroy();} |
| | | while(i--);} |
| | | Event.purgeElement(oElement);oParentNode.removeChild(oElement);},toString:function(){return("ButtonGroup "+this.get("id"));}});})();YAHOO.register("button",YAHOO.widget.Button,{version:"2.2.0",build:"127"}); |
New file |
| | |
| | | /* |
| | | 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 <p>The Button Control enables the creation of rich, graphical |
| | | * buttons that function like traditional HTML form buttons. <em>Unlike</em> |
| | | * 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 |
| | | * <a href="module_menu.html">Menu Control</a>, 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.</p> |
| | | * <p>The Button Control supports the following types:</p> |
| | | * <dl> |
| | | * <dt>button</dt> |
| | | * <dd>Basic push button that can execute a user-specified command when |
| | | * pressed.</dd> |
| | | * <dt>link</dt> |
| | | * <dd>Navigates to a specified url when pressed.</dd> |
| | | * <dt>submit</dt> |
| | | * <dd>Submits the parent form when pressed.</dd> |
| | | * <dt>reset</dt> |
| | | * <dd>Resets the parent form when pressed.</dd> |
| | | * <dt>checkbox</dt> |
| | | * <dd>Maintains a "checked" state that can be toggled on and off.</dd> |
| | | * <dt>radio</dt> |
| | | * <dd>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.</dd> |
| | | * <dt>menubutton</dt> |
| | | * <dd>When pressed will show/hide a menu.</dd> |
| | | * <dt>splitbutton</dt> |
| | | * <dd>Can execute a user-specified command or display a menu when pressed.</dd> |
| | | * </dl> |
| | | * @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 |
| | | * <code><input></code>, <code><a></code> or |
| | | * <code><span></code> element to be used to create the button. |
| | | * @param {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level- |
| | | * one-html.html#ID-6043025">HTMLInputElement</a>|<a href=" |
| | | * http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html# |
| | | * ID-33759296">HTMLElement</a>} p_oElement Object reference for the |
| | | * <code><input></code>, <code><a></code> or |
| | | * <code><span></code> 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(); |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | 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(); |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | oConfig.attributes.srcelement = this; |
| | | |
| | | initConfig.call(me, oConfig); |
| | | |
| | | |
| | | if(!oConfig.element) { |
| | | |
| | | |
| | | 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(); |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | else if(sTagName == "INPUT" && !oConfig.attributes.id) { |
| | | |
| | | oConfig.attributes.id = Dom.generateId(); |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | oConfig.attributes.srcelement = p_oElement; |
| | | |
| | | initConfig.call(this, oConfig); |
| | | |
| | | |
| | | if(!oConfig.element) { |
| | | |
| | | |
| | | 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 {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/ |
| | | * level-one-html.html#ID-58190037">HTMLElement</a>} p_oElement Object |
| | | * reference specifying the element to be evaluated. |
| | | * @return {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/ |
| | | * level-one-html.html#ID-58190037">HTMLElement</a>} |
| | | */ |
| | | 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 <code><input></code> element of the |
| | | * specified type. |
| | | * @private |
| | | * @param {String} p_sType String specifying the type of |
| | | * <code><input></code> element to create. |
| | | * @param {String} p_sName String specifying the name of |
| | | * <code><input></code> element to create. |
| | | * @param {String} p_sValue String specifying the value of |
| | | * <code><input></code> element to create. |
| | | * @param {String} p_bChecked Boolean specifying if the |
| | | * <code><input></code> element is to be checked. |
| | | * @return {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level- |
| | | * one-html.html#ID-6043025">HTMLInputElement</a>} |
| | | */ |
| | | 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 type=\"" + p_sType + "\" name=\"" + p_sName + "\""; |
| | | |
| | | if(p_bChecked) { |
| | | |
| | | sInput += " checked"; |
| | | |
| | | } |
| | | |
| | | sInput += ">"; |
| | | |
| | | oInput = document.createElement(sInput); |
| | | |
| | | } |
| | | else { |
| | | |
| | | oInput = document.createElement("input"); |
| | | oInput.name = p_sName; |
| | | oInput.type = p_sType; |
| | | |
| | | if(p_bChecked) { |
| | | |
| | | oInput.checked = true; |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | oInput.value = p_sValue; |
| | | |
| | | return oInput; |
| | | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * @method setAttributesFromSrcElement |
| | | * @description Gets the values for all the attributes of the source element |
| | | * (either <code><input></code> or <code><a></code>) that map to |
| | | * Button configuration attributes and sets them into a collection that is |
| | | * passed to the Button constructor. |
| | | * @private |
| | | * @param {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level- |
| | | * one-html.html#ID-6043025">HTMLInputElement</a>|<a href="http://www.w3.org/ |
| | | * TR/2000/WD-DOM-Level-1-20000929/level-one-html.html#ID- |
| | | * 48250443">HTMLAnchorElement</a>} p_oElement Object reference to the HTML |
| | | * element (either <code><input></code> or <code><span></code>) |
| | | * 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 <code><button></code> for the value attribute rather |
| | | than the value of the "value" attribute. |
| | | */ |
| | | |
| | | var oAttribute = p_oElement.getAttributeNode(p_sAttribute); |
| | | |
| | | |
| | | if(oAttribute && ("value" in oAttribute)) { |
| | | |
| | | |
| | | 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 |
| | | * <code><a></code> or <code><button></code> element. |
| | | * @default null |
| | | * @protected |
| | | * @type <a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level- |
| | | * one-html.html#ID-48250443">HTMLAnchorElement</a>|<a href=" |
| | | * http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html#ID- |
| | | * 34812697">HTMLButtonElement</a> |
| | | */ |
| | | _button: null, |
| | | |
| | | |
| | | /** |
| | | * @property _menu |
| | | * @description Object reference to the button's menu. |
| | | * @default null |
| | | * @protected |
| | | * @type <a href="YAHOO.widget.Menu.html">YAHOO.widget.Menu</a> |
| | | */ |
| | | _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) { |
| | | |
| | | |
| | | 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 {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/ |
| | | * level-one-html.html#ID-58190037">HTMLElement</a>} |
| | | */ |
| | | _createButtonElement: function(p_sType) { |
| | | |
| | | var sTagName = this.TAG_NAME, |
| | | oElement = document.createElement(sTagName); |
| | | |
| | | oElement.innerHTML = |
| | | |
| | | "<" + sTagName + " class=\"first-child\">" + |
| | | (p_sType == "link" ? "<a></a>" : "<button type=\"button\"></button>") + |
| | | "</" + sTagName + ">"; |
| | | |
| | | 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) { |
| | | |
| | | |
| | | 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") { |
| | | |
| | | |
| | | 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 {<a href="YAHOO.widget.MenuItem.html">YAHOO.widget.MenuItem</a>} |
| | | * 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 {<a href="YAHOO.widget.MenuItem.html">YAHOO.widget.MenuItem</a>} |
| | | * 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 {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level- |
| | | * one-html.html#ID-6043025">HTMLInputElement</a>} |
| | | */ |
| | | 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 |
| | | * <code><input></code>, <code><a></code> or |
| | | * <code><span></code> element to be used to create the button. |
| | | * @param {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level- |
| | | * one-html.html#ID-6043025">HTMLInputElement</a>|<a href=" |
| | | * http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html# |
| | | * ID-33759296">HTMLElement</a>} p_oElement Object reference for the |
| | | * <code><input></code>, <code><a></code> or |
| | | * <code><span></code> 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"); |
| | | |
| | | |
| | | }, |
| | | |
| | | |
| | | /** |
| | | * @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 <a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/ |
| | | * level-one-html.html#ID-58190037">HTMLElement</a>|String |
| | | * @default null |
| | | */ |
| | | this.setAttributeConfig("container", { |
| | | |
| | | value: oAttributes.container |
| | | |
| | | }); |
| | | |
| | | |
| | | /** |
| | | * @config srcelement |
| | | * @description Object reference to the HTML element (either |
| | | * <code><input></code> or <code><span></code>) used to |
| | | * create the button. |
| | | * @type <a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/ |
| | | * level-one-html.html#ID-58190037">HTMLElement</a>|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: |
| | | * <ul> |
| | | * <li>Object specifying a <a href="YAHOO.widget.Menu.html"> |
| | | * YAHOO.widget.Menu</a> instance.</li> |
| | | * <li>String specifying the id attribute of the <code><div></code> |
| | | * element used to create the menu.</li> |
| | | * <li>String specifying the id attribute of the |
| | | * <code><select></code> element used to create the menu.</li> |
| | | * <li>Object specifying the <code><div></code> element used to |
| | | * create the menu.</li> |
| | | * <li>Object specifying the <code><select></code> element used to |
| | | * create the menu.</li> |
| | | * <li>Array of object literals, each representing a set of |
| | | * <a href="YAHOO.widget.MenuItem.html">YAHOO.widget.MenuItem</a> |
| | | * configuration attributes.</li> |
| | | * <li>Array of strings representing the text labels for each menu item in |
| | | * the menu.</li> |
| | | * </ul> |
| | | * @type <a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/ |
| | | * level-one-html.html#ID-58190037">HTMLElement</a>|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 <a href="YAHOO.widget.MenuItem.html">YAHOO.widget.MenuItem</a> |
| | | * @default null |
| | | */ |
| | | this.setAttributeConfig("selectedMenuItem", { |
| | | |
| | | value: null |
| | | |
| | | }); |
| | | |
| | | |
| | | /** |
| | | * @config onclick |
| | | * @description Object literal representing the code to be executed when |
| | | * the button is clicked. Format:<br> <code> {<br> |
| | | * <strong>fn:</strong> Function, // The handler to call when the |
| | | * event fires.<br> <strong>obj:</strong> Object, // An object to |
| | | * pass back to the handler.<br> <strong>scope:</strong> Object // |
| | | * The object to use for the scope of the handler.<br> } </code> |
| | | * @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:<br> <code> {<br> |
| | | * <strong>fn:</strong> Function, // The handler to call when the |
| | | * event fires.<br> <strong>obj:</strong> Object, // An object to |
| | | * pass back to the handler.<br> <strong>scope:</strong> Object // |
| | | * The object to use for the scope of the handler.<br> } </code> |
| | | * @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 {<a href="YAHOO.widget.Menu.html">YAHOO.widget.Menu</a>} |
| | | */ |
| | | getMenu: function() { |
| | | |
| | | return this._menu; |
| | | |
| | | }, |
| | | |
| | | |
| | | /** |
| | | * @method getForm |
| | | * @description Returns a reference to the button's menu. |
| | | * @return {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level- |
| | | * one-html.html#ID-40002357">HTMLFormElement</a>} |
| | | */ |
| | | 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() { |
| | | |
| | | |
| | | var oElement = this.get("element"), |
| | | oParentNode = oElement.parentNode, |
| | | oMenu = this._menu; |
| | | |
| | | if(oMenu) { |
| | | |
| | | |
| | | oMenu.destroy(); |
| | | |
| | | } |
| | | |
| | | |
| | | 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); |
| | | |
| | | |
| | | delete m_oButtons[this.get("id")]; |
| | | |
| | | |
| | | }, |
| | | |
| | | |
| | | /** |
| | | * @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 {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level- |
| | | * one-html.html#ID-40002357">HTMLFormElement</a>} 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) { |
| | | |
| | | |
| | | var oButton = null, |
| | | sType = null, |
| | | oMenuItem = null, |
| | | oMenu = null; |
| | | |
| | | for(var i=0; i<nButtons; i++) { |
| | | |
| | | oButton = m_oButtons[aButtons[i].id]; |
| | | |
| | | if(oButton) { |
| | | |
| | | sType = oButton.get("type"); |
| | | oMenuItem = oButton.get("selectedMenuItem"); |
| | | |
| | | |
| | | if(sType == "radio" || sType == "checkbox") { |
| | | |
| | | |
| | | oButton.createHiddenField(); |
| | | |
| | | } |
| | | else if(oMenuItem) { |
| | | |
| | | oMenu = oButton.getMenu(); |
| | | |
| | | var oSrcElement = oMenu.srcElement; |
| | | |
| | | if( |
| | | oSrcElement && |
| | | oSrcElement.tagName.toUpperCase() == "SELECT" |
| | | ) { |
| | | |
| | | oButton.getForm().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", |
| | | (oButton.get("name") + "_options"), |
| | | oValue |
| | | ); |
| | | |
| | | oButton.getForm().appendChild(oField); |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | }; |
| | | |
| | | |
| | | |
| | | // Events |
| | | |
| | | |
| | | /** |
| | | * @event focus |
| | | * @description Fires when the menu item receives focus. Passes back a single |
| | | * object representing the original DOM event object passed back by the event |
| | | * utility (YAHOO.util.Event) when the event was fired. See <a href=" |
| | | * YAHOO.util.Element.html#addListener">Element.addListener</a> for more |
| | | * information on listening for this event. |
| | | * @type YAHOO.util.CustomEvent |
| | | */ |
| | | |
| | | |
| | | /** |
| | | * @event blur |
| | | * @description Fires when the menu item loses the input focus. Passes back a |
| | | * single object representing the original DOM event object passed back by the |
| | | * event utility (YAHOO.util.Event) when the event was fired. See <a href=" |
| | | * YAHOO.util.Element.html#addListener">Element.addListener</a> for more |
| | | * information on listening for this event. |
| | | * @type YAHOO.util.CustomEvent |
| | | */ |
| | | |
| | | |
| | | /** |
| | | * @event option |
| | | * @description Fires when the user invokes the button's option. Passes back a |
| | | * single object representing the original DOM event (either "mousedown" or |
| | | * "keydown") that caused the "option" event to fire. See <a href=" |
| | | * YAHOO.util.Element.html#addListener">Element.addListener</a> for more |
| | | * information on listening for this event. |
| | | * @type YAHOO.util.CustomEvent |
| | | */ |
| | | |
| | | |
| | | /** |
| | | * @event init |
| | | * @description Fires when the Button is initialized. Subscribe to this event |
| | | * by specifying a value for the "oninit" configuration attribute. Format:<br> |
| | | * <code> {<br> <strong>fn:</strong> Function, // The handler to call |
| | | * when the event fires.<br> <strong>obj:</strong> Object, // An object |
| | | * to pass back to the handler.<br> <strong>scope:</strong> Object // |
| | | * The object to use for the scope of the handler.<br> } </code> |
| | | * @type YAHOO.util.CustomEvent |
| | | */ |
| | | |
| | | })(); |
| | | (function() { |
| | | |
| | | // Shorthard for utilities |
| | | |
| | | var Dom = YAHOO.util.Dom, |
| | | Event = YAHOO.util.Event, |
| | | Lang = YAHOO.lang, |
| | | Button = YAHOO.widget.Button; |
| | | |
| | | // Private collection of radio buttons |
| | | |
| | | m_oButtons = {}; |
| | | |
| | | |
| | | |
| | | /** |
| | | * The ButtonGroup class creates a set of buttons that are mutually exclusive; |
| | | * checking one button in the set will uncheck all others in the button group. |
| | | * @param {String} p_oElement String specifying the id attribute of the |
| | | * <code><div></code> element of the button group. |
| | | * @param {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/ |
| | | * level-one-html.html#ID-22445964">HTMLDivElement</a>} p_oElement Object |
| | | * specifying the <code><div></code> element of the button group. |
| | | * @param {Object} p_oElement Object literal specifying a set of |
| | | * configuration attributes used to create the button group. |
| | | * @param {Object} p_oAttributes Optional. Object literal specifying a set of |
| | | * configuration attributes used to create the button group. |
| | | * @namespace YAHOO.widget |
| | | * @class ButtonGroup |
| | | * @constructor |
| | | * @extends YAHOO.util.Element |
| | | */ |
| | | YAHOO.widget.ButtonGroup = function(p_oElement, p_oAttributes) { |
| | | |
| | | var fnSuperClass = YAHOO.widget.ButtonGroup.superclass.constructor; |
| | | |
| | | if( |
| | | arguments.length == 1 && |
| | | !Lang.isString(p_oElement) && |
| | | !p_oElement.nodeName |
| | | ) { |
| | | |
| | | if(!p_oElement.id) { |
| | | |
| | | var sId = Dom.generateId(); |
| | | |
| | | p_oElement.id = sId; |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | fnSuperClass.call(this, (this._createGroupElement()), p_oElement); |
| | | |
| | | } |
| | | else if(Lang.isString(p_oElement)) { |
| | | |
| | | var me = this; |
| | | |
| | | Event.onContentReady(p_oElement, function() { |
| | | |
| | | if(this.nodeName.toUpperCase() == me.TAG_NAME) { |
| | | |
| | | |
| | | fnSuperClass.call(me, this, p_oAttributes); |
| | | |
| | | } |
| | | |
| | | }); |
| | | |
| | | } |
| | | else { |
| | | |
| | | var sNodeName = p_oElement.nodeName; |
| | | |
| | | if(sNodeName && sNodeName == this.TAG_NAME) { |
| | | |
| | | if(!p_oElement.id) { |
| | | |
| | | p_oElement.id = Dom.generateId(); |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | fnSuperClass.call(this, p_oElement, p_oAttributes); |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | }; |
| | | |
| | | |
| | | YAHOO.extend(YAHOO.widget.ButtonGroup, YAHOO.util.Element, { |
| | | |
| | | |
| | | // Protected properties |
| | | |
| | | |
| | | /** |
| | | * @property _buttons |
| | | * @description Array of buttons in the button group. |
| | | * @default null |
| | | * @protected |
| | | * @type Array |
| | | */ |
| | | _buttons: null, |
| | | |
| | | |
| | | /** |
| | | * @property _oninitAttributeValue |
| | | * @description Object reference to the button group's current value for the |
| | | * "oninit" configuration attribute. |
| | | * @default null |
| | | * @protected |
| | | * @type Object |
| | | */ |
| | | _oninitAttributeValue: null, |
| | | |
| | | |
| | | |
| | | // Constants |
| | | |
| | | |
| | | /** |
| | | * @property TAG_NAME |
| | | * @description The name of the tag to be used for the button group's element. |
| | | * @default "DIV" |
| | | * @final |
| | | * @type String |
| | | */ |
| | | TAG_NAME: "DIV", |
| | | |
| | | |
| | | /** |
| | | * @property CSS_CLASS_NAME |
| | | * @description String representing the CSS class(es) to be applied to the |
| | | * button group's element. |
| | | * @default "yuibuttongroup" |
| | | * @final |
| | | * @type String |
| | | */ |
| | | CSS_CLASS_NAME: "yuibuttongroup", |
| | | |
| | | |
| | | |
| | | // Protected methods |
| | | |
| | | |
| | | /** |
| | | * @method _createGroupElement |
| | | * @description Creates the button group's element. |
| | | * @protected |
| | | * @return {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/ |
| | | * level-one-html.html#ID-22445964">HTMLDivElement</a>} |
| | | */ |
| | | _createGroupElement: function() { |
| | | |
| | | var oElement = document.createElement(this.TAG_NAME); |
| | | |
| | | oElement.className = this.CSS_CLASS_NAME; |
| | | |
| | | return oElement; |
| | | |
| | | }, |
| | | |
| | | |
| | | |
| | | // Protected attribute setter methods |
| | | |
| | | |
| | | /** |
| | | * @method _setDisabled |
| | | * @description Sets the value of the button groups's "disabled" attribute. |
| | | * @protected |
| | | * @param {Boolean} p_bDisabled Boolean indicating the value for the button |
| | | * group's "disabled" attribute. |
| | | */ |
| | | _setDisabled: function(p_bDisabled) { |
| | | |
| | | var nButtons = this.getCount(); |
| | | |
| | | if(nButtons > 0) { |
| | | |
| | | var i = nButtons - 1; |
| | | |
| | | do { |
| | | |
| | | this._buttons[i].set("disabled", p_bDisabled); |
| | | |
| | | } |
| | | while(i--); |
| | | |
| | | } |
| | | |
| | | }, |
| | | |
| | | |
| | | /** |
| | | * @method _setOnInit |
| | | * @description Sets the value of the button group'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 event handlers |
| | | |
| | | |
| | | /** |
| | | * @method _onKeyDown |
| | | * @description "keydown" event handler for the button group. |
| | | * @protected |
| | | * @param {Event} p_oEvent Object representing the DOM event object passed |
| | | * back by the event utility (YAHOO.util.Event). |
| | | */ |
| | | _onKeyDown: function(p_oEvent) { |
| | | |
| | | var oTarget = Event.getTarget(p_oEvent), |
| | | nCharCode = Event.getCharCode(p_oEvent), |
| | | sId = oTarget.parentNode.parentNode.id, |
| | | oButton = m_oButtons[sId], |
| | | nIndex = -1; |
| | | |
| | | |
| | | if(nCharCode == 37 || nCharCode == 38) { |
| | | |
| | | nIndex = (oButton.index === 0) ? |
| | | (this._buttons.length -1) : (oButton.index - 1); |
| | | |
| | | } |
| | | else if(nCharCode == 39 || nCharCode == 40) { |
| | | |
| | | nIndex = (oButton.index === (this._buttons.length - 1)) ? |
| | | 0 : (oButton.index + 1); |
| | | |
| | | } |
| | | |
| | | |
| | | if(nIndex > -1) { |
| | | |
| | | this.check(nIndex); |
| | | this.getButton(nIndex).focus(); |
| | | |
| | | } |
| | | |
| | | }, |
| | | |
| | | |
| | | /** |
| | | * @method _onAppendTo |
| | | * @description "appendTo" event handler for the button group. |
| | | * @protected |
| | | * @param {Event} p_oEvent Object representing the event that was fired. |
| | | */ |
| | | _onAppendTo: function(p_oEvent) { |
| | | |
| | | var aButtons = this._buttons, |
| | | nButtons = aButtons.length; |
| | | |
| | | for(var i=0; i<nButtons; i++) { |
| | | |
| | | aButtons[i].appendTo(this.get("element")); |
| | | |
| | | } |
| | | |
| | | }, |
| | | |
| | | |
| | | /** |
| | | * @method _onButtonCheckedChange |
| | | * @description "checkedChange" event handler for each button in the |
| | | * button group. |
| | | * @protected |
| | | * @param {Event} p_oEvent Object representing the event that was fired. |
| | | * @param {<a href="YAHOO.widget.Button.html">YAHOO.widget.Button</a>} p_oButton |
| | | * Object representing the button that |
| | | * fired the event. |
| | | */ |
| | | _onButtonCheckedChange: function(p_oEvent, p_oButton) { |
| | | |
| | | var bChecked = p_oEvent.newValue, |
| | | oCheckedButton = this.get("checkedButton"); |
| | | |
| | | if(bChecked && oCheckedButton != p_oButton) { |
| | | |
| | | if(oCheckedButton) { |
| | | |
| | | oCheckedButton.set("checked", false, true); |
| | | |
| | | } |
| | | |
| | | this.set("checkedButton", p_oButton); |
| | | this.set("value", p_oButton.get("value")); |
| | | |
| | | } |
| | | else if(oCheckedButton && !oCheckedButton.set("checked")) { |
| | | |
| | | oCheckedButton.set("checked", true, true); |
| | | |
| | | } |
| | | |
| | | }, |
| | | |
| | | |
| | | |
| | | // Public methods |
| | | |
| | | |
| | | /** |
| | | * @method init |
| | | * @description The ButtonGroup class's initialization method. |
| | | * @param {String} p_oElement String specifying the id attribute of the |
| | | * <code><div></code> element of the button group. |
| | | * @param {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/ |
| | | * level-one-html.html#ID-22445964">HTMLDivElement</a>} p_oElement Object |
| | | * specifying the <code><div></code> element of the button group. |
| | | * @param {Object} p_oElement Object literal specifying a set of configuration |
| | | * attributes used to create the button group. |
| | | * @param {Object} p_oAttributes Optional. Object literal specifying a set of |
| | | * configuration attributes used to create the button group. |
| | | */ |
| | | init: function(p_oElement, p_oAttributes) { |
| | | |
| | | this._buttons = []; |
| | | |
| | | YAHOO.widget.ButtonGroup.superclass.init.call( |
| | | this, p_oElement, |
| | | p_oAttributes |
| | | ); |
| | | |
| | | |
| | | |
| | | var aButtons = this.getElementsByClassName("yuibutton"); |
| | | |
| | | |
| | | if(aButtons.length > 0) { |
| | | |
| | | |
| | | this.addButtons(aButtons); |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | function isRadioButton(p_oElement) { |
| | | |
| | | return (p_oElement.type == "radio"); |
| | | |
| | | } |
| | | |
| | | aButtons = Dom.getElementsBy(isRadioButton, "input", this.get("element")); |
| | | |
| | | |
| | | if(aButtons.length > 0) { |
| | | |
| | | |
| | | this.addButtons(aButtons); |
| | | |
| | | } |
| | | |
| | | this.on("keydown", this._onKeyDown); |
| | | this.on("appendTo", this._onAppendTo); |
| | | |
| | | var oContainer = this.get("container"); |
| | | |
| | | if(oContainer) { |
| | | |
| | | if(Lang.isString(oContainer)) { |
| | | |
| | | var me = this; |
| | | |
| | | Event.onContentReady(oContainer, function() { |
| | | |
| | | me.appendTo(this); |
| | | |
| | | }); |
| | | |
| | | } |
| | | else { |
| | | |
| | | this.appendTo(oContainer); |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | this.fireEvent("init"); |
| | | |
| | | |
| | | }, |
| | | |
| | | |
| | | /** |
| | | * @method initAttributes |
| | | * @description Initializes all of the configuration attributes used to create |
| | | * the button group. |
| | | * @param {Object} p_oAttributes Object literal specifying a set of |
| | | * configuration attributes used to create the button group. |
| | | */ |
| | | initAttributes: function(p_oAttributes) { |
| | | |
| | | var oAttributes = p_oAttributes || {}; |
| | | |
| | | YAHOO.widget.ButtonGroup.superclass.initAttributes.call( |
| | | this, |
| | | oAttributes |
| | | ); |
| | | |
| | | |
| | | /** |
| | | * @config name |
| | | * @description String specifying the name for the button group. This |
| | | * name will be applied to each button in the button group. |
| | | * @default null |
| | | * @type String |
| | | */ |
| | | this.setAttributeConfig("name", { |
| | | |
| | | value: oAttributes.name, |
| | | validator: Lang.isString |
| | | |
| | | }); |
| | | |
| | | |
| | | /** |
| | | * @config disabled |
| | | * @description Boolean indicating if the button group should be disabled. |
| | | * Disabling the button group will disable each button in the button group. |
| | | * 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 value |
| | | * @description Object specifying the value for the button group. |
| | | * @default null |
| | | * @type Object |
| | | */ |
| | | this.setAttributeConfig("value", { |
| | | |
| | | value: oAttributes.value |
| | | |
| | | }); |
| | | |
| | | |
| | | /** |
| | | * @config container |
| | | * @description HTML element reference or string specifying the id |
| | | * attribute of the HTML element that the button group's markup should be |
| | | * rendered into. |
| | | * @type <a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/ |
| | | * level-one-html.html#ID-58190037">HTMLElement</a>|String |
| | | * @default null |
| | | */ |
| | | this.setAttributeConfig("container", { |
| | | |
| | | value: oAttributes.container |
| | | |
| | | }); |
| | | |
| | | |
| | | /** |
| | | * @config checkedButton |
| | | * @description Reference for the button in the button group that |
| | | * is checked. |
| | | * @type {<a href="YAHOO.widget.Button.html">YAHOO.widget.Button</a>} |
| | | * @default null |
| | | */ |
| | | this.setAttributeConfig("checkedButton", { |
| | | |
| | | value: null |
| | | |
| | | }); |
| | | |
| | | |
| | | /** |
| | | * @config oninit |
| | | * @description Object literal representing the code to be executed when |
| | | * the button group is initialized. Format:<br> <code> {<br> |
| | | * <strong>fn:</strong> Function, // The handler to call when the |
| | | * event fires.<br> <strong>obj:</strong> Object, // An object to |
| | | * pass back to the handler.<br> <strong>scope:</strong> Object // |
| | | * The object to use for the scope of the handler.<br> } </code> |
| | | * @type Object |
| | | * @default null |
| | | */ |
| | | this.setAttributeConfig("oninit", { |
| | | |
| | | value: oAttributes.oninit, |
| | | method: this._setOnInit |
| | | |
| | | }); |
| | | |
| | | }, |
| | | |
| | | |
| | | /** |
| | | * @method addButton |
| | | * @description Adds the button to the button group. |
| | | * @param {<a href="YAHOO.widget.Button.html">YAHOO.widget.Button</a>} p_oButton |
| | | * Object reference for the <a href="YAHOO.widget.Button.html"> |
| | | * YAHOO.widget.Button</a> instance to be added to the button group. |
| | | * @param {String} p_oButton String specifying the id attribute of the |
| | | * <code><input></code> or <code><span></code> element to be |
| | | * used to create the button to be added to the button group. |
| | | * @param {<a href="http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level- |
| | | * one-html.html#ID-6043025">HTMLInputElement</a>|<a href=" |
| | | * http://www.w3.org/TR/2000/WD-DOM-Level-1-20000929/level-one-html.html# |
| | | * ID-33759296">HTMLElement</a>} p_oButton Object reference for the |
| | | * <code><input></code> or <code><span></code> element to be |
| | | * used to create the button to be added to the button group. |
| | | * @param {Object} p_oButton Object literal specifying a set of |
| | | * <a href="YAHOO.widget.Button.html">YAHOO.widget.Button</a> configuration |
| | | * attributes used to configure the button to be added to the button group. |
| | | * @return {<a href="YAHOO.widget.Button.html">YAHOO.widget.Button</a>} |
| | | */ |
| | | addButton: function(p_oButton) { |
| | | |
| | | var oButton; |
| | | |
| | | |
| | | if(p_oButton instanceof Button && p_oButton.get("type") == "radio") { |
| | | |
| | | oButton = p_oButton; |
| | | |
| | | } |
| | | else if(!Lang.isString(p_oButton) && !p_oButton.nodeName) { |
| | | |
| | | p_oButton.type = "radio"; |
| | | |
| | | oButton = new Button(p_oButton); |
| | | |
| | | } |
| | | else { |
| | | |
| | | oButton = new Button(p_oButton, { type: "radio" }); |
| | | |
| | | } |
| | | |
| | | |
| | | if(oButton) { |
| | | |
| | | var nIndex = this._buttons.length, |
| | | sButtonName = oButton.get("name"), |
| | | sGroupName = this.get("name"); |
| | | |
| | | oButton.index = nIndex; |
| | | |
| | | this._buttons[nIndex] = oButton; |
| | | m_oButtons[oButton.get("id")] = oButton; |
| | | |
| | | |
| | | if(sButtonName != sGroupName) { |
| | | |
| | | oButton.set("name", sGroupName); |
| | | |
| | | } |
| | | |
| | | |
| | | if(this.get("disabled")) { |
| | | |
| | | oButton.set("disabled", true); |
| | | |
| | | } |
| | | |
| | | |
| | | if(oButton.get("checked")) { |
| | | |
| | | this.set("checkedButton", oButton); |
| | | |
| | | } |
| | | |
| | | |
| | | oButton.on("checkedChange", this._onButtonCheckedChange, oButton, this); |
| | | |
| | | |
| | | return oButton; |
| | | |
| | | } |
| | | |
| | | }, |
| | | |
| | | |
| | | /** |
| | | * @method addButtons |
| | | * @description Adds the array of buttons to the button group. |
| | | * @param {Array} p_aButtons Array of <a href="YAHOO.widget.Button.html"> |
| | | * YAHOO.widget.Button</a> instances to be added |
| | | * to the button group. |
| | | * @param {Array} p_aButtons Array of strings specifying the id attribute of |
| | | * the <code><input></code> or <code><span></code> elements to |
| | | * be used to create the buttons to be added to the button group. |
| | | * @param {Array} p_aButtons Array of object references for the |
| | | * <code><input></code> or <code><span></code> elements to be |
| | | * used to create the buttons to be added to the button group. |
| | | * @param {Array} p_aButtons Array of object literals, each containing a set of |
| | | * <a href="YAHOO.widget.Button.html">YAHOO.widget.Button</a> configuration |
| | | * attributes used to configure each button to be added to the button group. |
| | | * @return {Array} |
| | | */ |
| | | addButtons: function(p_aButtons) { |
| | | |
| | | if(Lang.isArray(p_aButtons)) { |
| | | |
| | | var nButtons = p_aButtons.length, |
| | | oButton, |
| | | aButtons = []; |
| | | |
| | | if(nButtons > 0) { |
| | | |
| | | for(var i=0; i<nButtons; i++) { |
| | | |
| | | oButton = this.addButton(p_aButtons[i]); |
| | | |
| | | if(oButton) { |
| | | |
| | | aButtons[aButtons.length] = oButton; |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | if(aButtons.length > 0) { |
| | | |
| | | |
| | | return aButtons; |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | }, |
| | | |
| | | |
| | | /** |
| | | * @method removeButton |
| | | * @description Removes the button at the specified index from the button group. |
| | | * @param {Number} p_nIndex Number specifying the index of the button to be |
| | | * removed from the button group. |
| | | */ |
| | | removeButton: function(p_nIndex) { |
| | | |
| | | var oButton = this.getButton(p_nIndex); |
| | | |
| | | if(oButton) { |
| | | |
| | | |
| | | this._buttons.splice(p_nIndex, 1); |
| | | delete m_oButtons[oButton.get("id")]; |
| | | |
| | | oButton.removeListener("checkedChange", this._onButtonCheckedChange); |
| | | oButton.destroy(); |
| | | |
| | | |
| | | var nButtons = this._buttons.length; |
| | | |
| | | if(nButtons > 0) { |
| | | |
| | | var i = this._buttons.length - 1; |
| | | |
| | | do { |
| | | |
| | | this._buttons[i].index = i; |
| | | |
| | | } |
| | | while(i--); |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | }, |
| | | |
| | | |
| | | /** |
| | | * @method getButton |
| | | * @description Returns the button at the specified index. |
| | | * @param {Number} p_nIndex The index of the button to retrieve from the |
| | | * button group. |
| | | * @return {<a href="YAHOO.widget.Button.html">YAHOO.widget.Button</a>} |
| | | */ |
| | | getButton: function(p_nIndex) { |
| | | |
| | | if(Lang.isNumber(p_nIndex)) { |
| | | |
| | | return this._buttons[p_nIndex]; |
| | | |
| | | } |
| | | |
| | | }, |
| | | |
| | | |
| | | /** |
| | | * @method getButtons |
| | | * @description Returns an array of the buttons in the button group. |
| | | * @return {Array} |
| | | */ |
| | | getButtons: function() { |
| | | |
| | | return this._buttons; |
| | | |
| | | }, |
| | | |
| | | |
| | | /** |
| | | * @method getCount |
| | | * @description Returns the number of buttons in the button group. |
| | | * @return {Number} |
| | | */ |
| | | getCount: function() { |
| | | |
| | | return this._buttons.length; |
| | | |
| | | }, |
| | | |
| | | |
| | | /** |
| | | * @method focus |
| | | * @description Sets focus to the button at the specified index. |
| | | * @param {Number} p_nIndex Number indicating the index of the button to focus. |
| | | */ |
| | | focus: function(p_nIndex) { |
| | | |
| | | var oButton; |
| | | |
| | | if(Lang.isNumber(p_nIndex)) { |
| | | |
| | | oButton = this._buttons[p_nIndex]; |
| | | |
| | | if(oButton) { |
| | | |
| | | oButton.focus(); |
| | | |
| | | } |
| | | |
| | | } |
| | | else { |
| | | |
| | | var nButtons = this.getCount(); |
| | | |
| | | for(var i=0; i<nButtons; i++) { |
| | | |
| | | oButton = this._buttons[i]; |
| | | |
| | | if(!oButton.get("disabled")) { |
| | | |
| | | oButton.focus(); |
| | | break; |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | } |
| | | |
| | | }, |
| | | |
| | | |
| | | /** |
| | | * @method check |
| | | * @description Checks the button at the specified index. |
| | | * @param {Number} p_nIndex Number indicating the index of the button to check. |
| | | */ |
| | | check: function(p_nIndex) { |
| | | |
| | | var oButton = this.getButton(p_nIndex); |
| | | |
| | | if(oButton) { |
| | | |
| | | oButton.set("checked", true); |
| | | |
| | | } |
| | | |
| | | }, |
| | | |
| | | |
| | | /** |
| | | * @method destroy |
| | | * @description Removes the button group's element from its parent element and |
| | | * removes all event handlers. |
| | | */ |
| | | destroy: function() { |
| | | |
| | | |
| | | var nButtons = this._buttons.length, |
| | | oElement = this.get("element"), |
| | | oParentNode = oElement.parentNode; |
| | | |
| | | if(nButtons > 0) { |
| | | |
| | | var i = this._buttons.length - 1; |
| | | |
| | | do { |
| | | |
| | | this._buttons[i].destroy(); |
| | | |
| | | } |
| | | while(i--); |
| | | |
| | | } |
| | | |
| | | |
| | | Event.purgeElement(oElement); |
| | | |
| | | |
| | | oParentNode.removeChild(oElement); |
| | | |
| | | }, |
| | | |
| | | |
| | | /** |
| | | * @method toString |
| | | * @description Returns a string representing the button group. |
| | | * @return {String} |
| | | */ |
| | | toString: function() { |
| | | |
| | | return ("ButtonGroup " + this.get("id")); |
| | | |
| | | } |
| | | |
| | | }); |
| | | |
| | | |
| | | |
| | | // Events |
| | | |
| | | |
| | | /** |
| | | * @event init |
| | | * @description Fires when the button group is initialized. Subscribe to this |
| | | * event by specifying a value for the "oninit" configuration attribute. |
| | | * Format:<br> <code> {<br> <strong>fn:</strong> Function, // The |
| | | * handler to call when the event fires.<br> <strong>obj:</strong> Object, |
| | | * // An object to pass back to the handler.<br> <strong>scope:</strong> |
| | | * Object // The object to use for the scope of the handler.<br> |
| | | * } </code> |
| | | * @type YAHOO.util.CustomEvent |
| | | */ |
| | | |
| | | })(); |
| | | YAHOO.register("button", YAHOO.widget.Button, {version: "2.2.0", build: "127"}); |
New file |
| | |
| | | Calendar Release Notes |
| | | |
| | | *** version 2.2.0 *** |
| | | |
| | | - Image customization can now be done through CSS. Images for Close, Left and Right Arrows are now pulled in using CSS defined in calendar.css and by default use relative paths to the images in the same directory as calendar.css. |
| | | - Deprecated Calendar.IMG_ROOT and NAV_ARROW_LEFT, NAV_ARROW_RIGHT configuration properties. Customizations based on older releases which set these properties will still function as expected. |
| | | - Deprecated CalendarGroup.CSS_2UPCLOSE. Calendar's Style.CSS_CLOSE property now represents the new default CSS class (calclose) for the close button. CSS_2UPCLOSE is still applied along with CSS_CLOSE to the new markup for the close button to support existing customizations of the CSS_2UPCLOSE CSS class (close-icon) |
| | | - Fixed problem with Safari setting Calendar pages to incorrect dates if the pages spanned a year boundary in CalendarGroups with 3 or more pages, due to a bug in Safari's implementation of Date setMonth |
| | | - Fixed problem with CalendarGroup setMonth rendering Calendar pages with incorrect dates in all browsers if current pages spanned year boundary |
| | | - Fixed incorrect CalendarGroup logging statement in calendar-debug.js |
| | | - Fixed domEventMap support for Safari versions prior to 2.0.2, caused by hasOwnProperty not being supported |
| | | - Removed unused private property : _pageDate from Calendar class |
| | | |
| | | *** version 0.12.2 *** |
| | | |
| | | - Corrected documentation for clearTime function to reflect the change from midnight to noon |
| | | |
| | | *** version 0.12.1 *** |
| | | |
| | | - Calendar and CalendarGroup now automatically parse the argument passed to setMonth and setYear into an integer, eliminating potential concatenation bugs. |
| | | |
| | | *** version 0.12 *** |
| | | |
| | | - New documentation format implemented |
| | | - Calendar2up and Calendar_Core are now deprecated. Now, Calendar alone represents the single Calendar instance, and CalendarGroup represents an n-up instance, defaulting to 2up |
| | | - Added semantic style classes to Calendar elements to allow for custom styling solely using CSS. |
| | | - Remapped all configuration properties to use the Config object (familiar to those who use the Container collection of controls). Property names are the same as their previous counterparts, but wrapped into Calendar.cfg, allowing for runtime reconfiguration of most properties |
| | | - Added "title" property for setting the Calendar title |
| | | - Added "close" property for enabling and disabling the close icon |
| | | - Added "iframe" property for enabling an iframe shim in Internet Explorer 6 and below to fix the select bleed-through bug |
| | | - pageDate moved to property: "pagedate" |
| | | - selectedDates moved to property: "selected" |
| | | - minDate moved to property : "mindate", which accepts a JavaScript Date object like its predecessor, but also supports string dates |
| | | - maxDate moved to property : "maxdate", which accepts a JavaScript Date object like its predecessor, but also supports string dates |
| | | - Moved style declarations to initStyles function |
| | | - Optimized event handling in doSelectCell/doCellMouseOver/doCellMouseOut by only attaching the listener to the outer Calendar container, and only reacting to events on cells with the "selectable" CSS class. |
| | | - Added domEventMap field for applying DOM event listeners to cells containing specific class and tag combinations. |
| | | - Moved all cell DOM event attachment to applyListeners function |
| | | - Added getDateByCellId / getDateFieldsByCellId helper functions |
| | | - Corrected DateMath.getWeekNumber to comply with ISO week number handling |
| | | - Separated renderCellDefault style portions into styleCellDefault function for easy extension |
| | | - Deprecated onBeforeSelect. Created beforeSelectEvent which automatically subscribes to its deprecated predecessor. |
| | | - Deprecated onSelect. Created selectEvent, which automatically subscribes to its deprecated predecessor. |
| | | - Deprecated onBeforeDeselect. Created beforeSelectEvent which automatically subscribes to its deprecated predecessor. |
| | | - Deprecated onDeselect. Created beforeDeselectEvent, which automatically subscribes to its deprecated predecessor. |
| | | - Deprecated onChangePage. Created changePageEvent, which automatically subscribes to its deprecated predecessor. |
| | | - Deprecated onRender. Created renderEvent, which automatically subscribes to its deprecated predecessor. |
| | | - Deprecated onReset. Created resetEvent, which automatically subscribes to its deprecated predecessor. |
| | | - Deprecated onClear. Created clearEvent, which automatically subscribes to its deprecated predecessor. |
| | | - Corrected setMonth documentation to refer to 0-11 indexed months. |
| | | - Added show and hide methods to Calendar for setting the Calendar's display property. |
| | | - Optimized internal render classes to use innerHTML and string buffers |
| | | - Removed wireCustomEvents function |
| | | - Removed wireDefaultEvents function |
| | | - Removed doNextMonth / doPreviousMonth |
| | | - Removed all buildShell (header, body, footer) functions, since the Calendar shell is now built dynamically on each render |
| | | - Wired all CalendarGroup events and configuration properties to be properly delegated to Calendar |
| | | - Augmented CalendarGroup with all built-in renderers, label functions, hide, show, and initStyles, creating API transparency between Calendar and CalendarGroup. |
| | | - Made all tagName, createElement, and entity references XHTML compliant |
| | | - Fixed Daylight Saving Time bug for Brazilian time zone |
| | | |
| | | *** version 0.11.3 *** |
| | | |
| | | - Calendar_Core: Added arguments for selected/deselected dates to onSelect/onDeselect |
| | | - CalendarGroup: Fixed bug where selected dates passed to constructor were not represented in selectedDates |
| | | - Calendar2up: Now displays correctly in Opera 9 |
| | | |
| | | *** version 0.11.0 *** |
| | | |
| | | - DateMath: DateMath.add now properly adds weeks |
| | | - DateMath: between() function added |
| | | - DateMath: getWeekNumber() fixed to take starting day of week into account |
| | | - All references to Calendar's built in CSS class handlers are removed, replaced with calls to Dom utility (addClass, removeClass) |
| | | - Several CSS class constants now have clearer names |
| | | - All CSS classes are now properly namespaced to avoid CSS conflicts |
| | | - Fixed table:hover bug in CSS |
| | | - Calendar no longer requires the container ID and variable name to match in order for month navigation to function properly |
| | | - Calendar month navigation arrows are now represented as background images |
| | | |
| | | *** version 0.10.0 *** |
| | | |
| | | - Major performance improvements from attaching DOM events to associated table cells only once, when the Calendar shell is built |
| | | - DOM events for mouseover/mouseout are now fired for all browsers (not just Internet Explorer) |
| | | - Reset functionality bug fixed for 2-up Calendar view |
| | | |
| | | *** version 0.9.0 *** |
| | | |
| | | * Initial release |
New file |
| | |
| | | /* |
| | | 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 |
| | | */ |
| | | .yui-calcontainer { |
| | | position:relative; |
| | | padding:5px; |
| | | background-color:#F7F9FB; |
| | | border:1px solid #7B9EBD; |
| | | float:left; |
| | | overflow:hidden; |
| | | } |
| | | |
| | | .yui-calcontainer iframe { |
| | | position:absolute; |
| | | border:none; |
| | | margin:0;padding:0; |
| | | left:-1px; |
| | | top:-1px; |
| | | z-index:0; |
| | | width:50em; |
| | | height:50em; |
| | | } |
| | | |
| | | .yui-calcontainer.multi { |
| | | padding:0; |
| | | } |
| | | |
| | | .yui-calcontainer.multi .groupcal { |
| | | padding:5px; |
| | | background-color:transparent; |
| | | z-index:1; |
| | | float:left; |
| | | position:relative; |
| | | border:none; |
| | | } |
| | | |
| | | .yui-calcontainer .title { |
| | | font:100% sans-serif; |
| | | color:#000; |
| | | font-weight:bold; |
| | | margin-bottom:5px; |
| | | height:25px; |
| | | position:absolute; |
| | | top:3px;left:5px; |
| | | z-index:1; |
| | | } |
| | | |
| | | .yui-calcontainer .close-icon { |
| | | position:absolute; |
| | | right:3px; |
| | | top:3px; |
| | | border:none; |
| | | z-index:1; |
| | | } |
| | | |
| | | .yui-calcontainer .calclose { |
| | | background: url("calx.gif") no-repeat; |
| | | width:17px; |
| | | height:13px; |
| | | cursor:pointer; |
| | | } |
| | | |
| | | /* Calendar element styles */ |
| | | |
| | | .yui-calendar { |
| | | font:100% sans-serif; |
| | | text-align:center; |
| | | border-spacing:0; |
| | | border-collapse:separate; |
| | | position:relative; |
| | | } |
| | | |
| | | .yui-calcontainer.withtitle { |
| | | padding-top:1.5em; |
| | | } |
| | | |
| | | .yui-calendar .calnavleft { |
| | | position:absolute; |
| | | cursor:pointer; |
| | | top:2px; |
| | | bottom:0; |
| | | width:9px; |
| | | height:12px; |
| | | left:2px; |
| | | z-index:1; |
| | | background: url("callt.gif") no-repeat; |
| | | } |
| | | |
| | | .yui-calendar .calnavright { |
| | | position:absolute; |
| | | cursor:pointer; |
| | | top:2px; |
| | | bottom:0; |
| | | width:9px; |
| | | height:12px; |
| | | right:2px; |
| | | z-index:1; |
| | | background: url("calrt.gif") no-repeat; |
| | | } |
| | | |
| | | .yui-calendar td.calcell { |
| | | padding:.1em .2em; |
| | | border:1px solid #E0E0E0; |
| | | text-align:center; |
| | | } |
| | | |
| | | .yui-calendar td.calcell a { |
| | | color:#003DB8; |
| | | text-decoration:none; |
| | | } |
| | | |
| | | .yui-calendar td.calcell.today { |
| | | border:1px solid #000; |
| | | } |
| | | |
| | | .yui-calendar td.calcell.oom { |
| | | cursor:default; |
| | | color:#999; |
| | | background-color:#EEE; |
| | | border:1px solid #E0E0E0; |
| | | } |
| | | |
| | | .yui-calendar td.calcell.selected { |
| | | color:#003DB8; |
| | | background-color:#FFF19F; |
| | | border:1px solid #FF9900; |
| | | } |
| | | |
| | | .yui-calendar td.calcell.calcellhover { |
| | | cursor:pointer; |
| | | color:#FFF; |
| | | background-color:#FF9900; |
| | | border:1px solid #FF9900; |
| | | } |
| | | |
| | | .yui-calendar td.calcell.calcellhover a { |
| | | color:#FFF; |
| | | } |
| | | |
| | | .yui-calendar td.calcell.restricted { |
| | | text-decoration:line-through; |
| | | } |
| | | |
| | | .yui-calendar td.calcell.previous { |
| | | color:#CCC; |
| | | } |
| | | |
| | | .yui-calendar td.calcell.highlight1 { background-color:#CCFF99; } |
| | | .yui-calendar td.calcell.highlight2 { background-color:#99CCFF; } |
| | | .yui-calendar td.calcell.highlight3 { background-color:#FFCCCC; } |
| | | .yui-calendar td.calcell.highlight4 { background-color:#CCFF99; } |
| | | |
| | | .yui-calendar .calhead { |
| | | border:1px solid #E0E0E0; |
| | | vertical-align:middle; |
| | | background-color:#FFF; |
| | | } |
| | | |
| | | .yui-calendar .calheader { |
| | | position:relative; |
| | | width:100%; |
| | | text-align:center; |
| | | } |
| | | |
| | | .yui-calendar .calheader img { |
| | | border:none; |
| | | } |
| | | |
| | | .yui-calendar .calweekdaycell { |
| | | color:#666; |
| | | font-weight:normal; |
| | | text-align:center; |
| | | width:1.5em; |
| | | } |
| | | |
| | | .yui-calendar .calfoot { |
| | | background-color:#EEE; |
| | | } |
| | | |
| | | .yui-calendar .calrowhead, .yui-calendar .calrowfoot { |
| | | color:#666; |
| | | font-size:9px; |
| | | font-style:italic; |
| | | font-weight:normal; |
| | | width:15px; |
| | | } |
| | | |
| | | .yui-calendar .calrowhead { |
| | | border-right-width:2px; |
| | | } |
| | | |
| | | /* Specific changes for calendar running under fonts/reset */ |
| | | .yui-calendar .calbody a:hover {background:inherit;} |
| | | p#clear {clear:left; padding-top:10px;} |
New file |
| | |
| | | /* |
| | | 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.Config=function(owner){if(owner){this.init(owner);}};YAHOO.util.Config.prototype={owner:null,queueInProgress:false,checkBoolean:function(val){if(typeof val=='boolean'){return true;}else{return false;}},checkNumber:function(val){if(isNaN(val)){return false;}else{return true;}}};YAHOO.util.Config.prototype.init=function(owner){this.owner=owner;this.configChangedEvent=new YAHOO.util.CustomEvent("configChanged");this.queueInProgress=false;var config={};var initialConfig={};var eventQueue=[];var fireEvent=function(key,value){key=key.toLowerCase();var property=config[key];if(typeof property!='undefined'&&property.event){property.event.fire(value);}};this.addProperty=function(key,propertyObject){key=key.toLowerCase();config[key]=propertyObject;propertyObject.event=new YAHOO.util.CustomEvent(key);propertyObject.key=key;if(propertyObject.handler){propertyObject.event.subscribe(propertyObject.handler,this.owner,true);} |
| | | this.setProperty(key,propertyObject.value,true);if(!propertyObject.suppressEvent){this.queueProperty(key,propertyObject.value);}};this.getConfig=function(){var cfg={};for(var prop in config){var property=config[prop];if(typeof property!='undefined'&&property.event){cfg[prop]=property.value;}} |
| | | return cfg;};this.getProperty=function(key){key=key.toLowerCase();var property=config[key];if(typeof property!='undefined'&&property.event){return property.value;}else{return undefined;}};this.resetProperty=function(key){key=key.toLowerCase();var property=config[key];if(typeof property!='undefined'&&property.event){if(initialConfig[key]&&initialConfig[key]!='undefined'){this.setProperty(key,initialConfig[key]);} |
| | | return true;}else{return false;}};this.setProperty=function(key,value,silent){key=key.toLowerCase();if(this.queueInProgress&&!silent){this.queueProperty(key,value);return true;}else{var property=config[key];if(typeof property!='undefined'&&property.event){if(property.validator&&!property.validator(value)){return false;}else{property.value=value;if(!silent){fireEvent(key,value);this.configChangedEvent.fire([key,value]);} |
| | | return true;}}else{return false;}}};this.queueProperty=function(key,value){key=key.toLowerCase();var property=config[key];if(typeof property!='undefined'&&property.event){if(typeof value!='undefined'&&property.validator&&!property.validator(value)){return false;}else{if(typeof value!='undefined'){property.value=value;}else{value=property.value;} |
| | | var foundDuplicate=false;for(var i=0;i<eventQueue.length;i++){var queueItem=eventQueue[i];if(queueItem){var queueItemKey=queueItem[0];var queueItemValue=queueItem[1];if(queueItemKey.toLowerCase()==key){eventQueue[i]=null;eventQueue.push([key,(typeof value!='undefined'?value:queueItemValue)]);foundDuplicate=true;break;}}} |
| | | if(!foundDuplicate&&typeof value!='undefined'){eventQueue.push([key,value]);}} |
| | | if(property.supercedes){for(var s=0;s<property.supercedes.length;s++){var supercedesCheck=property.supercedes[s];for(var q=0;q<eventQueue.length;q++){var queueItemCheck=eventQueue[q];if(queueItemCheck){var queueItemCheckKey=queueItemCheck[0];var queueItemCheckValue=queueItemCheck[1];if(queueItemCheckKey.toLowerCase()==supercedesCheck.toLowerCase()){eventQueue.push([queueItemCheckKey,queueItemCheckValue]);eventQueue[q]=null;break;}}}}} |
| | | return true;}else{return false;}};this.refireEvent=function(key){key=key.toLowerCase();var property=config[key];if(typeof property!='undefined'&&property.event&&typeof property.value!='undefined'){if(this.queueInProgress){this.queueProperty(key);}else{fireEvent(key,property.value);}}};this.applyConfig=function(userConfig,init){if(init){initialConfig=userConfig;} |
| | | for(var prop in userConfig){this.queueProperty(prop,userConfig[prop]);}};this.refresh=function(){for(var prop in config){this.refireEvent(prop);}};this.fireQueue=function(){this.queueInProgress=true;for(var i=0;i<eventQueue.length;i++){var queueItem=eventQueue[i];if(queueItem){var key=queueItem[0];var value=queueItem[1];var property=config[key];property.value=value;fireEvent(key,value);}} |
| | | this.queueInProgress=false;eventQueue=[];};this.subscribeToConfigEvent=function(key,handler,obj,override){key=key.toLowerCase();var property=config[key];if(typeof property!='undefined'&&property.event){if(!YAHOO.util.Config.alreadySubscribed(property.event,handler,obj)){property.event.subscribe(handler,obj,override);} |
| | | return true;}else{return false;}};this.unsubscribeFromConfigEvent=function(key,handler,obj){key=key.toLowerCase();var property=config[key];if(typeof property!='undefined'&&property.event){return property.event.unsubscribe(handler,obj);}else{return false;}};this.toString=function(){var output="Config";if(this.owner){output+=" ["+this.owner.toString()+"]";} |
| | | return output;};this.outputEventQueue=function(){var output="";for(var q=0;q<eventQueue.length;q++){var queueItem=eventQueue[q];if(queueItem){output+=queueItem[0]+"="+queueItem[1]+", ";}} |
| | | return output;};};YAHOO.util.Config.alreadySubscribed=function(evt,fn,obj){for(var e=0;e<evt.subscribers.length;e++){var subsc=evt.subscribers[e];if(subsc&&subsc.obj==obj&&subsc.fn==fn){return true;}} |
| | | return false;};YAHOO.widget.DateMath={DAY:"D",WEEK:"W",YEAR:"Y",MONTH:"M",ONE_DAY_MS:1000*60*60*24,add:function(date,field,amount){var d=new Date(date.getTime());switch(field){case this.MONTH:var newMonth=date.getMonth()+amount;var years=0;if(newMonth<0){while(newMonth<0){newMonth+=12;years-=1;}}else if(newMonth>11){while(newMonth>11){newMonth-=12;years+=1;}} |
| | | d.setMonth(newMonth);d.setFullYear(date.getFullYear()+years);break;case this.DAY:d.setDate(date.getDate()+amount);break;case this.YEAR:d.setFullYear(date.getFullYear()+amount);break;case this.WEEK:d.setDate(date.getDate()+(amount*7));break;} |
| | | return d;},subtract:function(date,field,amount){return this.add(date,field,(amount*-1));},before:function(date,compareTo){var ms=compareTo.getTime();if(date.getTime()<ms){return true;}else{return false;}},after:function(date,compareTo){var ms=compareTo.getTime();if(date.getTime()>ms){return true;}else{return false;}},between:function(date,dateBegin,dateEnd){if(this.after(date,dateBegin)&&this.before(date,dateEnd)){return true;}else{return false;}},getJan1:function(calendarYear){return new Date(calendarYear,0,1);},getDayOffset:function(date,calendarYear){var beginYear=this.getJan1(calendarYear);var dayOffset=Math.ceil((date.getTime()-beginYear.getTime())/this.ONE_DAY_MS);return dayOffset;},getWeekNumber:function(date,calendarYear){date=this.clearTime(date);var nearestThurs=new Date(date.getTime()+(4*this.ONE_DAY_MS)-((date.getDay())*this.ONE_DAY_MS));var jan1=new Date(nearestThurs.getFullYear(),0,1);var dayOfYear=((nearestThurs.getTime()-jan1.getTime())/this.ONE_DAY_MS)-1;var weekNum=Math.ceil((dayOfYear)/7);return weekNum;},isYearOverlapWeek:function(weekBeginDate){var overlaps=false;var nextWeek=this.add(weekBeginDate,this.DAY,6);if(nextWeek.getFullYear()!=weekBeginDate.getFullYear()){overlaps=true;} |
| | | return overlaps;},isMonthOverlapWeek:function(weekBeginDate){var overlaps=false;var nextWeek=this.add(weekBeginDate,this.DAY,6);if(nextWeek.getMonth()!=weekBeginDate.getMonth()){overlaps=true;} |
| | | return overlaps;},findMonthStart:function(date){var start=new Date(date.getFullYear(),date.getMonth(),1);return start;},findMonthEnd:function(date){var start=this.findMonthStart(date);var nextMonth=this.add(start,this.MONTH,1);var end=this.subtract(nextMonth,this.DAY,1);return end;},clearTime:function(date){date.setHours(12,0,0,0);return date;}};YAHOO.widget.Calendar=function(id,containerId,config){this.init(id,containerId,config);};YAHOO.widget.Calendar.IMG_ROOT=null;YAHOO.widget.Calendar.DATE="D";YAHOO.widget.Calendar.MONTH_DAY="MD";YAHOO.widget.Calendar.WEEKDAY="WD";YAHOO.widget.Calendar.RANGE="R";YAHOO.widget.Calendar.MONTH="M";YAHOO.widget.Calendar.DISPLAY_DAYS=42;YAHOO.widget.Calendar.STOP_RENDER="S";YAHOO.widget.Calendar.prototype={Config:null,parent:null,index:-1,cells:null,cellDates:null,id:null,oDomContainer:null,today:null,renderStack:null,_renderStack:null,_selectedDates:null,domEventMap:null};YAHOO.widget.Calendar.prototype.init=function(id,containerId,config){this.initEvents();this.today=new Date();YAHOO.widget.DateMath.clearTime(this.today);this.id=id;this.oDomContainer=document.getElementById(containerId);this.cfg=new YAHOO.util.Config(this);this.Options={};this.Locale={};this.initStyles();YAHOO.util.Dom.addClass(this.oDomContainer,this.Style.CSS_CONTAINER);YAHOO.util.Dom.addClass(this.oDomContainer,this.Style.CSS_SINGLE);this.cellDates=[];this.cells=[];this.renderStack=[];this._renderStack=[];this.setupConfig();if(config){this.cfg.applyConfig(config,true);} |
| | | this.cfg.fireQueue();};YAHOO.widget.Calendar.prototype.configIframe=function(type,args,obj){var useIframe=args[0];if(YAHOO.util.Dom.inDocument(this.oDomContainer)){if(useIframe){var pos=YAHOO.util.Dom.getStyle(this.oDomContainer,"position");if(this.browser=="ie"&&(pos=="absolute"||pos=="relative")){if(!YAHOO.util.Dom.inDocument(this.iframe)){this.iframe=document.createElement("iframe");this.iframe.src="javascript:false;";YAHOO.util.Dom.setStyle(this.iframe,"opacity","0");this.oDomContainer.insertBefore(this.iframe,this.oDomContainer.firstChild);}}}else{if(this.iframe){if(this.iframe.parentNode){this.iframe.parentNode.removeChild(this.iframe);} |
| | | this.iframe=null;}}}};YAHOO.widget.Calendar.prototype.configTitle=function(type,args,obj){var title=args[0];var close=this.cfg.getProperty("close");var titleDiv;if(title&&title!==""){titleDiv=YAHOO.util.Dom.getElementsByClassName(YAHOO.widget.CalendarGroup.CSS_2UPTITLE,"div",this.oDomContainer)[0]||document.createElement("div");titleDiv.className=YAHOO.widget.CalendarGroup.CSS_2UPTITLE;titleDiv.innerHTML=title;this.oDomContainer.insertBefore(titleDiv,this.oDomContainer.firstChild);YAHOO.util.Dom.addClass(this.oDomContainer,"withtitle");}else{titleDiv=YAHOO.util.Dom.getElementsByClassName(YAHOO.widget.CalendarGroup.CSS_2UPTITLE,"div",this.oDomContainer)[0]||null;if(titleDiv){YAHOO.util.Event.purgeElement(titleDiv);this.oDomContainer.removeChild(titleDiv);} |
| | | if(!close){YAHOO.util.Dom.removeClass(this.oDomContainer,"withtitle");}}};YAHOO.widget.Calendar.prototype.configClose=function(type,args,obj){var close=args[0];var title=this.cfg.getProperty("title");var DEPR_CLOSE_PATH="us/my/bn/x_d.gif";var linkClose;if(close===true){linkClose=YAHOO.util.Dom.getElementsByClassName("link-close","a",this.oDomContainer)[0]||document.createElement("a");linkClose.href="javascript:void(null);";linkClose.className="link-close";YAHOO.util.Event.addListener(linkClose,"click",this.hide,this,true);if(YAHOO.widget.Calendar.IMG_ROOT!==null){var imgClose=document.createElement("img");imgClose.src=YAHOO.widget.Calendar.IMG_ROOT+DEPR_CLOSE_PATH;imgClose.className=YAHOO.widget.CalendarGroup.CSS_2UPCLOSE;linkClose.appendChild(imgClose);}else{linkClose.innerHTML='<span class="'+YAHOO.widget.CalendarGroup.CSS_2UPCLOSE+' '+this.Style.CSS_CLOSE+'"></span>';} |
| | | this.oDomContainer.appendChild(linkClose);YAHOO.util.Dom.addClass(this.oDomContainer,"withtitle");}else{linkClose=YAHOO.util.Dom.getElementsByClassName("link-close","a",this.oDomContainer)[0]||null;if(linkClose){YAHOO.util.Event.purgeElement(linkClose);this.oDomContainer.removeChild(linkClose);} |
| | | if(!title||title===""){YAHOO.util.Dom.removeClass(this.oDomContainer,"withtitle");}}};YAHOO.widget.Calendar.prototype.initEvents=function(){this.beforeSelectEvent=new YAHOO.util.CustomEvent("beforeSelect");this.selectEvent=new YAHOO.util.CustomEvent("select");this.beforeDeselectEvent=new YAHOO.util.CustomEvent("beforeDeselect");this.deselectEvent=new YAHOO.util.CustomEvent("deselect");this.changePageEvent=new YAHOO.util.CustomEvent("changePage");this.beforeRenderEvent=new YAHOO.util.CustomEvent("beforeRender");this.renderEvent=new YAHOO.util.CustomEvent("render");this.resetEvent=new YAHOO.util.CustomEvent("reset");this.clearEvent=new YAHOO.util.CustomEvent("clear");this.beforeSelectEvent.subscribe(this.onBeforeSelect,this,true);this.selectEvent.subscribe(this.onSelect,this,true);this.beforeDeselectEvent.subscribe(this.onBeforeDeselect,this,true);this.deselectEvent.subscribe(this.onDeselect,this,true);this.changePageEvent.subscribe(this.onChangePage,this,true);this.renderEvent.subscribe(this.onRender,this,true);this.resetEvent.subscribe(this.onReset,this,true);this.clearEvent.subscribe(this.onClear,this,true);};YAHOO.widget.Calendar.prototype.doSelectCell=function(e,cal){var target=YAHOO.util.Event.getTarget(e);var cell,index,d,date;while(target.tagName.toLowerCase()!="td"&&!YAHOO.util.Dom.hasClass(target,cal.Style.CSS_CELL_SELECTABLE)){target=target.parentNode;if(target.tagName.toLowerCase()=="html"){return;}} |
| | | cell=target;if(YAHOO.util.Dom.hasClass(cell,cal.Style.CSS_CELL_SELECTABLE)){index=cell.id.split("cell")[1];d=cal.cellDates[index];date=new Date(d[0],d[1]-1,d[2]);var link;if(cal.Options.MULTI_SELECT){link=cell.getElementsByTagName("a")[0];if(link){link.blur();} |
| | | var cellDate=cal.cellDates[index];var cellDateIndex=cal._indexOfSelectedFieldArray(cellDate);if(cellDateIndex>-1){cal.deselectCell(index);}else{cal.selectCell(index);}}else{link=cell.getElementsByTagName("a")[0];if(link){link.blur();} |
| | | cal.selectCell(index);}}};YAHOO.widget.Calendar.prototype.doCellMouseOver=function(e,cal){var target;if(e){target=YAHOO.util.Event.getTarget(e);}else{target=this;} |
| | | while(target.tagName.toLowerCase()!="td"){target=target.parentNode;if(target.tagName.toLowerCase()=="html"){return;}} |
| | | if(YAHOO.util.Dom.hasClass(target,cal.Style.CSS_CELL_SELECTABLE)){YAHOO.util.Dom.addClass(target,cal.Style.CSS_CELL_HOVER);}};YAHOO.widget.Calendar.prototype.doCellMouseOut=function(e,cal){var target;if(e){target=YAHOO.util.Event.getTarget(e);}else{target=this;} |
| | | while(target.tagName.toLowerCase()!="td"){target=target.parentNode;if(target.tagName.toLowerCase()=="html"){return;}} |
| | | if(YAHOO.util.Dom.hasClass(target,cal.Style.CSS_CELL_SELECTABLE)){YAHOO.util.Dom.removeClass(target,cal.Style.CSS_CELL_HOVER);}};YAHOO.widget.Calendar.prototype.setupConfig=function(){this.cfg.addProperty("pagedate",{value:new Date(),handler:this.configPageDate});this.cfg.addProperty("selected",{value:[],handler:this.configSelected});this.cfg.addProperty("title",{value:"",handler:this.configTitle});this.cfg.addProperty("close",{value:false,handler:this.configClose});this.cfg.addProperty("iframe",{value:true,handler:this.configIframe,validator:this.cfg.checkBoolean});this.cfg.addProperty("mindate",{value:null,handler:this.configMinDate});this.cfg.addProperty("maxdate",{value:null,handler:this.configMaxDate});this.cfg.addProperty("MULTI_SELECT",{value:false,handler:this.configOptions,validator:this.cfg.checkBoolean});this.cfg.addProperty("START_WEEKDAY",{value:0,handler:this.configOptions,validator:this.cfg.checkNumber});this.cfg.addProperty("SHOW_WEEKDAYS",{value:true,handler:this.configOptions,validator:this.cfg.checkBoolean});this.cfg.addProperty("SHOW_WEEK_HEADER",{value:false,handler:this.configOptions,validator:this.cfg.checkBoolean});this.cfg.addProperty("SHOW_WEEK_FOOTER",{value:false,handler:this.configOptions,validator:this.cfg.checkBoolean});this.cfg.addProperty("HIDE_BLANK_WEEKS",{value:false,handler:this.configOptions,validator:this.cfg.checkBoolean});this.cfg.addProperty("NAV_ARROW_LEFT",{value:null,handler:this.configOptions});this.cfg.addProperty("NAV_ARROW_RIGHT",{value:null,handler:this.configOptions});this.cfg.addProperty("MONTHS_SHORT",{value:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],handler:this.configLocale});this.cfg.addProperty("MONTHS_LONG",{value:["January","February","March","April","May","June","July","August","September","October","November","December"],handler:this.configLocale});this.cfg.addProperty("WEEKDAYS_1CHAR",{value:["S","M","T","W","T","F","S"],handler:this.configLocale});this.cfg.addProperty("WEEKDAYS_SHORT",{value:["Su","Mo","Tu","We","Th","Fr","Sa"],handler:this.configLocale});this.cfg.addProperty("WEEKDAYS_MEDIUM",{value:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],handler:this.configLocale});this.cfg.addProperty("WEEKDAYS_LONG",{value:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],handler:this.configLocale});var refreshLocale=function(){this.cfg.refireEvent("LOCALE_MONTHS");this.cfg.refireEvent("LOCALE_WEEKDAYS");};this.cfg.subscribeToConfigEvent("START_WEEKDAY",refreshLocale,this,true);this.cfg.subscribeToConfigEvent("MONTHS_SHORT",refreshLocale,this,true);this.cfg.subscribeToConfigEvent("MONTHS_LONG",refreshLocale,this,true);this.cfg.subscribeToConfigEvent("WEEKDAYS_1CHAR",refreshLocale,this,true);this.cfg.subscribeToConfigEvent("WEEKDAYS_SHORT",refreshLocale,this,true);this.cfg.subscribeToConfigEvent("WEEKDAYS_MEDIUM",refreshLocale,this,true);this.cfg.subscribeToConfigEvent("WEEKDAYS_LONG",refreshLocale,this,true);this.cfg.addProperty("LOCALE_MONTHS",{value:"long",handler:this.configLocaleValues});this.cfg.addProperty("LOCALE_WEEKDAYS",{value:"short",handler:this.configLocaleValues});this.cfg.addProperty("DATE_DELIMITER",{value:",",handler:this.configLocale});this.cfg.addProperty("DATE_FIELD_DELIMITER",{value:"/",handler:this.configLocale});this.cfg.addProperty("DATE_RANGE_DELIMITER",{value:"-",handler:this.configLocale});this.cfg.addProperty("MY_MONTH_POSITION",{value:1,handler:this.configLocale,validator:this.cfg.checkNumber});this.cfg.addProperty("MY_YEAR_POSITION",{value:2,handler:this.configLocale,validator:this.cfg.checkNumber});this.cfg.addProperty("MD_MONTH_POSITION",{value:1,handler:this.configLocale,validator:this.cfg.checkNumber});this.cfg.addProperty("MD_DAY_POSITION",{value:2,handler:this.configLocale,validator:this.cfg.checkNumber});this.cfg.addProperty("MDY_MONTH_POSITION",{value:1,handler:this.configLocale,validator:this.cfg.checkNumber});this.cfg.addProperty("MDY_DAY_POSITION",{value:2,handler:this.configLocale,validator:this.cfg.checkNumber});this.cfg.addProperty("MDY_YEAR_POSITION",{value:3,handler:this.configLocale,validator:this.cfg.checkNumber});};YAHOO.widget.Calendar.prototype.configPageDate=function(type,args,obj){this.cfg.setProperty("pagedate",this._parsePageDate(args[0]),true);};YAHOO.widget.Calendar.prototype.configMinDate=function(type,args,obj){var val=args[0];if(typeof val=='string'){val=this._parseDate(val);this.cfg.setProperty("mindate",new Date(val[0],(val[1]-1),val[2]));}};YAHOO.widget.Calendar.prototype.configMaxDate=function(type,args,obj){var val=args[0];if(typeof val=='string'){val=this._parseDate(val);this.cfg.setProperty("maxdate",new Date(val[0],(val[1]-1),val[2]));}};YAHOO.widget.Calendar.prototype.configSelected=function(type,args,obj){var selected=args[0];if(selected){if(typeof selected=='string'){this.cfg.setProperty("selected",this._parseDates(selected),true);}} |
| | | if(!this._selectedDates){this._selectedDates=this.cfg.getProperty("selected");}};YAHOO.widget.Calendar.prototype.configOptions=function(type,args,obj){type=type.toUpperCase();var val=args[0];this.Options[type]=val;};YAHOO.widget.Calendar.prototype.configLocale=function(type,args,obj){type=type.toUpperCase();var val=args[0];this.Locale[type]=val;this.cfg.refireEvent("LOCALE_MONTHS");this.cfg.refireEvent("LOCALE_WEEKDAYS");};YAHOO.widget.Calendar.prototype.configLocaleValues=function(type,args,obj){type=type.toUpperCase();var val=args[0];switch(type){case"LOCALE_MONTHS":switch(val){case"short":this.Locale.LOCALE_MONTHS=this.cfg.getProperty("MONTHS_SHORT").concat();break;case"long":this.Locale.LOCALE_MONTHS=this.cfg.getProperty("MONTHS_LONG").concat();break;} |
| | | break;case"LOCALE_WEEKDAYS":switch(val){case"1char":this.Locale.LOCALE_WEEKDAYS=this.cfg.getProperty("WEEKDAYS_1CHAR").concat();break;case"short":this.Locale.LOCALE_WEEKDAYS=this.cfg.getProperty("WEEKDAYS_SHORT").concat();break;case"medium":this.Locale.LOCALE_WEEKDAYS=this.cfg.getProperty("WEEKDAYS_MEDIUM").concat();break;case"long":this.Locale.LOCALE_WEEKDAYS=this.cfg.getProperty("WEEKDAYS_LONG").concat();break;} |
| | | var START_WEEKDAY=this.cfg.getProperty("START_WEEKDAY");if(START_WEEKDAY>0){for(var w=0;w<START_WEEKDAY;++w){this.Locale.LOCALE_WEEKDAYS.push(this.Locale.LOCALE_WEEKDAYS.shift());}} |
| | | break;}};YAHOO.widget.Calendar.prototype.initStyles=function(){this.Style={CSS_ROW_HEADER:"calrowhead",CSS_ROW_FOOTER:"calrowfoot",CSS_CELL:"calcell",CSS_CELL_SELECTED:"selected",CSS_CELL_SELECTABLE:"selectable",CSS_CELL_RESTRICTED:"restricted",CSS_CELL_TODAY:"today",CSS_CELL_OOM:"oom",CSS_CELL_OOB:"previous",CSS_HEADER:"calheader",CSS_HEADER_TEXT:"calhead",CSS_BODY:"calbody",CSS_WEEKDAY_CELL:"calweekdaycell",CSS_WEEKDAY_ROW:"calweekdayrow",CSS_FOOTER:"calfoot",CSS_CALENDAR:"yui-calendar",CSS_SINGLE:"single",CSS_CONTAINER:"yui-calcontainer",CSS_NAV_LEFT:"calnavleft",CSS_NAV_RIGHT:"calnavright",CSS_CLOSE:"calclose",CSS_CELL_TOP:"calcelltop",CSS_CELL_LEFT:"calcellleft",CSS_CELL_RIGHT:"calcellright",CSS_CELL_BOTTOM:"calcellbottom",CSS_CELL_HOVER:"calcellhover",CSS_CELL_HIGHLIGHT1:"highlight1",CSS_CELL_HIGHLIGHT2:"highlight2",CSS_CELL_HIGHLIGHT3:"highlight3",CSS_CELL_HIGHLIGHT4:"highlight4"};};YAHOO.widget.Calendar.prototype.buildMonthLabel=function(){var text=this.Locale.LOCALE_MONTHS[this.cfg.getProperty("pagedate").getMonth()]+" "+this.cfg.getProperty("pagedate").getFullYear();return text;};YAHOO.widget.Calendar.prototype.buildDayLabel=function(workingDate){var day=workingDate.getDate();return day;};YAHOO.widget.Calendar.prototype.renderHeader=function(html){var colSpan=7;var DEPR_NAV_LEFT="us/tr/callt.gif";var DEPR_NAV_RIGHT="us/tr/calrt.gif";if(this.cfg.getProperty("SHOW_WEEK_HEADER")){colSpan+=1;} |
| | | if(this.cfg.getProperty("SHOW_WEEK_FOOTER")){colSpan+=1;} |
| | | html[html.length]="<thead>";html[html.length]="<tr>";html[html.length]='<th colspan="'+colSpan+'" class="'+this.Style.CSS_HEADER_TEXT+'">';html[html.length]='<div class="'+this.Style.CSS_HEADER+'">';var renderLeft,renderRight=false;if(this.parent){if(this.index===0){renderLeft=true;} |
| | | if(this.index==(this.parent.cfg.getProperty("pages")-1)){renderRight=true;}}else{renderLeft=true;renderRight=true;} |
| | | var cal=this.parent||this;if(renderLeft){var leftArrow=this.cfg.getProperty("NAV_ARROW_LEFT");if(leftArrow===null&&YAHOO.widget.Calendar.IMG_ROOT!==null){leftArrow=YAHOO.widget.Calendar.IMG_ROOT+DEPR_NAV_LEFT;} |
| | | var leftStyle=(leftArrow===null)?"":' style="background-image:url('+leftArrow+')"';html[html.length]='<a class="'+this.Style.CSS_NAV_LEFT+'"'+leftStyle+' > </a>';} |
| | | html[html.length]=this.buildMonthLabel();if(renderRight){var rightArrow=this.cfg.getProperty("NAV_ARROW_RIGHT");if(rightArrow===null&&YAHOO.widget.Calendar.IMG_ROOT!==null){rightArrow=YAHOO.widget.Calendar.IMG_ROOT+DEPR_NAV_RIGHT;} |
| | | var rightStyle=(rightArrow===null)?"":' style="background-image:url('+rightArrow+')"';html[html.length]='<a class="'+this.Style.CSS_NAV_RIGHT+'"'+rightStyle+' > </a>';} |
| | | html[html.length]='</div>';html[html.length]='</th>';html[html.length]='</tr>';if(this.cfg.getProperty("SHOW_WEEKDAYS")){html=this.buildWeekdays(html);} |
| | | html[html.length]='</thead>';return html;};YAHOO.widget.Calendar.prototype.buildWeekdays=function(html){html[html.length]='<tr class="'+this.Style.CSS_WEEKDAY_ROW+'">';if(this.cfg.getProperty("SHOW_WEEK_HEADER")){html[html.length]='<th> </th>';} |
| | | for(var i=0;i<this.Locale.LOCALE_WEEKDAYS.length;++i){html[html.length]='<th class="calweekdaycell">'+this.Locale.LOCALE_WEEKDAYS[i]+'</th>';} |
| | | if(this.cfg.getProperty("SHOW_WEEK_FOOTER")){html[html.length]='<th> </th>';} |
| | | html[html.length]='</tr>';return html;};YAHOO.widget.Calendar.prototype.renderBody=function(workingDate,html){var startDay=this.cfg.getProperty("START_WEEKDAY");this.preMonthDays=workingDate.getDay();if(startDay>0){this.preMonthDays-=startDay;} |
| | | if(this.preMonthDays<0){this.preMonthDays+=7;} |
| | | this.monthDays=YAHOO.widget.DateMath.findMonthEnd(workingDate).getDate();this.postMonthDays=YAHOO.widget.Calendar.DISPLAY_DAYS-this.preMonthDays-this.monthDays;workingDate=YAHOO.widget.DateMath.subtract(workingDate,YAHOO.widget.DateMath.DAY,this.preMonthDays);var useDate,weekNum,weekClass;useDate=this.cfg.getProperty("pagedate");html[html.length]='<tbody class="m'+(useDate.getMonth()+1)+' '+this.Style.CSS_BODY+'">';var i=0;var tempDiv=document.createElement("div");var cell=document.createElement("td");tempDiv.appendChild(cell);var jan1=new Date(useDate.getFullYear(),0,1);var cal=this.parent||this;for(var r=0;r<6;r++){weekNum=YAHOO.widget.DateMath.getWeekNumber(workingDate,useDate.getFullYear(),startDay);weekClass="w"+weekNum;if(r!==0&&this.isDateOOM(workingDate)&&this.cfg.getProperty("HIDE_BLANK_WEEKS")===true){break;}else{html[html.length]='<tr class="'+weekClass+'">';if(this.cfg.getProperty("SHOW_WEEK_HEADER")){html=this.renderRowHeader(weekNum,html);} |
| | | for(var d=0;d<7;d++){var cellRenderers=[];this.clearElement(cell);YAHOO.util.Dom.addClass(cell,"calcell");cell.id=this.id+"_cell"+i;cell.innerHTML=i;var renderer=null;if(workingDate.getFullYear()==this.today.getFullYear()&&workingDate.getMonth()==this.today.getMonth()&&workingDate.getDate()==this.today.getDate()){cellRenderers[cellRenderers.length]=cal.renderCellStyleToday;} |
| | | this.cellDates[this.cellDates.length]=[workingDate.getFullYear(),workingDate.getMonth()+1,workingDate.getDate()];if(this.isDateOOM(workingDate)){cellRenderers[cellRenderers.length]=cal.renderCellNotThisMonth;}else{YAHOO.util.Dom.addClass(cell,"wd"+workingDate.getDay());YAHOO.util.Dom.addClass(cell,"d"+workingDate.getDate());for(var s=0;s<this.renderStack.length;++s){var rArray=this.renderStack[s];var type=rArray[0];var month;var day;var year;switch(type){case YAHOO.widget.Calendar.DATE:month=rArray[1][1];day=rArray[1][2];year=rArray[1][0];if(workingDate.getMonth()+1==month&&workingDate.getDate()==day&&workingDate.getFullYear()==year){renderer=rArray[2];this.renderStack.splice(s,1);} |
| | | break;case YAHOO.widget.Calendar.MONTH_DAY:month=rArray[1][0];day=rArray[1][1];if(workingDate.getMonth()+1==month&&workingDate.getDate()==day){renderer=rArray[2];this.renderStack.splice(s,1);} |
| | | break;case YAHOO.widget.Calendar.RANGE:var date1=rArray[1][0];var date2=rArray[1][1];var d1month=date1[1];var d1day=date1[2];var d1year=date1[0];var d1=new Date(d1year,d1month-1,d1day);var d2month=date2[1];var d2day=date2[2];var d2year=date2[0];var d2=new Date(d2year,d2month-1,d2day);if(workingDate.getTime()>=d1.getTime()&&workingDate.getTime()<=d2.getTime()){renderer=rArray[2];if(workingDate.getTime()==d2.getTime()){this.renderStack.splice(s,1);}} |
| | | break;case YAHOO.widget.Calendar.WEEKDAY:var weekday=rArray[1][0];if(workingDate.getDay()+1==weekday){renderer=rArray[2];} |
| | | break;case YAHOO.widget.Calendar.MONTH:month=rArray[1][0];if(workingDate.getMonth()+1==month){renderer=rArray[2];} |
| | | break;} |
| | | if(renderer){cellRenderers[cellRenderers.length]=renderer;}}} |
| | | if(this._indexOfSelectedFieldArray([workingDate.getFullYear(),workingDate.getMonth()+1,workingDate.getDate()])>-1){cellRenderers[cellRenderers.length]=cal.renderCellStyleSelected;} |
| | | var mindate=this.cfg.getProperty("mindate");var maxdate=this.cfg.getProperty("maxdate");if(mindate){mindate=YAHOO.widget.DateMath.clearTime(mindate);} |
| | | if(maxdate){maxdate=YAHOO.widget.DateMath.clearTime(maxdate);} |
| | | if((mindate&&(workingDate.getTime()<mindate.getTime()))||(maxdate&&(workingDate.getTime()>maxdate.getTime()))){cellRenderers[cellRenderers.length]=cal.renderOutOfBoundsDate;}else{cellRenderers[cellRenderers.length]=cal.styleCellDefault;cellRenderers[cellRenderers.length]=cal.renderCellDefault;} |
| | | for(var x=0;x<cellRenderers.length;++x){var ren=cellRenderers[x];if(ren.call((this.parent||this),workingDate,cell)==YAHOO.widget.Calendar.STOP_RENDER){break;}} |
| | | workingDate.setTime(workingDate.getTime()+YAHOO.widget.DateMath.ONE_DAY_MS);if(i>=0&&i<=6){YAHOO.util.Dom.addClass(cell,this.Style.CSS_CELL_TOP);} |
| | | if((i%7)===0){YAHOO.util.Dom.addClass(cell,this.Style.CSS_CELL_LEFT);} |
| | | if(((i+1)%7)===0){YAHOO.util.Dom.addClass(cell,this.Style.CSS_CELL_RIGHT);} |
| | | var postDays=this.postMonthDays;if(postDays>=7&&this.cfg.getProperty("HIDE_BLANK_WEEKS")){var blankWeeks=Math.floor(postDays/7);for(var p=0;p<blankWeeks;++p){postDays-=7;}} |
| | | if(i>=((this.preMonthDays+postDays+this.monthDays)-7)){YAHOO.util.Dom.addClass(cell,this.Style.CSS_CELL_BOTTOM);} |
| | | html[html.length]=tempDiv.innerHTML;i++;} |
| | | if(this.cfg.getProperty("SHOW_WEEK_FOOTER")){html=this.renderRowFooter(weekNum,html);} |
| | | html[html.length]='</tr>';}} |
| | | html[html.length]='</tbody>';return html;};YAHOO.widget.Calendar.prototype.renderFooter=function(html){return html;};YAHOO.widget.Calendar.prototype.render=function(){this.beforeRenderEvent.fire();var workingDate=YAHOO.widget.DateMath.findMonthStart(this.cfg.getProperty("pagedate"));this.resetRenderers();this.cellDates.length=0;YAHOO.util.Event.purgeElement(this.oDomContainer,true);var html=[];html[html.length]='<table cellSpacing="0" class="'+this.Style.CSS_CALENDAR+' y'+workingDate.getFullYear()+'" id="'+this.id+'">';html=this.renderHeader(html);html=this.renderBody(workingDate,html);html=this.renderFooter(html);html[html.length]='</table>';this.oDomContainer.innerHTML=html.join("\n");this.applyListeners();this.cells=this.oDomContainer.getElementsByTagName("td");this.cfg.refireEvent("title");this.cfg.refireEvent("close");this.cfg.refireEvent("iframe");this.renderEvent.fire();};YAHOO.widget.Calendar.prototype.applyListeners=function(){var root=this.oDomContainer;var cal=this.parent||this;var linkLeft,linkRight;linkLeft=YAHOO.util.Dom.getElementsByClassName(this.Style.CSS_NAV_LEFT,"a",root);linkRight=YAHOO.util.Dom.getElementsByClassName(this.Style.CSS_NAV_RIGHT,"a",root);if(linkLeft){this.linkLeft=linkLeft[0];YAHOO.util.Event.addListener(this.linkLeft,"mousedown",cal.previousMonth,cal,true);} |
| | | if(linkRight){this.linkRight=linkRight[0];YAHOO.util.Event.addListener(this.linkRight,"mousedown",cal.nextMonth,cal,true);} |
| | | if(this.domEventMap){var el,elements;for(var cls in this.domEventMap){if(YAHOO.lang.hasOwnProperty(this.domEventMap,cls)){var items=this.domEventMap[cls];if(!(items instanceof Array)){items=[items];} |
| | | for(var i=0;i<items.length;i++){var item=items[i];elements=YAHOO.util.Dom.getElementsByClassName(cls,item.tag,this.oDomContainer);for(var c=0;c<elements.length;c++){el=elements[c];YAHOO.util.Event.addListener(el,item.event,item.handler,item.scope,item.correct);}}}}} |
| | | YAHOO.util.Event.addListener(this.oDomContainer,"click",this.doSelectCell,this);YAHOO.util.Event.addListener(this.oDomContainer,"mouseover",this.doCellMouseOver,this);YAHOO.util.Event.addListener(this.oDomContainer,"mouseout",this.doCellMouseOut,this);};YAHOO.widget.Calendar.prototype.getDateByCellId=function(id){var date=this.getDateFieldsByCellId(id);return new Date(date[0],date[1]-1,date[2]);};YAHOO.widget.Calendar.prototype.getDateFieldsByCellId=function(id){id=id.toLowerCase().split("_cell")[1];id=parseInt(id,10);return this.cellDates[id];};YAHOO.widget.Calendar.prototype.renderOutOfBoundsDate=function(workingDate,cell){YAHOO.util.Dom.addClass(cell,this.Style.CSS_CELL_OOB);cell.innerHTML=workingDate.getDate();return YAHOO.widget.Calendar.STOP_RENDER;};YAHOO.widget.Calendar.prototype.renderRowHeader=function(weekNum,html){html[html.length]='<th class="calrowhead">'+weekNum+'</th>';return html;};YAHOO.widget.Calendar.prototype.renderRowFooter=function(weekNum,html){html[html.length]='<th class="calrowfoot">'+weekNum+'</th>';return html;};YAHOO.widget.Calendar.prototype.renderCellDefault=function(workingDate,cell){cell.innerHTML='<a href="javascript:void(null);" >'+this.buildDayLabel(workingDate)+"</a>";};YAHOO.widget.Calendar.prototype.styleCellDefault=function(workingDate,cell){YAHOO.util.Dom.addClass(cell,this.Style.CSS_CELL_SELECTABLE);};YAHOO.widget.Calendar.prototype.renderCellStyleHighlight1=function(workingDate,cell){YAHOO.util.Dom.addClass(cell,this.Style.CSS_CELL_HIGHLIGHT1);};YAHOO.widget.Calendar.prototype.renderCellStyleHighlight2=function(workingDate,cell){YAHOO.util.Dom.addClass(cell,this.Style.CSS_CELL_HIGHLIGHT2);};YAHOO.widget.Calendar.prototype.renderCellStyleHighlight3=function(workingDate,cell){YAHOO.util.Dom.addClass(cell,this.Style.CSS_CELL_HIGHLIGHT3);};YAHOO.widget.Calendar.prototype.renderCellStyleHighlight4=function(workingDate,cell){YAHOO.util.Dom.addClass(cell,this.Style.CSS_CELL_HIGHLIGHT4);};YAHOO.widget.Calendar.prototype.renderCellStyleToday=function(workingDate,cell){YAHOO.util.Dom.addClass(cell,this.Style.CSS_CELL_TODAY);};YAHOO.widget.Calendar.prototype.renderCellStyleSelected=function(workingDate,cell){YAHOO.util.Dom.addClass(cell,this.Style.CSS_CELL_SELECTED);};YAHOO.widget.Calendar.prototype.renderCellNotThisMonth=function(workingDate,cell){YAHOO.util.Dom.addClass(cell,this.Style.CSS_CELL_OOM);cell.innerHTML=workingDate.getDate();return YAHOO.widget.Calendar.STOP_RENDER;};YAHOO.widget.Calendar.prototype.renderBodyCellRestricted=function(workingDate,cell){YAHOO.util.Dom.addClass(cell,this.Style.CSS_CELL);YAHOO.util.Dom.addClass(cell,this.Style.CSS_CELL_RESTRICTED);cell.innerHTML=workingDate.getDate();return YAHOO.widget.Calendar.STOP_RENDER;};YAHOO.widget.Calendar.prototype.addMonths=function(count){this.cfg.setProperty("pagedate",YAHOO.widget.DateMath.add(this.cfg.getProperty("pagedate"),YAHOO.widget.DateMath.MONTH,count));this.resetRenderers();this.changePageEvent.fire();};YAHOO.widget.Calendar.prototype.subtractMonths=function(count){this.cfg.setProperty("pagedate",YAHOO.widget.DateMath.subtract(this.cfg.getProperty("pagedate"),YAHOO.widget.DateMath.MONTH,count));this.resetRenderers();this.changePageEvent.fire();};YAHOO.widget.Calendar.prototype.addYears=function(count){this.cfg.setProperty("pagedate",YAHOO.widget.DateMath.add(this.cfg.getProperty("pagedate"),YAHOO.widget.DateMath.YEAR,count));this.resetRenderers();this.changePageEvent.fire();};YAHOO.widget.Calendar.prototype.subtractYears=function(count){this.cfg.setProperty("pagedate",YAHOO.widget.DateMath.subtract(this.cfg.getProperty("pagedate"),YAHOO.widget.DateMath.YEAR,count));this.resetRenderers();this.changePageEvent.fire();};YAHOO.widget.Calendar.prototype.nextMonth=function(){this.addMonths(1);};YAHOO.widget.Calendar.prototype.previousMonth=function(){this.subtractMonths(1);};YAHOO.widget.Calendar.prototype.nextYear=function(){this.addYears(1);};YAHOO.widget.Calendar.prototype.previousYear=function(){this.subtractYears(1);};YAHOO.widget.Calendar.prototype.reset=function(){this.cfg.resetProperty("selected");this.cfg.resetProperty("pagedate");this.resetEvent.fire();};YAHOO.widget.Calendar.prototype.clear=function(){this.cfg.setProperty("selected",[]);this.cfg.setProperty("pagedate",new Date(this.today.getTime()));this.clearEvent.fire();};YAHOO.widget.Calendar.prototype.select=function(date){this.beforeSelectEvent.fire();var selected=this.cfg.getProperty("selected");var aToBeSelected=this._toFieldArray(date);for(var a=0;a<aToBeSelected.length;++a){var toSelect=aToBeSelected[a];if(this._indexOfSelectedFieldArray(toSelect)==-1){selected[selected.length]=toSelect;}} |
| | | if(this.parent){this.parent.cfg.setProperty("selected",selected);}else{this.cfg.setProperty("selected",selected);} |
| | | this.selectEvent.fire(aToBeSelected);return this.getSelectedDates();};YAHOO.widget.Calendar.prototype.selectCell=function(cellIndex){this.beforeSelectEvent.fire();var selected=this.cfg.getProperty("selected");var cell=this.cells[cellIndex];var cellDate=this.cellDates[cellIndex];var dCellDate=this._toDate(cellDate);var selectDate=cellDate.concat();selected[selected.length]=selectDate;if(this.parent){this.parent.cfg.setProperty("selected",selected);}else{this.cfg.setProperty("selected",selected);} |
| | | this.renderCellStyleSelected(dCellDate,cell);this.selectEvent.fire([selectDate]);this.doCellMouseOut.call(cell,null,this);return this.getSelectedDates();};YAHOO.widget.Calendar.prototype.deselect=function(date){this.beforeDeselectEvent.fire();var selected=this.cfg.getProperty("selected");var aToBeSelected=this._toFieldArray(date);for(var a=0;a<aToBeSelected.length;++a){var toSelect=aToBeSelected[a];var index=this._indexOfSelectedFieldArray(toSelect);if(index!=-1){selected.splice(index,1);}} |
| | | if(this.parent){this.parent.cfg.setProperty("selected",selected);}else{this.cfg.setProperty("selected",selected);} |
| | | this.deselectEvent.fire(aToBeSelected);return this.getSelectedDates();};YAHOO.widget.Calendar.prototype.deselectCell=function(i){this.beforeDeselectEvent.fire();var selected=this.cfg.getProperty("selected");var cell=this.cells[i];var cellDate=this.cellDates[i];var cellDateIndex=this._indexOfSelectedFieldArray(cellDate);var dCellDate=this._toDate(cellDate);var selectDate=cellDate.concat();if(cellDateIndex>-1){if(this.cfg.getProperty("pagedate").getMonth()==dCellDate.getMonth()&&this.cfg.getProperty("pagedate").getFullYear()==dCellDate.getFullYear()){YAHOO.util.Dom.removeClass(cell,this.Style.CSS_CELL_SELECTED);} |
| | | selected.splice(cellDateIndex,1);} |
| | | if(this.parent){this.parent.cfg.setProperty("selected",selected);}else{this.cfg.setProperty("selected",selected);} |
| | | this.deselectEvent.fire(selectDate);return this.getSelectedDates();};YAHOO.widget.Calendar.prototype.deselectAll=function(){this.beforeDeselectEvent.fire();var selected=this.cfg.getProperty("selected");var count=selected.length;var sel=selected.concat();if(this.parent){this.parent.cfg.setProperty("selected",[]);}else{this.cfg.setProperty("selected",[]);} |
| | | if(count>0){this.deselectEvent.fire(sel);} |
| | | return this.getSelectedDates();};YAHOO.widget.Calendar.prototype._toFieldArray=function(date){var returnDate=[];if(date instanceof Date){returnDate=[[date.getFullYear(),date.getMonth()+1,date.getDate()]];}else if(typeof date=='string'){returnDate=this._parseDates(date);}else if(date instanceof Array){for(var i=0;i<date.length;++i){var d=date[i];returnDate[returnDate.length]=[d.getFullYear(),d.getMonth()+1,d.getDate()];}} |
| | | return returnDate;};YAHOO.widget.Calendar.prototype._toDate=function(dateFieldArray){if(dateFieldArray instanceof Date){return dateFieldArray;}else{return new Date(dateFieldArray[0],dateFieldArray[1]-1,dateFieldArray[2]);}};YAHOO.widget.Calendar.prototype._fieldArraysAreEqual=function(array1,array2){var match=false;if(array1[0]==array2[0]&&array1[1]==array2[1]&&array1[2]==array2[2]){match=true;} |
| | | return match;};YAHOO.widget.Calendar.prototype._indexOfSelectedFieldArray=function(find){var selected=-1;var seldates=this.cfg.getProperty("selected");for(var s=0;s<seldates.length;++s){var sArray=seldates[s];if(find[0]==sArray[0]&&find[1]==sArray[1]&&find[2]==sArray[2]){selected=s;break;}} |
| | | return selected;};YAHOO.widget.Calendar.prototype.isDateOOM=function(date){var isOOM=false;if(date.getMonth()!=this.cfg.getProperty("pagedate").getMonth()){isOOM=true;} |
| | | return isOOM;};YAHOO.widget.Calendar.prototype._parsePageDate=function(date){var parsedDate;if(date){if(date instanceof Date){parsedDate=YAHOO.widget.DateMath.findMonthStart(date);}else{var month,year,aMonthYear;aMonthYear=date.split(this.cfg.getProperty("DATE_FIELD_DELIMITER"));month=parseInt(aMonthYear[this.cfg.getProperty("MY_MONTH_POSITION")-1],10)-1;year=parseInt(aMonthYear[this.cfg.getProperty("MY_YEAR_POSITION")-1],10);parsedDate=new Date(year,month,1);}}else{parsedDate=new Date(this.today.getFullYear(),this.today.getMonth(),1);} |
| | | return parsedDate;};YAHOO.widget.Calendar.prototype.onBeforeSelect=function(){if(this.cfg.getProperty("MULTI_SELECT")===false){if(this.parent){this.parent.callChildFunction("clearAllBodyCellStyles",this.Style.CSS_CELL_SELECTED);this.parent.deselectAll();}else{this.clearAllBodyCellStyles(this.Style.CSS_CELL_SELECTED);this.deselectAll();}}};YAHOO.widget.Calendar.prototype.onSelect=function(selected){};YAHOO.widget.Calendar.prototype.onBeforeDeselect=function(){};YAHOO.widget.Calendar.prototype.onDeselect=function(deselected){};YAHOO.widget.Calendar.prototype.onChangePage=function(){this.render();};YAHOO.widget.Calendar.prototype.onRender=function(){};YAHOO.widget.Calendar.prototype.onReset=function(){this.render();};YAHOO.widget.Calendar.prototype.onClear=function(){this.render();};YAHOO.widget.Calendar.prototype.validate=function(){return true;};YAHOO.widget.Calendar.prototype._parseDate=function(sDate){var aDate=sDate.split(this.Locale.DATE_FIELD_DELIMITER);var rArray;if(aDate.length==2){rArray=[aDate[this.Locale.MD_MONTH_POSITION-1],aDate[this.Locale.MD_DAY_POSITION-1]];rArray.type=YAHOO.widget.Calendar.MONTH_DAY;}else{rArray=[aDate[this.Locale.MDY_YEAR_POSITION-1],aDate[this.Locale.MDY_MONTH_POSITION-1],aDate[this.Locale.MDY_DAY_POSITION-1]];rArray.type=YAHOO.widget.Calendar.DATE;} |
| | | for(var i=0;i<rArray.length;i++){rArray[i]=parseInt(rArray[i],10);} |
| | | return rArray;};YAHOO.widget.Calendar.prototype._parseDates=function(sDates){var aReturn=[];var aDates=sDates.split(this.Locale.DATE_DELIMITER);for(var d=0;d<aDates.length;++d){var sDate=aDates[d];if(sDate.indexOf(this.Locale.DATE_RANGE_DELIMITER)!=-1){var aRange=sDate.split(this.Locale.DATE_RANGE_DELIMITER);var dateStart=this._parseDate(aRange[0]);var dateEnd=this._parseDate(aRange[1]);var fullRange=this._parseRange(dateStart,dateEnd);aReturn=aReturn.concat(fullRange);}else{var aDate=this._parseDate(sDate);aReturn.push(aDate);}} |
| | | return aReturn;};YAHOO.widget.Calendar.prototype._parseRange=function(startDate,endDate){var dStart=new Date(startDate[0],startDate[1]-1,startDate[2]);var dCurrent=YAHOO.widget.DateMath.add(new Date(startDate[0],startDate[1]-1,startDate[2]),YAHOO.widget.DateMath.DAY,1);var dEnd=new Date(endDate[0],endDate[1]-1,endDate[2]);var results=[];results.push(startDate);while(dCurrent.getTime()<=dEnd.getTime()){results.push([dCurrent.getFullYear(),dCurrent.getMonth()+1,dCurrent.getDate()]);dCurrent=YAHOO.widget.DateMath.add(dCurrent,YAHOO.widget.DateMath.DAY,1);} |
| | | return results;};YAHOO.widget.Calendar.prototype.resetRenderers=function(){this.renderStack=this._renderStack.concat();};YAHOO.widget.Calendar.prototype.clearElement=function(cell){cell.innerHTML=" ";cell.className="";};YAHOO.widget.Calendar.prototype.addRenderer=function(sDates,fnRender){var aDates=this._parseDates(sDates);for(var i=0;i<aDates.length;++i){var aDate=aDates[i];if(aDate.length==2){if(aDate[0]instanceof Array){this._addRenderer(YAHOO.widget.Calendar.RANGE,aDate,fnRender);}else{this._addRenderer(YAHOO.widget.Calendar.MONTH_DAY,aDate,fnRender);}}else if(aDate.length==3){this._addRenderer(YAHOO.widget.Calendar.DATE,aDate,fnRender);}}};YAHOO.widget.Calendar.prototype._addRenderer=function(type,aDates,fnRender){var add=[type,aDates,fnRender];this.renderStack.unshift(add);this._renderStack=this.renderStack.concat();};YAHOO.widget.Calendar.prototype.addMonthRenderer=function(month,fnRender){this._addRenderer(YAHOO.widget.Calendar.MONTH,[month],fnRender);};YAHOO.widget.Calendar.prototype.addWeekdayRenderer=function(weekday,fnRender){this._addRenderer(YAHOO.widget.Calendar.WEEKDAY,[weekday],fnRender);};YAHOO.widget.Calendar.prototype.clearAllBodyCellStyles=function(style){for(var c=0;c<this.cells.length;++c){YAHOO.util.Dom.removeClass(this.cells[c],style);}};YAHOO.widget.Calendar.prototype.setMonth=function(month){var current=this.cfg.getProperty("pagedate");current.setMonth(parseInt(month,10));this.cfg.setProperty("pagedate",current);};YAHOO.widget.Calendar.prototype.setYear=function(year){var current=this.cfg.getProperty("pagedate");current.setFullYear(parseInt(year,10));this.cfg.setProperty("pagedate",current);};YAHOO.widget.Calendar.prototype.getSelectedDates=function(){var returnDates=[];var selected=this.cfg.getProperty("selected");for(var d=0;d<selected.length;++d){var dateArray=selected[d];var date=new Date(dateArray[0],dateArray[1]-1,dateArray[2]);returnDates.push(date);} |
| | | returnDates.sort(function(a,b){return a-b;});return returnDates;};YAHOO.widget.Calendar.prototype.hide=function(){this.oDomContainer.style.display="none";};YAHOO.widget.Calendar.prototype.show=function(){this.oDomContainer.style.display="block";};YAHOO.widget.Calendar.prototype.browser=function(){var ua=navigator.userAgent.toLowerCase();if(ua.indexOf('opera')!=-1){return'opera';}else if(ua.indexOf('msie 7')!=-1){return'ie7';}else if(ua.indexOf('msie')!=-1){return'ie';}else if(ua.indexOf('safari')!=-1){return'safari';}else if(ua.indexOf('gecko')!=-1){return'gecko';}else{return false;}}();YAHOO.widget.Calendar.prototype.toString=function(){return"Calendar "+this.id;};YAHOO.widget.Calendar_Core=YAHOO.widget.Calendar;YAHOO.widget.Cal_Core=YAHOO.widget.Calendar;YAHOO.widget.CalendarGroup=function(id,containerId,config){if(arguments.length>0){this.init(id,containerId,config);}};YAHOO.widget.CalendarGroup.prototype.init=function(id,containerId,config){this.initEvents();this.initStyles();this.pages=[];this.id=id;this.containerId=containerId;this.oDomContainer=document.getElementById(containerId);YAHOO.util.Dom.addClass(this.oDomContainer,YAHOO.widget.CalendarGroup.CSS_CONTAINER);YAHOO.util.Dom.addClass(this.oDomContainer,YAHOO.widget.CalendarGroup.CSS_MULTI_UP);this.cfg=new YAHOO.util.Config(this);this.Options={};this.Locale={};this.setupConfig();if(config){this.cfg.applyConfig(config,true);} |
| | | this.cfg.fireQueue();if(this.browser=="opera"){var fixWidth=function(){var startW=this.oDomContainer.offsetWidth;var w=0;for(var p=0;p<this.pages.length;++p){var cal=this.pages[p];w+=cal.oDomContainer.offsetWidth;} |
| | | if(w>0){this.oDomContainer.style.width=w+"px";}};this.renderEvent.subscribe(fixWidth,this,true);}};YAHOO.widget.CalendarGroup.prototype.setupConfig=function(){this.cfg.addProperty("pages",{value:2,validator:this.cfg.checkNumber,handler:this.configPages});this.cfg.addProperty("pagedate",{value:new Date(),handler:this.configPageDate});this.cfg.addProperty("selected",{value:[],handler:this.delegateConfig});this.cfg.addProperty("title",{value:"",handler:this.configTitle});this.cfg.addProperty("close",{value:false,handler:this.configClose});this.cfg.addProperty("iframe",{value:true,handler:this.delegateConfig,validator:this.cfg.checkBoolean});this.cfg.addProperty("mindate",{value:null,handler:this.delegateConfig});this.cfg.addProperty("maxdate",{value:null,handler:this.delegateConfig});this.cfg.addProperty("MULTI_SELECT",{value:false,handler:this.delegateConfig,validator:this.cfg.checkBoolean});this.cfg.addProperty("START_WEEKDAY",{value:0,handler:this.delegateConfig,validator:this.cfg.checkNumber});this.cfg.addProperty("SHOW_WEEKDAYS",{value:true,handler:this.delegateConfig,validator:this.cfg.checkBoolean});this.cfg.addProperty("SHOW_WEEK_HEADER",{value:false,handler:this.delegateConfig,validator:this.cfg.checkBoolean});this.cfg.addProperty("SHOW_WEEK_FOOTER",{value:false,handler:this.delegateConfig,validator:this.cfg.checkBoolean});this.cfg.addProperty("HIDE_BLANK_WEEKS",{value:false,handler:this.delegateConfig,validator:this.cfg.checkBoolean});this.cfg.addProperty("NAV_ARROW_LEFT",{value:null,handler:this.delegateConfig});this.cfg.addProperty("NAV_ARROW_RIGHT",{value:null,handler:this.delegateConfig});this.cfg.addProperty("MONTHS_SHORT",{value:["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],handler:this.delegateConfig});this.cfg.addProperty("MONTHS_LONG",{value:["January","February","March","April","May","June","July","August","September","October","November","December"],handler:this.delegateConfig});this.cfg.addProperty("WEEKDAYS_1CHAR",{value:["S","M","T","W","T","F","S"],handler:this.delegateConfig});this.cfg.addProperty("WEEKDAYS_SHORT",{value:["Su","Mo","Tu","We","Th","Fr","Sa"],handler:this.delegateConfig});this.cfg.addProperty("WEEKDAYS_MEDIUM",{value:["Sun","Mon","Tue","Wed","Thu","Fri","Sat"],handler:this.delegateConfig});this.cfg.addProperty("WEEKDAYS_LONG",{value:["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],handler:this.delegateConfig});this.cfg.addProperty("LOCALE_MONTHS",{value:"long",handler:this.delegateConfig});this.cfg.addProperty("LOCALE_WEEKDAYS",{value:"short",handler:this.delegateConfig});this.cfg.addProperty("DATE_DELIMITER",{value:",",handler:this.delegateConfig});this.cfg.addProperty("DATE_FIELD_DELIMITER",{value:"/",handler:this.delegateConfig});this.cfg.addProperty("DATE_RANGE_DELIMITER",{value:"-",handler:this.delegateConfig});this.cfg.addProperty("MY_MONTH_POSITION",{value:1,handler:this.delegateConfig,validator:this.cfg.checkNumber});this.cfg.addProperty("MY_YEAR_POSITION",{value:2,handler:this.delegateConfig,validator:this.cfg.checkNumber});this.cfg.addProperty("MD_MONTH_POSITION",{value:1,handler:this.delegateConfig,validator:this.cfg.checkNumber});this.cfg.addProperty("MD_DAY_POSITION",{value:2,handler:this.delegateConfig,validator:this.cfg.checkNumber});this.cfg.addProperty("MDY_MONTH_POSITION",{value:1,handler:this.delegateConfig,validator:this.cfg.checkNumber});this.cfg.addProperty("MDY_DAY_POSITION",{value:2,handler:this.delegateConfig,validator:this.cfg.checkNumber});this.cfg.addProperty("MDY_YEAR_POSITION",{value:3,handler:this.delegateConfig,validator:this.cfg.checkNumber});};YAHOO.widget.CalendarGroup.prototype.initEvents=function(){var me=this;var sub=function(fn,obj,bOverride){for(var p=0;p<me.pages.length;++p){var cal=me.pages[p];cal[this.type+"Event"].subscribe(fn,obj,bOverride);}};var unsub=function(fn,obj){for(var p=0;p<me.pages.length;++p){var cal=me.pages[p];cal[this.type+"Event"].unsubscribe(fn,obj);}};this.beforeSelectEvent=new YAHOO.util.CustomEvent("beforeSelect");this.beforeSelectEvent.subscribe=sub;this.beforeSelectEvent.unsubscribe=unsub;this.selectEvent=new YAHOO.util.CustomEvent("select");this.selectEvent.subscribe=sub;this.selectEvent.unsubscribe=unsub;this.beforeDeselectEvent=new YAHOO.util.CustomEvent("beforeDeselect");this.beforeDeselectEvent.subscribe=sub;this.beforeDeselectEvent.unsubscribe=unsub;this.deselectEvent=new YAHOO.util.CustomEvent("deselect");this.deselectEvent.subscribe=sub;this.deselectEvent.unsubscribe=unsub;this.changePageEvent=new YAHOO.util.CustomEvent("changePage");this.changePageEvent.subscribe=sub;this.changePageEvent.unsubscribe=unsub;this.beforeRenderEvent=new YAHOO.util.CustomEvent("beforeRender");this.beforeRenderEvent.subscribe=sub;this.beforeRenderEvent.unsubscribe=unsub;this.renderEvent=new YAHOO.util.CustomEvent("render");this.renderEvent.subscribe=sub;this.renderEvent.unsubscribe=unsub;this.resetEvent=new YAHOO.util.CustomEvent("reset");this.resetEvent.subscribe=sub;this.resetEvent.unsubscribe=unsub;this.clearEvent=new YAHOO.util.CustomEvent("clear");this.clearEvent.subscribe=sub;this.clearEvent.unsubscribe=unsub;};YAHOO.widget.CalendarGroup.prototype.configPages=function(type,args,obj){var pageCount=args[0];for(var p=0;p<pageCount;++p){var calId=this.id+"_"+p;var calContainerId=this.containerId+"_"+p;var childConfig=this.cfg.getConfig();childConfig.close=false;childConfig.title=false;var cal=this.constructChild(calId,calContainerId,childConfig);var caldate=cal.cfg.getProperty("pagedate");this._setMonthOnDate(caldate,caldate.getMonth()+p);cal.cfg.setProperty("pagedate",caldate);YAHOO.util.Dom.removeClass(cal.oDomContainer,this.Style.CSS_SINGLE);YAHOO.util.Dom.addClass(cal.oDomContainer,"groupcal");if(p===0){YAHOO.util.Dom.addClass(cal.oDomContainer,"first");} |
| | | if(p==(pageCount-1)){YAHOO.util.Dom.addClass(cal.oDomContainer,"last");} |
| | | cal.parent=this;cal.index=p;this.pages[this.pages.length]=cal;}};YAHOO.widget.CalendarGroup.prototype.configPageDate=function(type,args,obj){var val=args[0];var firstPageDate;for(var p=0;p<this.pages.length;++p){var cal=this.pages[p];if(p===0){firstPageDate=cal._parsePageDate(val);cal.cfg.setProperty("pagedate",firstPageDate);}else{var pageDate=new Date(firstPageDate);this._setMonthOnDate(pageDate,pageDate.getMonth()+p);cal.cfg.setProperty("pagedate",pageDate);}}};YAHOO.widget.CalendarGroup.prototype.delegateConfig=function(type,args,obj){var val=args[0];var cal;for(var p=0;p<this.pages.length;p++){cal=this.pages[p];cal.cfg.setProperty(type,val);}};YAHOO.widget.CalendarGroup.prototype.setChildFunction=function(fnName,fn){var pageCount=this.cfg.getProperty("pages");for(var p=0;p<pageCount;++p){this.pages[p][fnName]=fn;}};YAHOO.widget.CalendarGroup.prototype.callChildFunction=function(fnName,args){var pageCount=this.cfg.getProperty("pages");for(var p=0;p<pageCount;++p){var page=this.pages[p];if(page[fnName]){var fn=page[fnName];fn.call(page,args);}}};YAHOO.widget.CalendarGroup.prototype.constructChild=function(id,containerId,config){var container=document.getElementById(containerId);if(!container){container=document.createElement("div");container.id=containerId;this.oDomContainer.appendChild(container);} |
| | | return new YAHOO.widget.Calendar(id,containerId,config);};YAHOO.widget.CalendarGroup.prototype.setMonth=function(month){month=parseInt(month,10);var currYear;for(var p=0;p<this.pages.length;++p){var cal=this.pages[p];var pageDate=cal.cfg.getProperty("pagedate");if(p===0){currYear=pageDate.getFullYear();}else{pageDate.setYear(currYear);} |
| | | this._setMonthOnDate(pageDate,month+p);cal.cfg.setProperty("pagedate",pageDate);}};YAHOO.widget.CalendarGroup.prototype.setYear=function(year){year=parseInt(year,10);for(var p=0;p<this.pages.length;++p){var cal=this.pages[p];var pageDate=cal.cfg.getProperty("pageDate");if((pageDate.getMonth()+1)==1&&p>0){year+=1;} |
| | | cal.setYear(year);}};YAHOO.widget.CalendarGroup.prototype.render=function(){this.renderHeader();for(var p=0;p<this.pages.length;++p){var cal=this.pages[p];cal.render();} |
| | | this.renderFooter();};YAHOO.widget.CalendarGroup.prototype.select=function(date){for(var p=0;p<this.pages.length;++p){var cal=this.pages[p];cal.select(date);} |
| | | return this.getSelectedDates();};YAHOO.widget.CalendarGroup.prototype.selectCell=function(cellIndex){for(var p=0;p<this.pages.length;++p){var cal=this.pages[p];cal.selectCell(cellIndex);} |
| | | return this.getSelectedDates();};YAHOO.widget.CalendarGroup.prototype.deselect=function(date){for(var p=0;p<this.pages.length;++p){var cal=this.pages[p];cal.deselect(date);} |
| | | return this.getSelectedDates();};YAHOO.widget.CalendarGroup.prototype.deselectAll=function(){for(var p=0;p<this.pages.length;++p){var cal=this.pages[p];cal.deselectAll();} |
| | | return this.getSelectedDates();};YAHOO.widget.CalendarGroup.prototype.deselectCell=function(cellIndex){for(var p=0;p<this.pages.length;++p){var cal=this.pages[p];cal.deselectCell(cellIndex);} |
| | | return this.getSelectedDates();};YAHOO.widget.CalendarGroup.prototype.reset=function(){for(var p=0;p<this.pages.length;++p){var cal=this.pages[p];cal.reset();}};YAHOO.widget.CalendarGroup.prototype.clear=function(){for(var p=0;p<this.pages.length;++p){var cal=this.pages[p];cal.clear();}};YAHOO.widget.CalendarGroup.prototype.nextMonth=function(){for(var p=0;p<this.pages.length;++p){var cal=this.pages[p];cal.nextMonth();}};YAHOO.widget.CalendarGroup.prototype.previousMonth=function(){for(var p=this.pages.length-1;p>=0;--p){var cal=this.pages[p];cal.previousMonth();}};YAHOO.widget.CalendarGroup.prototype.nextYear=function(){for(var p=0;p<this.pages.length;++p){var cal=this.pages[p];cal.nextYear();}};YAHOO.widget.CalendarGroup.prototype.previousYear=function(){for(var p=0;p<this.pages.length;++p){var cal=this.pages[p];cal.previousYear();}};YAHOO.widget.CalendarGroup.prototype.getSelectedDates=function(){var returnDates=[];var selected=this.cfg.getProperty("selected");for(var d=0;d<selected.length;++d){var dateArray=selected[d];var date=new Date(dateArray[0],dateArray[1]-1,dateArray[2]);returnDates.push(date);} |
| | | returnDates.sort(function(a,b){return a-b;});return returnDates;};YAHOO.widget.CalendarGroup.prototype.addRenderer=function(sDates,fnRender){for(var p=0;p<this.pages.length;++p){var cal=this.pages[p];cal.addRenderer(sDates,fnRender);}};YAHOO.widget.CalendarGroup.prototype.addMonthRenderer=function(month,fnRender){for(var p=0;p<this.pages.length;++p){var cal=this.pages[p];cal.addMonthRenderer(month,fnRender);}};YAHOO.widget.CalendarGroup.prototype.addWeekdayRenderer=function(weekday,fnRender){for(var p=0;p<this.pages.length;++p){var cal=this.pages[p];cal.addWeekdayRenderer(weekday,fnRender);}};YAHOO.widget.CalendarGroup.prototype.renderHeader=function(){};YAHOO.widget.CalendarGroup.prototype.renderFooter=function(){};YAHOO.widget.CalendarGroup.prototype.addMonths=function(count){this.callChildFunction("addMonths",count);};YAHOO.widget.CalendarGroup.prototype.subtractMonths=function(count){this.callChildFunction("subtractMonths",count);};YAHOO.widget.CalendarGroup.prototype.addYears=function(count){this.callChildFunction("addYears",count);};YAHOO.widget.CalendarGroup.prototype.subtractYears=function(count){this.callChildFunction("subtractYears",count);};YAHOO.widget.CalendarGroup.prototype._setMonthOnDate=function(date,iMonth){if(this.browser=="safari"&&(iMonth<0||iMonth>11)){var DM=YAHOO.widget.DateMath;var newDate=DM.add(date,DM.MONTH,iMonth-date.getMonth());date.setTime(newDate.getTime());}else{date.setMonth(iMonth);}};YAHOO.widget.CalendarGroup.CSS_CONTAINER="yui-calcontainer";YAHOO.widget.CalendarGroup.CSS_MULTI_UP="multi";YAHOO.widget.CalendarGroup.CSS_2UPTITLE="title";YAHOO.widget.CalendarGroup.CSS_2UPCLOSE="close-icon";YAHOO.augment(YAHOO.widget.CalendarGroup,YAHOO.widget.Calendar,"buildDayLabel","buildMonthLabel","renderOutOfBoundsDate","renderRowHeader","renderRowFooter","renderCellDefault","styleCellDefault","renderCellStyleHighlight1","renderCellStyleHighlight2","renderCellStyleHighlight3","renderCellStyleHighlight4","renderCellStyleToday","renderCellStyleSelected","renderCellNotThisMonth","renderBodyCellRestricted","initStyles","configTitle","configClose","hide","show","browser");YAHOO.widget.CalendarGroup.prototype.toString=function(){return"CalendarGroup "+this.id;};YAHOO.widget.CalGrp=YAHOO.widget.CalendarGroup;YAHOO.widget.Calendar2up=function(id,containerId,config){this.init(id,containerId,config);};YAHOO.extend(YAHOO.widget.Calendar2up,YAHOO.widget.CalendarGroup);YAHOO.widget.Cal2up=YAHOO.widget.Calendar2up;YAHOO.register("calendar",YAHOO.widget.Calendar,{version:"2.2.0",build:"127"}); |
New file |
| | |
| | | Connection Manager Release Notes |
| | | |
| | | *** version 2.2.0 *** |
| | | |
| | | * initHeader() now accepts a third argument as a boolean. When set to true, |
| | | this specific header will automatically be sent with each transaction. |
| | | Otherwise, the header will be set and sent for the specific transaction only. |
| | | Example: initHeader('X-YUI-State','Beta', true); all transactions will send this |
| | | header. |
| | | * resetDefaultHeaders() will clear the default headers collection. |
| | | |
| | | * All Connection Mananger transactions will broadcast the header: "X-Requested- |
| | | With: XMLHttpRequest". |
| | | * This can be turned off: YAHOO.util.Connect.setDefaultXhrHeader(false); |
| | | |
| | | * The HTTP method argument in asyncRequest is now case-insensitive. |
| | | |
| | | * uploadFile() will now correctly handle the absence of a callback object, |
| | | allowing the transaction to complete silently. |
| | | |
| | | *** version 0.12.2 *** |
| | | |
| | | * The Opera/Connection Manager concurrent object condition, described in version |
| | | 0.12.0, no longer tests applies for Opera, version 9.10. |
| | | |
| | | *** version 0.12.1 *** |
| | | |
| | | * connection-debug.js corrected and synchronized with connection.js. Code |
| | | inconsistencies between the two files existed in 0.12.0. |
| | | |
| | | *** version 0.12.0 *** |
| | | |
| | | * When uploading files via setForm() and asyncRequest includes a POST data |
| | | argument, appendPostData() will create hidden input fields for each postData |
| | | label/value and append each field to the form object. |
| | | |
| | | * setForm() returns the assembled label/value string of the parsed HTML form |
| | | fields. |
| | | |
| | | * NOTE: Opera 9.02 does not allow for more than 12 concurrent Connection Manager |
| | | objects. |
| | | |
| | | The following example creates 12 requests in a loop: |
| | | for(var n=0; n<=12; i++){ |
| | | conn[n] = YAHOO.util.Connect.asyncRequest('GET', sUrl, callback); |
| | | } |
| | | |
| | | If n > 13, Opera 9.02 will crash. Connection manager objects count n must be <= |
| | | 12 at all times. This condition was not present in Opera version 9.01. |
| | | |
| | | This condition does not apply to other A-Grade browsers ( |
| | | http://developer.yahoo.com/yui/articles/gbs/gbs_browser-chart.html) |
| | | |
| | | *** version 0.11.3 *** |
| | | |
| | | * YUI Event dependency for file uploading is now optional. |
| | | |
| | | * uploadFile() now sets unique IDs for each file upload transaction to prevent |
| | | iframe collisions with parallel uploads. |
| | | |
| | | * The callback object now has property responseXML to provide support for file |
| | | upload transactions that return an XML document. |
| | | |
| | | * setForm() will verify if a select option value attribute is present and use |
| | | its value, including empty string, before using the text node value. |
| | | |
| | | * Modified polling mechanism in handleReadyState() and |
| | | handleTransactionResponse() to prevent infinite polling if JavaScript errors |
| | | occur in the user-defined callback. |
| | | |
| | | * createFrame() will now accept a boolean argument of true to set the frame |
| | | source to "javascript:false" to prevent IE from throwing security warnings in an |
| | | HTTPS environment. |
| | | |
| | | * setHeader() now enumerates through the _http_header object using |
| | | hasOwnProperty() to prevent collisions with members added to Object via |
| | | prototype. |
| | | |
| | | * If using setForm() and asyncRequest includes a POST data argument, the data |
| | | will be concatenated to the HTML form POST message. |
| | | |
| | | *** version 0.11.2 *** |
| | | |
| | | * No revisions. |
| | | |
| | | *** version 0.11.1 *** |
| | | |
| | | * uploadFile() now verifies the existence of callback.upload before invoking |
| | | callback, with or without object scope. |
| | | |
| | | *** version 0.11.0 *** |
| | | |
| | | * Each transaction can be defined with a timeout threshold, in milliseconds, |
| | | through the callback object. If the threshold is reached, and the transaction |
| | | hasn't yet completed, the transaction will call abort(). |
| | | |
| | | * abort() will now accept a callback object as the second argument. The |
| | | failure callback will receive a response object to indicate the transaction was |
| | | aborted. |
| | | |
| | | * setForm() will now support file uploads by setting the second argument to |
| | | true (e.g., YAHOO.util.Connect.setForm(formObject, true). File upload does not |
| | | use the callback success or failure handler. Instead, it uses a new callback |
| | | object handler: upload. |
| | | |
| | | * HTML form submit will no longer submit form fields without a defined name |
| | | attribute. |
| | | |
| | | * The default POST header of 'Content-Type','application/x-www-form-urlencoded' |
| | | can be overridden by calling setDefaultPostHeader(false). This |
| | | will remove the default header from non-HTML form, POST submissions. |
| | | |
| | | * setHeader() now enumerates through the _http_header object with |
| | | propertyIsEnumerable to prevent collisions with members added to Object via |
| | | prototype. |
| | | |
| | | *** version 0.10.0 *** |
| | | |
| | | * handleTransactionResponse() now treats the full HTTP 2xx range as a success |
| | | case, instead of just HTTP 200. |
| | | |
| | | * To accommodate multiple field values in Mozilla/Firefox, multiple initHeader |
| | | calls with the same label will now result in the values concatenated to a |
| | | comma- delimited string value. |
| | | Example: |
| | | Setting Content-Type:'application/x-www-form-urlencoded' and Content- |
| | | Type:'text/xml' will result in Content-Type:'application/x-www-form-urlencoded, |
| | | text/xml'. |
| | | |
| | | * Default polling interval lowered to 50ms. |
| | | |
| | | * YAHOO.util.Connect.setPollingInterval() will allow you to set a polling |
| | | interval -- in milliseconds -- to override the default value. |
| | | |
| | | * YAHOO.util.Connect.getResponseHeader[headerLabel] now supported as a response |
| | | object property to provide symmetry with the native XHR object's property. |
| | | Example: |
| | | YAHOO.util.Connect.getResponseHeader['Content-Length'] will return the value |
| | | for the Content-Length header, if the header is available. |
| | | |
| | | * YAHOO.util.Connect.allResponseHeaders property renamed to |
| | | getAllResponseHeaders to provide symmetry with the native XHR object's |
| | | property. |
| | | |
| | | * YAHOO.util.Connect.setForm() now supports HTTP GET as well as HTTP POST. |
| | | |
| | | * YAHOO.util.Connect.setForm() now accepts an HTML form object as well as its |
| | | name attribute value. |
| | | |
| | | * YAHOO.util.Connect.setForm() will not submit HTML form fields that are |
| | | disabled or do not have a name attribute value. |
| | | |
| | | * [FIXED] Response exceptions result in infinite callback loop in |
| | | Mozilla/Firefox. |
| | | |
| | | * [FIXED] YAHOO.util.Connect.abort() now properly clears polling interval. |
| | | |
| | | * [FIXED] isCallInProgress() now verifies whether XHR instance still exists, |
| | | and returns false if the connection object is no longer available. |
| | | |
| | | *** version 0.9.0 *** |
| | | |
| | | * Initial release |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
New file |
| | |
| | | /* |
| | | 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 Connection Manager provides a simplified interface to the XMLHttpRequest |
| | | * object. It handles cross-browser instantiantion of XMLHttpRequest, negotiates the |
| | | * interactive states and server response, returning the results to a pre-defined |
| | | * callback you create. |
| | | * |
| | | * @namespace YAHOO.util |
| | | * @module connection |
| | | * @requires yahoo |
| | | */ |
| | | |
| | | /** |
| | | * The Connection Manager singleton provides methods for creating and managing |
| | | * asynchronous transactions. |
| | | * |
| | | * @class Connect |
| | | */ |
| | | |
| | | YAHOO.util.Connect = |
| | | { |
| | | /** |
| | | * @description Array of MSFT ActiveX ids for XMLHttpRequest. |
| | | * @property _msxml_progid |
| | | * @private |
| | | * @static |
| | | * @type array |
| | | */ |
| | | _msxml_progid:[ |
| | | 'MSXML2.XMLHTTP.3.0', |
| | | 'MSXML2.XMLHTTP', |
| | | 'Microsoft.XMLHTTP' |
| | | ], |
| | | |
| | | /** |
| | | * @description Object literal of HTTP header(s) |
| | | * @property _http_header |
| | | * @private |
| | | * @static |
| | | * @type object |
| | | */ |
| | | _http_headers:{}, |
| | | |
| | | /** |
| | | * @description Determines if HTTP headers are set. |
| | | * @property _has_http_headers |
| | | * @private |
| | | * @static |
| | | * @type boolean |
| | | */ |
| | | _has_http_headers:false, |
| | | |
| | | /** |
| | | * @description Determines if a default header of |
| | | * Content-Type of 'application/x-www-form-urlencoded' |
| | | * will be added to any client HTTP headers sent for POST |
| | | * transactions. |
| | | * @property _use_default_post_header |
| | | * @private |
| | | * @static |
| | | * @type boolean |
| | | */ |
| | | _use_default_post_header:true, |
| | | |
| | | /** |
| | | * @description Determines if a default header of |
| | | * Content-Type of 'application/x-www-form-urlencoded' |
| | | * will be added to client HTTP headers sent for POST |
| | | * transactions. |
| | | * @property _default_post_header |
| | | * @private |
| | | * @static |
| | | * @type boolean |
| | | */ |
| | | _default_post_header:'application/x-www-form-urlencoded', |
| | | |
| | | /** |
| | | * @description Determines if a default header of |
| | | * 'X-Requested-With: XMLHttpRequest' |
| | | * will be added to each transaction. |
| | | * @property _use_default_xhr_header |
| | | * @private |
| | | * @static |
| | | * @type boolean |
| | | */ |
| | | _use_default_xhr_header:true, |
| | | |
| | | /** |
| | | * @description The default header value for the label |
| | | * "X-Requested-With". This is sent with each |
| | | * transaction, by default, to identify the |
| | | * request as being made by YUI Connection Manager. |
| | | * @property _default_xhr_header |
| | | * @private |
| | | * @static |
| | | * @type boolean |
| | | */ |
| | | _default_xhr_header:'XMLHttpRequest', |
| | | |
| | | /** |
| | | * @description Determines if custom, default headers |
| | | * are set for each transaction. |
| | | * @property _has_default_header |
| | | * @private |
| | | * @static |
| | | * @type boolean |
| | | */ |
| | | _has_default_headers:true, |
| | | |
| | | /** |
| | | * @description Determines if custom, default headers |
| | | * are set for each transaction. |
| | | * @property _has_default_header |
| | | * @private |
| | | * @static |
| | | * @type boolean |
| | | */ |
| | | _default_headers:{}, |
| | | |
| | | /** |
| | | * @description Property modified by setForm() to determine if the data |
| | | * should be submitted as an HTML form. |
| | | * @property _isFormSubmit |
| | | * @private |
| | | * @static |
| | | * @type boolean |
| | | */ |
| | | _isFormSubmit:false, |
| | | |
| | | /** |
| | | * @description Property modified by setForm() to determine if a file(s) |
| | | * upload is expected. |
| | | * @property _isFileUpload |
| | | * @private |
| | | * @static |
| | | * @type boolean |
| | | */ |
| | | _isFileUpload:false, |
| | | |
| | | /** |
| | | * @description Property modified by setForm() to set a reference to the HTML |
| | | * form node if the desired action is file upload. |
| | | * @property _formNode |
| | | * @private |
| | | * @static |
| | | * @type object |
| | | */ |
| | | _formNode:null, |
| | | |
| | | /** |
| | | * @description Property modified by setForm() to set the HTML form data |
| | | * for each transaction. |
| | | * @property _sFormData |
| | | * @private |
| | | * @static |
| | | * @type string |
| | | */ |
| | | _sFormData:null, |
| | | |
| | | /** |
| | | * @description Collection of polling references to the polling mechanism in handleReadyState. |
| | | * @property _poll |
| | | * @private |
| | | * @static |
| | | * @type object |
| | | */ |
| | | _poll:{}, |
| | | |
| | | /** |
| | | * @description Queue of timeout values for each transaction callback with a defined timeout value. |
| | | * @property _timeOut |
| | | * @private |
| | | * @static |
| | | * @type object |
| | | */ |
| | | _timeOut:{}, |
| | | |
| | | /** |
| | | * @description The polling frequency, in milliseconds, for HandleReadyState. |
| | | * when attempting to determine a transaction's XHR readyState. |
| | | * The default is 50 milliseconds. |
| | | * @property _polling_interval |
| | | * @private |
| | | * @static |
| | | * @type int |
| | | */ |
| | | _polling_interval:50, |
| | | |
| | | /** |
| | | * @description A transaction counter that increments the transaction id for each transaction. |
| | | * @property _transaction_id |
| | | * @private |
| | | * @static |
| | | * @type int |
| | | */ |
| | | _transaction_id:0, |
| | | |
| | | /** |
| | | * @description Member to add an ActiveX id to the existing xml_progid array. |
| | | * In the event(unlikely) a new ActiveX id is introduced, it can be added |
| | | * without internal code modifications. |
| | | * @method setProgId |
| | | * @public |
| | | * @static |
| | | * @param {string} id The ActiveX id to be added to initialize the XHR object. |
| | | * @return void |
| | | */ |
| | | setProgId:function(id) |
| | | { |
| | | this._msxml_progid.unshift(id); |
| | | YAHOO.log('ActiveX Program Id ' + id + ' added to _msxml_progid.', 'info', 'Connection'); |
| | | }, |
| | | |
| | | /** |
| | | * @description Member to enable or disable the default POST header. |
| | | * @method setDefaultPostHeader |
| | | * @public |
| | | * @static |
| | | * @param {boolean} b Set and use default header - true or false . |
| | | * @return void |
| | | */ |
| | | setDefaultPostHeader:function(b) |
| | | { |
| | | this._use_default_post_header = b; |
| | | YAHOO.log('Use default POST header set to ' + b, 'info', 'Connection'); |
| | | }, |
| | | |
| | | /** |
| | | * @description Member to enable or disable the default POST header. |
| | | * @method setDefaultXhrHeader |
| | | * @public |
| | | * @static |
| | | * @param {boolean} b Set and use default header - true or false . |
| | | * @return void |
| | | */ |
| | | setDefaultXhrHeader:function(b) |
| | | { |
| | | this._use_default_xhr_header = b; |
| | | YAHOO.log('Use default transaction header set to ' + b, 'info', 'Connection'); |
| | | }, |
| | | |
| | | /** |
| | | * @description Member to modify the default polling interval. |
| | | * @method setPollingInterval |
| | | * @public |
| | | * @static |
| | | * @param {int} i The polling interval in milliseconds. |
| | | * @return void |
| | | */ |
| | | setPollingInterval:function(i) |
| | | { |
| | | if(typeof i == 'number' && isFinite(i)){ |
| | | this._polling_interval = i; |
| | | YAHOO.log('Default polling interval set to ' + i +'ms', 'info', 'Connection'); |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * @description Instantiates a XMLHttpRequest object and returns an object with two properties: |
| | | * the XMLHttpRequest instance and the transaction id. |
| | | * @method createXhrObject |
| | | * @private |
| | | * @static |
| | | * @param {int} transactionId Property containing the transaction id for this transaction. |
| | | * @return object |
| | | */ |
| | | createXhrObject:function(transactionId) |
| | | { |
| | | var obj,http; |
| | | try |
| | | { |
| | | // Instantiates XMLHttpRequest in non-IE browsers and assigns to http. |
| | | http = new XMLHttpRequest(); |
| | | // Object literal with http and tId properties |
| | | obj = { conn:http, tId:transactionId }; |
| | | YAHOO.log('XHR object created for transaction ' + transactionId, 'info', 'Connection'); |
| | | } |
| | | catch(e) |
| | | { |
| | | for(var i=0; i<this._msxml_progid.length; ++i){ |
| | | try |
| | | { |
| | | // Instantiates XMLHttpRequest for IE and assign to http. |
| | | http = new ActiveXObject(this._msxml_progid[i]); |
| | | // Object literal with conn and tId properties |
| | | obj = { conn:http, tId:transactionId }; |
| | | YAHOO.log('ActiveX XHR object created for transaction ' + transactionId, 'info', 'Connection'); |
| | | break; |
| | | } |
| | | catch(e){} |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | return obj; |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * @description This method is called by asyncRequest to create a |
| | | * valid connection object for the transaction. It also passes a |
| | | * transaction id and increments the transaction id counter. |
| | | * @method getConnectionObject |
| | | * @private |
| | | * @static |
| | | * @return {object} |
| | | */ |
| | | getConnectionObject:function() |
| | | { |
| | | var o; |
| | | var tId = this._transaction_id; |
| | | |
| | | try |
| | | { |
| | | o = this.createXhrObject(tId); |
| | | if(o){ |
| | | this._transaction_id++; |
| | | } |
| | | } |
| | | catch(e){} |
| | | finally |
| | | { |
| | | return o; |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * @description Method for initiating an asynchronous request via the XHR object. |
| | | * @method asyncRequest |
| | | * @public |
| | | * @static |
| | | * @param {string} method HTTP transaction method |
| | | * @param {string} uri Fully qualified path of resource |
| | | * @param {callback} callback User-defined callback function or object |
| | | * @param {string} postData POST body |
| | | * @return {object} Returns the connection object |
| | | */ |
| | | asyncRequest:function(method, uri, callback, postData) |
| | | { |
| | | var o = this.getConnectionObject(); |
| | | |
| | | if(!o){ |
| | | YAHOO.log('Unable to create connection object.', 'error', 'Connection'); |
| | | return null; |
| | | } |
| | | else{ |
| | | if(this._isFormSubmit){ |
| | | if(this._isFileUpload){ |
| | | this.uploadFile(o.tId, callback, uri, postData); |
| | | this.releaseObject(o); |
| | | |
| | | return; |
| | | } |
| | | |
| | | //If the specified HTTP method is GET, setForm() will return an |
| | | //encoded string that is concatenated to the uri to |
| | | //create a querystring. |
| | | if(method.toUpperCase() == 'GET'){ |
| | | if(this._sFormData.length != 0){ |
| | | // If the URI already contains a querystring, append an ampersand |
| | | // and then concatenate _sFormData to the URI. |
| | | uri += ((uri.indexOf('?') == -1)?'?':'&') + this._sFormData; |
| | | } |
| | | else{ |
| | | uri += "?" + this._sFormData; |
| | | } |
| | | } |
| | | else if(method.toUpperCase() == 'POST'){ |
| | | //If POST data exist in addition to the HTML form data, |
| | | //it will be concatenated to the form data. |
| | | postData = postData?this._sFormData + "&" + postData:this._sFormData; |
| | | } |
| | | } |
| | | |
| | | o.conn.open(method, uri, true); |
| | | |
| | | if(this._use_default_xhr_header){ |
| | | if(!this._default_headers['X-Requested-With']){ |
| | | this.initHeader('X-Requested-With', this._default_xhr_header, true); |
| | | YAHOO.log('Initialize transaction header X-Request-Header to XMLHttpRequest.', 'info', 'Connection'); |
| | | } |
| | | } |
| | | if(this._isFormSubmit || (postData && this._use_default_post_header)){ |
| | | this.initHeader('Content-Type', this._default_post_header); |
| | | YAHOO.log('Initialize header Content-Type to application/x-www-form-urlencoded for POST transaction.', 'info', 'Connection'); |
| | | if(this._isFormSubmit){ |
| | | this.resetFormState(); |
| | | } |
| | | } |
| | | |
| | | if(this._has_default_headers || this._has_http_headers){ |
| | | this.setHeader(o); |
| | | } |
| | | |
| | | this.handleReadyState(o, callback); |
| | | o.conn.send(postData || null); |
| | | |
| | | return o; |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * @description This method serves as a timer that polls the XHR object's readyState |
| | | * property during a transaction, instead of binding a callback to the |
| | | * onreadystatechange event. Upon readyState 4, handleTransactionResponse |
| | | * will process the response, and the timer will be cleared. |
| | | * @method handleReadyState |
| | | * @private |
| | | * @static |
| | | * @param {object} o The connection object |
| | | * @param {callback} callback The user-defined callback object |
| | | * @return {void} |
| | | */ |
| | | handleReadyState:function(o, callback) |
| | | { |
| | | var oConn = this; |
| | | |
| | | if(callback && callback.timeout){ |
| | | this._timeOut[o.tId] = window.setTimeout(function(){ oConn.abort(o, callback, true); }, callback.timeout); |
| | | } |
| | | |
| | | this._poll[o.tId] = window.setInterval( |
| | | function(){ |
| | | if(o.conn && o.conn.readyState == 4){ |
| | | window.clearInterval(oConn._poll[o.tId]); |
| | | delete oConn._poll[o.tId]; |
| | | |
| | | if(callback && callback.timeout){ |
| | | delete oConn._timeOut[o.tId]; |
| | | } |
| | | |
| | | oConn.handleTransactionResponse(o, callback); |
| | | } |
| | | } |
| | | ,this._polling_interval); |
| | | }, |
| | | |
| | | /** |
| | | * @description This method attempts to interpret the server response and |
| | | * determine whether the transaction was successful, or if an error or |
| | | * exception was encountered. |
| | | * @method handleTransactionResponse |
| | | * @private |
| | | * @static |
| | | * @param {object} o The connection object |
| | | * @param {object} callback The sser-defined callback object |
| | | * @param {boolean} isAbort Determines if the transaction was aborted. |
| | | * @return {void} |
| | | */ |
| | | handleTransactionResponse:function(o, callback, isAbort) |
| | | { |
| | | // If no valid callback is provided, then do not process any callback handling. |
| | | if(!callback){ |
| | | this.releaseObject(o); |
| | | YAHOO.log('No callback object to process. Transaction complete.', 'warn', 'Connection'); |
| | | return; |
| | | } |
| | | |
| | | var httpStatus, responseObject; |
| | | |
| | | try |
| | | { |
| | | if(o.conn.status !== undefined && o.conn.status != 0){ |
| | | httpStatus = o.conn.status; |
| | | } |
| | | else{ |
| | | httpStatus = 13030; |
| | | } |
| | | } |
| | | catch(e){ |
| | | // 13030 is the custom code to indicate the condition -- in Mozilla/FF -- |
| | | // when the o object's status and statusText properties are |
| | | // unavailable, and a query attempt throws an exception. |
| | | httpStatus = 13030; |
| | | } |
| | | |
| | | if(httpStatus >= 200 && httpStatus < 300){ |
| | | responseObject = this.createResponseObject(o, callback.argument); |
| | | if(callback.success){ |
| | | if(!callback.scope){ |
| | | callback.success(responseObject); |
| | | YAHOO.log('Success callback. HTTP code is ' + httpStatus, 'info', 'Connection'); |
| | | } |
| | | else{ |
| | | // If a scope property is defined, the callback will be fired from |
| | | // the context of the object. |
| | | callback.success.apply(callback.scope, [responseObject]); |
| | | YAHOO.log('Success callback with scope. HTTP code is ' + httpStatus, 'info', 'Connection'); |
| | | } |
| | | } |
| | | } |
| | | else{ |
| | | switch(httpStatus){ |
| | | // The following cases are wininet.dll error codes that may be encountered. |
| | | case 12002: // Server timeout |
| | | case 12029: // 12029 to 12031 correspond to dropped connections. |
| | | case 12030: |
| | | case 12031: |
| | | case 12152: // Connection closed by server. |
| | | case 13030: // See above comments for variable status. |
| | | responseObject = this.createExceptionObject(o.tId, callback.argument, (isAbort?isAbort:false)); |
| | | if(callback.failure){ |
| | | if(!callback.scope){ |
| | | callback.failure(responseObject); |
| | | YAHOO.log('Failure callback. Exception detected. Status code is ' + httpStatus, 'warn', 'Connection'); |
| | | } |
| | | else{ |
| | | callback.failure.apply(callback.scope, [responseObject]); |
| | | YAHOO.log('Failure callback with scope. Exception detected. Status code is ' + httpStatus, 'warn', 'Connection'); |
| | | } |
| | | } |
| | | break; |
| | | default: |
| | | responseObject = this.createResponseObject(o, callback.argument); |
| | | if(callback.failure){ |
| | | if(!callback.scope){ |
| | | callback.failure(responseObject); |
| | | YAHOO.log('Failure callback. HTTP status code is ' + httpStatus, 'warn', 'Connection'); |
| | | } |
| | | else{ |
| | | callback.failure.apply(callback.scope, [responseObject]); |
| | | YAHOO.log('Failure callback with scope. HTTP status code is ' + httpStatus, 'warn', 'Connection'); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | this.releaseObject(o); |
| | | responseObject = null; |
| | | }, |
| | | |
| | | /** |
| | | * @description This method evaluates the server response, creates and returns the results via |
| | | * its properties. Success and failure cases will differ in the response |
| | | * object's property values. |
| | | * @method createResponseObject |
| | | * @private |
| | | * @static |
| | | * @param {object} o The connection object |
| | | * @param {callbackArg} callbackArg The user-defined argument or arguments to be passed to the callback |
| | | * @return {object} |
| | | */ |
| | | createResponseObject:function(o, callbackArg) |
| | | { |
| | | var obj = {}; |
| | | var headerObj = {}; |
| | | |
| | | try |
| | | { |
| | | var headerStr = o.conn.getAllResponseHeaders(); |
| | | var header = headerStr.split('\n'); |
| | | for(var i=0; i<header.length; i++){ |
| | | var delimitPos = header[i].indexOf(':'); |
| | | if(delimitPos != -1){ |
| | | headerObj[header[i].substring(0,delimitPos)] = header[i].substring(delimitPos+2); |
| | | } |
| | | } |
| | | } |
| | | catch(e){} |
| | | |
| | | obj.tId = o.tId; |
| | | obj.status = o.conn.status; |
| | | obj.statusText = o.conn.statusText; |
| | | obj.getResponseHeader = headerObj; |
| | | obj.getAllResponseHeaders = headerStr; |
| | | obj.responseText = o.conn.responseText; |
| | | obj.responseXML = o.conn.responseXML; |
| | | |
| | | if(typeof callbackArg !== undefined){ |
| | | obj.argument = callbackArg; |
| | | } |
| | | |
| | | return obj; |
| | | }, |
| | | |
| | | /** |
| | | * @description If a transaction cannot be completed due to dropped or closed connections, |
| | | * there may be not be enough information to build a full response object. |
| | | * The failure callback will be fired and this specific condition can be identified |
| | | * by a status property value of 0. |
| | | * |
| | | * If an abort was successful, the status property will report a value of -1. |
| | | * |
| | | * @method createExceptionObject |
| | | * @private |
| | | * @static |
| | | * @param {int} tId The Transaction Id |
| | | * @param {callbackArg} callbackArg The user-defined argument or arguments to be passed to the callback |
| | | * @param {boolean} isAbort Determines if the exception case is caused by a transaction abort |
| | | * @return {object} |
| | | */ |
| | | createExceptionObject:function(tId, callbackArg, isAbort) |
| | | { |
| | | var COMM_CODE = 0; |
| | | var COMM_ERROR = 'communication failure'; |
| | | var ABORT_CODE = -1; |
| | | var ABORT_ERROR = 'transaction aborted'; |
| | | |
| | | var obj = {}; |
| | | |
| | | obj.tId = tId; |
| | | if(isAbort){ |
| | | obj.status = ABORT_CODE; |
| | | obj.statusText = ABORT_ERROR; |
| | | } |
| | | else{ |
| | | obj.status = COMM_CODE; |
| | | obj.statusText = COMM_ERROR; |
| | | } |
| | | |
| | | if(callbackArg){ |
| | | obj.argument = callbackArg; |
| | | } |
| | | |
| | | return obj; |
| | | }, |
| | | |
| | | /** |
| | | * @description Method that initializes the custom HTTP headers for the each transaction. |
| | | * @method initHeader |
| | | * @public |
| | | * @static |
| | | * @param {string} label The HTTP header label |
| | | * @param {string} value The HTTP header value |
| | | * @param {string} isDefault Determines if the specific header is a default header |
| | | * automatically sent with each transaction. |
| | | * @return {void} |
| | | */ |
| | | initHeader:function(label,value,isDefault) |
| | | { |
| | | var headerObj = (isDefault)?this._default_headers:this._http_headers; |
| | | |
| | | if(headerObj[label] === undefined){ |
| | | headerObj[label] = value; |
| | | } |
| | | else{ |
| | | // Concatenate multiple values, comma-delimited, |
| | | // for the same header label, |
| | | headerObj[label] = value + "," + headerObj[label]; |
| | | } |
| | | |
| | | if(isDefault){ |
| | | this._has_default_headers = true; |
| | | } |
| | | else{ |
| | | this._has_http_headers = true; |
| | | } |
| | | }, |
| | | |
| | | |
| | | /** |
| | | * @description Accessor that sets the HTTP headers for each transaction. |
| | | * @method setHeader |
| | | * @private |
| | | * @static |
| | | * @param {object} o The connection object for the transaction. |
| | | * @return {void} |
| | | */ |
| | | setHeader:function(o) |
| | | { |
| | | if(this._has_default_headers){ |
| | | for(var prop in this._default_headers){ |
| | | if(YAHOO.lang.hasOwnProperty(this._default_headers,prop)){ |
| | | o.conn.setRequestHeader(prop, this._default_headers[prop]); |
| | | YAHOO.log('Default HTTP header ' + prop + ' set with value of ' + this._default_headers[prop], 'info', 'Connection'); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if(this._has_http_headers){ |
| | | for(var prop in this._http_headers){ |
| | | if(YAHOO.lang.hasOwnProperty(this._http_headers,prop)){ |
| | | o.conn.setRequestHeader(prop, this._http_headers[prop]); |
| | | YAHOO.log('HTTP header ' + prop + ' set with value of ' + this._http_headers[prop], 'info', 'Connection'); |
| | | } |
| | | } |
| | | delete this._http_headers; |
| | | |
| | | this._http_headers = {}; |
| | | this._has_http_headers = false; |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * @description Resets the default HTTP headers object |
| | | * @method resetDefaultHeaders |
| | | * @public |
| | | * @static |
| | | * @return {void} |
| | | */ |
| | | resetDefaultHeaders:function(){ |
| | | delete this._default_headers |
| | | this._default_headers = {}; |
| | | this._has_default_headers = false; |
| | | }, |
| | | |
| | | /** |
| | | * @description This method assembles the form label and value pairs and |
| | | * constructs an encoded string. |
| | | * asyncRequest() will automatically initialize the |
| | | * transaction with a HTTP header Content-Type of |
| | | * application/x-www-form-urlencoded. |
| | | * @method setForm |
| | | * @public |
| | | * @static |
| | | * @param {string || object} form id or name attribute, or form object. |
| | | * @param {string} optional boolean to indicate SSL environment. |
| | | * @param {string || boolean} optional qualified path of iframe resource for SSL in IE. |
| | | * @return {string} string of the HTML form field name and value pairs.. |
| | | */ |
| | | setForm:function(formId, isUpload, secureUri) |
| | | { |
| | | this.resetFormState(); |
| | | var oForm; |
| | | if(typeof formId == 'string'){ |
| | | // Determine if the argument is a form id or a form name. |
| | | // Note form name usage is deprecated by supported |
| | | // here for legacy reasons. |
| | | oForm = (document.getElementById(formId) || document.forms[formId]); |
| | | } |
| | | else if(typeof formId == 'object'){ |
| | | // Treat argument as an HTML form object. |
| | | oForm = formId; |
| | | } |
| | | else{ |
| | | YAHOO.log('Unable to create form object ' + formId, 'warn', 'Connection'); |
| | | return; |
| | | } |
| | | |
| | | // If the isUpload argument is true, setForm will call createFrame to initialize |
| | | // an iframe as the form target. |
| | | // |
| | | // The argument secureURI is also required by IE in SSL environments |
| | | // where the secureURI string is a fully qualified HTTP path, used to set the source |
| | | // of the iframe, to a stub resource in the same domain. |
| | | if(isUpload){ |
| | | |
| | | // Create iframe in preparation for file upload. |
| | | this.createFrame(secureUri?secureUri:null); |
| | | |
| | | // Set form reference and file upload properties to true. |
| | | this._isFormSubmit = true; |
| | | this._isFileUpload = true; |
| | | this._formNode = oForm; |
| | | |
| | | return; |
| | | } |
| | | |
| | | var oElement, oName, oValue, oDisabled; |
| | | var hasSubmit = false; |
| | | |
| | | // Iterate over the form elements collection to construct the |
| | | // label-value pairs. |
| | | for (var i=0; i<oForm.elements.length; i++){ |
| | | oElement = oForm.elements[i]; |
| | | oDisabled = oForm.elements[i].disabled; |
| | | oName = oForm.elements[i].name; |
| | | oValue = oForm.elements[i].value; |
| | | |
| | | // Do not submit fields that are disabled or |
| | | // do not have a name attribute value. |
| | | if(!oDisabled && oName) |
| | | { |
| | | switch (oElement.type) |
| | | { |
| | | case 'select-one': |
| | | case 'select-multiple': |
| | | for(var j=0; j<oElement.options.length; j++){ |
| | | if(oElement.options[j].selected){ |
| | | if(window.ActiveXObject){ |
| | | this._sFormData += encodeURIComponent(oName) + '=' + encodeURIComponent(oElement.options[j].attributes['value'].specified?oElement.options[j].value:oElement.options[j].text) + '&'; |
| | | } |
| | | else{ |
| | | this._sFormData += encodeURIComponent(oName) + '=' + encodeURIComponent(oElement.options[j].hasAttribute('value')?oElement.options[j].value:oElement.options[j].text) + '&'; |
| | | } |
| | | |
| | | } |
| | | } |
| | | break; |
| | | case 'radio': |
| | | case 'checkbox': |
| | | if(oElement.checked){ |
| | | this._sFormData += encodeURIComponent(oName) + '=' + encodeURIComponent(oValue) + '&'; |
| | | } |
| | | break; |
| | | case 'file': |
| | | // stub case as XMLHttpRequest will only send the file path as a string. |
| | | case undefined: |
| | | // stub case for fieldset element which returns undefined. |
| | | case 'reset': |
| | | // stub case for input type reset button. |
| | | case 'button': |
| | | // stub case for input type button elements. |
| | | break; |
| | | case 'submit': |
| | | if(hasSubmit == false){ |
| | | this._sFormData += encodeURIComponent(oName) + '=' + encodeURIComponent(oValue) + '&'; |
| | | hasSubmit = true; |
| | | } |
| | | break; |
| | | default: |
| | | this._sFormData += encodeURIComponent(oName) + '=' + encodeURIComponent(oValue) + '&'; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | this._isFormSubmit = true; |
| | | this._sFormData = this._sFormData.substr(0, this._sFormData.length - 1); |
| | | |
| | | YAHOO.log('Form initialized for transaction. HTML form POST message is: ' + this._sFormData, 'info', 'Connection'); |
| | | |
| | | return this._sFormData; |
| | | }, |
| | | |
| | | /** |
| | | * @description Resets HTML form properties when an HTML form or HTML form |
| | | * with file upload transaction is sent. |
| | | * @method resetFormState |
| | | * @private |
| | | * @static |
| | | * @return {void} |
| | | */ |
| | | resetFormState:function(){ |
| | | this._isFormSubmit = false; |
| | | this._isFileUpload = false; |
| | | this._formNode = null; |
| | | this._sFormData = ""; |
| | | }, |
| | | |
| | | /** |
| | | * @description Creates an iframe to be used for form file uploads. It is remove from the |
| | | * document upon completion of the upload transaction. |
| | | * @method createFrame |
| | | * @private |
| | | * @static |
| | | * @param {string} optional qualified path of iframe resource for SSL in IE. |
| | | * @return {void} |
| | | */ |
| | | createFrame:function(secureUri){ |
| | | |
| | | // IE does not allow the setting of id and name attributes as object |
| | | // properties via createElement(). A different iframe creation |
| | | // pattern is required for IE. |
| | | var frameId = 'yuiIO' + this._transaction_id; |
| | | if(window.ActiveXObject){ |
| | | var io = document.createElement('<iframe id="' + frameId + '" name="' + frameId + '" />'); |
| | | |
| | | // IE will throw a security exception in an SSL environment if the |
| | | // iframe source is undefined. |
| | | if(typeof secureUri == 'boolean'){ |
| | | io.src = 'javascript:false'; |
| | | } |
| | | else if(typeof secureURI == 'string'){ |
| | | // Deprecated |
| | | io.src = secureUri; |
| | | } |
| | | } |
| | | else{ |
| | | var io = document.createElement('iframe'); |
| | | io.id = frameId; |
| | | io.name = frameId; |
| | | } |
| | | |
| | | io.style.position = 'absolute'; |
| | | io.style.top = '-1000px'; |
| | | io.style.left = '-1000px'; |
| | | |
| | | document.body.appendChild(io); |
| | | YAHOO.log('File upload iframe created. Id is:' + frameId, 'info', 'Connection'); |
| | | }, |
| | | |
| | | /** |
| | | * @description Parses the POST data and creates hidden form elements |
| | | * for each key-value, and appends them to the HTML form object. |
| | | * @method appendPostData |
| | | * @private |
| | | * @static |
| | | * @param {string} postData The HTTP POST data |
| | | * @return {array} formElements Collection of hidden fields. |
| | | */ |
| | | appendPostData:function(postData) |
| | | { |
| | | var formElements = []; |
| | | var postMessage = postData.split('&'); |
| | | for(var i=0; i < postMessage.length; i++){ |
| | | var delimitPos = postMessage[i].indexOf('='); |
| | | if(delimitPos != -1){ |
| | | formElements[i] = document.createElement('input'); |
| | | formElements[i].type = 'hidden'; |
| | | formElements[i].name = postMessage[i].substring(0,delimitPos); |
| | | formElements[i].value = postMessage[i].substring(delimitPos+1); |
| | | this._formNode.appendChild(formElements[i]); |
| | | } |
| | | } |
| | | |
| | | return formElements; |
| | | }, |
| | | |
| | | /** |
| | | * @description Uploads HTML form, including files/attachments, to the |
| | | * iframe created in createFrame. |
| | | * @method uploadFile |
| | | * @private |
| | | * @static |
| | | * @param {int} id The transaction id. |
| | | * @param {object} callback - User-defined callback object. |
| | | * @param {string} uri Fully qualified path of resource. |
| | | * @return {void} |
| | | */ |
| | | uploadFile:function(id, callback, uri, postData){ |
| | | |
| | | // Each iframe has an id prefix of "yuiIO" followed |
| | | // by the unique transaction id. |
| | | var frameId = 'yuiIO' + id; |
| | | var uploadEncoding = 'multipart/form-data'; |
| | | var io = document.getElementById(frameId); |
| | | |
| | | // Initialize the HTML form properties in case they are |
| | | // not defined in the HTML form. |
| | | this._formNode.action = uri; |
| | | this._formNode.method = 'POST'; |
| | | this._formNode.target = frameId; |
| | | |
| | | if(this._formNode.encoding){ |
| | | // IE does not respect property enctype for HTML forms. |
| | | // Instead it uses the property - "encoding". |
| | | this._formNode.encoding = uploadEncoding; |
| | | } |
| | | else{ |
| | | this._formNode.enctype = uploadEncoding; |
| | | } |
| | | |
| | | |
| | | if(postData){ |
| | | var oElements = this.appendPostData(postData); |
| | | } |
| | | |
| | | this._formNode.submit(); |
| | | |
| | | if(oElements && oElements.length > 0){ |
| | | for(var i=0; i < oElements.length; i++){ |
| | | this._formNode.removeChild(oElements[i]); |
| | | } |
| | | } |
| | | |
| | | // Reset HTML form status properties. |
| | | this.resetFormState(); |
| | | |
| | | // Create the upload callback handler that fires when the iframe |
| | | // receives the load event. Subsequently, the event handler is detached |
| | | // and the iframe removed from the document. |
| | | |
| | | var uploadCallback = function() |
| | | { |
| | | var obj = {}; |
| | | obj.tId = id; |
| | | obj.argument = callback.argument; |
| | | |
| | | try |
| | | { |
| | | obj.responseText = io.contentWindow.document.body?io.contentWindow.document.body.innerHTML:null; |
| | | obj.responseXML = io.contentWindow.document.XMLDocument?io.contentWindow.document.XMLDocument:io.contentWindow.document; |
| | | } |
| | | catch(e){} |
| | | |
| | | if(callback && callback.upload){ |
| | | if(!callback.scope){ |
| | | callback.upload(obj); |
| | | YAHOO.log('Upload callback.', 'info', 'Connection'); |
| | | } |
| | | else{ |
| | | callback.upload.apply(callback.scope, [obj]); |
| | | YAHOO.log('Upload callback with scope.', 'info', 'Connection'); |
| | | } |
| | | } |
| | | |
| | | if(YAHOO.util.Event){ |
| | | YAHOO.util.Event.removeListener(io, "load", uploadCallback); |
| | | } |
| | | else if(window.detachEvent){ |
| | | io.detachEvent('onload', uploadCallback); |
| | | } |
| | | else{ |
| | | io.removeEventListener('load', uploadCallback, false); |
| | | } |
| | | setTimeout( |
| | | function(){ |
| | | document.body.removeChild(io); |
| | | YAHOO.log('File upload iframe destroyed. Id is:' + frameId, 'info', 'Connection'); |
| | | }, 100); |
| | | }; |
| | | |
| | | |
| | | // Bind the onload handler to the iframe to detect the file upload response. |
| | | if(YAHOO.util.Event){ |
| | | YAHOO.util.Event.addListener(io, "load", uploadCallback); |
| | | } |
| | | else if(window.attachEvent){ |
| | | io.attachEvent('onload', uploadCallback); |
| | | } |
| | | else{ |
| | | io.addEventListener('load', uploadCallback, false); |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * @description Method to terminate a transaction, if it has not reached readyState 4. |
| | | * @method abort |
| | | * @public |
| | | * @static |
| | | * @param {object} o The connection object returned by asyncRequest. |
| | | * @param {object} callback User-defined callback object. |
| | | * @param {string} isTimeout boolean to indicate if abort was a timeout. |
| | | * @return {boolean} |
| | | */ |
| | | abort:function(o, callback, isTimeout) |
| | | { |
| | | if(this.isCallInProgress(o)){ |
| | | o.conn.abort(); |
| | | window.clearInterval(this._poll[o.tId]); |
| | | delete this._poll[o.tId]; |
| | | if(isTimeout){ |
| | | delete this._timeOut[o.tId]; |
| | | } |
| | | |
| | | this.handleTransactionResponse(o, callback, true); |
| | | YAHOO.log('Transaction ' + o.tId + ' aborted.', 'info', 'Connection'); |
| | | |
| | | return true; |
| | | } |
| | | else{ |
| | | YAHOO.log('Transaction ' + o.tId + ' abort call failed.', 'warn', 'Connection'); |
| | | return false; |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * Public method to check if the transaction is still being processed. |
| | | * |
| | | * @method isCallInProgress |
| | | * @public |
| | | * @static |
| | | * @param {object} o The connection object returned by asyncRequest |
| | | * @return {boolean} |
| | | */ |
| | | isCallInProgress:function(o) |
| | | { |
| | | // if the XHR object assigned to the transaction has not been dereferenced, |
| | | // then check its readyState status. Otherwise, return false. |
| | | if(o.conn){ |
| | | return o.conn.readyState != 4 && o.conn.readyState != 0; |
| | | } |
| | | else{ |
| | | //The XHR object has been destroyed. |
| | | return false; |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * @description Dereference the XHR instance and the connection object after the transaction is completed. |
| | | * @method releaseObject |
| | | * @private |
| | | * @static |
| | | * @param {object} o The connection object |
| | | * @return {void} |
| | | */ |
| | | releaseObject:function(o) |
| | | { |
| | | //dereference the XHR instance. |
| | | o.conn = null; |
| | | YAHOO.log('Connection object for transaction ' + o.tId + ' destroyed.', 'info', 'Connection'); |
| | | //dereference the connection object. |
| | | o = null; |
| | | } |
| | | }; |
| | | YAHOO.register("connection", YAHOO.widget.Module, {version: "2.2.0", build: "127"}); |
New file |
| | |
| | | /* |
| | | 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.Connect={_msxml_progid:['MSXML2.XMLHTTP.3.0','MSXML2.XMLHTTP','Microsoft.XMLHTTP'],_http_headers:{},_has_http_headers:false,_use_default_post_header:true,_default_post_header:'application/x-www-form-urlencoded',_use_default_xhr_header:true,_default_xhr_header:'XMLHttpRequest',_has_default_headers:true,_default_headers:{},_isFormSubmit:false,_isFileUpload:false,_formNode:null,_sFormData:null,_poll:{},_timeOut:{},_polling_interval:50,_transaction_id:0,setProgId:function(id) |
| | | {this._msxml_progid.unshift(id);},setDefaultPostHeader:function(b) |
| | | {this._use_default_post_header=b;},setDefaultXhrHeader:function(b) |
| | | {this._use_default_xhr_header=b;},setPollingInterval:function(i) |
| | | {if(typeof i=='number'&&isFinite(i)){this._polling_interval=i;}},createXhrObject:function(transactionId) |
| | | {var obj,http;try |
| | | {http=new XMLHttpRequest();obj={conn:http,tId:transactionId};} |
| | | catch(e) |
| | | {for(var i=0;i<this._msxml_progid.length;++i){try |
| | | {http=new ActiveXObject(this._msxml_progid[i]);obj={conn:http,tId:transactionId};break;} |
| | | catch(e){}}} |
| | | finally |
| | | {return obj;}},getConnectionObject:function() |
| | | {var o;var tId=this._transaction_id;try |
| | | {o=this.createXhrObject(tId);if(o){this._transaction_id++;}} |
| | | catch(e){} |
| | | finally |
| | | {return o;}},asyncRequest:function(method,uri,callback,postData) |
| | | {var o=this.getConnectionObject();if(!o){return null;} |
| | | else{if(this._isFormSubmit){if(this._isFileUpload){this.uploadFile(o.tId,callback,uri,postData);this.releaseObject(o);return;} |
| | | if(method.toUpperCase()=='GET'){if(this._sFormData.length!=0){uri+=((uri.indexOf('?')==-1)?'?':'&')+this._sFormData;} |
| | | else{uri+="?"+this._sFormData;}} |
| | | else if(method.toUpperCase()=='POST'){postData=postData?this._sFormData+"&"+postData:this._sFormData;}} |
| | | o.conn.open(method,uri,true);if(this._use_default_xhr_header){if(!this._default_headers['X-Requested-With']){this.initHeader('X-Requested-With',this._default_xhr_header,true);}} |
| | | if(this._isFormSubmit||(postData&&this._use_default_post_header)){this.initHeader('Content-Type',this._default_post_header);if(this._isFormSubmit){this.resetFormState();}} |
| | | if(this._has_default_headers||this._has_http_headers){this.setHeader(o);} |
| | | this.handleReadyState(o,callback);o.conn.send(postData||null);return o;}},handleReadyState:function(o,callback) |
| | | {var oConn=this;if(callback&&callback.timeout){this._timeOut[o.tId]=window.setTimeout(function(){oConn.abort(o,callback,true);},callback.timeout);} |
| | | this._poll[o.tId]=window.setInterval(function(){if(o.conn&&o.conn.readyState==4){window.clearInterval(oConn._poll[o.tId]);delete oConn._poll[o.tId];if(callback&&callback.timeout){delete oConn._timeOut[o.tId];} |
| | | oConn.handleTransactionResponse(o,callback);}},this._polling_interval);},handleTransactionResponse:function(o,callback,isAbort) |
| | | {if(!callback){this.releaseObject(o);return;} |
| | | var httpStatus,responseObject;try |
| | | {if(o.conn.status!==undefined&&o.conn.status!=0){httpStatus=o.conn.status;} |
| | | else{httpStatus=13030;}} |
| | | catch(e){httpStatus=13030;} |
| | | if(httpStatus>=200&&httpStatus<300){responseObject=this.createResponseObject(o,callback.argument);if(callback.success){if(!callback.scope){callback.success(responseObject);} |
| | | else{callback.success.apply(callback.scope,[responseObject]);}}} |
| | | else{switch(httpStatus){case 12002:case 12029:case 12030:case 12031:case 12152:case 13030:responseObject=this.createExceptionObject(o.tId,callback.argument,(isAbort?isAbort:false));if(callback.failure){if(!callback.scope){callback.failure(responseObject);} |
| | | else{callback.failure.apply(callback.scope,[responseObject]);}} |
| | | break;default:responseObject=this.createResponseObject(o,callback.argument);if(callback.failure){if(!callback.scope){callback.failure(responseObject);} |
| | | else{callback.failure.apply(callback.scope,[responseObject]);}}}} |
| | | this.releaseObject(o);responseObject=null;},createResponseObject:function(o,callbackArg) |
| | | {var obj={};var headerObj={};try |
| | | {var headerStr=o.conn.getAllResponseHeaders();var header=headerStr.split('\n');for(var i=0;i<header.length;i++){var delimitPos=header[i].indexOf(':');if(delimitPos!=-1){headerObj[header[i].substring(0,delimitPos)]=header[i].substring(delimitPos+2);}}} |
| | | catch(e){} |
| | | obj.tId=o.tId;obj.status=o.conn.status;obj.statusText=o.conn.statusText;obj.getResponseHeader=headerObj;obj.getAllResponseHeaders=headerStr;obj.responseText=o.conn.responseText;obj.responseXML=o.conn.responseXML;if(typeof callbackArg!==undefined){obj.argument=callbackArg;} |
| | | return obj;},createExceptionObject:function(tId,callbackArg,isAbort) |
| | | {var COMM_CODE=0;var COMM_ERROR='communication failure';var ABORT_CODE=-1;var ABORT_ERROR='transaction aborted';var obj={};obj.tId=tId;if(isAbort){obj.status=ABORT_CODE;obj.statusText=ABORT_ERROR;} |
| | | else{obj.status=COMM_CODE;obj.statusText=COMM_ERROR;} |
| | | if(callbackArg){obj.argument=callbackArg;} |
| | | return obj;},initHeader:function(label,value,isDefault) |
| | | {var headerObj=(isDefault)?this._default_headers:this._http_headers;if(headerObj[label]===undefined){headerObj[label]=value;} |
| | | else{headerObj[label]=value+","+headerObj[label];} |
| | | if(isDefault){this._has_default_headers=true;} |
| | | else{this._has_http_headers=true;}},setHeader:function(o) |
| | | {if(this._has_default_headers){for(var prop in this._default_headers){if(YAHOO.lang.hasOwnProperty(this._default_headers,prop)){o.conn.setRequestHeader(prop,this._default_headers[prop]);}}} |
| | | if(this._has_http_headers){for(var prop in this._http_headers){if(YAHOO.lang.hasOwnProperty(this._http_headers,prop)){o.conn.setRequestHeader(prop,this._http_headers[prop]);}} |
| | | delete this._http_headers;this._http_headers={};this._has_http_headers=false;}},resetDefaultHeaders:function(){delete this._default_headers |
| | | this._default_headers={};this._has_default_headers=false;},setForm:function(formId,isUpload,secureUri) |
| | | {this.resetFormState();var oForm;if(typeof formId=='string'){oForm=(document.getElementById(formId)||document.forms[formId]);} |
| | | else if(typeof formId=='object'){oForm=formId;} |
| | | else{return;} |
| | | if(isUpload){this.createFrame(secureUri?secureUri:null);this._isFormSubmit=true;this._isFileUpload=true;this._formNode=oForm;return;} |
| | | var oElement,oName,oValue,oDisabled;var hasSubmit=false;for(var i=0;i<oForm.elements.length;i++){oElement=oForm.elements[i];oDisabled=oForm.elements[i].disabled;oName=oForm.elements[i].name;oValue=oForm.elements[i].value;if(!oDisabled&&oName) |
| | | {switch(oElement.type) |
| | | {case'select-one':case'select-multiple':for(var j=0;j<oElement.options.length;j++){if(oElement.options[j].selected){if(window.ActiveXObject){this._sFormData+=encodeURIComponent(oName)+'='+encodeURIComponent(oElement.options[j].attributes['value'].specified?oElement.options[j].value:oElement.options[j].text)+'&';} |
| | | else{this._sFormData+=encodeURIComponent(oName)+'='+encodeURIComponent(oElement.options[j].hasAttribute('value')?oElement.options[j].value:oElement.options[j].text)+'&';}}} |
| | | break;case'radio':case'checkbox':if(oElement.checked){this._sFormData+=encodeURIComponent(oName)+'='+encodeURIComponent(oValue)+'&';} |
| | | break;case'file':case undefined:case'reset':case'button':break;case'submit':if(hasSubmit==false){this._sFormData+=encodeURIComponent(oName)+'='+encodeURIComponent(oValue)+'&';hasSubmit=true;} |
| | | break;default:this._sFormData+=encodeURIComponent(oName)+'='+encodeURIComponent(oValue)+'&';break;}}} |
| | | this._isFormSubmit=true;this._sFormData=this._sFormData.substr(0,this._sFormData.length-1);return this._sFormData;},resetFormState:function(){this._isFormSubmit=false;this._isFileUpload=false;this._formNode=null;this._sFormData="";},createFrame:function(secureUri){var frameId='yuiIO'+this._transaction_id;if(window.ActiveXObject){var io=document.createElement('<iframe id="'+frameId+'" name="'+frameId+'" />');if(typeof secureUri=='boolean'){io.src='javascript:false';} |
| | | else if(typeof secureURI=='string'){io.src=secureUri;}} |
| | | else{var io=document.createElement('iframe');io.id=frameId;io.name=frameId;} |
| | | io.style.position='absolute';io.style.top='-1000px';io.style.left='-1000px';document.body.appendChild(io);},appendPostData:function(postData) |
| | | {var formElements=[];var postMessage=postData.split('&');for(var i=0;i<postMessage.length;i++){var delimitPos=postMessage[i].indexOf('=');if(delimitPos!=-1){formElements[i]=document.createElement('input');formElements[i].type='hidden';formElements[i].name=postMessage[i].substring(0,delimitPos);formElements[i].value=postMessage[i].substring(delimitPos+1);this._formNode.appendChild(formElements[i]);}} |
| | | return formElements;},uploadFile:function(id,callback,uri,postData){var frameId='yuiIO'+id;var uploadEncoding='multipart/form-data';var io=document.getElementById(frameId);this._formNode.action=uri;this._formNode.method='POST';this._formNode.target=frameId;if(this._formNode.encoding){this._formNode.encoding=uploadEncoding;} |
| | | else{this._formNode.enctype=uploadEncoding;} |
| | | if(postData){var oElements=this.appendPostData(postData);} |
| | | this._formNode.submit();if(oElements&&oElements.length>0){for(var i=0;i<oElements.length;i++){this._formNode.removeChild(oElements[i]);}} |
| | | this.resetFormState();var uploadCallback=function() |
| | | {var obj={};obj.tId=id;obj.argument=callback.argument;try |
| | | {obj.responseText=io.contentWindow.document.body?io.contentWindow.document.body.innerHTML:null;obj.responseXML=io.contentWindow.document.XMLDocument?io.contentWindow.document.XMLDocument:io.contentWindow.document;} |
| | | catch(e){} |
| | | if(callback&&callback.upload){if(!callback.scope){callback.upload(obj);} |
| | | else{callback.upload.apply(callback.scope,[obj]);}} |
| | | if(YAHOO.util.Event){YAHOO.util.Event.removeListener(io,"load",uploadCallback);} |
| | | else if(window.detachEvent){io.detachEvent('onload',uploadCallback);} |
| | | else{io.removeEventListener('load',uploadCallback,false);} |
| | | setTimeout(function(){document.body.removeChild(io);},100);};if(YAHOO.util.Event){YAHOO.util.Event.addListener(io,"load",uploadCallback);} |
| | | else if(window.attachEvent){io.attachEvent('onload',uploadCallback);} |
| | | else{io.addEventListener('load',uploadCallback,false);}},abort:function(o,callback,isTimeout) |
| | | {if(this.isCallInProgress(o)){o.conn.abort();window.clearInterval(this._poll[o.tId]);delete this._poll[o.tId];if(isTimeout){delete this._timeOut[o.tId];} |
| | | this.handleTransactionResponse(o,callback,true);return true;} |
| | | else{return false;}},isCallInProgress:function(o) |
| | | {if(o.conn){return o.conn.readyState!=4&&o.conn.readyState!=0;} |
| | | else{return false;}},releaseObject:function(o) |
| | | {o.conn=null;o=null;}}; |
| | | YAHOO.register("connection", YAHOO.widget.Module, {version: "2.2.0", build: "127"}); |
New file |
| | |
| | | /* |
| | | 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 Connection Manager provides a simplified interface to the XMLHttpRequest |
| | | * object. It handles cross-browser instantiantion of XMLHttpRequest, negotiates the |
| | | * interactive states and server response, returning the results to a pre-defined |
| | | * callback you create. |
| | | * |
| | | * @namespace YAHOO.util |
| | | * @module connection |
| | | * @requires yahoo |
| | | */ |
| | | |
| | | /** |
| | | * The Connection Manager singleton provides methods for creating and managing |
| | | * asynchronous transactions. |
| | | * |
| | | * @class Connect |
| | | */ |
| | | |
| | | YAHOO.util.Connect = |
| | | { |
| | | /** |
| | | * @description Array of MSFT ActiveX ids for XMLHttpRequest. |
| | | * @property _msxml_progid |
| | | * @private |
| | | * @static |
| | | * @type array |
| | | */ |
| | | _msxml_progid:[ |
| | | 'MSXML2.XMLHTTP.3.0', |
| | | 'MSXML2.XMLHTTP', |
| | | 'Microsoft.XMLHTTP' |
| | | ], |
| | | |
| | | /** |
| | | * @description Object literal of HTTP header(s) |
| | | * @property _http_header |
| | | * @private |
| | | * @static |
| | | * @type object |
| | | */ |
| | | _http_headers:{}, |
| | | |
| | | /** |
| | | * @description Determines if HTTP headers are set. |
| | | * @property _has_http_headers |
| | | * @private |
| | | * @static |
| | | * @type boolean |
| | | */ |
| | | _has_http_headers:false, |
| | | |
| | | /** |
| | | * @description Determines if a default header of |
| | | * Content-Type of 'application/x-www-form-urlencoded' |
| | | * will be added to any client HTTP headers sent for POST |
| | | * transactions. |
| | | * @property _use_default_post_header |
| | | * @private |
| | | * @static |
| | | * @type boolean |
| | | */ |
| | | _use_default_post_header:true, |
| | | |
| | | /** |
| | | * @description Determines if a default header of |
| | | * Content-Type of 'application/x-www-form-urlencoded' |
| | | * will be added to client HTTP headers sent for POST |
| | | * transactions. |
| | | * @property _default_post_header |
| | | * @private |
| | | * @static |
| | | * @type boolean |
| | | */ |
| | | _default_post_header:'application/x-www-form-urlencoded', |
| | | |
| | | /** |
| | | * @description Determines if a default header of |
| | | * 'X-Requested-With: XMLHttpRequest' |
| | | * will be added to each transaction. |
| | | * @property _use_default_xhr_header |
| | | * @private |
| | | * @static |
| | | * @type boolean |
| | | */ |
| | | _use_default_xhr_header:true, |
| | | |
| | | /** |
| | | * @description The default header value for the label |
| | | * "X-Requested-With". This is sent with each |
| | | * transaction, by default, to identify the |
| | | * request as being made by YUI Connection Manager. |
| | | * @property _default_xhr_header |
| | | * @private |
| | | * @static |
| | | * @type boolean |
| | | */ |
| | | _default_xhr_header:'XMLHttpRequest', |
| | | |
| | | /** |
| | | * @description Determines if custom, default headers |
| | | * are set for each transaction. |
| | | * @property _has_default_header |
| | | * @private |
| | | * @static |
| | | * @type boolean |
| | | */ |
| | | _has_default_headers:true, |
| | | |
| | | /** |
| | | * @description Determines if custom, default headers |
| | | * are set for each transaction. |
| | | * @property _has_default_header |
| | | * @private |
| | | * @static |
| | | * @type boolean |
| | | */ |
| | | _default_headers:{}, |
| | | |
| | | /** |
| | | * @description Property modified by setForm() to determine if the data |
| | | * should be submitted as an HTML form. |
| | | * @property _isFormSubmit |
| | | * @private |
| | | * @static |
| | | * @type boolean |
| | | */ |
| | | _isFormSubmit:false, |
| | | |
| | | /** |
| | | * @description Property modified by setForm() to determine if a file(s) |
| | | * upload is expected. |
| | | * @property _isFileUpload |
| | | * @private |
| | | * @static |
| | | * @type boolean |
| | | */ |
| | | _isFileUpload:false, |
| | | |
| | | /** |
| | | * @description Property modified by setForm() to set a reference to the HTML |
| | | * form node if the desired action is file upload. |
| | | * @property _formNode |
| | | * @private |
| | | * @static |
| | | * @type object |
| | | */ |
| | | _formNode:null, |
| | | |
| | | /** |
| | | * @description Property modified by setForm() to set the HTML form data |
| | | * for each transaction. |
| | | * @property _sFormData |
| | | * @private |
| | | * @static |
| | | * @type string |
| | | */ |
| | | _sFormData:null, |
| | | |
| | | /** |
| | | * @description Collection of polling references to the polling mechanism in handleReadyState. |
| | | * @property _poll |
| | | * @private |
| | | * @static |
| | | * @type object |
| | | */ |
| | | _poll:{}, |
| | | |
| | | /** |
| | | * @description Queue of timeout values for each transaction callback with a defined timeout value. |
| | | * @property _timeOut |
| | | * @private |
| | | * @static |
| | | * @type object |
| | | */ |
| | | _timeOut:{}, |
| | | |
| | | /** |
| | | * @description The polling frequency, in milliseconds, for HandleReadyState. |
| | | * when attempting to determine a transaction's XHR readyState. |
| | | * The default is 50 milliseconds. |
| | | * @property _polling_interval |
| | | * @private |
| | | * @static |
| | | * @type int |
| | | */ |
| | | _polling_interval:50, |
| | | |
| | | /** |
| | | * @description A transaction counter that increments the transaction id for each transaction. |
| | | * @property _transaction_id |
| | | * @private |
| | | * @static |
| | | * @type int |
| | | */ |
| | | _transaction_id:0, |
| | | |
| | | /** |
| | | * @description Member to add an ActiveX id to the existing xml_progid array. |
| | | * In the event(unlikely) a new ActiveX id is introduced, it can be added |
| | | * without internal code modifications. |
| | | * @method setProgId |
| | | * @public |
| | | * @static |
| | | * @param {string} id The ActiveX id to be added to initialize the XHR object. |
| | | * @return void |
| | | */ |
| | | setProgId:function(id) |
| | | { |
| | | this._msxml_progid.unshift(id); |
| | | }, |
| | | |
| | | /** |
| | | * @description Member to enable or disable the default POST header. |
| | | * @method setDefaultPostHeader |
| | | * @public |
| | | * @static |
| | | * @param {boolean} b Set and use default header - true or false . |
| | | * @return void |
| | | */ |
| | | setDefaultPostHeader:function(b) |
| | | { |
| | | this._use_default_post_header = b; |
| | | }, |
| | | |
| | | /** |
| | | * @description Member to enable or disable the default POST header. |
| | | * @method setDefaultXhrHeader |
| | | * @public |
| | | * @static |
| | | * @param {boolean} b Set and use default header - true or false . |
| | | * @return void |
| | | */ |
| | | setDefaultXhrHeader:function(b) |
| | | { |
| | | this._use_default_xhr_header = b; |
| | | }, |
| | | |
| | | /** |
| | | * @description Member to modify the default polling interval. |
| | | * @method setPollingInterval |
| | | * @public |
| | | * @static |
| | | * @param {int} i The polling interval in milliseconds. |
| | | * @return void |
| | | */ |
| | | setPollingInterval:function(i) |
| | | { |
| | | if(typeof i == 'number' && isFinite(i)){ |
| | | this._polling_interval = i; |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * @description Instantiates a XMLHttpRequest object and returns an object with two properties: |
| | | * the XMLHttpRequest instance and the transaction id. |
| | | * @method createXhrObject |
| | | * @private |
| | | * @static |
| | | * @param {int} transactionId Property containing the transaction id for this transaction. |
| | | * @return object |
| | | */ |
| | | createXhrObject:function(transactionId) |
| | | { |
| | | var obj,http; |
| | | try |
| | | { |
| | | // Instantiates XMLHttpRequest in non-IE browsers and assigns to http. |
| | | http = new XMLHttpRequest(); |
| | | // Object literal with http and tId properties |
| | | obj = { conn:http, tId:transactionId }; |
| | | } |
| | | catch(e) |
| | | { |
| | | for(var i=0; i<this._msxml_progid.length; ++i){ |
| | | try |
| | | { |
| | | // Instantiates XMLHttpRequest for IE and assign to http. |
| | | http = new ActiveXObject(this._msxml_progid[i]); |
| | | // Object literal with conn and tId properties |
| | | obj = { conn:http, tId:transactionId }; |
| | | break; |
| | | } |
| | | catch(e){} |
| | | } |
| | | } |
| | | finally |
| | | { |
| | | return obj; |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * @description This method is called by asyncRequest to create a |
| | | * valid connection object for the transaction. It also passes a |
| | | * transaction id and increments the transaction id counter. |
| | | * @method getConnectionObject |
| | | * @private |
| | | * @static |
| | | * @return {object} |
| | | */ |
| | | getConnectionObject:function() |
| | | { |
| | | var o; |
| | | var tId = this._transaction_id; |
| | | |
| | | try |
| | | { |
| | | o = this.createXhrObject(tId); |
| | | if(o){ |
| | | this._transaction_id++; |
| | | } |
| | | } |
| | | catch(e){} |
| | | finally |
| | | { |
| | | return o; |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * @description Method for initiating an asynchronous request via the XHR object. |
| | | * @method asyncRequest |
| | | * @public |
| | | * @static |
| | | * @param {string} method HTTP transaction method |
| | | * @param {string} uri Fully qualified path of resource |
| | | * @param {callback} callback User-defined callback function or object |
| | | * @param {string} postData POST body |
| | | * @return {object} Returns the connection object |
| | | */ |
| | | asyncRequest:function(method, uri, callback, postData) |
| | | { |
| | | var o = this.getConnectionObject(); |
| | | |
| | | if(!o){ |
| | | return null; |
| | | } |
| | | else{ |
| | | if(this._isFormSubmit){ |
| | | if(this._isFileUpload){ |
| | | this.uploadFile(o.tId, callback, uri, postData); |
| | | this.releaseObject(o); |
| | | |
| | | return; |
| | | } |
| | | |
| | | //If the specified HTTP method is GET, setForm() will return an |
| | | //encoded string that is concatenated to the uri to |
| | | //create a querystring. |
| | | if(method.toUpperCase() == 'GET'){ |
| | | if(this._sFormData.length != 0){ |
| | | // If the URI already contains a querystring, append an ampersand |
| | | // and then concatenate _sFormData to the URI. |
| | | uri += ((uri.indexOf('?') == -1)?'?':'&') + this._sFormData; |
| | | } |
| | | else{ |
| | | uri += "?" + this._sFormData; |
| | | } |
| | | } |
| | | else if(method.toUpperCase() == 'POST'){ |
| | | //If POST data exist in addition to the HTML form data, |
| | | //it will be concatenated to the form data. |
| | | postData = postData?this._sFormData + "&" + postData:this._sFormData; |
| | | } |
| | | } |
| | | |
| | | o.conn.open(method, uri, true); |
| | | |
| | | if(this._use_default_xhr_header){ |
| | | if(!this._default_headers['X-Requested-With']){ |
| | | this.initHeader('X-Requested-With', this._default_xhr_header, true); |
| | | } |
| | | } |
| | | if(this._isFormSubmit || (postData && this._use_default_post_header)){ |
| | | this.initHeader('Content-Type', this._default_post_header); |
| | | if(this._isFormSubmit){ |
| | | this.resetFormState(); |
| | | } |
| | | } |
| | | |
| | | if(this._has_default_headers || this._has_http_headers){ |
| | | this.setHeader(o); |
| | | } |
| | | |
| | | this.handleReadyState(o, callback); |
| | | o.conn.send(postData || null); |
| | | |
| | | return o; |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * @description This method serves as a timer that polls the XHR object's readyState |
| | | * property during a transaction, instead of binding a callback to the |
| | | * onreadystatechange event. Upon readyState 4, handleTransactionResponse |
| | | * will process the response, and the timer will be cleared. |
| | | * @method handleReadyState |
| | | * @private |
| | | * @static |
| | | * @param {object} o The connection object |
| | | * @param {callback} callback The user-defined callback object |
| | | * @return {void} |
| | | */ |
| | | handleReadyState:function(o, callback) |
| | | { |
| | | var oConn = this; |
| | | |
| | | if(callback && callback.timeout){ |
| | | this._timeOut[o.tId] = window.setTimeout(function(){ oConn.abort(o, callback, true); }, callback.timeout); |
| | | } |
| | | |
| | | this._poll[o.tId] = window.setInterval( |
| | | function(){ |
| | | if(o.conn && o.conn.readyState == 4){ |
| | | window.clearInterval(oConn._poll[o.tId]); |
| | | delete oConn._poll[o.tId]; |
| | | |
| | | if(callback && callback.timeout){ |
| | | delete oConn._timeOut[o.tId]; |
| | | } |
| | | |
| | | oConn.handleTransactionResponse(o, callback); |
| | | } |
| | | } |
| | | ,this._polling_interval); |
| | | }, |
| | | |
| | | /** |
| | | * @description This method attempts to interpret the server response and |
| | | * determine whether the transaction was successful, or if an error or |
| | | * exception was encountered. |
| | | * @method handleTransactionResponse |
| | | * @private |
| | | * @static |
| | | * @param {object} o The connection object |
| | | * @param {object} callback The sser-defined callback object |
| | | * @param {boolean} isAbort Determines if the transaction was aborted. |
| | | * @return {void} |
| | | */ |
| | | handleTransactionResponse:function(o, callback, isAbort) |
| | | { |
| | | // If no valid callback is provided, then do not process any callback handling. |
| | | if(!callback){ |
| | | this.releaseObject(o); |
| | | return; |
| | | } |
| | | |
| | | var httpStatus, responseObject; |
| | | |
| | | try |
| | | { |
| | | if(o.conn.status !== undefined && o.conn.status != 0){ |
| | | httpStatus = o.conn.status; |
| | | } |
| | | else{ |
| | | httpStatus = 13030; |
| | | } |
| | | } |
| | | catch(e){ |
| | | // 13030 is the custom code to indicate the condition -- in Mozilla/FF -- |
| | | // when the o object's status and statusText properties are |
| | | // unavailable, and a query attempt throws an exception. |
| | | httpStatus = 13030; |
| | | } |
| | | |
| | | if(httpStatus >= 200 && httpStatus < 300){ |
| | | responseObject = this.createResponseObject(o, callback.argument); |
| | | if(callback.success){ |
| | | if(!callback.scope){ |
| | | callback.success(responseObject); |
| | | } |
| | | else{ |
| | | // If a scope property is defined, the callback will be fired from |
| | | // the context of the object. |
| | | callback.success.apply(callback.scope, [responseObject]); |
| | | } |
| | | } |
| | | } |
| | | else{ |
| | | switch(httpStatus){ |
| | | // The following cases are wininet.dll error codes that may be encountered. |
| | | case 12002: // Server timeout |
| | | case 12029: // 12029 to 12031 correspond to dropped connections. |
| | | case 12030: |
| | | case 12031: |
| | | case 12152: // Connection closed by server. |
| | | case 13030: // See above comments for variable status. |
| | | responseObject = this.createExceptionObject(o.tId, callback.argument, (isAbort?isAbort:false)); |
| | | if(callback.failure){ |
| | | if(!callback.scope){ |
| | | callback.failure(responseObject); |
| | | } |
| | | else{ |
| | | callback.failure.apply(callback.scope, [responseObject]); |
| | | } |
| | | } |
| | | break; |
| | | default: |
| | | responseObject = this.createResponseObject(o, callback.argument); |
| | | if(callback.failure){ |
| | | if(!callback.scope){ |
| | | callback.failure(responseObject); |
| | | } |
| | | else{ |
| | | callback.failure.apply(callback.scope, [responseObject]); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | this.releaseObject(o); |
| | | responseObject = null; |
| | | }, |
| | | |
| | | /** |
| | | * @description This method evaluates the server response, creates and returns the results via |
| | | * its properties. Success and failure cases will differ in the response |
| | | * object's property values. |
| | | * @method createResponseObject |
| | | * @private |
| | | * @static |
| | | * @param {object} o The connection object |
| | | * @param {callbackArg} callbackArg The user-defined argument or arguments to be passed to the callback |
| | | * @return {object} |
| | | */ |
| | | createResponseObject:function(o, callbackArg) |
| | | { |
| | | var obj = {}; |
| | | var headerObj = {}; |
| | | |
| | | try |
| | | { |
| | | var headerStr = o.conn.getAllResponseHeaders(); |
| | | var header = headerStr.split('\n'); |
| | | for(var i=0; i<header.length; i++){ |
| | | var delimitPos = header[i].indexOf(':'); |
| | | if(delimitPos != -1){ |
| | | headerObj[header[i].substring(0,delimitPos)] = header[i].substring(delimitPos+2); |
| | | } |
| | | } |
| | | } |
| | | catch(e){} |
| | | |
| | | obj.tId = o.tId; |
| | | obj.status = o.conn.status; |
| | | obj.statusText = o.conn.statusText; |
| | | obj.getResponseHeader = headerObj; |
| | | obj.getAllResponseHeaders = headerStr; |
| | | obj.responseText = o.conn.responseText; |
| | | obj.responseXML = o.conn.responseXML; |
| | | |
| | | if(typeof callbackArg !== undefined){ |
| | | obj.argument = callbackArg; |
| | | } |
| | | |
| | | return obj; |
| | | }, |
| | | |
| | | /** |
| | | * @description If a transaction cannot be completed due to dropped or closed connections, |
| | | * there may be not be enough information to build a full response object. |
| | | * The failure callback will be fired and this specific condition can be identified |
| | | * by a status property value of 0. |
| | | * |
| | | * If an abort was successful, the status property will report a value of -1. |
| | | * |
| | | * @method createExceptionObject |
| | | * @private |
| | | * @static |
| | | * @param {int} tId The Transaction Id |
| | | * @param {callbackArg} callbackArg The user-defined argument or arguments to be passed to the callback |
| | | * @param {boolean} isAbort Determines if the exception case is caused by a transaction abort |
| | | * @return {object} |
| | | */ |
| | | createExceptionObject:function(tId, callbackArg, isAbort) |
| | | { |
| | | var COMM_CODE = 0; |
| | | var COMM_ERROR = 'communication failure'; |
| | | var ABORT_CODE = -1; |
| | | var ABORT_ERROR = 'transaction aborted'; |
| | | |
| | | var obj = {}; |
| | | |
| | | obj.tId = tId; |
| | | if(isAbort){ |
| | | obj.status = ABORT_CODE; |
| | | obj.statusText = ABORT_ERROR; |
| | | } |
| | | else{ |
| | | obj.status = COMM_CODE; |
| | | obj.statusText = COMM_ERROR; |
| | | } |
| | | |
| | | if(callbackArg){ |
| | | obj.argument = callbackArg; |
| | | } |
| | | |
| | | return obj; |
| | | }, |
| | | |
| | | /** |
| | | * @description Method that initializes the custom HTTP headers for the each transaction. |
| | | * @method initHeader |
| | | * @public |
| | | * @static |
| | | * @param {string} label The HTTP header label |
| | | * @param {string} value The HTTP header value |
| | | * @param {string} isDefault Determines if the specific header is a default header |
| | | * automatically sent with each transaction. |
| | | * @return {void} |
| | | */ |
| | | initHeader:function(label,value,isDefault) |
| | | { |
| | | var headerObj = (isDefault)?this._default_headers:this._http_headers; |
| | | |
| | | if(headerObj[label] === undefined){ |
| | | headerObj[label] = value; |
| | | } |
| | | else{ |
| | | // Concatenate multiple values, comma-delimited, |
| | | // for the same header label, |
| | | headerObj[label] = value + "," + headerObj[label]; |
| | | } |
| | | |
| | | if(isDefault){ |
| | | this._has_default_headers = true; |
| | | } |
| | | else{ |
| | | this._has_http_headers = true; |
| | | } |
| | | }, |
| | | |
| | | |
| | | /** |
| | | * @description Accessor that sets the HTTP headers for each transaction. |
| | | * @method setHeader |
| | | * @private |
| | | * @static |
| | | * @param {object} o The connection object for the transaction. |
| | | * @return {void} |
| | | */ |
| | | setHeader:function(o) |
| | | { |
| | | if(this._has_default_headers){ |
| | | for(var prop in this._default_headers){ |
| | | if(YAHOO.lang.hasOwnProperty(this._default_headers,prop)){ |
| | | o.conn.setRequestHeader(prop, this._default_headers[prop]); |
| | | } |
| | | } |
| | | } |
| | | |
| | | if(this._has_http_headers){ |
| | | for(var prop in this._http_headers){ |
| | | if(YAHOO.lang.hasOwnProperty(this._http_headers,prop)){ |
| | | o.conn.setRequestHeader(prop, this._http_headers[prop]); |
| | | } |
| | | } |
| | | delete this._http_headers; |
| | | |
| | | this._http_headers = {}; |
| | | this._has_http_headers = false; |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * @description Resets the default HTTP headers object |
| | | * @method resetDefaultHeaders |
| | | * @public |
| | | * @static |
| | | * @return {void} |
| | | */ |
| | | resetDefaultHeaders:function(){ |
| | | delete this._default_headers |
| | | this._default_headers = {}; |
| | | this._has_default_headers = false; |
| | | }, |
| | | |
| | | /** |
| | | * @description This method assembles the form label and value pairs and |
| | | * constructs an encoded string. |
| | | * asyncRequest() will automatically initialize the |
| | | * transaction with a HTTP header Content-Type of |
| | | * application/x-www-form-urlencoded. |
| | | * @method setForm |
| | | * @public |
| | | * @static |
| | | * @param {string || object} form id or name attribute, or form object. |
| | | * @param {string} optional boolean to indicate SSL environment. |
| | | * @param {string || boolean} optional qualified path of iframe resource for SSL in IE. |
| | | * @return {string} string of the HTML form field name and value pairs.. |
| | | */ |
| | | setForm:function(formId, isUpload, secureUri) |
| | | { |
| | | this.resetFormState(); |
| | | var oForm; |
| | | if(typeof formId == 'string'){ |
| | | // Determine if the argument is a form id or a form name. |
| | | // Note form name usage is deprecated by supported |
| | | // here for legacy reasons. |
| | | oForm = (document.getElementById(formId) || document.forms[formId]); |
| | | } |
| | | else if(typeof formId == 'object'){ |
| | | // Treat argument as an HTML form object. |
| | | oForm = formId; |
| | | } |
| | | else{ |
| | | return; |
| | | } |
| | | |
| | | // If the isUpload argument is true, setForm will call createFrame to initialize |
| | | // an iframe as the form target. |
| | | // |
| | | // The argument secureURI is also required by IE in SSL environments |
| | | // where the secureURI string is a fully qualified HTTP path, used to set the source |
| | | // of the iframe, to a stub resource in the same domain. |
| | | if(isUpload){ |
| | | |
| | | // Create iframe in preparation for file upload. |
| | | this.createFrame(secureUri?secureUri:null); |
| | | |
| | | // Set form reference and file upload properties to true. |
| | | this._isFormSubmit = true; |
| | | this._isFileUpload = true; |
| | | this._formNode = oForm; |
| | | |
| | | return; |
| | | } |
| | | |
| | | var oElement, oName, oValue, oDisabled; |
| | | var hasSubmit = false; |
| | | |
| | | // Iterate over the form elements collection to construct the |
| | | // label-value pairs. |
| | | for (var i=0; i<oForm.elements.length; i++){ |
| | | oElement = oForm.elements[i]; |
| | | oDisabled = oForm.elements[i].disabled; |
| | | oName = oForm.elements[i].name; |
| | | oValue = oForm.elements[i].value; |
| | | |
| | | // Do not submit fields that are disabled or |
| | | // do not have a name attribute value. |
| | | if(!oDisabled && oName) |
| | | { |
| | | switch (oElement.type) |
| | | { |
| | | case 'select-one': |
| | | case 'select-multiple': |
| | | for(var j=0; j<oElement.options.length; j++){ |
| | | if(oElement.options[j].selected){ |
| | | if(window.ActiveXObject){ |
| | | this._sFormData += encodeURIComponent(oName) + '=' + encodeURIComponent(oElement.options[j].attributes['value'].specified?oElement.options[j].value:oElement.options[j].text) + '&'; |
| | | } |
| | | else{ |
| | | this._sFormData += encodeURIComponent(oName) + '=' + encodeURIComponent(oElement.options[j].hasAttribute('value')?oElement.options[j].value:oElement.options[j].text) + '&'; |
| | | } |
| | | |
| | | } |
| | | } |
| | | break; |
| | | case 'radio': |
| | | case 'checkbox': |
| | | if(oElement.checked){ |
| | | this._sFormData += encodeURIComponent(oName) + '=' + encodeURIComponent(oValue) + '&'; |
| | | } |
| | | break; |
| | | case 'file': |
| | | // stub case as XMLHttpRequest will only send the file path as a string. |
| | | case undefined: |
| | | // stub case for fieldset element which returns undefined. |
| | | case 'reset': |
| | | // stub case for input type reset button. |
| | | case 'button': |
| | | // stub case for input type button elements. |
| | | break; |
| | | case 'submit': |
| | | if(hasSubmit == false){ |
| | | this._sFormData += encodeURIComponent(oName) + '=' + encodeURIComponent(oValue) + '&'; |
| | | hasSubmit = true; |
| | | } |
| | | break; |
| | | default: |
| | | this._sFormData += encodeURIComponent(oName) + '=' + encodeURIComponent(oValue) + '&'; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | this._isFormSubmit = true; |
| | | this._sFormData = this._sFormData.substr(0, this._sFormData.length - 1); |
| | | |
| | | return this._sFormData; |
| | | }, |
| | | |
| | | /** |
| | | * @description Resets HTML form properties when an HTML form or HTML form |
| | | * with file upload transaction is sent. |
| | | * @method resetFormState |
| | | * @private |
| | | * @static |
| | | * @return {void} |
| | | */ |
| | | resetFormState:function(){ |
| | | this._isFormSubmit = false; |
| | | this._isFileUpload = false; |
| | | this._formNode = null; |
| | | this._sFormData = ""; |
| | | }, |
| | | |
| | | /** |
| | | * @description Creates an iframe to be used for form file uploads. It is remove from the |
| | | * document upon completion of the upload transaction. |
| | | * @method createFrame |
| | | * @private |
| | | * @static |
| | | * @param {string} optional qualified path of iframe resource for SSL in IE. |
| | | * @return {void} |
| | | */ |
| | | createFrame:function(secureUri){ |
| | | |
| | | // IE does not allow the setting of id and name attributes as object |
| | | // properties via createElement(). A different iframe creation |
| | | // pattern is required for IE. |
| | | var frameId = 'yuiIO' + this._transaction_id; |
| | | if(window.ActiveXObject){ |
| | | var io = document.createElement('<iframe id="' + frameId + '" name="' + frameId + '" />'); |
| | | |
| | | // IE will throw a security exception in an SSL environment if the |
| | | // iframe source is undefined. |
| | | if(typeof secureUri == 'boolean'){ |
| | | io.src = 'javascript:false'; |
| | | } |
| | | else if(typeof secureURI == 'string'){ |
| | | // Deprecated |
| | | io.src = secureUri; |
| | | } |
| | | } |
| | | else{ |
| | | var io = document.createElement('iframe'); |
| | | io.id = frameId; |
| | | io.name = frameId; |
| | | } |
| | | |
| | | io.style.position = 'absolute'; |
| | | io.style.top = '-1000px'; |
| | | io.style.left = '-1000px'; |
| | | |
| | | document.body.appendChild(io); |
| | | }, |
| | | |
| | | /** |
| | | * @description Parses the POST data and creates hidden form elements |
| | | * for each key-value, and appends them to the HTML form object. |
| | | * @method appendPostData |
| | | * @private |
| | | * @static |
| | | * @param {string} postData The HTTP POST data |
| | | * @return {array} formElements Collection of hidden fields. |
| | | */ |
| | | appendPostData:function(postData) |
| | | { |
| | | var formElements = []; |
| | | var postMessage = postData.split('&'); |
| | | for(var i=0; i < postMessage.length; i++){ |
| | | var delimitPos = postMessage[i].indexOf('='); |
| | | if(delimitPos != -1){ |
| | | formElements[i] = document.createElement('input'); |
| | | formElements[i].type = 'hidden'; |
| | | formElements[i].name = postMessage[i].substring(0,delimitPos); |
| | | formElements[i].value = postMessage[i].substring(delimitPos+1); |
| | | this._formNode.appendChild(formElements[i]); |
| | | } |
| | | } |
| | | |
| | | return formElements; |
| | | }, |
| | | |
| | | /** |
| | | * @description Uploads HTML form, including files/attachments, to the |
| | | * iframe created in createFrame. |
| | | * @method uploadFile |
| | | * @private |
| | | * @static |
| | | * @param {int} id The transaction id. |
| | | * @param {object} callback - User-defined callback object. |
| | | * @param {string} uri Fully qualified path of resource. |
| | | * @return {void} |
| | | */ |
| | | uploadFile:function(id, callback, uri, postData){ |
| | | |
| | | // Each iframe has an id prefix of "yuiIO" followed |
| | | // by the unique transaction id. |
| | | var frameId = 'yuiIO' + id; |
| | | var uploadEncoding = 'multipart/form-data'; |
| | | var io = document.getElementById(frameId); |
| | | |
| | | // Initialize the HTML form properties in case they are |
| | | // not defined in the HTML form. |
| | | this._formNode.action = uri; |
| | | this._formNode.method = 'POST'; |
| | | this._formNode.target = frameId; |
| | | |
| | | if(this._formNode.encoding){ |
| | | // IE does not respect property enctype for HTML forms. |
| | | // Instead it uses the property - "encoding". |
| | | this._formNode.encoding = uploadEncoding; |
| | | } |
| | | else{ |
| | | this._formNode.enctype = uploadEncoding; |
| | | } |
| | | |
| | | |
| | | if(postData){ |
| | | var oElements = this.appendPostData(postData); |
| | | } |
| | | |
| | | this._formNode.submit(); |
| | | |
| | | if(oElements && oElements.length > 0){ |
| | | for(var i=0; i < oElements.length; i++){ |
| | | this._formNode.removeChild(oElements[i]); |
| | | } |
| | | } |
| | | |
| | | // Reset HTML form status properties. |
| | | this.resetFormState(); |
| | | |
| | | // Create the upload callback handler that fires when the iframe |
| | | // receives the load event. Subsequently, the event handler is detached |
| | | // and the iframe removed from the document. |
| | | |
| | | var uploadCallback = function() |
| | | { |
| | | var obj = {}; |
| | | obj.tId = id; |
| | | obj.argument = callback.argument; |
| | | |
| | | try |
| | | { |
| | | obj.responseText = io.contentWindow.document.body?io.contentWindow.document.body.innerHTML:null; |
| | | obj.responseXML = io.contentWindow.document.XMLDocument?io.contentWindow.document.XMLDocument:io.contentWindow.document; |
| | | } |
| | | catch(e){} |
| | | |
| | | if(callback && callback.upload){ |
| | | if(!callback.scope){ |
| | | callback.upload(obj); |
| | | } |
| | | else{ |
| | | callback.upload.apply(callback.scope, [obj]); |
| | | } |
| | | } |
| | | |
| | | if(YAHOO.util.Event){ |
| | | YAHOO.util.Event.removeListener(io, "load", uploadCallback); |
| | | } |
| | | else if(window.detachEvent){ |
| | | io.detachEvent('onload', uploadCallback); |
| | | } |
| | | else{ |
| | | io.removeEventListener('load', uploadCallback, false); |
| | | } |
| | | setTimeout( |
| | | function(){ |
| | | document.body.removeChild(io); |
| | | }, 100); |
| | | }; |
| | | |
| | | |
| | | // Bind the onload handler to the iframe to detect the file upload response. |
| | | if(YAHOO.util.Event){ |
| | | YAHOO.util.Event.addListener(io, "load", uploadCallback); |
| | | } |
| | | else if(window.attachEvent){ |
| | | io.attachEvent('onload', uploadCallback); |
| | | } |
| | | else{ |
| | | io.addEventListener('load', uploadCallback, false); |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * @description Method to terminate a transaction, if it has not reached readyState 4. |
| | | * @method abort |
| | | * @public |
| | | * @static |
| | | * @param {object} o The connection object returned by asyncRequest. |
| | | * @param {object} callback User-defined callback object. |
| | | * @param {string} isTimeout boolean to indicate if abort was a timeout. |
| | | * @return {boolean} |
| | | */ |
| | | abort:function(o, callback, isTimeout) |
| | | { |
| | | if(this.isCallInProgress(o)){ |
| | | o.conn.abort(); |
| | | window.clearInterval(this._poll[o.tId]); |
| | | delete this._poll[o.tId]; |
| | | if(isTimeout){ |
| | | delete this._timeOut[o.tId]; |
| | | } |
| | | |
| | | this.handleTransactionResponse(o, callback, true); |
| | | |
| | | return true; |
| | | } |
| | | else{ |
| | | return false; |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * Public method to check if the transaction is still being processed. |
| | | * |
| | | * @method isCallInProgress |
| | | * @public |
| | | * @static |
| | | * @param {object} o The connection object returned by asyncRequest |
| | | * @return {boolean} |
| | | */ |
| | | isCallInProgress:function(o) |
| | | { |
| | | // if the XHR object assigned to the transaction has not been dereferenced, |
| | | // then check its readyState status. Otherwise, return false. |
| | | if(o.conn){ |
| | | return o.conn.readyState != 4 && o.conn.readyState != 0; |
| | | } |
| | | else{ |
| | | //The XHR object has been destroyed. |
| | | return false; |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * @description Dereference the XHR instance and the connection object after the transaction is completed. |
| | | * @method releaseObject |
| | | * @private |
| | | * @static |
| | | * @param {object} o The connection object |
| | | * @return {void} |
| | | */ |
| | | releaseObject:function(o) |
| | | { |
| | | //dereference the XHR instance. |
| | | o.conn = null; |
| | | //dereference the connection object. |
| | | o = null; |
| | | } |
| | | }; |
| | | YAHOO.register("connection", YAHOO.widget.Module, {version: "2.2.0", build: "127"}); |
New file |
| | |
| | | Container Release Notes |
| | | |
| | | *** version 2.2.0 *** |
| | | |
| | | Module |
| | | - Removed hardcoded file paths for image roots. Affected properties |
| | | include: |
| | | - YAHOO.widget.Module.IMG_ROOT |
| | | - YAHOO.widget.Module.IMG_ROOT_SSL |
| | | - HTML elements, created via createElement, now use lowercase. |
| | | |
| | | Panel |
| | | - To shield against CSS class collision, the following references now |
| | | have a "yui-" prefix: |
| | | - YAHOO.widget.Panel.CSS_PANEL now references CSS class "yui- |
| | | panel". |
| | | - YAHOO.widget.Panel.CSS_PANEL_CONTAINER now references CSS class |
| | | "yui-panel-container". |
| | | - Close button can now be configured via the CSS class "container- |
| | | close". |
| | | - HTML elements, created via createElement, now use lowercase. |
| | | |
| | | Dialog |
| | | - To shield against CSS class collision, the following references now |
| | | have a "yui-" prefix: |
| | | - YAHOO.widget.Dialog.CSS_DIALOG now references CSS class "yui- |
| | | dialog". |
| | | - HTML elements, created via createElement, now use lowercase. |
| | | |
| | | SimpleDialog |
| | | - Removed hardcoded file paths for SimpleDialog icons, which are now |
| | | configurable in CSS: |
| | | - YAHOO.widget.SimpleDialog.ICON_BLOCK now references CSS class |
| | | "blckicon". |
| | | - YAHOO.widget.SimpleDialog.ICON_ALARM now references CSS class |
| | | "alrticon". |
| | | - YAHOO.widget.SimpleDialog.ICON_HELP now references CSS class |
| | | "hlpicon". |
| | | - YAHOO.widget.SimpleDialog.ICON_INFO now references CSS class |
| | | "infoicon". |
| | | - YAHOO.widget.SimpleDialog.ICON_WARN now references CSS class |
| | | "warnicon". |
| | | - YAHOO.widget.SimpleDialog.ICON_TIP now references CSS class |
| | | "tipicon". |
| | | - To provide shield against CSS class collision the following |
| | | references now have a "yui-" prefix: |
| | | - YAHOO.widget.SimpleDialog.CSS_SIMPLEDIALOG now references CSS |
| | | class "yui-simple-dialog"; |
| | | |
| | | Tooltip |
| | | - To shield against CSS class collision, the following references now |
| | | have a "yui-" prefix: |
| | | - YAHOO.widget.Tooltip.CSS_TOOLTIP now references CSS class "yui- |
| | | tipicon" "yui-tt"; |
| | | |
| | | *** version 0.12.2 *** |
| | | |
| | | Module |
| | | - Corrected issue where listener was not properly removed from resize |
| | | monitor element when "monitorresize" is disabled |
| | | |
| | | Panel |
| | | - Fixed issue that would sometimes prevent select lists from working |
| | | properly in Firefox |
| | | |
| | | Dialog |
| | | - Fixed error that would occur when trying to create a Dialog where |
| | | the first form element is set to "disabled" |
| | | - Modified "close" property handler for Dialog/SimpleDialog to call |
| | | "cancel" instead of "hide" |
| | | |
| | | *** version 0.12.1 *** |
| | | |
| | | All Classes |
| | | - "monitorresize" property now functions in situations where |
| | | document.domain has been modified. |
| | | - YAHOO.widget.Module.textResizeEvent now fires when the font size is |
| | | changed (except for Opera, which uses "zoom" functionality that |
| | | prevents this) |
| | | - Event listeners attached to container elements are now properly |
| | | purged on destroy using YAHOO.util.Event.purgeElement |
| | | |
| | | Panel |
| | | - Fixed issue where focus events were broken on the page when a modal |
| | | Panel was created |
| | | |
| | | Dialog |
| | | - Fixed bug where hitting "enter" on a Dialog was forcing the default |
| | | submission behavior of the form's action to execute |
| | | - Dialog no longer tries to give focus to hidden form elements. |
| | | - Replaced references in Panel with   for XHTML |
| | | compliance. |
| | | - Fixed issue that was preventing Safari from successfully using the |
| | | getData() function |
| | | |
| | | *** version 0.12 *** |
| | | |
| | | All Classes |
| | | - New documentation format implemented, and removed unnecessary |
| | | prototype null references previously used for generating |
| | | documentation |
| | | |
| | | Config |
| | | - Added 'undefined' check when reading initial properties for |
| | | .reset() |
| | | - Fixed Firefox warning on .resetProperty() |
| | | - Fixed issue preventing resetProperty() from resetting values |
| | | correctly |
| | | |
| | | Module |
| | | - Removed unused "childNodesInDom" property |
| | | |
| | | Overlay |
| | | - Converted center() to use Dom utility |
| | | - Fixed configVisible() to properly detect actual visible/hidden |
| | | status in Internet Explorer, which reports "inherit" for all elements |
| | | by default. |
| | | - Updated onDomResize to properly reapply "context" property |
| | | - Unified scroll/resize handlers so that they fire properly (when the |
| | | event has completed) as opposed to constantly (as seen in Mozilla- |
| | | based browsers) |
| | | |
| | | Panel |
| | | - Modified modality mask to show before Panel is shown (prior to any |
| | | animation) |
| | | - Modified buildWrapper to eliminate cloning of the initial markup |
| | | module, which fixes issues with select options not maintaining their |
| | | default selections in IE |
| | | - Modality mask is now z-indexed properly so that the mask z-index is |
| | | always one less than the Panel z-index |
| | | |
| | | Dialog |
| | | - Fixed Connection to get "action" attribute using getAttribute, to |
| | | allow for form fields named "action" |
| | | - Added support for "GET" by retrieving the form "method" rather than |
| | | always defaulting to "POST" |
| | | |
| | | KeyListener |
| | | - Fixed to work properly with Safari 2.0 by matching against keyCode |
| | | or charCode |
| | | |
| | | *** version 0.11.4 *** |
| | | |
| | | - Panel: Modality mask is now properly removed from DOM on Panel |
| | | destroy. |
| | | |
| | | *** version 0.11.3 *** |
| | | |
| | | - Module: Fixed SSL warning issue in IE |
| | | - Overlay: Fixed memory leak related to iframe shim in IE |
| | | - Panel: No focusable elements under the mask can now be tabbed to |
| | | - Panel: Set Panel container overflow to hidden to fix scrolling issue |
| | | in Opera 9 |
| | | |
| | | *** version 0.11.2 *** |
| | | |
| | | - All: JsLint optimization |
| | | - Overlay: Fixed SSL issues with monitorresize property |
| | | - OverlayManager: Fixed z-index incrementing issues |
| | | - Dialog: Form elements called "name" will now function properly |
| | | - Dialog: Removed unnecessary scope:this reference |
| | | |
| | | *** version 0.11.1 *** |
| | | |
| | | - Tooltip: Removed incorrect logger statement |
| | | - Dialog: Corrected logic that was causing browser lockup in IE for |
| | | SimpleDialog |
| | | - Dialog: Fixed "firstButtom" typo |
| | | |
| | | *** version 0.11.0 *** |
| | | |
| | | - toString function added to all classes for easy logging |
| | | - YAHOO.extend is now being used for inheritance on all container |
| | | classes |
| | | - Module: monitorresize feature now works on all browsers |
| | | - Module: Fixed bug with image root and isSecure |
| | | - Overlay: Fixed bugs related to IFRAME shim positioning |
| | | - Overlay: center() now works in quirks mode |
| | | - Overlay: Overlay now has a custom destroy() method that also removes |
| | | the IFRAME shim |
| | | - OverlayManager: Fixed bug in the prototype that was preventing |
| | | multiple Managers on one page |
| | | - OverlayManager: focusEvent now fires at all appropriate times |
| | | - Tooltip: context can now be specified as an array, so Tooltips can be |
| | | reused across multiple context elements |
| | | - Tooltip: preventoverlap now functions properly for large context |
| | | elements (i.e, images) |
| | | - Tooltip: fixed bugs regarding setTimeout |
| | | - Tooltip: added mousemove event to allow for more accurate Tooltip |
| | | positioning |
| | | - Panel: added dragEvent for monitoring all event handlers for drag and |
| | | drop |
| | | - Panel: modality mask is now resized on scroll |
| | | - Panel: KeyListeners are now properly destroyed when the Panel is |
| | | destroyed |
| | | - Panel: Header is now sized properly in quirks mode |
| | | - Dialog: Blinking cursor issue is fixed for Firefox |
| | | - Dialog: callback object for Connection is now public (this.callback) |
| | | - Dialog: onsuccess/onfailure properties removed (as a result of the |
| | | public callback object) |
| | | - Dialog: Dialog is now invisible by default |
| | | - Dialog: Buttons are now properly cleaned up on destroy |
| | | |
| | | *** version 0.10.0 *** |
| | | |
| | | * Initial release |
| | | |
New file |
| | |
| | | /* |
| | | 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 |
| | | */ |
| | | .yui-overlay { |
| | | position:absolute; |
| | | display:block; |
| | | } |
| | | |
| | | .yui-tt { |
| | | visibility:hidden; |
| | | position:absolute; |
| | | color:#333; |
| | | background-color:#FDFFB4; |
| | | font-family:arial,helvetica,verdana,sans-serif; |
| | | padding:2px; |
| | | border:1px solid #FCC90D; |
| | | font:100% sans-serif; |
| | | width:auto; |
| | | } |
| | | |
| | | * html body.masked select { |
| | | visibility:hidden; |
| | | } |
| | | |
| | | * html div.yui-panel-container select { |
| | | visibility:inherit; |
| | | } |
| | | |
| | | * html div.drag select { |
| | | visibility:hidden; |
| | | } |
| | | |
| | | * html div.hide-select select { |
| | | visibility:hidden; |
| | | } |
| | | |
| | | .mask { |
| | | z-index:0; |
| | | display:none; |
| | | position:absolute; |
| | | top:0; |
| | | left:0; |
| | | -moz-opacity: 0.5; |
| | | opacity:.50; |
| | | filter: alpha(opacity=50); |
| | | background-color:#CCC; |
| | | } |
| | | |
| | | .hide-scrollbars * { |
| | | overflow:hidden; |
| | | } |
| | | |
| | | .hide-scrollbars textarea, .hide-scrollbars select { |
| | | overflow:hidden; |
| | | display:none; |
| | | } |
| | | |
| | | .show-scrollbars textarea, .show-scrollbars select { |
| | | overflow:visible; |
| | | } |
| | | |
| | | .yui-panel-container { |
| | | position:absolute; |
| | | background-color:transparent; |
| | | z-index:6; |
| | | visibility:hidden; |
| | | overflow:visible; |
| | | width:auto; |
| | | } |
| | | |
| | | .yui-panel-container.focused { |
| | | } |
| | | |
| | | |
| | | .yui-panel-container.matte { |
| | | padding:3px; |
| | | background-color:#FFF; |
| | | } |
| | | |
| | | .yui-panel-container.matte .underlay { |
| | | display:none; |
| | | } |
| | | |
| | | .yui-panel-container.shadow { |
| | | padding:0px; |
| | | background-color:transparent; |
| | | } |
| | | |
| | | .yui-panel-container.shadow .underlay { |
| | | visibility:inherit; |
| | | position:absolute; |
| | | background-color:#CCC; |
| | | top:3px;left:3px; |
| | | z-index:0; |
| | | width:100%; |
| | | height:100%; |
| | | -moz-opacity: 0.7; |
| | | opacity:.70; |
| | | filter:alpha(opacity=70); |
| | | zoom:1; |
| | | } |
| | | |
| | | .yui-panel { |
| | | visibility:hidden; |
| | | border-collapse:separate; |
| | | position:relative; |
| | | left:0px;top:0px; |
| | | font:1em Arial; |
| | | background-color:#FFF; |
| | | border:1px solid #000; |
| | | z-index:1; |
| | | overflow:hidden; |
| | | } |
| | | |
| | | .yui-panel .hd { |
| | | background-color:#3d77cb; |
| | | color:#FFF; |
| | | font-size:100%; |
| | | line-height:100%; |
| | | border:1px solid #FFF; |
| | | border-bottom:1px solid #000; |
| | | font-weight:bold; |
| | | overflow:hidden; |
| | | padding:4px; |
| | | } |
| | | |
| | | .yui-panel .bd { |
| | | overflow:hidden; |
| | | padding:4px; |
| | | } |
| | | |
| | | .yui-panel .bd p { |
| | | margin:0 0 1em; |
| | | } |
| | | |
| | | .yui-panel .container-close { |
| | | position:absolute; |
| | | top:5px; |
| | | right:4px; |
| | | z-index:6; |
| | | height:12px; |
| | | width:12px; |
| | | margin:0px; |
| | | padding:0px; |
| | | background:url(close12_1.gif) no-repeat; |
| | | cursor:pointer; |
| | | visibility:inherit; |
| | | } |
| | | |
| | | .yui-panel .ft { |
| | | padding:4px; |
| | | overflow:hidden; |
| | | } |
| | | |
| | | .yui-simple-dialog .bd .yui-icon { |
| | | background-repeat:no-repeat; |
| | | width:16px; |
| | | height:16px; |
| | | margin-right:10px; |
| | | float:left; |
| | | } |
| | | |
| | | .yui-simple-dialog .bd span.blckicon { |
| | | background: url("blck16_1.gif") no-repeat; |
| | | } |
| | | |
| | | .yui-simple-dialog .bd span.alrticon { |
| | | background: url("alrt16_1.gif") no-repeat; |
| | | } |
| | | |
| | | .yui-simple-dialog .bd span.hlpicon { |
| | | background: url("hlp16_1.gif") no-repeat; |
| | | } |
| | | |
| | | .yui-simple-dialog .bd span.infoicon { |
| | | background: url("info16_1.gif") no-repeat; |
| | | } |
| | | |
| | | .yui-simple-dialog .bd span.warnicon { |
| | | background: url("warn16_1.gif") no-repeat; |
| | | } |
| | | |
| | | .yui-simple-dialog .bd span.tipicon { |
| | | background: url("tip16_1.gif") no-repeat; |
| | | } |
| | | |
| | | .yui-dialog .ft, .simple-dialog .ft { |
| | | padding-bottom:5px; |
| | | padding-right:5px; |
| | | text-align:right; |
| | | } |
| | | |
| | | .yui-dialog form, .yui-simple-dialog form { |
| | | margin:0; |
| | | } |
| | | |
| | | .button-group button { |
| | | font:100 76% verdana; |
| | | text-decoration:none; |
| | | background-color: #E4E4E4; |
| | | color: #333; |
| | | cursor: hand; |
| | | vertical-align: middle; |
| | | border: 2px solid #797979; |
| | | border-top-color:#FFF; |
| | | border-left-color:#FFF; |
| | | margin:2px; |
| | | padding:2px; |
| | | } |
| | | |
| | | .button-group button.default { |
| | | font-weight:bold; |
| | | } |
| | | |
| | | .button-group button:hover, .button-group button.hover { |
| | | border:2px solid #90A029; |
| | | background-color:#EBF09E; |
| | | border-top-color:#FFF; |
| | | border-left-color:#FFF; |
| | | } |
| | | |
| | | .button-group button:active { |
| | | border:2px solid #E4E4E4; |
| | | background-color:#BBB; |
| | | border-top-color:#333; |
| | | border-left-color:#333; |
| | | } |
New file |
| | |
| | | /* |
| | | 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.Config=function(owner){if(owner){this.init(owner);}};YAHOO.util.Config.prototype={owner:null,queueInProgress:false,checkBoolean:function(val){if(typeof val=='boolean'){return true;}else{return false;}},checkNumber:function(val){if(isNaN(val)){return false;}else{return true;}}};YAHOO.util.Config.prototype.init=function(owner){this.owner=owner;this.configChangedEvent=new YAHOO.util.CustomEvent("configChanged");this.queueInProgress=false;var config={};var initialConfig={};var eventQueue=[];var fireEvent=function(key,value){key=key.toLowerCase();var property=config[key];if(typeof property!='undefined'&&property.event){property.event.fire(value);}};this.addProperty=function(key,propertyObject){key=key.toLowerCase();config[key]=propertyObject;propertyObject.event=new YAHOO.util.CustomEvent(key);propertyObject.key=key;if(propertyObject.handler){propertyObject.event.subscribe(propertyObject.handler,this.owner,true);} |
| | | this.setProperty(key,propertyObject.value,true);if(!propertyObject.suppressEvent){this.queueProperty(key,propertyObject.value);}};this.getConfig=function(){var cfg={};for(var prop in config){var property=config[prop];if(typeof property!='undefined'&&property.event){cfg[prop]=property.value;}} |
| | | return cfg;};this.getProperty=function(key){key=key.toLowerCase();var property=config[key];if(typeof property!='undefined'&&property.event){return property.value;}else{return undefined;}};this.resetProperty=function(key){key=key.toLowerCase();var property=config[key];if(typeof property!='undefined'&&property.event){if(initialConfig[key]&&initialConfig[key]!='undefined'){this.setProperty(key,initialConfig[key]);} |
| | | return true;}else{return false;}};this.setProperty=function(key,value,silent){key=key.toLowerCase();if(this.queueInProgress&&!silent){this.queueProperty(key,value);return true;}else{var property=config[key];if(typeof property!='undefined'&&property.event){if(property.validator&&!property.validator(value)){return false;}else{property.value=value;if(!silent){fireEvent(key,value);this.configChangedEvent.fire([key,value]);} |
| | | return true;}}else{return false;}}};this.queueProperty=function(key,value){key=key.toLowerCase();var property=config[key];if(typeof property!='undefined'&&property.event){if(typeof value!='undefined'&&property.validator&&!property.validator(value)){return false;}else{if(typeof value!='undefined'){property.value=value;}else{value=property.value;} |
| | | var foundDuplicate=false;for(var i=0;i<eventQueue.length;i++){var queueItem=eventQueue[i];if(queueItem){var queueItemKey=queueItem[0];var queueItemValue=queueItem[1];if(queueItemKey.toLowerCase()==key){eventQueue[i]=null;eventQueue.push([key,(typeof value!='undefined'?value:queueItemValue)]);foundDuplicate=true;break;}}} |
| | | if(!foundDuplicate&&typeof value!='undefined'){eventQueue.push([key,value]);}} |
| | | if(property.supercedes){for(var s=0;s<property.supercedes.length;s++){var supercedesCheck=property.supercedes[s];for(var q=0;q<eventQueue.length;q++){var queueItemCheck=eventQueue[q];if(queueItemCheck){var queueItemCheckKey=queueItemCheck[0];var queueItemCheckValue=queueItemCheck[1];if(queueItemCheckKey.toLowerCase()==supercedesCheck.toLowerCase()){eventQueue.push([queueItemCheckKey,queueItemCheckValue]);eventQueue[q]=null;break;}}}}} |
| | | return true;}else{return false;}};this.refireEvent=function(key){key=key.toLowerCase();var property=config[key];if(typeof property!='undefined'&&property.event&&typeof property.value!='undefined'){if(this.queueInProgress){this.queueProperty(key);}else{fireEvent(key,property.value);}}};this.applyConfig=function(userConfig,init){if(init){initialConfig=userConfig;} |
| | | for(var prop in userConfig){this.queueProperty(prop,userConfig[prop]);}};this.refresh=function(){for(var prop in config){this.refireEvent(prop);}};this.fireQueue=function(){this.queueInProgress=true;for(var i=0;i<eventQueue.length;i++){var queueItem=eventQueue[i];if(queueItem){var key=queueItem[0];var value=queueItem[1];var property=config[key];property.value=value;fireEvent(key,value);}} |
| | | this.queueInProgress=false;eventQueue=[];};this.subscribeToConfigEvent=function(key,handler,obj,override){key=key.toLowerCase();var property=config[key];if(typeof property!='undefined'&&property.event){if(!YAHOO.util.Config.alreadySubscribed(property.event,handler,obj)){property.event.subscribe(handler,obj,override);} |
| | | return true;}else{return false;}};this.unsubscribeFromConfigEvent=function(key,handler,obj){key=key.toLowerCase();var property=config[key];if(typeof property!='undefined'&&property.event){return property.event.unsubscribe(handler,obj);}else{return false;}};this.toString=function(){var output="Config";if(this.owner){output+=" ["+this.owner.toString()+"]";} |
| | | return output;};this.outputEventQueue=function(){var output="";for(var q=0;q<eventQueue.length;q++){var queueItem=eventQueue[q];if(queueItem){output+=queueItem[0]+"="+queueItem[1]+", ";}} |
| | | return output;};};YAHOO.util.Config.alreadySubscribed=function(evt,fn,obj){for(var e=0;e<evt.subscribers.length;e++){var subsc=evt.subscribers[e];if(subsc&&subsc.obj==obj&&subsc.fn==fn){return true;}} |
| | | return false;};YAHOO.widget.Module=function(el,userConfig){if(el){this.init(el,userConfig);}else{}};YAHOO.widget.Module.IMG_ROOT=null;YAHOO.widget.Module.IMG_ROOT_SSL=null;YAHOO.widget.Module.CSS_MODULE="module";YAHOO.widget.Module.CSS_HEADER="hd";YAHOO.widget.Module.CSS_BODY="bd";YAHOO.widget.Module.CSS_FOOTER="ft";YAHOO.widget.Module.RESIZE_MONITOR_SECURE_URL="javascript:false;";YAHOO.widget.Module.textResizeEvent=new YAHOO.util.CustomEvent("textResize");YAHOO.widget.Module.prototype={constructor:YAHOO.widget.Module,element:null,header:null,body:null,footer:null,id:null,imageRoot:YAHOO.widget.Module.IMG_ROOT,initEvents:function(){this.beforeInitEvent=new YAHOO.util.CustomEvent("beforeInit");this.initEvent=new YAHOO.util.CustomEvent("init");this.appendEvent=new YAHOO.util.CustomEvent("append");this.beforeRenderEvent=new YAHOO.util.CustomEvent("beforeRender");this.renderEvent=new YAHOO.util.CustomEvent("render");this.changeHeaderEvent=new YAHOO.util.CustomEvent("changeHeader");this.changeBodyEvent=new YAHOO.util.CustomEvent("changeBody");this.changeFooterEvent=new YAHOO.util.CustomEvent("changeFooter");this.changeContentEvent=new YAHOO.util.CustomEvent("changeContent");this.destroyEvent=new YAHOO.util.CustomEvent("destroy");this.beforeShowEvent=new YAHOO.util.CustomEvent("beforeShow");this.showEvent=new YAHOO.util.CustomEvent("show");this.beforeHideEvent=new YAHOO.util.CustomEvent("beforeHide");this.hideEvent=new YAHOO.util.CustomEvent("hide");},platform:function(){var ua=navigator.userAgent.toLowerCase();if(ua.indexOf("windows")!=-1||ua.indexOf("win32")!=-1){return"windows";}else if(ua.indexOf("macintosh")!=-1){return"mac";}else{return false;}}(),browser:function(){var ua=navigator.userAgent.toLowerCase();if(ua.indexOf('opera')!=-1){return'opera';}else if(ua.indexOf('msie 7')!=-1){return'ie7';}else if(ua.indexOf('msie')!=-1){return'ie';}else if(ua.indexOf('safari')!=-1){return'safari';}else if(ua.indexOf('gecko')!=-1){return'gecko';}else{return false;}}(),isSecure:function(){if(window.location.href.toLowerCase().indexOf("https")===0){return true;}else{return false;}}(),initDefaultConfig:function(){this.cfg.addProperty("visible",{value:true,handler:this.configVisible,validator:this.cfg.checkBoolean});this.cfg.addProperty("effect",{suppressEvent:true,supercedes:["visible"]});this.cfg.addProperty("monitorresize",{value:true,handler:this.configMonitorResize});},init:function(el,userConfig){this.initEvents();this.beforeInitEvent.fire(YAHOO.widget.Module);this.cfg=new YAHOO.util.Config(this);if(this.isSecure){this.imageRoot=YAHOO.widget.Module.IMG_ROOT_SSL;} |
| | | if(typeof el=="string"){var elId=el;el=document.getElementById(el);if(!el){el=document.createElement("div");el.id=elId;}} |
| | | this.element=el;if(el.id){this.id=el.id;} |
| | | var childNodes=this.element.childNodes;if(childNodes){for(var i=0;i<childNodes.length;i++){var child=childNodes[i];switch(child.className){case YAHOO.widget.Module.CSS_HEADER:this.header=child;break;case YAHOO.widget.Module.CSS_BODY:this.body=child;break;case YAHOO.widget.Module.CSS_FOOTER:this.footer=child;break;}}} |
| | | this.initDefaultConfig();YAHOO.util.Dom.addClass(this.element,YAHOO.widget.Module.CSS_MODULE);if(userConfig){this.cfg.applyConfig(userConfig,true);} |
| | | if(!YAHOO.util.Config.alreadySubscribed(this.renderEvent,this.cfg.fireQueue,this.cfg)){this.renderEvent.subscribe(this.cfg.fireQueue,this.cfg,true);} |
| | | this.initEvent.fire(YAHOO.widget.Module);},initResizeMonitor:function(){if(this.browser!="opera"){var resizeMonitor=document.getElementById("_yuiResizeMonitor");if(!resizeMonitor){resizeMonitor=document.createElement("iframe");var bIE=(this.browser.indexOf("ie")===0);if(this.isSecure&&YAHOO.widget.Module.RESIZE_MONITOR_SECURE_URL&&bIE){resizeMonitor.src=YAHOO.widget.Module.RESIZE_MONITOR_SECURE_URL;} |
| | | resizeMonitor.id="_yuiResizeMonitor";resizeMonitor.style.visibility="hidden";document.body.appendChild(resizeMonitor);resizeMonitor.style.width="10em";resizeMonitor.style.height="10em";resizeMonitor.style.position="absolute";var nLeft=-1*resizeMonitor.offsetWidth;var nTop=-1*resizeMonitor.offsetHeight;resizeMonitor.style.top=nTop+"px";resizeMonitor.style.left=nLeft+"px";resizeMonitor.style.borderStyle="none";resizeMonitor.style.borderWidth="0";YAHOO.util.Dom.setStyle(resizeMonitor,"opacity","0");resizeMonitor.style.visibility="visible";if(!bIE){var doc=resizeMonitor.contentWindow.document;doc.open();doc.close();}} |
| | | var fireTextResize=function(){YAHOO.widget.Module.textResizeEvent.fire();};if(resizeMonitor&&resizeMonitor.contentWindow){this.resizeMonitor=resizeMonitor;YAHOO.widget.Module.textResizeEvent.subscribe(this.onDomResize,this,true);if(!YAHOO.widget.Module.textResizeInitialized){if(!YAHOO.util.Event.addListener(this.resizeMonitor.contentWindow,"resize",fireTextResize)){YAHOO.util.Event.addListener(this.resizeMonitor,"resize",fireTextResize);} |
| | | YAHOO.widget.Module.textResizeInitialized=true;}}}},onDomResize:function(e,obj){var nLeft=-1*this.resizeMonitor.offsetWidth,nTop=-1*this.resizeMonitor.offsetHeight;this.resizeMonitor.style.top=nTop+"px";this.resizeMonitor.style.left=nLeft+"px";},setHeader:function(headerContent){if(!this.header){this.header=document.createElement("div");this.header.className=YAHOO.widget.Module.CSS_HEADER;} |
| | | if(typeof headerContent=="string"){this.header.innerHTML=headerContent;}else{this.header.innerHTML="";this.header.appendChild(headerContent);} |
| | | this.changeHeaderEvent.fire(headerContent);this.changeContentEvent.fire();},appendToHeader:function(element){if(!this.header){this.header=document.createElement("div");this.header.className=YAHOO.widget.Module.CSS_HEADER;} |
| | | this.header.appendChild(element);this.changeHeaderEvent.fire(element);this.changeContentEvent.fire();},setBody:function(bodyContent){if(!this.body){this.body=document.createElement("div");this.body.className=YAHOO.widget.Module.CSS_BODY;} |
| | | if(typeof bodyContent=="string") |
| | | {this.body.innerHTML=bodyContent;}else{this.body.innerHTML="";this.body.appendChild(bodyContent);} |
| | | this.changeBodyEvent.fire(bodyContent);this.changeContentEvent.fire();},appendToBody:function(element){if(!this.body){this.body=document.createElement("div");this.body.className=YAHOO.widget.Module.CSS_BODY;} |
| | | this.body.appendChild(element);this.changeBodyEvent.fire(element);this.changeContentEvent.fire();},setFooter:function(footerContent){if(!this.footer){this.footer=document.createElement("div");this.footer.className=YAHOO.widget.Module.CSS_FOOTER;} |
| | | if(typeof footerContent=="string"){this.footer.innerHTML=footerContent;}else{this.footer.innerHTML="";this.footer.appendChild(footerContent);} |
| | | this.changeFooterEvent.fire(footerContent);this.changeContentEvent.fire();},appendToFooter:function(element){if(!this.footer){this.footer=document.createElement("div");this.footer.className=YAHOO.widget.Module.CSS_FOOTER;} |
| | | this.footer.appendChild(element);this.changeFooterEvent.fire(element);this.changeContentEvent.fire();},render:function(appendToNode,moduleElement){this.beforeRenderEvent.fire();if(!moduleElement){moduleElement=this.element;} |
| | | var me=this;var appendTo=function(element){if(typeof element=="string"){element=document.getElementById(element);} |
| | | if(element){element.appendChild(me.element);me.appendEvent.fire();}};if(appendToNode){appendTo(appendToNode);}else{if(!YAHOO.util.Dom.inDocument(this.element)){return false;}} |
| | | if(this.header&&!YAHOO.util.Dom.inDocument(this.header)){var firstChild=moduleElement.firstChild;if(firstChild){moduleElement.insertBefore(this.header,firstChild);}else{moduleElement.appendChild(this.header);}} |
| | | if(this.body&&!YAHOO.util.Dom.inDocument(this.body)){if(this.footer&&YAHOO.util.Dom.isAncestor(this.moduleElement,this.footer)){moduleElement.insertBefore(this.body,this.footer);}else{moduleElement.appendChild(this.body);}} |
| | | if(this.footer&&!YAHOO.util.Dom.inDocument(this.footer)){moduleElement.appendChild(this.footer);} |
| | | this.renderEvent.fire();return true;},destroy:function(){var parent;if(this.element){YAHOO.util.Event.purgeElement(this.element,true);parent=this.element.parentNode;} |
| | | if(parent){parent.removeChild(this.element);} |
| | | this.element=null;this.header=null;this.body=null;this.footer=null;for(var e in this){if(e instanceof YAHOO.util.CustomEvent){e.unsubscribeAll();}} |
| | | YAHOO.widget.Module.textResizeEvent.unsubscribe(this.onDomResize,this);this.destroyEvent.fire();},show:function(){this.cfg.setProperty("visible",true);},hide:function(){this.cfg.setProperty("visible",false);},configVisible:function(type,args,obj){var visible=args[0];if(visible){this.beforeShowEvent.fire();YAHOO.util.Dom.setStyle(this.element,"display","block");this.showEvent.fire();}else{this.beforeHideEvent.fire();YAHOO.util.Dom.setStyle(this.element,"display","none");this.hideEvent.fire();}},configMonitorResize:function(type,args,obj){var monitor=args[0];if(monitor){this.initResizeMonitor();}else{YAHOO.widget.Module.textResizeEvent.unsubscribe(this.onDomResize,this,true);this.resizeMonitor=null;}}};YAHOO.widget.Module.prototype.toString=function(){return"Module "+this.id;};YAHOO.widget.Overlay=function(el,userConfig){YAHOO.widget.Overlay.superclass.constructor.call(this,el,userConfig);};YAHOO.extend(YAHOO.widget.Overlay,YAHOO.widget.Module);YAHOO.widget.Overlay.IFRAME_SRC="javascript:false;";YAHOO.widget.Overlay.TOP_LEFT="tl";YAHOO.widget.Overlay.TOP_RIGHT="tr";YAHOO.widget.Overlay.BOTTOM_LEFT="bl";YAHOO.widget.Overlay.BOTTOM_RIGHT="br";YAHOO.widget.Overlay.CSS_OVERLAY="yui-overlay";YAHOO.widget.Overlay.prototype.init=function(el,userConfig){YAHOO.widget.Overlay.superclass.init.call(this,el);this.beforeInitEvent.fire(YAHOO.widget.Overlay);YAHOO.util.Dom.addClass(this.element,YAHOO.widget.Overlay.CSS_OVERLAY);if(userConfig){this.cfg.applyConfig(userConfig,true);} |
| | | if(this.platform=="mac"&&this.browser=="gecko"){if(!YAHOO.util.Config.alreadySubscribed(this.showEvent,this.showMacGeckoScrollbars,this)){this.showEvent.subscribe(this.showMacGeckoScrollbars,this,true);} |
| | | if(!YAHOO.util.Config.alreadySubscribed(this.hideEvent,this.hideMacGeckoScrollbars,this)){this.hideEvent.subscribe(this.hideMacGeckoScrollbars,this,true);}} |
| | | this.initEvent.fire(YAHOO.widget.Overlay);};YAHOO.widget.Overlay.prototype.initEvents=function(){YAHOO.widget.Overlay.superclass.initEvents.call(this);this.beforeMoveEvent=new YAHOO.util.CustomEvent("beforeMove",this);this.moveEvent=new YAHOO.util.CustomEvent("move",this);};YAHOO.widget.Overlay.prototype.initDefaultConfig=function(){YAHOO.widget.Overlay.superclass.initDefaultConfig.call(this);this.cfg.addProperty("x",{handler:this.configX,validator:this.cfg.checkNumber,suppressEvent:true,supercedes:["iframe"]});this.cfg.addProperty("y",{handler:this.configY,validator:this.cfg.checkNumber,suppressEvent:true,supercedes:["iframe"]});this.cfg.addProperty("xy",{handler:this.configXY,suppressEvent:true,supercedes:["iframe"]});this.cfg.addProperty("context",{handler:this.configContext,suppressEvent:true,supercedes:["iframe"]});this.cfg.addProperty("fixedcenter",{value:false,handler:this.configFixedCenter,validator:this.cfg.checkBoolean,supercedes:["iframe","visible"]});this.cfg.addProperty("width",{handler:this.configWidth,suppressEvent:true,supercedes:["iframe"]});this.cfg.addProperty("height",{handler:this.configHeight,suppressEvent:true,supercedes:["iframe"]});this.cfg.addProperty("zIndex",{value:null,handler:this.configzIndex});this.cfg.addProperty("constraintoviewport",{value:false,handler:this.configConstrainToViewport,validator:this.cfg.checkBoolean,supercedes:["iframe","x","y","xy"]});this.cfg.addProperty("iframe",{value:(this.browser=="ie"?true:false),handler:this.configIframe,validator:this.cfg.checkBoolean,supercedes:["zIndex"]});};YAHOO.widget.Overlay.prototype.moveTo=function(x,y){this.cfg.setProperty("xy",[x,y]);};YAHOO.widget.Overlay.prototype.hideMacGeckoScrollbars=function(){YAHOO.util.Dom.removeClass(this.element,"show-scrollbars");YAHOO.util.Dom.addClass(this.element,"hide-scrollbars");};YAHOO.widget.Overlay.prototype.showMacGeckoScrollbars=function(){YAHOO.util.Dom.removeClass(this.element,"hide-scrollbars");YAHOO.util.Dom.addClass(this.element,"show-scrollbars");};YAHOO.widget.Overlay.prototype.configVisible=function(type,args,obj){var visible=args[0];var currentVis=YAHOO.util.Dom.getStyle(this.element,"visibility");if(currentVis=="inherit"){var e=this.element.parentNode;while(e.nodeType!=9&&e.nodeType!=11){currentVis=YAHOO.util.Dom.getStyle(e,"visibility");if(currentVis!="inherit"){break;} |
| | | e=e.parentNode;} |
| | | if(currentVis=="inherit"){currentVis="visible";}} |
| | | var effect=this.cfg.getProperty("effect");var effectInstances=[];if(effect){if(effect instanceof Array){for(var i=0;i<effect.length;i++){var eff=effect[i];effectInstances[effectInstances.length]=eff.effect(this,eff.duration);}}else{effectInstances[effectInstances.length]=effect.effect(this,effect.duration);}} |
| | | var isMacGecko=(this.platform=="mac"&&this.browser=="gecko");if(visible){if(isMacGecko){this.showMacGeckoScrollbars();} |
| | | if(effect){if(visible){if(currentVis!="visible"||currentVis===""){this.beforeShowEvent.fire();for(var j=0;j<effectInstances.length;j++){var ei=effectInstances[j];if(j===0&&!YAHOO.util.Config.alreadySubscribed(ei.animateInCompleteEvent,this.showEvent.fire,this.showEvent)){ei.animateInCompleteEvent.subscribe(this.showEvent.fire,this.showEvent,true);} |
| | | ei.animateIn();}}}}else{if(currentVis!="visible"||currentVis===""){this.beforeShowEvent.fire();YAHOO.util.Dom.setStyle(this.element,"visibility","visible");this.cfg.refireEvent("iframe");this.showEvent.fire();}}}else{if(isMacGecko){this.hideMacGeckoScrollbars();} |
| | | if(effect){if(currentVis=="visible"){this.beforeHideEvent.fire();for(var k=0;k<effectInstances.length;k++){var h=effectInstances[k];if(k===0&&!YAHOO.util.Config.alreadySubscribed(h.animateOutCompleteEvent,this.hideEvent.fire,this.hideEvent)){h.animateOutCompleteEvent.subscribe(this.hideEvent.fire,this.hideEvent,true);} |
| | | h.animateOut();}}else if(currentVis===""){YAHOO.util.Dom.setStyle(this.element,"visibility","hidden");}}else{if(currentVis=="visible"||currentVis===""){this.beforeHideEvent.fire();YAHOO.util.Dom.setStyle(this.element,"visibility","hidden");this.cfg.refireEvent("iframe");this.hideEvent.fire();}}}};YAHOO.widget.Overlay.prototype.doCenterOnDOMEvent=function(){if(this.cfg.getProperty("visible")){this.center();}};YAHOO.widget.Overlay.prototype.configFixedCenter=function(type,args,obj){var val=args[0];if(val){this.center();if(!YAHOO.util.Config.alreadySubscribed(this.beforeShowEvent,this.center,this)){this.beforeShowEvent.subscribe(this.center,this,true);} |
| | | if(!YAHOO.util.Config.alreadySubscribed(YAHOO.widget.Overlay.windowResizeEvent,this.doCenterOnDOMEvent,this)){YAHOO.widget.Overlay.windowResizeEvent.subscribe(this.doCenterOnDOMEvent,this,true);} |
| | | if(!YAHOO.util.Config.alreadySubscribed(YAHOO.widget.Overlay.windowScrollEvent,this.doCenterOnDOMEvent,this)){YAHOO.widget.Overlay.windowScrollEvent.subscribe(this.doCenterOnDOMEvent,this,true);}}else{YAHOO.widget.Overlay.windowResizeEvent.unsubscribe(this.doCenterOnDOMEvent,this);YAHOO.widget.Overlay.windowScrollEvent.unsubscribe(this.doCenterOnDOMEvent,this);}};YAHOO.widget.Overlay.prototype.configHeight=function(type,args,obj){var height=args[0];var el=this.element;YAHOO.util.Dom.setStyle(el,"height",height);this.cfg.refireEvent("iframe");};YAHOO.widget.Overlay.prototype.configWidth=function(type,args,obj){var width=args[0];var el=this.element;YAHOO.util.Dom.setStyle(el,"width",width);this.cfg.refireEvent("iframe");};YAHOO.widget.Overlay.prototype.configzIndex=function(type,args,obj){var zIndex=args[0];var el=this.element;if(!zIndex){zIndex=YAHOO.util.Dom.getStyle(el,"zIndex");if(!zIndex||isNaN(zIndex)){zIndex=0;}} |
| | | if(this.iframe){if(zIndex<=0){zIndex=1;} |
| | | YAHOO.util.Dom.setStyle(this.iframe,"zIndex",(zIndex-1));} |
| | | YAHOO.util.Dom.setStyle(el,"zIndex",zIndex);this.cfg.setProperty("zIndex",zIndex,true);};YAHOO.widget.Overlay.prototype.configXY=function(type,args,obj){var pos=args[0];var x=pos[0];var y=pos[1];this.cfg.setProperty("x",x);this.cfg.setProperty("y",y);this.beforeMoveEvent.fire([x,y]);x=this.cfg.getProperty("x");y=this.cfg.getProperty("y");this.cfg.refireEvent("iframe");this.moveEvent.fire([x,y]);};YAHOO.widget.Overlay.prototype.configX=function(type,args,obj){var x=args[0];var y=this.cfg.getProperty("y");this.cfg.setProperty("x",x,true);this.cfg.setProperty("y",y,true);this.beforeMoveEvent.fire([x,y]);x=this.cfg.getProperty("x");y=this.cfg.getProperty("y");YAHOO.util.Dom.setX(this.element,x,true);this.cfg.setProperty("xy",[x,y],true);this.cfg.refireEvent("iframe");this.moveEvent.fire([x,y]);};YAHOO.widget.Overlay.prototype.configY=function(type,args,obj){var x=this.cfg.getProperty("x");var y=args[0];this.cfg.setProperty("x",x,true);this.cfg.setProperty("y",y,true);this.beforeMoveEvent.fire([x,y]);x=this.cfg.getProperty("x");y=this.cfg.getProperty("y");YAHOO.util.Dom.setY(this.element,y,true);this.cfg.setProperty("xy",[x,y],true);this.cfg.refireEvent("iframe");this.moveEvent.fire([x,y]);};YAHOO.widget.Overlay.prototype.showIframe=function(){if(this.iframe){this.iframe.style.display="block";}};YAHOO.widget.Overlay.prototype.hideIframe=function(){if(this.iframe){this.iframe.style.display="none";}};YAHOO.widget.Overlay.prototype.configIframe=function(type,args,obj){var val=args[0];if(val){if(!YAHOO.util.Config.alreadySubscribed(this.showEvent,this.showIframe,this)){this.showEvent.subscribe(this.showIframe,this,true);} |
| | | if(!YAHOO.util.Config.alreadySubscribed(this.hideEvent,this.hideIframe,this)){this.hideEvent.subscribe(this.hideIframe,this,true);} |
| | | var x=this.cfg.getProperty("x");var y=this.cfg.getProperty("y");if(!x||!y){this.syncPosition();x=this.cfg.getProperty("x");y=this.cfg.getProperty("y");} |
| | | if(!isNaN(x)&&!isNaN(y)){if(!this.iframe){this.iframe=document.createElement("iframe");if(this.isSecure){this.iframe.src=YAHOO.widget.Overlay.IFRAME_SRC;} |
| | | var parent=this.element.parentNode;if(parent){parent.appendChild(this.iframe);}else{document.body.appendChild(this.iframe);} |
| | | YAHOO.util.Dom.setStyle(this.iframe,"position","absolute");YAHOO.util.Dom.setStyle(this.iframe,"border","none");YAHOO.util.Dom.setStyle(this.iframe,"margin","0");YAHOO.util.Dom.setStyle(this.iframe,"padding","0");YAHOO.util.Dom.setStyle(this.iframe,"opacity","0");if(this.cfg.getProperty("visible")){this.showIframe();}else{this.hideIframe();}} |
| | | var iframeDisplay=YAHOO.util.Dom.getStyle(this.iframe,"display");if(iframeDisplay=="none"){this.iframe.style.display="block";} |
| | | YAHOO.util.Dom.setXY(this.iframe,[x,y]);var width=this.element.clientWidth;var height=this.element.clientHeight;YAHOO.util.Dom.setStyle(this.iframe,"width",(width+2)+"px");YAHOO.util.Dom.setStyle(this.iframe,"height",(height+2)+"px");if(iframeDisplay=="none"){this.iframe.style.display="none";}}}else{if(this.iframe){this.iframe.style.display="none";} |
| | | this.showEvent.unsubscribe(this.showIframe,this);this.hideEvent.unsubscribe(this.hideIframe,this);}};YAHOO.widget.Overlay.prototype.configConstrainToViewport=function(type,args,obj){var val=args[0];if(val){if(!YAHOO.util.Config.alreadySubscribed(this.beforeMoveEvent,this.enforceConstraints,this)){this.beforeMoveEvent.subscribe(this.enforceConstraints,this,true);}}else{this.beforeMoveEvent.unsubscribe(this.enforceConstraints,this);}};YAHOO.widget.Overlay.prototype.configContext=function(type,args,obj){var contextArgs=args[0];if(contextArgs){var contextEl=contextArgs[0];var elementMagnetCorner=contextArgs[1];var contextMagnetCorner=contextArgs[2];if(contextEl){if(typeof contextEl=="string"){this.cfg.setProperty("context",[document.getElementById(contextEl),elementMagnetCorner,contextMagnetCorner],true);} |
| | | if(elementMagnetCorner&&contextMagnetCorner){this.align(elementMagnetCorner,contextMagnetCorner);}}}};YAHOO.widget.Overlay.prototype.align=function(elementAlign,contextAlign){var contextArgs=this.cfg.getProperty("context");if(contextArgs){var context=contextArgs[0];var element=this.element;var me=this;if(!elementAlign){elementAlign=contextArgs[1];} |
| | | if(!contextAlign){contextAlign=contextArgs[2];} |
| | | if(element&&context){var contextRegion=YAHOO.util.Dom.getRegion(context);var doAlign=function(v,h){switch(elementAlign){case YAHOO.widget.Overlay.TOP_LEFT:me.moveTo(h,v);break;case YAHOO.widget.Overlay.TOP_RIGHT:me.moveTo(h-element.offsetWidth,v);break;case YAHOO.widget.Overlay.BOTTOM_LEFT:me.moveTo(h,v-element.offsetHeight);break;case YAHOO.widget.Overlay.BOTTOM_RIGHT:me.moveTo(h-element.offsetWidth,v-element.offsetHeight);break;}};switch(contextAlign){case YAHOO.widget.Overlay.TOP_LEFT:doAlign(contextRegion.top,contextRegion.left);break;case YAHOO.widget.Overlay.TOP_RIGHT:doAlign(contextRegion.top,contextRegion.right);break;case YAHOO.widget.Overlay.BOTTOM_LEFT:doAlign(contextRegion.bottom,contextRegion.left);break;case YAHOO.widget.Overlay.BOTTOM_RIGHT:doAlign(contextRegion.bottom,contextRegion.right);break;}}}};YAHOO.widget.Overlay.prototype.enforceConstraints=function(type,args,obj){var pos=args[0];var x=pos[0];var y=pos[1];var offsetHeight=this.element.offsetHeight;var offsetWidth=this.element.offsetWidth;var viewPortWidth=YAHOO.util.Dom.getViewportWidth();var viewPortHeight=YAHOO.util.Dom.getViewportHeight();var scrollX=document.documentElement.scrollLeft||document.body.scrollLeft;var scrollY=document.documentElement.scrollTop||document.body.scrollTop;var topConstraint=scrollY+10;var leftConstraint=scrollX+10;var bottomConstraint=scrollY+viewPortHeight-offsetHeight-10;var rightConstraint=scrollX+viewPortWidth-offsetWidth-10;if(x<leftConstraint){x=leftConstraint;}else if(x>rightConstraint){x=rightConstraint;} |
| | | if(y<topConstraint){y=topConstraint;}else if(y>bottomConstraint){y=bottomConstraint;} |
| | | this.cfg.setProperty("x",x,true);this.cfg.setProperty("y",y,true);this.cfg.setProperty("xy",[x,y],true);};YAHOO.widget.Overlay.prototype.center=function(){var scrollX=document.documentElement.scrollLeft||document.body.scrollLeft;var scrollY=document.documentElement.scrollTop||document.body.scrollTop;var viewPortWidth=YAHOO.util.Dom.getClientWidth();var viewPortHeight=YAHOO.util.Dom.getClientHeight();var elementWidth=this.element.offsetWidth;var elementHeight=this.element.offsetHeight;var x=(viewPortWidth/2)-(elementWidth/2)+scrollX;var y=(viewPortHeight/2)-(elementHeight/2)+scrollY;this.cfg.setProperty("xy",[parseInt(x,10),parseInt(y,10)]);this.cfg.refireEvent("iframe");};YAHOO.widget.Overlay.prototype.syncPosition=function(){var pos=YAHOO.util.Dom.getXY(this.element);this.cfg.setProperty("x",pos[0],true);this.cfg.setProperty("y",pos[1],true);this.cfg.setProperty("xy",pos,true);};YAHOO.widget.Overlay.prototype.onDomResize=function(e,obj){YAHOO.widget.Overlay.superclass.onDomResize.call(this,e,obj);var me=this;setTimeout(function(){me.syncPosition();me.cfg.refireEvent("iframe");me.cfg.refireEvent("context");},0);};YAHOO.widget.Overlay.prototype.destroy=function(){if(this.iframe){this.iframe.parentNode.removeChild(this.iframe);} |
| | | this.iframe=null;YAHOO.widget.Overlay.windowResizeEvent.unsubscribe(this.doCenterOnDOMEvent,this);YAHOO.widget.Overlay.windowScrollEvent.unsubscribe(this.doCenterOnDOMEvent,this);YAHOO.widget.Overlay.superclass.destroy.call(this);};YAHOO.widget.Overlay.prototype.toString=function(){return"Overlay "+this.id;};YAHOO.widget.Overlay.windowScrollEvent=new YAHOO.util.CustomEvent("windowScroll");YAHOO.widget.Overlay.windowResizeEvent=new YAHOO.util.CustomEvent("windowResize");YAHOO.widget.Overlay.windowScrollHandler=function(e){if(YAHOO.widget.Module.prototype.browser=="ie"||YAHOO.widget.Module.prototype.browser=="ie7"){if(!window.scrollEnd){window.scrollEnd=-1;} |
| | | clearTimeout(window.scrollEnd);window.scrollEnd=setTimeout(function(){YAHOO.widget.Overlay.windowScrollEvent.fire();},1);}else{YAHOO.widget.Overlay.windowScrollEvent.fire();}};YAHOO.widget.Overlay.windowResizeHandler=function(e){if(YAHOO.widget.Module.prototype.browser=="ie"||YAHOO.widget.Module.prototype.browser=="ie7"){if(!window.resizeEnd){window.resizeEnd=-1;} |
| | | clearTimeout(window.resizeEnd);window.resizeEnd=setTimeout(function(){YAHOO.widget.Overlay.windowResizeEvent.fire();},100);}else{YAHOO.widget.Overlay.windowResizeEvent.fire();}};YAHOO.widget.Overlay._initialized=null;if(YAHOO.widget.Overlay._initialized===null){YAHOO.util.Event.addListener(window,"scroll",YAHOO.widget.Overlay.windowScrollHandler);YAHOO.util.Event.addListener(window,"resize",YAHOO.widget.Overlay.windowResizeHandler);YAHOO.widget.Overlay._initialized=true;} |
| | | YAHOO.widget.OverlayManager=function(userConfig){this.init(userConfig);};YAHOO.widget.OverlayManager.CSS_FOCUSED="focused";YAHOO.widget.OverlayManager.prototype={constructor:YAHOO.widget.OverlayManager,overlays:null,initDefaultConfig:function(){this.cfg.addProperty("overlays",{suppressEvent:true});this.cfg.addProperty("focusevent",{value:"mousedown"});},init:function(userConfig){this.cfg=new YAHOO.util.Config(this);this.initDefaultConfig();if(userConfig){this.cfg.applyConfig(userConfig,true);} |
| | | this.cfg.fireQueue();var activeOverlay=null;this.getActive=function(){return activeOverlay;};this.focus=function(overlay){var o=this.find(overlay);if(o){this.blurAll();activeOverlay=o;YAHOO.util.Dom.addClass(activeOverlay.element,YAHOO.widget.OverlayManager.CSS_FOCUSED);this.overlays.sort(this.compareZIndexDesc);var topZIndex=YAHOO.util.Dom.getStyle(this.overlays[0].element,"zIndex");if(!isNaN(topZIndex)&&this.overlays[0]!=overlay){activeOverlay.cfg.setProperty("zIndex",(parseInt(topZIndex,10)+2));} |
| | | this.overlays.sort(this.compareZIndexDesc);}};this.remove=function(overlay){var o=this.find(overlay);if(o){var originalZ=YAHOO.util.Dom.getStyle(o.element,"zIndex");o.cfg.setProperty("zIndex",-1000,true);this.overlays.sort(this.compareZIndexDesc);this.overlays=this.overlays.slice(0,this.overlays.length-1);o.cfg.setProperty("zIndex",originalZ,true);o.cfg.setProperty("manager",null);o.focusEvent=null;o.blurEvent=null;o.focus=null;o.blur=null;}};this.blurAll=function(){activeOverlay=null;for(var o=0;o<this.overlays.length;o++){YAHOO.util.Dom.removeClass(this.overlays[o].element,YAHOO.widget.OverlayManager.CSS_FOCUSED);}};var overlays=this.cfg.getProperty("overlays");if(!this.overlays){this.overlays=[];} |
| | | if(overlays){this.register(overlays);this.overlays.sort(this.compareZIndexDesc);}},register:function(overlay){if(overlay instanceof YAHOO.widget.Overlay){overlay.cfg.addProperty("manager",{value:this});overlay.focusEvent=new YAHOO.util.CustomEvent("focus");overlay.blurEvent=new YAHOO.util.CustomEvent("blur");var mgr=this;overlay.focus=function(){mgr.focus(this);this.focusEvent.fire();};overlay.blur=function(){mgr.blurAll();this.blurEvent.fire();};var focusOnDomEvent=function(e,obj){overlay.focus();};var focusevent=this.cfg.getProperty("focusevent");YAHOO.util.Event.addListener(overlay.element,focusevent,focusOnDomEvent,this,true);var zIndex=YAHOO.util.Dom.getStyle(overlay.element,"zIndex");if(!isNaN(zIndex)){overlay.cfg.setProperty("zIndex",parseInt(zIndex,10));}else{overlay.cfg.setProperty("zIndex",0);} |
| | | this.overlays.push(overlay);return true;}else if(overlay instanceof Array){var regcount=0;for(var i=0;i<overlay.length;i++){if(this.register(overlay[i])){regcount++;}} |
| | | if(regcount>0){return true;}}else{return false;}},find:function(overlay){if(overlay instanceof YAHOO.widget.Overlay){for(var o=0;o<this.overlays.length;o++){if(this.overlays[o]==overlay){return this.overlays[o];}}}else if(typeof overlay=="string"){for(var p=0;p<this.overlays.length;p++){if(this.overlays[p].id==overlay){return this.overlays[p];}}} |
| | | return null;},compareZIndexDesc:function(o1,o2){var zIndex1=o1.cfg.getProperty("zIndex");var zIndex2=o2.cfg.getProperty("zIndex");if(zIndex1>zIndex2){return-1;}else if(zIndex1<zIndex2){return 1;}else{return 0;}},showAll:function(){for(var o=0;o<this.overlays.length;o++){this.overlays[o].show();}},hideAll:function(){for(var o=0;o<this.overlays.length;o++){this.overlays[o].hide();}},toString:function(){return"OverlayManager";}};YAHOO.util.KeyListener=function(attachTo,keyData,handler,event){if(!attachTo){} |
| | | if(!keyData){} |
| | | if(!handler){} |
| | | if(!event){event=YAHOO.util.KeyListener.KEYDOWN;} |
| | | var keyEvent=new YAHOO.util.CustomEvent("keyPressed");this.enabledEvent=new YAHOO.util.CustomEvent("enabled");this.disabledEvent=new YAHOO.util.CustomEvent("disabled");if(typeof attachTo=='string'){attachTo=document.getElementById(attachTo);} |
| | | if(typeof handler=='function'){keyEvent.subscribe(handler);}else{keyEvent.subscribe(handler.fn,handler.scope,handler.correctScope);} |
| | | function handleKeyPress(e,obj){if(!keyData.shift){keyData.shift=false;} |
| | | if(!keyData.alt){keyData.alt=false;} |
| | | if(!keyData.ctrl){keyData.ctrl=false;} |
| | | if(e.shiftKey==keyData.shift&&e.altKey==keyData.alt&&e.ctrlKey==keyData.ctrl){var dataItem;var keyPressed;if(keyData.keys instanceof Array){for(var i=0;i<keyData.keys.length;i++){dataItem=keyData.keys[i];if(dataItem==e.charCode){keyEvent.fire(e.charCode,e);break;}else if(dataItem==e.keyCode){keyEvent.fire(e.keyCode,e);break;}}}else{dataItem=keyData.keys;if(dataItem==e.charCode){keyEvent.fire(e.charCode,e);}else if(dataItem==e.keyCode){keyEvent.fire(e.keyCode,e);}}}} |
| | | this.enable=function(){if(!this.enabled){YAHOO.util.Event.addListener(attachTo,event,handleKeyPress);this.enabledEvent.fire(keyData);} |
| | | this.enabled=true;};this.disable=function(){if(this.enabled){YAHOO.util.Event.removeListener(attachTo,event,handleKeyPress);this.disabledEvent.fire(keyData);} |
| | | this.enabled=false;};this.toString=function(){return"KeyListener ["+keyData.keys+"] "+attachTo.tagName+(attachTo.id?"["+attachTo.id+"]":"");};};YAHOO.util.KeyListener.KEYDOWN="keydown";YAHOO.util.KeyListener.KEYUP="keyup";YAHOO.widget.Tooltip=function(el,userConfig){YAHOO.widget.Tooltip.superclass.constructor.call(this,el,userConfig);};YAHOO.extend(YAHOO.widget.Tooltip,YAHOO.widget.Overlay);YAHOO.widget.Tooltip.CSS_TOOLTIP="yui-tt";YAHOO.widget.Tooltip.prototype.init=function(el,userConfig){if(document.readyState&&document.readyState!="complete"){var deferredInit=function(){this.init(el,userConfig);};YAHOO.util.Event.addListener(window,"load",deferredInit,this,true);}else{YAHOO.widget.Tooltip.superclass.init.call(this,el);this.beforeInitEvent.fire(YAHOO.widget.Tooltip);YAHOO.util.Dom.addClass(this.element,YAHOO.widget.Tooltip.CSS_TOOLTIP);if(userConfig){this.cfg.applyConfig(userConfig,true);} |
| | | this.cfg.queueProperty("visible",false);this.cfg.queueProperty("constraintoviewport",true);this.setBody("");this.render(this.cfg.getProperty("container"));this.initEvent.fire(YAHOO.widget.Tooltip);}};YAHOO.widget.Tooltip.prototype.initDefaultConfig=function(){YAHOO.widget.Tooltip.superclass.initDefaultConfig.call(this);this.cfg.addProperty("preventoverlap",{value:true,validator:this.cfg.checkBoolean,supercedes:["x","y","xy"]});this.cfg.addProperty("showdelay",{value:200,handler:this.configShowDelay,validator:this.cfg.checkNumber});this.cfg.addProperty("autodismissdelay",{value:5000,handler:this.configAutoDismissDelay,validator:this.cfg.checkNumber});this.cfg.addProperty("hidedelay",{value:250,handler:this.configHideDelay,validator:this.cfg.checkNumber});this.cfg.addProperty("text",{handler:this.configText,suppressEvent:true});this.cfg.addProperty("container",{value:document.body,handler:this.configContainer});};YAHOO.widget.Tooltip.prototype.configText=function(type,args,obj){var text=args[0];if(text){this.setBody(text);}};YAHOO.widget.Tooltip.prototype.configContainer=function(type,args,obj){var container=args[0];if(typeof container=='string'){this.cfg.setProperty("container",document.getElementById(container),true);}};YAHOO.widget.Tooltip.prototype.configContext=function(type,args,obj){var context=args[0];if(context){if(!(context instanceof Array)){if(typeof context=="string"){this.cfg.setProperty("context",[document.getElementById(context)],true);}else{this.cfg.setProperty("context",[context],true);} |
| | | context=this.cfg.getProperty("context");} |
| | | if(this._context){for(var c=0;c<this._context.length;++c){var el=this._context[c];YAHOO.util.Event.removeListener(el,"mouseover",this.onContextMouseOver);YAHOO.util.Event.removeListener(el,"mousemove",this.onContextMouseMove);YAHOO.util.Event.removeListener(el,"mouseout",this.onContextMouseOut);}} |
| | | this._context=context;for(var d=0;d<this._context.length;++d){var el2=this._context[d];YAHOO.util.Event.addListener(el2,"mouseover",this.onContextMouseOver,this);YAHOO.util.Event.addListener(el2,"mousemove",this.onContextMouseMove,this);YAHOO.util.Event.addListener(el2,"mouseout",this.onContextMouseOut,this);}}};YAHOO.widget.Tooltip.prototype.onContextMouseMove=function(e,obj){obj.pageX=YAHOO.util.Event.getPageX(e);obj.pageY=YAHOO.util.Event.getPageY(e);};YAHOO.widget.Tooltip.prototype.onContextMouseOver=function(e,obj){if(obj.hideProcId){clearTimeout(obj.hideProcId);obj.hideProcId=null;} |
| | | var context=this;YAHOO.util.Event.addListener(context,"mousemove",obj.onContextMouseMove,obj);if(context.title){obj._tempTitle=context.title;context.title="";} |
| | | obj.showProcId=obj.doShow(e,context);};YAHOO.widget.Tooltip.prototype.onContextMouseOut=function(e,obj){var el=this;if(obj._tempTitle){el.title=obj._tempTitle;obj._tempTitle=null;} |
| | | if(obj.showProcId){clearTimeout(obj.showProcId);obj.showProcId=null;} |
| | | if(obj.hideProcId){clearTimeout(obj.hideProcId);obj.hideProcId=null;} |
| | | obj.hideProcId=setTimeout(function(){obj.hide();},obj.cfg.getProperty("hidedelay"));};YAHOO.widget.Tooltip.prototype.doShow=function(e,context){var yOffset=25;if(this.browser=="opera"&&context.tagName=="A"){yOffset+=12;} |
| | | var me=this;return setTimeout(function(){if(me._tempTitle){me.setBody(me._tempTitle);}else{me.cfg.refireEvent("text");} |
| | | me.moveTo(me.pageX,me.pageY+yOffset);if(me.cfg.getProperty("preventoverlap")){me.preventOverlap(me.pageX,me.pageY);} |
| | | YAHOO.util.Event.removeListener(context,"mousemove",me.onContextMouseMove);me.show();me.hideProcId=me.doHide();},this.cfg.getProperty("showdelay"));};YAHOO.widget.Tooltip.prototype.doHide=function(){var me=this;return setTimeout(function(){me.hide();},this.cfg.getProperty("autodismissdelay"));};YAHOO.widget.Tooltip.prototype.preventOverlap=function(pageX,pageY){var height=this.element.offsetHeight;var elementRegion=YAHOO.util.Dom.getRegion(this.element);elementRegion.top-=5;elementRegion.left-=5;elementRegion.right+=5;elementRegion.bottom+=5;var mousePoint=new YAHOO.util.Point(pageX,pageY);if(elementRegion.contains(mousePoint)){this.cfg.setProperty("y",(pageY-height-5));}};YAHOO.widget.Tooltip.prototype.toString=function(){return"Tooltip "+this.id;};YAHOO.widget.Panel=function(el,userConfig){YAHOO.widget.Panel.superclass.constructor.call(this,el,userConfig);};YAHOO.extend(YAHOO.widget.Panel,YAHOO.widget.Overlay);YAHOO.widget.Panel.CSS_PANEL="yui-panel";YAHOO.widget.Panel.CSS_PANEL_CONTAINER="yui-panel-container";YAHOO.widget.Panel.prototype.init=function(el,userConfig){YAHOO.widget.Panel.superclass.init.call(this,el);this.beforeInitEvent.fire(YAHOO.widget.Panel);YAHOO.util.Dom.addClass(this.element,YAHOO.widget.Panel.CSS_PANEL);this.buildWrapper();if(userConfig){this.cfg.applyConfig(userConfig,true);} |
| | | this.beforeRenderEvent.subscribe(function(){var draggable=this.cfg.getProperty("draggable");if(draggable){if(!this.header){this.setHeader(" ");}}},this,true);var me=this;var doBlur=function(){this.blur();};this.showMaskEvent.subscribe(function(){var checkFocusable=function(el){if((el.tagName=="A"||el.tagName=="BUTTON"||el.tagName=="SELECT"||el.tagName=="INPUT"||el.tagName=="TEXTAREA")&&el.type!="hidden"){if(!YAHOO.util.Dom.isAncestor(me.element,el)){YAHOO.util.Event.addListener(el,"focus",doBlur,el,true);return true;}}else{return false;}};this.focusableElements=YAHOO.util.Dom.getElementsBy(checkFocusable);},this,true);this.hideMaskEvent.subscribe(function(){for(var i=0;i<this.focusableElements.length;i++){var el2=this.focusableElements[i];YAHOO.util.Event.removeListener(el2,"focus",doBlur);}},this,true);this.beforeShowEvent.subscribe(function(){this.cfg.refireEvent("underlay");},this,true);this.initEvent.fire(YAHOO.widget.Panel);};YAHOO.widget.Panel.prototype.initEvents=function(){YAHOO.widget.Panel.superclass.initEvents.call(this);this.showMaskEvent=new YAHOO.util.CustomEvent("showMask");this.hideMaskEvent=new YAHOO.util.CustomEvent("hideMask");this.dragEvent=new YAHOO.util.CustomEvent("drag");};YAHOO.widget.Panel.prototype.initDefaultConfig=function(){YAHOO.widget.Panel.superclass.initDefaultConfig.call(this);this.cfg.addProperty("close",{value:true,handler:this.configClose,validator:this.cfg.checkBoolean,supercedes:["visible"]});this.cfg.addProperty("draggable",{value:true,handler:this.configDraggable,validator:this.cfg.checkBoolean,supercedes:["visible"]});this.cfg.addProperty("underlay",{value:"shadow",handler:this.configUnderlay,supercedes:["visible"]});this.cfg.addProperty("modal",{value:false,handler:this.configModal,validator:this.cfg.checkBoolean,supercedes:["visible"]});this.cfg.addProperty("keylisteners",{handler:this.configKeyListeners,suppressEvent:true,supercedes:["visible"]});};YAHOO.widget.Panel.prototype.configClose=function(type,args,obj){var val=args[0];var doHide=function(e,obj){obj.hide();};if(val){if(!this.close){this.close=document.createElement("span");YAHOO.util.Dom.addClass(this.close,"container-close");this.close.innerHTML=" ";this.innerElement.appendChild(this.close);YAHOO.util.Event.addListener(this.close,"click",doHide,this);}else{this.close.style.display="block";}}else{if(this.close){this.close.style.display="none";}}};YAHOO.widget.Panel.prototype.configDraggable=function(type,args,obj){var val=args[0];if(val){if(this.header){YAHOO.util.Dom.setStyle(this.header,"cursor","move");this.registerDragDrop();}}else{if(this.dd){this.dd.unreg();} |
| | | if(this.header){YAHOO.util.Dom.setStyle(this.header,"cursor","auto");}}};YAHOO.widget.Panel.prototype.configUnderlay=function(type,args,obj){var val=args[0];switch(val.toLowerCase()){case"shadow":YAHOO.util.Dom.removeClass(this.element,"matte");YAHOO.util.Dom.addClass(this.element,"shadow");if(!this.underlay){this.underlay=document.createElement("div");this.underlay.className="underlay";this.underlay.innerHTML=" ";this.element.appendChild(this.underlay);} |
| | | this.sizeUnderlay();break;case"matte":YAHOO.util.Dom.removeClass(this.element,"shadow");YAHOO.util.Dom.addClass(this.element,"matte");break;default:YAHOO.util.Dom.removeClass(this.element,"shadow");YAHOO.util.Dom.removeClass(this.element,"matte");break;}};YAHOO.widget.Panel.prototype.configModal=function(type,args,obj){var modal=args[0];if(modal){this.buildMask();if(!YAHOO.util.Config.alreadySubscribed(this.beforeShowEvent,this.showMask,this)){this.beforeShowEvent.subscribe(this.showMask,this,true);} |
| | | if(!YAHOO.util.Config.alreadySubscribed(this.hideEvent,this.hideMask,this)){this.hideEvent.subscribe(this.hideMask,this,true);} |
| | | if(!YAHOO.util.Config.alreadySubscribed(YAHOO.widget.Overlay.windowResizeEvent,this.sizeMask,this)){YAHOO.widget.Overlay.windowResizeEvent.subscribe(this.sizeMask,this,true);} |
| | | if(!YAHOO.util.Config.alreadySubscribed(this.destroyEvent,this.removeMask,this)){this.destroyEvent.subscribe(this.removeMask,this,true);} |
| | | this.cfg.refireEvent("zIndex");}else{this.beforeShowEvent.unsubscribe(this.showMask,this);this.hideEvent.unsubscribe(this.hideMask,this);YAHOO.widget.Overlay.windowResizeEvent.unsubscribe(this.sizeMask,this);this.destroyEvent.unsubscribe(this.removeMask,this);}};YAHOO.widget.Panel.prototype.removeMask=function(){if(this.mask){if(this.mask.parentNode){this.mask.parentNode.removeChild(this.mask);} |
| | | this.mask=null;}};YAHOO.widget.Panel.prototype.configKeyListeners=function(type,args,obj){var listeners=args[0];if(listeners){if(listeners instanceof Array){for(var i=0;i<listeners.length;i++){var listener=listeners[i];if(!YAHOO.util.Config.alreadySubscribed(this.showEvent,listener.enable,listener)){this.showEvent.subscribe(listener.enable,listener,true);} |
| | | if(!YAHOO.util.Config.alreadySubscribed(this.hideEvent,listener.disable,listener)){this.hideEvent.subscribe(listener.disable,listener,true);this.destroyEvent.subscribe(listener.disable,listener,true);}}}else{if(!YAHOO.util.Config.alreadySubscribed(this.showEvent,listeners.enable,listeners)){this.showEvent.subscribe(listeners.enable,listeners,true);} |
| | | if(!YAHOO.util.Config.alreadySubscribed(this.hideEvent,listeners.disable,listeners)){this.hideEvent.subscribe(listeners.disable,listeners,true);this.destroyEvent.subscribe(listeners.disable,listeners,true);}}}};YAHOO.widget.Panel.prototype.configHeight=function(type,args,obj){var height=args[0];var el=this.innerElement;YAHOO.util.Dom.setStyle(el,"height",height);this.cfg.refireEvent("underlay");this.cfg.refireEvent("iframe");};YAHOO.widget.Panel.prototype.configWidth=function(type,args,obj){var width=args[0];var el=this.innerElement;YAHOO.util.Dom.setStyle(el,"width",width);this.cfg.refireEvent("underlay");this.cfg.refireEvent("iframe");};YAHOO.widget.Panel.prototype.configzIndex=function(type,args,obj){YAHOO.widget.Panel.superclass.configzIndex.call(this,type,args,obj);var maskZ=0;var currentZ=YAHOO.util.Dom.getStyle(this.element,"zIndex");if(this.mask){if(!currentZ||isNaN(currentZ)){currentZ=0;} |
| | | if(currentZ===0){this.cfg.setProperty("zIndex",1);}else{maskZ=currentZ-1;YAHOO.util.Dom.setStyle(this.mask,"zIndex",maskZ);}}};YAHOO.widget.Panel.prototype.buildWrapper=function(){var elementParent=this.element.parentNode;var originalElement=this.element;var wrapper=document.createElement("div");wrapper.className=YAHOO.widget.Panel.CSS_PANEL_CONTAINER;wrapper.id=originalElement.id+"_c";if(elementParent){elementParent.insertBefore(wrapper,originalElement);} |
| | | wrapper.appendChild(originalElement);this.element=wrapper;this.innerElement=originalElement;YAHOO.util.Dom.setStyle(this.innerElement,"visibility","inherit");};YAHOO.widget.Panel.prototype.sizeUnderlay=function(){if(this.underlay&&this.browser!="gecko"&&this.browser!="safari"){this.underlay.style.width=this.innerElement.offsetWidth+"px";this.underlay.style.height=this.innerElement.offsetHeight+"px";}};YAHOO.widget.Panel.prototype.onDomResize=function(e,obj){YAHOO.widget.Panel.superclass.onDomResize.call(this,e,obj);var me=this;setTimeout(function(){me.sizeUnderlay();},0);};YAHOO.widget.Panel.prototype.registerDragDrop=function(){if(this.header){this.dd=new YAHOO.util.DD(this.element.id,this.id);if(!this.header.id){this.header.id=this.id+"_h";} |
| | | var me=this;this.dd.startDrag=function(){if(me.browser=="ie"){YAHOO.util.Dom.addClass(me.element,"drag");} |
| | | if(me.cfg.getProperty("constraintoviewport")){var offsetHeight=me.element.offsetHeight;var offsetWidth=me.element.offsetWidth;var viewPortWidth=YAHOO.util.Dom.getViewportWidth();var viewPortHeight=YAHOO.util.Dom.getViewportHeight();var scrollX=window.scrollX||document.documentElement.scrollLeft;var scrollY=window.scrollY||document.documentElement.scrollTop;var topConstraint=scrollY+10;var leftConstraint=scrollX+10;var bottomConstraint=scrollY+viewPortHeight-offsetHeight-10;var rightConstraint=scrollX+viewPortWidth-offsetWidth-10;this.minX=leftConstraint;this.maxX=rightConstraint;this.constrainX=true;this.minY=topConstraint;this.maxY=bottomConstraint;this.constrainY=true;}else{this.constrainX=false;this.constrainY=false;} |
| | | me.dragEvent.fire("startDrag",arguments);};this.dd.onDrag=function(){me.syncPosition();me.cfg.refireEvent("iframe");if(this.platform=="mac"&&this.browser=="gecko"){this.showMacGeckoScrollbars();} |
| | | me.dragEvent.fire("onDrag",arguments);};this.dd.endDrag=function(){if(me.browser=="ie"){YAHOO.util.Dom.removeClass(me.element,"drag");} |
| | | me.dragEvent.fire("endDrag",arguments);};this.dd.setHandleElId(this.header.id);this.dd.addInvalidHandleType("INPUT");this.dd.addInvalidHandleType("SELECT");this.dd.addInvalidHandleType("TEXTAREA");}};YAHOO.widget.Panel.prototype.buildMask=function(){if(!this.mask){this.mask=document.createElement("div");this.mask.id=this.id+"_mask";this.mask.className="mask";this.mask.innerHTML=" ";var maskClick=function(e,obj){YAHOO.util.Event.stopEvent(e);};var firstChild=document.body.firstChild;if(firstChild){document.body.insertBefore(this.mask,document.body.firstChild);}else{document.body.appendChild(this.mask);}}};YAHOO.widget.Panel.prototype.hideMask=function(){if(this.cfg.getProperty("modal")&&this.mask){this.mask.style.display="none";this.hideMaskEvent.fire();YAHOO.util.Dom.removeClass(document.body,"masked");}};YAHOO.widget.Panel.prototype.showMask=function(){if(this.cfg.getProperty("modal")&&this.mask){YAHOO.util.Dom.addClass(document.body,"masked");this.sizeMask();this.mask.style.display="block";this.showMaskEvent.fire();}};YAHOO.widget.Panel.prototype.sizeMask=function(){if(this.mask){this.mask.style.height=YAHOO.util.Dom.getDocumentHeight()+"px";this.mask.style.width=YAHOO.util.Dom.getDocumentWidth()+"px";}};YAHOO.widget.Panel.prototype.render=function(appendToNode){return YAHOO.widget.Panel.superclass.render.call(this,appendToNode,this.innerElement);};YAHOO.widget.Panel.prototype.toString=function(){return"Panel "+this.id;};YAHOO.widget.Dialog=function(el,userConfig){YAHOO.widget.Dialog.superclass.constructor.call(this,el,userConfig);};YAHOO.extend(YAHOO.widget.Dialog,YAHOO.widget.Panel);YAHOO.widget.Dialog.CSS_DIALOG="yui-dialog";YAHOO.widget.Dialog.prototype.initDefaultConfig=function(){YAHOO.widget.Dialog.superclass.initDefaultConfig.call(this);this.callback={success:null,failure:null,argument:null};this.cfg.addProperty("postmethod",{value:"async",handler:this.configPostMethod,validator:function(val){if(val!="form"&&val!="async"&&val!="none"&&val!="manual"){return false;}else{return true;}}});this.cfg.addProperty("buttons",{value:"none",handler:this.configButtons});};YAHOO.widget.Dialog.prototype.initEvents=function(){YAHOO.widget.Dialog.superclass.initEvents.call(this);this.beforeSubmitEvent=new YAHOO.util.CustomEvent("beforeSubmit");this.submitEvent=new YAHOO.util.CustomEvent("submit");this.manualSubmitEvent=new YAHOO.util.CustomEvent("manualSubmit");this.asyncSubmitEvent=new YAHOO.util.CustomEvent("asyncSubmit");this.formSubmitEvent=new YAHOO.util.CustomEvent("formSubmit");this.cancelEvent=new YAHOO.util.CustomEvent("cancel");};YAHOO.widget.Dialog.prototype.init=function(el,userConfig){YAHOO.widget.Dialog.superclass.init.call(this,el);this.beforeInitEvent.fire(YAHOO.widget.Dialog);YAHOO.util.Dom.addClass(this.element,YAHOO.widget.Dialog.CSS_DIALOG);this.cfg.setProperty("visible",false);if(userConfig){this.cfg.applyConfig(userConfig,true);} |
| | | this.showEvent.subscribe(this.focusFirst,this,true);this.beforeHideEvent.subscribe(this.blurButtons,this,true);this.beforeRenderEvent.subscribe(function(){var buttonCfg=this.cfg.getProperty("buttons");if(buttonCfg&&buttonCfg!="none"){if(!this.footer){this.setFooter("");}}},this,true);this.initEvent.fire(YAHOO.widget.Dialog);};YAHOO.widget.Dialog.prototype.doSubmit=function(){var pm=this.cfg.getProperty("postmethod");switch(pm){case"async":var method=this.form.getAttribute("method")||'POST';method=method.toUpperCase();YAHOO.util.Connect.setForm(this.form);var cObj=YAHOO.util.Connect.asyncRequest(method,this.form.getAttribute("action"),this.callback);this.asyncSubmitEvent.fire();break;case"form":this.form.submit();this.formSubmitEvent.fire();break;case"none":case"manual":this.manualSubmitEvent.fire();break;}};YAHOO.widget.Dialog.prototype.registerForm=function(){var form=this.element.getElementsByTagName("form")[0];if(!form){var formHTML="<form name=\"frm_"+this.id+"\" action=\"\"></form>";this.body.innerHTML+=formHTML;form=this.element.getElementsByTagName("form")[0];} |
| | | this.firstFormElement=function(){for(var f=0;f<form.elements.length;f++){var el=form.elements[f];if(el.focus&&!el.disabled){if(el.type&&el.type!="hidden"){return el;}}} |
| | | return null;}();this.lastFormElement=function(){for(var f=form.elements.length-1;f>=0;f--){var el=form.elements[f];if(el.focus&&!el.disabled){if(el.type&&el.type!="hidden"){return el;}}} |
| | | return null;}();this.form=form;if(this.cfg.getProperty("modal")&&this.form){var me=this;var firstElement=this.firstFormElement||this.firstButton;if(firstElement){this.preventBackTab=new YAHOO.util.KeyListener(firstElement,{shift:true,keys:9},{fn:me.focusLast,scope:me,correctScope:true});this.showEvent.subscribe(this.preventBackTab.enable,this.preventBackTab,true);this.hideEvent.subscribe(this.preventBackTab.disable,this.preventBackTab,true);} |
| | | var lastElement=this.lastButton||this.lastFormElement;if(lastElement){this.preventTabOut=new YAHOO.util.KeyListener(lastElement,{shift:false,keys:9},{fn:me.focusFirst,scope:me,correctScope:true});this.showEvent.subscribe(this.preventTabOut.enable,this.preventTabOut,true);this.hideEvent.subscribe(this.preventTabOut.disable,this.preventTabOut,true);}}};YAHOO.widget.Dialog.prototype.configClose=function(type,args,obj){var val=args[0];var doCancel=function(e,obj){obj.cancel();};if(val){if(!this.close){this.close=document.createElement("div");YAHOO.util.Dom.addClass(this.close,"container-close");this.close.innerHTML=" ";this.innerElement.appendChild(this.close);YAHOO.util.Event.addListener(this.close,"click",doCancel,this);}else{this.close.style.display="block";}}else{if(this.close){this.close.style.display="none";}}};YAHOO.widget.Dialog.prototype.configButtons=function(type,args,obj){var buttons=args[0];if(buttons!="none"){this.buttonSpan=null;this.buttonSpan=document.createElement("span");this.buttonSpan.className="button-group";for(var b=0;b<buttons.length;b++){var button=buttons[b];var htmlButton=document.createElement("button");htmlButton.setAttribute("type","button");if(button.isDefault){htmlButton.className="default";this.defaultHtmlButton=htmlButton;} |
| | | htmlButton.appendChild(document.createTextNode(button.text));YAHOO.util.Event.addListener(htmlButton,"click",button.handler,this,true);this.buttonSpan.appendChild(htmlButton);button.htmlButton=htmlButton;if(b===0){this.firstButton=button.htmlButton;} |
| | | if(b==(buttons.length-1)){this.lastButton=button.htmlButton;}} |
| | | this.setFooter(this.buttonSpan);this.cfg.refireEvent("iframe");this.cfg.refireEvent("underlay");}else{if(this.buttonSpan){if(this.buttonSpan.parentNode){this.buttonSpan.parentNode.removeChild(this.buttonSpan);} |
| | | this.buttonSpan=null;this.firstButton=null;this.lastButton=null;this.defaultHtmlButton=null;}}};YAHOO.widget.Dialog.prototype.focusFirst=function(type,args,obj){if(args){var e=args[1];if(e){YAHOO.util.Event.stopEvent(e);}} |
| | | if(this.firstFormElement){this.firstFormElement.focus();}else{this.focusDefaultButton();}};YAHOO.widget.Dialog.prototype.focusLast=function(type,args,obj){if(args){var e=args[1];if(e){YAHOO.util.Event.stopEvent(e);}} |
| | | var buttons=this.cfg.getProperty("buttons");if(buttons&&buttons instanceof Array){this.focusLastButton();}else{if(this.lastFormElement){this.lastFormElement.focus();}}};YAHOO.widget.Dialog.prototype.focusDefaultButton=function(){if(this.defaultHtmlButton){this.defaultHtmlButton.focus();}};YAHOO.widget.Dialog.prototype.blurButtons=function(){var buttons=this.cfg.getProperty("buttons");if(buttons&&buttons instanceof Array){var html=buttons[0].htmlButton;if(html){html.blur();}}};YAHOO.widget.Dialog.prototype.focusFirstButton=function(){var buttons=this.cfg.getProperty("buttons");if(buttons&&buttons instanceof Array){var html=buttons[0].htmlButton;if(html){html.focus();}}};YAHOO.widget.Dialog.prototype.focusLastButton=function(){var buttons=this.cfg.getProperty("buttons");if(buttons&&buttons instanceof Array){var html=buttons[buttons.length-1].htmlButton;if(html){html.focus();}}};YAHOO.widget.Dialog.prototype.configPostMethod=function(type,args,obj){var postmethod=args[0];this.registerForm();YAHOO.util.Event.addListener(this.form,"submit",function(e){YAHOO.util.Event.stopEvent(e);this.submit();this.form.blur();},this,true);};YAHOO.widget.Dialog.prototype.validate=function(){return true;};YAHOO.widget.Dialog.prototype.submit=function(){if(this.validate()){this.beforeSubmitEvent.fire();this.doSubmit();this.submitEvent.fire();this.hide();return true;}else{return false;}};YAHOO.widget.Dialog.prototype.cancel=function(){this.cancelEvent.fire();this.hide();};YAHOO.widget.Dialog.prototype.getData=function(){var oForm=this.form;if(oForm){var aElements=oForm.elements,nTotalElements=aElements.length,oData={},sName,oElement;for(var i=0;i<nTotalElements;i++){sName=aElements[i].name,oElement=aElements[sName];if(oElement){if(oElement.tagName){var sType=oElement.type,sTagName=oElement.tagName.toUpperCase();switch(sTagName){case"INPUT":if(sType=="checkbox"){oData[sName]=oElement.checked;} |
| | | else if(sType!="radio"){oData[sName]=oElement.value;} |
| | | break;case"TEXTAREA":oData[sName]=oElement.value;break;case"SELECT":var aOptions=oElement.options,nOptions=aOptions.length,aValues=[],oOption,sValue;for(var n=0;n<nOptions;n++){oOption=aOptions[n];if(oOption.selected){sValue=oOption.value;if(!sValue||sValue===""){sValue=oOption.text;} |
| | | aValues[aValues.length]=sValue;}} |
| | | oData[sName]=aValues;break;}} |
| | | else{var nElements=oElement.length,sType=oElement[0].type,sTagName=oElement[0].tagName.toUpperCase();switch(sType){case"radio":var oRadio;for(var n=0;n<nElements;n++){oRadio=oElement[n];if(oRadio.checked){oData[sName]=oRadio.value;break;}} |
| | | break;case"checkbox":var aValues=[],oCheckbox;for(var n=0;n<nElements;n++){oCheckbox=oElement[n];if(oCheckbox.checked){aValues[aValues.length]=oCheckbox.value;}} |
| | | oData[sName]=aValues;break;}}}}} |
| | | return oData;};YAHOO.widget.Dialog.prototype.toString=function(){return"Dialog "+this.id;};YAHOO.widget.SimpleDialog=function(el,userConfig){YAHOO.widget.SimpleDialog.superclass.constructor.call(this,el,userConfig);};YAHOO.extend(YAHOO.widget.SimpleDialog,YAHOO.widget.Dialog);YAHOO.widget.SimpleDialog.ICON_BLOCK="blckicon";YAHOO.widget.SimpleDialog.ICON_ALARM="alrticon";YAHOO.widget.SimpleDialog.ICON_HELP="hlpicon";YAHOO.widget.SimpleDialog.ICON_INFO="infoicon";YAHOO.widget.SimpleDialog.ICON_WARN="warnicon";YAHOO.widget.SimpleDialog.ICON_TIP="tipicon";YAHOO.widget.SimpleDialog.CSS_SIMPLEDIALOG="yui-simple-dialog";YAHOO.widget.SimpleDialog.prototype.initDefaultConfig=function(){YAHOO.widget.SimpleDialog.superclass.initDefaultConfig.call(this);this.cfg.addProperty("icon",{value:"none",handler:this.configIcon,suppressEvent:true});this.cfg.addProperty("text",{value:"",handler:this.configText,suppressEvent:true,supercedes:["icon"]});};YAHOO.widget.SimpleDialog.prototype.init=function(el,userConfig){YAHOO.widget.SimpleDialog.superclass.init.call(this,el);this.beforeInitEvent.fire(YAHOO.widget.SimpleDialog);YAHOO.util.Dom.addClass(this.element,YAHOO.widget.SimpleDialog.CSS_SIMPLEDIALOG);this.cfg.queueProperty("postmethod","manual");if(userConfig){this.cfg.applyConfig(userConfig,true);} |
| | | this.beforeRenderEvent.subscribe(function(){if(!this.body){this.setBody("");}},this,true);this.initEvent.fire(YAHOO.widget.SimpleDialog);};YAHOO.widget.SimpleDialog.prototype.registerForm=function(){YAHOO.widget.SimpleDialog.superclass.registerForm.call(this);this.form.innerHTML+="<input type=\"hidden\" name=\""+this.id+"\" value=\"\"/>";};YAHOO.widget.SimpleDialog.prototype.configIcon=function(type,args,obj){var icon=args[0];if(icon&&icon!="none"){var iconHTML="";if(icon.indexOf(".")==-1){iconHTML="<span class=\"yui-icon "+icon+"\" > </span>";}else{iconHTML="<img src=\""+this.imageRoot+icon+"\" class=\"yui-icon\" />";} |
| | | this.body.innerHTML=iconHTML+this.body.innerHTML;}};YAHOO.widget.SimpleDialog.prototype.configText=function(type,args,obj){var text=args[0];if(text){this.setBody(text);this.cfg.refireEvent("icon");}};YAHOO.widget.SimpleDialog.prototype.toString=function(){return"SimpleDialog "+this.id;};YAHOO.widget.ContainerEffect=function(overlay,attrIn,attrOut,targetElement,animClass){if(!animClass){animClass=YAHOO.util.Anim;} |
| | | this.overlay=overlay;this.attrIn=attrIn;this.attrOut=attrOut;this.targetElement=targetElement||overlay.element;this.animClass=animClass;};YAHOO.widget.ContainerEffect.prototype.init=function(){this.beforeAnimateInEvent=new YAHOO.util.CustomEvent("beforeAnimateIn");this.beforeAnimateOutEvent=new YAHOO.util.CustomEvent("beforeAnimateOut");this.animateInCompleteEvent=new YAHOO.util.CustomEvent("animateInComplete");this.animateOutCompleteEvent=new YAHOO.util.CustomEvent("animateOutComplete");this.animIn=new this.animClass(this.targetElement,this.attrIn.attributes,this.attrIn.duration,this.attrIn.method);this.animIn.onStart.subscribe(this.handleStartAnimateIn,this);this.animIn.onTween.subscribe(this.handleTweenAnimateIn,this);this.animIn.onComplete.subscribe(this.handleCompleteAnimateIn,this);this.animOut=new this.animClass(this.targetElement,this.attrOut.attributes,this.attrOut.duration,this.attrOut.method);this.animOut.onStart.subscribe(this.handleStartAnimateOut,this);this.animOut.onTween.subscribe(this.handleTweenAnimateOut,this);this.animOut.onComplete.subscribe(this.handleCompleteAnimateOut,this);};YAHOO.widget.ContainerEffect.prototype.animateIn=function(){this.beforeAnimateInEvent.fire();this.animIn.animate();};YAHOO.widget.ContainerEffect.prototype.animateOut=function(){this.beforeAnimateOutEvent.fire();this.animOut.animate();};YAHOO.widget.ContainerEffect.prototype.handleStartAnimateIn=function(type,args,obj){};YAHOO.widget.ContainerEffect.prototype.handleTweenAnimateIn=function(type,args,obj){};YAHOO.widget.ContainerEffect.prototype.handleCompleteAnimateIn=function(type,args,obj){};YAHOO.widget.ContainerEffect.prototype.handleStartAnimateOut=function(type,args,obj){};YAHOO.widget.ContainerEffect.prototype.handleTweenAnimateOut=function(type,args,obj){};YAHOO.widget.ContainerEffect.prototype.handleCompleteAnimateOut=function(type,args,obj){};YAHOO.widget.ContainerEffect.prototype.toString=function(){var output="ContainerEffect";if(this.overlay){output+=" ["+this.overlay.toString()+"]";} |
| | | return output;};YAHOO.widget.ContainerEffect.FADE=function(overlay,dur){var fade=new YAHOO.widget.ContainerEffect(overlay,{attributes:{opacity:{from:0,to:1}},duration:dur,method:YAHOO.util.Easing.easeIn},{attributes:{opacity:{to:0}},duration:dur,method:YAHOO.util.Easing.easeOut},overlay.element);fade.handleStartAnimateIn=function(type,args,obj){YAHOO.util.Dom.addClass(obj.overlay.element,"hide-select");if(!obj.overlay.underlay){obj.overlay.cfg.refireEvent("underlay");} |
| | | if(obj.overlay.underlay){obj.initialUnderlayOpacity=YAHOO.util.Dom.getStyle(obj.overlay.underlay,"opacity");obj.overlay.underlay.style.filter=null;} |
| | | YAHOO.util.Dom.setStyle(obj.overlay.element,"visibility","visible");YAHOO.util.Dom.setStyle(obj.overlay.element,"opacity",0);};fade.handleCompleteAnimateIn=function(type,args,obj){YAHOO.util.Dom.removeClass(obj.overlay.element,"hide-select");if(obj.overlay.element.style.filter){obj.overlay.element.style.filter=null;} |
| | | if(obj.overlay.underlay){YAHOO.util.Dom.setStyle(obj.overlay.underlay,"opacity",obj.initialUnderlayOpacity);} |
| | | obj.overlay.cfg.refireEvent("iframe");obj.animateInCompleteEvent.fire();};fade.handleStartAnimateOut=function(type,args,obj){YAHOO.util.Dom.addClass(obj.overlay.element,"hide-select");if(obj.overlay.underlay){obj.overlay.underlay.style.filter=null;}};fade.handleCompleteAnimateOut=function(type,args,obj){YAHOO.util.Dom.removeClass(obj.overlay.element,"hide-select");if(obj.overlay.element.style.filter){obj.overlay.element.style.filter=null;} |
| | | YAHOO.util.Dom.setStyle(obj.overlay.element,"visibility","hidden");YAHOO.util.Dom.setStyle(obj.overlay.element,"opacity",1);obj.overlay.cfg.refireEvent("iframe");obj.animateOutCompleteEvent.fire();};fade.init();return fade;};YAHOO.widget.ContainerEffect.SLIDE=function(overlay,dur){var x=overlay.cfg.getProperty("x")||YAHOO.util.Dom.getX(overlay.element);var y=overlay.cfg.getProperty("y")||YAHOO.util.Dom.getY(overlay.element);var clientWidth=YAHOO.util.Dom.getClientWidth();var offsetWidth=overlay.element.offsetWidth;var slide=new YAHOO.widget.ContainerEffect(overlay,{attributes:{points:{to:[x,y]}},duration:dur,method:YAHOO.util.Easing.easeIn},{attributes:{points:{to:[(clientWidth+25),y]}},duration:dur,method:YAHOO.util.Easing.easeOut},overlay.element,YAHOO.util.Motion);slide.handleStartAnimateIn=function(type,args,obj){obj.overlay.element.style.left=(-25-offsetWidth)+"px";obj.overlay.element.style.top=y+"px";};slide.handleTweenAnimateIn=function(type,args,obj){var pos=YAHOO.util.Dom.getXY(obj.overlay.element);var currentX=pos[0];var currentY=pos[1];if(YAHOO.util.Dom.getStyle(obj.overlay.element,"visibility")=="hidden"&¤tX<x){YAHOO.util.Dom.setStyle(obj.overlay.element,"visibility","visible");} |
| | | obj.overlay.cfg.setProperty("xy",[currentX,currentY],true);obj.overlay.cfg.refireEvent("iframe");};slide.handleCompleteAnimateIn=function(type,args,obj){obj.overlay.cfg.setProperty("xy",[x,y],true);obj.startX=x;obj.startY=y;obj.overlay.cfg.refireEvent("iframe");obj.animateInCompleteEvent.fire();};slide.handleStartAnimateOut=function(type,args,obj){var vw=YAHOO.util.Dom.getViewportWidth();var pos=YAHOO.util.Dom.getXY(obj.overlay.element);var yso=pos[1];var currentTo=obj.animOut.attributes.points.to;obj.animOut.attributes.points.to=[(vw+25),yso];};slide.handleTweenAnimateOut=function(type,args,obj){var pos=YAHOO.util.Dom.getXY(obj.overlay.element);var xto=pos[0];var yto=pos[1];obj.overlay.cfg.setProperty("xy",[xto,yto],true);obj.overlay.cfg.refireEvent("iframe");};slide.handleCompleteAnimateOut=function(type,args,obj){YAHOO.util.Dom.setStyle(obj.overlay.element,"visibility","hidden");obj.overlay.cfg.setProperty("xy",[x,y]);obj.animateOutCompleteEvent.fire();};slide.init();return slide;};YAHOO.register("container",YAHOO.widget.Module,{version:"2.2.0",build:"127"}); |
New file |
| | |
| | | /* |
| | | 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 |
| | | */ |
| | | /** |
| | | * Config is a utility used within an Object to allow the implementer to maintain a list of local configuration properties and listen for changes to those properties dynamically using CustomEvent. The initial values are also maintained so that the configuration can be reset at any given point to its initial state. |
| | | * @namespace YAHOO.util |
| | | * @class Config |
| | | * @constructor |
| | | * @param {Object} owner The owner Object to which this Config Object belongs |
| | | */ |
| | | YAHOO.util.Config = function(owner) { |
| | | if (owner) { |
| | | this.init(owner); |
| | | } |
| | | if (!owner) { YAHOO.log("No owner specified for Config object", "error"); } |
| | | }; |
| | | |
| | | YAHOO.util.Config.prototype = { |
| | | |
| | | /** |
| | | * Object reference to the owner of this Config Object |
| | | * @property owner |
| | | * @type Object |
| | | */ |
| | | owner : null, |
| | | |
| | | /** |
| | | * Boolean flag that specifies whether a queue is currently being executed |
| | | * @property queueInProgress |
| | | * @type Boolean |
| | | */ |
| | | queueInProgress : false, |
| | | |
| | | |
| | | /** |
| | | * Validates that the value passed in is a Boolean. |
| | | * @method checkBoolean |
| | | * @param {Object} val The value to validate |
| | | * @return {Boolean} true, if the value is valid |
| | | */ |
| | | checkBoolean: function(val) { |
| | | if (typeof val == 'boolean') { |
| | | return true; |
| | | } else { |
| | | return false; |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * Validates that the value passed in is a number. |
| | | * @method checkNumber |
| | | * @param {Object} val The value to validate |
| | | * @return {Boolean} true, if the value is valid |
| | | */ |
| | | checkNumber: function(val) { |
| | | if (isNaN(val)) { |
| | | return false; |
| | | } else { |
| | | return true; |
| | | } |
| | | } |
| | | }; |
| | | |
| | | |
| | | /** |
| | | * Initializes the configuration Object and all of its local members. |
| | | * @method init |
| | | * @param {Object} owner The owner Object to which this Config Object belongs |
| | | */ |
| | | YAHOO.util.Config.prototype.init = function(owner) { |
| | | |
| | | this.owner = owner; |
| | | |
| | | /** |
| | | * Object reference to the owner of this Config Object |
| | | * @event configChangedEvent |
| | | */ |
| | | this.configChangedEvent = new YAHOO.util.CustomEvent("configChanged"); |
| | | this.queueInProgress = false; |
| | | |
| | | /* Private Members */ |
| | | |
| | | /** |
| | | * Maintains the local collection of configuration property objects and their specified values |
| | | * @property config |
| | | * @private |
| | | * @type Object |
| | | */ |
| | | var config = {}; |
| | | |
| | | /** |
| | | * Maintains the local collection of configuration property objects as they were initially applied. |
| | | * This object is used when resetting a property. |
| | | * @property initialConfig |
| | | * @private |
| | | * @type Object |
| | | */ |
| | | var initialConfig = {}; |
| | | |
| | | /** |
| | | * Maintains the local, normalized CustomEvent queue |
| | | * @property eventQueue |
| | | * @private |
| | | * @type Object |
| | | */ |
| | | var eventQueue = []; |
| | | |
| | | /** |
| | | * Fires a configuration property event using the specified value. |
| | | * @method fireEvent |
| | | * @private |
| | | * @param {String} key The configuration property's name |
| | | * @param {value} Object The value of the correct type for the property |
| | | */ |
| | | var fireEvent = function( key, value ) { |
| | | YAHOO.log("Firing Config event: " + key + "=" + value, "info"); |
| | | key = key.toLowerCase(); |
| | | |
| | | var property = config[key]; |
| | | |
| | | if (typeof property != 'undefined' && property.event) { |
| | | property.event.fire(value); |
| | | } |
| | | }; |
| | | /* End Private Members */ |
| | | |
| | | /** |
| | | * Adds a property to the Config Object's private config hash. |
| | | * @method addProperty |
| | | * @param {String} key The configuration property's name |
| | | * @param {Object} propertyObject The Object containing all of this property's arguments |
| | | */ |
| | | this.addProperty = function( key, propertyObject ) { |
| | | key = key.toLowerCase(); |
| | | YAHOO.log("Added property: " + key, "info"); |
| | | |
| | | config[key] = propertyObject; |
| | | |
| | | propertyObject.event = new YAHOO.util.CustomEvent(key); |
| | | propertyObject.key = key; |
| | | |
| | | if (propertyObject.handler) { |
| | | propertyObject.event.subscribe(propertyObject.handler, this.owner, true); |
| | | } |
| | | |
| | | this.setProperty(key, propertyObject.value, true); |
| | | |
| | | if (! propertyObject.suppressEvent) { |
| | | this.queueProperty(key, propertyObject.value); |
| | | } |
| | | }; |
| | | |
| | | /** |
| | | * Returns a key-value configuration map of the values currently set in the Config Object. |
| | | * @method getConfig |
| | | * @return {Object} The current config, represented in a key-value map |
| | | */ |
| | | this.getConfig = function() { |
| | | var cfg = {}; |
| | | |
| | | for (var prop in config) { |
| | | var property = config[prop]; |
| | | if (typeof property != 'undefined' && property.event) { |
| | | cfg[prop] = property.value; |
| | | } |
| | | } |
| | | |
| | | return cfg; |
| | | }; |
| | | |
| | | /** |
| | | * Returns the value of specified property. |
| | | * @method getProperty |
| | | * @param {String} key The name of the property |
| | | * @return {Object} The value of the specified property |
| | | */ |
| | | this.getProperty = function(key) { |
| | | key = key.toLowerCase(); |
| | | |
| | | var property = config[key]; |
| | | if (typeof property != 'undefined' && property.event) { |
| | | return property.value; |
| | | } else { |
| | | return undefined; |
| | | } |
| | | }; |
| | | |
| | | /** |
| | | * Resets the specified property's value to its initial value. |
| | | * @method resetProperty |
| | | * @param {String} key The name of the property |
| | | * @return {Boolean} True is the property was reset, false if not |
| | | */ |
| | | this.resetProperty = function(key) { |
| | | key = key.toLowerCase(); |
| | | |
| | | var property = config[key]; |
| | | if (typeof property != 'undefined' && property.event) { |
| | | if (initialConfig[key] && initialConfig[key] != 'undefined') { |
| | | this.setProperty(key, initialConfig[key]); |
| | | } |
| | | return true; |
| | | } else { |
| | | return false; |
| | | } |
| | | }; |
| | | |
| | | /** |
| | | * Sets the value of a property. If the silent property is passed as true, the property's event will not be fired. |
| | | * @method setProperty |
| | | * @param {String} key The name of the property |
| | | * @param {String} value The value to set the property to |
| | | * @param {Boolean} silent Whether the value should be set silently, without firing the property event. |
| | | * @return {Boolean} True, if the set was successful, false if it failed. |
| | | */ |
| | | this.setProperty = function(key, value, silent) { |
| | | key = key.toLowerCase(); |
| | | YAHOO.log("setProperty: " + key + "=" + value, "info"); |
| | | |
| | | if (this.queueInProgress && ! silent) { |
| | | this.queueProperty(key,value); // Currently running through a queue... |
| | | return true; |
| | | } else { |
| | | var property = config[key]; |
| | | if (typeof property != 'undefined' && property.event) { |
| | | if (property.validator && ! property.validator(value)) { // validator |
| | | return false; |
| | | } else { |
| | | property.value = value; |
| | | if (! silent) { |
| | | fireEvent(key, value); |
| | | this.configChangedEvent.fire([key, value]); |
| | | } |
| | | return true; |
| | | } |
| | | } else { |
| | | return false; |
| | | } |
| | | } |
| | | }; |
| | | |
| | | /** |
| | | * Sets the value of a property and queues its event to execute. If the event is already scheduled to execute, it is |
| | | * moved from its current position to the end of the queue. |
| | | * @method queueProperty |
| | | * @param {String} key The name of the property |
| | | * @param {String} value The value to set the property to |
| | | * @return {Boolean} true, if the set was successful, false if it failed. |
| | | */ |
| | | this.queueProperty = function(key, value) { |
| | | key = key.toLowerCase(); |
| | | YAHOO.log("queueProperty: " + key + "=" + value, "info"); |
| | | |
| | | var property = config[key]; |
| | | |
| | | if (typeof property != 'undefined' && property.event) { |
| | | if (typeof value != 'undefined' && property.validator && ! property.validator(value)) { // validator |
| | | return false; |
| | | } else { |
| | | |
| | | if (typeof value != 'undefined') { |
| | | property.value = value; |
| | | } else { |
| | | value = property.value; |
| | | } |
| | | |
| | | var foundDuplicate = false; |
| | | |
| | | for (var i=0;i<eventQueue.length;i++) { |
| | | var queueItem = eventQueue[i]; |
| | | |
| | | if (queueItem) { |
| | | var queueItemKey = queueItem[0]; |
| | | var queueItemValue = queueItem[1]; |
| | | |
| | | if (queueItemKey.toLowerCase() == key) { |
| | | // found a dupe... push to end of queue, null current item, and break |
| | | eventQueue[i] = null; |
| | | eventQueue.push([key, (typeof value != 'undefined' ? value : queueItemValue)]); |
| | | foundDuplicate = true; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | if (! foundDuplicate && typeof value != 'undefined') { // this is a refire, or a new property in the queue |
| | | eventQueue.push([key, value]); |
| | | } |
| | | } |
| | | |
| | | if (property.supercedes) { |
| | | for (var s=0;s<property.supercedes.length;s++) { |
| | | var supercedesCheck = property.supercedes[s]; |
| | | |
| | | for (var q=0;q<eventQueue.length;q++) { |
| | | var queueItemCheck = eventQueue[q]; |
| | | |
| | | if (queueItemCheck) { |
| | | var queueItemCheckKey = queueItemCheck[0]; |
| | | var queueItemCheckValue = queueItemCheck[1]; |
| | | |
| | | if ( queueItemCheckKey.toLowerCase() == supercedesCheck.toLowerCase() ) { |
| | | eventQueue.push([queueItemCheckKey, queueItemCheckValue]); |
| | | eventQueue[q] = null; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | YAHOO.log("Config event queue: " + this.outputEventQueue(), "info"); |
| | | |
| | | return true; |
| | | } else { |
| | | return false; |
| | | } |
| | | }; |
| | | |
| | | /** |
| | | * Fires the event for a property using the property's current value. |
| | | * @method refireEvent |
| | | * @param {String} key The name of the property |
| | | */ |
| | | this.refireEvent = function(key) { |
| | | key = key.toLowerCase(); |
| | | |
| | | var property = config[key]; |
| | | if (typeof property != 'undefined' && property.event && typeof property.value != 'undefined') { |
| | | if (this.queueInProgress) { |
| | | this.queueProperty(key); |
| | | } else { |
| | | fireEvent(key, property.value); |
| | | } |
| | | } |
| | | }; |
| | | |
| | | /** |
| | | * Applies a key-value Object literal to the configuration, replacing any existing values, and queueing the property events. |
| | | * Although the values will be set, fireQueue() must be called for their associated events to execute. |
| | | * @method applyConfig |
| | | * @param {Object} userConfig The configuration Object literal |
| | | * @param {Boolean} init When set to true, the initialConfig will be set to the userConfig passed in, so that calling a reset will reset the properties to the passed values. |
| | | */ |
| | | this.applyConfig = function(userConfig, init) { |
| | | if (init) { |
| | | initialConfig = userConfig; |
| | | } |
| | | for (var prop in userConfig) { |
| | | this.queueProperty(prop, userConfig[prop]); |
| | | } |
| | | }; |
| | | |
| | | /** |
| | | * Refires the events for all configuration properties using their current values. |
| | | * @method refresh |
| | | */ |
| | | this.refresh = function() { |
| | | for (var prop in config) { |
| | | this.refireEvent(prop); |
| | | } |
| | | }; |
| | | |
| | | /** |
| | | * Fires the normalized list of queued property change events |
| | | * @method fireQueue |
| | | */ |
| | | this.fireQueue = function() { |
| | | this.queueInProgress = true; |
| | | for (var i=0;i<eventQueue.length;i++) { |
| | | var queueItem = eventQueue[i]; |
| | | if (queueItem) { |
| | | var key = queueItem[0]; |
| | | var value = queueItem[1]; |
| | | |
| | | var property = config[key]; |
| | | property.value = value; |
| | | |
| | | fireEvent(key,value); |
| | | } |
| | | } |
| | | |
| | | this.queueInProgress = false; |
| | | eventQueue = []; |
| | | }; |
| | | |
| | | /** |
| | | * Subscribes an external handler to the change event for any given property. |
| | | * @method subscribeToConfigEvent |
| | | * @param {String} key The property name |
| | | * @param {Function} handler The handler function to use subscribe to the property's event |
| | | * @param {Object} obj The Object to use for scoping the event handler (see CustomEvent documentation) |
| | | * @param {Boolean} override Optional. If true, will override "this" within the handler to map to the scope Object passed into the method. |
| | | * @return {Boolean} True, if the subscription was successful, otherwise false. |
| | | */ |
| | | this.subscribeToConfigEvent = function(key, handler, obj, override) { |
| | | key = key.toLowerCase(); |
| | | |
| | | var property = config[key]; |
| | | if (typeof property != 'undefined' && property.event) { |
| | | if (! YAHOO.util.Config.alreadySubscribed(property.event, handler, obj)) { |
| | | property.event.subscribe(handler, obj, override); |
| | | } |
| | | return true; |
| | | } else { |
| | | return false; |
| | | } |
| | | }; |
| | | |
| | | /** |
| | | * Unsubscribes an external handler from the change event for any given property. |
| | | * @method unsubscribeFromConfigEvent |
| | | * @param {String} key The property name |
| | | * @param {Function} handler The handler function to use subscribe to the property's event |
| | | * @param {Object} obj The Object to use for scoping the event handler (see CustomEvent documentation) |
| | | * @return {Boolean} True, if the unsubscription was successful, otherwise false. |
| | | */ |
| | | this.unsubscribeFromConfigEvent = function(key, handler, obj) { |
| | | key = key.toLowerCase(); |
| | | |
| | | var property = config[key]; |
| | | if (typeof property != 'undefined' && property.event) { |
| | | return property.event.unsubscribe(handler, obj); |
| | | } else { |
| | | return false; |
| | | } |
| | | }; |
| | | |
| | | /** |
| | | * Returns a string representation of the Config object |
| | | * @method toString |
| | | * @return {String} The Config object in string format. |
| | | */ |
| | | this.toString = function() { |
| | | var output = "Config"; |
| | | if (this.owner) { |
| | | output += " [" + this.owner.toString() + "]"; |
| | | } |
| | | return output; |
| | | }; |
| | | |
| | | /** |
| | | * Returns a string representation of the Config object's current CustomEvent queue |
| | | * @method outputEventQueue |
| | | * @return {String} The string list of CustomEvents currently queued for execution |
| | | */ |
| | | this.outputEventQueue = function() { |
| | | var output = ""; |
| | | for (var q=0;q<eventQueue.length;q++) { |
| | | var queueItem = eventQueue[q]; |
| | | if (queueItem) { |
| | | output += queueItem[0] + "=" + queueItem[1] + ", "; |
| | | } |
| | | } |
| | | return output; |
| | | }; |
| | | }; |
| | | |
| | | /** |
| | | * Checks to determine if a particular function/Object pair are already subscribed to the specified CustomEvent |
| | | * @method YAHOO.util.Config.alreadySubscribed |
| | | * @static |
| | | * @param {YAHOO.util.CustomEvent} evt The CustomEvent for which to check the subscriptions |
| | | * @param {Function} fn The function to look for in the subscribers list |
| | | * @param {Object} obj The execution scope Object for the subscription |
| | | * @return {Boolean} true, if the function/Object pair is already subscribed to the CustomEvent passed in |
| | | */ |
| | | YAHOO.util.Config.alreadySubscribed = function(evt, fn, obj) { |
| | | for (var e=0;e<evt.subscribers.length;e++) { |
| | | var subsc = evt.subscribers[e]; |
| | | if (subsc && subsc.obj == obj && subsc.fn == fn) { |
| | | return true; |
| | | } |
| | | } |
| | | return false; |
| | | }; |
| | | |
| | | /** |
| | | * The Container family of components is designed to enable developers to create different kinds of content-containing modules on the web. Module and Overlay are the most basic containers, and they can be used directly or extended to build custom containers. Also part of the Container family are four UI controls that extend Module and Overlay: Tooltip, Panel, Dialog, and SimpleDialog. |
| | | * @module container |
| | | * @title Container |
| | | * @requires yahoo,dom,event,dragdrop,animation |
| | | */ |
| | | |
| | | /** |
| | | * Module is a JavaScript representation of the Standard Module Format. Standard Module Format is a simple standard for markup containers where child nodes representing the header, body, and footer of the content are denoted using the CSS classes "hd", "bd", and "ft" respectively. Module is the base class for all other classes in the YUI Container package. |
| | | * @namespace YAHOO.widget |
| | | * @class Module |
| | | * @constructor |
| | | * @param {String} el The element ID representing the Module <em>OR</em> |
| | | * @param {HTMLElement} el The element representing the Module |
| | | * @param {Object} userConfig The configuration Object literal containing the configuration that should be set for this module. See configuration documentation for more details. |
| | | */ |
| | | YAHOO.widget.Module = function(el, userConfig) { |
| | | if (el) { |
| | | this.init(el, userConfig); |
| | | } else { |
| | | YAHOO.log("No element or element ID specified for Module instantiation", "error"); |
| | | } |
| | | }; |
| | | |
| | | /** |
| | | * Constant representing the prefix path to use for non-secure images |
| | | * @property YAHOO.widget.Module.IMG_ROOT |
| | | * @static |
| | | * @final |
| | | * @type String |
| | | */ |
| | | YAHOO.widget.Module.IMG_ROOT = null; |
| | | |
| | | /** |
| | | * Constant representing the prefix path to use for securely served images |
| | | * @property YAHOO.widget.Module.IMG_ROOT_SSL |
| | | * @static |
| | | * @final |
| | | * @type String |
| | | */ |
| | | YAHOO.widget.Module.IMG_ROOT_SSL = null; |
| | | |
| | | /** |
| | | * Constant for the default CSS class name that represents a Module |
| | | * @property YAHOO.widget.Module.CSS_MODULE |
| | | * @static |
| | | * @final |
| | | * @type String |
| | | */ |
| | | YAHOO.widget.Module.CSS_MODULE = "module"; |
| | | |
| | | /** |
| | | * Constant representing the module header |
| | | * @property YAHOO.widget.Module.CSS_HEADER |
| | | * @static |
| | | * @final |
| | | * @type String |
| | | */ |
| | | YAHOO.widget.Module.CSS_HEADER = "hd"; |
| | | |
| | | /** |
| | | * Constant representing the module body |
| | | * @property YAHOO.widget.Module.CSS_BODY |
| | | * @static |
| | | * @final |
| | | * @type String |
| | | */ |
| | | YAHOO.widget.Module.CSS_BODY = "bd"; |
| | | |
| | | /** |
| | | * Constant representing the module footer |
| | | * @property YAHOO.widget.Module.CSS_FOOTER |
| | | * @static |
| | | * @final |
| | | * @type String |
| | | */ |
| | | YAHOO.widget.Module.CSS_FOOTER = "ft"; |
| | | |
| | | /** |
| | | * Constant representing the url for the "src" attribute of the iframe used to monitor changes to the browser's base font size |
| | | * @property YAHOO.widget.Module.RESIZE_MONITOR_SECURE_URL |
| | | * @static |
| | | * @final |
| | | * @type String |
| | | */ |
| | | YAHOO.widget.Module.RESIZE_MONITOR_SECURE_URL = "javascript:false;"; |
| | | |
| | | /** |
| | | * Singleton CustomEvent fired when the font size is changed in the browser. |
| | | * Opera's "zoom" functionality currently does not support text size detection. |
| | | * @event YAHOO.widget.Module.textResizeEvent |
| | | */ |
| | | YAHOO.widget.Module.textResizeEvent = new YAHOO.util.CustomEvent("textResize"); |
| | | |
| | | YAHOO.widget.Module.prototype = { |
| | | /** |
| | | * The class's constructor function |
| | | * @property contructor |
| | | * @type Function |
| | | */ |
| | | constructor : YAHOO.widget.Module, |
| | | |
| | | /** |
| | | * The main module element that contains the header, body, and footer |
| | | * @property element |
| | | * @type HTMLElement |
| | | */ |
| | | element : null, |
| | | |
| | | /** |
| | | * The header element, denoted with CSS class "hd" |
| | | * @property header |
| | | * @type HTMLElement |
| | | */ |
| | | header : null, |
| | | |
| | | /** |
| | | * The body element, denoted with CSS class "bd" |
| | | * @property body |
| | | * @type HTMLElement |
| | | */ |
| | | body : null, |
| | | |
| | | /** |
| | | * The footer element, denoted with CSS class "ft" |
| | | * @property footer |
| | | * @type HTMLElement |
| | | */ |
| | | footer : null, |
| | | |
| | | /** |
| | | * The id of the element |
| | | * @property id |
| | | * @type String |
| | | */ |
| | | id : null, |
| | | |
| | | /** |
| | | * The String representing the image root |
| | | * @property imageRoot |
| | | * @type String |
| | | */ |
| | | imageRoot : YAHOO.widget.Module.IMG_ROOT, |
| | | |
| | | /** |
| | | * Initializes the custom events for Module which are fired automatically at appropriate times by the Module class. |
| | | * @method initEvents |
| | | */ |
| | | initEvents : function() { |
| | | |
| | | /** |
| | | * CustomEvent fired prior to class initalization. |
| | | * @event beforeInitEvent |
| | | * @param {class} classRef class reference of the initializing class, such as this.beforeInitEvent.fire(YAHOO.widget.Module) |
| | | */ |
| | | this.beforeInitEvent = new YAHOO.util.CustomEvent("beforeInit"); |
| | | |
| | | /** |
| | | * CustomEvent fired after class initalization. |
| | | * @event initEvent |
| | | * @param {class} classRef class reference of the initializing class, such as this.beforeInitEvent.fire(YAHOO.widget.Module) |
| | | */ |
| | | this.initEvent = new YAHOO.util.CustomEvent("init"); |
| | | |
| | | /** |
| | | * CustomEvent fired when the Module is appended to the DOM |
| | | * @event appendEvent |
| | | */ |
| | | this.appendEvent = new YAHOO.util.CustomEvent("append"); |
| | | |
| | | /** |
| | | * CustomEvent fired before the Module is rendered |
| | | * @event beforeRenderEvent |
| | | */ |
| | | this.beforeRenderEvent = new YAHOO.util.CustomEvent("beforeRender"); |
| | | |
| | | /** |
| | | * CustomEvent fired after the Module is rendered |
| | | * @event renderEvent |
| | | */ |
| | | this.renderEvent = new YAHOO.util.CustomEvent("render"); |
| | | |
| | | /** |
| | | * CustomEvent fired when the header content of the Module is modified |
| | | * @event changeHeaderEvent |
| | | * @param {String/HTMLElement} content String/element representing the new header content |
| | | */ |
| | | this.changeHeaderEvent = new YAHOO.util.CustomEvent("changeHeader"); |
| | | |
| | | /** |
| | | * CustomEvent fired when the body content of the Module is modified |
| | | * @event changeBodyEvent |
| | | * @param {String/HTMLElement} content String/element representing the new body content |
| | | */ |
| | | this.changeBodyEvent = new YAHOO.util.CustomEvent("changeBody"); |
| | | |
| | | /** |
| | | * CustomEvent fired when the footer content of the Module is modified |
| | | * @event changeFooterEvent |
| | | * @param {String/HTMLElement} content String/element representing the new footer content |
| | | */ |
| | | this.changeFooterEvent = new YAHOO.util.CustomEvent("changeFooter"); |
| | | |
| | | /** |
| | | * CustomEvent fired when the content of the Module is modified |
| | | * @event changeContentEvent |
| | | */ |
| | | this.changeContentEvent = new YAHOO.util.CustomEvent("changeContent"); |
| | | |
| | | /** |
| | | * CustomEvent fired when the Module is destroyed |
| | | * @event destroyEvent |
| | | */ |
| | | this.destroyEvent = new YAHOO.util.CustomEvent("destroy"); |
| | | |
| | | /** |
| | | * CustomEvent fired before the Module is shown |
| | | * @event beforeShowEvent |
| | | */ |
| | | this.beforeShowEvent = new YAHOO.util.CustomEvent("beforeShow"); |
| | | |
| | | /** |
| | | * CustomEvent fired after the Module is shown |
| | | * @event showEvent |
| | | */ |
| | | this.showEvent = new YAHOO.util.CustomEvent("show"); |
| | | |
| | | /** |
| | | * CustomEvent fired before the Module is hidden |
| | | * @event beforeHideEvent |
| | | */ |
| | | this.beforeHideEvent = new YAHOO.util.CustomEvent("beforeHide"); |
| | | |
| | | /** |
| | | * CustomEvent fired after the Module is hidden |
| | | * @event hideEvent |
| | | */ |
| | | this.hideEvent = new YAHOO.util.CustomEvent("hide"); |
| | | }, |
| | | |
| | | /** |
| | | * String representing the current user-agent platform |
| | | * @property platform |
| | | * @type String |
| | | */ |
| | | platform : function() { |
| | | var ua = navigator.userAgent.toLowerCase(); |
| | | if (ua.indexOf("windows") != -1 || ua.indexOf("win32") != -1) { |
| | | return "windows"; |
| | | } else if (ua.indexOf("macintosh") != -1) { |
| | | return "mac"; |
| | | } else { |
| | | return false; |
| | | } |
| | | }(), |
| | | |
| | | /** |
| | | * String representing the current user-agent browser |
| | | * @property browser |
| | | * @type String |
| | | */ |
| | | browser : function() { |
| | | var ua = navigator.userAgent.toLowerCase(); |
| | | if (ua.indexOf('opera')!=-1) { // Opera (check first in case of spoof) |
| | | return 'opera'; |
| | | } else if (ua.indexOf('msie 7')!=-1) { // IE7 |
| | | return 'ie7'; |
| | | } else if (ua.indexOf('msie') !=-1) { // IE |
| | | return 'ie'; |
| | | } else if (ua.indexOf('safari')!=-1) { // Safari (check before Gecko because it includes "like Gecko") |
| | | return 'safari'; |
| | | } else if (ua.indexOf('gecko') != -1) { // Gecko |
| | | return 'gecko'; |
| | | } else { |
| | | return false; |
| | | } |
| | | }(), |
| | | |
| | | /** |
| | | * Boolean representing whether or not the current browsing context is secure (https) |
| | | * @property isSecure |
| | | * @type Boolean |
| | | */ |
| | | isSecure : function() { |
| | | if (window.location.href.toLowerCase().indexOf("https") === 0) { |
| | | return true; |
| | | } else { |
| | | return false; |
| | | } |
| | | }(), |
| | | |
| | | /** |
| | | * Initializes the custom events for Module which are fired automatically at appropriate times by the Module class. |
| | | */ |
| | | initDefaultConfig : function() { |
| | | // Add properties // |
| | | |
| | | /** |
| | | * Specifies whether the Module is visible on the page. |
| | | * @config visible |
| | | * @type Boolean |
| | | * @default true |
| | | */ |
| | | this.cfg.addProperty("visible", { value:true, handler:this.configVisible, validator:this.cfg.checkBoolean } ); |
| | | |
| | | /** |
| | | * Object or array of objects representing the ContainerEffect classes that are active for animating the container. |
| | | * @config effect |
| | | * @type Object |
| | | * @default null |
| | | */ |
| | | this.cfg.addProperty("effect", { suppressEvent:true, supercedes:["visible"] } ); |
| | | |
| | | /** |
| | | * Specifies whether to create a special proxy iframe to monitor for user font resizing in the document |
| | | * @config monitorresize |
| | | * @type Boolean |
| | | * @default true |
| | | */ |
| | | this.cfg.addProperty("monitorresize", { value:true, handler:this.configMonitorResize } ); |
| | | }, |
| | | |
| | | /** |
| | | * The Module class's initialization method, which is executed for Module and all of its subclasses. This method is automatically called by the constructor, and sets up all DOM references for pre-existing markup, and creates required markup if it is not already present. |
| | | * @method init |
| | | * @param {String} el The element ID representing the Module <em>OR</em> |
| | | * @param {HTMLElement} el The element representing the Module |
| | | * @param {Object} userConfig The configuration Object literal containing the configuration that should be set for this module. See configuration documentation for more details. |
| | | */ |
| | | init : function(el, userConfig) { |
| | | |
| | | this.initEvents(); |
| | | |
| | | this.beforeInitEvent.fire(YAHOO.widget.Module); |
| | | |
| | | /** |
| | | * The Module's Config object used for monitoring configuration properties. |
| | | * @property cfg |
| | | * @type YAHOO.util.Config |
| | | */ |
| | | this.cfg = new YAHOO.util.Config(this); |
| | | |
| | | if (this.isSecure) { |
| | | this.imageRoot = YAHOO.widget.Module.IMG_ROOT_SSL; |
| | | } |
| | | |
| | | if (typeof el == "string") { |
| | | var elId = el; |
| | | |
| | | el = document.getElementById(el); |
| | | if (! el) { |
| | | el = document.createElement("div"); |
| | | el.id = elId; |
| | | } |
| | | } |
| | | |
| | | this.element = el; |
| | | |
| | | if (el.id) { |
| | | this.id = el.id; |
| | | } |
| | | |
| | | var childNodes = this.element.childNodes; |
| | | |
| | | if (childNodes) { |
| | | for (var i=0;i<childNodes.length;i++) { |
| | | var child = childNodes[i]; |
| | | switch (child.className) { |
| | | case YAHOO.widget.Module.CSS_HEADER: |
| | | this.header = child; |
| | | break; |
| | | case YAHOO.widget.Module.CSS_BODY: |
| | | this.body = child; |
| | | break; |
| | | case YAHOO.widget.Module.CSS_FOOTER: |
| | | this.footer = child; |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | |
| | | this.initDefaultConfig(); |
| | | |
| | | YAHOO.util.Dom.addClass(this.element, YAHOO.widget.Module.CSS_MODULE); |
| | | |
| | | if (userConfig) { |
| | | this.cfg.applyConfig(userConfig, true); |
| | | } |
| | | |
| | | // Subscribe to the fireQueue() method of Config so that any queued configuration changes are |
| | | // excecuted upon render of the Module |
| | | if (! YAHOO.util.Config.alreadySubscribed(this.renderEvent, this.cfg.fireQueue, this.cfg)) { |
| | | this.renderEvent.subscribe(this.cfg.fireQueue, this.cfg, true); |
| | | } |
| | | |
| | | this.initEvent.fire(YAHOO.widget.Module); |
| | | }, |
| | | |
| | | /** |
| | | * Initialized an empty IFRAME that is placed out of the visible area that can be used to detect text resize. |
| | | * @method initResizeMonitor |
| | | */ |
| | | initResizeMonitor : function() { |
| | | |
| | | if(this.browser != "opera") { |
| | | |
| | | var resizeMonitor = document.getElementById("_yuiResizeMonitor"); |
| | | |
| | | if (! resizeMonitor) { |
| | | |
| | | resizeMonitor = document.createElement("iframe"); |
| | | |
| | | var bIE = (this.browser.indexOf("ie") === 0); |
| | | |
| | | if(this.isSecure && YAHOO.widget.Module.RESIZE_MONITOR_SECURE_URL && bIE) { |
| | | resizeMonitor.src = YAHOO.widget.Module.RESIZE_MONITOR_SECURE_URL; |
| | | } |
| | | |
| | | resizeMonitor.id = "_yuiResizeMonitor"; |
| | | resizeMonitor.style.visibility = "hidden"; |
| | | |
| | | document.body.appendChild(resizeMonitor); |
| | | |
| | | resizeMonitor.style.width = "10em"; |
| | | resizeMonitor.style.height = "10em"; |
| | | resizeMonitor.style.position = "absolute"; |
| | | |
| | | var nLeft = -1 * resizeMonitor.offsetWidth; |
| | | var nTop = -1 * resizeMonitor.offsetHeight; |
| | | |
| | | resizeMonitor.style.top = nTop + "px"; |
| | | resizeMonitor.style.left = nLeft + "px"; |
| | | resizeMonitor.style.borderStyle = "none"; |
| | | resizeMonitor.style.borderWidth = "0"; |
| | | YAHOO.util.Dom.setStyle(resizeMonitor, "opacity", "0"); |
| | | |
| | | resizeMonitor.style.visibility = "visible"; |
| | | |
| | | if(!bIE) { |
| | | |
| | | var doc = resizeMonitor.contentWindow.document; |
| | | |
| | | doc.open(); |
| | | doc.close(); |
| | | |
| | | } |
| | | } |
| | | |
| | | var fireTextResize = function() { |
| | | YAHOO.widget.Module.textResizeEvent.fire(); |
| | | }; |
| | | |
| | | if(resizeMonitor && resizeMonitor.contentWindow) { |
| | | this.resizeMonitor = resizeMonitor; |
| | | |
| | | YAHOO.widget.Module.textResizeEvent.subscribe(this.onDomResize, this, true); |
| | | |
| | | if (! YAHOO.widget.Module.textResizeInitialized) { |
| | | if (! YAHOO.util.Event.addListener(this.resizeMonitor.contentWindow, "resize", fireTextResize)) { |
| | | // This will fail in IE if document.domain has changed, so we must change the listener to |
| | | // use the resizeMonitor element instead |
| | | YAHOO.util.Event.addListener(this.resizeMonitor, "resize", fireTextResize); |
| | | } |
| | | YAHOO.widget.Module.textResizeInitialized = true; |
| | | } |
| | | } |
| | | |
| | | } |
| | | |
| | | }, |
| | | |
| | | /** |
| | | * Event handler fired when the resize monitor element is resized. |
| | | * @method onDomResize |
| | | * @param {DOMEvent} e The DOM resize event |
| | | * @param {Object} obj The scope object passed to the handler |
| | | */ |
| | | onDomResize : function(e, obj) { |
| | | |
| | | var nLeft = -1 * this.resizeMonitor.offsetWidth, |
| | | nTop = -1 * this.resizeMonitor.offsetHeight; |
| | | |
| | | this.resizeMonitor.style.top = nTop + "px"; |
| | | this.resizeMonitor.style.left = nLeft + "px"; |
| | | |
| | | }, |
| | | |
| | | /** |
| | | * Sets the Module's header content to the HTML specified, or appends the passed element to the header. If no header is present, one will be automatically created. |
| | | * @method setHeader |
| | | * @param {String} headerContent The HTML used to set the header <em>OR</em> |
| | | * @param {HTMLElement} headerContent The HTMLElement to append to the header |
| | | */ |
| | | setHeader : function(headerContent) { |
| | | if (! this.header) { |
| | | this.header = document.createElement("div"); |
| | | this.header.className = YAHOO.widget.Module.CSS_HEADER; |
| | | } |
| | | |
| | | if (typeof headerContent == "string") { |
| | | this.header.innerHTML = headerContent; |
| | | } else { |
| | | this.header.innerHTML = ""; |
| | | this.header.appendChild(headerContent); |
| | | } |
| | | |
| | | this.changeHeaderEvent.fire(headerContent); |
| | | this.changeContentEvent.fire(); |
| | | }, |
| | | |
| | | /** |
| | | * Appends the passed element to the header. If no header is present, one will be automatically created. |
| | | * @method appendToHeader |
| | | * @param {HTMLElement} element The element to append to the header |
| | | */ |
| | | appendToHeader : function(element) { |
| | | if (! this.header) { |
| | | this.header = document.createElement("div"); |
| | | this.header.className = YAHOO.widget.Module.CSS_HEADER; |
| | | } |
| | | |
| | | this.header.appendChild(element); |
| | | this.changeHeaderEvent.fire(element); |
| | | this.changeContentEvent.fire(); |
| | | }, |
| | | |
| | | /** |
| | | * Sets the Module's body content to the HTML specified, or appends the passed element to the body. If no body is present, one will be automatically created. |
| | | * @method setBody |
| | | * @param {String} bodyContent The HTML used to set the body <em>OR</em> |
| | | * @param {HTMLElement} bodyContent The HTMLElement to append to the body |
| | | */ |
| | | setBody : function(bodyContent) { |
| | | if (! this.body) { |
| | | this.body = document.createElement("div"); |
| | | this.body.className = YAHOO.widget.Module.CSS_BODY; |
| | | } |
| | | |
| | | if (typeof bodyContent == "string") |
| | | { |
| | | this.body.innerHTML = bodyContent; |
| | | } else { |
| | | this.body.innerHTML = ""; |
| | | this.body.appendChild(bodyContent); |
| | | } |
| | | |
| | | this.changeBodyEvent.fire(bodyContent); |
| | | this.changeContentEvent.fire(); |
| | | }, |
| | | |
| | | /** |
| | | * Appends the passed element to the body. If no body is present, one will be automatically created. |
| | | * @method appendToBody |
| | | * @param {HTMLElement} element The element to append to the body |
| | | */ |
| | | appendToBody : function(element) { |
| | | if (! this.body) { |
| | | this.body = document.createElement("div"); |
| | | this.body.className = YAHOO.widget.Module.CSS_BODY; |
| | | } |
| | | |
| | | this.body.appendChild(element); |
| | | this.changeBodyEvent.fire(element); |
| | | this.changeContentEvent.fire(); |
| | | }, |
| | | |
| | | /** |
| | | * Sets the Module's footer content to the HTML specified, or appends the passed element to the footer. If no footer is present, one will be automatically created. |
| | | * @method setFooter |
| | | * @param {String} footerContent The HTML used to set the footer <em>OR</em> |
| | | * @param {HTMLElement} footerContent The HTMLElement to append to the footer |
| | | */ |
| | | setFooter : function(footerContent) { |
| | | if (! this.footer) { |
| | | this.footer = document.createElement("div"); |
| | | this.footer.className = YAHOO.widget.Module.CSS_FOOTER; |
| | | } |
| | | |
| | | if (typeof footerContent == "string") { |
| | | this.footer.innerHTML = footerContent; |
| | | } else { |
| | | this.footer.innerHTML = ""; |
| | | this.footer.appendChild(footerContent); |
| | | } |
| | | |
| | | this.changeFooterEvent.fire(footerContent); |
| | | this.changeContentEvent.fire(); |
| | | }, |
| | | |
| | | /** |
| | | * Appends the passed element to the footer. If no footer is present, one will be automatically created. |
| | | * @method appendToFooter |
| | | * @param {HTMLElement} element The element to append to the footer |
| | | */ |
| | | appendToFooter : function(element) { |
| | | if (! this.footer) { |
| | | this.footer = document.createElement("div"); |
| | | this.footer.className = YAHOO.widget.Module.CSS_FOOTER; |
| | | } |
| | | |
| | | this.footer.appendChild(element); |
| | | this.changeFooterEvent.fire(element); |
| | | this.changeContentEvent.fire(); |
| | | }, |
| | | |
| | | /** |
| | | * Renders the Module by inserting the elements that are not already in the main Module into their correct places. Optionally appends the Module to the specified node prior to the render's execution. NOTE: For Modules without existing markup, the appendToNode argument is REQUIRED. If this argument is ommitted and the current element is not present in the document, the function will return false, indicating that the render was a failure. |
| | | * @method render |
| | | * @param {String} appendToNode The element id to which the Module should be appended to prior to rendering <em>OR</em> |
| | | * @param {HTMLElement} appendToNode The element to which the Module should be appended to prior to rendering |
| | | * @param {HTMLElement} moduleElement OPTIONAL. The element that represents the actual Standard Module container. |
| | | * @return {Boolean} Success or failure of the render |
| | | */ |
| | | render : function(appendToNode, moduleElement) { |
| | | this.beforeRenderEvent.fire(); |
| | | |
| | | if (! moduleElement) { |
| | | moduleElement = this.element; |
| | | } |
| | | |
| | | var me = this; |
| | | var appendTo = function(element) { |
| | | if (typeof element == "string") { |
| | | element = document.getElementById(element); |
| | | } |
| | | |
| | | if (element) { |
| | | element.appendChild(me.element); |
| | | me.appendEvent.fire(); |
| | | } |
| | | }; |
| | | |
| | | if (appendToNode) { |
| | | appendTo(appendToNode); |
| | | } else { // No node was passed in. If the element is not pre-marked up, this fails |
| | | if (! YAHOO.util.Dom.inDocument(this.element)) { |
| | | YAHOO.log("Render failed. Must specify appendTo node if Module isn't already in the DOM.", "error"); |
| | | return false; |
| | | } |
| | | } |
| | | |
| | | // Need to get everything into the DOM if it isn't already |
| | | |
| | | if (this.header && ! YAHOO.util.Dom.inDocument(this.header)) { |
| | | // There is a header, but it's not in the DOM yet... need to add it |
| | | var firstChild = moduleElement.firstChild; |
| | | if (firstChild) { // Insert before first child if exists |
| | | moduleElement.insertBefore(this.header, firstChild); |
| | | } else { // Append to empty body because there are no children |
| | | moduleElement.appendChild(this.header); |
| | | } |
| | | } |
| | | |
| | | if (this.body && ! YAHOO.util.Dom.inDocument(this.body)) { |
| | | // There is a body, but it's not in the DOM yet... need to add it |
| | | if (this.footer && YAHOO.util.Dom.isAncestor(this.moduleElement, this.footer)) { // Insert before footer if exists in DOM |
| | | moduleElement.insertBefore(this.body, this.footer); |
| | | } else { // Append to element because there is no footer |
| | | moduleElement.appendChild(this.body); |
| | | } |
| | | } |
| | | |
| | | if (this.footer && ! YAHOO.util.Dom.inDocument(this.footer)) { |
| | | // There is a footer, but it's not in the DOM yet... need to add it |
| | | moduleElement.appendChild(this.footer); |
| | | } |
| | | |
| | | this.renderEvent.fire(); |
| | | return true; |
| | | }, |
| | | |
| | | /** |
| | | * Removes the Module element from the DOM and sets all child elements to null. |
| | | * @method destroy |
| | | */ |
| | | destroy : function() { |
| | | var parent; |
| | | |
| | | if (this.element) { |
| | | YAHOO.util.Event.purgeElement(this.element, true); |
| | | parent = this.element.parentNode; |
| | | } |
| | | if (parent) { |
| | | parent.removeChild(this.element); |
| | | } |
| | | |
| | | this.element = null; |
| | | this.header = null; |
| | | this.body = null; |
| | | this.footer = null; |
| | | |
| | | for (var e in this) { |
| | | if (e instanceof YAHOO.util.CustomEvent) { |
| | | e.unsubscribeAll(); |
| | | } |
| | | } |
| | | |
| | | YAHOO.widget.Module.textResizeEvent.unsubscribe(this.onDomResize, this); |
| | | |
| | | this.destroyEvent.fire(); |
| | | }, |
| | | |
| | | /** |
| | | * Shows the Module element by setting the visible configuration property to true. Also fires two events: beforeShowEvent prior to the visibility change, and showEvent after. |
| | | * @method show |
| | | */ |
| | | show : function() { |
| | | this.cfg.setProperty("visible", true); |
| | | }, |
| | | |
| | | /** |
| | | * Hides the Module element by setting the visible configuration property to false. Also fires two events: beforeHideEvent prior to the visibility change, and hideEvent after. |
| | | * @method hide |
| | | */ |
| | | hide : function() { |
| | | this.cfg.setProperty("visible", false); |
| | | }, |
| | | |
| | | // BUILT-IN EVENT HANDLERS FOR MODULE // |
| | | |
| | | /** |
| | | * Default event handler for changing the visibility property of a Module. By default, this is achieved by switching the "display" style between "block" and "none". |
| | | * This method is responsible for firing showEvent and hideEvent. |
| | | * @param {String} type The CustomEvent type (usually the property name) |
| | | * @param {Object[]} args The CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property. |
| | | * @param {Object} obj The scope object. For configuration handlers, this will usually equal the owner. |
| | | * @method configVisible |
| | | */ |
| | | configVisible : function(type, args, obj) { |
| | | var visible = args[0]; |
| | | if (visible) { |
| | | this.beforeShowEvent.fire(); |
| | | YAHOO.util.Dom.setStyle(this.element, "display", "block"); |
| | | this.showEvent.fire(); |
| | | } else { |
| | | this.beforeHideEvent.fire(); |
| | | YAHOO.util.Dom.setStyle(this.element, "display", "none"); |
| | | this.hideEvent.fire(); |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * Default event handler for the "monitorresize" configuration property |
| | | * @param {String} type The CustomEvent type (usually the property name) |
| | | * @param {Object[]} args The CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property. |
| | | * @param {Object} obj The scope object. For configuration handlers, this will usually equal the owner. |
| | | * @method configMonitorResize |
| | | */ |
| | | configMonitorResize : function(type, args, obj) { |
| | | var monitor = args[0]; |
| | | if (monitor) { |
| | | this.initResizeMonitor(); |
| | | } else { |
| | | YAHOO.widget.Module.textResizeEvent.unsubscribe(this.onDomResize, this, true); |
| | | this.resizeMonitor = null; |
| | | } |
| | | } |
| | | }; |
| | | |
| | | /** |
| | | * Returns a String representation of the Object. |
| | | * @method toString |
| | | * @return {String} The string representation of the Module |
| | | */ |
| | | YAHOO.widget.Module.prototype.toString = function() { |
| | | return "Module " + this.id; |
| | | }; |
| | | |
| | | /** |
| | | * Overlay is a Module that is absolutely positioned above the page flow. It has convenience methods for positioning and sizing, as well as options for controlling zIndex and constraining the Overlay's position to the current visible viewport. Overlay also contains a dynamicly generated IFRAME which is placed beneath it for Internet Explorer 6 and 5.x so that it will be properly rendered above SELECT elements. |
| | | * @namespace YAHOO.widget |
| | | * @class Overlay |
| | | * @extends YAHOO.widget.Module |
| | | * @param {String} el The element ID representing the Overlay <em>OR</em> |
| | | * @param {HTMLElement} el The element representing the Overlay |
| | | * @param {Object} userConfig The configuration object literal containing 10/23/2006the configuration that should be set for this Overlay. See configuration documentation for more details. |
| | | * @constructor |
| | | */ |
| | | YAHOO.widget.Overlay = function(el, userConfig) { |
| | | YAHOO.widget.Overlay.superclass.constructor.call(this, el, userConfig); |
| | | }; |
| | | |
| | | YAHOO.extend(YAHOO.widget.Overlay, YAHOO.widget.Module); |
| | | |
| | | /** |
| | | * The URL that will be placed in the iframe |
| | | * @property YAHOO.widget.Overlay.IFRAME_SRC |
| | | * @static |
| | | * @final |
| | | * @type String |
| | | */ |
| | | YAHOO.widget.Overlay.IFRAME_SRC = "javascript:false;"; |
| | | |
| | | /** |
| | | * Constant representing the top left corner of an element, used for configuring the context element alignment |
| | | * @property YAHOO.widget.Overlay.TOP_LEFT |
| | | * @static |
| | | * @final |
| | | * @type String |
| | | */ |
| | | YAHOO.widget.Overlay.TOP_LEFT = "tl"; |
| | | |
| | | /** |
| | | * Constant representing the top right corner of an element, used for configuring the context element alignment |
| | | * @property YAHOO.widget.Overlay.TOP_RIGHT |
| | | * @static |
| | | * @final |
| | | * @type String |
| | | */ |
| | | YAHOO.widget.Overlay.TOP_RIGHT = "tr"; |
| | | |
| | | /** |
| | | * Constant representing the top bottom left corner of an element, used for configuring the context element alignment |
| | | * @property YAHOO.widget.Overlay.BOTTOM_LEFT |
| | | * @static |
| | | * @final |
| | | * @type String |
| | | */ |
| | | YAHOO.widget.Overlay.BOTTOM_LEFT = "bl"; |
| | | |
| | | /** |
| | | * Constant representing the bottom right corner of an element, used for configuring the context element alignment |
| | | * @property YAHOO.widget.Overlay.BOTTOM_RIGHT |
| | | * @static |
| | | * @final |
| | | * @type String |
| | | */ |
| | | YAHOO.widget.Overlay.BOTTOM_RIGHT = "br"; |
| | | |
| | | /** |
| | | * Constant representing the default CSS class used for an Overlay |
| | | * @property YAHOO.widget.Overlay.CSS_OVERLAY |
| | | * @static |
| | | * @final |
| | | * @type String |
| | | */ |
| | | YAHOO.widget.Overlay.CSS_OVERLAY = "yui-overlay"; |
| | | |
| | | /** |
| | | * The Overlay initialization method, which is executed for Overlay and all of its subclasses. This method is automatically called by the constructor, and sets up all DOM references for pre-existing markup, and creates required markup if it is not already present. |
| | | * @method init |
| | | * @param {String} el The element ID representing the Overlay <em>OR</em> |
| | | * @param {HTMLElement} el The element representing the Overlay |
| | | * @param {Object} userConfig The configuration object literal containing the configuration that should be set for this Overlay. See configuration documentation for more details. |
| | | */ |
| | | YAHOO.widget.Overlay.prototype.init = function(el, userConfig) { |
| | | YAHOO.widget.Overlay.superclass.init.call(this, el/*, userConfig*/); // Note that we don't pass the user config in here yet because we only want it executed once, at the lowest subclass level |
| | | |
| | | this.beforeInitEvent.fire(YAHOO.widget.Overlay); |
| | | |
| | | YAHOO.util.Dom.addClass(this.element, YAHOO.widget.Overlay.CSS_OVERLAY); |
| | | |
| | | if (userConfig) { |
| | | this.cfg.applyConfig(userConfig, true); |
| | | } |
| | | |
| | | if (this.platform == "mac" && this.browser == "gecko") { |
| | | if (! YAHOO.util.Config.alreadySubscribed(this.showEvent,this.showMacGeckoScrollbars,this)) { |
| | | this.showEvent.subscribe(this.showMacGeckoScrollbars,this,true); |
| | | } |
| | | if (! YAHOO.util.Config.alreadySubscribed(this.hideEvent,this.hideMacGeckoScrollbars,this)) { |
| | | this.hideEvent.subscribe(this.hideMacGeckoScrollbars,this,true); |
| | | } |
| | | } |
| | | |
| | | this.initEvent.fire(YAHOO.widget.Overlay); |
| | | |
| | | }; |
| | | |
| | | /** |
| | | * Initializes the custom events for Overlay which are fired automatically at appropriate times by the Overlay class. |
| | | * @method initEvents |
| | | */ |
| | | YAHOO.widget.Overlay.prototype.initEvents = function() { |
| | | YAHOO.widget.Overlay.superclass.initEvents.call(this); |
| | | |
| | | /** |
| | | * CustomEvent fired before the Overlay is moved. |
| | | * @event beforeMoveEvent |
| | | * @param {Number} x x coordinate |
| | | * @param {Number} y y coordinate |
| | | */ |
| | | this.beforeMoveEvent = new YAHOO.util.CustomEvent("beforeMove", this); |
| | | |
| | | /** |
| | | * CustomEvent fired after the Overlay is moved. |
| | | * @event moveEvent |
| | | * @param {Number} x x coordinate |
| | | * @param {Number} y y coordinate |
| | | */ |
| | | this.moveEvent = new YAHOO.util.CustomEvent("move", this); |
| | | }; |
| | | |
| | | /** |
| | | * Initializes the class's configurable properties which can be changed using the Overlay's Config object (cfg). |
| | | * @method initDefaultConfig |
| | | */ |
| | | YAHOO.widget.Overlay.prototype.initDefaultConfig = function() { |
| | | YAHOO.widget.Overlay.superclass.initDefaultConfig.call(this); |
| | | |
| | | // Add overlay config properties // |
| | | |
| | | /** |
| | | * The absolute x-coordinate position of the Overlay |
| | | * @config x |
| | | * @type Number |
| | | * @default null |
| | | */ |
| | | this.cfg.addProperty("x", { handler:this.configX, validator:this.cfg.checkNumber, suppressEvent:true, supercedes:["iframe"] } ); |
| | | |
| | | /** |
| | | * The absolute y-coordinate position of the Overlay |
| | | * @config y |
| | | * @type Number |
| | | * @default null |
| | | */ |
| | | this.cfg.addProperty("y", { handler:this.configY, validator:this.cfg.checkNumber, suppressEvent:true, supercedes:["iframe"] } ); |
| | | |
| | | /** |
| | | * An array with the absolute x and y positions of the Overlay |
| | | * @config xy |
| | | * @type Number[] |
| | | * @default null |
| | | */ |
| | | this.cfg.addProperty("xy",{ handler:this.configXY, suppressEvent:true, supercedes:["iframe"] } ); |
| | | |
| | | /** |
| | | * The array of context arguments for context-sensitive positioning. The format is: [id or element, element corner, context corner]. For example, setting this property to ["img1", "tl", "bl"] would align the Overlay's top left corner to the context element's bottom left corner. |
| | | * @config context |
| | | * @type Array |
| | | * @default null |
| | | */ |
| | | this.cfg.addProperty("context", { handler:this.configContext, suppressEvent:true, supercedes:["iframe"] } ); |
| | | |
| | | /** |
| | | * True if the Overlay should be anchored to the center of the viewport. |
| | | * @config fixedcenter |
| | | * @type Boolean |
| | | * @default false |
| | | */ |
| | | this.cfg.addProperty("fixedcenter", { value:false, handler:this.configFixedCenter, validator:this.cfg.checkBoolean, supercedes:["iframe","visible"] } ); |
| | | |
| | | /** |
| | | * CSS width of the Overlay. |
| | | * @config width |
| | | * @type String |
| | | * @default null |
| | | */ |
| | | this.cfg.addProperty("width", { handler:this.configWidth, suppressEvent:true, supercedes:["iframe"] } ); |
| | | |
| | | /** |
| | | * CSS height of the Overlay. |
| | | * @config height |
| | | * @type String |
| | | * @default null |
| | | */ |
| | | this.cfg.addProperty("height", { handler:this.configHeight, suppressEvent:true, supercedes:["iframe"] } ); |
| | | |
| | | /** |
| | | * CSS z-index of the Overlay. |
| | | * @config zIndex |
| | | * @type Number |
| | | * @default null |
| | | */ |
| | | this.cfg.addProperty("zIndex", { value:null, handler:this.configzIndex } ); |
| | | |
| | | /** |
| | | * True if the Overlay should be prevented from being positioned out of the viewport. |
| | | * @config constraintoviewport |
| | | * @type Boolean |
| | | * @default false |
| | | */ |
| | | this.cfg.addProperty("constraintoviewport", { value:false, handler:this.configConstrainToViewport, validator:this.cfg.checkBoolean, supercedes:["iframe","x","y","xy"] } ); |
| | | |
| | | /** |
| | | * True if the Overlay should have an IFRAME shim (for correcting the select z-index bug in IE6 and below). |
| | | * @config iframe |
| | | * @type Boolean |
| | | * @default true for IE6 and below, false for all others |
| | | */ |
| | | this.cfg.addProperty("iframe", { value:(this.browser == "ie" ? true : false), handler:this.configIframe, validator:this.cfg.checkBoolean, supercedes:["zIndex"] } ); |
| | | }; |
| | | |
| | | /** |
| | | * Moves the Overlay to the specified position. This function is identical to calling this.cfg.setProperty("xy", [x,y]); |
| | | * @method moveTo |
| | | * @param {Number} x The Overlay's new x position |
| | | * @param {Number} y The Overlay's new y position |
| | | */ |
| | | YAHOO.widget.Overlay.prototype.moveTo = function(x, y) { |
| | | this.cfg.setProperty("xy",[x,y]); |
| | | }; |
| | | |
| | | /** |
| | | * Adds a special CSS class to the Overlay when Mac/Gecko is in use, to work around a Gecko bug where |
| | | * scrollbars cannot be hidden. See https://bugzilla.mozilla.org/show_bug.cgi?id=187435 |
| | | * @method hideMacGeckoScrollbars |
| | | */ |
| | | YAHOO.widget.Overlay.prototype.hideMacGeckoScrollbars = function() { |
| | | YAHOO.util.Dom.removeClass(this.element, "show-scrollbars"); |
| | | YAHOO.util.Dom.addClass(this.element, "hide-scrollbars"); |
| | | }; |
| | | |
| | | /** |
| | | * Removes a special CSS class from the Overlay when Mac/Gecko is in use, to work around a Gecko bug where |
| | | * scrollbars cannot be hidden. See https://bugzilla.mozilla.org/show_bug.cgi?id=187435 |
| | | * @method showMacGeckoScrollbars |
| | | */ |
| | | YAHOO.widget.Overlay.prototype.showMacGeckoScrollbars = function() { |
| | | YAHOO.util.Dom.removeClass(this.element, "hide-scrollbars"); |
| | | YAHOO.util.Dom.addClass(this.element, "show-scrollbars"); |
| | | }; |
| | | |
| | | // BEGIN BUILT-IN PROPERTY EVENT HANDLERS // |
| | | |
| | | /** |
| | | * The default event handler fired when the "visible" property is changed. This method is responsible for firing showEvent and hideEvent. |
| | | * @method configVisible |
| | | * @param {String} type The CustomEvent type (usually the property name) |
| | | * @param {Object[]} args The CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property. |
| | | * @param {Object} obj The scope object. For configuration handlers, this will usually equal the owner. |
| | | */ |
| | | YAHOO.widget.Overlay.prototype.configVisible = function(type, args, obj) { |
| | | var visible = args[0]; |
| | | var currentVis = YAHOO.util.Dom.getStyle(this.element, "visibility"); |
| | | |
| | | if (currentVis == "inherit") { |
| | | var e = this.element.parentNode; |
| | | while (e.nodeType != 9 && e.nodeType != 11) { |
| | | currentVis = YAHOO.util.Dom.getStyle(e, "visibility"); |
| | | if (currentVis != "inherit") { break; } |
| | | e = e.parentNode; |
| | | } |
| | | if (currentVis == "inherit") { |
| | | currentVis = "visible"; |
| | | } |
| | | } |
| | | |
| | | var effect = this.cfg.getProperty("effect"); |
| | | |
| | | var effectInstances = []; |
| | | if (effect) { |
| | | if (effect instanceof Array) { |
| | | for (var i=0;i<effect.length;i++) { |
| | | var eff = effect[i]; |
| | | effectInstances[effectInstances.length] = eff.effect(this, eff.duration); |
| | | } |
| | | } else { |
| | | effectInstances[effectInstances.length] = effect.effect(this, effect.duration); |
| | | } |
| | | } |
| | | |
| | | var isMacGecko = (this.platform == "mac" && this.browser == "gecko"); |
| | | |
| | | if (visible) { // Show |
| | | if (isMacGecko) { |
| | | this.showMacGeckoScrollbars(); |
| | | } |
| | | |
| | | if (effect) { // Animate in |
| | | if (visible) { // Animate in if not showing |
| | | if (currentVis != "visible" || currentVis === "") { |
| | | this.beforeShowEvent.fire(); |
| | | for (var j=0;j<effectInstances.length;j++) { |
| | | var ei = effectInstances[j]; |
| | | if (j === 0 && ! YAHOO.util.Config.alreadySubscribed(ei.animateInCompleteEvent,this.showEvent.fire,this.showEvent)) { |
| | | ei.animateInCompleteEvent.subscribe(this.showEvent.fire,this.showEvent,true); // Delegate showEvent until end of animateInComplete |
| | | } |
| | | ei.animateIn(); |
| | | } |
| | | } |
| | | } |
| | | } else { // Show |
| | | if (currentVis != "visible" || currentVis === "") { |
| | | this.beforeShowEvent.fire(); |
| | | YAHOO.util.Dom.setStyle(this.element, "visibility", "visible"); |
| | | this.cfg.refireEvent("iframe"); |
| | | this.showEvent.fire(); |
| | | } |
| | | } |
| | | |
| | | } else { // Hide |
| | | if (isMacGecko) { |
| | | this.hideMacGeckoScrollbars(); |
| | | } |
| | | |
| | | if (effect) { // Animate out if showing |
| | | if (currentVis == "visible") { |
| | | this.beforeHideEvent.fire(); |
| | | for (var k=0;k<effectInstances.length;k++) { |
| | | var h = effectInstances[k]; |
| | | if (k === 0 && ! YAHOO.util.Config.alreadySubscribed(h.animateOutCompleteEvent,this.hideEvent.fire,this.hideEvent)) { |
| | | h.animateOutCompleteEvent.subscribe(this.hideEvent.fire,this.hideEvent,true); // Delegate hideEvent until end of animateOutComplete |
| | | } |
| | | h.animateOut(); |
| | | } |
| | | } else if (currentVis === "") { |
| | | YAHOO.util.Dom.setStyle(this.element, "visibility", "hidden"); |
| | | } |
| | | } else { // Simple hide |
| | | if (currentVis == "visible" || currentVis === "") { |
| | | this.beforeHideEvent.fire(); |
| | | YAHOO.util.Dom.setStyle(this.element, "visibility", "hidden"); |
| | | this.cfg.refireEvent("iframe"); |
| | | this.hideEvent.fire(); |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | |
| | | /** |
| | | * Center event handler used for centering on scroll/resize, but only if the Overlay is visible |
| | | * @method doCenterOnDOMEvent |
| | | */ |
| | | YAHOO.widget.Overlay.prototype.doCenterOnDOMEvent = function() { |
| | | if (this.cfg.getProperty("visible")) { |
| | | this.center(); |
| | | } |
| | | }; |
| | | |
| | | /** |
| | | * The default event handler fired when the "fixedcenter" property is changed. |
| | | * @method configFixedCenter |
| | | * @param {String} type The CustomEvent type (usually the property name) |
| | | * @param {Object[]} args The CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property. |
| | | * @param {Object} obj The scope object. For configuration handlers, this will usually equal the owner. |
| | | */ |
| | | YAHOO.widget.Overlay.prototype.configFixedCenter = function(type, args, obj) { |
| | | var val = args[0]; |
| | | |
| | | if (val) { |
| | | this.center(); |
| | | |
| | | if (! YAHOO.util.Config.alreadySubscribed(this.beforeShowEvent, this.center, this)) { |
| | | this.beforeShowEvent.subscribe(this.center, this, true); |
| | | } |
| | | |
| | | if (! YAHOO.util.Config.alreadySubscribed(YAHOO.widget.Overlay.windowResizeEvent, this.doCenterOnDOMEvent, this)) { |
| | | YAHOO.widget.Overlay.windowResizeEvent.subscribe(this.doCenterOnDOMEvent, this, true); |
| | | } |
| | | |
| | | if (! YAHOO.util.Config.alreadySubscribed(YAHOO.widget.Overlay.windowScrollEvent, this.doCenterOnDOMEvent, this)) { |
| | | YAHOO.widget.Overlay.windowScrollEvent.subscribe( this.doCenterOnDOMEvent, this, true); |
| | | } |
| | | } else { |
| | | YAHOO.widget.Overlay.windowResizeEvent.unsubscribe(this.doCenterOnDOMEvent, this); |
| | | YAHOO.widget.Overlay.windowScrollEvent.unsubscribe(this.doCenterOnDOMEvent, this); |
| | | } |
| | | }; |
| | | |
| | | /** |
| | | * The default event handler fired when the "height" property is changed. |
| | | * @method configHeight |
| | | * @param {String} type The CustomEvent type (usually the property name) |
| | | * @param {Object[]} args The CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property. |
| | | * @param {Object} obj The scope object. For configuration handlers, this will usually equal the owner. |
| | | */ |
| | | YAHOO.widget.Overlay.prototype.configHeight = function(type, args, obj) { |
| | | var height = args[0]; |
| | | var el = this.element; |
| | | YAHOO.util.Dom.setStyle(el, "height", height); |
| | | this.cfg.refireEvent("iframe"); |
| | | }; |
| | | |
| | | /** |
| | | * The default event handler fired when the "width" property is changed. |
| | | * @method configWidth |
| | | * @param {String} type The CustomEvent type (usually the property name) |
| | | * @param {Object[]} args The CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property. |
| | | * @param {Object} obj The scope object. For configuration handlers, this will usually equal the owner. |
| | | */ |
| | | YAHOO.widget.Overlay.prototype.configWidth = function(type, args, obj) { |
| | | var width = args[0]; |
| | | var el = this.element; |
| | | YAHOO.util.Dom.setStyle(el, "width", width); |
| | | this.cfg.refireEvent("iframe"); |
| | | }; |
| | | |
| | | /** |
| | | * The default event handler fired when the "zIndex" property is changed. |
| | | * @method configzIndex |
| | | * @param {String} type The CustomEvent type (usually the property name) |
| | | * @param {Object[]} args The CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property. |
| | | * @param {Object} obj The scope object. For configuration handlers, this will usually equal the owner. |
| | | */ |
| | | YAHOO.widget.Overlay.prototype.configzIndex = function(type, args, obj) { |
| | | var zIndex = args[0]; |
| | | |
| | | var el = this.element; |
| | | |
| | | if (! zIndex) { |
| | | zIndex = YAHOO.util.Dom.getStyle(el, "zIndex"); |
| | | if (! zIndex || isNaN(zIndex)) { |
| | | zIndex = 0; |
| | | } |
| | | } |
| | | |
| | | if (this.iframe) { |
| | | if (zIndex <= 0) { |
| | | zIndex = 1; |
| | | } |
| | | YAHOO.util.Dom.setStyle(this.iframe, "zIndex", (zIndex-1)); |
| | | } |
| | | |
| | | YAHOO.util.Dom.setStyle(el, "zIndex", zIndex); |
| | | this.cfg.setProperty("zIndex", zIndex, true); |
| | | }; |
| | | |
| | | /** |
| | | * The default event handler fired when the "xy" property is changed. |
| | | * @method configXY |
| | | * @param {String} type The CustomEvent type (usually the property name) |
| | | * @param {Object[]} args The CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property. |
| | | * @param {Object} obj The scope object. For configuration handlers, this will usually equal the owner. |
| | | */ |
| | | YAHOO.widget.Overlay.prototype.configXY = function(type, args, obj) { |
| | | var pos = args[0]; |
| | | var x = pos[0]; |
| | | var y = pos[1]; |
| | | |
| | | this.cfg.setProperty("x", x); |
| | | this.cfg.setProperty("y", y); |
| | | |
| | | this.beforeMoveEvent.fire([x,y]); |
| | | |
| | | x = this.cfg.getProperty("x"); |
| | | y = this.cfg.getProperty("y"); |
| | | |
| | | YAHOO.log("xy: " + [x,y], "iframe"); |
| | | |
| | | this.cfg.refireEvent("iframe"); |
| | | this.moveEvent.fire([x,y]); |
| | | }; |
| | | |
| | | /** |
| | | * The default event handler fired when the "x" property is changed. |
| | | * @method configX |
| | | * @param {String} type The CustomEvent type (usually the property name) |
| | | * @param {Object[]} args The CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property. |
| | | * @param {Object} obj The scope object. For configuration handlers, this will usually equal the owner. |
| | | */ |
| | | YAHOO.widget.Overlay.prototype.configX = function(type, args, obj) { |
| | | var x = args[0]; |
| | | var y = this.cfg.getProperty("y"); |
| | | |
| | | this.cfg.setProperty("x", x, true); |
| | | this.cfg.setProperty("y", y, true); |
| | | |
| | | this.beforeMoveEvent.fire([x,y]); |
| | | |
| | | x = this.cfg.getProperty("x"); |
| | | y = this.cfg.getProperty("y"); |
| | | |
| | | YAHOO.util.Dom.setX(this.element, x, true); |
| | | |
| | | this.cfg.setProperty("xy", [x, y], true); |
| | | |
| | | this.cfg.refireEvent("iframe"); |
| | | this.moveEvent.fire([x, y]); |
| | | }; |
| | | |
| | | /** |
| | | * The default event handler fired when the "y" property is changed. |
| | | * @method configY |
| | | * @param {String} type The CustomEvent type (usually the property name) |
| | | * @param {Object[]} args The CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property. |
| | | * @param {Object} obj The scope object. For configuration handlers, this will usually equal the owner. |
| | | */ |
| | | YAHOO.widget.Overlay.prototype.configY = function(type, args, obj) { |
| | | var x = this.cfg.getProperty("x"); |
| | | var y = args[0]; |
| | | |
| | | this.cfg.setProperty("x", x, true); |
| | | this.cfg.setProperty("y", y, true); |
| | | |
| | | this.beforeMoveEvent.fire([x,y]); |
| | | |
| | | x = this.cfg.getProperty("x"); |
| | | y = this.cfg.getProperty("y"); |
| | | |
| | | YAHOO.util.Dom.setY(this.element, y, true); |
| | | |
| | | this.cfg.setProperty("xy", [x, y], true); |
| | | |
| | | this.cfg.refireEvent("iframe"); |
| | | this.moveEvent.fire([x, y]); |
| | | }; |
| | | |
| | | /** |
| | | * Shows the iframe shim, if it has been enabled |
| | | * @method showIframe |
| | | */ |
| | | YAHOO.widget.Overlay.prototype.showIframe = function() { |
| | | if (this.iframe) { |
| | | this.iframe.style.display = "block"; |
| | | } |
| | | }; |
| | | |
| | | /** |
| | | * Hides the iframe shim, if it has been enabled |
| | | * @method hideIframe |
| | | */ |
| | | YAHOO.widget.Overlay.prototype.hideIframe = function() { |
| | | if (this.iframe) { |
| | | this.iframe.style.display = "none"; |
| | | } |
| | | }; |
| | | |
| | | /** |
| | | * The default event handler fired when the "iframe" property is changed. |
| | | * @method configIframe |
| | | * @param {String} type The CustomEvent type (usually the property name) |
| | | * @param {Object[]} args The CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property. |
| | | * @param {Object} obj The scope object. For configuration handlers, this will usually equal the owner. |
| | | */ |
| | | YAHOO.widget.Overlay.prototype.configIframe = function(type, args, obj) { |
| | | |
| | | var val = args[0]; |
| | | |
| | | if (val) { // IFRAME shim is enabled |
| | | |
| | | if (! YAHOO.util.Config.alreadySubscribed(this.showEvent, this.showIframe, this)) { |
| | | this.showEvent.subscribe(this.showIframe, this, true); |
| | | } |
| | | if (! YAHOO.util.Config.alreadySubscribed(this.hideEvent, this.hideIframe, this)) { |
| | | this.hideEvent.subscribe(this.hideIframe, this, true); |
| | | } |
| | | |
| | | var x = this.cfg.getProperty("x"); |
| | | var y = this.cfg.getProperty("y"); |
| | | |
| | | if (! x || ! y) { |
| | | this.syncPosition(); |
| | | x = this.cfg.getProperty("x"); |
| | | y = this.cfg.getProperty("y"); |
| | | } |
| | | |
| | | YAHOO.log("iframe positioning to: " + [x,y], "iframe"); |
| | | |
| | | if (! isNaN(x) && ! isNaN(y)) { |
| | | if (! this.iframe) { |
| | | this.iframe = document.createElement("iframe"); |
| | | if (this.isSecure) { |
| | | this.iframe.src = YAHOO.widget.Overlay.IFRAME_SRC; |
| | | } |
| | | |
| | | var parent = this.element.parentNode; |
| | | if (parent) { |
| | | parent.appendChild(this.iframe); |
| | | } else { |
| | | document.body.appendChild(this.iframe); |
| | | } |
| | | |
| | | YAHOO.util.Dom.setStyle(this.iframe, "position", "absolute"); |
| | | YAHOO.util.Dom.setStyle(this.iframe, "border", "none"); |
| | | YAHOO.util.Dom.setStyle(this.iframe, "margin", "0"); |
| | | YAHOO.util.Dom.setStyle(this.iframe, "padding", "0"); |
| | | YAHOO.util.Dom.setStyle(this.iframe, "opacity", "0"); |
| | | if (this.cfg.getProperty("visible")) { |
| | | this.showIframe(); |
| | | } else { |
| | | this.hideIframe(); |
| | | } |
| | | } |
| | | |
| | | var iframeDisplay = YAHOO.util.Dom.getStyle(this.iframe, "display"); |
| | | |
| | | if (iframeDisplay == "none") { |
| | | this.iframe.style.display = "block"; |
| | | } |
| | | |
| | | YAHOO.util.Dom.setXY(this.iframe, [x,y]); |
| | | |
| | | var width = this.element.clientWidth; |
| | | var height = this.element.clientHeight; |
| | | |
| | | YAHOO.util.Dom.setStyle(this.iframe, "width", (width+2) + "px"); |
| | | YAHOO.util.Dom.setStyle(this.iframe, "height", (height+2) + "px"); |
| | | |
| | | if (iframeDisplay == "none") { |
| | | this.iframe.style.display = "none"; |
| | | } |
| | | } |
| | | } else { |
| | | if (this.iframe) { |
| | | this.iframe.style.display = "none"; |
| | | } |
| | | this.showEvent.unsubscribe(this.showIframe, this); |
| | | this.hideEvent.unsubscribe(this.hideIframe, this); |
| | | } |
| | | }; |
| | | |
| | | |
| | | /** |
| | | * The default event handler fired when the "constraintoviewport" property is changed. |
| | | * @method configConstrainToViewport |
| | | * @param {String} type The CustomEvent type (usually the property name) |
| | | * @param {Object[]} args The CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property. |
| | | * @param {Object} obj The scope object. For configuration handlers, this will usually equal the owner. |
| | | */ |
| | | YAHOO.widget.Overlay.prototype.configConstrainToViewport = function(type, args, obj) { |
| | | var val = args[0]; |
| | | if (val) { |
| | | if (! YAHOO.util.Config.alreadySubscribed(this.beforeMoveEvent, this.enforceConstraints, this)) { |
| | | this.beforeMoveEvent.subscribe(this.enforceConstraints, this, true); |
| | | } |
| | | } else { |
| | | this.beforeMoveEvent.unsubscribe(this.enforceConstraints, this); |
| | | } |
| | | }; |
| | | |
| | | /** |
| | | * The default event handler fired when the "context" property is changed. |
| | | * @method configContext |
| | | * @param {String} type The CustomEvent type (usually the property name) |
| | | * @param {Object[]} args The CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property. |
| | | * @param {Object} obj The scope object. For configuration handlers, this will usually equal the owner. |
| | | */ |
| | | YAHOO.widget.Overlay.prototype.configContext = function(type, args, obj) { |
| | | var contextArgs = args[0]; |
| | | |
| | | if (contextArgs) { |
| | | var contextEl = contextArgs[0]; |
| | | var elementMagnetCorner = contextArgs[1]; |
| | | var contextMagnetCorner = contextArgs[2]; |
| | | |
| | | if (contextEl) { |
| | | if (typeof contextEl == "string") { |
| | | this.cfg.setProperty("context", [document.getElementById(contextEl),elementMagnetCorner,contextMagnetCorner], true); |
| | | } |
| | | |
| | | if (elementMagnetCorner && contextMagnetCorner) { |
| | | this.align(elementMagnetCorner, contextMagnetCorner); |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | |
| | | |
| | | // END BUILT-IN PROPERTY EVENT HANDLERS // |
| | | |
| | | /** |
| | | * Aligns the Overlay to its context element using the specified corner points (represented by the constants TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, and BOTTOM_RIGHT. |
| | | * @method align |
| | | * @param {String} elementAlign The String representing the corner of the Overlay that should be aligned to the context element |
| | | * @param {String} contextAlign The corner of the context element that the elementAlign corner should stick to. |
| | | */ |
| | | YAHOO.widget.Overlay.prototype.align = function(elementAlign, contextAlign) { |
| | | var contextArgs = this.cfg.getProperty("context"); |
| | | if (contextArgs) { |
| | | var context = contextArgs[0]; |
| | | |
| | | var element = this.element; |
| | | var me = this; |
| | | |
| | | if (! elementAlign) { |
| | | elementAlign = contextArgs[1]; |
| | | } |
| | | |
| | | if (! contextAlign) { |
| | | contextAlign = contextArgs[2]; |
| | | } |
| | | |
| | | if (element && context) { |
| | | var contextRegion = YAHOO.util.Dom.getRegion(context); |
| | | |
| | | var doAlign = function(v,h) { |
| | | switch (elementAlign) { |
| | | case YAHOO.widget.Overlay.TOP_LEFT: |
| | | me.moveTo(h,v); |
| | | break; |
| | | case YAHOO.widget.Overlay.TOP_RIGHT: |
| | | me.moveTo(h-element.offsetWidth,v); |
| | | break; |
| | | case YAHOO.widget.Overlay.BOTTOM_LEFT: |
| | | me.moveTo(h,v-element.offsetHeight); |
| | | break; |
| | | case YAHOO.widget.Overlay.BOTTOM_RIGHT: |
| | | me.moveTo(h-element.offsetWidth,v-element.offsetHeight); |
| | | break; |
| | | } |
| | | }; |
| | | |
| | | switch (contextAlign) { |
| | | case YAHOO.widget.Overlay.TOP_LEFT: |
| | | doAlign(contextRegion.top, contextRegion.left); |
| | | break; |
| | | case YAHOO.widget.Overlay.TOP_RIGHT: |
| | | doAlign(contextRegion.top, contextRegion.right); |
| | | break; |
| | | case YAHOO.widget.Overlay.BOTTOM_LEFT: |
| | | doAlign(contextRegion.bottom, contextRegion.left); |
| | | break; |
| | | case YAHOO.widget.Overlay.BOTTOM_RIGHT: |
| | | doAlign(contextRegion.bottom, contextRegion.right); |
| | | break; |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | |
| | | /** |
| | | * The default event handler executed when the moveEvent is fired, if the "constraintoviewport" is set to true. |
| | | * @method enforceConstraints |
| | | * @param {String} type The CustomEvent type (usually the property name) |
| | | * @param {Object[]} args The CustomEvent arguments. For configuration handlers, args[0] will equal the newly applied value for the property. |
| | | * @param {Object} obj The scope object. For configuration handlers, this will usually equal the owner. |
| | | */ |
| | | YAHOO.widget.Overlay.prototype.enforceConstraints = function(type, args, obj) { |
| | | var pos = args[0]; |
| | | |
| | | var x = pos[0]; |
| | | var y = pos[1]; |
| | | |
| | | var offsetHeight = this.element.offsetHeight; |
| | | var offsetWidth = this.element.offsetWidth; |
| | | |
| | | var viewPortWidth = YAHOO.util.Dom.getViewportWidth(); |
| | | var viewPortHeight = YAHOO.util.Dom.getViewportHeight(); |
| | | |
| | | var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft; |
| | | var scrollY = document.documentElement.scrollTop || document.body.scrollTop; |
| | | |
| | | var topConstraint = scrollY + 10; |
| | | var leftConstraint = scrollX + 10; |
| | | var bottomConstraint = scrollY + viewPortHeight - offsetHeight - 10; |
| | | var rightConstraint = scrollX + viewPortWidth - offsetWidth - 10; |
| | | |
| | | if (x < leftConstraint) { |
| | | x = leftConstraint; |
| | | } else if (x > rightConstraint) { |
| | | x = rightConstraint; |
| | | } |
| | | |
| | | if (y < topConstraint) { |
| | | y = topConstraint; |
| | | } else if (y > bottomConstraint) { |
| | | y = bottomConstraint; |
| | | } |
| | | |
| | | this.cfg.setProperty("x", x, true); |
| | | this.cfg.setProperty("y", y, true); |
| | | this.cfg.setProperty("xy", [x,y], true); |
| | | }; |
| | | |
| | | /** |
| | | * Centers the container in the viewport. |
| | | * @method center |
| | | */ |
| | | YAHOO.widget.Overlay.prototype.center = function() { |
| | | var scrollX = document.documentElement.scrollLeft || document.body.scrollLeft; |
| | | var scrollY = document.documentElement.scrollTop || document.body.scrollTop; |
| | | |
| | | var viewPortWidth = YAHOO.util.Dom.getClientWidth(); |
| | | var viewPortHeight = YAHOO.util.Dom.getClientHeight(); |
| | | |
| | | var elementWidth = this.element.offsetWidth; |
| | | var elementHeight = this.element.offsetHeight; |
| | | |
| | | var x = (viewPortWidth / 2) - (elementWidth / 2) + scrollX; |
| | | var y = (viewPortHeight / 2) - (elementHeight / 2) + scrollY; |
| | | |
| | | this.cfg.setProperty("xy", [parseInt(x, 10), parseInt(y, 10)]); |
| | | |
| | | this.cfg.refireEvent("iframe"); |
| | | }; |
| | | |
| | | /** |
| | | * Synchronizes the Panel's "xy", "x", and "y" properties with the Panel's position in the DOM. This is primarily used to update position information during drag & drop. |
| | | * @method syncPosition |
| | | */ |
| | | YAHOO.widget.Overlay.prototype.syncPosition = function() { |
| | | var pos = YAHOO.util.Dom.getXY(this.element); |
| | | this.cfg.setProperty("x", pos[0], true); |
| | | this.cfg.setProperty("y", pos[1], true); |
| | | this.cfg.setProperty("xy", pos, true); |
| | | }; |
| | | |
| | | /** |
| | | * Event handler fired when the resize monitor element is resized. |
| | | * @method onDomResize |
| | | * @param {DOMEvent} e The resize DOM event |
| | | * @param {Object} obj The scope object |
| | | */ |
| | | YAHOO.widget.Overlay.prototype.onDomResize = function(e, obj) { |
| | | YAHOO.widget.Overlay.superclass.onDomResize.call(this, e, obj); |
| | | var me = this; |
| | | setTimeout(function() { |
| | | me.syncPosition(); |
| | | me.cfg.refireEvent("iframe"); |
| | | me.cfg.refireEvent("context"); |
| | | }, 0); |
| | | }; |
| | | |
| | | /** |
| | | * Removes the Overlay element from the DOM and sets all child elements to null. |
| | | * @method destroy |
| | | */ |
| | | YAHOO.widget.Overlay.prototype.destroy = function() { |
| | | if (this.iframe) { |
| | | this.iframe.parentNode.removeChild(this.iframe); |
| | | } |
| | | |
| | | this.iframe = null; |
| | | |
| | | YAHOO.widget.Overlay.windowResizeEvent.unsubscribe(this.doCenterOnDOMEvent, this); |
| | | YAHOO.widget.Overlay.windowScrollEvent.unsubscribe(this.doCenterOnDOMEvent, this); |
| | | |
| | | YAHOO.widget.Overlay.superclass.destroy.call(this); |
| | | }; |
| | | |
| | | /** |
| | | * Returns a String representation of the object. |
| | | * @method toString |
| | | * @return {String} The string representation of the Overlay. |
| | | */ |
| | | YAHOO.widget.Overlay.prototype.toString = function() { |
| | | return "Overlay " + this.id; |
| | | }; |
| | | |
| | | /** |
| | | * A singleton CustomEvent used for reacting to the DOM event for window scroll |
| | | * @event YAHOO.widget.Overlay.windowScrollEvent |
| | | */ |
| | | YAHOO.widget.Overlay.windowScrollEvent = new YAHOO.util.CustomEvent("windowScroll"); |
| | | |
| | | /** |
| | | * A singleton CustomEvent used for reacting to the DOM event for window resize |
| | | * @event YAHOO.widget.Overlay.windowResizeEvent |
| | | */ |
| | | YAHOO.widget.Overlay.windowResizeEvent = new YAHOO.util.CustomEvent("windowResize"); |
| | | |
| | | /** |
| | | * The DOM event handler used to fire the CustomEvent for window scroll |
| | | * @method YAHOO.widget.Overlay.windowScrollHandler |
| | | * @static |
| | | * @param {DOMEvent} e The DOM scroll event |
| | | */ |
| | | YAHOO.widget.Overlay.windowScrollHandler = function(e) { |
| | | if (YAHOO.widget.Module.prototype.browser == "ie" || YAHOO.widget.Module.prototype.browser == "ie7") { |
| | | if (! window.scrollEnd) { |
| | | window.scrollEnd = -1; |
| | | } |
| | | clearTimeout(window.scrollEnd); |
| | | window.scrollEnd = setTimeout(function() { YAHOO.widget.Overlay.windowScrollEvent.fire(); }, 1); |
| | | } else { |
| | | YAHOO.widget.Overlay.windowScrollEvent.fire(); |
| | | } |
| | | }; |
| | | |
| | | /** |
| | | * The DOM event handler used to fire the CustomEvent for window resize |
| | | * @method YAHOO.widget.Overlay.windowResizeHandler |
| | | * @static |
| | | * @param {DOMEvent} e The DOM resize event |
| | | */ |
| | | YAHOO.widget.Overlay.windowResizeHandler = function(e) { |
| | | if (YAHOO.widget.Module.prototype.browser == "ie" || YAHOO.widget.Module.prototype.browser == "ie7") { |
| | | if (! window.resizeEnd) { |
| | | window.resizeEnd = -1; |
| | | } |
| | | clearTimeout(window.resizeEnd); |
| | | window.resizeEnd = setTimeout(function() { YAHOO.widget.Overlay.windowResizeEvent.fire(); }, 100); |
| | | } else { |
| | | YAHOO.widget.Overlay.windowResizeEvent.fire(); |
| | | } |
| | | }; |
| | | |
| | | /** |
| | | * A boolean that indicated whether the window resize and scroll events have already been subscribed to. |
| | | * @property YAHOO.widget.Overlay._initialized |
| | | * @private |
| | | * @type Boolean |
| | | */ |
| | | YAHOO.widget.Overlay._initialized = null; |
| | | |
| | | if (YAHOO.widget.Overlay._initialized === null) { |
| | | YAHOO.util.Event.addListener(window, "scroll", YAHOO.widget.Overlay.windowScrollHandler); |
| | | YAHOO.util.Event.addListener(window, "resize", YAHOO.widget.Overlay.windowResizeHandler); |
| | | |
| | | YAHOO.widget.Overlay._initialized = true; |
| | | } |
| | | |
| | | /** |
| | | * OverlayManager is used for maintaining the focus status of multiple Overlays.* @namespace YAHOO.widget |
| | | * @namespace YAHOO.widget |
| | | * @class OverlayManager |
| | | * @constructor |
| | | * @param {Array} overlays Optional. A collection of Overlays to register with the manager. |
| | | * @param {Object} userConfig The object literal representing the user configuration of the OverlayManager |
| | | */ |
| | | YAHOO.widget.OverlayManager = function(userConfig) { |
| | | this.init(userConfig); |
| | | }; |
| | | |
| | | /** |
| | | * The CSS class representing a focused Overlay |
| | | * @property YAHOO.widget.OverlayManager.CSS_FOCUSED |
| | | * @static |
| | | * @final |
| | | * @type String |
| | | */ |
| | | YAHOO.widget.OverlayManager.CSS_FOCUSED = "focused"; |
| | | |
| | | YAHOO.widget.OverlayManager.prototype = { |
| | | /** |
| | | * The class's constructor function |
| | | * @property contructor |
| | | * @type Function |
| | | */ |
| | | constructor : YAHOO.widget.OverlayManager, |
| | | |
| | | /** |
| | | * The array of Overlays that are currently registered |
| | | * @property overlays |
| | | * @type YAHOO.widget.Overlay[] |
| | | */ |
| | | overlays : null, |
| | | |
| | | /** |
| | | * Initializes the default configuration of the OverlayManager |
| | | * @method initDefaultConfig |
| | | */ |
| | | initDefaultConfig : function() { |
| | | /** |
| | | * The collection of registered Overlays in use by the OverlayManager |
| | | * @config overlays |
| | | * @type YAHOO.widget.Overlay[] |
| | | * @default null |
| | | */ |
| | | this.cfg.addProperty("overlays", { suppressEvent:true } ); |
| | | |
| | | /** |
| | | * The default DOM event that should be used to focus an Overlay |
| | | * @config focusevent |
| | | * @type String |
| | | * @default "mousedown" |
| | | */ |
| | | this.cfg.addProperty("focusevent", { value:"mousedown" } ); |
| | | }, |
| | | |
| | | /** |
| | | * Initializes the OverlayManager |
| | | * @method init |
| | | * @param {YAHOO.widget.Overlay[]} overlays Optional. A collection of Overlays to register with the manager. |
| | | * @param {Object} userConfig The object literal representing the user configuration of the OverlayManager |
| | | */ |
| | | init : function(userConfig) { |
| | | /** |
| | | * The OverlayManager's Config object used for monitoring configuration properties. |
| | | * @property cfg |
| | | * @type YAHOO.util.Config |
| | | */ |
| | | this.cfg = new YAHOO.util.Config(this); |
| | | |
| | | this.initDefaultConfig(); |
| | | |
| | | if (userConfig) { |
| | | this.cfg.applyConfig(userConfig, true); |
| | | } |
| | | this.cfg.fireQueue(); |
| | | |
| | | /** |
| | | * The currently activated Overlay |
| | | * @property activeOverlay |
| | | * @private |
| | | * @type YAHOO.widget.Overlay |
| | | */ |
| | | var activeOverlay = null; |
| | | |
| | | /** |
| | | * Returns the currently focused Overlay |
| | | * @method getActive |
| | | * @return {YAHOO.widget.Overlay} The currently focused Overlay |
| | | */ |
| | | this.getActive = function() { |
| | | return activeOverlay; |
| | | }; |
| | | |
| | | /** |
| | | * Focuses the specified Overlay |
| | | * @method focus |
| | | * @param {YAHOO.widget.Overlay} overlay The Overlay to focus |
| | | * @param {String} overlay The id of the Overlay to focus |
| | | */ |
| | | this.focus = function(overlay) { |
| | | var o = this.find(overlay); |
| | | if (o) { |
| | | this.blurAll(); |
| | | activeOverlay = o; |
| | | YAHOO.util.Dom.addClass(activeOverlay.element, YAHOO.widget.OverlayManager.CSS_FOCUSED); |
| | | this.overlays.sort(this.compareZIndexDesc); |
| | | var topZIndex = YAHOO.util.Dom.getStyle(this.overlays[0].element, "zIndex"); |
| | | if (! isNaN(topZIndex) && this.overlays[0] != overlay) { |
| | | activeOverlay.cfg.setProperty("zIndex", (parseInt(topZIndex, 10) + 2)); |
| | | } |
| | | this.overlays.sort(this.compareZIndexDesc); |
| | | } |
| | | }; |
| | | |
| | | /** |
| | | * Removes the specified Overlay from the manager |
| | | * @method remove |
| | | * @param {YAHOO.widget.Overlay} overlay The Overlay to remove |
| | | * @param {String} overlay The id of the Overlay to remove |
| | | */ |
| | | this.remove = function(overlay) { |
| | | var o = this.find(overlay); |
| | | if (o) { |
| | | var originalZ = YAHOO.util.Dom.getStyle(o.element, "zIndex"); |
| | | o.cfg.setProperty("zIndex", -1000, true); |
| | | this.overlays.sort(this.compareZIndexDesc); |
| | | this.overlays = this.overlays.slice(0, this.overlays.length-1); |
| | | o.cfg.setProperty("zIndex", originalZ, true); |
| | | |
| | | o.cfg.setProperty("manager", null); |
| | | o.focusEvent = null; |
| | | o.blurEvent = null; |
| | | o.focus = null; |
| | | o.blur = null; |
| | | } |
| | | }; |
| | | |
| | | /** |
| | | * Removes focus from all registered Overlays in the manager |
| | | * @method blurAll |
| | | */ |
| | | this.blurAll = function() { |
| | | activeOverlay = null; |
| | | for (var o=0;o<this.overlays.length;o++) { |
| | | YAHOO.util.Dom.removeClass(this.overlays[o].element, YAHOO.widget.OverlayManager.CSS_FOCUSED); |
| | | } |
| | | }; |
| | | |
| | | var overlays = this.cfg.getProperty("overlays"); |
| | | |
| | | if (! this.overlays) { |
| | | this.overlays = []; |
| | | } |
| | | |
| | | if (overlays) { |
| | | this.register(overlays); |
| | | this.overlays.sort(this.compareZIndexDesc); |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * Registers an Overlay or an array of Overlays with the manager. Upon registration, the Overlay receives functions for focus and blur, along with CustomEvents for each. |
| | | * @method register |
| | | * @param {YAHOO.widget.Overlay} overlay An Overlay to register with the manager. |
| | | * @param {YAHOO.widget.Overlay[]} overlay An array of Overlays to register with the manager. |
| | | * @return {Boolean} True if any Overlays are registered. |
| | | */ |
| | | register : function(overlay) { |
| | | if (overlay instanceof YAHOO.widget.Overlay) { |
| | | overlay.cfg.addProperty("manager", { value:this } ); |
| | | |
| | | overlay.focusEvent = new YAHOO.util.CustomEvent("focus"); |
| | | overlay.blurEvent = new YAHOO.util.CustomEvent("blur"); |
| | | |
| | | var mgr=this; |
| | | |
| | | overlay.focus = function() { |
| | | mgr.focus(this); |
| | | this.focusEvent.fire(); |
| | | }; |
| | | |
| | | overlay.blur = function() { |
| | | mgr.blurAll(); |
| | | this.blurEvent.fire(); |
| | | }; |
| | | |
| | | var focusOnDomEvent = function(e,obj) { |
| | | overlay.focus(); |
| | | }; |
| | | |
| | | var focusevent = this.cfg.getProperty("focusevent"); |
| | | YAHOO.util.Event.addListener(overlay.element,focusevent,focusOnDomEvent,this,true); |
| | | |
| | | var zIndex = YAHOO.util.Dom.getStyle(overlay.element, "zIndex"); |
| | | if (! isNaN(zIndex)) { |
| | | overlay.cfg.setProperty("zIndex", parseInt(zIndex, 10)); |
| | | } else { |
| | | overlay.cfg.setProperty("zIndex", 0); |
| | | } |
| | | |
| | | this.overlays.push(overlay); |
| | | return true; |
| | | } else if (overlay instanceof Array) { |
| | | var regcount = 0; |
| | | for (var i=0;i<overlay.length;i++) { |
| | | if (this.register(overlay[i])) { |
| | | regcount++; |
| | | } |
| | | } |
| | | if (regcount > 0) { |
| | | return true; |
| | | } |
| | | } else { |
| | | return false; |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * Attempts to locate an Overlay by instance or ID. |
| | | * @method find |
| | | * @param {YAHOO.widget.Overlay} overlay An Overlay to locate within the manager |
| | | * @param {String} overlay An Overlay id to locate within the manager |
| | | * @return {YAHOO.widget.Overlay} The requested Overlay, if found, or null if it cannot be located. |
| | | */ |
| | | find : function(overlay) { |
| | | if (overlay instanceof YAHOO.widget.Overlay) { |
| | | for (var o=0;o<this.overlays.length;o++) { |
| | | if (this.overlays[o] == overlay) { |
| | | return this.overlays[o]; |
| | | } |
| | | } |
| | | } else if (typeof overlay == "string") { |
| | | for (var p=0;p<this.overlays.length;p++) { |
| | | if (this.overlays[p].id == overlay) { |
| | | return this.overlays[p]; |
| | | } |
| | | } |
| | | } |
| | | return null; |
| | | }, |
| | | |
| | | /** |
| | | * Used for sorting the manager's Overlays by z-index. |
| | | * @method compareZIndexDesc |
| | | * @private |
| | | * @return {Number} 0, 1, or -1, depending on where the Overlay should fall in the stacking order. |
| | | */ |
| | | compareZIndexDesc : function(o1, o2) { |
| | | var zIndex1 = o1.cfg.getProperty("zIndex"); |
| | | var zIndex2 = o2.cfg.getProperty("zIndex"); |
| | | |
| | | if (zIndex1 > zIndex2) { |
| | | return -1; |
| | | } else if (zIndex1 < zIndex2) { |
| | | return 1; |
| | | } else { |
| | | return 0; |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * Shows all Overlays in the manager. |
| | | * @method showAll |
| | | */ |
| | | showAll : function() { |
| | | for (var o=0;o<this.overlays.length;o++) { |
| | | this.overlays[o].show(); |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * Hides all Overlays in the manager. |
| | | * @method hideAll |
| | | */ |
| | | hideAll : function() { |
| | | for (var o=0;o<this.overlays.length;o++) { |
| | | this.overlays[o].hide(); |
| | | } |
| | | }, |
| | | |
| | | /** |
| | | * Returns a string representation of the object. |
| | | * @method toString |
| | | * @return {String} The string representation of the OverlayManager |
| | | */ |
| | | toString : function() { |
| | | return "OverlayManager"; |
| | | } |
| | | |
| | | }; |
| | | |
| | | /** |
| | | * KeyListener is a utility that provides an easy interface for listening for keydown/keyup events fired against DOM elements. |
| | | * @namespace YAHOO.util |
| | | * @class KeyListener |
| | | * @constructor |
| | | * @param {HTMLElement} attachTo The element or element ID to which the key event should be attached |
| | | * @param {String} attachTo The element or element ID to which the key event should be attached |
| | | * @param {Object} keyData The object literal representing the key(s) to detect. Possible attributes are shift(boolean), alt(boolean), ctrl(boolean) and keys(either an int or an array of ints representing keycodes). |
| | | * @param {Function} handler The CustomEvent handler to fire when the key event is detected |
| | | * @param {Object} handler An object literal representing the handler. |
| | | * @param {String} event Optional. The event (keydown or keyup) to listen for. Defaults automatically to keydown. |
| | | */ |
| | | YAHOO.util.KeyListener = function(attachTo, keyData, handler, event) { |
| | | if (! attachTo) { |
| | | YAHOO.log("No attachTo element specified", "error"); |
| | | } |
| | | if (! keyData) { |
| | | YAHOO.log("No keyData specified", "error"); |
| | | } |
| | | if (! handler) { |
| | | YAHOO.log("No handler specified", "error"); |
| | | } |
| | | |
| | | if (! event) { |
| | | event = YAHOO.util.KeyListener.KEYDOWN; |
| | | } |
| | | |
| | | /** |
| | | * The CustomEvent fired internally when a key is pressed |
| | | * @event keyEvent |
| | | * @private |
| | | * @param {Object} keyData The object literal representing the key(s) to detect. Possible attributes are shift(boolean), alt(boolean), ctrl(boolean) and keys(either an int or an array of ints representing keycodes). |
| | | */ |
| | | var keyEvent = new YAHOO.util.CustomEvent("keyPressed"); |
| | | |
| | | /** |
| | | * The CustomEvent fired when the KeyListener is enabled via the enable() function |
| | | * @event enabledEvent |
| | | * @param {Object} keyData The object literal representing the key(s) to detect. Possible attributes are shift(boolean), alt(boolean), ctrl(boolean) and keys(either an int or an array of ints representing keycodes). |
| | | */ |
| | | this.enabledEvent = new YAHOO.util.CustomEvent("enabled"); |
| | | |
| | | /** |
| | | * The CustomEvent fired when the KeyListener is disabled via the disable() function |
| | | * @event disabledEvent |
| | | * @param {Object} keyData The object literal representing the key(s) to detect. Possible attributes are shift(boolean), alt(boolean), ctrl(boolean) and keys(either an int or an array of ints representing keycodes). |
| | | */ |
| | | this.disabledEvent = new YAHOO.util.CustomEvent("disabled"); |
| | | |
| | | if (typeof attachTo == 'string') { |
| | | attachTo = document.getElementById(attachTo); |
| | | } |
| | | |
| | | if (typeof handler == 'function') { |
| | | keyEvent.subscribe(handler); |
| | | } else { |
| | | keyEvent.subscribe(handler.fn, handler.scope, handler.correctScope); |
| | | } |
| | | |
| | | /** |
| | | * Handles the key event when a key is pressed. |
| | | * @method handleKeyPress |
| | | * @param {DOMEvent} e The keypress DOM event |
| | | * @param {Object} obj The DOM event scope object |
| | | * @private |
| | | */ |
| | | function handleKeyPress(e, obj) { |
| | | if (! keyData.shift) { |
| | | keyData.shift = false; |
| | | } |
| | | if (! keyData.alt) { |
| | | keyData.alt = false; |
| | | } |
| | | if (! keyData.ctrl) { |
| | | keyData.ctrl = false; |
| | | } |
| | | |
| | | // check held down modifying keys first |
| | | if (e.shiftKey == keyData.shift && |
| | | e.altKey == keyData.alt && |
| | | e.ctrlKey == keyData.ctrl) { // if we pass this, all modifiers match |
| | | |
| | | var dataItem; |
| | | var keyPressed; |
| | | |
| | | if (keyData.keys instanceof Array) { |
| | | for (var i=0;i<keyData.keys.length;i++) { |
| | | dataItem = keyData.keys[i]; |
| | | |
| | | if (dataItem == e.charCode ) { |
| | | keyEvent.fire(e.charCode, e); |
| | | break; |
| | | } else if (dataItem == e.keyCode) { |
| | | keyEvent.fire(e.keyCode, e); |
| | | break; |
| | | } |
| | | } |
| | | } else { |
| | | dataItem = keyData.keys; |
| | | if (dataItem == e.charCode ) { |
| | | keyEvent.fire(e.charCode, e); |
| | | } else if (dataItem == e.keyCode) { |
| | | keyEvent.fire(e.keyCode, e); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Enables the KeyListener by attaching the DOM event listeners to the target DOM element |
| | | * @method enable |
| | | */ |
| | | this.enable = function() { |
| | | if (! this.enabled) { |
| | | YAHOO.util.Event.addListener(attachTo, event, handleKeyPress); |
| | | this.enabledEvent.fire(keyData); |
| | | } |
| | | /** |
| | | * Boolean indicating the enabled/disabled state of the Tooltip |
| | | * @property enabled |
| | | * @type Boolean |
| | | */ |
| | | this.enabled = true; |
| | | }; |
| | | |
| | | /** |
| | | * Disables the KeyListener by removing the DOM event listeners from the target DOM element |
| | | * @method disable |
| | | */ |
| | | this.disable = function() { |
| | | if (this.enabled) { |
| | | YAHOO.util.Event.removeListener(attachTo, event, handleKeyPress); |
| | | this.disabledEvent.fire(keyData); |
| | | } |
| | | this.enabled = false; |
| | | }; |
| | | |
| | | /** |
| | | * Returns a String representation of the object. |
| | | * @method toString |
| | | * @return {String} The string representation of the KeyListener |
| | | */ |
| | | this.toString = function() { |
| | | return "KeyListener [" + keyData.keys + "] " + attachTo.tagName + (attachTo.id ? "[" + attachTo.id + "]" : ""); |
| | | }; |
| | | |
| | | }; |
| | | |
| | | /** |
| | | * Constant representing the DOM "keydown" event. |
| | | * @property YAHOO.util.KeyListener.KEYDOWN |
| | | * @static |
| | | * @final |
| | | * @type String |
| | | */ |
| | | YAHOO.util.KeyListener.KEYDOWN = "keydown"; |
| | | |
| | | /** |
| | | * Constant representing the DOM "keyup" event. |
| | | * @property YAHOO.util.KeyListener.KEYUP |
| | | * @static |
| | | * @final |
| | | * @type String |
| | | */ |
| | | YAHOO.util.KeyListener.KEYUP = "keyup"; |
| | | |
| | | /** |
| | | * ContainerEffect encapsulates animation transitions that are executed when an Overlay is shown or hidden. |
| | | * @namespace YAHOO.widget |
| | | * @class ContainerEffect |
| | | * @constructor |
| | | * @param {YAHOO.widget.Overlay} overlay The Overlay that the animation should be associated with |
| | | * @param {Object} attrIn The object literal representing the animation arguments to be used for the animate-in transition. The arguments for this literal are: attributes(object, see YAHOO.util.Anim for description), duration(Number), and method(i.e. YAHOO.util.Easing.easeIn). |
| | | * @param {Object} attrOut The object literal representing the animation arguments to be used for the animate-out transition. The arguments for this literal are: attributes(object, see YAHOO.util.Anim for description), duration(Number), and method(i.e. YAHOO.util.Easing.easeIn). |
| | | * @param {HTMLElement} targetElement Optional. The target element that should be animated during the transition. Defaults to overlay.element. |
| | | * @param {class} Optional. The animation class to instantiate. Defaults to YAHOO.util.Anim. Other options include YAHOO.util.Motion. |
| | | */ |
| | | YAHOO.widget.ContainerEffect = function(overlay, attrIn, attrOut, targetElement, animClass) { |
| | | if (! animClass) { |
| | | animClass = YAHOO.util.Anim; |
| | | } |
| | | |
| | | /** |
| | | * The overlay to animate |
| | | * @property overlay |
| | | * @type YAHOO.widget.Overlay |
| | | */ |
| | | this.overlay = overlay; |
| | | /** |
| | | * The animation attributes to use when transitioning into view |
| | | * @property attrIn |
| | | * @type Object |
| | | */ |
| | | this.attrIn = attrIn; |
| | | /** |
| | | * The animation attributes to use when transitioning out of view |
| | | * @property attrOut |
| | | * @type Object |
| | | */ |
| | | this.attrOut = attrOut; |
| | | /** |
| | | * The target element to be animated |
| | | * @property targetElement |
| | | * @type HTMLElement |
| | | */ |
| | | this.targetElement = targetElement || overlay.element; |
| | | /** |
| | | * The animation class to use for animating the overlay |
| | | * @property animClass |
| | | * @type class |
| | | */ |
| | | this.animClass = animClass; |
| | | }; |
| | | |
| | | /** |
| | | * Initializes the animation classes and events. |
| | | * @method init |
| | | */ |
| | | YAHOO.widget.ContainerEffect.prototype.init = function() { |
| | | this.beforeAnimateInEvent = new YAHOO.util.CustomEvent("beforeAnimateIn"); |
| | | this.beforeAnimateOutEvent = new YAHOO.util.CustomEvent("beforeAnimateOut"); |
| | | |
| | | this.animateInCompleteEvent = new YAHOO.util.CustomEvent("animateInComplete"); |
| | | this.animateOutCompleteEvent = new YAHOO.util.CustomEvent("animateOutComplete"); |
| | | |
| | | this.animIn = new this.animClass(this.targetElement, this.attrIn.attributes, this.attrIn.duration, this.attrIn.method); |
| | | this.animIn.onStart.subscribe(this.handleStartAnimateIn, this); |
| | | this.animIn.onTween.subscribe(this.handleTweenAnimateIn, this); |
| | | this.animIn.onComplete.subscribe(this.handleCompleteAnimateIn, this); |
| | | |
| | | this.animOut = new this.animClass(this.targetElement, this.attrOut.attributes, this.attrOut.duration, this.attrOut.method); |
| | | this.animOut.onStart.subscribe(this.handleStartAnimateOut, this); |
| | | this.animOut.onTween.subscribe(this.handleTweenAnimateOut, this); |
| | | this.animOut.onComplete.subscribe(this.handleCompleteAnimateOut, this); |
| | | }; |
| | | |
| | | /** |
| | | * Triggers the in-animation. |
| | | * @method animateIn |
| | | */ |
| | | YAHOO.widget.ContainerEffect.prototype.animateIn = function() { |
| | | this.beforeAnimateInEvent.fire(); |
| | | this.animIn.animate(); |
| | | }; |
| | | |
| | | /** |
| | | * Triggers the out-animation. |
| | | * @method animateOut |
| | | */ |
| | | YAHOO.widget.ContainerEffect.prototype.animateOut = function() { |
| | | this.beforeAnimateOutEvent.fire(); |
| | | this.animOut.animate(); |
| | | }; |
| | | |
| | | /** |
| | | * The default onStart handler for the in-animation. |
| | | * @method handleStartAnimateIn |
| | | * @param {String} type The CustomEvent type |
| | | * @param {Object[]} args The CustomEvent arguments |
| | | * @param {Object} obj The scope object |
| | | */ |
| | | YAHOO.widget.ContainerEffect.prototype.handleStartAnimateIn = function(type, args, obj) { }; |
| | | /** |
| | | * The default onTween handler for the in-animation. |
| | | * @method handleTweenAnimateIn |
| | | * @param {String} type The CustomEvent type |
| | | * @param {Object[]} args The CustomEvent arguments |
| | | * @param {Object} obj The scope object |
| | | */ |
| | | YAHOO.widget.ContainerEffect.prototype.handleTweenAnimateIn = function(type, args, obj) { }; |
| | | /** |
| | | * The default onComplete handler for the in-animation. |
| | | * @method handleCompleteAnimateIn |
| | | * @param {String} type The CustomEvent type |
| | | * @param {Object[]} args The CustomEvent arguments |
| | | * @param {Object} obj The scope object |
| | | */ |
| | | YAHOO.widget.ContainerEffect.prototype.handleCompleteAnimateIn = function(type, args, obj) { }; |
| | | |
| | | /** |
| | | * The default onStart handler for the out-animation. |
| | | * @method handleStartAnimateOut |
| | | * @param {String} type The CustomEvent type |
| | | * @param {Object[]} args The CustomEvent arguments |
| | | * @param {Object} obj The scope object |
| | | */ |
| | | YAHOO.widget.ContainerEffect.prototype.handleStartAnimateOut = function(type, args, obj) { }; |
| | | /** |
| | | * The default onTween handler for the out-animation. |
| | | * @method handleTweenAnimateOut |
| | | * @param {String} type The CustomEvent type |
| | | * @param {Object[]} args The CustomEvent arguments |
| | | * @param {Object} obj The scope object |
| | | */ |
| | | YAHOO.widget.ContainerEffect.prototype.handleTweenAnimateOut = function(type, args, obj) { }; |
| | | /** |
| | | * The default onComplete handler for the out-animation. |
| | | * @method handleCompleteAnimateOut |
| | | * @param {String} type The CustomEvent type |
| | | * @param {Object[]} args The CustomEvent arguments |
| | | * @param {Object} obj The scope object |
| | | */ |
| | | YAHOO.widget.ContainerEffect.prototype.handleCompleteAnimateOut = function(type, args, obj) { }; |
| | | |
| | | /** |
| | | * Returns a string representation of the object. |
| | | * @method toString |
| | | * @return {String} The string representation of the ContainerEffect |
| | | */ |
| | | YAHOO.widget.ContainerEffect.prototype.toString = function() { |
| | | var output = "ContainerEffect"; |
| | | if (this.overlay) { |
| | | output += " [" + this.overlay.toString() + "]"; |
| | | } |
| | | return output; |
| | | }; |
| | | |
| | | /** |
| | | * A pre-configured ContainerEffect instance that can be used for fading an overlay in and out. |
| | | * @method FADE |
| | | * @static |
| | | * @param {Overlay} overlay The Overlay object to animate |
| | | * @param {Number} dur The duration of the animation |
| | | * @return {ContainerEffect} The configured ContainerEffect object |
| | | */ |
| | | YAHOO.widget.ContainerEffect.FADE = function(overlay, dur) { |
| | | var fade = new YAHOO.widget.ContainerEffect(overlay, { attributes:{opacity: {from:0, to:1}}, duration:dur, method:YAHOO.util.Easing.easeIn }, { attributes:{opacity: {to:0}}, duration:dur, method:YAHOO.util.Easing.easeOut}, overlay.element ); |
| | | |
| | | fade.handleStartAnimateIn = function(type,args,obj) { |
| | | YAHOO.util.Dom.addClass(obj.overlay.element, "hide-select"); |
| | | |
| | | if (! obj.overlay.underlay) { |
| | | obj.overlay.cfg.refireEvent("underlay"); |
| | | } |
| | | |
| | | if (obj.overlay.underlay) { |
| | | obj.initialUnderlayOpacity = YAHOO.util.Dom.getStyle(obj.overlay.underlay, "opacity"); |
| | | obj.overlay.underlay.style.filter = null; |
| | | } |
| | | |
| | | YAHOO.util.Dom.setStyle(obj.overlay.element, "visibility", "visible"); |
| | | YAHOO.util.Dom.setStyle(obj.overlay.element, "opacity", 0); |
| | | }; |
| | | |
| | | fade.handleCompleteAnimateIn = function(type,args,obj) { |
| | | YAHOO.util.Dom.removeClass(obj.overlay.element, "hide-select"); |
| | | |
| | | if (obj.overlay.element.style.filter) { |
| | | obj.overlay.element.style.filter = null; |
| | | } |
| | | |
| | | if (obj.overlay.underlay) { |
| | | YAHOO.util.Dom.setStyle(obj.overlay.underlay, "opacity", obj.initialUnderlayOpacity); |
| | | } |
| | | |
| | | obj.overlay.cfg.refireEvent("iframe"); |
| | | obj.animateInCompleteEvent.fire(); |
| | | }; |
| | | |
| | | fade.handleStartAnimateOut = function(type, args, obj) { |
| | | YAHOO.util.Dom.addClass(obj.overlay.element, "hide-select"); |
| | | |
| | | if (obj.overlay.underlay) { |
| | | obj.overlay.underlay.style.filter = null; |
| | | } |
| | | }; |
| | | |
| | | fade.handleCompleteAnimateOut = function(type, args, obj) { |
| | | YAHOO.util.Dom.removeClass(obj.overlay.element, "hide-select"); |
| | | if (obj.overlay.element.style.filter) { |
| | | obj.overlay.element.style.filter = null; |
| | | } |
| | | YAHOO.util.Dom.setStyle(obj.overlay.element, "visibility", "hidden"); |
| | | YAHOO.util.Dom.setStyle(obj.overlay.element, "opacity", 1); |
| | | |
| | | obj.overlay.cfg.refireEvent("iframe"); |
| | | |
| | | obj.animateOutCompleteEvent.fire(); |
| | | }; |
| | | |
| | | fade.init(); |
| | | return fade; |
| | | }; |
| | | |
| | | |
| | | /** |
| | | * A pre-configured ContainerEffect instance that can be used for sliding an overlay in and out. |
| | | * @method SLIDE |
| | | * @static |
| | | * @param {Overlay} overlay The Overlay object to animate |
| | | * @param {Number} dur The duration of the animation |
| | | * @return {ContainerEffect} The configured ContainerEffect object |
| | | */ |
| | | YAHOO.widget.ContainerEffect.SLIDE = function(overlay, dur) { |
| | | var x = overlay.cfg.getProperty("x") || YAHOO.util.Dom.getX(overlay.element); |
| | | var y = overlay.cfg.getProperty("y") || YAHOO.util.Dom.getY(overlay.element); |
| | | |
| | | var clientWidth = YAHOO.util.Dom.getClientWidth(); |
| | | var offsetWidth = overlay.element.offsetWidth; |
| | | |
| | | var slide = new YAHOO.widget.ContainerEffect(overlay, { |
| | | attributes:{ points: { to:[x, y] } }, |
| | | duration:dur, |
| | | method:YAHOO.util.Easing.easeIn |
| | | }, |
| | | { |
| | | attributes:{ points: { to:[(clientWidth+25), y] } }, |
| | | duration:dur, |
| | | method:YAHOO.util.Easing.easeOut |
| | | }, |
| | | overlay.element, |
| | | YAHOO.util.Motion); |
| | | |
| | | |
| | | slide.handleStartAnimateIn = function(type,args,obj) { |
| | | obj.overlay.element.style.left = (-25-offsetWidth) + "px"; |
| | | obj.overlay.element.style.top = y + "px"; |
| | | }; |
| | | |
| | | slide.handleTweenAnimateIn = function(type, args, obj) { |
| | | |
| | | |
| | | var pos = YAHOO.util.Dom.getXY(obj.overlay.element); |
| | | |
| | | var currentX = pos[0]; |
| | | var currentY = pos[1]; |
| | | |
| | | if (YAHOO.util.Dom.getStyle(obj.overlay.element, "visibility") == "hidden" && currentX < x) { |
| | | YAHOO.util.Dom.setStyle(obj.overlay.element, "visibility", "visible"); |
| | | } |
| | | |
| | | obj.overlay.cfg.setProperty("xy", [currentX,currentY], true); |
| | | obj.overlay.cfg.refireEvent("iframe"); |
| | | }; |
| | | |
| | | slide.handleCompleteAnimateIn = function(type, args, obj) { |
| | | obj.overlay.cfg.setProperty("xy", [x,y], true); |
| | | obj.startX = x; |
| | | obj.startY = y; |
| | | obj.overlay.cfg.refireEvent("iframe"); |
| | | obj.animateInCompleteEvent.fire(); |
| | | }; |
| | | |
| | | slide.handleStartAnimateOut = function(type, args, obj) { |
| | | var vw = YAHOO.util.Dom.getViewportWidth(); |
| | | |
| | | var pos = YAHOO.util.Dom.getXY(obj.overlay.element); |
| | | |
| | | var yso = pos[1]; |
| | | |
| | | var currentTo = obj.animOut.attributes.points.to; |
| | | obj.animOut.attributes.points.to = [(vw+25), yso]; |
| | | }; |
| | | |
| | | slide.handleTweenAnimateOut = function(type, args, obj) { |
| | | var pos = YAHOO.util.Dom.getXY(obj.overlay.element); |
| | | |
| | | var xto = pos[0]; |
| | | var yto = pos[1]; |
| | | |
| | | obj.overlay.cfg.setProperty("xy", [xto,yto], true); |
| | | obj.overlay.cfg.refireEvent("iframe"); |
| | | }; |
| | | |
| | | slide.handleCompleteAnimateOut = function(type, args, obj) { |
| | | YAHOO.util.Dom.setStyle(obj.overlay.element, "visibility", "hidden"); |
| | | |
| | | obj.overlay.cfg.setProperty("xy", [x,y]); |
| | | obj.animateOutCompleteEvent.fire(); |
| | | }; |
| | | |
| | | slide.init(); |
| | | return slide; |
| | | }; |
| | | |
| | | YAHOO.register("container_core", YAHOO.widget.Module, {version: "2.2.0", build: "127"}); |
interface/web/js/yui/container/container_core-min.js
interface/web/js/yui/container/container_core.js
interface/web/js/yui/datasource/README
interface/web/js/yui/datasource/datasource-beta-debug.js
interface/web/js/yui/datasource/datasource-beta-min.js
interface/web/js/yui/datasource/datasource-beta.js
interface/web/js/yui/datatable/README
interface/web/js/yui/datatable/assets/datatable.css
interface/web/js/yui/datatable/datatable-beta-debug.js
interface/web/js/yui/datatable/datatable-beta-min.js
interface/web/js/yui/datatable/datatable-beta.js
interface/web/js/yui/dom/README
interface/web/js/yui/dom/dom-debug.js
interface/web/js/yui/dom/dom-min.js
interface/web/js/yui/dom/dom.js
interface/web/js/yui/dragdrop/README
interface/web/js/yui/dragdrop/dragdrop-debug.js
interface/web/js/yui/dragdrop/dragdrop-min.js
interface/web/js/yui/dragdrop/dragdrop.js
interface/web/js/yui/element/README
interface/web/js/yui/element/element-beta-debug.js
interface/web/js/yui/element/element-beta-min.js
interface/web/js/yui/element/element-beta.js
interface/web/js/yui/event/README
interface/web/js/yui/event/event-debug.js
interface/web/js/yui/event/event-min.js
interface/web/js/yui/event/event.js
interface/web/js/yui/fonts/README
interface/web/js/yui/fonts/fonts-min.css
interface/web/js/yui/fonts/fonts.css
interface/web/js/yui/grids/README
interface/web/js/yui/grids/grids-min.css
interface/web/js/yui/grids/grids.css
interface/web/js/yui/history/README
interface/web/js/yui/history/assets/blank.html
interface/web/js/yui/history/history-experimental-debug.js
interface/web/js/yui/history/history-experimental-min.js
interface/web/js/yui/history/history-experimental.js
interface/web/js/yui/logger/README
interface/web/js/yui/logger/assets/logger.css
interface/web/js/yui/logger/logger-debug.js
interface/web/js/yui/logger/logger-min.js
interface/web/js/yui/logger/logger.js
interface/web/js/yui/menu/README
interface/web/js/yui/menu/assets/map.gif
interface/web/js/yui/menu/assets/menu.css
interface/web/js/yui/menu/assets/menuarodwn8_dim_1.gif
interface/web/js/yui/menu/assets/menuarodwn8_hov_1.gif
interface/web/js/yui/menu/assets/menuarodwn8_nrm_1.gif
interface/web/js/yui/menu/assets/menuarorght8_dim_1.gif
interface/web/js/yui/menu/assets/menuarorght8_hov_1.gif
interface/web/js/yui/menu/assets/menuarorght8_nrm_1.gif
interface/web/js/yui/menu/assets/menuaroup8_dim_1.gif
interface/web/js/yui/menu/assets/menuaroup8_nrm_1.gif
interface/web/js/yui/menu/assets/menuchk8_dim_1.gif
interface/web/js/yui/menu/assets/menuchk8_hov_1.gif
interface/web/js/yui/menu/assets/menuchk8_nrm_1.gif
interface/web/js/yui/menu/menu-debug.js
interface/web/js/yui/menu/menu-min.js
interface/web/js/yui/menu/menu.js
interface/web/js/yui/reset-fonts-grids/README
interface/web/js/yui/reset-fonts-grids/reset-fonts-grids.css
interface/web/js/yui/reset/README
interface/web/js/yui/reset/reset-min.css
interface/web/js/yui/reset/reset.css
interface/web/js/yui/slider/README
interface/web/js/yui/slider/slider-debug.js
interface/web/js/yui/slider/slider-min.js
interface/web/js/yui/slider/slider.js
interface/web/js/yui/tabview/README
interface/web/js/yui/tabview/assets/border_tabs.css
interface/web/js/yui/tabview/assets/tabview.css
interface/web/js/yui/tabview/tabview-debug.js
interface/web/js/yui/tabview/tabview-min.js
interface/web/js/yui/tabview/tabview.js
interface/web/js/yui/treeview/README
interface/web/js/yui/treeview/assets/lm.gif
interface/web/js/yui/treeview/assets/lmh.gif
interface/web/js/yui/treeview/assets/ln.gif
interface/web/js/yui/treeview/assets/loading.gif
interface/web/js/yui/treeview/assets/lp.gif
interface/web/js/yui/treeview/assets/lph.gif
interface/web/js/yui/treeview/assets/tm.gif
interface/web/js/yui/treeview/assets/tmh.gif
interface/web/js/yui/treeview/assets/tn.gif
interface/web/js/yui/treeview/assets/tp.gif
interface/web/js/yui/treeview/assets/tph.gif
interface/web/js/yui/treeview/assets/tree.css
interface/web/js/yui/treeview/assets/vline.gif
interface/web/js/yui/treeview/treeview-debug.js
interface/web/js/yui/treeview/treeview-min.js
interface/web/js/yui/treeview/treeview.js
interface/web/js/yui/utilities/README
interface/web/js/yui/utilities/utilities.js
interface/web/js/yui/yahoo-dom-event/README
interface/web/js/yui/yahoo-dom-event/yahoo-dom-event.js
interface/web/js/yui/yahoo/README
interface/web/js/yui/yahoo/yahoo-debug.js
interface/web/js/yui/yahoo/yahoo-min.js
interface/web/js/yui/yahoo/yahoo.js
interface/web/login/_index.php
interface/web/login/index.php
interface/web/login/templates/index.htm
interface/web/mail/form/_old_mail_domain_catchall.tform.php (deleted)
interface/web/mail/lib/lang/en_mail_alias_list.lng
interface/web/mail/lib/lang/en_mail_blacklist_list.lng
interface/web/mail/lib/lang/en_mail_domain_catchall_list.lng
interface/web/mail/lib/lang/en_mail_forward_list.lng
interface/web/mail/lib/lang/en_mail_transport_list.lng
interface/web/mail/lib/lang/en_mail_whitelist_list.lng
interface/web/mail/lib/lang/en_spamfilter_blacklist_list.lng
interface/web/mail/lib/lang/en_spamfilter_policy_list.lng
interface/web/mail/lib/lang/en_spamfilter_users_list.lng
interface/web/mail/lib/lang/en_spamfilter_whitelist_list.lng
interface/web/mail/lib/module.conf.php
interface/web/mail/templates/mail_alias_edit.htm
interface/web/mail/templates/mail_alias_list.htm
interface/web/mail/templates/mail_blacklist_edit.htm
interface/web/mail/templates/mail_blacklist_list.htm
interface/web/mail/templates/mail_box_mailuser_edit.htm
interface/web/mail/templates/mail_domain_catchall_edit.htm
interface/web/mail/templates/mail_domain_catchall_list.htm
interface/web/mail/templates/mail_domain_edit.htm
interface/web/mail/templates/mail_domain_list.htm
interface/web/mail/templates/mail_forward_edit.htm
interface/web/mail/templates/mail_forward_list.htm
interface/web/mail/templates/mail_spamfilter_edit.htm
interface/web/mail/templates/mail_spamfilter_list.htm (deleted)
interface/web/mail/templates/mail_transport_edit.htm
interface/web/mail/templates/mail_transport_list.htm
interface/web/mail/templates/mail_user_autoresponder_edit.htm
interface/web/mail/templates/mail_user_list.htm
interface/web/mail/templates/mail_user_mailbox_edit.htm
interface/web/mail/templates/mail_user_mailuser_edit.htm
interface/web/mail/templates/mail_whitelist_edit.htm
interface/web/mail/templates/mail_whitelist_list.htm
interface/web/mail/templates/spamfilter_blacklist_edit.htm
interface/web/mail/templates/spamfilter_blacklist_list.htm
interface/web/mail/templates/spamfilter_other_edit.htm
interface/web/mail/templates/spamfilter_policy_edit.htm
interface/web/mail/templates/spamfilter_policy_list.htm
interface/web/mail/templates/spamfilter_quarantine_edit.htm
interface/web/mail/templates/spamfilter_taglevel_edit.htm
interface/web/mail/templates/spamfilter_users_edit.htm
interface/web/mail/templates/spamfilter_users_list.htm
interface/web/mail/templates/spamfilter_whitelist_edit.htm
interface/web/mail/templates/spamfilter_whitelist_list.htm
interface/web/nav.php
interface/web/test.txt
interface/web/test/lib/module.conf.php
interface/web/themes/default/images/button_bg.gif
interface/web/themes/default/images/button_end.gif
interface/web/themes/default/style.css
interface/web/themes/default/templates/_form.tpl.htm
interface/web/themes/default/templates/form.tpl.htm
interface/web/themes/default/templates/listpage.tpl.htm
interface/web/themes/default/templates/main.tpl.htm
interface/web/themes/default/templates/main_prototype.tpl.htm
interface/web/themes/default/templates/sidenav.tpl.htm
interface/web/themes/default/templates/tabbed_form.tpl.htm
interface/web/themes/default/templates/topnav.tpl.htm
interface/web/themes/grey/templates/_main.tpl.htm
interface/web/themes/grey/templates/form.tpl.htm
interface/web/themes/grey/templates/main.tpl.htm
interface/web/themes/grey/templates/sidenav.tpl.htm
interface/web/themes/grey/templates/topnav.tpl.htm |