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.

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