Version Notes
Extension tested on Magento CE 1.3.X.Y , 1.4.X.Y and Magento Enterprise Edition (1.8.0.0).
- Update Admin Interface (new date/time picker)
- Added missed files
Download this release
Release Info
Developer | Magento Core Team |
Extension | Speedup_your_catalog_update_using_our_Direct_SQL_Update_extension |
Version | 1.2 |
Comparing to | |
See all releases |
Code changes from version 1.1 to 1.2
- app/code/community/Ayasoftware/SQLupdate/Model/DBHelper.php +1 -1
- app/code/community/Ayasoftware/SQLupdate/Model/Massimport.php +31 -10
- app/code/community/Ayasoftware/SQLupdate/controllers/Adminhtml/SqlupdateController.php +4 -2
- app/code/community/Ayasoftware/SQLupdate/etc/config.xml +2 -2
- app/design/adminhtml/default/default/template/sqlupdate/schedule.phtml +53 -42
- app/etc/modules/Ayasoftware_SQLupdate.xml +9 -0
- js/ayasoftware/behaviors.js +6 -0
- js/ayasoftware/behaviour.js +239 -0
- js/ayasoftware/datepicker.css +108 -0
- js/ayasoftware/datepicker.js +911 -0
- js/ayasoftware/prototype-1.6.0.2.js +4222 -0
- js/ayasoftware/prototype-base-extensions.js +22 -0
- js/ayasoftware/prototype-date-extensions.js +230 -0
- package.xml +9 -5
app/code/community/Ayasoftware/SQLupdate/Model/DBHelper.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
/**
|
3 |
* @category Ayasoftware
|
4 |
* @package Ayasoftware_SQLupdate
|
5 |
-
* @
|
6 |
* website: www.ayasoftware.com/
|
7 |
*/
|
8 |
class Ayasoftware_SQLupdate_Model_DBHelper {
|
2 |
/**
|
3 |
* @category Ayasoftware
|
4 |
* @package Ayasoftware_SQLupdate
|
5 |
+
* @authors Sebastien Bracquemont <dweeves@gmail.com>, EL Hassan Matar <support@ayasoftware.com>
|
6 |
* website: www.ayasoftware.com/
|
7 |
*/
|
8 |
class Ayasoftware_SQLupdate_Model_DBHelper {
|
app/code/community/Ayasoftware/SQLupdate/Model/Massimport.php
CHANGED
@@ -2,7 +2,7 @@
|
|
2 |
/**
|
3 |
* @category Ayasoftware
|
4 |
* @package Ayasoftware_SQLupdate
|
5 |
-
* @
|
6 |
* website: www.ayasoftware.com/
|
7 |
*/
|
8 |
class Ayasoftware_SQLupdate_Model_Massimport extends Ayasoftware_SQLupdate_Model_DBHelper {
|
@@ -17,6 +17,8 @@ class Ayasoftware_SQLupdate_Model_Massimport extends Ayasoftware_SQLupdate_Model
|
|
17 |
public $imgsourcedir;
|
18 |
public $tprefix;
|
19 |
public $logfilename;
|
|
|
|
|
20 |
|
21 |
/**
|
22 |
* retrieve property value with default if not found
|
@@ -104,14 +106,20 @@ class Ayasoftware_SQLupdate_Model_Massimport extends Ayasoftware_SQLupdate_Model
|
|
104 |
/**
|
105 |
* Initialize attribute infos to be used during import
|
106 |
* @param array $cols : array of attribute names
|
|
|
107 |
*/
|
108 |
-
|
|
|
|
|
|
|
|
|
|
|
109 |
//create statement parameter string ?,?,?.....
|
110 |
-
|
111 |
$tname = $this->tablename ( "eav_attribute" );
|
112 |
//SQL for selecting attribute properties for all wanted attributes
|
113 |
$sql = "SELECT `$tname`.* FROM `$tname`
|
114 |
-
WHERE ($tname.attribute_code IN ($qcolstr)) AND (entity_type_id
|
115 |
$stmt = $this->select ( $sql, $cols );
|
116 |
//create an attribute code based array for the wanted columns
|
117 |
while ( $r = $stmt->fetch () ) {
|
@@ -532,7 +540,6 @@ class Ayasoftware_SQLupdate_Model_Massimport extends Ayasoftware_SQLupdate_Model
|
|
532 |
*/
|
533 |
public function updateStock($pid, $item) {
|
534 |
$csit = $this->tablename ( "cataloginventory_stock_item" );
|
535 |
-
Mage::log ( $csit );
|
536 |
$sql = "INSERT INTO `$csit`
|
537 |
(`product_id`,
|
538 |
`stock_id`,
|
@@ -573,10 +580,24 @@ class Ayasoftware_SQLupdate_Model_Massimport extends Ayasoftware_SQLupdate_Model
|
|
573 |
$this->insert ( $sql, array ($catid, $pid ) );
|
574 |
}
|
575 |
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
580 |
/**
|
581 |
* set website of product if not exists
|
582 |
* @param int $pid : product id
|
@@ -722,7 +743,7 @@ class Ayasoftware_SQLupdate_Model_Massimport extends Ayasoftware_SQLupdate_Model
|
|
722 |
$etimer = explode( ' ', microtime() );
|
723 |
$etimer = $etimer[1] + $etimer[0];
|
724 |
fwrite($fp, "Update completed in ");
|
725 |
-
fwrite($fp, $etimer- $stimer. " Seconds
|
726 |
@fclose($fp);
|
727 |
$this->disconnectFromMagento ();
|
728 |
}
|
2 |
/**
|
3 |
* @category Ayasoftware
|
4 |
* @package Ayasoftware_SQLupdate
|
5 |
+
* @authors Sebastien Bracquemont <dweeves@gmail.com>, EL Hassan Matar <support@ayasoftware.com>
|
6 |
* website: www.ayasoftware.com/
|
7 |
*/
|
8 |
class Ayasoftware_SQLupdate_Model_Massimport extends Ayasoftware_SQLupdate_Model_DBHelper {
|
17 |
public $imgsourcedir;
|
18 |
public $tprefix;
|
19 |
public $logfilename;
|
20 |
+
public $prod_etype;
|
21 |
+
|
22 |
|
23 |
/**
|
24 |
* retrieve property value with default if not found
|
106 |
/**
|
107 |
* Initialize attribute infos to be used during import
|
108 |
* @param array $cols : array of attribute names
|
109 |
+
* updated 23 August 2010 - by Dweeves
|
110 |
*/
|
111 |
+
|
112 |
+
public function initAttrInfos($cols)
|
113 |
+
{
|
114 |
+
//Find product entity type
|
115 |
+
$tname=$this->tablename("eav_entity_type");
|
116 |
+
$this->prod_etype=$this->selectone("SELECT entity_type_id FROM $tname WHERE entity_type_code=?","catalog_product","entity_type_id");
|
117 |
//create statement parameter string ?,?,?.....
|
118 |
+
$qcolstr = substr ( str_repeat ( "?,", count ( $cols ) ), 0, - 1 );
|
119 |
$tname = $this->tablename ( "eav_attribute" );
|
120 |
//SQL for selecting attribute properties for all wanted attributes
|
121 |
$sql = "SELECT `$tname`.* FROM `$tname`
|
122 |
+
WHERE ($tname.attribute_code IN ($qcolstr)) AND (entity_type_id=$this->prod_etype)";
|
123 |
$stmt = $this->select ( $sql, $cols );
|
124 |
//create an attribute code based array for the wanted columns
|
125 |
while ( $r = $stmt->fetch () ) {
|
540 |
*/
|
541 |
public function updateStock($pid, $item) {
|
542 |
$csit = $this->tablename ( "cataloginventory_stock_item" );
|
|
|
543 |
$sql = "INSERT INTO `$csit`
|
544 |
(`product_id`,
|
545 |
`stock_id`,
|
580 |
$this->insert ( $sql, array ($catid, $pid ) );
|
581 |
}
|
582 |
|
583 |
+
public function updateIndexes ()
|
584 |
+
{
|
585 |
+
$indexer = Mage::getBaseDir() . DS . "shell/indexer.php";
|
586 |
+
if (file_exists($indexer)) {
|
587 |
+
$idxlist = array("catalog_product_attribute", "catalog_product_price", "catalog_product_flat", "catalog_category_flat", "catalog_category_product", "catalog_url", "catalogsearch_fulltext", "cataloginventory_stock");
|
588 |
+
//reindex using magento command line
|
589 |
+
foreach ($idxlist as $idx) {
|
590 |
+
$tstart = microtime(true);
|
591 |
+
Mage::log("Reindexing $idx....\n");
|
592 |
+
exec("php $indexer --reindex $idx");
|
593 |
+
$tend = microtime(true);
|
594 |
+
Mage::log("done in " . round($tend - $tstart, 2) . " secs \n");
|
595 |
+
flush();
|
596 |
+
}
|
597 |
+
} else {
|
598 |
+
Mage::log("Magento 1.3 indexer not found, you should reindex manually using magento admin \n");
|
599 |
+
}
|
600 |
+
}
|
601 |
/**
|
602 |
* set website of product if not exists
|
603 |
* @param int $pid : product id
|
743 |
$etimer = explode( ' ', microtime() );
|
744 |
$etimer = $etimer[1] + $etimer[0];
|
745 |
fwrite($fp, "Update completed in ");
|
746 |
+
fwrite($fp, $etimer- $stimer. " Seconds - ".date("Y-m-d H:i:s")."\n");
|
747 |
@fclose($fp);
|
748 |
$this->disconnectFromMagento ();
|
749 |
}
|
app/code/community/Ayasoftware/SQLupdate/controllers/Adminhtml/SqlupdateController.php
CHANGED
@@ -1,13 +1,15 @@
|
|
1 |
<?php
|
2 |
class Ayasoftware_SQLupdate_Adminhtml_SqlupdateController extends Mage_Adminhtml_Controller_Action {
|
3 |
public function indexAction() {
|
4 |
-
//Mage::helper('affiliatepack')->addAdminhtmlVersion('affiliatepack');
|
5 |
$this->loadLayout ()->renderLayout ();
|
6 |
}
|
7 |
public function postAction() {
|
8 |
$post = $this->getRequest ()->getPost ();
|
9 |
$scheduling = $post ['scheduling'];
|
10 |
$timecreated = date("Y-m-d H:i:s");
|
|
|
|
|
|
|
11 |
$scheduling = date("Y-m-d H:i:s", strtotime($scheduling));
|
12 |
try {
|
13 |
if ($timecreated > $scheduling) {
|
@@ -15,7 +17,7 @@ class Ayasoftware_SQLupdate_Adminhtml_SqlupdateController extends Mage_Adminhtml
|
|
15 |
}
|
16 |
$update = Mage::getModel ( 'sqlupdate/observer' );
|
17 |
$update->changeScheduling ( $scheduling );
|
18 |
-
$message = $this->__ ( 'The
|
19 |
Mage::getSingleton ( 'adminhtml/session' )->addSuccess ( $message );
|
20 |
} catch ( Exception $e ) {
|
21 |
Mage::getSingleton ( 'adminhtml/session' )->addError ( $e->getMessage () );
|
1 |
<?php
|
2 |
class Ayasoftware_SQLupdate_Adminhtml_SqlupdateController extends Mage_Adminhtml_Controller_Action {
|
3 |
public function indexAction() {
|
|
|
4 |
$this->loadLayout ()->renderLayout ();
|
5 |
}
|
6 |
public function postAction() {
|
7 |
$post = $this->getRequest ()->getPost ();
|
8 |
$scheduling = $post ['scheduling'];
|
9 |
$timecreated = date("Y-m-d H:i:s");
|
10 |
+
$a1 = explode(" ", $scheduling);
|
11 |
+
$a2 = explode("-", $a1[0] );
|
12 |
+
$scheduling = $a2[2]."-".$a2[0]."-".$a2[1]." ".$a1[1];
|
13 |
$scheduling = date("Y-m-d H:i:s", strtotime($scheduling));
|
14 |
try {
|
15 |
if ($timecreated > $scheduling) {
|
17 |
}
|
18 |
$update = Mage::getModel ( 'sqlupdate/observer' );
|
19 |
$update->changeScheduling ( $scheduling );
|
20 |
+
$message = $this->__ ( 'The import has been Scheduled Successfully to be automatically run at '.$scheduling );
|
21 |
Mage::getSingleton ( 'adminhtml/session' )->addSuccess ( $message );
|
22 |
} catch ( Exception $e ) {
|
23 |
Mage::getSingleton ( 'adminhtml/session' )->addError ( $e->getMessage () );
|
app/code/community/Ayasoftware/SQLupdate/etc/config.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<config>
|
2 |
<modules>
|
3 |
<Ayasoftware_SQLupdate>
|
4 |
-
<version>
|
5 |
<depends>
|
6 |
<!-- no dependencies -->
|
7 |
</depends>
|
@@ -22,7 +22,7 @@
|
|
22 |
<jobs>
|
23 |
<direct_sql_update>
|
24 |
<schedule>
|
25 |
-
<cron_expr>
|
26 |
</schedule>
|
27 |
<run>
|
28 |
<model>sqlupdate/observer::batchUpdate</model>
|
1 |
<config>
|
2 |
<modules>
|
3 |
<Ayasoftware_SQLupdate>
|
4 |
+
<version>1.2</version>
|
5 |
<depends>
|
6 |
<!-- no dependencies -->
|
7 |
</depends>
|
22 |
<jobs>
|
23 |
<direct_sql_update>
|
24 |
<schedule>
|
25 |
+
<cron_expr>00 00 * * *</cron_expr>
|
26 |
</schedule>
|
27 |
<run>
|
28 |
<model>sqlupdate/observer::batchUpdate</model>
|
app/design/adminhtml/default/default/template/sqlupdate/schedule.phtml
CHANGED
@@ -1,43 +1,54 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
|
4 |
-
|
5 |
-
<
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
<
|
18 |
-
<
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
<
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
value="<?php
|
26 |
-
echo Mage::getSingleton ( 'core/session' )->getFormKey ()?>" />
|
27 |
-
</td>
|
28 |
-
</tr>
|
29 |
-
<tr>
|
30 |
-
<td><
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
</
|
35 |
-
</
|
36 |
-
</
|
37 |
-
<
|
38 |
-
<h4 class="icon-head head-edit-form fieldset-legend"><?=$this->__ ( '
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
</script>
|
1 |
+
<SCRIPT type="text/javascript" language="javascript"
|
2 |
+
src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS)?>ayasoftware/prototype-1.6.0.2.js"></SCRIPT>
|
3 |
+
<SCRIPT type="text/javascript" language="javascript"
|
4 |
+
src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS)?>ayasoftware/prototype-date-extensions.js"></SCRIPT>
|
5 |
+
<SCRIPT type="text/javascript" language="javascript"
|
6 |
+
src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS)?>ayasoftware/behaviour.js"></SCRIPT>
|
7 |
+
<SCRIPT type="text/javascript" language="javascript"
|
8 |
+
src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS)?>ayasoftware/datepicker.js"></SCRIPT>
|
9 |
+
<LINK rel="stylesheet"
|
10 |
+
href="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS)?>ayasoftware/datepicker.css">
|
11 |
+
<SCRIPT type="text/javascript" language="javascript"
|
12 |
+
src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS)?>ayasoftware/behaviors.js"></SCRIPT>
|
13 |
+
<?php
|
14 |
+
$timecreated = date("Y-m-d H:i:s");
|
15 |
+
?>
|
16 |
+
<div class="content-header">
|
17 |
+
<table cellspacing="0" class="grid-header">
|
18 |
+
<tr>
|
19 |
+
<td>
|
20 |
+
<h3><?=$this->__ ( 'Schedule SQL Update. ' )?></h3>
|
21 |
+
</td>
|
22 |
+
<td class="a-right">
|
23 |
+
<button onclick="editForm.submit()" class="scalable save"
|
24 |
+
type="button"><span>Create Scheduled Task for SQL Update.</span></button>
|
25 |
+
</td>
|
26 |
+
</tr>
|
27 |
+
</table>
|
28 |
+
</div>
|
29 |
+
<div class="entry-edit">
|
30 |
+
<form id="edit_form" name="edit_form" method="post"
|
31 |
+
action="<?=$this->getUrl ( '*/*/post' )?>">
|
32 |
+
|
33 |
+
<fieldset id="my-fieldset">
|
34 |
+
<table cellspacing="3" cellpadding="10" class="form-list">
|
35 |
+
<tr>
|
36 |
+
<td colspan="2"><input name="form_key" type="hidden"
|
37 |
value="<?php
|
38 |
+
echo Mage::getSingleton ( 'core/session' )->getFormKey ()?>" />
|
39 |
+
</td>
|
40 |
+
</tr>
|
41 |
+
<tr>
|
42 |
+
<td><INPUT class="datetimepicker" name="scheduling" value="Click to pick a date" onfocus="if(this.value=='Click to pick a date')this.value=''; " ></td>
|
43 |
+
<td> <span class="required">*</span> Server Time: <?php echo $timecreated?></td>
|
44 |
+
</tr>
|
45 |
+
</table>
|
46 |
+
</fieldset>
|
47 |
+
</form>
|
48 |
+
<h2>How to use this module</h2>
|
49 |
+
<h4 class="icon-head head-edit-form fieldset-legend"><?=$this->__ ( 'The SQL Update is by default Scheduled to be automatically run at midnight 00:00 ' )?></h4>
|
50 |
+
<h4 class="icon-head head-edit-form fieldset-legend"><?=$this->__ ( 'If you pick a new Scheduling for your SQL Update, we will replace the default (only this time) ' )?></h4>
|
51 |
+
</div>
|
52 |
+
<script type="text/javascript">
|
53 |
+
var editForm = new varienForm('edit_form');
|
54 |
+
</script>
|
|
app/etc/modules/Ayasoftware_SQLupdate.xml
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?xml version="1.0"?>
|
2 |
+
<config>
|
3 |
+
<modules>
|
4 |
+
<Ayasoftware_SQLupdate>
|
5 |
+
<active>true</active>
|
6 |
+
<codePool>community</codePool>
|
7 |
+
</Ayasoftware_SQLupdate>
|
8 |
+
</modules>
|
9 |
+
</config>
|
js/ayasoftware/behaviors.js
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
var rules = {
|
2 |
+
'input.datetimepicker': function(elt) {
|
3 |
+
new Control.DatePicker(elt, { icon: 'http://www.cionlinestores.com/js/ayasoftware/calendar.png', timePicker: true, timePickerAdjacent: true, use24hrs: true });
|
4 |
+
}
|
5 |
+
};
|
6 |
+
Behaviour.register(rules);
|
js/ayasoftware/behaviour.js
ADDED
@@ -0,0 +1,239 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
Behaviour v1.1 by Ben Nolan, June 2005. Based largely on the work
|
3 |
+
of Simon Willison (see comments by Simon below).
|
4 |
+
|
5 |
+
Description:
|
6 |
+
|
7 |
+
Uses css selectors to apply javascript behaviours to enable
|
8 |
+
unobtrusive javascript in html documents.
|
9 |
+
|
10 |
+
Usage:
|
11 |
+
|
12 |
+
var myrules = {
|
13 |
+
'b.someclass' : function(element){
|
14 |
+
element.onclick = function(){
|
15 |
+
alert(this.innerHTML);
|
16 |
+
}
|
17 |
+
},
|
18 |
+
'#someid u' : function(element){
|
19 |
+
element.onmouseover = function(){
|
20 |
+
this.innerHTML = "BLAH!";
|
21 |
+
}
|
22 |
+
}
|
23 |
+
};
|
24 |
+
|
25 |
+
Behaviour.register(myrules);
|
26 |
+
|
27 |
+
// Call Behaviour.apply() to re-apply the rules (if you
|
28 |
+
// update the dom, etc).
|
29 |
+
|
30 |
+
License:
|
31 |
+
|
32 |
+
My stuff is BSD licensed. Not sure about Simon's.
|
33 |
+
|
34 |
+
More information:
|
35 |
+
|
36 |
+
http://ripcord.co.nz/behaviour/
|
37 |
+
|
38 |
+
*/
|
39 |
+
|
40 |
+
var Behaviour = {
|
41 |
+
list : new Array,
|
42 |
+
|
43 |
+
register: function(sheet){
|
44 |
+
Behaviour.list.push(sheet);
|
45 |
+
},
|
46 |
+
|
47 |
+
start : function(){
|
48 |
+
// Replace with Prototype library function
|
49 |
+
Event.observe(window, 'load', function() { Behaviour.apply(); });
|
50 |
+
},
|
51 |
+
|
52 |
+
apply : function(){
|
53 |
+
for (h = 0; sheet = Behaviour.list[h]; ++h)
|
54 |
+
Behaviour.applyRules(sheet);
|
55 |
+
},
|
56 |
+
|
57 |
+
applyRules: function(sheet) {
|
58 |
+
for (selector in sheet) {
|
59 |
+
list = document.getElementsBySelector(selector);
|
60 |
+
if (!list)
|
61 |
+
continue;
|
62 |
+
for (i = 0; element = list[i]; ++i)
|
63 |
+
sheet[selector](element);
|
64 |
+
}
|
65 |
+
}
|
66 |
+
}
|
67 |
+
|
68 |
+
Behaviour.start();
|
69 |
+
|
70 |
+
/*
|
71 |
+
The following code is Copyright (C) Simon Willison 2004.
|
72 |
+
|
73 |
+
document.getElementsBySelector(selector)
|
74 |
+
- returns an array of element objects from the current document
|
75 |
+
matching the CSS selector. Selectors can contain element names,
|
76 |
+
class names and ids and can be nested. For example:
|
77 |
+
|
78 |
+
elements = document.getElementsBySelect('div#main p a.external')
|
79 |
+
|
80 |
+
Will return an array of all 'a' elements with 'external' in their
|
81 |
+
class attribute that are contained inside 'p' elements that are
|
82 |
+
contained inside the 'div' element which has id="main"
|
83 |
+
|
84 |
+
New in version 0.4: Support for CSS2 and CSS3 attribute selectors:
|
85 |
+
See http://www.w3.org/TR/css3-selectors/#attribute-selectors
|
86 |
+
|
87 |
+
Version 0.4 - Simon Willison, March 25th 2003
|
88 |
+
-- Works in Phoenix 0.5, Mozilla 1.3, Opera 7, Internet Explorer 6, Internet Explorer 5 on Windows
|
89 |
+
-- Opera 7 fails
|
90 |
+
*/
|
91 |
+
|
92 |
+
function getAllChildren(e) {
|
93 |
+
// Returns all children of element. Workaround required for IE5/Windows. Ugh.
|
94 |
+
return e.all ? e.all : e.getElementsByTagName('*');
|
95 |
+
}
|
96 |
+
|
97 |
+
document.getElementsBySelector = function(selector) {
|
98 |
+
// Attempt to fail gracefully in lesser browsers
|
99 |
+
if (!document.getElementsByTagName) {
|
100 |
+
return new Array();
|
101 |
+
}
|
102 |
+
// Split selector in to tokens
|
103 |
+
var tokens = selector.split(' ');
|
104 |
+
var currentContext = new Array(document);
|
105 |
+
for (var i = 0; i < tokens.length; i++) {
|
106 |
+
token = tokens[i].replace(/^\s+/,'').replace(/\s+$/,'');;
|
107 |
+
if (token.indexOf('#') > -1) {
|
108 |
+
// Token is an ID selector
|
109 |
+
var bits = token.split('#');
|
110 |
+
var tagName = bits[0];
|
111 |
+
var id = bits[1];
|
112 |
+
var element = document.getElementById(id);
|
113 |
+
if (element && tagName && element.nodeName.toLowerCase() != tagName) {
|
114 |
+
// tag with that ID not found, return false
|
115 |
+
return new Array();
|
116 |
+
}
|
117 |
+
// Set currentContext to contain just this element
|
118 |
+
currentContext = new Array(element);
|
119 |
+
continue; // Skip to next token
|
120 |
+
}
|
121 |
+
if (token.indexOf('.') > -1) {
|
122 |
+
// Token contains a class selector
|
123 |
+
var bits = token.split('.');
|
124 |
+
var tagName = bits[0];
|
125 |
+
var className = bits[1];
|
126 |
+
if (!tagName) {
|
127 |
+
tagName = '*';
|
128 |
+
}
|
129 |
+
// Get elements matching tag, filter them for class selector
|
130 |
+
var found = new Array;
|
131 |
+
var foundCount = 0;
|
132 |
+
for (var h = 0; h < currentContext.length; h++) {
|
133 |
+
var elements;
|
134 |
+
if (tagName == '*') {
|
135 |
+
elements = getAllChildren(currentContext[h]);
|
136 |
+
} else {
|
137 |
+
elements = currentContext[h].getElementsByTagName(tagName);
|
138 |
+
}
|
139 |
+
for (var j = 0; j < elements.length; j++) {
|
140 |
+
found[foundCount++] = elements[j];
|
141 |
+
}
|
142 |
+
}
|
143 |
+
currentContext = new Array;
|
144 |
+
var currentContextIndex = 0;
|
145 |
+
for (var k = 0; k < found.length; k++) {
|
146 |
+
if (found[k].className && found[k].className.match(new RegExp('\\b'+className+'\\b'))) {
|
147 |
+
currentContext[currentContextIndex++] = found[k];
|
148 |
+
}
|
149 |
+
}
|
150 |
+
continue; // Skip to next token
|
151 |
+
}
|
152 |
+
// Code to deal with attribute selectors
|
153 |
+
if (token.match(/^(\w*)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/)) {
|
154 |
+
var tagName = RegExp.$1;
|
155 |
+
var attrName = RegExp.$2;
|
156 |
+
var attrOperator = RegExp.$3;
|
157 |
+
var attrValue = RegExp.$4;
|
158 |
+
if (!tagName) {
|
159 |
+
tagName = '*';
|
160 |
+
}
|
161 |
+
// Grab all of the tagName elements within current context
|
162 |
+
var found = new Array;
|
163 |
+
var foundCount = 0;
|
164 |
+
for (var h = 0; h < currentContext.length; h++) {
|
165 |
+
var elements;
|
166 |
+
if (tagName == '*') {
|
167 |
+
elements = getAllChildren(currentContext[h]);
|
168 |
+
} else {
|
169 |
+
elements = currentContext[h].getElementsByTagName(tagName);
|
170 |
+
}
|
171 |
+
for (var j = 0; j < elements.length; j++) {
|
172 |
+
found[foundCount++] = elements[j];
|
173 |
+
}
|
174 |
+
}
|
175 |
+
currentContext = new Array;
|
176 |
+
var currentContextIndex = 0;
|
177 |
+
var checkFunction; // This function will be used to filter the elements
|
178 |
+
switch (attrOperator) {
|
179 |
+
case '=': // Equality
|
180 |
+
checkFunction = function(e) { return (e.getAttribute(attrName) == attrValue); };
|
181 |
+
break;
|
182 |
+
case '~': // Match one of space seperated words
|
183 |
+
checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('\\b'+attrValue+'\\b'))); };
|
184 |
+
break;
|
185 |
+
case '|': // Match start with value followed by optional hyphen
|
186 |
+
checkFunction = function(e) { return (e.getAttribute(attrName).match(new RegExp('^'+attrValue+'-?'))); };
|
187 |
+
break;
|
188 |
+
case '^': // Match starts with value
|
189 |
+
checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) == 0); };
|
190 |
+
break;
|
191 |
+
case '$': // Match ends with value - fails with "Warning" in Opera 7
|
192 |
+
checkFunction = function(e) { return (e.getAttribute(attrName).lastIndexOf(attrValue) == e.getAttribute(attrName).length - attrValue.length); };
|
193 |
+
break;
|
194 |
+
case '*': // Match ends with value
|
195 |
+
checkFunction = function(e) { return (e.getAttribute(attrName).indexOf(attrValue) > -1); };
|
196 |
+
break;
|
197 |
+
default :
|
198 |
+
// Just test for existence of attribute
|
199 |
+
checkFunction = function(e) { return e.getAttribute(attrName); };
|
200 |
+
}
|
201 |
+
currentContext = new Array;
|
202 |
+
var currentContextIndex = 0;
|
203 |
+
for (var k = 0; k < found.length; k++) {
|
204 |
+
if (checkFunction(found[k])) {
|
205 |
+
currentContext[currentContextIndex++] = found[k];
|
206 |
+
}
|
207 |
+
}
|
208 |
+
// alert('Attribute Selector: '+tagName+' '+attrName+' '+attrOperator+' '+attrValue);
|
209 |
+
continue; // Skip to next token
|
210 |
+
}
|
211 |
+
|
212 |
+
if (!currentContext[0]){
|
213 |
+
return;
|
214 |
+
}
|
215 |
+
|
216 |
+
// If we get here, token is JUST an element (not a class or ID selector)
|
217 |
+
tagName = token;
|
218 |
+
var found = new Array;
|
219 |
+
var foundCount = 0;
|
220 |
+
for (var h = 0; h < currentContext.length; h++) {
|
221 |
+
var elements = currentContext[h].getElementsByTagName(tagName);
|
222 |
+
for (var j = 0; j < elements.length; j++) {
|
223 |
+
found[foundCount++] = elements[j];
|
224 |
+
}
|
225 |
+
}
|
226 |
+
currentContext = found;
|
227 |
+
}
|
228 |
+
return currentContext;
|
229 |
+
}
|
230 |
+
|
231 |
+
/* That revolting regular expression explained
|
232 |
+
/^(\w+)\[(\w+)([=~\|\^\$\*]?)=?"?([^\]"]*)"?\]$/
|
233 |
+
\---/ \---/\-------------/ \-------/
|
234 |
+
| | | |
|
235 |
+
| | | The value
|
236 |
+
| | ~,|,^,$,* or =
|
237 |
+
| Attribute
|
238 |
+
Tag
|
239 |
+
*/
|
js/ayasoftware/datepicker.css
ADDED
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/**
|
2 |
+
* Styles for DatePicker
|
3 |
+
*/
|
4 |
+
|
5 |
+
.datepickerControl {
|
6 |
+
border: 1px solid #999999;
|
7 |
+
background-color: #EEEEEE;
|
8 |
+
padding: 5px;
|
9 |
+
}
|
10 |
+
|
11 |
+
.datepickerControl td {
|
12 |
+
text-align: center;
|
13 |
+
font-family: sans-serif;
|
14 |
+
font-size: 11px;
|
15 |
+
padding: 1px;
|
16 |
+
}
|
17 |
+
|
18 |
+
.datepickerControl tr.monthLabel td {
|
19 |
+
background-color: #FFFFFF;
|
20 |
+
border: 1px solid #999999;
|
21 |
+
font-weight: bold;
|
22 |
+
}
|
23 |
+
|
24 |
+
.datepickerControl tr.navigation td {
|
25 |
+
cursor: pointer;
|
26 |
+
}
|
27 |
+
|
28 |
+
.datepickerControl tr.navigation td:hover {
|
29 |
+
text-decoration: underline;
|
30 |
+
}
|
31 |
+
|
32 |
+
.datepickerControl tr.dayLabel td {
|
33 |
+
/*
|
34 |
+
border: 1px solid #C0D8EA;
|
35 |
+
background-color: #C0D8EA;
|
36 |
+
*/
|
37 |
+
border: 1px solid #003366;
|
38 |
+
background-color: #003366;
|
39 |
+
color: white;
|
40 |
+
font-weight: bold;
|
41 |
+
}
|
42 |
+
|
43 |
+
.datepickerControl td.day, .datepickerControl td.dayothermonth {
|
44 |
+
cursor: pointer;
|
45 |
+
background-color: #FFFFFF;
|
46 |
+
border: 1px solid #EEEEEE;
|
47 |
+
width: 2em;
|
48 |
+
}
|
49 |
+
|
50 |
+
.datepickerControl td.dayothermonth {
|
51 |
+
color: #999999;
|
52 |
+
font-style: italic;
|
53 |
+
}
|
54 |
+
|
55 |
+
.datepickerControl td.day:hover {
|
56 |
+
background-color: #EBE4C0;
|
57 |
+
}
|
58 |
+
|
59 |
+
.datepickerControl td.weekend {
|
60 |
+
background-color: #CCCCCC;
|
61 |
+
font-style: italic;
|
62 |
+
}
|
63 |
+
|
64 |
+
.datepickerControl td.today {
|
65 |
+
font-weight: bold;
|
66 |
+
}
|
67 |
+
|
68 |
+
.datepickerControl td.hour {
|
69 |
+
cursor: pointer;
|
70 |
+
background-color: #FFFFFF;
|
71 |
+
border: 1px solid #EEEEEE;
|
72 |
+
width: 2em;
|
73 |
+
}
|
74 |
+
|
75 |
+
.datepickerControl td.minute {
|
76 |
+
cursor: pointer;
|
77 |
+
background-color: #FFFFFF;
|
78 |
+
border: 1px solid #EEEEEE;
|
79 |
+
width: 2em;
|
80 |
+
}
|
81 |
+
|
82 |
+
.datepickerControl td input,
|
83 |
+
.datepickerControl td button {
|
84 |
+
font-size: 11px;
|
85 |
+
padding: 0;
|
86 |
+
border: 1px solid #999999;
|
87 |
+
text-align: center;
|
88 |
+
}
|
89 |
+
|
90 |
+
.datepickerControl td.ampm {
|
91 |
+
cursor: pointer;
|
92 |
+
background-color: #CCCCCC;
|
93 |
+
border: 1px solid #EEEEEE;
|
94 |
+
width: 2em;
|
95 |
+
}
|
96 |
+
|
97 |
+
.datepickerControl td.current {
|
98 |
+
font-weight: bold;
|
99 |
+
background-color: #EBC2C0;
|
100 |
+
}
|
101 |
+
|
102 |
+
.datepickerControl input.current {
|
103 |
+
background-color: #EBC2C0;
|
104 |
+
}
|
105 |
+
|
106 |
+
.datepickerControl td.current:hover {
|
107 |
+
background-color: #EBC2C0;
|
108 |
+
}
|
js/ayasoftware/datepicker.js
ADDED
@@ -0,0 +1,911 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
* Control.DatePicker
|
3 |
+
*
|
4 |
+
* Transforms an ordinary input textbox into an interactive date picker.
|
5 |
+
* When the textbox is clicked (or the down arrow is pressed), a calendar
|
6 |
+
* appears that the user can browse through and select a date.
|
7 |
+
*
|
8 |
+
* Features:
|
9 |
+
* - Allows user to specify a date format
|
10 |
+
* - Easy to localize
|
11 |
+
* - Customizable by CSS
|
12 |
+
*
|
13 |
+
* Written and maintained by Jeremy Jongsma (jeremy@jongsma.org)
|
14 |
+
*/
|
15 |
+
if (window.Control == undefined) Control = {};
|
16 |
+
|
17 |
+
Control.DatePicker = Class.create();
|
18 |
+
Control.DatePicker.activePicker = null;
|
19 |
+
Control.DatePicker.prototype = {
|
20 |
+
initialize: function(element, options) {
|
21 |
+
this.element = $(element);
|
22 |
+
this.i18n = new Control.DatePicker.i18n(options && options.locale ? options.locale : 'en_US');
|
23 |
+
options = this.i18n.inheritOptions(options);
|
24 |
+
options = Object.extend({
|
25 |
+
datePicker: true,
|
26 |
+
timePicker: false
|
27 |
+
}, options || {});
|
28 |
+
|
29 |
+
this.handlers = { onClick: options.onClick,
|
30 |
+
onHover: options.onHover,
|
31 |
+
onSelect: options.onSelect };
|
32 |
+
|
33 |
+
this.options = Object.extend(options || {}, {
|
34 |
+
onClick: this.pickerClicked.bind(this),
|
35 |
+
onHover: this.dateHover.bind(this),
|
36 |
+
onSelect: this.datePicked.bind(this)
|
37 |
+
});
|
38 |
+
|
39 |
+
if (this.options.timePicker && this.options.datePicker)
|
40 |
+
this.options.currentFormat = this.options.dateTimeFormat;
|
41 |
+
else if (this.options.timePicker)
|
42 |
+
this.options.currentFormat = this.options.timeFormat;
|
43 |
+
else
|
44 |
+
this.options.currentFormat = this.options.dateFormat;
|
45 |
+
// this.options.currentFormat = this.options.timePicker ? this.options.dateTimeFormat : this.options.dateFormat;
|
46 |
+
this.options.date = DateFormat.parseFormat(this.element.value, this.options.currentFormat);
|
47 |
+
|
48 |
+
// Lazy load to avoid excessive CPU usage with lots of controls on one page
|
49 |
+
this.datepicker = null;
|
50 |
+
|
51 |
+
this.originalValue = null;
|
52 |
+
this.hideTimeout = null;
|
53 |
+
|
54 |
+
if (this.options.icon) {
|
55 |
+
this.element.style.background = 'url('+this.options.icon+') right center no-repeat #FFF';
|
56 |
+
// Prevent text writing over icon
|
57 |
+
this.element.style.paddingRight = '20px';
|
58 |
+
}
|
59 |
+
Event.observe(this.element, 'click', this.togglePicker.bindAsEventListener(this));
|
60 |
+
|
61 |
+
this.hidePickerListener = this.delayedHide.bindAsEventListener(this);
|
62 |
+
Event.observe(this.element, 'keydown', this.keyHandler.bindAsEventListener(this));
|
63 |
+
Event.observe(document, 'keydown', this.docKeyHandler.bindAsEventListener(this));
|
64 |
+
|
65 |
+
this.pickerActive = false;
|
66 |
+
},
|
67 |
+
tr: function(str) {
|
68 |
+
return this.i18n.tr(str);
|
69 |
+
},
|
70 |
+
delayedHide: function(e) {
|
71 |
+
this.hideTimeout = setTimeout(this.hide.bind(this), 100);
|
72 |
+
},
|
73 |
+
pickerClicked: function() {
|
74 |
+
if (this.hideTimeout) {
|
75 |
+
clearTimeout(this.hideTimeout);
|
76 |
+
this.hideTimeout = null;
|
77 |
+
}
|
78 |
+
if (this.handlers.onClick)
|
79 |
+
this.handlers.onClick();
|
80 |
+
},
|
81 |
+
datePicked: function(date) {
|
82 |
+
this.element.value = DateFormat.format(date, this.options.currentFormat);
|
83 |
+
this.element.focus();
|
84 |
+
this.hide();
|
85 |
+
if (this.handlers.onSelect)
|
86 |
+
this.handlers.onSelect(date);
|
87 |
+
if (this.element.onchange)
|
88 |
+
this.element.onchange();
|
89 |
+
},
|
90 |
+
dateHover: function(date) {
|
91 |
+
if (this.hideTimeout) {
|
92 |
+
clearTimeout(this.hideTimeout);
|
93 |
+
this.hideTimeout = null;
|
94 |
+
}
|
95 |
+
if (this.pickerActive) {
|
96 |
+
this.element.value = DateFormat.format(date, this.options.currentFormat);
|
97 |
+
if (this.handlers.onHover)
|
98 |
+
this.handlers.onHover(date);
|
99 |
+
}
|
100 |
+
},
|
101 |
+
togglePicker: function(e) {
|
102 |
+
if (this.pickerActive) {
|
103 |
+
this.element.value = this.originalValue;
|
104 |
+
this.hide();
|
105 |
+
} else {
|
106 |
+
this.show();
|
107 |
+
}
|
108 |
+
Event.stop(e);
|
109 |
+
return false;
|
110 |
+
},
|
111 |
+
docKeyHandler: function(e) {
|
112 |
+
if (e.keyCode == Event.KEY_ESC)
|
113 |
+
if (this.pickerActive) {
|
114 |
+
this.element.value = this.originalValue;
|
115 |
+
this.hide();
|
116 |
+
}
|
117 |
+
|
118 |
+
},
|
119 |
+
keyHandler: function(e) {
|
120 |
+
switch (e.keyCode) {
|
121 |
+
case Event.KEY_ESC:
|
122 |
+
if (this.pickerActive)
|
123 |
+
this.element.value = this.originalValue;
|
124 |
+
case Event.KEY_TAB:
|
125 |
+
this.hide();
|
126 |
+
return;
|
127 |
+
case Event.KEY_DOWN:
|
128 |
+
if (!this.pickerActive) {
|
129 |
+
this.show();
|
130 |
+
Event.stop(e);
|
131 |
+
}
|
132 |
+
}
|
133 |
+
if (this.pickerActive)
|
134 |
+
return false;
|
135 |
+
},
|
136 |
+
hide: function() {
|
137 |
+
if(this.pickerActive && !this.element.disabled) {
|
138 |
+
this.datepicker.releaseKeys();
|
139 |
+
Element.remove(this.datepicker.element);
|
140 |
+
Event.stopObserving(document, 'click', this.hidePickerListener, true);
|
141 |
+
this.pickerActive = false;
|
142 |
+
Control.DatePicker.activePicker = null;
|
143 |
+
}
|
144 |
+
},
|
145 |
+
scrollOffset: function(element) {
|
146 |
+
var valueT = 0, valueL = 0;
|
147 |
+
do {
|
148 |
+
if (element.tagName == 'BODY') break;
|
149 |
+
valueT += element.scrollTop || 0;
|
150 |
+
valueL += element.scrollLeft || 0;
|
151 |
+
element = element.parentNode;
|
152 |
+
} while (element);
|
153 |
+
return Element._returnOffset(valueL, valueT);
|
154 |
+
},
|
155 |
+
show: function () {
|
156 |
+
if (!this.pickerActive) {
|
157 |
+
if (Control.DatePicker.activePicker)
|
158 |
+
Control.DatePicker.activePicker.hide();
|
159 |
+
this.element.focus();
|
160 |
+
if (!this.datepicker)
|
161 |
+
this.datepicker = new Control.DatePickerPanel(this.options);
|
162 |
+
this.originalValue = this.element.value;
|
163 |
+
|
164 |
+
// Find real page position
|
165 |
+
/*
|
166 |
+
var pos = this.element.cumulativeOffset();
|
167 |
+
if (!/MSIE 8/.test(navigator.userAgent)) {
|
168 |
+
// IE seems to account for scrollTop in offsetTop already
|
169 |
+
var scroll = this.scrollOffset(this.element);
|
170 |
+
pos[0] -= scroll[0] + document.body.scrollTop;
|
171 |
+
pos[1] -= scroll[1] + document.body.scrollLeft;
|
172 |
+
}
|
173 |
+
*/
|
174 |
+
var pos = Position.positionedOffset(this.element);
|
175 |
+
var dim = Element.getDimensions(this.element);
|
176 |
+
var pickerTop = /MSIE/.test(navigator.userAgent) ? (pos[1] + dim.height) + 'px' : (pos[1] + dim.height - 1) + 'px';
|
177 |
+
this.datepicker.element.style.position = 'absolute';
|
178 |
+
this.datepicker.element.style.top = pickerTop;
|
179 |
+
this.datepicker.element.style.left = pos[0] + 'px';
|
180 |
+
this.datepicker.element.style.zIndex = '99';
|
181 |
+
this.datepicker.selectDate(DateFormat.parseFormat(this.element.value, this.options.currentFormat));
|
182 |
+
this.datepicker.captureKeys();
|
183 |
+
|
184 |
+
this.element.parentNode.appendChild(this.datepicker.element);
|
185 |
+
Event.observe(document, 'click', this.hidePickerListener, true);
|
186 |
+
this.pickerActive = true;
|
187 |
+
Control.DatePicker.activePicker = this;
|
188 |
+
this.pickerClicked();
|
189 |
+
}
|
190 |
+
}
|
191 |
+
};
|
192 |
+
|
193 |
+
Control.DatePicker.i18n = Class.create();
|
194 |
+
Object.extend(Control.DatePicker.i18n, {
|
195 |
+
baseLocales: {
|
196 |
+
'us': {
|
197 |
+
dateTimeFormat: 'MM-dd-yyyy HH:mm',
|
198 |
+
dateFormat: 'MM-dd-yyyy',
|
199 |
+
firstWeekDay: 0,
|
200 |
+
weekend: [0,6],
|
201 |
+
timeFormat: 'HH:mm'
|
202 |
+
},
|
203 |
+
'eu': {
|
204 |
+
dateTimeFormat: 'dd-MM-yyyy HH:mm',
|
205 |
+
dateFormat: 'dd-MM-yyyy',
|
206 |
+
firstWeekDay: 1,
|
207 |
+
weekend: [0,6],
|
208 |
+
timeFormat: 'HH:mm'
|
209 |
+
},
|
210 |
+
'iso8601': {
|
211 |
+
dateTimeFormat: 'yyyy-MM-dd HH:mm',
|
212 |
+
dateFormat: 'yyyy-MM-dd',
|
213 |
+
firstWeekDay: 1,
|
214 |
+
weekend: [0,6],
|
215 |
+
timeFormat: 'HH:mm'
|
216 |
+
}
|
217 |
+
},
|
218 |
+
createLocale: function(base, lang) {
|
219 |
+
return Object.extend(Object.clone(Control.DatePicker.i18n.baseLocales[base]), {'language': lang});
|
220 |
+
}
|
221 |
+
});
|
222 |
+
Control.DatePicker.i18n.prototype = {
|
223 |
+
initialize: function(code) {
|
224 |
+
var lang = code.charAt(2) == '_' ? code.substring(0,2) : code;
|
225 |
+
var locale = (Control.DatePicker.Locale[code] || Control.DatePicker.Locale[lang]);
|
226 |
+
this.opts = Object.clone(locale || {});
|
227 |
+
var language = locale ? Control.DatePicker.Language[locale.language] : null;
|
228 |
+
if (language) Object.extend(this.opts, language);
|
229 |
+
},
|
230 |
+
opts: null,
|
231 |
+
inheritOptions: function(options) {
|
232 |
+
if (!this.opts) this.setLocale('en_US');
|
233 |
+
return Object.extend(this.opts, options || {});
|
234 |
+
},
|
235 |
+
tr: function(str) {
|
236 |
+
return this.opts && this.opts.strings ? this.opts.strings[str] || str : str;
|
237 |
+
}
|
238 |
+
};
|
239 |
+
|
240 |
+
Control.DatePicker.Locale = {};
|
241 |
+
with (Control.DatePicker) {
|
242 |
+
// Full locale definitions not needed if countries use the language default format
|
243 |
+
// Datepicker will fallback to the language default; i.e. 'es_AR' will use 'es'
|
244 |
+
Locale['es'] = i18n.createLocale('eu', 'es');
|
245 |
+
Locale['en'] = i18n.createLocale('us', 'en');
|
246 |
+
Locale['en_GB'] = i18n.createLocale('eu', 'en');
|
247 |
+
Locale['en_AU'] = Locale['en_GB'];
|
248 |
+
Locale['de'] = i18n.createLocale('eu', 'de');
|
249 |
+
Locale['es_iso8601'] = i18n.createLocale('iso8601', 'es');
|
250 |
+
Locale['en_iso8601'] = i18n.createLocale('iso8601', 'en');
|
251 |
+
Locale['de_iso8601'] = i18n.createLocale('iso8601', 'de');
|
252 |
+
}
|
253 |
+
|
254 |
+
Control.DatePicker.Language = {
|
255 |
+
'es': {
|
256 |
+
months: ['Enero', 'Febrero', 'Marzo', 'Abril', 'Mayo', 'Junio', 'Julio', 'Augosto', 'Septiembre', 'Octubre', 'Novimbre', 'Diciembre'],
|
257 |
+
days: ['Do', 'Lu', 'Ma', 'Mi', 'Ju', 'Vi', 'Sa'],
|
258 |
+
strings: {
|
259 |
+
'Now': 'Ahora',
|
260 |
+
'Today': 'Hoy',
|
261 |
+
'Time': 'Hora',
|
262 |
+
'Exact minutes': 'Minuto exacto',
|
263 |
+
'Select Date and Time': 'Selecciona Dia y Hora',
|
264 |
+
'Select Time': 'Selecciona Hora',
|
265 |
+
'Open calendar': 'Abre calendario'
|
266 |
+
}
|
267 |
+
},
|
268 |
+
'de': {
|
269 |
+
months: ['Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember'],
|
270 |
+
days: ['So', 'Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa'],
|
271 |
+
strings: {
|
272 |
+
'Now': 'Jetzt',
|
273 |
+
'Today': 'Heute',
|
274 |
+
'Time': 'Zeit',
|
275 |
+
'Exact minutes': 'Exakte minuten',
|
276 |
+
'Select Date and Time': 'Zeit und Datum Auswählen',
|
277 |
+
'Select Time': 'Zeit Auswählen',
|
278 |
+
'Open calendar': 'Kalender öffnen'
|
279 |
+
}
|
280 |
+
}
|
281 |
+
};
|
282 |
+
|
283 |
+
Control.DatePickerPanel = Class.create();
|
284 |
+
Object.extend(Control.DatePickerPanel.prototype, {
|
285 |
+
initialize: function(options) {
|
286 |
+
this.i18n = new Control.DatePicker.i18n(options && options.locale ? options.locale : 'en_US');
|
287 |
+
options = this.i18n.inheritOptions(options);
|
288 |
+
this.options = Object.extend({
|
289 |
+
className: 'datepickerControl',
|
290 |
+
closeOnToday: true,
|
291 |
+
selectToday: true,
|
292 |
+
showOnFocus: false,
|
293 |
+
datePicker: true,
|
294 |
+
timePicker: false,
|
295 |
+
use24hrs: false,
|
296 |
+
firstWeekDay: 0,
|
297 |
+
weekend: [0,6],
|
298 |
+
months: ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'],
|
299 |
+
days: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']
|
300 |
+
}, options || {});
|
301 |
+
// Make sure first weekday is in the correct range
|
302 |
+
with (this.options)
|
303 |
+
if (isNaN(firstWeekDay*1)) firstWeekDay = 0;
|
304 |
+
else firstWeekDay = firstWeekDay % 7;
|
305 |
+
|
306 |
+
this.keysCaptured = false;
|
307 |
+
this.calendarCont = null;
|
308 |
+
this.currentDate = this.options.date ? this.options.date : new Date();
|
309 |
+
this.dayOfWeek = 0;
|
310 |
+
this.minInterval = 5;
|
311 |
+
|
312 |
+
this.selectedDay = null;
|
313 |
+
this.selectedHour = null;
|
314 |
+
this.selectedMinute = null;
|
315 |
+
this.selectedAmPm = null;
|
316 |
+
|
317 |
+
this.currentDays = [];
|
318 |
+
this.hourCells = [];
|
319 |
+
this.minuteCells = [];
|
320 |
+
this.otherMinutes = null;
|
321 |
+
this.amCell = null;
|
322 |
+
this.pmCell = null;
|
323 |
+
|
324 |
+
this.element = this.createPicker();
|
325 |
+
this.selectDate(this.currentDate);
|
326 |
+
},
|
327 |
+
createPicker: function() {
|
328 |
+
var elt = document.createElement('div');
|
329 |
+
elt.style.position = 'absolute';
|
330 |
+
elt.className = this.options.className;
|
331 |
+
this.calendarCont = this.drawCalendar(elt, this.currentDate);
|
332 |
+
|
333 |
+
Event.observe(elt, 'click', this.clickHandler.bindAsEventListener(this));
|
334 |
+
Event.observe(elt, 'dblclick', this.dblClickHandler.bindAsEventListener(this));
|
335 |
+
this.documentKeyListener = this.keyHandler.bindAsEventListener(this);
|
336 |
+
if (this.options.captureKeys)
|
337 |
+
this.captureKeys();
|
338 |
+
|
339 |
+
return elt;
|
340 |
+
},
|
341 |
+
tr: function(str) {
|
342 |
+
return this.i18n.tr(str);
|
343 |
+
},
|
344 |
+
captureKeys: function() {
|
345 |
+
Event.observe(document, 'keydown', this.documentKeyListener, true);
|
346 |
+
this.keysCaptured = true;
|
347 |
+
},
|
348 |
+
releaseKeys: function() {
|
349 |
+
Event.stopObserving(document, 'keydown', this.documentKeyListener, true);
|
350 |
+
this.keysCaptured = false;
|
351 |
+
},
|
352 |
+
setDate: function(date) {
|
353 |
+
if (date) {
|
354 |
+
// Clear container
|
355 |
+
while (this.element.firstChild)
|
356 |
+
this.element.removeChild(this.element.firstChild);
|
357 |
+
this.calendarCont = this.drawCalendar(this.element, date);
|
358 |
+
}
|
359 |
+
},
|
360 |
+
drawCalendar: function(container, date) {
|
361 |
+
var calCont = container;
|
362 |
+
if (!this.options.datePicker) {
|
363 |
+
var calTable = document.createElement('table');
|
364 |
+
calTable.cellSpacing = 0;
|
365 |
+
calTable.cellPadding = 0;
|
366 |
+
calTable.border = 0;
|
367 |
+
} else {
|
368 |
+
var calTable = this.createCalendar(date);
|
369 |
+
}
|
370 |
+
|
371 |
+
var rowwidth = this.options.use24hrs ? 6 : 7;
|
372 |
+
if (this.options.timePicker) {
|
373 |
+
var timeTable;
|
374 |
+
if (this.options.timePickerAdjacent && this.options.datePicker) {
|
375 |
+
var rows = 0;
|
376 |
+
|
377 |
+
var adjTable = document.createElement('table');
|
378 |
+
adjTable.cellSpacing = 0;
|
379 |
+
adjTable.cellPadding = 0;
|
380 |
+
adjTable.border = 0;
|
381 |
+
|
382 |
+
row = adjTable.insertRow(0);
|
383 |
+
|
384 |
+
cell = row.insertCell(0);
|
385 |
+
cell.vAlign = 'top';
|
386 |
+
cell.appendChild(calTable);
|
387 |
+
calCont = cell;
|
388 |
+
|
389 |
+
cell = row.insertCell(1);
|
390 |
+
cell.style.width = '5px';
|
391 |
+
|
392 |
+
cell = row.insertCell(2);
|
393 |
+
cell.vAlign = 'top';
|
394 |
+
timeTable = document.createElement('table');
|
395 |
+
timeTable.cellSpacing = 0;
|
396 |
+
timeTable.cellPadding = 0;
|
397 |
+
timeTable.border = 0;
|
398 |
+
cell.appendChild(timeTable);
|
399 |
+
|
400 |
+
container.appendChild(adjTable);
|
401 |
+
|
402 |
+
row = timeTable.insertRow(rows++);
|
403 |
+
row.className = 'monthLabel';
|
404 |
+
cell = row.insertCell(0);
|
405 |
+
cell.colSpan = rowwidth;
|
406 |
+
cell.innerHTML = this.tr('Time');
|
407 |
+
|
408 |
+
row = timeTable.insertRow(rows++);
|
409 |
+
cell = row.insertCell(0);
|
410 |
+
cell.colSpan = rowwidth;
|
411 |
+
cell.style.height = '1px';
|
412 |
+
|
413 |
+
} else {
|
414 |
+
container.appendChild(calTable);
|
415 |
+
timeTable = calTable;
|
416 |
+
var rows = calTable.rows.length;
|
417 |
+
|
418 |
+
if (this.options.datePicker) {
|
419 |
+
row = timeTable.insertRow(rows++);
|
420 |
+
cell = row.insertCell(0);
|
421 |
+
cell.colSpan = rowwidth;
|
422 |
+
|
423 |
+
var hr = document.createElement('hr');
|
424 |
+
Element.setStyle(hr, {'color': 'gray', 'backgroundColor': 'gray', 'height': '1px', 'border': '0', 'marginTop': '3px', 'marginBottom': '3px', 'padding': '0'});
|
425 |
+
cell.appendChild(hr);
|
426 |
+
}
|
427 |
+
}
|
428 |
+
|
429 |
+
var hourrows = this.options.use24hrs ? 4 : 2;
|
430 |
+
for (var j = 0; j < hourrows; ++j) {
|
431 |
+
row = timeTable.insertRow(rows++);
|
432 |
+
for (var i = 0; i < 6; ++i){
|
433 |
+
cell = row.insertCell(i);
|
434 |
+
cell.className = 'hour';
|
435 |
+
cell.width = '14%';
|
436 |
+
cell.innerHTML = (j*6)+i+(this.options.use24hrs?0:1);
|
437 |
+
cell.onclick = this.hourClickedListener((j*6)+i+(this.options.use24hrs?0:1));
|
438 |
+
this.hourCells[(j*6)+i] = cell;
|
439 |
+
}
|
440 |
+
if (!this.options.use24hrs) {
|
441 |
+
cell = row.insertCell(i);
|
442 |
+
cell.className = 'ampm';
|
443 |
+
cell.width = '14%';
|
444 |
+
if (j) {
|
445 |
+
cell.innerHTML = this.tr('PM');
|
446 |
+
cell.onclick = this.pmClickedListener();
|
447 |
+
this.pmCell = cell;
|
448 |
+
} else {
|
449 |
+
cell.innerHTML = this.tr('AM');
|
450 |
+
cell.onclick = this.amClickedListener();
|
451 |
+
this.amCell = cell;
|
452 |
+
}
|
453 |
+
}
|
454 |
+
}
|
455 |
+
|
456 |
+
row = timeTable.insertRow(rows++);
|
457 |
+
cell = row.insertCell(0);
|
458 |
+
cell.colSpan = 6;
|
459 |
+
|
460 |
+
var hr = document.createElement('hr');
|
461 |
+
Element.setStyle(hr, {'color': '#CCCCCC', 'backgroundColor': '#CCCCCC', 'height': '1px', 'border': '0', 'marginTop': '2px', 'marginBottom': '2px', 'padding': '0'});
|
462 |
+
cell.appendChild(hr);
|
463 |
+
cell = row.insertCell(1);
|
464 |
+
|
465 |
+
for (var j = 0; j < (10/this.minInterval); ++j) {
|
466 |
+
row = timeTable.insertRow(rows++);
|
467 |
+
for (var i = 0; i < 6; ++i){
|
468 |
+
cell = row.insertCell(i);
|
469 |
+
cell.className = 'minute';
|
470 |
+
cell.width = '14%';
|
471 |
+
var minval = ((j*6+i)*this.minInterval);
|
472 |
+
if (minval < 10) minval = '0'+minval;
|
473 |
+
cell.innerHTML = ':'+minval;
|
474 |
+
cell.onclick = this.minuteClickedListener(minval);
|
475 |
+
this.minuteCells[(j*6)+i] = cell;
|
476 |
+
}
|
477 |
+
if (!this.options.use24hrs) {
|
478 |
+
cell = row.insertCell(i);
|
479 |
+
cell.width = '14%';
|
480 |
+
}
|
481 |
+
}
|
482 |
+
|
483 |
+
row = timeTable.insertRow(rows++);
|
484 |
+
cell = row.insertCell(0);
|
485 |
+
cell.style.textAlign = 'right';
|
486 |
+
cell.colSpan = 5;
|
487 |
+
cell.innerHTML = '<i>'+this.tr('Exact minutes')+':</i>';
|
488 |
+
|
489 |
+
cell = row.insertCell(1);
|
490 |
+
cell.className = 'otherminute';
|
491 |
+
var otherInput = document.createElement('input');
|
492 |
+
otherInput.type = 'text';
|
493 |
+
otherInput.maxLength = 2;
|
494 |
+
otherInput.style.width = '2em';
|
495 |
+
var inputTimeout = null;
|
496 |
+
otherInput.onkeyup = function(e) {
|
497 |
+
if (!isNaN(otherInput.value)) {
|
498 |
+
inputTimeout = setTimeout(function() {
|
499 |
+
this.currentDate.setMinutes(otherInput.value);
|
500 |
+
this.dateChanged(this.currentDate);
|
501 |
+
}.bind(this), 500);
|
502 |
+
}
|
503 |
+
}.bindAsEventListener(this);
|
504 |
+
otherInput.onkeydown = function(e) {
|
505 |
+
if (e.keyCode == Event.KEY_RETURN)
|
506 |
+
if (this.options.onSelect) this.options.onSelect(this.currentDate);
|
507 |
+
if (inputTimeout)
|
508 |
+
clearTimeout(inputTimeout)
|
509 |
+
}.bindAsEventListener(this);
|
510 |
+
// Remove event key capture to allow use of arrow keys
|
511 |
+
otherInput.onclick = otherInput.select;
|
512 |
+
otherInput.onfocus = this.releaseKeys.bindAsEventListener(this);
|
513 |
+
otherInput.onblur = this.captureKeys.bindAsEventListener(this);
|
514 |
+
this.otherMinutes = otherInput;
|
515 |
+
cell.appendChild(otherInput);
|
516 |
+
// Padding cell
|
517 |
+
if (!this.options.use24hrs)
|
518 |
+
cell = row.insertCell(2);
|
519 |
+
|
520 |
+
row = timeTable.insertRow(rows++);
|
521 |
+
cell = row.insertCell(0);
|
522 |
+
cell.colSpan = rowwidth;
|
523 |
+
|
524 |
+
hr = document.createElement('hr');
|
525 |
+
Element.setStyle(hr, {'color': 'gray', 'backgroundColor': 'gray', 'height': '1px', 'border': '0', 'marginTop': '3px', 'marginBottom': '3px', 'padding': '0'});
|
526 |
+
cell.appendChild(hr);
|
527 |
+
|
528 |
+
row = timeTable.insertRow(rows++);
|
529 |
+
cell = row.insertCell(0);
|
530 |
+
cell.colSpan = rowwidth;
|
531 |
+
|
532 |
+
selectButton = document.createElement('input');
|
533 |
+
selectButton.type = 'button';
|
534 |
+
if (this.options.datePicker)
|
535 |
+
selectButton.value = this.tr('Select Date and Time');
|
536 |
+
else
|
537 |
+
selectButton.value = this.tr('Select Time');
|
538 |
+
selectButton.onclick = function(e) {
|
539 |
+
this.options.onSelect && this.options.onSelect(this.currentDate);
|
540 |
+
}.bindAsEventListener(this);
|
541 |
+
cell.appendChild(selectButton);
|
542 |
+
|
543 |
+
} else {
|
544 |
+
calCont.appendChild(calTable);
|
545 |
+
}
|
546 |
+
|
547 |
+
return calCont;
|
548 |
+
|
549 |
+
},
|
550 |
+
createCalendar: function(date) {
|
551 |
+
this.currentDate = date;
|
552 |
+
this.currentDays = [];
|
553 |
+
|
554 |
+
var today = new Date();
|
555 |
+
var previousYear = new Date(date.getFullYear() - 1, date.getMonth(), 1)
|
556 |
+
var previousMonth = new Date(date.getFullYear(), date.getMonth() - 1, 1)
|
557 |
+
var nextMonth = new Date(date.getFullYear(), date.getMonth() + 1, 1)
|
558 |
+
var nextYear = new Date(date.getFullYear() + 1, date.getMonth(), 1)
|
559 |
+
|
560 |
+
var row;
|
561 |
+
var cell;
|
562 |
+
var rows = 0;
|
563 |
+
|
564 |
+
var calTable = document.createElement('table');
|
565 |
+
calTable.cellSpacing = 0;
|
566 |
+
calTable.cellPadding = 0;
|
567 |
+
calTable.border = 0;
|
568 |
+
|
569 |
+
row = calTable.insertRow(rows++);
|
570 |
+
row.className = 'monthLabel';
|
571 |
+
cell = row.insertCell(0);
|
572 |
+
cell.colSpan = 7;
|
573 |
+
cell.innerHTML = this.monthName(date.getMonth()) + ' ' + date.getFullYear();
|
574 |
+
|
575 |
+
row = calTable.insertRow(rows++);
|
576 |
+
row.className = 'navigation';
|
577 |
+
|
578 |
+
cell = row.insertCell(0);
|
579 |
+
cell.className = 'navbutton';
|
580 |
+
cell.title = this.monthName(previousYear.getMonth()) + ' ' + previousYear.getFullYear();
|
581 |
+
cell.onclick = this.movePreviousYearListener();
|
582 |
+
cell.innerHTML = '<<';
|
583 |
+
|
584 |
+
cell = row.insertCell(1);
|
585 |
+
cell.className = 'navbutton';
|
586 |
+
cell.title = this.monthName(previousMonth.getMonth()) + ' ' + previousMonth.getFullYear();
|
587 |
+
cell.onclick = this.movePreviousMonthListener();
|
588 |
+
cell.innerHTML = '<';
|
589 |
+
|
590 |
+
cell = row.insertCell(2);
|
591 |
+
cell.colSpan = 3;
|
592 |
+
cell.className = 'navbutton';
|
593 |
+
cell.title = today.getDate() + ' ' + this.monthName(today.getMonth()) + ' ' + today.getFullYear();
|
594 |
+
cell.onclick = this.dateClickedListener(today, true);
|
595 |
+
if (this.options.timePicker)
|
596 |
+
cell.innerHTML = this.tr('Now');
|
597 |
+
else
|
598 |
+
cell.innerHTML = this.tr('Today');
|
599 |
+
|
600 |
+
cell = row.insertCell(3);
|
601 |
+
cell.className = 'navbutton';
|
602 |
+
cell.title = this.monthName(nextMonth.getMonth()) + ' ' + nextMonth.getFullYear();
|
603 |
+
cell.onclick = this.moveNextMonthListener();
|
604 |
+
cell.innerHTML = '>';
|
605 |
+
|
606 |
+
cell = row.insertCell(4);
|
607 |
+
cell.className = 'navbutton';
|
608 |
+
cell.title = this.monthName(nextYear.getMonth()) + ' ' + nextYear.getFullYear();
|
609 |
+
cell.onclick = this.moveNextYearListener();
|
610 |
+
cell.innerHTML = '>>';
|
611 |
+
|
612 |
+
row = calTable.insertRow(rows++);
|
613 |
+
row.className = 'dayLabel';
|
614 |
+
for (var i = 0; i < 7; ++i){
|
615 |
+
cell = row.insertCell(i);
|
616 |
+
cell.width = '14%';
|
617 |
+
cell.innerHTML = this.dayName((this.options.firstWeekDay + i) % 7);
|
618 |
+
}
|
619 |
+
|
620 |
+
row = null;
|
621 |
+
var workDate = new Date(date.getFullYear(), date.getMonth(), 1);
|
622 |
+
var day = workDate.getDay();
|
623 |
+
var j = 0;
|
624 |
+
|
625 |
+
// Pad with previous month
|
626 |
+
if (day != this.options.firstWeekDay) {
|
627 |
+
row = calTable.insertRow(rows++);
|
628 |
+
row.className = 'calendarRow';
|
629 |
+
workDate.setDate(workDate.getDate() - ((day - this.options.firstWeekDay + 7) % 7));
|
630 |
+
day = workDate.getDay();
|
631 |
+
while (workDate.getMonth() != date.getMonth()) {
|
632 |
+
cell = row.insertCell(row.cells.length);
|
633 |
+
this.assignDayClasses(cell, 'dayothermonth', workDate);
|
634 |
+
cell.innerHTML = workDate.getDate();
|
635 |
+
cell.onclick = this.dateClickedListener(workDate);
|
636 |
+
workDate.setDate(workDate.getDate() + 1);
|
637 |
+
day = workDate.getDay();
|
638 |
+
}
|
639 |
+
}
|
640 |
+
|
641 |
+
// Display days
|
642 |
+
while (workDate.getMonth() == date.getMonth()) {
|
643 |
+
if (day == this.options.firstWeekDay) {
|
644 |
+
row = calTable.insertRow(rows++);
|
645 |
+
row.className = 'calendarRow';
|
646 |
+
}
|
647 |
+
cell = row.insertCell(row.cells.length);
|
648 |
+
this.assignDayClasses(cell, 'day', workDate);
|
649 |
+
cell.innerHTML = workDate.getDate();
|
650 |
+
cell.onclick = this.dateClickedListener(workDate);
|
651 |
+
this.currentDays[workDate.getDate()] = cell;
|
652 |
+
workDate.setDate(workDate.getDate() + 1);
|
653 |
+
day = workDate.getDay();
|
654 |
+
}
|
655 |
+
|
656 |
+
// Pad with next month
|
657 |
+
if (day != this.options.firstWeekDay)
|
658 |
+
do {
|
659 |
+
cell = row.insertCell(row.cells.length);
|
660 |
+
this.assignDayClasses(cell, 'dayothermonth', workDate);
|
661 |
+
cell.innerHTML = workDate.getDate();
|
662 |
+
var thisDate = new Date(workDate.getTime());
|
663 |
+
cell.onclick = this.dateClickedListener(workDate);
|
664 |
+
workDate.setDate(workDate.getDate() + 1);
|
665 |
+
day = workDate.getDay();
|
666 |
+
} while (workDate.getDay() != this.options.firstWeekDay);
|
667 |
+
|
668 |
+
return calTable;
|
669 |
+
},
|
670 |
+
movePreviousMonthListener: function() {
|
671 |
+
return function(e) {
|
672 |
+
var prevMonth = new Date(
|
673 |
+
this.currentDate.getFullYear(),
|
674 |
+
this.currentDate.getMonth() - 1,
|
675 |
+
this.currentDate.getDate(),
|
676 |
+
this.currentDate.getHours(),
|
677 |
+
this.currentDate.getMinutes());
|
678 |
+
if (prevMonth.getMonth() != (this.currentDate.getMonth() + 11) % 12) prevMonth.setDate(0);
|
679 |
+
this.selectDate(prevMonth);
|
680 |
+
}.bindAsEventListener(this);
|
681 |
+
},
|
682 |
+
moveNextMonthListener: function() {
|
683 |
+
return function(e) {
|
684 |
+
var nextMonth = new Date(
|
685 |
+
this.currentDate.getFullYear(),
|
686 |
+
this.currentDate.getMonth() + 1,
|
687 |
+
this.currentDate.getDate(),
|
688 |
+
this.currentDate.getHours(),
|
689 |
+
this.currentDate.getMinutes());
|
690 |
+
if (nextMonth.getMonth() != (this.currentDate.getMonth() + 1) % 12) nextMonth.setDate(0);
|
691 |
+
this.selectDate(nextMonth);
|
692 |
+
}.bindAsEventListener(this);
|
693 |
+
},
|
694 |
+
moveNextYearListener: function() {
|
695 |
+
return function(e) {
|
696 |
+
var nextYear = new Date(
|
697 |
+
this.currentDate.getFullYear() + 1,
|
698 |
+
this.currentDate.getMonth(),
|
699 |
+
this.currentDate.getDate(),
|
700 |
+
this.currentDate.getHours(),
|
701 |
+
this.currentDate.getMinutes());
|
702 |
+
if (nextYear.getMonth() != this.currentDate.getMonth()) nextYear.setDate(0);
|
703 |
+
this.selectDate(nextYear);
|
704 |
+
}.bindAsEventListener(this);
|
705 |
+
},
|
706 |
+
movePreviousYearListener: function() {
|
707 |
+
return function(e) {
|
708 |
+
var prevYear = new Date(
|
709 |
+
this.currentDate.getFullYear() - 1,
|
710 |
+
this.currentDate.getMonth(),
|
711 |
+
this.currentDate.getDate(),
|
712 |
+
this.currentDate.getHours(),
|
713 |
+
this.currentDate.getMinutes());
|
714 |
+
if (prevYear.getMonth() != this.currentDate.getMonth()) prevYear.setDate(0);
|
715 |
+
this.selectDate(prevYear);
|
716 |
+
}.bindAsEventListener(this);
|
717 |
+
},
|
718 |
+
dateClickedListener: function(date, timeOverride) {
|
719 |
+
var dateCopy = new Date(date.getTime());
|
720 |
+
return function(e) {
|
721 |
+
if (!timeOverride) {
|
722 |
+
dateCopy.setHours(this.currentDate.getHours());
|
723 |
+
dateCopy.setMinutes(this.currentDate.getMinutes());
|
724 |
+
}
|
725 |
+
this.dateClicked(dateCopy);
|
726 |
+
}.bindAsEventListener(this);
|
727 |
+
},
|
728 |
+
hourClickedListener: function(hour) {
|
729 |
+
return function(e) {
|
730 |
+
this.hourClicked(hour);
|
731 |
+
}.bindAsEventListener(this);
|
732 |
+
},
|
733 |
+
minuteClickedListener: function(minutes) {
|
734 |
+
return function(e) {
|
735 |
+
this.currentDate.setMinutes(minutes);
|
736 |
+
this.dateClicked(this.currentDate);
|
737 |
+
}.bindAsEventListener(this);
|
738 |
+
},
|
739 |
+
amClickedListener: function() {
|
740 |
+
return function(e) {
|
741 |
+
if (this.selectedAmPm == this.pmCell) {
|
742 |
+
this.currentDate.setHours(this.currentDate.getHours()-12);
|
743 |
+
this.dateClicked(this.currentDate);
|
744 |
+
}
|
745 |
+
}.bindAsEventListener(this);
|
746 |
+
},
|
747 |
+
pmClickedListener: function() {
|
748 |
+
return function(e) {
|
749 |
+
if (this.selectedAmPm == this.amCell) {
|
750 |
+
this.currentDate.setHours(this.currentDate.getHours()+12);
|
751 |
+
this.dateClicked(this.currentDate);
|
752 |
+
}
|
753 |
+
}.bindAsEventListener(this);
|
754 |
+
},
|
755 |
+
assignDayClasses: function(cell, baseClass, date) {
|
756 |
+
var today = new Date();
|
757 |
+
Element.addClassName(cell, baseClass);
|
758 |
+
if (date.getFullYear() == today.getFullYear() && date.getMonth() == today.getMonth() && date.getDate() == today.getDate())
|
759 |
+
Element.addClassName(cell, 'today');
|
760 |
+
if (this.options.weekend.include(date.getDay()))
|
761 |
+
Element.addClassName(cell, 'weekend');
|
762 |
+
},
|
763 |
+
monthName: function(month) {
|
764 |
+
return this.options.months[month];
|
765 |
+
},
|
766 |
+
dayName: function(day) {
|
767 |
+
return this.options.days[day];
|
768 |
+
},
|
769 |
+
dblClickHandler: function(e) {
|
770 |
+
if(this.options.onSelect)
|
771 |
+
this.options.onSelect(this.currentDate);
|
772 |
+
Event.stop(e);
|
773 |
+
},
|
774 |
+
clickHandler: function(e) {
|
775 |
+
if(this.options.onClick)
|
776 |
+
this.options.onClick();
|
777 |
+
Event.stop(e);
|
778 |
+
},
|
779 |
+
hoverHandler: function(e) {
|
780 |
+
if(this.options.onHover)
|
781 |
+
this.options.onHover(date);
|
782 |
+
},
|
783 |
+
keyHandler: function(e) {
|
784 |
+
var days = 0;
|
785 |
+
switch (e.keyCode){
|
786 |
+
case Event.KEY_RETURN:
|
787 |
+
if (this.options.onSelect) this.options.onSelect(this.currentDate);
|
788 |
+
break;
|
789 |
+
case Event.KEY_LEFT:
|
790 |
+
days = -1;
|
791 |
+
break;
|
792 |
+
case Event.KEY_UP:
|
793 |
+
days = -7;
|
794 |
+
break;
|
795 |
+
case Event.KEY_RIGHT:
|
796 |
+
days = 1;
|
797 |
+
break;
|
798 |
+
case Event.KEY_DOWN:
|
799 |
+
days = 7;
|
800 |
+
break;
|
801 |
+
case 33: // PgUp
|
802 |
+
var lastMonth = new Date(this.currentDate.getFullYear(), this.currentDate.getMonth() - 1, this.currentDate.getDate());
|
803 |
+
days = -this.getDaysOfMonth(lastMonth);
|
804 |
+
break;
|
805 |
+
case 34: // PgDn
|
806 |
+
days = this.getDaysOfMonth(this.currentDate);
|
807 |
+
break;
|
808 |
+
case 13: // enter-key (forms without submit buttons)
|
809 |
+
this.dateClicked(this.currentDate);
|
810 |
+
break;
|
811 |
+
default:
|
812 |
+
return;
|
813 |
+
}
|
814 |
+
if (days != 0) {
|
815 |
+
var moveDate = new Date(this.currentDate.getFullYear(), this.currentDate.getMonth(), this.currentDate.getDate() + days);
|
816 |
+
moveDate.setHours(this.currentDate.getHours());
|
817 |
+
moveDate.setMinutes(this.currentDate.getMinutes());
|
818 |
+
this.selectDate(moveDate);
|
819 |
+
}
|
820 |
+
Event.stop(e);
|
821 |
+
return false;
|
822 |
+
},
|
823 |
+
getDaysOfMonth: function(date) {
|
824 |
+
var lastDay = new Date(date.getFullYear(), date.getMonth() + 1, 0);
|
825 |
+
return lastDay.getDate();
|
826 |
+
},
|
827 |
+
getNextMonth: function(month, year, increment) {
|
828 |
+
if (p_Month == 11) return [0, year + 1];
|
829 |
+
else return [month + 1, year];
|
830 |
+
},
|
831 |
+
getPrevMonth: function(month, year, increment) {
|
832 |
+
if (p_Month == 0) return [11, year - 1];
|
833 |
+
else return [month - 1, year];
|
834 |
+
},
|
835 |
+
dateClicked: function(date) {
|
836 |
+
if (date) {
|
837 |
+
if (!this.options.timePicker && this.options.onSelect)
|
838 |
+
this.options.onSelect(date);
|
839 |
+
this.selectDate(date);
|
840 |
+
}
|
841 |
+
},
|
842 |
+
dateChanged: function(date) {
|
843 |
+
if (date) {
|
844 |
+
if ((!this.options.timePicker || !this.options.datePicker) && this.options.onHover)
|
845 |
+
this.options.onHover(date);
|
846 |
+
this.selectDate(date);
|
847 |
+
}
|
848 |
+
},
|
849 |
+
hourClicked: function(hour) {
|
850 |
+
if (!this.options.use24hrs) {
|
851 |
+
if (hour == 12) {
|
852 |
+
if (this.selectedAmPm == this.amCell)
|
853 |
+
hour = 0;
|
854 |
+
} else if (this.selectedAmPm == this.pmCell) {
|
855 |
+
hour += 12;
|
856 |
+
}
|
857 |
+
}
|
858 |
+
this.currentDate.setHours(hour);
|
859 |
+
this.dateClicked(this.currentDate);
|
860 |
+
},
|
861 |
+
selectDate: function(date) {
|
862 |
+
if (date) {
|
863 |
+
if (this.options.datePicker) {
|
864 |
+
if (date.getMonth() != this.currentDate.getMonth()
|
865 |
+
|| date.getFullYear() != this.currentDate.getFullYear())
|
866 |
+
this.setDate(date);
|
867 |
+
else
|
868 |
+
this.currentDate = date;
|
869 |
+
|
870 |
+
if (date.getDate() < this.currentDays.length) {
|
871 |
+
if (this.selectedDay)
|
872 |
+
Element.removeClassName(this.selectedDay, 'current');
|
873 |
+
this.selectedDay = this.currentDays[date.getDate()];
|
874 |
+
Element.addClassName(this.selectedDay, 'current');
|
875 |
+
}
|
876 |
+
}
|
877 |
+
|
878 |
+
if (this.options.timePicker) {
|
879 |
+
var hours = date.getHours();
|
880 |
+
if (this.selectedHour)
|
881 |
+
Element.removeClassName(this.selectedHour, 'current');
|
882 |
+
if (this.options.use24hrs)
|
883 |
+
this.selectedHour = this.hourCells[hours];
|
884 |
+
else
|
885 |
+
this.selectedHour = this.hourCells[hours % 12 ? (hours % 12) - 1 : 11];
|
886 |
+
Element.addClassName(this.selectedHour, 'current');
|
887 |
+
|
888 |
+
if (this.selectedAmPm)
|
889 |
+
Element.removeClassName(this.selectedAmPm, 'current');
|
890 |
+
this.selectedAmPm = (hours < 12 ? this.amCell : this.pmCell);
|
891 |
+
Element.addClassName(this.selectedAmPm, 'current');
|
892 |
+
|
893 |
+
var minutes = date.getMinutes();
|
894 |
+
if (this.selectedMinute)
|
895 |
+
Element.removeClassName(this.selectedMinute, 'current');
|
896 |
+
Element.removeClassName(this.otherMinutes, 'current');
|
897 |
+
if (minutes % this.minInterval == 0) {
|
898 |
+
this.otherMinutes.value = '';
|
899 |
+
this.selectedMinute = this.minuteCells[minutes / this.minInterval];
|
900 |
+
Element.addClassName(this.selectedMinute, 'current');
|
901 |
+
} else {
|
902 |
+
this.otherMinutes.value = minutes;
|
903 |
+
Element.addClassName(this.otherMinutes, 'current');
|
904 |
+
}
|
905 |
+
}
|
906 |
+
|
907 |
+
if (this.options.onHover)
|
908 |
+
this.options.onHover(date);
|
909 |
+
}
|
910 |
+
}
|
911 |
+
});
|
js/ayasoftware/prototype-1.6.0.2.js
ADDED
@@ -0,0 +1,4222 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* Prototype JavaScript framework, version 1.6.0.2
|
2 |
+
* (c) 2005-2008 Sam Stephenson
|
3 |
+
*
|
4 |
+
* Prototype is freely distributable under the terms of an MIT-style license.
|
5 |
+
* For details, see the Prototype web site: http://www.prototypejs.org/
|
6 |
+
*
|
7 |
+
*--------------------------------------------------------------------------*/
|
8 |
+
|
9 |
+
var Prototype = {
|
10 |
+
Version: '1.6.0.2',
|
11 |
+
|
12 |
+
Browser: {
|
13 |
+
IE: !!(window.attachEvent && !window.opera),
|
14 |
+
Opera: !!window.opera,
|
15 |
+
WebKit: navigator.userAgent.indexOf('AppleWebKit/') > -1,
|
16 |
+
Gecko: navigator.userAgent.indexOf('Gecko') > -1 && navigator.userAgent.indexOf('KHTML') == -1,
|
17 |
+
MobileSafari: !!navigator.userAgent.match(/Apple.*Mobile.*Safari/)
|
18 |
+
},
|
19 |
+
|
20 |
+
BrowserFeatures: {
|
21 |
+
XPath: !!document.evaluate,
|
22 |
+
ElementExtensions: !!window.HTMLElement,
|
23 |
+
SpecificElementExtensions:
|
24 |
+
document.createElement('div').__proto__ &&
|
25 |
+
document.createElement('div').__proto__ !==
|
26 |
+
document.createElement('form').__proto__
|
27 |
+
},
|
28 |
+
|
29 |
+
ScriptFragment: '<script[^>]*>([\\S\\s]*?)<\/script>',
|
30 |
+
JSONFilter: /^\/\*-secure-([\s\S]*)\*\/\s*$/,
|
31 |
+
|
32 |
+
emptyFunction: function() { },
|
33 |
+
K: function(x) { return x }
|
34 |
+
};
|
35 |
+
|
36 |
+
if (Prototype.Browser.MobileSafari)
|
37 |
+
Prototype.BrowserFeatures.SpecificElementExtensions = false;
|
38 |
+
|
39 |
+
|
40 |
+
/* Based on Alex Arnell's inheritance implementation. */
|
41 |
+
var Class = {
|
42 |
+
create: function() {
|
43 |
+
var parent = null, properties = $A(arguments);
|
44 |
+
if (Object.isFunction(properties[0]))
|
45 |
+
parent = properties.shift();
|
46 |
+
|
47 |
+
function klass() {
|
48 |
+
this.initialize.apply(this, arguments);
|
49 |
+
}
|
50 |
+
|
51 |
+
Object.extend(klass, Class.Methods);
|
52 |
+
klass.superclass = parent;
|
53 |
+
klass.subclasses = [];
|
54 |
+
|
55 |
+
if (parent) {
|
56 |
+
var subclass = function() { };
|
57 |
+
subclass.prototype = parent.prototype;
|
58 |
+
klass.prototype = new subclass;
|
59 |
+
parent.subclasses.push(klass);
|
60 |
+
}
|
61 |
+
|
62 |
+
for (var i = 0; i < properties.length; i++)
|
63 |
+
klass.addMethods(properties[i]);
|
64 |
+
|
65 |
+
if (!klass.prototype.initialize)
|
66 |
+
klass.prototype.initialize = Prototype.emptyFunction;
|
67 |
+
|
68 |
+
klass.prototype.constructor = klass;
|
69 |
+
|
70 |
+
return klass;
|
71 |
+
}
|
72 |
+
};
|
73 |
+
|
74 |
+
Class.Methods = {
|
75 |
+
addMethods: function(source) {
|
76 |
+
var ancestor = this.superclass && this.superclass.prototype;
|
77 |
+
var properties = Object.keys(source);
|
78 |
+
|
79 |
+
if (!Object.keys({ toString: true }).length)
|
80 |
+
properties.push("toString", "valueOf");
|
81 |
+
|
82 |
+
for (var i = 0, length = properties.length; i < length; i++) {
|
83 |
+
var property = properties[i], value = source[property];
|
84 |
+
if (ancestor && Object.isFunction(value) &&
|
85 |
+
value.argumentNames().first() == "$super") {
|
86 |
+
var method = value, value = Object.extend((function(m) {
|
87 |
+
return function() { return ancestor[m].apply(this, arguments) };
|
88 |
+
})(property).wrap(method), {
|
89 |
+
valueOf: function() { return method },
|
90 |
+
toString: function() { return method.toString() }
|
91 |
+
});
|
92 |
+
}
|
93 |
+
this.prototype[property] = value;
|
94 |
+
}
|
95 |
+
|
96 |
+
return this;
|
97 |
+
}
|
98 |
+
};
|
99 |
+
|
100 |
+
var Abstract = { };
|
101 |
+
|
102 |
+
Object.extend = function(destination, source) {
|
103 |
+
for (var property in source)
|
104 |
+
destination[property] = source[property];
|
105 |
+
return destination;
|
106 |
+
};
|
107 |
+
|
108 |
+
Object.extend(Object, {
|
109 |
+
inspect: function(object) {
|
110 |
+
try {
|
111 |
+
if (Object.isUndefined(object)) return 'undefined';
|
112 |
+
if (object === null) return 'null';
|
113 |
+
return object.inspect ? object.inspect() : String(object);
|
114 |
+
} catch (e) {
|
115 |
+
if (e instanceof RangeError) return '...';
|
116 |
+
throw e;
|
117 |
+
}
|
118 |
+
},
|
119 |
+
|
120 |
+
toJSON: function(object) {
|
121 |
+
var type = typeof object;
|
122 |
+
switch (type) {
|
123 |
+
case 'undefined':
|
124 |
+
case 'function':
|
125 |
+
case 'unknown': return;
|
126 |
+
case 'boolean': return object.toString();
|
127 |
+
}
|
128 |
+
|
129 |
+
if (object === null) return 'null';
|
130 |
+
if (object.toJSON) return object.toJSON();
|
131 |
+
if (Object.isElement(object)) return;
|
132 |
+
|
133 |
+
var results = [];
|
134 |
+
for (var property in object) {
|
135 |
+
var value = Object.toJSON(object[property]);
|
136 |
+
if (!Object.isUndefined(value))
|
137 |
+
results.push(property.toJSON() + ': ' + value);
|
138 |
+
}
|
139 |
+
|
140 |
+
return '{' + results.join(', ') + '}';
|
141 |
+
},
|
142 |
+
|
143 |
+
toQueryString: function(object) {
|
144 |
+
return $H(object).toQueryString();
|
145 |
+
},
|
146 |
+
|
147 |
+
toHTML: function(object) {
|
148 |
+
return object && object.toHTML ? object.toHTML() : String.interpret(object);
|
149 |
+
},
|
150 |
+
|
151 |
+
keys: function(object) {
|
152 |
+
var keys = [];
|
153 |
+
for (var property in object)
|
154 |
+
keys.push(property);
|
155 |
+
return keys;
|
156 |
+
},
|
157 |
+
|
158 |
+
values: function(object) {
|
159 |
+
var values = [];
|
160 |
+
for (var property in object)
|
161 |
+
values.push(object[property]);
|
162 |
+
return values;
|
163 |
+
},
|
164 |
+
|
165 |
+
clone: function(object) {
|
166 |
+
return Object.extend({ }, object);
|
167 |
+
},
|
168 |
+
|
169 |
+
isElement: function(object) {
|
170 |
+
return object && object.nodeType == 1;
|
171 |
+
},
|
172 |
+
|
173 |
+
isArray: function(object) {
|
174 |
+
return object != null && typeof object == "object" &&
|
175 |
+
'splice' in object && 'join' in object;
|
176 |
+
},
|
177 |
+
|
178 |
+
isHash: function(object) {
|
179 |
+
return object instanceof Hash;
|
180 |
+
},
|
181 |
+
|
182 |
+
isFunction: function(object) {
|
183 |
+
return typeof object == "function";
|
184 |
+
},
|
185 |
+
|
186 |
+
isString: function(object) {
|
187 |
+
return typeof object == "string";
|
188 |
+
},
|
189 |
+
|
190 |
+
isNumber: function(object) {
|
191 |
+
return typeof object == "number";
|
192 |
+
},
|
193 |
+
|
194 |
+
isUndefined: function(object) {
|
195 |
+
return typeof object == "undefined";
|
196 |
+
}
|
197 |
+
});
|
198 |
+
|
199 |
+
Object.extend(Function.prototype, {
|
200 |
+
argumentNames: function() {
|
201 |
+
var names = this.toString().match(/^[\s\(]*function[^(]*\((.*?)\)/)[1].split(",").invoke("strip");
|
202 |
+
return names.length == 1 && !names[0] ? [] : names;
|
203 |
+
},
|
204 |
+
|
205 |
+
bind: function() {
|
206 |
+
if (arguments.length < 2 && Object.isUndefined(arguments[0])) return this;
|
207 |
+
var __method = this, args = $A(arguments), object = args.shift();
|
208 |
+
return function() {
|
209 |
+
return __method.apply(object, args.concat($A(arguments)));
|
210 |
+
}
|
211 |
+
},
|
212 |
+
|
213 |
+
bindAsEventListener: function() {
|
214 |
+
var __method = this, args = $A(arguments), object = args.shift();
|
215 |
+
return function(event) {
|
216 |
+
return __method.apply(object, [event || window.event].concat(args));
|
217 |
+
}
|
218 |
+
},
|
219 |
+
|
220 |
+
curry: function() {
|
221 |
+
if (!arguments.length) return this;
|
222 |
+
var __method = this, args = $A(arguments);
|
223 |
+
return function() {
|
224 |
+
return __method.apply(this, args.concat($A(arguments)));
|
225 |
+
}
|
226 |
+
},
|
227 |
+
|
228 |
+
delay: function() {
|
229 |
+
var __method = this, args = $A(arguments), timeout = args.shift() * 1000;
|
230 |
+
return window.setTimeout(function() {
|
231 |
+
return __method.apply(__method, args);
|
232 |
+
}, timeout);
|
233 |
+
},
|
234 |
+
|
235 |
+
wrap: function(wrapper) {
|
236 |
+
var __method = this;
|
237 |
+
return function() {
|
238 |
+
return wrapper.apply(this, [__method.bind(this)].concat($A(arguments)));
|
239 |
+
}
|
240 |
+
},
|
241 |
+
|
242 |
+
methodize: function() {
|
243 |
+
if (this._methodized) return this._methodized;
|
244 |
+
var __method = this;
|
245 |
+
return this._methodized = function() {
|
246 |
+
return __method.apply(null, [this].concat($A(arguments)));
|
247 |
+
};
|
248 |
+
}
|
249 |
+
});
|
250 |
+
|
251 |
+
Function.prototype.defer = Function.prototype.delay.curry(0.01);
|
252 |
+
|
253 |
+
Date.prototype.toJSON = function() {
|
254 |
+
return '"' + this.getUTCFullYear() + '-' +
|
255 |
+
(this.getUTCMonth() + 1).toPaddedString(2) + '-' +
|
256 |
+
this.getUTCDate().toPaddedString(2) + 'T' +
|
257 |
+
this.getUTCHours().toPaddedString(2) + ':' +
|
258 |
+
this.getUTCMinutes().toPaddedString(2) + ':' +
|
259 |
+
this.getUTCSeconds().toPaddedString(2) + 'Z"';
|
260 |
+
};
|
261 |
+
|
262 |
+
var Try = {
|
263 |
+
these: function() {
|
264 |
+
var returnValue;
|
265 |
+
|
266 |
+
for (var i = 0, length = arguments.length; i < length; i++) {
|
267 |
+
var lambda = arguments[i];
|
268 |
+
try {
|
269 |
+
returnValue = lambda();
|
270 |
+
break;
|
271 |
+
} catch (e) { }
|
272 |
+
}
|
273 |
+
|
274 |
+
return returnValue;
|
275 |
+
}
|
276 |
+
};
|
277 |
+
|
278 |
+
RegExp.prototype.match = RegExp.prototype.test;
|
279 |
+
|
280 |
+
RegExp.escape = function(str) {
|
281 |
+
return String(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
|
282 |
+
};
|
283 |
+
|
284 |
+
/*--------------------------------------------------------------------------*/
|
285 |
+
|
286 |
+
var PeriodicalExecuter = Class.create({
|
287 |
+
initialize: function(callback, frequency) {
|
288 |
+
this.callback = callback;
|
289 |
+
this.frequency = frequency;
|
290 |
+
this.currentlyExecuting = false;
|
291 |
+
|
292 |
+
this.registerCallback();
|
293 |
+
},
|
294 |
+
|
295 |
+
registerCallback: function() {
|
296 |
+
this.timer = setInterval(this.onTimerEvent.bind(this), this.frequency * 1000);
|
297 |
+
},
|
298 |
+
|
299 |
+
execute: function() {
|
300 |
+
this.callback(this);
|
301 |
+
},
|
302 |
+
|
303 |
+
stop: function() {
|
304 |
+
if (!this.timer) return;
|
305 |
+
clearInterval(this.timer);
|
306 |
+
this.timer = null;
|
307 |
+
},
|
308 |
+
|
309 |
+
onTimerEvent: function() {
|
310 |
+
if (!this.currentlyExecuting) {
|
311 |
+
try {
|
312 |
+
this.currentlyExecuting = true;
|
313 |
+
this.execute();
|
314 |
+
} finally {
|
315 |
+
this.currentlyExecuting = false;
|
316 |
+
}
|
317 |
+
}
|
318 |
+
}
|
319 |
+
});
|
320 |
+
Object.extend(String, {
|
321 |
+
interpret: function(value) {
|
322 |
+
return value == null ? '' : String(value);
|
323 |
+
},
|
324 |
+
specialChar: {
|
325 |
+
'\b': '\\b',
|
326 |
+
'\t': '\\t',
|
327 |
+
'\n': '\\n',
|
328 |
+
'\f': '\\f',
|
329 |
+
'\r': '\\r',
|
330 |
+
'\\': '\\\\'
|
331 |
+
}
|
332 |
+
});
|
333 |
+
|
334 |
+
Object.extend(String.prototype, {
|
335 |
+
gsub: function(pattern, replacement) {
|
336 |
+
var result = '', source = this, match;
|
337 |
+
replacement = arguments.callee.prepareReplacement(replacement);
|
338 |
+
|
339 |
+
while (source.length > 0) {
|
340 |
+
if (match = source.match(pattern)) {
|
341 |
+
result += source.slice(0, match.index);
|
342 |
+
result += String.interpret(replacement(match));
|
343 |
+
source = source.slice(match.index + match[0].length);
|
344 |
+
} else {
|
345 |
+
result += source, source = '';
|
346 |
+
}
|
347 |
+
}
|
348 |
+
return result;
|
349 |
+
},
|
350 |
+
|
351 |
+
sub: function(pattern, replacement, count) {
|
352 |
+
replacement = this.gsub.prepareReplacement(replacement);
|
353 |
+
count = Object.isUndefined(count) ? 1 : count;
|
354 |
+
|
355 |
+
return this.gsub(pattern, function(match) {
|
356 |
+
if (--count < 0) return match[0];
|
357 |
+
return replacement(match);
|
358 |
+
});
|
359 |
+
},
|
360 |
+
|
361 |
+
scan: function(pattern, iterator) {
|
362 |
+
this.gsub(pattern, iterator);
|
363 |
+
return String(this);
|
364 |
+
},
|
365 |
+
|
366 |
+
truncate: function(length, truncation) {
|
367 |
+
length = length || 30;
|
368 |
+
truncation = Object.isUndefined(truncation) ? '...' : truncation;
|
369 |
+
return this.length > length ?
|
370 |
+
this.slice(0, length - truncation.length) + truncation : String(this);
|
371 |
+
},
|
372 |
+
|
373 |
+
strip: function() {
|
374 |
+
return this.replace(/^\s+/, '').replace(/\s+$/, '');
|
375 |
+
},
|
376 |
+
|
377 |
+
stripTags: function() {
|
378 |
+
return this.replace(/<\/?[^>]+>/gi, '');
|
379 |
+
},
|
380 |
+
|
381 |
+
stripScripts: function() {
|
382 |
+
return this.replace(new RegExp(Prototype.ScriptFragment, 'img'), '');
|
383 |
+
},
|
384 |
+
|
385 |
+
extractScripts: function() {
|
386 |
+
var matchAll = new RegExp(Prototype.ScriptFragment, 'img');
|
387 |
+
var matchOne = new RegExp(Prototype.ScriptFragment, 'im');
|
388 |
+
return (this.match(matchAll) || []).map(function(scriptTag) {
|
389 |
+
return (scriptTag.match(matchOne) || ['', ''])[1];
|
390 |
+
});
|
391 |
+
},
|
392 |
+
|
393 |
+
evalScripts: function() {
|
394 |
+
return this.extractScripts().map(function(script) { return eval(script) });
|
395 |
+
},
|
396 |
+
|
397 |
+
escapeHTML: function() {
|
398 |
+
var self = arguments.callee;
|
399 |
+
self.text.data = this;
|
400 |
+
return self.div.innerHTML;
|
401 |
+
},
|
402 |
+
|
403 |
+
unescapeHTML: function() {
|
404 |
+
var div = new Element('div');
|
405 |
+
div.innerHTML = this.stripTags();
|
406 |
+
return div.childNodes[0] ? (div.childNodes.length > 1 ?
|
407 |
+
$A(div.childNodes).inject('', function(memo, node) { return memo+node.nodeValue }) :
|
408 |
+
div.childNodes[0].nodeValue) : '';
|
409 |
+
},
|
410 |
+
|
411 |
+
toQueryParams: function(separator) {
|
412 |
+
var match = this.strip().match(/([^?#]*)(#.*)?$/);
|
413 |
+
if (!match) return { };
|
414 |
+
|
415 |
+
return match[1].split(separator || '&').inject({ }, function(hash, pair) {
|
416 |
+
if ((pair = pair.split('='))[0]) {
|
417 |
+
var key = decodeURIComponent(pair.shift());
|
418 |
+
var value = pair.length > 1 ? pair.join('=') : pair[0];
|
419 |
+
if (value != undefined) value = decodeURIComponent(value);
|
420 |
+
|
421 |
+
if (key in hash) {
|
422 |
+
if (!Object.isArray(hash[key])) hash[key] = [hash[key]];
|
423 |
+
hash[key].push(value);
|
424 |
+
}
|
425 |
+
else hash[key] = value;
|
426 |
+
}
|
427 |
+
return hash;
|
428 |
+
});
|
429 |
+
},
|
430 |
+
|
431 |
+
toArray: function() {
|
432 |
+
return this.split('');
|
433 |
+
},
|
434 |
+
|
435 |
+
succ: function() {
|
436 |
+
return this.slice(0, this.length - 1) +
|
437 |
+
String.fromCharCode(this.charCodeAt(this.length - 1) + 1);
|
438 |
+
},
|
439 |
+
|
440 |
+
times: function(count) {
|
441 |
+
return count < 1 ? '' : new Array(count + 1).join(this);
|
442 |
+
},
|
443 |
+
|
444 |
+
camelize: function() {
|
445 |
+
var parts = this.split('-'), len = parts.length;
|
446 |
+
if (len == 1) return parts[0];
|
447 |
+
|
448 |
+
var camelized = this.charAt(0) == '-'
|
449 |
+
? parts[0].charAt(0).toUpperCase() + parts[0].substring(1)
|
450 |
+
: parts[0];
|
451 |
+
|
452 |
+
for (var i = 1; i < len; i++)
|
453 |
+
camelized += parts[i].charAt(0).toUpperCase() + parts[i].substring(1);
|
454 |
+
|
455 |
+
return camelized;
|
456 |
+
},
|
457 |
+
|
458 |
+
capitalize: function() {
|
459 |
+
return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase();
|
460 |
+
},
|
461 |
+
|
462 |
+
underscore: function() {
|
463 |
+
return this.gsub(/::/, '/').gsub(/([A-Z]+)([A-Z][a-z])/,'#{1}_#{2}').gsub(/([a-z\d])([A-Z])/,'#{1}_#{2}').gsub(/-/,'_').toLowerCase();
|
464 |
+
},
|
465 |
+
|
466 |
+
dasherize: function() {
|
467 |
+
return this.gsub(/_/,'-');
|
468 |
+
},
|
469 |
+
|
470 |
+
inspect: function(useDoubleQuotes) {
|
471 |
+
var escapedString = this.gsub(/[\x00-\x1f\\]/, function(match) {
|
472 |
+
var character = String.specialChar[match[0]];
|
473 |
+
return character ? character : '\\u00' + match[0].charCodeAt().toPaddedString(2, 16);
|
474 |
+
});
|
475 |
+
if (useDoubleQuotes) return '"' + escapedString.replace(/"/g, '\\"') + '"';
|
476 |
+
return "'" + escapedString.replace(/'/g, '\\\'') + "'";
|
477 |
+
},
|
478 |
+
|
479 |
+
toJSON: function() {
|
480 |
+
return this.inspect(true);
|
481 |
+
},
|
482 |
+
|
483 |
+
unfilterJSON: function(filter) {
|
484 |
+
return this.sub(filter || Prototype.JSONFilter, '#{1}');
|
485 |
+
},
|
486 |
+
|
487 |
+
isJSON: function() {
|
488 |
+
var str = this;
|
489 |
+
if (str.blank()) return false;
|
490 |
+
str = this.replace(/\\./g, '@').replace(/"[^"\\\n\r]*"/g, '');
|
491 |
+
return (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(str);
|
492 |
+
},
|
493 |
+
|
494 |
+
evalJSON: function(sanitize) {
|
495 |
+
var json = this.unfilterJSON();
|
496 |
+
try {
|
497 |
+
if (!sanitize || json.isJSON()) return eval('(' + json + ')');
|
498 |
+
} catch (e) { }
|
499 |
+
throw new SyntaxError('Badly formed JSON string: ' + this.inspect());
|
500 |
+
},
|
501 |
+
|
502 |
+
include: function(pattern) {
|
503 |
+
return this.indexOf(pattern) > -1;
|
504 |
+
},
|
505 |
+
|
506 |
+
startsWith: function(pattern) {
|
507 |
+
return this.indexOf(pattern) === 0;
|
508 |
+
},
|
509 |
+
|
510 |
+
endsWith: function(pattern) {
|
511 |
+
var d = this.length - pattern.length;
|
512 |
+
return d >= 0 && this.lastIndexOf(pattern) === d;
|
513 |
+
},
|
514 |
+
|
515 |
+
empty: function() {
|
516 |
+
return this == '';
|
517 |
+
},
|
518 |
+
|
519 |
+
blank: function() {
|
520 |
+
return /^\s*$/.test(this);
|
521 |
+
},
|
522 |
+
|
523 |
+
interpolate: function(object, pattern) {
|
524 |
+
return new Template(this, pattern).evaluate(object);
|
525 |
+
}
|
526 |
+
});
|
527 |
+
|
528 |
+
if (Prototype.Browser.WebKit || Prototype.Browser.IE) Object.extend(String.prototype, {
|
529 |
+
escapeHTML: function() {
|
530 |
+
return this.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
|
531 |
+
},
|
532 |
+
unescapeHTML: function() {
|
533 |
+
return this.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>');
|
534 |
+
}
|
535 |
+
});
|
536 |
+
|
537 |
+
String.prototype.gsub.prepareReplacement = function(replacement) {
|
538 |
+
if (Object.isFunction(replacement)) return replacement;
|
539 |
+
var template = new Template(replacement);
|
540 |
+
return function(match) { return template.evaluate(match) };
|
541 |
+
};
|
542 |
+
|
543 |
+
String.prototype.parseQuery = String.prototype.toQueryParams;
|
544 |
+
|
545 |
+
Object.extend(String.prototype.escapeHTML, {
|
546 |
+
div: document.createElement('div'),
|
547 |
+
text: document.createTextNode('')
|
548 |
+
});
|
549 |
+
|
550 |
+
with (String.prototype.escapeHTML) div.appendChild(text);
|
551 |
+
|
552 |
+
var Template = Class.create({
|
553 |
+
initialize: function(template, pattern) {
|
554 |
+
this.template = template.toString();
|
555 |
+
this.pattern = pattern || Template.Pattern;
|
556 |
+
},
|
557 |
+
|
558 |
+
evaluate: function(object) {
|
559 |
+
if (Object.isFunction(object.toTemplateReplacements))
|
560 |
+
object = object.toTemplateReplacements();
|
561 |
+
|
562 |
+
return this.template.gsub(this.pattern, function(match) {
|
563 |
+
if (object == null) return '';
|
564 |
+
|
565 |
+
var before = match[1] || '';
|
566 |
+
if (before == '\\') return match[2];
|
567 |
+
|
568 |
+
var ctx = object, expr = match[3];
|
569 |
+
var pattern = /^([^.[]+|\[((?:.*?[^\\])?)\])(\.|\[|$)/;
|
570 |
+
match = pattern.exec(expr);
|
571 |
+
if (match == null) return before;
|
572 |
+
|
573 |
+
while (match != null) {
|
574 |
+
var comp = match[1].startsWith('[') ? match[2].gsub('\\\\]', ']') : match[1];
|
575 |
+
ctx = ctx[comp];
|
576 |
+
if (null == ctx || '' == match[3]) break;
|
577 |
+
expr = expr.substring('[' == match[3] ? match[1].length : match[0].length);
|
578 |
+
match = pattern.exec(expr);
|
579 |
+
}
|
580 |
+
|
581 |
+
return before + String.interpret(ctx);
|
582 |
+
});
|
583 |
+
}
|
584 |
+
});
|
585 |
+
Template.Pattern = /(^|.|\r|\n)(#\{(.*?)\})/;
|
586 |
+
|
587 |
+
var $break = { };
|
588 |
+
|
589 |
+
var Enumerable = {
|
590 |
+
each: function(iterator, context) {
|
591 |
+
var index = 0;
|
592 |
+
iterator = iterator.bind(context);
|
593 |
+
try {
|
594 |
+
this._each(function(value) {
|
595 |
+
iterator(value, index++);
|
596 |
+
});
|
597 |
+
} catch (e) {
|
598 |
+
if (e != $break) throw e;
|
599 |
+
}
|
600 |
+
return this;
|
601 |
+
},
|
602 |
+
|
603 |
+
eachSlice: function(number, iterator, context) {
|
604 |
+
iterator = iterator ? iterator.bind(context) : Prototype.K;
|
605 |
+
var index = -number, slices = [], array = this.toArray();
|
606 |
+
while ((index += number) < array.length)
|
607 |
+
slices.push(array.slice(index, index+number));
|
608 |
+
return slices.collect(iterator, context);
|
609 |
+
},
|
610 |
+
|
611 |
+
all: function(iterator, context) {
|
612 |
+
iterator = iterator ? iterator.bind(context) : Prototype.K;
|
613 |
+
var result = true;
|
614 |
+
this.each(function(value, index) {
|
615 |
+
result = result && !!iterator(value, index);
|
616 |
+
if (!result) throw $break;
|
617 |
+
});
|
618 |
+
return result;
|
619 |
+
},
|
620 |
+
|
621 |
+
any: function(iterator, context) {
|
622 |
+
iterator = iterator ? iterator.bind(context) : Prototype.K;
|
623 |
+
var result = false;
|
624 |
+
this.each(function(value, index) {
|
625 |
+
if (result = !!iterator(value, index))
|
626 |
+
throw $break;
|
627 |
+
});
|
628 |
+
return result;
|
629 |
+
},
|
630 |
+
|
631 |
+
collect: function(iterator, context) {
|
632 |
+
iterator = iterator ? iterator.bind(context) : Prototype.K;
|
633 |
+
var results = [];
|
634 |
+
this.each(function(value, index) {
|
635 |
+
results.push(iterator(value, index));
|
636 |
+
});
|
637 |
+
return results;
|
638 |
+
},
|
639 |
+
|
640 |
+
detect: function(iterator, context) {
|
641 |
+
iterator = iterator.bind(context);
|
642 |
+
var result;
|
643 |
+
this.each(function(value, index) {
|
644 |
+
if (iterator(value, index)) {
|
645 |
+
result = value;
|
646 |
+
throw $break;
|
647 |
+
}
|
648 |
+
});
|
649 |
+
return result;
|
650 |
+
},
|
651 |
+
|
652 |
+
findAll: function(iterator, context) {
|
653 |
+
iterator = iterator.bind(context);
|
654 |
+
var results = [];
|
655 |
+
this.each(function(value, index) {
|
656 |
+
if (iterator(value, index))
|
657 |
+
results.push(value);
|
658 |
+
});
|
659 |
+
return results;
|
660 |
+
},
|
661 |
+
|
662 |
+
grep: function(filter, iterator, context) {
|
663 |
+
iterator = iterator ? iterator.bind(context) : Prototype.K;
|
664 |
+
var results = [];
|
665 |
+
|
666 |
+
if (Object.isString(filter))
|
667 |
+
filter = new RegExp(filter);
|
668 |
+
|
669 |
+
this.each(function(value, index) {
|
670 |
+
if (filter.match(value))
|
671 |
+
results.push(iterator(value, index));
|
672 |
+
});
|
673 |
+
return results;
|
674 |
+
},
|
675 |
+
|
676 |
+
include: function(object) {
|
677 |
+
if (Object.isFunction(this.indexOf))
|
678 |
+
if (this.indexOf(object) != -1) return true;
|
679 |
+
|
680 |
+
var found = false;
|
681 |
+
this.each(function(value) {
|
682 |
+
if (value == object) {
|
683 |
+
found = true;
|
684 |
+
throw $break;
|
685 |
+
}
|
686 |
+
});
|
687 |
+
return found;
|
688 |
+
},
|
689 |
+
|
690 |
+
inGroupsOf: function(number, fillWith) {
|
691 |
+
fillWith = Object.isUndefined(fillWith) ? null : fillWith;
|
692 |
+
return this.eachSlice(number, function(slice) {
|
693 |
+
while(slice.length < number) slice.push(fillWith);
|
694 |
+
return slice;
|
695 |
+
});
|
696 |
+
},
|
697 |
+
|
698 |
+
inject: function(memo, iterator, context) {
|
699 |
+
iterator = iterator.bind(context);
|
700 |
+
this.each(function(value, index) {
|
701 |
+
memo = iterator(memo, value, index);
|
702 |
+
});
|
703 |
+
return memo;
|
704 |
+
},
|
705 |
+
|
706 |
+
invoke: function(method) {
|
707 |
+
var args = $A(arguments).slice(1);
|
708 |
+
return this.map(function(value) {
|
709 |
+
return value[method].apply(value, args);
|
710 |
+
});
|
711 |
+
},
|
712 |
+
|
713 |
+
max: function(iterator, context) {
|
714 |
+
iterator = iterator ? iterator.bind(context) : Prototype.K;
|
715 |
+
var result;
|
716 |
+
this.each(function(value, index) {
|
717 |
+
value = iterator(value, index);
|
718 |
+
if (result == null || value >= result)
|
719 |
+
result = value;
|
720 |
+
});
|
721 |
+
return result;
|
722 |
+
},
|
723 |
+
|
724 |
+
min: function(iterator, context) {
|
725 |
+
iterator = iterator ? iterator.bind(context) : Prototype.K;
|
726 |
+
var result;
|
727 |
+
this.each(function(value, index) {
|
728 |
+
value = iterator(value, index);
|
729 |
+
if (result == null || value < result)
|
730 |
+
result = value;
|
731 |
+
});
|
732 |
+
return result;
|
733 |
+
},
|
734 |
+
|
735 |
+
partition: function(iterator, context) {
|
736 |
+
iterator = iterator ? iterator.bind(context) : Prototype.K;
|
737 |
+
var trues = [], falses = [];
|
738 |
+
this.each(function(value, index) {
|
739 |
+
(iterator(value, index) ?
|
740 |
+
trues : falses).push(value);
|
741 |
+
});
|
742 |
+
return [trues, falses];
|
743 |
+
},
|
744 |
+
|
745 |
+
pluck: function(property) {
|
746 |
+
var results = [];
|
747 |
+
this.each(function(value) {
|
748 |
+
results.push(value[property]);
|
749 |
+
});
|
750 |
+
return results;
|
751 |
+
},
|
752 |
+
|
753 |
+
reject: function(iterator, context) {
|
754 |
+
iterator = iterator.bind(context);
|
755 |
+
var results = [];
|
756 |
+
this.each(function(value, index) {
|
757 |
+
if (!iterator(value, index))
|
758 |
+
results.push(value);
|
759 |
+
});
|
760 |
+
return results;
|
761 |
+
},
|
762 |
+
|
763 |
+
sortBy: function(iterator, context) {
|
764 |
+
iterator = iterator.bind(context);
|
765 |
+
return this.map(function(value, index) {
|
766 |
+
return {value: value, criteria: iterator(value, index)};
|
767 |
+
}).sort(function(left, right) {
|
768 |
+
var a = left.criteria, b = right.criteria;
|
769 |
+
return a < b ? -1 : a > b ? 1 : 0;
|
770 |
+
}).pluck('value');
|
771 |
+
},
|
772 |
+
|
773 |
+
toArray: function() {
|
774 |
+
return this.map();
|
775 |
+
},
|
776 |
+
|
777 |
+
zip: function() {
|
778 |
+
var iterator = Prototype.K, args = $A(arguments);
|
779 |
+
if (Object.isFunction(args.last()))
|
780 |
+
iterator = args.pop();
|
781 |
+
|
782 |
+
var collections = [this].concat(args).map($A);
|
783 |
+
return this.map(function(value, index) {
|
784 |
+
return iterator(collections.pluck(index));
|
785 |
+
});
|
786 |
+
},
|
787 |
+
|
788 |
+
size: function() {
|
789 |
+
return this.toArray().length;
|
790 |
+
},
|
791 |
+
|
792 |
+
inspect: function() {
|
793 |
+
return '#<Enumerable:' + this.toArray().inspect() + '>';
|
794 |
+
}
|
795 |
+
};
|
796 |
+
|
797 |
+
Object.extend(Enumerable, {
|
798 |
+
map: Enumerable.collect,
|
799 |
+
find: Enumerable.detect,
|
800 |
+
select: Enumerable.findAll,
|
801 |
+
filter: Enumerable.findAll,
|
802 |
+
member: Enumerable.include,
|
803 |
+
entries: Enumerable.toArray,
|
804 |
+
every: Enumerable.all,
|
805 |
+
some: Enumerable.any
|
806 |
+
});
|
807 |
+
function $A(iterable) {
|
808 |
+
if (!iterable) return [];
|
809 |
+
if (iterable.toArray) return iterable.toArray();
|
810 |
+
var length = iterable.length || 0, results = new Array(length);
|
811 |
+
while (length--) results[length] = iterable[length];
|
812 |
+
return results;
|
813 |
+
}
|
814 |
+
|
815 |
+
if (Prototype.Browser.WebKit) {
|
816 |
+
$A = function(iterable) {
|
817 |
+
if (!iterable) return [];
|
818 |
+
if (!(Object.isFunction(iterable) && iterable == '[object NodeList]') &&
|
819 |
+
iterable.toArray) return iterable.toArray();
|
820 |
+
var length = iterable.length || 0, results = new Array(length);
|
821 |
+
while (length--) results[length] = iterable[length];
|
822 |
+
return results;
|
823 |
+
};
|
824 |
+
}
|
825 |
+
|
826 |
+
Array.from = $A;
|
827 |
+
|
828 |
+
Object.extend(Array.prototype, Enumerable);
|
829 |
+
|
830 |
+
if (!Array.prototype._reverse) Array.prototype._reverse = Array.prototype.reverse;
|
831 |
+
|
832 |
+
Object.extend(Array.prototype, {
|
833 |
+
_each: function(iterator) {
|
834 |
+
for (var i = 0, length = this.length; i < length; i++)
|
835 |
+
iterator(this[i]);
|
836 |
+
},
|
837 |
+
|
838 |
+
clear: function() {
|
839 |
+
this.length = 0;
|
840 |
+
return this;
|
841 |
+
},
|
842 |
+
|
843 |
+
first: function() {
|
844 |
+
return this[0];
|
845 |
+
},
|
846 |
+
|
847 |
+
last: function() {
|
848 |
+
return this[this.length - 1];
|
849 |
+
},
|
850 |
+
|
851 |
+
compact: function() {
|
852 |
+
return this.select(function(value) {
|
853 |
+
return value != null;
|
854 |
+
});
|
855 |
+
},
|
856 |
+
|
857 |
+
flatten: function() {
|
858 |
+
return this.inject([], function(array, value) {
|
859 |
+
return array.concat(Object.isArray(value) ?
|
860 |
+
value.flatten() : [value]);
|
861 |
+
});
|
862 |
+
},
|
863 |
+
|
864 |
+
without: function() {
|
865 |
+
var values = $A(arguments);
|
866 |
+
return this.select(function(value) {
|
867 |
+
return !values.include(value);
|
868 |
+
});
|
869 |
+
},
|
870 |
+
|
871 |
+
reverse: function(inline) {
|
872 |
+
return (inline !== false ? this : this.toArray())._reverse();
|
873 |
+
},
|
874 |
+
|
875 |
+
reduce: function() {
|
876 |
+
return this.length > 1 ? this : this[0];
|
877 |
+
},
|
878 |
+
|
879 |
+
uniq: function(sorted) {
|
880 |
+
return this.inject([], function(array, value, index) {
|
881 |
+
if (0 == index || (sorted ? array.last() != value : !array.include(value)))
|
882 |
+
array.push(value);
|
883 |
+
return array;
|
884 |
+
});
|
885 |
+
},
|
886 |
+
|
887 |
+
intersect: function(array) {
|
888 |
+
return this.uniq().findAll(function(item) {
|
889 |
+
return array.detect(function(value) { return item === value });
|
890 |
+
});
|
891 |
+
},
|
892 |
+
|
893 |
+
clone: function() {
|
894 |
+
return [].concat(this);
|
895 |
+
},
|
896 |
+
|
897 |
+
size: function() {
|
898 |
+
return this.length;
|
899 |
+
},
|
900 |
+
|
901 |
+
inspect: function() {
|
902 |
+
return '[' + this.map(Object.inspect).join(', ') + ']';
|
903 |
+
},
|
904 |
+
|
905 |
+
toJSON: function() {
|
906 |
+
var results = [];
|
907 |
+
this.each(function(object) {
|
908 |
+
var value = Object.toJSON(object);
|
909 |
+
if (!Object.isUndefined(value)) results.push(value);
|
910 |
+
});
|
911 |
+
return '[' + results.join(', ') + ']';
|
912 |
+
}
|
913 |
+
});
|
914 |
+
|
915 |
+
// use native browser JS 1.6 implementation if available
|
916 |
+
if (Object.isFunction(Array.prototype.forEach))
|
917 |
+
Array.prototype._each = Array.prototype.forEach;
|
918 |
+
|
919 |
+
if (!Array.prototype.indexOf) Array.prototype.indexOf = function(item, i) {
|
920 |
+
i || (i = 0);
|
921 |
+
var length = this.length;
|
922 |
+
if (i < 0) i = length + i;
|
923 |
+
for (; i < length; i++)
|
924 |
+
if (this[i] === item) return i;
|
925 |
+
return -1;
|
926 |
+
};
|
927 |
+
|
928 |
+
if (!Array.prototype.lastIndexOf) Array.prototype.lastIndexOf = function(item, i) {
|
929 |
+
i = isNaN(i) ? this.length : (i < 0 ? this.length + i : i) + 1;
|
930 |
+
var n = this.slice(0, i).reverse().indexOf(item);
|
931 |
+
return (n < 0) ? n : i - n - 1;
|
932 |
+
};
|
933 |
+
|
934 |
+
Array.prototype.toArray = Array.prototype.clone;
|
935 |
+
|
936 |
+
function $w(string) {
|
937 |
+
if (!Object.isString(string)) return [];
|
938 |
+
string = string.strip();
|
939 |
+
return string ? string.split(/\s+/) : [];
|
940 |
+
}
|
941 |
+
|
942 |
+
if (Prototype.Browser.Opera){
|
943 |
+
Array.prototype.concat = function() {
|
944 |
+
var array = [];
|
945 |
+
for (var i = 0, length = this.length; i < length; i++) array.push(this[i]);
|
946 |
+
for (var i = 0, length = arguments.length; i < length; i++) {
|
947 |
+
if (Object.isArray(arguments[i])) {
|
948 |
+
for (var j = 0, arrayLength = arguments[i].length; j < arrayLength; j++)
|
949 |
+
array.push(arguments[i][j]);
|
950 |
+
} else {
|
951 |
+
array.push(arguments[i]);
|
952 |
+
}
|
953 |
+
}
|
954 |
+
return array;
|
955 |
+
};
|
956 |
+
}
|
957 |
+
Object.extend(Number.prototype, {
|
958 |
+
toColorPart: function() {
|
959 |
+
return this.toPaddedString(2, 16);
|
960 |
+
},
|
961 |
+
|
962 |
+
succ: function() {
|
963 |
+
return this + 1;
|
964 |
+
},
|
965 |
+
|
966 |
+
times: function(iterator) {
|
967 |
+
$R(0, this, true).each(iterator);
|
968 |
+
return this;
|
969 |
+
},
|
970 |
+
|
971 |
+
toPaddedString: function(length, radix) {
|
972 |
+
var string = this.toString(radix || 10);
|
973 |
+
return '0'.times(length - string.length) + string;
|
974 |
+
},
|
975 |
+
|
976 |
+
toJSON: function() {
|
977 |
+
return isFinite(this) ? this.toString() : 'null';
|
978 |
+
}
|
979 |
+
});
|
980 |
+
|
981 |
+
$w('abs round ceil floor').each(function(method){
|
982 |
+
Number.prototype[method] = Math[method].methodize();
|
983 |
+
});
|
984 |
+
function $H(object) {
|
985 |
+
return new Hash(object);
|
986 |
+
};
|
987 |
+
|
988 |
+
var Hash = Class.create(Enumerable, (function() {
|
989 |
+
|
990 |
+
function toQueryPair(key, value) {
|
991 |
+
if (Object.isUndefined(value)) return key;
|
992 |
+
return key + '=' + encodeURIComponent(String.interpret(value));
|
993 |
+
}
|
994 |
+
|
995 |
+
return {
|
996 |
+
initialize: function(object) {
|
997 |
+
this._object = Object.isHash(object) ? object.toObject() : Object.clone(object);
|
998 |
+
},
|
999 |
+
|
1000 |
+
_each: function(iterator) {
|
1001 |
+
for (var key in this._object) {
|
1002 |
+
var value = this._object[key], pair = [key, value];
|
1003 |
+
pair.key = key;
|
1004 |
+
pair.value = value;
|
1005 |
+
iterator(pair);
|
1006 |
+
}
|
1007 |
+
},
|
1008 |
+
|
1009 |
+
set: function(key, value) {
|
1010 |
+
return this._object[key] = value;
|
1011 |
+
},
|
1012 |
+
|
1013 |
+
get: function(key) {
|
1014 |
+
return this._object[key];
|
1015 |
+
},
|
1016 |
+
|
1017 |
+
unset: function(key) {
|
1018 |
+
var value = this._object[key];
|
1019 |
+
delete this._object[key];
|
1020 |
+
return value;
|
1021 |
+
},
|
1022 |
+
|
1023 |
+
toObject: function() {
|
1024 |
+
return Object.clone(this._object);
|
1025 |
+
},
|
1026 |
+
|
1027 |
+
keys: function() {
|
1028 |
+
return this.pluck('key');
|
1029 |
+
},
|
1030 |
+
|
1031 |
+
values: function() {
|
1032 |
+
return this.pluck('value');
|
1033 |
+
},
|
1034 |
+
|
1035 |
+
index: function(value) {
|
1036 |
+
var match = this.detect(function(pair) {
|
1037 |
+
return pair.value === value;
|
1038 |
+
});
|
1039 |
+
return match && match.key;
|
1040 |
+
},
|
1041 |
+
|
1042 |
+
merge: function(object) {
|
1043 |
+
return this.clone().update(object);
|
1044 |
+
},
|
1045 |
+
|
1046 |
+
update: function(object) {
|
1047 |
+
return new Hash(object).inject(this, function(result, pair) {
|
1048 |
+
result.set(pair.key, pair.value);
|
1049 |
+
return result;
|
1050 |
+
});
|
1051 |
+
},
|
1052 |
+
|
1053 |
+
toQueryString: function() {
|
1054 |
+
return this.map(function(pair) {
|
1055 |
+
var key = encodeURIComponent(pair.key), values = pair.value;
|
1056 |
+
|
1057 |
+
if (values && typeof values == 'object') {
|
1058 |
+
if (Object.isArray(values))
|
1059 |
+
return values.map(toQueryPair.curry(key)).join('&');
|
1060 |
+
}
|
1061 |
+
return toQueryPair(key, values);
|
1062 |
+
}).join('&');
|
1063 |
+
},
|
1064 |
+
|
1065 |
+
inspect: function() {
|
1066 |
+
return '#<Hash:{' + this.map(function(pair) {
|
1067 |
+
return pair.map(Object.inspect).join(': ');
|
1068 |
+
}).join(', ') + '}>';
|
1069 |
+
},
|
1070 |
+
|
1071 |
+
toJSON: function() {
|
1072 |
+
return Object.toJSON(this.toObject());
|
1073 |
+
},
|
1074 |
+
|
1075 |
+
clone: function() {
|
1076 |
+
return new Hash(this);
|
1077 |
+
}
|
1078 |
+
}
|
1079 |
+
})());
|
1080 |
+
|
1081 |
+
Hash.prototype.toTemplateReplacements = Hash.prototype.toObject;
|
1082 |
+
Hash.from = $H;
|
1083 |
+
var ObjectRange = Class.create(Enumerable, {
|
1084 |
+
initialize: function(start, end, exclusive) {
|
1085 |
+
this.start = start;
|
1086 |
+
this.end = end;
|
1087 |
+
this.exclusive = exclusive;
|
1088 |
+
},
|
1089 |
+
|
1090 |
+
_each: function(iterator) {
|
1091 |
+
var value = this.start;
|
1092 |
+
while (this.include(value)) {
|
1093 |
+
iterator(value);
|
1094 |
+
value = value.succ();
|
1095 |
+
}
|
1096 |
+
},
|
1097 |
+
|
1098 |
+
include: function(value) {
|
1099 |
+
if (value < this.start)
|
1100 |
+
return false;
|
1101 |
+
if (this.exclusive)
|
1102 |
+
return value < this.end;
|
1103 |
+
return value <= this.end;
|
1104 |
+
}
|
1105 |
+
});
|
1106 |
+
|
1107 |
+
var $R = function(start, end, exclusive) {
|
1108 |
+
return new ObjectRange(start, end, exclusive);
|
1109 |
+
};
|
1110 |
+
|
1111 |
+
var Ajax = {
|
1112 |
+
getTransport: function() {
|
1113 |
+
return Try.these(
|
1114 |
+
function() {return new XMLHttpRequest()},
|
1115 |
+
function() {return new ActiveXObject('Msxml2.XMLHTTP')},
|
1116 |
+
function() {return new ActiveXObject('Microsoft.XMLHTTP')}
|
1117 |
+
) || false;
|
1118 |
+
},
|
1119 |
+
|
1120 |
+
activeRequestCount: 0
|
1121 |
+
};
|
1122 |
+
|
1123 |
+
Ajax.Responders = {
|
1124 |
+
responders: [],
|
1125 |
+
|
1126 |
+
_each: function(iterator) {
|
1127 |
+
this.responders._each(iterator);
|
1128 |
+
},
|
1129 |
+
|
1130 |
+
register: function(responder) {
|
1131 |
+
if (!this.include(responder))
|
1132 |
+
this.responders.push(responder);
|
1133 |
+
},
|
1134 |
+
|
1135 |
+
unregister: function(responder) {
|
1136 |
+
this.responders = this.responders.without(responder);
|
1137 |
+
},
|
1138 |
+
|
1139 |
+
dispatch: function(callback, request, transport, json) {
|
1140 |
+
this.each(function(responder) {
|
1141 |
+
if (Object.isFunction(responder[callback])) {
|
1142 |
+
try {
|
1143 |
+
responder[callback].apply(responder, [request, transport, json]);
|
1144 |
+
} catch (e) { }
|
1145 |
+
}
|
1146 |
+
});
|
1147 |
+
}
|
1148 |
+
};
|
1149 |
+
|
1150 |
+
Object.extend(Ajax.Responders, Enumerable);
|
1151 |
+
|
1152 |
+
Ajax.Responders.register({
|
1153 |
+
onCreate: function() { Ajax.activeRequestCount++ },
|
1154 |
+
onComplete: function() { Ajax.activeRequestCount-- }
|
1155 |
+
});
|
1156 |
+
|
1157 |
+
Ajax.Base = Class.create({
|
1158 |
+
initialize: function(options) {
|
1159 |
+
this.options = {
|
1160 |
+
method: 'post',
|
1161 |
+
asynchronous: true,
|
1162 |
+
contentType: 'application/x-www-form-urlencoded',
|
1163 |
+
encoding: 'UTF-8',
|
1164 |
+
parameters: '',
|
1165 |
+
evalJSON: true,
|
1166 |
+
evalJS: true
|
1167 |
+
};
|
1168 |
+
Object.extend(this.options, options || { });
|
1169 |
+
|
1170 |
+
this.options.method = this.options.method.toLowerCase();
|
1171 |
+
|
1172 |
+
if (Object.isString(this.options.parameters))
|
1173 |
+
this.options.parameters = this.options.parameters.toQueryParams();
|
1174 |
+
else if (Object.isHash(this.options.parameters))
|
1175 |
+
this.options.parameters = this.options.parameters.toObject();
|
1176 |
+
}
|
1177 |
+
});
|
1178 |
+
|
1179 |
+
Ajax.Request = Class.create(Ajax.Base, {
|
1180 |
+
_complete: false,
|
1181 |
+
|
1182 |
+
initialize: function($super, url, options) {
|
1183 |
+
$super(options);
|
1184 |
+
this.transport = Ajax.getTransport();
|
1185 |
+
this.request(url);
|
1186 |
+
},
|
1187 |
+
|
1188 |
+
request: function(url) {
|
1189 |
+
this.url = url;
|
1190 |
+
this.method = this.options.method;
|
1191 |
+
var params = Object.clone(this.options.parameters);
|
1192 |
+
|
1193 |
+
if (!['get', 'post'].include(this.method)) {
|
1194 |
+
// simulate other verbs over post
|
1195 |
+
params['_method'] = this.method;
|
1196 |
+
this.method = 'post';
|
1197 |
+
}
|
1198 |
+
|
1199 |
+
this.parameters = params;
|
1200 |
+
|
1201 |
+
if (params = Object.toQueryString(params)) {
|
1202 |
+
// when GET, append parameters to URL
|
1203 |
+
if (this.method == 'get')
|
1204 |
+
this.url += (this.url.include('?') ? '&' : '?') + params;
|
1205 |
+
else if (/Konqueror|Safari|KHTML/.test(navigator.userAgent))
|
1206 |
+
params += '&_=';
|
1207 |
+
}
|
1208 |
+
|
1209 |
+
try {
|
1210 |
+
var response = new Ajax.Response(this);
|
1211 |
+
if (this.options.onCreate) this.options.onCreate(response);
|
1212 |
+
Ajax.Responders.dispatch('onCreate', this, response);
|
1213 |
+
|
1214 |
+
this.transport.open(this.method.toUpperCase(), this.url,
|
1215 |
+
this.options.asynchronous);
|
1216 |
+
|
1217 |
+
if (this.options.asynchronous) this.respondToReadyState.bind(this).defer(1);
|
1218 |
+
|
1219 |
+
this.transport.onreadystatechange = this.onStateChange.bind(this);
|
1220 |
+
this.setRequestHeaders();
|
1221 |
+
|
1222 |
+
this.body = this.method == 'post' ? (this.options.postBody || params) : null;
|
1223 |
+
this.transport.send(this.body);
|
1224 |
+
|
1225 |
+
/* Force Firefox to handle ready state 4 for synchronous requests */
|
1226 |
+
if (!this.options.asynchronous && this.transport.overrideMimeType)
|
1227 |
+
this.onStateChange();
|
1228 |
+
|
1229 |
+
}
|
1230 |
+
catch (e) {
|
1231 |
+
this.dispatchException(e);
|
1232 |
+
}
|
1233 |
+
},
|
1234 |
+
|
1235 |
+
onStateChange: function() {
|
1236 |
+
var readyState = this.transport.readyState;
|
1237 |
+
if (readyState > 1 && !((readyState == 4) && this._complete))
|
1238 |
+
this.respondToReadyState(this.transport.readyState);
|
1239 |
+
},
|
1240 |
+
|
1241 |
+
setRequestHeaders: function() {
|
1242 |
+
var headers = {
|
1243 |
+
'X-Requested-With': 'XMLHttpRequest',
|
1244 |
+
'X-Prototype-Version': Prototype.Version,
|
1245 |
+
'Accept': 'text/javascript, text/html, application/xml, text/xml, */*'
|
1246 |
+
};
|
1247 |
+
|
1248 |
+
if (this.method == 'post') {
|
1249 |
+
headers['Content-type'] = this.options.contentType +
|
1250 |
+
(this.options.encoding ? '; charset=' + this.options.encoding : '');
|
1251 |
+
|
1252 |
+
/* Force "Connection: close" for older Mozilla browsers to work
|
1253 |
+
* around a bug where XMLHttpRequest sends an incorrect
|
1254 |
+
* Content-length header. See Mozilla Bugzilla #246651.
|
1255 |
+
*/
|
1256 |
+
if (this.transport.overrideMimeType &&
|
1257 |
+
(navigator.userAgent.match(/Gecko\/(\d{4})/) || [0,2005])[1] < 2005)
|
1258 |
+
headers['Connection'] = 'close';
|
1259 |
+
}
|
1260 |
+
|
1261 |
+
// user-defined headers
|
1262 |
+
if (typeof this.options.requestHeaders == 'object') {
|
1263 |
+
var extras = this.options.requestHeaders;
|
1264 |
+
|
1265 |
+
if (Object.isFunction(extras.push))
|
1266 |
+
for (var i = 0, length = extras.length; i < length; i += 2)
|
1267 |
+
headers[extras[i]] = extras[i+1];
|
1268 |
+
else
|
1269 |
+
$H(extras).each(function(pair) { headers[pair.key] = pair.value });
|
1270 |
+
}
|
1271 |
+
|
1272 |
+
for (var name in headers)
|
1273 |
+
this.transport.setRequestHeader(name, headers[name]);
|
1274 |
+
},
|
1275 |
+
|
1276 |
+
success: function() {
|
1277 |
+
var status = this.getStatus();
|
1278 |
+
return !status || (status >= 200 && status < 300);
|
1279 |
+
},
|
1280 |
+
|
1281 |
+
getStatus: function() {
|
1282 |
+
try {
|
1283 |
+
return this.transport.status || 0;
|
1284 |
+
} catch (e) { return 0 }
|
1285 |
+
},
|
1286 |
+
|
1287 |
+
respondToReadyState: function(readyState) {
|
1288 |
+
var state = Ajax.Request.Events[readyState], response = new Ajax.Response(this);
|
1289 |
+
|
1290 |
+
if (state == 'Complete') {
|
1291 |
+
try {
|
1292 |
+
this._complete = true;
|
1293 |
+
(this.options['on' + response.status]
|
1294 |
+
|| this.options['on' + (this.success() ? 'Success' : 'Failure')]
|
1295 |
+
|| Prototype.emptyFunction)(response, response.headerJSON);
|
1296 |
+
} catch (e) {
|
1297 |
+
this.dispatchException(e);
|
1298 |
+
}
|
1299 |
+
|
1300 |
+
var contentType = response.getHeader('Content-type');
|
1301 |
+
if (this.options.evalJS == 'force'
|
1302 |
+
|| (this.options.evalJS && this.isSameOrigin() && contentType
|
1303 |
+
&& contentType.match(/^\s*(text|application)\/(x-)?(java|ecma)script(;.*)?\s*$/i)))
|
1304 |
+
this.evalResponse();
|
1305 |
+
}
|
1306 |
+
|
1307 |
+
try {
|
1308 |
+
(this.options['on' + state] || Prototype.emptyFunction)(response, response.headerJSON);
|
1309 |
+
Ajax.Responders.dispatch('on' + state, this, response, response.headerJSON);
|
1310 |
+
} catch (e) {
|
1311 |
+
this.dispatchException(e);
|
1312 |
+
}
|
1313 |
+
|
1314 |
+
if (state == 'Complete') {
|
1315 |
+
// avoid memory leak in MSIE: clean up
|
1316 |
+
this.transport.onreadystatechange = Prototype.emptyFunction;
|
1317 |
+
}
|
1318 |
+
},
|
1319 |
+
|
1320 |
+
isSameOrigin: function() {
|
1321 |
+
var m = this.url.match(/^\s*https?:\/\/[^\/]*/);
|
1322 |
+
return !m || (m[0] == '#{protocol}//#{domain}#{port}'.interpolate({
|
1323 |
+
protocol: location.protocol,
|
1324 |
+
domain: document.domain,
|
1325 |
+
port: location.port ? ':' + location.port : ''
|
1326 |
+
}));
|
1327 |
+
},
|
1328 |
+
|
1329 |
+
getHeader: function(name) {
|
1330 |
+
try {
|
1331 |
+
return this.transport.getResponseHeader(name) || null;
|
1332 |
+
} catch (e) { return null }
|
1333 |
+
},
|
1334 |
+
|
1335 |
+
evalResponse: function() {
|
1336 |
+
try {
|
1337 |
+
return eval((this.transport.responseText || '').unfilterJSON());
|
1338 |
+
} catch (e) {
|
1339 |
+
this.dispatchException(e);
|
1340 |
+
}
|
1341 |
+
},
|
1342 |
+
|
1343 |
+
dispatchException: function(exception) {
|
1344 |
+
(this.options.onException || Prototype.emptyFunction)(this, exception);
|
1345 |
+
Ajax.Responders.dispatch('onException', this, exception);
|
1346 |
+
}
|
1347 |
+
});
|
1348 |
+
|
1349 |
+
Ajax.Request.Events =
|
1350 |
+
['Uninitialized', 'Loading', 'Loaded', 'Interactive', 'Complete'];
|
1351 |
+
|
1352 |
+
Ajax.Response = Class.create({
|
1353 |
+
initialize: function(request){
|
1354 |
+
this.request = request;
|
1355 |
+
var transport = this.transport = request.transport,
|
1356 |
+
readyState = this.readyState = transport.readyState;
|
1357 |
+
|
1358 |
+
if((readyState > 2 && !Prototype.Browser.IE) || readyState == 4) {
|
1359 |
+
this.status = this.getStatus();
|
1360 |
+
this.statusText = this.getStatusText();
|
1361 |
+
this.responseText = String.interpret(transport.responseText);
|
1362 |
+
this.headerJSON = this._getHeaderJSON();
|
1363 |
+
}
|
1364 |
+
|
1365 |
+
if(readyState == 4) {
|
1366 |
+
var xml = transport.responseXML;
|
1367 |
+
this.responseXML = Object.isUndefined(xml) ? null : xml;
|
1368 |
+
this.responseJSON = this._getResponseJSON();
|
1369 |
+
}
|
1370 |
+
},
|
1371 |
+
|
1372 |
+
status: 0,
|
1373 |
+
statusText: '',
|
1374 |
+
|
1375 |
+
getStatus: Ajax.Request.prototype.getStatus,
|
1376 |
+
|
1377 |
+
getStatusText: function() {
|
1378 |
+
try {
|
1379 |
+
return this.transport.statusText || '';
|
1380 |
+
} catch (e) { return '' }
|
1381 |
+
},
|
1382 |
+
|
1383 |
+
getHeader: Ajax.Request.prototype.getHeader,
|
1384 |
+
|
1385 |
+
getAllHeaders: function() {
|
1386 |
+
try {
|
1387 |
+
return this.getAllResponseHeaders();
|
1388 |
+
} catch (e) { return null }
|
1389 |
+
},
|
1390 |
+
|
1391 |
+
getResponseHeader: function(name) {
|
1392 |
+
return this.transport.getResponseHeader(name);
|
1393 |
+
},
|
1394 |
+
|
1395 |
+
getAllResponseHeaders: function() {
|
1396 |
+
return this.transport.getAllResponseHeaders();
|
1397 |
+
},
|
1398 |
+
|
1399 |
+
_getHeaderJSON: function() {
|
1400 |
+
var json = this.getHeader('X-JSON');
|
1401 |
+
if (!json) return null;
|
1402 |
+
json = decodeURIComponent(escape(json));
|
1403 |
+
try {
|
1404 |
+
return json.evalJSON(this.request.options.sanitizeJSON ||
|
1405 |
+
!this.request.isSameOrigin());
|
1406 |
+
} catch (e) {
|
1407 |
+
this.request.dispatchException(e);
|
1408 |
+
}
|
1409 |
+
},
|
1410 |
+
|
1411 |
+
_getResponseJSON: function() {
|
1412 |
+
var options = this.request.options;
|
1413 |
+
if (!options.evalJSON || (options.evalJSON != 'force' &&
|
1414 |
+
!(this.getHeader('Content-type') || '').include('application/json')) ||
|
1415 |
+
this.responseText.blank())
|
1416 |
+
return null;
|
1417 |
+
try {
|
1418 |
+
return this.responseText.evalJSON(options.sanitizeJSON ||
|
1419 |
+
!this.request.isSameOrigin());
|
1420 |
+
} catch (e) {
|
1421 |
+
this.request.dispatchException(e);
|
1422 |
+
}
|
1423 |
+
}
|
1424 |
+
});
|
1425 |
+
|
1426 |
+
Ajax.Updater = Class.create(Ajax.Request, {
|
1427 |
+
initialize: function($super, container, url, options) {
|
1428 |
+
this.container = {
|
1429 |
+
success: (container.success || container),
|
1430 |
+
failure: (container.failure || (container.success ? null : container))
|
1431 |
+
};
|
1432 |
+
|
1433 |
+
options = Object.clone(options);
|
1434 |
+
var onComplete = options.onComplete;
|
1435 |
+
options.onComplete = (function(response, json) {
|
1436 |
+
this.updateContent(response.responseText);
|
1437 |
+
if (Object.isFunction(onComplete)) onComplete(response, json);
|
1438 |
+
}).bind(this);
|
1439 |
+
|
1440 |
+
$super(url, options);
|
1441 |
+
},
|
1442 |
+
|
1443 |
+
updateContent: function(responseText) {
|
1444 |
+
var receiver = this.container[this.success() ? 'success' : 'failure'],
|
1445 |
+
options = this.options;
|
1446 |
+
|
1447 |
+
if (!options.evalScripts) responseText = responseText.stripScripts();
|
1448 |
+
|
1449 |
+
if (receiver = $(receiver)) {
|
1450 |
+
if (options.insertion) {
|
1451 |
+
if (Object.isString(options.insertion)) {
|
1452 |
+
var insertion = { }; insertion[options.insertion] = responseText;
|
1453 |
+
receiver.insert(insertion);
|
1454 |
+
}
|
1455 |
+
else options.insertion(receiver, responseText);
|
1456 |
+
}
|
1457 |
+
else receiver.update(responseText);
|
1458 |
+
}
|
1459 |
+
}
|
1460 |
+
});
|
1461 |
+
|
1462 |
+
Ajax.PeriodicalUpdater = Class.create(Ajax.Base, {
|
1463 |
+
initialize: function($super, container, url, options) {
|
1464 |
+
$super(options);
|
1465 |
+
this.onComplete = this.options.onComplete;
|
1466 |
+
|
1467 |
+
this.frequency = (this.options.frequency || 2);
|
1468 |
+
this.decay = (this.options.decay || 1);
|
1469 |
+
|
1470 |
+
this.updater = { };
|
1471 |
+
this.container = container;
|
1472 |
+
this.url = url;
|
1473 |
+
|
1474 |
+
this.start();
|
1475 |
+
},
|
1476 |
+
|
1477 |
+
start: function() {
|
1478 |
+
this.options.onComplete = this.updateComplete.bind(this);
|
1479 |
+
this.onTimerEvent();
|
1480 |
+
},
|
1481 |
+
|
1482 |
+
stop: function() {
|
1483 |
+
this.updater.options.onComplete = undefined;
|
1484 |
+
clearTimeout(this.timer);
|
1485 |
+
(this.onComplete || Prototype.emptyFunction).apply(this, arguments);
|
1486 |
+
},
|
1487 |
+
|
1488 |
+
updateComplete: function(response) {
|
1489 |
+
if (this.options.decay) {
|
1490 |
+
this.decay = (response.responseText == this.lastText ?
|
1491 |
+
this.decay * this.options.decay : 1);
|
1492 |
+
|
1493 |
+
this.lastText = response.responseText;
|
1494 |
+
}
|
1495 |
+
this.timer = this.onTimerEvent.bind(this).delay(this.decay * this.frequency);
|
1496 |
+
},
|
1497 |
+
|
1498 |
+
onTimerEvent: function() {
|
1499 |
+
this.updater = new Ajax.Updater(this.container, this.url, this.options);
|
1500 |
+
}
|
1501 |
+
});
|
1502 |
+
function $(element) {
|
1503 |
+
if (arguments.length > 1) {
|
1504 |
+
for (var i = 0, elements = [], length = arguments.length; i < length; i++)
|
1505 |
+
elements.push($(arguments[i]));
|
1506 |
+
return elements;
|
1507 |
+
}
|
1508 |
+
if (Object.isString(element))
|
1509 |
+
element = document.getElementById(element);
|
1510 |
+
return Element.extend(element);
|
1511 |
+
}
|
1512 |
+
|
1513 |
+
if (Prototype.BrowserFeatures.XPath) {
|
1514 |
+
document._getElementsByXPath = function(expression, parentElement) {
|
1515 |
+
var results = [];
|
1516 |
+
var query = document.evaluate(expression, $(parentElement) || document,
|
1517 |
+
null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
|
1518 |
+
for (var i = 0, length = query.snapshotLength; i < length; i++)
|
1519 |
+
results.push(Element.extend(query.snapshotItem(i)));
|
1520 |
+
return results;
|
1521 |
+
};
|
1522 |
+
}
|
1523 |
+
|
1524 |
+
/*--------------------------------------------------------------------------*/
|
1525 |
+
|
1526 |
+
if (!window.Node) var Node = { };
|
1527 |
+
|
1528 |
+
if (!Node.ELEMENT_NODE) {
|
1529 |
+
// DOM level 2 ECMAScript Language Binding
|
1530 |
+
Object.extend(Node, {
|
1531 |
+
ELEMENT_NODE: 1,
|
1532 |
+
ATTRIBUTE_NODE: 2,
|
1533 |
+
TEXT_NODE: 3,
|
1534 |
+
CDATA_SECTION_NODE: 4,
|
1535 |
+
ENTITY_REFERENCE_NODE: 5,
|
1536 |
+
ENTITY_NODE: 6,
|
1537 |
+
PROCESSING_INSTRUCTION_NODE: 7,
|
1538 |
+
COMMENT_NODE: 8,
|
1539 |
+
DOCUMENT_NODE: 9,
|
1540 |
+
DOCUMENT_TYPE_NODE: 10,
|
1541 |
+
DOCUMENT_FRAGMENT_NODE: 11,
|
1542 |
+
NOTATION_NODE: 12
|
1543 |
+
});
|
1544 |
+
}
|
1545 |
+
|
1546 |
+
(function() {
|
1547 |
+
var element = this.Element;
|
1548 |
+
this.Element = function(tagName, attributes) {
|
1549 |
+
attributes = attributes || { };
|
1550 |
+
tagName = tagName.toLowerCase();
|
1551 |
+
var cache = Element.cache;
|
1552 |
+
if (Prototype.Browser.IE && attributes.name) {
|
1553 |
+
tagName = '<' + tagName + ' name="' + attributes.name + '">';
|
1554 |
+
delete attributes.name;
|
1555 |
+
return Element.writeAttribute(document.createElement(tagName), attributes);
|
1556 |
+
}
|
1557 |
+
if (!cache[tagName]) cache[tagName] = Element.extend(document.createElement(tagName));
|
1558 |
+
return Element.writeAttribute(cache[tagName].cloneNode(false), attributes);
|
1559 |
+
};
|
1560 |
+
Object.extend(this.Element, element || { });
|
1561 |
+
}).call(window);
|
1562 |
+
|
1563 |
+
Element.cache = { };
|
1564 |
+
|
1565 |
+
Element.Methods = {
|
1566 |
+
visible: function(element) {
|
1567 |
+
return $(element).style.display != 'none';
|
1568 |
+
},
|
1569 |
+
|
1570 |
+
toggle: function(element) {
|
1571 |
+
element = $(element);
|
1572 |
+
Element[Element.visible(element) ? 'hide' : 'show'](element);
|
1573 |
+
return element;
|
1574 |
+
},
|
1575 |
+
|
1576 |
+
hide: function(element) {
|
1577 |
+
$(element).style.display = 'none';
|
1578 |
+
return element;
|
1579 |
+
},
|
1580 |
+
|
1581 |
+
show: function(element) {
|
1582 |
+
$(element).style.display = '';
|
1583 |
+
return element;
|
1584 |
+
},
|
1585 |
+
|
1586 |
+
remove: function(element) {
|
1587 |
+
element = $(element);
|
1588 |
+
element.parentNode.removeChild(element);
|
1589 |
+
return element;
|
1590 |
+
},
|
1591 |
+
|
1592 |
+
update: function(element, content) {
|
1593 |
+
element = $(element);
|
1594 |
+
if (content && content.toElement) content = content.toElement();
|
1595 |
+
if (Object.isElement(content)) return element.update().insert(content);
|
1596 |
+
content = Object.toHTML(content);
|
1597 |
+
element.innerHTML = content.stripScripts();
|
1598 |
+
content.evalScripts.bind(content).defer();
|
1599 |
+
return element;
|
1600 |
+
},
|
1601 |
+
|
1602 |
+
replace: function(element, content) {
|
1603 |
+
element = $(element);
|
1604 |
+
if (content && content.toElement) content = content.toElement();
|
1605 |
+
else if (!Object.isElement(content)) {
|
1606 |
+
content = Object.toHTML(content);
|
1607 |
+
var range = element.ownerDocument.createRange();
|
1608 |
+
range.selectNode(element);
|
1609 |
+
content.evalScripts.bind(content).defer();
|
1610 |
+
content = range.createContextualFragment(content.stripScripts());
|
1611 |
+
}
|
1612 |
+
element.parentNode.replaceChild(content, element);
|
1613 |
+
return element;
|
1614 |
+
},
|
1615 |
+
|
1616 |
+
insert: function(element, insertions) {
|
1617 |
+
element = $(element);
|
1618 |
+
|
1619 |
+
if (Object.isString(insertions) || Object.isNumber(insertions) ||
|
1620 |
+
Object.isElement(insertions) || (insertions && (insertions.toElement || insertions.toHTML)))
|
1621 |
+
insertions = {bottom:insertions};
|
1622 |
+
|
1623 |
+
var content, insert, tagName, childNodes;
|
1624 |
+
|
1625 |
+
for (var position in insertions) {
|
1626 |
+
content = insertions[position];
|
1627 |
+
position = position.toLowerCase();
|
1628 |
+
insert = Element._insertionTranslations[position];
|
1629 |
+
|
1630 |
+
if (content && content.toElement) content = content.toElement();
|
1631 |
+
if (Object.isElement(content)) {
|
1632 |
+
insert(element, content);
|
1633 |
+
continue;
|
1634 |
+
}
|
1635 |
+
|
1636 |
+
content = Object.toHTML(content);
|
1637 |
+
|
1638 |
+
tagName = ((position == 'before' || position == 'after')
|
1639 |
+
? element.parentNode : element).tagName.toUpperCase();
|
1640 |
+
|
1641 |
+
childNodes = Element._getContentFromAnonymousElement(tagName, content.stripScripts());
|
1642 |
+
|
1643 |
+
if (position == 'top' || position == 'after') childNodes.reverse();
|
1644 |
+
childNodes.each(insert.curry(element));
|
1645 |
+
|
1646 |
+
content.evalScripts.bind(content).defer();
|
1647 |
+
}
|
1648 |
+
|
1649 |
+
return element;
|
1650 |
+
},
|
1651 |
+
|
1652 |
+
wrap: function(element, wrapper, attributes) {
|
1653 |
+
element = $(element);
|
1654 |
+
if (Object.isElement(wrapper))
|
1655 |
+
$(wrapper).writeAttribute(attributes || { });
|
1656 |
+
else if (Object.isString(wrapper)) wrapper = new Element(wrapper, attributes);
|
1657 |
+
else wrapper = new Element('div', wrapper);
|
1658 |
+
if (element.parentNode)
|
1659 |
+
element.parentNode.replaceChild(wrapper, element);
|
1660 |
+
wrapper.appendChild(element);
|
1661 |
+
return wrapper;
|
1662 |
+
},
|
1663 |
+
|
1664 |
+
inspect: function(element) {
|
1665 |
+
element = $(element);
|
1666 |
+
var result = '<' + element.tagName.toLowerCase();
|
1667 |
+
$H({'id': 'id', 'className': 'class'}).each(function(pair) {
|
1668 |
+
var property = pair.first(), attribute = pair.last();
|
1669 |
+
var value = (element[property] || '').toString();
|
1670 |
+
if (value) result += ' ' + attribute + '=' + value.inspect(true);
|
1671 |
+
});
|
1672 |
+
return result + '>';
|
1673 |
+
},
|
1674 |
+
|
1675 |
+
recursivelyCollect: function(element, property) {
|
1676 |
+
element = $(element);
|
1677 |
+
var elements = [];
|
1678 |
+
while (element = element[property])
|
1679 |
+
if (element.nodeType == 1)
|
1680 |
+
elements.push(Element.extend(element));
|
1681 |
+
return elements;
|
1682 |
+
},
|
1683 |
+
|
1684 |
+
ancestors: function(element) {
|
1685 |
+
return $(element).recursivelyCollect('parentNode');
|
1686 |
+
},
|
1687 |
+
|
1688 |
+
descendants: function(element) {
|
1689 |
+
return $(element).select("*");
|
1690 |
+
},
|
1691 |
+
|
1692 |
+
firstDescendant: function(element) {
|
1693 |
+
element = $(element).firstChild;
|
1694 |
+
while (element && element.nodeType != 1) element = element.nextSibling;
|
1695 |
+
return $(element);
|
1696 |
+
},
|
1697 |
+
|
1698 |
+
immediateDescendants: function(element) {
|
1699 |
+
if (!(element = $(element).firstChild)) return [];
|
1700 |
+
while (element && element.nodeType != 1) element = element.nextSibling;
|
1701 |
+
if (element) return [element].concat($(element).nextSiblings());
|
1702 |
+
return [];
|
1703 |
+
},
|
1704 |
+
|
1705 |
+
previousSiblings: function(element) {
|
1706 |
+
return $(element).recursivelyCollect('previousSibling');
|
1707 |
+
},
|
1708 |
+
|
1709 |
+
nextSiblings: function(element) {
|
1710 |
+
return $(element).recursivelyCollect('nextSibling');
|
1711 |
+
},
|
1712 |
+
|
1713 |
+
siblings: function(element) {
|
1714 |
+
element = $(element);
|
1715 |
+
return element.previousSiblings().reverse().concat(element.nextSiblings());
|
1716 |
+
},
|
1717 |
+
|
1718 |
+
match: function(element, selector) {
|
1719 |
+
if (Object.isString(selector))
|
1720 |
+
selector = new Selector(selector);
|
1721 |
+
return selector.match($(element));
|
1722 |
+
},
|
1723 |
+
|
1724 |
+
up: function(element, expression, index) {
|
1725 |
+
element = $(element);
|
1726 |
+
if (arguments.length == 1) return $(element.parentNode);
|
1727 |
+
var ancestors = element.ancestors();
|
1728 |
+
return Object.isNumber(expression) ? ancestors[expression] :
|
1729 |
+
Selector.findElement(ancestors, expression, index);
|
1730 |
+
},
|
1731 |
+
|
1732 |
+
down: function(element, expression, index) {
|
1733 |
+
element = $(element);
|
1734 |
+
if (arguments.length == 1) return element.firstDescendant();
|
1735 |
+
return Object.isNumber(expression) ? element.descendants()[expression] :
|
1736 |
+
element.select(expression)[index || 0];
|
1737 |
+
},
|
1738 |
+
|
1739 |
+
previous: function(element, expression, index) {
|
1740 |
+
element = $(element);
|
1741 |
+
if (arguments.length == 1) return $(Selector.handlers.previousElementSibling(element));
|
1742 |
+
var previousSiblings = element.previousSiblings();
|
1743 |
+
return Object.isNumber(expression) ? previousSiblings[expression] :
|
1744 |
+
Selector.findElement(previousSiblings, expression, index);
|
1745 |
+
},
|
1746 |
+
|
1747 |
+
next: function(element, expression, index) {
|
1748 |
+
element = $(element);
|
1749 |
+
if (arguments.length == 1) return $(Selector.handlers.nextElementSibling(element));
|
1750 |
+
var nextSiblings = element.nextSiblings();
|
1751 |
+
return Object.isNumber(expression) ? nextSiblings[expression] :
|
1752 |
+
Selector.findElement(nextSiblings, expression, index);
|
1753 |
+
},
|
1754 |
+
|
1755 |
+
select: function() {
|
1756 |
+
var args = $A(arguments), element = $(args.shift());
|
1757 |
+
return Selector.findChildElements(element, args);
|
1758 |
+
},
|
1759 |
+
|
1760 |
+
adjacent: function() {
|
1761 |
+
var args = $A(arguments), element = $(args.shift());
|
1762 |
+
return Selector.findChildElements(element.parentNode, args).without(element);
|
1763 |
+
},
|
1764 |
+
|
1765 |
+
identify: function(element) {
|
1766 |
+
element = $(element);
|
1767 |
+
var id = element.readAttribute('id'), self = arguments.callee;
|
1768 |
+
if (id) return id;
|
1769 |
+
do { id = 'anonymous_element_' + self.counter++ } while ($(id));
|
1770 |
+
element.writeAttribute('id', id);
|
1771 |
+
return id;
|
1772 |
+
},
|
1773 |
+
|
1774 |
+
readAttribute: function(element, name) {
|
1775 |
+
element = $(element);
|
1776 |
+
if (Prototype.Browser.IE) {
|
1777 |
+
var t = Element._attributeTranslations.read;
|
1778 |
+
if (t.values[name]) return t.values[name](element, name);
|
1779 |
+
if (t.names[name]) name = t.names[name];
|
1780 |
+
if (name.include(':')) {
|
1781 |
+
return (!element.attributes || !element.attributes[name]) ? null :
|
1782 |
+
element.attributes[name].value;
|
1783 |
+
}
|
1784 |
+
}
|
1785 |
+
return element.getAttribute(name);
|
1786 |
+
},
|
1787 |
+
|
1788 |
+
writeAttribute: function(element, name, value) {
|
1789 |
+
element = $(element);
|
1790 |
+
var attributes = { }, t = Element._attributeTranslations.write;
|
1791 |
+
|
1792 |
+
if (typeof name == 'object') attributes = name;
|
1793 |
+
else attributes[name] = Object.isUndefined(value) ? true : value;
|
1794 |
+
|
1795 |
+
for (var attr in attributes) {
|
1796 |
+
name = t.names[attr] || attr;
|
1797 |
+
value = attributes[attr];
|
1798 |
+
if (t.values[attr]) name = t.values[attr](element, value);
|
1799 |
+
if (value === false || value === null)
|
1800 |
+
element.removeAttribute(name);
|
1801 |
+
else if (value === true)
|
1802 |
+
element.setAttribute(name, name);
|
1803 |
+
else element.setAttribute(name, value);
|
1804 |
+
}
|
1805 |
+
return element;
|
1806 |
+
},
|
1807 |
+
|
1808 |
+
getHeight: function(element) {
|
1809 |
+
return $(element).getDimensions().height;
|
1810 |
+
},
|
1811 |
+
|
1812 |
+
getWidth: function(element) {
|
1813 |
+
return $(element).getDimensions().width;
|
1814 |
+
},
|
1815 |
+
|
1816 |
+
classNames: function(element) {
|
1817 |
+
return new Element.ClassNames(element);
|
1818 |
+
},
|
1819 |
+
|
1820 |
+
hasClassName: function(element, className) {
|
1821 |
+
if (!(element = $(element))) return;
|
1822 |
+
var elementClassName = element.className;
|
1823 |
+
return (elementClassName.length > 0 && (elementClassName == className ||
|
1824 |
+
new RegExp("(^|\\s)" + className + "(\\s|$)").test(elementClassName)));
|
1825 |
+
},
|
1826 |
+
|
1827 |
+
addClassName: function(element, className) {
|
1828 |
+
if (!(element = $(element))) return;
|
1829 |
+
if (!element.hasClassName(className))
|
1830 |
+
element.className += (element.className ? ' ' : '') + className;
|
1831 |
+
return element;
|
1832 |
+
},
|
1833 |
+
|
1834 |
+
removeClassName: function(element, className) {
|
1835 |
+
if (!(element = $(element))) return;
|
1836 |
+
element.className = element.className.replace(
|
1837 |
+
new RegExp("(^|\\s+)" + className + "(\\s+|$)"), ' ').strip();
|
1838 |
+
return element;
|
1839 |
+
},
|
1840 |
+
|
1841 |
+
toggleClassName: function(element, className) {
|
1842 |
+
if (!(element = $(element))) return;
|
1843 |
+
return element[element.hasClassName(className) ?
|
1844 |
+
'removeClassName' : 'addClassName'](className);
|
1845 |
+
},
|
1846 |
+
|
1847 |
+
// removes whitespace-only text node children
|
1848 |
+
cleanWhitespace: function(element) {
|
1849 |
+
element = $(element);
|
1850 |
+
var node = element.firstChild;
|
1851 |
+
while (node) {
|
1852 |
+
var nextNode = node.nextSibling;
|
1853 |
+
if (node.nodeType == 3 && !/\S/.test(node.nodeValue))
|
1854 |
+
element.removeChild(node);
|
1855 |
+
node = nextNode;
|
1856 |
+
}
|
1857 |
+
return element;
|
1858 |
+
},
|
1859 |
+
|
1860 |
+
empty: function(element) {
|
1861 |
+
return $(element).innerHTML.blank();
|
1862 |
+
},
|
1863 |
+
|
1864 |
+
descendantOf: function(element, ancestor) {
|
1865 |
+
element = $(element), ancestor = $(ancestor);
|
1866 |
+
var originalAncestor = ancestor;
|
1867 |
+
|
1868 |
+
if (element.compareDocumentPosition)
|
1869 |
+
return (element.compareDocumentPosition(ancestor) & 8) === 8;
|
1870 |
+
|
1871 |
+
if (element.sourceIndex && !Prototype.Browser.Opera) {
|
1872 |
+
var e = element.sourceIndex, a = ancestor.sourceIndex,
|
1873 |
+
nextAncestor = ancestor.nextSibling;
|
1874 |
+
if (!nextAncestor) {
|
1875 |
+
do { ancestor = ancestor.parentNode; }
|
1876 |
+
while (!(nextAncestor = ancestor.nextSibling) && ancestor.parentNode);
|
1877 |
+
}
|
1878 |
+
if (nextAncestor && nextAncestor.sourceIndex)
|
1879 |
+
return (e > a && e < nextAncestor.sourceIndex);
|
1880 |
+
}
|
1881 |
+
|
1882 |
+
while (element = element.parentNode)
|
1883 |
+
if (element == originalAncestor) return true;
|
1884 |
+
return false;
|
1885 |
+
},
|
1886 |
+
|
1887 |
+
scrollTo: function(element) {
|
1888 |
+
element = $(element);
|
1889 |
+
var pos = element.cumulativeOffset();
|
1890 |
+
window.scrollTo(pos[0], pos[1]);
|
1891 |
+
return element;
|
1892 |
+
},
|
1893 |
+
|
1894 |
+
getStyle: function(element, style) {
|
1895 |
+
element = $(element);
|
1896 |
+
style = style == 'float' ? 'cssFloat' : style.camelize();
|
1897 |
+
var value = element.style[style];
|
1898 |
+
if (!value) {
|
1899 |
+
var css = document.defaultView.getComputedStyle(element, null);
|
1900 |
+
value = css ? css[style] : null;
|
1901 |
+
}
|
1902 |
+
if (style == 'opacity') return value ? parseFloat(value) : 1.0;
|
1903 |
+
return value == 'auto' ? null : value;
|
1904 |
+
},
|
1905 |
+
|
1906 |
+
getOpacity: function(element) {
|
1907 |
+
return $(element).getStyle('opacity');
|
1908 |
+
},
|
1909 |
+
|
1910 |
+
setStyle: function(element, styles) {
|
1911 |
+
element = $(element);
|
1912 |
+
var elementStyle = element.style, match;
|
1913 |
+
if (Object.isString(styles)) {
|
1914 |
+
element.style.cssText += ';' + styles;
|
1915 |
+
return styles.include('opacity') ?
|
1916 |
+
element.setOpacity(styles.match(/opacity:\s*(\d?\.?\d*)/)[1]) : element;
|
1917 |
+
}
|
1918 |
+
for (var property in styles) {
|
1919 |
+
if (property == 'opacity') element.setOpacity(styles[property]);
|
1920 |
+
else
|
1921 |
+
elementStyle[(property == 'float' || property == 'cssFloat') ?
|
1922 |
+
(Object.isUndefined(elementStyle.styleFloat) ? 'cssFloat' : 'styleFloat') :
|
1923 |
+
property] = styles[property];
|
1924 |
+
}
|
1925 |
+
|
1926 |
+
return element;
|
1927 |
+
},
|
1928 |
+
|
1929 |
+
setOpacity: function(element, value) {
|
1930 |
+
element = $(element);
|
1931 |
+
element.style.opacity = (value == 1 || value === '') ? '' :
|
1932 |
+
(value < 0.00001) ? 0 : value;
|
1933 |
+
return element;
|
1934 |
+
},
|
1935 |
+
|
1936 |
+
getDimensions: function(element) {
|
1937 |
+
element = $(element);
|
1938 |
+
var display = $(element).getStyle('display');
|
1939 |
+
if (display != 'none' && display != null) // Safari bug
|
1940 |
+
return {width: element.offsetWidth, height: element.offsetHeight};
|
1941 |
+
|
1942 |
+
// All *Width and *Height properties give 0 on elements with display none,
|
1943 |
+
// so enable the element temporarily
|
1944 |
+
var els = element.style;
|
1945 |
+
var originalVisibility = els.visibility;
|
1946 |
+
var originalPosition = els.position;
|
1947 |
+
var originalDisplay = els.display;
|
1948 |
+
els.visibility = 'hidden';
|
1949 |
+
els.position = 'absolute';
|
1950 |
+
els.display = 'block';
|
1951 |
+
var originalWidth = element.clientWidth;
|
1952 |
+
var originalHeight = element.clientHeight;
|
1953 |
+
els.display = originalDisplay;
|
1954 |
+
els.position = originalPosition;
|
1955 |
+
els.visibility = originalVisibility;
|
1956 |
+
return {width: originalWidth, height: originalHeight};
|
1957 |
+
},
|
1958 |
+
|
1959 |
+
makePositioned: function(element) {
|
1960 |
+
element = $(element);
|
1961 |
+
var pos = Element.getStyle(element, 'position');
|
1962 |
+
if (pos == 'static' || !pos) {
|
1963 |
+
element._madePositioned = true;
|
1964 |
+
element.style.position = 'relative';
|
1965 |
+
// Opera returns the offset relative to the positioning context, when an
|
1966 |
+
// element is position relative but top and left have not been defined
|
1967 |
+
if (window.opera) {
|
1968 |
+
element.style.top = 0;
|
1969 |
+
element.style.left = 0;
|
1970 |
+
}
|
1971 |
+
}
|
1972 |
+
return element;
|
1973 |
+
},
|
1974 |
+
|
1975 |
+
undoPositioned: function(element) {
|
1976 |
+
element = $(element);
|
1977 |
+
if (element._madePositioned) {
|
1978 |
+
element._madePositioned = undefined;
|
1979 |
+
element.style.position =
|
1980 |
+
element.style.top =
|
1981 |
+
element.style.left =
|
1982 |
+
element.style.bottom =
|
1983 |
+
element.style.right = '';
|
1984 |
+
}
|
1985 |
+
return element;
|
1986 |
+
},
|
1987 |
+
|
1988 |
+
makeClipping: function(element) {
|
1989 |
+
element = $(element);
|
1990 |
+
if (element._overflow) return element;
|
1991 |
+
element._overflow = Element.getStyle(element, 'overflow') || 'auto';
|
1992 |
+
if (element._overflow !== 'hidden')
|
1993 |
+
element.style.overflow = 'hidden';
|
1994 |
+
return element;
|
1995 |
+
},
|
1996 |
+
|
1997 |
+
undoClipping: function(element) {
|
1998 |
+
element = $(element);
|
1999 |
+
if (!element._overflow) return element;
|
2000 |
+
element.style.overflow = element._overflow == 'auto' ? '' : element._overflow;
|
2001 |
+
element._overflow = null;
|
2002 |
+
return element;
|
2003 |
+
},
|
2004 |
+
|
2005 |
+
cumulativeOffset: function(element) {
|
2006 |
+
var valueT = 0, valueL = 0;
|
2007 |
+
do {
|
2008 |
+
valueT += element.offsetTop || 0;
|
2009 |
+
valueL += element.offsetLeft || 0;
|
2010 |
+
element = element.offsetParent;
|
2011 |
+
} while (element);
|
2012 |
+
return Element._returnOffset(valueL, valueT);
|
2013 |
+
},
|
2014 |
+
|
2015 |
+
positionedOffset: function(element) {
|
2016 |
+
var valueT = 0, valueL = 0;
|
2017 |
+
do {
|
2018 |
+
valueT += element.offsetTop || 0;
|
2019 |
+
valueL += element.offsetLeft || 0;
|
2020 |
+
element = element.offsetParent;
|
2021 |
+
if (element) {
|
2022 |
+
if (element.tagName == 'BODY') break;
|
2023 |
+
var p = Element.getStyle(element, 'position');
|
2024 |
+
if (p !== 'static') break;
|
2025 |
+
}
|
2026 |
+
} while (element);
|
2027 |
+
return Element._returnOffset(valueL, valueT);
|
2028 |
+
},
|
2029 |
+
|
2030 |
+
absolutize: function(element) {
|
2031 |
+
element = $(element);
|
2032 |
+
if (element.getStyle('position') == 'absolute') return;
|
2033 |
+
// Position.prepare(); // To be done manually by Scripty when it needs it.
|
2034 |
+
|
2035 |
+
var offsets = element.positionedOffset();
|
2036 |
+
var top = offsets[1];
|
2037 |
+
var left = offsets[0];
|
2038 |
+
var width = element.clientWidth;
|
2039 |
+
var height = element.clientHeight;
|
2040 |
+
|
2041 |
+
element._originalLeft = left - parseFloat(element.style.left || 0);
|
2042 |
+
element._originalTop = top - parseFloat(element.style.top || 0);
|
2043 |
+
element._originalWidth = element.style.width;
|
2044 |
+
element._originalHeight = element.style.height;
|
2045 |
+
|
2046 |
+
element.style.position = 'absolute';
|
2047 |
+
element.style.top = top + 'px';
|
2048 |
+
element.style.left = left + 'px';
|
2049 |
+
element.style.width = width + 'px';
|
2050 |
+
element.style.height = height + 'px';
|
2051 |
+
return element;
|
2052 |
+
},
|
2053 |
+
|
2054 |
+
relativize: function(element) {
|
2055 |
+
element = $(element);
|
2056 |
+
if (element.getStyle('position') == 'relative') return;
|
2057 |
+
// Position.prepare(); // To be done manually by Scripty when it needs it.
|
2058 |
+
|
2059 |
+
element.style.position = 'relative';
|
2060 |
+
var top = parseFloat(element.style.top || 0) - (element._originalTop || 0);
|
2061 |
+
var left = parseFloat(element.style.left || 0) - (element._originalLeft || 0);
|
2062 |
+
|
2063 |
+
element.style.top = top + 'px';
|
2064 |
+
element.style.left = left + 'px';
|
2065 |
+
element.style.height = element._originalHeight;
|
2066 |
+
element.style.width = element._originalWidth;
|
2067 |
+
return element;
|
2068 |
+
},
|
2069 |
+
|
2070 |
+
cumulativeScrollOffset: function(element) {
|
2071 |
+
var valueT = 0, valueL = 0;
|
2072 |
+
do {
|
2073 |
+
valueT += element.scrollTop || 0;
|
2074 |
+
valueL += element.scrollLeft || 0;
|
2075 |
+
element = element.parentNode;
|
2076 |
+
} while (element);
|
2077 |
+
return Element._returnOffset(valueL, valueT);
|
2078 |
+
},
|
2079 |
+
|
2080 |
+
getOffsetParent: function(element) {
|
2081 |
+
if (element.offsetParent) return $(element.offsetParent);
|
2082 |
+
if (element == document.body) return $(element);
|
2083 |
+
|
2084 |
+
while ((element = element.parentNode) && element != document.body)
|
2085 |
+
if (Element.getStyle(element, 'position') != 'static')
|
2086 |
+
return $(element);
|
2087 |
+
|
2088 |
+
return $(document.body);
|
2089 |
+
},
|
2090 |
+
|
2091 |
+
viewportOffset: function(forElement) {
|
2092 |
+
var valueT = 0, valueL = 0;
|
2093 |
+
|
2094 |
+
var element = forElement;
|
2095 |
+
do {
|
2096 |
+
valueT += element.offsetTop || 0;
|
2097 |
+
valueL += element.offsetLeft || 0;
|
2098 |
+
|
2099 |
+
// Safari fix
|
2100 |
+
if (element.offsetParent == document.body &&
|
2101 |
+
Element.getStyle(element, 'position') == 'absolute') break;
|
2102 |
+
|
2103 |
+
} while (element = element.offsetParent);
|
2104 |
+
|
2105 |
+
element = forElement;
|
2106 |
+
do {
|
2107 |
+
if (!Prototype.Browser.Opera || element.tagName == 'BODY') {
|
2108 |
+
valueT -= element.scrollTop || 0;
|
2109 |
+
valueL -= element.scrollLeft || 0;
|
2110 |
+
}
|
2111 |
+
} while (element = element.parentNode);
|
2112 |
+
|
2113 |
+
return Element._returnOffset(valueL, valueT);
|
2114 |
+
},
|
2115 |
+
|
2116 |
+
clonePosition: function(element, source) {
|
2117 |
+
var options = Object.extend({
|
2118 |
+
setLeft: true,
|
2119 |
+
setTop: true,
|
2120 |
+
setWidth: true,
|
2121 |
+
setHeight: true,
|
2122 |
+
offsetTop: 0,
|
2123 |
+
offsetLeft: 0
|
2124 |
+
}, arguments[2] || { });
|
2125 |
+
|
2126 |
+
// find page position of source
|
2127 |
+
source = $(source);
|
2128 |
+
var p = source.viewportOffset();
|
2129 |
+
|
2130 |
+
// find coordinate system to use
|
2131 |
+
element = $(element);
|
2132 |
+
var delta = [0, 0];
|
2133 |
+
var parent = null;
|
2134 |
+
// delta [0,0] will do fine with position: fixed elements,
|
2135 |
+
// position:absolute needs offsetParent deltas
|
2136 |
+
if (Element.getStyle(element, 'position') == 'absolute') {
|
2137 |
+
parent = element.getOffsetParent();
|
2138 |
+
delta = parent.viewportOffset();
|
2139 |
+
}
|
2140 |
+
|
2141 |
+
// correct by body offsets (fixes Safari)
|
2142 |
+
if (parent == document.body) {
|
2143 |
+
delta[0] -= document.body.offsetLeft;
|
2144 |
+
delta[1] -= document.body.offsetTop;
|
2145 |
+
}
|
2146 |
+
|
2147 |
+
// set position
|
2148 |
+
if (options.setLeft) element.style.left = (p[0] - delta[0] + options.offsetLeft) + 'px';
|
2149 |
+
if (options.setTop) element.style.top = (p[1] - delta[1] + options.offsetTop) + 'px';
|
2150 |
+
if (options.setWidth) element.style.width = source.offsetWidth + 'px';
|
2151 |
+
if (options.setHeight) element.style.height = source.offsetHeight + 'px';
|
2152 |
+
return element;
|
2153 |
+
}
|
2154 |
+
};
|
2155 |
+
|
2156 |
+
Element.Methods.identify.counter = 1;
|
2157 |
+
|
2158 |
+
Object.extend(Element.Methods, {
|
2159 |
+
getElementsBySelector: Element.Methods.select,
|
2160 |
+
childElements: Element.Methods.immediateDescendants
|
2161 |
+
});
|
2162 |
+
|
2163 |
+
Element._attributeTranslations = {
|
2164 |
+
write: {
|
2165 |
+
names: {
|
2166 |
+
className: 'class',
|
2167 |
+
htmlFor: 'for'
|
2168 |
+
},
|
2169 |
+
values: { }
|
2170 |
+
}
|
2171 |
+
};
|
2172 |
+
|
2173 |
+
if (Prototype.Browser.Opera) {
|
2174 |
+
Element.Methods.getStyle = Element.Methods.getStyle.wrap(
|
2175 |
+
function(proceed, element, style) {
|
2176 |
+
switch (style) {
|
2177 |
+
case 'left': case 'top': case 'right': case 'bottom':
|
2178 |
+
if (proceed(element, 'position') === 'static') return null;
|
2179 |
+
case 'height': case 'width':
|
2180 |
+
// returns '0px' for hidden elements; we want it to return null
|
2181 |
+
if (!Element.visible(element)) return null;
|
2182 |
+
|
2183 |
+
// returns the border-box dimensions rather than the content-box
|
2184 |
+
// dimensions, so we subtract padding and borders from the value
|
2185 |
+
var dim = parseInt(proceed(element, style), 10);
|
2186 |
+
|
2187 |
+
if (dim !== element['offset' + style.capitalize()])
|
2188 |
+
return dim + 'px';
|
2189 |
+
|
2190 |
+
var properties;
|
2191 |
+
if (style === 'height') {
|
2192 |
+
properties = ['border-top-width', 'padding-top',
|
2193 |
+
'padding-bottom', 'border-bottom-width'];
|
2194 |
+
}
|
2195 |
+
else {
|
2196 |
+
properties = ['border-left-width', 'padding-left',
|
2197 |
+
'padding-right', 'border-right-width'];
|
2198 |
+
}
|
2199 |
+
return properties.inject(dim, function(memo, property) {
|
2200 |
+
var val = proceed(element, property);
|
2201 |
+
return val === null ? memo : memo - parseInt(val, 10);
|
2202 |
+
}) + 'px';
|
2203 |
+
default: return proceed(element, style);
|
2204 |
+
}
|
2205 |
+
}
|
2206 |
+
);
|
2207 |
+
|
2208 |
+
Element.Methods.readAttribute = Element.Methods.readAttribute.wrap(
|
2209 |
+
function(proceed, element, attribute) {
|
2210 |
+
if (attribute === 'title') return element.title;
|
2211 |
+
return proceed(element, attribute);
|
2212 |
+
}
|
2213 |
+
);
|
2214 |
+
}
|
2215 |
+
|
2216 |
+
else if (Prototype.Browser.IE) {
|
2217 |
+
// IE doesn't report offsets correctly for static elements, so we change them
|
2218 |
+
// to "relative" to get the values, then change them back.
|
2219 |
+
Element.Methods.getOffsetParent = Element.Methods.getOffsetParent.wrap(
|
2220 |
+
function(proceed, element) {
|
2221 |
+
element = $(element);
|
2222 |
+
var position = element.getStyle('position');
|
2223 |
+
if (position !== 'static') return proceed(element);
|
2224 |
+
element.setStyle({ position: 'relative' });
|
2225 |
+
var value = proceed(element);
|
2226 |
+
element.setStyle({ position: position });
|
2227 |
+
return value;
|
2228 |
+
}
|
2229 |
+
);
|
2230 |
+
|
2231 |
+
$w('positionedOffset viewportOffset').each(function(method) {
|
2232 |
+
Element.Methods[method] = Element.Methods[method].wrap(
|
2233 |
+
function(proceed, element) {
|
2234 |
+
element = $(element);
|
2235 |
+
var position = element.getStyle('position');
|
2236 |
+
if (position !== 'static') return proceed(element);
|
2237 |
+
// Trigger hasLayout on the offset parent so that IE6 reports
|
2238 |
+
// accurate offsetTop and offsetLeft values for position: fixed.
|
2239 |
+
var offsetParent = element.getOffsetParent();
|
2240 |
+
if (offsetParent && offsetParent.getStyle('position') === 'fixed')
|
2241 |
+
offsetParent.setStyle({ zoom: 1 });
|
2242 |
+
element.setStyle({ position: 'relative' });
|
2243 |
+
var value = proceed(element);
|
2244 |
+
element.setStyle({ position: position });
|
2245 |
+
return value;
|
2246 |
+
}
|
2247 |
+
);
|
2248 |
+
});
|
2249 |
+
|
2250 |
+
Element.Methods.getStyle = function(element, style) {
|
2251 |
+
element = $(element);
|
2252 |
+
style = (style == 'float' || style == 'cssFloat') ? 'styleFloat' : style.camelize();
|
2253 |
+
var value = element.style[style];
|
2254 |
+
if (!value && element.currentStyle) value = element.currentStyle[style];
|
2255 |
+
|
2256 |
+
if (style == 'opacity') {
|
2257 |
+
if (value = (element.getStyle('filter') || '').match(/alpha\(opacity=(.*)\)/))
|
2258 |
+
if (value[1]) return parseFloat(value[1]) / 100;
|
2259 |
+
return 1.0;
|
2260 |
+
}
|
2261 |
+
|
2262 |
+
if (value == 'auto') {
|
2263 |
+
if ((style == 'width' || style == 'height') && (element.getStyle('display') != 'none'))
|
2264 |
+
return element['offset' + style.capitalize()] + 'px';
|
2265 |
+
return null;
|
2266 |
+
}
|
2267 |
+
return value;
|
2268 |
+
};
|
2269 |
+
|
2270 |
+
Element.Methods.setOpacity = function(element, value) {
|
2271 |
+
function stripAlpha(filter){
|
2272 |
+
return filter.replace(/alpha\([^\)]*\)/gi,'');
|
2273 |
+
}
|
2274 |
+
element = $(element);
|
2275 |
+
var currentStyle = element.currentStyle;
|
2276 |
+
if ((currentStyle && !currentStyle.hasLayout) ||
|
2277 |
+
(!currentStyle && element.style.zoom == 'normal'))
|
2278 |
+
element.style.zoom = 1;
|
2279 |
+
|
2280 |
+
var filter = element.getStyle('filter'), style = element.style;
|
2281 |
+
if (value == 1 || value === '') {
|
2282 |
+
(filter = stripAlpha(filter)) ?
|
2283 |
+
style.filter = filter : style.removeAttribute('filter');
|
2284 |
+
return element;
|
2285 |
+
} else if (value < 0.00001) value = 0;
|
2286 |
+
style.filter = stripAlpha(filter) +
|
2287 |
+
'alpha(opacity=' + (value * 100) + ')';
|
2288 |
+
return element;
|
2289 |
+
};
|
2290 |
+
|
2291 |
+
Element._attributeTranslations = {
|
2292 |
+
read: {
|
2293 |
+
names: {
|
2294 |
+
'class': 'className',
|
2295 |
+
'for': 'htmlFor'
|
2296 |
+
},
|
2297 |
+
values: {
|
2298 |
+
_getAttr: function(element, attribute) {
|
2299 |
+
return element.getAttribute(attribute, 2);
|
2300 |
+
},
|
2301 |
+
_getAttrNode: function(element, attribute) {
|
2302 |
+
var node = element.getAttributeNode(attribute);
|
2303 |
+
return node ? node.value : "";
|
2304 |
+
},
|
2305 |
+
_getEv: function(element, attribute) {
|
2306 |
+
attribute = element.getAttribute(attribute);
|
2307 |
+
return attribute ? attribute.toString().slice(23, -2) : null;
|
2308 |
+
},
|
2309 |
+
_flag: function(element, attribute) {
|
2310 |
+
return $(element).hasAttribute(attribute) ? attribute : null;
|
2311 |
+
},
|
2312 |
+
style: function(element) {
|
2313 |
+
return element.style.cssText.toLowerCase();
|
2314 |
+
},
|
2315 |
+
title: function(element) {
|
2316 |
+
return element.title;
|
2317 |
+
}
|
2318 |
+
}
|
2319 |
+
}
|
2320 |
+
};
|
2321 |
+
|
2322 |
+
Element._attributeTranslations.write = {
|
2323 |
+
names: Object.extend({
|
2324 |
+
cellpadding: 'cellPadding',
|
2325 |
+
cellspacing: 'cellSpacing'
|
2326 |
+
}, Element._attributeTranslations.read.names),
|
2327 |
+
values: {
|
2328 |
+
checked: function(element, value) {
|
2329 |
+
element.checked = !!value;
|
2330 |
+
},
|
2331 |
+
|
2332 |
+
style: function(element, value) {
|
2333 |
+
element.style.cssText = value ? value : '';
|
2334 |
+
}
|
2335 |
+
}
|
2336 |
+
};
|
2337 |
+
|
2338 |
+
Element._attributeTranslations.has = {};
|
2339 |
+
|
2340 |
+
$w('colSpan rowSpan vAlign dateTime accessKey tabIndex ' +
|
2341 |
+
'encType maxLength readOnly longDesc').each(function(attr) {
|
2342 |
+
Element._attributeTranslations.write.names[attr.toLowerCase()] = attr;
|
2343 |
+
Element._attributeTranslations.has[attr.toLowerCase()] = attr;
|
2344 |
+
});
|
2345 |
+
|
2346 |
+
(function(v) {
|
2347 |
+
Object.extend(v, {
|
2348 |
+
href: v._getAttr,
|
2349 |
+
src: v._getAttr,
|
2350 |
+
type: v._getAttr,
|
2351 |
+
action: v._getAttrNode,
|
2352 |
+
disabled: v._flag,
|
2353 |
+
checked: v._flag,
|
2354 |
+
readonly: v._flag,
|
2355 |
+
multiple: v._flag,
|
2356 |
+
onload: v._getEv,
|
2357 |
+
onunload: v._getEv,
|
2358 |
+
onclick: v._getEv,
|
2359 |
+
ondblclick: v._getEv,
|
2360 |
+
onmousedown: v._getEv,
|
2361 |
+
onmouseup: v._getEv,
|
2362 |
+
onmouseover: v._getEv,
|
2363 |
+
onmousemove: v._getEv,
|
2364 |
+
onmouseout: v._getEv,
|
2365 |
+
onfocus: v._getEv,
|
2366 |
+
onblur: v._getEv,
|
2367 |
+
onkeypress: v._getEv,
|
2368 |
+
onkeydown: v._getEv,
|
2369 |
+
onkeyup: v._getEv,
|
2370 |
+
onsubmit: v._getEv,
|
2371 |
+
onreset: v._getEv,
|
2372 |
+
onselect: v._getEv,
|
2373 |
+
onchange: v._getEv
|
2374 |
+
});
|
2375 |
+
})(Element._attributeTranslations.read.values);
|
2376 |
+
}
|
2377 |
+
|
2378 |
+
else if (Prototype.Browser.Gecko && /rv:1\.8\.0/.test(navigator.userAgent)) {
|
2379 |
+
Element.Methods.setOpacity = function(element, value) {
|
2380 |
+
element = $(element);
|
2381 |
+
element.style.opacity = (value == 1) ? 0.999999 :
|
2382 |
+
(value === '') ? '' : (value < 0.00001) ? 0 : value;
|
2383 |
+
return element;
|
2384 |
+
};
|
2385 |
+
}
|
2386 |
+
|
2387 |
+
else if (Prototype.Browser.WebKit) {
|
2388 |
+
Element.Methods.setOpacity = function(element, value) {
|
2389 |
+
element = $(element);
|
2390 |
+
element.style.opacity = (value == 1 || value === '') ? '' :
|
2391 |
+
(value < 0.00001) ? 0 : value;
|
2392 |
+
|
2393 |
+
if (value == 1)
|
2394 |
+
if(element.tagName == 'IMG' && element.width) {
|
2395 |
+
element.width++; element.width--;
|
2396 |
+
} else try {
|
2397 |
+
var n = document.createTextNode(' ');
|
2398 |
+
element.appendChild(n);
|
2399 |
+
element.removeChild(n);
|
2400 |
+
} catch (e) { }
|
2401 |
+
|
2402 |
+
return element;
|
2403 |
+
};
|
2404 |
+
|
2405 |
+
// Safari returns margins on body which is incorrect if the child is absolutely
|
2406 |
+
// positioned. For performance reasons, redefine Element#cumulativeOffset for
|
2407 |
+
// KHTML/WebKit only.
|
2408 |
+
Element.Methods.cumulativeOffset = function(element) {
|
2409 |
+
var valueT = 0, valueL = 0;
|
2410 |
+
do {
|
2411 |
+
valueT += element.offsetTop || 0;
|
2412 |
+
valueL += element.offsetLeft || 0;
|
2413 |
+
if (element.offsetParent == document.body)
|
2414 |
+
if (Element.getStyle(element, 'position') == 'absolute') break;
|
2415 |
+
|
2416 |
+
element = element.offsetParent;
|
2417 |
+
} while (element);
|
2418 |
+
|
2419 |
+
return Element._returnOffset(valueL, valueT);
|
2420 |
+
};
|
2421 |
+
}
|
2422 |
+
|
2423 |
+
if (Prototype.Browser.IE || Prototype.Browser.Opera) {
|
2424 |
+
// IE and Opera are missing .innerHTML support for TABLE-related and SELECT elements
|
2425 |
+
Element.Methods.update = function(element, content) {
|
2426 |
+
element = $(element);
|
2427 |
+
|
2428 |
+
if (content && content.toElement) content = content.toElement();
|
2429 |
+
if (Object.isElement(content)) return element.update().insert(content);
|
2430 |
+
|
2431 |
+
content = Object.toHTML(content);
|
2432 |
+
var tagName = element.tagName.toUpperCase();
|
2433 |
+
|
2434 |
+
if (tagName in Element._insertionTranslations.tags) {
|
2435 |
+
$A(element.childNodes).each(function(node) { element.removeChild(node) });
|
2436 |
+
Element._getContentFromAnonymousElement(tagName, content.stripScripts())
|
2437 |
+
.each(function(node) { element.appendChild(node) });
|
2438 |
+
}
|
2439 |
+
else element.innerHTML = content.stripScripts();
|
2440 |
+
|
2441 |
+
content.evalScripts.bind(content).defer();
|
2442 |
+
return element;
|
2443 |
+
};
|
2444 |
+
}
|
2445 |
+
|
2446 |
+
if ('outerHTML' in document.createElement('div')) {
|
2447 |
+
Element.Methods.replace = function(element, content) {
|
2448 |
+
element = $(element);
|
2449 |
+
|
2450 |
+
if (content && content.toElement) content = content.toElement();
|
2451 |
+
if (Object.isElement(content)) {
|
2452 |
+
element.parentNode.replaceChild(content, element);
|
2453 |
+
return element;
|
2454 |
+
}
|
2455 |
+
|
2456 |
+
content = Object.toHTML(content);
|
2457 |
+
var parent = element.parentNode, tagName = parent.tagName.toUpperCase();
|
2458 |
+
|
2459 |
+
if (Element._insertionTranslations.tags[tagName]) {
|
2460 |
+
var nextSibling = element.next();
|
2461 |
+
var fragments = Element._getContentFromAnonymousElement(tagName, content.stripScripts());
|
2462 |
+
parent.removeChild(element);
|
2463 |
+
if (nextSibling)
|
2464 |
+
fragments.each(function(node) { parent.insertBefore(node, nextSibling) });
|
2465 |
+
else
|
2466 |
+
fragments.each(function(node) { parent.appendChild(node) });
|
2467 |
+
}
|
2468 |
+
else element.outerHTML = content.stripScripts();
|
2469 |
+
|
2470 |
+
content.evalScripts.bind(content).defer();
|
2471 |
+
return element;
|
2472 |
+
};
|
2473 |
+
}
|
2474 |
+
|
2475 |
+
Element._returnOffset = function(l, t) {
|
2476 |
+
var result = [l, t];
|
2477 |
+
result.left = l;
|
2478 |
+
result.top = t;
|
2479 |
+
return result;
|
2480 |
+
};
|
2481 |
+
|
2482 |
+
Element._getContentFromAnonymousElement = function(tagName, html) {
|
2483 |
+
var div = new Element('div'), t = Element._insertionTranslations.tags[tagName];
|
2484 |
+
if (t) {
|
2485 |
+
div.innerHTML = t[0] + html + t[1];
|
2486 |
+
t[2].times(function() { div = div.firstChild });
|
2487 |
+
} else div.innerHTML = html;
|
2488 |
+
return $A(div.childNodes);
|
2489 |
+
};
|
2490 |
+
|
2491 |
+
Element._insertionTranslations = {
|
2492 |
+
before: function(element, node) {
|
2493 |
+
element.parentNode.insertBefore(node, element);
|
2494 |
+
},
|
2495 |
+
top: function(element, node) {
|
2496 |
+
element.insertBefore(node, element.firstChild);
|
2497 |
+
},
|
2498 |
+
bottom: function(element, node) {
|
2499 |
+
element.appendChild(node);
|
2500 |
+
},
|
2501 |
+
after: function(element, node) {
|
2502 |
+
element.parentNode.insertBefore(node, element.nextSibling);
|
2503 |
+
},
|
2504 |
+
tags: {
|
2505 |
+
TABLE: ['<table>', '</table>', 1],
|
2506 |
+
TBODY: ['<table><tbody>', '</tbody></table>', 2],
|
2507 |
+
TR: ['<table><tbody><tr>', '</tr></tbody></table>', 3],
|
2508 |
+
TD: ['<table><tbody><tr><td>', '</td></tr></tbody></table>', 4],
|
2509 |
+
SELECT: ['<select>', '</select>', 1]
|
2510 |
+
}
|
2511 |
+
};
|
2512 |
+
|
2513 |
+
(function() {
|
2514 |
+
Object.extend(this.tags, {
|
2515 |
+
THEAD: this.tags.TBODY,
|
2516 |
+
TFOOT: this.tags.TBODY,
|
2517 |
+
TH: this.tags.TD
|
2518 |
+
});
|
2519 |
+
}).call(Element._insertionTranslations);
|
2520 |
+
|
2521 |
+
Element.Methods.Simulated = {
|
2522 |
+
hasAttribute: function(element, attribute) {
|
2523 |
+
attribute = Element._attributeTranslations.has[attribute] || attribute;
|
2524 |
+
var node = $(element).getAttributeNode(attribute);
|
2525 |
+
return node && node.specified;
|
2526 |
+
}
|
2527 |
+
};
|
2528 |
+
|
2529 |
+
Element.Methods.ByTag = { };
|
2530 |
+
|
2531 |
+
Object.extend(Element, Element.Methods);
|
2532 |
+
|
2533 |
+
if (!Prototype.BrowserFeatures.ElementExtensions &&
|
2534 |
+
document.createElement('div').__proto__) {
|
2535 |
+
window.HTMLElement = { };
|
2536 |
+
window.HTMLElement.prototype = document.createElement('div').__proto__;
|
2537 |
+
Prototype.BrowserFeatures.ElementExtensions = true;
|
2538 |
+
}
|
2539 |
+
|
2540 |
+
Element.extend = (function() {
|
2541 |
+
if (Prototype.BrowserFeatures.SpecificElementExtensions)
|
2542 |
+
return Prototype.K;
|
2543 |
+
|
2544 |
+
var Methods = { }, ByTag = Element.Methods.ByTag;
|
2545 |
+
|
2546 |
+
var extend = Object.extend(function(element) {
|
2547 |
+
if (!element || element._extendedByPrototype ||
|
2548 |
+
element.nodeType != 1 || element == window) return element;
|
2549 |
+
|
2550 |
+
var methods = Object.clone(Methods),
|
2551 |
+
tagName = element.tagName, property, value;
|
2552 |
+
|
2553 |
+
// extend methods for specific tags
|
2554 |
+
if (ByTag[tagName]) Object.extend(methods, ByTag[tagName]);
|
2555 |
+
|
2556 |
+
for (property in methods) {
|
2557 |
+
value = methods[property];
|
2558 |
+
if (Object.isFunction(value) && !(property in element))
|
2559 |
+
element[property] = value.methodize();
|
2560 |
+
}
|
2561 |
+
|
2562 |
+
element._extendedByPrototype = Prototype.emptyFunction;
|
2563 |
+
return element;
|
2564 |
+
|
2565 |
+
}, {
|
2566 |
+
refresh: function() {
|
2567 |
+
// extend methods for all tags (Safari doesn't need this)
|
2568 |
+
if (!Prototype.BrowserFeatures.ElementExtensions) {
|
2569 |
+
Object.extend(Methods, Element.Methods);
|
2570 |
+
Object.extend(Methods, Element.Methods.Simulated);
|
2571 |
+
}
|
2572 |
+
}
|
2573 |
+
});
|
2574 |
+
|
2575 |
+
extend.refresh();
|
2576 |
+
return extend;
|
2577 |
+
})();
|
2578 |
+
|
2579 |
+
Element.hasAttribute = function(element, attribute) {
|
2580 |
+
if (element.hasAttribute) return element.hasAttribute(attribute);
|
2581 |
+
return Element.Methods.Simulated.hasAttribute(element, attribute);
|
2582 |
+
};
|
2583 |
+
|
2584 |
+
Element.addMethods = function(methods) {
|
2585 |
+
var F = Prototype.BrowserFeatures, T = Element.Methods.ByTag;
|
2586 |
+
|
2587 |
+
if (!methods) {
|
2588 |
+
Object.extend(Form, Form.Methods);
|
2589 |
+
Object.extend(Form.Element, Form.Element.Methods);
|
2590 |
+
Object.extend(Element.Methods.ByTag, {
|
2591 |
+
"FORM": Object.clone(Form.Methods),
|
2592 |
+
"INPUT": Object.clone(Form.Element.Methods),
|
2593 |
+
"SELECT": Object.clone(Form.Element.Methods),
|
2594 |
+
"TEXTAREA": Object.clone(Form.Element.Methods)
|
2595 |
+
});
|
2596 |
+
}
|
2597 |
+
|
2598 |
+
if (arguments.length == 2) {
|
2599 |
+
var tagName = methods;
|
2600 |
+
methods = arguments[1];
|
2601 |
+
}
|
2602 |
+
|
2603 |
+
if (!tagName) Object.extend(Element.Methods, methods || { });
|
2604 |
+
else {
|
2605 |
+
if (Object.isArray(tagName)) tagName.each(extend);
|
2606 |
+
else extend(tagName);
|
2607 |
+
}
|
2608 |
+
|
2609 |
+
function extend(tagName) {
|
2610 |
+
tagName = tagName.toUpperCase();
|
2611 |
+
if (!Element.Methods.ByTag[tagName])
|
2612 |
+
Element.Methods.ByTag[tagName] = { };
|
2613 |
+
Object.extend(Element.Methods.ByTag[tagName], methods);
|
2614 |
+
}
|
2615 |
+
|
2616 |
+
function copy(methods, destination, onlyIfAbsent) {
|
2617 |
+
onlyIfAbsent = onlyIfAbsent || false;
|
2618 |
+
for (var property in methods) {
|
2619 |
+
var value = methods[property];
|
2620 |
+
if (!Object.isFunction(value)) continue;
|
2621 |
+
if (!onlyIfAbsent || !(property in destination))
|
2622 |
+
destination[property] = value.methodize();
|
2623 |
+
}
|
2624 |
+
}
|
2625 |
+
|
2626 |
+
function findDOMClass(tagName) {
|
2627 |
+
var klass;
|
2628 |
+
var trans = {
|
2629 |
+
"OPTGROUP": "OptGroup", "TEXTAREA": "TextArea", "P": "Paragraph",
|
2630 |
+
"FIELDSET": "FieldSet", "UL": "UList", "OL": "OList", "DL": "DList",
|
2631 |
+
"DIR": "Directory", "H1": "Heading", "H2": "Heading", "H3": "Heading",
|
2632 |
+
"H4": "Heading", "H5": "Heading", "H6": "Heading", "Q": "Quote",
|
2633 |
+
"INS": "Mod", "DEL": "Mod", "A": "Anchor", "IMG": "Image", "CAPTION":
|
2634 |
+
"TableCaption", "COL": "TableCol", "COLGROUP": "TableCol", "THEAD":
|
2635 |
+
"TableSection", "TFOOT": "TableSection", "TBODY": "TableSection", "TR":
|
2636 |
+
"TableRow", "TH": "TableCell", "TD": "TableCell", "FRAMESET":
|
2637 |
+
"FrameSet", "IFRAME": "IFrame"
|
2638 |
+
};
|
2639 |
+
if (trans[tagName]) klass = 'HTML' + trans[tagName] + 'Element';
|
2640 |
+
if (window[klass]) return window[klass];
|
2641 |
+
klass = 'HTML' + tagName + 'Element';
|
2642 |
+
if (window[klass]) return window[klass];
|
2643 |
+
klass = 'HTML' + tagName.capitalize() + 'Element';
|
2644 |
+
if (window[klass]) return window[klass];
|
2645 |
+
|
2646 |
+
window[klass] = { };
|
2647 |
+
window[klass].prototype = document.createElement(tagName).__proto__;
|
2648 |
+
return window[klass];
|
2649 |
+
}
|
2650 |
+
|
2651 |
+
if (F.ElementExtensions) {
|
2652 |
+
copy(Element.Methods, HTMLElement.prototype);
|
2653 |
+
copy(Element.Methods.Simulated, HTMLElement.prototype, true);
|
2654 |
+
}
|
2655 |
+
|
2656 |
+
if (F.SpecificElementExtensions) {
|
2657 |
+
for (var tag in Element.Methods.ByTag) {
|
2658 |
+
var klass = findDOMClass(tag);
|
2659 |
+
if (Object.isUndefined(klass)) continue;
|
2660 |
+
copy(T[tag], klass.prototype);
|
2661 |
+
}
|
2662 |
+
}
|
2663 |
+
|
2664 |
+
Object.extend(Element, Element.Methods);
|
2665 |
+
delete Element.ByTag;
|
2666 |
+
|
2667 |
+
if (Element.extend.refresh) Element.extend.refresh();
|
2668 |
+
Element.cache = { };
|
2669 |
+
};
|
2670 |
+
|
2671 |
+
document.viewport = {
|
2672 |
+
getDimensions: function() {
|
2673 |
+
var dimensions = { };
|
2674 |
+
var B = Prototype.Browser;
|
2675 |
+
$w('width height').each(function(d) {
|
2676 |
+
var D = d.capitalize();
|
2677 |
+
dimensions[d] = (B.WebKit && !document.evaluate) ? self['inner' + D] :
|
2678 |
+
(B.Opera) ? document.body['client' + D] : document.documentElement['client' + D];
|
2679 |
+
});
|
2680 |
+
return dimensions;
|
2681 |
+
},
|
2682 |
+
|
2683 |
+
getWidth: function() {
|
2684 |
+
return this.getDimensions().width;
|
2685 |
+
},
|
2686 |
+
|
2687 |
+
getHeight: function() {
|
2688 |
+
return this.getDimensions().height;
|
2689 |
+
},
|
2690 |
+
|
2691 |
+
getScrollOffsets: function() {
|
2692 |
+
return Element._returnOffset(
|
2693 |
+
window.pageXOffset || document.documentElement.scrollLeft || document.body.scrollLeft,
|
2694 |
+
window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop);
|
2695 |
+
}
|
2696 |
+
};
|
2697 |
+
/* Portions of the Selector class are derived from Jack Slocum’s DomQuery,
|
2698 |
+
* part of YUI-Ext version 0.40, distributed under the terms of an MIT-style
|
2699 |
+
* license. Please see http://www.yui-ext.com/ for more information. */
|
2700 |
+
|
2701 |
+
var Selector = Class.create({
|
2702 |
+
initialize: function(expression) {
|
2703 |
+
this.expression = expression.strip();
|
2704 |
+
this.compileMatcher();
|
2705 |
+
},
|
2706 |
+
|
2707 |
+
shouldUseXPath: function() {
|
2708 |
+
if (!Prototype.BrowserFeatures.XPath) return false;
|
2709 |
+
|
2710 |
+
var e = this.expression;
|
2711 |
+
|
2712 |
+
// Safari 3 chokes on :*-of-type and :empty
|
2713 |
+
if (Prototype.Browser.WebKit &&
|
2714 |
+
(e.include("-of-type") || e.include(":empty")))
|
2715 |
+
return false;
|
2716 |
+
|
2717 |
+
// XPath can't do namespaced attributes, nor can it read
|
2718 |
+
// the "checked" property from DOM nodes
|
2719 |
+
if ((/(\[[\w-]*?:|:checked)/).test(this.expression))
|
2720 |
+
return false;
|
2721 |
+
|
2722 |
+
return true;
|
2723 |
+
},
|
2724 |
+
|
2725 |
+
compileMatcher: function() {
|
2726 |
+
if (this.shouldUseXPath())
|
2727 |
+
return this.compileXPathMatcher();
|
2728 |
+
|
2729 |
+
var e = this.expression, ps = Selector.patterns, h = Selector.handlers,
|
2730 |
+
c = Selector.criteria, le, p, m;
|
2731 |
+
|
2732 |
+
if (Selector._cache[e]) {
|
2733 |
+
this.matcher = Selector._cache[e];
|
2734 |
+
return;
|
2735 |
+
}
|
2736 |
+
|
2737 |
+
this.matcher = ["this.matcher = function(root) {",
|
2738 |
+
"var r = root, h = Selector.handlers, c = false, n;"];
|
2739 |
+
|
2740 |
+
while (e && le != e && (/\S/).test(e)) {
|
2741 |
+
le = e;
|
2742 |
+
for (var i in ps) {
|
2743 |
+
p = ps[i];
|
2744 |
+
if (m = e.match(p)) {
|
2745 |
+
this.matcher.push(Object.isFunction(c[i]) ? c[i](m) :
|
2746 |
+
new Template(c[i]).evaluate(m));
|
2747 |
+
e = e.replace(m[0], '');
|
2748 |
+
break;
|
2749 |
+
}
|
2750 |
+
}
|
2751 |
+
}
|
2752 |
+
|
2753 |
+
this.matcher.push("return h.unique(n);\n}");
|
2754 |
+
eval(this.matcher.join('\n'));
|
2755 |
+
Selector._cache[this.expression] = this.matcher;
|
2756 |
+
},
|
2757 |
+
|
2758 |
+
compileXPathMatcher: function() {
|
2759 |
+
var e = this.expression, ps = Selector.patterns,
|
2760 |
+
x = Selector.xpath, le, m;
|
2761 |
+
|
2762 |
+
if (Selector._cache[e]) {
|
2763 |
+
this.xpath = Selector._cache[e]; return;
|
2764 |
+
}
|
2765 |
+
|
2766 |
+
this.matcher = ['.//*'];
|
2767 |
+
while (e && le != e && (/\S/).test(e)) {
|
2768 |
+
le = e;
|
2769 |
+
for (var i in ps) {
|
2770 |
+
if (m = e.match(ps[i])) {
|
2771 |
+
this.matcher.push(Object.isFunction(x[i]) ? x[i](m) :
|
2772 |
+
new Template(x[i]).evaluate(m));
|
2773 |
+
e = e.replace(m[0], '');
|
2774 |
+
break;
|
2775 |
+
}
|
2776 |
+
}
|
2777 |
+
}
|
2778 |
+
|
2779 |
+
this.xpath = this.matcher.join('');
|
2780 |
+
Selector._cache[this.expression] = this.xpath;
|
2781 |
+
},
|
2782 |
+
|
2783 |
+
findElements: function(root) {
|
2784 |
+
root = root || document;
|
2785 |
+
if (this.xpath) return document._getElementsByXPath(this.xpath, root);
|
2786 |
+
return this.matcher(root);
|
2787 |
+
},
|
2788 |
+
|
2789 |
+
match: function(element) {
|
2790 |
+
this.tokens = [];
|
2791 |
+
|
2792 |
+
var e = this.expression, ps = Selector.patterns, as = Selector.assertions;
|
2793 |
+
var le, p, m;
|
2794 |
+
|
2795 |
+
while (e && le !== e && (/\S/).test(e)) {
|
2796 |
+
le = e;
|
2797 |
+
for (var i in ps) {
|
2798 |
+
p = ps[i];
|
2799 |
+
if (m = e.match(p)) {
|
2800 |
+
// use the Selector.assertions methods unless the selector
|
2801 |
+
// is too complex.
|
2802 |
+
if (as[i]) {
|
2803 |
+
this.tokens.push([i, Object.clone(m)]);
|
2804 |
+
e = e.replace(m[0], '');
|
2805 |
+
} else {
|
2806 |
+
// reluctantly do a document-wide search
|
2807 |
+
// and look for a match in the array
|
2808 |
+
return this.findElements(document).include(element);
|
2809 |
+
}
|
2810 |
+
}
|
2811 |
+
}
|
2812 |
+
}
|
2813 |
+
|
2814 |
+
var match = true, name, matches;
|
2815 |
+
for (var i = 0, token; token = this.tokens[i]; i++) {
|
2816 |
+
name = token[0], matches = token[1];
|
2817 |
+
if (!Selector.assertions[name](element, matches)) {
|
2818 |
+
match = false; break;
|
2819 |
+
}
|
2820 |
+
}
|
2821 |
+
|
2822 |
+
return match;
|
2823 |
+
},
|
2824 |
+
|
2825 |
+
toString: function() {
|
2826 |
+
return this.expression;
|
2827 |
+
},
|
2828 |
+
|
2829 |
+
inspect: function() {
|
2830 |
+
return "#<Selector:" + this.expression.inspect() + ">";
|
2831 |
+
}
|
2832 |
+
});
|
2833 |
+
|
2834 |
+
Object.extend(Selector, {
|
2835 |
+
_cache: { },
|
2836 |
+
|
2837 |
+
xpath: {
|
2838 |
+
descendant: "//*",
|
2839 |
+
child: "/*",
|
2840 |
+
adjacent: "/following-sibling::*[1]",
|
2841 |
+
laterSibling: '/following-sibling::*',
|
2842 |
+
tagName: function(m) {
|
2843 |
+
if (m[1] == '*') return '';
|
2844 |
+
return "[local-name()='" + m[1].toLowerCase() +
|
2845 |
+
"' or local-name()='" + m[1].toUpperCase() + "']";
|
2846 |
+
},
|
2847 |
+
className: "[contains(concat(' ', @class, ' '), ' #{1} ')]",
|
2848 |
+
id: "[@id='#{1}']",
|
2849 |
+
attrPresence: function(m) {
|
2850 |
+
m[1] = m[1].toLowerCase();
|
2851 |
+
return new Template("[@#{1}]").evaluate(m);
|
2852 |
+
},
|
2853 |
+
attr: function(m) {
|
2854 |
+
m[1] = m[1].toLowerCase();
|
2855 |
+
m[3] = m[5] || m[6];
|
2856 |
+
return new Template(Selector.xpath.operators[m[2]]).evaluate(m);
|
2857 |
+
},
|
2858 |
+
pseudo: function(m) {
|
2859 |
+
var h = Selector.xpath.pseudos[m[1]];
|
2860 |
+
if (!h) return '';
|
2861 |
+
if (Object.isFunction(h)) return h(m);
|
2862 |
+
return new Template(Selector.xpath.pseudos[m[1]]).evaluate(m);
|
2863 |
+
},
|
2864 |
+
operators: {
|
2865 |
+
'=': "[@#{1}='#{3}']",
|
2866 |
+
'!=': "[@#{1}!='#{3}']",
|
2867 |
+
'^=': "[starts-with(@#{1}, '#{3}')]",
|
2868 |
+
'$=': "[substring(@#{1}, (string-length(@#{1}) - string-length('#{3}') + 1))='#{3}']",
|
2869 |
+
'*=': "[contains(@#{1}, '#{3}')]",
|
2870 |
+
'~=': "[contains(concat(' ', @#{1}, ' '), ' #{3} ')]",
|
2871 |
+
'|=': "[contains(concat('-', @#{1}, '-'), '-#{3}-')]"
|
2872 |
+
},
|
2873 |
+
pseudos: {
|
2874 |
+
'first-child': '[not(preceding-sibling::*)]',
|
2875 |
+
'last-child': '[not(following-sibling::*)]',
|
2876 |
+
'only-child': '[not(preceding-sibling::* or following-sibling::*)]',
|
2877 |
+
'empty': "[count(*) = 0 and (count(text()) = 0 or translate(text(), ' \t\r\n', '') = '')]",
|
2878 |
+
'checked': "[@checked]",
|
2879 |
+
'disabled': "[@disabled]",
|
2880 |
+
'enabled': "[not(@disabled)]",
|
2881 |
+
'not': function(m) {
|
2882 |
+
var e = m[6], p = Selector.patterns,
|
2883 |
+
x = Selector.xpath, le, v;
|
2884 |
+
|
2885 |
+
var exclusion = [];
|
2886 |
+
while (e && le != e && (/\S/).test(e)) {
|
2887 |
+
le = e;
|
2888 |
+
for (var i in p) {
|
2889 |
+
if (m = e.match(p[i])) {
|
2890 |
+
v = Object.isFunction(x[i]) ? x[i](m) : new Template(x[i]).evaluate(m);
|
2891 |
+
exclusion.push("(" + v.substring(1, v.length - 1) + ")");
|
2892 |
+
e = e.replace(m[0], '');
|
2893 |
+
break;
|
2894 |
+
}
|
2895 |
+
}
|
2896 |
+
}
|
2897 |
+
return "[not(" + exclusion.join(" and ") + ")]";
|
2898 |
+
},
|
2899 |
+
'nth-child': function(m) {
|
2900 |
+
return Selector.xpath.pseudos.nth("(count(./preceding-sibling::*) + 1) ", m);
|
2901 |
+
},
|
2902 |
+
'nth-last-child': function(m) {
|
2903 |
+
return Selector.xpath.pseudos.nth("(count(./following-sibling::*) + 1) ", m);
|
2904 |
+
},
|
2905 |
+
'nth-of-type': function(m) {
|
2906 |
+
return Selector.xpath.pseudos.nth("position() ", m);
|
2907 |
+
},
|
2908 |
+
'nth-last-of-type': function(m) {
|
2909 |
+
return Selector.xpath.pseudos.nth("(last() + 1 - position()) ", m);
|
2910 |
+
},
|
2911 |
+
'first-of-type': function(m) {
|
2912 |
+
m[6] = "1"; return Selector.xpath.pseudos['nth-of-type'](m);
|
2913 |
+
},
|
2914 |
+
'last-of-type': function(m) {
|
2915 |
+
m[6] = "1"; return Selector.xpath.pseudos['nth-last-of-type'](m);
|
2916 |
+
},
|
2917 |
+
'only-of-type': function(m) {
|
2918 |
+
var p = Selector.xpath.pseudos; return p['first-of-type'](m) + p['last-of-type'](m);
|
2919 |
+
},
|
2920 |
+
nth: function(fragment, m) {
|
2921 |
+
var mm, formula = m[6], predicate;
|
2922 |
+
if (formula == 'even') formula = '2n+0';
|
2923 |
+
if (formula == 'odd') formula = '2n+1';
|
2924 |
+
if (mm = formula.match(/^(\d+)$/)) // digit only
|
2925 |
+
return '[' + fragment + "= " + mm[1] + ']';
|
2926 |
+
if (mm = formula.match(/^(-?\d*)?n(([+-])(\d+))?/)) { // an+b
|
2927 |
+
if (mm[1] == "-") mm[1] = -1;
|
2928 |
+
var a = mm[1] ? Number(mm[1]) : 1;
|
2929 |
+
var b = mm[2] ? Number(mm[2]) : 0;
|
2930 |
+
predicate = "[((#{fragment} - #{b}) mod #{a} = 0) and " +
|
2931 |
+
"((#{fragment} - #{b}) div #{a} >= 0)]";
|
2932 |
+
return new Template(predicate).evaluate({
|
2933 |
+
fragment: fragment, a: a, b: b });
|
2934 |
+
}
|
2935 |
+
}
|
2936 |
+
}
|
2937 |
+
},
|
2938 |
+
|
2939 |
+
criteria: {
|
2940 |
+
tagName: 'n = h.tagName(n, r, "#{1}", c); c = false;',
|
2941 |
+
className: 'n = h.className(n, r, "#{1}", c); c = false;',
|
2942 |
+
id: 'n = h.id(n, r, "#{1}", c); c = false;',
|
2943 |
+
attrPresence: 'n = h.attrPresence(n, r, "#{1}", c); c = false;',
|
2944 |
+
attr: function(m) {
|
2945 |
+
m[3] = (m[5] || m[6]);
|
2946 |
+
return new Template('n = h.attr(n, r, "#{1}", "#{3}", "#{2}", c); c = false;').evaluate(m);
|
2947 |
+
},
|
2948 |
+
pseudo: function(m) {
|
2949 |
+
if (m[6]) m[6] = m[6].replace(/"/g, '\\"');
|
2950 |
+
return new Template('n = h.pseudo(n, "#{1}", "#{6}", r, c); c = false;').evaluate(m);
|
2951 |
+
},
|
2952 |
+
descendant: 'c = "descendant";',
|
2953 |
+
child: 'c = "child";',
|
2954 |
+
adjacent: 'c = "adjacent";',
|
2955 |
+
laterSibling: 'c = "laterSibling";'
|
2956 |
+
},
|
2957 |
+
|
2958 |
+
patterns: {
|
2959 |
+
// combinators must be listed first
|
2960 |
+
// (and descendant needs to be last combinator)
|
2961 |
+
laterSibling: /^\s*~\s*/,
|
2962 |
+
child: /^\s*>\s*/,
|
2963 |
+
adjacent: /^\s*\+\s*/,
|
2964 |
+
descendant: /^\s/,
|
2965 |
+
|
2966 |
+
// selectors follow
|
2967 |
+
tagName: /^\s*(\*|[\w\-]+)(\b|$)?/,
|
2968 |
+
id: /^#([\w\-\*]+)(\b|$)/,
|
2969 |
+
className: /^\.([\w\-\*]+)(\b|$)/,
|
2970 |
+
pseudo:
|
2971 |
+
/^:((first|last|nth|nth-last|only)(-child|-of-type)|empty|checked|(en|dis)abled|not)(\((.*?)\))?(\b|$|(?=\s|[:+~>]))/,
|
2972 |
+
attrPresence: /^\[([\w]+)\]/,
|
2973 |
+
attr: /\[((?:[\w-]*:)?[\w-]+)\s*(?:([!^$*~|]?=)\s*((['"])([^\4]*?)\4|([^'"][^\]]*?)))?\]/
|
2974 |
+
},
|
2975 |
+
|
2976 |
+
// for Selector.match and Element#match
|
2977 |
+
assertions: {
|
2978 |
+
tagName: function(element, matches) {
|
2979 |
+
return matches[1].toUpperCase() == element.tagName.toUpperCase();
|
2980 |
+
},
|
2981 |
+
|
2982 |
+
className: function(element, matches) {
|
2983 |
+
return Element.hasClassName(element, matches[1]);
|
2984 |
+
},
|
2985 |
+
|
2986 |
+
id: function(element, matches) {
|
2987 |
+
return element.id === matches[1];
|
2988 |
+
},
|
2989 |
+
|
2990 |
+
attrPresence: function(element, matches) {
|
2991 |
+
return Element.hasAttribute(element, matches[1]);
|
2992 |
+
},
|
2993 |
+
|
2994 |
+
attr: function(element, matches) {
|
2995 |
+
var nodeValue = Element.readAttribute(element, matches[1]);
|
2996 |
+
return nodeValue && Selector.operators[matches[2]](nodeValue, matches[5] || matches[6]);
|
2997 |
+
}
|
2998 |
+
},
|
2999 |
+
|
3000 |
+
handlers: {
|
3001 |
+
// UTILITY FUNCTIONS
|
3002 |
+
// joins two collections
|
3003 |
+
concat: function(a, b) {
|
3004 |
+
for (var i = 0, node; node = b[i]; i++)
|
3005 |
+
a.push(node);
|
3006 |
+
return a;
|
3007 |
+
},
|
3008 |
+
|
3009 |
+
// marks an array of nodes for counting
|
3010 |
+
mark: function(nodes) {
|
3011 |
+
var _true = Prototype.emptyFunction;
|
3012 |
+
for (var i = 0, node; node = nodes[i]; i++)
|
3013 |
+
node._countedByPrototype = _true;
|
3014 |
+
return nodes;
|
3015 |
+
},
|
3016 |
+
|
3017 |
+
unmark: function(nodes) {
|
3018 |
+
for (var i = 0, node; node = nodes[i]; i++)
|
3019 |
+
node._countedByPrototype = undefined;
|
3020 |
+
return nodes;
|
3021 |
+
},
|
3022 |
+
|
3023 |
+
// mark each child node with its position (for nth calls)
|
3024 |
+
// "ofType" flag indicates whether we're indexing for nth-of-type
|
3025 |
+
// rather than nth-child
|
3026 |
+
index: function(parentNode, reverse, ofType) {
|
3027 |
+
parentNode._countedByPrototype = Prototype.emptyFunction;
|
3028 |
+
if (reverse) {
|
3029 |
+
for (var nodes = parentNode.childNodes, i = nodes.length - 1, j = 1; i >= 0; i--) {
|
3030 |
+
var node = nodes[i];
|
3031 |
+
if (node.nodeType == 1 && (!ofType || node._countedByPrototype)) node.nodeIndex = j++;
|
3032 |
+
}
|
3033 |
+
} else {
|
3034 |
+
for (var i = 0, j = 1, nodes = parentNode.childNodes; node = nodes[i]; i++)
|
3035 |
+
if (node.nodeType == 1 && (!ofType || node._countedByPrototype)) node.nodeIndex = j++;
|
3036 |
+
}
|
3037 |
+
},
|
3038 |
+
|
3039 |
+
// filters out duplicates and extends all nodes
|
3040 |
+
unique: function(nodes) {
|
3041 |
+
if (nodes.length == 0) return nodes;
|
3042 |
+
var results = [], n;
|
3043 |
+
for (var i = 0, l = nodes.length; i < l; i++)
|
3044 |
+
if (!(n = nodes[i])._countedByPrototype) {
|
3045 |
+
n._countedByPrototype = Prototype.emptyFunction;
|
3046 |
+
results.push(Element.extend(n));
|
3047 |
+
}
|
3048 |
+
return Selector.handlers.unmark(results);
|
3049 |
+
},
|
3050 |
+
|
3051 |
+
// COMBINATOR FUNCTIONS
|
3052 |
+
descendant: function(nodes) {
|
3053 |
+
var h = Selector.handlers;
|
3054 |
+
for (var i = 0, results = [], node; node = nodes[i]; i++)
|
3055 |
+
h.concat(results, node.getElementsByTagName('*'));
|
3056 |
+
return results;
|
3057 |
+
},
|
3058 |
+
|
3059 |
+
child: function(nodes) {
|
3060 |
+
var h = Selector.handlers;
|
3061 |
+
for (var i = 0, results = [], node; node = nodes[i]; i++) {
|
3062 |
+
for (var j = 0, child; child = node.childNodes[j]; j++)
|
3063 |
+
if (child.nodeType == 1 && child.tagName != '!') results.push(child);
|
3064 |
+
}
|
3065 |
+
return results;
|
3066 |
+
},
|
3067 |
+
|
3068 |
+
adjacent: function(nodes) {
|
3069 |
+
for (var i = 0, results = [], node; node = nodes[i]; i++) {
|
3070 |
+
var next = this.nextElementSibling(node);
|
3071 |
+
if (next) results.push(next);
|
3072 |
+
}
|
3073 |
+
return results;
|
3074 |
+
},
|
3075 |
+
|
3076 |
+
laterSibling: function(nodes) {
|
3077 |
+
var h = Selector.handlers;
|
3078 |
+
for (var i = 0, results = [], node; node = nodes[i]; i++)
|
3079 |
+
h.concat(results, Element.nextSiblings(node));
|
3080 |
+
return results;
|
3081 |
+
},
|
3082 |
+
|
3083 |
+
nextElementSibling: function(node) {
|
3084 |
+
while (node = node.nextSibling)
|
3085 |
+
if (node.nodeType == 1) return node;
|
3086 |
+
return null;
|
3087 |
+
},
|
3088 |
+
|
3089 |
+
previousElementSibling: function(node) {
|
3090 |
+
while (node = node.previousSibling)
|
3091 |
+
if (node.nodeType == 1) return node;
|
3092 |
+
return null;
|
3093 |
+
},
|
3094 |
+
|
3095 |
+
// TOKEN FUNCTIONS
|
3096 |
+
tagName: function(nodes, root, tagName, combinator) {
|
3097 |
+
var uTagName = tagName.toUpperCase();
|
3098 |
+
var results = [], h = Selector.handlers;
|
3099 |
+
if (nodes) {
|
3100 |
+
if (combinator) {
|
3101 |
+
// fastlane for ordinary descendant combinators
|
3102 |
+
if (combinator == "descendant") {
|
3103 |
+
for (var i = 0, node; node = nodes[i]; i++)
|
3104 |
+
h.concat(results, node.getElementsByTagName(tagName));
|
3105 |
+
return results;
|
3106 |
+
} else nodes = this[combinator](nodes);
|
3107 |
+
if (tagName == "*") return nodes;
|
3108 |
+
}
|
3109 |
+
for (var i = 0, node; node = nodes[i]; i++)
|
3110 |
+
if (node.tagName.toUpperCase() === uTagName) results.push(node);
|
3111 |
+
return results;
|
3112 |
+
} else return root.getElementsByTagName(tagName);
|
3113 |
+
},
|
3114 |
+
|
3115 |
+
id: function(nodes, root, id, combinator) {
|
3116 |
+
var targetNode = $(id), h = Selector.handlers;
|
3117 |
+
if (!targetNode) return [];
|
3118 |
+
if (!nodes && root == document) return [targetNode];
|
3119 |
+
if (nodes) {
|
3120 |
+
if (combinator) {
|
3121 |
+
if (combinator == 'child') {
|
3122 |
+
for (var i = 0, node; node = nodes[i]; i++)
|
3123 |
+
if (targetNode.parentNode == node) return [targetNode];
|
3124 |
+
} else if (combinator == 'descendant') {
|
3125 |
+
for (var i = 0, node; node = nodes[i]; i++)
|
3126 |
+
if (Element.descendantOf(targetNode, node)) return [targetNode];
|
3127 |
+
} else if (combinator == 'adjacent') {
|
3128 |
+
for (var i = 0, node; node = nodes[i]; i++)
|
3129 |
+
if (Selector.handlers.previousElementSibling(targetNode) == node)
|
3130 |
+
return [targetNode];
|
3131 |
+
} else nodes = h[combinator](nodes);
|
3132 |
+
}
|
3133 |
+
for (var i = 0, node; node = nodes[i]; i++)
|
3134 |
+
if (node == targetNode) return [targetNode];
|
3135 |
+
return [];
|
3136 |
+
}
|
3137 |
+
return (targetNode && Element.descendantOf(targetNode, root)) ? [targetNode] : [];
|
3138 |
+
},
|
3139 |
+
|
3140 |
+
className: function(nodes, root, className, combinator) {
|
3141 |
+
if (nodes && combinator) nodes = this[combinator](nodes);
|
3142 |
+
return Selector.handlers.byClassName(nodes, root, className);
|
3143 |
+
},
|
3144 |
+
|
3145 |
+
byClassName: function(nodes, root, className) {
|
3146 |
+
if (!nodes) nodes = Selector.handlers.descendant([root]);
|
3147 |
+
var needle = ' ' + className + ' ';
|
3148 |
+
for (var i = 0, results = [], node, nodeClassName; node = nodes[i]; i++) {
|
3149 |
+
nodeClassName = node.className;
|
3150 |
+
if (nodeClassName.length == 0) continue;
|
3151 |
+
if (nodeClassName == className || (' ' + nodeClassName + ' ').include(needle))
|
3152 |
+
results.push(node);
|
3153 |
+
}
|
3154 |
+
return results;
|
3155 |
+
},
|
3156 |
+
|
3157 |
+
attrPresence: function(nodes, root, attr, combinator) {
|
3158 |
+
if (!nodes) nodes = root.getElementsByTagName("*");
|
3159 |
+
if (nodes && combinator) nodes = this[combinator](nodes);
|
3160 |
+
var results = [];
|
3161 |
+
for (var i = 0, node; node = nodes[i]; i++)
|
3162 |
+
if (Element.hasAttribute(node, attr)) results.push(node);
|
3163 |
+
return results;
|
3164 |
+
},
|
3165 |
+
|
3166 |
+
attr: function(nodes, root, attr, value, operator, combinator) {
|
3167 |
+
if (!nodes) nodes = root.getElementsByTagName("*");
|
3168 |
+
if (nodes && combinator) nodes = this[combinator](nodes);
|
3169 |
+
var handler = Selector.operators[operator], results = [];
|
3170 |
+
for (var i = 0, node; node = nodes[i]; i++) {
|
3171 |
+
var nodeValue = Element.readAttribute(node, attr);
|
3172 |
+
if (nodeValue === null) continue;
|
3173 |
+
if (handler(nodeValue, value)) results.push(node);
|
3174 |
+
}
|
3175 |
+
return results;
|
3176 |
+
},
|
3177 |
+
|
3178 |
+
pseudo: function(nodes, name, value, root, combinator) {
|
3179 |
+
if (nodes && combinator) nodes = this[combinator](nodes);
|
3180 |
+
if (!nodes) nodes = root.getElementsByTagName("*");
|
3181 |
+
return Selector.pseudos[name](nodes, value, root);
|
3182 |
+
}
|
3183 |
+
},
|
3184 |
+
|
3185 |
+
pseudos: {
|
3186 |
+
'first-child': function(nodes, value, root) {
|
3187 |
+
for (var i = 0, results = [], node; node = nodes[i]; i++) {
|
3188 |
+
if (Selector.handlers.previousElementSibling(node)) continue;
|
3189 |
+
results.push(node);
|
3190 |
+
}
|
3191 |
+
return results;
|
3192 |
+
},
|
3193 |
+
'last-child': function(nodes, value, root) {
|
3194 |
+
for (var i = 0, results = [], node; node = nodes[i]; i++) {
|
3195 |
+
if (Selector.handlers.nextElementSibling(node)) continue;
|
3196 |
+
results.push(node);
|
3197 |
+
}
|
3198 |
+
return results;
|
3199 |
+
},
|
3200 |
+
'only-child': function(nodes, value, root) {
|
3201 |
+
var h = Selector.handlers;
|
3202 |
+
for (var i = 0, results = [], node; node = nodes[i]; i++)
|
3203 |
+
if (!h.previousElementSibling(node) && !h.nextElementSibling(node))
|
3204 |
+
results.push(node);
|
3205 |
+
return results;
|
3206 |
+
},
|
3207 |
+
'nth-child': function(nodes, formula, root) {
|
3208 |
+
return Selector.pseudos.nth(nodes, formula, root);
|
3209 |
+
},
|
3210 |
+
'nth-last-child': function(nodes, formula, root) {
|
3211 |
+
return Selector.pseudos.nth(nodes, formula, root, true);
|
3212 |
+
},
|
3213 |
+
'nth-of-type': function(nodes, formula, root) {
|
3214 |
+
return Selector.pseudos.nth(nodes, formula, root, false, true);
|
3215 |
+
},
|
3216 |
+
'nth-last-of-type': function(nodes, formula, root) {
|
3217 |
+
return Selector.pseudos.nth(nodes, formula, root, true, true);
|
3218 |
+
},
|
3219 |
+
'first-of-type': function(nodes, formula, root) {
|
3220 |
+
return Selector.pseudos.nth(nodes, "1", root, false, true);
|
3221 |
+
},
|
3222 |
+
'last-of-type': function(nodes, formula, root) {
|
3223 |
+
return Selector.pseudos.nth(nodes, "1", root, true, true);
|
3224 |
+
},
|
3225 |
+
'only-of-type': function(nodes, formula, root) {
|
3226 |
+
var p = Selector.pseudos;
|
3227 |
+
return p['last-of-type'](p['first-of-type'](nodes, formula, root), formula, root);
|
3228 |
+
},
|
3229 |
+
|
3230 |
+
// handles the an+b logic
|
3231 |
+
getIndices: function(a, b, total) {
|
3232 |
+
if (a == 0) return b > 0 ? [b] : [];
|
3233 |
+
return $R(1, total).inject([], function(memo, i) {
|
3234 |
+
if (0 == (i - b) % a && (i - b) / a >= 0) memo.push(i);
|
3235 |
+
return memo;
|
3236 |
+
});
|
3237 |
+
},
|
3238 |
+
|
3239 |
+
// handles nth(-last)-child, nth(-last)-of-type, and (first|last)-of-type
|
3240 |
+
nth: function(nodes, formula, root, reverse, ofType) {
|
3241 |
+
if (nodes.length == 0) return [];
|
3242 |
+
if (formula == 'even') formula = '2n+0';
|
3243 |
+
if (formula == 'odd') formula = '2n+1';
|
3244 |
+
var h = Selector.handlers, results = [], indexed = [], m;
|
3245 |
+
h.mark(nodes);
|
3246 |
+
for (var i = 0, node; node = nodes[i]; i++) {
|
3247 |
+
if (!node.parentNode._countedByPrototype) {
|
3248 |
+
h.index(node.parentNode, reverse, ofType);
|
3249 |
+
indexed.push(node.parentNode);
|
3250 |
+
}
|
3251 |
+
}
|
3252 |
+
if (formula.match(/^\d+$/)) { // just a number
|
3253 |
+
formula = Number(formula);
|
3254 |
+
for (var i = 0, node; node = nodes[i]; i++)
|
3255 |
+
if (node.nodeIndex == formula) results.push(node);
|
3256 |
+
} else if (m = formula.match(/^(-?\d*)?n(([+-])(\d+))?/)) { // an+b
|
3257 |
+
if (m[1] == "-") m[1] = -1;
|
3258 |
+
var a = m[1] ? Number(m[1]) : 1;
|
3259 |
+
var b = m[2] ? Number(m[2]) : 0;
|
3260 |
+
var indices = Selector.pseudos.getIndices(a, b, nodes.length);
|
3261 |
+
for (var i = 0, node, l = indices.length; node = nodes[i]; i++) {
|
3262 |
+
for (var j = 0; j < l; j++)
|
3263 |
+
if (node.nodeIndex == indices[j]) results.push(node);
|
3264 |
+
}
|
3265 |
+
}
|
3266 |
+
h.unmark(nodes);
|
3267 |
+
h.unmark(indexed);
|
3268 |
+
return results;
|
3269 |
+
},
|
3270 |
+
|
3271 |
+
'empty': function(nodes, value, root) {
|
3272 |
+
for (var i = 0, results = [], node; node = nodes[i]; i++) {
|
3273 |
+
// IE treats comments as element nodes
|
3274 |
+
if (node.tagName == '!' || (node.firstChild && !node.innerHTML.match(/^\s*$/))) continue;
|
3275 |
+
results.push(node);
|
3276 |
+
}
|
3277 |
+
return results;
|
3278 |
+
},
|
3279 |
+
|
3280 |
+
'not': function(nodes, selector, root) {
|
3281 |
+
var h = Selector.handlers, selectorType, m;
|
3282 |
+
var exclusions = new Selector(selector).findElements(root);
|
3283 |
+
h.mark(exclusions);
|
3284 |
+
for (var i = 0, results = [], node; node = nodes[i]; i++)
|
3285 |
+
if (!node._countedByPrototype) results.push(node);
|
3286 |
+
h.unmark(exclusions);
|
3287 |
+
return results;
|
3288 |
+
},
|
3289 |
+
|
3290 |
+
'enabled': function(nodes, value, root) {
|
3291 |
+
for (var i = 0, results = [], node; node = nodes[i]; i++)
|
3292 |
+
if (!node.disabled) results.push(node);
|
3293 |
+
return results;
|
3294 |
+
},
|
3295 |
+
|
3296 |
+
'disabled': function(nodes, value, root) {
|
3297 |
+
for (var i = 0, results = [], node; node = nodes[i]; i++)
|
3298 |
+
if (node.disabled) results.push(node);
|
3299 |
+
return results;
|
3300 |
+
},
|
3301 |
+
|
3302 |
+
'checked': function(nodes, value, root) {
|
3303 |
+
for (var i = 0, results = [], node; node = nodes[i]; i++)
|
3304 |
+
if (node.checked) results.push(node);
|
3305 |
+
return results;
|
3306 |
+
}
|
3307 |
+
},
|
3308 |
+
|
3309 |
+
operators: {
|
3310 |
+
'=': function(nv, v) { return nv == v; },
|
3311 |
+
'!=': function(nv, v) { return nv != v; },
|
3312 |
+
'^=': function(nv, v) { return nv.startsWith(v); },
|
3313 |
+
'$=': function(nv, v) { return nv.endsWith(v); },
|
3314 |
+
'*=': function(nv, v) { return nv.include(v); },
|
3315 |
+
'~=': function(nv, v) { return (' ' + nv + ' ').include(' ' + v + ' '); },
|
3316 |
+
'|=': function(nv, v) { return ('-' + nv.toUpperCase() + '-').include('-' + v.toUpperCase() + '-'); }
|
3317 |
+
},
|
3318 |
+
|
3319 |
+
split: function(expression) {
|
3320 |
+
var expressions = [];
|
3321 |
+
expression.scan(/(([\w#:.~>+()\s-]+|\*|\[.*?\])+)\s*(,|$)/, function(m) {
|
3322 |
+
expressions.push(m[1].strip());
|
3323 |
+
});
|
3324 |
+
return expressions;
|
3325 |
+
},
|
3326 |
+
|
3327 |
+
matchElements: function(elements, expression) {
|
3328 |
+
var matches = $$(expression), h = Selector.handlers;
|
3329 |
+
h.mark(matches);
|
3330 |
+
for (var i = 0, results = [], element; element = elements[i]; i++)
|
3331 |
+
if (element._countedByPrototype) results.push(element);
|
3332 |
+
h.unmark(matches);
|
3333 |
+
return results;
|
3334 |
+
},
|
3335 |
+
|
3336 |
+
findElement: function(elements, expression, index) {
|
3337 |
+
if (Object.isNumber(expression)) {
|
3338 |
+
index = expression; expression = false;
|
3339 |
+
}
|
3340 |
+
return Selector.matchElements(elements, expression || '*')[index || 0];
|
3341 |
+
},
|
3342 |
+
|
3343 |
+
findChildElements: function(element, expressions) {
|
3344 |
+
expressions = Selector.split(expressions.join(','));
|
3345 |
+
var results = [], h = Selector.handlers;
|
3346 |
+
for (var i = 0, l = expressions.length, selector; i < l; i++) {
|
3347 |
+
selector = new Selector(expressions[i].strip());
|
3348 |
+
h.concat(results, selector.findElements(element));
|
3349 |
+
}
|
3350 |
+
return (l > 1) ? h.unique(results) : results;
|
3351 |
+
}
|
3352 |
+
});
|
3353 |
+
|
3354 |
+
if (Prototype.Browser.IE) {
|
3355 |
+
Object.extend(Selector.handlers, {
|
3356 |
+
// IE returns comment nodes on getElementsByTagName("*").
|
3357 |
+
// Filter them out.
|
3358 |
+
concat: function(a, b) {
|
3359 |
+
for (var i = 0, node; node = b[i]; i++)
|
3360 |
+
if (node.tagName !== "!") a.push(node);
|
3361 |
+
return a;
|
3362 |
+
},
|
3363 |
+
|
3364 |
+
// IE improperly serializes _countedByPrototype in (inner|outer)HTML.
|
3365 |
+
unmark: function(nodes) {
|
3366 |
+
for (var i = 0, node; node = nodes[i]; i++)
|
3367 |
+
node.removeAttribute('_countedByPrototype');
|
3368 |
+
return nodes;
|
3369 |
+
}
|
3370 |
+
});
|
3371 |
+
}
|
3372 |
+
|
3373 |
+
function $$() {
|
3374 |
+
return Selector.findChildElements(document, $A(arguments));
|
3375 |
+
}
|
3376 |
+
var Form = {
|
3377 |
+
reset: function(form) {
|
3378 |
+
$(form).reset();
|
3379 |
+
return form;
|
3380 |
+
},
|
3381 |
+
|
3382 |
+
serializeElements: function(elements, options) {
|
3383 |
+
if (typeof options != 'object') options = { hash: !!options };
|
3384 |
+
else if (Object.isUndefined(options.hash)) options.hash = true;
|
3385 |
+
var key, value, submitted = false, submit = options.submit;
|
3386 |
+
|
3387 |
+
var data = elements.inject({ }, function(result, element) {
|
3388 |
+
if (!element.disabled && element.name) {
|
3389 |
+
key = element.name; value = $(element).getValue();
|
3390 |
+
if (value != null && (element.type != 'submit' || (!submitted &&
|
3391 |
+
submit !== false && (!submit || key == submit) && (submitted = true)))) {
|
3392 |
+
if (key in result) {
|
3393 |
+
// a key is already present; construct an array of values
|
3394 |
+
if (!Object.isArray(result[key])) result[key] = [result[key]];
|
3395 |
+
result[key].push(value);
|
3396 |
+
}
|
3397 |
+
else result[key] = value;
|
3398 |
+
}
|
3399 |
+
}
|
3400 |
+
return result;
|
3401 |
+
});
|
3402 |
+
|
3403 |
+
return options.hash ? data : Object.toQueryString(data);
|
3404 |
+
}
|
3405 |
+
};
|
3406 |
+
|
3407 |
+
Form.Methods = {
|
3408 |
+
serialize: function(form, options) {
|
3409 |
+
return Form.serializeElements(Form.getElements(form), options);
|
3410 |
+
},
|
3411 |
+
|
3412 |
+
getElements: function(form) {
|
3413 |
+
return $A($(form).getElementsByTagName('*')).inject([],
|
3414 |
+
function(elements, child) {
|
3415 |
+
if (Form.Element.Serializers[child.tagName.toLowerCase()])
|
3416 |
+
elements.push(Element.extend(child));
|
3417 |
+
return elements;
|
3418 |
+
}
|
3419 |
+
);
|
3420 |
+
},
|
3421 |
+
|
3422 |
+
getInputs: function(form, typeName, name) {
|
3423 |
+
form = $(form);
|
3424 |
+
var inputs = form.getElementsByTagName('input');
|
3425 |
+
|
3426 |
+
if (!typeName && !name) return $A(inputs).map(Element.extend);
|
3427 |
+
|
3428 |
+
for (var i = 0, matchingInputs = [], length = inputs.length; i < length; i++) {
|
3429 |
+
var input = inputs[i];
|
3430 |
+
if ((typeName && input.type != typeName) || (name && input.name != name))
|
3431 |
+
continue;
|
3432 |
+
matchingInputs.push(Element.extend(input));
|
3433 |
+
}
|
3434 |
+
|
3435 |
+
return matchingInputs;
|
3436 |
+
},
|
3437 |
+
|
3438 |
+
disable: function(form) {
|
3439 |
+
form = $(form);
|
3440 |
+
Form.getElements(form).invoke('disable');
|
3441 |
+
return form;
|
3442 |
+
},
|
3443 |
+
|
3444 |
+
enable: function(form) {
|
3445 |
+
form = $(form);
|
3446 |
+
Form.getElements(form).invoke('enable');
|
3447 |
+
return form;
|
3448 |
+
},
|
3449 |
+
|
3450 |
+
findFirstElement: function(form) {
|
3451 |
+
var elements = $(form).getElements().findAll(function(element) {
|
3452 |
+
return 'hidden' != element.type && !element.disabled;
|
3453 |
+
});
|
3454 |
+
var firstByIndex = elements.findAll(function(element) {
|
3455 |
+
return element.hasAttribute('tabIndex') && element.tabIndex >= 0;
|
3456 |
+
}).sortBy(function(element) { return element.tabIndex }).first();
|
3457 |
+
|
3458 |
+
return firstByIndex ? firstByIndex : elements.find(function(element) {
|
3459 |
+
return ['input', 'select', 'textarea'].include(element.tagName.toLowerCase());
|
3460 |
+
});
|
3461 |
+
},
|
3462 |
+
|
3463 |
+
focusFirstElement: function(form) {
|
3464 |
+
form = $(form);
|
3465 |
+
form.findFirstElement().activate();
|
3466 |
+
return form;
|
3467 |
+
},
|
3468 |
+
|
3469 |
+
request: function(form, options) {
|
3470 |
+
form = $(form), options = Object.clone(options || { });
|
3471 |
+
|
3472 |
+
var params = options.parameters, action = form.readAttribute('action') || '';
|
3473 |
+
if (action.blank()) action = window.location.href;
|
3474 |
+
options.parameters = form.serialize(true);
|
3475 |
+
|
3476 |
+
if (params) {
|
3477 |
+
if (Object.isString(params)) params = params.toQueryParams();
|
3478 |
+
Object.extend(options.parameters, params);
|
3479 |
+
}
|
3480 |
+
|
3481 |
+
if (form.hasAttribute('method') && !options.method)
|
3482 |
+
options.method = form.method;
|
3483 |
+
|
3484 |
+
return new Ajax.Request(action, options);
|
3485 |
+
}
|
3486 |
+
};
|
3487 |
+
|
3488 |
+
/*--------------------------------------------------------------------------*/
|
3489 |
+
|
3490 |
+
Form.Element = {
|
3491 |
+
focus: function(element) {
|
3492 |
+
$(element).focus();
|
3493 |
+
return element;
|
3494 |
+
},
|
3495 |
+
|
3496 |
+
select: function(element) {
|
3497 |
+
$(element).select();
|
3498 |
+
return element;
|
3499 |
+
}
|
3500 |
+
};
|
3501 |
+
|
3502 |
+
Form.Element.Methods = {
|
3503 |
+
serialize: function(element) {
|
3504 |
+
element = $(element);
|
3505 |
+
if (!element.disabled && element.name) {
|
3506 |
+
var value = element.getValue();
|
3507 |
+
if (value != undefined) {
|
3508 |
+
var pair = { };
|
3509 |
+
pair[element.name] = value;
|
3510 |
+
return Object.toQueryString(pair);
|
3511 |
+
}
|
3512 |
+
}
|
3513 |
+
return '';
|
3514 |
+
},
|
3515 |
+
|
3516 |
+
getValue: function(element) {
|
3517 |
+
element = $(element);
|
3518 |
+
var method = element.tagName.toLowerCase();
|
3519 |
+
return Form.Element.Serializers[method](element);
|
3520 |
+
},
|
3521 |
+
|
3522 |
+
setValue: function(element, value) {
|
3523 |
+
element = $(element);
|
3524 |
+
var method = element.tagName.toLowerCase();
|
3525 |
+
Form.Element.Serializers[method](element, value);
|
3526 |
+
return element;
|
3527 |
+
},
|
3528 |
+
|
3529 |
+
clear: function(element) {
|
3530 |
+
$(element).value = '';
|
3531 |
+
return element;
|
3532 |
+
},
|
3533 |
+
|
3534 |
+
present: function(element) {
|
3535 |
+
return $(element).value != '';
|
3536 |
+
},
|
3537 |
+
|
3538 |
+
activate: function(element) {
|
3539 |
+
element = $(element);
|
3540 |
+
try {
|
3541 |
+
element.focus();
|
3542 |
+
if (element.select && (element.tagName.toLowerCase() != 'input' ||
|
3543 |
+
!['button', 'reset', 'submit'].include(element.type)))
|
3544 |
+
element.select();
|
3545 |
+
} catch (e) { }
|
3546 |
+
return element;
|
3547 |
+
},
|
3548 |
+
|
3549 |
+
disable: function(element) {
|
3550 |
+
element = $(element);
|
3551 |
+
element.blur();
|
3552 |
+
element.disabled = true;
|
3553 |
+
return element;
|
3554 |
+
},
|
3555 |
+
|
3556 |
+
enable: function(element) {
|
3557 |
+
element = $(element);
|
3558 |
+
element.disabled = false;
|
3559 |
+
return element;
|
3560 |
+
}
|
3561 |
+
};
|
3562 |
+
|
3563 |
+
/*--------------------------------------------------------------------------*/
|
3564 |
+
|
3565 |
+
var Field = Form.Element;
|
3566 |
+
var $F = Form.Element.Methods.getValue;
|
3567 |
+
|
3568 |
+
/*--------------------------------------------------------------------------*/
|
3569 |
+
|
3570 |
+
Form.Element.Serializers = {
|
3571 |
+
input: function(element, value) {
|
3572 |
+
switch (element.type.toLowerCase()) {
|
3573 |
+
case 'checkbox':
|
3574 |
+
case 'radio':
|
3575 |
+
return Form.Element.Serializers.inputSelector(element, value);
|
3576 |
+
default:
|
3577 |
+
return Form.Element.Serializers.textarea(element, value);
|
3578 |
+
}
|
3579 |
+
},
|
3580 |
+
|
3581 |
+
inputSelector: function(element, value) {
|
3582 |
+
if (Object.isUndefined(value)) return element.checked ? element.value : null;
|
3583 |
+
else element.checked = !!value;
|
3584 |
+
},
|
3585 |
+
|
3586 |
+
textarea: function(element, value) {
|
3587 |
+
if (Object.isUndefined(value)) return element.value;
|
3588 |
+
else element.value = value;
|
3589 |
+
},
|
3590 |
+
|
3591 |
+
select: function(element, index) {
|
3592 |
+
if (Object.isUndefined(index))
|
3593 |
+
return this[element.type == 'select-one' ?
|
3594 |
+
'selectOne' : 'selectMany'](element);
|
3595 |
+
else {
|
3596 |
+
var opt, value, single = !Object.isArray(index);
|
3597 |
+
for (var i = 0, length = element.length; i < length; i++) {
|
3598 |
+
opt = element.options[i];
|
3599 |
+
value = this.optionValue(opt);
|
3600 |
+
if (single) {
|
3601 |
+
if (value == index) {
|
3602 |
+
opt.selected = true;
|
3603 |
+
return;
|
3604 |
+
}
|
3605 |
+
}
|
3606 |
+
else opt.selected = index.include(value);
|
3607 |
+
}
|
3608 |
+
}
|
3609 |
+
},
|
3610 |
+
|
3611 |
+
selectOne: function(element) {
|
3612 |
+
var index = element.selectedIndex;
|
3613 |
+
return index >= 0 ? this.optionValue(element.options[index]) : null;
|
3614 |
+
},
|
3615 |
+
|
3616 |
+
selectMany: function(element) {
|
3617 |
+
var values, length = element.length;
|
3618 |
+
if (!length) return null;
|
3619 |
+
|
3620 |
+
for (var i = 0, values = []; i < length; i++) {
|
3621 |
+
var opt = element.options[i];
|
3622 |
+
if (opt.selected) values.push(this.optionValue(opt));
|
3623 |
+
}
|
3624 |
+
return values;
|
3625 |
+
},
|
3626 |
+
|
3627 |
+
optionValue: function(opt) {
|
3628 |
+
// extend element because hasAttribute may not be native
|
3629 |
+
return Element.extend(opt).hasAttribute('value') ? opt.value : opt.text;
|
3630 |
+
}
|
3631 |
+
};
|
3632 |
+
|
3633 |
+
/*--------------------------------------------------------------------------*/
|
3634 |
+
|
3635 |
+
Abstract.TimedObserver = Class.create(PeriodicalExecuter, {
|
3636 |
+
initialize: function($super, element, frequency, callback) {
|
3637 |
+
$super(callback, frequency);
|
3638 |
+
this.element = $(element);
|
3639 |
+
this.lastValue = this.getValue();
|
3640 |
+
},
|
3641 |
+
|
3642 |
+
execute: function() {
|
3643 |
+
var value = this.getValue();
|
3644 |
+
if (Object.isString(this.lastValue) && Object.isString(value) ?
|
3645 |
+
this.lastValue != value : String(this.lastValue) != String(value)) {
|
3646 |
+
this.callback(this.element, value);
|
3647 |
+
this.lastValue = value;
|
3648 |
+
}
|
3649 |
+
}
|
3650 |
+
});
|
3651 |
+
|
3652 |
+
Form.Element.Observer = Class.create(Abstract.TimedObserver, {
|
3653 |
+
getValue: function() {
|
3654 |
+
return Form.Element.getValue(this.element);
|
3655 |
+
}
|
3656 |
+
});
|
3657 |
+
|
3658 |
+
Form.Observer = Class.create(Abstract.TimedObserver, {
|
3659 |
+
getValue: function() {
|
3660 |
+
return Form.serialize(this.element);
|
3661 |
+
}
|
3662 |
+
});
|
3663 |
+
|
3664 |
+
/*--------------------------------------------------------------------------*/
|
3665 |
+
|
3666 |
+
Abstract.EventObserver = Class.create({
|
3667 |
+
initialize: function(element, callback) {
|
3668 |
+
this.element = $(element);
|
3669 |
+
this.callback = callback;
|
3670 |
+
|
3671 |
+
this.lastValue = this.getValue();
|
3672 |
+
if (this.element.tagName.toLowerCase() == 'form')
|
3673 |
+
this.registerFormCallbacks();
|
3674 |
+
else
|
3675 |
+
this.registerCallback(this.element);
|
3676 |
+
},
|
3677 |
+
|
3678 |
+
onElementEvent: function() {
|
3679 |
+
var value = this.getValue();
|
3680 |
+
if (this.lastValue != value) {
|
3681 |
+
this.callback(this.element, value);
|
3682 |
+
this.lastValue = value;
|
3683 |
+
}
|
3684 |
+
},
|
3685 |
+
|
3686 |
+
registerFormCallbacks: function() {
|
3687 |
+
Form.getElements(this.element).each(this.registerCallback, this);
|
3688 |
+
},
|
3689 |
+
|
3690 |
+
registerCallback: function(element) {
|
3691 |
+
if (element.type) {
|
3692 |
+
switch (element.type.toLowerCase()) {
|
3693 |
+
case 'checkbox':
|
3694 |
+
case 'radio':
|
3695 |
+
Event.observe(element, 'click', this.onElementEvent.bind(this));
|
3696 |
+
break;
|
3697 |
+
default:
|
3698 |
+
Event.observe(element, 'change', this.onElementEvent.bind(this));
|
3699 |
+
break;
|
3700 |
+
}
|
3701 |
+
}
|
3702 |
+
}
|
3703 |
+
});
|
3704 |
+
|
3705 |
+
Form.Element.EventObserver = Class.create(Abstract.EventObserver, {
|
3706 |
+
getValue: function() {
|
3707 |
+
return Form.Element.getValue(this.element);
|
3708 |
+
}
|
3709 |
+
});
|
3710 |
+
|
3711 |
+
Form.EventObserver = Class.create(Abstract.EventObserver, {
|
3712 |
+
getValue: function() {
|
3713 |
+
return Form.serialize(this.element);
|
3714 |
+
}
|
3715 |
+
});
|
3716 |
+
if (!window.Event) var Event = { };
|
3717 |
+
|
3718 |
+
Object.extend(Event, {
|
3719 |
+
KEY_BACKSPACE: 8,
|
3720 |
+
KEY_TAB: 9,
|
3721 |
+
KEY_RETURN: 13,
|
3722 |
+
KEY_ESC: 27,
|
3723 |
+
KEY_LEFT: 37,
|
3724 |
+
KEY_UP: 38,
|
3725 |
+
KEY_RIGHT: 39,
|
3726 |
+
KEY_DOWN: 40,
|
3727 |
+
KEY_DELETE: 46,
|
3728 |
+
KEY_HOME: 36,
|
3729 |
+
KEY_END: 35,
|
3730 |
+
KEY_PAGEUP: 33,
|
3731 |
+
KEY_PAGEDOWN: 34,
|
3732 |
+
KEY_INSERT: 45,
|
3733 |
+
|
3734 |
+
cache: { },
|
3735 |
+
|
3736 |
+
relatedTarget: function(event) {
|
3737 |
+
var element;
|
3738 |
+
switch(event.type) {
|
3739 |
+
case 'mouseover': element = event.fromElement; break;
|
3740 |
+
case 'mouseout': element = event.toElement; break;
|
3741 |
+
default: return null;
|
3742 |
+
}
|
3743 |
+
return Element.extend(element);
|
3744 |
+
}
|
3745 |
+
});
|
3746 |
+
|
3747 |
+
Event.Methods = (function() {
|
3748 |
+
var isButton;
|
3749 |
+
|
3750 |
+
if (Prototype.Browser.IE) {
|
3751 |
+
var buttonMap = { 0: 1, 1: 4, 2: 2 };
|
3752 |
+
isButton = function(event, code) {
|
3753 |
+
return event.button == buttonMap[code];
|
3754 |
+
};
|
3755 |
+
|
3756 |
+
} else if (Prototype.Browser.WebKit) {
|
3757 |
+
isButton = function(event, code) {
|
3758 |
+
switch (code) {
|
3759 |
+
case 0: return event.which == 1 && !event.metaKey;
|
3760 |
+
case 1: return event.which == 1 && event.metaKey;
|
3761 |
+
default: return false;
|
3762 |
+
}
|
3763 |
+
};
|
3764 |
+
|
3765 |
+
} else {
|
3766 |
+
isButton = function(event, code) {
|
3767 |
+
return event.which ? (event.which === code + 1) : (event.button === code);
|
3768 |
+
};
|
3769 |
+
}
|
3770 |
+
|
3771 |
+
return {
|
3772 |
+
isLeftClick: function(event) { return isButton(event, 0) },
|
3773 |
+
isMiddleClick: function(event) { return isButton(event, 1) },
|
3774 |
+
isRightClick: function(event) { return isButton(event, 2) },
|
3775 |
+
|
3776 |
+
element: function(event) {
|
3777 |
+
var node = Event.extend(event).target;
|
3778 |
+
return Element.extend(node.nodeType == Node.TEXT_NODE ? node.parentNode : node);
|
3779 |
+
},
|
3780 |
+
|
3781 |
+
findElement: function(event, expression) {
|
3782 |
+
var element = Event.element(event);
|
3783 |
+
if (!expression) return element;
|
3784 |
+
var elements = [element].concat(element.ancestors());
|
3785 |
+
return Selector.findElement(elements, expression, 0);
|
3786 |
+
},
|
3787 |
+
|
3788 |
+
pointer: function(event) {
|
3789 |
+
return {
|
3790 |
+
x: event.pageX || (event.clientX +
|
3791 |
+
(document.documentElement.scrollLeft || document.body.scrollLeft)),
|
3792 |
+
y: event.pageY || (event.clientY +
|
3793 |
+
(document.documentElement.scrollTop || document.body.scrollTop))
|
3794 |
+
};
|
3795 |
+
},
|
3796 |
+
|
3797 |
+
pointerX: function(event) { return Event.pointer(event).x },
|
3798 |
+
pointerY: function(event) { return Event.pointer(event).y },
|
3799 |
+
|
3800 |
+
stop: function(event) {
|
3801 |
+
Event.extend(event);
|
3802 |
+
event.preventDefault();
|
3803 |
+
event.stopPropagation();
|
3804 |
+
event.stopped = true;
|
3805 |
+
}
|
3806 |
+
};
|
3807 |
+
})();
|
3808 |
+
|
3809 |
+
Event.extend = (function() {
|
3810 |
+
var methods = Object.keys(Event.Methods).inject({ }, function(m, name) {
|
3811 |
+
m[name] = Event.Methods[name].methodize();
|
3812 |
+
return m;
|
3813 |
+
});
|
3814 |
+
|
3815 |
+
if (Prototype.Browser.IE) {
|
3816 |
+
Object.extend(methods, {
|
3817 |
+
stopPropagation: function() { this.cancelBubble = true },
|
3818 |
+
preventDefault: function() { this.returnValue = false },
|
3819 |
+
inspect: function() { return "[object Event]" }
|
3820 |
+
});
|
3821 |
+
|
3822 |
+
return function(event) {
|
3823 |
+
if (!event) return false;
|
3824 |
+
if (event._extendedByPrototype) return event;
|
3825 |
+
|
3826 |
+
event._extendedByPrototype = Prototype.emptyFunction;
|
3827 |
+
var pointer = Event.pointer(event);
|
3828 |
+
Object.extend(event, {
|
3829 |
+
target: event.srcElement,
|
3830 |
+
relatedTarget: Event.relatedTarget(event),
|
3831 |
+
pageX: pointer.x,
|
3832 |
+
pageY: pointer.y
|
3833 |
+
});
|
3834 |
+
return Object.extend(event, methods);
|
3835 |
+
};
|
3836 |
+
|
3837 |
+
} else {
|
3838 |
+
Event.prototype = Event.prototype || document.createEvent("HTMLEvents").__proto__;
|
3839 |
+
Object.extend(Event.prototype, methods);
|
3840 |
+
return Prototype.K;
|
3841 |
+
}
|
3842 |
+
})();
|
3843 |
+
|
3844 |
+
Object.extend(Event, (function() {
|
3845 |
+
var cache = Event.cache;
|
3846 |
+
|
3847 |
+
function getEventID(element) {
|
3848 |
+
if (element._prototypeEventID) return element._prototypeEventID[0];
|
3849 |
+
arguments.callee.id = arguments.callee.id || 1;
|
3850 |
+
return element._prototypeEventID = [++arguments.callee.id];
|
3851 |
+
}
|
3852 |
+
|
3853 |
+
function getDOMEventName(eventName) {
|
3854 |
+
if (eventName && eventName.include(':')) return "dataavailable";
|
3855 |
+
return eventName;
|
3856 |
+
}
|
3857 |
+
|
3858 |
+
function getCacheForID(id) {
|
3859 |
+
return cache[id] = cache[id] || { };
|
3860 |
+
}
|
3861 |
+
|
3862 |
+
function getWrappersForEventName(id, eventName) {
|
3863 |
+
var c = getCacheForID(id);
|
3864 |
+
return c[eventName] = c[eventName] || [];
|
3865 |
+
}
|
3866 |
+
|
3867 |
+
function createWrapper(element, eventName, handler) {
|
3868 |
+
var id = getEventID(element);
|
3869 |
+
var c = getWrappersForEventName(id, eventName);
|
3870 |
+
if (c.pluck("handler").include(handler)) return false;
|
3871 |
+
|
3872 |
+
var wrapper = function(event) {
|
3873 |
+
if (!Event || !Event.extend ||
|
3874 |
+
(event.eventName && event.eventName != eventName))
|
3875 |
+
return false;
|
3876 |
+
|
3877 |
+
Event.extend(event);
|
3878 |
+
handler.call(element, event);
|
3879 |
+
};
|
3880 |
+
|
3881 |
+
wrapper.handler = handler;
|
3882 |
+
c.push(wrapper);
|
3883 |
+
return wrapper;
|
3884 |
+
}
|
3885 |
+
|
3886 |
+
function findWrapper(id, eventName, handler) {
|
3887 |
+
var c = getWrappersForEventName(id, eventName);
|
3888 |
+
return c.find(function(wrapper) { return wrapper.handler == handler });
|
3889 |
+
}
|
3890 |
+
|
3891 |
+
function destroyWrapper(id, eventName, handler) {
|
3892 |
+
var c = getCacheForID(id);
|
3893 |
+
if (!c[eventName]) return false;
|
3894 |
+
c[eventName] = c[eventName].without(findWrapper(id, eventName, handler));
|
3895 |
+
}
|
3896 |
+
|
3897 |
+
function destroyCache() {
|
3898 |
+
for (var id in cache)
|
3899 |
+
for (var eventName in cache[id])
|
3900 |
+
cache[id][eventName] = null;
|
3901 |
+
}
|
3902 |
+
|
3903 |
+
if (window.attachEvent) {
|
3904 |
+
window.attachEvent("onunload", destroyCache);
|
3905 |
+
}
|
3906 |
+
|
3907 |
+
return {
|
3908 |
+
observe: function(element, eventName, handler) {
|
3909 |
+
element = $(element);
|
3910 |
+
var name = getDOMEventName(eventName);
|
3911 |
+
|
3912 |
+
var wrapper = createWrapper(element, eventName, handler);
|
3913 |
+
if (!wrapper) return element;
|
3914 |
+
|
3915 |
+
if (element.addEventListener) {
|
3916 |
+
element.addEventListener(name, wrapper, false);
|
3917 |
+
} else {
|
3918 |
+
element.attachEvent("on" + name, wrapper);
|
3919 |
+
}
|
3920 |
+
|
3921 |
+
return element;
|
3922 |
+
},
|
3923 |
+
|
3924 |
+
stopObserving: function(element, eventName, handler) {
|
3925 |
+
element = $(element);
|
3926 |
+
var id = getEventID(element), name = getDOMEventName(eventName);
|
3927 |
+
|
3928 |
+
if (!handler && eventName) {
|
3929 |
+
getWrappersForEventName(id, eventName).each(function(wrapper) {
|
3930 |
+
element.stopObserving(eventName, wrapper.handler);
|
3931 |
+
});
|
3932 |
+
return element;
|
3933 |
+
|
3934 |
+
} else if (!eventName) {
|
3935 |
+
Object.keys(getCacheForID(id)).each(function(eventName) {
|
3936 |
+
element.stopObserving(eventName);
|
3937 |
+
});
|
3938 |
+
return element;
|
3939 |
+
}
|
3940 |
+
|
3941 |
+
var wrapper = findWrapper(id, eventName, handler);
|
3942 |
+
if (!wrapper) return element;
|
3943 |
+
|
3944 |
+
if (element.removeEventListener) {
|
3945 |
+
element.removeEventListener(name, wrapper, false);
|
3946 |
+
} else {
|
3947 |
+
element.detachEvent("on" + name, wrapper);
|
3948 |
+
}
|
3949 |
+
|
3950 |
+
destroyWrapper(id, eventName, handler);
|
3951 |
+
|
3952 |
+
return element;
|
3953 |
+
},
|
3954 |
+
|
3955 |
+
fire: function(element, eventName, memo) {
|
3956 |
+
element = $(element);
|
3957 |
+
if (element == document && document.createEvent && !element.dispatchEvent)
|
3958 |
+
element = document.documentElement;
|
3959 |
+
|
3960 |
+
var event;
|
3961 |
+
if (document.createEvent) {
|
3962 |
+
event = document.createEvent("HTMLEvents");
|
3963 |
+
event.initEvent("dataavailable", true, true);
|
3964 |
+
} else {
|
3965 |
+
event = document.createEventObject();
|
3966 |
+
event.eventType = "ondataavailable";
|
3967 |
+
}
|
3968 |
+
|
3969 |
+
event.eventName = eventName;
|
3970 |
+
event.memo = memo || { };
|
3971 |
+
|
3972 |
+
if (document.createEvent) {
|
3973 |
+
element.dispatchEvent(event);
|
3974 |
+
} else {
|
3975 |
+
element.fireEvent(event.eventType, event);
|
3976 |
+
}
|
3977 |
+
|
3978 |
+
return Event.extend(event);
|
3979 |
+
}
|
3980 |
+
};
|
3981 |
+
})());
|
3982 |
+
|
3983 |
+
Object.extend(Event, Event.Methods);
|
3984 |
+
|
3985 |
+
Element.addMethods({
|
3986 |
+
fire: Event.fire,
|
3987 |
+
observe: Event.observe,
|
3988 |
+
stopObserving: Event.stopObserving
|
3989 |
+
});
|
3990 |
+
|
3991 |
+
Object.extend(document, {
|
3992 |
+
fire: Element.Methods.fire.methodize(),
|
3993 |
+
observe: Element.Methods.observe.methodize(),
|
3994 |
+
stopObserving: Element.Methods.stopObserving.methodize(),
|
3995 |
+
loaded: false
|
3996 |
+
});
|
3997 |
+
|
3998 |
+
(function() {
|
3999 |
+
/* Support for the DOMContentLoaded event is based on work by Dan Webb,
|
4000 |
+
Matthias Miller, Dean Edwards and John Resig. */
|
4001 |
+
|
4002 |
+
var timer;
|
4003 |
+
|
4004 |
+
function fireContentLoadedEvent() {
|
4005 |
+
if (document.loaded) return;
|
4006 |
+
if (timer) window.clearInterval(timer);
|
4007 |
+
document.fire("dom:loaded");
|
4008 |
+
document.loaded = true;
|
4009 |
+
}
|
4010 |
+
|
4011 |
+
if (document.addEventListener) {
|
4012 |
+
if (Prototype.Browser.WebKit) {
|
4013 |
+
timer = window.setInterval(function() {
|
4014 |
+
if (/loaded|complete/.test(document.readyState))
|
4015 |
+
fireContentLoadedEvent();
|
4016 |
+
}, 0);
|
4017 |
+
|
4018 |
+
Event.observe(window, "load", fireContentLoadedEvent);
|
4019 |
+
|
4020 |
+
} else {
|
4021 |
+
document.addEventListener("DOMContentLoaded",
|
4022 |
+
fireContentLoadedEvent, false);
|
4023 |
+
}
|
4024 |
+
|
4025 |
+
} else {
|
4026 |
+
document.write("<script id=__onDOMContentLoaded defer src=//:><\/script>");
|
4027 |
+
$("__onDOMContentLoaded").onreadystatechange = function() {
|
4028 |
+
if (this.readyState == "complete") {
|
4029 |
+
this.onreadystatechange = null;
|
4030 |
+
fireContentLoadedEvent();
|
4031 |
+
}
|
4032 |
+
};
|
4033 |
+
}
|
4034 |
+
})();
|
4035 |
+
/*------------------------------- DEPRECATED -------------------------------*/
|
4036 |
+
|
4037 |
+
Hash.toQueryString = Object.toQueryString;
|
4038 |
+
|
4039 |
+
var Toggle = { display: Element.toggle };
|
4040 |
+
|
4041 |
+
Element.Methods.childOf = Element.Methods.descendantOf;
|
4042 |
+
|
4043 |
+
var Insertion = {
|
4044 |
+
Before: function(element, content) {
|
4045 |
+
return Element.insert(element, {before:content});
|
4046 |
+
},
|
4047 |
+
|
4048 |
+
Top: function(element, content) {
|
4049 |
+
return Element.insert(element, {top:content});
|
4050 |
+
},
|
4051 |
+
|
4052 |
+
Bottom: function(element, content) {
|
4053 |
+
return Element.insert(element, {bottom:content});
|
4054 |
+
},
|
4055 |
+
|
4056 |
+
After: function(element, content) {
|
4057 |
+
return Element.insert(element, {after:content});
|
4058 |
+
}
|
4059 |
+
};
|
4060 |
+
|
4061 |
+
var $continue = new Error('"throw $continue" is deprecated, use "return" instead');
|
4062 |
+
|
4063 |
+
// This should be moved to script.aculo.us; notice the deprecated methods
|
4064 |
+
// further below, that map to the newer Element methods.
|
4065 |
+
var Position = {
|
4066 |
+
// set to true if needed, warning: firefox performance problems
|
4067 |
+
// NOT neeeded for page scrolling, only if draggable contained in
|
4068 |
+
// scrollable elements
|
4069 |
+
includeScrollOffsets: false,
|
4070 |
+
|
4071 |
+
// must be called before calling withinIncludingScrolloffset, every time the
|
4072 |
+
// page is scrolled
|
4073 |
+
prepare: function() {
|
4074 |
+
this.deltaX = window.pageXOffset
|
4075 |
+
|| document.documentElement.scrollLeft
|
4076 |
+
|| document.body.scrollLeft
|
4077 |
+
|| 0;
|
4078 |
+
this.deltaY = window.pageYOffset
|
4079 |
+
|| document.documentElement.scrollTop
|
4080 |
+
|| document.body.scrollTop
|
4081 |
+
|| 0;
|
4082 |
+
},
|
4083 |
+
|
4084 |
+
// caches x/y coordinate pair to use with overlap
|
4085 |
+
within: function(element, x, y) {
|
4086 |
+
if (this.includeScrollOffsets)
|
4087 |
+
return this.withinIncludingScrolloffsets(element, x, y);
|
4088 |
+
this.xcomp = x;
|
4089 |
+
this.ycomp = y;
|
4090 |
+
this.offset = Element.cumulativeOffset(element);
|
4091 |
+
|
4092 |
+
return (y >= this.offset[1] &&
|
4093 |
+
y < this.offset[1] + element.offsetHeight &&
|
4094 |
+
x >= this.offset[0] &&
|
4095 |
+
x < this.offset[0] + element.offsetWidth);
|
4096 |
+
},
|
4097 |
+
|
4098 |
+
withinIncludingScrolloffsets: function(element, x, y) {
|
4099 |
+
var offsetcache = Element.cumulativeScrollOffset(element);
|
4100 |
+
|
4101 |
+
this.xcomp = x + offsetcache[0] - this.deltaX;
|
4102 |
+
this.ycomp = y + offsetcache[1] - this.deltaY;
|
4103 |
+
this.offset = Element.cumulativeOffset(element);
|
4104 |
+
|
4105 |
+
return (this.ycomp >= this.offset[1] &&
|
4106 |
+
this.ycomp < this.offset[1] + element.offsetHeight &&
|
4107 |
+
this.xcomp >= this.offset[0] &&
|
4108 |
+
this.xcomp < this.offset[0] + element.offsetWidth);
|
4109 |
+
},
|
4110 |
+
|
4111 |
+
// within must be called directly before
|
4112 |
+
overlap: function(mode, element) {
|
4113 |
+
if (!mode) return 0;
|
4114 |
+
if (mode == 'vertical')
|
4115 |
+
return ((this.offset[1] + element.offsetHeight) - this.ycomp) /
|
4116 |
+
element.offsetHeight;
|
4117 |
+
if (mode == 'horizontal')
|
4118 |
+
return ((this.offset[0] + element.offsetWidth) - this.xcomp) /
|
4119 |
+
element.offsetWidth;
|
4120 |
+
},
|
4121 |
+
|
4122 |
+
// Deprecation layer -- use newer Element methods now (1.5.2).
|
4123 |
+
|
4124 |
+
cumulativeOffset: Element.Methods.cumulativeOffset,
|
4125 |
+
|
4126 |
+
positionedOffset: Element.Methods.positionedOffset,
|
4127 |
+
|
4128 |
+
absolutize: function(element) {
|
4129 |
+
Position.prepare();
|
4130 |
+
return Element.absolutize(element);
|
4131 |
+
},
|
4132 |
+
|
4133 |
+
relativize: function(element) {
|
4134 |
+
Position.prepare();
|
4135 |
+
return Element.relativize(element);
|
4136 |
+
},
|
4137 |
+
|
4138 |
+
realOffset: Element.Methods.cumulativeScrollOffset,
|
4139 |
+
|
4140 |
+
offsetParent: Element.Methods.getOffsetParent,
|
4141 |
+
|
4142 |
+
page: Element.Methods.viewportOffset,
|
4143 |
+
|
4144 |
+
clone: function(source, target, options) {
|
4145 |
+
options = options || { };
|
4146 |
+
return Element.clonePosition(target, source, options);
|
4147 |
+
}
|
4148 |
+
};
|
4149 |
+
|
4150 |
+
/*--------------------------------------------------------------------------*/
|
4151 |
+
|
4152 |
+
if (!document.getElementsByClassName) document.getElementsByClassName = function(instanceMethods){
|
4153 |
+
function iter(name) {
|
4154 |
+
return name.blank() ? null : "[contains(concat(' ', @class, ' '), ' " + name + " ')]";
|
4155 |
+
}
|
4156 |
+
|
4157 |
+
instanceMethods.getElementsByClassName = Prototype.BrowserFeatures.XPath ?
|
4158 |
+
function(element, className) {
|
4159 |
+
className = className.toString().strip();
|
4160 |
+
var cond = /\s/.test(className) ? $w(className).map(iter).join('') : iter(className);
|
4161 |
+
return cond ? document._getElementsByXPath('.//*' + cond, element) : [];
|
4162 |
+
} : function(element, className) {
|
4163 |
+
className = className.toString().strip();
|
4164 |
+
var elements = [], classNames = (/\s/.test(className) ? $w(className) : null);
|
4165 |
+
if (!classNames && !className) return elements;
|
4166 |
+
|
4167 |
+
var nodes = $(element).getElementsByTagName('*');
|
4168 |
+
className = ' ' + className + ' ';
|
4169 |
+
|
4170 |
+
for (var i = 0, child, cn; child = nodes[i]; i++) {
|
4171 |
+
if (child.className && (cn = ' ' + child.className + ' ') && (cn.include(className) ||
|
4172 |
+
(classNames && classNames.all(function(name) {
|
4173 |
+
return !name.toString().blank() && cn.include(' ' + name + ' ');
|
4174 |
+
}))))
|
4175 |
+
elements.push(Element.extend(child));
|
4176 |
+
}
|
4177 |
+
return elements;
|
4178 |
+
};
|
4179 |
+
|
4180 |
+
return function(className, parentElement) {
|
4181 |
+
return $(parentElement || document.body).getElementsByClassName(className);
|
4182 |
+
};
|
4183 |
+
}(Element.Methods);
|
4184 |
+
|
4185 |
+
/*--------------------------------------------------------------------------*/
|
4186 |
+
|
4187 |
+
Element.ClassNames = Class.create();
|
4188 |
+
Element.ClassNames.prototype = {
|
4189 |
+
initialize: function(element) {
|
4190 |
+
this.element = $(element);
|
4191 |
+
},
|
4192 |
+
|
4193 |
+
_each: function(iterator) {
|
4194 |
+
this.element.className.split(/\s+/).select(function(name) {
|
4195 |
+
return name.length > 0;
|
4196 |
+
})._each(iterator);
|
4197 |
+
},
|
4198 |
+
|
4199 |
+
set: function(className) {
|
4200 |
+
this.element.className = className;
|
4201 |
+
},
|
4202 |
+
|
4203 |
+
add: function(classNameToAdd) {
|
4204 |
+
if (this.include(classNameToAdd)) return;
|
4205 |
+
this.set($A(this).concat(classNameToAdd).join(' '));
|
4206 |
+
},
|
4207 |
+
|
4208 |
+
remove: function(classNameToRemove) {
|
4209 |
+
if (!this.include(classNameToRemove)) return;
|
4210 |
+
this.set($A(this).without(classNameToRemove).join(' '));
|
4211 |
+
},
|
4212 |
+
|
4213 |
+
toString: function() {
|
4214 |
+
return $A(this).join(' ');
|
4215 |
+
}
|
4216 |
+
};
|
4217 |
+
|
4218 |
+
Object.extend(Element.ClassNames.prototype, Enumerable);
|
4219 |
+
|
4220 |
+
/*--------------------------------------------------------------------------*/
|
4221 |
+
|
4222 |
+
Element.addMethods();
|
js/ayasoftware/prototype-base-extensions.js
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Hash.prototype.without = function() {
|
2 |
+
var values = $A(arguments);
|
3 |
+
var retHash = $H();
|
4 |
+
this.each(function(entry) {
|
5 |
+
if(!values.include(entry.key))
|
6 |
+
retHash.set(entry.key, entry.value);
|
7 |
+
});
|
8 |
+
return retHash;
|
9 |
+
}
|
10 |
+
|
11 |
+
Element.insertAfter = function(insert, element) {
|
12 |
+
if (element.nextSibling) element.parentNode.insertBefore(insert, element.nextSibling);
|
13 |
+
else element.parentNode.appendChild(insert);
|
14 |
+
}
|
15 |
+
|
16 |
+
// Fix exceptions thrown thrown when removing an element with no parent
|
17 |
+
Element._remove = Element.remove;
|
18 |
+
Element.remove = function(element) {
|
19 |
+
element = $(element);
|
20 |
+
if (element.parentNode)
|
21 |
+
return Element._remove(element);
|
22 |
+
}
|
js/ayasoftware/prototype-date-extensions.js
ADDED
@@ -0,0 +1,230 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
DateFormat = Class.create();
|
2 |
+
Object.extend(DateFormat, {
|
3 |
+
MONTH_NAMES: ['January','February','March','April','May','June','July','August','September','October','November','December','Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'],
|
4 |
+
DAY_NAMES: ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sun','Mon','Tue','Wed','Thu','Fri','Sat'],
|
5 |
+
LZ: function(x) {return(x<0||x>9?"":"0")+x},
|
6 |
+
compareDates: function(date1,dateformat1,date2,dateformat2) {
|
7 |
+
var d1=DateFormat.parseFormat(date1,dateformat1);
|
8 |
+
var d2=DateFormat.parseFormat(date2,dateformat2);
|
9 |
+
if (d1==0 || d2==0) return -1;
|
10 |
+
else if (d1 > d2) return 1;
|
11 |
+
return 0;
|
12 |
+
},
|
13 |
+
format: function(date,format) {
|
14 |
+
format=format+"";
|
15 |
+
var result="";
|
16 |
+
var i_format=0;
|
17 |
+
var c="";
|
18 |
+
var token="";
|
19 |
+
var y=date.getYear()+"";
|
20 |
+
var M=date.getMonth()+1;
|
21 |
+
var d=date.getDate();
|
22 |
+
var E=date.getDay();
|
23 |
+
var H=date.getHours();
|
24 |
+
var m=date.getMinutes();
|
25 |
+
var s=date.getSeconds();
|
26 |
+
var yyyy,yy,MMM,MM,dd,hh,h,mm,ss,ampm,HH,H,KK,K,kk,k;
|
27 |
+
// Convert real date parts into formatted versions
|
28 |
+
var value=new Object();
|
29 |
+
if (y.length < 4) {y=""+(y-0+1900);}
|
30 |
+
value["y"]=""+y;
|
31 |
+
value["yyyy"]=y;
|
32 |
+
value["yy"]=y.substring(2,4);
|
33 |
+
value["M"]=M;
|
34 |
+
value["MM"]=DateFormat.LZ(M);
|
35 |
+
value["MMM"]=DateFormat.MONTH_NAMES[M-1];
|
36 |
+
value["NNN"]=DateFormat.MONTH_NAMES[M+11];
|
37 |
+
value["d"]=d;
|
38 |
+
value["dd"]=DateFormat.LZ(d);
|
39 |
+
value["E"]=DateFormat.DAY_NAMES[E+7];
|
40 |
+
value["EE"]=DateFormat.DAY_NAMES[E];
|
41 |
+
value["H"]=H;
|
42 |
+
value["HH"]=DateFormat.LZ(H);
|
43 |
+
if (H==0){value["h"]=12;}
|
44 |
+
else if (H>12){value["h"]=H-12;}
|
45 |
+
else {value["h"]=H;}
|
46 |
+
value["hh"]=DateFormat.LZ(value["h"]);
|
47 |
+
if (H>11){value["K"]=H-12;} else {value["K"]=H;}
|
48 |
+
value["k"]=H+1;
|
49 |
+
value["KK"]=DateFormat.LZ(value["K"]);
|
50 |
+
value["kk"]=DateFormat.LZ(value["k"]);
|
51 |
+
if (H > 11) { value["a"]="PM"; }
|
52 |
+
else { value["a"]="AM"; }
|
53 |
+
value["m"]=m;
|
54 |
+
value["mm"]=DateFormat.LZ(m);
|
55 |
+
value["s"]=s;
|
56 |
+
value["ss"]=DateFormat.LZ(s);
|
57 |
+
while (i_format < format.length) {
|
58 |
+
c=format.charAt(i_format);
|
59 |
+
token="";
|
60 |
+
while ((format.charAt(i_format)==c) && (i_format < format.length))
|
61 |
+
token += format.charAt(i_format++);
|
62 |
+
if (value[token] != null) result += value[token];
|
63 |
+
else result += token;
|
64 |
+
}
|
65 |
+
return result;
|
66 |
+
},
|
67 |
+
_isInteger: function(val) {
|
68 |
+
var digits="1234567890";
|
69 |
+
for (var i=0; i < val.length; i++)
|
70 |
+
if (digits.indexOf(val.charAt(i))==-1) return false;
|
71 |
+
return true;
|
72 |
+
},
|
73 |
+
_getInt: function(str,i,minlength,maxlength) {
|
74 |
+
for (var x=maxlength; x>=minlength; x--) {
|
75 |
+
var token=str.substring(i,i+x);
|
76 |
+
if (token.length < minlength) return null;
|
77 |
+
if (DateFormat._isInteger(token)) return token;
|
78 |
+
}
|
79 |
+
return null;
|
80 |
+
},
|
81 |
+
parseFormat: function(val,format) {
|
82 |
+
val=val+"";
|
83 |
+
format=format+"";
|
84 |
+
var i_val=0;
|
85 |
+
var i_format=0;
|
86 |
+
var c="";
|
87 |
+
var token="";
|
88 |
+
var token2="";
|
89 |
+
var x,y;
|
90 |
+
var now=new Date();
|
91 |
+
var year=now.getYear();
|
92 |
+
var month=now.getMonth()+1;
|
93 |
+
var date=1;
|
94 |
+
var hh=now.getHours();
|
95 |
+
var mm=now.getMinutes();
|
96 |
+
var ss=now.getSeconds();
|
97 |
+
var ampm="";
|
98 |
+
|
99 |
+
while (i_format < format.length) {
|
100 |
+
// Get next token from format string
|
101 |
+
c=format.charAt(i_format);
|
102 |
+
token="";
|
103 |
+
while ((format.charAt(i_format)==c) && (i_format < format.length))
|
104 |
+
token += format.charAt(i_format++);
|
105 |
+
// Extract contents of value based on format token
|
106 |
+
if (token=="yyyy" || token=="yy" || token=="y") {
|
107 |
+
if (token=="yyyy") x=4;y=4;
|
108 |
+
if (token=="yy") x=2;y=2;
|
109 |
+
if (token=="y") x=2;y=4;
|
110 |
+
year=DateFormat._getInt(val,i_val,x,y);
|
111 |
+
if (year==null) return 0;
|
112 |
+
i_val += year.length;
|
113 |
+
if (year.length==2) {
|
114 |
+
if (year > 70) year=1900+(year-0);
|
115 |
+
else year=2000+(year-0);
|
116 |
+
}
|
117 |
+
} else if (token=="MMM"||token=="NNN") {
|
118 |
+
month=0;
|
119 |
+
for (var i=0; i<DateFormat.MONTH_NAMES.length; i++) {
|
120 |
+
var month_name=DateFormat.MONTH_NAMES[i];
|
121 |
+
if (val.substring(i_val,i_val+month_name.length).toLowerCase()==month_name.toLowerCase()) {
|
122 |
+
if (token=="MMM"||(token=="NNN"&&i>11)) {
|
123 |
+
month=i+1;
|
124 |
+
if (month>12) month -= 12;
|
125 |
+
i_val += month_name.length;
|
126 |
+
break;
|
127 |
+
}
|
128 |
+
}
|
129 |
+
}
|
130 |
+
if ((month < 1)||(month>12)) return 0;
|
131 |
+
} else if (token=="EE"||token=="E") {
|
132 |
+
for (var i=0; i<DateFormat.DAY_NAMES.length; i++) {
|
133 |
+
var day_name=DateFormat.DAY_NAMES[i];
|
134 |
+
if (val.substring(i_val,i_val+day_name.length).toLowerCase()==day_name.toLowerCase()) {
|
135 |
+
i_val += day_name.length;
|
136 |
+
break;
|
137 |
+
}
|
138 |
+
}
|
139 |
+
} else if (token=="MM"||token=="M") {
|
140 |
+
month=DateFormat._getInt(val,i_val,token.length,2);
|
141 |
+
if(month==null||(month<1)||(month>12)) return 0;
|
142 |
+
i_val+=month.length;
|
143 |
+
} else if (token=="dd"||token=="d") {
|
144 |
+
date=DateFormat._getInt(val,i_val,token.length,2);
|
145 |
+
if(date==null||(date<1)||(date>31)) return 0;
|
146 |
+
i_val+=date.length;
|
147 |
+
} else if (token=="hh"||token=="h") {
|
148 |
+
hh=DateFormat._getInt(val,i_val,token.length,2);
|
149 |
+
if(hh==null||(hh<1)||(hh>12)) return 0;
|
150 |
+
i_val+=hh.length;
|
151 |
+
} else if (token=="HH"||token=="H") {
|
152 |
+
hh=DateFormat._getInt(val,i_val,token.length,2);
|
153 |
+
if(hh==null||(hh<0)||(hh>23)) return 0;
|
154 |
+
i_val+=hh.length;
|
155 |
+
} else if (token=="KK"||token=="K") {
|
156 |
+
hh=DateFormat._getInt(val,i_val,token.length,2);
|
157 |
+
if(hh==null||(hh<0)||(hh>11)) return 0;
|
158 |
+
i_val+=hh.length;
|
159 |
+
} else if (token=="kk"||token=="k") {
|
160 |
+
hh=DateFormat._getInt(val,i_val,token.length,2);
|
161 |
+
if(hh==null||(hh<1)||(hh>24)) return 0;
|
162 |
+
i_val+=hh.length;hh--;
|
163 |
+
} else if (token=="mm"||token=="m") {
|
164 |
+
mm=DateFormat._getInt(val,i_val,token.length,2);
|
165 |
+
if(mm==null||(mm<0)||(mm>59)) return 0;
|
166 |
+
i_val+=mm.length;
|
167 |
+
} else if (token=="ss"||token=="s") {
|
168 |
+
ss=DateFormat._getInt(val,i_val,token.length,2);
|
169 |
+
if(ss==null||(ss<0)||(ss>59)) return 0;
|
170 |
+
i_val+=ss.length;
|
171 |
+
} else if (token=="a") {
|
172 |
+
if (val.substring(i_val,i_val+2).toLowerCase()=="am") ampm="AM";
|
173 |
+
else if (val.substring(i_val,i_val+2).toLowerCase()=="pm") ampm="PM";
|
174 |
+
else return 0;
|
175 |
+
i_val+=2;
|
176 |
+
} else {
|
177 |
+
if (val.substring(i_val,i_val+token.length)!=token) return 0;
|
178 |
+
else i_val+=token.length;
|
179 |
+
}
|
180 |
+
}
|
181 |
+
// If there are any trailing characters left in the value, it doesn't match
|
182 |
+
if (i_val != val.length) return 0;
|
183 |
+
// Is date valid for month?
|
184 |
+
if (month==2) {
|
185 |
+
// Check for leap year
|
186 |
+
if (((year%4==0)&&(year%100 != 0)) || (year%400==0)) { // leap year
|
187 |
+
if (date > 29) return 0;
|
188 |
+
} else if (date > 28) {
|
189 |
+
return 0;
|
190 |
+
}
|
191 |
+
}
|
192 |
+
if ((month==4)||(month==6)||(month==9)||(month==11))
|
193 |
+
if (date > 30) return 0;
|
194 |
+
// Correct hours value
|
195 |
+
if (hh<12 && ampm=="PM") hh=hh-0+12;
|
196 |
+
else if (hh>11 && ampm=="AM") hh-=12;
|
197 |
+
var newdate=new Date(year,month-1,date,hh,mm,ss);
|
198 |
+
return newdate;
|
199 |
+
},
|
200 |
+
parse: function(val, format) {
|
201 |
+
if (format) {
|
202 |
+
return DateFormat.parseFormat(val, format);
|
203 |
+
} else {
|
204 |
+
var preferEuro=(arguments.length==2)?arguments[1]:false;
|
205 |
+
var generalFormats=new Array('y-M-d','MMM d, y','MMM d,y','y-MMM-d','d-MMM-y','MMM d');
|
206 |
+
var monthFirst=new Array('M/d/y','M-d-y','M.d.y','MMM-d','M/d','M-d');
|
207 |
+
var dateFirst =new Array('d/M/y','d-M-y','d.M.y','d-MMM','d/M','d-M');
|
208 |
+
var checkList=[generalFormats,preferEuro?dateFirst:monthFirst,preferEuro?monthFirst:dateFirst];
|
209 |
+
var d=null;
|
210 |
+
for (var i=0; i<checkList.length; i++) {
|
211 |
+
var l=checkList[i];
|
212 |
+
for (var j=0; j<l.length; j++) {
|
213 |
+
d=DateFormat.parseFormat(val,l[j]);
|
214 |
+
if (d!=0) return new Date(d);
|
215 |
+
}
|
216 |
+
}
|
217 |
+
return null;
|
218 |
+
}
|
219 |
+
}
|
220 |
+
});
|
221 |
+
|
222 |
+
DateFormat.prototype = {
|
223 |
+
initialize: function(format) { this.format = format; },
|
224 |
+
parse: function(value) { return DateFormat.parseFormat(value, this.format); },
|
225 |
+
format: function(value) { return DateFormat.format(value, this.format); }
|
226 |
+
}
|
227 |
+
|
228 |
+
Date.prototype.format = function(format) {
|
229 |
+
return DateFormat.format(this, format);
|
230 |
+
}
|
package.xml
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Speedup_your_catalog_update_using_our_Direct_SQL_Update_extension</name>
|
4 |
-
<version>1.
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://www.opensource.org/licenses/osl-3.0.php">Extension license name (OSL v3.0)</license>
|
7 |
<channel>community</channel>
|
@@ -24,11 +24,15 @@ Extension Features:
|
|
24 |
- User-friendly interface
|
25 |
- Provide a detailed updates report saved to a log File.
|
26 |
- Based on Dweeves script (Follow thread )</description>
|
27 |
-
<notes>Extension tested on Magento CE 1.3.X.Y , 1.4.X.Y and Magento Enterprise Edition (1.8.0.0)
|
|
|
|
|
|
|
|
|
28 |
<authors><author><name>EL Hassan Matar</name><user>auto-converted</user><email>el.hassan.matar@gmail.com</email></author></authors>
|
29 |
-
<date>2010-
|
30 |
-
<time>
|
31 |
-
<contents><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="sqlupdate.xml" hash="77ad8d193fe5f92ea54ca471858836eb"/></dir><dir name="template"><dir name="sqlupdate"><file name="schedule.phtml" hash="
|
32 |
<compatible/>
|
33 |
<dependencies/>
|
34 |
</package>
|
1 |
<?xml version="1.0"?>
|
2 |
<package>
|
3 |
<name>Speedup_your_catalog_update_using_our_Direct_SQL_Update_extension</name>
|
4 |
+
<version>1.2</version>
|
5 |
<stability>stable</stability>
|
6 |
<license uri="http://www.opensource.org/licenses/osl-3.0.php">Extension license name (OSL v3.0)</license>
|
7 |
<channel>community</channel>
|
24 |
- User-friendly interface
|
25 |
- Provide a detailed updates report saved to a log File.
|
26 |
- Based on Dweeves script (Follow thread )</description>
|
27 |
+
<notes>Extension tested on Magento CE 1.3.X.Y , 1.4.X.Y and Magento Enterprise Edition (1.8.0.0).
|
28 |
+
|
29 |
+
|
30 |
+
- Update Admin Interface (new date/time picker)
|
31 |
+
- Added missed files</notes>
|
32 |
<authors><author><name>EL Hassan Matar</name><user>auto-converted</user><email>el.hassan.matar@gmail.com</email></author></authors>
|
33 |
+
<date>2010-09-06</date>
|
34 |
+
<time>16:52:13</time>
|
35 |
+
<contents><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><file name="sqlupdate.xml" hash="77ad8d193fe5f92ea54ca471858836eb"/></dir><dir name="template"><dir name="sqlupdate"><file name="schedule.phtml" hash="22ab1d54363e178e63839930d4069bbb"/></dir></dir></dir></dir></dir></target><target name="magecommunity"><dir name="Ayasoftware"><dir name="SQLupdate"><dir name="Block"><dir name="System"><file name="Html.php" hash="9b9e6aa706535e58e86ea1260910cb17"/></dir></dir><dir name="controllers"><dir name="Adminhtml"><file name="SqlupdateController.php" hash="2fd2836a321c738679656f73de64f7c5"/></dir></dir><dir name="etc"><file name="config.xml" hash="24646eb59f0cdcf12778f00f55915f79"/><file name="system.xml" hash="45031a024e40a09cf1906fea75a6d03f"/></dir><dir name="Helper"><file name="Data.php" hash="ecbe414b1c243fb379266dbd15047993"/></dir><dir name="Model"><file name="DBHelper.php" hash="5f991190b397853c5dee307110b21060"/><file name="Massimport.php" hash="1e8c0605f2a0d07272c9ac766f9a45cb"/><file name="Observer.php" hash="fcc7212083cd72920ff117f3299afcc8"/></dir></dir></dir></target><target name="mage"><dir name="js"><dir name="ayasoftware"><file name="behaviors.js" hash="803fbd82d3a132633288f31edb12f5ca"/><file name="behaviour.js" hash="782fb396b22aff61b4e4b03d144fd1d7"/><file name="datepicker.css" hash="7889f5fe2cf572b8bce80d7d8d1ac5c2"/><file name="datepicker.js" hash="56234bdc9ebbb7f58da1344664f9bbb1"/><file name="datetimepicker.js" hash="39a363522d2654d5a35a7469a753481f"/><file name="prototype-1.6.0.2.js" hash="6f804651639c56d134e892125179b76d"/><file name="prototype-base-extensions.js" hash="eec08721b9e8b4fd05ecd20653978355"/><file name="prototype-date-extensions.js" hash="babd1760797624cbac3479a16647a5fd"/></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Ayasoftware_SQLupdate.xml" hash="8ef6e3f0f41e0960a02484cefd1afd48"/></dir></target></contents>
|
36 |
<compatible/>
|
37 |
<dependencies/>
|
38 |
</package>
|