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.

8051 lines
298 KiB

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