Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

8022 lines
297 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*!
  2. * Ext JS Library 3.3.1
  3. * Copyright(c) 2006-2010 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. /**
  8. * @class Ext
  9. */
  10. Ext.ns("Ext.grid", "Ext.list", "Ext.dd", "Ext.tree", "Ext.form", "Ext.menu",
  11. "Ext.state", "Ext.layout", "Ext.app", "Ext.ux", "Ext.chart", "Ext.direct");
  12. /**
  13. * Namespace alloted for extensions to the framework.
  14. * @property ux
  15. * @type Object
  16. */
  17. Ext.apply(Ext, function(){
  18. var E = Ext,
  19. idSeed = 0,
  20. scrollWidth = null;
  21. return {
  22. /**
  23. * A reusable empty function
  24. * @property
  25. * @type Function
  26. */
  27. emptyFn : function(){},
  28. /**
  29. * URL to a 1x1 transparent gif image used by Ext to create inline icons with CSS background images.
  30. * In older versions of IE, this defaults to "http://extjs.com/s.gif" and you should change this to a URL on your server.
  31. * For other browsers it uses an inline data URL.
  32. * @type String
  33. */
  34. BLANK_IMAGE_URL : Ext.isIE6 || Ext.isIE7 || Ext.isAir ?
  35. 'http:/' + '/www.extjs.com/s.gif' :
  36. 'data:image/gif;base64,R0lGODlhAQABAID/AMDAwAAAACH5BAEAAAAALAAAAAABAAEAAAICRAEAOw==',
  37. extendX : function(supr, fn){
  38. return Ext.extend(supr, fn(supr.prototype));
  39. },
  40. /**
  41. * Returns the current HTML document object as an {@link Ext.Element}.
  42. * @return Ext.Element The document
  43. */
  44. getDoc : function(){
  45. return Ext.get(document);
  46. },
  47. /**
  48. * Utility method for validating that a value is numeric, returning the specified default value if it is not.
  49. * @param {Mixed} value Should be a number, but any type will be handled appropriately
  50. * @param {Number} defaultValue The value to return if the original value is non-numeric
  51. * @return {Number} Value, if numeric, else defaultValue
  52. */
  53. num : function(v, defaultValue){
  54. v = Number(Ext.isEmpty(v) || Ext.isArray(v) || typeof v == 'boolean' || (typeof v == 'string' && v.trim().length == 0) ? NaN : v);
  55. return isNaN(v) ? defaultValue : v;
  56. },
  57. /**
  58. * <p>Utility method for returning a default value if the passed value is empty.</p>
  59. * <p>The value is deemed to be empty if it is<div class="mdetail-params"><ul>
  60. * <li>null</li>
  61. * <li>undefined</li>
  62. * <li>an empty array</li>
  63. * <li>a zero length string (Unless the <tt>allowBlank</tt> parameter is <tt>true</tt>)</li>
  64. * </ul></div>
  65. * @param {Mixed} value The value to test
  66. * @param {Mixed} defaultValue The value to return if the original value is empty
  67. * @param {Boolean} allowBlank (optional) true to allow zero length strings to qualify as non-empty (defaults to false)
  68. * @return {Mixed} value, if non-empty, else defaultValue
  69. */
  70. value : function(v, defaultValue, allowBlank){
  71. return Ext.isEmpty(v, allowBlank) ? defaultValue : v;
  72. },
  73. /**
  74. * Escapes the passed string for use in a regular expression
  75. * @param {String} str
  76. * @return {String}
  77. */
  78. escapeRe : function(s) {
  79. return s.replace(/([-.*+?^${}()|[\]\/\\])/g, "\\$1");
  80. },
  81. sequence : function(o, name, fn, scope){
  82. o[name] = o[name].createSequence(fn, scope);
  83. },
  84. /**
  85. * Applies event listeners to elements by selectors when the document is ready.
  86. * The event name is specified with an <tt>&#64;</tt> suffix.
  87. * <pre><code>
  88. Ext.addBehaviors({
  89. // add a listener for click on all anchors in element with id foo
  90. '#foo a&#64;click' : function(e, t){
  91. // do something
  92. },
  93. // add the same listener to multiple selectors (separated by comma BEFORE the &#64;)
  94. '#foo a, #bar span.some-class&#64;mouseover' : function(){
  95. // do something
  96. }
  97. });
  98. * </code></pre>
  99. * @param {Object} obj The list of behaviors to apply
  100. */
  101. addBehaviors : function(o){
  102. if(!Ext.isReady){
  103. Ext.onReady(function(){
  104. Ext.addBehaviors(o);
  105. });
  106. } else {
  107. var cache = {}, // simple cache for applying multiple behaviors to same selector does query multiple times
  108. parts,
  109. b,
  110. s;
  111. for (b in o) {
  112. if ((parts = b.split('@'))[1]) { // for Object prototype breakers
  113. s = parts[0];
  114. if(!cache[s]){
  115. cache[s] = Ext.select(s);
  116. }
  117. cache[s].on(parts[1], o[b]);
  118. }
  119. }
  120. cache = null;
  121. }
  122. },
  123. /**
  124. * Utility method for getting the width of the browser scrollbar. This can differ depending on
  125. * operating system settings, such as the theme or font size.
  126. * @param {Boolean} force (optional) true to force a recalculation of the value.
  127. * @return {Number} The width of the scrollbar.
  128. */
  129. getScrollBarWidth: function(force){
  130. if(!Ext.isReady){
  131. return 0;
  132. }
  133. if(force === true || scrollWidth === null){
  134. // Append our div, do our calculation and then remove it
  135. var div = Ext.getBody().createChild('<div class="x-hide-offsets" style="width:100px;height:50px;overflow:hidden;"><div style="height:200px;"></div></div>'),
  136. child = div.child('div', true);
  137. var w1 = child.offsetWidth;
  138. div.setStyle('overflow', (Ext.isWebKit || Ext.isGecko) ? 'auto' : 'scroll');
  139. var w2 = child.offsetWidth;
  140. div.remove();
  141. // Need to add 2 to ensure we leave enough space
  142. scrollWidth = w1 - w2 + 2;
  143. }
  144. return scrollWidth;
  145. },
  146. // deprecated
  147. combine : function(){
  148. var as = arguments, l = as.length, r = [];
  149. for(var i = 0; i < l; i++){
  150. var a = as[i];
  151. if(Ext.isArray(a)){
  152. r = r.concat(a);
  153. }else if(a.length !== undefined && !a.substr){
  154. r = r.concat(Array.prototype.slice.call(a, 0));
  155. }else{
  156. r.push(a);
  157. }
  158. }
  159. return r;
  160. },
  161. /**
  162. * Copies a set of named properties fom the source object to the destination object.
  163. * <p>example:<pre><code>
  164. ImageComponent = Ext.extend(Ext.BoxComponent, {
  165. initComponent: function() {
  166. this.autoEl = { tag: 'img' };
  167. MyComponent.superclass.initComponent.apply(this, arguments);
  168. this.initialBox = Ext.copyTo({}, this.initialConfig, 'x,y,width,height');
  169. }
  170. });
  171. * </code></pre>
  172. * @param {Object} dest The destination object.
  173. * @param {Object} source The source object.
  174. * @param {Array/String} names Either an Array of property names, or a comma-delimited list
  175. * of property names to copy.
  176. * @return {Object} The modified object.
  177. */
  178. copyTo : function(dest, source, names){
  179. if(typeof names == 'string'){
  180. names = names.split(/[,;\s]/);
  181. }
  182. Ext.each(names, function(name){
  183. if(source.hasOwnProperty(name)){
  184. dest[name] = source[name];
  185. }
  186. }, this);
  187. return dest;
  188. },
  189. /**
  190. * Attempts to destroy any objects passed to it by removing all event listeners, removing them from the
  191. * DOM (if applicable) and calling their destroy functions (if available). This method is primarily
  192. * intended for arguments of type {@link Ext.Element} and {@link Ext.Component}, but any subclass of
  193. * {@link Ext.util.Observable} can be passed in. Any number of elements and/or components can be
  194. * passed into this function in a single call as separate arguments.
  195. * @param {Mixed} arg1 An {@link Ext.Element}, {@link Ext.Component}, or an Array of either of these to destroy
  196. * @param {Mixed} arg2 (optional)
  197. * @param {Mixed} etc... (optional)
  198. */
  199. destroy : function(){
  200. Ext.each(arguments, function(arg){
  201. if(arg){
  202. if(Ext.isArray(arg)){
  203. this.destroy.apply(this, arg);
  204. }else if(typeof arg.destroy == 'function'){
  205. arg.destroy();
  206. }else if(arg.dom){
  207. arg.remove();
  208. }
  209. }
  210. }, this);
  211. },
  212. /**
  213. * Attempts to destroy and then remove a set of named properties of the passed object.
  214. * @param {Object} o The object (most likely a Component) who's properties you wish to destroy.
  215. * @param {Mixed} arg1 The name of the property to destroy and remove from the object.
  216. * @param {Mixed} etc... More property names to destroy and remove.
  217. */
  218. destroyMembers : function(o, arg1, arg2, etc){
  219. for(var i = 1, a = arguments, len = a.length; i < len; i++) {
  220. Ext.destroy(o[a[i]]);
  221. delete o[a[i]];
  222. }
  223. },
  224. /**
  225. * Creates a copy of the passed Array with falsy values removed.
  226. * @param {Array/NodeList} arr The Array from which to remove falsy values.
  227. * @return {Array} The new, compressed Array.
  228. */
  229. clean : function(arr){
  230. var ret = [];
  231. Ext.each(arr, function(v){
  232. if(!!v){
  233. ret.push(v);
  234. }
  235. });
  236. return ret;
  237. },
  238. /**
  239. * Creates a copy of the passed Array, filtered to contain only unique values.
  240. * @param {Array} arr The Array to filter
  241. * @return {Array} The new Array containing unique values.
  242. */
  243. unique : function(arr){
  244. var ret = [],
  245. collect = {};
  246. Ext.each(arr, function(v) {
  247. if(!collect[v]){
  248. ret.push(v);
  249. }
  250. collect[v] = true;
  251. });
  252. return ret;
  253. },
  254. /**
  255. * Recursively flattens into 1-d Array. Injects Arrays inline.
  256. * @param {Array} arr The array to flatten
  257. * @return {Array} The new, flattened array.
  258. */
  259. flatten : function(arr){
  260. var worker = [];
  261. function rFlatten(a) {
  262. Ext.each(a, function(v) {
  263. if(Ext.isArray(v)){
  264. rFlatten(v);
  265. }else{
  266. worker.push(v);
  267. }
  268. });
  269. return worker;
  270. }
  271. return rFlatten(arr);
  272. },
  273. /**
  274. * Returns the minimum value in the Array.
  275. * @param {Array|NodeList} arr The Array from which to select the minimum value.
  276. * @param {Function} comp (optional) a function to perform the comparision which determines minimization.
  277. * If omitted the "<" operator will be used. Note: gt = 1; eq = 0; lt = -1
  278. * @return {Object} The minimum value in the Array.
  279. */
  280. min : function(arr, comp){
  281. var ret = arr[0];
  282. comp = comp || function(a,b){ return a < b ? -1 : 1; };
  283. Ext.each(arr, function(v) {
  284. ret = comp(ret, v) == -1 ? ret : v;
  285. });
  286. return ret;
  287. },
  288. /**
  289. * Returns the maximum value in the Array
  290. * @param {Array|NodeList} arr The Array from which to select the maximum value.
  291. * @param {Function} comp (optional) a function to perform the comparision which determines maximization.
  292. * If omitted the ">" operator will be used. Note: gt = 1; eq = 0; lt = -1
  293. * @return {Object} The maximum value in the Array.
  294. */
  295. max : function(arr, comp){
  296. var ret = arr[0];
  297. comp = comp || function(a,b){ return a > b ? 1 : -1; };
  298. Ext.each(arr, function(v) {
  299. ret = comp(ret, v) == 1 ? ret : v;
  300. });
  301. return ret;
  302. },
  303. /**
  304. * Calculates the mean of the Array
  305. * @param {Array} arr The Array to calculate the mean value of.
  306. * @return {Number} The mean.
  307. */
  308. mean : function(arr){
  309. return arr.length > 0 ? Ext.sum(arr) / arr.length : undefined;
  310. },
  311. /**
  312. * Calculates the sum of the Array
  313. * @param {Array} arr The Array to calculate the sum value of.
  314. * @return {Number} The sum.
  315. */
  316. sum : function(arr){
  317. var ret = 0;
  318. Ext.each(arr, function(v) {
  319. ret += v;
  320. });
  321. return ret;
  322. },
  323. /**
  324. * Partitions the set into two sets: a true set and a false set.
  325. * Example:
  326. * Example2:
  327. * <pre><code>
  328. // Example 1:
  329. Ext.partition([true, false, true, true, false]); // [[true, true, true], [false, false]]
  330. // Example 2:
  331. Ext.partition(
  332. Ext.query("p"),
  333. function(val){
  334. return val.className == "class1"
  335. }
  336. );
  337. // true are those paragraph elements with a className of "class1",
  338. // false set are those that do not have that className.
  339. * </code></pre>
  340. * @param {Array|NodeList} arr The array to partition
  341. * @param {Function} truth (optional) a function to determine truth. If this is omitted the element
  342. * itself must be able to be evaluated for its truthfulness.
  343. * @return {Array} [true<Array>,false<Array>]
  344. */
  345. partition : function(arr, truth){
  346. var ret = [[],[]];
  347. Ext.each(arr, function(v, i, a) {
  348. ret[ (truth && truth(v, i, a)) || (!truth && v) ? 0 : 1].push(v);
  349. });
  350. return ret;
  351. },
  352. /**
  353. * Invokes a method on each item in an Array.
  354. * <pre><code>
  355. // Example:
  356. Ext.invoke(Ext.query("p"), "getAttribute", "id");
  357. // [el1.getAttribute("id"), el2.getAttribute("id"), ..., elN.getAttribute("id")]
  358. * </code></pre>
  359. * @param {Array|NodeList} arr The Array of items to invoke the method on.
  360. * @param {String} methodName The method name to invoke.
  361. * @param {...*} args Arguments to send into the method invocation.
  362. * @return {Array} The results of invoking the method on each item in the array.
  363. */
  364. invoke : function(arr, methodName){
  365. var ret = [],
  366. args = Array.prototype.slice.call(arguments, 2);
  367. Ext.each(arr, function(v,i) {
  368. if (v && typeof v[methodName] == 'function') {
  369. ret.push(v[methodName].apply(v, args));
  370. } else {
  371. ret.push(undefined);
  372. }
  373. });
  374. return ret;
  375. },
  376. /**
  377. * Plucks the value of a property from each item in the Array
  378. * <pre><code>
  379. // Example:
  380. Ext.pluck(Ext.query("p"), "className"); // [el1.className, el2.className, ..., elN.className]
  381. * </code></pre>
  382. * @param {Array|NodeList} arr The Array of items to pluck the value from.
  383. * @param {String} prop The property name to pluck from each element.
  384. * @return {Array} The value from each item in the Array.
  385. */
  386. pluck : function(arr, prop){
  387. var ret = [];
  388. Ext.each(arr, function(v) {
  389. ret.push( v[prop] );
  390. });
  391. return ret;
  392. },
  393. /**
  394. * <p>Zips N sets together.</p>
  395. * <pre><code>
  396. // Example 1:
  397. Ext.zip([1,2,3],[4,5,6]); // [[1,4],[2,5],[3,6]]
  398. // Example 2:
  399. Ext.zip(
  400. [ "+", "-", "+"],
  401. [ 12, 10, 22],
  402. [ 43, 15, 96],
  403. function(a, b, c){
  404. return "$" + a + "" + b + "." + c
  405. }
  406. ); // ["$+12.43", "$-10.15", "$+22.96"]
  407. * </code></pre>
  408. * @param {Arrays|NodeLists} arr This argument may be repeated. Array(s) to contribute values.
  409. * @param {Function} zipper (optional) The last item in the argument list. This will drive how the items are zipped together.
  410. * @return {Array} The zipped set.
  411. */
  412. zip : function(){
  413. var parts = Ext.partition(arguments, function( val ){ return typeof val != 'function'; }),
  414. arrs = parts[0],
  415. fn = parts[1][0],
  416. len = Ext.max(Ext.pluck(arrs, "length")),
  417. ret = [];
  418. for (var i = 0; i < len; i++) {
  419. ret[i] = [];
  420. if(fn){
  421. ret[i] = fn.apply(fn, Ext.pluck(arrs, i));
  422. }else{
  423. for (var j = 0, aLen = arrs.length; j < aLen; j++){
  424. ret[i].push( arrs[j][i] );
  425. }
  426. }
  427. }
  428. return ret;
  429. },
  430. /**
  431. * This is shorthand reference to {@link Ext.ComponentMgr#get}.
  432. * Looks up an existing {@link Ext.Component Component} by {@link Ext.Component#id id}
  433. * @param {String} id The component {@link Ext.Component#id id}
  434. * @return Ext.Component The Component, <tt>undefined</tt> if not found, or <tt>null</tt> if a
  435. * Class was found.
  436. */
  437. getCmp : function(id){
  438. return Ext.ComponentMgr.get(id);
  439. },
  440. /**
  441. * By default, Ext intelligently decides whether floating elements should be shimmed. If you are using flash,
  442. * you may want to set this to true.
  443. * @type Boolean
  444. */
  445. useShims: E.isIE6 || (E.isMac && E.isGecko2),
  446. // inpired by a similar function in mootools library
  447. /**
  448. * Returns the type of object that is passed in. If the object passed in is null or undefined it
  449. * return false otherwise it returns one of the following values:<div class="mdetail-params"><ul>
  450. * <li><b>string</b>: If the object passed is a string</li>
  451. * <li><b>number</b>: If the object passed is a number</li>
  452. * <li><b>boolean</b>: If the object passed is a boolean value</li>
  453. * <li><b>date</b>: If the object passed is a Date object</li>
  454. * <li><b>function</b>: If the object passed is a function reference</li>
  455. * <li><b>object</b>: If the object passed is an object</li>
  456. * <li><b>array</b>: If the object passed is an array</li>
  457. * <li><b>regexp</b>: If the object passed is a regular expression</li>
  458. * <li><b>element</b>: If the object passed is a DOM Element</li>
  459. * <li><b>nodelist</b>: If the object passed is a DOM NodeList</li>
  460. * <li><b>textnode</b>: If the object passed is a DOM text node and contains something other than whitespace</li>
  461. * <li><b>whitespace</b>: If the object passed is a DOM text node and contains only whitespace</li>
  462. * </ul></div>
  463. * @param {Mixed} object
  464. * @return {String}
  465. */
  466. type : function(o){
  467. if(o === undefined || o === null){
  468. return false;
  469. }
  470. if(o.htmlElement){
  471. return 'element';
  472. }
  473. var t = typeof o;
  474. if(t == 'object' && o.nodeName) {
  475. switch(o.nodeType) {
  476. case 1: return 'element';
  477. case 3: return (/\S/).test(o.nodeValue) ? 'textnode' : 'whitespace';
  478. }
  479. }
  480. if(t == 'object' || t == 'function') {
  481. switch(o.constructor) {
  482. case Array: return 'array';
  483. case RegExp: return 'regexp';
  484. case Date: return 'date';
  485. }
  486. if(typeof o.length == 'number' && typeof o.item == 'function') {
  487. return 'nodelist';
  488. }
  489. }
  490. return t;
  491. },
  492. intercept : function(o, name, fn, scope){
  493. o[name] = o[name].createInterceptor(fn, scope);
  494. },
  495. // internal
  496. callback : function(cb, scope, args, delay){
  497. if(typeof cb == 'function'){
  498. if(delay){
  499. cb.defer(delay, scope, args || []);
  500. }else{
  501. cb.apply(scope, args || []);
  502. }
  503. }
  504. }
  505. };
  506. }());
  507. /**
  508. * @class Function
  509. * These functions are available on every Function object (any JavaScript function).
  510. */
  511. Ext.apply(Function.prototype, {
  512. /**
  513. * Create a combined function call sequence of the original function + the passed function.
  514. * The resulting function returns the results of the original function.
  515. * The passed fcn is called with the parameters of the original function. Example usage:
  516. * <pre><code>
  517. var sayHi = function(name){
  518. alert('Hi, ' + name);
  519. }
  520. sayHi('Fred'); // alerts "Hi, Fred"
  521. var sayGoodbye = sayHi.createSequence(function(name){
  522. alert('Bye, ' + name);
  523. });
  524. sayGoodbye('Fred'); // both alerts show
  525. </code></pre>
  526. * @param {Function} fcn The function to sequence
  527. * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the passed function is executed.
  528. * <b>If omitted, defaults to the scope in which the original function is called or the browser window.</b>
  529. * @return {Function} The new function
  530. */
  531. createSequence : function(fcn, scope){
  532. var method = this;
  533. return (typeof fcn != 'function') ?
  534. this :
  535. function(){
  536. var retval = method.apply(this || window, arguments);
  537. fcn.apply(scope || this || window, arguments);
  538. return retval;
  539. };
  540. }
  541. });
  542. /**
  543. * @class String
  544. * These functions are available as static methods on the JavaScript String object.
  545. */
  546. Ext.applyIf(String, {
  547. /**
  548. * Escapes the passed string for ' and \
  549. * @param {String} string The string to escape
  550. * @return {String} The escaped string
  551. * @static
  552. */
  553. escape : function(string) {
  554. return string.replace(/('|\\)/g, "\\$1");
  555. },
  556. /**
  557. * Pads the left side of a string with a specified character. This is especially useful
  558. * for normalizing number and date strings. Example usage:
  559. * <pre><code>
  560. var s = String.leftPad('123', 5, '0');
  561. // s now contains the string: '00123'
  562. * </code></pre>
  563. * @param {String} string The original string
  564. * @param {Number} size The total length of the output string
  565. * @param {String} char (optional) The character with which to pad the original string (defaults to empty string " ")
  566. * @return {String} The padded string
  567. * @static
  568. */
  569. leftPad : function (val, size, ch) {
  570. var result = String(val);
  571. if(!ch) {
  572. ch = " ";
  573. }
  574. while (result.length < size) {
  575. result = ch + result;
  576. }
  577. return result;
  578. }
  579. });
  580. /**
  581. * Utility function that allows you to easily switch a string between two alternating values. The passed value
  582. * is compared to the current string, and if they are equal, the other value that was passed in is returned. If
  583. * they are already different, the first value passed in is returned. Note that this method returns the new value
  584. * but does not change the current string.
  585. * <pre><code>
  586. // alternate sort directions
  587. sort = sort.toggle('ASC', 'DESC');
  588. // instead of conditional logic:
  589. sort = (sort == 'ASC' ? 'DESC' : 'ASC');
  590. </code></pre>
  591. * @param {String} value The value to compare to the current string
  592. * @param {String} other The new value to use if the string already equals the first value passed in
  593. * @return {String} The new value
  594. */
  595. String.prototype.toggle = function(value, other){
  596. return this == value ? other : value;
  597. };
  598. /**
  599. * Trims whitespace from either end of a string, leaving spaces within the string intact. Example:
  600. * <pre><code>
  601. var s = ' foo bar ';
  602. alert('-' + s + '-'); //alerts "- foo bar -"
  603. alert('-' + s.trim() + '-'); //alerts "-foo bar-"
  604. </code></pre>
  605. * @return {String} The trimmed string
  606. */
  607. String.prototype.trim = function(){
  608. var re = /^\s+|\s+$/g;
  609. return function(){ return this.replace(re, ""); };
  610. }();
  611. // here to prevent dependency on Date.js
  612. /**
  613. Returns the number of milliseconds between this date and date
  614. @param {Date} date (optional) Defaults to now
  615. @return {Number} The diff in milliseconds
  616. @member Date getElapsed
  617. */
  618. Date.prototype.getElapsed = function(date) {
  619. return Math.abs((date || new Date()).getTime()-this.getTime());
  620. };
  621. /**
  622. * @class Number
  623. */
  624. Ext.applyIf(Number.prototype, {
  625. /**
  626. * Checks whether or not the current number is within a desired range. If the number is already within the
  627. * range it is returned, otherwise the min or max value is returned depending on which side of the range is
  628. * exceeded. Note that this method returns the constrained value but does not change the current number.
  629. * @param {Number} min The minimum number in the range
  630. * @param {Number} max The maximum number in the range
  631. * @return {Number} The constrained value if outside the range, otherwise the current value
  632. */
  633. constrain : function(min, max){
  634. return Math.min(Math.max(this, min), max);
  635. }
  636. });
  637. Ext.lib.Dom.getRegion = function(el) {
  638. return Ext.lib.Region.getRegion(el);
  639. }; Ext.lib.Region = function(t, r, b, l) {
  640. var me = this;
  641. me.top = t;
  642. me[1] = t;
  643. me.right = r;
  644. me.bottom = b;
  645. me.left = l;
  646. me[0] = l;
  647. };
  648. Ext.lib.Region.prototype = {
  649. contains : function(region) {
  650. var me = this;
  651. return ( region.left >= me.left &&
  652. region.right <= me.right &&
  653. region.top >= me.top &&
  654. region.bottom <= me.bottom );
  655. },
  656. getArea : function() {
  657. var me = this;
  658. return ( (me.bottom - me.top) * (me.right - me.left) );
  659. },
  660. intersect : function(region) {
  661. var me = this,
  662. t = Math.max(me.top, region.top),
  663. r = Math.min(me.right, region.right),
  664. b = Math.min(me.bottom, region.bottom),
  665. l = Math.max(me.left, region.left);
  666. if (b >= t && r >= l) {
  667. return new Ext.lib.Region(t, r, b, l);
  668. }
  669. },
  670. union : function(region) {
  671. var me = this,
  672. t = Math.min(me.top, region.top),
  673. r = Math.max(me.right, region.right),
  674. b = Math.max(me.bottom, region.bottom),
  675. l = Math.min(me.left, region.left);
  676. return new Ext.lib.Region(t, r, b, l);
  677. },
  678. constrainTo : function(r) {
  679. var me = this;
  680. me.top = me.top.constrain(r.top, r.bottom);
  681. me.bottom = me.bottom.constrain(r.top, r.bottom);
  682. me.left = me.left.constrain(r.left, r.right);
  683. me.right = me.right.constrain(r.left, r.right);
  684. return me;
  685. },
  686. adjust : function(t, l, b, r) {
  687. var me = this;
  688. me.top += t;
  689. me.left += l;
  690. me.right += r;
  691. me.bottom += b;
  692. return me;
  693. }
  694. };
  695. Ext.lib.Region.getRegion = function(el) {
  696. var p = Ext.lib.Dom.getXY(el),
  697. t = p[1],
  698. r = p[0] + el.offsetWidth,
  699. b = p[1] + el.offsetHeight,
  700. l = p[0];
  701. return new Ext.lib.Region(t, r, b, l);
  702. }; Ext.lib.Point = function(x, y) {
  703. if (Ext.isArray(x)) {
  704. y = x[1];
  705. x = x[0];
  706. }
  707. var me = this;
  708. me.x = me.right = me.left = me[0] = x;
  709. me.y = me.top = me.bottom = me[1] = y;
  710. };
  711. Ext.lib.Point.prototype = new Ext.lib.Region();
  712. /**
  713. * @class Ext.DomHelper
  714. */
  715. Ext.apply(Ext.DomHelper,
  716. function(){
  717. var pub,
  718. afterbegin = 'afterbegin',
  719. afterend = 'afterend',
  720. beforebegin = 'beforebegin',
  721. beforeend = 'beforeend',
  722. confRe = /tag|children|cn|html$/i;
  723. // private
  724. function doInsert(el, o, returnElement, pos, sibling, append){
  725. el = Ext.getDom(el);
  726. var newNode;
  727. if (pub.useDom) {
  728. newNode = createDom(o, null);
  729. if (append) {
  730. el.appendChild(newNode);
  731. } else {
  732. (sibling == 'firstChild' ? el : el.parentNode).insertBefore(newNode, el[sibling] || el);
  733. }
  734. } else {
  735. newNode = Ext.DomHelper.insertHtml(pos, el, Ext.DomHelper.createHtml(o));
  736. }
  737. return returnElement ? Ext.get(newNode, true) : newNode;
  738. }
  739. // build as dom
  740. /** @ignore */
  741. function createDom(o, parentNode){
  742. var el,
  743. doc = document,
  744. useSet,
  745. attr,
  746. val,
  747. cn;
  748. if (Ext.isArray(o)) { // Allow Arrays of siblings to be inserted
  749. el = doc.createDocumentFragment(); // in one shot using a DocumentFragment
  750. for (var i = 0, l = o.length; i < l; i++) {
  751. createDom(o[i], el);
  752. }
  753. } else if (typeof o == 'string') { // Allow a string as a child spec.
  754. el = doc.createTextNode(o);
  755. } else {
  756. el = doc.createElement( o.tag || 'div' );
  757. useSet = !!el.setAttribute; // In IE some elements don't have setAttribute
  758. for (var attr in o) {
  759. if(!confRe.test(attr)){
  760. val = o[attr];
  761. if(attr == 'cls'){
  762. el.className = val;
  763. }else{
  764. if(useSet){
  765. el.setAttribute(attr, val);
  766. }else{
  767. el[attr] = val;
  768. }
  769. }
  770. }
  771. }
  772. Ext.DomHelper.applyStyles(el, o.style);
  773. if ((cn = o.children || o.cn)) {
  774. createDom(cn, el);
  775. } else if (o.html) {
  776. el.innerHTML = o.html;
  777. }
  778. }
  779. if(parentNode){
  780. parentNode.appendChild(el);
  781. }
  782. return el;
  783. }
  784. pub = {
  785. /**
  786. * Creates a new Ext.Template from the DOM object spec.
  787. * @param {Object} o The DOM object spec (and children)
  788. * @return {Ext.Template} The new template
  789. */
  790. createTemplate : function(o){
  791. var html = Ext.DomHelper.createHtml(o);
  792. return new Ext.Template(html);
  793. },
  794. /** True to force the use of DOM instead of html fragments @type Boolean */
  795. useDom : false,
  796. /**
  797. * Creates new DOM element(s) and inserts them before el.
  798. * @param {Mixed} el The context element
  799. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  800. * @param {Boolean} returnElement (optional) true to return a Ext.Element
  801. * @return {HTMLElement/Ext.Element} The new node
  802. * @hide (repeat)
  803. */
  804. insertBefore : function(el, o, returnElement){
  805. return doInsert(el, o, returnElement, beforebegin);
  806. },
  807. /**
  808. * Creates new DOM element(s) and inserts them after el.
  809. * @param {Mixed} el The context element
  810. * @param {Object} o The DOM object spec (and children)
  811. * @param {Boolean} returnElement (optional) true to return a Ext.Element
  812. * @return {HTMLElement/Ext.Element} The new node
  813. * @hide (repeat)
  814. */
  815. insertAfter : function(el, o, returnElement){
  816. return doInsert(el, o, returnElement, afterend, 'nextSibling');
  817. },
  818. /**
  819. * Creates new DOM element(s) and inserts them as the first child of el.
  820. * @param {Mixed} el The context element
  821. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  822. * @param {Boolean} returnElement (optional) true to return a Ext.Element
  823. * @return {HTMLElement/Ext.Element} The new node
  824. * @hide (repeat)
  825. */
  826. insertFirst : function(el, o, returnElement){
  827. return doInsert(el, o, returnElement, afterbegin, 'firstChild');
  828. },
  829. /**
  830. * Creates new DOM element(s) and appends them to el.
  831. * @param {Mixed} el The context element
  832. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  833. * @param {Boolean} returnElement (optional) true to return a Ext.Element
  834. * @return {HTMLElement/Ext.Element} The new node
  835. * @hide (repeat)
  836. */
  837. append: function(el, o, returnElement){
  838. return doInsert(el, o, returnElement, beforeend, '', true);
  839. },
  840. /**
  841. * Creates new DOM element(s) without inserting them to the document.
  842. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  843. * @return {HTMLElement} The new uninserted node
  844. */
  845. createDom: createDom
  846. };
  847. return pub;
  848. }());
  849. /**
  850. * @class Ext.Template
  851. */
  852. Ext.apply(Ext.Template.prototype, {
  853. /**
  854. * @cfg {Boolean} disableFormats Specify <tt>true</tt> to disable format
  855. * functions in the template. If the template does not contain
  856. * {@link Ext.util.Format format functions}, setting <code>disableFormats</code>
  857. * to true will reduce <code>{@link #apply}</code> time. Defaults to <tt>false</tt>.
  858. * <pre><code>
  859. var t = new Ext.Template(
  860. '&lt;div name="{id}"&gt;',
  861. '&lt;span class="{cls}"&gt;{name} {value}&lt;/span&gt;',
  862. '&lt;/div&gt;',
  863. {
  864. compiled: true, // {@link #compile} immediately
  865. disableFormats: true // reduce <code>{@link #apply}</code> time since no formatting
  866. }
  867. );
  868. * </code></pre>
  869. * For a list of available format functions, see {@link Ext.util.Format}.
  870. */
  871. disableFormats : false,
  872. /**
  873. * See <code>{@link #disableFormats}</code>.
  874. * @type Boolean
  875. * @property disableFormats
  876. */
  877. /**
  878. * The regular expression used to match template variables
  879. * @type RegExp
  880. * @property
  881. * @hide repeat doc
  882. */
  883. re : /\{([\w-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g,
  884. argsRe : /^\s*['"](.*)["']\s*$/,
  885. compileARe : /\\/g,
  886. compileBRe : /(\r\n|\n)/g,
  887. compileCRe : /'/g,
  888. /**
  889. * Returns an HTML fragment of this template with the specified values applied.
  890. * @param {Object/Array} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
  891. * @return {String} The HTML fragment
  892. * @hide repeat doc
  893. */
  894. applyTemplate : function(values){
  895. var me = this,
  896. useF = me.disableFormats !== true,
  897. fm = Ext.util.Format,
  898. tpl = me;
  899. if(me.compiled){
  900. return me.compiled(values);
  901. }
  902. function fn(m, name, format, args){
  903. if (format && useF) {
  904. if (format.substr(0, 5) == "this.") {
  905. return tpl.call(format.substr(5), values[name], values);
  906. } else {
  907. if (args) {
  908. // quoted values are required for strings in compiled templates,
  909. // but for non compiled we need to strip them
  910. // quoted reversed for jsmin
  911. var re = me.argsRe;
  912. args = args.split(',');
  913. for(var i = 0, len = args.length; i < len; i++){
  914. args[i] = args[i].replace(re, "$1");
  915. }
  916. args = [values[name]].concat(args);
  917. } else {
  918. args = [values[name]];
  919. }
  920. return fm[format].apply(fm, args);
  921. }
  922. } else {
  923. return values[name] !== undefined ? values[name] : "";
  924. }
  925. }
  926. return me.html.replace(me.re, fn);
  927. },
  928. /**
  929. * Compiles the template into an internal function, eliminating the RegEx overhead.
  930. * @return {Ext.Template} this
  931. * @hide repeat doc
  932. */
  933. compile : function(){
  934. var me = this,
  935. fm = Ext.util.Format,
  936. useF = me.disableFormats !== true,
  937. sep = Ext.isGecko ? "+" : ",",
  938. body;
  939. function fn(m, name, format, args){
  940. if(format && useF){
  941. args = args ? ',' + args : "";
  942. if(format.substr(0, 5) != "this."){
  943. format = "fm." + format + '(';
  944. }else{
  945. format = 'this.call("'+ format.substr(5) + '", ';
  946. args = ", values";
  947. }
  948. }else{
  949. args= ''; format = "(values['" + name + "'] == undefined ? '' : ";
  950. }
  951. return "'"+ sep + format + "values['" + name + "']" + args + ")"+sep+"'";
  952. }
  953. // branched to use + in gecko and [].join() in others
  954. if(Ext.isGecko){
  955. body = "this.compiled = function(values){ return '" +
  956. me.html.replace(me.compileARe, '\\\\').replace(me.compileBRe, '\\n').replace(me.compileCRe, "\\'").replace(me.re, fn) +
  957. "';};";
  958. }else{
  959. body = ["this.compiled = function(values){ return ['"];
  960. body.push(me.html.replace(me.compileARe, '\\\\').replace(me.compileBRe, '\\n').replace(me.compileCRe, "\\'").replace(me.re, fn));
  961. body.push("'].join('');};");
  962. body = body.join('');
  963. }
  964. eval(body);
  965. return me;
  966. },
  967. // private function used to call members
  968. call : function(fnName, value, allValues){
  969. return this[fnName](value, allValues);
  970. }
  971. });
  972. Ext.Template.prototype.apply = Ext.Template.prototype.applyTemplate;
  973. /**
  974. * @class Ext.util.Functions
  975. * @singleton
  976. */
  977. Ext.util.Functions = {
  978. /**
  979. * Creates an interceptor function. The passed function is called before the original one. If it returns false,
  980. * the original one is not called. The resulting function returns the results of the original function.
  981. * The passed function is called with the parameters of the original function. Example usage:
  982. * <pre><code>
  983. var sayHi = function(name){
  984. alert('Hi, ' + name);
  985. }
  986. sayHi('Fred'); // alerts "Hi, Fred"
  987. // create a new function that validates input without
  988. // directly modifying the original function:
  989. var sayHiToFriend = Ext.createInterceptor(sayHi, function(name){
  990. return name == 'Brian';
  991. });
  992. sayHiToFriend('Fred'); // no alert
  993. sayHiToFriend('Brian'); // alerts "Hi, Brian"
  994. </code></pre>
  995. * @param {Function} origFn The original function.
  996. * @param {Function} newFn The function to call before the original
  997. * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the passed function is executed.
  998. * <b>If omitted, defaults to the scope in which the original function is called or the browser window.</b>
  999. * @return {Function} The new function
  1000. */
  1001. createInterceptor: function(origFn, newFn, scope) {
  1002. var method = origFn;
  1003. if (!Ext.isFunction(newFn)) {
  1004. return origFn;
  1005. }
  1006. else {
  1007. return function() {
  1008. var me = this,
  1009. args = arguments;
  1010. newFn.target = me;
  1011. newFn.method = origFn;
  1012. return (newFn.apply(scope || me || window, args) !== false) ?
  1013. origFn.apply(me || window, args) :
  1014. null;
  1015. };
  1016. }
  1017. },
  1018. /**
  1019. * Creates a delegate (callback) that sets the scope to obj.
  1020. * Call directly on any function. Example: <code>Ext.createDelegate(this.myFunction, this, [arg1, arg2])</code>
  1021. * Will create a function that is automatically scoped to obj so that the <tt>this</tt> variable inside the
  1022. * callback points to obj. Example usage:
  1023. * <pre><code>
  1024. var sayHi = function(name){
  1025. // Note this use of "this.text" here. This function expects to
  1026. // execute within a scope that contains a text property. In this
  1027. // example, the "this" variable is pointing to the btn object that
  1028. // was passed in createDelegate below.
  1029. alert('Hi, ' + name + '. You clicked the "' + this.text + '" button.');
  1030. }
  1031. var btn = new Ext.Button({
  1032. text: 'Say Hi',
  1033. renderTo: Ext.getBody()
  1034. });
  1035. // This callback will execute in the scope of the
  1036. // button instance. Clicking the button alerts
  1037. // "Hi, Fred. You clicked the "Say Hi" button."
  1038. btn.on('click', Ext.createDelegate(sayHi, btn, ['Fred']));
  1039. </code></pre>
  1040. * @param {Function} fn The function to delegate.
  1041. * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
  1042. * <b>If omitted, defaults to the browser window.</b>
  1043. * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
  1044. * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
  1045. * if a number the args are inserted at the specified position
  1046. * @return {Function} The new function
  1047. */
  1048. createDelegate: function(fn, obj, args, appendArgs) {
  1049. if (!Ext.isFunction(fn)) {
  1050. return fn;
  1051. }
  1052. return function() {
  1053. var callArgs = args || arguments;
  1054. if (appendArgs === true) {
  1055. callArgs = Array.prototype.slice.call(arguments, 0);
  1056. callArgs = callArgs.concat(args);
  1057. }
  1058. else if (Ext.isNumber(appendArgs)) {
  1059. callArgs = Array.prototype.slice.call(arguments, 0);
  1060. // copy arguments first
  1061. var applyArgs = [appendArgs, 0].concat(args);
  1062. // create method call params
  1063. Array.prototype.splice.apply(callArgs, applyArgs);
  1064. // splice them in
  1065. }
  1066. return fn.apply(obj || window, callArgs);
  1067. };
  1068. },
  1069. /**
  1070. * Calls this function after the number of millseconds specified, optionally in a specific scope. Example usage:
  1071. * <pre><code>
  1072. var sayHi = function(name){
  1073. alert('Hi, ' + name);
  1074. }
  1075. // executes immediately:
  1076. sayHi('Fred');
  1077. // executes after 2 seconds:
  1078. Ext.defer(sayHi, 2000, this, ['Fred']);
  1079. // this syntax is sometimes useful for deferring
  1080. // execution of an anonymous function:
  1081. Ext.defer(function(){
  1082. alert('Anonymous');
  1083. }, 100);
  1084. </code></pre>
  1085. * @param {Function} fn The function to defer.
  1086. * @param {Number} millis The number of milliseconds for the setTimeout call (if less than or equal to 0 the function is executed immediately)
  1087. * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
  1088. * <b>If omitted, defaults to the browser window.</b>
  1089. * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
  1090. * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
  1091. * if a number the args are inserted at the specified position
  1092. * @return {Number} The timeout id that can be used with clearTimeout
  1093. */
  1094. defer: function(fn, millis, obj, args, appendArgs) {
  1095. fn = Ext.util.Functions.createDelegate(fn, obj, args, appendArgs);
  1096. if (millis > 0) {
  1097. return setTimeout(fn, millis);
  1098. }
  1099. fn();
  1100. return 0;
  1101. },
  1102. /**
  1103. * Create a combined function call sequence of the original function + the passed function.
  1104. * The resulting function returns the results of the original function.
  1105. * The passed fcn is called with the parameters of the original function. Example usage:
  1106. *
  1107. var sayHi = function(name){
  1108. alert('Hi, ' + name);
  1109. }
  1110. sayHi('Fred'); // alerts "Hi, Fred"
  1111. var sayGoodbye = Ext.createSequence(sayHi, function(name){
  1112. alert('Bye, ' + name);
  1113. });
  1114. sayGoodbye('Fred'); // both alerts show
  1115. * @param {Function} origFn The original function.
  1116. * @param {Function} newFn The function to sequence
  1117. * @param {Object} scope (optional) The scope (this reference) in which the passed function is executed.
  1118. * If omitted, defaults to the scope in which the original function is called or the browser window.
  1119. * @return {Function} The new function
  1120. */
  1121. createSequence: function(origFn, newFn, scope) {
  1122. if (!Ext.isFunction(newFn)) {
  1123. return origFn;
  1124. }
  1125. else {
  1126. return function() {
  1127. var retval = origFn.apply(this || window, arguments);
  1128. newFn.apply(scope || this || window, arguments);
  1129. return retval;
  1130. };
  1131. }
  1132. }
  1133. };
  1134. /**
  1135. * Shorthand for {@link Ext.util.Functions#defer}
  1136. * @param {Function} fn The function to defer.
  1137. * @param {Number} millis The number of milliseconds for the setTimeout call (if less than or equal to 0 the function is executed immediately)
  1138. * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
  1139. * <b>If omitted, defaults to the browser window.</b>
  1140. * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
  1141. * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
  1142. * if a number the args are inserted at the specified position
  1143. * @return {Number} The timeout id that can be used with clearTimeout
  1144. * @member Ext
  1145. * @method defer
  1146. */
  1147. Ext.defer = Ext.util.Functions.defer;
  1148. /**
  1149. * Shorthand for {@link Ext.util.Functions#createInterceptor}
  1150. * @param {Function} origFn The original function.
  1151. * @param {Function} newFn The function to call before the original
  1152. * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the passed function is executed.
  1153. * <b>If omitted, defaults to the scope in which the original function is called or the browser window.</b>
  1154. * @return {Function} The new function
  1155. * @member Ext
  1156. * @method defer
  1157. */
  1158. Ext.createInterceptor = Ext.util.Functions.createInterceptor;
  1159. /**
  1160. * Shorthand for {@link Ext.util.Functions#createSequence}
  1161. * @param {Function} origFn The original function.
  1162. * @param {Function} newFn The function to sequence
  1163. * @param {Object} scope (optional) The scope (this reference) in which the passed function is executed.
  1164. * If omitted, defaults to the scope in which the original function is called or the browser window.
  1165. * @return {Function} The new function
  1166. * @member Ext
  1167. * @method defer
  1168. */
  1169. Ext.createSequence = Ext.util.Functions.createSequence;
  1170. /**
  1171. * Shorthand for {@link Ext.util.Functions#createDelegate}
  1172. * @param {Function} fn The function to delegate.
  1173. * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the function is executed.
  1174. * <b>If omitted, defaults to the browser window.</b>
  1175. * @param {Array} args (optional) Overrides arguments for the call. (Defaults to the arguments passed by the caller)
  1176. * @param {Boolean/Number} appendArgs (optional) if True args are appended to call args instead of overriding,
  1177. * if a number the args are inserted at the specified position
  1178. * @return {Function} The new function
  1179. * @member Ext
  1180. * @method defer
  1181. */
  1182. Ext.createDelegate = Ext.util.Functions.createDelegate;
  1183. /**
  1184. * @class Ext.util.Observable
  1185. */
  1186. Ext.apply(Ext.util.Observable.prototype, function(){
  1187. // this is considered experimental (along with beforeMethod, afterMethod, removeMethodListener?)
  1188. // allows for easier interceptor and sequences, including cancelling and overwriting the return value of the call
  1189. // private
  1190. function getMethodEvent(method){
  1191. var e = (this.methodEvents = this.methodEvents ||
  1192. {})[method], returnValue, v, cancel, obj = this;
  1193. if (!e) {
  1194. this.methodEvents[method] = e = {};
  1195. e.originalFn = this[method];
  1196. e.methodName = method;
  1197. e.before = [];
  1198. e.after = [];
  1199. var makeCall = function(fn, scope, args){
  1200. if((v = fn.apply(scope || obj, args)) !== undefined){
  1201. if (typeof v == 'object') {
  1202. if(v.returnValue !== undefined){
  1203. returnValue = v.returnValue;
  1204. }else{
  1205. returnValue = v;
  1206. }
  1207. cancel = !!v.cancel;
  1208. }
  1209. else
  1210. if (v === false) {
  1211. cancel = true;
  1212. }
  1213. else {
  1214. returnValue = v;
  1215. }
  1216. }
  1217. };
  1218. this[method] = function(){
  1219. var args = Array.prototype.slice.call(arguments, 0),
  1220. b;
  1221. returnValue = v = undefined;
  1222. cancel = false;
  1223. for(var i = 0, len = e.before.length; i < len; i++){
  1224. b = e.before[i];
  1225. makeCall(b.fn, b.scope, args);
  1226. if (cancel) {
  1227. return returnValue;
  1228. }
  1229. }
  1230. if((v = e.originalFn.apply(obj, args)) !== undefined){
  1231. returnValue = v;
  1232. }
  1233. for(var i = 0, len = e.after.length; i < len; i++){
  1234. b = e.after[i];
  1235. makeCall(b.fn, b.scope, args);
  1236. if (cancel) {
  1237. return returnValue;
  1238. }
  1239. }
  1240. return returnValue;
  1241. };
  1242. }
  1243. return e;
  1244. }
  1245. return {
  1246. // these are considered experimental
  1247. // allows for easier interceptor and sequences, including cancelling and overwriting the return value of the call
  1248. // adds an 'interceptor' called before the original method
  1249. beforeMethod : function(method, fn, scope){
  1250. getMethodEvent.call(this, method).before.push({
  1251. fn: fn,
  1252. scope: scope
  1253. });
  1254. },
  1255. // adds a 'sequence' called after the original method
  1256. afterMethod : function(method, fn, scope){
  1257. getMethodEvent.call(this, method).after.push({
  1258. fn: fn,
  1259. scope: scope
  1260. });
  1261. },
  1262. removeMethodListener: function(method, fn, scope){
  1263. var e = this.getMethodEvent(method);
  1264. for(var i = 0, len = e.before.length; i < len; i++){
  1265. if(e.before[i].fn == fn && e.before[i].scope == scope){
  1266. e.before.splice(i, 1);
  1267. return;
  1268. }
  1269. }
  1270. for(var i = 0, len = e.after.length; i < len; i++){
  1271. if(e.after[i].fn == fn && e.after[i].scope == scope){
  1272. e.after.splice(i, 1);
  1273. return;
  1274. }
  1275. }
  1276. },
  1277. /**
  1278. * Relays selected events from the specified Observable as if the events were fired by <tt><b>this</b></tt>.
  1279. * @param {Object} o The Observable whose events this object is to relay.
  1280. * @param {Array} events Array of event names to relay.
  1281. */
  1282. relayEvents : function(o, events){
  1283. var me = this;
  1284. function createHandler(ename){
  1285. return function(){
  1286. return me.fireEvent.apply(me, [ename].concat(Array.prototype.slice.call(arguments, 0)));
  1287. };
  1288. }
  1289. for(var i = 0, len = events.length; i < len; i++){
  1290. var ename = events[i];
  1291. me.events[ename] = me.events[ename] || true;
  1292. o.on(ename, createHandler(ename), me);
  1293. }
  1294. },
  1295. /**
  1296. * <p>Enables events fired by this Observable to bubble up an owner hierarchy by calling
  1297. * <code>this.getBubbleTarget()</code> if present. There is no implementation in the Observable base class.</p>
  1298. * <p>This is commonly used by Ext.Components to bubble events to owner Containers. See {@link Ext.Component.getBubbleTarget}. The default
  1299. * implementation in Ext.Component returns the Component's immediate owner. But if a known target is required, this can be overridden to
  1300. * access the required target more quickly.</p>
  1301. * <p>Example:</p><pre><code>
  1302. Ext.override(Ext.form.Field, {
  1303. // Add functionality to Field&#39;s initComponent to enable the change event to bubble
  1304. initComponent : Ext.form.Field.prototype.initComponent.createSequence(function() {
  1305. this.enableBubble('change');
  1306. }),
  1307. // We know that we want Field&#39;s events to bubble directly to the FormPanel.
  1308. getBubbleTarget : function() {
  1309. if (!this.formPanel) {
  1310. this.formPanel = this.findParentByType('form');
  1311. }
  1312. return this.formPanel;
  1313. }
  1314. });
  1315. var myForm = new Ext.formPanel({
  1316. title: 'User Details',
  1317. items: [{
  1318. ...
  1319. }],
  1320. listeners: {
  1321. change: function() {
  1322. // Title goes red if form has been modified.
  1323. myForm.header.setStyle('color', 'red');
  1324. }
  1325. }
  1326. });
  1327. </code></pre>
  1328. * @param {String/Array} events The event name to bubble, or an Array of event names.
  1329. */
  1330. enableBubble : function(events){
  1331. var me = this;
  1332. if(!Ext.isEmpty(events)){
  1333. events = Ext.isArray(events) ? events : Array.prototype.slice.call(arguments, 0);
  1334. for(var i = 0, len = events.length; i < len; i++){
  1335. var ename = events[i];
  1336. ename = ename.toLowerCase();
  1337. var ce = me.events[ename] || true;
  1338. if (typeof ce == 'boolean') {
  1339. ce = new Ext.util.Event(me, ename);
  1340. me.events[ename] = ce;
  1341. }
  1342. ce.bubble = true;
  1343. }
  1344. }
  1345. }
  1346. };
  1347. }());
  1348. /**
  1349. * Starts capture on the specified Observable. All events will be passed
  1350. * to the supplied function with the event name + standard signature of the event
  1351. * <b>before</b> the event is fired. If the supplied function returns false,
  1352. * the event will not fire.
  1353. * @param {Observable} o The Observable to capture events from.
  1354. * @param {Function} fn The function to call when an event is fired.
  1355. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the Observable firing the event.
  1356. * @static
  1357. */
  1358. Ext.util.Observable.capture = function(o, fn, scope){
  1359. o.fireEvent = o.fireEvent.createInterceptor(fn, scope);
  1360. };
  1361. /**
  1362. * Sets observability on the passed class constructor.<p>
  1363. * <p>This makes any event fired on any instance of the passed class also fire a single event through
  1364. * the <i>class</i> allowing for central handling of events on many instances at once.</p>
  1365. * <p>Usage:</p><pre><code>
  1366. Ext.util.Observable.observeClass(Ext.data.Connection);
  1367. Ext.data.Connection.on('beforerequest', function(con, options) {
  1368. console.log('Ajax request made to ' + options.url);
  1369. });</code></pre>
  1370. * @param {Function} c The class constructor to make observable.
  1371. * @param {Object} listeners An object containing a series of listeners to add. See {@link #addListener}.
  1372. * @static
  1373. */
  1374. Ext.util.Observable.observeClass = function(c, listeners){
  1375. if(c){
  1376. if(!c.fireEvent){
  1377. Ext.apply(c, new Ext.util.Observable());
  1378. Ext.util.Observable.capture(c.prototype, c.fireEvent, c);
  1379. }
  1380. if(typeof listeners == 'object'){
  1381. c.on(listeners);
  1382. }
  1383. return c;
  1384. }
  1385. };
  1386. /**
  1387. * @class Ext.EventManager
  1388. */
  1389. Ext.apply(Ext.EventManager, function(){
  1390. var resizeEvent,
  1391. resizeTask,
  1392. textEvent,
  1393. textSize,
  1394. D = Ext.lib.Dom,
  1395. propRe = /^(?:scope|delay|buffer|single|stopEvent|preventDefault|stopPropagation|normalized|args|delegate)$/,
  1396. curWidth = 0,
  1397. curHeight = 0,
  1398. // note 1: IE fires ONLY the keydown event on specialkey autorepeat
  1399. // note 2: Safari < 3.1, Gecko (Mac/Linux) & Opera fire only the keypress event on specialkey autorepeat
  1400. // (research done by @Jan Wolter at http://unixpapa.com/js/key.html)
  1401. useKeydown = Ext.isWebKit ?
  1402. Ext.num(navigator.userAgent.match(/AppleWebKit\/(\d+)/)[1]) >= 525 :
  1403. !((Ext.isGecko && !Ext.isWindows) || Ext.isOpera);
  1404. return {
  1405. // private
  1406. doResizeEvent: function(){
  1407. var h = D.getViewHeight(),
  1408. w = D.getViewWidth();
  1409. //whacky problem in IE where the resize event will fire even though the w/h are the same.
  1410. if(curHeight != h || curWidth != w){
  1411. resizeEvent.fire(curWidth = w, curHeight = h);
  1412. }
  1413. },
  1414. /**
  1415. * Adds a listener to be notified when the browser window is resized and provides resize event buffering (100 milliseconds),
  1416. * passes new viewport width and height to handlers.
  1417. * @param {Function} fn The handler function the window resize event invokes.
  1418. * @param {Object} scope The scope (<code>this</code> reference) in which the handler function executes. Defaults to the browser window.
  1419. * @param {boolean} options Options object as passed to {@link Ext.Element#addListener}
  1420. */
  1421. onWindowResize : function(fn, scope, options){
  1422. if(!resizeEvent){
  1423. resizeEvent = new Ext.util.Event();
  1424. resizeTask = new Ext.util.DelayedTask(this.doResizeEvent);
  1425. Ext.EventManager.on(window, "resize", this.fireWindowResize, this);
  1426. }
  1427. resizeEvent.addListener(fn, scope, options);
  1428. },
  1429. // exposed only to allow manual firing
  1430. fireWindowResize : function(){
  1431. if(resizeEvent){
  1432. resizeTask.delay(100);
  1433. }
  1434. },
  1435. /**
  1436. * Adds a listener to be notified when the user changes the active text size. Handler gets called with 2 params, the old size and the new size.
  1437. * @param {Function} fn The function the event invokes.
  1438. * @param {Object} scope The scope (<code>this</code> reference) in which the handler function executes. Defaults to the browser window.
  1439. * @param {boolean} options Options object as passed to {@link Ext.Element#addListener}
  1440. */
  1441. onTextResize : function(fn, scope, options){
  1442. if(!textEvent){
  1443. textEvent = new Ext.util.Event();
  1444. var textEl = new Ext.Element(document.createElement('div'));
  1445. textEl.dom.className = 'x-text-resize';
  1446. textEl.dom.innerHTML = 'X';
  1447. textEl.appendTo(document.body);
  1448. textSize = textEl.dom.offsetHeight;
  1449. setInterval(function(){
  1450. if(textEl.dom.offsetHeight != textSize){
  1451. textEvent.fire(textSize, textSize = textEl.dom.offsetHeight);
  1452. }
  1453. }, this.textResizeInterval);
  1454. }
  1455. textEvent.addListener(fn, scope, options);
  1456. },
  1457. /**
  1458. * Removes the passed window resize listener.
  1459. * @param {Function} fn The method the event invokes
  1460. * @param {Object} scope The scope of handler
  1461. */
  1462. removeResizeListener : function(fn, scope){
  1463. if(resizeEvent){
  1464. resizeEvent.removeListener(fn, scope);
  1465. }
  1466. },
  1467. // private
  1468. fireResize : function(){
  1469. if(resizeEvent){
  1470. resizeEvent.fire(D.getViewWidth(), D.getViewHeight());
  1471. }
  1472. },
  1473. /**
  1474. * The frequency, in milliseconds, to check for text resize events (defaults to 50)
  1475. */
  1476. textResizeInterval : 50,
  1477. /**
  1478. * Url used for onDocumentReady with using SSL (defaults to Ext.SSL_SECURE_URL)
  1479. */
  1480. ieDeferSrc : false,
  1481. // protected, short accessor for useKeydown
  1482. getKeyEvent : function(){
  1483. return useKeydown ? 'keydown' : 'keypress';
  1484. },
  1485. // protected for use inside the framework
  1486. // detects whether we should use keydown or keypress based on the browser.
  1487. useKeydown: useKeydown
  1488. };
  1489. }());
  1490. Ext.EventManager.on = Ext.EventManager.addListener;
  1491. Ext.apply(Ext.EventObjectImpl.prototype, {
  1492. /** Key constant @type Number */
  1493. BACKSPACE: 8,
  1494. /** Key constant @type Number */
  1495. TAB: 9,
  1496. /** Key constant @type Number */
  1497. NUM_CENTER: 12,
  1498. /** Key constant @type Number */
  1499. ENTER: 13,
  1500. /** Key constant @type Number */
  1501. RETURN: 13,
  1502. /** Key constant @type Number */
  1503. SHIFT: 16,
  1504. /** Key constant @type Number */
  1505. CTRL: 17,
  1506. CONTROL : 17, // legacy
  1507. /** Key constant @type Number */
  1508. ALT: 18,
  1509. /** Key constant @type Number */
  1510. PAUSE: 19,
  1511. /** Key constant @type Number */
  1512. CAPS_LOCK: 20,
  1513. /** Key constant @type Number */
  1514. ESC: 27,
  1515. /** Key constant @type Number */
  1516. SPACE: 32,
  1517. /** Key constant @type Number */
  1518. PAGE_UP: 33,
  1519. PAGEUP : 33, // legacy
  1520. /** Key constant @type Number */
  1521. PAGE_DOWN: 34,
  1522. PAGEDOWN : 34, // legacy
  1523. /** Key constant @type Number */
  1524. END: 35,
  1525. /** Key constant @type Number */
  1526. HOME: 36,
  1527. /** Key constant @type Number */
  1528. LEFT: 37,
  1529. /** Key constant @type Number */
  1530. UP: 38,
  1531. /** Key constant @type Number */
  1532. RIGHT: 39,
  1533. /** Key constant @type Number */
  1534. DOWN: 40,
  1535. /** Key constant @type Number */
  1536. PRINT_SCREEN: 44,
  1537. /** Key constant @type Number */
  1538. INSERT: 45,
  1539. /** Key constant @type Number */
  1540. DELETE: 46,
  1541. /** Key constant @type Number */
  1542. ZERO: 48,
  1543. /** Key constant @type Number */
  1544. ONE: 49,
  1545. /** Key constant @type Number */
  1546. TWO: 50,
  1547. /** Key constant @type Number */
  1548. THREE: 51,
  1549. /** Key constant @type Number */
  1550. FOUR: 52,
  1551. /** Key constant @type Number */
  1552. FIVE: 53,
  1553. /** Key constant @type Number */
  1554. SIX: 54,
  1555. /** Key constant @type Number */
  1556. SEVEN: 55,
  1557. /** Key constant @type Number */
  1558. EIGHT: 56,
  1559. /** Key constant @type Number */
  1560. NINE: 57,
  1561. /** Key constant @type Number */
  1562. A: 65,
  1563. /** Key constant @type Number */
  1564. B: 66,
  1565. /** Key constant @type Number */
  1566. C: 67,
  1567. /** Key constant @type Number */
  1568. D: 68,
  1569. /** Key constant @type Number */
  1570. E: 69,
  1571. /** Key constant @type Number */
  1572. F: 70,
  1573. /** Key constant @type Number */
  1574. G: 71,
  1575. /** Key constant @type Number */
  1576. H: 72,
  1577. /** Key constant @type Number */
  1578. I: 73,
  1579. /** Key constant @type Number */
  1580. J: 74,
  1581. /** Key constant @type Number */
  1582. K: 75,
  1583. /** Key constant @type Number */
  1584. L: 76,
  1585. /** Key constant @type Number */
  1586. M: 77,
  1587. /** Key constant @type Number */
  1588. N: 78,
  1589. /** Key constant @type Number */
  1590. O: 79,
  1591. /** Key constant @type Number */
  1592. P: 80,
  1593. /** Key constant @type Number */
  1594. Q: 81,
  1595. /** Key constant @type Number */
  1596. R: 82,
  1597. /** Key constant @type Number */
  1598. S: 83,
  1599. /** Key constant @type Number */
  1600. T: 84,
  1601. /** Key constant @type Number */
  1602. U: 85,
  1603. /** Key constant @type Number */
  1604. V: 86,
  1605. /** Key constant @type Number */
  1606. W: 87,
  1607. /** Key constant @type Number */
  1608. X: 88,
  1609. /** Key constant @type Number */
  1610. Y: 89,
  1611. /** Key constant @type Number */
  1612. Z: 90,
  1613. /** Key constant @type Number */
  1614. CONTEXT_MENU: 93,
  1615. /** Key constant @type Number */
  1616. NUM_ZERO: 96,
  1617. /** Key constant @type Number */
  1618. NUM_ONE: 97,
  1619. /** Key constant @type Number */
  1620. NUM_TWO: 98,
  1621. /** Key constant @type Number */
  1622. NUM_THREE: 99,
  1623. /** Key constant @type Number */
  1624. NUM_FOUR: 100,
  1625. /** Key constant @type Number */
  1626. NUM_FIVE: 101,
  1627. /** Key constant @type Number */
  1628. NUM_SIX: 102,
  1629. /** Key constant @type Number */
  1630. NUM_SEVEN: 103,
  1631. /** Key constant @type Number */
  1632. NUM_EIGHT: 104,
  1633. /** Key constant @type Number */
  1634. NUM_NINE: 105,
  1635. /** Key constant @type Number */
  1636. NUM_MULTIPLY: 106,
  1637. /** Key constant @type Number */
  1638. NUM_PLUS: 107,
  1639. /** Key constant @type Number */
  1640. NUM_MINUS: 109,
  1641. /** Key constant @type Number */
  1642. NUM_PERIOD: 110,
  1643. /** Key constant @type Number */
  1644. NUM_DIVISION: 111,
  1645. /** Key constant @type Number */
  1646. F1: 112,
  1647. /** Key constant @type Number */
  1648. F2: 113,
  1649. /** Key constant @type Number */
  1650. F3: 114,
  1651. /** Key constant @type Number */
  1652. F4: 115,
  1653. /** Key constant @type Number */
  1654. F5: 116,
  1655. /** Key constant @type Number */
  1656. F6: 117,
  1657. /** Key constant @type Number */
  1658. F7: 118,
  1659. /** Key constant @type Number */
  1660. F8: 119,
  1661. /** Key constant @type Number */
  1662. F9: 120,
  1663. /** Key constant @type Number */
  1664. F10: 121,
  1665. /** Key constant @type Number */
  1666. F11: 122,
  1667. /** Key constant @type Number */
  1668. F12: 123,
  1669. /** @private */
  1670. isNavKeyPress : function(){
  1671. var me = this,
  1672. k = this.normalizeKey(me.keyCode);
  1673. return (k >= 33 && k <= 40) || // Page Up/Down, End, Home, Left, Up, Right, Down
  1674. k == me.RETURN ||
  1675. k == me.TAB ||
  1676. k == me.ESC;
  1677. },
  1678. isSpecialKey : function(){
  1679. var k = this.normalizeKey(this.keyCode);
  1680. return (this.type == 'keypress' && this.ctrlKey) ||
  1681. this.isNavKeyPress() ||
  1682. (k == this.BACKSPACE) || // Backspace
  1683. (k >= 16 && k <= 20) || // Shift, Ctrl, Alt, Pause, Caps Lock
  1684. (k >= 44 && k <= 46); // Print Screen, Insert, Delete
  1685. },
  1686. getPoint : function(){
  1687. return new Ext.lib.Point(this.xy[0], this.xy[1]);
  1688. },
  1689. /**
  1690. * Returns true if the control, meta, shift or alt key was pressed during this event.
  1691. * @return {Boolean}
  1692. */
  1693. hasModifier : function(){
  1694. return ((this.ctrlKey || this.altKey) || this.shiftKey);
  1695. }
  1696. });/**
  1697. * @class Ext.Element
  1698. */
  1699. Ext.Element.addMethods({
  1700. /**
  1701. * Stops the specified event(s) from bubbling and optionally prevents the default action
  1702. * @param {String/Array} eventName an event / array of events to stop from bubbling
  1703. * @param {Boolean} preventDefault (optional) true to prevent the default action too
  1704. * @return {Ext.Element} this
  1705. */
  1706. swallowEvent : function(eventName, preventDefault) {
  1707. var me = this;
  1708. function fn(e) {
  1709. e.stopPropagation();
  1710. if (preventDefault) {
  1711. e.preventDefault();
  1712. }
  1713. }
  1714. if (Ext.isArray(eventName)) {
  1715. Ext.each(eventName, function(e) {
  1716. me.on(e, fn);
  1717. });
  1718. return me;
  1719. }
  1720. me.on(eventName, fn);
  1721. return me;
  1722. },
  1723. /**
  1724. * Create an event handler on this element such that when the event fires and is handled by this element,
  1725. * it will be relayed to another object (i.e., fired again as if it originated from that object instead).
  1726. * @param {String} eventName The type of event to relay
  1727. * @param {Object} object Any object that extends {@link Ext.util.Observable} that will provide the context
  1728. * for firing the relayed event
  1729. */
  1730. relayEvent : function(eventName, observable) {
  1731. this.on(eventName, function(e) {
  1732. observable.fireEvent(eventName, e);
  1733. });
  1734. },
  1735. /**
  1736. * Removes worthless text nodes
  1737. * @param {Boolean} forceReclean (optional) By default the element
  1738. * keeps track if it has been cleaned already so
  1739. * you can call this over and over. However, if you update the element and
  1740. * need to force a reclean, you can pass true.
  1741. */
  1742. clean : function(forceReclean) {
  1743. var me = this,
  1744. dom = me.dom,
  1745. n = dom.firstChild,
  1746. ni = -1;
  1747. if (Ext.Element.data(dom, 'isCleaned') && forceReclean !== true) {
  1748. return me;
  1749. }
  1750. while (n) {
  1751. var nx = n.nextSibling;
  1752. if (n.nodeType == 3 && !(/\S/.test(n.nodeValue))) {
  1753. dom.removeChild(n);
  1754. } else {
  1755. n.nodeIndex = ++ni;
  1756. }
  1757. n = nx;
  1758. }
  1759. Ext.Element.data(dom, 'isCleaned', true);
  1760. return me;
  1761. },
  1762. /**
  1763. * Direct access to the Updater {@link Ext.Updater#update} method. The method takes the same object
  1764. * parameter as {@link Ext.Updater#update}
  1765. * @return {Ext.Element} this
  1766. */
  1767. load : function() {
  1768. var updateManager = this.getUpdater();
  1769. updateManager.update.apply(updateManager, arguments);
  1770. return this;
  1771. },
  1772. /**
  1773. * Gets this element's {@link Ext.Updater Updater}
  1774. * @return {Ext.Updater} The Updater
  1775. */
  1776. getUpdater : function() {
  1777. return this.updateManager || (this.updateManager = new Ext.Updater(this));
  1778. },
  1779. /**
  1780. * Update the innerHTML of this element, optionally searching for and processing scripts
  1781. * @param {String} html The new HTML
  1782. * @param {Boolean} loadScripts (optional) True to look for and process scripts (defaults to false)
  1783. * @param {Function} callback (optional) For async script loading you can be notified when the update completes
  1784. * @return {Ext.Element} this
  1785. */
  1786. update : function(html, loadScripts, callback) {
  1787. if (!this.dom) {
  1788. return this;
  1789. }
  1790. html = html || "";
  1791. if (loadScripts !== true) {
  1792. this.dom.innerHTML = html;
  1793. if (typeof callback == 'function') {
  1794. callback();
  1795. }
  1796. return this;
  1797. }
  1798. var id = Ext.id(),
  1799. dom = this.dom;
  1800. html += '<span id="' + id + '"></span>';
  1801. Ext.lib.Event.onAvailable(id, function() {
  1802. var DOC = document,
  1803. hd = DOC.getElementsByTagName("head")[0],
  1804. re = /(?:<script([^>]*)?>)((\n|\r|.)*?)(?:<\/script>)/ig,
  1805. srcRe = /\ssrc=([\'\"])(.*?)\1/i,
  1806. typeRe = /\stype=([\'\"])(.*?)\1/i,
  1807. match,
  1808. attrs,
  1809. srcMatch,
  1810. typeMatch,
  1811. el,
  1812. s;
  1813. while ((match = re.exec(html))) {
  1814. attrs = match[1];
  1815. srcMatch = attrs ? attrs.match(srcRe) : false;
  1816. if (srcMatch && srcMatch[2]) {
  1817. s = DOC.createElement("script");
  1818. s.src = srcMatch[2];
  1819. typeMatch = attrs.match(typeRe);
  1820. if (typeMatch && typeMatch[2]) {
  1821. s.type = typeMatch[2];
  1822. }
  1823. hd.appendChild(s);
  1824. } else if (match[2] && match[2].length > 0) {
  1825. if (window.execScript) {
  1826. window.execScript(match[2]);
  1827. } else {
  1828. window.eval(match[2]);
  1829. }
  1830. }
  1831. }
  1832. el = DOC.getElementById(id);
  1833. if (el) {
  1834. Ext.removeNode(el);
  1835. }
  1836. if (typeof callback == 'function') {
  1837. callback();
  1838. }
  1839. });
  1840. dom.innerHTML = html.replace(/(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig, "");
  1841. return this;
  1842. },
  1843. // inherit docs, overridden so we can add removeAnchor
  1844. removeAllListeners : function() {
  1845. this.removeAnchor();
  1846. Ext.EventManager.removeAll(this.dom);
  1847. return this;
  1848. },
  1849. /**
  1850. * Creates a proxy element of this element
  1851. * @param {String/Object} config The class name of the proxy element or a DomHelper config object
  1852. * @param {String/HTMLElement} renderTo (optional) The element or element id to render the proxy to (defaults to document.body)
  1853. * @param {Boolean} matchBox (optional) True to align and size the proxy to this element now (defaults to false)
  1854. * @return {Ext.Element} The new proxy element
  1855. */
  1856. createProxy : function(config, renderTo, matchBox) {
  1857. config = (typeof config == 'object') ? config : {tag : "div", cls: config};
  1858. var me = this,
  1859. proxy = renderTo ? Ext.DomHelper.append(renderTo, config, true) :
  1860. Ext.DomHelper.insertBefore(me.dom, config, true);
  1861. if (matchBox && me.setBox && me.getBox) { // check to make sure Element.position.js is loaded
  1862. proxy.setBox(me.getBox());
  1863. }
  1864. return proxy;
  1865. }
  1866. });
  1867. Ext.Element.prototype.getUpdateManager = Ext.Element.prototype.getUpdater;
  1868. /**
  1869. * @class Ext.Element
  1870. */
  1871. Ext.Element.addMethods({
  1872. /**
  1873. * Gets the x,y coordinates specified by the anchor position on the element.
  1874. * @param {String} anchor (optional) The specified anchor position (defaults to "c"). See {@link #alignTo}
  1875. * for details on supported anchor positions.
  1876. * @param {Boolean} local (optional) True to get the local (element top/left-relative) anchor position instead
  1877. * of page coordinates
  1878. * @param {Object} size (optional) An object containing the size to use for calculating anchor position
  1879. * {width: (target width), height: (target height)} (defaults to the element's current size)
  1880. * @return {Array} [x, y] An array containing the element's x and y coordinates
  1881. */
  1882. getAnchorXY : function(anchor, local, s){
  1883. //Passing a different size is useful for pre-calculating anchors,
  1884. //especially for anchored animations that change the el size.
  1885. anchor = (anchor || "tl").toLowerCase();
  1886. s = s || {};
  1887. var me = this,
  1888. vp = me.dom == document.body || me.dom == document,
  1889. w = s.width || vp ? Ext.lib.Dom.getViewWidth() : me.getWidth(),
  1890. h = s.height || vp ? Ext.lib.Dom.getViewHeight() : me.getHeight(),
  1891. xy,
  1892. r = Math.round,
  1893. o = me.getXY(),
  1894. scroll = me.getScroll(),
  1895. extraX = vp ? scroll.left : !local ? o[0] : 0,
  1896. extraY = vp ? scroll.top : !local ? o[1] : 0,
  1897. hash = {
  1898. c : [r(w * 0.5), r(h * 0.5)],
  1899. t : [r(w * 0.5), 0],
  1900. l : [0, r(h * 0.5)],
  1901. r : [w, r(h * 0.5)],
  1902. b : [r(w * 0.5), h],
  1903. tl : [0, 0],
  1904. bl : [0, h],
  1905. br : [w, h],
  1906. tr : [w, 0]
  1907. };
  1908. xy = hash[anchor];
  1909. return [xy[0] + extraX, xy[1] + extraY];
  1910. },
  1911. /**
  1912. * Anchors an element to another element and realigns it when the window is resized.
  1913. * @param {Mixed} element The element to align to.
  1914. * @param {String} position The position to align to.
  1915. * @param {Array} offsets (optional) Offset the positioning by [x, y]
  1916. * @param {Boolean/Object} animate (optional) True for the default animation or a standard Element animation config object
  1917. * @param {Boolean/Number} monitorScroll (optional) True to monitor body scroll and reposition. If this parameter
  1918. * is a number, it is used as the buffer delay (defaults to 50ms).
  1919. * @param {Function} callback The function to call after the animation finishes
  1920. * @return {Ext.Element} this
  1921. */
  1922. anchorTo : function(el, alignment, offsets, animate, monitorScroll, callback){
  1923. var me = this,
  1924. dom = me.dom,
  1925. scroll = !Ext.isEmpty(monitorScroll),
  1926. action = function(){
  1927. Ext.fly(dom).alignTo(el, alignment, offsets, animate);
  1928. Ext.callback(callback, Ext.fly(dom));
  1929. },
  1930. anchor = this.getAnchor();
  1931. // previous listener anchor, remove it
  1932. this.removeAnchor();
  1933. Ext.apply(anchor, {
  1934. fn: action,
  1935. scroll: scroll
  1936. });
  1937. Ext.EventManager.onWindowResize(action, null);
  1938. if(scroll){
  1939. Ext.EventManager.on(window, 'scroll', action, null,
  1940. {buffer: !isNaN(monitorScroll) ? monitorScroll : 50});
  1941. }
  1942. action.call(me); // align immediately
  1943. return me;
  1944. },
  1945. /**
  1946. * Remove any anchor to this element. See {@link #anchorTo}.
  1947. * @return {Ext.Element} this
  1948. */
  1949. removeAnchor : function(){
  1950. var me = this,
  1951. anchor = this.getAnchor();
  1952. if(anchor && anchor.fn){
  1953. Ext.EventManager.removeResizeListener(anchor.fn);
  1954. if(anchor.scroll){
  1955. Ext.EventManager.un(window, 'scroll', anchor.fn);
  1956. }
  1957. delete anchor.fn;
  1958. }
  1959. return me;
  1960. },
  1961. // private
  1962. getAnchor : function(){
  1963. var data = Ext.Element.data,
  1964. dom = this.dom;
  1965. if (!dom) {
  1966. return;
  1967. }
  1968. var anchor = data(dom, '_anchor');
  1969. if(!anchor){
  1970. anchor = data(dom, '_anchor', {});
  1971. }
  1972. return anchor;
  1973. },
  1974. /**
  1975. * Gets the x,y coordinates to align this element with another element. See {@link #alignTo} for more info on the
  1976. * supported position values.
  1977. * @param {Mixed} element The element to align to.
  1978. * @param {String} position (optional, defaults to "tl-bl?") The position to align to.
  1979. * @param {Array} offsets (optional) Offset the positioning by [x, y]
  1980. * @return {Array} [x, y]
  1981. */
  1982. getAlignToXY : function(el, p, o){
  1983. el = Ext.get(el);
  1984. if(!el || !el.dom){
  1985. throw "Element.alignToXY with an element that doesn't exist";
  1986. }
  1987. o = o || [0,0];
  1988. p = (!p || p == "?" ? "tl-bl?" : (!(/-/).test(p) && p !== "" ? "tl-" + p : p || "tl-bl")).toLowerCase();
  1989. var me = this,
  1990. d = me.dom,
  1991. a1,
  1992. a2,
  1993. x,
  1994. y,
  1995. //constrain the aligned el to viewport if necessary
  1996. w,
  1997. h,
  1998. r,
  1999. dw = Ext.lib.Dom.getViewWidth() -10, // 10px of margin for ie
  2000. dh = Ext.lib.Dom.getViewHeight()-10, // 10px of margin for ie
  2001. p1y,
  2002. p1x,
  2003. p2y,
  2004. p2x,
  2005. swapY,
  2006. swapX,
  2007. doc = document,
  2008. docElement = doc.documentElement,
  2009. docBody = doc.body,
  2010. scrollX = (docElement.scrollLeft || docBody.scrollLeft || 0)+5,
  2011. scrollY = (docElement.scrollTop || docBody.scrollTop || 0)+5,
  2012. c = false, //constrain to viewport
  2013. p1 = "",
  2014. p2 = "",
  2015. m = p.match(/^([a-z]+)-([a-z]+)(\?)?$/);
  2016. if(!m){
  2017. throw "Element.alignTo with an invalid alignment " + p;
  2018. }
  2019. p1 = m[1];
  2020. p2 = m[2];
  2021. c = !!m[3];
  2022. //Subtract the aligned el's internal xy from the target's offset xy
  2023. //plus custom offset to get the aligned el's new offset xy
  2024. a1 = me.getAnchorXY(p1, true);
  2025. a2 = el.getAnchorXY(p2, false);
  2026. x = a2[0] - a1[0] + o[0];
  2027. y = a2[1] - a1[1] + o[1];
  2028. if(c){
  2029. w = me.getWidth();
  2030. h = me.getHeight();
  2031. r = el.getRegion();
  2032. //If we are at a viewport boundary and the aligned el is anchored on a target border that is
  2033. //perpendicular to the vp border, allow the aligned el to slide on that border,
  2034. //otherwise swap the aligned el to the opposite border of the target.
  2035. p1y = p1.charAt(0);
  2036. p1x = p1.charAt(p1.length-1);
  2037. p2y = p2.charAt(0);
  2038. p2x = p2.charAt(p2.length-1);
  2039. swapY = ((p1y=="t" && p2y=="b") || (p1y=="b" && p2y=="t"));
  2040. swapX = ((p1x=="r" && p2x=="l") || (p1x=="l" && p2x=="r"));
  2041. if (x + w > dw + scrollX) {
  2042. x = swapX ? r.left-w : dw+scrollX-w;
  2043. }
  2044. if (x < scrollX) {
  2045. x = swapX ? r.right : scrollX;
  2046. }
  2047. if (y + h > dh + scrollY) {
  2048. y = swapY ? r.top-h : dh+scrollY-h;
  2049. }
  2050. if (y < scrollY){
  2051. y = swapY ? r.bottom : scrollY;
  2052. }
  2053. }
  2054. return [x,y];
  2055. },
  2056. /**
  2057. * Aligns this element with another element relative to the specified anchor points. If the other element is the
  2058. * document it aligns it to the viewport.
  2059. * The position parameter is optional, and can be specified in any one of the following formats:
  2060. * <ul>
  2061. * <li><b>Blank</b>: Defaults to aligning the element's top-left corner to the target's bottom-left corner ("tl-bl").</li>
  2062. * <li><b>One anchor (deprecated)</b>: The passed anchor position is used as the target element's anchor point.
  2063. * The element being aligned will position its top-left corner (tl) to that point. <i>This method has been
  2064. * deprecated in favor of the newer two anchor syntax below</i>.</li>
  2065. * <li><b>Two anchors</b>: If two values from the table below are passed separated by a dash, the first value is used as the
  2066. * element's anchor point, and the second value is used as the target's anchor point.</li>
  2067. * </ul>
  2068. * In addition to the anchor points, the position parameter also supports the "?" character. If "?" is passed at the end of
  2069. * the position string, the element will attempt to align as specified, but the position will be adjusted to constrain to
  2070. * the viewport if necessary. Note that the element being aligned might be swapped to align to a different position than
  2071. * that specified in order to enforce the viewport constraints.
  2072. * Following are all of the supported anchor positions:
  2073. <pre>
  2074. Value Description
  2075. ----- -----------------------------
  2076. tl The top left corner (default)
  2077. t The center of the top edge
  2078. tr The top right corner
  2079. l The center of the left edge
  2080. c In the center of the element
  2081. r The center of the right edge
  2082. bl The bottom left corner
  2083. b The center of the bottom edge
  2084. br The bottom right corner
  2085. </pre>
  2086. Example Usage:
  2087. <pre><code>
  2088. // align el to other-el using the default positioning ("tl-bl", non-constrained)
  2089. el.alignTo("other-el");
  2090. // align the top left corner of el with the top right corner of other-el (constrained to viewport)
  2091. el.alignTo("other-el", "tr?");
  2092. // align the bottom right corner of el with the center left edge of other-el
  2093. el.alignTo("other-el", "br-l?");
  2094. // align the center of el with the bottom left corner of other-el and
  2095. // adjust the x position by -6 pixels (and the y position by 0)
  2096. el.alignTo("other-el", "c-bl", [-6, 0]);
  2097. </code></pre>
  2098. * @param {Mixed} element The element to align to.
  2099. * @param {String} position (optional, defaults to "tl-bl?") The position to align to.
  2100. * @param {Array} offsets (optional) Offset the positioning by [x, y]
  2101. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  2102. * @return {Ext.Element} this
  2103. */
  2104. alignTo : function(element, position, offsets, animate){
  2105. var me = this;
  2106. return me.setXY(me.getAlignToXY(element, position, offsets),
  2107. me.preanim && !!animate ? me.preanim(arguments, 3) : false);
  2108. },
  2109. // private ==> used outside of core
  2110. adjustForConstraints : function(xy, parent, offsets){
  2111. return this.getConstrainToXY(parent || document, false, offsets, xy) || xy;
  2112. },
  2113. // private ==> used outside of core
  2114. getConstrainToXY : function(el, local, offsets, proposedXY){
  2115. var os = {top:0, left:0, bottom:0, right: 0};
  2116. return function(el, local, offsets, proposedXY){
  2117. el = Ext.get(el);
  2118. offsets = offsets ? Ext.applyIf(offsets, os) : os;
  2119. var vw, vh, vx = 0, vy = 0;
  2120. if(el.dom == document.body || el.dom == document){
  2121. vw =Ext.lib.Dom.getViewWidth();
  2122. vh = Ext.lib.Dom.getViewHeight();
  2123. }else{
  2124. vw = el.dom.clientWidth;
  2125. vh = el.dom.clientHeight;
  2126. if(!local){
  2127. var vxy = el.getXY();
  2128. vx = vxy[0];
  2129. vy = vxy[1];
  2130. }
  2131. }
  2132. var s = el.getScroll();
  2133. vx += offsets.left + s.left;
  2134. vy += offsets.top + s.top;
  2135. vw -= offsets.right;
  2136. vh -= offsets.bottom;
  2137. var vr = vx + vw,
  2138. vb = vy + vh,
  2139. xy = proposedXY || (!local ? this.getXY() : [this.getLeft(true), this.getTop(true)]),
  2140. x = xy[0], y = xy[1],
  2141. offset = this.getConstrainOffset(),
  2142. w = this.dom.offsetWidth + offset,
  2143. h = this.dom.offsetHeight + offset;
  2144. // only move it if it needs it
  2145. var moved = false;
  2146. // first validate right/bottom
  2147. if((x + w) > vr){
  2148. x = vr - w;
  2149. moved = true;
  2150. }
  2151. if((y + h) > vb){
  2152. y = vb - h;
  2153. moved = true;
  2154. }
  2155. // then make sure top/left isn't negative
  2156. if(x < vx){
  2157. x = vx;
  2158. moved = true;
  2159. }
  2160. if(y < vy){
  2161. y = vy;
  2162. moved = true;
  2163. }
  2164. return moved ? [x, y] : false;
  2165. };
  2166. }(),
  2167. // el = Ext.get(el);
  2168. // offsets = Ext.applyIf(offsets || {}, {top : 0, left : 0, bottom : 0, right : 0});
  2169. // var me = this,
  2170. // doc = document,
  2171. // s = el.getScroll(),
  2172. // vxy = el.getXY(),
  2173. // vx = offsets.left + s.left,
  2174. // vy = offsets.top + s.top,
  2175. // vw = -offsets.right,
  2176. // vh = -offsets.bottom,
  2177. // vr,
  2178. // vb,
  2179. // xy = proposedXY || (!local ? me.getXY() : [me.getLeft(true), me.getTop(true)]),
  2180. // x = xy[0],
  2181. // y = xy[1],
  2182. // w = me.dom.offsetWidth, h = me.dom.offsetHeight,
  2183. // moved = false; // only move it if it needs it
  2184. //
  2185. //
  2186. // if(el.dom == doc.body || el.dom == doc){
  2187. // vw += Ext.lib.Dom.getViewWidth();
  2188. // vh += Ext.lib.Dom.getViewHeight();
  2189. // }else{
  2190. // vw += el.dom.clientWidth;
  2191. // vh += el.dom.clientHeight;
  2192. // if(!local){
  2193. // vx += vxy[0];
  2194. // vy += vxy[1];
  2195. // }
  2196. // }
  2197. // // first validate right/bottom
  2198. // if(x + w > vx + vw){
  2199. // x = vx + vw - w;
  2200. // moved = true;
  2201. // }
  2202. // if(y + h > vy + vh){
  2203. // y = vy + vh - h;
  2204. // moved = true;
  2205. // }
  2206. // // then make sure top/left isn't negative
  2207. // if(x < vx){
  2208. // x = vx;
  2209. // moved = true;
  2210. // }
  2211. // if(y < vy){
  2212. // y = vy;
  2213. // moved = true;
  2214. // }
  2215. // return moved ? [x, y] : false;
  2216. // },
  2217. // private, used internally
  2218. getConstrainOffset : function(){
  2219. return 0;
  2220. },
  2221. /**
  2222. * Calculates the x, y to center this element on the screen
  2223. * @return {Array} The x, y values [x, y]
  2224. */
  2225. getCenterXY : function(){
  2226. return this.getAlignToXY(document, 'c-c');
  2227. },
  2228. /**
  2229. * Centers the Element in either the viewport, or another Element.
  2230. * @param {Mixed} centerIn (optional) The element in which to center the element.
  2231. */
  2232. center : function(centerIn){
  2233. return this.alignTo(centerIn || document, 'c-c');
  2234. }
  2235. });
  2236. /**
  2237. * @class Ext.Element
  2238. */
  2239. Ext.Element.addMethods({
  2240. /**
  2241. * Creates a {@link Ext.CompositeElement} for child nodes based on the passed CSS selector (the selector should not contain an id).
  2242. * @param {String} selector The CSS selector
  2243. * @param {Boolean} unique (optional) True to create a unique Ext.Element for each child (defaults to false, which creates a single shared flyweight object)
  2244. * @return {CompositeElement/CompositeElementLite} The composite element
  2245. */
  2246. select : function(selector, unique){
  2247. return Ext.Element.select(selector, unique, this.dom);
  2248. }
  2249. });/**
  2250. * @class Ext.Element
  2251. */
  2252. Ext.apply(Ext.Element.prototype, function() {
  2253. var GETDOM = Ext.getDom,
  2254. GET = Ext.get,
  2255. DH = Ext.DomHelper;
  2256. return {
  2257. /**
  2258. * Inserts (or creates) the passed element (or DomHelper config) as a sibling of this element
  2259. * @param {Mixed/Object/Array} el The id, element to insert or a DomHelper config to create and insert *or* an array of any of those.
  2260. * @param {String} where (optional) 'before' or 'after' defaults to before
  2261. * @param {Boolean} returnDom (optional) True to return the raw DOM element instead of Ext.Element
  2262. * @return {Ext.Element} The inserted Element. If an array is passed, the last inserted element is returned.
  2263. */
  2264. insertSibling: function(el, where, returnDom){
  2265. var me = this,
  2266. rt,
  2267. isAfter = (where || 'before').toLowerCase() == 'after',
  2268. insertEl;
  2269. if(Ext.isArray(el)){
  2270. insertEl = me;
  2271. Ext.each(el, function(e) {
  2272. rt = Ext.fly(insertEl, '_internal').insertSibling(e, where, returnDom);
  2273. if(isAfter){
  2274. insertEl = rt;
  2275. }
  2276. });
  2277. return rt;
  2278. }
  2279. el = el || {};
  2280. if(el.nodeType || el.dom){
  2281. rt = me.dom.parentNode.insertBefore(GETDOM(el), isAfter ? me.dom.nextSibling : me.dom);
  2282. if (!returnDom) {
  2283. rt = GET(rt);
  2284. }
  2285. }else{
  2286. if (isAfter && !me.dom.nextSibling) {
  2287. rt = DH.append(me.dom.parentNode, el, !returnDom);
  2288. } else {
  2289. rt = DH[isAfter ? 'insertAfter' : 'insertBefore'](me.dom, el, !returnDom);
  2290. }
  2291. }
  2292. return rt;
  2293. }
  2294. };
  2295. }());/**
  2296. * @class Ext.Element
  2297. */
  2298. // special markup used throughout Ext when box wrapping elements
  2299. Ext.Element.boxMarkup = '<div class="{0}-tl"><div class="{0}-tr"><div class="{0}-tc"></div></div></div><div class="{0}-ml"><div class="{0}-mr"><div class="{0}-mc"></div></div></div><div class="{0}-bl"><div class="{0}-br"><div class="{0}-bc"></div></div></div>';
  2300. Ext.Element.addMethods(function(){
  2301. var INTERNAL = "_internal",
  2302. pxMatch = /(\d+\.?\d+)px/;
  2303. return {
  2304. /**
  2305. * More flexible version of {@link #setStyle} for setting style properties.
  2306. * @param {String/Object/Function} styles A style specification string, e.g. "width:100px", or object in the form {width:"100px"}, or
  2307. * a function which returns such a specification.
  2308. * @return {Ext.Element} this
  2309. */
  2310. applyStyles : function(style){
  2311. Ext.DomHelper.applyStyles(this.dom, style);
  2312. return this;
  2313. },
  2314. /**
  2315. * Returns an object with properties matching the styles requested.
  2316. * For example, el.getStyles('color', 'font-size', 'width') might return
  2317. * {'color': '#FFFFFF', 'font-size': '13px', 'width': '100px'}.
  2318. * @param {String} style1 A style name
  2319. * @param {String} style2 A style name
  2320. * @param {String} etc.
  2321. * @return {Object} The style object
  2322. */
  2323. getStyles : function(){
  2324. var ret = {};
  2325. Ext.each(arguments, function(v) {
  2326. ret[v] = this.getStyle(v);
  2327. },
  2328. this);
  2329. return ret;
  2330. },
  2331. // private ==> used by ext full
  2332. setOverflow : function(v){
  2333. var dom = this.dom;
  2334. if(v=='auto' && Ext.isMac && Ext.isGecko2){ // work around stupid FF 2.0/Mac scroll bar bug
  2335. dom.style.overflow = 'hidden';
  2336. (function(){dom.style.overflow = 'auto';}).defer(1);
  2337. }else{
  2338. dom.style.overflow = v;
  2339. }
  2340. },
  2341. /**
  2342. * <p>Wraps the specified element with a special 9 element markup/CSS block that renders by default as
  2343. * a gray container with a gradient background, rounded corners and a 4-way shadow.</p>
  2344. * <p>This special markup is used throughout Ext when box wrapping elements ({@link Ext.Button},
  2345. * {@link Ext.Panel} when <tt>{@link Ext.Panel#frame frame=true}</tt>, {@link Ext.Window}). The markup
  2346. * is of this form:</p>
  2347. * <pre><code>
  2348. Ext.Element.boxMarkup =
  2349. &#39;&lt;div class="{0}-tl">&lt;div class="{0}-tr">&lt;div class="{0}-tc">&lt;/div>&lt;/div>&lt;/div>
  2350. &lt;div class="{0}-ml">&lt;div class="{0}-mr">&lt;div class="{0}-mc">&lt;/div>&lt;/div>&lt;/div>
  2351. &lt;div class="{0}-bl">&lt;div class="{0}-br">&lt;div class="{0}-bc">&lt;/div>&lt;/div>&lt;/div>&#39;;
  2352. * </code></pre>
  2353. * <p>Example usage:</p>
  2354. * <pre><code>
  2355. // Basic box wrap
  2356. Ext.get("foo").boxWrap();
  2357. // You can also add a custom class and use CSS inheritance rules to customize the box look.
  2358. // 'x-box-blue' is a built-in alternative -- look at the related CSS definitions as an example
  2359. // for how to create a custom box wrap style.
  2360. Ext.get("foo").boxWrap().addClass("x-box-blue");
  2361. * </code></pre>
  2362. * @param {String} class (optional) A base CSS class to apply to the containing wrapper element
  2363. * (defaults to <tt>'x-box'</tt>). Note that there are a number of CSS rules that are dependent on
  2364. * this name to make the overall effect work, so if you supply an alternate base class, make sure you
  2365. * also supply all of the necessary rules.
  2366. * @return {Ext.Element} The outermost wrapping element of the created box structure.
  2367. */
  2368. boxWrap : function(cls){
  2369. cls = cls || 'x-box';
  2370. var el = Ext.get(this.insertHtml("beforeBegin", "<div class='" + cls + "'>" + String.format(Ext.Element.boxMarkup, cls) + "</div>")); //String.format('<div class="{0}">'+Ext.Element.boxMarkup+'</div>', cls)));
  2371. Ext.DomQuery.selectNode('.' + cls + '-mc', el.dom).appendChild(this.dom);
  2372. return el;
  2373. },
  2374. /**
  2375. * Set the size of this Element. If animation is true, both width and height will be animated concurrently.
  2376. * @param {Mixed} width The new width. This may be one of:<div class="mdetail-params"><ul>
  2377. * <li>A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels).</li>
  2378. * <li>A String used to set the CSS width style. Animation may <b>not</b> be used.
  2379. * <li>A size object in the format <code>{width: widthValue, height: heightValue}</code>.</li>
  2380. * </ul></div>
  2381. * @param {Mixed} height The new height. This may be one of:<div class="mdetail-params"><ul>
  2382. * <li>A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels).</li>
  2383. * <li>A String used to set the CSS height style. Animation may <b>not</b> be used.</li>
  2384. * </ul></div>
  2385. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  2386. * @return {Ext.Element} this
  2387. */
  2388. setSize : function(width, height, animate){
  2389. var me = this;
  2390. if(typeof width == 'object'){ // in case of object from getSize()
  2391. height = width.height;
  2392. width = width.width;
  2393. }
  2394. width = me.adjustWidth(width);
  2395. height = me.adjustHeight(height);
  2396. if(!animate || !me.anim){
  2397. me.dom.style.width = me.addUnits(width);
  2398. me.dom.style.height = me.addUnits(height);
  2399. }else{
  2400. me.anim({width: {to: width}, height: {to: height}}, me.preanim(arguments, 2));
  2401. }
  2402. return me;
  2403. },
  2404. /**
  2405. * Returns either the offsetHeight or the height of this element based on CSS height adjusted by padding or borders
  2406. * when needed to simulate offsetHeight when offsets aren't available. This may not work on display:none elements
  2407. * if a height has not been set using CSS.
  2408. * @return {Number}
  2409. */
  2410. getComputedHeight : function(){
  2411. var me = this,
  2412. h = Math.max(me.dom.offsetHeight, me.dom.clientHeight);
  2413. if(!h){
  2414. h = parseFloat(me.getStyle('height')) || 0;
  2415. if(!me.isBorderBox()){
  2416. h += me.getFrameWidth('tb');
  2417. }
  2418. }
  2419. return h;
  2420. },
  2421. /**
  2422. * Returns either the offsetWidth or the width of this element based on CSS width adjusted by padding or borders
  2423. * when needed to simulate offsetWidth when offsets aren't available. This may not work on display:none elements
  2424. * if a width has not been set using CSS.
  2425. * @return {Number}
  2426. */
  2427. getComputedWidth : function(){
  2428. var w = Math.max(this.dom.offsetWidth, this.dom.clientWidth);
  2429. if(!w){
  2430. w = parseFloat(this.getStyle('width')) || 0;
  2431. if(!this.isBorderBox()){
  2432. w += this.getFrameWidth('lr');
  2433. }
  2434. }
  2435. return w;
  2436. },
  2437. /**
  2438. * Returns the sum width of the padding and borders for the passed "sides". See getBorderWidth()
  2439. for more information about the sides.
  2440. * @param {String} sides
  2441. * @return {Number}
  2442. */
  2443. getFrameWidth : function(sides, onlyContentBox){
  2444. return onlyContentBox && this.isBorderBox() ? 0 : (this.getPadding(sides) + this.getBorderWidth(sides));
  2445. },
  2446. /**
  2447. * Sets up event handlers to add and remove a css class when the mouse is over this element
  2448. * @param {String} className
  2449. * @return {Ext.Element} this
  2450. */
  2451. addClassOnOver : function(className){
  2452. this.hover(
  2453. function(){
  2454. Ext.fly(this, INTERNAL).addClass(className);
  2455. },
  2456. function(){
  2457. Ext.fly(this, INTERNAL).removeClass(className);
  2458. }
  2459. );
  2460. return this;
  2461. },
  2462. /**
  2463. * Sets up event handlers to add and remove a css class when this element has the focus
  2464. * @param {String} className
  2465. * @return {Ext.Element} this
  2466. */
  2467. addClassOnFocus : function(className){
  2468. this.on("focus", function(){
  2469. Ext.fly(this, INTERNAL).addClass(className);
  2470. }, this.dom);
  2471. this.on("blur", function(){
  2472. Ext.fly(this, INTERNAL).removeClass(className);
  2473. }, this.dom);
  2474. return this;
  2475. },
  2476. /**
  2477. * Sets up event handlers to add and remove a css class when the mouse is down and then up on this element (a click effect)
  2478. * @param {String} className
  2479. * @return {Ext.Element} this
  2480. */
  2481. addClassOnClick : function(className){
  2482. var dom = this.dom;
  2483. this.on("mousedown", function(){
  2484. Ext.fly(dom, INTERNAL).addClass(className);
  2485. var d = Ext.getDoc(),
  2486. fn = function(){
  2487. Ext.fly(dom, INTERNAL).removeClass(className);
  2488. d.removeListener("mouseup", fn);
  2489. };
  2490. d.on("mouseup", fn);
  2491. });
  2492. return this;
  2493. },
  2494. /**
  2495. * <p>Returns the dimensions of the element available to lay content out in.<p>
  2496. * <p>If the element (or any ancestor element) has CSS style <code>display : none</code>, the dimensions will be zero.</p>
  2497. * example:<pre><code>
  2498. var vpSize = Ext.getBody().getViewSize();
  2499. // all Windows created afterwards will have a default value of 90% height and 95% width
  2500. Ext.Window.override({
  2501. width: vpSize.width * 0.9,
  2502. height: vpSize.height * 0.95
  2503. });
  2504. // To handle window resizing you would have to hook onto onWindowResize.
  2505. * </code></pre>
  2506. *
  2507. * getViewSize utilizes clientHeight/clientWidth which excludes sizing of scrollbars.
  2508. * To obtain the size including scrollbars, use getStyleSize
  2509. *
  2510. * Sizing of the document body is handled at the adapter level which handles special cases for IE and strict modes, etc.
  2511. */
  2512. getViewSize : function(){
  2513. var doc = document,
  2514. d = this.dom,
  2515. isDoc = (d == doc || d == doc.body);
  2516. // If the body, use Ext.lib.Dom
  2517. if (isDoc) {
  2518. var extdom = Ext.lib.Dom;
  2519. return {
  2520. width : extdom.getViewWidth(),
  2521. height : extdom.getViewHeight()
  2522. };
  2523. // Else use clientHeight/clientWidth
  2524. } else {
  2525. return {
  2526. width : d.clientWidth,
  2527. height : d.clientHeight
  2528. };
  2529. }
  2530. },
  2531. /**
  2532. * <p>Returns the dimensions of the element available to lay content out in.<p>
  2533. *
  2534. * getStyleSize utilizes prefers style sizing if present, otherwise it chooses the larger of offsetHeight/clientHeight and offsetWidth/clientWidth.
  2535. * To obtain the size excluding scrollbars, use getViewSize
  2536. *
  2537. * Sizing of the document body is handled at the adapter level which handles special cases for IE and strict modes, etc.
  2538. */
  2539. getStyleSize : function(){
  2540. var me = this,
  2541. w, h,
  2542. doc = document,
  2543. d = this.dom,
  2544. isDoc = (d == doc || d == doc.body),
  2545. s = d.style;
  2546. // If the body, use Ext.lib.Dom
  2547. if (isDoc) {
  2548. var extdom = Ext.lib.Dom;
  2549. return {
  2550. width : extdom.getViewWidth(),
  2551. height : extdom.getViewHeight()
  2552. };
  2553. }
  2554. // Use Styles if they are set
  2555. if(s.width && s.width != 'auto'){
  2556. w = parseFloat(s.width);
  2557. if(me.isBorderBox()){
  2558. w -= me.getFrameWidth('lr');
  2559. }
  2560. }
  2561. // Use Styles if they are set
  2562. if(s.height && s.height != 'auto'){
  2563. h = parseFloat(s.height);
  2564. if(me.isBorderBox()){
  2565. h -= me.getFrameWidth('tb');
  2566. }
  2567. }
  2568. // Use getWidth/getHeight if style not set.
  2569. return {width: w || me.getWidth(true), height: h || me.getHeight(true)};
  2570. },
  2571. /**
  2572. * Returns the size of the element.
  2573. * @param {Boolean} contentSize (optional) true to get the width/size minus borders and padding
  2574. * @return {Object} An object containing the element's size {width: (element width), height: (element height)}
  2575. */
  2576. getSize : function(contentSize){
  2577. return {width: this.getWidth(contentSize), height: this.getHeight(contentSize)};
  2578. },
  2579. /**
  2580. * Forces the browser to repaint this element
  2581. * @return {Ext.Element} this
  2582. */
  2583. repaint : function(){
  2584. var dom = this.dom;
  2585. this.addClass("x-repaint");
  2586. setTimeout(function(){
  2587. Ext.fly(dom).removeClass("x-repaint");
  2588. }, 1);
  2589. return this;
  2590. },
  2591. /**
  2592. * Disables text selection for this element (normalized across browsers)
  2593. * @return {Ext.Element} this
  2594. */
  2595. unselectable : function(){
  2596. this.dom.unselectable = "on";
  2597. return this.swallowEvent("selectstart", true).
  2598. applyStyles("-moz-user-select:none;-khtml-user-select:none;").
  2599. addClass("x-unselectable");
  2600. },
  2601. /**
  2602. * Returns an object with properties top, left, right and bottom representing the margins of this element unless sides is passed,
  2603. * then it returns the calculated width of the sides (see getPadding)
  2604. * @param {String} sides (optional) Any combination of l, r, t, b to get the sum of those sides
  2605. * @return {Object/Number}
  2606. */
  2607. getMargins : function(side){
  2608. var me = this,
  2609. key,
  2610. hash = {t:"top", l:"left", r:"right", b: "bottom"},
  2611. o = {};
  2612. if (!side) {
  2613. for (key in me.margins){
  2614. o[hash[key]] = parseFloat(me.getStyle(me.margins[key])) || 0;
  2615. }
  2616. return o;
  2617. } else {
  2618. return me.addStyles.call(me, side, me.margins);
  2619. }
  2620. }
  2621. };
  2622. }());
  2623. /**
  2624. * @class Ext.Element
  2625. */
  2626. Ext.Element.addMethods({
  2627. /**
  2628. * Sets the element's box. Use getBox() on another element to get a box obj. If animate is true then width, height, x and y will be animated concurrently.
  2629. * @param {Object} box The box to fill {x, y, width, height}
  2630. * @param {Boolean} adjust (optional) Whether to adjust for box-model issues automatically
  2631. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  2632. * @return {Ext.Element} this
  2633. */
  2634. setBox : function(box, adjust, animate){
  2635. var me = this,
  2636. w = box.width,
  2637. h = box.height;
  2638. if((adjust && !me.autoBoxAdjust) && !me.isBorderBox()){
  2639. w -= (me.getBorderWidth("lr") + me.getPadding("lr"));
  2640. h -= (me.getBorderWidth("tb") + me.getPadding("tb"));
  2641. }
  2642. me.setBounds(box.x, box.y, w, h, me.animTest.call(me, arguments, animate, 2));
  2643. return me;
  2644. },
  2645. /**
  2646. * Return an object defining the area of this Element which can be passed to {@link #setBox} to
  2647. * set another Element's size/location to match this element.
  2648. * @param {Boolean} contentBox (optional) If true a box for the content of the element is returned.
  2649. * @param {Boolean} local (optional) If true the element's left and top are returned instead of page x/y.
  2650. * @return {Object} box An object in the format<pre><code>
  2651. {
  2652. x: &lt;Element's X position>,
  2653. y: &lt;Element's Y position>,
  2654. width: &lt;Element's width>,
  2655. height: &lt;Element's height>,
  2656. bottom: &lt;Element's lower bound>,
  2657. right: &lt;Element's rightmost bound>
  2658. }
  2659. </code></pre>
  2660. * The returned object may also be addressed as an Array where index 0 contains the X position
  2661. * and index 1 contains the Y position. So the result may also be used for {@link #setXY}
  2662. */
  2663. getBox : function(contentBox, local) {
  2664. var me = this,
  2665. xy,
  2666. left,
  2667. top,
  2668. getBorderWidth = me.getBorderWidth,
  2669. getPadding = me.getPadding,
  2670. l,
  2671. r,
  2672. t,
  2673. b;
  2674. if(!local){
  2675. xy = me.getXY();
  2676. }else{
  2677. left = parseInt(me.getStyle("left"), 10) || 0;
  2678. top = parseInt(me.getStyle("top"), 10) || 0;
  2679. xy = [left, top];
  2680. }
  2681. var el = me.dom, w = el.offsetWidth, h = el.offsetHeight, bx;
  2682. if(!contentBox){
  2683. bx = {x: xy[0], y: xy[1], 0: xy[0], 1: xy[1], width: w, height: h};
  2684. }else{
  2685. l = getBorderWidth.call(me, "l") + getPadding.call(me, "l");
  2686. r = getBorderWidth.call(me, "r") + getPadding.call(me, "r");
  2687. t = getBorderWidth.call(me, "t") + getPadding.call(me, "t");
  2688. b = getBorderWidth.call(me, "b") + getPadding.call(me, "b");
  2689. bx = {x: xy[0]+l, y: xy[1]+t, 0: xy[0]+l, 1: xy[1]+t, width: w-(l+r), height: h-(t+b)};
  2690. }
  2691. bx.right = bx.x + bx.width;
  2692. bx.bottom = bx.y + bx.height;
  2693. return bx;
  2694. },
  2695. /**
  2696. * Move this element relative to its current position.
  2697. * @param {String} direction Possible values are: "l" (or "left"), "r" (or "right"), "t" (or "top", or "up"), "b" (or "bottom", or "down").
  2698. * @param {Number} distance How far to move the element in pixels
  2699. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  2700. * @return {Ext.Element} this
  2701. */
  2702. move : function(direction, distance, animate){
  2703. var me = this,
  2704. xy = me.getXY(),
  2705. x = xy[0],
  2706. y = xy[1],
  2707. left = [x - distance, y],
  2708. right = [x + distance, y],
  2709. top = [x, y - distance],
  2710. bottom = [x, y + distance],
  2711. hash = {
  2712. l : left,
  2713. left : left,
  2714. r : right,
  2715. right : right,
  2716. t : top,
  2717. top : top,
  2718. up : top,
  2719. b : bottom,
  2720. bottom : bottom,
  2721. down : bottom
  2722. };
  2723. direction = direction.toLowerCase();
  2724. me.moveTo(hash[direction][0], hash[direction][1], me.animTest.call(me, arguments, animate, 2));
  2725. },
  2726. /**
  2727. * Quick set left and top adding default units
  2728. * @param {String} left The left CSS property value
  2729. * @param {String} top The top CSS property value
  2730. * @return {Ext.Element} this
  2731. */
  2732. setLeftTop : function(left, top){
  2733. var me = this,
  2734. style = me.dom.style;
  2735. style.left = me.addUnits(left);
  2736. style.top = me.addUnits(top);
  2737. return me;
  2738. },
  2739. /**
  2740. * Returns the region of the given element.
  2741. * The element must be part of the DOM tree to have a region (display:none or elements not appended return false).
  2742. * @return {Region} A Ext.lib.Region containing "top, left, bottom, right" member data.
  2743. */
  2744. getRegion : function(){
  2745. return Ext.lib.Dom.getRegion(this.dom);
  2746. },
  2747. /**
  2748. * Sets the element's position and size in one shot. If animation is true then width, height, x and y will be animated concurrently.
  2749. * @param {Number} x X value for new position (coordinates are page-based)
  2750. * @param {Number} y Y value for new position (coordinates are page-based)
  2751. * @param {Mixed} width The new width. This may be one of:<div class="mdetail-params"><ul>
  2752. * <li>A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels)</li>
  2753. * <li>A String used to set the CSS width style. Animation may <b>not</b> be used.
  2754. * </ul></div>
  2755. * @param {Mixed} height The new height. This may be one of:<div class="mdetail-params"><ul>
  2756. * <li>A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels)</li>
  2757. * <li>A String used to set the CSS height style. Animation may <b>not</b> be used.</li>
  2758. * </ul></div>
  2759. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  2760. * @return {Ext.Element} this
  2761. */
  2762. setBounds : function(x, y, width, height, animate){
  2763. var me = this;
  2764. if (!animate || !me.anim) {
  2765. me.setSize(width, height);
  2766. me.setLocation(x, y);
  2767. } else {
  2768. me.anim({points: {to: [x, y]},
  2769. width: {to: me.adjustWidth(width)},
  2770. height: {to: me.adjustHeight(height)}},
  2771. me.preanim(arguments, 4),
  2772. 'motion');
  2773. }
  2774. return me;
  2775. },
  2776. /**
  2777. * Sets the element's position and size the specified region. If animation is true then width, height, x and y will be animated concurrently.
  2778. * @param {Ext.lib.Region} region The region to fill
  2779. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  2780. * @return {Ext.Element} this
  2781. */
  2782. setRegion : function(region, animate) {
  2783. return this.setBounds(region.left, region.top, region.right-region.left, region.bottom-region.top, this.animTest.call(this, arguments, animate, 1));
  2784. }
  2785. });/**
  2786. * @class Ext.Element
  2787. */
  2788. Ext.Element.addMethods({
  2789. /**
  2790. * Scrolls this element the specified scroll point. It does NOT do bounds checking so if you scroll to a weird value it will try to do it. For auto bounds checking, use scroll().
  2791. * @param {String} side Either "left" for scrollLeft values or "top" for scrollTop values.
  2792. * @param {Number} value The new scroll value
  2793. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  2794. * @return {Element} this
  2795. */
  2796. scrollTo : function(side, value, animate) {
  2797. //check if we're scrolling top or left
  2798. var top = /top/i.test(side),
  2799. me = this,
  2800. dom = me.dom,
  2801. prop;
  2802. if (!animate || !me.anim) {
  2803. // just setting the value, so grab the direction
  2804. prop = 'scroll' + (top ? 'Top' : 'Left');
  2805. dom[prop] = value;
  2806. }
  2807. else {
  2808. // if scrolling top, we need to grab scrollLeft, if left, scrollTop
  2809. prop = 'scroll' + (top ? 'Left' : 'Top');
  2810. me.anim({scroll: {to: top ? [dom[prop], value] : [value, dom[prop]]}}, me.preanim(arguments, 2), 'scroll');
  2811. }
  2812. return me;
  2813. },
  2814. /**
  2815. * Scrolls this element into view within the passed container.
  2816. * @param {Mixed} container (optional) The container element to scroll (defaults to document.body). Should be a
  2817. * string (id), dom node, or Ext.Element.
  2818. * @param {Boolean} hscroll (optional) False to disable horizontal scroll (defaults to true)
  2819. * @return {Ext.Element} this
  2820. */
  2821. scrollIntoView : function(container, hscroll) {
  2822. var c = Ext.getDom(container) || Ext.getBody().dom,
  2823. el = this.dom,
  2824. o = this.getOffsetsTo(c),
  2825. l = o[0] + c.scrollLeft,
  2826. t = o[1] + c.scrollTop,
  2827. b = t + el.offsetHeight,
  2828. r = l + el.offsetWidth,
  2829. ch = c.clientHeight,
  2830. ct = parseInt(c.scrollTop, 10),
  2831. cl = parseInt(c.scrollLeft, 10),
  2832. cb = ct + ch,
  2833. cr = cl + c.clientWidth;
  2834. if (el.offsetHeight > ch || t < ct) {
  2835. c.scrollTop = t;
  2836. }
  2837. else if (b > cb) {
  2838. c.scrollTop = b-ch;
  2839. }
  2840. // corrects IE, other browsers will ignore
  2841. c.scrollTop = c.scrollTop;
  2842. if (hscroll !== false) {
  2843. if (el.offsetWidth > c.clientWidth || l < cl) {
  2844. c.scrollLeft = l;
  2845. }
  2846. else if (r > cr) {
  2847. c.scrollLeft = r - c.clientWidth;
  2848. }
  2849. c.scrollLeft = c.scrollLeft;
  2850. }
  2851. return this;
  2852. },
  2853. // private
  2854. scrollChildIntoView : function(child, hscroll) {
  2855. Ext.fly(child, '_scrollChildIntoView').scrollIntoView(this, hscroll);
  2856. },
  2857. /**
  2858. * Scrolls this element the specified direction. Does bounds checking to make sure the scroll is
  2859. * within this element's scrollable range.
  2860. * @param {String} direction Possible values are: "l" (or "left"), "r" (or "right"), "t" (or "top", or "up"), "b" (or "bottom", or "down").
  2861. * @param {Number} distance How far to scroll the element in pixels
  2862. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  2863. * @return {Boolean} Returns true if a scroll was triggered or false if the element
  2864. * was scrolled as far as it could go.
  2865. */
  2866. scroll : function(direction, distance, animate) {
  2867. if (!this.isScrollable()) {
  2868. return false;
  2869. }
  2870. var el = this.dom,
  2871. l = el.scrollLeft, t = el.scrollTop,
  2872. w = el.scrollWidth, h = el.scrollHeight,
  2873. cw = el.clientWidth, ch = el.clientHeight,
  2874. scrolled = false, v,
  2875. hash = {
  2876. l: Math.min(l + distance, w-cw),
  2877. r: v = Math.max(l - distance, 0),
  2878. t: Math.max(t - distance, 0),
  2879. b: Math.min(t + distance, h-ch)
  2880. };
  2881. hash.d = hash.b;
  2882. hash.u = hash.t;
  2883. direction = direction.substr(0, 1);
  2884. if ((v = hash[direction]) > -1) {
  2885. scrolled = true;
  2886. this.scrollTo(direction == 'l' || direction == 'r' ? 'left' : 'top', v, this.preanim(arguments, 2));
  2887. }
  2888. return scrolled;
  2889. }
  2890. });/**
  2891. * @class Ext.Element
  2892. */
  2893. Ext.Element.addMethods(
  2894. function() {
  2895. var VISIBILITY = "visibility",
  2896. DISPLAY = "display",
  2897. HIDDEN = "hidden",
  2898. NONE = "none",
  2899. XMASKED = "x-masked",
  2900. XMASKEDRELATIVE = "x-masked-relative",
  2901. data = Ext.Element.data;
  2902. return {
  2903. /**
  2904. * Checks whether the element is currently visible using both visibility and display properties.
  2905. * @param {Boolean} deep (optional) True to walk the dom and see if parent elements are hidden (defaults to false)
  2906. * @return {Boolean} True if the element is currently visible, else false
  2907. */
  2908. isVisible : function(deep) {
  2909. var vis = !this.isStyle(VISIBILITY, HIDDEN) && !this.isStyle(DISPLAY, NONE),
  2910. p = this.dom.parentNode;
  2911. if (deep !== true || !vis) {
  2912. return vis;
  2913. }
  2914. while (p && !(/^body/i.test(p.tagName))) {
  2915. if (!Ext.fly(p, '_isVisible').isVisible()) {
  2916. return false;
  2917. }
  2918. p = p.parentNode;
  2919. }
  2920. return true;
  2921. },
  2922. /**
  2923. * Returns true if display is not "none"
  2924. * @return {Boolean}
  2925. */
  2926. isDisplayed : function() {
  2927. return !this.isStyle(DISPLAY, NONE);
  2928. },
  2929. /**
  2930. * Convenience method for setVisibilityMode(Element.DISPLAY)
  2931. * @param {String} display (optional) What to set display to when visible
  2932. * @return {Ext.Element} this
  2933. */
  2934. enableDisplayMode : function(display) {
  2935. this.setVisibilityMode(Ext.Element.DISPLAY);
  2936. if (!Ext.isEmpty(display)) {
  2937. data(this.dom, 'originalDisplay', display);
  2938. }
  2939. return this;
  2940. },
  2941. /**
  2942. * Puts a mask over this element to disable user interaction. Requires core.css.
  2943. * This method can only be applied to elements which accept child nodes.
  2944. * @param {String} msg (optional) A message to display in the mask
  2945. * @param {String} msgCls (optional) A css class to apply to the msg element
  2946. * @return {Element} The mask element
  2947. */
  2948. mask : function(msg, msgCls) {
  2949. var me = this,
  2950. dom = me.dom,
  2951. dh = Ext.DomHelper,
  2952. EXTELMASKMSG = "ext-el-mask-msg",
  2953. el,
  2954. mask;
  2955. if (!(/^body/i.test(dom.tagName) && me.getStyle('position') == 'static')) {
  2956. me.addClass(XMASKEDRELATIVE);
  2957. }
  2958. if (el = data(dom, 'maskMsg')) {
  2959. el.remove();
  2960. }
  2961. if (el = data(dom, 'mask')) {
  2962. el.remove();
  2963. }
  2964. mask = dh.append(dom, {cls : "ext-el-mask"}, true);
  2965. data(dom, 'mask', mask);
  2966. me.addClass(XMASKED);
  2967. mask.setDisplayed(true);
  2968. if (typeof msg == 'string') {
  2969. var mm = dh.append(dom, {cls : EXTELMASKMSG, cn:{tag:'div'}}, true);
  2970. data(dom, 'maskMsg', mm);
  2971. mm.dom.className = msgCls ? EXTELMASKMSG + " " + msgCls : EXTELMASKMSG;
  2972. mm.dom.firstChild.innerHTML = msg;
  2973. mm.setDisplayed(true);
  2974. mm.center(me);
  2975. }
  2976. // ie will not expand full height automatically
  2977. if (Ext.isIE && !(Ext.isIE7 && Ext.isStrict) && me.getStyle('height') == 'auto') {
  2978. mask.setSize(undefined, me.getHeight());
  2979. }
  2980. return mask;
  2981. },
  2982. /**
  2983. * Removes a previously applied mask.
  2984. */
  2985. unmask : function() {
  2986. var me = this,
  2987. dom = me.dom,
  2988. mask = data(dom, 'mask'),
  2989. maskMsg = data(dom, 'maskMsg');
  2990. if (mask) {
  2991. if (maskMsg) {
  2992. maskMsg.remove();
  2993. data(dom, 'maskMsg', undefined);
  2994. }
  2995. mask.remove();
  2996. data(dom, 'mask', undefined);
  2997. me.removeClass([XMASKED, XMASKEDRELATIVE]);
  2998. }
  2999. },
  3000. /**
  3001. * Returns true if this element is masked
  3002. * @return {Boolean}
  3003. */
  3004. isMasked : function() {
  3005. var m = data(this.dom, 'mask');
  3006. return m && m.isVisible();
  3007. },
  3008. /**
  3009. * Creates an iframe shim for this element to keep selects and other windowed objects from
  3010. * showing through.
  3011. * @return {Ext.Element} The new shim element
  3012. */
  3013. createShim : function() {
  3014. var el = document.createElement('iframe'),
  3015. shim;
  3016. el.frameBorder = '0';
  3017. el.className = 'ext-shim';
  3018. el.src = Ext.SSL_SECURE_URL;
  3019. shim = Ext.get(this.dom.parentNode.insertBefore(el, this.dom));
  3020. shim.autoBoxAdjust = false;
  3021. return shim;
  3022. }
  3023. };
  3024. }()
  3025. );/**
  3026. * @class Ext.Element
  3027. */
  3028. Ext.Element.addMethods({
  3029. /**
  3030. * Convenience method for constructing a KeyMap
  3031. * @param {Number/Array/Object/String} key Either a string with the keys to listen for, the numeric key code, array of key codes or an object with the following options:
  3032. * <code>{key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}</code>
  3033. * @param {Function} fn The function to call
  3034. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the specified function is executed. Defaults to this Element.
  3035. * @return {Ext.KeyMap} The KeyMap created
  3036. */
  3037. addKeyListener : function(key, fn, scope){
  3038. var config;
  3039. if(typeof key != 'object' || Ext.isArray(key)){
  3040. config = {
  3041. key: key,
  3042. fn: fn,
  3043. scope: scope
  3044. };
  3045. }else{
  3046. config = {
  3047. key : key.key,
  3048. shift : key.shift,
  3049. ctrl : key.ctrl,
  3050. alt : key.alt,
  3051. fn: fn,
  3052. scope: scope
  3053. };
  3054. }
  3055. return new Ext.KeyMap(this, config);
  3056. },
  3057. /**
  3058. * Creates a KeyMap for this element
  3059. * @param {Object} config The KeyMap config. See {@link Ext.KeyMap} for more details
  3060. * @return {Ext.KeyMap} The KeyMap created
  3061. */
  3062. addKeyMap : function(config){
  3063. return new Ext.KeyMap(this, config);
  3064. }
  3065. });
  3066. //Import the newly-added Ext.Element functions into CompositeElementLite. We call this here because
  3067. //Element.keys.js is the last extra Ext.Element include in the ext-all.js build
  3068. Ext.CompositeElementLite.importElementMethods();/**
  3069. * @class Ext.CompositeElementLite
  3070. */
  3071. Ext.apply(Ext.CompositeElementLite.prototype, {
  3072. addElements : function(els, root){
  3073. if(!els){
  3074. return this;
  3075. }
  3076. if(typeof els == "string"){
  3077. els = Ext.Element.selectorFunction(els, root);
  3078. }
  3079. var yels = this.elements;
  3080. Ext.each(els, function(e) {
  3081. yels.push(Ext.get(e));
  3082. });
  3083. return this;
  3084. },
  3085. /**
  3086. * Returns the first Element
  3087. * @return {Ext.Element}
  3088. */
  3089. first : function(){
  3090. return this.item(0);
  3091. },
  3092. /**
  3093. * Returns the last Element
  3094. * @return {Ext.Element}
  3095. */
  3096. last : function(){
  3097. return this.item(this.getCount()-1);
  3098. },
  3099. /**
  3100. * Returns true if this composite contains the passed element
  3101. * @param el {Mixed} The id of an element, or an Ext.Element, or an HtmlElement to find within the composite collection.
  3102. * @return Boolean
  3103. */
  3104. contains : function(el){
  3105. return this.indexOf(el) != -1;
  3106. },
  3107. /**
  3108. * Removes the specified element(s).
  3109. * @param {Mixed} el The id of an element, the Element itself, the index of the element in this composite
  3110. * or an array of any of those.
  3111. * @param {Boolean} removeDom (optional) True to also remove the element from the document
  3112. * @return {CompositeElement} this
  3113. */
  3114. removeElement : function(keys, removeDom){
  3115. var me = this,
  3116. els = this.elements,
  3117. el;
  3118. Ext.each(keys, function(val){
  3119. if ((el = (els[val] || els[val = me.indexOf(val)]))) {
  3120. if(removeDom){
  3121. if(el.dom){
  3122. el.remove();
  3123. }else{
  3124. Ext.removeNode(el);
  3125. }
  3126. }
  3127. els.splice(val, 1);
  3128. }
  3129. });
  3130. return this;
  3131. }
  3132. });
  3133. /**
  3134. * @class Ext.CompositeElement
  3135. * @extends Ext.CompositeElementLite
  3136. * <p>This class encapsulates a <i>collection</i> of DOM elements, providing methods to filter
  3137. * members, or to perform collective actions upon the whole set.</p>
  3138. * <p>Although they are not listed, this class supports all of the methods of {@link Ext.Element} and
  3139. * {@link Ext.Fx}. The methods from these classes will be performed on all the elements in this collection.</p>
  3140. * <p>All methods return <i>this</i> and can be chained.</p>
  3141. * Usage:
  3142. <pre><code>
  3143. var els = Ext.select("#some-el div.some-class", true);
  3144. // or select directly from an existing element
  3145. var el = Ext.get('some-el');
  3146. el.select('div.some-class', true);
  3147. els.setWidth(100); // all elements become 100 width
  3148. els.hide(true); // all elements fade out and hide
  3149. // or
  3150. els.setWidth(100).hide(true);
  3151. </code></pre>
  3152. */
  3153. Ext.CompositeElement = Ext.extend(Ext.CompositeElementLite, {
  3154. constructor : function(els, root){
  3155. this.elements = [];
  3156. this.add(els, root);
  3157. },
  3158. // private
  3159. getElement : function(el){
  3160. // In this case just return it, since we already have a reference to it
  3161. return el;
  3162. },
  3163. // private
  3164. transformElement : function(el){
  3165. return Ext.get(el);
  3166. }
  3167. /**
  3168. * Adds elements to this composite.
  3169. * @param {String/Array} els A string CSS selector, an array of elements or an element
  3170. * @return {CompositeElement} this
  3171. */
  3172. /**
  3173. * Returns the Element object at the specified index
  3174. * @param {Number} index
  3175. * @return {Ext.Element}
  3176. */
  3177. /**
  3178. * Iterates each <code>element</code> in this <code>composite</code>
  3179. * calling the supplied function using {@link Ext#each}.
  3180. * @param {Function} fn The function to be called with each
  3181. * <code>element</code>. If the supplied function returns <tt>false</tt>,
  3182. * iteration stops. This function is called with the following arguments:
  3183. * <div class="mdetail-params"><ul>
  3184. * <li><code>element</code> : <i>Ext.Element</i><div class="sub-desc">The element at the current <code>index</code>
  3185. * in the <code>composite</code></div></li>
  3186. * <li><code>composite</code> : <i>Object</i> <div class="sub-desc">This composite.</div></li>
  3187. * <li><code>index</code> : <i>Number</i> <div class="sub-desc">The current index within the <code>composite</code> </div></li>
  3188. * </ul></div>
  3189. * @param {Object} scope (optional) The scope (<code><this</code> reference) in which the specified function is executed.
  3190. * Defaults to the <code>element</code> at the current <code>index</code>
  3191. * within the composite.
  3192. * @return {CompositeElement} this
  3193. */
  3194. });
  3195. /**
  3196. * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
  3197. * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
  3198. * {@link Ext.CompositeElementLite CompositeElementLite} object.
  3199. * @param {String/Array} selector The CSS selector or an array of elements
  3200. * @param {Boolean} unique (optional) true to create a unique Ext.Element for each element (defaults to a shared flyweight object)
  3201. * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
  3202. * @return {CompositeElementLite/CompositeElement}
  3203. * @member Ext.Element
  3204. * @method select
  3205. */
  3206. Ext.Element.select = function(selector, unique, root){
  3207. var els;
  3208. if(typeof selector == "string"){
  3209. els = Ext.Element.selectorFunction(selector, root);
  3210. }else if(selector.length !== undefined){
  3211. els = selector;
  3212. }else{
  3213. throw "Invalid selector";
  3214. }
  3215. return (unique === true) ? new Ext.CompositeElement(els) : new Ext.CompositeElementLite(els);
  3216. };
  3217. /**
  3218. * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
  3219. * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
  3220. * {@link Ext.CompositeElementLite CompositeElementLite} object.
  3221. * @param {String/Array} selector The CSS selector or an array of elements
  3222. * @param {Boolean} unique (optional) true to create a unique Ext.Element for each element (defaults to a shared flyweight object)
  3223. * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
  3224. * @return {CompositeElementLite/CompositeElement}
  3225. * @member Ext
  3226. * @method select
  3227. */
  3228. Ext.select = Ext.Element.select;/**
  3229. * @class Ext.Updater
  3230. * @extends Ext.util.Observable
  3231. * Provides AJAX-style update capabilities for Element objects. Updater can be used to {@link #update}
  3232. * an {@link Ext.Element} once, or you can use {@link #startAutoRefresh} to set up an auto-updating
  3233. * {@link Ext.Element Element} on a specific interval.<br><br>
  3234. * Usage:<br>
  3235. * <pre><code>
  3236. * var el = Ext.get("foo"); // Get Ext.Element object
  3237. * var mgr = el.getUpdater();
  3238. * mgr.update({
  3239. url: "http://myserver.com/index.php",
  3240. params: {
  3241. param1: "foo",
  3242. param2: "bar"
  3243. }
  3244. * });
  3245. * ...
  3246. * mgr.formUpdate("myFormId", "http://myserver.com/index.php");
  3247. * <br>
  3248. * // or directly (returns the same Updater instance)
  3249. * var mgr = new Ext.Updater("myElementId");
  3250. * mgr.startAutoRefresh(60, "http://myserver.com/index.php");
  3251. * mgr.on("update", myFcnNeedsToKnow);
  3252. * <br>
  3253. * // short handed call directly from the element object
  3254. * Ext.get("foo").load({
  3255. url: "bar.php",
  3256. scripts: true,
  3257. params: "param1=foo&amp;param2=bar",
  3258. text: "Loading Foo..."
  3259. * });
  3260. * </code></pre>
  3261. * @constructor
  3262. * Create new Updater directly.
  3263. * @param {Mixed} el The element to update
  3264. * @param {Boolean} forceNew (optional) By default the constructor checks to see if the passed element already
  3265. * has an Updater and if it does it returns the same instance. This will skip that check (useful for extending this class).
  3266. */
  3267. Ext.UpdateManager = Ext.Updater = Ext.extend(Ext.util.Observable,
  3268. function() {
  3269. var BEFOREUPDATE = "beforeupdate",
  3270. UPDATE = "update",
  3271. FAILURE = "failure";
  3272. // private
  3273. function processSuccess(response){
  3274. var me = this;
  3275. me.transaction = null;
  3276. if (response.argument.form && response.argument.reset) {
  3277. try { // put in try/catch since some older FF releases had problems with this
  3278. response.argument.form.reset();
  3279. } catch(e){}
  3280. }
  3281. if (me.loadScripts) {
  3282. me.renderer.render(me.el, response, me,
  3283. updateComplete.createDelegate(me, [response]));
  3284. } else {
  3285. me.renderer.render(me.el, response, me);
  3286. updateComplete.call(me, response);
  3287. }
  3288. }
  3289. // private
  3290. function updateComplete(response, type, success){
  3291. this.fireEvent(type || UPDATE, this.el, response);
  3292. if(Ext.isFunction(response.argument.callback)){
  3293. response.argument.callback.call(response.argument.scope, this.el, Ext.isEmpty(success) ? true : false, response, response.argument.options);
  3294. }
  3295. }
  3296. // private
  3297. function processFailure(response){
  3298. updateComplete.call(this, response, FAILURE, !!(this.transaction = null));
  3299. }
  3300. return {
  3301. constructor: function(el, forceNew){
  3302. var me = this;
  3303. el = Ext.get(el);
  3304. if(!forceNew && el.updateManager){
  3305. return el.updateManager;
  3306. }
  3307. /**
  3308. * The Element object
  3309. * @type Ext.Element
  3310. */
  3311. me.el = el;
  3312. /**
  3313. * Cached url to use for refreshes. Overwritten every time update() is called unless "discardUrl" param is set to true.
  3314. * @type String
  3315. */
  3316. me.defaultUrl = null;
  3317. me.addEvents(
  3318. /**
  3319. * @event beforeupdate
  3320. * Fired before an update is made, return false from your handler and the update is cancelled.
  3321. * @param {Ext.Element} el
  3322. * @param {String/Object/Function} url
  3323. * @param {String/Object} params
  3324. */
  3325. BEFOREUPDATE,
  3326. /**
  3327. * @event update
  3328. * Fired after successful update is made.
  3329. * @param {Ext.Element} el
  3330. * @param {Object} oResponseObject The response Object
  3331. */
  3332. UPDATE,
  3333. /**
  3334. * @event failure
  3335. * Fired on update failure.
  3336. * @param {Ext.Element} el
  3337. * @param {Object} oResponseObject The response Object
  3338. */
  3339. FAILURE
  3340. );
  3341. Ext.apply(me, Ext.Updater.defaults);
  3342. /**
  3343. * Blank page URL to use with SSL file uploads (defaults to {@link Ext.Updater.defaults#sslBlankUrl}).
  3344. * @property sslBlankUrl
  3345. * @type String
  3346. */
  3347. /**
  3348. * Whether to append unique parameter on get request to disable caching (defaults to {@link Ext.Updater.defaults#disableCaching}).
  3349. * @property disableCaching
  3350. * @type Boolean
  3351. */
  3352. /**
  3353. * Text for loading indicator (defaults to {@link Ext.Updater.defaults#indicatorText}).
  3354. * @property indicatorText
  3355. * @type String
  3356. */
  3357. /**
  3358. * Whether to show indicatorText when loading (defaults to {@link Ext.Updater.defaults#showLoadIndicator}).
  3359. * @property showLoadIndicator
  3360. * @type String
  3361. */
  3362. /**
  3363. * Timeout for requests or form posts in seconds (defaults to {@link Ext.Updater.defaults#timeout}).
  3364. * @property timeout
  3365. * @type Number
  3366. */
  3367. /**
  3368. * True to process scripts in the output (defaults to {@link Ext.Updater.defaults#loadScripts}).
  3369. * @property loadScripts
  3370. * @type Boolean
  3371. */
  3372. /**
  3373. * Transaction object of the current executing transaction, or null if there is no active transaction.
  3374. */
  3375. me.transaction = null;
  3376. /**
  3377. * Delegate for refresh() prebound to "this", use myUpdater.refreshDelegate.createCallback(arg1, arg2) to bind arguments
  3378. * @type Function
  3379. */
  3380. me.refreshDelegate = me.refresh.createDelegate(me);
  3381. /**
  3382. * Delegate for update() prebound to "this", use myUpdater.updateDelegate.createCallback(arg1, arg2) to bind arguments
  3383. * @type Function
  3384. */
  3385. me.updateDelegate = me.update.createDelegate(me);
  3386. /**
  3387. * Delegate for formUpdate() prebound to "this", use myUpdater.formUpdateDelegate.createCallback(arg1, arg2) to bind arguments
  3388. * @type Function
  3389. */
  3390. me.formUpdateDelegate = (me.formUpdate || function(){}).createDelegate(me);
  3391. /**
  3392. * The renderer for this Updater (defaults to {@link Ext.Updater.BasicRenderer}).
  3393. */
  3394. me.renderer = me.renderer || me.getDefaultRenderer();
  3395. Ext.Updater.superclass.constructor.call(me);
  3396. },
  3397. /**
  3398. * Sets the content renderer for this Updater. See {@link Ext.Updater.BasicRenderer#render} for more details.
  3399. * @param {Object} renderer The object implementing the render() method
  3400. */
  3401. setRenderer : function(renderer){
  3402. this.renderer = renderer;
  3403. },
  3404. /**
  3405. * Returns the current content renderer for this Updater. See {@link Ext.Updater.BasicRenderer#render} for more details.
  3406. * @return {Object}
  3407. */
  3408. getRenderer : function(){
  3409. return this.renderer;
  3410. },
  3411. /**
  3412. * This is an overrideable method which returns a reference to a default
  3413. * renderer class if none is specified when creating the Ext.Updater.
  3414. * Defaults to {@link Ext.Updater.BasicRenderer}
  3415. */
  3416. getDefaultRenderer: function() {
  3417. return new Ext.Updater.BasicRenderer();
  3418. },
  3419. /**
  3420. * Sets the default URL used for updates.
  3421. * @param {String/Function} defaultUrl The url or a function to call to get the url
  3422. */
  3423. setDefaultUrl : function(defaultUrl){
  3424. this.defaultUrl = defaultUrl;
  3425. },
  3426. /**
  3427. * Get the Element this Updater is bound to
  3428. * @return {Ext.Element} The element
  3429. */
  3430. getEl : function(){
  3431. return this.el;
  3432. },
  3433. /**
  3434. * Performs an <b>asynchronous</b> request, updating this element with the response.
  3435. * If params are specified it uses POST, otherwise it uses GET.<br><br>
  3436. * <b>Note:</b> Due to the asynchronous nature of remote server requests, the Element
  3437. * will not have been fully updated when the function returns. To post-process the returned
  3438. * data, use the callback option, or an <b><code>update</code></b> event handler.
  3439. * @param {Object} options A config object containing any of the following options:<ul>
  3440. * <li>url : <b>String/Function</b><p class="sub-desc">The URL to request or a function which
  3441. * <i>returns</i> the URL (defaults to the value of {@link Ext.Ajax#url} if not specified).</p></li>
  3442. * <li>method : <b>String</b><p class="sub-desc">The HTTP method to
  3443. * use. Defaults to POST if the <code>params</code> argument is present, otherwise GET.</p></li>
  3444. * <li>params : <b>String/Object/Function</b><p class="sub-desc">The
  3445. * parameters to pass to the server (defaults to none). These may be specified as a url-encoded
  3446. * string, or as an object containing properties which represent parameters,
  3447. * or as a function, which returns such an object.</p></li>
  3448. * <li>scripts : <b>Boolean</b><p class="sub-desc">If <code>true</code>
  3449. * any &lt;script&gt; tags embedded in the response text will be extracted
  3450. * and executed (defaults to {@link Ext.Updater.defaults#loadScripts}). If this option is specified,
  3451. * the callback will be called <i>after</i> the execution of the scripts.</p></li>
  3452. * <li>callback : <b>Function</b><p class="sub-desc">A function to
  3453. * be called when the response from the server arrives. The following
  3454. * parameters are passed:<ul>
  3455. * <li><b>el</b> : Ext.Element<p class="sub-desc">The Element being updated.</p></li>
  3456. * <li><b>success</b> : Boolean<p class="sub-desc">True for success, false for failure.</p></li>
  3457. * <li><b>response</b> : XMLHttpRequest<p class="sub-desc">The XMLHttpRequest which processed the update.</p></li>
  3458. * <li><b>options</b> : Object<p class="sub-desc">The config object passed to the update call.</p></li></ul>
  3459. * </p></li>
  3460. * <li>scope : <b>Object</b><p class="sub-desc">The scope in which
  3461. * to execute the callback (The callback's <code>this</code> reference.) If the
  3462. * <code>params</code> argument is a function, this scope is used for that function also.</p></li>
  3463. * <li>discardUrl : <b>Boolean</b><p class="sub-desc">By default, the URL of this request becomes
  3464. * the default URL for this Updater object, and will be subsequently used in {@link #refresh}
  3465. * calls. To bypass this behavior, pass <code>discardUrl:true</code> (defaults to false).</p></li>
  3466. * <li>timeout : <b>Number</b><p class="sub-desc">The number of seconds to wait for a response before
  3467. * timing out (defaults to {@link Ext.Updater.defaults#timeout}).</p></li>
  3468. * <li>text : <b>String</b><p class="sub-desc">The text to use as the innerHTML of the
  3469. * {@link Ext.Updater.defaults#indicatorText} div (defaults to 'Loading...'). To replace the entire div, not
  3470. * just the text, override {@link Ext.Updater.defaults#indicatorText} directly.</p></li>
  3471. * <li>nocache : <b>Boolean</b><p class="sub-desc">Only needed for GET
  3472. * requests, this option causes an extra, auto-generated parameter to be appended to the request
  3473. * to defeat caching (defaults to {@link Ext.Updater.defaults#disableCaching}).</p></li></ul>
  3474. * <p>
  3475. * For example:
  3476. <pre><code>
  3477. um.update({
  3478. url: "your-url.php",
  3479. params: {param1: "foo", param2: "bar"}, // or a URL encoded string
  3480. callback: yourFunction,
  3481. scope: yourObject, //(optional scope)
  3482. discardUrl: true,
  3483. nocache: true,
  3484. text: "Loading...",
  3485. timeout: 60,
  3486. scripts: false // Save time by avoiding RegExp execution.
  3487. });
  3488. </code></pre>
  3489. */
  3490. update : function(url, params, callback, discardUrl){
  3491. var me = this,
  3492. cfg,
  3493. callerScope;
  3494. if(me.fireEvent(BEFOREUPDATE, me.el, url, params) !== false){
  3495. if(Ext.isObject(url)){ // must be config object
  3496. cfg = url;
  3497. url = cfg.url;
  3498. params = params || cfg.params;
  3499. callback = callback || cfg.callback;
  3500. discardUrl = discardUrl || cfg.discardUrl;
  3501. callerScope = cfg.scope;
  3502. if(!Ext.isEmpty(cfg.nocache)){me.disableCaching = cfg.nocache;};
  3503. if(!Ext.isEmpty(cfg.text)){me.indicatorText = '<div class="loading-indicator">'+cfg.text+"</div>";};
  3504. if(!Ext.isEmpty(cfg.scripts)){me.loadScripts = cfg.scripts;};
  3505. if(!Ext.isEmpty(cfg.timeout)){me.timeout = cfg.timeout;};
  3506. }
  3507. me.showLoading();
  3508. if(!discardUrl){
  3509. me.defaultUrl = url;
  3510. }
  3511. if(Ext.isFunction(url)){
  3512. url = url.call(me);
  3513. }
  3514. var o = Ext.apply({}, {
  3515. url : url,
  3516. params: (Ext.isFunction(params) && callerScope) ? params.createDelegate(callerScope) : params,
  3517. success: processSuccess,
  3518. failure: processFailure,
  3519. scope: me,
  3520. callback: undefined,
  3521. timeout: (me.timeout*1000),
  3522. disableCaching: me.disableCaching,
  3523. argument: {
  3524. "options": cfg,
  3525. "url": url,
  3526. "form": null,
  3527. "callback": callback,
  3528. "scope": callerScope || window,
  3529. "params": params
  3530. }
  3531. }, cfg);
  3532. me.transaction = Ext.Ajax.request(o);
  3533. }
  3534. },
  3535. /**
  3536. * <p>Performs an asynchronous form post, updating this element with the response. If the form has the attribute
  3537. * enctype="<a href="http://www.faqs.org/rfcs/rfc2388.html">multipart/form-data</a>", it assumes it's a file upload.
  3538. * Uses this.sslBlankUrl for SSL file uploads to prevent IE security warning.</p>
  3539. * <p>File uploads are not performed using normal "Ajax" techniques, that is they are <b>not</b>
  3540. * performed using XMLHttpRequests. Instead the form is submitted in the standard manner with the
  3541. * DOM <code>&lt;form></code> element temporarily modified to have its
  3542. * <a href="http://www.w3.org/TR/REC-html40/present/frames.html#adef-target">target</a> set to refer
  3543. * to a dynamically generated, hidden <code>&lt;iframe></code> which is inserted into the document
  3544. * but removed after the return data has been gathered.</p>
  3545. * <p>Be aware that file upload packets, sent with the content type <a href="http://www.faqs.org/rfcs/rfc2388.html">multipart/form-data</a>
  3546. * and some server technologies (notably JEE) may require some custom processing in order to
  3547. * retrieve parameter names and parameter values from the packet content.</p>
  3548. * @param {String/HTMLElement} form The form Id or form element
  3549. * @param {String} url (optional) The url to pass the form to. If omitted the action attribute on the form will be used.
  3550. * @param {Boolean} reset (optional) Whether to try to reset the form after the update
  3551. * @param {Function} callback (optional) Callback when transaction is complete. The following
  3552. * parameters are passed:<ul>
  3553. * <li><b>el</b> : Ext.Element<p class="sub-desc">The Element being updated.</p></li>
  3554. * <li><b>success</b> : Boolean<p class="sub-desc">True for success, false for failure.</p></li>
  3555. * <li><b>response</b> : XMLHttpRequest<p class="sub-desc">The XMLHttpRequest which processed the update.</p></li></ul>
  3556. */
  3557. formUpdate : function(form, url, reset, callback){
  3558. var me = this;
  3559. if(me.fireEvent(BEFOREUPDATE, me.el, form, url) !== false){
  3560. if(Ext.isFunction(url)){
  3561. url = url.call(me);
  3562. }
  3563. form = Ext.getDom(form);
  3564. me.transaction = Ext.Ajax.request({
  3565. form: form,
  3566. url:url,
  3567. success: processSuccess,
  3568. failure: processFailure,
  3569. scope: me,
  3570. timeout: (me.timeout*1000),
  3571. argument: {
  3572. "url": url,
  3573. "form": form,
  3574. "callback": callback,
  3575. "reset": reset
  3576. }
  3577. });
  3578. me.showLoading.defer(1, me);
  3579. }
  3580. },
  3581. /**
  3582. * Set this element to auto refresh. Can be canceled by calling {@link #stopAutoRefresh}.
  3583. * @param {Number} interval How often to update (in seconds).
  3584. * @param {String/Object/Function} url (optional) The url for this request, a config object in the same format
  3585. * supported by {@link #load}, or a function to call to get the url (defaults to the last used url). Note that while
  3586. * the url used in a load call can be reused by this method, other load config options will not be reused and must be
  3587. * sepcified as part of a config object passed as this paramter if needed.
  3588. * @param {String/Object} params (optional) The parameters to pass as either a url encoded string
  3589. * "&param1=1&param2=2" or as an object {param1: 1, param2: 2}
  3590. * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
  3591. * @param {Boolean} refreshNow (optional) Whether to execute the refresh now, or wait the interval
  3592. */
  3593. startAutoRefresh : function(interval, url, params, callback, refreshNow){
  3594. var me = this;
  3595. if(refreshNow){
  3596. me.update(url || me.defaultUrl, params, callback, true);
  3597. }
  3598. if(me.autoRefreshProcId){
  3599. clearInterval(me.autoRefreshProcId);
  3600. }
  3601. me.autoRefreshProcId = setInterval(me.update.createDelegate(me, [url || me.defaultUrl, params, callback, true]), interval * 1000);
  3602. },
  3603. /**
  3604. * Stop auto refresh on this element.
  3605. */
  3606. stopAutoRefresh : function(){
  3607. if(this.autoRefreshProcId){
  3608. clearInterval(this.autoRefreshProcId);
  3609. delete this.autoRefreshProcId;
  3610. }
  3611. },
  3612. /**
  3613. * Returns true if the Updater is currently set to auto refresh its content (see {@link #startAutoRefresh}), otherwise false.
  3614. */
  3615. isAutoRefreshing : function(){
  3616. return !!this.autoRefreshProcId;
  3617. },
  3618. /**
  3619. * Display the element's "loading" state. By default, the element is updated with {@link #indicatorText}. This
  3620. * method may be overridden to perform a custom action while this Updater is actively updating its contents.
  3621. */
  3622. showLoading : function(){
  3623. if(this.showLoadIndicator){
  3624. this.el.dom.innerHTML = this.indicatorText;
  3625. }
  3626. },
  3627. /**
  3628. * Aborts the currently executing transaction, if any.
  3629. */
  3630. abort : function(){
  3631. if(this.transaction){
  3632. Ext.Ajax.abort(this.transaction);
  3633. }
  3634. },
  3635. /**
  3636. * Returns true if an update is in progress, otherwise false.
  3637. * @return {Boolean}
  3638. */
  3639. isUpdating : function(){
  3640. return this.transaction ? Ext.Ajax.isLoading(this.transaction) : false;
  3641. },
  3642. /**
  3643. * Refresh the element with the last used url or defaultUrl. If there is no url, it returns immediately
  3644. * @param {Function} callback (optional) Callback when transaction is complete - called with signature (oElement, bSuccess)
  3645. */
  3646. refresh : function(callback){
  3647. if(this.defaultUrl){
  3648. this.update(this.defaultUrl, null, callback, true);
  3649. }
  3650. }
  3651. };
  3652. }());
  3653. /**
  3654. * @class Ext.Updater.defaults
  3655. * The defaults collection enables customizing the default properties of Updater
  3656. */
  3657. Ext.Updater.defaults = {
  3658. /**
  3659. * Timeout for requests or form posts in seconds (defaults to 30 seconds).
  3660. * @type Number
  3661. */
  3662. timeout : 30,
  3663. /**
  3664. * True to append a unique parameter to GET requests to disable caching (defaults to false).
  3665. * @type Boolean
  3666. */
  3667. disableCaching : false,
  3668. /**
  3669. * Whether or not to show {@link #indicatorText} during loading (defaults to true).
  3670. * @type Boolean
  3671. */
  3672. showLoadIndicator : true,
  3673. /**
  3674. * Text for loading indicator (defaults to '&lt;div class="loading-indicator"&gt;Loading...&lt;/div&gt;').
  3675. * @type String
  3676. */
  3677. indicatorText : '<div class="loading-indicator">Loading...</div>',
  3678. /**
  3679. * True to process scripts by default (defaults to false).
  3680. * @type Boolean
  3681. */
  3682. loadScripts : false,
  3683. /**
  3684. * Blank page URL to use with SSL file uploads (defaults to {@link Ext#SSL_SECURE_URL} if set, or "javascript:false").
  3685. * @type String
  3686. */
  3687. sslBlankUrl : Ext.SSL_SECURE_URL
  3688. };
  3689. /**
  3690. * Static convenience method. <b>This method is deprecated in favor of el.load({url:'foo.php', ...})</b>.
  3691. * Usage:
  3692. * <pre><code>Ext.Updater.updateElement("my-div", "stuff.php");</code></pre>
  3693. * @param {Mixed} el The element to update
  3694. * @param {String} url The url
  3695. * @param {String/Object} params (optional) Url encoded param string or an object of name/value pairs
  3696. * @param {Object} options (optional) A config object with any of the Updater properties you want to set - for
  3697. * example: {disableCaching:true, indicatorText: "Loading data..."}
  3698. * @static
  3699. * @deprecated
  3700. * @member Ext.Updater
  3701. */
  3702. Ext.Updater.updateElement = function(el, url, params, options){
  3703. var um = Ext.get(el).getUpdater();
  3704. Ext.apply(um, options);
  3705. um.update(url, params, options ? options.callback : null);
  3706. };
  3707. /**
  3708. * @class Ext.Updater.BasicRenderer
  3709. * <p>This class is a base class implementing a simple render method which updates an element using results from an Ajax request.</p>
  3710. * <p>The BasicRenderer updates the element's innerHTML with the responseText. To perform a custom render (i.e. XML or JSON processing),
  3711. * create an object with a conforming {@link #render} method and pass it to setRenderer on the Updater.</p>
  3712. */
  3713. Ext.Updater.BasicRenderer = function(){};
  3714. Ext.Updater.BasicRenderer.prototype = {
  3715. /**
  3716. * This method is called when an Ajax response is received, and an Element needs updating.
  3717. * @param {Ext.Element} el The element being rendered
  3718. * @param {Object} xhr The XMLHttpRequest object
  3719. * @param {Updater} updateManager The calling update manager
  3720. * @param {Function} callback A callback that will need to be called if loadScripts is true on the Updater
  3721. */
  3722. render : function(el, response, updateManager, callback){
  3723. el.update(response.responseText, updateManager.loadScripts, callback);
  3724. }
  3725. };/**
  3726. * @class Date
  3727. *
  3728. * The date parsing and formatting syntax contains a subset of
  3729. * <a href="http://www.php.net/date">PHP's date() function</a>, and the formats that are
  3730. * supported will provide results equivalent to their PHP versions.
  3731. *
  3732. * The following is a list of all currently supported formats:
  3733. * <pre>
  3734. Format Description Example returned values
  3735. ------ ----------------------------------------------------------------------- -----------------------
  3736. d Day of the month, 2 digits with leading zeros 01 to 31
  3737. D A short textual representation of the day of the week Mon to Sun
  3738. j Day of the month without leading zeros 1 to 31
  3739. l A full textual representation of the day of the week Sunday to Saturday
  3740. N ISO-8601 numeric representation of the day of the week 1 (for Monday) through 7 (for Sunday)
  3741. S English ordinal suffix for the day of the month, 2 characters st, nd, rd or th. Works well with j
  3742. w Numeric representation of the day of the week 0 (for Sunday) to 6 (for Saturday)
  3743. z The day of the year (starting from 0) 0 to 364 (365 in leap years)
  3744. W ISO-8601 week number of year, weeks starting on Monday 01 to 53
  3745. F A full textual representation of a month, such as January or March January to December
  3746. m Numeric representation of a month, with leading zeros 01 to 12
  3747. M A short textual representation of a month Jan to Dec
  3748. n Numeric representation of a month, without leading zeros 1 to 12
  3749. t Number of days in the given month 28 to 31
  3750. L Whether it's a leap year 1 if it is a leap year, 0 otherwise.
  3751. o ISO-8601 year number (identical to (Y), but if the ISO week number (W) Examples: 1998 or 2004
  3752. belongs to the previous or next year, that year is used instead)
  3753. Y A full numeric representation of a year, 4 digits Examples: 1999 or 2003
  3754. y A two digit representation of a year Examples: 99 or 03
  3755. a Lowercase Ante meridiem and Post meridiem am or pm
  3756. A Uppercase Ante meridiem and Post meridiem AM or PM
  3757. g 12-hour format of an hour without leading zeros 1 to 12
  3758. G 24-hour format of an hour without leading zeros 0 to 23
  3759. h 12-hour format of an hour with leading zeros 01 to 12
  3760. H 24-hour format of an hour with leading zeros 00 to 23
  3761. i Minutes, with leading zeros 00 to 59
  3762. s Seconds, with leading zeros 00 to 59
  3763. u Decimal fraction of a second Examples:
  3764. (minimum 1 digit, arbitrary number of digits allowed) 001 (i.e. 0.001s) or
  3765. 100 (i.e. 0.100s) or
  3766. 999 (i.e. 0.999s) or
  3767. 999876543210 (i.e. 0.999876543210s)
  3768. O Difference to Greenwich time (GMT) in hours and minutes Example: +1030
  3769. P Difference to Greenwich time (GMT) with colon between hours and minutes Example: -08:00
  3770. T Timezone abbreviation of the machine running the code Examples: EST, MDT, PDT ...
  3771. Z Timezone offset in seconds (negative if west of UTC, positive if east) -43200 to 50400
  3772. c ISO 8601 date
  3773. Notes: Examples:
  3774. 1) If unspecified, the month / day defaults to the current month / day, 1991 or
  3775. the time defaults to midnight, while the timezone defaults to the 1992-10 or
  3776. browser's timezone. If a time is specified, it must include both hours 1993-09-20 or
  3777. and minutes. The "T" delimiter, seconds, milliseconds and timezone 1994-08-19T16:20+01:00 or
  3778. are optional. 1995-07-18T17:21:28-02:00 or
  3779. 2) The decimal fraction of a second, if specified, must contain at 1996-06-17T18:22:29.98765+03:00 or
  3780. least 1 digit (there is no limit to the maximum number 1997-05-16T19:23:30,12345-0400 or
  3781. of digits allowed), and may be delimited by either a '.' or a ',' 1998-04-15T20:24:31.2468Z or
  3782. Refer to the examples on the right for the various levels of 1999-03-14T20:24:32Z or
  3783. date-time granularity which are supported, or see 2000-02-13T21:25:33
  3784. http://www.w3.org/TR/NOTE-datetime for more info. 2001-01-12 22:26:34
  3785. U Seconds since the Unix Epoch (January 1 1970 00:00:00 GMT) 1193432466 or -2138434463
  3786. M$ Microsoft AJAX serialized dates \/Date(1238606590509)\/ (i.e. UTC milliseconds since epoch) or
  3787. \/Date(1238606590509+0800)\/
  3788. </pre>
  3789. *
  3790. * Example usage (note that you must escape format specifiers with '\\' to render them as character literals):
  3791. * <pre><code>
  3792. // Sample date:
  3793. // 'Wed Jan 10 2007 15:05:01 GMT-0600 (Central Standard Time)'
  3794. var dt = new Date('1/10/2007 03:05:01 PM GMT-0600');
  3795. document.write(dt.format('Y-m-d')); // 2007-01-10
  3796. document.write(dt.format('F j, Y, g:i a')); // January 10, 2007, 3:05 pm
  3797. document.write(dt.format('l, \\t\\he jS \\of F Y h:i:s A')); // Wednesday, the 10th of January 2007 03:05:01 PM
  3798. </code></pre>
  3799. *
  3800. * Here are some standard date/time patterns that you might find helpful. They
  3801. * are not part of the source of Date.js, but to use them you can simply copy this
  3802. * block of code into any script that is included after Date.js and they will also become
  3803. * globally available on the Date object. Feel free to add or remove patterns as needed in your code.
  3804. * <pre><code>
  3805. Date.patterns = {
  3806. ISO8601Long:"Y-m-d H:i:s",
  3807. ISO8601Short:"Y-m-d",
  3808. ShortDate: "n/j/Y",
  3809. LongDate: "l, F d, Y",
  3810. FullDateTime: "l, F d, Y g:i:s A",
  3811. MonthDay: "F d",
  3812. ShortTime: "g:i A",
  3813. LongTime: "g:i:s A",
  3814. SortableDateTime: "Y-m-d\\TH:i:s",
  3815. UniversalSortableDateTime: "Y-m-d H:i:sO",
  3816. YearMonth: "F, Y"
  3817. };
  3818. </code></pre>
  3819. *
  3820. * Example usage:
  3821. * <pre><code>
  3822. var dt = new Date();
  3823. document.write(dt.format(Date.patterns.ShortDate));
  3824. </code></pre>
  3825. * <p>Developer-written, custom formats may be used by supplying both a formatting and a parsing function
  3826. * which perform to specialized requirements. The functions are stored in {@link #parseFunctions} and {@link #formatFunctions}.</p>
  3827. */
  3828. /*
  3829. * Most of the date-formatting functions below are the excellent work of Baron Schwartz.
  3830. * (see http://www.xaprb.com/blog/2005/12/12/javascript-closures-for-runtime-efficiency/)
  3831. * They generate precompiled functions from format patterns instead of parsing and
  3832. * processing each pattern every time a date is formatted. These functions are available
  3833. * on every Date object.
  3834. */
  3835. (function() {
  3836. /**
  3837. * Global flag which determines if strict date parsing should be used.
  3838. * Strict date parsing will not roll-over invalid dates, which is the
  3839. * default behaviour of javascript Date objects.
  3840. * (see {@link #parseDate} for more information)
  3841. * Defaults to <tt>false</tt>.
  3842. * @static
  3843. * @type Boolean
  3844. */
  3845. Date.useStrict = false;
  3846. // create private copy of Ext's String.format() method
  3847. // - to remove unnecessary dependency
  3848. // - to resolve namespace conflict with M$-Ajax's implementation
  3849. function xf(format) {
  3850. var args = Array.prototype.slice.call(arguments, 1);
  3851. return format.replace(/\{(\d+)\}/g, function(m, i) {
  3852. return args[i];
  3853. });
  3854. }
  3855. // private
  3856. Date.formatCodeToRegex = function(character, currentGroup) {
  3857. // Note: currentGroup - position in regex result array (see notes for Date.parseCodes below)
  3858. var p = Date.parseCodes[character];
  3859. if (p) {
  3860. p = typeof p == 'function'? p() : p;
  3861. Date.parseCodes[character] = p; // reassign function result to prevent repeated execution
  3862. }
  3863. return p ? Ext.applyIf({
  3864. c: p.c ? xf(p.c, currentGroup || "{0}") : p.c
  3865. }, p) : {
  3866. g:0,
  3867. c:null,
  3868. s:Ext.escapeRe(character) // treat unrecognised characters as literals
  3869. };
  3870. };
  3871. // private shorthand for Date.formatCodeToRegex since we'll be using it fairly often
  3872. var $f = Date.formatCodeToRegex;
  3873. Ext.apply(Date, {
  3874. /**
  3875. * <p>An object hash in which each property is a date parsing function. The property name is the
  3876. * format string which that function parses.</p>
  3877. * <p>This object is automatically populated with date parsing functions as
  3878. * date formats are requested for Ext standard formatting strings.</p>
  3879. * <p>Custom parsing functions may be inserted into this object, keyed by a name which from then on
  3880. * may be used as a format string to {@link #parseDate}.<p>
  3881. * <p>Example:</p><pre><code>
  3882. Date.parseFunctions['x-date-format'] = myDateParser;
  3883. </code></pre>
  3884. * <p>A parsing function should return a Date object, and is passed the following parameters:<div class="mdetail-params"><ul>
  3885. * <li><code>date</code> : String<div class="sub-desc">The date string to parse.</div></li>
  3886. * <li><code>strict</code> : Boolean<div class="sub-desc">True to validate date strings while parsing
  3887. * (i.e. prevent javascript Date "rollover") (The default must be false).
  3888. * Invalid date strings should return null when parsed.</div></li>
  3889. * </ul></div></p>
  3890. * <p>To enable Dates to also be <i>formatted</i> according to that format, a corresponding
  3891. * formatting function must be placed into the {@link #formatFunctions} property.
  3892. * @property parseFunctions
  3893. * @static
  3894. * @type Object
  3895. */
  3896. parseFunctions: {
  3897. "M$": function(input, strict) {
  3898. // note: the timezone offset is ignored since the M$ Ajax server sends
  3899. // a UTC milliseconds-since-Unix-epoch value (negative values are allowed)
  3900. var re = new RegExp('\\/Date\\(([-+])?(\\d+)(?:[+-]\\d{4})?\\)\\/');
  3901. var r = (input || '').match(re);
  3902. return r? new Date(((r[1] || '') + r[2]) * 1) : null;
  3903. }
  3904. },
  3905. parseRegexes: [],
  3906. /**
  3907. * <p>An object hash in which each property is a date formatting function. The property name is the
  3908. * format string which corresponds to the produced formatted date string.</p>
  3909. * <p>This object is automatically populated with date formatting functions as
  3910. * date formats are requested for Ext standard formatting strings.</p>
  3911. * <p>Custom formatting functions may be inserted into this object, keyed by a name which from then on
  3912. * may be used as a format string to {@link #format}. Example:</p><pre><code>
  3913. Date.formatFunctions['x-date-format'] = myDateFormatter;
  3914. </code></pre>
  3915. * <p>A formatting function should return a string representation of the passed Date object, and is passed the following parameters:<div class="mdetail-params"><ul>
  3916. * <li><code>date</code> : Date<div class="sub-desc">The Date to format.</div></li>
  3917. * </ul></div></p>
  3918. * <p>To enable date strings to also be <i>parsed</i> according to that format, a corresponding
  3919. * parsing function must be placed into the {@link #parseFunctions} property.
  3920. * @property formatFunctions
  3921. * @static
  3922. * @type Object
  3923. */
  3924. formatFunctions: {
  3925. "M$": function() {
  3926. // UTC milliseconds since Unix epoch (M$-AJAX serialized date format (MRSF))
  3927. return '\\/Date(' + this.getTime() + ')\\/';
  3928. }
  3929. },
  3930. y2kYear : 50,
  3931. /**
  3932. * Date interval constant
  3933. * @static
  3934. * @type String
  3935. */
  3936. MILLI : "ms",
  3937. /**
  3938. * Date interval constant
  3939. * @static
  3940. * @type String
  3941. */
  3942. SECOND : "s",
  3943. /**
  3944. * Date interval constant
  3945. * @static
  3946. * @type String
  3947. */
  3948. MINUTE : "mi",
  3949. /** Date interval constant
  3950. * @static
  3951. * @type String
  3952. */
  3953. HOUR : "h",
  3954. /**
  3955. * Date interval constant
  3956. * @static
  3957. * @type String
  3958. */
  3959. DAY : "d",
  3960. /**
  3961. * Date interval constant
  3962. * @static
  3963. * @type String
  3964. */
  3965. MONTH : "mo",
  3966. /**
  3967. * Date interval constant
  3968. * @static
  3969. * @type String
  3970. */
  3971. YEAR : "y",
  3972. /**
  3973. * <p>An object hash containing default date values used during date parsing.</p>
  3974. * <p>The following properties are available:<div class="mdetail-params"><ul>
  3975. * <li><code>y</code> : Number<div class="sub-desc">The default year value. (defaults to undefined)</div></li>
  3976. * <li><code>m</code> : Number<div class="sub-desc">The default 1-based month value. (defaults to undefined)</div></li>
  3977. * <li><code>d</code> : Number<div class="sub-desc">The default day value. (defaults to undefined)</div></li>
  3978. * <li><code>h</code> : Number<div class="sub-desc">The default hour value. (defaults to undefined)</div></li>
  3979. * <li><code>i</code> : Number<div class="sub-desc">The default minute value. (defaults to undefined)</div></li>
  3980. * <li><code>s</code> : Number<div class="sub-desc">The default second value. (defaults to undefined)</div></li>
  3981. * <li><code>ms</code> : Number<div class="sub-desc">The default millisecond value. (defaults to undefined)</div></li>
  3982. * </ul></div></p>
  3983. * <p>Override these properties to customize the default date values used by the {@link #parseDate} method.</p>
  3984. * <p><b>Note: In countries which experience Daylight Saving Time (i.e. DST), the <tt>h</tt>, <tt>i</tt>, <tt>s</tt>
  3985. * and <tt>ms</tt> properties may coincide with the exact time in which DST takes effect.
  3986. * It is the responsiblity of the developer to account for this.</b></p>
  3987. * Example Usage:
  3988. * <pre><code>
  3989. // set default day value to the first day of the month
  3990. Date.defaults.d = 1;
  3991. // parse a February date string containing only year and month values.
  3992. // setting the default day value to 1 prevents weird date rollover issues
  3993. // when attempting to parse the following date string on, for example, March 31st 2009.
  3994. Date.parseDate('2009-02', 'Y-m'); // returns a Date object representing February 1st 2009
  3995. </code></pre>
  3996. * @property defaults
  3997. * @static
  3998. * @type Object
  3999. */
  4000. defaults: {},
  4001. /**
  4002. * An array of textual day names.
  4003. * Override these values for international dates.
  4004. * Example:
  4005. * <pre><code>
  4006. Date.dayNames = [
  4007. 'SundayInYourLang',
  4008. 'MondayInYourLang',
  4009. ...
  4010. ];
  4011. </code></pre>
  4012. * @type Array
  4013. * @static
  4014. */
  4015. dayNames : [
  4016. "Sunday",
  4017. "Monday",
  4018. "Tuesday",
  4019. "Wednesday",
  4020. "Thursday",
  4021. "Friday",
  4022. "Saturday"
  4023. ],
  4024. /**
  4025. * An array of textual month names.
  4026. * Override these values for international dates.
  4027. * Example:
  4028. * <pre><code>
  4029. Date.monthNames = [
  4030. 'JanInYourLang',
  4031. 'FebInYourLang',
  4032. ...
  4033. ];
  4034. </code></pre>
  4035. * @type Array
  4036. * @static
  4037. */
  4038. monthNames : [
  4039. "January",
  4040. "February",
  4041. "March",
  4042. "April",
  4043. "May",
  4044. "June",
  4045. "July",
  4046. "August",
  4047. "September",
  4048. "October",
  4049. "November",
  4050. "December"
  4051. ],
  4052. /**
  4053. * An object hash of zero-based javascript month numbers (with short month names as keys. note: keys are case-sensitive).
  4054. * Override these values for international dates.
  4055. * Example:
  4056. * <pre><code>
  4057. Date.monthNumbers = {
  4058. 'ShortJanNameInYourLang':0,
  4059. 'ShortFebNameInYourLang':1,
  4060. ...
  4061. };
  4062. </code></pre>
  4063. * @type Object
  4064. * @static
  4065. */
  4066. monthNumbers : {
  4067. Jan:0,
  4068. Feb:1,
  4069. Mar:2,
  4070. Apr:3,
  4071. May:4,
  4072. Jun:5,
  4073. Jul:6,
  4074. Aug:7,
  4075. Sep:8,
  4076. Oct:9,
  4077. Nov:10,
  4078. Dec:11
  4079. },
  4080. /**
  4081. * Get the short month name for the given month number.
  4082. * Override this function for international dates.
  4083. * @param {Number} month A zero-based javascript month number.
  4084. * @return {String} The short month name.
  4085. * @static
  4086. */
  4087. getShortMonthName : function(month) {
  4088. return Date.monthNames[month].substring(0, 3);
  4089. },
  4090. /**
  4091. * Get the short day name for the given day number.
  4092. * Override this function for international dates.
  4093. * @param {Number} day A zero-based javascript day number.
  4094. * @return {String} The short day name.
  4095. * @static
  4096. */
  4097. getShortDayName : function(day) {
  4098. return Date.dayNames[day].substring(0, 3);
  4099. },
  4100. /**
  4101. * Get the zero-based javascript month number for the given short/full month name.
  4102. * Override this function for international dates.
  4103. * @param {String} name The short/full month name.
  4104. * @return {Number} The zero-based javascript month number.
  4105. * @static
  4106. */
  4107. getMonthNumber : function(name) {
  4108. // handle camel casing for english month names (since the keys for the Date.monthNumbers hash are case sensitive)
  4109. return Date.monthNumbers[name.substring(0, 1).toUpperCase() + name.substring(1, 3).toLowerCase()];
  4110. },
  4111. /**
  4112. * The base format-code to formatting-function hashmap used by the {@link #format} method.
  4113. * Formatting functions are strings (or functions which return strings) which
  4114. * will return the appropriate value when evaluated in the context of the Date object
  4115. * from which the {@link #format} method is called.
  4116. * Add to / override these mappings for custom date formatting.
  4117. * Note: Date.format() treats characters as literals if an appropriate mapping cannot be found.
  4118. * Example:
  4119. * <pre><code>
  4120. Date.formatCodes.x = "String.leftPad(this.getDate(), 2, '0')";
  4121. (new Date()).format("X"); // returns the current day of the month
  4122. </code></pre>
  4123. * @type Object
  4124. * @static
  4125. */
  4126. formatCodes : {
  4127. d: "String.leftPad(this.getDate(), 2, '0')",
  4128. D: "Date.getShortDayName(this.getDay())", // get localised short day name
  4129. j: "this.getDate()",
  4130. l: "Date.dayNames[this.getDay()]",
  4131. N: "(this.getDay() ? this.getDay() : 7)",
  4132. S: "this.getSuffix()",
  4133. w: "this.getDay()",
  4134. z: "this.getDayOfYear()",
  4135. W: "String.leftPad(this.getWeekOfYear(), 2, '0')",
  4136. F: "Date.monthNames[this.getMonth()]",
  4137. m: "String.leftPad(this.getMonth() + 1, 2, '0')",
  4138. M: "Date.getShortMonthName(this.getMonth())", // get localised short month name
  4139. n: "(this.getMonth() + 1)",
  4140. t: "this.getDaysInMonth()",
  4141. L: "(this.isLeapYear() ? 1 : 0)",
  4142. o: "(this.getFullYear() + (this.getWeekOfYear() == 1 && this.getMonth() > 0 ? +1 : (this.getWeekOfYear() >= 52 && this.getMonth() < 11 ? -1 : 0)))",
  4143. Y: "String.leftPad(this.getFullYear(), 4, '0')",
  4144. y: "('' + this.getFullYear()).substring(2, 4)",
  4145. a: "(this.getHours() < 12 ? 'am' : 'pm')",
  4146. A: "(this.getHours() < 12 ? 'AM' : 'PM')",
  4147. g: "((this.getHours() % 12) ? this.getHours() % 12 : 12)",
  4148. G: "this.getHours()",
  4149. h: "String.leftPad((this.getHours() % 12) ? this.getHours() % 12 : 12, 2, '0')",
  4150. H: "String.leftPad(this.getHours(), 2, '0')",
  4151. i: "String.leftPad(this.getMinutes(), 2, '0')",
  4152. s: "String.leftPad(this.getSeconds(), 2, '0')",
  4153. u: "String.leftPad(this.getMilliseconds(), 3, '0')",
  4154. O: "this.getGMTOffset()",
  4155. P: "this.getGMTOffset(true)",
  4156. T: "this.getTimezone()",
  4157. Z: "(this.getTimezoneOffset() * -60)",
  4158. c: function() { // ISO-8601 -- GMT format
  4159. for (var c = "Y-m-dTH:i:sP", code = [], i = 0, l = c.length; i < l; ++i) {
  4160. var e = c.charAt(i);
  4161. code.push(e == "T" ? "'T'" : Date.getFormatCode(e)); // treat T as a character literal
  4162. }
  4163. return code.join(" + ");
  4164. },
  4165. /*
  4166. c: function() { // ISO-8601 -- UTC format
  4167. return [
  4168. "this.getUTCFullYear()", "'-'",
  4169. "String.leftPad(this.getUTCMonth() + 1, 2, '0')", "'-'",
  4170. "String.leftPad(this.getUTCDate(), 2, '0')",
  4171. "'T'",
  4172. "String.leftPad(this.getUTCHours(), 2, '0')", "':'",
  4173. "String.leftPad(this.getUTCMinutes(), 2, '0')", "':'",
  4174. "String.leftPad(this.getUTCSeconds(), 2, '0')",
  4175. "'Z'"
  4176. ].join(" + ");
  4177. },
  4178. */
  4179. U: "Math.round(this.getTime() / 1000)"
  4180. },
  4181. /**
  4182. * Checks if the passed Date parameters will cause a javascript Date "rollover".
  4183. * @param {Number} year 4-digit year
  4184. * @param {Number} month 1-based month-of-year
  4185. * @param {Number} day Day of month
  4186. * @param {Number} hour (optional) Hour
  4187. * @param {Number} minute (optional) Minute
  4188. * @param {Number} second (optional) Second
  4189. * @param {Number} millisecond (optional) Millisecond
  4190. * @return {Boolean} true if the passed parameters do not cause a Date "rollover", false otherwise.
  4191. * @static
  4192. */
  4193. isValid : function(y, m, d, h, i, s, ms) {
  4194. // setup defaults
  4195. h = h || 0;
  4196. i = i || 0;
  4197. s = s || 0;
  4198. ms = ms || 0;
  4199. // Special handling for year < 100
  4200. var dt = new Date(y < 100 ? 100 : y, m - 1, d, h, i, s, ms).add(Date.YEAR, y < 100 ? y - 100 : 0);
  4201. return y == dt.getFullYear() &&
  4202. m == dt.getMonth() + 1 &&
  4203. d == dt.getDate() &&
  4204. h == dt.getHours() &&
  4205. i == dt.getMinutes() &&
  4206. s == dt.getSeconds() &&
  4207. ms == dt.getMilliseconds();
  4208. },
  4209. /**
  4210. * Parses the passed string using the specified date format.
  4211. * Note that this function expects normal calendar dates, meaning that months are 1-based (i.e. 1 = January).
  4212. * The {@link #defaults} hash will be used for any date value (i.e. year, month, day, hour, minute, second or millisecond)
  4213. * which cannot be found in the passed string. If a corresponding default date value has not been specified in the {@link #defaults} hash,
  4214. * the current date's year, month, day or DST-adjusted zero-hour time value will be used instead.
  4215. * Keep in mind that the input date string must precisely match the specified format string
  4216. * in order for the parse operation to be successful (failed parse operations return a null value).
  4217. * <p>Example:</p><pre><code>
  4218. //dt = Fri May 25 2007 (current date)
  4219. var dt = new Date();
  4220. //dt = Thu May 25 2006 (today&#39;s month/day in 2006)
  4221. dt = Date.parseDate("2006", "Y");
  4222. //dt = Sun Jan 15 2006 (all date parts specified)
  4223. dt = Date.parseDate("2006-01-15", "Y-m-d");
  4224. //dt = Sun Jan 15 2006 15:20:01
  4225. dt = Date.parseDate("2006-01-15 3:20:01 PM", "Y-m-d g:i:s A");
  4226. // attempt to parse Sun Feb 29 2006 03:20:01 in strict mode
  4227. dt = Date.parseDate("2006-02-29 03:20:01", "Y-m-d H:i:s", true); // returns null
  4228. </code></pre>
  4229. * @param {String} input The raw date string.
  4230. * @param {String} format The expected date string format.
  4231. * @param {Boolean} strict (optional) True to validate date strings while parsing (i.e. prevents javascript Date "rollover")
  4232. (defaults to false). Invalid date strings will return null when parsed.
  4233. * @return {Date} The parsed Date.
  4234. * @static
  4235. */
  4236. parseDate : function(input, format, strict) {
  4237. var p = Date.parseFunctions;
  4238. if (p[format] == null) {
  4239. Date.createParser(format);
  4240. }
  4241. return p[format](input, Ext.isDefined(strict) ? strict : Date.useStrict);
  4242. },
  4243. // private
  4244. getFormatCode : function(character) {
  4245. var f = Date.formatCodes[character];
  4246. if (f) {
  4247. f = typeof f == 'function'? f() : f;
  4248. Date.formatCodes[character] = f; // reassign function result to prevent repeated execution
  4249. }
  4250. // note: unknown characters are treated as literals
  4251. return f || ("'" + String.escape(character) + "'");
  4252. },
  4253. // private
  4254. createFormat : function(format) {
  4255. var code = [],
  4256. special = false,
  4257. ch = '';
  4258. for (var i = 0; i < format.length; ++i) {
  4259. ch = format.charAt(i);
  4260. if (!special && ch == "\\") {
  4261. special = true;
  4262. } else if (special) {
  4263. special = false;
  4264. code.push("'" + String.escape(ch) + "'");
  4265. } else {
  4266. code.push(Date.getFormatCode(ch));
  4267. }
  4268. }
  4269. Date.formatFunctions[format] = new Function("return " + code.join('+'));
  4270. },
  4271. // private
  4272. createParser : function() {
  4273. var code = [
  4274. "var dt, y, m, d, h, i, s, ms, o, z, zz, u, v,",
  4275. "def = Date.defaults,",
  4276. "results = String(input).match(Date.parseRegexes[{0}]);", // either null, or an array of matched strings
  4277. "if(results){",
  4278. "{1}",
  4279. "if(u != null){", // i.e. unix time is defined
  4280. "v = new Date(u * 1000);", // give top priority to UNIX time
  4281. "}else{",
  4282. // create Date object representing midnight of the current day;
  4283. // this will provide us with our date defaults
  4284. // (note: clearTime() handles Daylight Saving Time automatically)
  4285. "dt = (new Date()).clearTime();",
  4286. // date calculations (note: these calculations create a dependency on Ext.num())
  4287. "y = Ext.num(y, Ext.num(def.y, dt.getFullYear()));",
  4288. "m = Ext.num(m, Ext.num(def.m - 1, dt.getMonth()));",
  4289. "d = Ext.num(d, Ext.num(def.d, dt.getDate()));",
  4290. // time calculations (note: these calculations create a dependency on Ext.num())
  4291. "h = Ext.num(h, Ext.num(def.h, dt.getHours()));",
  4292. "i = Ext.num(i, Ext.num(def.i, dt.getMinutes()));",
  4293. "s = Ext.num(s, Ext.num(def.s, dt.getSeconds()));",
  4294. "ms = Ext.num(ms, Ext.num(def.ms, dt.getMilliseconds()));",
  4295. "if(z >= 0 && y >= 0){",
  4296. // both the year and zero-based day of year are defined and >= 0.
  4297. // these 2 values alone provide sufficient info to create a full date object
  4298. // create Date object representing January 1st for the given year
  4299. // handle years < 100 appropriately
  4300. "v = new Date(y < 100 ? 100 : y, 0, 1, h, i, s, ms).add(Date.YEAR, y < 100 ? y - 100 : 0);",
  4301. // then add day of year, checking for Date "rollover" if necessary
  4302. "v = !strict? v : (strict === true && (z <= 364 || (v.isLeapYear() && z <= 365))? v.add(Date.DAY, z) : null);",
  4303. "}else if(strict === true && !Date.isValid(y, m + 1, d, h, i, s, ms)){", // check for Date "rollover"
  4304. "v = null;", // invalid date, so return null
  4305. "}else{",
  4306. // plain old Date object
  4307. // handle years < 100 properly
  4308. "v = new Date(y < 100 ? 100 : y, m, d, h, i, s, ms).add(Date.YEAR, y < 100 ? y - 100 : 0);",
  4309. "}",
  4310. "}",
  4311. "}",
  4312. "if(v){",
  4313. // favour UTC offset over GMT offset
  4314. "if(zz != null){",
  4315. // reset to UTC, then add offset
  4316. "v = v.add(Date.SECOND, -v.getTimezoneOffset() * 60 - zz);",
  4317. "}else if(o){",
  4318. // reset to GMT, then add offset
  4319. "v = v.add(Date.MINUTE, -v.getTimezoneOffset() + (sn == '+'? -1 : 1) * (hr * 60 + mn));",
  4320. "}",
  4321. "}",
  4322. "return v;"
  4323. ].join('\n');
  4324. return function(format) {
  4325. var regexNum = Date.parseRegexes.length,
  4326. currentGroup = 1,
  4327. calc = [],
  4328. regex = [],
  4329. special = false,
  4330. ch = "",
  4331. i = 0,
  4332. obj,
  4333. last;
  4334. for (; i < format.length; ++i) {
  4335. ch = format.charAt(i);
  4336. if (!special && ch == "\\") {
  4337. special = true;
  4338. } else if (special) {
  4339. special = false;
  4340. regex.push(String.escape(ch));
  4341. } else {
  4342. obj = $f(ch, currentGroup);
  4343. currentGroup += obj.g;
  4344. regex.push(obj.s);
  4345. if (obj.g && obj.c) {
  4346. if (obj.calcLast) {
  4347. last = obj.c;
  4348. } else {
  4349. calc.push(obj.c);
  4350. }
  4351. }
  4352. }
  4353. }
  4354. if (last) {
  4355. calc.push(last);
  4356. }
  4357. Date.parseRegexes[regexNum] = new RegExp("^" + regex.join('') + "$", 'i');
  4358. Date.parseFunctions[format] = new Function("input", "strict", xf(code, regexNum, calc.join('')));
  4359. };
  4360. }(),
  4361. // private
  4362. parseCodes : {
  4363. /*
  4364. * Notes:
  4365. * g = {Number} calculation group (0 or 1. only group 1 contributes to date calculations.)
  4366. * c = {String} calculation method (required for group 1. null for group 0. {0} = currentGroup - position in regex result array)
  4367. * s = {String} regex pattern. all matches are stored in results[], and are accessible by the calculation mapped to 'c'
  4368. */
  4369. d: {
  4370. g:1,
  4371. c:"d = parseInt(results[{0}], 10);\n",
  4372. s:"(\\d{2})" // day of month with leading zeroes (01 - 31)
  4373. },
  4374. j: {
  4375. g:1,
  4376. c:"d = parseInt(results[{0}], 10);\n",
  4377. s:"(\\d{1,2})" // day of month without leading zeroes (1 - 31)
  4378. },
  4379. D: function() {
  4380. for (var a = [], i = 0; i < 7; a.push(Date.getShortDayName(i)), ++i); // get localised short day names
  4381. return {
  4382. g:0,
  4383. c:null,
  4384. s:"(?:" + a.join("|") +")"
  4385. };
  4386. },
  4387. l: function() {
  4388. return {
  4389. g:0,
  4390. c:null,
  4391. s:"(?:" + Date.dayNames.join("|") + ")"
  4392. };
  4393. },
  4394. N: {
  4395. g:0,
  4396. c:null,
  4397. s:"[1-7]" // ISO-8601 day number (1 (monday) - 7 (sunday))
  4398. },
  4399. S: {
  4400. g:0,
  4401. c:null,
  4402. s:"(?:st|nd|rd|th)"
  4403. },
  4404. w: {
  4405. g:0,
  4406. c:null,
  4407. s:"[0-6]" // javascript day number (0 (sunday) - 6 (saturday))
  4408. },
  4409. z: {
  4410. g:1,
  4411. c:"z = parseInt(results[{0}], 10);\n",
  4412. s:"(\\d{1,3})" // day of the year (0 - 364 (365 in leap years))
  4413. },
  4414. W: {
  4415. g:0,
  4416. c:null,
  4417. s:"(?:\\d{2})" // ISO-8601 week number (with leading zero)
  4418. },
  4419. F: function() {
  4420. return {
  4421. g:1,
  4422. c:"m = parseInt(Date.getMonthNumber(results[{0}]), 10);\n", // get localised month number
  4423. s:"(" + Date.monthNames.join("|") + ")"
  4424. };
  4425. },
  4426. M: function() {
  4427. for (var a = [], i = 0; i < 12; a.push(Date.getShortMonthName(i)), ++i); // get localised short month names
  4428. return Ext.applyIf({
  4429. s:"(" + a.join("|") + ")"
  4430. }, $f("F"));
  4431. },
  4432. m: {
  4433. g:1,
  4434. c:"m = parseInt(results[{0}], 10) - 1;\n",
  4435. s:"(\\d{2})" // month number with leading zeros (01 - 12)
  4436. },
  4437. n: {
  4438. g:1,
  4439. c:"m = parseInt(results[{0}], 10) - 1;\n",
  4440. s:"(\\d{1,2})" // month number without leading zeros (1 - 12)
  4441. },
  4442. t: {
  4443. g:0,
  4444. c:null,
  4445. s:"(?:\\d{2})" // no. of days in the month (28 - 31)
  4446. },
  4447. L: {
  4448. g:0,
  4449. c:null,
  4450. s:"(?:1|0)"
  4451. },
  4452. o: function() {
  4453. return $f("Y");
  4454. },
  4455. Y: {
  4456. g:1,
  4457. c:"y = parseInt(results[{0}], 10);\n",
  4458. s:"(\\d{4})" // 4-digit year
  4459. },
  4460. y: {
  4461. g:1,
  4462. c:"var ty = parseInt(results[{0}], 10);\n"
  4463. + "y = ty > Date.y2kYear ? 1900 + ty : 2000 + ty;\n", // 2-digit year
  4464. s:"(\\d{1,2})"
  4465. },
  4466. /**
  4467. * In the am/pm parsing routines, we allow both upper and lower case
  4468. * even though it doesn't exactly match the spec. It gives much more flexibility
  4469. * in being able to specify case insensitive regexes.
  4470. */
  4471. a: function(){
  4472. return $f("A");
  4473. },
  4474. A: {
  4475. // We need to calculate the hour before we apply AM/PM when parsing
  4476. calcLast: true,
  4477. g:1,
  4478. c:"if (/(am)/i.test(results[{0}])) {\n"
  4479. + "if (!h || h == 12) { h = 0; }\n"
  4480. + "} else { if (!h || h < 12) { h = (h || 0) + 12; }}",
  4481. s:"(AM|PM|am|pm)"
  4482. },
  4483. g: function() {
  4484. return $f("G");
  4485. },
  4486. G: {
  4487. g:1,
  4488. c:"h = parseInt(results[{0}], 10);\n",
  4489. s:"(\\d{1,2})" // 24-hr format of an hour without leading zeroes (0 - 23)
  4490. },
  4491. h: function() {
  4492. return $f("H");
  4493. },
  4494. H: {
  4495. g:1,
  4496. c:"h = parseInt(results[{0}], 10);\n",
  4497. s:"(\\d{2})" // 24-hr format of an hour with leading zeroes (00 - 23)
  4498. },
  4499. i: {
  4500. g:1,
  4501. c:"i = parseInt(results[{0}], 10);\n",
  4502. s:"(\\d{2})" // minutes with leading zeros (00 - 59)
  4503. },
  4504. s: {
  4505. g:1,
  4506. c:"s = parseInt(results[{0}], 10);\n",
  4507. s:"(\\d{2})" // seconds with leading zeros (00 - 59)
  4508. },
  4509. u: {
  4510. g:1,
  4511. c:"ms = results[{0}]; ms = parseInt(ms, 10)/Math.pow(10, ms.length - 3);\n",
  4512. s:"(\\d+)" // decimal fraction of a second (minimum = 1 digit, maximum = unlimited)
  4513. },
  4514. O: {
  4515. g:1,
  4516. c:[
  4517. "o = results[{0}];",
  4518. "var sn = o.substring(0,1),", // get + / - sign
  4519. "hr = o.substring(1,3)*1 + Math.floor(o.substring(3,5) / 60),", // get hours (performs minutes-to-hour conversion also, just in case)
  4520. "mn = o.substring(3,5) % 60;", // get minutes
  4521. "o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))? (sn + String.leftPad(hr, 2, '0') + String.leftPad(mn, 2, '0')) : null;\n" // -12hrs <= GMT offset <= 14hrs
  4522. ].join("\n"),
  4523. s: "([+\-]\\d{4})" // GMT offset in hrs and mins
  4524. },
  4525. P: {
  4526. g:1,
  4527. c:[
  4528. "o = results[{0}];",
  4529. "var sn = o.substring(0,1),", // get + / - sign
  4530. "hr = o.substring(1,3)*1 + Math.floor(o.substring(4,6) / 60),", // get hours (performs minutes-to-hour conversion also, just in case)
  4531. "mn = o.substring(4,6) % 60;", // get minutes
  4532. "o = ((-12 <= (hr*60 + mn)/60) && ((hr*60 + mn)/60 <= 14))? (sn + String.leftPad(hr, 2, '0') + String.leftPad(mn, 2, '0')) : null;\n" // -12hrs <= GMT offset <= 14hrs
  4533. ].join("\n"),
  4534. s: "([+\-]\\d{2}:\\d{2})" // GMT offset in hrs and mins (with colon separator)
  4535. },
  4536. T: {
  4537. g:0,
  4538. c:null,
  4539. s:"[A-Z]{1,4}" // timezone abbrev. may be between 1 - 4 chars
  4540. },
  4541. Z: {
  4542. g:1,
  4543. c:"zz = results[{0}] * 1;\n" // -43200 <= UTC offset <= 50400
  4544. + "zz = (-43200 <= zz && zz <= 50400)? zz : null;\n",
  4545. s:"([+\-]?\\d{1,5})" // leading '+' sign is optional for UTC offset
  4546. },
  4547. c: function() {
  4548. var calc = [],
  4549. arr = [
  4550. $f("Y", 1), // year
  4551. $f("m", 2), // month
  4552. $f("d", 3), // day
  4553. $f("h", 4), // hour
  4554. $f("i", 5), // minute
  4555. $f("s", 6), // second
  4556. {c:"ms = results[7] || '0'; ms = parseInt(ms, 10)/Math.pow(10, ms.length - 3);\n"}, // decimal fraction of a second (minimum = 1 digit, maximum = unlimited)
  4557. {c:[ // allow either "Z" (i.e. UTC) or "-0530" or "+08:00" (i.e. UTC offset) timezone delimiters. assumes local timezone if no timezone is specified
  4558. "if(results[8]) {", // timezone specified
  4559. "if(results[8] == 'Z'){",
  4560. "zz = 0;", // UTC
  4561. "}else if (results[8].indexOf(':') > -1){",
  4562. $f("P", 8).c, // timezone offset with colon separator
  4563. "}else{",
  4564. $f("O", 8).c, // timezone offset without colon separator
  4565. "}",
  4566. "}"
  4567. ].join('\n')}
  4568. ];
  4569. for (var i = 0, l = arr.length; i < l; ++i) {
  4570. calc.push(arr[i].c);
  4571. }
  4572. return {
  4573. g:1,
  4574. c:calc.join(""),
  4575. s:[
  4576. arr[0].s, // year (required)
  4577. "(?:", "-", arr[1].s, // month (optional)
  4578. "(?:", "-", arr[2].s, // day (optional)
  4579. "(?:",
  4580. "(?:T| )?", // time delimiter -- either a "T" or a single blank space
  4581. arr[3].s, ":", arr[4].s, // hour AND minute, delimited by a single colon (optional). MUST be preceded by either a "T" or a single blank space
  4582. "(?::", arr[5].s, ")?", // seconds (optional)
  4583. "(?:(?:\\.|,)(\\d+))?", // decimal fraction of a second (e.g. ",12345" or ".98765") (optional)
  4584. "(Z|(?:[-+]\\d{2}(?::)?\\d{2}))?", // "Z" (UTC) or "-0530" (UTC offset without colon delimiter) or "+08:00" (UTC offset with colon delimiter) (optional)
  4585. ")?",
  4586. ")?",
  4587. ")?"
  4588. ].join("")
  4589. };
  4590. },
  4591. U: {
  4592. g:1,
  4593. c:"u = parseInt(results[{0}], 10);\n",
  4594. s:"(-?\\d+)" // leading minus sign indicates seconds before UNIX epoch
  4595. }
  4596. }
  4597. });
  4598. }());
  4599. Ext.apply(Date.prototype, {
  4600. // private
  4601. dateFormat : function(format) {
  4602. if (Date.formatFunctions[format] == null) {
  4603. Date.createFormat(format);
  4604. }
  4605. return Date.formatFunctions[format].call(this);
  4606. },
  4607. /**
  4608. * Get the timezone abbreviation of the current date (equivalent to the format specifier 'T').
  4609. *
  4610. * Note: The date string returned by the javascript Date object's toString() method varies
  4611. * between browsers (e.g. FF vs IE) and system region settings (e.g. IE in Asia vs IE in America).
  4612. * For a given date string e.g. "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)",
  4613. * getTimezone() first tries to get the timezone abbreviation from between a pair of parentheses
  4614. * (which may or may not be present), failing which it proceeds to get the timezone abbreviation
  4615. * from the GMT offset portion of the date string.
  4616. * @return {String} The abbreviated timezone name (e.g. 'CST', 'PDT', 'EDT', 'MPST' ...).
  4617. */
  4618. getTimezone : function() {
  4619. // the following list shows the differences between date strings from different browsers on a WinXP SP2 machine from an Asian locale:
  4620. //
  4621. // Opera : "Thu, 25 Oct 2007 22:53:45 GMT+0800" -- shortest (weirdest) date string of the lot
  4622. // Safari : "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)" -- value in parentheses always gives the correct timezone (same as FF)
  4623. // FF : "Thu Oct 25 2007 22:55:35 GMT+0800 (Malay Peninsula Standard Time)" -- value in parentheses always gives the correct timezone
  4624. // IE : "Thu Oct 25 22:54:35 UTC+0800 2007" -- (Asian system setting) look for 3-4 letter timezone abbrev
  4625. // IE : "Thu Oct 25 17:06:37 PDT 2007" -- (American system setting) look for 3-4 letter timezone abbrev
  4626. //
  4627. // this crazy regex attempts to guess the correct timezone abbreviation despite these differences.
  4628. // step 1: (?:\((.*)\) -- find timezone in parentheses
  4629. // step 2: ([A-Z]{1,4})(?:[\-+][0-9]{4})?(?: -?\d+)?) -- if nothing was found in step 1, find timezone from timezone offset portion of date string
  4630. // step 3: remove all non uppercase characters found in step 1 and 2
  4631. return this.toString().replace(/^.* (?:\((.*)\)|([A-Z]{1,4})(?:[\-+][0-9]{4})?(?: -?\d+)?)$/, "$1$2").replace(/[^A-Z]/g, "");
  4632. },
  4633. /**
  4634. * Get the offset from GMT of the current date (equivalent to the format specifier 'O').
  4635. * @param {Boolean} colon (optional) true to separate the hours and minutes with a colon (defaults to false).
  4636. * @return {String} The 4-character offset string prefixed with + or - (e.g. '-0600').
  4637. */
  4638. getGMTOffset : function(colon) {
  4639. return (this.getTimezoneOffset() > 0 ? "-" : "+")
  4640. + String.leftPad(Math.floor(Math.abs(this.getTimezoneOffset()) / 60), 2, "0")
  4641. + (colon ? ":" : "")
  4642. + String.leftPad(Math.abs(this.getTimezoneOffset() % 60), 2, "0");
  4643. },
  4644. /**
  4645. * Get the numeric day number of the year, adjusted for leap year.
  4646. * @return {Number} 0 to 364 (365 in leap years).
  4647. */
  4648. getDayOfYear: function() {
  4649. var num = 0,
  4650. d = this.clone(),
  4651. m = this.getMonth(),
  4652. i;
  4653. for (i = 0, d.setDate(1), d.setMonth(0); i < m; d.setMonth(++i)) {
  4654. num += d.getDaysInMonth();
  4655. }
  4656. return num + this.getDate() - 1;
  4657. },
  4658. /**
  4659. * Get the numeric ISO-8601 week number of the year.
  4660. * (equivalent to the format specifier 'W', but without a leading zero).
  4661. * @return {Number} 1 to 53
  4662. */
  4663. getWeekOfYear : function() {
  4664. // adapted from http://www.merlyn.demon.co.uk/weekcalc.htm
  4665. var ms1d = 864e5, // milliseconds in a day
  4666. ms7d = 7 * ms1d; // milliseconds in a week
  4667. return function() { // return a closure so constants get calculated only once
  4668. var DC3 = Date.UTC(this.getFullYear(), this.getMonth(), this.getDate() + 3) / ms1d, // an Absolute Day Number
  4669. AWN = Math.floor(DC3 / 7), // an Absolute Week Number
  4670. Wyr = new Date(AWN * ms7d).getUTCFullYear();
  4671. return AWN - Math.floor(Date.UTC(Wyr, 0, 7) / ms7d) + 1;
  4672. };
  4673. }(),
  4674. /**
  4675. * Checks if the current date falls within a leap year.
  4676. * @return {Boolean} True if the current date falls within a leap year, false otherwise.
  4677. */
  4678. isLeapYear : function() {
  4679. var year = this.getFullYear();
  4680. return !!((year & 3) == 0 && (year % 100 || (year % 400 == 0 && year)));
  4681. },
  4682. /**
  4683. * Get the first day of the current month, adjusted for leap year. The returned value
  4684. * is the numeric day index within the week (0-6) which can be used in conjunction with
  4685. * the {@link #monthNames} array to retrieve the textual day name.
  4686. * Example:
  4687. * <pre><code>
  4688. var dt = new Date('1/10/2007');
  4689. document.write(Date.dayNames[dt.getFirstDayOfMonth()]); //output: 'Monday'
  4690. </code></pre>
  4691. * @return {Number} The day number (0-6).
  4692. */
  4693. getFirstDayOfMonth : function() {
  4694. var day = (this.getDay() - (this.getDate() - 1)) % 7;
  4695. return (day < 0) ? (day + 7) : day;
  4696. },
  4697. /**
  4698. * Get the last day of the current month, adjusted for leap year. The returned value
  4699. * is the numeric day index within the week (0-6) which can be used in conjunction with
  4700. * the {@link #monthNames} array to retrieve the textual day name.
  4701. * Example:
  4702. * <pre><code>
  4703. var dt = new Date('1/10/2007');
  4704. document.write(Date.dayNames[dt.getLastDayOfMonth()]); //output: 'Wednesday'
  4705. </code></pre>
  4706. * @return {Number} The day number (0-6).
  4707. */
  4708. getLastDayOfMonth : function() {
  4709. return this.getLastDateOfMonth().getDay();
  4710. },
  4711. /**
  4712. * Get the date of the first day of the month in which this date resides.
  4713. * @return {Date}
  4714. */
  4715. getFirstDateOfMonth : function() {
  4716. return new Date(this.getFullYear(), this.getMonth(), 1);
  4717. },
  4718. /**
  4719. * Get the date of the last day of the month in which this date resides.
  4720. * @return {Date}
  4721. */
  4722. getLastDateOfMonth : function() {
  4723. return new Date(this.getFullYear(), this.getMonth(), this.getDaysInMonth());
  4724. },
  4725. /**
  4726. * Get the number of days in the current month, adjusted for leap year.
  4727. * @return {Number} The number of days in the month.
  4728. */
  4729. getDaysInMonth: function() {
  4730. var daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
  4731. return function() { // return a closure for efficiency
  4732. var m = this.getMonth();
  4733. return m == 1 && this.isLeapYear() ? 29 : daysInMonth[m];
  4734. };
  4735. }(),
  4736. /**
  4737. * Get the English ordinal suffix of the current day (equivalent to the format specifier 'S').
  4738. * @return {String} 'st, 'nd', 'rd' or 'th'.
  4739. */
  4740. getSuffix : function() {
  4741. switch (this.getDate()) {
  4742. case 1:
  4743. case 21:
  4744. case 31:
  4745. return "st";
  4746. case 2:
  4747. case 22:
  4748. return "nd";
  4749. case 3:
  4750. case 23:
  4751. return "rd";
  4752. default:
  4753. return "th";
  4754. }
  4755. },
  4756. /**
  4757. * Creates and returns a new Date instance with the exact same date value as the called instance.
  4758. * Dates are copied and passed by reference, so if a copied date variable is modified later, the original
  4759. * variable will also be changed. When the intention is to create a new variable that will not
  4760. * modify the original instance, you should create a clone.
  4761. *
  4762. * Example of correctly cloning a date:
  4763. * <pre><code>
  4764. //wrong way:
  4765. var orig = new Date('10/1/2006');
  4766. var copy = orig;
  4767. copy.setDate(5);
  4768. document.write(orig); //returns 'Thu Oct 05 2006'!
  4769. //correct way:
  4770. var orig = new Date('10/1/2006');
  4771. var copy = orig.clone();
  4772. copy.setDate(5);
  4773. document.write(orig); //returns 'Thu Oct 01 2006'
  4774. </code></pre>
  4775. * @return {Date} The new Date instance.
  4776. */
  4777. clone : function() {
  4778. return new Date(this.getTime());
  4779. },
  4780. /**
  4781. * Checks if the current date is affected by Daylight Saving Time (DST).
  4782. * @return {Boolean} True if the current date is affected by DST.
  4783. */
  4784. isDST : function() {
  4785. // adapted from http://extjs.com/forum/showthread.php?p=247172#post247172
  4786. // courtesy of @geoffrey.mcgill
  4787. return new Date(this.getFullYear(), 0, 1).getTimezoneOffset() != this.getTimezoneOffset();
  4788. },
  4789. /**
  4790. * Attempts to clear all time information from this Date by setting the time to midnight of the same day,
  4791. * automatically adjusting for Daylight Saving Time (DST) where applicable.
  4792. * (note: DST timezone information for the browser's host operating system is assumed to be up-to-date)
  4793. * @param {Boolean} clone true to create a clone of this date, clear the time and return it (defaults to false).
  4794. * @return {Date} this or the clone.
  4795. */
  4796. clearTime : function(clone) {
  4797. if (clone) {
  4798. return this.clone().clearTime();
  4799. }
  4800. // get current date before clearing time
  4801. var d = this.getDate();
  4802. // clear time
  4803. this.setHours(0);
  4804. this.setMinutes(0);
  4805. this.setSeconds(0);
  4806. this.setMilliseconds(0);
  4807. if (this.getDate() != d) { // account for DST (i.e. day of month changed when setting hour = 0)
  4808. // note: DST adjustments are assumed to occur in multiples of 1 hour (this is almost always the case)
  4809. // refer to http://www.timeanddate.com/time/aboutdst.html for the (rare) exceptions to this rule
  4810. // increment hour until cloned date == current date
  4811. for (var hr = 1, c = this.add(Date.HOUR, hr); c.getDate() != d; hr++, c = this.add(Date.HOUR, hr));
  4812. this.setDate(d);
  4813. this.setHours(c.getHours());
  4814. }
  4815. return this;
  4816. },
  4817. /**
  4818. * Provides a convenient method for performing basic date arithmetic. This method
  4819. * does not modify the Date instance being called - it creates and returns
  4820. * a new Date instance containing the resulting date value.
  4821. *
  4822. * Examples:
  4823. * <pre><code>
  4824. // Basic usage:
  4825. var dt = new Date('10/29/2006').add(Date.DAY, 5);
  4826. document.write(dt); //returns 'Fri Nov 03 2006 00:00:00'
  4827. // Negative values will be subtracted:
  4828. var dt2 = new Date('10/1/2006').add(Date.DAY, -5);
  4829. document.write(dt2); //returns 'Tue Sep 26 2006 00:00:00'
  4830. // You can even chain several calls together in one line:
  4831. var dt3 = new Date('10/1/2006').add(Date.DAY, 5).add(Date.HOUR, 8).add(Date.MINUTE, -30);
  4832. document.write(dt3); //returns 'Fri Oct 06 2006 07:30:00'
  4833. </code></pre>
  4834. *
  4835. * @param {String} interval A valid date interval enum value.
  4836. * @param {Number} value The amount to add to the current date.
  4837. * @return {Date} The new Date instance.
  4838. */
  4839. add : function(interval, value) {
  4840. var d = this.clone();
  4841. if (!interval || value === 0) return d;
  4842. switch(interval.toLowerCase()) {
  4843. case Date.MILLI:
  4844. d.setMilliseconds(this.getMilliseconds() + value);
  4845. break;
  4846. case Date.SECOND:
  4847. d.setSeconds(this.getSeconds() + value);
  4848. break;
  4849. case Date.MINUTE:
  4850. d.setMinutes(this.getMinutes() + value);
  4851. break;
  4852. case Date.HOUR:
  4853. d.setHours(this.getHours() + value);
  4854. break;
  4855. case Date.DAY:
  4856. d.setDate(this.getDate() + value);
  4857. break;
  4858. case Date.MONTH:
  4859. var day = this.getDate();
  4860. if (day > 28) {
  4861. day = Math.min(day, this.getFirstDateOfMonth().add('mo', value).getLastDateOfMonth().getDate());
  4862. }
  4863. d.setDate(day);
  4864. d.setMonth(this.getMonth() + value);
  4865. break;
  4866. case Date.YEAR:
  4867. d.setFullYear(this.getFullYear() + value);
  4868. break;
  4869. }
  4870. return d;
  4871. },
  4872. /**
  4873. * Checks if this date falls on or between the given start and end dates.
  4874. * @param {Date} start Start date
  4875. * @param {Date} end End date
  4876. * @return {Boolean} true if this date falls on or between the given start and end dates.
  4877. */
  4878. between : function(start, end) {
  4879. var t = this.getTime();
  4880. return start.getTime() <= t && t <= end.getTime();
  4881. }
  4882. });
  4883. /**
  4884. * Formats a date given the supplied format string.
  4885. * @param {String} format The format string.
  4886. * @return {String} The formatted date.
  4887. * @method format
  4888. */
  4889. Date.prototype.format = Date.prototype.dateFormat;
  4890. // private
  4891. if (Ext.isSafari && (navigator.userAgent.match(/WebKit\/(\d+)/)[1] || NaN) < 420) {
  4892. Ext.apply(Date.prototype, {
  4893. _xMonth : Date.prototype.setMonth,
  4894. _xDate : Date.prototype.setDate,
  4895. // Bug in Safari 1.3, 2.0 (WebKit build < 420)
  4896. // Date.setMonth does not work consistently if iMonth is not 0-11
  4897. setMonth : function(num) {
  4898. if (num <= -1) {
  4899. var n = Math.ceil(-num),
  4900. back_year = Math.ceil(n / 12),
  4901. month = (n % 12) ? 12 - n % 12 : 0;
  4902. this.setFullYear(this.getFullYear() - back_year);
  4903. return this._xMonth(month);
  4904. } else {
  4905. return this._xMonth(num);
  4906. }
  4907. },
  4908. // Bug in setDate() method (resolved in WebKit build 419.3, so to be safe we target Webkit builds < 420)
  4909. // The parameter for Date.setDate() is converted to a signed byte integer in Safari
  4910. // http://brianary.blogspot.com/2006/03/safari-date-bug.html
  4911. setDate : function(d) {
  4912. // use setTime() to workaround setDate() bug
  4913. // subtract current day of month in milliseconds, then add desired day of month in milliseconds
  4914. return this.setTime(this.getTime() - (this.getDate() - d) * 864e5);
  4915. }
  4916. });
  4917. }
  4918. /* Some basic Date tests... (requires Firebug)
  4919. Date.parseDate('', 'c'); // call Date.parseDate() once to force computation of regex string so we can console.log() it
  4920. console.log('Insane Regex for "c" format: %o', Date.parseCodes.c.s); // view the insane regex for the "c" format specifier
  4921. // standard tests
  4922. console.group('Standard Date.parseDate() Tests');
  4923. console.log('Date.parseDate("2009-01-05T11:38:56", "c") = %o', Date.parseDate("2009-01-05T11:38:56", "c")); // assumes browser's timezone setting
  4924. console.log('Date.parseDate("2009-02-04T12:37:55.001000", "c") = %o', Date.parseDate("2009-02-04T12:37:55.001000", "c")); // assumes browser's timezone setting
  4925. console.log('Date.parseDate("2009-03-03T13:36:54,101000Z", "c") = %o', Date.parseDate("2009-03-03T13:36:54,101000Z", "c")); // UTC
  4926. console.log('Date.parseDate("2009-04-02T14:35:53.901000-0530", "c") = %o', Date.parseDate("2009-04-02T14:35:53.901000-0530", "c")); // GMT-0530
  4927. console.log('Date.parseDate("2009-05-01T15:34:52,9876000+08:00", "c") = %o', Date.parseDate("2009-05-01T15:34:52,987600+08:00", "c")); // GMT+08:00
  4928. console.groupEnd();
  4929. // ISO-8601 format as specified in http://www.w3.org/TR/NOTE-datetime
  4930. // -- accepts ALL 6 levels of date-time granularity
  4931. console.group('ISO-8601 Granularity Test (see http://www.w3.org/TR/NOTE-datetime)');
  4932. console.log('Date.parseDate("1997", "c") = %o', Date.parseDate("1997", "c")); // YYYY (e.g. 1997)
  4933. console.log('Date.parseDate("1997-07", "c") = %o', Date.parseDate("1997-07", "c")); // YYYY-MM (e.g. 1997-07)
  4934. console.log('Date.parseDate("1997-07-16", "c") = %o', Date.parseDate("1997-07-16", "c")); // YYYY-MM-DD (e.g. 1997-07-16)
  4935. console.log('Date.parseDate("1997-07-16T19:20+01:00", "c") = %o', Date.parseDate("1997-07-16T19:20+01:00", "c")); // YYYY-MM-DDThh:mmTZD (e.g. 1997-07-16T19:20+01:00)
  4936. console.log('Date.parseDate("1997-07-16T19:20:30+01:00", "c") = %o', Date.parseDate("1997-07-16T19:20:30+01:00", "c")); // YYYY-MM-DDThh:mm:ssTZD (e.g. 1997-07-16T19:20:30+01:00)
  4937. console.log('Date.parseDate("1997-07-16T19:20:30.45+01:00", "c") = %o', Date.parseDate("1997-07-16T19:20:30.45+01:00", "c")); // YYYY-MM-DDThh:mm:ss.sTZD (e.g. 1997-07-16T19:20:30.45+01:00)
  4938. console.log('Date.parseDate("1997-07-16 19:20:30.45+01:00", "c") = %o', Date.parseDate("1997-07-16 19:20:30.45+01:00", "c")); // YYYY-MM-DD hh:mm:ss.sTZD (e.g. 1997-07-16T19:20:30.45+01:00)
  4939. console.log('Date.parseDate("1997-13-16T19:20:30.45+01:00", "c", true)= %o', Date.parseDate("1997-13-16T19:20:30.45+01:00", "c", true)); // strict date parsing with invalid month value
  4940. console.groupEnd();
  4941. */
  4942. /**
  4943. * @class Ext.util.MixedCollection
  4944. * @extends Ext.util.Observable
  4945. * A Collection class that maintains both numeric indexes and keys and exposes events.
  4946. * @constructor
  4947. * @param {Boolean} allowFunctions Specify <tt>true</tt> if the {@link #addAll}
  4948. * function should add function references to the collection. Defaults to
  4949. * <tt>false</tt>.
  4950. * @param {Function} keyFn A function that can accept an item of the type(s) stored in this MixedCollection
  4951. * and return the key value for that item. This is used when available to look up the key on items that
  4952. * were passed without an explicit key parameter to a MixedCollection method. Passing this parameter is
  4953. * equivalent to providing an implementation for the {@link #getKey} method.
  4954. */
  4955. Ext.util.MixedCollection = function(allowFunctions, keyFn){
  4956. this.items = [];
  4957. this.map = {};
  4958. this.keys = [];
  4959. this.length = 0;
  4960. this.addEvents(
  4961. /**
  4962. * @event clear
  4963. * Fires when the collection is cleared.
  4964. */
  4965. 'clear',
  4966. /**
  4967. * @event add
  4968. * Fires when an item is added to the collection.
  4969. * @param {Number} index The index at which the item was added.
  4970. * @param {Object} o The item added.
  4971. * @param {String} key The key associated with the added item.
  4972. */
  4973. 'add',
  4974. /**
  4975. * @event replace
  4976. * Fires when an item is replaced in the collection.
  4977. * @param {String} key he key associated with the new added.
  4978. * @param {Object} old The item being replaced.
  4979. * @param {Object} new The new item.
  4980. */
  4981. 'replace',
  4982. /**
  4983. * @event remove
  4984. * Fires when an item is removed from the collection.
  4985. * @param {Object} o The item being removed.
  4986. * @param {String} key (optional) The key associated with the removed item.
  4987. */
  4988. 'remove',
  4989. 'sort'
  4990. );
  4991. this.allowFunctions = allowFunctions === true;
  4992. if(keyFn){
  4993. this.getKey = keyFn;
  4994. }
  4995. Ext.util.MixedCollection.superclass.constructor.call(this);
  4996. };
  4997. Ext.extend(Ext.util.MixedCollection, Ext.util.Observable, {
  4998. /**
  4999. * @cfg {Boolean} allowFunctions Specify <tt>true</tt> if the {@link #addAll}
  5000. * function should add function references to the collection. Defaults to
  5001. * <tt>false</tt>.
  5002. */
  5003. allowFunctions : false,
  5004. /**
  5005. * Adds an item to the collection. Fires the {@link #add} event when complete.
  5006. * @param {String} key <p>The key to associate with the item, or the new item.</p>
  5007. * <p>If a {@link #getKey} implementation was specified for this MixedCollection,
  5008. * or if the key of the stored items is in a property called <tt><b>id</b></tt>,
  5009. * the MixedCollection will be able to <i>derive</i> the key for the new item.
  5010. * In this case just pass the new item in this parameter.</p>
  5011. * @param {Object} o The item to add.
  5012. * @return {Object} The item added.
  5013. */
  5014. add : function(key, o){
  5015. if(arguments.length == 1){
  5016. o = arguments[0];
  5017. key = this.getKey(o);
  5018. }
  5019. if(typeof key != 'undefined' && key !== null){
  5020. var old = this.map[key];
  5021. if(typeof old != 'undefined'){
  5022. return this.replace(key, o);
  5023. }
  5024. this.map[key] = o;
  5025. }
  5026. this.length++;
  5027. this.items.push(o);
  5028. this.keys.push(key);
  5029. this.fireEvent('add', this.length-1, o, key);
  5030. return o;
  5031. },
  5032. /**
  5033. * MixedCollection has a generic way to fetch keys if you implement getKey. The default implementation
  5034. * simply returns <b><code>item.id</code></b> but you can provide your own implementation
  5035. * to return a different value as in the following examples:<pre><code>
  5036. // normal way
  5037. var mc = new Ext.util.MixedCollection();
  5038. mc.add(someEl.dom.id, someEl);
  5039. mc.add(otherEl.dom.id, otherEl);
  5040. //and so on
  5041. // using getKey
  5042. var mc = new Ext.util.MixedCollection();
  5043. mc.getKey = function(el){
  5044. return el.dom.id;
  5045. };
  5046. mc.add(someEl);
  5047. mc.add(otherEl);
  5048. // or via the constructor
  5049. var mc = new Ext.util.MixedCollection(false, function(el){
  5050. return el.dom.id;
  5051. });
  5052. mc.add(someEl);
  5053. mc.add(otherEl);
  5054. * </code></pre>
  5055. * @param {Object} item The item for which to find the key.
  5056. * @return {Object} The key for the passed item.
  5057. */
  5058. getKey : function(o){
  5059. return o.id;
  5060. },
  5061. /**
  5062. * Replaces an item in the collection. Fires the {@link #replace} event when complete.
  5063. * @param {String} key <p>The key associated with the item to replace, or the replacement item.</p>
  5064. * <p>If you supplied a {@link #getKey} implementation for this MixedCollection, or if the key
  5065. * of your stored items is in a property called <tt><b>id</b></tt>, then the MixedCollection
  5066. * will be able to <i>derive</i> the key of the replacement item. If you want to replace an item
  5067. * with one having the same key value, then just pass the replacement item in this parameter.</p>
  5068. * @param o {Object} o (optional) If the first parameter passed was a key, the item to associate
  5069. * with that key.
  5070. * @return {Object} The new item.
  5071. */
  5072. replace : function(key, o){
  5073. if(arguments.length == 1){
  5074. o = arguments[0];
  5075. key = this.getKey(o);
  5076. }
  5077. var old = this.map[key];
  5078. if(typeof key == 'undefined' || key === null || typeof old == 'undefined'){
  5079. return this.add(key, o);
  5080. }
  5081. var index = this.indexOfKey(key);
  5082. this.items[index] = o;
  5083. this.map[key] = o;
  5084. this.fireEvent('replace', key, old, o);
  5085. return o;
  5086. },
  5087. /**
  5088. * Adds all elements of an Array or an Object to the collection.
  5089. * @param {Object/Array} objs An Object containing properties which will be added
  5090. * to the collection, or an Array of values, each of which are added to the collection.
  5091. * Functions references will be added to the collection if <code>{@link #allowFunctions}</code>
  5092. * has been set to <tt>true</tt>.
  5093. */
  5094. addAll : function(objs){
  5095. if(arguments.length > 1 || Ext.isArray(objs)){
  5096. var args = arguments.length > 1 ? arguments : objs;
  5097. for(var i = 0, len = args.length; i < len; i++){
  5098. this.add(args[i]);
  5099. }
  5100. }else{
  5101. for(var key in objs){
  5102. if(this.allowFunctions || typeof objs[key] != 'function'){
  5103. this.add(key, objs[key]);
  5104. }
  5105. }
  5106. }
  5107. },
  5108. /**
  5109. * Executes the specified function once for every item in the collection, passing the following arguments:
  5110. * <div class="mdetail-params"><ul>
  5111. * <li><b>item</b> : Mixed<p class="sub-desc">The collection item</p></li>
  5112. * <li><b>index</b> : Number<p class="sub-desc">The item's index</p></li>
  5113. * <li><b>length</b> : Number<p class="sub-desc">The total number of items in the collection</p></li>
  5114. * </ul></div>
  5115. * The function should return a boolean value. Returning false from the function will stop the iteration.
  5116. * @param {Function} fn The function to execute for each item.
  5117. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the current item in the iteration.
  5118. */
  5119. each : function(fn, scope){
  5120. var items = [].concat(this.items); // each safe for removal
  5121. for(var i = 0, len = items.length; i < len; i++){
  5122. if(fn.call(scope || items[i], items[i], i, len) === false){
  5123. break;
  5124. }
  5125. }
  5126. },
  5127. /**
  5128. * Executes the specified function once for every key in the collection, passing each
  5129. * key, and its associated item as the first two parameters.
  5130. * @param {Function} fn The function to execute for each item.
  5131. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the browser window.
  5132. */
  5133. eachKey : function(fn, scope){
  5134. for(var i = 0, len = this.keys.length; i < len; i++){
  5135. fn.call(scope || window, this.keys[i], this.items[i], i, len);
  5136. }
  5137. },
  5138. /**
  5139. * Returns the first item in the collection which elicits a true return value from the
  5140. * passed selection function.
  5141. * @param {Function} fn The selection function to execute for each item.
  5142. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the browser window.
  5143. * @return {Object} The first item in the collection which returned true from the selection function.
  5144. */
  5145. find : function(fn, scope){
  5146. for(var i = 0, len = this.items.length; i < len; i++){
  5147. if(fn.call(scope || window, this.items[i], this.keys[i])){
  5148. return this.items[i];
  5149. }
  5150. }
  5151. return null;
  5152. },
  5153. /**
  5154. * Inserts an item at the specified index in the collection. Fires the {@link #add} event when complete.
  5155. * @param {Number} index The index to insert the item at.
  5156. * @param {String} key The key to associate with the new item, or the item itself.
  5157. * @param {Object} o (optional) If the second parameter was a key, the new item.
  5158. * @return {Object} The item inserted.
  5159. */
  5160. insert : function(index, key, o){
  5161. if(arguments.length == 2){
  5162. o = arguments[1];
  5163. key = this.getKey(o);
  5164. }
  5165. if(this.containsKey(key)){
  5166. this.suspendEvents();
  5167. this.removeKey(key);
  5168. this.resumeEvents();
  5169. }
  5170. if(index >= this.length){
  5171. return this.add(key, o);
  5172. }
  5173. this.length++;
  5174. this.items.splice(index, 0, o);
  5175. if(typeof key != 'undefined' && key !== null){
  5176. this.map[key] = o;
  5177. }
  5178. this.keys.splice(index, 0, key);
  5179. this.fireEvent('add', index, o, key);
  5180. return o;
  5181. },
  5182. /**
  5183. * Remove an item from the collection.
  5184. * @param {Object} o The item to remove.
  5185. * @return {Object} The item removed or false if no item was removed.
  5186. */
  5187. remove : function(o){
  5188. return this.removeAt(this.indexOf(o));
  5189. },
  5190. /**
  5191. * Remove an item from a specified index in the collection. Fires the {@link #remove} event when complete.
  5192. * @param {Number} index The index within the collection of the item to remove.
  5193. * @return {Object} The item removed or false if no item was removed.
  5194. */
  5195. removeAt : function(index){
  5196. if(index < this.length && index >= 0){
  5197. this.length--;
  5198. var o = this.items[index];
  5199. this.items.splice(index, 1);
  5200. var key = this.keys[index];
  5201. if(typeof key != 'undefined'){
  5202. delete this.map[key];
  5203. }
  5204. this.keys.splice(index, 1);
  5205. this.fireEvent('remove', o, key);
  5206. return o;
  5207. }
  5208. return false;
  5209. },
  5210. /**
  5211. * Removed an item associated with the passed key fom the collection.
  5212. * @param {String} key The key of the item to remove.
  5213. * @return {Object} The item removed or false if no item was removed.
  5214. */
  5215. removeKey : function(key){
  5216. return this.removeAt(this.indexOfKey(key));
  5217. },
  5218. /**
  5219. * Returns the number of items in the collection.
  5220. * @return {Number} the number of items in the collection.
  5221. */
  5222. getCount : function(){
  5223. return this.length;
  5224. },
  5225. /**
  5226. * Returns index within the collection of the passed Object.
  5227. * @param {Object} o The item to find the index of.
  5228. * @return {Number} index of the item. Returns -1 if not found.
  5229. */
  5230. indexOf : function(o){
  5231. return this.items.indexOf(o);
  5232. },
  5233. /**
  5234. * Returns index within the collection of the passed key.
  5235. * @param {String} key The key to find the index of.
  5236. * @return {Number} index of the key.
  5237. */
  5238. indexOfKey : function(key){
  5239. return this.keys.indexOf(key);
  5240. },
  5241. /**
  5242. * Returns the item associated with the passed key OR index.
  5243. * Key has priority over index. This is the equivalent
  5244. * of calling {@link #key} first, then if nothing matched calling {@link #itemAt}.
  5245. * @param {String/Number} key The key or index of the item.
  5246. * @return {Object} If the item is found, returns the item. If the item was not found, returns <tt>undefined</tt>.
  5247. * If an item was found, but is a Class, returns <tt>null</tt>.
  5248. */
  5249. item : function(key){
  5250. var mk = this.map[key],
  5251. item = mk !== undefined ? mk : (typeof key == 'number') ? this.items[key] : undefined;
  5252. return typeof item != 'function' || this.allowFunctions ? item : null; // for prototype!
  5253. },
  5254. /**
  5255. * Returns the item at the specified index.
  5256. * @param {Number} index The index of the item.
  5257. * @return {Object} The item at the specified index.
  5258. */
  5259. itemAt : function(index){
  5260. return this.items[index];
  5261. },
  5262. /**
  5263. * Returns the item associated with the passed key.
  5264. * @param {String/Number} key The key of the item.
  5265. * @return {Object} The item associated with the passed key.
  5266. */
  5267. key : function(key){
  5268. return this.map[key];
  5269. },
  5270. /**
  5271. * Returns true if the collection contains the passed Object as an item.
  5272. * @param {Object} o The Object to look for in the collection.
  5273. * @return {Boolean} True if the collection contains the Object as an item.
  5274. */
  5275. contains : function(o){
  5276. return this.indexOf(o) != -1;
  5277. },
  5278. /**
  5279. * Returns true if the collection contains the passed Object as a key.
  5280. * @param {String} key The key to look for in the collection.
  5281. * @return {Boolean} True if the collection contains the Object as a key.
  5282. */
  5283. containsKey : function(key){
  5284. return typeof this.map[key] != 'undefined';
  5285. },
  5286. /**
  5287. * Removes all items from the collection. Fires the {@link #clear} event when complete.
  5288. */
  5289. clear : function(){
  5290. this.length = 0;
  5291. this.items = [];
  5292. this.keys = [];
  5293. this.map = {};
  5294. this.fireEvent('clear');
  5295. },
  5296. /**
  5297. * Returns the first item in the collection.
  5298. * @return {Object} the first item in the collection..
  5299. */
  5300. first : function(){
  5301. return this.items[0];
  5302. },
  5303. /**
  5304. * Returns the last item in the collection.
  5305. * @return {Object} the last item in the collection..
  5306. */
  5307. last : function(){
  5308. return this.items[this.length-1];
  5309. },
  5310. /**
  5311. * @private
  5312. * Performs the actual sorting based on a direction and a sorting function. Internally,
  5313. * this creates a temporary array of all items in the MixedCollection, sorts it and then writes
  5314. * the sorted array data back into this.items and this.keys
  5315. * @param {String} property Property to sort by ('key', 'value', or 'index')
  5316. * @param {String} dir (optional) Direction to sort 'ASC' or 'DESC'. Defaults to 'ASC'.
  5317. * @param {Function} fn (optional) Comparison function that defines the sort order.
  5318. * Defaults to sorting by numeric value.
  5319. */
  5320. _sort : function(property, dir, fn){
  5321. var i, len,
  5322. dsc = String(dir).toUpperCase() == 'DESC' ? -1 : 1,
  5323. //this is a temporary array used to apply the sorting function
  5324. c = [],
  5325. keys = this.keys,
  5326. items = this.items;
  5327. //default to a simple sorter function if one is not provided
  5328. fn = fn || function(a, b) {
  5329. return a - b;
  5330. };
  5331. //copy all the items into a temporary array, which we will sort
  5332. for(i = 0, len = items.length; i < len; i++){
  5333. c[c.length] = {
  5334. key : keys[i],
  5335. value: items[i],
  5336. index: i
  5337. };
  5338. }
  5339. //sort the temporary array
  5340. c.sort(function(a, b){
  5341. var v = fn(a[property], b[property]) * dsc;
  5342. if(v === 0){
  5343. v = (a.index < b.index ? -1 : 1);
  5344. }
  5345. return v;
  5346. });
  5347. //copy the temporary array back into the main this.items and this.keys objects
  5348. for(i = 0, len = c.length; i < len; i++){
  5349. items[i] = c[i].value;
  5350. keys[i] = c[i].key;
  5351. }
  5352. this.fireEvent('sort', this);
  5353. },
  5354. /**
  5355. * Sorts this collection by <b>item</b> value with the passed comparison function.
  5356. * @param {String} direction (optional) 'ASC' or 'DESC'. Defaults to 'ASC'.
  5357. * @param {Function} fn (optional) Comparison function that defines the sort order.
  5358. * Defaults to sorting by numeric value.
  5359. */
  5360. sort : function(dir, fn){
  5361. this._sort('value', dir, fn);
  5362. },
  5363. /**
  5364. * Reorders each of the items based on a mapping from old index to new index. Internally this
  5365. * just translates into a sort. The 'sort' event is fired whenever reordering has occured.
  5366. * @param {Object} mapping Mapping from old item index to new item index
  5367. */
  5368. reorder: function(mapping) {
  5369. this.suspendEvents();
  5370. var items = this.items,
  5371. index = 0,
  5372. length = items.length,
  5373. order = [],
  5374. remaining = [],
  5375. oldIndex;
  5376. //object of {oldPosition: newPosition} reversed to {newPosition: oldPosition}
  5377. for (oldIndex in mapping) {
  5378. order[mapping[oldIndex]] = items[oldIndex];
  5379. }
  5380. for (index = 0; index < length; index++) {
  5381. if (mapping[index] == undefined) {
  5382. remaining.push(items[index]);
  5383. }
  5384. }
  5385. for (index = 0; index < length; index++) {
  5386. if (order[index] == undefined) {
  5387. order[index] = remaining.shift();
  5388. }
  5389. }
  5390. this.clear();
  5391. this.addAll(order);
  5392. this.resumeEvents();
  5393. this.fireEvent('sort', this);
  5394. },
  5395. /**
  5396. * Sorts this collection by <b>key</b>s.
  5397. * @param {String} direction (optional) 'ASC' or 'DESC'. Defaults to 'ASC'.
  5398. * @param {Function} fn (optional) Comparison function that defines the sort order.
  5399. * Defaults to sorting by case insensitive string.
  5400. */
  5401. keySort : function(dir, fn){
  5402. this._sort('key', dir, fn || function(a, b){
  5403. var v1 = String(a).toUpperCase(), v2 = String(b).toUpperCase();
  5404. return v1 > v2 ? 1 : (v1 < v2 ? -1 : 0);
  5405. });
  5406. },
  5407. /**
  5408. * Returns a range of items in this collection
  5409. * @param {Number} startIndex (optional) The starting index. Defaults to 0.
  5410. * @param {Number} endIndex (optional) The ending index. Defaults to the last item.
  5411. * @return {Array} An array of items
  5412. */
  5413. getRange : function(start, end){
  5414. var items = this.items;
  5415. if(items.length < 1){
  5416. return [];
  5417. }
  5418. start = start || 0;
  5419. end = Math.min(typeof end == 'undefined' ? this.length-1 : end, this.length-1);
  5420. var i, r = [];
  5421. if(start <= end){
  5422. for(i = start; i <= end; i++) {
  5423. r[r.length] = items[i];
  5424. }
  5425. }else{
  5426. for(i = start; i >= end; i--) {
  5427. r[r.length] = items[i];
  5428. }
  5429. }
  5430. return r;
  5431. },
  5432. /**
  5433. * Filter the <i>objects</i> in this collection by a specific property.
  5434. * Returns a new collection that has been filtered.
  5435. * @param {String} property A property on your objects
  5436. * @param {String/RegExp} value Either string that the property values
  5437. * should start with or a RegExp to test against the property
  5438. * @param {Boolean} anyMatch (optional) True to match any part of the string, not just the beginning
  5439. * @param {Boolean} caseSensitive (optional) True for case sensitive comparison (defaults to False).
  5440. * @return {MixedCollection} The new filtered collection
  5441. */
  5442. filter : function(property, value, anyMatch, caseSensitive){
  5443. if(Ext.isEmpty(value, false)){
  5444. return this.clone();
  5445. }
  5446. value = this.createValueMatcher(value, anyMatch, caseSensitive);
  5447. return this.filterBy(function(o){
  5448. return o && value.test(o[property]);
  5449. });
  5450. },
  5451. /**
  5452. * Filter by a function. Returns a <i>new</i> collection that has been filtered.
  5453. * The passed function will be called with each object in the collection.
  5454. * If the function returns true, the value is included otherwise it is filtered.
  5455. * @param {Function} fn The function to be called, it will receive the args o (the object), k (the key)
  5456. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to this MixedCollection.
  5457. * @return {MixedCollection} The new filtered collection
  5458. */
  5459. filterBy : function(fn, scope){
  5460. var r = new Ext.util.MixedCollection();
  5461. r.getKey = this.getKey;
  5462. var k = this.keys, it = this.items;
  5463. for(var i = 0, len = it.length; i < len; i++){
  5464. if(fn.call(scope||this, it[i], k[i])){
  5465. r.add(k[i], it[i]);
  5466. }
  5467. }
  5468. return r;
  5469. },
  5470. /**
  5471. * Finds the index of the first matching object in this collection by a specific property/value.
  5472. * @param {String} property The name of a property on your objects.
  5473. * @param {String/RegExp} value A string that the property values
  5474. * should start with or a RegExp to test against the property.
  5475. * @param {Number} start (optional) The index to start searching at (defaults to 0).
  5476. * @param {Boolean} anyMatch (optional) True to match any part of the string, not just the beginning.
  5477. * @param {Boolean} caseSensitive (optional) True for case sensitive comparison.
  5478. * @return {Number} The matched index or -1
  5479. */
  5480. findIndex : function(property, value, start, anyMatch, caseSensitive){
  5481. if(Ext.isEmpty(value, false)){
  5482. return -1;
  5483. }
  5484. value = this.createValueMatcher(value, anyMatch, caseSensitive);
  5485. return this.findIndexBy(function(o){
  5486. return o && value.test(o[property]);
  5487. }, null, start);
  5488. },
  5489. /**
  5490. * Find the index of the first matching object in this collection by a function.
  5491. * If the function returns <i>true</i> it is considered a match.
  5492. * @param {Function} fn The function to be called, it will receive the args o (the object), k (the key).
  5493. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to this MixedCollection.
  5494. * @param {Number} start (optional) The index to start searching at (defaults to 0).
  5495. * @return {Number} The matched index or -1
  5496. */
  5497. findIndexBy : function(fn, scope, start){
  5498. var k = this.keys, it = this.items;
  5499. for(var i = (start||0), len = it.length; i < len; i++){
  5500. if(fn.call(scope||this, it[i], k[i])){
  5501. return i;
  5502. }
  5503. }
  5504. return -1;
  5505. },
  5506. /**
  5507. * Returns a regular expression based on the given value and matching options. This is used internally for finding and filtering,
  5508. * and by Ext.data.Store#filter
  5509. * @private
  5510. * @param {String} value The value to create the regex for. This is escaped using Ext.escapeRe
  5511. * @param {Boolean} anyMatch True to allow any match - no regex start/end line anchors will be added. Defaults to false
  5512. * @param {Boolean} caseSensitive True to make the regex case sensitive (adds 'i' switch to regex). Defaults to false.
  5513. * @param {Boolean} exactMatch True to force exact match (^ and $ characters added to the regex). Defaults to false. Ignored if anyMatch is true.
  5514. */
  5515. createValueMatcher : function(value, anyMatch, caseSensitive, exactMatch) {
  5516. if (!value.exec) { // not a regex
  5517. var er = Ext.escapeRe;
  5518. value = String(value);
  5519. if (anyMatch === true) {
  5520. value = er(value);
  5521. } else {
  5522. value = '^' + er(value);
  5523. if (exactMatch === true) {
  5524. value += '$';
  5525. }
  5526. }
  5527. value = new RegExp(value, caseSensitive ? '' : 'i');
  5528. }
  5529. return value;
  5530. },
  5531. /**
  5532. * Creates a shallow copy of this collection
  5533. * @return {MixedCollection}
  5534. */
  5535. clone : function(){
  5536. var r = new Ext.util.MixedCollection();
  5537. var k = this.keys, it = this.items;
  5538. for(var i = 0, len = it.length; i < len; i++){
  5539. r.add(k[i], it[i]);
  5540. }
  5541. r.getKey = this.getKey;
  5542. return r;
  5543. }
  5544. });
  5545. /**
  5546. * This method calls {@link #item item()}.
  5547. * Returns the item associated with the passed key OR index. Key has priority
  5548. * over index. This is the equivalent of calling {@link #key} first, then if
  5549. * nothing matched calling {@link #itemAt}.
  5550. * @param {String/Number} key The key or index of the item.
  5551. * @return {Object} If the item is found, returns the item. If the item was
  5552. * not found, returns <tt>undefined</tt>. If an item was found, but is a Class,
  5553. * returns <tt>null</tt>.
  5554. */
  5555. Ext.util.MixedCollection.prototype.get = Ext.util.MixedCollection.prototype.item;
  5556. /**
  5557. * @class Ext.AbstractManager
  5558. * @extends Object
  5559. * Base Manager class - extended by ComponentMgr and PluginMgr
  5560. */
  5561. Ext.AbstractManager = Ext.extend(Object, {
  5562. typeName: 'type',
  5563. constructor: function(config) {
  5564. Ext.apply(this, config || {});
  5565. /**
  5566. * Contains all of the items currently managed
  5567. * @property all
  5568. * @type Ext.util.MixedCollection
  5569. */
  5570. this.all = new Ext.util.MixedCollection();
  5571. this.types = {};
  5572. },
  5573. /**
  5574. * Returns a component by {@link Ext.Component#id id}.
  5575. * For additional details see {@link Ext.util.MixedCollection#get}.
  5576. * @param {String} id The component {@link Ext.Component#id id}
  5577. * @return Ext.Component The Component, <code>undefined</code> if not found, or <code>null</code> if a
  5578. * Class was found.
  5579. */
  5580. get : function(id){
  5581. return this.all.get(id);
  5582. },
  5583. /**
  5584. * Registers an item to be managed
  5585. * @param {Mixed} item The item to register
  5586. */
  5587. register: function(item) {
  5588. this.all.add(item);
  5589. },
  5590. /**
  5591. * Unregisters a component by removing it from this manager
  5592. * @param {Mixed} item The item to unregister
  5593. */
  5594. unregister: function(item) {
  5595. this.all.remove(item);
  5596. },
  5597. /**
  5598. * <p>Registers a new Component constructor, keyed by a new
  5599. * {@link Ext.Component#xtype}.</p>
  5600. * <p>Use this method (or its alias {@link Ext#reg Ext.reg}) to register new
  5601. * subclasses of {@link Ext.Component} so that lazy instantiation may be used when specifying
  5602. * child Components.
  5603. * see {@link Ext.Container#items}</p>
  5604. * @param {String} xtype The mnemonic string by which the Component class may be looked up.
  5605. * @param {Constructor} cls The new Component class.
  5606. */
  5607. registerType : function(type, cls){
  5608. this.types[type] = cls;
  5609. cls[this.typeName] = type;
  5610. },
  5611. /**
  5612. * Checks if a Component type is registered.
  5613. * @param {Ext.Component} xtype The mnemonic string by which the Component class may be looked up
  5614. * @return {Boolean} Whether the type is registered.
  5615. */
  5616. isRegistered : function(type){
  5617. return this.types[type] !== undefined;
  5618. },
  5619. /**
  5620. * Creates and returns an instance of whatever this manager manages, based on the supplied type and config object
  5621. * @param {Object} config The config object
  5622. * @param {String} defaultType If no type is discovered in the config object, we fall back to this type
  5623. * @return {Mixed} The instance of whatever this manager is managing
  5624. */
  5625. create: function(config, defaultType) {
  5626. var type = config[this.typeName] || config.type || defaultType,
  5627. Constructor = this.types[type];
  5628. if (Constructor == undefined) {
  5629. throw new Error(String.format("The '{0}' type has not been registered with this manager", type));
  5630. }
  5631. return new Constructor(config);
  5632. },
  5633. /**
  5634. * Registers a function that will be called when a Component with the specified id is added to the manager. This will happen on instantiation.
  5635. * @param {String} id The component {@link Ext.Component#id id}
  5636. * @param {Function} fn The callback function
  5637. * @param {Object} scope The scope (<code>this</code> reference) in which the callback is executed. Defaults to the Component.
  5638. */
  5639. onAvailable : function(id, fn, scope){
  5640. var all = this.all;
  5641. all.on("add", function(index, o){
  5642. if (o.id == id) {
  5643. fn.call(scope || o, o);
  5644. all.un("add", fn, scope);
  5645. }
  5646. });
  5647. }
  5648. });/**
  5649. * @class Ext.util.Format
  5650. * Reusable data formatting functions
  5651. * @singleton
  5652. */
  5653. Ext.util.Format = function() {
  5654. var trimRe = /^\s+|\s+$/g,
  5655. stripTagsRE = /<\/?[^>]+>/gi,
  5656. stripScriptsRe = /(?:<script.*?>)((\n|\r|.)*?)(?:<\/script>)/ig,
  5657. nl2brRe = /\r?\n/g;
  5658. return {
  5659. /**
  5660. * Truncate a string and add an ellipsis ('...') to the end if it exceeds the specified length
  5661. * @param {String} value The string to truncate
  5662. * @param {Number} length The maximum length to allow before truncating
  5663. * @param {Boolean} word True to try to find a common work break
  5664. * @return {String} The converted text
  5665. */
  5666. ellipsis : function(value, len, word) {
  5667. if (value && value.length > len) {
  5668. if (word) {
  5669. var vs = value.substr(0, len - 2),
  5670. index = Math.max(vs.lastIndexOf(' '), vs.lastIndexOf('.'), vs.lastIndexOf('!'), vs.lastIndexOf('?'));
  5671. if (index == -1 || index < (len - 15)) {
  5672. return value.substr(0, len - 3) + "...";
  5673. } else {
  5674. return vs.substr(0, index) + "...";
  5675. }
  5676. } else {
  5677. return value.substr(0, len - 3) + "...";
  5678. }
  5679. }
  5680. return value;
  5681. },
  5682. /**
  5683. * Checks a reference and converts it to empty string if it is undefined
  5684. * @param {Mixed} value Reference to check
  5685. * @return {Mixed} Empty string if converted, otherwise the original value
  5686. */
  5687. undef : function(value) {
  5688. return value !== undefined ? value : "";
  5689. },
  5690. /**
  5691. * Checks a reference and converts it to the default value if it's empty
  5692. * @param {Mixed} value Reference to check
  5693. * @param {String} defaultValue The value to insert of it's undefined (defaults to "")
  5694. * @return {String}
  5695. */
  5696. defaultValue : function(value, defaultValue) {
  5697. return value !== undefined && value !== '' ? value : defaultValue;
  5698. },
  5699. /**
  5700. * Convert certain characters (&, <, >, and ') to their HTML character equivalents for literal display in web pages.
  5701. * @param {String} value The string to encode
  5702. * @return {String} The encoded text
  5703. */
  5704. htmlEncode : function(value) {
  5705. return !value ? value : String(value).replace(/&/g, "&amp;").replace(/>/g, "&gt;").replace(/</g, "&lt;").replace(/"/g, "&quot;");
  5706. },
  5707. /**
  5708. * Convert certain characters (&, <, >, and ') from their HTML character equivalents.
  5709. * @param {String} value The string to decode
  5710. * @return {String} The decoded text
  5711. */
  5712. htmlDecode : function(value) {
  5713. return !value ? value : String(value).replace(/&gt;/g, ">").replace(/&lt;/g, "<").replace(/&quot;/g, '"').replace(/&amp;/g, "&");
  5714. },
  5715. /**
  5716. * Trims any whitespace from either side of a string
  5717. * @param {String} value The text to trim
  5718. * @return {String} The trimmed text
  5719. */
  5720. trim : function(value) {
  5721. return String(value).replace(trimRe, "");
  5722. },
  5723. /**
  5724. * Returns a substring from within an original string
  5725. * @param {String} value The original text
  5726. * @param {Number} start The start index of the substring
  5727. * @param {Number} length The length of the substring
  5728. * @return {String} The substring
  5729. */
  5730. substr : function(value, start, length) {
  5731. return String(value).substr(start, length);
  5732. },
  5733. /**
  5734. * Converts a string to all lower case letters
  5735. * @param {String} value The text to convert
  5736. * @return {String} The converted text
  5737. */
  5738. lowercase : function(value) {
  5739. return String(value).toLowerCase();
  5740. },
  5741. /**
  5742. * Converts a string to all upper case letters
  5743. * @param {String} value The text to convert
  5744. * @return {String} The converted text
  5745. */
  5746. uppercase : function(value) {
  5747. return String(value).toUpperCase();
  5748. },
  5749. /**
  5750. * Converts the first character only of a string to upper case
  5751. * @param {String} value The text to convert
  5752. * @return {String} The converted text
  5753. */
  5754. capitalize : function(value) {
  5755. return !value ? value : value.charAt(0).toUpperCase() + value.substr(1).toLowerCase();
  5756. },
  5757. // private
  5758. call : function(value, fn) {
  5759. if (arguments.length > 2) {
  5760. var args = Array.prototype.slice.call(arguments, 2);
  5761. args.unshift(value);
  5762. return eval(fn).apply(window, args);
  5763. } else {
  5764. return eval(fn).call(window, value);
  5765. }
  5766. },
  5767. /**
  5768. * Format a number as US currency
  5769. * @param {Number/String} value The numeric value to format
  5770. * @return {String} The formatted currency string
  5771. */
  5772. usMoney : function(v) {
  5773. v = (Math.round((v-0)*100))/100;
  5774. v = (v == Math.floor(v)) ? v + ".00" : ((v*10 == Math.floor(v*10)) ? v + "0" : v);
  5775. v = String(v);
  5776. var ps = v.split('.'),
  5777. whole = ps[0],
  5778. sub = ps[1] ? '.'+ ps[1] : '.00',
  5779. r = /(\d+)(\d{3})/;
  5780. while (r.test(whole)) {
  5781. whole = whole.replace(r, '$1' + ',' + '$2');
  5782. }
  5783. v = whole + sub;
  5784. if (v.charAt(0) == '-') {
  5785. return '-$' + v.substr(1);
  5786. }
  5787. return "$" + v;
  5788. },
  5789. /**
  5790. * Parse a value into a formatted date using the specified format pattern.
  5791. * @param {String/Date} value The value to format (Strings must conform to the format expected by the javascript Date object's <a href="http://www.w3schools.com/jsref/jsref_parse.asp">parse()</a> method)
  5792. * @param {String} format (optional) Any valid date format string (defaults to 'm/d/Y')
  5793. * @return {String} The formatted date string
  5794. */
  5795. date : function(v, format) {
  5796. if (!v) {
  5797. return "";
  5798. }
  5799. if (!Ext.isDate(v)) {
  5800. v = new Date(Date.parse(v));
  5801. }
  5802. return v.dateFormat(format || "m/d/Y");
  5803. },
  5804. /**
  5805. * Returns a date rendering function that can be reused to apply a date format multiple times efficiently
  5806. * @param {String} format Any valid date format string
  5807. * @return {Function} The date formatting function
  5808. */
  5809. dateRenderer : function(format) {
  5810. return function(v) {
  5811. return Ext.util.Format.date(v, format);
  5812. };
  5813. },
  5814. /**
  5815. * Strips all HTML tags
  5816. * @param {Mixed} value The text from which to strip tags
  5817. * @return {String} The stripped text
  5818. */
  5819. stripTags : function(v) {
  5820. return !v ? v : String(v).replace(stripTagsRE, "");
  5821. },
  5822. /**
  5823. * Strips all script tags
  5824. * @param {Mixed} value The text from which to strip script tags
  5825. * @return {String} The stripped text
  5826. */
  5827. stripScripts : function(v) {
  5828. return !v ? v : String(v).replace(stripScriptsRe, "");
  5829. },
  5830. /**
  5831. * Simple format for a file size (xxx bytes, xxx KB, xxx MB)
  5832. * @param {Number/String} size The numeric value to format
  5833. * @return {String} The formatted file size
  5834. */
  5835. fileSize : function(size) {
  5836. if (size < 1024) {
  5837. return size + " bytes";
  5838. } else if (size < 1048576) {
  5839. return (Math.round(((size*10) / 1024))/10) + " KB";
  5840. } else {
  5841. return (Math.round(((size*10) / 1048576))/10) + " MB";
  5842. }
  5843. },
  5844. /**
  5845. * It does simple math for use in a template, for example:<pre><code>
  5846. * var tpl = new Ext.Template('{value} * 10 = {value:math("* 10")}');
  5847. * </code></pre>
  5848. * @return {Function} A function that operates on the passed value.
  5849. */
  5850. math : function(){
  5851. var fns = {};
  5852. return function(v, a){
  5853. if (!fns[a]) {
  5854. fns[a] = new Function('v', 'return v ' + a + ';');
  5855. }
  5856. return fns[a](v);
  5857. };
  5858. }(),
  5859. /**
  5860. * Rounds the passed number to the required decimal precision.
  5861. * @param {Number/String} value The numeric value to round.
  5862. * @param {Number} precision The number of decimal places to which to round the first parameter's value.
  5863. * @return {Number} The rounded value.
  5864. */
  5865. round : function(value, precision) {
  5866. var result = Number(value);
  5867. if (typeof precision == 'number') {
  5868. precision = Math.pow(10, precision);
  5869. result = Math.round(value * precision) / precision;
  5870. }
  5871. return result;
  5872. },
  5873. /**
  5874. * Formats the number according to the format string.
  5875. * <div style="margin-left:40px">examples (123456.789):
  5876. * <div style="margin-left:10px">
  5877. * 0 - (123456) show only digits, no precision<br>
  5878. * 0.00 - (123456.78) show only digits, 2 precision<br>
  5879. * 0.0000 - (123456.7890) show only digits, 4 precision<br>
  5880. * 0,000 - (123,456) show comma and digits, no precision<br>
  5881. * 0,000.00 - (123,456.78) show comma and digits, 2 precision<br>
  5882. * 0,0.00 - (123,456.78) shortcut method, show comma and digits, 2 precision<br>
  5883. * To reverse the grouping (,) and decimal (.) for international numbers, add /i to the end.
  5884. * For example: 0.000,00/i
  5885. * </div></div>
  5886. * @param {Number} v The number to format.
  5887. * @param {String} format The way you would like to format this text.
  5888. * @return {String} The formatted number.
  5889. */
  5890. number: function(v, format) {
  5891. if (!format) {
  5892. return v;
  5893. }
  5894. v = Ext.num(v, NaN);
  5895. if (isNaN(v)) {
  5896. return '';
  5897. }
  5898. var comma = ',',
  5899. dec = '.',
  5900. i18n = false,
  5901. neg = v < 0;
  5902. v = Math.abs(v);
  5903. if (format.substr(format.length - 2) == '/i') {
  5904. format = format.substr(0, format.length - 2);
  5905. i18n = true;
  5906. comma = '.';
  5907. dec = ',';
  5908. }
  5909. var hasComma = format.indexOf(comma) != -1,
  5910. psplit = (i18n ? format.replace(/[^\d\,]/g, '') : format.replace(/[^\d\.]/g, '')).split(dec);
  5911. if (1 < psplit.length) {
  5912. v = v.toFixed(psplit[1].length);
  5913. } else if(2 < psplit.length) {
  5914. throw ('NumberFormatException: invalid format, formats should have no more than 1 period: ' + format);
  5915. } else {
  5916. v = v.toFixed(0);
  5917. }
  5918. var fnum = v.toString();
  5919. psplit = fnum.split('.');
  5920. if (hasComma) {
  5921. var cnum = psplit[0],
  5922. parr = [],
  5923. j = cnum.length,
  5924. m = Math.floor(j / 3),
  5925. n = cnum.length % 3 || 3,
  5926. i;
  5927. for (i = 0; i < j; i += n) {
  5928. if (i != 0) {
  5929. n = 3;
  5930. }
  5931. parr[parr.length] = cnum.substr(i, n);
  5932. m -= 1;
  5933. }
  5934. fnum = parr.join(comma);
  5935. if (psplit[1]) {
  5936. fnum += dec + psplit[1];
  5937. }
  5938. } else {
  5939. if (psplit[1]) {
  5940. fnum = psplit[0] + dec + psplit[1];
  5941. }
  5942. }
  5943. return (neg ? '-' : '') + format.replace(/[\d,?\.?]+/, fnum);
  5944. },
  5945. /**
  5946. * Returns a number rendering function that can be reused to apply a number format multiple times efficiently
  5947. * @param {String} format Any valid number format string for {@link #number}
  5948. * @return {Function} The number formatting function
  5949. */
  5950. numberRenderer : function(format) {
  5951. return function(v) {
  5952. return Ext.util.Format.number(v, format);
  5953. };
  5954. },
  5955. /**
  5956. * Selectively do a plural form of a word based on a numeric value. For example, in a template,
  5957. * {commentCount:plural("Comment")} would result in "1 Comment" if commentCount was 1 or would be "x Comments"
  5958. * if the value is 0 or greater than 1.
  5959. * @param {Number} value The value to compare against
  5960. * @param {String} singular The singular form of the word
  5961. * @param {String} plural (optional) The plural form of the word (defaults to the singular with an "s")
  5962. */
  5963. plural : function(v, s, p) {
  5964. return v +' ' + (v == 1 ? s : (p ? p : s+'s'));
  5965. },
  5966. /**
  5967. * Converts newline characters to the HTML tag &lt;br/>
  5968. * @param {String} The string value to format.
  5969. * @return {String} The string with embedded &lt;br/> tags in place of newlines.
  5970. */
  5971. nl2br : function(v) {
  5972. return Ext.isEmpty(v) ? '' : v.replace(nl2brRe, '<br/>');
  5973. }
  5974. };
  5975. }();
  5976. /**
  5977. * @class Ext.XTemplate
  5978. * @extends Ext.Template
  5979. * <p>A template class that supports advanced functionality like:<div class="mdetail-params"><ul>
  5980. * <li>Autofilling arrays using templates and sub-templates</li>
  5981. * <li>Conditional processing with basic comparison operators</li>
  5982. * <li>Basic math function support</li>
  5983. * <li>Execute arbitrary inline code with special built-in template variables</li>
  5984. * <li>Custom member functions</li>
  5985. * <li>Many special tags and built-in operators that aren't defined as part of
  5986. * the API, but are supported in the templates that can be created</li>
  5987. * </ul></div></p>
  5988. * <p>XTemplate provides the templating mechanism built into:<div class="mdetail-params"><ul>
  5989. * <li>{@link Ext.DataView}</li>
  5990. * <li>{@link Ext.ListView}</li>
  5991. * <li>{@link Ext.form.ComboBox}</li>
  5992. * <li>{@link Ext.grid.TemplateColumn}</li>
  5993. * <li>{@link Ext.grid.GroupingView}</li>
  5994. * <li>{@link Ext.menu.Item}</li>
  5995. * <li>{@link Ext.layout.MenuLayout}</li>
  5996. * <li>{@link Ext.ColorPalette}</li>
  5997. * </ul></div></p>
  5998. *
  5999. * <p>For example usage {@link #XTemplate see the constructor}.</p>
  6000. *
  6001. * @constructor
  6002. * The {@link Ext.Template#Template Ext.Template constructor} describes
  6003. * the acceptable parameters to pass to the constructor. The following
  6004. * examples demonstrate all of the supported features.</p>
  6005. *
  6006. * <div class="mdetail-params"><ul>
  6007. *
  6008. * <li><b><u>Sample Data</u></b>
  6009. * <div class="sub-desc">
  6010. * <p>This is the data object used for reference in each code example:</p>
  6011. * <pre><code>
  6012. var data = {
  6013. name: 'Jack Slocum',
  6014. title: 'Lead Developer',
  6015. company: 'Ext JS, LLC',
  6016. email: 'jack@extjs.com',
  6017. address: '4 Red Bulls Drive',
  6018. city: 'Cleveland',
  6019. state: 'Ohio',
  6020. zip: '44102',
  6021. drinks: ['Red Bull', 'Coffee', 'Water'],
  6022. kids: [{
  6023. name: 'Sara Grace',
  6024. age:3
  6025. },{
  6026. name: 'Zachary',
  6027. age:2
  6028. },{
  6029. name: 'John James',
  6030. age:0
  6031. }]
  6032. };
  6033. * </code></pre>
  6034. * </div>
  6035. * </li>
  6036. *
  6037. *
  6038. * <li><b><u>Auto filling of arrays</u></b>
  6039. * <div class="sub-desc">
  6040. * <p>The <b><tt>tpl</tt></b> tag and the <b><tt>for</tt></b> operator are used
  6041. * to process the provided data object:
  6042. * <ul>
  6043. * <li>If the value specified in <tt>for</tt> is an array, it will auto-fill,
  6044. * repeating the template block inside the <tt>tpl</tt> tag for each item in the
  6045. * array.</li>
  6046. * <li>If <tt>for="."</tt> is specified, the data object provided is examined.</li>
  6047. * <li>While processing an array, the special variable <tt>{#}</tt>
  6048. * will provide the current array index + 1 (starts at 1, not 0).</li>
  6049. * </ul>
  6050. * </p>
  6051. * <pre><code>
  6052. &lt;tpl <b>for</b>=".">...&lt;/tpl> // loop through array at root node
  6053. &lt;tpl <b>for</b>="foo">...&lt;/tpl> // loop through array at foo node
  6054. &lt;tpl <b>for</b>="foo.bar">...&lt;/tpl> // loop through array at foo.bar node
  6055. * </code></pre>
  6056. * Using the sample data above:
  6057. * <pre><code>
  6058. var tpl = new Ext.XTemplate(
  6059. '&lt;p>Kids: ',
  6060. '&lt;tpl <b>for</b>=".">', // process the data.kids node
  6061. '&lt;p>{#}. {name}&lt;/p>', // use current array index to autonumber
  6062. '&lt;/tpl>&lt;/p>'
  6063. );
  6064. tpl.overwrite(panel.body, data.kids); // pass the kids property of the data object
  6065. * </code></pre>
  6066. * <p>An example illustrating how the <b><tt>for</tt></b> property can be leveraged
  6067. * to access specified members of the provided data object to populate the template:</p>
  6068. * <pre><code>
  6069. var tpl = new Ext.XTemplate(
  6070. '&lt;p>Name: {name}&lt;/p>',
  6071. '&lt;p>Title: {title}&lt;/p>',
  6072. '&lt;p>Company: {company}&lt;/p>',
  6073. '&lt;p>Kids: ',
  6074. '&lt;tpl <b>for="kids"</b>>', // interrogate the kids property within the data
  6075. '&lt;p>{name}&lt;/p>',
  6076. '&lt;/tpl>&lt;/p>'
  6077. );
  6078. tpl.overwrite(panel.body, data); // pass the root node of the data object
  6079. * </code></pre>
  6080. * <p>Flat arrays that contain values (and not objects) can be auto-rendered
  6081. * using the special <b><tt>{.}</tt></b> variable inside a loop. This variable
  6082. * will represent the value of the array at the current index:</p>
  6083. * <pre><code>
  6084. var tpl = new Ext.XTemplate(
  6085. '&lt;p>{name}\&#39;s favorite beverages:&lt;/p>',
  6086. '&lt;tpl for="drinks">',
  6087. '&lt;div> - {.}&lt;/div>',
  6088. '&lt;/tpl>'
  6089. );
  6090. tpl.overwrite(panel.body, data);
  6091. * </code></pre>
  6092. * <p>When processing a sub-template, for example while looping through a child array,
  6093. * you can access the parent object's members via the <b><tt>parent</tt></b> object:</p>
  6094. * <pre><code>
  6095. var tpl = new Ext.XTemplate(
  6096. '&lt;p>Name: {name}&lt;/p>',
  6097. '&lt;p>Kids: ',
  6098. '&lt;tpl for="kids">',
  6099. '&lt;tpl if="age > 1">',
  6100. '&lt;p>{name}&lt;/p>',
  6101. '&lt;p>Dad: {<b>parent</b>.name}&lt;/p>',
  6102. '&lt;/tpl>',
  6103. '&lt;/tpl>&lt;/p>'
  6104. );
  6105. tpl.overwrite(panel.body, data);
  6106. * </code></pre>
  6107. * </div>
  6108. * </li>
  6109. *
  6110. *
  6111. * <li><b><u>Conditional processing with basic comparison operators</u></b>
  6112. * <div class="sub-desc">
  6113. * <p>The <b><tt>tpl</tt></b> tag and the <b><tt>if</tt></b> operator are used
  6114. * to provide conditional checks for deciding whether or not to render specific
  6115. * parts of the template. Notes:<div class="sub-desc"><ul>
  6116. * <li>Double quotes must be encoded if used within the conditional</li>
  6117. * <li>There is no <tt>else</tt> operator &mdash; if needed, two opposite
  6118. * <tt>if</tt> statements should be used.</li>
  6119. * </ul></div>
  6120. * <pre><code>
  6121. &lt;tpl if="age &gt; 1 &amp;&amp; age &lt; 10">Child&lt;/tpl>
  6122. &lt;tpl if="age >= 10 && age < 18">Teenager&lt;/tpl>
  6123. &lt;tpl <b>if</b>="this.isGirl(name)">...&lt;/tpl>
  6124. &lt;tpl <b>if</b>="id==\'download\'">...&lt;/tpl>
  6125. &lt;tpl <b>if</b>="needsIcon">&lt;img src="{icon}" class="{iconCls}"/>&lt;/tpl>
  6126. // no good:
  6127. &lt;tpl if="name == "Jack"">Hello&lt;/tpl>
  6128. // encode &#34; if it is part of the condition, e.g.
  6129. &lt;tpl if="name == &#38;quot;Jack&#38;quot;">Hello&lt;/tpl>
  6130. * </code></pre>
  6131. * Using the sample data above:
  6132. * <pre><code>
  6133. var tpl = new Ext.XTemplate(
  6134. '&lt;p>Name: {name}&lt;/p>',
  6135. '&lt;p>Kids: ',
  6136. '&lt;tpl for="kids">',
  6137. '&lt;tpl if="age > 1">',
  6138. '&lt;p>{name}&lt;/p>',
  6139. '&lt;/tpl>',
  6140. '&lt;/tpl>&lt;/p>'
  6141. );
  6142. tpl.overwrite(panel.body, data);
  6143. * </code></pre>
  6144. * </div>
  6145. * </li>
  6146. *
  6147. *
  6148. * <li><b><u>Basic math support</u></b>
  6149. * <div class="sub-desc">
  6150. * <p>The following basic math operators may be applied directly on numeric
  6151. * data values:</p><pre>
  6152. * + - * /
  6153. * </pre>
  6154. * For example:
  6155. * <pre><code>
  6156. var tpl = new Ext.XTemplate(
  6157. '&lt;p>Name: {name}&lt;/p>',
  6158. '&lt;p>Kids: ',
  6159. '&lt;tpl for="kids">',
  6160. '&lt;tpl if="age &amp;gt; 1">', // <-- Note that the &gt; is encoded
  6161. '&lt;p>{#}: {name}&lt;/p>', // <-- Auto-number each item
  6162. '&lt;p>In 5 Years: {age+5}&lt;/p>', // <-- Basic math
  6163. '&lt;p>Dad: {parent.name}&lt;/p>',
  6164. '&lt;/tpl>',
  6165. '&lt;/tpl>&lt;/p>'
  6166. );
  6167. tpl.overwrite(panel.body, data);
  6168. </code></pre>
  6169. * </div>
  6170. * </li>
  6171. *
  6172. *
  6173. * <li><b><u>Execute arbitrary inline code with special built-in template variables</u></b>
  6174. * <div class="sub-desc">
  6175. * <p>Anything between <code>{[ ... ]}</code> is considered code to be executed
  6176. * in the scope of the template. There are some special variables available in that code:
  6177. * <ul>
  6178. * <li><b><tt>values</tt></b>: The values in the current scope. If you are using
  6179. * scope changing sub-templates, you can change what <tt>values</tt> is.</li>
  6180. * <li><b><tt>parent</tt></b>: The scope (values) of the ancestor template.</li>
  6181. * <li><b><tt>xindex</tt></b>: If you are in a looping template, the index of the
  6182. * loop you are in (1-based).</li>
  6183. * <li><b><tt>xcount</tt></b>: If you are in a looping template, the total length
  6184. * of the array you are looping.</li>
  6185. * <li><b><tt>fm</tt></b>: An alias for <tt>Ext.util.Format</tt>.</li>
  6186. * </ul>
  6187. * This example demonstrates basic row striping using an inline code block and the
  6188. * <tt>xindex</tt> variable:</p>
  6189. * <pre><code>
  6190. var tpl = new Ext.XTemplate(
  6191. '&lt;p>Name: {name}&lt;/p>',
  6192. '&lt;p>Company: {[values.company.toUpperCase() + ", " + values.title]}&lt;/p>',
  6193. '&lt;p>Kids: ',
  6194. '&lt;tpl for="kids">',
  6195. '&lt;div class="{[xindex % 2 === 0 ? "even" : "odd"]}">',
  6196. '{name}',
  6197. '&lt;/div>',
  6198. '&lt;/tpl>&lt;/p>'
  6199. );
  6200. tpl.overwrite(panel.body, data);
  6201. * </code></pre>
  6202. * </div>
  6203. * </li>
  6204. *
  6205. * <li><b><u>Template member functions</u></b>
  6206. * <div class="sub-desc">
  6207. * <p>One or more member functions can be specified in a configuration
  6208. * object passed into the XTemplate constructor for more complex processing:</p>
  6209. * <pre><code>
  6210. var tpl = new Ext.XTemplate(
  6211. '&lt;p>Name: {name}&lt;/p>',
  6212. '&lt;p>Kids: ',
  6213. '&lt;tpl for="kids">',
  6214. '&lt;tpl if="this.isGirl(name)">',
  6215. '&lt;p>Girl: {name} - {age}&lt;/p>',
  6216. '&lt;/tpl>',
  6217. // use opposite if statement to simulate 'else' processing:
  6218. '&lt;tpl if="this.isGirl(name) == false">',
  6219. '&lt;p>Boy: {name} - {age}&lt;/p>',
  6220. '&lt;/tpl>',
  6221. '&lt;tpl if="this.isBaby(age)">',
  6222. '&lt;p>{name} is a baby!&lt;/p>',
  6223. '&lt;/tpl>',
  6224. '&lt;/tpl>&lt;/p>',
  6225. {
  6226. // XTemplate configuration:
  6227. compiled: true,
  6228. disableFormats: true,
  6229. // member functions:
  6230. isGirl: function(name){
  6231. return name == 'Sara Grace';
  6232. },
  6233. isBaby: function(age){
  6234. return age < 1;
  6235. }
  6236. }
  6237. );
  6238. tpl.overwrite(panel.body, data);
  6239. * </code></pre>
  6240. * </div>
  6241. * </li>
  6242. *
  6243. * </ul></div>
  6244. *
  6245. * @param {Mixed} config
  6246. */
  6247. Ext.XTemplate = function(){
  6248. Ext.XTemplate.superclass.constructor.apply(this, arguments);
  6249. var me = this,
  6250. s = me.html,
  6251. re = /<tpl\b[^>]*>((?:(?=([^<]+))\2|<(?!tpl\b[^>]*>))*?)<\/tpl>/,
  6252. nameRe = /^<tpl\b[^>]*?for="(.*?)"/,
  6253. ifRe = /^<tpl\b[^>]*?if="(.*?)"/,
  6254. execRe = /^<tpl\b[^>]*?exec="(.*?)"/,
  6255. m,
  6256. id = 0,
  6257. tpls = [],
  6258. VALUES = 'values',
  6259. PARENT = 'parent',
  6260. XINDEX = 'xindex',
  6261. XCOUNT = 'xcount',
  6262. RETURN = 'return ',
  6263. WITHVALUES = 'with(values){ ';
  6264. s = ['<tpl>', s, '</tpl>'].join('');
  6265. while((m = s.match(re))){
  6266. var m2 = m[0].match(nameRe),
  6267. m3 = m[0].match(ifRe),
  6268. m4 = m[0].match(execRe),
  6269. exp = null,
  6270. fn = null,
  6271. exec = null,
  6272. name = m2 && m2[1] ? m2[1] : '';
  6273. if (m3) {
  6274. exp = m3 && m3[1] ? m3[1] : null;
  6275. if(exp){
  6276. fn = new Function(VALUES, PARENT, XINDEX, XCOUNT, WITHVALUES + RETURN +(Ext.util.Format.htmlDecode(exp))+'; }');
  6277. }
  6278. }
  6279. if (m4) {
  6280. exp = m4 && m4[1] ? m4[1] : null;
  6281. if(exp){
  6282. exec = new Function(VALUES, PARENT, XINDEX, XCOUNT, WITHVALUES +(Ext.util.Format.htmlDecode(exp))+'; }');
  6283. }
  6284. }
  6285. if(name){
  6286. switch(name){
  6287. case '.': name = new Function(VALUES, PARENT, WITHVALUES + RETURN + VALUES + '; }'); break;
  6288. case '..': name = new Function(VALUES, PARENT, WITHVALUES + RETURN + PARENT + '; }'); break;
  6289. default: name = new Function(VALUES, PARENT, WITHVALUES + RETURN + name + '; }');
  6290. }
  6291. }
  6292. tpls.push({
  6293. id: id,
  6294. target: name,
  6295. exec: exec,
  6296. test: fn,
  6297. body: m[1]||''
  6298. });
  6299. s = s.replace(m[0], '{xtpl'+ id + '}');
  6300. ++id;
  6301. }
  6302. for(var i = tpls.length-1; i >= 0; --i){
  6303. me.compileTpl(tpls[i]);
  6304. }
  6305. me.master = tpls[tpls.length-1];
  6306. me.tpls = tpls;
  6307. };
  6308. Ext.extend(Ext.XTemplate, Ext.Template, {
  6309. // private
  6310. re : /\{([\w-\.\#]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?(\s?[\+\-\*\\]\s?[\d\.\+\-\*\\\(\)]+)?\}/g,
  6311. // private
  6312. codeRe : /\{\[((?:\\\]|.|\n)*?)\]\}/g,
  6313. // private
  6314. applySubTemplate : function(id, values, parent, xindex, xcount){
  6315. var me = this,
  6316. len,
  6317. t = me.tpls[id],
  6318. vs,
  6319. buf = [];
  6320. if ((t.test && !t.test.call(me, values, parent, xindex, xcount)) ||
  6321. (t.exec && t.exec.call(me, values, parent, xindex, xcount))) {
  6322. return '';
  6323. }
  6324. vs = t.target ? t.target.call(me, values, parent) : values;
  6325. len = vs.length;
  6326. parent = t.target ? values : parent;
  6327. if(t.target && Ext.isArray(vs)){
  6328. for(var i = 0, len = vs.length; i < len; i++){
  6329. buf[buf.length] = t.compiled.call(me, vs[i], parent, i+1, len);
  6330. }
  6331. return buf.join('');
  6332. }
  6333. return t.compiled.call(me, vs, parent, xindex, xcount);
  6334. },
  6335. // private
  6336. compileTpl : function(tpl){
  6337. var fm = Ext.util.Format,
  6338. useF = this.disableFormats !== true,
  6339. sep = Ext.isGecko ? "+" : ",",
  6340. body;
  6341. function fn(m, name, format, args, math){
  6342. if(name.substr(0, 4) == 'xtpl'){
  6343. return "'"+ sep +'this.applySubTemplate('+name.substr(4)+', values, parent, xindex, xcount)'+sep+"'";
  6344. }
  6345. var v;
  6346. if(name === '.'){
  6347. v = 'values';
  6348. }else if(name === '#'){
  6349. v = 'xindex';
  6350. }else if(name.indexOf('.') != -1){
  6351. v = name;
  6352. }else{
  6353. v = "values['" + name + "']";
  6354. }
  6355. if(math){
  6356. v = '(' + v + math + ')';
  6357. }
  6358. if (format && useF) {
  6359. args = args ? ',' + args : "";
  6360. if(format.substr(0, 5) != "this."){
  6361. format = "fm." + format + '(';
  6362. }else{
  6363. format = 'this.call("'+ format.substr(5) + '", ';
  6364. args = ", values";
  6365. }
  6366. } else {
  6367. args= ''; format = "("+v+" === undefined ? '' : ";
  6368. }
  6369. return "'"+ sep + format + v + args + ")"+sep+"'";
  6370. }
  6371. function codeFn(m, code){
  6372. // Single quotes get escaped when the template is compiled, however we want to undo this when running code.
  6373. return "'" + sep + '(' + code.replace(/\\'/g, "'") + ')' + sep + "'";
  6374. }
  6375. // branched to use + in gecko and [].join() in others
  6376. if(Ext.isGecko){
  6377. body = "tpl.compiled = function(values, parent, xindex, xcount){ return '" +
  6378. tpl.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn).replace(this.codeRe, codeFn) +
  6379. "';};";
  6380. }else{
  6381. body = ["tpl.compiled = function(values, parent, xindex, xcount){ return ['"];
  6382. body.push(tpl.body.replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn).replace(this.codeRe, codeFn));
  6383. body.push("'].join('');};");
  6384. body = body.join('');
  6385. }
  6386. eval(body);
  6387. return this;
  6388. },
  6389. /**
  6390. * Returns an HTML fragment of this template with the specified values applied.
  6391. * @param {Object} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
  6392. * @return {String} The HTML fragment
  6393. */
  6394. applyTemplate : function(values){
  6395. return this.master.compiled.call(this, values, {}, 1, 1);
  6396. },
  6397. /**
  6398. * Compile the template to a function for optimized performance. Recommended if the template will be used frequently.
  6399. * @return {Function} The compiled function
  6400. */
  6401. compile : function(){return this;}
  6402. /**
  6403. * @property re
  6404. * @hide
  6405. */
  6406. /**
  6407. * @property disableFormats
  6408. * @hide
  6409. */
  6410. /**
  6411. * @method set
  6412. * @hide
  6413. */
  6414. });
  6415. /**
  6416. * Alias for {@link #applyTemplate}
  6417. * Returns an HTML fragment of this template with the specified values applied.
  6418. * @param {Object/Array} values The template values. Can be an array if your params are numeric (i.e. {0}) or an object (i.e. {foo: 'bar'})
  6419. * @return {String} The HTML fragment
  6420. * @member Ext.XTemplate
  6421. * @method apply
  6422. */
  6423. Ext.XTemplate.prototype.apply = Ext.XTemplate.prototype.applyTemplate;
  6424. /**
  6425. * Creates a template from the passed element's value (<i>display:none</i> textarea, preferred) or innerHTML.
  6426. * @param {String/HTMLElement} el A DOM element or its id
  6427. * @return {Ext.Template} The created template
  6428. * @static
  6429. */
  6430. Ext.XTemplate.from = function(el){
  6431. el = Ext.getDom(el);
  6432. return new Ext.XTemplate(el.value || el.innerHTML);
  6433. };
  6434. /**
  6435. * @class Ext.util.CSS
  6436. * Utility class for manipulating CSS rules
  6437. * @singleton
  6438. */
  6439. Ext.util.CSS = function(){
  6440. var rules = null;
  6441. var doc = document;
  6442. var camelRe = /(-[a-z])/gi;
  6443. var camelFn = function(m, a){ return a.charAt(1).toUpperCase(); };
  6444. return {
  6445. /**
  6446. * Creates a stylesheet from a text blob of rules.
  6447. * These rules will be wrapped in a STYLE tag and appended to the HEAD of the document.
  6448. * @param {String} cssText The text containing the css rules
  6449. * @param {String} id An id to add to the stylesheet for later removal
  6450. * @return {StyleSheet}
  6451. */
  6452. createStyleSheet : function(cssText, id){
  6453. var ss;
  6454. var head = doc.getElementsByTagName("head")[0];
  6455. var rules = doc.createElement("style");
  6456. rules.setAttribute("type", "text/css");
  6457. if(id){
  6458. rules.setAttribute("id", id);
  6459. }
  6460. if(Ext.isIE){
  6461. head.appendChild(rules);
  6462. ss = rules.styleSheet;
  6463. ss.cssText = cssText;
  6464. }else{
  6465. try{
  6466. rules.appendChild(doc.createTextNode(cssText));
  6467. }catch(e){
  6468. rules.cssText = cssText;
  6469. }
  6470. head.appendChild(rules);
  6471. ss = rules.styleSheet ? rules.styleSheet : (rules.sheet || doc.styleSheets[doc.styleSheets.length-1]);
  6472. }
  6473. this.cacheStyleSheet(ss);
  6474. return ss;
  6475. },
  6476. /**
  6477. * Removes a style or link tag by id
  6478. * @param {String} id The id of the tag
  6479. */
  6480. removeStyleSheet : function(id){
  6481. var existing = doc.getElementById(id);
  6482. if(existing){
  6483. existing.parentNode.removeChild(existing);
  6484. }
  6485. },
  6486. /**
  6487. * Dynamically swaps an existing stylesheet reference for a new one
  6488. * @param {String} id The id of an existing link tag to remove
  6489. * @param {String} url The href of the new stylesheet to include
  6490. */
  6491. swapStyleSheet : function(id, url){
  6492. this.removeStyleSheet(id);
  6493. var ss = doc.createElement("link");
  6494. ss.setAttribute("rel", "stylesheet");
  6495. ss.setAttribute("type", "text/css");
  6496. ss.setAttribute("id", id);
  6497. ss.setAttribute("href", url);
  6498. doc.getElementsByTagName("head")[0].appendChild(ss);
  6499. },
  6500. /**
  6501. * Refresh the rule cache if you have dynamically added stylesheets
  6502. * @return {Object} An object (hash) of rules indexed by selector
  6503. */
  6504. refreshCache : function(){
  6505. return this.getRules(true);
  6506. },
  6507. // private
  6508. cacheStyleSheet : function(ss){
  6509. if(!rules){
  6510. rules = {};
  6511. }
  6512. try{// try catch for cross domain access issue
  6513. var ssRules = ss.cssRules || ss.rules;
  6514. for(var j = ssRules.length-1; j >= 0; --j){
  6515. rules[ssRules[j].selectorText.toLowerCase()] = ssRules[j];
  6516. }
  6517. }catch(e){}
  6518. },
  6519. /**
  6520. * Gets all css rules for the document
  6521. * @param {Boolean} refreshCache true to refresh the internal cache
  6522. * @return {Object} An object (hash) of rules indexed by selector
  6523. */
  6524. getRules : function(refreshCache){
  6525. if(rules === null || refreshCache){
  6526. rules = {};
  6527. var ds = doc.styleSheets;
  6528. for(var i =0, len = ds.length; i < len; i++){
  6529. try{
  6530. this.cacheStyleSheet(ds[i]);
  6531. }catch(e){}
  6532. }
  6533. }
  6534. return rules;
  6535. },
  6536. /**
  6537. * Gets an an individual CSS rule by selector(s)
  6538. * @param {String/Array} selector The CSS selector or an array of selectors to try. The first selector that is found is returned.
  6539. * @param {Boolean} refreshCache true to refresh the internal cache if you have recently updated any rules or added styles dynamically
  6540. * @return {CSSRule} The CSS rule or null if one is not found
  6541. */
  6542. getRule : function(selector, refreshCache){
  6543. var rs = this.getRules(refreshCache);
  6544. if(!Ext.isArray(selector)){
  6545. return rs[selector.toLowerCase()];
  6546. }
  6547. for(var i = 0; i < selector.length; i++){
  6548. if(rs[selector[i]]){
  6549. return rs[selector[i].toLowerCase()];
  6550. }
  6551. }
  6552. return null;
  6553. },
  6554. /**
  6555. * Updates a rule property
  6556. * @param {String/Array} selector If it's an array it tries each selector until it finds one. Stops immediately once one is found.
  6557. * @param {String} property The css property
  6558. * @param {String} value The new value for the property
  6559. * @return {Boolean} true If a rule was found and updated
  6560. */
  6561. updateRule : function(selector, property, value){
  6562. if(!Ext.isArray(selector)){
  6563. var rule = this.getRule(selector);
  6564. if(rule){
  6565. rule.style[property.replace(camelRe, camelFn)] = value;
  6566. return true;
  6567. }
  6568. }else{
  6569. for(var i = 0; i < selector.length; i++){
  6570. if(this.updateRule(selector[i], property, value)){
  6571. return true;
  6572. }
  6573. }
  6574. }
  6575. return false;
  6576. }
  6577. };
  6578. }();/**
  6579. @class Ext.util.ClickRepeater
  6580. @extends Ext.util.Observable
  6581. A wrapper class which can be applied to any element. Fires a "click" event while the
  6582. mouse is pressed. The interval between firings may be specified in the config but
  6583. defaults to 20 milliseconds.
  6584. Optionally, a CSS class may be applied to the element during the time it is pressed.
  6585. @cfg {Mixed} el The element to act as a button.
  6586. @cfg {Number} delay The initial delay before the repeating event begins firing.
  6587. Similar to an autorepeat key delay.
  6588. @cfg {Number} interval The interval between firings of the "click" event. Default 20 ms.
  6589. @cfg {String} pressClass A CSS class name to be applied to the element while pressed.
  6590. @cfg {Boolean} accelerate True if autorepeating should start slowly and accelerate.
  6591. "interval" and "delay" are ignored.
  6592. @cfg {Boolean} preventDefault True to prevent the default click event
  6593. @cfg {Boolean} stopDefault True to stop the default click event
  6594. @history
  6595. 2007-02-02 jvs Original code contributed by Nige "Animal" White
  6596. 2007-02-02 jvs Renamed to ClickRepeater
  6597. 2007-02-03 jvs Modifications for FF Mac and Safari
  6598. @constructor
  6599. @param {Mixed} el The element to listen on
  6600. @param {Object} config
  6601. */
  6602. Ext.util.ClickRepeater = Ext.extend(Ext.util.Observable, {
  6603. constructor : function(el, config){
  6604. this.el = Ext.get(el);
  6605. this.el.unselectable();
  6606. Ext.apply(this, config);
  6607. this.addEvents(
  6608. /**
  6609. * @event mousedown
  6610. * Fires when the mouse button is depressed.
  6611. * @param {Ext.util.ClickRepeater} this
  6612. * @param {Ext.EventObject} e
  6613. */
  6614. "mousedown",
  6615. /**
  6616. * @event click
  6617. * Fires on a specified interval during the time the element is pressed.
  6618. * @param {Ext.util.ClickRepeater} this
  6619. * @param {Ext.EventObject} e
  6620. */
  6621. "click",
  6622. /**
  6623. * @event mouseup
  6624. * Fires when the mouse key is released.
  6625. * @param {Ext.util.ClickRepeater} this
  6626. * @param {Ext.EventObject} e
  6627. */
  6628. "mouseup"
  6629. );
  6630. if(!this.disabled){
  6631. this.disabled = true;
  6632. this.enable();
  6633. }
  6634. // allow inline handler
  6635. if(this.handler){
  6636. this.on("click", this.handler, this.scope || this);
  6637. }
  6638. Ext.util.ClickRepeater.superclass.constructor.call(this);
  6639. },
  6640. interval : 20,
  6641. delay: 250,
  6642. preventDefault : true,
  6643. stopDefault : false,
  6644. timer : 0,
  6645. /**
  6646. * Enables the repeater and allows events to fire.
  6647. */
  6648. enable: function(){
  6649. if(this.disabled){
  6650. this.el.on('mousedown', this.handleMouseDown, this);
  6651. if (Ext.isIE){
  6652. this.el.on('dblclick', this.handleDblClick, this);
  6653. }
  6654. if(this.preventDefault || this.stopDefault){
  6655. this.el.on('click', this.eventOptions, this);
  6656. }
  6657. }
  6658. this.disabled = false;
  6659. },
  6660. /**
  6661. * Disables the repeater and stops events from firing.
  6662. */
  6663. disable: function(/* private */ force){
  6664. if(force || !this.disabled){
  6665. clearTimeout(this.timer);
  6666. if(this.pressClass){
  6667. this.el.removeClass(this.pressClass);
  6668. }
  6669. Ext.getDoc().un('mouseup', this.handleMouseUp, this);
  6670. this.el.removeAllListeners();
  6671. }
  6672. this.disabled = true;
  6673. },
  6674. /**
  6675. * Convenience function for setting disabled/enabled by boolean.
  6676. * @param {Boolean} disabled
  6677. */
  6678. setDisabled: function(disabled){
  6679. this[disabled ? 'disable' : 'enable']();
  6680. },
  6681. eventOptions: function(e){
  6682. if(this.preventDefault){
  6683. e.preventDefault();
  6684. }
  6685. if(this.stopDefault){
  6686. e.stopEvent();
  6687. }
  6688. },
  6689. // private
  6690. destroy : function() {
  6691. this.disable(true);
  6692. Ext.destroy(this.el);
  6693. this.purgeListeners();
  6694. },
  6695. handleDblClick : function(e){
  6696. clearTimeout(this.timer);
  6697. this.el.blur();
  6698. this.fireEvent("mousedown", this, e);
  6699. this.fireEvent("click", this, e);
  6700. },
  6701. // private
  6702. handleMouseDown : function(e){
  6703. clearTimeout(this.timer);
  6704. this.el.blur();
  6705. if(this.pressClass){
  6706. this.el.addClass(this.pressClass);
  6707. }
  6708. this.mousedownTime = new Date();
  6709. Ext.getDoc().on("mouseup", this.handleMouseUp, this);
  6710. this.el.on("mouseout", this.handleMouseOut, this);
  6711. this.fireEvent("mousedown", this, e);
  6712. this.fireEvent("click", this, e);
  6713. // Do not honor delay or interval if acceleration wanted.
  6714. if (this.accelerate) {
  6715. this.delay = 400;
  6716. }
  6717. this.timer = this.click.defer(this.delay || this.interval, this, [e]);
  6718. },
  6719. // private
  6720. click : function(e){
  6721. this.fireEvent("click", this, e);
  6722. this.timer = this.click.defer(this.accelerate ?
  6723. this.easeOutExpo(this.mousedownTime.getElapsed(),
  6724. 400,
  6725. -390,
  6726. 12000) :
  6727. this.interval, this, [e]);
  6728. },
  6729. easeOutExpo : function (t, b, c, d) {
  6730. return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;
  6731. },
  6732. // private
  6733. handleMouseOut : function(){
  6734. clearTimeout(this.timer);
  6735. if(this.pressClass){
  6736. this.el.removeClass(this.pressClass);
  6737. }
  6738. this.el.on("mouseover", this.handleMouseReturn, this);
  6739. },
  6740. // private
  6741. handleMouseReturn : function(){
  6742. this.el.un("mouseover", this.handleMouseReturn, this);
  6743. if(this.pressClass){
  6744. this.el.addClass(this.pressClass);
  6745. }
  6746. this.click();
  6747. },
  6748. // private
  6749. handleMouseUp : function(e){
  6750. clearTimeout(this.timer);
  6751. this.el.un("mouseover", this.handleMouseReturn, this);
  6752. this.el.un("mouseout", this.handleMouseOut, this);
  6753. Ext.getDoc().un("mouseup", this.handleMouseUp, this);
  6754. this.el.removeClass(this.pressClass);
  6755. this.fireEvent("mouseup", this, e);
  6756. }
  6757. });/**
  6758. * @class Ext.KeyNav
  6759. * <p>Provides a convenient wrapper for normalized keyboard navigation. KeyNav allows you to bind
  6760. * navigation keys to function calls that will get called when the keys are pressed, providing an easy
  6761. * way to implement custom navigation schemes for any UI component.</p>
  6762. * <p>The following are all of the possible keys that can be implemented: enter, left, right, up, down, tab, esc,
  6763. * pageUp, pageDown, del, home, end. Usage:</p>
  6764. <pre><code>
  6765. var nav = new Ext.KeyNav("my-element", {
  6766. "left" : function(e){
  6767. this.moveLeft(e.ctrlKey);
  6768. },
  6769. "right" : function(e){
  6770. this.moveRight(e.ctrlKey);
  6771. },
  6772. "enter" : function(e){
  6773. this.save();
  6774. },
  6775. scope : this
  6776. });
  6777. </code></pre>
  6778. * @constructor
  6779. * @param {Mixed} el The element to bind to
  6780. * @param {Object} config The config
  6781. */
  6782. Ext.KeyNav = function(el, config){
  6783. this.el = Ext.get(el);
  6784. Ext.apply(this, config);
  6785. if(!this.disabled){
  6786. this.disabled = true;
  6787. this.enable();
  6788. }
  6789. };
  6790. Ext.KeyNav.prototype = {
  6791. /**
  6792. * @cfg {Boolean} disabled
  6793. * True to disable this KeyNav instance (defaults to false)
  6794. */
  6795. disabled : false,
  6796. /**
  6797. * @cfg {String} defaultEventAction
  6798. * The method to call on the {@link Ext.EventObject} after this KeyNav intercepts a key. Valid values are
  6799. * {@link Ext.EventObject#stopEvent}, {@link Ext.EventObject#preventDefault} and
  6800. * {@link Ext.EventObject#stopPropagation} (defaults to 'stopEvent')
  6801. */
  6802. defaultEventAction: "stopEvent",
  6803. /**
  6804. * @cfg {Boolean} forceKeyDown
  6805. * Handle the keydown event instead of keypress (defaults to false). KeyNav automatically does this for IE since
  6806. * IE does not propagate special keys on keypress, but setting this to true will force other browsers to also
  6807. * handle keydown instead of keypress.
  6808. */
  6809. forceKeyDown : false,
  6810. // private
  6811. relay : function(e){
  6812. var k = e.getKey(),
  6813. h = this.keyToHandler[k];
  6814. if(h && this[h]){
  6815. if(this.doRelay(e, this[h], h) !== true){
  6816. e[this.defaultEventAction]();
  6817. }
  6818. }
  6819. },
  6820. // private
  6821. doRelay : function(e, h, hname){
  6822. return h.call(this.scope || this, e, hname);
  6823. },
  6824. // possible handlers
  6825. enter : false,
  6826. left : false,
  6827. right : false,
  6828. up : false,
  6829. down : false,
  6830. tab : false,
  6831. esc : false,
  6832. pageUp : false,
  6833. pageDown : false,
  6834. del : false,
  6835. home : false,
  6836. end : false,
  6837. // quick lookup hash
  6838. keyToHandler : {
  6839. 37 : "left",
  6840. 39 : "right",
  6841. 38 : "up",
  6842. 40 : "down",
  6843. 33 : "pageUp",
  6844. 34 : "pageDown",
  6845. 46 : "del",
  6846. 36 : "home",
  6847. 35 : "end",
  6848. 13 : "enter",
  6849. 27 : "esc",
  6850. 9 : "tab"
  6851. },
  6852. stopKeyUp: function(e) {
  6853. var k = e.getKey();
  6854. if (k >= 37 && k <= 40) {
  6855. // *** bugfix - safari 2.x fires 2 keyup events on cursor keys
  6856. // *** (note: this bugfix sacrifices the "keyup" event originating from keyNav elements in Safari 2)
  6857. e.stopEvent();
  6858. }
  6859. },
  6860. /**
  6861. * Destroy this KeyNav (this is the same as calling disable).
  6862. */
  6863. destroy: function(){
  6864. this.disable();
  6865. },
  6866. /**
  6867. * Enable this KeyNav
  6868. */
  6869. enable: function() {
  6870. if (this.disabled) {
  6871. if (Ext.isSafari2) {
  6872. // call stopKeyUp() on "keyup" event
  6873. this.el.on('keyup', this.stopKeyUp, this);
  6874. }
  6875. this.el.on(this.isKeydown()? 'keydown' : 'keypress', this.relay, this);
  6876. this.disabled = false;
  6877. }
  6878. },
  6879. /**
  6880. * Disable this KeyNav
  6881. */
  6882. disable: function() {
  6883. if (!this.disabled) {
  6884. if (Ext.isSafari2) {
  6885. // remove "keyup" event handler
  6886. this.el.un('keyup', this.stopKeyUp, this);
  6887. }
  6888. this.el.un(this.isKeydown()? 'keydown' : 'keypress', this.relay, this);
  6889. this.disabled = true;
  6890. }
  6891. },
  6892. /**
  6893. * Convenience function for setting disabled/enabled by boolean.
  6894. * @param {Boolean} disabled
  6895. */
  6896. setDisabled : function(disabled){
  6897. this[disabled ? "disable" : "enable"]();
  6898. },
  6899. // private
  6900. isKeydown: function(){
  6901. return this.forceKeyDown || Ext.EventManager.useKeydown;
  6902. }
  6903. };
  6904. /**
  6905. * @class Ext.KeyMap
  6906. * Handles mapping keys to actions for an element. One key map can be used for multiple actions.
  6907. * The constructor accepts the same config object as defined by {@link #addBinding}.
  6908. * If you bind a callback function to a KeyMap, anytime the KeyMap handles an expected key
  6909. * combination it will call the function with this signature (if the match is a multi-key
  6910. * combination the callback will still be called only once): (String key, Ext.EventObject e)
  6911. * A KeyMap can also handle a string representation of keys.<br />
  6912. * Usage:
  6913. <pre><code>
  6914. // map one key by key code
  6915. var map = new Ext.KeyMap("my-element", {
  6916. key: 13, // or Ext.EventObject.ENTER
  6917. fn: myHandler,
  6918. scope: myObject
  6919. });
  6920. // map multiple keys to one action by string
  6921. var map = new Ext.KeyMap("my-element", {
  6922. key: "a\r\n\t",
  6923. fn: myHandler,
  6924. scope: myObject
  6925. });
  6926. // map multiple keys to multiple actions by strings and array of codes
  6927. var map = new Ext.KeyMap("my-element", [
  6928. {
  6929. key: [10,13],
  6930. fn: function(){ alert("Return was pressed"); }
  6931. }, {
  6932. key: "abc",
  6933. fn: function(){ alert('a, b or c was pressed'); }
  6934. }, {
  6935. key: "\t",
  6936. ctrl:true,
  6937. shift:true,
  6938. fn: function(){ alert('Control + shift + tab was pressed.'); }
  6939. }
  6940. ]);
  6941. </code></pre>
  6942. * <b>Note: A KeyMap starts enabled</b>
  6943. * @constructor
  6944. * @param {Mixed} el The element to bind to
  6945. * @param {Object} config The config (see {@link #addBinding})
  6946. * @param {String} eventName (optional) The event to bind to (defaults to "keydown")
  6947. */
  6948. Ext.KeyMap = function(el, config, eventName){
  6949. this.el = Ext.get(el);
  6950. this.eventName = eventName || "keydown";
  6951. this.bindings = [];
  6952. if(config){
  6953. this.addBinding(config);
  6954. }
  6955. this.enable();
  6956. };
  6957. Ext.KeyMap.prototype = {
  6958. /**
  6959. * True to stop the event from bubbling and prevent the default browser action if the
  6960. * key was handled by the KeyMap (defaults to false)
  6961. * @type Boolean
  6962. */
  6963. stopEvent : false,
  6964. /**
  6965. * Add a new binding to this KeyMap. The following config object properties are supported:
  6966. * <pre>
  6967. Property Type Description
  6968. ---------- --------------- ----------------------------------------------------------------------
  6969. key String/Array A single keycode or an array of keycodes to handle
  6970. shift Boolean True to handle key only when shift is pressed, False to handle the key only when shift is not pressed (defaults to undefined)
  6971. ctrl Boolean True to handle key only when ctrl is pressed, False to handle the key only when ctrl is not pressed (defaults to undefined)
  6972. alt Boolean True to handle key only when alt is pressed, False to handle the key only when alt is not pressed (defaults to undefined)
  6973. handler Function The function to call when KeyMap finds the expected key combination
  6974. fn Function Alias of handler (for backwards-compatibility)
  6975. scope Object The scope of the callback function
  6976. stopEvent Boolean True to stop the event from bubbling and prevent the default browser action if the key was handled by the KeyMap (defaults to false)
  6977. </pre>
  6978. *
  6979. * Usage:
  6980. * <pre><code>
  6981. // Create a KeyMap
  6982. var map = new Ext.KeyMap(document, {
  6983. key: Ext.EventObject.ENTER,
  6984. fn: handleKey,
  6985. scope: this
  6986. });
  6987. //Add a new binding to the existing KeyMap later
  6988. map.addBinding({
  6989. key: 'abc',
  6990. shift: true,
  6991. fn: handleKey,
  6992. scope: this
  6993. });
  6994. </code></pre>
  6995. * @param {Object/Array} config A single KeyMap config or an array of configs
  6996. */
  6997. addBinding : function(config){
  6998. if(Ext.isArray(config)){
  6999. Ext.each(config, function(c){
  7000. this.addBinding(c);
  7001. }, this);
  7002. return;
  7003. }
  7004. var keyCode = config.key,
  7005. fn = config.fn || config.handler,
  7006. scope = config.scope;
  7007. if (config.stopEvent) {
  7008. this.stopEvent = config.stopEvent;
  7009. }
  7010. if(typeof keyCode == "string"){
  7011. var ks = [];
  7012. var keyString = keyCode.toUpperCase();
  7013. for(var j = 0, len = keyString.length; j < len; j++){
  7014. ks.push(keyString.charCodeAt(j));
  7015. }
  7016. keyCode = ks;
  7017. }
  7018. var keyArray = Ext.isArray(keyCode);
  7019. var handler = function(e){
  7020. if(this.checkModifiers(config, e)){
  7021. var k = e.getKey();
  7022. if(keyArray){
  7023. for(var i = 0, len = keyCode.length; i < len; i++){
  7024. if(keyCode[i] == k){
  7025. if(this.stopEvent){
  7026. e.stopEvent();
  7027. }
  7028. fn.call(scope || window, k, e);
  7029. return;
  7030. }
  7031. }
  7032. }else{
  7033. if(k == keyCode){
  7034. if(this.stopEvent){
  7035. e.stopEvent();
  7036. }
  7037. fn.call(scope || window, k, e);
  7038. }
  7039. }
  7040. }
  7041. };
  7042. this.bindings.push(handler);
  7043. },
  7044. // private
  7045. checkModifiers: function(config, e){
  7046. var val, key, keys = ['shift', 'ctrl', 'alt'];
  7047. for (var i = 0, len = keys.length; i < len; ++i){
  7048. key = keys[i];
  7049. val = config[key];
  7050. if(!(val === undefined || (val === e[key + 'Key']))){
  7051. return false;
  7052. }
  7053. }
  7054. return true;
  7055. },
  7056. /**
  7057. * Shorthand for adding a single key listener
  7058. * @param {Number/Array/Object} key Either the numeric key code, array of key codes or an object with the
  7059. * following options:
  7060. * {key: (number or array), shift: (true/false), ctrl: (true/false), alt: (true/false)}
  7061. * @param {Function} fn The function to call
  7062. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the function is executed. Defaults to the browser window.
  7063. */
  7064. on : function(key, fn, scope){
  7065. var keyCode, shift, ctrl, alt;
  7066. if(typeof key == "object" && !Ext.isArray(key)){
  7067. keyCode = key.key;
  7068. shift = key.shift;
  7069. ctrl = key.ctrl;
  7070. alt = key.alt;
  7071. }else{
  7072. keyCode = key;
  7073. }
  7074. this.addBinding({
  7075. key: keyCode,
  7076. shift: shift,
  7077. ctrl: ctrl,
  7078. alt: alt,
  7079. fn: fn,
  7080. scope: scope
  7081. });
  7082. },
  7083. // private
  7084. handleKeyDown : function(e){
  7085. if(this.enabled){ //just in case
  7086. var b = this.bindings;
  7087. for(var i = 0, len = b.length; i < len; i++){
  7088. b[i].call(this, e);
  7089. }
  7090. }
  7091. },
  7092. /**
  7093. * Returns true if this KeyMap is enabled
  7094. * @return {Boolean}
  7095. */
  7096. isEnabled : function(){
  7097. return this.enabled;
  7098. },
  7099. /**
  7100. * Enables this KeyMap
  7101. */
  7102. enable: function(){
  7103. if(!this.enabled){
  7104. this.el.on(this.eventName, this.handleKeyDown, this);
  7105. this.enabled = true;
  7106. }
  7107. },
  7108. /**
  7109. * Disable this KeyMap
  7110. */
  7111. disable: function(){
  7112. if(this.enabled){
  7113. this.el.removeListener(this.eventName, this.handleKeyDown, this);
  7114. this.enabled = false;
  7115. }
  7116. },
  7117. /**
  7118. * Convenience function for setting disabled/enabled by boolean.
  7119. * @param {Boolean} disabled
  7120. */
  7121. setDisabled : function(disabled){
  7122. this[disabled ? "disable" : "enable"]();
  7123. }
  7124. };/**
  7125. * @class Ext.util.TextMetrics
  7126. * Provides precise pixel measurements for blocks of text so that you can determine exactly how high and
  7127. * wide, in pixels, a given block of text will be. Note that when measuring text, it should be plain text and
  7128. * should not contain any HTML, otherwise it may not be measured correctly.
  7129. * @singleton
  7130. */
  7131. Ext.util.TextMetrics = function(){
  7132. var shared;
  7133. return {
  7134. /**
  7135. * Measures the size of the specified text
  7136. * @param {String/HTMLElement} el The element, dom node or id from which to copy existing CSS styles
  7137. * that can affect the size of the rendered text
  7138. * @param {String} text The text to measure
  7139. * @param {Number} fixedWidth (optional) If the text will be multiline, you have to set a fixed width
  7140. * in order to accurately measure the text height
  7141. * @return {Object} An object containing the text's size {width: (width), height: (height)}
  7142. */
  7143. measure : function(el, text, fixedWidth){
  7144. if(!shared){
  7145. shared = Ext.util.TextMetrics.Instance(el, fixedWidth);
  7146. }
  7147. shared.bind(el);
  7148. shared.setFixedWidth(fixedWidth || 'auto');
  7149. return shared.getSize(text);
  7150. },
  7151. /**
  7152. * Return a unique TextMetrics instance that can be bound directly to an element and reused. This reduces
  7153. * the overhead of multiple calls to initialize the style properties on each measurement.
  7154. * @param {String/HTMLElement} el The element, dom node or id that the instance will be bound to
  7155. * @param {Number} fixedWidth (optional) If the text will be multiline, you have to set a fixed width
  7156. * in order to accurately measure the text height
  7157. * @return {Ext.util.TextMetrics.Instance} instance The new instance
  7158. */
  7159. createInstance : function(el, fixedWidth){
  7160. return Ext.util.TextMetrics.Instance(el, fixedWidth);
  7161. }
  7162. };
  7163. }();
  7164. Ext.util.TextMetrics.Instance = function(bindTo, fixedWidth){
  7165. var ml = new Ext.Element(document.createElement('div'));
  7166. document.body.appendChild(ml.dom);
  7167. ml.position('absolute');
  7168. ml.setLeftTop(-1000, -1000);
  7169. ml.hide();
  7170. if(fixedWidth){
  7171. ml.setWidth(fixedWidth);
  7172. }
  7173. var instance = {
  7174. /**
  7175. * <p><b>Only available on the instance returned from {@link #createInstance}, <u>not</u> on the singleton.</b></p>
  7176. * Returns the size of the specified text based on the internal element's style and width properties
  7177. * @param {String} text The text to measure
  7178. * @return {Object} An object containing the text's size {width: (width), height: (height)}
  7179. */
  7180. getSize : function(text){
  7181. ml.update(text);
  7182. var s = ml.getSize();
  7183. ml.update('');
  7184. return s;
  7185. },
  7186. /**
  7187. * <p><b>Only available on the instance returned from {@link #createInstance}, <u>not</u> on the singleton.</b></p>
  7188. * Binds this TextMetrics instance to an element from which to copy existing CSS styles
  7189. * that can affect the size of the rendered text
  7190. * @param {String/HTMLElement} el The element, dom node or id
  7191. */
  7192. bind : function(el){
  7193. ml.setStyle(
  7194. Ext.fly(el).getStyles('font-size','font-style', 'font-weight', 'font-family','line-height', 'text-transform', 'letter-spacing')
  7195. );
  7196. },
  7197. /**
  7198. * <p><b>Only available on the instance returned from {@link #createInstance}, <u>not</u> on the singleton.</b></p>
  7199. * Sets a fixed width on the internal measurement element. If the text will be multiline, you have
  7200. * to set a fixed width in order to accurately measure the text height.
  7201. * @param {Number} width The width to set on the element
  7202. */
  7203. setFixedWidth : function(width){
  7204. ml.setWidth(width);
  7205. },
  7206. /**
  7207. * <p><b>Only available on the instance returned from {@link #createInstance}, <u>not</u> on the singleton.</b></p>
  7208. * Returns the measured width of the specified text
  7209. * @param {String} text The text to measure
  7210. * @return {Number} width The width in pixels
  7211. */
  7212. getWidth : function(text){
  7213. ml.dom.style.width = 'auto';
  7214. return this.getSize(text).width;
  7215. },
  7216. /**
  7217. * <p><b>Only available on the instance returned from {@link #createInstance}, <u>not</u> on the singleton.</b></p>
  7218. * Returns the measured height of the specified text. For multiline text, be sure to call
  7219. * {@link #setFixedWidth} if necessary.
  7220. * @param {String} text The text to measure
  7221. * @return {Number} height The height in pixels
  7222. */
  7223. getHeight : function(text){
  7224. return this.getSize(text).height;
  7225. }
  7226. };
  7227. instance.bind(bindTo);
  7228. return instance;
  7229. };
  7230. Ext.Element.addMethods({
  7231. /**
  7232. * Returns the width in pixels of the passed text, or the width of the text in this Element.
  7233. * @param {String} text The text to measure. Defaults to the innerHTML of the element.
  7234. * @param {Number} min (Optional) The minumum value to return.
  7235. * @param {Number} max (Optional) The maximum value to return.
  7236. * @return {Number} The text width in pixels.
  7237. * @member Ext.Element getTextWidth
  7238. */
  7239. getTextWidth : function(text, min, max){
  7240. return (Ext.util.TextMetrics.measure(this.dom, Ext.value(text, this.dom.innerHTML, true)).width).constrain(min || 0, max || 1000000);
  7241. }
  7242. });
  7243. /**
  7244. * @class Ext.util.Cookies
  7245. * Utility class for managing and interacting with cookies.
  7246. * @singleton
  7247. */
  7248. Ext.util.Cookies = {
  7249. /**
  7250. * Create a cookie with the specified name and value. Additional settings
  7251. * for the cookie may be optionally specified (for example: expiration,
  7252. * access restriction, SSL).
  7253. * @param {String} name The name of the cookie to set.
  7254. * @param {Mixed} value The value to set for the cookie.
  7255. * @param {Object} expires (Optional) Specify an expiration date the
  7256. * cookie is to persist until. Note that the specified Date object will
  7257. * be converted to Greenwich Mean Time (GMT).
  7258. * @param {String} path (Optional) Setting a path on the cookie restricts
  7259. * access to pages that match that path. Defaults to all pages (<tt>'/'</tt>).
  7260. * @param {String} domain (Optional) Setting a domain restricts access to
  7261. * pages on a given domain (typically used to allow cookie access across
  7262. * subdomains). For example, "extjs.com" will create a cookie that can be
  7263. * accessed from any subdomain of extjs.com, including www.extjs.com,
  7264. * support.extjs.com, etc.
  7265. * @param {Boolean} secure (Optional) Specify true to indicate that the cookie
  7266. * should only be accessible via SSL on a page using the HTTPS protocol.
  7267. * Defaults to <tt>false</tt>. Note that this will only work if the page
  7268. * calling this code uses the HTTPS protocol, otherwise the cookie will be
  7269. * created with default options.
  7270. */
  7271. set : function(name, value){
  7272. var argv = arguments;
  7273. var argc = arguments.length;
  7274. var expires = (argc > 2) ? argv[2] : null;
  7275. var path = (argc > 3) ? argv[3] : '/';
  7276. var domain = (argc > 4) ? argv[4] : null;
  7277. var secure = (argc > 5) ? argv[5] : false;
  7278. document.cookie = name + "=" + escape(value) + ((expires === null) ? "" : ("; expires=" + expires.toGMTString())) + ((path === null) ? "" : ("; path=" + path)) + ((domain === null) ? "" : ("; domain=" + domain)) + ((secure === true) ? "; secure" : "");
  7279. },
  7280. /**
  7281. * Retrieves cookies that are accessible by the current page. If a cookie
  7282. * does not exist, <code>get()</code> returns <tt>null</tt>. The following
  7283. * example retrieves the cookie called "valid" and stores the String value
  7284. * in the variable <tt>validStatus</tt>.
  7285. * <pre><code>
  7286. * var validStatus = Ext.util.Cookies.get("valid");
  7287. * </code></pre>
  7288. * @param {String} name The name of the cookie to get
  7289. * @return {Mixed} Returns the cookie value for the specified name;
  7290. * null if the cookie name does not exist.
  7291. */
  7292. get : function(name){
  7293. var arg = name + "=";
  7294. var alen = arg.length;
  7295. var clen = document.cookie.length;
  7296. var i = 0;
  7297. var j = 0;
  7298. while(i < clen){
  7299. j = i + alen;
  7300. if(document.cookie.substring(i, j) == arg){
  7301. return Ext.util.Cookies.getCookieVal(j);
  7302. }
  7303. i = document.cookie.indexOf(" ", i) + 1;
  7304. if(i === 0){
  7305. break;
  7306. }
  7307. }
  7308. return null;
  7309. },
  7310. /**
  7311. * Removes a cookie with the provided name from the browser
  7312. * if found by setting its expiration date to sometime in the past.
  7313. * @param {String} name The name of the cookie to remove
  7314. */
  7315. clear : function(name){
  7316. if(Ext.util.Cookies.get(name)){
  7317. document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  7318. }
  7319. },
  7320. /**
  7321. * @private
  7322. */
  7323. getCookieVal : function(offset){
  7324. var endstr = document.cookie.indexOf(";", offset);
  7325. if(endstr == -1){
  7326. endstr = document.cookie.length;
  7327. }
  7328. return unescape(document.cookie.substring(offset, endstr));
  7329. }
  7330. };/**
  7331. * Framework-wide error-handler. Developers can override this method to provide
  7332. * custom exception-handling. Framework errors will often extend from the base
  7333. * Ext.Error class.
  7334. * @param {Object/Error} e The thrown exception object.
  7335. */
  7336. Ext.handleError = function(e) {
  7337. throw e;
  7338. };
  7339. /**
  7340. * @class Ext.Error
  7341. * @extends Error
  7342. * <p>A base error class. Future implementations are intended to provide more
  7343. * robust error handling throughout the framework (<b>in the debug build only</b>)
  7344. * to check for common errors and problems. The messages issued by this class
  7345. * will aid error checking. Error checks will be automatically removed in the
  7346. * production build so that performance is not negatively impacted.</p>
  7347. * <p>Some sample messages currently implemented:</p><pre>
  7348. "DataProxy attempted to execute an API-action but found an undefined
  7349. url / function. Please review your Proxy url/api-configuration."
  7350. * </pre><pre>
  7351. "Could not locate your "root" property in your server response.
  7352. Please review your JsonReader config to ensure the config-property
  7353. "root" matches the property your server-response. See the JsonReader
  7354. docs for additional assistance."
  7355. * </pre>
  7356. * <p>An example of the code used for generating error messages:</p><pre><code>
  7357. try {
  7358. generateError({
  7359. foo: 'bar'
  7360. });
  7361. }
  7362. catch (e) {
  7363. console.error(e);
  7364. }
  7365. function generateError(data) {
  7366. throw new Ext.Error('foo-error', data);
  7367. }
  7368. * </code></pre>
  7369. * @param {String} message
  7370. */
  7371. Ext.Error = function(message) {
  7372. // Try to read the message from Ext.Error.lang
  7373. this.message = (this.lang[message]) ? this.lang[message] : message;
  7374. };
  7375. Ext.Error.prototype = new Error();
  7376. Ext.apply(Ext.Error.prototype, {
  7377. // protected. Extensions place their error-strings here.
  7378. lang: {},
  7379. name: 'Ext.Error',
  7380. /**
  7381. * getName
  7382. * @return {String}
  7383. */
  7384. getName : function() {
  7385. return this.name;
  7386. },
  7387. /**
  7388. * getMessage
  7389. * @return {String}
  7390. */
  7391. getMessage : function() {
  7392. return this.message;
  7393. },
  7394. /**
  7395. * toJson
  7396. * @return {String}
  7397. */
  7398. toJson : function() {
  7399. return Ext.encode(this);
  7400. }
  7401. });