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.

7918 lines
294 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. (function(){
  8. var EXTUTIL = Ext.util,
  9. EACH = Ext.each,
  10. TRUE = true,
  11. FALSE = false;
  12. /**
  13. * @class Ext.util.Observable
  14. * Base class that provides a common interface for publishing events. Subclasses are expected to
  15. * to have a property "events" with all the events defined, and, optionally, a property "listeners"
  16. * with configured listeners defined.<br>
  17. * For example:
  18. * <pre><code>
  19. Employee = Ext.extend(Ext.util.Observable, {
  20. constructor: function(config){
  21. this.name = config.name;
  22. this.addEvents({
  23. "fired" : true,
  24. "quit" : true
  25. });
  26. // Copy configured listeners into *this* object so that the base class&#39;s
  27. // constructor will add them.
  28. this.listeners = config.listeners;
  29. // Call our superclass constructor to complete construction process.
  30. Employee.superclass.constructor.call(this, config)
  31. }
  32. });
  33. </code></pre>
  34. * This could then be used like this:<pre><code>
  35. var newEmployee = new Employee({
  36. name: employeeName,
  37. listeners: {
  38. quit: function() {
  39. // By default, "this" will be the object that fired the event.
  40. alert(this.name + " has quit!");
  41. }
  42. }
  43. });
  44. </code></pre>
  45. */
  46. EXTUTIL.Observable = function(){
  47. /**
  48. * @cfg {Object} listeners (optional) <p>A config object containing one or more event handlers to be added to this
  49. * object during initialization. This should be a valid listeners config object as specified in the
  50. * {@link #addListener} example for attaching multiple handlers at once.</p>
  51. * <br><p><b><u>DOM events from ExtJs {@link Ext.Component Components}</u></b></p>
  52. * <br><p>While <i>some</i> ExtJs Component classes export selected DOM events (e.g. "click", "mouseover" etc), this
  53. * is usually only done when extra value can be added. For example the {@link Ext.DataView DataView}'s
  54. * <b><code>{@link Ext.DataView#click click}</code></b> event passing the node clicked on. To access DOM
  55. * events directly from a Component's HTMLElement, listeners must be added to the <i>{@link Ext.Component#getEl Element}</i> after the Component
  56. * has been rendered. A plugin can simplify this step:<pre><code>
  57. // Plugin is configured with a listeners config object.
  58. // The Component is appended to the argument list of all handler functions.
  59. Ext.DomObserver = Ext.extend(Object, {
  60. constructor: function(config) {
  61. this.listeners = config.listeners ? config.listeners : config;
  62. },
  63. // Component passes itself into plugin&#39;s init method
  64. init: function(c) {
  65. var p, l = this.listeners;
  66. for (p in l) {
  67. if (Ext.isFunction(l[p])) {
  68. l[p] = this.createHandler(l[p], c);
  69. } else {
  70. l[p].fn = this.createHandler(l[p].fn, c);
  71. }
  72. }
  73. // Add the listeners to the Element immediately following the render call
  74. c.render = c.render.{@link Function#createSequence createSequence}(function() {
  75. var e = c.getEl();
  76. if (e) {
  77. e.on(l);
  78. }
  79. });
  80. },
  81. createHandler: function(fn, c) {
  82. return function(e) {
  83. fn.call(this, e, c);
  84. };
  85. }
  86. });
  87. var combo = new Ext.form.ComboBox({
  88. // Collapse combo when its element is clicked on
  89. plugins: [ new Ext.DomObserver({
  90. click: function(evt, comp) {
  91. comp.collapse();
  92. }
  93. })],
  94. store: myStore,
  95. typeAhead: true,
  96. mode: 'local',
  97. triggerAction: 'all'
  98. });
  99. * </code></pre></p>
  100. */
  101. var me = this, e = me.events;
  102. if(me.listeners){
  103. me.on(me.listeners);
  104. delete me.listeners;
  105. }
  106. me.events = e || {};
  107. };
  108. EXTUTIL.Observable.prototype = {
  109. // private
  110. filterOptRe : /^(?:scope|delay|buffer|single)$/,
  111. /**
  112. * <p>Fires the specified event with the passed parameters (minus the event name).</p>
  113. * <p>An event may be set to bubble up an Observable parent hierarchy (See {@link Ext.Component#getBubbleTarget})
  114. * by calling {@link #enableBubble}.</p>
  115. * @param {String} eventName The name of the event to fire.
  116. * @param {Object...} args Variable number of parameters are passed to handlers.
  117. * @return {Boolean} returns false if any of the handlers return false otherwise it returns true.
  118. */
  119. fireEvent : function(){
  120. var a = Array.prototype.slice.call(arguments, 0),
  121. ename = a[0].toLowerCase(),
  122. me = this,
  123. ret = TRUE,
  124. ce = me.events[ename],
  125. cc,
  126. q,
  127. c;
  128. if (me.eventsSuspended === TRUE) {
  129. if (q = me.eventQueue) {
  130. q.push(a);
  131. }
  132. }
  133. else if(typeof ce == 'object') {
  134. if (ce.bubble){
  135. if(ce.fire.apply(ce, a.slice(1)) === FALSE) {
  136. return FALSE;
  137. }
  138. c = me.getBubbleTarget && me.getBubbleTarget();
  139. if(c && c.enableBubble) {
  140. cc = c.events[ename];
  141. if(!cc || typeof cc != 'object' || !cc.bubble) {
  142. c.enableBubble(ename);
  143. }
  144. return c.fireEvent.apply(c, a);
  145. }
  146. }
  147. else {
  148. a.shift();
  149. ret = ce.fire.apply(ce, a);
  150. }
  151. }
  152. return ret;
  153. },
  154. /**
  155. * Appends an event handler to this object.
  156. * @param {String} eventName The name of the event to listen for.
  157. * @param {Function} handler The method the event invokes.
  158. * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the handler function is executed.
  159. * <b>If omitted, defaults to the object which fired the event.</b>
  160. * @param {Object} options (optional) An object containing handler configuration.
  161. * properties. This may contain any of the following properties:<ul>
  162. * <li><b>scope</b> : Object<div class="sub-desc">The scope (<code><b>this</b></code> reference) in which the handler function is executed.
  163. * <b>If omitted, defaults to the object which fired the event.</b></div></li>
  164. * <li><b>delay</b> : Number<div class="sub-desc">The number of milliseconds to delay the invocation of the handler after the event fires.</div></li>
  165. * <li><b>single</b> : Boolean<div class="sub-desc">True to add a handler to handle just the next firing of the event, and then remove itself.</div></li>
  166. * <li><b>buffer</b> : Number<div class="sub-desc">Causes the handler to be scheduled to run in an {@link Ext.util.DelayedTask} delayed
  167. * by the specified number of milliseconds. If the event fires again within that time, the original
  168. * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</div></li>
  169. * <li><b>target</b> : Observable<div class="sub-desc">Only call the handler if the event was fired on the target Observable, <i>not</i>
  170. * if the event was bubbled up from a child Observable.</div></li>
  171. * </ul><br>
  172. * <p>
  173. * <b>Combining Options</b><br>
  174. * Using the options argument, it is possible to combine different types of listeners:<br>
  175. * <br>
  176. * A delayed, one-time listener.
  177. * <pre><code>
  178. myDataView.on('click', this.onClick, this, {
  179. single: true,
  180. delay: 100
  181. });</code></pre>
  182. * <p>
  183. * <b>Attaching multiple handlers in 1 call</b><br>
  184. * The method also allows for a single argument to be passed which is a config object containing properties
  185. * which specify multiple handlers.
  186. * <p>
  187. * <pre><code>
  188. myGridPanel.on({
  189. 'click' : {
  190. fn: this.onClick,
  191. scope: this,
  192. delay: 100
  193. },
  194. 'mouseover' : {
  195. fn: this.onMouseOver,
  196. scope: this
  197. },
  198. 'mouseout' : {
  199. fn: this.onMouseOut,
  200. scope: this
  201. }
  202. });</code></pre>
  203. * <p>
  204. * Or a shorthand syntax:<br>
  205. * <pre><code>
  206. myGridPanel.on({
  207. 'click' : this.onClick,
  208. 'mouseover' : this.onMouseOver,
  209. 'mouseout' : this.onMouseOut,
  210. scope: this
  211. });</code></pre>
  212. */
  213. addListener : function(eventName, fn, scope, o){
  214. var me = this,
  215. e,
  216. oe,
  217. ce;
  218. if (typeof eventName == 'object') {
  219. o = eventName;
  220. for (e in o) {
  221. oe = o[e];
  222. if (!me.filterOptRe.test(e)) {
  223. me.addListener(e, oe.fn || oe, oe.scope || o.scope, oe.fn ? oe : o);
  224. }
  225. }
  226. } else {
  227. eventName = eventName.toLowerCase();
  228. ce = me.events[eventName] || TRUE;
  229. if (typeof ce == 'boolean') {
  230. me.events[eventName] = ce = new EXTUTIL.Event(me, eventName);
  231. }
  232. ce.addListener(fn, scope, typeof o == 'object' ? o : {});
  233. }
  234. },
  235. /**
  236. * Removes an event handler.
  237. * @param {String} eventName The type of event the handler was associated with.
  238. * @param {Function} handler The handler to remove. <b>This must be a reference to the function passed into the {@link #addListener} call.</b>
  239. * @param {Object} scope (optional) The scope originally specified for the handler.
  240. */
  241. removeListener : function(eventName, fn, scope){
  242. var ce = this.events[eventName.toLowerCase()];
  243. if (typeof ce == 'object') {
  244. ce.removeListener(fn, scope);
  245. }
  246. },
  247. /**
  248. * Removes all listeners for this object
  249. */
  250. purgeListeners : function(){
  251. var events = this.events,
  252. evt,
  253. key;
  254. for(key in events){
  255. evt = events[key];
  256. if(typeof evt == 'object'){
  257. evt.clearListeners();
  258. }
  259. }
  260. },
  261. /**
  262. * Adds the specified events to the list of events which this Observable may fire.
  263. * @param {Object|String} o Either an object with event names as properties with a value of <code>true</code>
  264. * or the first event name string if multiple event names are being passed as separate parameters.
  265. * @param {string} Optional. Event name if multiple event names are being passed as separate parameters.
  266. * Usage:<pre><code>
  267. this.addEvents('storeloaded', 'storecleared');
  268. </code></pre>
  269. */
  270. addEvents : function(o){
  271. var me = this;
  272. me.events = me.events || {};
  273. if (typeof o == 'string') {
  274. var a = arguments,
  275. i = a.length;
  276. while(i--) {
  277. me.events[a[i]] = me.events[a[i]] || TRUE;
  278. }
  279. } else {
  280. Ext.applyIf(me.events, o);
  281. }
  282. },
  283. /**
  284. * Checks to see if this object has any listeners for a specified event
  285. * @param {String} eventName The name of the event to check for
  286. * @return {Boolean} True if the event is being listened for, else false
  287. */
  288. hasListener : function(eventName){
  289. var e = this.events[eventName.toLowerCase()];
  290. return typeof e == 'object' && e.listeners.length > 0;
  291. },
  292. /**
  293. * Suspend the firing of all events. (see {@link #resumeEvents})
  294. * @param {Boolean} queueSuspended Pass as true to queue up suspended events to be fired
  295. * after the {@link #resumeEvents} call instead of discarding all suspended events;
  296. */
  297. suspendEvents : function(queueSuspended){
  298. this.eventsSuspended = TRUE;
  299. if(queueSuspended && !this.eventQueue){
  300. this.eventQueue = [];
  301. }
  302. },
  303. /**
  304. * Resume firing events. (see {@link #suspendEvents})
  305. * If events were suspended using the <tt><b>queueSuspended</b></tt> parameter, then all
  306. * events fired during event suspension will be sent to any listeners now.
  307. */
  308. resumeEvents : function(){
  309. var me = this,
  310. queued = me.eventQueue || [];
  311. me.eventsSuspended = FALSE;
  312. delete me.eventQueue;
  313. EACH(queued, function(e) {
  314. me.fireEvent.apply(me, e);
  315. });
  316. }
  317. };
  318. var OBSERVABLE = EXTUTIL.Observable.prototype;
  319. /**
  320. * Appends an event handler to this object (shorthand for {@link #addListener}.)
  321. * @param {String} eventName The type of event to listen for
  322. * @param {Function} handler The method the event invokes
  323. * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the handler function is executed.
  324. * <b>If omitted, defaults to the object which fired the event.</b>
  325. * @param {Object} options (optional) An object containing handler configuration.
  326. * @method
  327. */
  328. OBSERVABLE.on = OBSERVABLE.addListener;
  329. /**
  330. * Removes an event handler (shorthand for {@link #removeListener}.)
  331. * @param {String} eventName The type of event the handler was associated with.
  332. * @param {Function} handler The handler to remove. <b>This must be a reference to the function passed into the {@link #addListener} call.</b>
  333. * @param {Object} scope (optional) The scope originally specified for the handler.
  334. * @method
  335. */
  336. OBSERVABLE.un = OBSERVABLE.removeListener;
  337. /**
  338. * Removes <b>all</b> added captures from the Observable.
  339. * @param {Observable} o The Observable to release
  340. * @static
  341. */
  342. EXTUTIL.Observable.releaseCapture = function(o){
  343. o.fireEvent = OBSERVABLE.fireEvent;
  344. };
  345. function createTargeted(h, o, scope){
  346. return function(){
  347. if(o.target == arguments[0]){
  348. h.apply(scope, Array.prototype.slice.call(arguments, 0));
  349. }
  350. };
  351. };
  352. function createBuffered(h, o, l, scope){
  353. l.task = new EXTUTIL.DelayedTask();
  354. return function(){
  355. l.task.delay(o.buffer, h, scope, Array.prototype.slice.call(arguments, 0));
  356. };
  357. };
  358. function createSingle(h, e, fn, scope){
  359. return function(){
  360. e.removeListener(fn, scope);
  361. return h.apply(scope, arguments);
  362. };
  363. };
  364. function createDelayed(h, o, l, scope){
  365. return function(){
  366. var task = new EXTUTIL.DelayedTask(),
  367. args = Array.prototype.slice.call(arguments, 0);
  368. if(!l.tasks) {
  369. l.tasks = [];
  370. }
  371. l.tasks.push(task);
  372. task.delay(o.delay || 10, function(){
  373. l.tasks.remove(task);
  374. h.apply(scope, args);
  375. }, scope);
  376. };
  377. };
  378. EXTUTIL.Event = function(obj, name){
  379. this.name = name;
  380. this.obj = obj;
  381. this.listeners = [];
  382. };
  383. EXTUTIL.Event.prototype = {
  384. addListener : function(fn, scope, options){
  385. var me = this,
  386. l;
  387. scope = scope || me.obj;
  388. if(!me.isListening(fn, scope)){
  389. l = me.createListener(fn, scope, options);
  390. if(me.firing){ // if we are currently firing this event, don't disturb the listener loop
  391. me.listeners = me.listeners.slice(0);
  392. }
  393. me.listeners.push(l);
  394. }
  395. },
  396. createListener: function(fn, scope, o){
  397. o = o || {};
  398. scope = scope || this.obj;
  399. var l = {
  400. fn: fn,
  401. scope: scope,
  402. options: o
  403. }, h = fn;
  404. if(o.target){
  405. h = createTargeted(h, o, scope);
  406. }
  407. if(o.delay){
  408. h = createDelayed(h, o, l, scope);
  409. }
  410. if(o.single){
  411. h = createSingle(h, this, fn, scope);
  412. }
  413. if(o.buffer){
  414. h = createBuffered(h, o, l, scope);
  415. }
  416. l.fireFn = h;
  417. return l;
  418. },
  419. findListener : function(fn, scope){
  420. var list = this.listeners,
  421. i = list.length,
  422. l;
  423. scope = scope || this.obj;
  424. while(i--){
  425. l = list[i];
  426. if(l){
  427. if(l.fn == fn && l.scope == scope){
  428. return i;
  429. }
  430. }
  431. }
  432. return -1;
  433. },
  434. isListening : function(fn, scope){
  435. return this.findListener(fn, scope) != -1;
  436. },
  437. removeListener : function(fn, scope){
  438. var index,
  439. l,
  440. k,
  441. me = this,
  442. ret = FALSE;
  443. if((index = me.findListener(fn, scope)) != -1){
  444. if (me.firing) {
  445. me.listeners = me.listeners.slice(0);
  446. }
  447. l = me.listeners[index];
  448. if(l.task) {
  449. l.task.cancel();
  450. delete l.task;
  451. }
  452. k = l.tasks && l.tasks.length;
  453. if(k) {
  454. while(k--) {
  455. l.tasks[k].cancel();
  456. }
  457. delete l.tasks;
  458. }
  459. me.listeners.splice(index, 1);
  460. ret = TRUE;
  461. }
  462. return ret;
  463. },
  464. // Iterate to stop any buffered/delayed events
  465. clearListeners : function(){
  466. var me = this,
  467. l = me.listeners,
  468. i = l.length;
  469. while(i--) {
  470. me.removeListener(l[i].fn, l[i].scope);
  471. }
  472. },
  473. fire : function(){
  474. var me = this,
  475. listeners = me.listeners,
  476. len = listeners.length,
  477. i = 0,
  478. l;
  479. if(len > 0){
  480. me.firing = TRUE;
  481. var args = Array.prototype.slice.call(arguments, 0);
  482. for (; i < len; i++) {
  483. l = listeners[i];
  484. if(l && l.fireFn.apply(l.scope || me.obj || window, args) === FALSE) {
  485. return (me.firing = FALSE);
  486. }
  487. }
  488. }
  489. me.firing = FALSE;
  490. return TRUE;
  491. }
  492. };
  493. })();
  494. /**
  495. * @class Ext.DomHelper
  496. * <p>The DomHelper class provides a layer of abstraction from DOM and transparently supports creating
  497. * elements via DOM or using HTML fragments. It also has the ability to create HTML fragment templates
  498. * from your DOM building code.</p>
  499. *
  500. * <p><b><u>DomHelper element specification object</u></b></p>
  501. * <p>A specification object is used when creating elements. Attributes of this object
  502. * are assumed to be element attributes, except for 4 special attributes:
  503. * <div class="mdetail-params"><ul>
  504. * <li><b><tt>tag</tt></b> : <div class="sub-desc">The tag name of the element</div></li>
  505. * <li><b><tt>children</tt></b> : or <tt>cn</tt><div class="sub-desc">An array of the
  506. * same kind of element definition objects to be created and appended. These can be nested
  507. * as deep as you want.</div></li>
  508. * <li><b><tt>cls</tt></b> : <div class="sub-desc">The class attribute of the element.
  509. * This will end up being either the "class" attribute on a HTML fragment or className
  510. * for a DOM node, depending on whether DomHelper is using fragments or DOM.</div></li>
  511. * <li><b><tt>html</tt></b> : <div class="sub-desc">The innerHTML for the element</div></li>
  512. * </ul></div></p>
  513. *
  514. * <p><b><u>Insertion methods</u></b></p>
  515. * <p>Commonly used insertion methods:
  516. * <div class="mdetail-params"><ul>
  517. * <li><b><tt>{@link #append}</tt></b> : <div class="sub-desc"></div></li>
  518. * <li><b><tt>{@link #insertBefore}</tt></b> : <div class="sub-desc"></div></li>
  519. * <li><b><tt>{@link #insertAfter}</tt></b> : <div class="sub-desc"></div></li>
  520. * <li><b><tt>{@link #overwrite}</tt></b> : <div class="sub-desc"></div></li>
  521. * <li><b><tt>{@link #createTemplate}</tt></b> : <div class="sub-desc"></div></li>
  522. * <li><b><tt>{@link #insertHtml}</tt></b> : <div class="sub-desc"></div></li>
  523. * </ul></div></p>
  524. *
  525. * <p><b><u>Example</u></b></p>
  526. * <p>This is an example, where an unordered list with 3 children items is appended to an existing
  527. * element with id <tt>'my-div'</tt>:<br>
  528. <pre><code>
  529. var dh = Ext.DomHelper; // create shorthand alias
  530. // specification object
  531. var spec = {
  532. id: 'my-ul',
  533. tag: 'ul',
  534. cls: 'my-list',
  535. // append children after creating
  536. children: [ // may also specify 'cn' instead of 'children'
  537. {tag: 'li', id: 'item0', html: 'List Item 0'},
  538. {tag: 'li', id: 'item1', html: 'List Item 1'},
  539. {tag: 'li', id: 'item2', html: 'List Item 2'}
  540. ]
  541. };
  542. var list = dh.append(
  543. 'my-div', // the context element 'my-div' can either be the id or the actual node
  544. spec // the specification object
  545. );
  546. </code></pre></p>
  547. * <p>Element creation specification parameters in this class may also be passed as an Array of
  548. * specification objects. This can be used to insert multiple sibling nodes into an existing
  549. * container very efficiently. For example, to add more list items to the example above:<pre><code>
  550. dh.append('my-ul', [
  551. {tag: 'li', id: 'item3', html: 'List Item 3'},
  552. {tag: 'li', id: 'item4', html: 'List Item 4'}
  553. ]);
  554. * </code></pre></p>
  555. *
  556. * <p><b><u>Templating</u></b></p>
  557. * <p>The real power is in the built-in templating. Instead of creating or appending any elements,
  558. * <tt>{@link #createTemplate}</tt> returns a Template object which can be used over and over to
  559. * insert new elements. Revisiting the example above, we could utilize templating this time:
  560. * <pre><code>
  561. // create the node
  562. var list = dh.append('my-div', {tag: 'ul', cls: 'my-list'});
  563. // get template
  564. var tpl = dh.createTemplate({tag: 'li', id: 'item{0}', html: 'List Item {0}'});
  565. for(var i = 0; i < 5, i++){
  566. tpl.append(list, [i]); // use template to append to the actual node
  567. }
  568. * </code></pre></p>
  569. * <p>An example using a template:<pre><code>
  570. var html = '<a id="{0}" href="{1}" class="nav">{2}</a>';
  571. var tpl = new Ext.DomHelper.createTemplate(html);
  572. tpl.append('blog-roll', ['link1', 'http://www.jackslocum.com/', "Jack&#39;s Site"]);
  573. tpl.append('blog-roll', ['link2', 'http://www.dustindiaz.com/', "Dustin&#39;s Site"]);
  574. * </code></pre></p>
  575. *
  576. * <p>The same example using named parameters:<pre><code>
  577. var html = '<a id="{id}" href="{url}" class="nav">{text}</a>';
  578. var tpl = new Ext.DomHelper.createTemplate(html);
  579. tpl.append('blog-roll', {
  580. id: 'link1',
  581. url: 'http://www.jackslocum.com/',
  582. text: "Jack&#39;s Site"
  583. });
  584. tpl.append('blog-roll', {
  585. id: 'link2',
  586. url: 'http://www.dustindiaz.com/',
  587. text: "Dustin&#39;s Site"
  588. });
  589. * </code></pre></p>
  590. *
  591. * <p><b><u>Compiling Templates</u></b></p>
  592. * <p>Templates are applied using regular expressions. The performance is great, but if
  593. * you are adding a bunch of DOM elements using the same template, you can increase
  594. * performance even further by {@link Ext.Template#compile "compiling"} the template.
  595. * The way "{@link Ext.Template#compile compile()}" works is the template is parsed and
  596. * broken up at the different variable points and a dynamic function is created and eval'ed.
  597. * The generated function performs string concatenation of these parts and the passed
  598. * variables instead of using regular expressions.
  599. * <pre><code>
  600. var html = '<a id="{id}" href="{url}" class="nav">{text}</a>';
  601. var tpl = new Ext.DomHelper.createTemplate(html);
  602. tpl.compile();
  603. //... use template like normal
  604. * </code></pre></p>
  605. *
  606. * <p><b><u>Performance Boost</u></b></p>
  607. * <p>DomHelper will transparently create HTML fragments when it can. Using HTML fragments instead
  608. * of DOM can significantly boost performance.</p>
  609. * <p>Element creation specification parameters may also be strings. If {@link #useDom} is <tt>false</tt>,
  610. * then the string is used as innerHTML. If {@link #useDom} is <tt>true</tt>, a string specification
  611. * results in the creation of a text node. Usage:</p>
  612. * <pre><code>
  613. Ext.DomHelper.useDom = true; // force it to use DOM; reduces performance
  614. * </code></pre>
  615. * @singleton
  616. */
  617. Ext.DomHelper = function(){
  618. var tempTableEl = null,
  619. emptyTags = /^(?:br|frame|hr|img|input|link|meta|range|spacer|wbr|area|param|col)$/i,
  620. tableRe = /^table|tbody|tr|td$/i,
  621. confRe = /tag|children|cn|html$/i,
  622. tableElRe = /td|tr|tbody/i,
  623. cssRe = /([a-z0-9-]+)\s*:\s*([^;\s]+(?:\s*[^;\s]+)*);?/gi,
  624. endRe = /end/i,
  625. pub,
  626. // kill repeat to save bytes
  627. afterbegin = 'afterbegin',
  628. afterend = 'afterend',
  629. beforebegin = 'beforebegin',
  630. beforeend = 'beforeend',
  631. ts = '<table>',
  632. te = '</table>',
  633. tbs = ts+'<tbody>',
  634. tbe = '</tbody>'+te,
  635. trs = tbs + '<tr>',
  636. tre = '</tr>'+tbe;
  637. // private
  638. function doInsert(el, o, returnElement, pos, sibling, append){
  639. var newNode = pub.insertHtml(pos, Ext.getDom(el), createHtml(o));
  640. return returnElement ? Ext.get(newNode, true) : newNode;
  641. }
  642. // build as innerHTML where available
  643. function createHtml(o){
  644. var b = '',
  645. attr,
  646. val,
  647. key,
  648. cn;
  649. if(typeof o == "string"){
  650. b = o;
  651. } else if (Ext.isArray(o)) {
  652. for (var i=0; i < o.length; i++) {
  653. if(o[i]) {
  654. b += createHtml(o[i]);
  655. }
  656. };
  657. } else {
  658. b += '<' + (o.tag = o.tag || 'div');
  659. for (attr in o) {
  660. val = o[attr];
  661. if(!confRe.test(attr)){
  662. if (typeof val == "object") {
  663. b += ' ' + attr + '="';
  664. for (key in val) {
  665. b += key + ':' + val[key] + ';';
  666. };
  667. b += '"';
  668. }else{
  669. b += ' ' + ({cls : 'class', htmlFor : 'for'}[attr] || attr) + '="' + val + '"';
  670. }
  671. }
  672. };
  673. // Now either just close the tag or try to add children and close the tag.
  674. if (emptyTags.test(o.tag)) {
  675. b += '/>';
  676. } else {
  677. b += '>';
  678. if ((cn = o.children || o.cn)) {
  679. b += createHtml(cn);
  680. } else if(o.html){
  681. b += o.html;
  682. }
  683. b += '</' + o.tag + '>';
  684. }
  685. }
  686. return b;
  687. }
  688. function ieTable(depth, s, h, e){
  689. tempTableEl.innerHTML = [s, h, e].join('');
  690. var i = -1,
  691. el = tempTableEl,
  692. ns;
  693. while(++i < depth){
  694. el = el.firstChild;
  695. }
  696. // If the result is multiple siblings, then encapsulate them into one fragment.
  697. if(ns = el.nextSibling){
  698. var df = document.createDocumentFragment();
  699. while(el){
  700. ns = el.nextSibling;
  701. df.appendChild(el);
  702. el = ns;
  703. }
  704. el = df;
  705. }
  706. return el;
  707. }
  708. /**
  709. * @ignore
  710. * Nasty code for IE's broken table implementation
  711. */
  712. function insertIntoTable(tag, where, el, html) {
  713. var node,
  714. before;
  715. tempTableEl = tempTableEl || document.createElement('div');
  716. if(tag == 'td' && (where == afterbegin || where == beforeend) ||
  717. !tableElRe.test(tag) && (where == beforebegin || where == afterend)) {
  718. return;
  719. }
  720. before = where == beforebegin ? el :
  721. where == afterend ? el.nextSibling :
  722. where == afterbegin ? el.firstChild : null;
  723. if (where == beforebegin || where == afterend) {
  724. el = el.parentNode;
  725. }
  726. if (tag == 'td' || (tag == 'tr' && (where == beforeend || where == afterbegin))) {
  727. node = ieTable(4, trs, html, tre);
  728. } else if ((tag == 'tbody' && (where == beforeend || where == afterbegin)) ||
  729. (tag == 'tr' && (where == beforebegin || where == afterend))) {
  730. node = ieTable(3, tbs, html, tbe);
  731. } else {
  732. node = ieTable(2, ts, html, te);
  733. }
  734. el.insertBefore(node, before);
  735. return node;
  736. }
  737. pub = {
  738. /**
  739. * Returns the markup for the passed Element(s) config.
  740. * @param {Object} o The DOM object spec (and children)
  741. * @return {String}
  742. */
  743. markup : function(o){
  744. return createHtml(o);
  745. },
  746. /**
  747. * Applies a style specification to an element.
  748. * @param {String/HTMLElement} el The element to apply styles to
  749. * @param {String/Object/Function} styles A style specification string e.g. 'width:100px', or object in the form {width:'100px'}, or
  750. * a function which returns such a specification.
  751. */
  752. applyStyles : function(el, styles){
  753. if (styles) {
  754. var matches;
  755. el = Ext.fly(el);
  756. if (typeof styles == "function") {
  757. styles = styles.call();
  758. }
  759. if (typeof styles == "string") {
  760. /**
  761. * Since we're using the g flag on the regex, we need to set the lastIndex.
  762. * This automatically happens on some implementations, but not others, see:
  763. * http://stackoverflow.com/questions/2645273/javascript-regular-expression-literal-persists-between-function-calls
  764. * http://blog.stevenlevithan.com/archives/fixing-javascript-regexp
  765. */
  766. cssRe.lastIndex = 0;
  767. while ((matches = cssRe.exec(styles))) {
  768. el.setStyle(matches[1], matches[2]);
  769. }
  770. } else if (typeof styles == "object") {
  771. el.setStyle(styles);
  772. }
  773. }
  774. },
  775. /**
  776. * Inserts an HTML fragment into the DOM.
  777. * @param {String} where Where to insert the html in relation to el - beforeBegin, afterBegin, beforeEnd, afterEnd.
  778. * @param {HTMLElement} el The context element
  779. * @param {String} html The HTML fragment
  780. * @return {HTMLElement} The new node
  781. */
  782. insertHtml : function(where, el, html){
  783. var hash = {},
  784. hashVal,
  785. setStart,
  786. range,
  787. frag,
  788. rangeEl,
  789. rs;
  790. where = where.toLowerCase();
  791. // add these here because they are used in both branches of the condition.
  792. hash[beforebegin] = ['BeforeBegin', 'previousSibling'];
  793. hash[afterend] = ['AfterEnd', 'nextSibling'];
  794. if (el.insertAdjacentHTML) {
  795. if(tableRe.test(el.tagName) && (rs = insertIntoTable(el.tagName.toLowerCase(), where, el, html))){
  796. return rs;
  797. }
  798. // add these two to the hash.
  799. hash[afterbegin] = ['AfterBegin', 'firstChild'];
  800. hash[beforeend] = ['BeforeEnd', 'lastChild'];
  801. if ((hashVal = hash[where])) {
  802. el.insertAdjacentHTML(hashVal[0], html);
  803. return el[hashVal[1]];
  804. }
  805. } else {
  806. range = el.ownerDocument.createRange();
  807. setStart = 'setStart' + (endRe.test(where) ? 'After' : 'Before');
  808. if (hash[where]) {
  809. range[setStart](el);
  810. frag = range.createContextualFragment(html);
  811. el.parentNode.insertBefore(frag, where == beforebegin ? el : el.nextSibling);
  812. return el[(where == beforebegin ? 'previous' : 'next') + 'Sibling'];
  813. } else {
  814. rangeEl = (where == afterbegin ? 'first' : 'last') + 'Child';
  815. if (el.firstChild) {
  816. range[setStart](el[rangeEl]);
  817. frag = range.createContextualFragment(html);
  818. if(where == afterbegin){
  819. el.insertBefore(frag, el.firstChild);
  820. }else{
  821. el.appendChild(frag);
  822. }
  823. } else {
  824. el.innerHTML = html;
  825. }
  826. return el[rangeEl];
  827. }
  828. }
  829. throw 'Illegal insertion point -> "' + where + '"';
  830. },
  831. /**
  832. * Creates new DOM element(s) and inserts them before el.
  833. * @param {Mixed} el The context element
  834. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  835. * @param {Boolean} returnElement (optional) true to return a Ext.Element
  836. * @return {HTMLElement/Ext.Element} The new node
  837. */
  838. insertBefore : function(el, o, returnElement){
  839. return doInsert(el, o, returnElement, beforebegin);
  840. },
  841. /**
  842. * Creates new DOM element(s) and inserts them after el.
  843. * @param {Mixed} el The context element
  844. * @param {Object} o The DOM object spec (and children)
  845. * @param {Boolean} returnElement (optional) true to return a Ext.Element
  846. * @return {HTMLElement/Ext.Element} The new node
  847. */
  848. insertAfter : function(el, o, returnElement){
  849. return doInsert(el, o, returnElement, afterend, 'nextSibling');
  850. },
  851. /**
  852. * Creates new DOM element(s) and inserts them as the first child of el.
  853. * @param {Mixed} el The context element
  854. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  855. * @param {Boolean} returnElement (optional) true to return a Ext.Element
  856. * @return {HTMLElement/Ext.Element} The new node
  857. */
  858. insertFirst : function(el, o, returnElement){
  859. return doInsert(el, o, returnElement, afterbegin, 'firstChild');
  860. },
  861. /**
  862. * Creates new DOM element(s) and appends them to el.
  863. * @param {Mixed} el The context element
  864. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  865. * @param {Boolean} returnElement (optional) true to return a Ext.Element
  866. * @return {HTMLElement/Ext.Element} The new node
  867. */
  868. append : function(el, o, returnElement){
  869. return doInsert(el, o, returnElement, beforeend, '', true);
  870. },
  871. /**
  872. * Creates new DOM element(s) and overwrites the contents of el with them.
  873. * @param {Mixed} el The context element
  874. * @param {Object/String} o The DOM object spec (and children) or raw HTML blob
  875. * @param {Boolean} returnElement (optional) true to return a Ext.Element
  876. * @return {HTMLElement/Ext.Element} The new node
  877. */
  878. overwrite : function(el, o, returnElement){
  879. el = Ext.getDom(el);
  880. el.innerHTML = createHtml(o);
  881. return returnElement ? Ext.get(el.firstChild) : el.firstChild;
  882. },
  883. createHtml : createHtml
  884. };
  885. return pub;
  886. }();
  887. /**
  888. * @class Ext.Template
  889. * <p>Represents an HTML fragment template. Templates may be {@link #compile precompiled}
  890. * for greater performance.</p>
  891. * <p>For example usage {@link #Template see the constructor}.</p>
  892. *
  893. * @constructor
  894. * An instance of this class may be created by passing to the constructor either
  895. * a single argument, or multiple arguments:
  896. * <div class="mdetail-params"><ul>
  897. * <li><b>single argument</b> : String/Array
  898. * <div class="sub-desc">
  899. * The single argument may be either a String or an Array:<ul>
  900. * <li><tt>String</tt> : </li><pre><code>
  901. var t = new Ext.Template("&lt;div>Hello {0}.&lt;/div>");
  902. t.{@link #append}('some-element', ['foo']);
  903. * </code></pre>
  904. * <li><tt>Array</tt> : </li>
  905. * An Array will be combined with <code>join('')</code>.
  906. <pre><code>
  907. var t = new Ext.Template([
  908. '&lt;div name="{id}"&gt;',
  909. '&lt;span class="{cls}"&gt;{name:trim} {value:ellipsis(10)}&lt;/span&gt;',
  910. '&lt;/div&gt;',
  911. ]);
  912. t.{@link #compile}();
  913. t.{@link #append}('some-element', {id: 'myid', cls: 'myclass', name: 'foo', value: 'bar'});
  914. </code></pre>
  915. * </ul></div></li>
  916. * <li><b>multiple arguments</b> : String, Object, Array, ...
  917. * <div class="sub-desc">
  918. * Multiple arguments will be combined with <code>join('')</code>.
  919. * <pre><code>
  920. var t = new Ext.Template(
  921. '&lt;div name="{id}"&gt;',
  922. '&lt;span class="{cls}"&gt;{name} {value}&lt;/span&gt;',
  923. '&lt;/div&gt;',
  924. // a configuration object:
  925. {
  926. compiled: true, // {@link #compile} immediately
  927. disableFormats: true // See Notes below.
  928. }
  929. );
  930. * </code></pre>
  931. * <p><b>Notes</b>:</p>
  932. * <div class="mdetail-params"><ul>
  933. * <li>Formatting and <code>disableFormats</code> are not applicable for Ext Core.</li>
  934. * <li>For a list of available format functions, see {@link Ext.util.Format}.</li>
  935. * <li><code>disableFormats</code> reduces <code>{@link #apply}</code> time
  936. * when no formatting is required.</li>
  937. * </ul></div>
  938. * </div></li>
  939. * </ul></div>
  940. * @param {Mixed} config
  941. */
  942. Ext.Template = function(html){
  943. var me = this,
  944. a = arguments,
  945. buf = [],
  946. v;
  947. if (Ext.isArray(html)) {
  948. html = html.join("");
  949. } else if (a.length > 1) {
  950. for(var i = 0, len = a.length; i < len; i++){
  951. v = a[i];
  952. if(typeof v == 'object'){
  953. Ext.apply(me, v);
  954. } else {
  955. buf.push(v);
  956. }
  957. };
  958. html = buf.join('');
  959. }
  960. /**@private*/
  961. me.html = html;
  962. /**
  963. * @cfg {Boolean} compiled Specify <tt>true</tt> to compile the template
  964. * immediately (see <code>{@link #compile}</code>).
  965. * Defaults to <tt>false</tt>.
  966. */
  967. if (me.compiled) {
  968. me.compile();
  969. }
  970. };
  971. Ext.Template.prototype = {
  972. /**
  973. * @cfg {RegExp} re The regular expression used to match template variables.
  974. * Defaults to:<pre><code>
  975. * re : /\{([\w-]+)\}/g // for Ext Core
  976. * re : /\{([\w-]+)(?:\:([\w\.]*)(?:\((.*?)?\))?)?\}/g // for Ext JS
  977. * </code></pre>
  978. */
  979. re : /\{([\w-]+)\}/g,
  980. /**
  981. * See <code>{@link #re}</code>.
  982. * @type RegExp
  983. * @property re
  984. */
  985. /**
  986. * Returns an HTML fragment of this template with the specified <code>values</code> applied.
  987. * @param {Object/Array} values
  988. * The template values. Can be an array if the params are numeric (i.e. <code>{0}</code>)
  989. * or an object (i.e. <code>{foo: 'bar'}</code>).
  990. * @return {String} The HTML fragment
  991. */
  992. applyTemplate : function(values){
  993. var me = this;
  994. return me.compiled ?
  995. me.compiled(values) :
  996. me.html.replace(me.re, function(m, name){
  997. return values[name] !== undefined ? values[name] : "";
  998. });
  999. },
  1000. /**
  1001. * Sets the HTML used as the template and optionally compiles it.
  1002. * @param {String} html
  1003. * @param {Boolean} compile (optional) True to compile the template (defaults to undefined)
  1004. * @return {Ext.Template} this
  1005. */
  1006. set : function(html, compile){
  1007. var me = this;
  1008. me.html = html;
  1009. me.compiled = null;
  1010. return compile ? me.compile() : me;
  1011. },
  1012. /**
  1013. * Compiles the template into an internal function, eliminating the RegEx overhead.
  1014. * @return {Ext.Template} this
  1015. */
  1016. compile : function(){
  1017. var me = this,
  1018. sep = Ext.isGecko ? "+" : ",";
  1019. function fn(m, name){
  1020. name = "values['" + name + "']";
  1021. return "'"+ sep + '(' + name + " == undefined ? '' : " + name + ')' + sep + "'";
  1022. }
  1023. eval("this.compiled = function(values){ return " + (Ext.isGecko ? "'" : "['") +
  1024. me.html.replace(/\\/g, '\\\\').replace(/(\r\n|\n)/g, '\\n').replace(/'/g, "\\'").replace(this.re, fn) +
  1025. (Ext.isGecko ? "';};" : "'].join('');};"));
  1026. return me;
  1027. },
  1028. /**
  1029. * Applies the supplied values to the template and inserts the new node(s) as the first child of el.
  1030. * @param {Mixed} el The context element
  1031. * @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'})
  1032. * @param {Boolean} returnElement (optional) true to return a Ext.Element (defaults to undefined)
  1033. * @return {HTMLElement/Ext.Element} The new node or Element
  1034. */
  1035. insertFirst: function(el, values, returnElement){
  1036. return this.doInsert('afterBegin', el, values, returnElement);
  1037. },
  1038. /**
  1039. * Applies the supplied values to the template and inserts the new node(s) before el.
  1040. * @param {Mixed} el The context element
  1041. * @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'})
  1042. * @param {Boolean} returnElement (optional) true to return a Ext.Element (defaults to undefined)
  1043. * @return {HTMLElement/Ext.Element} The new node or Element
  1044. */
  1045. insertBefore: function(el, values, returnElement){
  1046. return this.doInsert('beforeBegin', el, values, returnElement);
  1047. },
  1048. /**
  1049. * Applies the supplied values to the template and inserts the new node(s) after el.
  1050. * @param {Mixed} el The context element
  1051. * @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'})
  1052. * @param {Boolean} returnElement (optional) true to return a Ext.Element (defaults to undefined)
  1053. * @return {HTMLElement/Ext.Element} The new node or Element
  1054. */
  1055. insertAfter : function(el, values, returnElement){
  1056. return this.doInsert('afterEnd', el, values, returnElement);
  1057. },
  1058. /**
  1059. * Applies the supplied <code>values</code> to the template and appends
  1060. * the new node(s) to the specified <code>el</code>.
  1061. * <p>For example usage {@link #Template see the constructor}.</p>
  1062. * @param {Mixed} el The context element
  1063. * @param {Object/Array} values
  1064. * The template values. Can be an array if the params are numeric (i.e. <code>{0}</code>)
  1065. * or an object (i.e. <code>{foo: 'bar'}</code>).
  1066. * @param {Boolean} returnElement (optional) true to return an Ext.Element (defaults to undefined)
  1067. * @return {HTMLElement/Ext.Element} The new node or Element
  1068. */
  1069. append : function(el, values, returnElement){
  1070. return this.doInsert('beforeEnd', el, values, returnElement);
  1071. },
  1072. doInsert : function(where, el, values, returnEl){
  1073. el = Ext.getDom(el);
  1074. var newNode = Ext.DomHelper.insertHtml(where, el, this.applyTemplate(values));
  1075. return returnEl ? Ext.get(newNode, true) : newNode;
  1076. },
  1077. /**
  1078. * Applies the supplied values to the template and overwrites the content of el with the new node(s).
  1079. * @param {Mixed} el The context element
  1080. * @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'})
  1081. * @param {Boolean} returnElement (optional) true to return a Ext.Element (defaults to undefined)
  1082. * @return {HTMLElement/Ext.Element} The new node or Element
  1083. */
  1084. overwrite : function(el, values, returnElement){
  1085. el = Ext.getDom(el);
  1086. el.innerHTML = this.applyTemplate(values);
  1087. return returnElement ? Ext.get(el.firstChild, true) : el.firstChild;
  1088. }
  1089. };
  1090. /**
  1091. * Alias for {@link #applyTemplate}
  1092. * Returns an HTML fragment of this template with the specified <code>values</code> applied.
  1093. * @param {Object/Array} values
  1094. * The template values. Can be an array if the params are numeric (i.e. <code>{0}</code>)
  1095. * or an object (i.e. <code>{foo: 'bar'}</code>).
  1096. * @return {String} The HTML fragment
  1097. * @member Ext.Template
  1098. * @method apply
  1099. */
  1100. Ext.Template.prototype.apply = Ext.Template.prototype.applyTemplate;
  1101. /**
  1102. * Creates a template from the passed element's value (<i>display:none</i> textarea, preferred) or innerHTML.
  1103. * @param {String/HTMLElement} el A DOM element or its id
  1104. * @param {Object} config A configuration object
  1105. * @return {Ext.Template} The created template
  1106. * @static
  1107. */
  1108. Ext.Template.from = function(el, config){
  1109. el = Ext.getDom(el);
  1110. return new Ext.Template(el.value || el.innerHTML, config || '');
  1111. };
  1112. /*
  1113. * This is code is also distributed under MIT license for use
  1114. * with jQuery and prototype JavaScript libraries.
  1115. */
  1116. /**
  1117. * @class Ext.DomQuery
  1118. Provides high performance selector/xpath processing by compiling queries into reusable functions. New pseudo classes and matchers can be plugged. It works on HTML and XML documents (if a content node is passed in).
  1119. <p>
  1120. DomQuery supports most of the <a href="http://www.w3.org/TR/2005/WD-css3-selectors-20051215/#selectors">CSS3 selectors spec</a>, along with some custom selectors and basic XPath.</p>
  1121. <p>
  1122. All selectors, attribute filters and pseudos below can be combined infinitely in any order. For example "div.foo:nth-child(odd)[@foo=bar].bar:first" would be a perfectly valid selector. Node filters are processed in the order in which they appear, which allows you to optimize your queries for your document structure.
  1123. </p>
  1124. <h4>Element Selectors:</h4>
  1125. <ul class="list">
  1126. <li> <b>*</b> any element</li>
  1127. <li> <b>E</b> an element with the tag E</li>
  1128. <li> <b>E F</b> All descendent elements of E that have the tag F</li>
  1129. <li> <b>E > F</b> or <b>E/F</b> all direct children elements of E that have the tag F</li>
  1130. <li> <b>E + F</b> all elements with the tag F that are immediately preceded by an element with the tag E</li>
  1131. <li> <b>E ~ F</b> all elements with the tag F that are preceded by a sibling element with the tag E</li>
  1132. </ul>
  1133. <h4>Attribute Selectors:</h4>
  1134. <p>The use of &#64; and quotes are optional. For example, div[&#64;foo='bar'] is also a valid attribute selector.</p>
  1135. <ul class="list">
  1136. <li> <b>E[foo]</b> has an attribute "foo"</li>
  1137. <li> <b>E[foo=bar]</b> has an attribute "foo" that equals "bar"</li>
  1138. <li> <b>E[foo^=bar]</b> has an attribute "foo" that starts with "bar"</li>
  1139. <li> <b>E[foo$=bar]</b> has an attribute "foo" that ends with "bar"</li>
  1140. <li> <b>E[foo*=bar]</b> has an attribute "foo" that contains the substring "bar"</li>
  1141. <li> <b>E[foo%=2]</b> has an attribute "foo" that is evenly divisible by 2</li>
  1142. <li> <b>E[foo!=bar]</b> attribute "foo" does not equal "bar"</li>
  1143. </ul>
  1144. <h4>Pseudo Classes:</h4>
  1145. <ul class="list">
  1146. <li> <b>E:first-child</b> E is the first child of its parent</li>
  1147. <li> <b>E:last-child</b> E is the last child of its parent</li>
  1148. <li> <b>E:nth-child(<i>n</i>)</b> E is the <i>n</i>th child of its parent (1 based as per the spec)</li>
  1149. <li> <b>E:nth-child(odd)</b> E is an odd child of its parent</li>
  1150. <li> <b>E:nth-child(even)</b> E is an even child of its parent</li>
  1151. <li> <b>E:only-child</b> E is the only child of its parent</li>
  1152. <li> <b>E:checked</b> E is an element that is has a checked attribute that is true (e.g. a radio or checkbox) </li>
  1153. <li> <b>E:first</b> the first E in the resultset</li>
  1154. <li> <b>E:last</b> the last E in the resultset</li>
  1155. <li> <b>E:nth(<i>n</i>)</b> the <i>n</i>th E in the resultset (1 based)</li>
  1156. <li> <b>E:odd</b> shortcut for :nth-child(odd)</li>
  1157. <li> <b>E:even</b> shortcut for :nth-child(even)</li>
  1158. <li> <b>E:contains(foo)</b> E's innerHTML contains the substring "foo"</li>
  1159. <li> <b>E:nodeValue(foo)</b> E contains a textNode with a nodeValue that equals "foo"</li>
  1160. <li> <b>E:not(S)</b> an E element that does not match simple selector S</li>
  1161. <li> <b>E:has(S)</b> an E element that has a descendent that matches simple selector S</li>
  1162. <li> <b>E:next(S)</b> an E element whose next sibling matches simple selector S</li>
  1163. <li> <b>E:prev(S)</b> an E element whose previous sibling matches simple selector S</li>
  1164. <li> <b>E:any(S1|S2|S2)</b> an E element which matches any of the simple selectors S1, S2 or S3//\\</li>
  1165. </ul>
  1166. <h4>CSS Value Selectors:</h4>
  1167. <ul class="list">
  1168. <li> <b>E{display=none}</b> css value "display" that equals "none"</li>
  1169. <li> <b>E{display^=none}</b> css value "display" that starts with "none"</li>
  1170. <li> <b>E{display$=none}</b> css value "display" that ends with "none"</li>
  1171. <li> <b>E{display*=none}</b> css value "display" that contains the substring "none"</li>
  1172. <li> <b>E{display%=2}</b> css value "display" that is evenly divisible by 2</li>
  1173. <li> <b>E{display!=none}</b> css value "display" that does not equal "none"</li>
  1174. </ul>
  1175. * @singleton
  1176. */
  1177. Ext.DomQuery = function(){
  1178. var cache = {},
  1179. simpleCache = {},
  1180. valueCache = {},
  1181. nonSpace = /\S/,
  1182. trimRe = /^\s+|\s+$/g,
  1183. tplRe = /\{(\d+)\}/g,
  1184. modeRe = /^(\s?[\/>+~]\s?|\s|$)/,
  1185. tagTokenRe = /^(#)?([\w-\*]+)/,
  1186. nthRe = /(\d*)n\+?(\d*)/,
  1187. nthRe2 = /\D/,
  1188. // This is for IE MSXML which does not support expandos.
  1189. // IE runs the same speed using setAttribute, however FF slows way down
  1190. // and Safari completely fails so they need to continue to use expandos.
  1191. isIE = window.ActiveXObject ? true : false,
  1192. key = 30803;
  1193. // this eval is stop the compressor from
  1194. // renaming the variable to something shorter
  1195. eval("var batch = 30803;");
  1196. // Retrieve the child node from a particular
  1197. // parent at the specified index.
  1198. function child(parent, index){
  1199. var i = 0,
  1200. n = parent.firstChild;
  1201. while(n){
  1202. if(n.nodeType == 1){
  1203. if(++i == index){
  1204. return n;
  1205. }
  1206. }
  1207. n = n.nextSibling;
  1208. }
  1209. return null;
  1210. }
  1211. // retrieve the next element node
  1212. function next(n){
  1213. while((n = n.nextSibling) && n.nodeType != 1);
  1214. return n;
  1215. }
  1216. // retrieve the previous element node
  1217. function prev(n){
  1218. while((n = n.previousSibling) && n.nodeType != 1);
  1219. return n;
  1220. }
  1221. // Mark each child node with a nodeIndex skipping and
  1222. // removing empty text nodes.
  1223. function children(parent){
  1224. var n = parent.firstChild,
  1225. nodeIndex = -1,
  1226. nextNode;
  1227. while(n){
  1228. nextNode = n.nextSibling;
  1229. // clean worthless empty nodes.
  1230. if(n.nodeType == 3 && !nonSpace.test(n.nodeValue)){
  1231. parent.removeChild(n);
  1232. }else{
  1233. // add an expando nodeIndex
  1234. n.nodeIndex = ++nodeIndex;
  1235. }
  1236. n = nextNode;
  1237. }
  1238. return this;
  1239. }
  1240. // nodeSet - array of nodes
  1241. // cls - CSS Class
  1242. function byClassName(nodeSet, cls){
  1243. if(!cls){
  1244. return nodeSet;
  1245. }
  1246. var result = [], ri = -1;
  1247. for(var i = 0, ci; ci = nodeSet[i]; i++){
  1248. if((' '+ci.className+' ').indexOf(cls) != -1){
  1249. result[++ri] = ci;
  1250. }
  1251. }
  1252. return result;
  1253. };
  1254. function attrValue(n, attr){
  1255. // if its an array, use the first node.
  1256. if(!n.tagName && typeof n.length != "undefined"){
  1257. n = n[0];
  1258. }
  1259. if(!n){
  1260. return null;
  1261. }
  1262. if(attr == "for"){
  1263. return n.htmlFor;
  1264. }
  1265. if(attr == "class" || attr == "className"){
  1266. return n.className;
  1267. }
  1268. return n.getAttribute(attr) || n[attr];
  1269. };
  1270. // ns - nodes
  1271. // mode - false, /, >, +, ~
  1272. // tagName - defaults to "*"
  1273. function getNodes(ns, mode, tagName){
  1274. var result = [], ri = -1, cs;
  1275. if(!ns){
  1276. return result;
  1277. }
  1278. tagName = tagName || "*";
  1279. // convert to array
  1280. if(typeof ns.getElementsByTagName != "undefined"){
  1281. ns = [ns];
  1282. }
  1283. // no mode specified, grab all elements by tagName
  1284. // at any depth
  1285. if(!mode){
  1286. for(var i = 0, ni; ni = ns[i]; i++){
  1287. cs = ni.getElementsByTagName(tagName);
  1288. for(var j = 0, ci; ci = cs[j]; j++){
  1289. result[++ri] = ci;
  1290. }
  1291. }
  1292. // Direct Child mode (/ or >)
  1293. // E > F or E/F all direct children elements of E that have the tag
  1294. } else if(mode == "/" || mode == ">"){
  1295. var utag = tagName.toUpperCase();
  1296. for(var i = 0, ni, cn; ni = ns[i]; i++){
  1297. cn = ni.childNodes;
  1298. for(var j = 0, cj; cj = cn[j]; j++){
  1299. if(cj.nodeName == utag || cj.nodeName == tagName || tagName == '*'){
  1300. result[++ri] = cj;
  1301. }
  1302. }
  1303. }
  1304. // Immediately Preceding mode (+)
  1305. // E + F all elements with the tag F that are immediately preceded by an element with the tag E
  1306. }else if(mode == "+"){
  1307. var utag = tagName.toUpperCase();
  1308. for(var i = 0, n; n = ns[i]; i++){
  1309. while((n = n.nextSibling) && n.nodeType != 1);
  1310. if(n && (n.nodeName == utag || n.nodeName == tagName || tagName == '*')){
  1311. result[++ri] = n;
  1312. }
  1313. }
  1314. // Sibling mode (~)
  1315. // E ~ F all elements with the tag F that are preceded by a sibling element with the tag E
  1316. }else if(mode == "~"){
  1317. var utag = tagName.toUpperCase();
  1318. for(var i = 0, n; n = ns[i]; i++){
  1319. while((n = n.nextSibling)){
  1320. if (n.nodeName == utag || n.nodeName == tagName || tagName == '*'){
  1321. result[++ri] = n;
  1322. }
  1323. }
  1324. }
  1325. }
  1326. return result;
  1327. }
  1328. function concat(a, b){
  1329. if(b.slice){
  1330. return a.concat(b);
  1331. }
  1332. for(var i = 0, l = b.length; i < l; i++){
  1333. a[a.length] = b[i];
  1334. }
  1335. return a;
  1336. }
  1337. function byTag(cs, tagName){
  1338. if(cs.tagName || cs == document){
  1339. cs = [cs];
  1340. }
  1341. if(!tagName){
  1342. return cs;
  1343. }
  1344. var result = [], ri = -1;
  1345. tagName = tagName.toLowerCase();
  1346. for(var i = 0, ci; ci = cs[i]; i++){
  1347. if(ci.nodeType == 1 && ci.tagName.toLowerCase() == tagName){
  1348. result[++ri] = ci;
  1349. }
  1350. }
  1351. return result;
  1352. }
  1353. function byId(cs, id){
  1354. if(cs.tagName || cs == document){
  1355. cs = [cs];
  1356. }
  1357. if(!id){
  1358. return cs;
  1359. }
  1360. var result = [], ri = -1;
  1361. for(var i = 0, ci; ci = cs[i]; i++){
  1362. if(ci && ci.id == id){
  1363. result[++ri] = ci;
  1364. return result;
  1365. }
  1366. }
  1367. return result;
  1368. }
  1369. // operators are =, !=, ^=, $=, *=, %=, |= and ~=
  1370. // custom can be "{"
  1371. function byAttribute(cs, attr, value, op, custom){
  1372. var result = [],
  1373. ri = -1,
  1374. useGetStyle = custom == "{",
  1375. fn = Ext.DomQuery.operators[op],
  1376. a,
  1377. xml,
  1378. hasXml;
  1379. for(var i = 0, ci; ci = cs[i]; i++){
  1380. // skip non-element nodes.
  1381. if(ci.nodeType != 1){
  1382. continue;
  1383. }
  1384. // only need to do this for the first node
  1385. if(!hasXml){
  1386. xml = Ext.DomQuery.isXml(ci);
  1387. hasXml = true;
  1388. }
  1389. // we only need to change the property names if we're dealing with html nodes, not XML
  1390. if(!xml){
  1391. if(useGetStyle){
  1392. a = Ext.DomQuery.getStyle(ci, attr);
  1393. } else if (attr == "class" || attr == "className"){
  1394. a = ci.className;
  1395. } else if (attr == "for"){
  1396. a = ci.htmlFor;
  1397. } else if (attr == "href"){
  1398. // getAttribute href bug
  1399. // http://www.glennjones.net/Post/809/getAttributehrefbug.htm
  1400. a = ci.getAttribute("href", 2);
  1401. } else{
  1402. a = ci.getAttribute(attr);
  1403. }
  1404. }else{
  1405. a = ci.getAttribute(attr);
  1406. }
  1407. if((fn && fn(a, value)) || (!fn && a)){
  1408. result[++ri] = ci;
  1409. }
  1410. }
  1411. return result;
  1412. }
  1413. function byPseudo(cs, name, value){
  1414. return Ext.DomQuery.pseudos[name](cs, value);
  1415. }
  1416. function nodupIEXml(cs){
  1417. var d = ++key,
  1418. r;
  1419. cs[0].setAttribute("_nodup", d);
  1420. r = [cs[0]];
  1421. for(var i = 1, len = cs.length; i < len; i++){
  1422. var c = cs[i];
  1423. if(!c.getAttribute("_nodup") != d){
  1424. c.setAttribute("_nodup", d);
  1425. r[r.length] = c;
  1426. }
  1427. }
  1428. for(var i = 0, len = cs.length; i < len; i++){
  1429. cs[i].removeAttribute("_nodup");
  1430. }
  1431. return r;
  1432. }
  1433. function nodup(cs){
  1434. if(!cs){
  1435. return [];
  1436. }
  1437. var len = cs.length, c, i, r = cs, cj, ri = -1;
  1438. if(!len || typeof cs.nodeType != "undefined" || len == 1){
  1439. return cs;
  1440. }
  1441. if(isIE && typeof cs[0].selectSingleNode != "undefined"){
  1442. return nodupIEXml(cs);
  1443. }
  1444. var d = ++key;
  1445. cs[0]._nodup = d;
  1446. for(i = 1; c = cs[i]; i++){
  1447. if(c._nodup != d){
  1448. c._nodup = d;
  1449. }else{
  1450. r = [];
  1451. for(var j = 0; j < i; j++){
  1452. r[++ri] = cs[j];
  1453. }
  1454. for(j = i+1; cj = cs[j]; j++){
  1455. if(cj._nodup != d){
  1456. cj._nodup = d;
  1457. r[++ri] = cj;
  1458. }
  1459. }
  1460. return r;
  1461. }
  1462. }
  1463. return r;
  1464. }
  1465. function quickDiffIEXml(c1, c2){
  1466. var d = ++key,
  1467. r = [];
  1468. for(var i = 0, len = c1.length; i < len; i++){
  1469. c1[i].setAttribute("_qdiff", d);
  1470. }
  1471. for(var i = 0, len = c2.length; i < len; i++){
  1472. if(c2[i].getAttribute("_qdiff") != d){
  1473. r[r.length] = c2[i];
  1474. }
  1475. }
  1476. for(var i = 0, len = c1.length; i < len; i++){
  1477. c1[i].removeAttribute("_qdiff");
  1478. }
  1479. return r;
  1480. }
  1481. function quickDiff(c1, c2){
  1482. var len1 = c1.length,
  1483. d = ++key,
  1484. r = [];
  1485. if(!len1){
  1486. return c2;
  1487. }
  1488. if(isIE && typeof c1[0].selectSingleNode != "undefined"){
  1489. return quickDiffIEXml(c1, c2);
  1490. }
  1491. for(var i = 0; i < len1; i++){
  1492. c1[i]._qdiff = d;
  1493. }
  1494. for(var i = 0, len = c2.length; i < len; i++){
  1495. if(c2[i]._qdiff != d){
  1496. r[r.length] = c2[i];
  1497. }
  1498. }
  1499. return r;
  1500. }
  1501. function quickId(ns, mode, root, id){
  1502. if(ns == root){
  1503. var d = root.ownerDocument || root;
  1504. return d.getElementById(id);
  1505. }
  1506. ns = getNodes(ns, mode, "*");
  1507. return byId(ns, id);
  1508. }
  1509. return {
  1510. getStyle : function(el, name){
  1511. return Ext.fly(el).getStyle(name);
  1512. },
  1513. /**
  1514. * Compiles a selector/xpath query into a reusable function. The returned function
  1515. * takes one parameter "root" (optional), which is the context node from where the query should start.
  1516. * @param {String} selector The selector/xpath query
  1517. * @param {String} type (optional) Either "select" (the default) or "simple" for a simple selector match
  1518. * @return {Function}
  1519. */
  1520. compile : function(path, type){
  1521. type = type || "select";
  1522. // setup fn preamble
  1523. var fn = ["var f = function(root){\n var mode; ++batch; var n = root || document;\n"],
  1524. mode,
  1525. lastPath,
  1526. matchers = Ext.DomQuery.matchers,
  1527. matchersLn = matchers.length,
  1528. modeMatch,
  1529. // accept leading mode switch
  1530. lmode = path.match(modeRe);
  1531. if(lmode && lmode[1]){
  1532. fn[fn.length] = 'mode="'+lmode[1].replace(trimRe, "")+'";';
  1533. path = path.replace(lmode[1], "");
  1534. }
  1535. // strip leading slashes
  1536. while(path.substr(0, 1)=="/"){
  1537. path = path.substr(1);
  1538. }
  1539. while(path && lastPath != path){
  1540. lastPath = path;
  1541. var tokenMatch = path.match(tagTokenRe);
  1542. if(type == "select"){
  1543. if(tokenMatch){
  1544. // ID Selector
  1545. if(tokenMatch[1] == "#"){
  1546. fn[fn.length] = 'n = quickId(n, mode, root, "'+tokenMatch[2]+'");';
  1547. }else{
  1548. fn[fn.length] = 'n = getNodes(n, mode, "'+tokenMatch[2]+'");';
  1549. }
  1550. path = path.replace(tokenMatch[0], "");
  1551. }else if(path.substr(0, 1) != '@'){
  1552. fn[fn.length] = 'n = getNodes(n, mode, "*");';
  1553. }
  1554. // type of "simple"
  1555. }else{
  1556. if(tokenMatch){
  1557. if(tokenMatch[1] == "#"){
  1558. fn[fn.length] = 'n = byId(n, "'+tokenMatch[2]+'");';
  1559. }else{
  1560. fn[fn.length] = 'n = byTag(n, "'+tokenMatch[2]+'");';
  1561. }
  1562. path = path.replace(tokenMatch[0], "");
  1563. }
  1564. }
  1565. while(!(modeMatch = path.match(modeRe))){
  1566. var matched = false;
  1567. for(var j = 0; j < matchersLn; j++){
  1568. var t = matchers[j];
  1569. var m = path.match(t.re);
  1570. if(m){
  1571. fn[fn.length] = t.select.replace(tplRe, function(x, i){
  1572. return m[i];
  1573. });
  1574. path = path.replace(m[0], "");
  1575. matched = true;
  1576. break;
  1577. }
  1578. }
  1579. // prevent infinite loop on bad selector
  1580. if(!matched){
  1581. throw 'Error parsing selector, parsing failed at "' + path + '"';
  1582. }
  1583. }
  1584. if(modeMatch[1]){
  1585. fn[fn.length] = 'mode="'+modeMatch[1].replace(trimRe, "")+'";';
  1586. path = path.replace(modeMatch[1], "");
  1587. }
  1588. }
  1589. // close fn out
  1590. fn[fn.length] = "return nodup(n);\n}";
  1591. // eval fn and return it
  1592. eval(fn.join(""));
  1593. return f;
  1594. },
  1595. /**
  1596. * Selects a group of elements.
  1597. * @param {String} selector The selector/xpath query (can be a comma separated list of selectors)
  1598. * @param {Node/String} root (optional) The start of the query (defaults to document).
  1599. * @return {Array} An Array of DOM elements which match the selector. If there are
  1600. * no matches, and empty Array is returned.
  1601. */
  1602. jsSelect: function(path, root, type){
  1603. // set root to doc if not specified.
  1604. root = root || document;
  1605. if(typeof root == "string"){
  1606. root = document.getElementById(root);
  1607. }
  1608. var paths = path.split(","),
  1609. results = [];
  1610. // loop over each selector
  1611. for(var i = 0, len = paths.length; i < len; i++){
  1612. var subPath = paths[i].replace(trimRe, "");
  1613. // compile and place in cache
  1614. if(!cache[subPath]){
  1615. cache[subPath] = Ext.DomQuery.compile(subPath);
  1616. if(!cache[subPath]){
  1617. throw subPath + " is not a valid selector";
  1618. }
  1619. }
  1620. var result = cache[subPath](root);
  1621. if(result && result != document){
  1622. results = results.concat(result);
  1623. }
  1624. }
  1625. // if there were multiple selectors, make sure dups
  1626. // are eliminated
  1627. if(paths.length > 1){
  1628. return nodup(results);
  1629. }
  1630. return results;
  1631. },
  1632. isXml: function(el) {
  1633. var docEl = (el ? el.ownerDocument || el : 0).documentElement;
  1634. return docEl ? docEl.nodeName !== "HTML" : false;
  1635. },
  1636. select : document.querySelectorAll ? function(path, root, type) {
  1637. root = root || document;
  1638. if (!Ext.DomQuery.isXml(root)) {
  1639. try {
  1640. var cs = root.querySelectorAll(path);
  1641. return Ext.toArray(cs);
  1642. }
  1643. catch (ex) {}
  1644. }
  1645. return Ext.DomQuery.jsSelect.call(this, path, root, type);
  1646. } : function(path, root, type) {
  1647. return Ext.DomQuery.jsSelect.call(this, path, root, type);
  1648. },
  1649. /**
  1650. * Selects a single element.
  1651. * @param {String} selector The selector/xpath query
  1652. * @param {Node} root (optional) The start of the query (defaults to document).
  1653. * @return {Element} The DOM element which matched the selector.
  1654. */
  1655. selectNode : function(path, root){
  1656. return Ext.DomQuery.select(path, root)[0];
  1657. },
  1658. /**
  1659. * Selects the value of a node, optionally replacing null with the defaultValue.
  1660. * @param {String} selector The selector/xpath query
  1661. * @param {Node} root (optional) The start of the query (defaults to document).
  1662. * @param {String} defaultValue
  1663. * @return {String}
  1664. */
  1665. selectValue : function(path, root, defaultValue){
  1666. path = path.replace(trimRe, "");
  1667. if(!valueCache[path]){
  1668. valueCache[path] = Ext.DomQuery.compile(path, "select");
  1669. }
  1670. var n = valueCache[path](root), v;
  1671. n = n[0] ? n[0] : n;
  1672. // overcome a limitation of maximum textnode size
  1673. // Rumored to potentially crash IE6 but has not been confirmed.
  1674. // http://reference.sitepoint.com/javascript/Node/normalize
  1675. // https://developer.mozilla.org/En/DOM/Node.normalize
  1676. if (typeof n.normalize == 'function') n.normalize();
  1677. v = (n && n.firstChild ? n.firstChild.nodeValue : null);
  1678. return ((v === null||v === undefined||v==='') ? defaultValue : v);
  1679. },
  1680. /**
  1681. * Selects the value of a node, parsing integers and floats. Returns the defaultValue, or 0 if none is specified.
  1682. * @param {String} selector The selector/xpath query
  1683. * @param {Node} root (optional) The start of the query (defaults to document).
  1684. * @param {Number} defaultValue
  1685. * @return {Number}
  1686. */
  1687. selectNumber : function(path, root, defaultValue){
  1688. var v = Ext.DomQuery.selectValue(path, root, defaultValue || 0);
  1689. return parseFloat(v);
  1690. },
  1691. /**
  1692. * Returns true if the passed element(s) match the passed simple selector (e.g. div.some-class or span:first-child)
  1693. * @param {String/HTMLElement/Array} el An element id, element or array of elements
  1694. * @param {String} selector The simple selector to test
  1695. * @return {Boolean}
  1696. */
  1697. is : function(el, ss){
  1698. if(typeof el == "string"){
  1699. el = document.getElementById(el);
  1700. }
  1701. var isArray = Ext.isArray(el),
  1702. result = Ext.DomQuery.filter(isArray ? el : [el], ss);
  1703. return isArray ? (result.length == el.length) : (result.length > 0);
  1704. },
  1705. /**
  1706. * Filters an array of elements to only include matches of a simple selector (e.g. div.some-class or span:first-child)
  1707. * @param {Array} el An array of elements to filter
  1708. * @param {String} selector The simple selector to test
  1709. * @param {Boolean} nonMatches If true, it returns the elements that DON'T match
  1710. * the selector instead of the ones that match
  1711. * @return {Array} An Array of DOM elements which match the selector. If there are
  1712. * no matches, and empty Array is returned.
  1713. */
  1714. filter : function(els, ss, nonMatches){
  1715. ss = ss.replace(trimRe, "");
  1716. if(!simpleCache[ss]){
  1717. simpleCache[ss] = Ext.DomQuery.compile(ss, "simple");
  1718. }
  1719. var result = simpleCache[ss](els);
  1720. return nonMatches ? quickDiff(result, els) : result;
  1721. },
  1722. /**
  1723. * Collection of matching regular expressions and code snippets.
  1724. * Each capture group within () will be replace the {} in the select
  1725. * statement as specified by their index.
  1726. */
  1727. matchers : [{
  1728. re: /^\.([\w-]+)/,
  1729. select: 'n = byClassName(n, " {1} ");'
  1730. }, {
  1731. re: /^\:([\w-]+)(?:\(((?:[^\s>\/]*|.*?))\))?/,
  1732. select: 'n = byPseudo(n, "{1}", "{2}");'
  1733. },{
  1734. re: /^(?:([\[\{])(?:@)?([\w-]+)\s?(?:(=|.=)\s?['"]?(.*?)["']?)?[\]\}])/,
  1735. select: 'n = byAttribute(n, "{2}", "{4}", "{3}", "{1}");'
  1736. }, {
  1737. re: /^#([\w-]+)/,
  1738. select: 'n = byId(n, "{1}");'
  1739. },{
  1740. re: /^@([\w-]+)/,
  1741. select: 'return {firstChild:{nodeValue:attrValue(n, "{1}")}};'
  1742. }
  1743. ],
  1744. /**
  1745. * Collection of operator comparison functions. The default operators are =, !=, ^=, $=, *=, %=, |= and ~=.
  1746. * New operators can be added as long as the match the format <i>c</i>= where <i>c</i> is any character other than space, &gt; &lt;.
  1747. */
  1748. operators : {
  1749. "=" : function(a, v){
  1750. return a == v;
  1751. },
  1752. "!=" : function(a, v){
  1753. return a != v;
  1754. },
  1755. "^=" : function(a, v){
  1756. return a && a.substr(0, v.length) == v;
  1757. },
  1758. "$=" : function(a, v){
  1759. return a && a.substr(a.length-v.length) == v;
  1760. },
  1761. "*=" : function(a, v){
  1762. return a && a.indexOf(v) !== -1;
  1763. },
  1764. "%=" : function(a, v){
  1765. return (a % v) == 0;
  1766. },
  1767. "|=" : function(a, v){
  1768. return a && (a == v || a.substr(0, v.length+1) == v+'-');
  1769. },
  1770. "~=" : function(a, v){
  1771. return a && (' '+a+' ').indexOf(' '+v+' ') != -1;
  1772. }
  1773. },
  1774. /**
  1775. * <p>Object hash of "pseudo class" filter functions which are used when filtering selections. Each function is passed
  1776. * two parameters:</p><div class="mdetail-params"><ul>
  1777. * <li><b>c</b> : Array<div class="sub-desc">An Array of DOM elements to filter.</div></li>
  1778. * <li><b>v</b> : String<div class="sub-desc">The argument (if any) supplied in the selector.</div></li>
  1779. * </ul></div>
  1780. * <p>A filter function returns an Array of DOM elements which conform to the pseudo class.</p>
  1781. * <p>In addition to the provided pseudo classes listed above such as <code>first-child</code> and <code>nth-child</code>,
  1782. * developers may add additional, custom psuedo class filters to select elements according to application-specific requirements.</p>
  1783. * <p>For example, to filter <code>&lt;a></code> elements to only return links to <i>external</i> resources:</p>
  1784. * <code><pre>
  1785. Ext.DomQuery.pseudos.external = function(c, v){
  1786. var r = [], ri = -1;
  1787. for(var i = 0, ci; ci = c[i]; i++){
  1788. // Include in result set only if it's a link to an external resource
  1789. if(ci.hostname != location.hostname){
  1790. r[++ri] = ci;
  1791. }
  1792. }
  1793. return r;
  1794. };</pre></code>
  1795. * Then external links could be gathered with the following statement:<code><pre>
  1796. var externalLinks = Ext.select("a:external");
  1797. </code></pre>
  1798. */
  1799. pseudos : {
  1800. "first-child" : function(c){
  1801. var r = [], ri = -1, n;
  1802. for(var i = 0, ci; ci = n = c[i]; i++){
  1803. while((n = n.previousSibling) && n.nodeType != 1);
  1804. if(!n){
  1805. r[++ri] = ci;
  1806. }
  1807. }
  1808. return r;
  1809. },
  1810. "last-child" : function(c){
  1811. var r = [], ri = -1, n;
  1812. for(var i = 0, ci; ci = n = c[i]; i++){
  1813. while((n = n.nextSibling) && n.nodeType != 1);
  1814. if(!n){
  1815. r[++ri] = ci;
  1816. }
  1817. }
  1818. return r;
  1819. },
  1820. "nth-child" : function(c, a) {
  1821. var r = [], ri = -1,
  1822. m = nthRe.exec(a == "even" && "2n" || a == "odd" && "2n+1" || !nthRe2.test(a) && "n+" + a || a),
  1823. f = (m[1] || 1) - 0, l = m[2] - 0;
  1824. for(var i = 0, n; n = c[i]; i++){
  1825. var pn = n.parentNode;
  1826. if (batch != pn._batch) {
  1827. var j = 0;
  1828. for(var cn = pn.firstChild; cn; cn = cn.nextSibling){
  1829. if(cn.nodeType == 1){
  1830. cn.nodeIndex = ++j;
  1831. }
  1832. }
  1833. pn._batch = batch;
  1834. }
  1835. if (f == 1) {
  1836. if (l == 0 || n.nodeIndex == l){
  1837. r[++ri] = n;
  1838. }
  1839. } else if ((n.nodeIndex + l) % f == 0){
  1840. r[++ri] = n;
  1841. }
  1842. }
  1843. return r;
  1844. },
  1845. "only-child" : function(c){
  1846. var r = [], ri = -1;;
  1847. for(var i = 0, ci; ci = c[i]; i++){
  1848. if(!prev(ci) && !next(ci)){
  1849. r[++ri] = ci;
  1850. }
  1851. }
  1852. return r;
  1853. },
  1854. "empty" : function(c){
  1855. var r = [], ri = -1;
  1856. for(var i = 0, ci; ci = c[i]; i++){
  1857. var cns = ci.childNodes, j = 0, cn, empty = true;
  1858. while(cn = cns[j]){
  1859. ++j;
  1860. if(cn.nodeType == 1 || cn.nodeType == 3){
  1861. empty = false;
  1862. break;
  1863. }
  1864. }
  1865. if(empty){
  1866. r[++ri] = ci;
  1867. }
  1868. }
  1869. return r;
  1870. },
  1871. "contains" : function(c, v){
  1872. var r = [], ri = -1;
  1873. for(var i = 0, ci; ci = c[i]; i++){
  1874. if((ci.textContent||ci.innerText||'').indexOf(v) != -1){
  1875. r[++ri] = ci;
  1876. }
  1877. }
  1878. return r;
  1879. },
  1880. "nodeValue" : function(c, v){
  1881. var r = [], ri = -1;
  1882. for(var i = 0, ci; ci = c[i]; i++){
  1883. if(ci.firstChild && ci.firstChild.nodeValue == v){
  1884. r[++ri] = ci;
  1885. }
  1886. }
  1887. return r;
  1888. },
  1889. "checked" : function(c){
  1890. var r = [], ri = -1;
  1891. for(var i = 0, ci; ci = c[i]; i++){
  1892. if(ci.checked == true){
  1893. r[++ri] = ci;
  1894. }
  1895. }
  1896. return r;
  1897. },
  1898. "not" : function(c, ss){
  1899. return Ext.DomQuery.filter(c, ss, true);
  1900. },
  1901. "any" : function(c, selectors){
  1902. var ss = selectors.split('|'),
  1903. r = [], ri = -1, s;
  1904. for(var i = 0, ci; ci = c[i]; i++){
  1905. for(var j = 0; s = ss[j]; j++){
  1906. if(Ext.DomQuery.is(ci, s)){
  1907. r[++ri] = ci;
  1908. break;
  1909. }
  1910. }
  1911. }
  1912. return r;
  1913. },
  1914. "odd" : function(c){
  1915. return this["nth-child"](c, "odd");
  1916. },
  1917. "even" : function(c){
  1918. return this["nth-child"](c, "even");
  1919. },
  1920. "nth" : function(c, a){
  1921. return c[a-1] || [];
  1922. },
  1923. "first" : function(c){
  1924. return c[0] || [];
  1925. },
  1926. "last" : function(c){
  1927. return c[c.length-1] || [];
  1928. },
  1929. "has" : function(c, ss){
  1930. var s = Ext.DomQuery.select,
  1931. r = [], ri = -1;
  1932. for(var i = 0, ci; ci = c[i]; i++){
  1933. if(s(ss, ci).length > 0){
  1934. r[++ri] = ci;
  1935. }
  1936. }
  1937. return r;
  1938. },
  1939. "next" : function(c, ss){
  1940. var is = Ext.DomQuery.is,
  1941. r = [], ri = -1;
  1942. for(var i = 0, ci; ci = c[i]; i++){
  1943. var n = next(ci);
  1944. if(n && is(n, ss)){
  1945. r[++ri] = ci;
  1946. }
  1947. }
  1948. return r;
  1949. },
  1950. "prev" : function(c, ss){
  1951. var is = Ext.DomQuery.is,
  1952. r = [], ri = -1;
  1953. for(var i = 0, ci; ci = c[i]; i++){
  1954. var n = prev(ci);
  1955. if(n && is(n, ss)){
  1956. r[++ri] = ci;
  1957. }
  1958. }
  1959. return r;
  1960. }
  1961. }
  1962. };
  1963. }();
  1964. /**
  1965. * Selects an array of DOM nodes by CSS/XPath selector. Shorthand of {@link Ext.DomQuery#select}
  1966. * @param {String} path The selector/xpath query
  1967. * @param {Node} root (optional) The start of the query (defaults to document).
  1968. * @return {Array}
  1969. * @member Ext
  1970. * @method query
  1971. */
  1972. Ext.query = Ext.DomQuery.select;
  1973. /**
  1974. * @class Ext.util.DelayedTask
  1975. * <p> The DelayedTask class provides a convenient way to "buffer" the execution of a method,
  1976. * performing setTimeout where a new timeout cancels the old timeout. When called, the
  1977. * task will wait the specified time period before executing. If durng that time period,
  1978. * the task is called again, the original call will be cancelled. This continues so that
  1979. * the function is only called a single time for each iteration.</p>
  1980. * <p>This method is especially useful for things like detecting whether a user has finished
  1981. * typing in a text field. An example would be performing validation on a keypress. You can
  1982. * use this class to buffer the keypress events for a certain number of milliseconds, and
  1983. * perform only if they stop for that amount of time. Usage:</p><pre><code>
  1984. var task = new Ext.util.DelayedTask(function(){
  1985. alert(Ext.getDom('myInputField').value.length);
  1986. });
  1987. // Wait 500ms before calling our function. If the user presses another key
  1988. // during that 500ms, it will be cancelled and we'll wait another 500ms.
  1989. Ext.get('myInputField').on('keypress', function(){
  1990. task.{@link #delay}(500);
  1991. });
  1992. * </code></pre>
  1993. * <p>Note that we are using a DelayedTask here to illustrate a point. The configuration
  1994. * option <tt>buffer</tt> for {@link Ext.util.Observable#addListener addListener/on} will
  1995. * also setup a delayed task for you to buffer events.</p>
  1996. * @constructor The parameters to this constructor serve as defaults and are not required.
  1997. * @param {Function} fn (optional) The default function to call.
  1998. * @param {Object} scope The default scope (The <code><b>this</b></code> reference) in which the
  1999. * function is called. If not specified, <code>this</code> will refer to the browser window.
  2000. * @param {Array} args (optional) The default Array of arguments.
  2001. */
  2002. Ext.util.DelayedTask = function(fn, scope, args){
  2003. var me = this,
  2004. id,
  2005. call = function(){
  2006. clearInterval(id);
  2007. id = null;
  2008. fn.apply(scope, args || []);
  2009. };
  2010. /**
  2011. * Cancels any pending timeout and queues a new one
  2012. * @param {Number} delay The milliseconds to delay
  2013. * @param {Function} newFn (optional) Overrides function passed to constructor
  2014. * @param {Object} newScope (optional) Overrides scope passed to constructor. Remember that if no scope
  2015. * is specified, <code>this</code> will refer to the browser window.
  2016. * @param {Array} newArgs (optional) Overrides args passed to constructor
  2017. */
  2018. me.delay = function(delay, newFn, newScope, newArgs){
  2019. me.cancel();
  2020. fn = newFn || fn;
  2021. scope = newScope || scope;
  2022. args = newArgs || args;
  2023. id = setInterval(call, delay);
  2024. };
  2025. /**
  2026. * Cancel the last queued timeout
  2027. */
  2028. me.cancel = function(){
  2029. if(id){
  2030. clearInterval(id);
  2031. id = null;
  2032. }
  2033. };
  2034. };/**
  2035. * @class Ext.Element
  2036. * <p>Encapsulates a DOM element, adding simple DOM manipulation facilities, normalizing for browser differences.</p>
  2037. * <p>All instances of this class inherit the methods of {@link Ext.Fx} making visual effects easily available to all DOM elements.</p>
  2038. * <p>Note that the events documented in this class are not Ext events, they encapsulate browser events. To
  2039. * access the underlying browser event, see {@link Ext.EventObject#browserEvent}. Some older
  2040. * browsers may not support the full range of events. Which events are supported is beyond the control of ExtJs.</p>
  2041. * Usage:<br>
  2042. <pre><code>
  2043. // by id
  2044. var el = Ext.get("my-div");
  2045. // by DOM element reference
  2046. var el = Ext.get(myDivElement);
  2047. </code></pre>
  2048. * <b>Animations</b><br />
  2049. * <p>When an element is manipulated, by default there is no animation.</p>
  2050. * <pre><code>
  2051. var el = Ext.get("my-div");
  2052. // no animation
  2053. el.setWidth(100);
  2054. * </code></pre>
  2055. * <p>Many of the functions for manipulating an element have an optional "animate" parameter. This
  2056. * parameter can be specified as boolean (<tt>true</tt>) for default animation effects.</p>
  2057. * <pre><code>
  2058. // default animation
  2059. el.setWidth(100, true);
  2060. * </code></pre>
  2061. *
  2062. * <p>To configure the effects, an object literal with animation options to use as the Element animation
  2063. * configuration object can also be specified. Note that the supported Element animation configuration
  2064. * options are a subset of the {@link Ext.Fx} animation options specific to Fx effects. The supported
  2065. * Element animation configuration options are:</p>
  2066. <pre>
  2067. Option Default Description
  2068. --------- -------- ---------------------------------------------
  2069. {@link Ext.Fx#duration duration} .35 The duration of the animation in seconds
  2070. {@link Ext.Fx#easing easing} easeOut The easing method
  2071. {@link Ext.Fx#callback callback} none A function to execute when the anim completes
  2072. {@link Ext.Fx#scope scope} this The scope (this) of the callback function
  2073. </pre>
  2074. *
  2075. * <pre><code>
  2076. // Element animation options object
  2077. var opt = {
  2078. {@link Ext.Fx#duration duration}: 1,
  2079. {@link Ext.Fx#easing easing}: 'elasticIn',
  2080. {@link Ext.Fx#callback callback}: this.foo,
  2081. {@link Ext.Fx#scope scope}: this
  2082. };
  2083. // animation with some options set
  2084. el.setWidth(100, opt);
  2085. * </code></pre>
  2086. * <p>The Element animation object being used for the animation will be set on the options
  2087. * object as "anim", which allows you to stop or manipulate the animation. Here is an example:</p>
  2088. * <pre><code>
  2089. // using the "anim" property to get the Anim object
  2090. if(opt.anim.isAnimated()){
  2091. opt.anim.stop();
  2092. }
  2093. * </code></pre>
  2094. * <p>Also see the <tt>{@link #animate}</tt> method for another animation technique.</p>
  2095. * <p><b> Composite (Collections of) Elements</b></p>
  2096. * <p>For working with collections of Elements, see {@link Ext.CompositeElement}</p>
  2097. * @constructor Create a new Element directly.
  2098. * @param {String/HTMLElement} element
  2099. * @param {Boolean} forceNew (optional) By default the constructor checks to see if there is already an instance of this element in the cache and if there is it returns the same instance. This will skip that check (useful for extending this class).
  2100. */
  2101. (function(){
  2102. var DOC = document;
  2103. Ext.Element = function(element, forceNew){
  2104. var dom = typeof element == "string" ?
  2105. DOC.getElementById(element) : element,
  2106. id;
  2107. if(!dom) return null;
  2108. id = dom.id;
  2109. if(!forceNew && id && Ext.elCache[id]){ // element object already exists
  2110. return Ext.elCache[id].el;
  2111. }
  2112. /**
  2113. * The DOM element
  2114. * @type HTMLElement
  2115. */
  2116. this.dom = dom;
  2117. /**
  2118. * The DOM element ID
  2119. * @type String
  2120. */
  2121. this.id = id || Ext.id(dom);
  2122. };
  2123. var DH = Ext.DomHelper,
  2124. El = Ext.Element,
  2125. EC = Ext.elCache;
  2126. El.prototype = {
  2127. /**
  2128. * Sets the passed attributes as attributes of this element (a style attribute can be a string, object or function)
  2129. * @param {Object} o The object with the attributes
  2130. * @param {Boolean} useSet (optional) false to override the default setAttribute to use expandos.
  2131. * @return {Ext.Element} this
  2132. */
  2133. set : function(o, useSet){
  2134. var el = this.dom,
  2135. attr,
  2136. val,
  2137. useSet = (useSet !== false) && !!el.setAttribute;
  2138. for (attr in o) {
  2139. if (o.hasOwnProperty(attr)) {
  2140. val = o[attr];
  2141. if (attr == 'style') {
  2142. DH.applyStyles(el, val);
  2143. } else if (attr == 'cls') {
  2144. el.className = val;
  2145. } else if (useSet) {
  2146. el.setAttribute(attr, val);
  2147. } else {
  2148. el[attr] = val;
  2149. }
  2150. }
  2151. }
  2152. return this;
  2153. },
  2154. // Mouse events
  2155. /**
  2156. * @event click
  2157. * Fires when a mouse click is detected within the element.
  2158. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2159. * @param {HtmlElement} t The target of the event.
  2160. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2161. */
  2162. /**
  2163. * @event contextmenu
  2164. * Fires when a right click is detected within the element.
  2165. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2166. * @param {HtmlElement} t The target of the event.
  2167. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2168. */
  2169. /**
  2170. * @event dblclick
  2171. * Fires when a mouse double click is detected within the element.
  2172. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2173. * @param {HtmlElement} t The target of the event.
  2174. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2175. */
  2176. /**
  2177. * @event mousedown
  2178. * Fires when a mousedown is detected within the element.
  2179. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2180. * @param {HtmlElement} t The target of the event.
  2181. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2182. */
  2183. /**
  2184. * @event mouseup
  2185. * Fires when a mouseup is detected within the element.
  2186. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2187. * @param {HtmlElement} t The target of the event.
  2188. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2189. */
  2190. /**
  2191. * @event mouseover
  2192. * Fires when a mouseover is detected within the element.
  2193. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2194. * @param {HtmlElement} t The target of the event.
  2195. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2196. */
  2197. /**
  2198. * @event mousemove
  2199. * Fires when a mousemove is detected with the element.
  2200. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2201. * @param {HtmlElement} t The target of the event.
  2202. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2203. */
  2204. /**
  2205. * @event mouseout
  2206. * Fires when a mouseout is detected with the element.
  2207. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2208. * @param {HtmlElement} t The target of the event.
  2209. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2210. */
  2211. /**
  2212. * @event mouseenter
  2213. * Fires when the mouse enters the element.
  2214. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2215. * @param {HtmlElement} t The target of the event.
  2216. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2217. */
  2218. /**
  2219. * @event mouseleave
  2220. * Fires when the mouse leaves the element.
  2221. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2222. * @param {HtmlElement} t The target of the event.
  2223. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2224. */
  2225. // Keyboard events
  2226. /**
  2227. * @event keypress
  2228. * Fires when a keypress is detected within the element.
  2229. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2230. * @param {HtmlElement} t The target of the event.
  2231. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2232. */
  2233. /**
  2234. * @event keydown
  2235. * Fires when a keydown is detected within the element.
  2236. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2237. * @param {HtmlElement} t The target of the event.
  2238. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2239. */
  2240. /**
  2241. * @event keyup
  2242. * Fires when a keyup is detected within the element.
  2243. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2244. * @param {HtmlElement} t The target of the event.
  2245. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2246. */
  2247. // HTML frame/object events
  2248. /**
  2249. * @event load
  2250. * Fires when the user agent finishes loading all content within the element. Only supported by window, frames, objects and images.
  2251. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2252. * @param {HtmlElement} t The target of the event.
  2253. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2254. */
  2255. /**
  2256. * @event unload
  2257. * Fires when the user agent removes all content from a window or frame. For elements, it fires when the target element or any of its content has been removed.
  2258. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2259. * @param {HtmlElement} t The target of the event.
  2260. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2261. */
  2262. /**
  2263. * @event abort
  2264. * Fires when an object/image is stopped from loading before completely loaded.
  2265. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2266. * @param {HtmlElement} t The target of the event.
  2267. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2268. */
  2269. /**
  2270. * @event error
  2271. * Fires when an object/image/frame cannot be loaded properly.
  2272. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2273. * @param {HtmlElement} t The target of the event.
  2274. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2275. */
  2276. /**
  2277. * @event resize
  2278. * Fires when a document view is resized.
  2279. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2280. * @param {HtmlElement} t The target of the event.
  2281. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2282. */
  2283. /**
  2284. * @event scroll
  2285. * Fires when a document view is scrolled.
  2286. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2287. * @param {HtmlElement} t The target of the event.
  2288. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2289. */
  2290. // Form events
  2291. /**
  2292. * @event select
  2293. * Fires when a user selects some text in a text field, including input and textarea.
  2294. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2295. * @param {HtmlElement} t The target of the event.
  2296. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2297. */
  2298. /**
  2299. * @event change
  2300. * Fires when a control loses the input focus and its value has been modified since gaining focus.
  2301. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2302. * @param {HtmlElement} t The target of the event.
  2303. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2304. */
  2305. /**
  2306. * @event submit
  2307. * Fires when a form is submitted.
  2308. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2309. * @param {HtmlElement} t The target of the event.
  2310. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2311. */
  2312. /**
  2313. * @event reset
  2314. * Fires when a form is reset.
  2315. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2316. * @param {HtmlElement} t The target of the event.
  2317. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2318. */
  2319. /**
  2320. * @event focus
  2321. * Fires when an element receives focus either via the pointing device or by tab navigation.
  2322. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2323. * @param {HtmlElement} t The target of the event.
  2324. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2325. */
  2326. /**
  2327. * @event blur
  2328. * Fires when an element loses focus either via the pointing device or by tabbing navigation.
  2329. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2330. * @param {HtmlElement} t The target of the event.
  2331. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2332. */
  2333. // User Interface events
  2334. /**
  2335. * @event DOMFocusIn
  2336. * Where supported. Similar to HTML focus event, but can be applied to any focusable element.
  2337. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2338. * @param {HtmlElement} t The target of the event.
  2339. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2340. */
  2341. /**
  2342. * @event DOMFocusOut
  2343. * Where supported. Similar to HTML blur event, but can be applied to any focusable element.
  2344. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2345. * @param {HtmlElement} t The target of the event.
  2346. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2347. */
  2348. /**
  2349. * @event DOMActivate
  2350. * Where supported. Fires when an element is activated, for instance, through a mouse click or a keypress.
  2351. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2352. * @param {HtmlElement} t The target of the event.
  2353. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2354. */
  2355. // DOM Mutation events
  2356. /**
  2357. * @event DOMSubtreeModified
  2358. * Where supported. Fires when the subtree is modified.
  2359. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2360. * @param {HtmlElement} t The target of the event.
  2361. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2362. */
  2363. /**
  2364. * @event DOMNodeInserted
  2365. * Where supported. Fires when a node has been added as a child of another node.
  2366. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2367. * @param {HtmlElement} t The target of the event.
  2368. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2369. */
  2370. /**
  2371. * @event DOMNodeRemoved
  2372. * Where supported. Fires when a descendant node of the element is removed.
  2373. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2374. * @param {HtmlElement} t The target of the event.
  2375. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2376. */
  2377. /**
  2378. * @event DOMNodeRemovedFromDocument
  2379. * Where supported. Fires when a node is being removed from a document.
  2380. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2381. * @param {HtmlElement} t The target of the event.
  2382. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2383. */
  2384. /**
  2385. * @event DOMNodeInsertedIntoDocument
  2386. * Where supported. Fires when a node is being inserted into a document.
  2387. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2388. * @param {HtmlElement} t The target of the event.
  2389. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2390. */
  2391. /**
  2392. * @event DOMAttrModified
  2393. * Where supported. Fires when an attribute has been modified.
  2394. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2395. * @param {HtmlElement} t The target of the event.
  2396. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2397. */
  2398. /**
  2399. * @event DOMCharacterDataModified
  2400. * Where supported. Fires when the character data has been modified.
  2401. * @param {Ext.EventObject} e The {@link Ext.EventObject} encapsulating the DOM event.
  2402. * @param {HtmlElement} t The target of the event.
  2403. * @param {Object} o The options configuration passed to the {@link #addListener} call.
  2404. */
  2405. /**
  2406. * The default unit to append to CSS values where a unit isn't provided (defaults to px).
  2407. * @type String
  2408. */
  2409. defaultUnit : "px",
  2410. /**
  2411. * Returns true if this element matches the passed simple selector (e.g. div.some-class or span:first-child)
  2412. * @param {String} selector The simple selector to test
  2413. * @return {Boolean} True if this element matches the selector, else false
  2414. */
  2415. is : function(simpleSelector){
  2416. return Ext.DomQuery.is(this.dom, simpleSelector);
  2417. },
  2418. /**
  2419. * Tries to focus the element. Any exceptions are caught and ignored.
  2420. * @param {Number} defer (optional) Milliseconds to defer the focus
  2421. * @return {Ext.Element} this
  2422. */
  2423. focus : function(defer, /* private */ dom) {
  2424. var me = this,
  2425. dom = dom || me.dom;
  2426. try{
  2427. if(Number(defer)){
  2428. me.focus.defer(defer, null, [null, dom]);
  2429. }else{
  2430. dom.focus();
  2431. }
  2432. }catch(e){}
  2433. return me;
  2434. },
  2435. /**
  2436. * Tries to blur the element. Any exceptions are caught and ignored.
  2437. * @return {Ext.Element} this
  2438. */
  2439. blur : function() {
  2440. try{
  2441. this.dom.blur();
  2442. }catch(e){}
  2443. return this;
  2444. },
  2445. /**
  2446. * Returns the value of the "value" attribute
  2447. * @param {Boolean} asNumber true to parse the value as a number
  2448. * @return {String/Number}
  2449. */
  2450. getValue : function(asNumber){
  2451. var val = this.dom.value;
  2452. return asNumber ? parseInt(val, 10) : val;
  2453. },
  2454. /**
  2455. * Appends an event handler to this element. The shorthand version {@link #on} is equivalent.
  2456. * @param {String} eventName The name of event to handle.
  2457. * @param {Function} fn The handler function the event invokes. This function is passed
  2458. * the following parameters:<ul>
  2459. * <li><b>evt</b> : EventObject<div class="sub-desc">The {@link Ext.EventObject EventObject} describing the event.</div></li>
  2460. * <li><b>el</b> : HtmlElement<div class="sub-desc">The DOM element which was the target of the event.
  2461. * Note that this may be filtered by using the <tt>delegate</tt> option.</div></li>
  2462. * <li><b>o</b> : Object<div class="sub-desc">The options object from the addListener call.</div></li>
  2463. * </ul>
  2464. * @param {Object} scope (optional) The scope (<code><b>this</b></code> reference) in which the handler function is executed.
  2465. * <b>If omitted, defaults to this Element.</b>.
  2466. * @param {Object} options (optional) An object containing handler configuration properties.
  2467. * This may contain any of the following properties:<ul>
  2468. * <li><b>scope</b> Object : <div class="sub-desc">The scope (<code><b>this</b></code> reference) in which the handler function is executed.
  2469. * <b>If omitted, defaults to this Element.</b></div></li>
  2470. * <li><b>delegate</b> String: <div class="sub-desc">A simple selector to filter the target or look for a descendant of the target. See below for additional details.</div></li>
  2471. * <li><b>stopEvent</b> Boolean: <div class="sub-desc">True to stop the event. That is stop propagation, and prevent the default action.</div></li>
  2472. * <li><b>preventDefault</b> Boolean: <div class="sub-desc">True to prevent the default action</div></li>
  2473. * <li><b>stopPropagation</b> Boolean: <div class="sub-desc">True to prevent event propagation</div></li>
  2474. * <li><b>normalized</b> Boolean: <div class="sub-desc">False to pass a browser event to the handler function instead of an Ext.EventObject</div></li>
  2475. * <li><b>target</b> Ext.Element: <div class="sub-desc">Only call the handler if the event was fired on the target Element, <i>not</i> if the event was bubbled up from a child node.</div></li>
  2476. * <li><b>delay</b> Number: <div class="sub-desc">The number of milliseconds to delay the invocation of the handler after the event fires.</div></li>
  2477. * <li><b>single</b> Boolean: <div class="sub-desc">True to add a handler to handle just the next firing of the event, and then remove itself.</div></li>
  2478. * <li><b>buffer</b> Number: <div class="sub-desc">Causes the handler to be scheduled to run in an {@link Ext.util.DelayedTask} delayed
  2479. * by the specified number of milliseconds. If the event fires again within that time, the original
  2480. * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</div></li>
  2481. * </ul><br>
  2482. * <p>
  2483. * <b>Combining Options</b><br>
  2484. * In the following examples, the shorthand form {@link #on} is used rather than the more verbose
  2485. * addListener. The two are equivalent. Using the options argument, it is possible to combine different
  2486. * types of listeners:<br>
  2487. * <br>
  2488. * A delayed, one-time listener that auto stops the event and adds a custom argument (forumId) to the
  2489. * options object. The options object is available as the third parameter in the handler function.<div style="margin: 5px 20px 20px;">
  2490. * Code:<pre><code>
  2491. el.on('click', this.onClick, this, {
  2492. single: true,
  2493. delay: 100,
  2494. stopEvent : true,
  2495. forumId: 4
  2496. });</code></pre></p>
  2497. * <p>
  2498. * <b>Attaching multiple handlers in 1 call</b><br>
  2499. * The method also allows for a single argument to be passed which is a config object containing properties
  2500. * which specify multiple handlers.</p>
  2501. * <p>
  2502. * Code:<pre><code>
  2503. el.on({
  2504. 'click' : {
  2505. fn: this.onClick,
  2506. scope: this,
  2507. delay: 100
  2508. },
  2509. 'mouseover' : {
  2510. fn: this.onMouseOver,
  2511. scope: this
  2512. },
  2513. 'mouseout' : {
  2514. fn: this.onMouseOut,
  2515. scope: this
  2516. }
  2517. });</code></pre>
  2518. * <p>
  2519. * Or a shorthand syntax:<br>
  2520. * Code:<pre><code></p>
  2521. el.on({
  2522. 'click' : this.onClick,
  2523. 'mouseover' : this.onMouseOver,
  2524. 'mouseout' : this.onMouseOut,
  2525. scope: this
  2526. });
  2527. * </code></pre></p>
  2528. * <p><b>delegate</b></p>
  2529. * <p>This is a configuration option that you can pass along when registering a handler for
  2530. * an event to assist with event delegation. Event delegation is a technique that is used to
  2531. * reduce memory consumption and prevent exposure to memory-leaks. By registering an event
  2532. * for a container element as opposed to each element within a container. By setting this
  2533. * configuration option to a simple selector, the target element will be filtered to look for
  2534. * a descendant of the target.
  2535. * For example:<pre><code>
  2536. // using this markup:
  2537. &lt;div id='elId'>
  2538. &lt;p id='p1'>paragraph one&lt;/p>
  2539. &lt;p id='p2' class='clickable'>paragraph two&lt;/p>
  2540. &lt;p id='p3'>paragraph three&lt;/p>
  2541. &lt;/div>
  2542. // utilize event delegation to registering just one handler on the container element:
  2543. el = Ext.get('elId');
  2544. el.on(
  2545. 'click',
  2546. function(e,t) {
  2547. // handle click
  2548. console.info(t.id); // 'p2'
  2549. },
  2550. this,
  2551. {
  2552. // filter the target element to be a descendant with the class 'clickable'
  2553. delegate: '.clickable'
  2554. }
  2555. );
  2556. * </code></pre></p>
  2557. * @return {Ext.Element} this
  2558. */
  2559. addListener : function(eventName, fn, scope, options){
  2560. Ext.EventManager.on(this.dom, eventName, fn, scope || this, options);
  2561. return this;
  2562. },
  2563. /**
  2564. * Removes an event handler from this element. The shorthand version {@link #un} is equivalent.
  2565. * <b>Note</b>: if a <i>scope</i> was explicitly specified when {@link #addListener adding} the
  2566. * listener, the same scope must be specified here.
  2567. * Example:
  2568. * <pre><code>
  2569. el.removeListener('click', this.handlerFn);
  2570. // or
  2571. el.un('click', this.handlerFn);
  2572. </code></pre>
  2573. * @param {String} eventName The name of the event from which to remove the handler.
  2574. * @param {Function} fn The handler function to remove. <b>This must be a reference to the function passed into the {@link #addListener} call.</b>
  2575. * @param {Object} scope If a scope (<b><code>this</code></b> reference) was specified when the listener was added,
  2576. * then this must refer to the same object.
  2577. * @return {Ext.Element} this
  2578. */
  2579. removeListener : function(eventName, fn, scope){
  2580. Ext.EventManager.removeListener(this.dom, eventName, fn, scope || this);
  2581. return this;
  2582. },
  2583. /**
  2584. * Removes all previous added listeners from this element
  2585. * @return {Ext.Element} this
  2586. */
  2587. removeAllListeners : function(){
  2588. Ext.EventManager.removeAll(this.dom);
  2589. return this;
  2590. },
  2591. /**
  2592. * Recursively removes all previous added listeners from this element and its children
  2593. * @return {Ext.Element} this
  2594. */
  2595. purgeAllListeners : function() {
  2596. Ext.EventManager.purgeElement(this, true);
  2597. return this;
  2598. },
  2599. /**
  2600. * @private Test if size has a unit, otherwise appends the default
  2601. */
  2602. addUnits : function(size){
  2603. if(size === "" || size == "auto" || size === undefined){
  2604. size = size || '';
  2605. } else if(!isNaN(size) || !unitPattern.test(size)){
  2606. size = size + (this.defaultUnit || 'px');
  2607. }
  2608. return size;
  2609. },
  2610. /**
  2611. * <p>Updates the <a href="http://developer.mozilla.org/en/DOM/element.innerHTML">innerHTML</a> of this Element
  2612. * from a specified URL. Note that this is subject to the <a href="http://en.wikipedia.org/wiki/Same_origin_policy">Same Origin Policy</a></p>
  2613. * <p>Updating innerHTML of an element will <b>not</b> execute embedded <tt>&lt;script></tt> elements. This is a browser restriction.</p>
  2614. * @param {Mixed} options. Either a sring containing the URL from which to load the HTML, or an {@link Ext.Ajax#request} options object specifying
  2615. * exactly how to request the HTML.
  2616. * @return {Ext.Element} this
  2617. */
  2618. load : function(url, params, cb){
  2619. Ext.Ajax.request(Ext.apply({
  2620. params: params,
  2621. url: url.url || url,
  2622. callback: cb,
  2623. el: this.dom,
  2624. indicatorText: url.indicatorText || ''
  2625. }, Ext.isObject(url) ? url : {}));
  2626. return this;
  2627. },
  2628. /**
  2629. * Tests various css rules/browsers to determine if this element uses a border box
  2630. * @return {Boolean}
  2631. */
  2632. isBorderBox : function(){
  2633. return Ext.isBorderBox || Ext.isForcedBorderBox || noBoxAdjust[(this.dom.tagName || "").toLowerCase()];
  2634. },
  2635. /**
  2636. * <p>Removes this element's dom reference. Note that event and cache removal is handled at {@link Ext#removeNode}</p>
  2637. */
  2638. remove : function(){
  2639. var me = this,
  2640. dom = me.dom;
  2641. if (dom) {
  2642. delete me.dom;
  2643. Ext.removeNode(dom);
  2644. }
  2645. },
  2646. /**
  2647. * Sets up event handlers to call the passed functions when the mouse is moved into and out of the Element.
  2648. * @param {Function} overFn The function to call when the mouse enters the Element.
  2649. * @param {Function} outFn The function to call when the mouse leaves the Element.
  2650. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the functions are executed. Defaults to the Element's DOM element.
  2651. * @param {Object} options (optional) Options for the listener. See {@link Ext.util.Observable#addListener the <tt>options</tt> parameter}.
  2652. * @return {Ext.Element} this
  2653. */
  2654. hover : function(overFn, outFn, scope, options){
  2655. var me = this;
  2656. me.on('mouseenter', overFn, scope || me.dom, options);
  2657. me.on('mouseleave', outFn, scope || me.dom, options);
  2658. return me;
  2659. },
  2660. /**
  2661. * Returns true if this element is an ancestor of the passed element
  2662. * @param {HTMLElement/String} el The element to check
  2663. * @return {Boolean} True if this element is an ancestor of el, else false
  2664. */
  2665. contains : function(el){
  2666. return !el ? false : Ext.lib.Dom.isAncestor(this.dom, el.dom ? el.dom : el);
  2667. },
  2668. /**
  2669. * Returns the value of a namespaced attribute from the element's underlying DOM node.
  2670. * @param {String} namespace The namespace in which to look for the attribute
  2671. * @param {String} name The attribute name
  2672. * @return {String} The attribute value
  2673. * @deprecated
  2674. */
  2675. getAttributeNS : function(ns, name){
  2676. return this.getAttribute(name, ns);
  2677. },
  2678. /**
  2679. * Returns the value of an attribute from the element's underlying DOM node.
  2680. * @param {String} name The attribute name
  2681. * @param {String} namespace (optional) The namespace in which to look for the attribute
  2682. * @return {String} The attribute value
  2683. */
  2684. getAttribute : Ext.isIE ? function(name, ns){
  2685. var d = this.dom,
  2686. type = typeof d[ns + ":" + name];
  2687. if(['undefined', 'unknown'].indexOf(type) == -1){
  2688. return d[ns + ":" + name];
  2689. }
  2690. return d[name];
  2691. } : function(name, ns){
  2692. var d = this.dom;
  2693. return d.getAttributeNS(ns, name) || d.getAttribute(ns + ":" + name) || d.getAttribute(name) || d[name];
  2694. },
  2695. /**
  2696. * Update the innerHTML of this element
  2697. * @param {String} html The new HTML
  2698. * @return {Ext.Element} this
  2699. */
  2700. update : function(html) {
  2701. if (this.dom) {
  2702. this.dom.innerHTML = html;
  2703. }
  2704. return this;
  2705. }
  2706. };
  2707. var ep = El.prototype;
  2708. El.addMethods = function(o){
  2709. Ext.apply(ep, o);
  2710. };
  2711. /**
  2712. * Appends an event handler (shorthand for {@link #addListener}).
  2713. * @param {String} eventName The name of event to handle.
  2714. * @param {Function} fn The handler function the event invokes.
  2715. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the handler function is executed.
  2716. * @param {Object} options (optional) An object containing standard {@link #addListener} options
  2717. * @member Ext.Element
  2718. * @method on
  2719. */
  2720. ep.on = ep.addListener;
  2721. /**
  2722. * Removes an event handler from this element (see {@link #removeListener} for additional notes).
  2723. * @param {String} eventName The name of the event from which to remove the handler.
  2724. * @param {Function} fn The handler function to remove. <b>This must be a reference to the function passed into the {@link #addListener} call.</b>
  2725. * @param {Object} scope If a scope (<b><code>this</code></b> reference) was specified when the listener was added,
  2726. * then this must refer to the same object.
  2727. * @return {Ext.Element} this
  2728. * @member Ext.Element
  2729. * @method un
  2730. */
  2731. ep.un = ep.removeListener;
  2732. /**
  2733. * true to automatically adjust width and height settings for box-model issues (default to true)
  2734. */
  2735. ep.autoBoxAdjust = true;
  2736. // private
  2737. var unitPattern = /\d+(px|em|%|en|ex|pt|in|cm|mm|pc)$/i,
  2738. docEl;
  2739. /**
  2740. * @private
  2741. */
  2742. /**
  2743. * Retrieves Ext.Element objects.
  2744. * <p><b>This method does not retrieve {@link Ext.Component Component}s.</b> This method
  2745. * retrieves Ext.Element objects which encapsulate DOM elements. To retrieve a Component by
  2746. * its ID, use {@link Ext.ComponentMgr#get}.</p>
  2747. * <p>Uses simple caching to consistently return the same object. Automatically fixes if an
  2748. * object was recreated with the same id via AJAX or DOM.</p>
  2749. * @param {Mixed} el The id of the node, a DOM Node or an existing Element.
  2750. * @return {Element} The Element object (or null if no matching element was found)
  2751. * @static
  2752. * @member Ext.Element
  2753. * @method get
  2754. */
  2755. El.get = function(el){
  2756. var ex,
  2757. elm,
  2758. id;
  2759. if(!el){ return null; }
  2760. if (typeof el == "string") { // element id
  2761. if (!(elm = DOC.getElementById(el))) {
  2762. return null;
  2763. }
  2764. if (EC[el] && EC[el].el) {
  2765. ex = EC[el].el;
  2766. ex.dom = elm;
  2767. } else {
  2768. ex = El.addToCache(new El(elm));
  2769. }
  2770. return ex;
  2771. } else if (el.tagName) { // dom element
  2772. if(!(id = el.id)){
  2773. id = Ext.id(el);
  2774. }
  2775. if (EC[id] && EC[id].el) {
  2776. ex = EC[id].el;
  2777. ex.dom = el;
  2778. } else {
  2779. ex = El.addToCache(new El(el));
  2780. }
  2781. return ex;
  2782. } else if (el instanceof El) {
  2783. if(el != docEl){
  2784. // refresh dom element in case no longer valid,
  2785. // catch case where it hasn't been appended
  2786. // If an el instance is passed, don't pass to getElementById without some kind of id
  2787. if (Ext.isIE && (el.id == undefined || el.id == '')) {
  2788. el.dom = el.dom;
  2789. } else {
  2790. el.dom = DOC.getElementById(el.id) || el.dom;
  2791. }
  2792. }
  2793. return el;
  2794. } else if(el.isComposite) {
  2795. return el;
  2796. } else if(Ext.isArray(el)) {
  2797. return El.select(el);
  2798. } else if(el == DOC) {
  2799. // create a bogus element object representing the document object
  2800. if(!docEl){
  2801. var f = function(){};
  2802. f.prototype = El.prototype;
  2803. docEl = new f();
  2804. docEl.dom = DOC;
  2805. }
  2806. return docEl;
  2807. }
  2808. return null;
  2809. };
  2810. El.addToCache = function(el, id){
  2811. id = id || el.id;
  2812. EC[id] = {
  2813. el: el,
  2814. data: {},
  2815. events: {}
  2816. };
  2817. return el;
  2818. };
  2819. // private method for getting and setting element data
  2820. El.data = function(el, key, value){
  2821. el = El.get(el);
  2822. if (!el) {
  2823. return null;
  2824. }
  2825. var c = EC[el.id].data;
  2826. if(arguments.length == 2){
  2827. return c[key];
  2828. }else{
  2829. return (c[key] = value);
  2830. }
  2831. };
  2832. // private
  2833. // Garbage collection - uncache elements/purge listeners on orphaned elements
  2834. // so we don't hold a reference and cause the browser to retain them
  2835. function garbageCollect(){
  2836. if(!Ext.enableGarbageCollector){
  2837. clearInterval(El.collectorThreadId);
  2838. } else {
  2839. var eid,
  2840. el,
  2841. d,
  2842. o;
  2843. for(eid in EC){
  2844. o = EC[eid];
  2845. if(o.skipGC){
  2846. continue;
  2847. }
  2848. el = o.el;
  2849. d = el.dom;
  2850. // -------------------------------------------------------
  2851. // Determining what is garbage:
  2852. // -------------------------------------------------------
  2853. // !d
  2854. // dom node is null, definitely garbage
  2855. // -------------------------------------------------------
  2856. // !d.parentNode
  2857. // no parentNode == direct orphan, definitely garbage
  2858. // -------------------------------------------------------
  2859. // !d.offsetParent && !document.getElementById(eid)
  2860. // display none elements have no offsetParent so we will
  2861. // also try to look it up by it's id. However, check
  2862. // offsetParent first so we don't do unneeded lookups.
  2863. // This enables collection of elements that are not orphans
  2864. // directly, but somewhere up the line they have an orphan
  2865. // parent.
  2866. // -------------------------------------------------------
  2867. if(!d || !d.parentNode || (!d.offsetParent && !DOC.getElementById(eid))){
  2868. if(Ext.enableListenerCollection){
  2869. Ext.EventManager.removeAll(d);
  2870. }
  2871. delete EC[eid];
  2872. }
  2873. }
  2874. // Cleanup IE Object leaks
  2875. if (Ext.isIE) {
  2876. var t = {};
  2877. for (eid in EC) {
  2878. t[eid] = EC[eid];
  2879. }
  2880. EC = Ext.elCache = t;
  2881. }
  2882. }
  2883. }
  2884. El.collectorThreadId = setInterval(garbageCollect, 30000);
  2885. var flyFn = function(){};
  2886. flyFn.prototype = El.prototype;
  2887. // dom is optional
  2888. El.Flyweight = function(dom){
  2889. this.dom = dom;
  2890. };
  2891. El.Flyweight.prototype = new flyFn();
  2892. El.Flyweight.prototype.isFlyweight = true;
  2893. El._flyweights = {};
  2894. /**
  2895. * <p>Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element -
  2896. * the dom node can be overwritten by other code. Shorthand of {@link Ext.Element#fly}</p>
  2897. * <p>Use this to make one-time references to DOM elements which are not going to be accessed again either by
  2898. * application code, or by Ext's classes. If accessing an element which will be processed regularly, then {@link Ext#get}
  2899. * will be more appropriate to take advantage of the caching provided by the Ext.Element class.</p>
  2900. * @param {String/HTMLElement} el The dom node or id
  2901. * @param {String} named (optional) Allows for creation of named reusable flyweights to prevent conflicts
  2902. * (e.g. internally Ext uses "_global")
  2903. * @return {Element} The shared Element object (or null if no matching element was found)
  2904. * @member Ext.Element
  2905. * @method fly
  2906. */
  2907. El.fly = function(el, named){
  2908. var ret = null;
  2909. named = named || '_global';
  2910. if (el = Ext.getDom(el)) {
  2911. (El._flyweights[named] = El._flyweights[named] || new El.Flyweight()).dom = el;
  2912. ret = El._flyweights[named];
  2913. }
  2914. return ret;
  2915. };
  2916. /**
  2917. * Retrieves Ext.Element objects.
  2918. * <p><b>This method does not retrieve {@link Ext.Component Component}s.</b> This method
  2919. * retrieves Ext.Element objects which encapsulate DOM elements. To retrieve a Component by
  2920. * its ID, use {@link Ext.ComponentMgr#get}.</p>
  2921. * <p>Uses simple caching to consistently return the same object. Automatically fixes if an
  2922. * object was recreated with the same id via AJAX or DOM.</p>
  2923. * Shorthand of {@link Ext.Element#get}
  2924. * @param {Mixed} el The id of the node, a DOM Node or an existing Element.
  2925. * @return {Element} The Element object (or null if no matching element was found)
  2926. * @member Ext
  2927. * @method get
  2928. */
  2929. Ext.get = El.get;
  2930. /**
  2931. * <p>Gets the globally shared flyweight Element, with the passed node as the active element. Do not store a reference to this element -
  2932. * the dom node can be overwritten by other code. Shorthand of {@link Ext.Element#fly}</p>
  2933. * <p>Use this to make one-time references to DOM elements which are not going to be accessed again either by
  2934. * application code, or by Ext's classes. If accessing an element which will be processed regularly, then {@link Ext#get}
  2935. * will be more appropriate to take advantage of the caching provided by the Ext.Element class.</p>
  2936. * @param {String/HTMLElement} el The dom node or id
  2937. * @param {String} named (optional) Allows for creation of named reusable flyweights to prevent conflicts
  2938. * (e.g. internally Ext uses "_global")
  2939. * @return {Element} The shared Element object (or null if no matching element was found)
  2940. * @member Ext
  2941. * @method fly
  2942. */
  2943. Ext.fly = El.fly;
  2944. // speedy lookup for elements never to box adjust
  2945. var noBoxAdjust = Ext.isStrict ? {
  2946. select:1
  2947. } : {
  2948. input:1, select:1, textarea:1
  2949. };
  2950. if(Ext.isIE || Ext.isGecko){
  2951. noBoxAdjust['button'] = 1;
  2952. }
  2953. })();
  2954. /**
  2955. * @class Ext.Element
  2956. */
  2957. Ext.Element.addMethods(function(){
  2958. var PARENTNODE = 'parentNode',
  2959. NEXTSIBLING = 'nextSibling',
  2960. PREVIOUSSIBLING = 'previousSibling',
  2961. DQ = Ext.DomQuery,
  2962. GET = Ext.get;
  2963. return {
  2964. /**
  2965. * Looks at this node and then at parent nodes for a match of the passed simple selector (e.g. div.some-class or span:first-child)
  2966. * @param {String} selector The simple selector to test
  2967. * @param {Number/Mixed} maxDepth (optional) The max depth to search as a number or element (defaults to 50 || document.body)
  2968. * @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node
  2969. * @return {HTMLElement} The matching DOM node (or null if no match was found)
  2970. */
  2971. findParent : function(simpleSelector, maxDepth, returnEl){
  2972. var p = this.dom,
  2973. b = document.body,
  2974. depth = 0,
  2975. stopEl;
  2976. if(Ext.isGecko && Object.prototype.toString.call(p) == '[object XULElement]') {
  2977. return null;
  2978. }
  2979. maxDepth = maxDepth || 50;
  2980. if (isNaN(maxDepth)) {
  2981. stopEl = Ext.getDom(maxDepth);
  2982. maxDepth = Number.MAX_VALUE;
  2983. }
  2984. while(p && p.nodeType == 1 && depth < maxDepth && p != b && p != stopEl){
  2985. if(DQ.is(p, simpleSelector)){
  2986. return returnEl ? GET(p) : p;
  2987. }
  2988. depth++;
  2989. p = p.parentNode;
  2990. }
  2991. return null;
  2992. },
  2993. /**
  2994. * Looks at parent nodes for a match of the passed simple selector (e.g. div.some-class or span:first-child)
  2995. * @param {String} selector The simple selector to test
  2996. * @param {Number/Mixed} maxDepth (optional) The max depth to
  2997. search as a number or element (defaults to 10 || document.body)
  2998. * @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node
  2999. * @return {HTMLElement} The matching DOM node (or null if no match was found)
  3000. */
  3001. findParentNode : function(simpleSelector, maxDepth, returnEl){
  3002. var p = Ext.fly(this.dom.parentNode, '_internal');
  3003. return p ? p.findParent(simpleSelector, maxDepth, returnEl) : null;
  3004. },
  3005. /**
  3006. * Walks up the dom looking for a parent node that matches the passed simple selector (e.g. div.some-class or span:first-child).
  3007. * This is a shortcut for findParentNode() that always returns an Ext.Element.
  3008. * @param {String} selector The simple selector to test
  3009. * @param {Number/Mixed} maxDepth (optional) The max depth to
  3010. search as a number or element (defaults to 10 || document.body)
  3011. * @return {Ext.Element} The matching DOM node (or null if no match was found)
  3012. */
  3013. up : function(simpleSelector, maxDepth){
  3014. return this.findParentNode(simpleSelector, maxDepth, true);
  3015. },
  3016. /**
  3017. * Creates a {@link Ext.CompositeElement} for child nodes based on the passed CSS selector (the selector should not contain an id).
  3018. * @param {String} selector The CSS selector
  3019. * @return {CompositeElement/CompositeElementLite} The composite element
  3020. */
  3021. select : function(selector){
  3022. return Ext.Element.select(selector, this.dom);
  3023. },
  3024. /**
  3025. * Selects child nodes based on the passed CSS selector (the selector should not contain an id).
  3026. * @param {String} selector The CSS selector
  3027. * @return {Array} An array of the matched nodes
  3028. */
  3029. query : function(selector){
  3030. return DQ.select(selector, this.dom);
  3031. },
  3032. /**
  3033. * Selects a single child at any depth below this element based on the passed CSS selector (the selector should not contain an id).
  3034. * @param {String} selector The CSS selector
  3035. * @param {Boolean} returnDom (optional) True to return the DOM node instead of Ext.Element (defaults to false)
  3036. * @return {HTMLElement/Ext.Element} The child Ext.Element (or DOM node if returnDom = true)
  3037. */
  3038. child : function(selector, returnDom){
  3039. var n = DQ.selectNode(selector, this.dom);
  3040. return returnDom ? n : GET(n);
  3041. },
  3042. /**
  3043. * Selects a single *direct* child based on the passed CSS selector (the selector should not contain an id).
  3044. * @param {String} selector The CSS selector
  3045. * @param {Boolean} returnDom (optional) True to return the DOM node instead of Ext.Element (defaults to false)
  3046. * @return {HTMLElement/Ext.Element} The child Ext.Element (or DOM node if returnDom = true)
  3047. */
  3048. down : function(selector, returnDom){
  3049. var n = DQ.selectNode(" > " + selector, this.dom);
  3050. return returnDom ? n : GET(n);
  3051. },
  3052. /**
  3053. * Gets the parent node for this element, optionally chaining up trying to match a selector
  3054. * @param {String} selector (optional) Find a parent node that matches the passed simple selector
  3055. * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
  3056. * @return {Ext.Element/HTMLElement} The parent node or null
  3057. */
  3058. parent : function(selector, returnDom){
  3059. return this.matchNode(PARENTNODE, PARENTNODE, selector, returnDom);
  3060. },
  3061. /**
  3062. * Gets the next sibling, skipping text nodes
  3063. * @param {String} selector (optional) Find the next sibling that matches the passed simple selector
  3064. * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
  3065. * @return {Ext.Element/HTMLElement} The next sibling or null
  3066. */
  3067. next : function(selector, returnDom){
  3068. return this.matchNode(NEXTSIBLING, NEXTSIBLING, selector, returnDom);
  3069. },
  3070. /**
  3071. * Gets the previous sibling, skipping text nodes
  3072. * @param {String} selector (optional) Find the previous sibling that matches the passed simple selector
  3073. * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
  3074. * @return {Ext.Element/HTMLElement} The previous sibling or null
  3075. */
  3076. prev : function(selector, returnDom){
  3077. return this.matchNode(PREVIOUSSIBLING, PREVIOUSSIBLING, selector, returnDom);
  3078. },
  3079. /**
  3080. * Gets the first child, skipping text nodes
  3081. * @param {String} selector (optional) Find the next sibling that matches the passed simple selector
  3082. * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
  3083. * @return {Ext.Element/HTMLElement} The first child or null
  3084. */
  3085. first : function(selector, returnDom){
  3086. return this.matchNode(NEXTSIBLING, 'firstChild', selector, returnDom);
  3087. },
  3088. /**
  3089. * Gets the last child, skipping text nodes
  3090. * @param {String} selector (optional) Find the previous sibling that matches the passed simple selector
  3091. * @param {Boolean} returnDom (optional) True to return a raw dom node instead of an Ext.Element
  3092. * @return {Ext.Element/HTMLElement} The last child or null
  3093. */
  3094. last : function(selector, returnDom){
  3095. return this.matchNode(PREVIOUSSIBLING, 'lastChild', selector, returnDom);
  3096. },
  3097. matchNode : function(dir, start, selector, returnDom){
  3098. var n = this.dom[start];
  3099. while(n){
  3100. if(n.nodeType == 1 && (!selector || DQ.is(n, selector))){
  3101. return !returnDom ? GET(n) : n;
  3102. }
  3103. n = n[dir];
  3104. }
  3105. return null;
  3106. }
  3107. };
  3108. }());/**
  3109. * @class Ext.Element
  3110. */
  3111. Ext.Element.addMethods(
  3112. function() {
  3113. var GETDOM = Ext.getDom,
  3114. GET = Ext.get,
  3115. DH = Ext.DomHelper;
  3116. return {
  3117. /**
  3118. * Appends the passed element(s) to this element
  3119. * @param {String/HTMLElement/Array/Element/CompositeElement} el
  3120. * @return {Ext.Element} this
  3121. */
  3122. appendChild: function(el){
  3123. return GET(el).appendTo(this);
  3124. },
  3125. /**
  3126. * Appends this element to the passed element
  3127. * @param {Mixed} el The new parent element
  3128. * @return {Ext.Element} this
  3129. */
  3130. appendTo: function(el){
  3131. GETDOM(el).appendChild(this.dom);
  3132. return this;
  3133. },
  3134. /**
  3135. * Inserts this element before the passed element in the DOM
  3136. * @param {Mixed} el The element before which this element will be inserted
  3137. * @return {Ext.Element} this
  3138. */
  3139. insertBefore: function(el){
  3140. (el = GETDOM(el)).parentNode.insertBefore(this.dom, el);
  3141. return this;
  3142. },
  3143. /**
  3144. * Inserts this element after the passed element in the DOM
  3145. * @param {Mixed} el The element to insert after
  3146. * @return {Ext.Element} this
  3147. */
  3148. insertAfter: function(el){
  3149. (el = GETDOM(el)).parentNode.insertBefore(this.dom, el.nextSibling);
  3150. return this;
  3151. },
  3152. /**
  3153. * Inserts (or creates) an element (or DomHelper config) as the first child of this element
  3154. * @param {Mixed/Object} el The id or element to insert or a DomHelper config to create and insert
  3155. * @return {Ext.Element} The new child
  3156. */
  3157. insertFirst: function(el, returnDom){
  3158. el = el || {};
  3159. if(el.nodeType || el.dom || typeof el == 'string'){ // element
  3160. el = GETDOM(el);
  3161. this.dom.insertBefore(el, this.dom.firstChild);
  3162. return !returnDom ? GET(el) : el;
  3163. }else{ // dh config
  3164. return this.createChild(el, this.dom.firstChild, returnDom);
  3165. }
  3166. },
  3167. /**
  3168. * Replaces the passed element with this element
  3169. * @param {Mixed} el The element to replace
  3170. * @return {Ext.Element} this
  3171. */
  3172. replace: function(el){
  3173. el = GET(el);
  3174. this.insertBefore(el);
  3175. el.remove();
  3176. return this;
  3177. },
  3178. /**
  3179. * Replaces this element with the passed element
  3180. * @param {Mixed/Object} el The new element or a DomHelper config of an element to create
  3181. * @return {Ext.Element} this
  3182. */
  3183. replaceWith: function(el){
  3184. var me = this;
  3185. if(el.nodeType || el.dom || typeof el == 'string'){
  3186. el = GETDOM(el);
  3187. me.dom.parentNode.insertBefore(el, me.dom);
  3188. }else{
  3189. el = DH.insertBefore(me.dom, el);
  3190. }
  3191. delete Ext.elCache[me.id];
  3192. Ext.removeNode(me.dom);
  3193. me.id = Ext.id(me.dom = el);
  3194. Ext.Element.addToCache(me.isFlyweight ? new Ext.Element(me.dom) : me);
  3195. return me;
  3196. },
  3197. /**
  3198. * Creates the passed DomHelper config and appends it to this element or optionally inserts it before the passed child element.
  3199. * @param {Object} config DomHelper element config object. If no tag is specified (e.g., {tag:'input'}) then a div will be
  3200. * automatically generated with the specified attributes.
  3201. * @param {HTMLElement} insertBefore (optional) a child element of this element
  3202. * @param {Boolean} returnDom (optional) true to return the dom node instead of creating an Element
  3203. * @return {Ext.Element} The new child element
  3204. */
  3205. createChild: function(config, insertBefore, returnDom){
  3206. config = config || {tag:'div'};
  3207. return insertBefore ?
  3208. DH.insertBefore(insertBefore, config, returnDom !== true) :
  3209. DH[!this.dom.firstChild ? 'overwrite' : 'append'](this.dom, config, returnDom !== true);
  3210. },
  3211. /**
  3212. * Creates and wraps this element with another element
  3213. * @param {Object} config (optional) DomHelper element config object for the wrapper element or null for an empty div
  3214. * @param {Boolean} returnDom (optional) True to return the raw DOM element instead of Ext.Element
  3215. * @return {HTMLElement/Element} The newly created wrapper element
  3216. */
  3217. wrap: function(config, returnDom){
  3218. var newEl = DH.insertBefore(this.dom, config || {tag: "div"}, !returnDom);
  3219. newEl.dom ? newEl.dom.appendChild(this.dom) : newEl.appendChild(this.dom);
  3220. return newEl;
  3221. },
  3222. /**
  3223. * Inserts an html fragment into this element
  3224. * @param {String} where Where to insert the html in relation to this element - beforeBegin, afterBegin, beforeEnd, afterEnd.
  3225. * @param {String} html The HTML fragment
  3226. * @param {Boolean} returnEl (optional) True to return an Ext.Element (defaults to false)
  3227. * @return {HTMLElement/Ext.Element} The inserted node (or nearest related if more than 1 inserted)
  3228. */
  3229. insertHtml : function(where, html, returnEl){
  3230. var el = DH.insertHtml(where, this.dom, html);
  3231. return returnEl ? Ext.get(el) : el;
  3232. }
  3233. };
  3234. }());/**
  3235. * @class Ext.Element
  3236. */
  3237. Ext.Element.addMethods(function(){
  3238. // local style camelizing for speed
  3239. var supports = Ext.supports,
  3240. propCache = {},
  3241. camelRe = /(-[a-z])/gi,
  3242. view = document.defaultView,
  3243. opacityRe = /alpha\(opacity=(.*)\)/i,
  3244. trimRe = /^\s+|\s+$/g,
  3245. EL = Ext.Element,
  3246. spacesRe = /\s+/,
  3247. wordsRe = /\w/g,
  3248. PADDING = "padding",
  3249. MARGIN = "margin",
  3250. BORDER = "border",
  3251. LEFT = "-left",
  3252. RIGHT = "-right",
  3253. TOP = "-top",
  3254. BOTTOM = "-bottom",
  3255. WIDTH = "-width",
  3256. MATH = Math,
  3257. HIDDEN = 'hidden',
  3258. ISCLIPPED = 'isClipped',
  3259. OVERFLOW = 'overflow',
  3260. OVERFLOWX = 'overflow-x',
  3261. OVERFLOWY = 'overflow-y',
  3262. ORIGINALCLIP = 'originalClip',
  3263. // special markup used throughout Ext when box wrapping elements
  3264. borders = {l: BORDER + LEFT + WIDTH, r: BORDER + RIGHT + WIDTH, t: BORDER + TOP + WIDTH, b: BORDER + BOTTOM + WIDTH},
  3265. paddings = {l: PADDING + LEFT, r: PADDING + RIGHT, t: PADDING + TOP, b: PADDING + BOTTOM},
  3266. margins = {l: MARGIN + LEFT, r: MARGIN + RIGHT, t: MARGIN + TOP, b: MARGIN + BOTTOM},
  3267. data = Ext.Element.data;
  3268. // private
  3269. function camelFn(m, a) {
  3270. return a.charAt(1).toUpperCase();
  3271. }
  3272. function chkCache(prop) {
  3273. return propCache[prop] || (propCache[prop] = prop == 'float' ? (supports.cssFloat ? 'cssFloat' : 'styleFloat') : prop.replace(camelRe, camelFn));
  3274. }
  3275. return {
  3276. // private ==> used by Fx
  3277. adjustWidth : function(width) {
  3278. var me = this;
  3279. var isNum = (typeof width == "number");
  3280. if(isNum && me.autoBoxAdjust && !me.isBorderBox()){
  3281. width -= (me.getBorderWidth("lr") + me.getPadding("lr"));
  3282. }
  3283. return (isNum && width < 0) ? 0 : width;
  3284. },
  3285. // private ==> used by Fx
  3286. adjustHeight : function(height) {
  3287. var me = this;
  3288. var isNum = (typeof height == "number");
  3289. if(isNum && me.autoBoxAdjust && !me.isBorderBox()){
  3290. height -= (me.getBorderWidth("tb") + me.getPadding("tb"));
  3291. }
  3292. return (isNum && height < 0) ? 0 : height;
  3293. },
  3294. /**
  3295. * Adds one or more CSS classes to the element. Duplicate classes are automatically filtered out.
  3296. * @param {String/Array} className The CSS class to add, or an array of classes
  3297. * @return {Ext.Element} this
  3298. */
  3299. addClass : function(className){
  3300. var me = this,
  3301. i,
  3302. len,
  3303. v,
  3304. cls = [];
  3305. // Separate case is for speed
  3306. if (!Ext.isArray(className)) {
  3307. if (typeof className == 'string' && !this.hasClass(className)) {
  3308. me.dom.className += " " + className;
  3309. }
  3310. }
  3311. else {
  3312. for (i = 0, len = className.length; i < len; i++) {
  3313. v = className[i];
  3314. if (typeof v == 'string' && (' ' + me.dom.className + ' ').indexOf(' ' + v + ' ') == -1) {
  3315. cls.push(v);
  3316. }
  3317. }
  3318. if (cls.length) {
  3319. me.dom.className += " " + cls.join(" ");
  3320. }
  3321. }
  3322. return me;
  3323. },
  3324. /**
  3325. * Removes one or more CSS classes from the element.
  3326. * @param {String/Array} className The CSS class to remove, or an array of classes
  3327. * @return {Ext.Element} this
  3328. */
  3329. removeClass : function(className){
  3330. var me = this,
  3331. i,
  3332. idx,
  3333. len,
  3334. cls,
  3335. elClasses;
  3336. if (!Ext.isArray(className)){
  3337. className = [className];
  3338. }
  3339. if (me.dom && me.dom.className) {
  3340. elClasses = me.dom.className.replace(trimRe, '').split(spacesRe);
  3341. for (i = 0, len = className.length; i < len; i++) {
  3342. cls = className[i];
  3343. if (typeof cls == 'string') {
  3344. cls = cls.replace(trimRe, '');
  3345. idx = elClasses.indexOf(cls);
  3346. if (idx != -1) {
  3347. elClasses.splice(idx, 1);
  3348. }
  3349. }
  3350. }
  3351. me.dom.className = elClasses.join(" ");
  3352. }
  3353. return me;
  3354. },
  3355. /**
  3356. * Adds one or more CSS classes to this element and removes the same class(es) from all siblings.
  3357. * @param {String/Array} className The CSS class to add, or an array of classes
  3358. * @return {Ext.Element} this
  3359. */
  3360. radioClass : function(className){
  3361. var cn = this.dom.parentNode.childNodes,
  3362. v,
  3363. i,
  3364. len;
  3365. className = Ext.isArray(className) ? className : [className];
  3366. for (i = 0, len = cn.length; i < len; i++) {
  3367. v = cn[i];
  3368. if (v && v.nodeType == 1) {
  3369. Ext.fly(v, '_internal').removeClass(className);
  3370. }
  3371. };
  3372. return this.addClass(className);
  3373. },
  3374. /**
  3375. * Toggles the specified CSS class on this element (removes it if it already exists, otherwise adds it).
  3376. * @param {String} className The CSS class to toggle
  3377. * @return {Ext.Element} this
  3378. */
  3379. toggleClass : function(className){
  3380. return this.hasClass(className) ? this.removeClass(className) : this.addClass(className);
  3381. },
  3382. /**
  3383. * Checks if the specified CSS class exists on this element's DOM node.
  3384. * @param {String} className The CSS class to check for
  3385. * @return {Boolean} True if the class exists, else false
  3386. */
  3387. hasClass : function(className){
  3388. return className && (' '+this.dom.className+' ').indexOf(' '+className+' ') != -1;
  3389. },
  3390. /**
  3391. * Replaces a CSS class on the element with another. If the old name does not exist, the new name will simply be added.
  3392. * @param {String} oldClassName The CSS class to replace
  3393. * @param {String} newClassName The replacement CSS class
  3394. * @return {Ext.Element} this
  3395. */
  3396. replaceClass : function(oldClassName, newClassName){
  3397. return this.removeClass(oldClassName).addClass(newClassName);
  3398. },
  3399. isStyle : function(style, val) {
  3400. return this.getStyle(style) == val;
  3401. },
  3402. /**
  3403. * Normalizes currentStyle and computedStyle.
  3404. * @param {String} property The style property whose value is returned.
  3405. * @return {String} The current value of the style property for this element.
  3406. */
  3407. getStyle : function(){
  3408. return view && view.getComputedStyle ?
  3409. function(prop){
  3410. var el = this.dom,
  3411. v,
  3412. cs,
  3413. out,
  3414. display;
  3415. if(el == document){
  3416. return null;
  3417. }
  3418. prop = chkCache(prop);
  3419. out = (v = el.style[prop]) ? v :
  3420. (cs = view.getComputedStyle(el, "")) ? cs[prop] : null;
  3421. // Ignore cases when the margin is correctly reported as 0, the bug only shows
  3422. // numbers larger.
  3423. if(prop == 'marginRight' && out != '0px' && !supports.correctRightMargin){
  3424. display = el.style.display;
  3425. el.style.display = 'inline-block';
  3426. out = view.getComputedStyle(el, '').marginRight;
  3427. el.style.display = display;
  3428. }
  3429. if(prop == 'backgroundColor' && out == 'rgba(0, 0, 0, 0)' && !supports.correctTransparentColor){
  3430. out = 'transparent';
  3431. }
  3432. return out;
  3433. } :
  3434. function(prop){
  3435. var el = this.dom,
  3436. m,
  3437. cs;
  3438. if(el == document) return null;
  3439. if (prop == 'opacity') {
  3440. if (el.style.filter.match) {
  3441. if(m = el.style.filter.match(opacityRe)){
  3442. var fv = parseFloat(m[1]);
  3443. if(!isNaN(fv)){
  3444. return fv ? fv / 100 : 0;
  3445. }
  3446. }
  3447. }
  3448. return 1;
  3449. }
  3450. prop = chkCache(prop);
  3451. return el.style[prop] || ((cs = el.currentStyle) ? cs[prop] : null);
  3452. };
  3453. }(),
  3454. /**
  3455. * Return the CSS color for the specified CSS attribute. rgb, 3 digit (like #fff) and valid values
  3456. * are convert to standard 6 digit hex color.
  3457. * @param {String} attr The css attribute
  3458. * @param {String} defaultValue The default value to use when a valid color isn't found
  3459. * @param {String} prefix (optional) defaults to #. Use an empty string when working with
  3460. * color anims.
  3461. */
  3462. getColor : function(attr, defaultValue, prefix){
  3463. var v = this.getStyle(attr),
  3464. color = (typeof prefix != 'undefined') ? prefix : '#',
  3465. h;
  3466. if(!v || (/transparent|inherit/.test(v))) {
  3467. return defaultValue;
  3468. }
  3469. if(/^r/.test(v)){
  3470. Ext.each(v.slice(4, v.length -1).split(','), function(s){
  3471. h = parseInt(s, 10);
  3472. color += (h < 16 ? '0' : '') + h.toString(16);
  3473. });
  3474. }else{
  3475. v = v.replace('#', '');
  3476. color += v.length == 3 ? v.replace(/^(\w)(\w)(\w)$/, '$1$1$2$2$3$3') : v;
  3477. }
  3478. return(color.length > 5 ? color.toLowerCase() : defaultValue);
  3479. },
  3480. /**
  3481. * Wrapper for setting style properties, also takes single object parameter of multiple styles.
  3482. * @param {String/Object} property The style property to be set, or an object of multiple styles.
  3483. * @param {String} value (optional) The value to apply to the given property, or null if an object was passed.
  3484. * @return {Ext.Element} this
  3485. */
  3486. setStyle : function(prop, value){
  3487. var tmp, style;
  3488. if (typeof prop != 'object') {
  3489. tmp = {};
  3490. tmp[prop] = value;
  3491. prop = tmp;
  3492. }
  3493. for (style in prop) {
  3494. value = prop[style];
  3495. style == 'opacity' ?
  3496. this.setOpacity(value) :
  3497. this.dom.style[chkCache(style)] = value;
  3498. }
  3499. return this;
  3500. },
  3501. /**
  3502. * Set the opacity of the element
  3503. * @param {Float} opacity The new opacity. 0 = transparent, .5 = 50% visibile, 1 = fully visible, etc
  3504. * @param {Boolean/Object} animate (optional) a standard Element animation config object or <tt>true</tt> for
  3505. * the default animation (<tt>{duration: .35, easing: 'easeIn'}</tt>)
  3506. * @return {Ext.Element} this
  3507. */
  3508. setOpacity : function(opacity, animate){
  3509. var me = this,
  3510. s = me.dom.style;
  3511. if(!animate || !me.anim){
  3512. if(Ext.isIE){
  3513. var opac = opacity < 1 ? 'alpha(opacity=' + opacity * 100 + ')' : '',
  3514. val = s.filter.replace(opacityRe, '').replace(trimRe, '');
  3515. s.zoom = 1;
  3516. s.filter = val + (val.length > 0 ? ' ' : '') + opac;
  3517. }else{
  3518. s.opacity = opacity;
  3519. }
  3520. }else{
  3521. me.anim({opacity: {to: opacity}}, me.preanim(arguments, 1), null, .35, 'easeIn');
  3522. }
  3523. return me;
  3524. },
  3525. /**
  3526. * Clears any opacity settings from this element. Required in some cases for IE.
  3527. * @return {Ext.Element} this
  3528. */
  3529. clearOpacity : function(){
  3530. var style = this.dom.style;
  3531. if(Ext.isIE){
  3532. if(!Ext.isEmpty(style.filter)){
  3533. style.filter = style.filter.replace(opacityRe, '').replace(trimRe, '');
  3534. }
  3535. }else{
  3536. style.opacity = style['-moz-opacity'] = style['-khtml-opacity'] = '';
  3537. }
  3538. return this;
  3539. },
  3540. /**
  3541. * Returns the offset height of the element
  3542. * @param {Boolean} contentHeight (optional) true to get the height minus borders and padding
  3543. * @return {Number} The element's height
  3544. */
  3545. getHeight : function(contentHeight){
  3546. var me = this,
  3547. dom = me.dom,
  3548. hidden = Ext.isIE && me.isStyle('display', 'none'),
  3549. h = MATH.max(dom.offsetHeight, hidden ? 0 : dom.clientHeight) || 0;
  3550. h = !contentHeight ? h : h - me.getBorderWidth("tb") - me.getPadding("tb");
  3551. return h < 0 ? 0 : h;
  3552. },
  3553. /**
  3554. * Returns the offset width of the element
  3555. * @param {Boolean} contentWidth (optional) true to get the width minus borders and padding
  3556. * @return {Number} The element's width
  3557. */
  3558. getWidth : function(contentWidth){
  3559. var me = this,
  3560. dom = me.dom,
  3561. hidden = Ext.isIE && me.isStyle('display', 'none'),
  3562. w = MATH.max(dom.offsetWidth, hidden ? 0 : dom.clientWidth) || 0;
  3563. w = !contentWidth ? w : w - me.getBorderWidth("lr") - me.getPadding("lr");
  3564. return w < 0 ? 0 : w;
  3565. },
  3566. /**
  3567. * Set the width of this Element.
  3568. * @param {Mixed} width The new width. This may be one of:<div class="mdetail-params"><ul>
  3569. * <li>A Number specifying the new width in this Element's {@link #defaultUnit}s (by default, pixels).</li>
  3570. * <li>A String used to set the CSS width style. Animation may <b>not</b> be used.
  3571. * </ul></div>
  3572. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  3573. * @return {Ext.Element} this
  3574. */
  3575. setWidth : function(width, animate){
  3576. var me = this;
  3577. width = me.adjustWidth(width);
  3578. !animate || !me.anim ?
  3579. me.dom.style.width = me.addUnits(width) :
  3580. me.anim({width : {to : width}}, me.preanim(arguments, 1));
  3581. return me;
  3582. },
  3583. /**
  3584. * Set the height of this Element.
  3585. * <pre><code>
  3586. // change the height to 200px and animate with default configuration
  3587. Ext.fly('elementId').setHeight(200, true);
  3588. // change the height to 150px and animate with a custom configuration
  3589. Ext.fly('elId').setHeight(150, {
  3590. duration : .5, // animation will have a duration of .5 seconds
  3591. // will change the content to "finished"
  3592. callback: function(){ this.{@link #update}("finished"); }
  3593. });
  3594. * </code></pre>
  3595. * @param {Mixed} height The new height. This may be one of:<div class="mdetail-params"><ul>
  3596. * <li>A Number specifying the new height in this Element's {@link #defaultUnit}s (by default, pixels.)</li>
  3597. * <li>A String used to set the CSS height style. Animation may <b>not</b> be used.</li>
  3598. * </ul></div>
  3599. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  3600. * @return {Ext.Element} this
  3601. */
  3602. setHeight : function(height, animate){
  3603. var me = this;
  3604. height = me.adjustHeight(height);
  3605. !animate || !me.anim ?
  3606. me.dom.style.height = me.addUnits(height) :
  3607. me.anim({height : {to : height}}, me.preanim(arguments, 1));
  3608. return me;
  3609. },
  3610. /**
  3611. * Gets the width of the border(s) for the specified side(s)
  3612. * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
  3613. * passing <tt>'lr'</tt> would get the border <b><u>l</u></b>eft width + the border <b><u>r</u></b>ight width.
  3614. * @return {Number} The width of the sides passed added together
  3615. */
  3616. getBorderWidth : function(side){
  3617. return this.addStyles(side, borders);
  3618. },
  3619. /**
  3620. * Gets the width of the padding(s) for the specified side(s)
  3621. * @param {String} side Can be t, l, r, b or any combination of those to add multiple values. For example,
  3622. * passing <tt>'lr'</tt> would get the padding <b><u>l</u></b>eft + the padding <b><u>r</u></b>ight.
  3623. * @return {Number} The padding of the sides passed added together
  3624. */
  3625. getPadding : function(side){
  3626. return this.addStyles(side, paddings);
  3627. },
  3628. /**
  3629. * Store the current overflow setting and clip overflow on the element - use <tt>{@link #unclip}</tt> to remove
  3630. * @return {Ext.Element} this
  3631. */
  3632. clip : function(){
  3633. var me = this,
  3634. dom = me.dom;
  3635. if(!data(dom, ISCLIPPED)){
  3636. data(dom, ISCLIPPED, true);
  3637. data(dom, ORIGINALCLIP, {
  3638. o: me.getStyle(OVERFLOW),
  3639. x: me.getStyle(OVERFLOWX),
  3640. y: me.getStyle(OVERFLOWY)
  3641. });
  3642. me.setStyle(OVERFLOW, HIDDEN);
  3643. me.setStyle(OVERFLOWX, HIDDEN);
  3644. me.setStyle(OVERFLOWY, HIDDEN);
  3645. }
  3646. return me;
  3647. },
  3648. /**
  3649. * Return clipping (overflow) to original clipping before <tt>{@link #clip}</tt> was called
  3650. * @return {Ext.Element} this
  3651. */
  3652. unclip : function(){
  3653. var me = this,
  3654. dom = me.dom;
  3655. if(data(dom, ISCLIPPED)){
  3656. data(dom, ISCLIPPED, false);
  3657. var o = data(dom, ORIGINALCLIP);
  3658. if(o.o){
  3659. me.setStyle(OVERFLOW, o.o);
  3660. }
  3661. if(o.x){
  3662. me.setStyle(OVERFLOWX, o.x);
  3663. }
  3664. if(o.y){
  3665. me.setStyle(OVERFLOWY, o.y);
  3666. }
  3667. }
  3668. return me;
  3669. },
  3670. // private
  3671. addStyles : function(sides, styles){
  3672. var ttlSize = 0,
  3673. sidesArr = sides.match(wordsRe),
  3674. side,
  3675. size,
  3676. i,
  3677. len = sidesArr.length;
  3678. for (i = 0; i < len; i++) {
  3679. side = sidesArr[i];
  3680. size = side && parseInt(this.getStyle(styles[side]), 10);
  3681. if (size) {
  3682. ttlSize += MATH.abs(size);
  3683. }
  3684. }
  3685. return ttlSize;
  3686. },
  3687. margins : margins
  3688. };
  3689. }()
  3690. );
  3691. /**
  3692. * @class Ext.Element
  3693. */
  3694. (function(){
  3695. var D = Ext.lib.Dom,
  3696. LEFT = "left",
  3697. RIGHT = "right",
  3698. TOP = "top",
  3699. BOTTOM = "bottom",
  3700. POSITION = "position",
  3701. STATIC = "static",
  3702. RELATIVE = "relative",
  3703. AUTO = "auto",
  3704. ZINDEX = "z-index";
  3705. Ext.Element.addMethods({
  3706. /**
  3707. * Gets the current X position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
  3708. * @return {Number} The X position of the element
  3709. */
  3710. getX : function(){
  3711. return D.getX(this.dom);
  3712. },
  3713. /**
  3714. * Gets the current Y position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
  3715. * @return {Number} The Y position of the element
  3716. */
  3717. getY : function(){
  3718. return D.getY(this.dom);
  3719. },
  3720. /**
  3721. * Gets the current position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
  3722. * @return {Array} The XY position of the element
  3723. */
  3724. getXY : function(){
  3725. return D.getXY(this.dom);
  3726. },
  3727. /**
  3728. * Returns the offsets of this element from the passed element. Both element must be part of the DOM tree and not have display:none to have page coordinates.
  3729. * @param {Mixed} element The element to get the offsets from.
  3730. * @return {Array} The XY page offsets (e.g. [100, -200])
  3731. */
  3732. getOffsetsTo : function(el){
  3733. var o = this.getXY(),
  3734. e = Ext.fly(el, '_internal').getXY();
  3735. return [o[0]-e[0],o[1]-e[1]];
  3736. },
  3737. /**
  3738. * Sets the X position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
  3739. * @param {Number} The X position of the element
  3740. * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
  3741. * @return {Ext.Element} this
  3742. */
  3743. setX : function(x, animate){
  3744. return this.setXY([x, this.getY()], this.animTest(arguments, animate, 1));
  3745. },
  3746. /**
  3747. * Sets the Y position of the element based on page coordinates. Element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
  3748. * @param {Number} The Y position of the element
  3749. * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
  3750. * @return {Ext.Element} this
  3751. */
  3752. setY : function(y, animate){
  3753. return this.setXY([this.getX(), y], this.animTest(arguments, animate, 1));
  3754. },
  3755. /**
  3756. * Sets the element's left position directly using CSS style (instead of {@link #setX}).
  3757. * @param {String} left The left CSS property value
  3758. * @return {Ext.Element} this
  3759. */
  3760. setLeft : function(left){
  3761. this.setStyle(LEFT, this.addUnits(left));
  3762. return this;
  3763. },
  3764. /**
  3765. * Sets the element's top position directly using CSS style (instead of {@link #setY}).
  3766. * @param {String} top The top CSS property value
  3767. * @return {Ext.Element} this
  3768. */
  3769. setTop : function(top){
  3770. this.setStyle(TOP, this.addUnits(top));
  3771. return this;
  3772. },
  3773. /**
  3774. * Sets the element's CSS right style.
  3775. * @param {String} right The right CSS property value
  3776. * @return {Ext.Element} this
  3777. */
  3778. setRight : function(right){
  3779. this.setStyle(RIGHT, this.addUnits(right));
  3780. return this;
  3781. },
  3782. /**
  3783. * Sets the element's CSS bottom style.
  3784. * @param {String} bottom The bottom CSS property value
  3785. * @return {Ext.Element} this
  3786. */
  3787. setBottom : function(bottom){
  3788. this.setStyle(BOTTOM, this.addUnits(bottom));
  3789. return this;
  3790. },
  3791. /**
  3792. * Sets the position of the element in page coordinates, regardless of how the element is positioned.
  3793. * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
  3794. * @param {Array} pos Contains X & Y [x, y] values for new position (coordinates are page-based)
  3795. * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
  3796. * @return {Ext.Element} this
  3797. */
  3798. setXY : function(pos, animate){
  3799. var me = this;
  3800. if(!animate || !me.anim){
  3801. D.setXY(me.dom, pos);
  3802. }else{
  3803. me.anim({points: {to: pos}}, me.preanim(arguments, 1), 'motion');
  3804. }
  3805. return me;
  3806. },
  3807. /**
  3808. * Sets the position of the element in page coordinates, regardless of how the element is positioned.
  3809. * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
  3810. * @param {Number} x X value for new position (coordinates are page-based)
  3811. * @param {Number} y Y value for new position (coordinates are page-based)
  3812. * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
  3813. * @return {Ext.Element} this
  3814. */
  3815. setLocation : function(x, y, animate){
  3816. return this.setXY([x, y], this.animTest(arguments, animate, 2));
  3817. },
  3818. /**
  3819. * Sets the position of the element in page coordinates, regardless of how the element is positioned.
  3820. * The element must be part of the DOM tree to have page coordinates (display:none or elements not appended return false).
  3821. * @param {Number} x X value for new position (coordinates are page-based)
  3822. * @param {Number} y Y value for new position (coordinates are page-based)
  3823. * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
  3824. * @return {Ext.Element} this
  3825. */
  3826. moveTo : function(x, y, animate){
  3827. return this.setXY([x, y], this.animTest(arguments, animate, 2));
  3828. },
  3829. /**
  3830. * Gets the left X coordinate
  3831. * @param {Boolean} local True to get the local css position instead of page coordinate
  3832. * @return {Number}
  3833. */
  3834. getLeft : function(local){
  3835. return !local ? this.getX() : parseInt(this.getStyle(LEFT), 10) || 0;
  3836. },
  3837. /**
  3838. * Gets the right X coordinate of the element (element X position + element width)
  3839. * @param {Boolean} local True to get the local css position instead of page coordinate
  3840. * @return {Number}
  3841. */
  3842. getRight : function(local){
  3843. var me = this;
  3844. return !local ? me.getX() + me.getWidth() : (me.getLeft(true) + me.getWidth()) || 0;
  3845. },
  3846. /**
  3847. * Gets the top Y coordinate
  3848. * @param {Boolean} local True to get the local css position instead of page coordinate
  3849. * @return {Number}
  3850. */
  3851. getTop : function(local) {
  3852. return !local ? this.getY() : parseInt(this.getStyle(TOP), 10) || 0;
  3853. },
  3854. /**
  3855. * Gets the bottom Y coordinate of the element (element Y position + element height)
  3856. * @param {Boolean} local True to get the local css position instead of page coordinate
  3857. * @return {Number}
  3858. */
  3859. getBottom : function(local){
  3860. var me = this;
  3861. return !local ? me.getY() + me.getHeight() : (me.getTop(true) + me.getHeight()) || 0;
  3862. },
  3863. /**
  3864. * Initializes positioning on this element. If a desired position is not passed, it will make the
  3865. * the element positioned relative IF it is not already positioned.
  3866. * @param {String} pos (optional) Positioning to use "relative", "absolute" or "fixed"
  3867. * @param {Number} zIndex (optional) The zIndex to apply
  3868. * @param {Number} x (optional) Set the page X position
  3869. * @param {Number} y (optional) Set the page Y position
  3870. */
  3871. position : function(pos, zIndex, x, y){
  3872. var me = this;
  3873. if(!pos && me.isStyle(POSITION, STATIC)){
  3874. me.setStyle(POSITION, RELATIVE);
  3875. } else if(pos) {
  3876. me.setStyle(POSITION, pos);
  3877. }
  3878. if(zIndex){
  3879. me.setStyle(ZINDEX, zIndex);
  3880. }
  3881. if(x || y) me.setXY([x || false, y || false]);
  3882. },
  3883. /**
  3884. * Clear positioning back to the default when the document was loaded
  3885. * @param {String} value (optional) The value to use for the left,right,top,bottom, defaults to '' (empty string). You could use 'auto'.
  3886. * @return {Ext.Element} this
  3887. */
  3888. clearPositioning : function(value){
  3889. value = value || '';
  3890. this.setStyle({
  3891. left : value,
  3892. right : value,
  3893. top : value,
  3894. bottom : value,
  3895. "z-index" : "",
  3896. position : STATIC
  3897. });
  3898. return this;
  3899. },
  3900. /**
  3901. * Gets an object with all CSS positioning properties. Useful along with setPostioning to get
  3902. * snapshot before performing an update and then restoring the element.
  3903. * @return {Object}
  3904. */
  3905. getPositioning : function(){
  3906. var l = this.getStyle(LEFT);
  3907. var t = this.getStyle(TOP);
  3908. return {
  3909. "position" : this.getStyle(POSITION),
  3910. "left" : l,
  3911. "right" : l ? "" : this.getStyle(RIGHT),
  3912. "top" : t,
  3913. "bottom" : t ? "" : this.getStyle(BOTTOM),
  3914. "z-index" : this.getStyle(ZINDEX)
  3915. };
  3916. },
  3917. /**
  3918. * Set positioning with an object returned by getPositioning().
  3919. * @param {Object} posCfg
  3920. * @return {Ext.Element} this
  3921. */
  3922. setPositioning : function(pc){
  3923. var me = this,
  3924. style = me.dom.style;
  3925. me.setStyle(pc);
  3926. if(pc.right == AUTO){
  3927. style.right = "";
  3928. }
  3929. if(pc.bottom == AUTO){
  3930. style.bottom = "";
  3931. }
  3932. return me;
  3933. },
  3934. /**
  3935. * Translates the passed page coordinates into left/top css values for this element
  3936. * @param {Number/Array} x The page x or an array containing [x, y]
  3937. * @param {Number} y (optional) The page y, required if x is not an array
  3938. * @return {Object} An object with left and top properties. e.g. {left: (value), top: (value)}
  3939. */
  3940. translatePoints : function(x, y){
  3941. y = isNaN(x[1]) ? y : x[1];
  3942. x = isNaN(x[0]) ? x : x[0];
  3943. var me = this,
  3944. relative = me.isStyle(POSITION, RELATIVE),
  3945. o = me.getXY(),
  3946. l = parseInt(me.getStyle(LEFT), 10),
  3947. t = parseInt(me.getStyle(TOP), 10);
  3948. l = !isNaN(l) ? l : (relative ? 0 : me.dom.offsetLeft);
  3949. t = !isNaN(t) ? t : (relative ? 0 : me.dom.offsetTop);
  3950. return {left: (x - o[0] + l), top: (y - o[1] + t)};
  3951. },
  3952. animTest : function(args, animate, i) {
  3953. return !!animate && this.preanim ? this.preanim(args, i) : false;
  3954. }
  3955. });
  3956. })();/**
  3957. * @class Ext.Element
  3958. */
  3959. Ext.Element.addMethods({
  3960. /**
  3961. * Returns true if this element is scrollable.
  3962. * @return {Boolean}
  3963. */
  3964. isScrollable : function(){
  3965. var dom = this.dom;
  3966. return dom.scrollHeight > dom.clientHeight || dom.scrollWidth > dom.clientWidth;
  3967. },
  3968. /**
  3969. * 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().
  3970. * @param {String} side Either "left" for scrollLeft values or "top" for scrollTop values.
  3971. * @param {Number} value The new scroll value.
  3972. * @return {Element} this
  3973. */
  3974. scrollTo : function(side, value){
  3975. this.dom["scroll" + (/top/i.test(side) ? "Top" : "Left")] = value;
  3976. return this;
  3977. },
  3978. /**
  3979. * Returns the current scroll position of the element.
  3980. * @return {Object} An object containing the scroll position in the format {left: (scrollLeft), top: (scrollTop)}
  3981. */
  3982. getScroll : function(){
  3983. var d = this.dom,
  3984. doc = document,
  3985. body = doc.body,
  3986. docElement = doc.documentElement,
  3987. l,
  3988. t,
  3989. ret;
  3990. if(d == doc || d == body){
  3991. if(Ext.isIE && Ext.isStrict){
  3992. l = docElement.scrollLeft;
  3993. t = docElement.scrollTop;
  3994. }else{
  3995. l = window.pageXOffset;
  3996. t = window.pageYOffset;
  3997. }
  3998. ret = {left: l || (body ? body.scrollLeft : 0), top: t || (body ? body.scrollTop : 0)};
  3999. }else{
  4000. ret = {left: d.scrollLeft, top: d.scrollTop};
  4001. }
  4002. return ret;
  4003. }
  4004. });/**
  4005. * @class Ext.Element
  4006. */
  4007. /**
  4008. * Visibility mode constant for use with {@link #setVisibilityMode}. Use visibility to hide element
  4009. * @static
  4010. * @type Number
  4011. */
  4012. Ext.Element.VISIBILITY = 1;
  4013. /**
  4014. * Visibility mode constant for use with {@link #setVisibilityMode}. Use display to hide element
  4015. * @static
  4016. * @type Number
  4017. */
  4018. Ext.Element.DISPLAY = 2;
  4019. /**
  4020. * Visibility mode constant for use with {@link #setVisibilityMode}. Use offsets (x and y positioning offscreen)
  4021. * to hide element.
  4022. * @static
  4023. * @type Number
  4024. */
  4025. Ext.Element.OFFSETS = 3;
  4026. Ext.Element.ASCLASS = 4;
  4027. /**
  4028. * Defaults to 'x-hide-nosize'
  4029. * @static
  4030. * @type String
  4031. */
  4032. Ext.Element.visibilityCls = 'x-hide-nosize';
  4033. Ext.Element.addMethods(function(){
  4034. var El = Ext.Element,
  4035. OPACITY = "opacity",
  4036. VISIBILITY = "visibility",
  4037. DISPLAY = "display",
  4038. HIDDEN = "hidden",
  4039. OFFSETS = "offsets",
  4040. ASCLASS = "asclass",
  4041. NONE = "none",
  4042. NOSIZE = 'nosize',
  4043. ORIGINALDISPLAY = 'originalDisplay',
  4044. VISMODE = 'visibilityMode',
  4045. ISVISIBLE = 'isVisible',
  4046. data = El.data,
  4047. getDisplay = function(dom){
  4048. var d = data(dom, ORIGINALDISPLAY);
  4049. if(d === undefined){
  4050. data(dom, ORIGINALDISPLAY, d = '');
  4051. }
  4052. return d;
  4053. },
  4054. getVisMode = function(dom){
  4055. var m = data(dom, VISMODE);
  4056. if(m === undefined){
  4057. data(dom, VISMODE, m = 1);
  4058. }
  4059. return m;
  4060. };
  4061. return {
  4062. /**
  4063. * The element's default display mode (defaults to "")
  4064. * @type String
  4065. */
  4066. originalDisplay : "",
  4067. visibilityMode : 1,
  4068. /**
  4069. * Sets the element's visibility mode. When setVisible() is called it
  4070. * will use this to determine whether to set the visibility or the display property.
  4071. * @param {Number} visMode Ext.Element.VISIBILITY or Ext.Element.DISPLAY
  4072. * @return {Ext.Element} this
  4073. */
  4074. setVisibilityMode : function(visMode){
  4075. data(this.dom, VISMODE, visMode);
  4076. return this;
  4077. },
  4078. /**
  4079. * Perform custom animation on this element.
  4080. * <div><ul class="mdetail-params">
  4081. * <li><u>Animation Properties</u></li>
  4082. *
  4083. * <p>The Animation Control Object enables gradual transitions for any member of an
  4084. * element's style object that takes a numeric value including but not limited to
  4085. * these properties:</p><div><ul class="mdetail-params">
  4086. * <li><tt>bottom, top, left, right</tt></li>
  4087. * <li><tt>height, width</tt></li>
  4088. * <li><tt>margin, padding</tt></li>
  4089. * <li><tt>borderWidth</tt></li>
  4090. * <li><tt>opacity</tt></li>
  4091. * <li><tt>fontSize</tt></li>
  4092. * <li><tt>lineHeight</tt></li>
  4093. * </ul></div>
  4094. *
  4095. *
  4096. * <li><u>Animation Property Attributes</u></li>
  4097. *
  4098. * <p>Each Animation Property is a config object with optional properties:</p>
  4099. * <div><ul class="mdetail-params">
  4100. * <li><tt>by</tt>* : relative change - start at current value, change by this value</li>
  4101. * <li><tt>from</tt> : ignore current value, start from this value</li>
  4102. * <li><tt>to</tt>* : start at current value, go to this value</li>
  4103. * <li><tt>unit</tt> : any allowable unit specification</li>
  4104. * <p>* do not specify both <tt>to</tt> and <tt>by</tt> for an animation property</p>
  4105. * </ul></div>
  4106. *
  4107. * <li><u>Animation Types</u></li>
  4108. *
  4109. * <p>The supported animation types:</p><div><ul class="mdetail-params">
  4110. * <li><tt>'run'</tt> : Default
  4111. * <pre><code>
  4112. var el = Ext.get('complexEl');
  4113. el.animate(
  4114. // animation control object
  4115. {
  4116. borderWidth: {to: 3, from: 0},
  4117. opacity: {to: .3, from: 1},
  4118. height: {to: 50, from: el.getHeight()},
  4119. width: {to: 300, from: el.getWidth()},
  4120. top : {by: - 100, unit: 'px'},
  4121. },
  4122. 0.35, // animation duration
  4123. null, // callback
  4124. 'easeOut', // easing method
  4125. 'run' // animation type ('run','color','motion','scroll')
  4126. );
  4127. * </code></pre>
  4128. * </li>
  4129. * <li><tt>'color'</tt>
  4130. * <p>Animates transition of background, text, or border colors.</p>
  4131. * <pre><code>
  4132. el.animate(
  4133. // animation control object
  4134. {
  4135. color: { to: '#06e' },
  4136. backgroundColor: { to: '#e06' }
  4137. },
  4138. 0.35, // animation duration
  4139. null, // callback
  4140. 'easeOut', // easing method
  4141. 'color' // animation type ('run','color','motion','scroll')
  4142. );
  4143. * </code></pre>
  4144. * </li>
  4145. *
  4146. * <li><tt>'motion'</tt>
  4147. * <p>Animates the motion of an element to/from specific points using optional bezier
  4148. * way points during transit.</p>
  4149. * <pre><code>
  4150. el.animate(
  4151. // animation control object
  4152. {
  4153. borderWidth: {to: 3, from: 0},
  4154. opacity: {to: .3, from: 1},
  4155. height: {to: 50, from: el.getHeight()},
  4156. width: {to: 300, from: el.getWidth()},
  4157. top : {by: - 100, unit: 'px'},
  4158. points: {
  4159. to: [50, 100], // go to this point
  4160. control: [ // optional bezier way points
  4161. [ 600, 800],
  4162. [-100, 200]
  4163. ]
  4164. }
  4165. },
  4166. 3000, // animation duration (milliseconds!)
  4167. null, // callback
  4168. 'easeOut', // easing method
  4169. 'motion' // animation type ('run','color','motion','scroll')
  4170. );
  4171. * </code></pre>
  4172. * </li>
  4173. * <li><tt>'scroll'</tt>
  4174. * <p>Animate horizontal or vertical scrolling of an overflowing page element.</p>
  4175. * <pre><code>
  4176. el.animate(
  4177. // animation control object
  4178. {
  4179. scroll: {to: [400, 300]}
  4180. },
  4181. 0.35, // animation duration
  4182. null, // callback
  4183. 'easeOut', // easing method
  4184. 'scroll' // animation type ('run','color','motion','scroll')
  4185. );
  4186. * </code></pre>
  4187. * </li>
  4188. * </ul></div>
  4189. *
  4190. * </ul></div>
  4191. *
  4192. * @param {Object} args The animation control args
  4193. * @param {Float} duration (optional) How long the animation lasts in seconds (defaults to <tt>.35</tt>)
  4194. * @param {Function} onComplete (optional) Function to call when animation completes
  4195. * @param {String} easing (optional) {@link Ext.Fx#easing} method to use (defaults to <tt>'easeOut'</tt>)
  4196. * @param {String} animType (optional) <tt>'run'</tt> is the default. Can also be <tt>'color'</tt>,
  4197. * <tt>'motion'</tt>, or <tt>'scroll'</tt>
  4198. * @return {Ext.Element} this
  4199. */
  4200. animate : function(args, duration, onComplete, easing, animType){
  4201. this.anim(args, {duration: duration, callback: onComplete, easing: easing}, animType);
  4202. return this;
  4203. },
  4204. /*
  4205. * @private Internal animation call
  4206. */
  4207. anim : function(args, opt, animType, defaultDur, defaultEase, cb){
  4208. animType = animType || 'run';
  4209. opt = opt || {};
  4210. var me = this,
  4211. anim = Ext.lib.Anim[animType](
  4212. me.dom,
  4213. args,
  4214. (opt.duration || defaultDur) || .35,
  4215. (opt.easing || defaultEase) || 'easeOut',
  4216. function(){
  4217. if(cb) cb.call(me);
  4218. if(opt.callback) opt.callback.call(opt.scope || me, me, opt);
  4219. },
  4220. me
  4221. );
  4222. opt.anim = anim;
  4223. return anim;
  4224. },
  4225. // private legacy anim prep
  4226. preanim : function(a, i){
  4227. return !a[i] ? false : (typeof a[i] == 'object' ? a[i]: {duration: a[i+1], callback: a[i+2], easing: a[i+3]});
  4228. },
  4229. /**
  4230. * Checks whether the element is currently visible using both visibility and display properties.
  4231. * @return {Boolean} True if the element is currently visible, else false
  4232. */
  4233. isVisible : function() {
  4234. var me = this,
  4235. dom = me.dom,
  4236. visible = data(dom, ISVISIBLE);
  4237. if(typeof visible == 'boolean'){ //return the cached value if registered
  4238. return visible;
  4239. }
  4240. //Determine the current state based on display states
  4241. visible = !me.isStyle(VISIBILITY, HIDDEN) &&
  4242. !me.isStyle(DISPLAY, NONE) &&
  4243. !((getVisMode(dom) == El.ASCLASS) && me.hasClass(me.visibilityCls || El.visibilityCls));
  4244. data(dom, ISVISIBLE, visible);
  4245. return visible;
  4246. },
  4247. /**
  4248. * Sets the visibility of the element (see details). If the visibilityMode is set to Element.DISPLAY, it will use
  4249. * the display property to hide the element, otherwise it uses visibility. The default is to hide and show using the visibility property.
  4250. * @param {Boolean} visible Whether the element is visible
  4251. * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
  4252. * @return {Ext.Element} this
  4253. */
  4254. setVisible : function(visible, animate){
  4255. var me = this, isDisplay, isVisibility, isOffsets, isNosize,
  4256. dom = me.dom,
  4257. visMode = getVisMode(dom);
  4258. // hideMode string override
  4259. if (typeof animate == 'string'){
  4260. switch (animate) {
  4261. case DISPLAY:
  4262. visMode = El.DISPLAY;
  4263. break;
  4264. case VISIBILITY:
  4265. visMode = El.VISIBILITY;
  4266. break;
  4267. case OFFSETS:
  4268. visMode = El.OFFSETS;
  4269. break;
  4270. case NOSIZE:
  4271. case ASCLASS:
  4272. visMode = El.ASCLASS;
  4273. break;
  4274. }
  4275. me.setVisibilityMode(visMode);
  4276. animate = false;
  4277. }
  4278. if (!animate || !me.anim) {
  4279. if(visMode == El.ASCLASS ){
  4280. me[visible?'removeClass':'addClass'](me.visibilityCls || El.visibilityCls);
  4281. } else if (visMode == El.DISPLAY){
  4282. return me.setDisplayed(visible);
  4283. } else if (visMode == El.OFFSETS){
  4284. if (!visible){
  4285. me.hideModeStyles = {
  4286. position: me.getStyle('position'),
  4287. top: me.getStyle('top'),
  4288. left: me.getStyle('left')
  4289. };
  4290. me.applyStyles({position: 'absolute', top: '-10000px', left: '-10000px'});
  4291. } else {
  4292. me.applyStyles(me.hideModeStyles || {position: '', top: '', left: ''});
  4293. delete me.hideModeStyles;
  4294. }
  4295. }else{
  4296. me.fixDisplay();
  4297. dom.style.visibility = visible ? "visible" : HIDDEN;
  4298. }
  4299. }else{
  4300. // closure for composites
  4301. if(visible){
  4302. me.setOpacity(.01);
  4303. me.setVisible(true);
  4304. }
  4305. me.anim({opacity: { to: (visible?1:0) }},
  4306. me.preanim(arguments, 1),
  4307. null,
  4308. .35,
  4309. 'easeIn',
  4310. function(){
  4311. visible || me.setVisible(false).setOpacity(1);
  4312. });
  4313. }
  4314. data(dom, ISVISIBLE, visible); //set logical visibility state
  4315. return me;
  4316. },
  4317. /**
  4318. * @private
  4319. * Determine if the Element has a relevant height and width available based
  4320. * upon current logical visibility state
  4321. */
  4322. hasMetrics : function(){
  4323. var dom = this.dom;
  4324. return this.isVisible() || (getVisMode(dom) == El.VISIBILITY);
  4325. },
  4326. /**
  4327. * Toggles the element's visibility or display, depending on visibility mode.
  4328. * @param {Boolean/Object} animate (optional) True for the default animation, or a standard Element animation config object
  4329. * @return {Ext.Element} this
  4330. */
  4331. toggle : function(animate){
  4332. var me = this;
  4333. me.setVisible(!me.isVisible(), me.preanim(arguments, 0));
  4334. return me;
  4335. },
  4336. /**
  4337. * Sets the CSS display property. Uses originalDisplay if the specified value is a boolean true.
  4338. * @param {Mixed} value Boolean value to display the element using its default display, or a string to set the display directly.
  4339. * @return {Ext.Element} this
  4340. */
  4341. setDisplayed : function(value) {
  4342. if(typeof value == "boolean"){
  4343. value = value ? getDisplay(this.dom) : NONE;
  4344. }
  4345. this.setStyle(DISPLAY, value);
  4346. return this;
  4347. },
  4348. // private
  4349. fixDisplay : function(){
  4350. var me = this;
  4351. if(me.isStyle(DISPLAY, NONE)){
  4352. me.setStyle(VISIBILITY, HIDDEN);
  4353. me.setStyle(DISPLAY, getDisplay(this.dom)); // first try reverting to default
  4354. if(me.isStyle(DISPLAY, NONE)){ // if that fails, default to block
  4355. me.setStyle(DISPLAY, "block");
  4356. }
  4357. }
  4358. },
  4359. /**
  4360. * Hide this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
  4361. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  4362. * @return {Ext.Element} this
  4363. */
  4364. hide : function(animate){
  4365. // hideMode override
  4366. if (typeof animate == 'string'){
  4367. this.setVisible(false, animate);
  4368. return this;
  4369. }
  4370. this.setVisible(false, this.preanim(arguments, 0));
  4371. return this;
  4372. },
  4373. /**
  4374. * Show this element - Uses display mode to determine whether to use "display" or "visibility". See {@link #setVisible}.
  4375. * @param {Boolean/Object} animate (optional) true for the default animation or a standard Element animation config object
  4376. * @return {Ext.Element} this
  4377. */
  4378. show : function(animate){
  4379. // hideMode override
  4380. if (typeof animate == 'string'){
  4381. this.setVisible(true, animate);
  4382. return this;
  4383. }
  4384. this.setVisible(true, this.preanim(arguments, 0));
  4385. return this;
  4386. }
  4387. };
  4388. }());(function(){
  4389. // contants
  4390. var NULL = null,
  4391. UNDEFINED = undefined,
  4392. TRUE = true,
  4393. FALSE = false,
  4394. SETX = "setX",
  4395. SETY = "setY",
  4396. SETXY = "setXY",
  4397. LEFT = "left",
  4398. BOTTOM = "bottom",
  4399. TOP = "top",
  4400. RIGHT = "right",
  4401. HEIGHT = "height",
  4402. WIDTH = "width",
  4403. POINTS = "points",
  4404. HIDDEN = "hidden",
  4405. ABSOLUTE = "absolute",
  4406. VISIBLE = "visible",
  4407. MOTION = "motion",
  4408. POSITION = "position",
  4409. EASEOUT = "easeOut",
  4410. /*
  4411. * Use a light flyweight here since we are using so many callbacks and are always assured a DOM element
  4412. */
  4413. flyEl = new Ext.Element.Flyweight(),
  4414. queues = {},
  4415. getObject = function(o){
  4416. return o || {};
  4417. },
  4418. fly = function(dom){
  4419. flyEl.dom = dom;
  4420. flyEl.id = Ext.id(dom);
  4421. return flyEl;
  4422. },
  4423. /*
  4424. * Queueing now stored outside of the element due to closure issues
  4425. */
  4426. getQueue = function(id){
  4427. if(!queues[id]){
  4428. queues[id] = [];
  4429. }
  4430. return queues[id];
  4431. },
  4432. setQueue = function(id, value){
  4433. queues[id] = value;
  4434. };
  4435. //Notifies Element that fx methods are available
  4436. Ext.enableFx = TRUE;
  4437. /**
  4438. * @class Ext.Fx
  4439. * <p>A class to provide basic animation and visual effects support. <b>Note:</b> This class is automatically applied
  4440. * to the {@link Ext.Element} interface when included, so all effects calls should be performed via {@link Ext.Element}.
  4441. * Conversely, since the effects are not actually defined in {@link Ext.Element}, Ext.Fx <b>must</b> be
  4442. * {@link Ext#enableFx included} in order for the Element effects to work.</p><br/>
  4443. *
  4444. * <p><b><u>Method Chaining</u></b></p>
  4445. * <p>It is important to note that although the Fx methods and many non-Fx Element methods support "method chaining" in that
  4446. * they return the Element object itself as the method return value, it is not always possible to mix the two in a single
  4447. * method chain. The Fx methods use an internal effects queue so that each effect can be properly timed and sequenced.
  4448. * Non-Fx methods, on the other hand, have no such internal queueing and will always execute immediately. For this reason,
  4449. * while it may be possible to mix certain Fx and non-Fx method calls in a single chain, it may not always provide the
  4450. * expected results and should be done with care. Also see <tt>{@link #callback}</tt>.</p><br/>
  4451. *
  4452. * <p><b><u>Anchor Options for Motion Effects</u></b></p>
  4453. * <p>Motion effects support 8-way anchoring, meaning that you can choose one of 8 different anchor points on the Element
  4454. * that will serve as either the start or end point of the animation. Following are all of the supported anchor positions:</p>
  4455. <pre>
  4456. Value Description
  4457. ----- -----------------------------
  4458. tl The top left corner
  4459. t The center of the top edge
  4460. tr The top right corner
  4461. l The center of the left edge
  4462. r The center of the right edge
  4463. bl The bottom left corner
  4464. b The center of the bottom edge
  4465. br The bottom right corner
  4466. </pre>
  4467. * <b>Note</b>: some Fx methods accept specific custom config parameters. The options shown in the Config Options
  4468. * section below are common options that can be passed to any Fx method unless otherwise noted.</b>
  4469. *
  4470. * @cfg {Function} callback A function called when the effect is finished. Note that effects are queued internally by the
  4471. * Fx class, so a callback is not required to specify another effect -- effects can simply be chained together
  4472. * and called in sequence (see note for <b><u>Method Chaining</u></b> above), for example:<pre><code>
  4473. * el.slideIn().highlight();
  4474. * </code></pre>
  4475. * The callback is intended for any additional code that should run once a particular effect has completed. The Element
  4476. * being operated upon is passed as the first parameter.
  4477. *
  4478. * @cfg {Object} scope The scope (<code>this</code> reference) in which the <tt>{@link #callback}</tt> function is executed. Defaults to the browser window.
  4479. *
  4480. * @cfg {String} easing A valid Ext.lib.Easing value for the effect:</p><div class="mdetail-params"><ul>
  4481. * <li><b><tt>backBoth</tt></b></li>
  4482. * <li><b><tt>backIn</tt></b></li>
  4483. * <li><b><tt>backOut</tt></b></li>
  4484. * <li><b><tt>bounceBoth</tt></b></li>
  4485. * <li><b><tt>bounceIn</tt></b></li>
  4486. * <li><b><tt>bounceOut</tt></b></li>
  4487. * <li><b><tt>easeBoth</tt></b></li>
  4488. * <li><b><tt>easeBothStrong</tt></b></li>
  4489. * <li><b><tt>easeIn</tt></b></li>
  4490. * <li><b><tt>easeInStrong</tt></b></li>
  4491. * <li><b><tt>easeNone</tt></b></li>
  4492. * <li><b><tt>easeOut</tt></b></li>
  4493. * <li><b><tt>easeOutStrong</tt></b></li>
  4494. * <li><b><tt>elasticBoth</tt></b></li>
  4495. * <li><b><tt>elasticIn</tt></b></li>
  4496. * <li><b><tt>elasticOut</tt></b></li>
  4497. * </ul></div>
  4498. *
  4499. * @cfg {String} afterCls A css class to apply after the effect
  4500. * @cfg {Number} duration The length of time (in seconds) that the effect should last
  4501. *
  4502. * @cfg {Number} endOpacity Only applicable for {@link #fadeIn} or {@link #fadeOut}, a number between
  4503. * <tt>0</tt> and <tt>1</tt> inclusive to configure the ending opacity value.
  4504. *
  4505. * @cfg {Boolean} remove Whether the Element should be removed from the DOM and destroyed after the effect finishes
  4506. * @cfg {Boolean} useDisplay Whether to use the <i>display</i> CSS property instead of <i>visibility</i> when hiding Elements (only applies to
  4507. * effects that end with the element being visually hidden, ignored otherwise)
  4508. * @cfg {String/Object/Function} afterStyle A style specification string, e.g. <tt>"width:100px"</tt>, or an object
  4509. * in the form <tt>{width:"100px"}</tt>, or a function which returns such a specification that will be applied to the
  4510. * Element after the effect finishes.
  4511. * @cfg {Boolean} block Whether the effect should block other effects from queueing while it runs
  4512. * @cfg {Boolean} concurrent Whether to allow subsequently-queued effects to run at the same time as the current effect, or to ensure that they run in sequence
  4513. * @cfg {Boolean} stopFx Whether preceding effects should be stopped and removed before running current effect (only applies to non blocking effects)
  4514. */
  4515. Ext.Fx = {
  4516. // private - calls the function taking arguments from the argHash based on the key. Returns the return value of the function.
  4517. // this is useful for replacing switch statements (for example).
  4518. switchStatements : function(key, fn, argHash){
  4519. return fn.apply(this, argHash[key]);
  4520. },
  4521. /**
  4522. * Slides the element into view. An anchor point can be optionally passed to set the point of
  4523. * origin for the slide effect. This function automatically handles wrapping the element with
  4524. * a fixed-size container if needed. See the Fx class overview for valid anchor point options.
  4525. * Usage:
  4526. *<pre><code>
  4527. // default: slide the element in from the top
  4528. el.slideIn();
  4529. // custom: slide the element in from the right with a 2-second duration
  4530. el.slideIn('r', { duration: 2 });
  4531. // common config options shown with default values
  4532. el.slideIn('t', {
  4533. easing: 'easeOut',
  4534. duration: .5
  4535. });
  4536. </code></pre>
  4537. * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't')
  4538. * @param {Object} options (optional) Object literal with any of the Fx config options
  4539. * @return {Ext.Element} The Element
  4540. */
  4541. slideIn : function(anchor, o){
  4542. o = getObject(o);
  4543. var me = this,
  4544. dom = me.dom,
  4545. st = dom.style,
  4546. xy,
  4547. r,
  4548. b,
  4549. wrap,
  4550. after,
  4551. st,
  4552. args,
  4553. pt,
  4554. bw,
  4555. bh;
  4556. anchor = anchor || "t";
  4557. me.queueFx(o, function(){
  4558. xy = fly(dom).getXY();
  4559. // fix display to visibility
  4560. fly(dom).fixDisplay();
  4561. // restore values after effect
  4562. r = fly(dom).getFxRestore();
  4563. b = {x: xy[0], y: xy[1], 0: xy[0], 1: xy[1], width: dom.offsetWidth, height: dom.offsetHeight};
  4564. b.right = b.x + b.width;
  4565. b.bottom = b.y + b.height;
  4566. // fixed size for slide
  4567. fly(dom).setWidth(b.width).setHeight(b.height);
  4568. // wrap if needed
  4569. wrap = fly(dom).fxWrap(r.pos, o, HIDDEN);
  4570. st.visibility = VISIBLE;
  4571. st.position = ABSOLUTE;
  4572. // clear out temp styles after slide and unwrap
  4573. function after(){
  4574. fly(dom).fxUnwrap(wrap, r.pos, o);
  4575. st.width = r.width;
  4576. st.height = r.height;
  4577. fly(dom).afterFx(o);
  4578. }
  4579. // time to calculate the positions
  4580. pt = {to: [b.x, b.y]};
  4581. bw = {to: b.width};
  4582. bh = {to: b.height};
  4583. function argCalc(wrap, style, ww, wh, sXY, sXYval, s1, s2, w, h, p){
  4584. var ret = {};
  4585. fly(wrap).setWidth(ww).setHeight(wh);
  4586. if(fly(wrap)[sXY]){
  4587. fly(wrap)[sXY](sXYval);
  4588. }
  4589. style[s1] = style[s2] = "0";
  4590. if(w){
  4591. ret.width = w;
  4592. }
  4593. if(h){
  4594. ret.height = h;
  4595. }
  4596. if(p){
  4597. ret.points = p;
  4598. }
  4599. return ret;
  4600. };
  4601. args = fly(dom).switchStatements(anchor.toLowerCase(), argCalc, {
  4602. t : [wrap, st, b.width, 0, NULL, NULL, LEFT, BOTTOM, NULL, bh, NULL],
  4603. l : [wrap, st, 0, b.height, NULL, NULL, RIGHT, TOP, bw, NULL, NULL],
  4604. r : [wrap, st, b.width, b.height, SETX, b.right, LEFT, TOP, NULL, NULL, pt],
  4605. b : [wrap, st, b.width, b.height, SETY, b.bottom, LEFT, TOP, NULL, bh, pt],
  4606. tl : [wrap, st, 0, 0, NULL, NULL, RIGHT, BOTTOM, bw, bh, pt],
  4607. bl : [wrap, st, 0, 0, SETY, b.y + b.height, RIGHT, TOP, bw, bh, pt],
  4608. br : [wrap, st, 0, 0, SETXY, [b.right, b.bottom], LEFT, TOP, bw, bh, pt],
  4609. tr : [wrap, st, 0, 0, SETX, b.x + b.width, LEFT, BOTTOM, bw, bh, pt]
  4610. });
  4611. st.visibility = VISIBLE;
  4612. fly(wrap).show();
  4613. arguments.callee.anim = fly(wrap).fxanim(args,
  4614. o,
  4615. MOTION,
  4616. .5,
  4617. EASEOUT,
  4618. after);
  4619. });
  4620. return me;
  4621. },
  4622. /**
  4623. * Slides the element out of view. An anchor point can be optionally passed to set the end point
  4624. * for the slide effect. When the effect is completed, the element will be hidden (visibility =
  4625. * 'hidden') but block elements will still take up space in the document. The element must be removed
  4626. * from the DOM using the 'remove' config option if desired. This function automatically handles
  4627. * wrapping the element with a fixed-size container if needed. See the Fx class overview for valid anchor point options.
  4628. * Usage:
  4629. *<pre><code>
  4630. // default: slide the element out to the top
  4631. el.slideOut();
  4632. // custom: slide the element out to the right with a 2-second duration
  4633. el.slideOut('r', { duration: 2 });
  4634. // common config options shown with default values
  4635. el.slideOut('t', {
  4636. easing: 'easeOut',
  4637. duration: .5,
  4638. remove: false,
  4639. useDisplay: false
  4640. });
  4641. </code></pre>
  4642. * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to top: 't')
  4643. * @param {Object} options (optional) Object literal with any of the Fx config options
  4644. * @return {Ext.Element} The Element
  4645. */
  4646. slideOut : function(anchor, o){
  4647. o = getObject(o);
  4648. var me = this,
  4649. dom = me.dom,
  4650. st = dom.style,
  4651. xy = me.getXY(),
  4652. wrap,
  4653. r,
  4654. b,
  4655. a,
  4656. zero = {to: 0};
  4657. anchor = anchor || "t";
  4658. me.queueFx(o, function(){
  4659. // restore values after effect
  4660. r = fly(dom).getFxRestore();
  4661. b = {x: xy[0], y: xy[1], 0: xy[0], 1: xy[1], width: dom.offsetWidth, height: dom.offsetHeight};
  4662. b.right = b.x + b.width;
  4663. b.bottom = b.y + b.height;
  4664. // fixed size for slide
  4665. fly(dom).setWidth(b.width).setHeight(b.height);
  4666. // wrap if needed
  4667. wrap = fly(dom).fxWrap(r.pos, o, VISIBLE);
  4668. st.visibility = VISIBLE;
  4669. st.position = ABSOLUTE;
  4670. fly(wrap).setWidth(b.width).setHeight(b.height);
  4671. function after(){
  4672. o.useDisplay ? fly(dom).setDisplayed(FALSE) : fly(dom).hide();
  4673. fly(dom).fxUnwrap(wrap, r.pos, o);
  4674. st.width = r.width;
  4675. st.height = r.height;
  4676. fly(dom).afterFx(o);
  4677. }
  4678. function argCalc(style, s1, s2, p1, v1, p2, v2, p3, v3){
  4679. var ret = {};
  4680. style[s1] = style[s2] = "0";
  4681. ret[p1] = v1;
  4682. if(p2){
  4683. ret[p2] = v2;
  4684. }
  4685. if(p3){
  4686. ret[p3] = v3;
  4687. }
  4688. return ret;
  4689. };
  4690. a = fly(dom).switchStatements(anchor.toLowerCase(), argCalc, {
  4691. t : [st, LEFT, BOTTOM, HEIGHT, zero],
  4692. l : [st, RIGHT, TOP, WIDTH, zero],
  4693. r : [st, LEFT, TOP, WIDTH, zero, POINTS, {to : [b.right, b.y]}],
  4694. b : [st, LEFT, TOP, HEIGHT, zero, POINTS, {to : [b.x, b.bottom]}],
  4695. tl : [st, RIGHT, BOTTOM, WIDTH, zero, HEIGHT, zero],
  4696. bl : [st, RIGHT, TOP, WIDTH, zero, HEIGHT, zero, POINTS, {to : [b.x, b.bottom]}],
  4697. br : [st, LEFT, TOP, WIDTH, zero, HEIGHT, zero, POINTS, {to : [b.x + b.width, b.bottom]}],
  4698. tr : [st, LEFT, BOTTOM, WIDTH, zero, HEIGHT, zero, POINTS, {to : [b.right, b.y]}]
  4699. });
  4700. arguments.callee.anim = fly(wrap).fxanim(a,
  4701. o,
  4702. MOTION,
  4703. .5,
  4704. EASEOUT,
  4705. after);
  4706. });
  4707. return me;
  4708. },
  4709. /**
  4710. * Fades the element out while slowly expanding it in all directions. When the effect is completed, the
  4711. * element will be hidden (visibility = 'hidden') but block elements will still take up space in the document.
  4712. * The element must be removed from the DOM using the 'remove' config option if desired.
  4713. * Usage:
  4714. *<pre><code>
  4715. // default
  4716. el.puff();
  4717. // common config options shown with default values
  4718. el.puff({
  4719. easing: 'easeOut',
  4720. duration: .5,
  4721. remove: false,
  4722. useDisplay: false
  4723. });
  4724. </code></pre>
  4725. * @param {Object} options (optional) Object literal with any of the Fx config options
  4726. * @return {Ext.Element} The Element
  4727. */
  4728. puff : function(o){
  4729. o = getObject(o);
  4730. var me = this,
  4731. dom = me.dom,
  4732. st = dom.style,
  4733. width,
  4734. height,
  4735. r;
  4736. me.queueFx(o, function(){
  4737. width = fly(dom).getWidth();
  4738. height = fly(dom).getHeight();
  4739. fly(dom).clearOpacity();
  4740. fly(dom).show();
  4741. // restore values after effect
  4742. r = fly(dom).getFxRestore();
  4743. function after(){
  4744. o.useDisplay ? fly(dom).setDisplayed(FALSE) : fly(dom).hide();
  4745. fly(dom).clearOpacity();
  4746. fly(dom).setPositioning(r.pos);
  4747. st.width = r.width;
  4748. st.height = r.height;
  4749. st.fontSize = '';
  4750. fly(dom).afterFx(o);
  4751. }
  4752. arguments.callee.anim = fly(dom).fxanim({
  4753. width : {to : fly(dom).adjustWidth(width * 2)},
  4754. height : {to : fly(dom).adjustHeight(height * 2)},
  4755. points : {by : [-width * .5, -height * .5]},
  4756. opacity : {to : 0},
  4757. fontSize: {to : 200, unit: "%"}
  4758. },
  4759. o,
  4760. MOTION,
  4761. .5,
  4762. EASEOUT,
  4763. after);
  4764. });
  4765. return me;
  4766. },
  4767. /**
  4768. * Blinks the element as if it was clicked and then collapses on its center (similar to switching off a television).
  4769. * When the effect is completed, the element will be hidden (visibility = 'hidden') but block elements will still
  4770. * take up space in the document. The element must be removed from the DOM using the 'remove' config option if desired.
  4771. * Usage:
  4772. *<pre><code>
  4773. // default
  4774. el.switchOff();
  4775. // all config options shown with default values
  4776. el.switchOff({
  4777. easing: 'easeIn',
  4778. duration: .3,
  4779. remove: false,
  4780. useDisplay: false
  4781. });
  4782. </code></pre>
  4783. * @param {Object} options (optional) Object literal with any of the Fx config options
  4784. * @return {Ext.Element} The Element
  4785. */
  4786. switchOff : function(o){
  4787. o = getObject(o);
  4788. var me = this,
  4789. dom = me.dom,
  4790. st = dom.style,
  4791. r;
  4792. me.queueFx(o, function(){
  4793. fly(dom).clearOpacity();
  4794. fly(dom).clip();
  4795. // restore values after effect
  4796. r = fly(dom).getFxRestore();
  4797. function after(){
  4798. o.useDisplay ? fly(dom).setDisplayed(FALSE) : fly(dom).hide();
  4799. fly(dom).clearOpacity();
  4800. fly(dom).setPositioning(r.pos);
  4801. st.width = r.width;
  4802. st.height = r.height;
  4803. fly(dom).afterFx(o);
  4804. };
  4805. fly(dom).fxanim({opacity : {to : 0.3}},
  4806. NULL,
  4807. NULL,
  4808. .1,
  4809. NULL,
  4810. function(){
  4811. fly(dom).clearOpacity();
  4812. (function(){
  4813. fly(dom).fxanim({
  4814. height : {to : 1},
  4815. points : {by : [0, fly(dom).getHeight() * .5]}
  4816. },
  4817. o,
  4818. MOTION,
  4819. 0.3,
  4820. 'easeIn',
  4821. after);
  4822. }).defer(100);
  4823. });
  4824. });
  4825. return me;
  4826. },
  4827. /**
  4828. * Highlights the Element by setting a color (applies to the background-color by default, but can be
  4829. * changed using the "attr" config option) and then fading back to the original color. If no original
  4830. * color is available, you should provide the "endColor" config option which will be cleared after the animation.
  4831. * Usage:
  4832. <pre><code>
  4833. // default: highlight background to yellow
  4834. el.highlight();
  4835. // custom: highlight foreground text to blue for 2 seconds
  4836. el.highlight("0000ff", { attr: 'color', duration: 2 });
  4837. // common config options shown with default values
  4838. el.highlight("ffff9c", {
  4839. attr: "background-color", //can be any valid CSS property (attribute) that supports a color value
  4840. endColor: (current color) or "ffffff",
  4841. easing: 'easeIn',
  4842. duration: 1
  4843. });
  4844. </code></pre>
  4845. * @param {String} color (optional) The highlight color. Should be a 6 char hex color without the leading # (defaults to yellow: 'ffff9c')
  4846. * @param {Object} options (optional) Object literal with any of the Fx config options
  4847. * @return {Ext.Element} The Element
  4848. */
  4849. highlight : function(color, o){
  4850. o = getObject(o);
  4851. var me = this,
  4852. dom = me.dom,
  4853. attr = o.attr || "backgroundColor",
  4854. a = {},
  4855. restore;
  4856. me.queueFx(o, function(){
  4857. fly(dom).clearOpacity();
  4858. fly(dom).show();
  4859. function after(){
  4860. dom.style[attr] = restore;
  4861. fly(dom).afterFx(o);
  4862. }
  4863. restore = dom.style[attr];
  4864. a[attr] = {from: color || "ffff9c", to: o.endColor || fly(dom).getColor(attr) || "ffffff"};
  4865. arguments.callee.anim = fly(dom).fxanim(a,
  4866. o,
  4867. 'color',
  4868. 1,
  4869. 'easeIn',
  4870. after);
  4871. });
  4872. return me;
  4873. },
  4874. /**
  4875. * Shows a ripple of exploding, attenuating borders to draw attention to an Element.
  4876. * Usage:
  4877. <pre><code>
  4878. // default: a single light blue ripple
  4879. el.frame();
  4880. // custom: 3 red ripples lasting 3 seconds total
  4881. el.frame("ff0000", 3, { duration: 3 });
  4882. // common config options shown with default values
  4883. el.frame("C3DAF9", 1, {
  4884. duration: 1 //duration of each individual ripple.
  4885. // Note: Easing is not configurable and will be ignored if included
  4886. });
  4887. </code></pre>
  4888. * @param {String} color (optional) The color of the border. Should be a 6 char hex color without the leading # (defaults to light blue: 'C3DAF9').
  4889. * @param {Number} count (optional) The number of ripples to display (defaults to 1)
  4890. * @param {Object} options (optional) Object literal with any of the Fx config options
  4891. * @return {Ext.Element} The Element
  4892. */
  4893. frame : function(color, count, o){
  4894. o = getObject(o);
  4895. var me = this,
  4896. dom = me.dom,
  4897. proxy,
  4898. active;
  4899. me.queueFx(o, function(){
  4900. color = color || '#C3DAF9';
  4901. if(color.length == 6){
  4902. color = '#' + color;
  4903. }
  4904. count = count || 1;
  4905. fly(dom).show();
  4906. var xy = fly(dom).getXY(),
  4907. b = {x: xy[0], y: xy[1], 0: xy[0], 1: xy[1], width: dom.offsetWidth, height: dom.offsetHeight},
  4908. queue = function(){
  4909. proxy = fly(document.body || document.documentElement).createChild({
  4910. style:{
  4911. position : ABSOLUTE,
  4912. 'z-index': 35000, // yee haw
  4913. border : '0px solid ' + color
  4914. }
  4915. });
  4916. return proxy.queueFx({}, animFn);
  4917. };
  4918. arguments.callee.anim = {
  4919. isAnimated: true,
  4920. stop: function() {
  4921. count = 0;
  4922. proxy.stopFx();
  4923. }
  4924. };
  4925. function animFn(){
  4926. var scale = Ext.isBorderBox ? 2 : 1;
  4927. active = proxy.anim({
  4928. top : {from : b.y, to : b.y - 20},
  4929. left : {from : b.x, to : b.x - 20},
  4930. borderWidth : {from : 0, to : 10},
  4931. opacity : {from : 1, to : 0},
  4932. height : {from : b.height, to : b.height + 20 * scale},
  4933. width : {from : b.width, to : b.width + 20 * scale}
  4934. },{
  4935. duration: o.duration || 1,
  4936. callback: function() {
  4937. proxy.remove();
  4938. --count > 0 ? queue() : fly(dom).afterFx(o);
  4939. }
  4940. });
  4941. arguments.callee.anim = {
  4942. isAnimated: true,
  4943. stop: function(){
  4944. active.stop();
  4945. }
  4946. };
  4947. };
  4948. queue();
  4949. });
  4950. return me;
  4951. },
  4952. /**
  4953. * Creates a pause before any subsequent queued effects begin. If there are
  4954. * no effects queued after the pause it will have no effect.
  4955. * Usage:
  4956. <pre><code>
  4957. el.pause(1);
  4958. </code></pre>
  4959. * @param {Number} seconds The length of time to pause (in seconds)
  4960. * @return {Ext.Element} The Element
  4961. */
  4962. pause : function(seconds){
  4963. var dom = this.dom,
  4964. t;
  4965. this.queueFx({}, function(){
  4966. t = setTimeout(function(){
  4967. fly(dom).afterFx({});
  4968. }, seconds * 1000);
  4969. arguments.callee.anim = {
  4970. isAnimated: true,
  4971. stop: function(){
  4972. clearTimeout(t);
  4973. fly(dom).afterFx({});
  4974. }
  4975. };
  4976. });
  4977. return this;
  4978. },
  4979. /**
  4980. * Fade an element in (from transparent to opaque). The ending opacity can be specified
  4981. * using the <tt>{@link #endOpacity}</tt> config option.
  4982. * Usage:
  4983. <pre><code>
  4984. // default: fade in from opacity 0 to 100%
  4985. el.fadeIn();
  4986. // custom: fade in from opacity 0 to 75% over 2 seconds
  4987. el.fadeIn({ endOpacity: .75, duration: 2});
  4988. // common config options shown with default values
  4989. el.fadeIn({
  4990. endOpacity: 1, //can be any value between 0 and 1 (e.g. .5)
  4991. easing: 'easeOut',
  4992. duration: .5
  4993. });
  4994. </code></pre>
  4995. * @param {Object} options (optional) Object literal with any of the Fx config options
  4996. * @return {Ext.Element} The Element
  4997. */
  4998. fadeIn : function(o){
  4999. o = getObject(o);
  5000. var me = this,
  5001. dom = me.dom,
  5002. to = o.endOpacity || 1;
  5003. me.queueFx(o, function(){
  5004. fly(dom).setOpacity(0);
  5005. fly(dom).fixDisplay();
  5006. dom.style.visibility = VISIBLE;
  5007. arguments.callee.anim = fly(dom).fxanim({opacity:{to:to}},
  5008. o, NULL, .5, EASEOUT, function(){
  5009. if(to == 1){
  5010. fly(dom).clearOpacity();
  5011. }
  5012. fly(dom).afterFx(o);
  5013. });
  5014. });
  5015. return me;
  5016. },
  5017. /**
  5018. * Fade an element out (from opaque to transparent). The ending opacity can be specified
  5019. * using the <tt>{@link #endOpacity}</tt> config option. Note that IE may require
  5020. * <tt>{@link #useDisplay}:true</tt> in order to redisplay correctly.
  5021. * Usage:
  5022. <pre><code>
  5023. // default: fade out from the element's current opacity to 0
  5024. el.fadeOut();
  5025. // custom: fade out from the element's current opacity to 25% over 2 seconds
  5026. el.fadeOut({ endOpacity: .25, duration: 2});
  5027. // common config options shown with default values
  5028. el.fadeOut({
  5029. endOpacity: 0, //can be any value between 0 and 1 (e.g. .5)
  5030. easing: 'easeOut',
  5031. duration: .5,
  5032. remove: false,
  5033. useDisplay: false
  5034. });
  5035. </code></pre>
  5036. * @param {Object} options (optional) Object literal with any of the Fx config options
  5037. * @return {Ext.Element} The Element
  5038. */
  5039. fadeOut : function(o){
  5040. o = getObject(o);
  5041. var me = this,
  5042. dom = me.dom,
  5043. style = dom.style,
  5044. to = o.endOpacity || 0;
  5045. me.queueFx(o, function(){
  5046. arguments.callee.anim = fly(dom).fxanim({
  5047. opacity : {to : to}},
  5048. o,
  5049. NULL,
  5050. .5,
  5051. EASEOUT,
  5052. function(){
  5053. if(to == 0){
  5054. Ext.Element.data(dom, 'visibilityMode') == Ext.Element.DISPLAY || o.useDisplay ?
  5055. style.display = "none" :
  5056. style.visibility = HIDDEN;
  5057. fly(dom).clearOpacity();
  5058. }
  5059. fly(dom).afterFx(o);
  5060. });
  5061. });
  5062. return me;
  5063. },
  5064. /**
  5065. * Animates the transition of an element's dimensions from a starting height/width
  5066. * to an ending height/width. This method is a convenience implementation of {@link shift}.
  5067. * Usage:
  5068. <pre><code>
  5069. // change height and width to 100x100 pixels
  5070. el.scale(100, 100);
  5071. // common config options shown with default values. The height and width will default to
  5072. // the element&#39;s existing values if passed as null.
  5073. el.scale(
  5074. [element&#39;s width],
  5075. [element&#39;s height], {
  5076. easing: 'easeOut',
  5077. duration: .35
  5078. }
  5079. );
  5080. </code></pre>
  5081. * @param {Number} width The new width (pass undefined to keep the original width)
  5082. * @param {Number} height The new height (pass undefined to keep the original height)
  5083. * @param {Object} options (optional) Object literal with any of the Fx config options
  5084. * @return {Ext.Element} The Element
  5085. */
  5086. scale : function(w, h, o){
  5087. this.shift(Ext.apply({}, o, {
  5088. width: w,
  5089. height: h
  5090. }));
  5091. return this;
  5092. },
  5093. /**
  5094. * Animates the transition of any combination of an element's dimensions, xy position and/or opacity.
  5095. * Any of these properties not specified in the config object will not be changed. This effect
  5096. * requires that at least one new dimension, position or opacity setting must be passed in on
  5097. * the config object in order for the function to have any effect.
  5098. * Usage:
  5099. <pre><code>
  5100. // slide the element horizontally to x position 200 while changing the height and opacity
  5101. el.shift({ x: 200, height: 50, opacity: .8 });
  5102. // common config options shown with default values.
  5103. el.shift({
  5104. width: [element&#39;s width],
  5105. height: [element&#39;s height],
  5106. x: [element&#39;s x position],
  5107. y: [element&#39;s y position],
  5108. opacity: [element&#39;s opacity],
  5109. easing: 'easeOut',
  5110. duration: .35
  5111. });
  5112. </code></pre>
  5113. * @param {Object} options Object literal with any of the Fx config options
  5114. * @return {Ext.Element} The Element
  5115. */
  5116. shift : function(o){
  5117. o = getObject(o);
  5118. var dom = this.dom,
  5119. a = {};
  5120. this.queueFx(o, function(){
  5121. for (var prop in o) {
  5122. if (o[prop] != UNDEFINED) {
  5123. a[prop] = {to : o[prop]};
  5124. }
  5125. }
  5126. a.width ? a.width.to = fly(dom).adjustWidth(o.width) : a;
  5127. a.height ? a.height.to = fly(dom).adjustWidth(o.height) : a;
  5128. if (a.x || a.y || a.xy) {
  5129. a.points = a.xy ||
  5130. {to : [ a.x ? a.x.to : fly(dom).getX(),
  5131. a.y ? a.y.to : fly(dom).getY()]};
  5132. }
  5133. arguments.callee.anim = fly(dom).fxanim(a,
  5134. o,
  5135. MOTION,
  5136. .35,
  5137. EASEOUT,
  5138. function(){
  5139. fly(dom).afterFx(o);
  5140. });
  5141. });
  5142. return this;
  5143. },
  5144. /**
  5145. * Slides the element while fading it out of view. An anchor point can be optionally passed to set the
  5146. * ending point of the effect.
  5147. * Usage:
  5148. *<pre><code>
  5149. // default: slide the element downward while fading out
  5150. el.ghost();
  5151. // custom: slide the element out to the right with a 2-second duration
  5152. el.ghost('r', { duration: 2 });
  5153. // common config options shown with default values
  5154. el.ghost('b', {
  5155. easing: 'easeOut',
  5156. duration: .5,
  5157. remove: false,
  5158. useDisplay: false
  5159. });
  5160. </code></pre>
  5161. * @param {String} anchor (optional) One of the valid Fx anchor positions (defaults to bottom: 'b')
  5162. * @param {Object} options (optional) Object literal with any of the Fx config options
  5163. * @return {Ext.Element} The Element
  5164. */
  5165. ghost : function(anchor, o){
  5166. o = getObject(o);
  5167. var me = this,
  5168. dom = me.dom,
  5169. st = dom.style,
  5170. a = {opacity: {to: 0}, points: {}},
  5171. pt = a.points,
  5172. r,
  5173. w,
  5174. h;
  5175. anchor = anchor || "b";
  5176. me.queueFx(o, function(){
  5177. // restore values after effect
  5178. r = fly(dom).getFxRestore();
  5179. w = fly(dom).getWidth();
  5180. h = fly(dom).getHeight();
  5181. function after(){
  5182. o.useDisplay ? fly(dom).setDisplayed(FALSE) : fly(dom).hide();
  5183. fly(dom).clearOpacity();
  5184. fly(dom).setPositioning(r.pos);
  5185. st.width = r.width;
  5186. st.height = r.height;
  5187. fly(dom).afterFx(o);
  5188. }
  5189. pt.by = fly(dom).switchStatements(anchor.toLowerCase(), function(v1,v2){ return [v1, v2];}, {
  5190. t : [0, -h],
  5191. l : [-w, 0],
  5192. r : [w, 0],
  5193. b : [0, h],
  5194. tl : [-w, -h],
  5195. bl : [-w, h],
  5196. br : [w, h],
  5197. tr : [w, -h]
  5198. });
  5199. arguments.callee.anim = fly(dom).fxanim(a,
  5200. o,
  5201. MOTION,
  5202. .5,
  5203. EASEOUT, after);
  5204. });
  5205. return me;
  5206. },
  5207. /**
  5208. * Ensures that all effects queued after syncFx is called on the element are
  5209. * run concurrently. This is the opposite of {@link #sequenceFx}.
  5210. * @return {Ext.Element} The Element
  5211. */
  5212. syncFx : function(){
  5213. var me = this;
  5214. me.fxDefaults = Ext.apply(me.fxDefaults || {}, {
  5215. block : FALSE,
  5216. concurrent : TRUE,
  5217. stopFx : FALSE
  5218. });
  5219. return me;
  5220. },
  5221. /**
  5222. * Ensures that all effects queued after sequenceFx is called on the element are
  5223. * run in sequence. This is the opposite of {@link #syncFx}.
  5224. * @return {Ext.Element} The Element
  5225. */
  5226. sequenceFx : function(){
  5227. var me = this;
  5228. me.fxDefaults = Ext.apply(me.fxDefaults || {}, {
  5229. block : FALSE,
  5230. concurrent : FALSE,
  5231. stopFx : FALSE
  5232. });
  5233. return me;
  5234. },
  5235. /* @private */
  5236. nextFx : function(){
  5237. var ef = getQueue(this.dom.id)[0];
  5238. if(ef){
  5239. ef.call(this);
  5240. }
  5241. },
  5242. /**
  5243. * Returns true if the element has any effects actively running or queued, else returns false.
  5244. * @return {Boolean} True if element has active effects, else false
  5245. */
  5246. hasActiveFx : function(){
  5247. return getQueue(this.dom.id)[0];
  5248. },
  5249. /**
  5250. * Stops any running effects and clears the element's internal effects queue if it contains
  5251. * any additional effects that haven't started yet.
  5252. * @return {Ext.Element} The Element
  5253. */
  5254. stopFx : function(finish){
  5255. var me = this,
  5256. id = me.dom.id;
  5257. if(me.hasActiveFx()){
  5258. var cur = getQueue(id)[0];
  5259. if(cur && cur.anim){
  5260. if(cur.anim.isAnimated){
  5261. setQueue(id, [cur]); //clear
  5262. cur.anim.stop(finish !== undefined ? finish : TRUE);
  5263. }else{
  5264. setQueue(id, []);
  5265. }
  5266. }
  5267. }
  5268. return me;
  5269. },
  5270. /* @private */
  5271. beforeFx : function(o){
  5272. if(this.hasActiveFx() && !o.concurrent){
  5273. if(o.stopFx){
  5274. this.stopFx();
  5275. return TRUE;
  5276. }
  5277. return FALSE;
  5278. }
  5279. return TRUE;
  5280. },
  5281. /**
  5282. * Returns true if the element is currently blocking so that no other effect can be queued
  5283. * until this effect is finished, else returns false if blocking is not set. This is commonly
  5284. * used to ensure that an effect initiated by a user action runs to completion prior to the
  5285. * same effect being restarted (e.g., firing only one effect even if the user clicks several times).
  5286. * @return {Boolean} True if blocking, else false
  5287. */
  5288. hasFxBlock : function(){
  5289. var q = getQueue(this.dom.id);
  5290. return q && q[0] && q[0].block;
  5291. },
  5292. /* @private */
  5293. queueFx : function(o, fn){
  5294. var me = fly(this.dom);
  5295. if(!me.hasFxBlock()){
  5296. Ext.applyIf(o, me.fxDefaults);
  5297. if(!o.concurrent){
  5298. var run = me.beforeFx(o);
  5299. fn.block = o.block;
  5300. getQueue(me.dom.id).push(fn);
  5301. if(run){
  5302. me.nextFx();
  5303. }
  5304. }else{
  5305. fn.call(me);
  5306. }
  5307. }
  5308. return me;
  5309. },
  5310. /* @private */
  5311. fxWrap : function(pos, o, vis){
  5312. var dom = this.dom,
  5313. wrap,
  5314. wrapXY;
  5315. if(!o.wrap || !(wrap = Ext.getDom(o.wrap))){
  5316. if(o.fixPosition){
  5317. wrapXY = fly(dom).getXY();
  5318. }
  5319. var div = document.createElement("div");
  5320. div.style.visibility = vis;
  5321. wrap = dom.parentNode.insertBefore(div, dom);
  5322. fly(wrap).setPositioning(pos);
  5323. if(fly(wrap).isStyle(POSITION, "static")){
  5324. fly(wrap).position("relative");
  5325. }
  5326. fly(dom).clearPositioning('auto');
  5327. fly(wrap).clip();
  5328. wrap.appendChild(dom);
  5329. if(wrapXY){
  5330. fly(wrap).setXY(wrapXY);
  5331. }
  5332. }
  5333. return wrap;
  5334. },
  5335. /* @private */
  5336. fxUnwrap : function(wrap, pos, o){
  5337. var dom = this.dom;
  5338. fly(dom).clearPositioning();
  5339. fly(dom).setPositioning(pos);
  5340. if(!o.wrap){
  5341. var pn = fly(wrap).dom.parentNode;
  5342. pn.insertBefore(dom, wrap);
  5343. fly(wrap).remove();
  5344. }
  5345. },
  5346. /* @private */
  5347. getFxRestore : function(){
  5348. var st = this.dom.style;
  5349. return {pos: this.getPositioning(), width: st.width, height : st.height};
  5350. },
  5351. /* @private */
  5352. afterFx : function(o){
  5353. var dom = this.dom,
  5354. id = dom.id;
  5355. if(o.afterStyle){
  5356. fly(dom).setStyle(o.afterStyle);
  5357. }
  5358. if(o.afterCls){
  5359. fly(dom).addClass(o.afterCls);
  5360. }
  5361. if(o.remove == TRUE){
  5362. fly(dom).remove();
  5363. }
  5364. if(o.callback){
  5365. o.callback.call(o.scope, fly(dom));
  5366. }
  5367. if(!o.concurrent){
  5368. getQueue(id).shift();
  5369. fly(dom).nextFx();
  5370. }
  5371. },
  5372. /* @private */
  5373. fxanim : function(args, opt, animType, defaultDur, defaultEase, cb){
  5374. animType = animType || 'run';
  5375. opt = opt || {};
  5376. var anim = Ext.lib.Anim[animType](
  5377. this.dom,
  5378. args,
  5379. (opt.duration || defaultDur) || .35,
  5380. (opt.easing || defaultEase) || EASEOUT,
  5381. cb,
  5382. this
  5383. );
  5384. opt.anim = anim;
  5385. return anim;
  5386. }
  5387. };
  5388. // backwards compat
  5389. Ext.Fx.resize = Ext.Fx.scale;
  5390. //When included, Ext.Fx is automatically applied to Element so that all basic
  5391. //effects are available directly via the Element API
  5392. Ext.Element.addMethods(Ext.Fx);
  5393. })();
  5394. /**
  5395. * @class Ext.CompositeElementLite
  5396. * <p>This class encapsulates a <i>collection</i> of DOM elements, providing methods to filter
  5397. * members, or to perform collective actions upon the whole set.</p>
  5398. * <p>Although they are not listed, this class supports all of the methods of {@link Ext.Element} and
  5399. * {@link Ext.Fx}. The methods from these classes will be performed on all the elements in this collection.</p>
  5400. * Example:<pre><code>
  5401. var els = Ext.select("#some-el div.some-class");
  5402. // or select directly from an existing element
  5403. var el = Ext.get('some-el');
  5404. el.select('div.some-class');
  5405. els.setWidth(100); // all elements become 100 width
  5406. els.hide(true); // all elements fade out and hide
  5407. // or
  5408. els.setWidth(100).hide(true);
  5409. </code>
  5410. */
  5411. Ext.CompositeElementLite = function(els, root){
  5412. /**
  5413. * <p>The Array of DOM elements which this CompositeElement encapsulates. Read-only.</p>
  5414. * <p>This will not <i>usually</i> be accessed in developers' code, but developers wishing
  5415. * to augment the capabilities of the CompositeElementLite class may use it when adding
  5416. * methods to the class.</p>
  5417. * <p>For example to add the <code>nextAll</code> method to the class to <b>add</b> all
  5418. * following siblings of selected elements, the code would be</p><code><pre>
  5419. Ext.override(Ext.CompositeElementLite, {
  5420. nextAll: function() {
  5421. var els = this.elements, i, l = els.length, n, r = [], ri = -1;
  5422. // Loop through all elements in this Composite, accumulating
  5423. // an Array of all siblings.
  5424. for (i = 0; i < l; i++) {
  5425. for (n = els[i].nextSibling; n; n = n.nextSibling) {
  5426. r[++ri] = n;
  5427. }
  5428. }
  5429. // Add all found siblings to this Composite
  5430. return this.add(r);
  5431. }
  5432. });</pre></code>
  5433. * @type Array
  5434. * @property elements
  5435. */
  5436. this.elements = [];
  5437. this.add(els, root);
  5438. this.el = new Ext.Element.Flyweight();
  5439. };
  5440. Ext.CompositeElementLite.prototype = {
  5441. isComposite: true,
  5442. // private
  5443. getElement : function(el){
  5444. // Set the shared flyweight dom property to the current element
  5445. var e = this.el;
  5446. e.dom = el;
  5447. e.id = el.id;
  5448. return e;
  5449. },
  5450. // private
  5451. transformElement : function(el){
  5452. return Ext.getDom(el);
  5453. },
  5454. /**
  5455. * Returns the number of elements in this Composite.
  5456. * @return Number
  5457. */
  5458. getCount : function(){
  5459. return this.elements.length;
  5460. },
  5461. /**
  5462. * Adds elements to this Composite object.
  5463. * @param {Mixed} els Either an Array of DOM elements to add, or another Composite object who's elements should be added.
  5464. * @return {CompositeElement} This Composite object.
  5465. */
  5466. add : function(els, root){
  5467. var me = this,
  5468. elements = me.elements;
  5469. if(!els){
  5470. return this;
  5471. }
  5472. if(typeof els == "string"){
  5473. els = Ext.Element.selectorFunction(els, root);
  5474. }else if(els.isComposite){
  5475. els = els.elements;
  5476. }else if(!Ext.isIterable(els)){
  5477. els = [els];
  5478. }
  5479. for(var i = 0, len = els.length; i < len; ++i){
  5480. elements.push(me.transformElement(els[i]));
  5481. }
  5482. return me;
  5483. },
  5484. invoke : function(fn, args){
  5485. var me = this,
  5486. els = me.elements,
  5487. len = els.length,
  5488. e,
  5489. i;
  5490. for(i = 0; i < len; i++) {
  5491. e = els[i];
  5492. if(e){
  5493. Ext.Element.prototype[fn].apply(me.getElement(e), args);
  5494. }
  5495. }
  5496. return me;
  5497. },
  5498. /**
  5499. * Returns a flyweight Element of the dom element object at the specified index
  5500. * @param {Number} index
  5501. * @return {Ext.Element}
  5502. */
  5503. item : function(index){
  5504. var me = this,
  5505. el = me.elements[index],
  5506. out = null;
  5507. if(el){
  5508. out = me.getElement(el);
  5509. }
  5510. return out;
  5511. },
  5512. // fixes scope with flyweight
  5513. addListener : function(eventName, handler, scope, opt){
  5514. var els = this.elements,
  5515. len = els.length,
  5516. i, e;
  5517. for(i = 0; i<len; i++) {
  5518. e = els[i];
  5519. if(e) {
  5520. Ext.EventManager.on(e, eventName, handler, scope || e, opt);
  5521. }
  5522. }
  5523. return this;
  5524. },
  5525. /**
  5526. * <p>Calls the passed function for each element in this composite.</p>
  5527. * @param {Function} fn The function to call. The function is passed the following parameters:<ul>
  5528. * <li><b>el</b> : Element<div class="sub-desc">The current Element in the iteration.
  5529. * <b>This is the flyweight (shared) Ext.Element instance, so if you require a
  5530. * a reference to the dom node, use el.dom.</b></div></li>
  5531. * <li><b>c</b> : Composite<div class="sub-desc">This Composite object.</div></li>
  5532. * <li><b>idx</b> : Number<div class="sub-desc">The zero-based index in the iteration.</div></li>
  5533. * </ul>
  5534. * @param {Object} scope (optional) The scope (<i>this</i> reference) in which the function is executed. (defaults to the Element)
  5535. * @return {CompositeElement} this
  5536. */
  5537. each : function(fn, scope){
  5538. var me = this,
  5539. els = me.elements,
  5540. len = els.length,
  5541. i, e;
  5542. for(i = 0; i<len; i++) {
  5543. e = els[i];
  5544. if(e){
  5545. e = this.getElement(e);
  5546. if(fn.call(scope || e, e, me, i) === false){
  5547. break;
  5548. }
  5549. }
  5550. }
  5551. return me;
  5552. },
  5553. /**
  5554. * Clears this Composite and adds the elements passed.
  5555. * @param {Mixed} els Either an array of DOM elements, or another Composite from which to fill this Composite.
  5556. * @return {CompositeElement} this
  5557. */
  5558. fill : function(els){
  5559. var me = this;
  5560. me.elements = [];
  5561. me.add(els);
  5562. return me;
  5563. },
  5564. /**
  5565. * Filters this composite to only elements that match the passed selector.
  5566. * @param {String/Function} selector A string CSS selector or a comparison function.
  5567. * The comparison function will be called with the following arguments:<ul>
  5568. * <li><code>el</code> : Ext.Element<div class="sub-desc">The current DOM element.</div></li>
  5569. * <li><code>index</code> : Number<div class="sub-desc">The current index within the collection.</div></li>
  5570. * </ul>
  5571. * @return {CompositeElement} this
  5572. */
  5573. filter : function(selector){
  5574. var els = [],
  5575. me = this,
  5576. fn = Ext.isFunction(selector) ? selector
  5577. : function(el){
  5578. return el.is(selector);
  5579. };
  5580. me.each(function(el, self, i) {
  5581. if (fn(el, i) !== false) {
  5582. els[els.length] = me.transformElement(el);
  5583. }
  5584. });
  5585. me.elements = els;
  5586. return me;
  5587. },
  5588. /**
  5589. * Find the index of the passed element within the composite collection.
  5590. * @param el {Mixed} The id of an element, or an Ext.Element, or an HtmlElement to find within the composite collection.
  5591. * @return Number The index of the passed Ext.Element in the composite collection, or -1 if not found.
  5592. */
  5593. indexOf : function(el){
  5594. return this.elements.indexOf(this.transformElement(el));
  5595. },
  5596. /**
  5597. * Replaces the specified element with the passed element.
  5598. * @param {Mixed} el The id of an element, the Element itself, the index of the element in this composite
  5599. * to replace.
  5600. * @param {Mixed} replacement The id of an element or the Element itself.
  5601. * @param {Boolean} domReplace (Optional) True to remove and replace the element in the document too.
  5602. * @return {CompositeElement} this
  5603. */
  5604. replaceElement : function(el, replacement, domReplace){
  5605. var index = !isNaN(el) ? el : this.indexOf(el),
  5606. d;
  5607. if(index > -1){
  5608. replacement = Ext.getDom(replacement);
  5609. if(domReplace){
  5610. d = this.elements[index];
  5611. d.parentNode.insertBefore(replacement, d);
  5612. Ext.removeNode(d);
  5613. }
  5614. this.elements.splice(index, 1, replacement);
  5615. }
  5616. return this;
  5617. },
  5618. /**
  5619. * Removes all elements.
  5620. */
  5621. clear : function(){
  5622. this.elements = [];
  5623. }
  5624. };
  5625. Ext.CompositeElementLite.prototype.on = Ext.CompositeElementLite.prototype.addListener;
  5626. /**
  5627. * @private
  5628. * Copies all of the functions from Ext.Element's prototype onto CompositeElementLite's prototype.
  5629. * This is called twice - once immediately below, and once again after additional Ext.Element
  5630. * are added in Ext JS
  5631. */
  5632. Ext.CompositeElementLite.importElementMethods = function() {
  5633. var fnName,
  5634. ElProto = Ext.Element.prototype,
  5635. CelProto = Ext.CompositeElementLite.prototype;
  5636. for (fnName in ElProto) {
  5637. if (typeof ElProto[fnName] == 'function'){
  5638. (function(fnName) {
  5639. CelProto[fnName] = CelProto[fnName] || function() {
  5640. return this.invoke(fnName, arguments);
  5641. };
  5642. }).call(CelProto, fnName);
  5643. }
  5644. }
  5645. };
  5646. Ext.CompositeElementLite.importElementMethods();
  5647. if(Ext.DomQuery){
  5648. Ext.Element.selectorFunction = Ext.DomQuery.select;
  5649. }
  5650. /**
  5651. * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
  5652. * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
  5653. * {@link Ext.CompositeElementLite CompositeElementLite} object.
  5654. * @param {String/Array} selector The CSS selector or an array of elements
  5655. * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
  5656. * @return {CompositeElementLite/CompositeElement}
  5657. * @member Ext.Element
  5658. * @method select
  5659. */
  5660. Ext.Element.select = function(selector, root){
  5661. var els;
  5662. if(typeof selector == "string"){
  5663. els = Ext.Element.selectorFunction(selector, root);
  5664. }else if(selector.length !== undefined){
  5665. els = selector;
  5666. }else{
  5667. throw "Invalid selector";
  5668. }
  5669. return new Ext.CompositeElementLite(els);
  5670. };
  5671. /**
  5672. * Selects elements based on the passed CSS selector to enable {@link Ext.Element Element} methods
  5673. * to be applied to many related elements in one statement through the returned {@link Ext.CompositeElement CompositeElement} or
  5674. * {@link Ext.CompositeElementLite CompositeElementLite} object.
  5675. * @param {String/Array} selector The CSS selector or an array of elements
  5676. * @param {HTMLElement/String} root (optional) The root element of the query or id of the root
  5677. * @return {CompositeElementLite/CompositeElement}
  5678. * @member Ext
  5679. * @method select
  5680. */
  5681. Ext.select = Ext.Element.select;
  5682. (function(){
  5683. var BEFOREREQUEST = "beforerequest",
  5684. REQUESTCOMPLETE = "requestcomplete",
  5685. REQUESTEXCEPTION = "requestexception",
  5686. UNDEFINED = undefined,
  5687. LOAD = 'load',
  5688. POST = 'POST',
  5689. GET = 'GET',
  5690. WINDOW = window;
  5691. /**
  5692. * @class Ext.data.Connection
  5693. * @extends Ext.util.Observable
  5694. * <p>The class encapsulates a connection to the page's originating domain, allowing requests to be made
  5695. * either to a configured URL, or to a URL specified at request time.</p>
  5696. * <p>Requests made by this class are asynchronous, and will return immediately. No data from
  5697. * the server will be available to the statement immediately following the {@link #request} call.
  5698. * To process returned data, use a
  5699. * <a href="#request-option-success" ext:member="request-option-success" ext:cls="Ext.data.Connection">success callback</a>
  5700. * in the request options object,
  5701. * or an {@link #requestcomplete event listener}.</p>
  5702. * <p><h3>File Uploads</h3><a href="#request-option-isUpload" ext:member="request-option-isUpload" ext:cls="Ext.data.Connection">File uploads</a> are not performed using normal "Ajax" techniques, that
  5703. * is they are <b>not</b> performed using XMLHttpRequests. Instead the form is submitted in the standard
  5704. * manner with the DOM <tt>&lt;form></tt> element temporarily modified to have its
  5705. * <a href="http://www.w3.org/TR/REC-html40/present/frames.html#adef-target">target</a> set to refer
  5706. * to a dynamically generated, hidden <tt>&lt;iframe></tt> which is inserted into the document
  5707. * but removed after the return data has been gathered.</p>
  5708. * <p>The server response is parsed by the browser to create the document for the IFRAME. If the
  5709. * server is using JSON to send the return object, then the
  5710. * <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17">Content-Type</a> header
  5711. * must be set to "text/html" in order to tell the browser to insert the text unchanged into the document body.</p>
  5712. * <p>Characters which are significant to an HTML parser must be sent as HTML entities, so encode
  5713. * "&lt;" as "&amp;lt;", "&amp;" as "&amp;amp;" etc.</p>
  5714. * <p>The response text is retrieved from the document, and a fake XMLHttpRequest object
  5715. * is created containing a <tt>responseText</tt> property in order to conform to the
  5716. * requirements of event handlers and callbacks.</p>
  5717. * <p>Be aware that file upload packets are sent with the content type <a href="http://www.faqs.org/rfcs/rfc2388.html">multipart/form</a>
  5718. * and some server technologies (notably JEE) may require some custom processing in order to
  5719. * retrieve parameter names and parameter values from the packet content.</p>
  5720. * <p>Also note that it's not possible to check the response code of the hidden iframe, so the success handler will ALWAYS fire.</p>
  5721. * @constructor
  5722. * @param {Object} config a configuration object.
  5723. */
  5724. Ext.data.Connection = function(config){
  5725. Ext.apply(this, config);
  5726. this.addEvents(
  5727. /**
  5728. * @event beforerequest
  5729. * Fires before a network request is made to retrieve a data object.
  5730. * @param {Connection} conn This Connection object.
  5731. * @param {Object} options The options config object passed to the {@link #request} method.
  5732. */
  5733. BEFOREREQUEST,
  5734. /**
  5735. * @event requestcomplete
  5736. * Fires if the request was successfully completed.
  5737. * @param {Connection} conn This Connection object.
  5738. * @param {Object} response The XHR object containing the response data.
  5739. * See <a href="http://www.w3.org/TR/XMLHttpRequest/">The XMLHttpRequest Object</a>
  5740. * for details.
  5741. * @param {Object} options The options config object passed to the {@link #request} method.
  5742. */
  5743. REQUESTCOMPLETE,
  5744. /**
  5745. * @event requestexception
  5746. * Fires if an error HTTP status was returned from the server.
  5747. * See <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html">HTTP Status Code Definitions</a>
  5748. * for details of HTTP status codes.
  5749. * @param {Connection} conn This Connection object.
  5750. * @param {Object} response The XHR object containing the response data.
  5751. * See <a href="http://www.w3.org/TR/XMLHttpRequest/">The XMLHttpRequest Object</a>
  5752. * for details.
  5753. * @param {Object} options The options config object passed to the {@link #request} method.
  5754. */
  5755. REQUESTEXCEPTION
  5756. );
  5757. Ext.data.Connection.superclass.constructor.call(this);
  5758. };
  5759. Ext.extend(Ext.data.Connection, Ext.util.Observable, {
  5760. /**
  5761. * @cfg {String} url (Optional) <p>The default URL to be used for requests to the server. Defaults to undefined.</p>
  5762. * <p>The <code>url</code> config may be a function which <i>returns</i> the URL to use for the Ajax request. The scope
  5763. * (<code><b>this</b></code> reference) of the function is the <code>scope</code> option passed to the {@link #request} method.</p>
  5764. */
  5765. /**
  5766. * @cfg {Object} extraParams (Optional) An object containing properties which are used as
  5767. * extra parameters to each request made by this object. (defaults to undefined)
  5768. */
  5769. /**
  5770. * @cfg {Object} defaultHeaders (Optional) An object containing request headers which are added
  5771. * to each request made by this object. (defaults to undefined)
  5772. */
  5773. /**
  5774. * @cfg {String} method (Optional) The default HTTP method to be used for requests.
  5775. * (defaults to undefined; if not set, but {@link #request} params are present, POST will be used;
  5776. * otherwise, GET will be used.)
  5777. */
  5778. /**
  5779. * @cfg {Number} timeout (Optional) The timeout in milliseconds to be used for requests. (defaults to 30000)
  5780. */
  5781. timeout : 30000,
  5782. /**
  5783. * @cfg {Boolean} autoAbort (Optional) Whether this request should abort any pending requests. (defaults to false)
  5784. * @type Boolean
  5785. */
  5786. autoAbort:false,
  5787. /**
  5788. * @cfg {Boolean} disableCaching (Optional) True to add a unique cache-buster param to GET requests. (defaults to true)
  5789. * @type Boolean
  5790. */
  5791. disableCaching: true,
  5792. /**
  5793. * @cfg {String} disableCachingParam (Optional) Change the parameter which is sent went disabling caching
  5794. * through a cache buster. Defaults to '_dc'
  5795. * @type String
  5796. */
  5797. disableCachingParam: '_dc',
  5798. /**
  5799. * <p>Sends an HTTP request to a remote server.</p>
  5800. * <p><b>Important:</b> Ajax server requests are asynchronous, and this call will
  5801. * return before the response has been received. Process any returned data
  5802. * in a callback function.</p>
  5803. * <pre><code>
  5804. Ext.Ajax.request({
  5805. url: 'ajax_demo/sample.json',
  5806. success: function(response, opts) {
  5807. var obj = Ext.decode(response.responseText);
  5808. console.dir(obj);
  5809. },
  5810. failure: function(response, opts) {
  5811. console.log('server-side failure with status code ' + response.status);
  5812. }
  5813. });
  5814. * </code></pre>
  5815. * <p>To execute a callback function in the correct scope, use the <tt>scope</tt> option.</p>
  5816. * @param {Object} options An object which may contain the following properties:<ul>
  5817. * <li><b>url</b> : String/Function (Optional)<div class="sub-desc">The URL to
  5818. * which to send the request, or a function to call which returns a URL string. The scope of the
  5819. * function is specified by the <tt>scope</tt> option. Defaults to the configured
  5820. * <tt>{@link #url}</tt>.</div></li>
  5821. * <li><b>params</b> : Object/String/Function (Optional)<div class="sub-desc">
  5822. * An object containing properties which are used as parameters to the
  5823. * request, a url encoded string or a function to call to get either. The scope of the function
  5824. * is specified by the <tt>scope</tt> option.</div></li>
  5825. * <li><b>method</b> : String (Optional)<div class="sub-desc">The HTTP method to use
  5826. * for the request. Defaults to the configured method, or if no method was configured,
  5827. * "GET" if no parameters are being sent, and "POST" if parameters are being sent. Note that
  5828. * the method name is case-sensitive and should be all caps.</div></li>
  5829. * <li><b>callback</b> : Function (Optional)<div class="sub-desc">The
  5830. * function to be called upon receipt of the HTTP response. The callback is
  5831. * called regardless of success or failure and is passed the following
  5832. * parameters:<ul>
  5833. * <li><b>options</b> : Object<div class="sub-desc">The parameter to the request call.</div></li>
  5834. * <li><b>success</b> : Boolean<div class="sub-desc">True if the request succeeded.</div></li>
  5835. * <li><b>response</b> : Object<div class="sub-desc">The XMLHttpRequest object containing the response data.
  5836. * See <a href="http://www.w3.org/TR/XMLHttpRequest/">http://www.w3.org/TR/XMLHttpRequest/</a> for details about
  5837. * accessing elements of the response.</div></li>
  5838. * </ul></div></li>
  5839. * <li><a id="request-option-success"></a><b>success</b> : Function (Optional)<div class="sub-desc">The function
  5840. * to be called upon success of the request. The callback is passed the following
  5841. * parameters:<ul>
  5842. * <li><b>response</b> : Object<div class="sub-desc">The XMLHttpRequest object containing the response data.</div></li>
  5843. * <li><b>options</b> : Object<div class="sub-desc">The parameter to the request call.</div></li>
  5844. * </ul></div></li>
  5845. * <li><b>failure</b> : Function (Optional)<div class="sub-desc">The function
  5846. * to be called upon failure of the request. The callback is passed the
  5847. * following parameters:<ul>
  5848. * <li><b>response</b> : Object<div class="sub-desc">The XMLHttpRequest object containing the response data.</div></li>
  5849. * <li><b>options</b> : Object<div class="sub-desc">The parameter to the request call.</div></li>
  5850. * </ul></div></li>
  5851. * <li><b>scope</b> : Object (Optional)<div class="sub-desc">The scope in
  5852. * which to execute the callbacks: The "this" object for the callback function. If the <tt>url</tt>, or <tt>params</tt> options were
  5853. * specified as functions from which to draw values, then this also serves as the scope for those function calls.
  5854. * Defaults to the browser window.</div></li>
  5855. * <li><b>timeout</b> : Number (Optional)<div class="sub-desc">The timeout in milliseconds to be used for this request. Defaults to 30 seconds.</div></li>
  5856. * <li><b>form</b> : Element/HTMLElement/String (Optional)<div class="sub-desc">The <tt>&lt;form&gt;</tt>
  5857. * Element or the id of the <tt>&lt;form&gt;</tt> to pull parameters from.</div></li>
  5858. * <li><a id="request-option-isUpload"></a><b>isUpload</b> : Boolean (Optional)<div class="sub-desc"><b>Only meaningful when used
  5859. * with the <tt>form</tt> option</b>.
  5860. * <p>True if the form object is a file upload (will be set automatically if the form was
  5861. * configured with <b><tt>enctype</tt></b> "multipart/form-data").</p>
  5862. * <p>File uploads are not performed using normal "Ajax" techniques, that is they are <b>not</b>
  5863. * performed using XMLHttpRequests. Instead the form is submitted in the standard manner with the
  5864. * DOM <tt>&lt;form></tt> element temporarily modified to have its
  5865. * <a href="http://www.w3.org/TR/REC-html40/present/frames.html#adef-target">target</a> set to refer
  5866. * to a dynamically generated, hidden <tt>&lt;iframe></tt> which is inserted into the document
  5867. * but removed after the return data has been gathered.</p>
  5868. * <p>The server response is parsed by the browser to create the document for the IFRAME. If the
  5869. * server is using JSON to send the return object, then the
  5870. * <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.17">Content-Type</a> header
  5871. * must be set to "text/html" in order to tell the browser to insert the text unchanged into the document body.</p>
  5872. * <p>The response text is retrieved from the document, and a fake XMLHttpRequest object
  5873. * is created containing a <tt>responseText</tt> property in order to conform to the
  5874. * requirements of event handlers and callbacks.</p>
  5875. * <p>Be aware that file upload packets are sent with the content type <a href="http://www.faqs.org/rfcs/rfc2388.html">multipart/form</a>
  5876. * and some server technologies (notably JEE) may require some custom processing in order to
  5877. * retrieve parameter names and parameter values from the packet content.</p>
  5878. * </div></li>
  5879. * <li><b>headers</b> : Object (Optional)<div class="sub-desc">Request
  5880. * headers to set for the request.</div></li>
  5881. * <li><b>xmlData</b> : Object (Optional)<div class="sub-desc">XML document
  5882. * to use for the post. Note: This will be used instead of params for the post
  5883. * data. Any params will be appended to the URL.</div></li>
  5884. * <li><b>jsonData</b> : Object/String (Optional)<div class="sub-desc">JSON
  5885. * data to use as the post. Note: This will be used instead of params for the post
  5886. * data. Any params will be appended to the URL.</div></li>
  5887. * <li><b>disableCaching</b> : Boolean (Optional)<div class="sub-desc">True
  5888. * to add a unique cache-buster param to GET requests.</div></li>
  5889. * </ul></p>
  5890. * <p>The options object may also contain any other property which might be needed to perform
  5891. * postprocessing in a callback because it is passed to callback functions.</p>
  5892. * @return {Number} transactionId The id of the server transaction. This may be used
  5893. * to cancel the request.
  5894. */
  5895. request : function(o){
  5896. var me = this;
  5897. if(me.fireEvent(BEFOREREQUEST, me, o)){
  5898. if (o.el) {
  5899. if(!Ext.isEmpty(o.indicatorText)){
  5900. me.indicatorText = '<div class="loading-indicator">'+o.indicatorText+"</div>";
  5901. }
  5902. if(me.indicatorText) {
  5903. Ext.getDom(o.el).innerHTML = me.indicatorText;
  5904. }
  5905. o.success = (Ext.isFunction(o.success) ? o.success : function(){}).createInterceptor(function(response) {
  5906. Ext.getDom(o.el).innerHTML = response.responseText;
  5907. });
  5908. }
  5909. var p = o.params,
  5910. url = o.url || me.url,
  5911. method,
  5912. cb = {success: me.handleResponse,
  5913. failure: me.handleFailure,
  5914. scope: me,
  5915. argument: {options: o},
  5916. timeout : Ext.num(o.timeout, me.timeout)
  5917. },
  5918. form,
  5919. serForm;
  5920. if (Ext.isFunction(p)) {
  5921. p = p.call(o.scope||WINDOW, o);
  5922. }
  5923. p = Ext.urlEncode(me.extraParams, Ext.isObject(p) ? Ext.urlEncode(p) : p);
  5924. if (Ext.isFunction(url)) {
  5925. url = url.call(o.scope || WINDOW, o);
  5926. }
  5927. if((form = Ext.getDom(o.form))){
  5928. url = url || form.action;
  5929. if(o.isUpload || (/multipart\/form-data/i.test(form.getAttribute("enctype")))) {
  5930. return me.doFormUpload.call(me, o, p, url);
  5931. }
  5932. serForm = Ext.lib.Ajax.serializeForm(form);
  5933. p = p ? (p + '&' + serForm) : serForm;
  5934. }
  5935. method = o.method || me.method || ((p || o.xmlData || o.jsonData) ? POST : GET);
  5936. if(method === GET && (me.disableCaching && o.disableCaching !== false) || o.disableCaching === true){
  5937. var dcp = o.disableCachingParam || me.disableCachingParam;
  5938. url = Ext.urlAppend(url, dcp + '=' + (new Date().getTime()));
  5939. }
  5940. o.headers = Ext.apply(o.headers || {}, me.defaultHeaders || {});
  5941. if(o.autoAbort === true || me.autoAbort) {
  5942. me.abort();
  5943. }
  5944. if((method == GET || o.xmlData || o.jsonData) && p){
  5945. url = Ext.urlAppend(url, p);
  5946. p = '';
  5947. }
  5948. return (me.transId = Ext.lib.Ajax.request(method, url, cb, p, o));
  5949. }else{
  5950. return o.callback ? o.callback.apply(o.scope, [o,UNDEFINED,UNDEFINED]) : null;
  5951. }
  5952. },
  5953. /**
  5954. * Determine whether this object has a request outstanding.
  5955. * @param {Number} transactionId (Optional) defaults to the last transaction
  5956. * @return {Boolean} True if there is an outstanding request.
  5957. */
  5958. isLoading : function(transId){
  5959. return transId ? Ext.lib.Ajax.isCallInProgress(transId) : !! this.transId;
  5960. },
  5961. /**
  5962. * Aborts any outstanding request.
  5963. * @param {Number} transactionId (Optional) defaults to the last transaction
  5964. */
  5965. abort : function(transId){
  5966. if(transId || this.isLoading()){
  5967. Ext.lib.Ajax.abort(transId || this.transId);
  5968. }
  5969. },
  5970. // private
  5971. handleResponse : function(response){
  5972. this.transId = false;
  5973. var options = response.argument.options;
  5974. response.argument = options ? options.argument : null;
  5975. this.fireEvent(REQUESTCOMPLETE, this, response, options);
  5976. if(options.success){
  5977. options.success.call(options.scope, response, options);
  5978. }
  5979. if(options.callback){
  5980. options.callback.call(options.scope, options, true, response);
  5981. }
  5982. },
  5983. // private
  5984. handleFailure : function(response, e){
  5985. this.transId = false;
  5986. var options = response.argument.options;
  5987. response.argument = options ? options.argument : null;
  5988. this.fireEvent(REQUESTEXCEPTION, this, response, options, e);
  5989. if(options.failure){
  5990. options.failure.call(options.scope, response, options);
  5991. }
  5992. if(options.callback){
  5993. options.callback.call(options.scope, options, false, response);
  5994. }
  5995. },
  5996. // private
  5997. doFormUpload : function(o, ps, url){
  5998. var id = Ext.id(),
  5999. doc = document,
  6000. frame = doc.createElement('iframe'),
  6001. form = Ext.getDom(o.form),
  6002. hiddens = [],
  6003. hd,
  6004. encoding = 'multipart/form-data',
  6005. buf = {
  6006. target: form.target,
  6007. method: form.method,
  6008. encoding: form.encoding,
  6009. enctype: form.enctype,
  6010. action: form.action
  6011. };
  6012. /*
  6013. * Originally this behaviour was modified for Opera 10 to apply the secure URL after
  6014. * the frame had been added to the document. It seems this has since been corrected in
  6015. * Opera so the behaviour has been reverted, the URL will be set before being added.
  6016. */
  6017. Ext.fly(frame).set({
  6018. id: id,
  6019. name: id,
  6020. cls: 'x-hidden',
  6021. src: Ext.SSL_SECURE_URL
  6022. });
  6023. doc.body.appendChild(frame);
  6024. // This is required so that IE doesn't pop the response up in a new window.
  6025. if(Ext.isIE){
  6026. document.frames[id].name = id;
  6027. }
  6028. Ext.fly(form).set({
  6029. target: id,
  6030. method: POST,
  6031. enctype: encoding,
  6032. encoding: encoding,
  6033. action: url || buf.action
  6034. });
  6035. // add dynamic params
  6036. Ext.iterate(Ext.urlDecode(ps, false), function(k, v){
  6037. hd = doc.createElement('input');
  6038. Ext.fly(hd).set({
  6039. type: 'hidden',
  6040. value: v,
  6041. name: k
  6042. });
  6043. form.appendChild(hd);
  6044. hiddens.push(hd);
  6045. });
  6046. function cb(){
  6047. var me = this,
  6048. // bogus response object
  6049. r = {responseText : '',
  6050. responseXML : null,
  6051. argument : o.argument},
  6052. doc,
  6053. firstChild;
  6054. try{
  6055. doc = frame.contentWindow.document || frame.contentDocument || WINDOW.frames[id].document;
  6056. if(doc){
  6057. if(doc.body){
  6058. if(/textarea/i.test((firstChild = doc.body.firstChild || {}).tagName)){ // json response wrapped in textarea
  6059. r.responseText = firstChild.value;
  6060. }else{
  6061. r.responseText = doc.body.innerHTML;
  6062. }
  6063. }
  6064. //in IE the document may still have a body even if returns XML.
  6065. r.responseXML = doc.XMLDocument || doc;
  6066. }
  6067. }
  6068. catch(e) {}
  6069. Ext.EventManager.removeListener(frame, LOAD, cb, me);
  6070. me.fireEvent(REQUESTCOMPLETE, me, r, o);
  6071. function runCallback(fn, scope, args){
  6072. if(Ext.isFunction(fn)){
  6073. fn.apply(scope, args);
  6074. }
  6075. }
  6076. runCallback(o.success, o.scope, [r, o]);
  6077. runCallback(o.callback, o.scope, [o, true, r]);
  6078. if(!me.debugUploads){
  6079. setTimeout(function(){Ext.removeNode(frame);}, 100);
  6080. }
  6081. }
  6082. Ext.EventManager.on(frame, LOAD, cb, this);
  6083. form.submit();
  6084. Ext.fly(form).set(buf);
  6085. Ext.each(hiddens, function(h) {
  6086. Ext.removeNode(h);
  6087. });
  6088. }
  6089. });
  6090. })();
  6091. /**
  6092. * @class Ext.Ajax
  6093. * @extends Ext.data.Connection
  6094. * <p>The global Ajax request class that provides a simple way to make Ajax requests
  6095. * with maximum flexibility.</p>
  6096. * <p>Since Ext.Ajax is a singleton, you can set common properties/events for it once
  6097. * and override them at the request function level only if necessary.</p>
  6098. * <p>Common <b>Properties</b> you may want to set are:<div class="mdetail-params"><ul>
  6099. * <li><b><tt>{@link #method}</tt></b><p class="sub-desc"></p></li>
  6100. * <li><b><tt>{@link #extraParams}</tt></b><p class="sub-desc"></p></li>
  6101. * <li><b><tt>{@link #url}</tt></b><p class="sub-desc"></p></li>
  6102. * </ul></div>
  6103. * <pre><code>
  6104. // Default headers to pass in every request
  6105. Ext.Ajax.defaultHeaders = {
  6106. 'Powered-By': 'Ext'
  6107. };
  6108. * </code></pre>
  6109. * </p>
  6110. * <p>Common <b>Events</b> you may want to set are:<div class="mdetail-params"><ul>
  6111. * <li><b><tt>{@link Ext.data.Connection#beforerequest beforerequest}</tt></b><p class="sub-desc"></p></li>
  6112. * <li><b><tt>{@link Ext.data.Connection#requestcomplete requestcomplete}</tt></b><p class="sub-desc"></p></li>
  6113. * <li><b><tt>{@link Ext.data.Connection#requestexception requestexception}</tt></b><p class="sub-desc"></p></li>
  6114. * </ul></div>
  6115. * <pre><code>
  6116. // Example: show a spinner during all Ajax requests
  6117. Ext.Ajax.on('beforerequest', this.showSpinner, this);
  6118. Ext.Ajax.on('requestcomplete', this.hideSpinner, this);
  6119. Ext.Ajax.on('requestexception', this.hideSpinner, this);
  6120. * </code></pre>
  6121. * </p>
  6122. * <p>An example request:</p>
  6123. * <pre><code>
  6124. // Basic request
  6125. Ext.Ajax.{@link Ext.data.Connection#request request}({
  6126. url: 'foo.php',
  6127. success: someFn,
  6128. failure: otherFn,
  6129. headers: {
  6130. 'my-header': 'foo'
  6131. },
  6132. params: { foo: 'bar' }
  6133. });
  6134. // Simple ajax form submission
  6135. Ext.Ajax.{@link Ext.data.Connection#request request}({
  6136. form: 'some-form',
  6137. params: 'foo=bar'
  6138. });
  6139. * </code></pre>
  6140. * </p>
  6141. * @singleton
  6142. */
  6143. Ext.Ajax = new Ext.data.Connection({
  6144. /**
  6145. * @cfg {String} url @hide
  6146. */
  6147. /**
  6148. * @cfg {Object} extraParams @hide
  6149. */
  6150. /**
  6151. * @cfg {Object} defaultHeaders @hide
  6152. */
  6153. /**
  6154. * @cfg {String} method (Optional) @hide
  6155. */
  6156. /**
  6157. * @cfg {Number} timeout (Optional) @hide
  6158. */
  6159. /**
  6160. * @cfg {Boolean} autoAbort (Optional) @hide
  6161. */
  6162. /**
  6163. * @cfg {Boolean} disableCaching (Optional) @hide
  6164. */
  6165. /**
  6166. * @property disableCaching
  6167. * True to add a unique cache-buster param to GET requests. (defaults to true)
  6168. * @type Boolean
  6169. */
  6170. /**
  6171. * @property url
  6172. * The default URL to be used for requests to the server. (defaults to undefined)
  6173. * If the server receives all requests through one URL, setting this once is easier than
  6174. * entering it on every request.
  6175. * @type String
  6176. */
  6177. /**
  6178. * @property extraParams
  6179. * An object containing properties which are used as extra parameters to each request made
  6180. * by this object (defaults to undefined). Session information and other data that you need
  6181. * to pass with each request are commonly put here.
  6182. * @type Object
  6183. */
  6184. /**
  6185. * @property defaultHeaders
  6186. * An object containing request headers which are added to each request made by this object
  6187. * (defaults to undefined).
  6188. * @type Object
  6189. */
  6190. /**
  6191. * @property method
  6192. * The default HTTP method to be used for requests. Note that this is case-sensitive and
  6193. * should be all caps (defaults to undefined; if not set but params are present will use
  6194. * <tt>"POST"</tt>, otherwise will use <tt>"GET"</tt>.)
  6195. * @type String
  6196. */
  6197. /**
  6198. * @property timeout
  6199. * The timeout in milliseconds to be used for requests. (defaults to 30000)
  6200. * @type Number
  6201. */
  6202. /**
  6203. * @property autoAbort
  6204. * Whether a new request should abort any pending requests. (defaults to false)
  6205. * @type Boolean
  6206. */
  6207. autoAbort : false,
  6208. /**
  6209. * Serialize the passed form into a url encoded string
  6210. * @param {String/HTMLElement} form
  6211. * @return {String}
  6212. */
  6213. serializeForm : function(form){
  6214. return Ext.lib.Ajax.serializeForm(form);
  6215. }
  6216. });
  6217. /**
  6218. * @class Ext.util.JSON
  6219. * Modified version of Douglas Crockford"s json.js that doesn"t
  6220. * mess with the Object prototype
  6221. * http://www.json.org/js.html
  6222. * @singleton
  6223. */
  6224. Ext.util.JSON = new (function(){
  6225. var useHasOwn = !!{}.hasOwnProperty,
  6226. isNative = function() {
  6227. var useNative = null;
  6228. return function() {
  6229. if (useNative === null) {
  6230. useNative = Ext.USE_NATIVE_JSON && window.JSON && JSON.toString() == '[object JSON]';
  6231. }
  6232. return useNative;
  6233. };
  6234. }(),
  6235. pad = function(n) {
  6236. return n < 10 ? "0" + n : n;
  6237. },
  6238. doDecode = function(json){
  6239. return eval("(" + json + ")");
  6240. },
  6241. doEncode = function(o){
  6242. if(!Ext.isDefined(o) || o === null){
  6243. return "null";
  6244. }else if(Ext.isArray(o)){
  6245. return encodeArray(o);
  6246. }else if(Ext.isDate(o)){
  6247. return Ext.util.JSON.encodeDate(o);
  6248. }else if(Ext.isString(o)){
  6249. return encodeString(o);
  6250. }else if(typeof o == "number"){
  6251. //don't use isNumber here, since finite checks happen inside isNumber
  6252. return isFinite(o) ? String(o) : "null";
  6253. }else if(Ext.isBoolean(o)){
  6254. return String(o);
  6255. }else {
  6256. var a = ["{"], b, i, v;
  6257. for (i in o) {
  6258. // don't encode DOM objects
  6259. if(!o.getElementsByTagName){
  6260. if(!useHasOwn || o.hasOwnProperty(i)) {
  6261. v = o[i];
  6262. switch (typeof v) {
  6263. case "undefined":
  6264. case "function":
  6265. case "unknown":
  6266. break;
  6267. default:
  6268. if(b){
  6269. a.push(',');
  6270. }
  6271. a.push(doEncode(i), ":",
  6272. v === null ? "null" : doEncode(v));
  6273. b = true;
  6274. }
  6275. }
  6276. }
  6277. }
  6278. a.push("}");
  6279. return a.join("");
  6280. }
  6281. },
  6282. m = {
  6283. "\b": '\\b',
  6284. "\t": '\\t',
  6285. "\n": '\\n',
  6286. "\f": '\\f',
  6287. "\r": '\\r',
  6288. '"' : '\\"',
  6289. "\\": '\\\\'
  6290. },
  6291. encodeString = function(s){
  6292. if (/["\\\x00-\x1f]/.test(s)) {
  6293. return '"' + s.replace(/([\x00-\x1f\\"])/g, function(a, b) {
  6294. var c = m[b];
  6295. if(c){
  6296. return c;
  6297. }
  6298. c = b.charCodeAt();
  6299. return "\\u00" +
  6300. Math.floor(c / 16).toString(16) +
  6301. (c % 16).toString(16);
  6302. }) + '"';
  6303. }
  6304. return '"' + s + '"';
  6305. },
  6306. encodeArray = function(o){
  6307. var a = ["["], b, i, l = o.length, v;
  6308. for (i = 0; i < l; i += 1) {
  6309. v = o[i];
  6310. switch (typeof v) {
  6311. case "undefined":
  6312. case "function":
  6313. case "unknown":
  6314. break;
  6315. default:
  6316. if (b) {
  6317. a.push(',');
  6318. }
  6319. a.push(v === null ? "null" : Ext.util.JSON.encode(v));
  6320. b = true;
  6321. }
  6322. }
  6323. a.push("]");
  6324. return a.join("");
  6325. };
  6326. /**
  6327. * <p>Encodes a Date. This returns the actual string which is inserted into the JSON string as the literal expression.
  6328. * <b>The returned value includes enclosing double quotation marks.</b></p>
  6329. * <p>The default return format is "yyyy-mm-ddThh:mm:ss".</p>
  6330. * <p>To override this:</p><pre><code>
  6331. Ext.util.JSON.encodeDate = function(d) {
  6332. return d.format('"Y-m-d"');
  6333. };
  6334. </code></pre>
  6335. * @param {Date} d The Date to encode
  6336. * @return {String} The string literal to use in a JSON string.
  6337. */
  6338. this.encodeDate = function(o){
  6339. return '"' + o.getFullYear() + "-" +
  6340. pad(o.getMonth() + 1) + "-" +
  6341. pad(o.getDate()) + "T" +
  6342. pad(o.getHours()) + ":" +
  6343. pad(o.getMinutes()) + ":" +
  6344. pad(o.getSeconds()) + '"';
  6345. };
  6346. /**
  6347. * Encodes an Object, Array or other value
  6348. * @param {Mixed} o The variable to encode
  6349. * @return {String} The JSON string
  6350. */
  6351. this.encode = function() {
  6352. var ec;
  6353. return function(o) {
  6354. if (!ec) {
  6355. // setup encoding function on first access
  6356. ec = isNative() ? JSON.stringify : doEncode;
  6357. }
  6358. return ec(o);
  6359. };
  6360. }();
  6361. /**
  6362. * Decodes (parses) a JSON string to an object. If the JSON is invalid, this function throws a SyntaxError unless the safe option is set.
  6363. * @param {String} json The JSON string
  6364. * @return {Object} The resulting object
  6365. */
  6366. this.decode = function() {
  6367. var dc;
  6368. return function(json) {
  6369. if (!dc) {
  6370. // setup decoding function on first access
  6371. dc = isNative() ? JSON.parse : doDecode;
  6372. }
  6373. return dc(json);
  6374. };
  6375. }();
  6376. })();
  6377. /**
  6378. * Shorthand for {@link Ext.util.JSON#encode}
  6379. * @param {Mixed} o The variable to encode
  6380. * @return {String} The JSON string
  6381. * @member Ext
  6382. * @method encode
  6383. */
  6384. Ext.encode = Ext.util.JSON.encode;
  6385. /**
  6386. * Shorthand for {@link Ext.util.JSON#decode}
  6387. * @param {String} json The JSON string
  6388. * @param {Boolean} safe (optional) Whether to return null or throw an exception if the JSON is invalid.
  6389. * @return {Object} The resulting object
  6390. * @member Ext
  6391. * @method decode
  6392. */
  6393. Ext.decode = Ext.util.JSON.decode;
  6394. /**
  6395. * @class Ext.EventManager
  6396. * Registers event handlers that want to receive a normalized EventObject instead of the standard browser event and provides
  6397. * several useful events directly.
  6398. * See {@link Ext.EventObject} for more details on normalized event objects.
  6399. * @singleton
  6400. */
  6401. Ext.EventManager = function(){
  6402. var docReadyEvent,
  6403. docReadyProcId,
  6404. docReadyState = false,
  6405. DETECT_NATIVE = Ext.isGecko || Ext.isWebKit || Ext.isSafari,
  6406. E = Ext.lib.Event,
  6407. D = Ext.lib.Dom,
  6408. DOC = document,
  6409. WINDOW = window,
  6410. DOMCONTENTLOADED = "DOMContentLoaded",
  6411. COMPLETE = 'complete',
  6412. propRe = /^(?:scope|delay|buffer|single|stopEvent|preventDefault|stopPropagation|normalized|args|delegate)$/,
  6413. /*
  6414. * This cache is used to hold special js objects, the document and window, that don't have an id. We need to keep
  6415. * a reference to them so we can look them up at a later point.
  6416. */
  6417. specialElCache = [];
  6418. function getId(el){
  6419. var id = false,
  6420. i = 0,
  6421. len = specialElCache.length,
  6422. skip = false,
  6423. o;
  6424. if (el) {
  6425. if (el.getElementById || el.navigator) {
  6426. // look up the id
  6427. for(; i < len; ++i){
  6428. o = specialElCache[i];
  6429. if(o.el === el){
  6430. id = o.id;
  6431. break;
  6432. }
  6433. }
  6434. if(!id){
  6435. // for browsers that support it, ensure that give the el the same id
  6436. id = Ext.id(el);
  6437. specialElCache.push({
  6438. id: id,
  6439. el: el
  6440. });
  6441. skip = true;
  6442. }
  6443. }else{
  6444. id = Ext.id(el);
  6445. }
  6446. if(!Ext.elCache[id]){
  6447. Ext.Element.addToCache(new Ext.Element(el), id);
  6448. if(skip){
  6449. Ext.elCache[id].skipGC = true;
  6450. }
  6451. }
  6452. }
  6453. return id;
  6454. }
  6455. /// There is some jquery work around stuff here that isn't needed in Ext Core.
  6456. function addListener(el, ename, fn, task, wrap, scope){
  6457. el = Ext.getDom(el);
  6458. var id = getId(el),
  6459. es = Ext.elCache[id].events,
  6460. wfn;
  6461. wfn = E.on(el, ename, wrap);
  6462. es[ename] = es[ename] || [];
  6463. /* 0 = Original Function,
  6464. 1 = Event Manager Wrapped Function,
  6465. 2 = Scope,
  6466. 3 = Adapter Wrapped Function,
  6467. 4 = Buffered Task
  6468. */
  6469. es[ename].push([fn, wrap, scope, wfn, task]);
  6470. // this is a workaround for jQuery and should somehow be removed from Ext Core in the future
  6471. // without breaking ExtJS.
  6472. // workaround for jQuery
  6473. if(el.addEventListener && ename == "mousewheel"){
  6474. var args = ["DOMMouseScroll", wrap, false];
  6475. el.addEventListener.apply(el, args);
  6476. Ext.EventManager.addListener(WINDOW, 'unload', function(){
  6477. el.removeEventListener.apply(el, args);
  6478. });
  6479. }
  6480. // fix stopped mousedowns on the document
  6481. if(el == DOC && ename == "mousedown"){
  6482. Ext.EventManager.stoppedMouseDownEvent.addListener(wrap);
  6483. }
  6484. }
  6485. function doScrollChk(){
  6486. /* Notes:
  6487. 'doScroll' will NOT work in a IFRAME/FRAMESET.
  6488. The method succeeds but, a DOM query done immediately after -- FAILS.
  6489. */
  6490. if(window != top){
  6491. return false;
  6492. }
  6493. try{
  6494. DOC.documentElement.doScroll('left');
  6495. }catch(e){
  6496. return false;
  6497. }
  6498. fireDocReady();
  6499. return true;
  6500. }
  6501. /**
  6502. * @return {Boolean} True if the document is in a 'complete' state (or was determined to
  6503. * be true by other means). If false, the state is evaluated again until canceled.
  6504. */
  6505. function checkReadyState(e){
  6506. if(Ext.isIE && doScrollChk()){
  6507. return true;
  6508. }
  6509. if(DOC.readyState == COMPLETE){
  6510. fireDocReady();
  6511. return true;
  6512. }
  6513. docReadyState || (docReadyProcId = setTimeout(arguments.callee, 2));
  6514. return false;
  6515. }
  6516. var styles;
  6517. function checkStyleSheets(e){
  6518. styles || (styles = Ext.query('style, link[rel=stylesheet]'));
  6519. if(styles.length == DOC.styleSheets.length){
  6520. fireDocReady();
  6521. return true;
  6522. }
  6523. docReadyState || (docReadyProcId = setTimeout(arguments.callee, 2));
  6524. return false;
  6525. }
  6526. function OperaDOMContentLoaded(e){
  6527. DOC.removeEventListener(DOMCONTENTLOADED, arguments.callee, false);
  6528. checkStyleSheets();
  6529. }
  6530. function fireDocReady(e){
  6531. if(!docReadyState){
  6532. docReadyState = true; //only attempt listener removal once
  6533. if(docReadyProcId){
  6534. clearTimeout(docReadyProcId);
  6535. }
  6536. if(DETECT_NATIVE) {
  6537. DOC.removeEventListener(DOMCONTENTLOADED, fireDocReady, false);
  6538. }
  6539. if(Ext.isIE && checkReadyState.bindIE){ //was this was actually set ??
  6540. DOC.detachEvent('onreadystatechange', checkReadyState);
  6541. }
  6542. E.un(WINDOW, "load", arguments.callee);
  6543. }
  6544. if(docReadyEvent && !Ext.isReady){
  6545. Ext.isReady = true;
  6546. docReadyEvent.fire();
  6547. docReadyEvent.listeners = [];
  6548. }
  6549. }
  6550. function initDocReady(){
  6551. docReadyEvent || (docReadyEvent = new Ext.util.Event());
  6552. if (DETECT_NATIVE) {
  6553. DOC.addEventListener(DOMCONTENTLOADED, fireDocReady, false);
  6554. }
  6555. /*
  6556. * Handle additional (exceptional) detection strategies here
  6557. */
  6558. if (Ext.isIE){
  6559. //Use readystatechange as a backup AND primary detection mechanism for a FRAME/IFRAME
  6560. //See if page is already loaded
  6561. if(!checkReadyState()){
  6562. checkReadyState.bindIE = true;
  6563. DOC.attachEvent('onreadystatechange', checkReadyState);
  6564. }
  6565. }else if(Ext.isOpera ){
  6566. /* Notes:
  6567. Opera needs special treatment needed here because CSS rules are NOT QUITE
  6568. available after DOMContentLoaded is raised.
  6569. */
  6570. //See if page is already loaded and all styleSheets are in place
  6571. (DOC.readyState == COMPLETE && checkStyleSheets()) ||
  6572. DOC.addEventListener(DOMCONTENTLOADED, OperaDOMContentLoaded, false);
  6573. }else if (Ext.isWebKit){
  6574. //Fallback for older Webkits without DOMCONTENTLOADED support
  6575. checkReadyState();
  6576. }
  6577. // no matter what, make sure it fires on load
  6578. E.on(WINDOW, "load", fireDocReady);
  6579. }
  6580. function createTargeted(h, o){
  6581. return function(){
  6582. var args = Ext.toArray(arguments);
  6583. if(o.target == Ext.EventObject.setEvent(args[0]).target){
  6584. h.apply(this, args);
  6585. }
  6586. };
  6587. }
  6588. function createBuffered(h, o, task){
  6589. return function(e){
  6590. // create new event object impl so new events don't wipe out properties
  6591. task.delay(o.buffer, h, null, [new Ext.EventObjectImpl(e)]);
  6592. };
  6593. }
  6594. function createSingle(h, el, ename, fn, scope){
  6595. return function(e){
  6596. Ext.EventManager.removeListener(el, ename, fn, scope);
  6597. h(e);
  6598. };
  6599. }
  6600. function createDelayed(h, o, fn){
  6601. return function(e){
  6602. var task = new Ext.util.DelayedTask(h);
  6603. if(!fn.tasks) {
  6604. fn.tasks = [];
  6605. }
  6606. fn.tasks.push(task);
  6607. task.delay(o.delay || 10, h, null, [new Ext.EventObjectImpl(e)]);
  6608. };
  6609. }
  6610. function listen(element, ename, opt, fn, scope){
  6611. var o = (!opt || typeof opt == "boolean") ? {} : opt,
  6612. el = Ext.getDom(element), task;
  6613. fn = fn || o.fn;
  6614. scope = scope || o.scope;
  6615. if(!el){
  6616. throw "Error listening for \"" + ename + '\". Element "' + element + '" doesn\'t exist.';
  6617. }
  6618. function h(e){
  6619. // prevent errors while unload occurring
  6620. if(!Ext){// !window[xname]){ ==> can't we do this?
  6621. return;
  6622. }
  6623. e = Ext.EventObject.setEvent(e);
  6624. var t;
  6625. if (o.delegate) {
  6626. if(!(t = e.getTarget(o.delegate, el))){
  6627. return;
  6628. }
  6629. } else {
  6630. t = e.target;
  6631. }
  6632. if (o.stopEvent) {
  6633. e.stopEvent();
  6634. }
  6635. if (o.preventDefault) {
  6636. e.preventDefault();
  6637. }
  6638. if (o.stopPropagation) {
  6639. e.stopPropagation();
  6640. }
  6641. if (o.normalized === false) {
  6642. e = e.browserEvent;
  6643. }
  6644. fn.call(scope || el, e, t, o);
  6645. }
  6646. if(o.target){
  6647. h = createTargeted(h, o);
  6648. }
  6649. if(o.delay){
  6650. h = createDelayed(h, o, fn);
  6651. }
  6652. if(o.single){
  6653. h = createSingle(h, el, ename, fn, scope);
  6654. }
  6655. if(o.buffer){
  6656. task = new Ext.util.DelayedTask(h);
  6657. h = createBuffered(h, o, task);
  6658. }
  6659. addListener(el, ename, fn, task, h, scope);
  6660. return h;
  6661. }
  6662. var pub = {
  6663. /**
  6664. * Appends an event handler to an element. The shorthand version {@link #on} is equivalent. Typically you will
  6665. * use {@link Ext.Element#addListener} directly on an Element in favor of calling this version.
  6666. * @param {String/HTMLElement} el The html element or id to assign the event handler to.
  6667. * @param {String} eventName The name of the event to listen for.
  6668. * @param {Function} handler The handler function the event invokes. This function is passed
  6669. * the following parameters:<ul>
  6670. * <li>evt : EventObject<div class="sub-desc">The {@link Ext.EventObject EventObject} describing the event.</div></li>
  6671. * <li>t : Element<div class="sub-desc">The {@link Ext.Element Element} which was the target of the event.
  6672. * Note that this may be filtered by using the <tt>delegate</tt> option.</div></li>
  6673. * <li>o : Object<div class="sub-desc">The options object from the addListener call.</div></li>
  6674. * </ul>
  6675. * @param {Object} scope (optional) The scope (<b><code>this</code></b> reference) in which the handler function is executed. <b>Defaults to the Element</b>.
  6676. * @param {Object} options (optional) An object containing handler configuration properties.
  6677. * This may contain any of the following properties:<ul>
  6678. * <li>scope : Object<div class="sub-desc">The scope (<b><code>this</code></b> reference) in which the handler function is executed. <b>Defaults to the Element</b>.</div></li>
  6679. * <li>delegate : String<div class="sub-desc">A simple selector to filter the target or look for a descendant of the target</div></li>
  6680. * <li>stopEvent : Boolean<div class="sub-desc">True to stop the event. That is stop propagation, and prevent the default action.</div></li>
  6681. * <li>preventDefault : Boolean<div class="sub-desc">True to prevent the default action</div></li>
  6682. * <li>stopPropagation : Boolean<div class="sub-desc">True to prevent event propagation</div></li>
  6683. * <li>normalized : Boolean<div class="sub-desc">False to pass a browser event to the handler function instead of an Ext.EventObject</div></li>
  6684. * <li>delay : Number<div class="sub-desc">The number of milliseconds to delay the invocation of the handler after te event fires.</div></li>
  6685. * <li>single : Boolean<div class="sub-desc">True to add a handler to handle just the next firing of the event, and then remove itself.</div></li>
  6686. * <li>buffer : Number<div class="sub-desc">Causes the handler to be scheduled to run in an {@link Ext.util.DelayedTask} delayed
  6687. * by the specified number of milliseconds. If the event fires again within that time, the original
  6688. * handler is <em>not</em> invoked, but the new handler is scheduled in its place.</div></li>
  6689. * <li>target : Element<div class="sub-desc">Only call the handler if the event was fired on the target Element, <i>not</i> if the event was bubbled up from a child node.</div></li>
  6690. * </ul><br>
  6691. * <p>See {@link Ext.Element#addListener} for examples of how to use these options.</p>
  6692. */
  6693. addListener : function(element, eventName, fn, scope, options){
  6694. if(typeof eventName == 'object'){
  6695. var o = eventName, e, val;
  6696. for(e in o){
  6697. val = o[e];
  6698. if(!propRe.test(e)){
  6699. if(Ext.isFunction(val)){
  6700. // shared options
  6701. listen(element, e, o, val, o.scope);
  6702. }else{
  6703. // individual options
  6704. listen(element, e, val);
  6705. }
  6706. }
  6707. }
  6708. } else {
  6709. listen(element, eventName, options, fn, scope);
  6710. }
  6711. },
  6712. /**
  6713. * Removes an event handler from an element. The shorthand version {@link #un} is equivalent. Typically
  6714. * you will use {@link Ext.Element#removeListener} directly on an Element in favor of calling this version.
  6715. * @param {String/HTMLElement} el The id or html element from which to remove the listener.
  6716. * @param {String} eventName The name of the event.
  6717. * @param {Function} fn The handler function to remove. <b>This must be a reference to the function passed into the {@link #addListener} call.</b>
  6718. * @param {Object} scope If a scope (<b><code>this</code></b> reference) was specified when the listener was added,
  6719. * then this must refer to the same object.
  6720. */
  6721. removeListener : function(el, eventName, fn, scope){
  6722. el = Ext.getDom(el);
  6723. var id = getId(el),
  6724. f = el && (Ext.elCache[id].events)[eventName] || [],
  6725. wrap, i, l, k, len, fnc;
  6726. for (i = 0, len = f.length; i < len; i++) {
  6727. /* 0 = Original Function,
  6728. 1 = Event Manager Wrapped Function,
  6729. 2 = Scope,
  6730. 3 = Adapter Wrapped Function,
  6731. 4 = Buffered Task
  6732. */
  6733. if (Ext.isArray(fnc = f[i]) && fnc[0] == fn && (!scope || fnc[2] == scope)) {
  6734. if(fnc[4]) {
  6735. fnc[4].cancel();
  6736. }
  6737. k = fn.tasks && fn.tasks.length;
  6738. if(k) {
  6739. while(k--) {
  6740. fn.tasks[k].cancel();
  6741. }
  6742. delete fn.tasks;
  6743. }
  6744. wrap = fnc[1];
  6745. E.un(el, eventName, E.extAdapter ? fnc[3] : wrap);
  6746. // jQuery workaround that should be removed from Ext Core
  6747. if(wrap && el.addEventListener && eventName == "mousewheel"){
  6748. el.removeEventListener("DOMMouseScroll", wrap, false);
  6749. }
  6750. // fix stopped mousedowns on the document
  6751. if(wrap && el == DOC && eventName == "mousedown"){
  6752. Ext.EventManager.stoppedMouseDownEvent.removeListener(wrap);
  6753. }
  6754. f.splice(i, 1);
  6755. if (f.length === 0) {
  6756. delete Ext.elCache[id].events[eventName];
  6757. }
  6758. for (k in Ext.elCache[id].events) {
  6759. return false;
  6760. }
  6761. Ext.elCache[id].events = {};
  6762. return false;
  6763. }
  6764. }
  6765. },
  6766. /**
  6767. * Removes all event handers from an element. Typically you will use {@link Ext.Element#removeAllListeners}
  6768. * directly on an Element in favor of calling this version.
  6769. * @param {String/HTMLElement} el The id or html element from which to remove all event handlers.
  6770. */
  6771. removeAll : function(el){
  6772. el = Ext.getDom(el);
  6773. var id = getId(el),
  6774. ec = Ext.elCache[id] || {},
  6775. es = ec.events || {},
  6776. f, i, len, ename, fn, k, wrap;
  6777. for(ename in es){
  6778. if(es.hasOwnProperty(ename)){
  6779. f = es[ename];
  6780. /* 0 = Original Function,
  6781. 1 = Event Manager Wrapped Function,
  6782. 2 = Scope,
  6783. 3 = Adapter Wrapped Function,
  6784. 4 = Buffered Task
  6785. */
  6786. for (i = 0, len = f.length; i < len; i++) {
  6787. fn = f[i];
  6788. if(fn[4]) {
  6789. fn[4].cancel();
  6790. }
  6791. if(fn[0].tasks && (k = fn[0].tasks.length)) {
  6792. while(k--) {
  6793. fn[0].tasks[k].cancel();
  6794. }
  6795. delete fn.tasks;
  6796. }
  6797. wrap = fn[1];
  6798. E.un(el, ename, E.extAdapter ? fn[3] : wrap);
  6799. // jQuery workaround that should be removed from Ext Core
  6800. if(el.addEventListener && wrap && ename == "mousewheel"){
  6801. el.removeEventListener("DOMMouseScroll", wrap, false);
  6802. }
  6803. // fix stopped mousedowns on the document
  6804. if(wrap && el == DOC && ename == "mousedown"){
  6805. Ext.EventManager.stoppedMouseDownEvent.removeListener(wrap);
  6806. }
  6807. }
  6808. }
  6809. }
  6810. if (Ext.elCache[id]) {
  6811. Ext.elCache[id].events = {};
  6812. }
  6813. },
  6814. getListeners : function(el, eventName) {
  6815. el = Ext.getDom(el);
  6816. var id = getId(el),
  6817. ec = Ext.elCache[id] || {},
  6818. es = ec.events || {},
  6819. results = [];
  6820. if (es && es[eventName]) {
  6821. return es[eventName];
  6822. } else {
  6823. return null;
  6824. }
  6825. },
  6826. purgeElement : function(el, recurse, eventName) {
  6827. el = Ext.getDom(el);
  6828. var id = getId(el),
  6829. ec = Ext.elCache[id] || {},
  6830. es = ec.events || {},
  6831. i, f, len;
  6832. if (eventName) {
  6833. if (es && es.hasOwnProperty(eventName)) {
  6834. f = es[eventName];
  6835. for (i = 0, len = f.length; i < len; i++) {
  6836. Ext.EventManager.removeListener(el, eventName, f[i][0]);
  6837. }
  6838. }
  6839. } else {
  6840. Ext.EventManager.removeAll(el);
  6841. }
  6842. if (recurse && el && el.childNodes) {
  6843. for (i = 0, len = el.childNodes.length; i < len; i++) {
  6844. Ext.EventManager.purgeElement(el.childNodes[i], recurse, eventName);
  6845. }
  6846. }
  6847. },
  6848. _unload : function() {
  6849. var el;
  6850. for (el in Ext.elCache) {
  6851. Ext.EventManager.removeAll(el);
  6852. }
  6853. delete Ext.elCache;
  6854. delete Ext.Element._flyweights;
  6855. // Abort any outstanding Ajax requests
  6856. var c,
  6857. conn,
  6858. tid,
  6859. ajax = Ext.lib.Ajax;
  6860. (typeof ajax.conn == 'object') ? conn = ajax.conn : conn = {};
  6861. for (tid in conn) {
  6862. c = conn[tid];
  6863. if (c) {
  6864. ajax.abort({conn: c, tId: tid});
  6865. }
  6866. }
  6867. },
  6868. /**
  6869. * Adds a listener to be notified when the document is ready (before onload and before images are loaded). Can be
  6870. * accessed shorthanded as Ext.onReady().
  6871. * @param {Function} fn The method the event invokes.
  6872. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the handler function executes. Defaults to the browser window.
  6873. * @param {boolean} options (optional) Options object as passed to {@link Ext.Element#addListener}. It is recommended that the options
  6874. * <code>{single: true}</code> be used so that the handler is removed on first invocation.
  6875. */
  6876. onDocumentReady : function(fn, scope, options){
  6877. if (Ext.isReady) { // if it already fired or document.body is present
  6878. docReadyEvent || (docReadyEvent = new Ext.util.Event());
  6879. docReadyEvent.addListener(fn, scope, options);
  6880. docReadyEvent.fire();
  6881. docReadyEvent.listeners = [];
  6882. } else {
  6883. if (!docReadyEvent) {
  6884. initDocReady();
  6885. }
  6886. options = options || {};
  6887. options.delay = options.delay || 1;
  6888. docReadyEvent.addListener(fn, scope, options);
  6889. }
  6890. },
  6891. /**
  6892. * Forces a document ready state transition for the framework. Used when Ext is loaded
  6893. * into a DOM structure AFTER initial page load (Google API or other dynamic load scenario.
  6894. * Any pending 'onDocumentReady' handlers will be fired (if not already handled).
  6895. */
  6896. fireDocReady : fireDocReady
  6897. };
  6898. /**
  6899. * Appends an event handler to an element. Shorthand for {@link #addListener}.
  6900. * @param {String/HTMLElement} el The html element or id to assign the event handler to
  6901. * @param {String} eventName The name of the event to listen for.
  6902. * @param {Function} handler The handler function the event invokes.
  6903. * @param {Object} scope (optional) (<code>this</code> reference) in which the handler function executes. <b>Defaults to the Element</b>.
  6904. * @param {Object} options (optional) An object containing standard {@link #addListener} options
  6905. * @member Ext.EventManager
  6906. * @method on
  6907. */
  6908. pub.on = pub.addListener;
  6909. /**
  6910. * Removes an event handler from an element. Shorthand for {@link #removeListener}.
  6911. * @param {String/HTMLElement} el The id or html element from which to remove the listener.
  6912. * @param {String} eventName The name of the event.
  6913. * @param {Function} fn The handler function to remove. <b>This must be a reference to the function passed into the {@link #on} call.</b>
  6914. * @param {Object} scope If a scope (<b><code>this</code></b> reference) was specified when the listener was added,
  6915. * then this must refer to the same object.
  6916. * @member Ext.EventManager
  6917. * @method un
  6918. */
  6919. pub.un = pub.removeListener;
  6920. pub.stoppedMouseDownEvent = new Ext.util.Event();
  6921. return pub;
  6922. }();
  6923. /**
  6924. * Adds a listener to be notified when the document is ready (before onload and before images are loaded). Shorthand of {@link Ext.EventManager#onDocumentReady}.
  6925. * @param {Function} fn The method the event invokes.
  6926. * @param {Object} scope (optional) The scope (<code>this</code> reference) in which the handler function executes. Defaults to the browser window.
  6927. * @param {boolean} options (optional) Options object as passed to {@link Ext.Element#addListener}. It is recommended that the options
  6928. * <code>{single: true}</code> be used so that the handler is removed on first invocation.
  6929. * @member Ext
  6930. * @method onReady
  6931. */
  6932. Ext.onReady = Ext.EventManager.onDocumentReady;
  6933. //Initialize doc classes
  6934. (function(){
  6935. var initExtCss = function() {
  6936. // find the body element
  6937. var bd = document.body || document.getElementsByTagName('body')[0];
  6938. if (!bd) {
  6939. return false;
  6940. }
  6941. var cls = [' ',
  6942. Ext.isIE ? "ext-ie " + (Ext.isIE6 ? 'ext-ie6' : (Ext.isIE7 ? 'ext-ie7' : 'ext-ie8'))
  6943. : Ext.isGecko ? "ext-gecko " + (Ext.isGecko2 ? 'ext-gecko2' : 'ext-gecko3')
  6944. : Ext.isOpera ? "ext-opera"
  6945. : Ext.isWebKit ? "ext-webkit" : ""];
  6946. if (Ext.isSafari) {
  6947. cls.push("ext-safari " + (Ext.isSafari2 ? 'ext-safari2' : (Ext.isSafari3 ? 'ext-safari3' : 'ext-safari4')));
  6948. } else if(Ext.isChrome) {
  6949. cls.push("ext-chrome");
  6950. }
  6951. if (Ext.isMac) {
  6952. cls.push("ext-mac");
  6953. }
  6954. if (Ext.isLinux) {
  6955. cls.push("ext-linux");
  6956. }
  6957. // add to the parent to allow for selectors like ".ext-strict .ext-ie"
  6958. if (Ext.isStrict || Ext.isBorderBox) {
  6959. var p = bd.parentNode;
  6960. if (p) {
  6961. Ext.fly(p, '_internal').addClass(((Ext.isStrict && Ext.isIE ) || (!Ext.enableForcedBoxModel && !Ext.isIE)) ? ' ext-strict' : ' ext-border-box');
  6962. }
  6963. }
  6964. // Forced border box model class applied to all elements. Bypassing javascript based box model adjustments
  6965. // in favor of css. This is for non-IE browsers.
  6966. if (Ext.enableForcedBoxModel && !Ext.isIE) {
  6967. Ext.isForcedBorderBox = true;
  6968. cls.push("ext-forced-border-box");
  6969. }
  6970. Ext.fly(bd, '_internal').addClass(cls);
  6971. return true;
  6972. };
  6973. if (!initExtCss()) {
  6974. Ext.onReady(initExtCss);
  6975. }
  6976. })();
  6977. /**
  6978. * Code used to detect certain browser feature/quirks/bugs at startup.
  6979. */
  6980. (function(){
  6981. var supports = Ext.apply(Ext.supports, {
  6982. /**
  6983. * In Webkit, there is an issue with getting the margin right property, see
  6984. * https://bugs.webkit.org/show_bug.cgi?id=13343
  6985. */
  6986. correctRightMargin: true,
  6987. /**
  6988. * Webkit browsers return rgba(0, 0, 0) when a transparent color is used
  6989. */
  6990. correctTransparentColor: true,
  6991. /**
  6992. * IE uses styleFloat, not cssFloat for the float property.
  6993. */
  6994. cssFloat: true
  6995. });
  6996. var supportTests = function(){
  6997. var div = document.createElement('div'),
  6998. doc = document,
  6999. view,
  7000. last;
  7001. div.innerHTML = '<div style="height:30px;width:50px;"><div style="height:20px;width:20px;"></div></div><div style="float:left;background-color:transparent;">';
  7002. doc.body.appendChild(div);
  7003. last = div.lastChild;
  7004. if((view = doc.defaultView)){
  7005. if(view.getComputedStyle(div.firstChild.firstChild, null).marginRight != '0px'){
  7006. supports.correctRightMargin = false;
  7007. }
  7008. if(view.getComputedStyle(last, null).backgroundColor != 'transparent'){
  7009. supports.correctTransparentColor = false;
  7010. }
  7011. }
  7012. supports.cssFloat = !!last.style.cssFloat;
  7013. doc.body.removeChild(div);
  7014. };
  7015. if (Ext.isReady) {
  7016. supportTests();
  7017. } else {
  7018. Ext.onReady(supportTests);
  7019. }
  7020. })();
  7021. /**
  7022. * @class Ext.EventObject
  7023. * Just as {@link Ext.Element} wraps around a native DOM node, Ext.EventObject
  7024. * wraps the browser's native event-object normalizing cross-browser differences,
  7025. * such as which mouse button is clicked, keys pressed, mechanisms to stop
  7026. * event-propagation along with a method to prevent default actions from taking place.
  7027. * <p>For example:</p>
  7028. * <pre><code>
  7029. function handleClick(e, t){ // e is not a standard event object, it is a Ext.EventObject
  7030. e.preventDefault();
  7031. var target = e.getTarget(); // same as t (the target HTMLElement)
  7032. ...
  7033. }
  7034. var myDiv = {@link Ext#get Ext.get}("myDiv"); // get reference to an {@link Ext.Element}
  7035. myDiv.on( // 'on' is shorthand for addListener
  7036. "click", // perform an action on click of myDiv
  7037. handleClick // reference to the action handler
  7038. );
  7039. // other methods to do the same:
  7040. Ext.EventManager.on("myDiv", 'click', handleClick);
  7041. Ext.EventManager.addListener("myDiv", 'click', handleClick);
  7042. </code></pre>
  7043. * @singleton
  7044. */
  7045. Ext.EventObject = function(){
  7046. var E = Ext.lib.Event,
  7047. clickRe = /(dbl)?click/,
  7048. // safari keypress events for special keys return bad keycodes
  7049. safariKeys = {
  7050. 3 : 13, // enter
  7051. 63234 : 37, // left
  7052. 63235 : 39, // right
  7053. 63232 : 38, // up
  7054. 63233 : 40, // down
  7055. 63276 : 33, // page up
  7056. 63277 : 34, // page down
  7057. 63272 : 46, // delete
  7058. 63273 : 36, // home
  7059. 63275 : 35 // end
  7060. },
  7061. // normalize button clicks
  7062. btnMap = Ext.isIE ? {1:0,4:1,2:2} : {0:0,1:1,2:2};
  7063. Ext.EventObjectImpl = function(e){
  7064. if(e){
  7065. this.setEvent(e.browserEvent || e);
  7066. }
  7067. };
  7068. Ext.EventObjectImpl.prototype = {
  7069. /** @private */
  7070. setEvent : function(e){
  7071. var me = this;
  7072. if(e == me || (e && e.browserEvent)){ // already wrapped
  7073. return e;
  7074. }
  7075. me.browserEvent = e;
  7076. if(e){
  7077. // normalize buttons
  7078. me.button = e.button ? btnMap[e.button] : (e.which ? e.which - 1 : -1);
  7079. if(clickRe.test(e.type) && me.button == -1){
  7080. me.button = 0;
  7081. }
  7082. me.type = e.type;
  7083. me.shiftKey = e.shiftKey;
  7084. // mac metaKey behaves like ctrlKey
  7085. me.ctrlKey = e.ctrlKey || e.metaKey || false;
  7086. me.altKey = e.altKey;
  7087. // in getKey these will be normalized for the mac
  7088. me.keyCode = e.keyCode;
  7089. me.charCode = e.charCode;
  7090. // cache the target for the delayed and or buffered events
  7091. me.target = E.getTarget(e);
  7092. // same for XY
  7093. me.xy = E.getXY(e);
  7094. }else{
  7095. me.button = -1;
  7096. me.shiftKey = false;
  7097. me.ctrlKey = false;
  7098. me.altKey = false;
  7099. me.keyCode = 0;
  7100. me.charCode = 0;
  7101. me.target = null;
  7102. me.xy = [0, 0];
  7103. }
  7104. return me;
  7105. },
  7106. /**
  7107. * Stop the event (preventDefault and stopPropagation)
  7108. */
  7109. stopEvent : function(){
  7110. var me = this;
  7111. if(me.browserEvent){
  7112. if(me.browserEvent.type == 'mousedown'){
  7113. Ext.EventManager.stoppedMouseDownEvent.fire(me);
  7114. }
  7115. E.stopEvent(me.browserEvent);
  7116. }
  7117. },
  7118. /**
  7119. * Prevents the browsers default handling of the event.
  7120. */
  7121. preventDefault : function(){
  7122. if(this.browserEvent){
  7123. E.preventDefault(this.browserEvent);
  7124. }
  7125. },
  7126. /**
  7127. * Cancels bubbling of the event.
  7128. */
  7129. stopPropagation : function(){
  7130. var me = this;
  7131. if(me.browserEvent){
  7132. if(me.browserEvent.type == 'mousedown'){
  7133. Ext.EventManager.stoppedMouseDownEvent.fire(me);
  7134. }
  7135. E.stopPropagation(me.browserEvent);
  7136. }
  7137. },
  7138. /**
  7139. * Gets the character code for the event.
  7140. * @return {Number}
  7141. */
  7142. getCharCode : function(){
  7143. return this.charCode || this.keyCode;
  7144. },
  7145. /**
  7146. * Returns a normalized keyCode for the event.
  7147. * @return {Number} The key code
  7148. */
  7149. getKey : function(){
  7150. return this.normalizeKey(this.keyCode || this.charCode);
  7151. },
  7152. // private
  7153. normalizeKey: function(k){
  7154. return Ext.isSafari ? (safariKeys[k] || k) : k;
  7155. },
  7156. /**
  7157. * Gets the x coordinate of the event.
  7158. * @return {Number}
  7159. */
  7160. getPageX : function(){
  7161. return this.xy[0];
  7162. },
  7163. /**
  7164. * Gets the y coordinate of the event.
  7165. * @return {Number}
  7166. */
  7167. getPageY : function(){
  7168. return this.xy[1];
  7169. },
  7170. /**
  7171. * Gets the page coordinates of the event.
  7172. * @return {Array} The xy values like [x, y]
  7173. */
  7174. getXY : function(){
  7175. return this.xy;
  7176. },
  7177. /**
  7178. * Gets the target for the event.
  7179. * @param {String} selector (optional) A simple selector to filter the target or look for an ancestor of the target
  7180. * @param {Number/Mixed} maxDepth (optional) The max depth to
  7181. search as a number or element (defaults to 10 || document.body)
  7182. * @param {Boolean} returnEl (optional) True to return a Ext.Element object instead of DOM node
  7183. * @return {HTMLelement}
  7184. */
  7185. getTarget : function(selector, maxDepth, returnEl){
  7186. return selector ? Ext.fly(this.target).findParent(selector, maxDepth, returnEl) : (returnEl ? Ext.get(this.target) : this.target);
  7187. },
  7188. /**
  7189. * Gets the related target.
  7190. * @return {HTMLElement}
  7191. */
  7192. getRelatedTarget : function(){
  7193. return this.browserEvent ? E.getRelatedTarget(this.browserEvent) : null;
  7194. },
  7195. /**
  7196. * Normalizes mouse wheel delta across browsers
  7197. * @return {Number} The delta
  7198. */
  7199. getWheelDelta : function(){
  7200. var e = this.browserEvent;
  7201. var delta = 0;
  7202. if(e.wheelDelta){ /* IE/Opera. */
  7203. delta = e.wheelDelta/120;
  7204. }else if(e.detail){ /* Mozilla case. */
  7205. delta = -e.detail/3;
  7206. }
  7207. return delta;
  7208. },
  7209. /**
  7210. * Returns true if the target of this event is a child of el. Unless the allowEl parameter is set, it will return false if if the target is el.
  7211. * Example usage:<pre><code>
  7212. // Handle click on any child of an element
  7213. Ext.getBody().on('click', function(e){
  7214. if(e.within('some-el')){
  7215. alert('Clicked on a child of some-el!');
  7216. }
  7217. });
  7218. // Handle click directly on an element, ignoring clicks on child nodes
  7219. Ext.getBody().on('click', function(e,t){
  7220. if((t.id == 'some-el') && !e.within(t, true)){
  7221. alert('Clicked directly on some-el!');
  7222. }
  7223. });
  7224. </code></pre>
  7225. * @param {Mixed} el The id, DOM element or Ext.Element to check
  7226. * @param {Boolean} related (optional) true to test if the related target is within el instead of the target
  7227. * @param {Boolean} allowEl {optional} true to also check if the passed element is the target or related target
  7228. * @return {Boolean}
  7229. */
  7230. within : function(el, related, allowEl){
  7231. if(el){
  7232. var t = this[related ? "getRelatedTarget" : "getTarget"]();
  7233. return t && ((allowEl ? (t == Ext.getDom(el)) : false) || Ext.fly(el).contains(t));
  7234. }
  7235. return false;
  7236. }
  7237. };
  7238. return new Ext.EventObjectImpl();
  7239. }();
  7240. /**
  7241. * @class Ext.Loader
  7242. * @singleton
  7243. * Simple class to help load JavaScript files on demand
  7244. */
  7245. Ext.Loader = Ext.apply({}, {
  7246. /**
  7247. * Loads a given set of .js files. Calls the callback function when all files have been loaded
  7248. * Set preserveOrder to true to ensure non-parallel loading of files if load order is important
  7249. * @param {Array} fileList Array of all files to load
  7250. * @param {Function} callback Callback to call after all files have been loaded
  7251. * @param {Object} scope The scope to call the callback in
  7252. * @param {Boolean} preserveOrder True to make files load in serial, one after the other (defaults to false)
  7253. */
  7254. load: function(fileList, callback, scope, preserveOrder) {
  7255. var scope = scope || this,
  7256. head = document.getElementsByTagName("head")[0],
  7257. fragment = document.createDocumentFragment(),
  7258. numFiles = fileList.length,
  7259. loadedFiles = 0,
  7260. me = this;
  7261. /**
  7262. * Loads a particular file from the fileList by index. This is used when preserving order
  7263. */
  7264. var loadFileIndex = function(index) {
  7265. head.appendChild(
  7266. me.buildScriptTag(fileList[index], onFileLoaded)
  7267. );
  7268. };
  7269. /**
  7270. * Callback function which is called after each file has been loaded. This calls the callback
  7271. * passed to load once the final file in the fileList has been loaded
  7272. */
  7273. var onFileLoaded = function() {
  7274. loadedFiles ++;
  7275. //if this was the last file, call the callback, otherwise load the next file
  7276. if (numFiles == loadedFiles && typeof callback == 'function') {
  7277. callback.call(scope);
  7278. } else {
  7279. if (preserveOrder === true) {
  7280. loadFileIndex(loadedFiles);
  7281. }
  7282. }
  7283. };
  7284. if (preserveOrder === true) {
  7285. loadFileIndex.call(this, 0);
  7286. } else {
  7287. //load each file (most browsers will do this in parallel)
  7288. Ext.each(fileList, function(file, index) {
  7289. fragment.appendChild(
  7290. this.buildScriptTag(file, onFileLoaded)
  7291. );
  7292. }, this);
  7293. head.appendChild(fragment);
  7294. }
  7295. },
  7296. /**
  7297. * @private
  7298. * Creates and returns a script tag, but does not place it into the document. If a callback function
  7299. * is passed, this is called when the script has been loaded
  7300. * @param {String} filename The name of the file to create a script tag for
  7301. * @param {Function} callback Optional callback, which is called when the script has been loaded
  7302. * @return {Element} The new script ta
  7303. */
  7304. buildScriptTag: function(filename, callback) {
  7305. var script = document.createElement('script');
  7306. script.type = "text/javascript";
  7307. script.src = filename;
  7308. //IE has a different way of handling &lt;script&gt; loads, so we need to check for it here
  7309. if (script.readyState) {
  7310. script.onreadystatechange = function() {
  7311. if (script.readyState == "loaded" || script.readyState == "complete") {
  7312. script.onreadystatechange = null;
  7313. callback();
  7314. }
  7315. };
  7316. } else {
  7317. script.onload = callback;
  7318. }
  7319. return script;
  7320. }
  7321. });