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.

4839 lines
160 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
2 years ago
​
2 years ago
​
​
2 years ago
​
​
​
2 years ago
​
2 years ago
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
2 years ago
2 years ago
​
2 years ago
2 years ago
​
​
2 years ago
​
​
​
2 years ago
​
​
​
​
​
2 years ago
​
​
​
​
​
2 years ago
​
​
​
2 years ago
​
​
​
​
2 years ago
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  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. * These classes are derivatives of the similarly named classes in the YUI Library.
  17. * The original license:
  18. * Copyright (c) 2006, Yahoo! Inc. All rights reserved.
  19. * Code licensed under the BSD License:
  20. * http://developer.yahoo.net/yui/license.txt
  21. */
  22. (function() {
  23. var Event=Ext.EventManager;
  24. var Dom=Ext.lib.Dom;
  25. /**
  26. * @class Ext.dd.DragDrop
  27. * Defines the interface and base operation of items that that can be
  28. * dragged or can be drop targets. It was designed to be extended, overriding
  29. * the event handlers for startDrag, onDrag, onDragOver and onDragOut.
  30. * Up to three html elements can be associated with a DragDrop instance:
  31. * <ul>
  32. * <li>linked element: the element that is passed into the constructor.
  33. * This is the element which defines the boundaries for interaction with
  34. * other DragDrop objects.</li>
  35. * <li>handle element(s): The drag operation only occurs if the element that
  36. * was clicked matches a handle element. By default this is the linked
  37. * element, but there are times that you will want only a portion of the
  38. * linked element to initiate the drag operation, and the setHandleElId()
  39. * method provides a way to define this.</li>
  40. * <li>drag element: this represents the element that would be moved along
  41. * with the cursor during a drag operation. By default, this is the linked
  42. * element itself as in {@link Ext.dd.DD}. setDragElId() lets you define
  43. * a separate element that would be moved, as in {@link Ext.dd.DDProxy}.
  44. * </li>
  45. * </ul>
  46. * This class should not be instantiated until the onload event to ensure that
  47. * the associated elements are available.
  48. * The following would define a DragDrop obj that would interact with any
  49. * other DragDrop obj in the "group1" group:
  50. * <pre>
  51. * dd = new Ext.dd.DragDrop("div1", "group1");
  52. * </pre>
  53. * Since none of the event handlers have been implemented, nothing would
  54. * actually happen if you were to run the code above. Normally you would
  55. * override this class or one of the default implementations, but you can
  56. * also override the methods you want on an instance of the class...
  57. * <pre>
  58. * dd.onDragDrop = function(e, id) {
  59. * &nbsp;&nbsp;alert("dd was dropped on " + id);
  60. * }
  61. * </pre>
  62. * @constructor
  63. * @param {String} id of the element that is linked to this instance
  64. * @param {String} sGroup the group of related DragDrop objects
  65. * @param {object} config an object containing configurable attributes
  66. * Valid properties for DragDrop:
  67. * padding, isTarget, maintainOffset, primaryButtonOnly
  68. */
  69. Ext.dd.DragDrop = function(id, sGroup, config) {
  70. if(id) {
  71. this.init(id, sGroup, config);
  72. }
  73. };
  74. Ext.dd.DragDrop.prototype = {
  75. /**
  76. * Set to false to enable a DragDrop object to fire drag events while dragging
  77. * over its own Element. Defaults to true - DragDrop objects do not by default
  78. * fire drag events to themselves.
  79. * @property ignoreSelf
  80. * @type Boolean
  81. */
  82. /**
  83. * The id of the element associated with this object. This is what we
  84. * refer to as the "linked element" because the size and position of
  85. * this element is used to determine when the drag and drop objects have
  86. * interacted.
  87. * @property id
  88. * @type String
  89. */
  90. id: null,
  91. /**
  92. * Configuration attributes passed into the constructor
  93. * @property config
  94. * @type object
  95. */
  96. config: null,
  97. /**
  98. * The id of the element that will be dragged. By default this is same
  99. * as the linked element, but could be changed to another element. Ex:
  100. * Ext.dd.DDProxy
  101. * @property dragElId
  102. * @type String
  103. * @private
  104. */
  105. dragElId: null,
  106. /**
  107. * The ID of the element that initiates the drag operation. By default
  108. * this is the linked element, but could be changed to be a child of this
  109. * element. This lets us do things like only starting the drag when the
  110. * header element within the linked html element is clicked.
  111. * @property handleElId
  112. * @type String
  113. * @private
  114. */
  115. handleElId: null,
  116. /**
  117. * An object who's property names identify HTML tags to be considered invalid as drag handles.
  118. * A non-null property value identifies the tag as invalid. Defaults to the
  119. * following value which prevents drag operations from being initiated by &lt;a> elements:<pre><code>
  120. {
  121. A: "A"
  122. }</code></pre>
  123. * @property invalidHandleTypes
  124. * @type Object
  125. */
  126. invalidHandleTypes: null,
  127. /**
  128. * An object who's property names identify the IDs of elements to be considered invalid as drag handles.
  129. * A non-null property value identifies the ID as invalid. For example, to prevent
  130. * dragging from being initiated on element ID "foo", use:<pre><code>
  131. {
  132. foo: true
  133. }</code></pre>
  134. * @property invalidHandleIds
  135. * @type Object
  136. */
  137. invalidHandleIds: null,
  138. /**
  139. * An Array of CSS class names for elements to be considered in valid as drag handles.
  140. * @property invalidHandleClasses
  141. * @type Array
  142. */
  143. invalidHandleClasses: null,
  144. /**
  145. * The linked element's absolute X position at the time the drag was
  146. * started
  147. * @property startPageX
  148. * @type int
  149. * @private
  150. */
  151. startPageX: 0,
  152. /**
  153. * The linked element's absolute X position at the time the drag was
  154. * started
  155. * @property startPageY
  156. * @type int
  157. * @private
  158. */
  159. startPageY: 0,
  160. /**
  161. * The group defines a logical collection of DragDrop objects that are
  162. * related. Instances only get events when interacting with other
  163. * DragDrop object in the same group. This lets us define multiple
  164. * groups using a single DragDrop subclass if we want.
  165. * @property groups
  166. * @type object An object in the format {'group1':true, 'group2':true}
  167. */
  168. groups: null,
  169. /**
  170. * Individual drag/drop instances can be locked. This will prevent
  171. * onmousedown start drag.
  172. * @property locked
  173. * @type boolean
  174. * @private
  175. */
  176. locked: false,
  177. /**
  178. * Lock this instance
  179. * @method lock
  180. */
  181. lock: function() {
  182. this.locked = true;
  183. },
  184. /**
  185. * When set to true, other DD objects in cooperating DDGroups do not receive
  186. * notification events when this DD object is dragged over them. Defaults to false.
  187. * @property moveOnly
  188. * @type boolean
  189. */
  190. moveOnly: false,
  191. /**
  192. * Unlock this instace
  193. * @method unlock
  194. */
  195. unlock: function() {
  196. this.locked = false;
  197. },
  198. /**
  199. * By default, all instances can be a drop target. This can be disabled by
  200. * setting isTarget to false.
  201. * @property isTarget
  202. * @type boolean
  203. */
  204. isTarget: true,
  205. /**
  206. * The padding configured for this drag and drop object for calculating
  207. * the drop zone intersection with this object.
  208. * @property padding
  209. * @type int[] An array containing the 4 padding values: [top, right, bottom, left]
  210. */
  211. padding: null,
  212. /**
  213. * Cached reference to the linked element
  214. * @property _domRef
  215. * @private
  216. */
  217. _domRef: null,
  218. /**
  219. * Internal typeof flag
  220. * @property __ygDragDrop
  221. * @private
  222. */
  223. __ygDragDrop: true,
  224. /**
  225. * Set to true when horizontal contraints are applied
  226. * @property constrainX
  227. * @type boolean
  228. * @private
  229. */
  230. constrainX: false,
  231. /**
  232. * Set to true when vertical contraints are applied
  233. * @property constrainY
  234. * @type boolean
  235. * @private
  236. */
  237. constrainY: false,
  238. /**
  239. * The left constraint
  240. * @property minX
  241. * @type int
  242. * @private
  243. */
  244. minX: 0,
  245. /**
  246. * The right constraint
  247. * @property maxX
  248. * @type int
  249. * @private
  250. */
  251. maxX: 0,
  252. /**
  253. * The up constraint
  254. * @property minY
  255. * @type int
  256. * @private
  257. */
  258. minY: 0,
  259. /**
  260. * The down constraint
  261. * @property maxY
  262. * @type int
  263. * @private
  264. */
  265. maxY: 0,
  266. /**
  267. * Maintain offsets when we resetconstraints. Set to true when you want
  268. * the position of the element relative to its parent to stay the same
  269. * when the page changes
  270. *
  271. * @property maintainOffset
  272. * @type boolean
  273. */
  274. maintainOffset: false,
  275. /**
  276. * Array of pixel locations the element will snap to if we specified a
  277. * horizontal graduation/interval. This array is generated automatically
  278. * when you define a tick interval.
  279. * @property xTicks
  280. * @type int[]
  281. */
  282. xTicks: null,
  283. /**
  284. * Array of pixel locations the element will snap to if we specified a
  285. * vertical graduation/interval. This array is generated automatically
  286. * when you define a tick interval.
  287. * @property yTicks
  288. * @type int[]
  289. */
  290. yTicks: null,
  291. /**
  292. * By default the drag and drop instance will only respond to the primary
  293. * button click (left button for a right-handed mouse). Set to true to
  294. * allow drag and drop to start with any mouse click that is propogated
  295. * by the browser
  296. * @property primaryButtonOnly
  297. * @type boolean
  298. */
  299. primaryButtonOnly: true,
  300. /**
  301. * The available property is false until the linked dom element is accessible.
  302. * @property available
  303. * @type boolean
  304. */
  305. available: false,
  306. /**
  307. * By default, drags can only be initiated if the mousedown occurs in the
  308. * region the linked element is. This is done in part to work around a
  309. * bug in some browsers that mis-report the mousedown if the previous
  310. * mouseup happened outside of the window. This property is set to true
  311. * if outer handles are defined.
  312. *
  313. * @property hasOuterHandles
  314. * @type boolean
  315. * @default false
  316. */
  317. hasOuterHandles: false,
  318. /**
  319. * Code that executes immediately before the startDrag event
  320. * @method b4StartDrag
  321. * @private
  322. */
  323. b4StartDrag: function(x, y) { },
  324. /**
  325. * Abstract method called after a drag/drop object is clicked
  326. * and the drag or mousedown time thresholds have beeen met.
  327. * @method startDrag
  328. * @param {int} X click location
  329. * @param {int} Y click location
  330. */
  331. startDrag: function(x, y) { /* override this */ },
  332. /**
  333. * Code that executes immediately before the onDrag event
  334. * @method b4Drag
  335. * @private
  336. */
  337. b4Drag: function(e) { },
  338. /**
  339. * Abstract method called during the onMouseMove event while dragging an
  340. * object.
  341. * @method onDrag
  342. * @param {Event} e the mousemove event
  343. */
  344. onDrag: function(e) { /* override this */ },
  345. /**
  346. * Abstract method called when this element fist begins hovering over
  347. * another DragDrop obj
  348. * @method onDragEnter
  349. * @param {Event} e the mousemove event
  350. * @param {String|DragDrop[]} id In POINT mode, the element
  351. * id this is hovering over. In INTERSECT mode, an array of one or more
  352. * dragdrop items being hovered over.
  353. */
  354. onDragEnter: function(e, id) { /* override this */ },
  355. /**
  356. * Code that executes immediately before the onDragOver event
  357. * @method b4DragOver
  358. * @private
  359. */
  360. b4DragOver: function(e) { },
  361. /**
  362. * Abstract method called when this element is hovering over another
  363. * DragDrop obj
  364. * @method onDragOver
  365. * @param {Event} e the mousemove event
  366. * @param {String|DragDrop[]} id In POINT mode, the element
  367. * id this is hovering over. In INTERSECT mode, an array of dd items
  368. * being hovered over.
  369. */
  370. onDragOver: function(e, id) { /* override this */ },
  371. /**
  372. * Code that executes immediately before the onDragOut event
  373. * @method b4DragOut
  374. * @private
  375. */
  376. b4DragOut: function(e) { },
  377. /**
  378. * Abstract method called when we are no longer hovering over an element
  379. * @method onDragOut
  380. * @param {Event} e the mousemove event
  381. * @param {String|DragDrop[]} id In POINT mode, the element
  382. * id this was hovering over. In INTERSECT mode, an array of dd items
  383. * that the mouse is no longer over.
  384. */
  385. onDragOut: function(e, id) { /* override this */ },
  386. /**
  387. * Code that executes immediately before the onDragDrop event
  388. * @method b4DragDrop
  389. * @private
  390. */
  391. b4DragDrop: function(e) { },
  392. /**
  393. * Abstract method called when this item is dropped on another DragDrop
  394. * obj
  395. * @method onDragDrop
  396. * @param {Event} e the mouseup event
  397. * @param {String|DragDrop[]} id In POINT mode, the element
  398. * id this was dropped on. In INTERSECT mode, an array of dd items this
  399. * was dropped on.
  400. */
  401. onDragDrop: function(e, id) { /* override this */ },
  402. /**
  403. * Abstract method called when this item is dropped on an area with no
  404. * drop target
  405. * @method onInvalidDrop
  406. * @param {Event} e the mouseup event
  407. */
  408. onInvalidDrop: function(e) { /* override this */ },
  409. /**
  410. * Code that executes immediately before the endDrag event
  411. * @method b4EndDrag
  412. * @private
  413. */
  414. b4EndDrag: function(e) { },
  415. /**
  416. * Fired when we are done dragging the object
  417. * @method endDrag
  418. * @param {Event} e the mouseup event
  419. */
  420. endDrag: function(e) { /* override this */ },
  421. /**
  422. * Code executed immediately before the onMouseDown event
  423. * @method b4MouseDown
  424. * @param {Event} e the mousedown event
  425. * @private
  426. */
  427. b4MouseDown: function(e) { },
  428. /**
  429. * Event handler that fires when a drag/drop obj gets a mousedown
  430. * @method onMouseDown
  431. * @param {Event} e the mousedown event
  432. */
  433. onMouseDown: function(e) { /* override this */ },
  434. /**
  435. * Event handler that fires when a drag/drop obj gets a mouseup
  436. * @method onMouseUp
  437. * @param {Event} e the mouseup event
  438. */
  439. onMouseUp: function(e) { /* override this */ },
  440. /**
  441. * Override the onAvailable method to do what is needed after the initial
  442. * position was determined.
  443. * @method onAvailable
  444. */
  445. onAvailable: function () {
  446. },
  447. /**
  448. * Provides default constraint padding to "constrainTo" elements (defaults to {left: 0, right:0, top:0, bottom:0}).
  449. * @type Object
  450. */
  451. defaultPadding : {left:0, right:0, top:0, bottom:0},
  452. /**
  453. * Initializes the drag drop object's constraints to restrict movement to a certain element.
  454. *
  455. * Usage:
  456. <pre><code>
  457. var dd = new Ext.dd.DDProxy("dragDiv1", "proxytest",
  458. { dragElId: "existingProxyDiv" });
  459. dd.startDrag = function(){
  460. this.constrainTo("parent-id");
  461. };
  462. </code></pre>
  463. * Or you can initalize it using the {@link Ext.Element} object:
  464. <pre><code>
  465. Ext.get("dragDiv1").initDDProxy("proxytest", {dragElId: "existingProxyDiv"}, {
  466. startDrag : function(){
  467. this.constrainTo("parent-id");
  468. }
  469. });
  470. </code></pre>
  471. * @param {Mixed} constrainTo The element to constrain to.
  472. * @param {Object/Number} pad (optional) Pad provides a way to specify "padding" of the constraints,
  473. * and can be either a number for symmetrical padding (4 would be equal to {left:4, right:4, top:4, bottom:4}) or
  474. * an object containing the sides to pad. For example: {right:10, bottom:10}
  475. * @param {Boolean} inContent (optional) Constrain the draggable in the content box of the element (inside padding and borders)
  476. */
  477. constrainTo : function(constrainTo, pad, inContent){
  478. if(Ext.isNumber(pad)){
  479. pad = {left: pad, right:pad, top:pad, bottom:pad};
  480. }
  481. pad = pad || this.defaultPadding;
  482. var b = Ext.get(this.getEl()).getBox(),
  483. ce = Ext.get(constrainTo),
  484. s = ce.getScroll(),
  485. c,
  486. cd = ce.dom;
  487. if(cd == document.body){
  488. c = { x: s.left, y: s.top, width: Ext.lib.Dom.getViewWidth(), height: Ext.lib.Dom.getViewHeight()};
  489. }else{
  490. var xy = ce.getXY();
  491. c = {x : xy[0], y: xy[1], width: cd.clientWidth, height: cd.clientHeight};
  492. }
  493. var topSpace = b.y - c.y,
  494. leftSpace = b.x - c.x;
  495. this.resetConstraints();
  496. this.setXConstraint(leftSpace - (pad.left||0), // left
  497. c.width - leftSpace - b.width - (pad.right||0), //right
  498. this.xTickSize
  499. );
  500. this.setYConstraint(topSpace - (pad.top||0), //top
  501. c.height - topSpace - b.height - (pad.bottom||0), //bottom
  502. this.yTickSize
  503. );
  504. },
  505. /**
  506. * Returns a reference to the linked element
  507. * @method getEl
  508. * @return {HTMLElement} the html element
  509. */
  510. getEl: function() {
  511. if (!this._domRef) {
  512. this._domRef = Ext.getDom(this.id);
  513. }
  514. return this._domRef;
  515. },
  516. /**
  517. * Returns a reference to the actual element to drag. By default this is
  518. * the same as the html element, but it can be assigned to another
  519. * element. An example of this can be found in Ext.dd.DDProxy
  520. * @method getDragEl
  521. * @return {HTMLElement} the html element
  522. */
  523. getDragEl: function() {
  524. return Ext.getDom(this.dragElId);
  525. },
  526. /**
  527. * Sets up the DragDrop object. Must be called in the constructor of any
  528. * Ext.dd.DragDrop subclass
  529. * @method init
  530. * @param id the id of the linked element
  531. * @param {String} sGroup the group of related items
  532. * @param {object} config configuration attributes
  533. */
  534. init: function(id, sGroup, config) {
  535. this.initTarget(id, sGroup, config);
  536. Event.on(this.id, "mousedown", this.handleMouseDown, this);
  537. // Event.on(this.id, "selectstart", Event.preventDefault);
  538. },
  539. /**
  540. * Initializes Targeting functionality only... the object does not
  541. * get a mousedown handler.
  542. * @method initTarget
  543. * @param id the id of the linked element
  544. * @param {String} sGroup the group of related items
  545. * @param {object} config configuration attributes
  546. */
  547. initTarget: function(id, sGroup, config) {
  548. // configuration attributes
  549. this.config = config || {};
  550. // create a local reference to the drag and drop manager
  551. this.DDM = Ext.dd.DDM;
  552. // initialize the groups array
  553. this.groups = {};
  554. // assume that we have an element reference instead of an id if the
  555. // parameter is not a string
  556. if (typeof id !== "string") {
  557. id = Ext.id(id);
  558. }
  559. // set the id
  560. this.id = id;
  561. // add to an interaction group
  562. this.addToGroup((sGroup) ? sGroup : "default");
  563. // We don't want to register this as the handle with the manager
  564. // so we just set the id rather than calling the setter.
  565. this.handleElId = id;
  566. // the linked element is the element that gets dragged by default
  567. this.setDragElId(id);
  568. // by default, clicked anchors will not start drag operations.
  569. this.invalidHandleTypes = { A: "A" };
  570. this.invalidHandleIds = {};
  571. this.invalidHandleClasses = [];
  572. this.applyConfig();
  573. this.handleOnAvailable();
  574. },
  575. /**
  576. * Applies the configuration parameters that were passed into the constructor.
  577. * This is supposed to happen at each level through the inheritance chain. So
  578. * a DDProxy implentation will execute apply config on DDProxy, DD, and
  579. * DragDrop in order to get all of the parameters that are available in
  580. * each object.
  581. * @method applyConfig
  582. */
  583. applyConfig: function() {
  584. // configurable properties:
  585. // padding, isTarget, maintainOffset, primaryButtonOnly
  586. this.padding = this.config.padding || [0, 0, 0, 0];
  587. this.isTarget = (this.config.isTarget !== false);
  588. this.maintainOffset = (this.config.maintainOffset);
  589. this.primaryButtonOnly = (this.config.primaryButtonOnly !== false);
  590. },
  591. /**
  592. * Executed when the linked element is available
  593. * @method handleOnAvailable
  594. * @private
  595. */
  596. handleOnAvailable: function() {
  597. this.available = true;
  598. this.resetConstraints();
  599. this.onAvailable();
  600. },
  601. /**
  602. * Configures the padding for the target zone in px. Effectively expands
  603. * (or reduces) the virtual object size for targeting calculations.
  604. * Supports css-style shorthand; if only one parameter is passed, all sides
  605. * will have that padding, and if only two are passed, the top and bottom
  606. * will have the first param, the left and right the second.
  607. * @method setPadding
  608. * @param {int} iTop Top pad
  609. * @param {int} iRight Right pad
  610. * @param {int} iBot Bot pad
  611. * @param {int} iLeft Left pad
  612. */
  613. setPadding: function(iTop, iRight, iBot, iLeft) {
  614. // this.padding = [iLeft, iRight, iTop, iBot];
  615. if (!iRight && 0 !== iRight) {
  616. this.padding = [iTop, iTop, iTop, iTop];
  617. } else if (!iBot && 0 !== iBot) {
  618. this.padding = [iTop, iRight, iTop, iRight];
  619. } else {
  620. this.padding = [iTop, iRight, iBot, iLeft];
  621. }
  622. },
  623. /**
  624. * Stores the initial placement of the linked element.
  625. * @method setInitPosition
  626. * @param {int} diffX the X offset, default 0
  627. * @param {int} diffY the Y offset, default 0
  628. */
  629. setInitPosition: function(diffX, diffY) {
  630. var el = this.getEl();
  631. if (!this.DDM.verifyEl(el)) {
  632. return;
  633. }
  634. var dx = diffX || 0;
  635. var dy = diffY || 0;
  636. var p = Dom.getXY( el );
  637. this.initPageX = p[0] - dx;
  638. this.initPageY = p[1] - dy;
  639. this.lastPageX = p[0];
  640. this.lastPageY = p[1];
  641. this.setStartPosition(p);
  642. },
  643. /**
  644. * Sets the start position of the element. This is set when the obj
  645. * is initialized, the reset when a drag is started.
  646. * @method setStartPosition
  647. * @param pos current position (from previous lookup)
  648. * @private
  649. */
  650. setStartPosition: function(pos) {
  651. var p = pos || Dom.getXY( this.getEl() );
  652. this.deltaSetXY = null;
  653. this.startPageX = p[0];
  654. this.startPageY = p[1];
  655. },
  656. /**
  657. * Add this instance to a group of related drag/drop objects. All
  658. * instances belong to at least one group, and can belong to as many
  659. * groups as needed.
  660. * @method addToGroup
  661. * @param sGroup {string} the name of the group
  662. */
  663. addToGroup: function(sGroup) {
  664. this.groups[sGroup] = true;
  665. this.DDM.regDragDrop(this, sGroup);
  666. },
  667. /**
  668. * Remove's this instance from the supplied interaction group
  669. * @method removeFromGroup
  670. * @param {string} sGroup The group to drop
  671. */
  672. removeFromGroup: function(sGroup) {
  673. if (this.groups[sGroup]) {
  674. delete this.groups[sGroup];
  675. }
  676. this.DDM.removeDDFromGroup(this, sGroup);
  677. },
  678. /**
  679. * Allows you to specify that an element other than the linked element
  680. * will be moved with the cursor during a drag
  681. * @method setDragElId
  682. * @param id {string} the id of the element that will be used to initiate the drag
  683. */
  684. setDragElId: function(id) {
  685. this.dragElId = id;
  686. },
  687. /**
  688. * Allows you to specify a child of the linked element that should be
  689. * used to initiate the drag operation. An example of this would be if
  690. * you have a content div with text and links. Clicking anywhere in the
  691. * content area would normally start the drag operation. Use this method
  692. * to specify that an element inside of the content div is the element
  693. * that starts the drag operation.
  694. * @method setHandleElId
  695. * @param id {string} the id of the element that will be used to
  696. * initiate the drag.
  697. */
  698. setHandleElId: function(id) {
  699. if (typeof id !== "string") {
  700. id = Ext.id(id);
  701. }
  702. this.handleElId = id;
  703. this.DDM.regHandle(this.id, id);
  704. },
  705. /**
  706. * Allows you to set an element outside of the linked element as a drag
  707. * handle
  708. * @method setOuterHandleElId
  709. * @param id the id of the element that will be used to initiate the drag
  710. */
  711. setOuterHandleElId: function(id) {
  712. if (typeof id !== "string") {
  713. id = Ext.id(id);
  714. }
  715. Event.on(id, "mousedown",
  716. this.handleMouseDown, this);
  717. this.setHandleElId(id);
  718. this.hasOuterHandles = true;
  719. },
  720. /**
  721. * Remove all drag and drop hooks for this element
  722. * @method unreg
  723. */
  724. unreg: function() {
  725. Event.un(this.id, "mousedown",
  726. this.handleMouseDown);
  727. this._domRef = null;
  728. this.DDM._remove(this);
  729. },
  730. destroy : function(){
  731. this.unreg();
  732. },
  733. /**
  734. * Returns true if this instance is locked, or the drag drop mgr is locked
  735. * (meaning that all drag/drop is disabled on the page.)
  736. * @method isLocked
  737. * @return {boolean} true if this obj or all drag/drop is locked, else
  738. * false
  739. */
  740. isLocked: function() {
  741. return (this.DDM.isLocked() || this.locked);
  742. },
  743. /**
  744. * Fired when this object is clicked
  745. * @method handleMouseDown
  746. * @param {Event} e
  747. * @param {Ext.dd.DragDrop} oDD the clicked dd object (this dd obj)
  748. * @private
  749. */
  750. handleMouseDown: function(e, oDD){
  751. if (this.primaryButtonOnly && e.button != 0) {
  752. return;
  753. }
  754. if (this.isLocked()) {
  755. return;
  756. }
  757. this.DDM.refreshCache(this.groups);
  758. var pt = new Ext.lib.Point(Ext.lib.Event.getPageX(e), Ext.lib.Event.getPageY(e));
  759. if (!this.hasOuterHandles && !this.DDM.isOverTarget(pt, this) ) {
  760. } else {
  761. if (this.clickValidator(e)) {
  762. // set the initial element position
  763. this.setStartPosition();
  764. this.b4MouseDown(e);
  765. this.onMouseDown(e);
  766. this.DDM.handleMouseDown(e, this);
  767. if (this.preventDefault || this.stopPropagation) {
  768. if (this.preventDefault) {
  769. e.preventDefault();
  770. }
  771. if (this.stopPropagation) {
  772. e.stopPropagation();
  773. }
  774. } else {
  775. this.DDM.stopEvent(e);
  776. }
  777. } else {
  778. }
  779. }
  780. },
  781. clickValidator: function(e) {
  782. var target = e.getTarget();
  783. return ( this.isValidHandleChild(target) &&
  784. (this.id == this.handleElId ||
  785. this.DDM.handleWasClicked(target, this.id)) );
  786. },
  787. /**
  788. * Allows you to specify a tag name that should not start a drag operation
  789. * when clicked. This is designed to facilitate embedding links within a
  790. * drag handle that do something other than start the drag.
  791. * @method addInvalidHandleType
  792. * @param {string} tagName the type of element to exclude
  793. */
  794. addInvalidHandleType: function(tagName) {
  795. var type = tagName.toUpperCase();
  796. this.invalidHandleTypes[type] = type;
  797. },
  798. /**
  799. * Lets you to specify an element id for a child of a drag handle
  800. * that should not initiate a drag
  801. * @method addInvalidHandleId
  802. * @param {string} id the element id of the element you wish to ignore
  803. */
  804. addInvalidHandleId: function(id) {
  805. if (typeof id !== "string") {
  806. id = Ext.id(id);
  807. }
  808. this.invalidHandleIds[id] = id;
  809. },
  810. /**
  811. * Lets you specify a css class of elements that will not initiate a drag
  812. * @method addInvalidHandleClass
  813. * @param {string} cssClass the class of the elements you wish to ignore
  814. */
  815. addInvalidHandleClass: function(cssClass) {
  816. this.invalidHandleClasses.push(cssClass);
  817. },
  818. /**
  819. * Unsets an excluded tag name set by addInvalidHandleType
  820. * @method removeInvalidHandleType
  821. * @param {string} tagName the type of element to unexclude
  822. */
  823. removeInvalidHandleType: function(tagName) {
  824. var type = tagName.toUpperCase();
  825. // this.invalidHandleTypes[type] = null;
  826. delete this.invalidHandleTypes[type];
  827. },
  828. /**
  829. * Unsets an invalid handle id
  830. * @method removeInvalidHandleId
  831. * @param {string} id the id of the element to re-enable
  832. */
  833. removeInvalidHandleId: function(id) {
  834. if (typeof id !== "string") {
  835. id = Ext.id(id);
  836. }
  837. delete this.invalidHandleIds[id];
  838. },
  839. /**
  840. * Unsets an invalid css class
  841. * @method removeInvalidHandleClass
  842. * @param {string} cssClass the class of the element(s) you wish to
  843. * re-enable
  844. */
  845. removeInvalidHandleClass: function(cssClass) {
  846. for (var i=0, len=this.invalidHandleClasses.length; i<len; ++i) {
  847. if (this.invalidHandleClasses[i] == cssClass) {
  848. delete this.invalidHandleClasses[i];
  849. }
  850. }
  851. },
  852. /**
  853. * Checks the tag exclusion list to see if this click should be ignored
  854. * @method isValidHandleChild
  855. * @param {HTMLElement} node the HTMLElement to evaluate
  856. * @return {boolean} true if this is a valid tag type, false if not
  857. */
  858. isValidHandleChild: function(node) {
  859. var valid = true;
  860. // var n = (node.nodeName == "#text") ? node.parentNode : node;
  861. var nodeName;
  862. try {
  863. nodeName = node.nodeName.toUpperCase();
  864. } catch(e) {
  865. nodeName = node.nodeName;
  866. }
  867. valid = valid && !this.invalidHandleTypes[nodeName];
  868. valid = valid && !this.invalidHandleIds[node.id];
  869. for (var i=0, len=this.invalidHandleClasses.length; valid && i<len; ++i) {
  870. valid = !Ext.fly(node).hasClass(this.invalidHandleClasses[i]);
  871. }
  872. return valid;
  873. },
  874. /**
  875. * Create the array of horizontal tick marks if an interval was specified
  876. * in setXConstraint().
  877. * @method setXTicks
  878. * @private
  879. */
  880. setXTicks: function(iStartX, iTickSize) {
  881. this.xTicks = [];
  882. this.xTickSize = iTickSize;
  883. var tickMap = {};
  884. for (var i = this.initPageX; i >= this.minX; i = i - iTickSize) {
  885. if (!tickMap[i]) {
  886. this.xTicks[this.xTicks.length] = i;
  887. tickMap[i] = true;
  888. }
  889. }
  890. for (i = this.initPageX; i <= this.maxX; i = i + iTickSize) {
  891. if (!tickMap[i]) {
  892. this.xTicks[this.xTicks.length] = i;
  893. tickMap[i] = true;
  894. }
  895. }
  896. this.xTicks.sort(this.DDM.numericSort) ;
  897. },
  898. /**
  899. * Create the array of vertical tick marks if an interval was specified in
  900. * setYConstraint().
  901. * @method setYTicks
  902. * @private
  903. */
  904. setYTicks: function(iStartY, iTickSize) {
  905. this.yTicks = [];
  906. this.yTickSize = iTickSize;
  907. var tickMap = {};
  908. for (var i = this.initPageY; i >= this.minY; i = i - iTickSize) {
  909. if (!tickMap[i]) {
  910. this.yTicks[this.yTicks.length] = i;
  911. tickMap[i] = true;
  912. }
  913. }
  914. for (i = this.initPageY; i <= this.maxY; i = i + iTickSize) {
  915. if (!tickMap[i]) {
  916. this.yTicks[this.yTicks.length] = i;
  917. tickMap[i] = true;
  918. }
  919. }
  920. this.yTicks.sort(this.DDM.numericSort) ;
  921. },
  922. /**
  923. * By default, the element can be dragged any place on the screen. Use
  924. * this method to limit the horizontal travel of the element. Pass in
  925. * 0,0 for the parameters if you want to lock the drag to the y axis.
  926. * @method setXConstraint
  927. * @param {int} iLeft the number of pixels the element can move to the left
  928. * @param {int} iRight the number of pixels the element can move to the
  929. * right
  930. * @param {int} iTickSize optional parameter for specifying that the
  931. * element
  932. * should move iTickSize pixels at a time.
  933. */
  934. setXConstraint: function(iLeft, iRight, iTickSize) {
  935. this.leftConstraint = iLeft;
  936. this.rightConstraint = iRight;
  937. this.minX = this.initPageX - iLeft;
  938. this.maxX = this.initPageX + iRight;
  939. if (iTickSize) { this.setXTicks(this.initPageX, iTickSize); }
  940. this.constrainX = true;
  941. },
  942. /**
  943. * Clears any constraints applied to this instance. Also clears ticks
  944. * since they can't exist independent of a constraint at this time.
  945. * @method clearConstraints
  946. */
  947. clearConstraints: function() {
  948. this.constrainX = false;
  949. this.constrainY = false;
  950. this.clearTicks();
  951. },
  952. /**
  953. * Clears any tick interval defined for this instance
  954. * @method clearTicks
  955. */
  956. clearTicks: function() {
  957. this.xTicks = null;
  958. this.yTicks = null;
  959. this.xTickSize = 0;
  960. this.yTickSize = 0;
  961. },
  962. /**
  963. * By default, the element can be dragged any place on the screen. Set
  964. * this to limit the vertical travel of the element. Pass in 0,0 for the
  965. * parameters if you want to lock the drag to the x axis.
  966. * @method setYConstraint
  967. * @param {int} iUp the number of pixels the element can move up
  968. * @param {int} iDown the number of pixels the element can move down
  969. * @param {int} iTickSize optional parameter for specifying that the
  970. * element should move iTickSize pixels at a time.
  971. */
  972. setYConstraint: function(iUp, iDown, iTickSize) {
  973. this.topConstraint = iUp;
  974. this.bottomConstraint = iDown;
  975. this.minY = this.initPageY - iUp;
  976. this.maxY = this.initPageY + iDown;
  977. if (iTickSize) { this.setYTicks(this.initPageY, iTickSize); }
  978. this.constrainY = true;
  979. },
  980. /**
  981. * resetConstraints must be called if you manually reposition a dd element.
  982. * @method resetConstraints
  983. * @param {boolean} maintainOffset
  984. */
  985. resetConstraints: function() {
  986. // Maintain offsets if necessary
  987. if (this.initPageX || this.initPageX === 0) {
  988. // figure out how much this thing has moved
  989. var dx = (this.maintainOffset) ? this.lastPageX - this.initPageX : 0;
  990. var dy = (this.maintainOffset) ? this.lastPageY - this.initPageY : 0;
  991. this.setInitPosition(dx, dy);
  992. // This is the first time we have detected the element's position
  993. } else {
  994. this.setInitPosition();
  995. }
  996. if (this.constrainX) {
  997. this.setXConstraint( this.leftConstraint,
  998. this.rightConstraint,
  999. this.xTickSize );
  1000. }
  1001. if (this.constrainY) {
  1002. this.setYConstraint( this.topConstraint,
  1003. this.bottomConstraint,
  1004. this.yTickSize );
  1005. }
  1006. },
  1007. /**
  1008. * Normally the drag element is moved pixel by pixel, but we can specify
  1009. * that it move a number of pixels at a time. This method resolves the
  1010. * location when we have it set up like this.
  1011. * @method getTick
  1012. * @param {int} val where we want to place the object
  1013. * @param {int[]} tickArray sorted array of valid points
  1014. * @return {int} the closest tick
  1015. * @private
  1016. */
  1017. getTick: function(val, tickArray) {
  1018. if (!tickArray) {
  1019. // If tick interval is not defined, it is effectively 1 pixel,
  1020. // so we return the value passed to us.
  1021. return val;
  1022. } else if (tickArray[0] >= val) {
  1023. // The value is lower than the first tick, so we return the first
  1024. // tick.
  1025. return tickArray[0];
  1026. } else {
  1027. for (var i=0, len=tickArray.length; i<len; ++i) {
  1028. var next = i + 1;
  1029. if (tickArray[next] && tickArray[next] >= val) {
  1030. var diff1 = val - tickArray[i];
  1031. var diff2 = tickArray[next] - val;
  1032. return (diff2 > diff1) ? tickArray[i] : tickArray[next];
  1033. }
  1034. }
  1035. // The value is larger than the last tick, so we return the last
  1036. // tick.
  1037. return tickArray[tickArray.length - 1];
  1038. }
  1039. },
  1040. /**
  1041. * toString method
  1042. * @method toString
  1043. * @return {string} string representation of the dd obj
  1044. */
  1045. toString: function() {
  1046. return ("DragDrop " + this.id);
  1047. }
  1048. };
  1049. })();
  1050. /*
  1051. * The drag and drop utility provides a framework for building drag and drop
  1052. * applications. In addition to enabling drag and drop for specific elements,
  1053. * the drag and drop elements are tracked by the manager class, and the
  1054. * interactions between the various elements are tracked during the drag and
  1055. * the implementing code is notified about these important moments.
  1056. */
  1057. // Only load the library once. Rewriting the manager class would orphan
  1058. // existing drag and drop instances.
  1059. if (!Ext.dd.DragDropMgr) {
  1060. /**
  1061. * @class Ext.dd.DragDropMgr
  1062. * DragDropMgr is a singleton that tracks the element interaction for
  1063. * all DragDrop items in the window. Generally, you will not call
  1064. * this class directly, but it does have helper methods that could
  1065. * be useful in your DragDrop implementations.
  1066. * @singleton
  1067. */
  1068. Ext.dd.DragDropMgr = function() {
  1069. var Event = Ext.EventManager;
  1070. return {
  1071. /**
  1072. * Two dimensional Array of registered DragDrop objects. The first
  1073. * dimension is the DragDrop item group, the second the DragDrop
  1074. * object.
  1075. * @property ids
  1076. * @type String[]
  1077. * @private
  1078. */
  1079. ids: {},
  1080. /**
  1081. * Array of element ids defined as drag handles. Used to determine
  1082. * if the element that generated the mousedown event is actually the
  1083. * handle and not the html element itself.
  1084. * @property handleIds
  1085. * @type String[]
  1086. * @private
  1087. */
  1088. handleIds: {},
  1089. /**
  1090. * the DragDrop object that is currently being dragged
  1091. * @property dragCurrent
  1092. * @type DragDrop
  1093. * @private
  1094. **/
  1095. dragCurrent: null,
  1096. /**
  1097. * the DragDrop object(s) that are being hovered over
  1098. * @property dragOvers
  1099. * @type Array
  1100. * @private
  1101. */
  1102. dragOvers: {},
  1103. /**
  1104. * the X distance between the cursor and the object being dragged
  1105. * @property deltaX
  1106. * @type int
  1107. * @private
  1108. */
  1109. deltaX: 0,
  1110. /**
  1111. * the Y distance between the cursor and the object being dragged
  1112. * @property deltaY
  1113. * @type int
  1114. * @private
  1115. */
  1116. deltaY: 0,
  1117. /**
  1118. * Flag to determine if we should prevent the default behavior of the
  1119. * events we define. By default this is true, but this can be set to
  1120. * false if you need the default behavior (not recommended)
  1121. * @property preventDefault
  1122. * @type boolean
  1123. */
  1124. preventDefault: true,
  1125. /**
  1126. * Flag to determine if we should stop the propagation of the events
  1127. * we generate. This is true by default but you may want to set it to
  1128. * false if the html element contains other features that require the
  1129. * mouse click.
  1130. * @property stopPropagation
  1131. * @type boolean
  1132. */
  1133. stopPropagation: true,
  1134. /**
  1135. * Internal flag that is set to true when drag and drop has been
  1136. * intialized
  1137. * @property initialized
  1138. * @private
  1139. */
  1140. initialized: false,
  1141. /**
  1142. * All drag and drop can be disabled.
  1143. * @property locked
  1144. * @private
  1145. */
  1146. locked: false,
  1147. /**
  1148. * Called the first time an element is registered.
  1149. * @method init
  1150. * @private
  1151. */
  1152. init: function() {
  1153. this.initialized = true;
  1154. },
  1155. /**
  1156. * In point mode, drag and drop interaction is defined by the
  1157. * location of the cursor during the drag/drop
  1158. * @property POINT
  1159. * @type int
  1160. */
  1161. POINT: 0,
  1162. /**
  1163. * In intersect mode, drag and drop interaction is defined by the
  1164. * overlap of two or more drag and drop objects.
  1165. * @property INTERSECT
  1166. * @type int
  1167. */
  1168. INTERSECT: 1,
  1169. /**
  1170. * The current drag and drop mode. Default: POINT
  1171. * @property mode
  1172. * @type int
  1173. */
  1174. mode: 0,
  1175. /**
  1176. * @property {Boolean} [notifyOccluded=false]
  1177. * This config is only provided to provide old, usually unwanted drag/drop behaviour.
  1178. *
  1179. * From ExtJS 4.1.0 onwards, when drop targets are contained in floating, absolutely positioned elements
  1180. * such as in {@link Ext.window.Window Windows}, which may overlap each other, `over` and `drop` events
  1181. * are only delivered to the topmost drop target at the mouse position.
  1182. *
  1183. * If all targets below that in zIndex order should also receive notifications, set
  1184. * `notifyOccluded` to `true`.
  1185. */
  1186. notifyOccluded: false,
  1187. /**
  1188. * Runs method on all drag and drop objects
  1189. * @method _execOnAll
  1190. * @private
  1191. */
  1192. _execOnAll: function(sMethod, args) {
  1193. for (var i in this.ids) {
  1194. for (var j in this.ids[i]) {
  1195. var oDD = this.ids[i][j];
  1196. if (! this.isTypeOfDD(oDD)) {
  1197. continue;
  1198. }
  1199. oDD[sMethod].apply(oDD, args);
  1200. }
  1201. }
  1202. },
  1203. /**
  1204. * Drag and drop initialization. Sets up the global event handlers
  1205. * @method _onLoad
  1206. * @private
  1207. */
  1208. _onLoad: function() {
  1209. this.init();
  1210. Event.on(document, "mouseup", this.handleMouseUp, this, true);
  1211. Event.on(document, "mousemove", this.handleMouseMove, this, true);
  1212. Event.on(window, "unload", this._onUnload, this, true);
  1213. Event.on(window, "resize", this._onResize, this, true);
  1214. // Event.on(window, "mouseout", this._test);
  1215. },
  1216. /**
  1217. * Reset constraints on all drag and drop objs
  1218. * @method _onResize
  1219. * @private
  1220. */
  1221. _onResize: function(e) {
  1222. this._execOnAll("resetConstraints", []);
  1223. },
  1224. /**
  1225. * Lock all drag and drop functionality
  1226. * @method lock
  1227. */
  1228. lock: function() { this.locked = true; },
  1229. /**
  1230. * Unlock all drag and drop functionality
  1231. * @method unlock
  1232. */
  1233. unlock: function() { this.locked = false; },
  1234. /**
  1235. * Is drag and drop locked?
  1236. * @method isLocked
  1237. * @return {boolean} True if drag and drop is locked, false otherwise.
  1238. */
  1239. isLocked: function() { return this.locked; },
  1240. /**
  1241. * Location cache that is set for all drag drop objects when a drag is
  1242. * initiated, cleared when the drag is finished.
  1243. * @property locationCache
  1244. * @private
  1245. */
  1246. locationCache: {},
  1247. /**
  1248. * Set useCache to false if you want to force object the lookup of each
  1249. * drag and drop linked element constantly during a drag.
  1250. * @property useCache
  1251. * @type boolean
  1252. */
  1253. useCache: true,
  1254. /**
  1255. * The number of pixels that the mouse needs to move after the
  1256. * mousedown before the drag is initiated. Default=3;
  1257. * @property clickPixelThresh
  1258. * @type int
  1259. */
  1260. clickPixelThresh: 3,
  1261. /**
  1262. * The number of milliseconds after the mousedown event to initiate the
  1263. * drag if we don't get a mouseup event. Default=350
  1264. * @property clickTimeThresh
  1265. * @type int
  1266. */
  1267. clickTimeThresh: 350,
  1268. /**
  1269. * Flag that indicates that either the drag pixel threshold or the
  1270. * mousdown time threshold has been met
  1271. * @property dragThreshMet
  1272. * @type boolean
  1273. * @private
  1274. */
  1275. dragThreshMet: false,
  1276. /**
  1277. * Timeout used for the click time threshold
  1278. * @property clickTimeout
  1279. * @type Object
  1280. * @private
  1281. */
  1282. clickTimeout: null,
  1283. /**
  1284. * The X position of the mousedown event stored for later use when a
  1285. * drag threshold is met.
  1286. * @property startX
  1287. * @type int
  1288. * @private
  1289. */
  1290. startX: 0,
  1291. /**
  1292. * The Y position of the mousedown event stored for later use when a
  1293. * drag threshold is met.
  1294. * @property startY
  1295. * @type int
  1296. * @private
  1297. */
  1298. startY: 0,
  1299. /**
  1300. * Each DragDrop instance must be registered with the DragDropMgr.
  1301. * This is executed in DragDrop.init()
  1302. * @method regDragDrop
  1303. * @param {DragDrop} oDD the DragDrop object to register
  1304. * @param {String} sGroup the name of the group this element belongs to
  1305. */
  1306. regDragDrop: function(oDD, sGroup) {
  1307. if (!this.initialized) { this.init(); }
  1308. if (!this.ids[sGroup]) {
  1309. this.ids[sGroup] = {};
  1310. }
  1311. this.ids[sGroup][oDD.id] = oDD;
  1312. },
  1313. /**
  1314. * Removes the supplied dd instance from the supplied group. Executed
  1315. * by DragDrop.removeFromGroup, so don't call this function directly.
  1316. * @method removeDDFromGroup
  1317. * @private
  1318. */
  1319. removeDDFromGroup: function(oDD, sGroup) {
  1320. if (!this.ids[sGroup]) {
  1321. this.ids[sGroup] = {};
  1322. }
  1323. var obj = this.ids[sGroup];
  1324. if (obj && obj[oDD.id]) {
  1325. delete obj[oDD.id];
  1326. }
  1327. },
  1328. /**
  1329. * Unregisters a drag and drop item. This is executed in
  1330. * DragDrop.unreg, use that method instead of calling this directly.
  1331. * @method _remove
  1332. * @private
  1333. */
  1334. _remove: function(oDD) {
  1335. for (var g in oDD.groups) {
  1336. if (g && this.ids[g] && this.ids[g][oDD.id]) {
  1337. delete this.ids[g][oDD.id];
  1338. }
  1339. }
  1340. delete this.handleIds[oDD.id];
  1341. },
  1342. /**
  1343. * Each DragDrop handle element must be registered. This is done
  1344. * automatically when executing DragDrop.setHandleElId()
  1345. * @method regHandle
  1346. * @param {String} sDDId the DragDrop id this element is a handle for
  1347. * @param {String} sHandleId the id of the element that is the drag
  1348. * handle
  1349. */
  1350. regHandle: function(sDDId, sHandleId) {
  1351. if (!this.handleIds[sDDId]) {
  1352. this.handleIds[sDDId] = {};
  1353. }
  1354. this.handleIds[sDDId][sHandleId] = sHandleId;
  1355. },
  1356. /**
  1357. * Utility function to determine if a given element has been
  1358. * registered as a drag drop item.
  1359. * @method isDragDrop
  1360. * @param {String} id the element id to check
  1361. * @return {boolean} true if this element is a DragDrop item,
  1362. * false otherwise
  1363. */
  1364. isDragDrop: function(id) {
  1365. return ( this.getDDById(id) ) ? true : false;
  1366. },
  1367. /**
  1368. * Returns the drag and drop instances that are in all groups the
  1369. * passed in instance belongs to.
  1370. * @method getRelated
  1371. * @param {DragDrop} p_oDD the obj to get related data for
  1372. * @param {boolean} bTargetsOnly if true, only return targetable objs
  1373. * @return {DragDrop[]} the related instances
  1374. */
  1375. getRelated: function(p_oDD, bTargetsOnly) {
  1376. var oDDs = [];
  1377. for (var i in p_oDD.groups) {
  1378. for (var j in this.ids[i]) {
  1379. var dd = this.ids[i][j];
  1380. if (! this.isTypeOfDD(dd)) {
  1381. continue;
  1382. }
  1383. if (!bTargetsOnly || dd.isTarget) {
  1384. oDDs[oDDs.length] = dd;
  1385. }
  1386. }
  1387. }
  1388. return oDDs;
  1389. },
  1390. /**
  1391. * Returns true if the specified dd target is a legal target for
  1392. * the specifice drag obj
  1393. * @method isLegalTarget
  1394. * @param {DragDrop} oDD the drag obj
  1395. * @param {DragDrop} oTargetDD the target
  1396. * @return {boolean} true if the target is a legal target for the
  1397. * dd obj
  1398. */
  1399. isLegalTarget: function (oDD, oTargetDD) {
  1400. var targets = this.getRelated(oDD, true);
  1401. for (var i=0, len=targets.length;i<len;++i) {
  1402. if (targets[i].id == oTargetDD.id) {
  1403. return true;
  1404. }
  1405. }
  1406. return false;
  1407. },
  1408. /**
  1409. * My goal is to be able to transparently determine if an object is
  1410. * typeof DragDrop, and the exact subclass of DragDrop. typeof
  1411. * returns "object", oDD.constructor.toString() always returns
  1412. * "DragDrop" and not the name of the subclass. So for now it just
  1413. * evaluates a well-known variable in DragDrop.
  1414. * @method isTypeOfDD
  1415. * @param {Object} the object to evaluate
  1416. * @return {boolean} true if typeof oDD = DragDrop
  1417. */
  1418. isTypeOfDD: function (oDD) {
  1419. return (oDD && oDD.__ygDragDrop);
  1420. },
  1421. /**
  1422. * Utility function to determine if a given element has been
  1423. * registered as a drag drop handle for the given Drag Drop object.
  1424. * @method isHandle
  1425. * @param {String} id the element id to check
  1426. * @return {boolean} true if this element is a DragDrop handle, false
  1427. * otherwise
  1428. */
  1429. isHandle: function(sDDId, sHandleId) {
  1430. return ( this.handleIds[sDDId] &&
  1431. this.handleIds[sDDId][sHandleId] );
  1432. },
  1433. /**
  1434. * Returns the DragDrop instance for a given id
  1435. * @method getDDById
  1436. * @param {String} id the id of the DragDrop object
  1437. * @return {DragDrop} the drag drop object, null if it is not found
  1438. */
  1439. getDDById: function(id) {
  1440. for (var i in this.ids) {
  1441. if (this.ids[i][id]) {
  1442. return this.ids[i][id];
  1443. }
  1444. }
  1445. return null;
  1446. },
  1447. /**
  1448. * Fired after a registered DragDrop object gets the mousedown event.
  1449. * Sets up the events required to track the object being dragged
  1450. * @method handleMouseDown
  1451. * @param {Event} e the event
  1452. * @param oDD the DragDrop object being dragged
  1453. * @private
  1454. */
  1455. handleMouseDown: function(e, oDD) {
  1456. if(Ext.QuickTips){
  1457. Ext.QuickTips.ddDisable();
  1458. }
  1459. if(this.dragCurrent){
  1460. // the original browser mouseup wasn't handled (e.g. outside FF browser window)
  1461. // so clean up first to avoid breaking the next drag
  1462. this.handleMouseUp(e);
  1463. }
  1464. this.currentTarget = e.getTarget();
  1465. this.dragCurrent = oDD;
  1466. var el = oDD.getEl();
  1467. // track start position
  1468. this.startX = e.getPageX();
  1469. this.startY = e.getPageY();
  1470. this.deltaX = this.startX - el.offsetLeft;
  1471. this.deltaY = this.startY - el.offsetTop;
  1472. this.dragThreshMet = false;
  1473. this.clickTimeout = setTimeout(
  1474. function() {
  1475. var DDM = Ext.dd.DDM;
  1476. DDM.startDrag(DDM.startX, DDM.startY);
  1477. },
  1478. this.clickTimeThresh );
  1479. },
  1480. /**
  1481. * Fired when either the drag pixel threshol or the mousedown hold
  1482. * time threshold has been met.
  1483. * @method startDrag
  1484. * @param x {int} the X position of the original mousedown
  1485. * @param y {int} the Y position of the original mousedown
  1486. */
  1487. startDrag: function(x, y) {
  1488. clearTimeout(this.clickTimeout);
  1489. if (this.dragCurrent) {
  1490. this.dragCurrent.b4StartDrag(x, y);
  1491. this.dragCurrent.startDrag(x, y);
  1492. }
  1493. this.dragThreshMet = true;
  1494. },
  1495. /**
  1496. * Internal function to handle the mouseup event. Will be invoked
  1497. * from the context of the document.
  1498. * @method handleMouseUp
  1499. * @param {Event} e the event
  1500. * @private
  1501. */
  1502. handleMouseUp: function(e) {
  1503. if(Ext.QuickTips){
  1504. Ext.QuickTips.ddEnable();
  1505. }
  1506. if (! this.dragCurrent) {
  1507. return;
  1508. }
  1509. clearTimeout(this.clickTimeout);
  1510. if (this.dragThreshMet) {
  1511. this.fireEvents(e, true);
  1512. } else {
  1513. }
  1514. this.stopDrag(e);
  1515. this.stopEvent(e);
  1516. },
  1517. /**
  1518. * Utility to stop event propagation and event default, if these
  1519. * features are turned on.
  1520. * @method stopEvent
  1521. * @param {Event} e the event as returned by this.getEvent()
  1522. */
  1523. stopEvent: function(e){
  1524. if(this.stopPropagation) {
  1525. e.stopPropagation();
  1526. }
  1527. if (this.preventDefault) {
  1528. e.preventDefault();
  1529. }
  1530. },
  1531. /**
  1532. * Internal function to clean up event handlers after the drag
  1533. * operation is complete
  1534. * @method stopDrag
  1535. * @param {Event} e the event
  1536. * @private
  1537. */
  1538. stopDrag: function(e) {
  1539. // Fire the drag end event for the item that was dragged
  1540. if (this.dragCurrent) {
  1541. if (this.dragThreshMet) {
  1542. this.dragCurrent.b4EndDrag(e);
  1543. this.dragCurrent.endDrag(e);
  1544. }
  1545. this.dragCurrent.onMouseUp(e);
  1546. }
  1547. this.dragCurrent = null;
  1548. this.dragOvers = {};
  1549. },
  1550. /**
  1551. * Internal function to handle the mousemove event. Will be invoked
  1552. * from the context of the html element.
  1553. *
  1554. * @TODO figure out what we can do about mouse events lost when the
  1555. * user drags objects beyond the window boundary. Currently we can
  1556. * detect this in internet explorer by verifying that the mouse is
  1557. * down during the mousemove event. Firefox doesn't give us the
  1558. * button state on the mousemove event.
  1559. * @method handleMouseMove
  1560. * @param {Event} e the event
  1561. * @private
  1562. */
  1563. handleMouseMove: function(e) {
  1564. if (! this.dragCurrent) {
  1565. return true;
  1566. }
  1567. // var button = e.which || e.button;
  1568. // check for IE mouseup outside of page boundary
  1569. if (Ext.isIE && (e.button !== 0 && e.button !== 1 && e.button !== 2)) {
  1570. this.stopEvent(e);
  1571. return this.handleMouseUp(e);
  1572. }
  1573. if (!this.dragThreshMet) {
  1574. var diffX = Math.abs(this.startX - e.getPageX());
  1575. var diffY = Math.abs(this.startY - e.getPageY());
  1576. if (diffX > this.clickPixelThresh ||
  1577. diffY > this.clickPixelThresh) {
  1578. this.startDrag(this.startX, this.startY);
  1579. }
  1580. }
  1581. if (this.dragThreshMet) {
  1582. this.dragCurrent.b4Drag(e);
  1583. this.dragCurrent.onDrag(e);
  1584. if(!this.dragCurrent.moveOnly){
  1585. this.fireEvents(e, false);
  1586. }
  1587. }
  1588. this.stopEvent(e);
  1589. return true;
  1590. },
  1591. /**
  1592. * Iterates over all of the DragDrop elements to find ones we are
  1593. * hovering over or dropping on
  1594. * @method fireEvents
  1595. * @param {Event} e the event
  1596. * @param {boolean} isDrop is this a drop op or a mouseover op?
  1597. * @private
  1598. */
  1599. fireEvents: function(e, isDrop) {
  1600. var me = this,
  1601. dragCurrent = me.dragCurrent,
  1602. mousePoint = e.getPoint(),
  1603. overTarget,
  1604. overTargetEl,
  1605. allTargets = [],
  1606. oldOvers = [], // cache the previous dragOver array
  1607. outEvts = [],
  1608. overEvts = [],
  1609. dropEvts = [],
  1610. enterEvts = [],
  1611. needsSort,
  1612. i,
  1613. len,
  1614. sGroup;
  1615. // If the user did the mouse up outside of the window, we could
  1616. // get here even though we have ended the drag.
  1617. if (!dragCurrent || dragCurrent.isLocked()) {
  1618. return;
  1619. }
  1620. // Check to see if the object(s) we were hovering over is no longer
  1621. // being hovered over so we can fire the onDragOut event
  1622. for (i in me.dragOvers) {
  1623. overTarget = me.dragOvers[i];
  1624. if (! me.isTypeOfDD(overTarget)) {
  1625. continue;
  1626. }
  1627. if (! this.isOverTarget(mousePoint, overTarget, me.mode)) {
  1628. outEvts.push( overTarget );
  1629. }
  1630. oldOvers[i] = true;
  1631. delete me.dragOvers[i];
  1632. }
  1633. // Collect all targets which are members of the same ddGoups that the dragCurrent is a member of, and which may recieve mouseover and drop notifications.
  1634. // This is preparatory to seeing which one(s) we are currently over
  1635. // Begin by iterating through the ddGroups of which the dragCurrent is a member
  1636. for (sGroup in dragCurrent.groups) {
  1637. if ("string" != typeof sGroup) {
  1638. continue;
  1639. }
  1640. // Loop over the registered members of each group, testing each as a potential target
  1641. for (i in me.ids[sGroup]) {
  1642. overTarget = me.ids[sGroup][i];
  1643. // The target is valid if it is a DD type
  1644. // And it's got a DOM element
  1645. // And it's configured to be a drop target
  1646. // And it's not locked
  1647. // And it's either not the dragCurrent, or, if it is, tha dragCurrent is configured to not ignore itself.
  1648. if (me.isTypeOfDD(overTarget) &&
  1649. (overTargetEl = overTarget.getEl()) &&
  1650. (overTarget.isTarget) &&
  1651. (!overTarget.isLocked()) &&
  1652. ((overTarget != dragCurrent) || (dragCurrent.ignoreSelf === false))) {
  1653. // Only sort by zIndex if there were some which had a floating zIndex value
  1654. if ((overTarget.zIndex = me.getZIndex(overTargetEl)) !== -1) {
  1655. needsSort = true;
  1656. }
  1657. allTargets.push(overTarget);
  1658. }
  1659. }
  1660. }
  1661. // If there were floating targets, sort the highest zIndex to the top
  1662. if (needsSort) {
  1663. allTargets.sort(me.byZIndex);
  1664. }
  1665. // Loop through possible targets, notifying the one(s) we are over.
  1666. // Usually we only deliver events to the topmost.
  1667. for (i = 0, len = allTargets.length; i < len; i++) {
  1668. overTarget = allTargets[i];
  1669. // If we are over the overTarget, queue it up to recieve an event of whatever type we are handling
  1670. if (me.isOverTarget(mousePoint, overTarget, me.mode)) {
  1671. // look for drop interactions
  1672. if (isDrop) {
  1673. dropEvts.push( overTarget );
  1674. // look for drag enter and drag over interactions
  1675. } else {
  1676. // initial drag over: dragEnter fires
  1677. if (!oldOvers[overTarget.id]) {
  1678. enterEvts.push( overTarget );
  1679. // subsequent drag overs: dragOver fires
  1680. } else {
  1681. overEvts.push( overTarget );
  1682. }
  1683. me.dragOvers[overTarget.id] = overTarget;
  1684. }
  1685. // Unless this DragDropManager has been explicitly configured to deliver events to multiple targets, then we are done.
  1686. if (!me.notifyOccluded) {
  1687. break;
  1688. }
  1689. }
  1690. }
  1691. if (me.mode) {
  1692. if (outEvts.length) {
  1693. dragCurrent.b4DragOut(e, outEvts);
  1694. dragCurrent.onDragOut(e, outEvts);
  1695. }
  1696. if (enterEvts.length) {
  1697. dragCurrent.onDragEnter(e, enterEvts);
  1698. }
  1699. if (overEvts.length) {
  1700. dragCurrent.b4DragOver(e, overEvts);
  1701. dragCurrent.onDragOver(e, overEvts);
  1702. }
  1703. if (dropEvts.length) {
  1704. dragCurrent.b4DragDrop(e, dropEvts);
  1705. dragCurrent.onDragDrop(e, dropEvts);
  1706. }
  1707. } else {
  1708. // fire dragout events
  1709. for (i=0, len=outEvts.length; i<len; ++i) {
  1710. dragCurrent.b4DragOut(e, outEvts[i].id);
  1711. dragCurrent.onDragOut(e, outEvts[i].id);
  1712. }
  1713. // fire enter events
  1714. for (i=0,len=enterEvts.length; i<len; ++i) {
  1715. // dc.b4DragEnter(e, oDD.id);
  1716. dragCurrent.onDragEnter(e, enterEvts[i].id);
  1717. }
  1718. // fire over events
  1719. for (i=0,len=overEvts.length; i<len; ++i) {
  1720. dragCurrent.b4DragOver(e, overEvts[i].id);
  1721. dragCurrent.onDragOver(e, overEvts[i].id);
  1722. }
  1723. // fire drop events
  1724. for (i=0, len=dropEvts.length; i<len; ++i) {
  1725. dragCurrent.b4DragDrop(e, dropEvts[i].id);
  1726. dragCurrent.onDragDrop(e, dropEvts[i].id);
  1727. }
  1728. }
  1729. // notify about a drop that did not find a target
  1730. if (isDrop && !dropEvts.length) {
  1731. dragCurrent.onInvalidDrop(e);
  1732. }
  1733. },
  1734. /**
  1735. * @private
  1736. * Collects the z-index of the passed element, looking up the parentNode axis to find an absolutely positioned ancestor
  1737. * which is able to yield a z-index. If found to be not absolutely positionedm returns -1.
  1738. *
  1739. * This is used when sorting potential drop targets into z-index order so that only the topmost receives `over` and `drop` events.
  1740. *
  1741. * @return {Number} The z-index of the element, or of its topmost absolutely positioned ancestor. Returns -1 if the element is not
  1742. * absolutely positioned.
  1743. */
  1744. getZIndex: function(element) {
  1745. var body = document.body,
  1746. z,
  1747. zIndex = -1;
  1748. element = Ext.getDom(element);
  1749. while (element !== body) {
  1750. if (!isNaN(z = Number(Ext.fly(element).getStyle('zIndex')))) {
  1751. zIndex = z;
  1752. }
  1753. element = element.parentNode;
  1754. }
  1755. return zIndex;
  1756. },
  1757. /**
  1758. * @private
  1759. * Utility method to pass to {@link Ext.Array#sort} when sorting potential drop targets by z-index.
  1760. */
  1761. byZIndex: function(d1, d2) {
  1762. return d1.zIndex < d2.zIndex;
  1763. },
  1764. /**
  1765. * Helper function for getting the best match from the list of drag
  1766. * and drop objects returned by the drag and drop events when we are
  1767. * in INTERSECT mode. It returns either the first object that the
  1768. * cursor is over, or the object that has the greatest overlap with
  1769. * the dragged element.
  1770. * @method getBestMatch
  1771. * @param {DragDrop[]} dds The array of drag and drop objects
  1772. * targeted
  1773. * @return {DragDrop} The best single match
  1774. */
  1775. getBestMatch: function(dds) {
  1776. var winner = null;
  1777. // Return null if the input is not what we expect
  1778. //if (!dds || !dds.length || dds.length == 0) {
  1779. // winner = null;
  1780. // If there is only one item, it wins
  1781. //} else if (dds.length == 1) {
  1782. var len = dds.length;
  1783. if (len == 1) {
  1784. winner = dds[0];
  1785. } else {
  1786. // Loop through the targeted items
  1787. for (var i=0; i<len; ++i) {
  1788. var dd = dds[i];
  1789. // If the cursor is over the object, it wins. If the
  1790. // cursor is over multiple matches, the first one we come
  1791. // to wins.
  1792. if (dd.cursorIsOver) {
  1793. winner = dd;
  1794. break;
  1795. // Otherwise the object with the most overlap wins
  1796. } else {
  1797. if (!winner ||
  1798. winner.overlap.getArea() < dd.overlap.getArea()) {
  1799. winner = dd;
  1800. }
  1801. }
  1802. }
  1803. }
  1804. return winner;
  1805. },
  1806. /**
  1807. * Refreshes the cache of the top-left and bottom-right points of the
  1808. * drag and drop objects in the specified group(s). This is in the
  1809. * format that is stored in the drag and drop instance, so typical
  1810. * usage is:
  1811. * <code>
  1812. * Ext.dd.DragDropMgr.refreshCache(ddinstance.groups);
  1813. * </code>
  1814. * Alternatively:
  1815. * <code>
  1816. * Ext.dd.DragDropMgr.refreshCache({group1:true, group2:true});
  1817. * </code>
  1818. * @TODO this really should be an indexed array. Alternatively this
  1819. * method could accept both.
  1820. * @method refreshCache
  1821. * @param {Object} groups an associative array of groups to refresh
  1822. */
  1823. refreshCache: function(groups) {
  1824. for (var sGroup in groups) {
  1825. if ("string" != typeof sGroup) {
  1826. continue;
  1827. }
  1828. for (var i in this.ids[sGroup]) {
  1829. var oDD = this.ids[sGroup][i];
  1830. if (this.isTypeOfDD(oDD)) {
  1831. // if (this.isTypeOfDD(oDD) && oDD.isTarget) {
  1832. var loc = this.getLocation(oDD);
  1833. if (loc) {
  1834. this.locationCache[oDD.id] = loc;
  1835. } else {
  1836. delete this.locationCache[oDD.id];
  1837. // this will unregister the drag and drop object if
  1838. // the element is not in a usable state
  1839. // oDD.unreg();
  1840. }
  1841. }
  1842. }
  1843. }
  1844. },
  1845. /**
  1846. * This checks to make sure an element exists and is in the DOM. The
  1847. * main purpose is to handle cases where innerHTML is used to remove
  1848. * drag and drop objects from the DOM. IE provides an 'unspecified
  1849. * error' when trying to access the offsetParent of such an element
  1850. * @method verifyEl
  1851. * @param {HTMLElement} el the element to check
  1852. * @return {boolean} true if the element looks usable
  1853. */
  1854. verifyEl: function(el) {
  1855. if (el) {
  1856. var parent;
  1857. if(Ext.isIE){
  1858. try{
  1859. parent = el.offsetParent;
  1860. }catch(e){}
  1861. }else{
  1862. parent = el.offsetParent;
  1863. }
  1864. if (parent) {
  1865. return true;
  1866. }
  1867. }
  1868. return false;
  1869. },
  1870. /**
  1871. * Returns a Region object containing the drag and drop element's position
  1872. * and size, including the padding configured for it
  1873. * @method getLocation
  1874. * @param {DragDrop} oDD the drag and drop object to get the
  1875. * location for
  1876. * @return {Ext.lib.Region} a Region object representing the total area
  1877. * the element occupies, including any padding
  1878. * the instance is configured for.
  1879. */
  1880. getLocation: function(oDD) {
  1881. if (! this.isTypeOfDD(oDD)) {
  1882. return null;
  1883. }
  1884. var el = oDD.getEl(), pos, x1, x2, y1, y2, t, r, b, l, region;
  1885. try {
  1886. pos= Ext.lib.Dom.getXY(el);
  1887. } catch (e) { }
  1888. if (!pos) {
  1889. return null;
  1890. }
  1891. x1 = pos[0];
  1892. x2 = x1 + el.offsetWidth;
  1893. y1 = pos[1];
  1894. y2 = y1 + el.offsetHeight;
  1895. t = y1 - oDD.padding[0];
  1896. r = x2 + oDD.padding[1];
  1897. b = y2 + oDD.padding[2];
  1898. l = x1 - oDD.padding[3];
  1899. return new Ext.lib.Region( t, r, b, l );
  1900. },
  1901. /**
  1902. * Checks the cursor location to see if it over the target
  1903. * @method isOverTarget
  1904. * @param {Ext.lib.Point} pt The point to evaluate
  1905. * @param {DragDrop} oTarget the DragDrop object we are inspecting
  1906. * @return {boolean} true if the mouse is over the target
  1907. * @private
  1908. */
  1909. isOverTarget: function(pt, oTarget, intersect) {
  1910. // use cache if available
  1911. var loc = this.locationCache[oTarget.id];
  1912. if (!loc || !this.useCache) {
  1913. loc = this.getLocation(oTarget);
  1914. this.locationCache[oTarget.id] = loc;
  1915. }
  1916. if (!loc) {
  1917. return false;
  1918. }
  1919. oTarget.cursorIsOver = loc.contains( pt );
  1920. // DragDrop is using this as a sanity check for the initial mousedown
  1921. // in this case we are done. In POINT mode, if the drag obj has no
  1922. // contraints, we are also done. Otherwise we need to evaluate the
  1923. // location of the target as related to the actual location of the
  1924. // dragged element.
  1925. var dc = this.dragCurrent;
  1926. if (!dc || !dc.getTargetCoord ||
  1927. (!intersect && !dc.constrainX && !dc.constrainY)) {
  1928. return oTarget.cursorIsOver;
  1929. }
  1930. oTarget.overlap = null;
  1931. // Get the current location of the drag element, this is the
  1932. // location of the mouse event less the delta that represents
  1933. // where the original mousedown happened on the element. We
  1934. // need to consider constraints and ticks as well.
  1935. var pos = dc.getTargetCoord(pt.x, pt.y);
  1936. var el = dc.getDragEl();
  1937. var curRegion = new Ext.lib.Region( pos.y,
  1938. pos.x + el.offsetWidth,
  1939. pos.y + el.offsetHeight,
  1940. pos.x );
  1941. var overlap = curRegion.intersect(loc);
  1942. if (overlap) {
  1943. oTarget.overlap = overlap;
  1944. return (intersect) ? true : oTarget.cursorIsOver;
  1945. } else {
  1946. return false;
  1947. }
  1948. },
  1949. /**
  1950. * unload event handler
  1951. * @method _onUnload
  1952. * @private
  1953. */
  1954. _onUnload: function(e, me) {
  1955. Event.removeListener(document, "mouseup", this.handleMouseUp, this);
  1956. Event.removeListener(document, "mousemove", this.handleMouseMove, this);
  1957. Event.removeListener(window, "resize", this._onResize, this);
  1958. Ext.dd.DragDropMgr.unregAll();
  1959. },
  1960. /**
  1961. * Cleans up the drag and drop events and objects.
  1962. * @method unregAll
  1963. * @private
  1964. */
  1965. unregAll: function() {
  1966. if (this.dragCurrent) {
  1967. this.stopDrag();
  1968. this.dragCurrent = null;
  1969. }
  1970. this._execOnAll("unreg", []);
  1971. for (var i in this.elementCache) {
  1972. delete this.elementCache[i];
  1973. }
  1974. this.elementCache = {};
  1975. this.ids = {};
  1976. },
  1977. /**
  1978. * A cache of DOM elements
  1979. * @property elementCache
  1980. * @private
  1981. */
  1982. elementCache: {},
  1983. /**
  1984. * Get the wrapper for the DOM element specified
  1985. * @method getElWrapper
  1986. * @param {String} id the id of the element to get
  1987. * @return {Ext.dd.DDM.ElementWrapper} the wrapped element
  1988. * @private
  1989. * @deprecated This wrapper isn't that useful
  1990. */
  1991. getElWrapper: function(id) {
  1992. var oWrapper = this.elementCache[id];
  1993. if (!oWrapper || !oWrapper.el) {
  1994. oWrapper = this.elementCache[id] =
  1995. new this.ElementWrapper(Ext.getDom(id));
  1996. }
  1997. return oWrapper;
  1998. },
  1999. /**
  2000. * Returns the actual DOM element
  2001. * @method getElement
  2002. * @param {String} id the id of the elment to get
  2003. * @return {Object} The element
  2004. * @deprecated use Ext.lib.Ext.getDom instead
  2005. */
  2006. getElement: function(id) {
  2007. return Ext.getDom(id);
  2008. },
  2009. /**
  2010. * Returns the style property for the DOM element (i.e.,
  2011. * document.getElById(id).style)
  2012. * @method getCss
  2013. * @param {String} id the id of the elment to get
  2014. * @return {Object} The style property of the element
  2015. * @deprecated use Ext.lib.Dom instead
  2016. */
  2017. getCss: function(id) {
  2018. var el = Ext.getDom(id);
  2019. return (el) ? el.style : null;
  2020. },
  2021. /**
  2022. * Inner class for cached elements
  2023. * @class Ext.dd.DragDropMgr.ElementWrapper
  2024. * @for DragDropMgr
  2025. * @private
  2026. * @deprecated
  2027. */
  2028. ElementWrapper: function(el) {
  2029. /**
  2030. * The element
  2031. * @property el
  2032. */
  2033. this.el = el || null;
  2034. /**
  2035. * The element id
  2036. * @property id
  2037. */
  2038. this.id = this.el && el.id;
  2039. /**
  2040. * A reference to the style property
  2041. * @property css
  2042. */
  2043. this.css = this.el && el.style;
  2044. },
  2045. /**
  2046. * Returns the X position of an html element
  2047. * @method getPosX
  2048. * @param el the element for which to get the position
  2049. * @return {int} the X coordinate
  2050. * @for DragDropMgr
  2051. * @deprecated use Ext.lib.Dom.getX instead
  2052. */
  2053. getPosX: function(el) {
  2054. return Ext.lib.Dom.getX(el);
  2055. },
  2056. /**
  2057. * Returns the Y position of an html element
  2058. * @method getPosY
  2059. * @param el the element for which to get the position
  2060. * @return {int} the Y coordinate
  2061. * @deprecated use Ext.lib.Dom.getY instead
  2062. */
  2063. getPosY: function(el) {
  2064. return Ext.lib.Dom.getY(el);
  2065. },
  2066. /**
  2067. * Swap two nodes. In IE, we use the native method, for others we
  2068. * emulate the IE behavior
  2069. * @method swapNode
  2070. * @param n1 the first node to swap
  2071. * @param n2 the other node to swap
  2072. */
  2073. swapNode: function(n1, n2) {
  2074. if (n1.swapNode) {
  2075. n1.swapNode(n2);
  2076. } else {
  2077. var p = n2.parentNode;
  2078. var s = n2.nextSibling;
  2079. if (s == n1) {
  2080. p.insertBefore(n1, n2);
  2081. } else if (n2 == n1.nextSibling) {
  2082. p.insertBefore(n2, n1);
  2083. } else {
  2084. n1.parentNode.replaceChild(n2, n1);
  2085. p.insertBefore(n1, s);
  2086. }
  2087. }
  2088. },
  2089. /**
  2090. * Returns the current scroll position
  2091. * @method getScroll
  2092. * @private
  2093. */
  2094. getScroll: function () {
  2095. var t, l, dde=document.documentElement, db=document.body;
  2096. if (dde && (dde.scrollTop || dde.scrollLeft)) {
  2097. t = dde.scrollTop;
  2098. l = dde.scrollLeft;
  2099. } else if (db) {
  2100. t = db.scrollTop;
  2101. l = db.scrollLeft;
  2102. } else {
  2103. }
  2104. return { top: t, left: l };
  2105. },
  2106. /**
  2107. * Returns the specified element style property
  2108. * @method getStyle
  2109. * @param {HTMLElement} el the element
  2110. * @param {string} styleProp the style property
  2111. * @return {string} The value of the style property
  2112. * @deprecated use Ext.lib.Dom.getStyle
  2113. */
  2114. getStyle: function(el, styleProp) {
  2115. return Ext.fly(el).getStyle(styleProp);
  2116. },
  2117. /**
  2118. * Gets the scrollTop
  2119. * @method getScrollTop
  2120. * @return {int} the document's scrollTop
  2121. */
  2122. getScrollTop: function () {
  2123. return this.getScroll().top;
  2124. },
  2125. /**
  2126. * Gets the scrollLeft
  2127. * @method getScrollLeft
  2128. * @return {int} the document's scrollTop
  2129. */
  2130. getScrollLeft: function () {
  2131. return this.getScroll().left;
  2132. },
  2133. /**
  2134. * Sets the x/y position of an element to the location of the
  2135. * target element.
  2136. * @method moveToEl
  2137. * @param {HTMLElement} moveEl The element to move
  2138. * @param {HTMLElement} targetEl The position reference element
  2139. */
  2140. moveToEl: function (moveEl, targetEl) {
  2141. var aCoord = Ext.lib.Dom.getXY(targetEl);
  2142. Ext.lib.Dom.setXY(moveEl, aCoord);
  2143. },
  2144. /**
  2145. * Numeric array sort function
  2146. * @method numericSort
  2147. */
  2148. numericSort: function(a, b) {
  2149. return (a - b);
  2150. },
  2151. /**
  2152. * Internal counter
  2153. * @property _timeoutCount
  2154. * @private
  2155. */
  2156. _timeoutCount: 0,
  2157. /**
  2158. * Trying to make the load order less important. Without this we get
  2159. * an error if this file is loaded before the Event Utility.
  2160. * @method _addListeners
  2161. * @private
  2162. */
  2163. _addListeners: function() {
  2164. var DDM = Ext.dd.DDM;
  2165. if ( Ext.lib.Event && document ) {
  2166. DDM._onLoad();
  2167. } else {
  2168. if (DDM._timeoutCount > 2000) {
  2169. } else {
  2170. setTimeout(DDM._addListeners, 10);
  2171. if (document && document.body) {
  2172. DDM._timeoutCount += 1;
  2173. }
  2174. }
  2175. }
  2176. },
  2177. /**
  2178. * Recursively searches the immediate parent and all child nodes for
  2179. * the handle element in order to determine wheter or not it was
  2180. * clicked.
  2181. * @method handleWasClicked
  2182. * @param node the html element to inspect
  2183. */
  2184. handleWasClicked: function(node, id) {
  2185. if (this.isHandle(id, node.id)) {
  2186. return true;
  2187. } else {
  2188. // check to see if this is a text node child of the one we want
  2189. var p = node.parentNode;
  2190. while (p) {
  2191. if (this.isHandle(id, p.id)) {
  2192. return true;
  2193. } else {
  2194. p = p.parentNode;
  2195. }
  2196. }
  2197. }
  2198. return false;
  2199. }
  2200. };
  2201. }();
  2202. // shorter alias, save a few bytes
  2203. Ext.dd.DDM = Ext.dd.DragDropMgr;
  2204. Ext.dd.DDM._addListeners();
  2205. }
  2206. /**
  2207. * @class Ext.dd.DD
  2208. * A DragDrop implementation where the linked element follows the
  2209. * mouse cursor during a drag.
  2210. * @extends Ext.dd.DragDrop
  2211. * @constructor
  2212. * @param {String} id the id of the linked element
  2213. * @param {String} sGroup the group of related DragDrop items
  2214. * @param {object} config an object containing configurable attributes
  2215. * Valid properties for DD:
  2216. * scroll
  2217. */
  2218. Ext.dd.DD = function(id, sGroup, config) {
  2219. if (id) {
  2220. this.init(id, sGroup, config);
  2221. }
  2222. };
  2223. Ext.extend(Ext.dd.DD, Ext.dd.DragDrop, {
  2224. /**
  2225. * When set to true, the utility automatically tries to scroll the browser
  2226. * window when a drag and drop element is dragged near the viewport boundary.
  2227. * Defaults to true.
  2228. * @property scroll
  2229. * @type boolean
  2230. */
  2231. scroll: true,
  2232. /**
  2233. * Sets the pointer offset to the distance between the linked element's top
  2234. * left corner and the location the element was clicked
  2235. * @method autoOffset
  2236. * @param {int} iPageX the X coordinate of the click
  2237. * @param {int} iPageY the Y coordinate of the click
  2238. */
  2239. autoOffset: function(iPageX, iPageY) {
  2240. var x = iPageX - this.startPageX;
  2241. var y = iPageY - this.startPageY;
  2242. this.setDelta(x, y);
  2243. },
  2244. /**
  2245. * Sets the pointer offset. You can call this directly to force the
  2246. * offset to be in a particular location (e.g., pass in 0,0 to set it
  2247. * to the center of the object)
  2248. * @method setDelta
  2249. * @param {int} iDeltaX the distance from the left
  2250. * @param {int} iDeltaY the distance from the top
  2251. */
  2252. setDelta: function(iDeltaX, iDeltaY) {
  2253. this.deltaX = iDeltaX;
  2254. this.deltaY = iDeltaY;
  2255. },
  2256. /**
  2257. * Sets the drag element to the location of the mousedown or click event,
  2258. * maintaining the cursor location relative to the location on the element
  2259. * that was clicked. Override this if you want to place the element in a
  2260. * location other than where the cursor is.
  2261. * @method setDragElPos
  2262. * @param {int} iPageX the X coordinate of the mousedown or drag event
  2263. * @param {int} iPageY the Y coordinate of the mousedown or drag event
  2264. */
  2265. setDragElPos: function(iPageX, iPageY) {
  2266. // the first time we do this, we are going to check to make sure
  2267. // the element has css positioning
  2268. var el = this.getDragEl();
  2269. this.alignElWithMouse(el, iPageX, iPageY);
  2270. },
  2271. /**
  2272. * Sets the element to the location of the mousedown or click event,
  2273. * maintaining the cursor location relative to the location on the element
  2274. * that was clicked. Override this if you want to place the element in a
  2275. * location other than where the cursor is.
  2276. * @method alignElWithMouse
  2277. * @param {HTMLElement} el the element to move
  2278. * @param {int} iPageX the X coordinate of the mousedown or drag event
  2279. * @param {int} iPageY the Y coordinate of the mousedown or drag event
  2280. */
  2281. alignElWithMouse: function(el, iPageX, iPageY) {
  2282. var oCoord = this.getTargetCoord(iPageX, iPageY);
  2283. var fly = el.dom ? el : Ext.fly(el, '_dd');
  2284. if (!this.deltaSetXY) {
  2285. var aCoord = [oCoord.x, oCoord.y];
  2286. fly.setXY(aCoord);
  2287. var newLeft = fly.getLeft(true);
  2288. var newTop = fly.getTop(true);
  2289. this.deltaSetXY = [ newLeft - oCoord.x, newTop - oCoord.y ];
  2290. } else {
  2291. fly.setLeftTop(oCoord.x + this.deltaSetXY[0], oCoord.y + this.deltaSetXY[1]);
  2292. }
  2293. this.cachePosition(oCoord.x, oCoord.y);
  2294. this.autoScroll(oCoord.x, oCoord.y, el.offsetHeight, el.offsetWidth);
  2295. return oCoord;
  2296. },
  2297. /**
  2298. * Saves the most recent position so that we can reset the constraints and
  2299. * tick marks on-demand. We need to know this so that we can calculate the
  2300. * number of pixels the element is offset from its original position.
  2301. * @method cachePosition
  2302. * @param iPageX the current x position (optional, this just makes it so we
  2303. * don't have to look it up again)
  2304. * @param iPageY the current y position (optional, this just makes it so we
  2305. * don't have to look it up again)
  2306. */
  2307. cachePosition: function(iPageX, iPageY) {
  2308. if (iPageX) {
  2309. this.lastPageX = iPageX;
  2310. this.lastPageY = iPageY;
  2311. } else {
  2312. var aCoord = Ext.lib.Dom.getXY(this.getEl());
  2313. this.lastPageX = aCoord[0];
  2314. this.lastPageY = aCoord[1];
  2315. }
  2316. },
  2317. /**
  2318. * Auto-scroll the window if the dragged object has been moved beyond the
  2319. * visible window boundary.
  2320. * @method autoScroll
  2321. * @param {int} x the drag element's x position
  2322. * @param {int} y the drag element's y position
  2323. * @param {int} h the height of the drag element
  2324. * @param {int} w the width of the drag element
  2325. * @private
  2326. */
  2327. autoScroll: function(x, y, h, w) {
  2328. if (this.scroll) {
  2329. // The client height
  2330. var clientH = Ext.lib.Dom.getViewHeight();
  2331. // The client width
  2332. var clientW = Ext.lib.Dom.getViewWidth();
  2333. // The amt scrolled down
  2334. var st = this.DDM.getScrollTop();
  2335. // The amt scrolled right
  2336. var sl = this.DDM.getScrollLeft();
  2337. // Location of the bottom of the element
  2338. var bot = h + y;
  2339. // Location of the right of the element
  2340. var right = w + x;
  2341. // The distance from the cursor to the bottom of the visible area,
  2342. // adjusted so that we don't scroll if the cursor is beyond the
  2343. // element drag constraints
  2344. var toBot = (clientH + st - y - this.deltaY);
  2345. // The distance from the cursor to the right of the visible area
  2346. var toRight = (clientW + sl - x - this.deltaX);
  2347. // How close to the edge the cursor must be before we scroll
  2348. // var thresh = (document.all) ? 100 : 40;
  2349. var thresh = 40;
  2350. // How many pixels to scroll per autoscroll op. This helps to reduce
  2351. // clunky scrolling. IE is more sensitive about this ... it needs this
  2352. // value to be higher.
  2353. var scrAmt = (document.all) ? 80 : 30;
  2354. // Scroll down if we are near the bottom of the visible page and the
  2355. // obj extends below the crease
  2356. if ( bot > clientH && toBot < thresh ) {
  2357. window.scrollTo(sl, st + scrAmt);
  2358. }
  2359. // Scroll up if the window is scrolled down and the top of the object
  2360. // goes above the top border
  2361. if ( y < st && st > 0 && y - st < thresh ) {
  2362. window.scrollTo(sl, st - scrAmt);
  2363. }
  2364. // Scroll right if the obj is beyond the right border and the cursor is
  2365. // near the border.
  2366. if ( right > clientW && toRight < thresh ) {
  2367. window.scrollTo(sl + scrAmt, st);
  2368. }
  2369. // Scroll left if the window has been scrolled to the right and the obj
  2370. // extends past the left border
  2371. if ( x < sl && sl > 0 && x - sl < thresh ) {
  2372. window.scrollTo(sl - scrAmt, st);
  2373. }
  2374. }
  2375. },
  2376. /**
  2377. * Finds the location the element should be placed if we want to move
  2378. * it to where the mouse location less the click offset would place us.
  2379. * @method getTargetCoord
  2380. * @param {int} iPageX the X coordinate of the click
  2381. * @param {int} iPageY the Y coordinate of the click
  2382. * @return an object that contains the coordinates (Object.x and Object.y)
  2383. * @private
  2384. */
  2385. getTargetCoord: function(iPageX, iPageY) {
  2386. var x = iPageX - this.deltaX;
  2387. var y = iPageY - this.deltaY;
  2388. if (this.constrainX) {
  2389. if (x < this.minX) { x = this.minX; }
  2390. if (x > this.maxX) { x = this.maxX; }
  2391. }
  2392. if (this.constrainY) {
  2393. if (y < this.minY) { y = this.minY; }
  2394. if (y > this.maxY) { y = this.maxY; }
  2395. }
  2396. x = this.getTick(x, this.xTicks);
  2397. y = this.getTick(y, this.yTicks);
  2398. return {x:x, y:y};
  2399. },
  2400. /**
  2401. * Sets up config options specific to this class. Overrides
  2402. * Ext.dd.DragDrop, but all versions of this method through the
  2403. * inheritance chain are called
  2404. */
  2405. applyConfig: function() {
  2406. Ext.dd.DD.superclass.applyConfig.call(this);
  2407. this.scroll = (this.config.scroll !== false);
  2408. },
  2409. /**
  2410. * Event that fires prior to the onMouseDown event. Overrides
  2411. * Ext.dd.DragDrop.
  2412. */
  2413. b4MouseDown: function(e) {
  2414. // this.resetConstraints();
  2415. this.autoOffset(e.getPageX(),
  2416. e.getPageY());
  2417. },
  2418. /**
  2419. * Event that fires prior to the onDrag event. Overrides
  2420. * Ext.dd.DragDrop.
  2421. */
  2422. b4Drag: function(e) {
  2423. this.setDragElPos(e.getPageX(),
  2424. e.getPageY());
  2425. },
  2426. toString: function() {
  2427. return ("DD " + this.id);
  2428. }
  2429. //////////////////////////////////////////////////////////////////////////
  2430. // Debugging ygDragDrop events that can be overridden
  2431. //////////////////////////////////////////////////////////////////////////
  2432. /*
  2433. startDrag: function(x, y) {
  2434. },
  2435. onDrag: function(e) {
  2436. },
  2437. onDragEnter: function(e, id) {
  2438. },
  2439. onDragOver: function(e, id) {
  2440. },
  2441. onDragOut: function(e, id) {
  2442. },
  2443. onDragDrop: function(e, id) {
  2444. },
  2445. endDrag: function(e) {
  2446. }
  2447. */
  2448. });
  2449. /**
  2450. * @class Ext.dd.DDProxy
  2451. * A DragDrop implementation that inserts an empty, bordered div into
  2452. * the document that follows the cursor during drag operations. At the time of
  2453. * the click, the frame div is resized to the dimensions of the linked html
  2454. * element, and moved to the exact location of the linked element.
  2455. *
  2456. * References to the "frame" element refer to the single proxy element that
  2457. * was created to be dragged in place of all DDProxy elements on the
  2458. * page.
  2459. *
  2460. * @extends Ext.dd.DD
  2461. * @constructor
  2462. * @param {String} id the id of the linked html element
  2463. * @param {String} sGroup the group of related DragDrop objects
  2464. * @param {object} config an object containing configurable attributes
  2465. * Valid properties for DDProxy in addition to those in DragDrop:
  2466. * resizeFrame, centerFrame, dragElId
  2467. */
  2468. Ext.dd.DDProxy = function(id, sGroup, config) {
  2469. if (id) {
  2470. this.init(id, sGroup, config);
  2471. this.initFrame();
  2472. }
  2473. };
  2474. /**
  2475. * The default drag frame div id
  2476. * @property Ext.dd.DDProxy.dragElId
  2477. * @type String
  2478. * @static
  2479. */
  2480. Ext.dd.DDProxy.dragElId = "ygddfdiv";
  2481. Ext.extend(Ext.dd.DDProxy, Ext.dd.DD, {
  2482. /**
  2483. * By default we resize the drag frame to be the same size as the element
  2484. * we want to drag (this is to get the frame effect). We can turn it off
  2485. * if we want a different behavior.
  2486. * @property resizeFrame
  2487. * @type boolean
  2488. */
  2489. resizeFrame: true,
  2490. /**
  2491. * By default the frame is positioned exactly where the drag element is, so
  2492. * we use the cursor offset provided by Ext.dd.DD. Another option that works only if
  2493. * you do not have constraints on the obj is to have the drag frame centered
  2494. * around the cursor. Set centerFrame to true for this effect.
  2495. * @property centerFrame
  2496. * @type boolean
  2497. */
  2498. centerFrame: false,
  2499. /**
  2500. * Creates the proxy element if it does not yet exist
  2501. * @method createFrame
  2502. */
  2503. createFrame: function() {
  2504. var self = this;
  2505. var body = document.body;
  2506. if (!body || !body.firstChild) {
  2507. setTimeout( function() { self.createFrame(); }, 50 );
  2508. return;
  2509. }
  2510. var div = this.getDragEl();
  2511. if (!div) {
  2512. div = document.createElement("div");
  2513. div.id = this.dragElId;
  2514. var s = div.style;
  2515. s.position = "absolute";
  2516. s.visibility = "hidden";
  2517. s.cursor = "move";
  2518. s.border = "2px solid #aaa";
  2519. s.zIndex = 999;
  2520. // appendChild can blow up IE if invoked prior to the window load event
  2521. // while rendering a table. It is possible there are other scenarios
  2522. // that would cause this to happen as well.
  2523. body.insertBefore(div, body.firstChild);
  2524. }
  2525. },
  2526. /**
  2527. * Initialization for the drag frame element. Must be called in the
  2528. * constructor of all subclasses
  2529. * @method initFrame
  2530. */
  2531. initFrame: function() {
  2532. this.createFrame();
  2533. },
  2534. applyConfig: function() {
  2535. Ext.dd.DDProxy.superclass.applyConfig.call(this);
  2536. this.resizeFrame = (this.config.resizeFrame !== false);
  2537. this.centerFrame = (this.config.centerFrame);
  2538. this.setDragElId(this.config.dragElId || Ext.dd.DDProxy.dragElId);
  2539. },
  2540. /**
  2541. * Resizes the drag frame to the dimensions of the clicked object, positions
  2542. * it over the object, and finally displays it
  2543. * @method showFrame
  2544. * @param {int} iPageX X click position
  2545. * @param {int} iPageY Y click position
  2546. * @private
  2547. */
  2548. showFrame: function(iPageX, iPageY) {
  2549. var el = this.getEl();
  2550. var dragEl = this.getDragEl();
  2551. var s = dragEl.style;
  2552. this._resizeProxy();
  2553. if (this.centerFrame) {
  2554. this.setDelta( Math.round(parseInt(s.width, 10)/2),
  2555. Math.round(parseInt(s.height, 10)/2) );
  2556. }
  2557. this.setDragElPos(iPageX, iPageY);
  2558. Ext.fly(dragEl).show();
  2559. },
  2560. /**
  2561. * The proxy is automatically resized to the dimensions of the linked
  2562. * element when a drag is initiated, unless resizeFrame is set to false
  2563. * @method _resizeProxy
  2564. * @private
  2565. */
  2566. _resizeProxy: function() {
  2567. if (this.resizeFrame) {
  2568. var el = this.getEl();
  2569. Ext.fly(this.getDragEl()).setSize(el.offsetWidth, el.offsetHeight);
  2570. }
  2571. },
  2572. // overrides Ext.dd.DragDrop
  2573. b4MouseDown: function(e) {
  2574. var x = e.getPageX();
  2575. var y = e.getPageY();
  2576. this.autoOffset(x, y);
  2577. this.setDragElPos(x, y);
  2578. },
  2579. // overrides Ext.dd.DragDrop
  2580. b4StartDrag: function(x, y) {
  2581. // show the drag frame
  2582. this.showFrame(x, y);
  2583. },
  2584. // overrides Ext.dd.DragDrop
  2585. b4EndDrag: function(e) {
  2586. Ext.fly(this.getDragEl()).hide();
  2587. },
  2588. // overrides Ext.dd.DragDrop
  2589. // By default we try to move the element to the last location of the frame.
  2590. // This is so that the default behavior mirrors that of Ext.dd.DD.
  2591. endDrag: function(e) {
  2592. var lel = this.getEl();
  2593. var del = this.getDragEl();
  2594. // Show the drag frame briefly so we can get its position
  2595. del.style.visibility = "";
  2596. this.beforeMove();
  2597. // Hide the linked element before the move to get around a Safari
  2598. // rendering bug.
  2599. lel.style.visibility = "hidden";
  2600. Ext.dd.DDM.moveToEl(lel, del);
  2601. del.style.visibility = "hidden";
  2602. lel.style.visibility = "";
  2603. this.afterDrag();
  2604. },
  2605. beforeMove : function(){
  2606. },
  2607. afterDrag : function(){
  2608. },
  2609. toString: function() {
  2610. return ("DDProxy " + this.id);
  2611. }
  2612. });
  2613. /**
  2614. * @class Ext.dd.DDTarget
  2615. * A DragDrop implementation that does not move, but can be a drop
  2616. * target. You would get the same result by simply omitting implementation
  2617. * for the event callbacks, but this way we reduce the processing cost of the
  2618. * event listener and the callbacks.
  2619. * @extends Ext.dd.DragDrop
  2620. * @constructor
  2621. * @param {String} id the id of the element that is a drop target
  2622. * @param {String} sGroup the group of related DragDrop objects
  2623. * @param {object} config an object containing configurable attributes
  2624. * Valid properties for DDTarget in addition to those in
  2625. * DragDrop:
  2626. * none
  2627. */
  2628. Ext.dd.DDTarget = function(id, sGroup, config) {
  2629. if (id) {
  2630. this.initTarget(id, sGroup, config);
  2631. }
  2632. };
  2633. // Ext.dd.DDTarget.prototype = new Ext.dd.DragDrop();
  2634. Ext.extend(Ext.dd.DDTarget, Ext.dd.DragDrop, {
  2635. /**
  2636. * @hide
  2637. * Overridden and disabled. A DDTarget does not support being dragged.
  2638. * @method
  2639. */
  2640. getDragEl: Ext.emptyFn,
  2641. /**
  2642. * @hide
  2643. * Overridden and disabled. A DDTarget does not support being dragged.
  2644. * @method
  2645. */
  2646. isValidHandleChild: Ext.emptyFn,
  2647. /**
  2648. * @hide
  2649. * Overridden and disabled. A DDTarget does not support being dragged.
  2650. * @method
  2651. */
  2652. startDrag: Ext.emptyFn,
  2653. /**
  2654. * @hide
  2655. * Overridden and disabled. A DDTarget does not support being dragged.
  2656. * @method
  2657. */
  2658. endDrag: Ext.emptyFn,
  2659. /**
  2660. * @hide
  2661. * Overridden and disabled. A DDTarget does not support being dragged.
  2662. * @method
  2663. */
  2664. onDrag: Ext.emptyFn,
  2665. /**
  2666. * @hide
  2667. * Overridden and disabled. A DDTarget does not support being dragged.
  2668. * @method
  2669. */
  2670. onDragDrop: Ext.emptyFn,
  2671. /**
  2672. * @hide
  2673. * Overridden and disabled. A DDTarget does not support being dragged.
  2674. * @method
  2675. */
  2676. onDragEnter: Ext.emptyFn,
  2677. /**
  2678. * @hide
  2679. * Overridden and disabled. A DDTarget does not support being dragged.
  2680. * @method
  2681. */
  2682. onDragOut: Ext.emptyFn,
  2683. /**
  2684. * @hide
  2685. * Overridden and disabled. A DDTarget does not support being dragged.
  2686. * @method
  2687. */
  2688. onDragOver: Ext.emptyFn,
  2689. /**
  2690. * @hide
  2691. * Overridden and disabled. A DDTarget does not support being dragged.
  2692. * @method
  2693. */
  2694. onInvalidDrop: Ext.emptyFn,
  2695. /**
  2696. * @hide
  2697. * Overridden and disabled. A DDTarget does not support being dragged.
  2698. * @method
  2699. */
  2700. onMouseDown: Ext.emptyFn,
  2701. /**
  2702. * @hide
  2703. * Overridden and disabled. A DDTarget does not support being dragged.
  2704. * @method
  2705. */
  2706. onMouseUp: Ext.emptyFn,
  2707. /**
  2708. * @hide
  2709. * Overridden and disabled. A DDTarget does not support being dragged.
  2710. * @method
  2711. */
  2712. setXConstraint: Ext.emptyFn,
  2713. /**
  2714. * @hide
  2715. * Overridden and disabled. A DDTarget does not support being dragged.
  2716. * @method
  2717. */
  2718. setYConstraint: Ext.emptyFn,
  2719. /**
  2720. * @hide
  2721. * Overridden and disabled. A DDTarget does not support being dragged.
  2722. * @method
  2723. */
  2724. resetConstraints: Ext.emptyFn,
  2725. /**
  2726. * @hide
  2727. * Overridden and disabled. A DDTarget does not support being dragged.
  2728. * @method
  2729. */
  2730. clearConstraints: Ext.emptyFn,
  2731. /**
  2732. * @hide
  2733. * Overridden and disabled. A DDTarget does not support being dragged.
  2734. * @method
  2735. */
  2736. clearTicks: Ext.emptyFn,
  2737. /**
  2738. * @hide
  2739. * Overridden and disabled. A DDTarget does not support being dragged.
  2740. * @method
  2741. */
  2742. setInitPosition: Ext.emptyFn,
  2743. /**
  2744. * @hide
  2745. * Overridden and disabled. A DDTarget does not support being dragged.
  2746. * @method
  2747. */
  2748. setDragElId: Ext.emptyFn,
  2749. /**
  2750. * @hide
  2751. * Overridden and disabled. A DDTarget does not support being dragged.
  2752. * @method
  2753. */
  2754. setHandleElId: Ext.emptyFn,
  2755. /**
  2756. * @hide
  2757. * Overridden and disabled. A DDTarget does not support being dragged.
  2758. * @method
  2759. */
  2760. setOuterHandleElId: Ext.emptyFn,
  2761. /**
  2762. * @hide
  2763. * Overridden and disabled. A DDTarget does not support being dragged.
  2764. * @method
  2765. */
  2766. addInvalidHandleClass: Ext.emptyFn,
  2767. /**
  2768. * @hide
  2769. * Overridden and disabled. A DDTarget does not support being dragged.
  2770. * @method
  2771. */
  2772. addInvalidHandleId: Ext.emptyFn,
  2773. /**
  2774. * @hide
  2775. * Overridden and disabled. A DDTarget does not support being dragged.
  2776. * @method
  2777. */
  2778. addInvalidHandleType: Ext.emptyFn,
  2779. /**
  2780. * @hide
  2781. * Overridden and disabled. A DDTarget does not support being dragged.
  2782. * @method
  2783. */
  2784. removeInvalidHandleClass: Ext.emptyFn,
  2785. /**
  2786. * @hide
  2787. * Overridden and disabled. A DDTarget does not support being dragged.
  2788. * @method
  2789. */
  2790. removeInvalidHandleId: Ext.emptyFn,
  2791. /**
  2792. * @hide
  2793. * Overridden and disabled. A DDTarget does not support being dragged.
  2794. * @method
  2795. */
  2796. removeInvalidHandleType: Ext.emptyFn,
  2797. toString: function() {
  2798. return ("DDTarget " + this.id);
  2799. }
  2800. });/**
  2801. * @class Ext.dd.DragTracker
  2802. * @extends Ext.util.Observable
  2803. * A DragTracker listens for drag events on an Element and fires events at the start and end of the drag,
  2804. * as well as during the drag. This is useful for components such as {@link Ext.slider.MultiSlider}, where there is
  2805. * an element that can be dragged around to change the Slider's value.
  2806. * DragTracker provides a series of template methods that should be overridden to provide functionality
  2807. * in response to detected drag operations. These are onBeforeStart, onStart, onDrag and onEnd.
  2808. * See {@link Ext.slider.MultiSlider}'s initEvents function for an example implementation.
  2809. */
  2810. Ext.dd.DragTracker = Ext.extend(Ext.util.Observable, {
  2811. /**
  2812. * @cfg {Boolean} active
  2813. * Defaults to <tt>false</tt>.
  2814. */
  2815. active: false,
  2816. /**
  2817. * @cfg {Number} tolerance
  2818. * Number of pixels the drag target must be moved before dragging is considered to have started. Defaults to <tt>5</tt>.
  2819. */
  2820. tolerance: 5,
  2821. /**
  2822. * @cfg {Boolean/Number} autoStart
  2823. * Defaults to <tt>false</tt>. Specify <tt>true</tt> to defer trigger start by 1000 ms.
  2824. * Specify a Number for the number of milliseconds to defer trigger start.
  2825. */
  2826. autoStart: false,
  2827. constructor : function(config){
  2828. Ext.apply(this, config);
  2829. this.addEvents(
  2830. /**
  2831. * @event mousedown
  2832. * @param {Object} this
  2833. * @param {Object} e event object
  2834. */
  2835. 'mousedown',
  2836. /**
  2837. * @event mouseup
  2838. * @param {Object} this
  2839. * @param {Object} e event object
  2840. */
  2841. 'mouseup',
  2842. /**
  2843. * @event mousemove
  2844. * @param {Object} this
  2845. * @param {Object} e event object
  2846. */
  2847. 'mousemove',
  2848. /**
  2849. * @event dragstart
  2850. * @param {Object} this
  2851. * @param {Object} e event object
  2852. */
  2853. 'dragstart',
  2854. /**
  2855. * @event dragend
  2856. * @param {Object} this
  2857. * @param {Object} e event object
  2858. */
  2859. 'dragend',
  2860. /**
  2861. * @event drag
  2862. * @param {Object} this
  2863. * @param {Object} e event object
  2864. */
  2865. 'drag'
  2866. );
  2867. this.dragRegion = new Ext.lib.Region(0,0,0,0);
  2868. if(this.el){
  2869. this.initEl(this.el);
  2870. }
  2871. Ext.dd.DragTracker.superclass.constructor.call(this, config);
  2872. },
  2873. initEl: function(el){
  2874. this.el = Ext.get(el);
  2875. el.on('mousedown', this.onMouseDown, this,
  2876. this.delegate ? {delegate: this.delegate} : undefined);
  2877. },
  2878. destroy : function(){
  2879. this.el.un('mousedown', this.onMouseDown, this);
  2880. delete this.el;
  2881. },
  2882. onMouseDown: function(e, target){
  2883. if(this.fireEvent('mousedown', this, e) !== false && this.onBeforeStart(e) !== false){
  2884. this.startXY = this.lastXY = e.getXY();
  2885. this.dragTarget = this.delegate ? target : this.el.dom;
  2886. if(this.preventDefault !== false){
  2887. e.preventDefault();
  2888. }
  2889. Ext.getDoc().on({
  2890. scope: this,
  2891. mouseup: this.onMouseUp,
  2892. mousemove: this.onMouseMove,
  2893. selectstart: this.stopSelect
  2894. });
  2895. if(this.autoStart){
  2896. this.timer = this.triggerStart.defer(this.autoStart === true ? 1000 : this.autoStart, this, [e]);
  2897. }
  2898. }
  2899. },
  2900. onMouseMove: function(e, target){
  2901. // HACK: IE hack to see if button was released outside of window. Resolved in IE9.
  2902. var ieCheck = Ext.isIE6 || Ext.isIE7 || Ext.isIE8;
  2903. if(this.active && ieCheck && !e.browserEvent.button){
  2904. e.preventDefault();
  2905. this.onMouseUp(e);
  2906. return;
  2907. }
  2908. e.preventDefault();
  2909. var xy = e.getXY(), s = this.startXY;
  2910. this.lastXY = xy;
  2911. if(!this.active){
  2912. if(Math.abs(s[0]-xy[0]) > this.tolerance || Math.abs(s[1]-xy[1]) > this.tolerance){
  2913. this.triggerStart(e);
  2914. }else{
  2915. return;
  2916. }
  2917. }
  2918. this.fireEvent('mousemove', this, e);
  2919. this.onDrag(e);
  2920. this.fireEvent('drag', this, e);
  2921. },
  2922. onMouseUp: function(e) {
  2923. var doc = Ext.getDoc(),
  2924. wasActive = this.active;
  2925. doc.un('mousemove', this.onMouseMove, this);
  2926. doc.un('mouseup', this.onMouseUp, this);
  2927. doc.un('selectstart', this.stopSelect, this);
  2928. e.preventDefault();
  2929. this.clearStart();
  2930. this.active = false;
  2931. delete this.elRegion;
  2932. this.fireEvent('mouseup', this, e);
  2933. if(wasActive){
  2934. this.onEnd(e);
  2935. this.fireEvent('dragend', this, e);
  2936. }
  2937. },
  2938. triggerStart: function(e) {
  2939. this.clearStart();
  2940. this.active = true;
  2941. this.onStart(e);
  2942. this.fireEvent('dragstart', this, e);
  2943. },
  2944. clearStart : function() {
  2945. if(this.timer){
  2946. clearTimeout(this.timer);
  2947. delete this.timer;
  2948. }
  2949. },
  2950. stopSelect : function(e) {
  2951. e.stopEvent();
  2952. return false;
  2953. },
  2954. /**
  2955. * Template method which should be overridden by each DragTracker instance. Called when the user first clicks and
  2956. * holds the mouse button down. Return false to disallow the drag
  2957. * @param {Ext.EventObject} e The event object
  2958. */
  2959. onBeforeStart : function(e) {
  2960. },
  2961. /**
  2962. * Template method which should be overridden by each DragTracker instance. Called when a drag operation starts
  2963. * (e.g. the user has moved the tracked element beyond the specified tolerance)
  2964. * @param {Ext.EventObject} e The event object
  2965. */
  2966. onStart : function(xy) {
  2967. },
  2968. /**
  2969. * Template method which should be overridden by each DragTracker instance. Called whenever a drag has been detected.
  2970. * @param {Ext.EventObject} e The event object
  2971. */
  2972. onDrag : function(e) {
  2973. },
  2974. /**
  2975. * Template method which should be overridden by each DragTracker instance. Called when a drag operation has been completed
  2976. * (e.g. the user clicked and held the mouse down, dragged the element and then released the mouse button)
  2977. * @param {Ext.EventObject} e The event object
  2978. */
  2979. onEnd : function(e) {
  2980. },
  2981. /**
  2982. * Returns the drag target
  2983. * @return {Ext.Element} The element currently being tracked
  2984. */
  2985. getDragTarget : function(){
  2986. return this.dragTarget;
  2987. },
  2988. getDragCt : function(){
  2989. return this.el;
  2990. },
  2991. getXY : function(constrain){
  2992. return constrain ?
  2993. this.constrainModes[constrain].call(this, this.lastXY) : this.lastXY;
  2994. },
  2995. getOffset : function(constrain){
  2996. var xy = this.getXY(constrain),
  2997. s = this.startXY;
  2998. return [s[0]-xy[0], s[1]-xy[1]];
  2999. },
  3000. constrainModes: {
  3001. 'point' : function(xy){
  3002. if(!this.elRegion){
  3003. this.elRegion = this.getDragCt().getRegion();
  3004. }
  3005. var dr = this.dragRegion;
  3006. dr.left = xy[0];
  3007. dr.top = xy[1];
  3008. dr.right = xy[0];
  3009. dr.bottom = xy[1];
  3010. dr.constrainTo(this.elRegion);
  3011. return [dr.left, dr.top];
  3012. }
  3013. }
  3014. });/**
  3015. * @class Ext.dd.ScrollManager
  3016. * <p>Provides automatic scrolling of overflow regions in the page during drag operations.</p>
  3017. * <p>The ScrollManager configs will be used as the defaults for any scroll container registered with it,
  3018. * but you can also override most of the configs per scroll container by adding a
  3019. * <tt>ddScrollConfig</tt> object to the target element that contains these properties: {@link #hthresh},
  3020. * {@link #vthresh}, {@link #increment} and {@link #frequency}. Example usage:
  3021. * <pre><code>
  3022. var el = Ext.get('scroll-ct');
  3023. el.ddScrollConfig = {
  3024. vthresh: 50,
  3025. hthresh: -1,
  3026. frequency: 100,
  3027. increment: 200
  3028. };
  3029. Ext.dd.ScrollManager.register(el);
  3030. </code></pre>
  3031. * <b>Note: This class uses "Point Mode" and is untested in "Intersect Mode".</b>
  3032. * @singleton
  3033. */
  3034. Ext.dd.ScrollManager = function(){
  3035. var ddm = Ext.dd.DragDropMgr;
  3036. var els = {};
  3037. var dragEl = null;
  3038. var proc = {};
  3039. var onStop = function(e){
  3040. dragEl = null;
  3041. clearProc();
  3042. };
  3043. var triggerRefresh = function(){
  3044. if(ddm.dragCurrent){
  3045. ddm.refreshCache(ddm.dragCurrent.groups);
  3046. }
  3047. };
  3048. var doScroll = function(){
  3049. if(ddm.dragCurrent){
  3050. var dds = Ext.dd.ScrollManager;
  3051. var inc = proc.el.ddScrollConfig ?
  3052. proc.el.ddScrollConfig.increment : dds.increment;
  3053. if(!dds.animate){
  3054. if(proc.el.scroll(proc.dir, inc)){
  3055. triggerRefresh();
  3056. }
  3057. }else{
  3058. proc.el.scroll(proc.dir, inc, true, dds.animDuration, triggerRefresh);
  3059. }
  3060. }
  3061. };
  3062. var clearProc = function(){
  3063. if(proc.id){
  3064. clearInterval(proc.id);
  3065. }
  3066. proc.id = 0;
  3067. proc.el = null;
  3068. proc.dir = "";
  3069. };
  3070. var startProc = function(el, dir){
  3071. clearProc();
  3072. proc.el = el;
  3073. proc.dir = dir;
  3074. var group = el.ddScrollConfig ? el.ddScrollConfig.ddGroup : undefined,
  3075. freq = (el.ddScrollConfig && el.ddScrollConfig.frequency)
  3076. ? el.ddScrollConfig.frequency
  3077. : Ext.dd.ScrollManager.frequency;
  3078. if (group === undefined || ddm.dragCurrent.ddGroup == group) {
  3079. proc.id = setInterval(doScroll, freq);
  3080. }
  3081. };
  3082. var onFire = function(e, isDrop){
  3083. if(isDrop || !ddm.dragCurrent){ return; }
  3084. var dds = Ext.dd.ScrollManager;
  3085. if(!dragEl || dragEl != ddm.dragCurrent){
  3086. dragEl = ddm.dragCurrent;
  3087. // refresh regions on drag start
  3088. dds.refreshCache();
  3089. }
  3090. var xy = Ext.lib.Event.getXY(e);
  3091. var pt = new Ext.lib.Point(xy[0], xy[1]);
  3092. for(var id in els){
  3093. var el = els[id], r = el._region;
  3094. var c = el.ddScrollConfig ? el.ddScrollConfig : dds;
  3095. if(r && r.contains(pt) && el.isScrollable()){
  3096. if(r.bottom - pt.y <= c.vthresh){
  3097. if(proc.el != el){
  3098. startProc(el, "down");
  3099. }
  3100. return;
  3101. }else if(r.right - pt.x <= c.hthresh){
  3102. if(proc.el != el){
  3103. startProc(el, "left");
  3104. }
  3105. return;
  3106. }else if(pt.y - r.top <= c.vthresh){
  3107. if(proc.el != el){
  3108. startProc(el, "up");
  3109. }
  3110. return;
  3111. }else if(pt.x - r.left <= c.hthresh){
  3112. if(proc.el != el){
  3113. startProc(el, "right");
  3114. }
  3115. return;
  3116. }
  3117. }
  3118. }
  3119. clearProc();
  3120. };
  3121. ddm.fireEvents = ddm.fireEvents.createSequence(onFire, ddm);
  3122. ddm.stopDrag = ddm.stopDrag.createSequence(onStop, ddm);
  3123. return {
  3124. /**
  3125. * Registers new overflow element(s) to auto scroll
  3126. * @param {Mixed/Array} el The id of or the element to be scrolled or an array of either
  3127. */
  3128. register : function(el){
  3129. if(Ext.isArray(el)){
  3130. for(var i = 0, len = el.length; i < len; i++) {
  3131. this.register(el[i]);
  3132. }
  3133. }else{
  3134. el = Ext.get(el);
  3135. els[el.id] = el;
  3136. }
  3137. },
  3138. /**
  3139. * Unregisters overflow element(s) so they are no longer scrolled
  3140. * @param {Mixed/Array} el The id of or the element to be removed or an array of either
  3141. */
  3142. unregister : function(el){
  3143. if(Ext.isArray(el)){
  3144. for(var i = 0, len = el.length; i < len; i++) {
  3145. this.unregister(el[i]);
  3146. }
  3147. }else{
  3148. el = Ext.get(el);
  3149. delete els[el.id];
  3150. }
  3151. },
  3152. /**
  3153. * The number of pixels from the top or bottom edge of a container the pointer needs to be to
  3154. * trigger scrolling (defaults to 25)
  3155. * @type Number
  3156. */
  3157. vthresh : 25,
  3158. /**
  3159. * The number of pixels from the right or left edge of a container the pointer needs to be to
  3160. * trigger scrolling (defaults to 25)
  3161. * @type Number
  3162. */
  3163. hthresh : 25,
  3164. /**
  3165. * The number of pixels to scroll in each scroll increment (defaults to 100)
  3166. * @type Number
  3167. */
  3168. increment : 100,
  3169. /**
  3170. * The frequency of scrolls in milliseconds (defaults to 500)
  3171. * @type Number
  3172. */
  3173. frequency : 500,
  3174. /**
  3175. * True to animate the scroll (defaults to true)
  3176. * @type Boolean
  3177. */
  3178. animate: true,
  3179. /**
  3180. * The animation duration in seconds -
  3181. * MUST BE less than Ext.dd.ScrollManager.frequency! (defaults to .4)
  3182. * @type Number
  3183. */
  3184. animDuration: .4,
  3185. /**
  3186. * The named drag drop {@link Ext.dd.DragSource#ddGroup group} to which this container belongs (defaults to undefined).
  3187. * If a ddGroup is specified, then container scrolling will only occur when a dragged object is in the same ddGroup.
  3188. * @type String
  3189. */
  3190. ddGroup: undefined,
  3191. /**
  3192. * Manually trigger a cache refresh.
  3193. */
  3194. refreshCache : function(){
  3195. for(var id in els){
  3196. if(typeof els[id] == 'object'){ // for people extending the object prototype
  3197. els[id]._region = els[id].getRegion();
  3198. }
  3199. }
  3200. }
  3201. };
  3202. }();/**
  3203. * @class Ext.dd.Registry
  3204. * Provides easy access to all drag drop components that are registered on a page. Items can be retrieved either
  3205. * directly by DOM node id, or by passing in the drag drop event that occurred and looking up the event target.
  3206. * @singleton
  3207. */
  3208. Ext.dd.Registry = function(){
  3209. var elements = {};
  3210. var handles = {};
  3211. var autoIdSeed = 0;
  3212. var getId = function(el, autogen){
  3213. if(typeof el == "string"){
  3214. return el;
  3215. }
  3216. var id = el.id;
  3217. if(!id && autogen !== false){
  3218. id = "extdd-" + (++autoIdSeed);
  3219. el.id = id;
  3220. }
  3221. return id;
  3222. };
  3223. return {
  3224. /**
  3225. * Resgister a drag drop element
  3226. * @param {String/HTMLElement} element The id or DOM node to register
  3227. * @param {Object} data (optional) An custom data object that will be passed between the elements that are involved
  3228. * in drag drop operations. You can populate this object with any arbitrary properties that your own code
  3229. * knows how to interpret, plus there are some specific properties known to the Registry that should be
  3230. * populated in the data object (if applicable):
  3231. * <pre>
  3232. Value Description<br />
  3233. --------- ------------------------------------------<br />
  3234. handles Array of DOM nodes that trigger dragging<br />
  3235. for the element being registered<br />
  3236. isHandle True if the element passed in triggers<br />
  3237. dragging itself, else false
  3238. </pre>
  3239. */
  3240. register : function(el, data){
  3241. data = data || {};
  3242. if(typeof el == "string"){
  3243. el = document.getElementById(el);
  3244. }
  3245. data.ddel = el;
  3246. elements[getId(el)] = data;
  3247. if(data.isHandle !== false){
  3248. handles[data.ddel.id] = data;
  3249. }
  3250. if(data.handles){
  3251. var hs = data.handles;
  3252. for(var i = 0, len = hs.length; i < len; i++){
  3253. handles[getId(hs[i])] = data;
  3254. }
  3255. }
  3256. },
  3257. /**
  3258. * Unregister a drag drop element
  3259. * @param {String/HTMLElement} element The id or DOM node to unregister
  3260. */
  3261. unregister : function(el){
  3262. var id = getId(el, false);
  3263. var data = elements[id];
  3264. if(data){
  3265. delete elements[id];
  3266. if(data.handles){
  3267. var hs = data.handles;
  3268. for(var i = 0, len = hs.length; i < len; i++){
  3269. delete handles[getId(hs[i], false)];
  3270. }
  3271. }
  3272. }
  3273. },
  3274. /**
  3275. * Returns the handle registered for a DOM Node by id
  3276. * @param {String/HTMLElement} id The DOM node or id to look up
  3277. * @return {Object} handle The custom handle data
  3278. */
  3279. getHandle : function(id){
  3280. if(typeof id != "string"){ // must be element?
  3281. id = id.id;
  3282. }
  3283. return handles[id];
  3284. },
  3285. /**
  3286. * Returns the handle that is registered for the DOM node that is the target of the event
  3287. * @param {Event} e The event
  3288. * @return {Object} handle The custom handle data
  3289. */
  3290. getHandleFromEvent : function(e){
  3291. var t = Ext.lib.Event.getTarget(e);
  3292. return t ? handles[t.id] : null;
  3293. },
  3294. /**
  3295. * Returns a custom data object that is registered for a DOM node by id
  3296. * @param {String/HTMLElement} id The DOM node or id to look up
  3297. * @return {Object} data The custom data
  3298. */
  3299. getTarget : function(id){
  3300. if(typeof id != "string"){ // must be element?
  3301. id = id.id;
  3302. }
  3303. return elements[id];
  3304. },
  3305. /**
  3306. * Returns a custom data object that is registered for the DOM node that is the target of the event
  3307. * @param {Event} e The event
  3308. * @return {Object} data The custom data
  3309. */
  3310. getTargetFromEvent : function(e){
  3311. var t = Ext.lib.Event.getTarget(e);
  3312. return t ? elements[t.id] || handles[t.id] : null;
  3313. }
  3314. };
  3315. }();/**
  3316. * @class Ext.dd.StatusProxy
  3317. * A specialized drag proxy that supports a drop status icon, {@link Ext.Layer} styles and auto-repair. This is the
  3318. * default drag proxy used by all Ext.dd components.
  3319. * @constructor
  3320. * @param {Object} config
  3321. */
  3322. Ext.dd.StatusProxy = function(config){
  3323. Ext.apply(this, config);
  3324. this.id = this.id || Ext.id();
  3325. this.el = new Ext.Layer({
  3326. dh: {
  3327. id: this.id, tag: "div", cls: "x-dd-drag-proxy "+this.dropNotAllowed, children: [
  3328. {tag: "div", cls: "x-dd-drop-icon"},
  3329. {tag: "div", cls: "x-dd-drag-ghost"}
  3330. ]
  3331. },
  3332. shadow: !config || config.shadow !== false
  3333. });
  3334. this.ghost = Ext.get(this.el.dom.childNodes[1]);
  3335. this.dropStatus = this.dropNotAllowed;
  3336. };
  3337. Ext.dd.StatusProxy.prototype = {
  3338. /**
  3339. * @cfg {String} dropAllowed
  3340. * The CSS class to apply to the status element when drop is allowed (defaults to "x-dd-drop-ok").
  3341. */
  3342. dropAllowed : "x-dd-drop-ok",
  3343. /**
  3344. * @cfg {String} dropNotAllowed
  3345. * The CSS class to apply to the status element when drop is not allowed (defaults to "x-dd-drop-nodrop").
  3346. */
  3347. dropNotAllowed : "x-dd-drop-nodrop",
  3348. /**
  3349. * Updates the proxy's visual element to indicate the status of whether or not drop is allowed
  3350. * over the current target element.
  3351. * @param {String} cssClass The css class for the new drop status indicator image
  3352. */
  3353. setStatus : function(cssClass){
  3354. cssClass = cssClass || this.dropNotAllowed;
  3355. if(this.dropStatus != cssClass){
  3356. this.el.replaceClass(this.dropStatus, cssClass);
  3357. this.dropStatus = cssClass;
  3358. }
  3359. },
  3360. /**
  3361. * Resets the status indicator to the default dropNotAllowed value
  3362. * @param {Boolean} clearGhost True to also remove all content from the ghost, false to preserve it
  3363. */
  3364. reset : function(clearGhost){
  3365. this.el.dom.className = "x-dd-drag-proxy " + this.dropNotAllowed;
  3366. this.dropStatus = this.dropNotAllowed;
  3367. if(clearGhost){
  3368. this.ghost.update("");
  3369. }
  3370. },
  3371. /**
  3372. * Updates the contents of the ghost element
  3373. * @param {String/HTMLElement} html The html that will replace the current innerHTML of the ghost element, or a
  3374. * DOM node to append as the child of the ghost element (in which case the innerHTML will be cleared first).
  3375. */
  3376. update : function(html){
  3377. if(typeof html == "string"){
  3378. this.ghost.update(html);
  3379. }else{
  3380. this.ghost.update("");
  3381. html.style.margin = "0";
  3382. this.ghost.dom.appendChild(html);
  3383. }
  3384. var el = this.ghost.dom.firstChild;
  3385. if(el){
  3386. Ext.fly(el).setStyle('float', 'none');
  3387. }
  3388. },
  3389. /**
  3390. * Returns the underlying proxy {@link Ext.Layer}
  3391. * @return {Ext.Layer} el
  3392. */
  3393. getEl : function(){
  3394. return this.el;
  3395. },
  3396. /**
  3397. * Returns the ghost element
  3398. * @return {Ext.Element} el
  3399. */
  3400. getGhost : function(){
  3401. return this.ghost;
  3402. },
  3403. /**
  3404. * Hides the proxy
  3405. * @param {Boolean} clear True to reset the status and clear the ghost contents, false to preserve them
  3406. */
  3407. hide : function(clear){
  3408. this.el.hide();
  3409. if(clear){
  3410. this.reset(true);
  3411. }
  3412. },
  3413. /**
  3414. * Stops the repair animation if it's currently running
  3415. */
  3416. stop : function(){
  3417. if(this.anim && this.anim.isAnimated && this.anim.isAnimated()){
  3418. this.anim.stop();
  3419. }
  3420. },
  3421. /**
  3422. * Displays this proxy
  3423. */
  3424. show : function(){
  3425. this.el.show();
  3426. },
  3427. /**
  3428. * Force the Layer to sync its shadow and shim positions to the element
  3429. */
  3430. sync : function(){
  3431. this.el.sync();
  3432. },
  3433. /**
  3434. * Causes the proxy to return to its position of origin via an animation. Should be called after an
  3435. * invalid drop operation by the item being dragged.
  3436. * @param {Array} xy The XY position of the element ([x, y])
  3437. * @param {Function} callback The function to call after the repair is complete.
  3438. * @param {Object} scope The scope (<code>this</code> reference) in which the callback function is executed. Defaults to the browser window.
  3439. */
  3440. repair : function(xy, callback, scope){
  3441. this.callback = callback;
  3442. this.scope = scope;
  3443. if(xy && this.animRepair !== false){
  3444. this.el.addClass("x-dd-drag-repair");
  3445. this.el.hideUnders(true);
  3446. this.anim = this.el.shift({
  3447. duration: this.repairDuration || .5,
  3448. easing: 'easeOut',
  3449. xy: xy,
  3450. stopFx: true,
  3451. callback: this.afterRepair,
  3452. scope: this
  3453. });
  3454. }else{
  3455. this.afterRepair();
  3456. }
  3457. },
  3458. // private
  3459. afterRepair : function(){
  3460. this.hide(true);
  3461. if(typeof this.callback == "function"){
  3462. this.callback.call(this.scope || this);
  3463. }
  3464. this.callback = null;
  3465. this.scope = null;
  3466. },
  3467. destroy: function(){
  3468. Ext.destroy(this.ghost, this.el);
  3469. }
  3470. };/**
  3471. * @class Ext.dd.DragSource
  3472. * @extends Ext.dd.DDProxy
  3473. * A simple class that provides the basic implementation needed to make any element draggable.
  3474. * @constructor
  3475. * @param {Mixed} el The container element
  3476. * @param {Object} config
  3477. */
  3478. Ext.dd.DragSource = function(el, config){
  3479. this.el = Ext.get(el);
  3480. if(!this.dragData){
  3481. this.dragData = {};
  3482. }
  3483. Ext.apply(this, config);
  3484. if(!this.proxy){
  3485. this.proxy = new Ext.dd.StatusProxy();
  3486. }
  3487. Ext.dd.DragSource.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group,
  3488. {dragElId : this.proxy.id, resizeFrame: false, isTarget: false, scroll: this.scroll === true});
  3489. this.dragging = false;
  3490. };
  3491. Ext.extend(Ext.dd.DragSource, Ext.dd.DDProxy, {
  3492. /**
  3493. * @cfg {String} ddGroup
  3494. * A named drag drop group to which this object belongs. If a group is specified, then this object will only
  3495. * interact with other drag drop objects in the same group (defaults to undefined).
  3496. */
  3497. /**
  3498. * @cfg {String} dropAllowed
  3499. * The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok").
  3500. */
  3501. dropAllowed : "x-dd-drop-ok",
  3502. /**
  3503. * @cfg {String} dropNotAllowed
  3504. * The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop").
  3505. */
  3506. dropNotAllowed : "x-dd-drop-nodrop",
  3507. /**
  3508. * Returns the data object associated with this drag source
  3509. * @return {Object} data An object containing arbitrary data
  3510. */
  3511. getDragData : function(e){
  3512. return this.dragData;
  3513. },
  3514. // private
  3515. onDragEnter : function(e, id){
  3516. var target = Ext.dd.DragDropMgr.getDDById(id);
  3517. this.cachedTarget = target;
  3518. if(this.beforeDragEnter(target, e, id) !== false){
  3519. if(target.isNotifyTarget){
  3520. var status = target.notifyEnter(this, e, this.dragData);
  3521. this.proxy.setStatus(status);
  3522. }else{
  3523. this.proxy.setStatus(this.dropAllowed);
  3524. }
  3525. if(this.afterDragEnter){
  3526. /**
  3527. * An empty function by default, but provided so that you can perform a custom action
  3528. * when the dragged item enters the drop target by providing an implementation.
  3529. * @param {Ext.dd.DragDrop} target The drop target
  3530. * @param {Event} e The event object
  3531. * @param {String} id The id of the dragged element
  3532. * @method afterDragEnter
  3533. */
  3534. this.afterDragEnter(target, e, id);
  3535. }
  3536. }
  3537. },
  3538. /**
  3539. * An empty function by default, but provided so that you can perform a custom action
  3540. * before the dragged item enters the drop target and optionally cancel the onDragEnter.
  3541. * @param {Ext.dd.DragDrop} target The drop target
  3542. * @param {Event} e The event object
  3543. * @param {String} id The id of the dragged element
  3544. * @return {Boolean} isValid True if the drag event is valid, else false to cancel
  3545. */
  3546. beforeDragEnter : function(target, e, id){
  3547. return true;
  3548. },
  3549. // private
  3550. alignElWithMouse: function() {
  3551. Ext.dd.DragSource.superclass.alignElWithMouse.apply(this, arguments);
  3552. this.proxy.sync();
  3553. },
  3554. // private
  3555. onDragOver : function(e, id){
  3556. var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id);
  3557. if(this.beforeDragOver(target, e, id) !== false){
  3558. if(target.isNotifyTarget){
  3559. var status = target.notifyOver(this, e, this.dragData);
  3560. this.proxy.setStatus(status);
  3561. }
  3562. if(this.afterDragOver){
  3563. /**
  3564. * An empty function by default, but provided so that you can perform a custom action
  3565. * while the dragged item is over the drop target by providing an implementation.
  3566. * @param {Ext.dd.DragDrop} target The drop target
  3567. * @param {Event} e The event object
  3568. * @param {String} id The id of the dragged element
  3569. * @method afterDragOver
  3570. */
  3571. this.afterDragOver(target, e, id);
  3572. }
  3573. }
  3574. },
  3575. /**
  3576. * An empty function by default, but provided so that you can perform a custom action
  3577. * while the dragged item is over the drop target and optionally cancel the onDragOver.
  3578. * @param {Ext.dd.DragDrop} target The drop target
  3579. * @param {Event} e The event object
  3580. * @param {String} id The id of the dragged element
  3581. * @return {Boolean} isValid True if the drag event is valid, else false to cancel
  3582. */
  3583. beforeDragOver : function(target, e, id){
  3584. return true;
  3585. },
  3586. // private
  3587. onDragOut : function(e, id){
  3588. var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id);
  3589. if(this.beforeDragOut(target, e, id) !== false){
  3590. if(target.isNotifyTarget){
  3591. target.notifyOut(this, e, this.dragData);
  3592. }
  3593. this.proxy.reset();
  3594. if(this.afterDragOut){
  3595. /**
  3596. * An empty function by default, but provided so that you can perform a custom action
  3597. * after the dragged item is dragged out of the target without dropping.
  3598. * @param {Ext.dd.DragDrop} target The drop target
  3599. * @param {Event} e The event object
  3600. * @param {String} id The id of the dragged element
  3601. * @method afterDragOut
  3602. */
  3603. this.afterDragOut(target, e, id);
  3604. }
  3605. }
  3606. this.cachedTarget = null;
  3607. },
  3608. /**
  3609. * An empty function by default, but provided so that you can perform a custom action before the dragged
  3610. * item is dragged out of the target without dropping, and optionally cancel the onDragOut.
  3611. * @param {Ext.dd.DragDrop} target The drop target
  3612. * @param {Event} e The event object
  3613. * @param {String} id The id of the dragged element
  3614. * @return {Boolean} isValid True if the drag event is valid, else false to cancel
  3615. */
  3616. beforeDragOut : function(target, e, id){
  3617. return true;
  3618. },
  3619. // private
  3620. onDragDrop : function(e, id){
  3621. var target = this.cachedTarget || Ext.dd.DragDropMgr.getDDById(id);
  3622. if(this.beforeDragDrop(target, e, id) !== false){
  3623. if(target.isNotifyTarget){
  3624. if(target.notifyDrop(this, e, this.dragData)){ // valid drop?
  3625. this.onValidDrop(target, e, id);
  3626. }else{
  3627. this.onInvalidDrop(target, e, id);
  3628. }
  3629. }else{
  3630. this.onValidDrop(target, e, id);
  3631. }
  3632. if(this.afterDragDrop){
  3633. /**
  3634. * An empty function by default, but provided so that you can perform a custom action
  3635. * after a valid drag drop has occurred by providing an implementation.
  3636. * @param {Ext.dd.DragDrop} target The drop target
  3637. * @param {Event} e The event object
  3638. * @param {String} id The id of the dropped element
  3639. * @method afterDragDrop
  3640. */
  3641. this.afterDragDrop(target, e, id);
  3642. }
  3643. }
  3644. delete this.cachedTarget;
  3645. },
  3646. /**
  3647. * An empty function by default, but provided so that you can perform a custom action before the dragged
  3648. * item is dropped onto the target and optionally cancel the onDragDrop.
  3649. * @param {Ext.dd.DragDrop} target The drop target
  3650. * @param {Event} e The event object
  3651. * @param {String} id The id of the dragged element
  3652. * @return {Boolean} isValid True if the drag drop event is valid, else false to cancel
  3653. */
  3654. beforeDragDrop : function(target, e, id){
  3655. return true;
  3656. },
  3657. // private
  3658. onValidDrop : function(target, e, id){
  3659. this.hideProxy();
  3660. if(this.afterValidDrop){
  3661. /**
  3662. * An empty function by default, but provided so that you can perform a custom action
  3663. * after a valid drop has occurred by providing an implementation.
  3664. * @param {Object} target The target DD
  3665. * @param {Event} e The event object
  3666. * @param {String} id The id of the dropped element
  3667. * @method afterValidDrop
  3668. */
  3669. this.afterValidDrop(target, e, id);
  3670. }
  3671. },
  3672. // private
  3673. getRepairXY : function(e, data){
  3674. return this.el.getXY();
  3675. },
  3676. // private
  3677. onInvalidDrop : function(target, e, id){
  3678. this.beforeInvalidDrop(target, e, id);
  3679. if(this.cachedTarget){
  3680. if(this.cachedTarget.isNotifyTarget){
  3681. this.cachedTarget.notifyOut(this, e, this.dragData);
  3682. }
  3683. this.cacheTarget = null;
  3684. }
  3685. this.proxy.repair(this.getRepairXY(e, this.dragData), this.afterRepair, this);
  3686. if(this.afterInvalidDrop){
  3687. /**
  3688. * An empty function by default, but provided so that you can perform a custom action
  3689. * after an invalid drop has occurred by providing an implementation.
  3690. * @param {Event} e The event object
  3691. * @param {String} id The id of the dropped element
  3692. * @method afterInvalidDrop
  3693. */
  3694. this.afterInvalidDrop(e, id);
  3695. }
  3696. },
  3697. // private
  3698. afterRepair : function(){
  3699. if(Ext.enableFx){
  3700. this.el.highlight(this.hlColor || "c3daf9");
  3701. }
  3702. this.dragging = false;
  3703. },
  3704. /**
  3705. * An empty function by default, but provided so that you can perform a custom action after an invalid
  3706. * drop has occurred.
  3707. * @param {Ext.dd.DragDrop} target The drop target
  3708. * @param {Event} e The event object
  3709. * @param {String} id The id of the dragged element
  3710. * @return {Boolean} isValid True if the invalid drop should proceed, else false to cancel
  3711. */
  3712. beforeInvalidDrop : function(target, e, id){
  3713. return true;
  3714. },
  3715. // private
  3716. handleMouseDown : function(e){
  3717. if(this.dragging) {
  3718. return;
  3719. }
  3720. var data = this.getDragData(e);
  3721. if(data && this.onBeforeDrag(data, e) !== false){
  3722. this.dragData = data;
  3723. this.proxy.stop();
  3724. Ext.dd.DragSource.superclass.handleMouseDown.apply(this, arguments);
  3725. }
  3726. },
  3727. /**
  3728. * An empty function by default, but provided so that you can perform a custom action before the initial
  3729. * drag event begins and optionally cancel it.
  3730. * @param {Object} data An object containing arbitrary data to be shared with drop targets
  3731. * @param {Event} e The event object
  3732. * @return {Boolean} isValid True if the drag event is valid, else false to cancel
  3733. */
  3734. onBeforeDrag : function(data, e){
  3735. return true;
  3736. },
  3737. /**
  3738. * An empty function by default, but provided so that you can perform a custom action once the initial
  3739. * drag event has begun. The drag cannot be canceled from this function.
  3740. * @param {Number} x The x position of the click on the dragged object
  3741. * @param {Number} y The y position of the click on the dragged object
  3742. */
  3743. onStartDrag : Ext.emptyFn,
  3744. // private override
  3745. startDrag : function(x, y){
  3746. this.proxy.reset();
  3747. this.dragging = true;
  3748. this.proxy.update("");
  3749. this.onInitDrag(x, y);
  3750. this.proxy.show();
  3751. },
  3752. // private
  3753. onInitDrag : function(x, y){
  3754. var clone = this.el.dom.cloneNode(true);
  3755. clone.id = Ext.id(); // prevent duplicate ids
  3756. this.proxy.update(clone);
  3757. this.onStartDrag(x, y);
  3758. return true;
  3759. },
  3760. /**
  3761. * Returns the drag source's underlying {@link Ext.dd.StatusProxy}
  3762. * @return {Ext.dd.StatusProxy} proxy The StatusProxy
  3763. */
  3764. getProxy : function(){
  3765. return this.proxy;
  3766. },
  3767. /**
  3768. * Hides the drag source's {@link Ext.dd.StatusProxy}
  3769. */
  3770. hideProxy : function(){
  3771. this.proxy.hide();
  3772. this.proxy.reset(true);
  3773. this.dragging = false;
  3774. },
  3775. // private
  3776. triggerCacheRefresh : function(){
  3777. Ext.dd.DDM.refreshCache(this.groups);
  3778. },
  3779. // private - override to prevent hiding
  3780. b4EndDrag: function(e) {
  3781. },
  3782. // private - override to prevent moving
  3783. endDrag : function(e){
  3784. this.onEndDrag(this.dragData, e);
  3785. },
  3786. // private
  3787. onEndDrag : function(data, e){
  3788. },
  3789. // private - pin to cursor
  3790. autoOffset : function(x, y) {
  3791. this.setDelta(-12, -20);
  3792. },
  3793. destroy: function(){
  3794. Ext.dd.DragSource.superclass.destroy.call(this);
  3795. Ext.destroy(this.proxy);
  3796. }
  3797. });/**
  3798. * @class Ext.dd.DropTarget
  3799. * @extends Ext.dd.DDTarget
  3800. * A simple class that provides the basic implementation needed to make any element a drop target that can have
  3801. * draggable items dropped onto it. The drop has no effect until an implementation of notifyDrop is provided.
  3802. * @constructor
  3803. * @param {Mixed} el The container element
  3804. * @param {Object} config
  3805. */
  3806. Ext.dd.DropTarget = Ext.extend(Ext.dd.DDTarget, {
  3807. constructor : function(el, config){
  3808. this.el = Ext.get(el);
  3809. Ext.apply(this, config);
  3810. if(this.containerScroll){
  3811. Ext.dd.ScrollManager.register(this.el);
  3812. }
  3813. Ext.dd.DropTarget.superclass.constructor.call(this, this.el.dom, this.ddGroup || this.group,
  3814. {isTarget: true});
  3815. },
  3816. /**
  3817. * @cfg {String} ddGroup
  3818. * A named drag drop group to which this object belongs. If a group is specified, then this object will only
  3819. * interact with other drag drop objects in the same group (defaults to undefined).
  3820. */
  3821. /**
  3822. * @cfg {String} overClass
  3823. * The CSS class applied to the drop target element while the drag source is over it (defaults to "").
  3824. */
  3825. /**
  3826. * @cfg {String} dropAllowed
  3827. * The CSS class returned to the drag source when drop is allowed (defaults to "x-dd-drop-ok").
  3828. */
  3829. dropAllowed : "x-dd-drop-ok",
  3830. /**
  3831. * @cfg {String} dropNotAllowed
  3832. * The CSS class returned to the drag source when drop is not allowed (defaults to "x-dd-drop-nodrop").
  3833. */
  3834. dropNotAllowed : "x-dd-drop-nodrop",
  3835. // private
  3836. isTarget : true,
  3837. // private
  3838. isNotifyTarget : true,
  3839. /**
  3840. * The function a {@link Ext.dd.DragSource} calls once to notify this drop target that the source is now over the
  3841. * target. This default implementation adds the CSS class specified by overClass (if any) to the drop element
  3842. * and returns the dropAllowed config value. This method should be overridden if drop validation is required.
  3843. * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target
  3844. * @param {Event} e The event
  3845. * @param {Object} data An object containing arbitrary data supplied by the drag source
  3846. * @return {String} status The CSS class that communicates the drop status back to the source so that the
  3847. * underlying {@link Ext.dd.StatusProxy} can be updated
  3848. */
  3849. notifyEnter : function(dd, e, data){
  3850. if(this.overClass){
  3851. this.el.addClass(this.overClass);
  3852. }
  3853. return this.dropAllowed;
  3854. },
  3855. /**
  3856. * The function a {@link Ext.dd.DragSource} calls continuously while it is being dragged over the target.
  3857. * This method will be called on every mouse movement while the drag source is over the drop target.
  3858. * This default implementation simply returns the dropAllowed config value.
  3859. * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target
  3860. * @param {Event} e The event
  3861. * @param {Object} data An object containing arbitrary data supplied by the drag source
  3862. * @return {String} status The CSS class that communicates the drop status back to the source so that the
  3863. * underlying {@link Ext.dd.StatusProxy} can be updated
  3864. */
  3865. notifyOver : function(dd, e, data){
  3866. return this.dropAllowed;
  3867. },
  3868. /**
  3869. * The function a {@link Ext.dd.DragSource} calls once to notify this drop target that the source has been dragged
  3870. * out of the target without dropping. This default implementation simply removes the CSS class specified by
  3871. * overClass (if any) from the drop element.
  3872. * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target
  3873. * @param {Event} e The event
  3874. * @param {Object} data An object containing arbitrary data supplied by the drag source
  3875. */
  3876. notifyOut : function(dd, e, data){
  3877. if(this.overClass){
  3878. this.el.removeClass(this.overClass);
  3879. }
  3880. },
  3881. /**
  3882. * The function a {@link Ext.dd.DragSource} calls once to notify this drop target that the dragged item has
  3883. * been dropped on it. This method has no default implementation and returns false, so you must provide an
  3884. * implementation that does something to process the drop event and returns true so that the drag source's
  3885. * repair action does not run.
  3886. * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target
  3887. * @param {Event} e The event
  3888. * @param {Object} data An object containing arbitrary data supplied by the drag source
  3889. * @return {Boolean} True if the drop was valid, else false
  3890. */
  3891. notifyDrop : function(dd, e, data){
  3892. return false;
  3893. },
  3894. destroy : function(){
  3895. Ext.dd.DropTarget.superclass.destroy.call(this);
  3896. if(this.containerScroll){
  3897. Ext.dd.ScrollManager.unregister(this.el);
  3898. }
  3899. }
  3900. });/**
  3901. * @class Ext.dd.DragZone
  3902. * @extends Ext.dd.DragSource
  3903. * <p>This class provides a container DD instance that allows dragging of multiple child source nodes.</p>
  3904. * <p>This class does not move the drag target nodes, but a proxy element which may contain
  3905. * any DOM structure you wish. The DOM element to show in the proxy is provided by either a
  3906. * provided implementation of {@link #getDragData}, or by registered draggables registered with {@link Ext.dd.Registry}</p>
  3907. * <p>If you wish to provide draggability for an arbitrary number of DOM nodes, each of which represent some
  3908. * application object (For example nodes in a {@link Ext.DataView DataView}) then use of this class
  3909. * is the most efficient way to "activate" those nodes.</p>
  3910. * <p>By default, this class requires that draggable child nodes are registered with {@link Ext.dd.Registry}.
  3911. * However a simpler way to allow a DragZone to manage any number of draggable elements is to configure
  3912. * the DragZone with an implementation of the {@link #getDragData} method which interrogates the passed
  3913. * mouse event to see if it has taken place within an element, or class of elements. This is easily done
  3914. * by using the event's {@link Ext.EventObject#getTarget getTarget} method to identify a node based on a
  3915. * {@link Ext.DomQuery} selector. For example, to make the nodes of a DataView draggable, use the following
  3916. * technique. Knowledge of the use of the DataView is required:</p><pre><code>
  3917. myDataView.on('render', function(v) {
  3918. myDataView.dragZone = new Ext.dd.DragZone(v.getEl(), {
  3919. // On receipt of a mousedown event, see if it is within a DataView node.
  3920. // Return a drag data object if so.
  3921. getDragData: function(e) {
  3922. // Use the DataView's own itemSelector (a mandatory property) to
  3923. // test if the mousedown is within one of the DataView's nodes.
  3924. var sourceEl = e.getTarget(v.itemSelector, 10);
  3925. // If the mousedown is within a DataView node, clone the node to produce
  3926. // a ddel element for use by the drag proxy. Also add application data
  3927. // to the returned data object.
  3928. if (sourceEl) {
  3929. d = sourceEl.cloneNode(true);
  3930. d.id = Ext.id();
  3931. return {
  3932. ddel: d,
  3933. sourceEl: sourceEl,
  3934. repairXY: Ext.fly(sourceEl).getXY(),
  3935. sourceStore: v.store,
  3936. draggedRecord: v.{@link Ext.DataView#getRecord getRecord}(sourceEl)
  3937. }
  3938. }
  3939. },
  3940. // Provide coordinates for the proxy to slide back to on failed drag.
  3941. // This is the original XY coordinates of the draggable element captured
  3942. // in the getDragData method.
  3943. getRepairXY: function() {
  3944. return this.dragData.repairXY;
  3945. }
  3946. });
  3947. });</code></pre>
  3948. * See the {@link Ext.dd.DropZone DropZone} documentation for details about building a DropZone which
  3949. * cooperates with this DragZone.
  3950. * @constructor
  3951. * @param {Mixed} el The container element
  3952. * @param {Object} config
  3953. */
  3954. Ext.dd.DragZone = Ext.extend(Ext.dd.DragSource, {
  3955. constructor : function(el, config){
  3956. Ext.dd.DragZone.superclass.constructor.call(this, el, config);
  3957. if(this.containerScroll){
  3958. Ext.dd.ScrollManager.register(this.el);
  3959. }
  3960. },
  3961. /**
  3962. * This property contains the data representing the dragged object. This data is set up by the implementation
  3963. * of the {@link #getDragData} method. It must contain a <tt>ddel</tt> property, but can contain
  3964. * any other data according to the application's needs.
  3965. * @type Object
  3966. * @property dragData
  3967. */
  3968. /**
  3969. * @cfg {Boolean} containerScroll True to register this container with the Scrollmanager
  3970. * for auto scrolling during drag operations.
  3971. */
  3972. /**
  3973. * @cfg {String} hlColor The color to use when visually highlighting the drag source in the afterRepair
  3974. * method after a failed drop (defaults to "c3daf9" - light blue)
  3975. */
  3976. /**
  3977. * Called when a mousedown occurs in this container. Looks in {@link Ext.dd.Registry}
  3978. * for a valid target to drag based on the mouse down. Override this method
  3979. * to provide your own lookup logic (e.g. finding a child by class name). Make sure your returned
  3980. * object has a "ddel" attribute (with an HTML Element) for other functions to work.
  3981. * @param {EventObject} e The mouse down event
  3982. * @return {Object} The dragData
  3983. */
  3984. getDragData : function(e){
  3985. return Ext.dd.Registry.getHandleFromEvent(e);
  3986. },
  3987. /**
  3988. * Called once drag threshold has been reached to initialize the proxy element. By default, it clones the
  3989. * this.dragData.ddel
  3990. * @param {Number} x The x position of the click on the dragged object
  3991. * @param {Number} y The y position of the click on the dragged object
  3992. * @return {Boolean} true to continue the drag, false to cancel
  3993. */
  3994. onInitDrag : function(x, y){
  3995. this.proxy.update(this.dragData.ddel.cloneNode(true));
  3996. this.onStartDrag(x, y);
  3997. return true;
  3998. },
  3999. /**
  4000. * Called after a repair of an invalid drop. By default, highlights this.dragData.ddel
  4001. */
  4002. afterRepair : function(){
  4003. if(Ext.enableFx){
  4004. Ext.Element.fly(this.dragData.ddel).highlight(this.hlColor || "c3daf9");
  4005. }
  4006. this.dragging = false;
  4007. },
  4008. /**
  4009. * Called before a repair of an invalid drop to get the XY to animate to. By default returns
  4010. * the XY of this.dragData.ddel
  4011. * @param {EventObject} e The mouse up event
  4012. * @return {Array} The xy location (e.g. [100, 200])
  4013. */
  4014. getRepairXY : function(e){
  4015. return Ext.Element.fly(this.dragData.ddel).getXY();
  4016. },
  4017. destroy : function(){
  4018. Ext.dd.DragZone.superclass.destroy.call(this);
  4019. if(this.containerScroll){
  4020. Ext.dd.ScrollManager.unregister(this.el);
  4021. }
  4022. }
  4023. });/**
  4024. * @class Ext.dd.DropZone
  4025. * @extends Ext.dd.DropTarget
  4026. * <p>This class provides a container DD instance that allows dropping on multiple child target nodes.</p>
  4027. * <p>By default, this class requires that child nodes accepting drop are registered with {@link Ext.dd.Registry}.
  4028. * However a simpler way to allow a DropZone to manage any number of target elements is to configure the
  4029. * DropZone with an implementation of {@link #getTargetFromEvent} which interrogates the passed
  4030. * mouse event to see if it has taken place within an element, or class of elements. This is easily done
  4031. * by using the event's {@link Ext.EventObject#getTarget getTarget} method to identify a node based on a
  4032. * {@link Ext.DomQuery} selector.</p>
  4033. * <p>Once the DropZone has detected through calling getTargetFromEvent, that the mouse is over
  4034. * a drop target, that target is passed as the first parameter to {@link #onNodeEnter}, {@link #onNodeOver},
  4035. * {@link #onNodeOut}, {@link #onNodeDrop}. You may configure the instance of DropZone with implementations
  4036. * of these methods to provide application-specific behaviour for these events to update both
  4037. * application state, and UI state.</p>
  4038. * <p>For example to make a GridPanel a cooperating target with the example illustrated in
  4039. * {@link Ext.dd.DragZone DragZone}, the following technique might be used:</p><pre><code>
  4040. myGridPanel.on('render', function() {
  4041. myGridPanel.dropZone = new Ext.dd.DropZone(myGridPanel.getView().scroller, {
  4042. // If the mouse is over a grid row, return that node. This is
  4043. // provided as the "target" parameter in all "onNodeXXXX" node event handling functions
  4044. getTargetFromEvent: function(e) {
  4045. return e.getTarget(myGridPanel.getView().rowSelector);
  4046. },
  4047. // On entry into a target node, highlight that node.
  4048. onNodeEnter : function(target, dd, e, data){
  4049. Ext.fly(target).addClass('my-row-highlight-class');
  4050. },
  4051. // On exit from a target node, unhighlight that node.
  4052. onNodeOut : function(target, dd, e, data){
  4053. Ext.fly(target).removeClass('my-row-highlight-class');
  4054. },
  4055. // While over a target node, return the default drop allowed class which
  4056. // places a "tick" icon into the drag proxy.
  4057. onNodeOver : function(target, dd, e, data){
  4058. return Ext.dd.DropZone.prototype.dropAllowed;
  4059. },
  4060. // On node drop we can interrogate the target to find the underlying
  4061. // application object that is the real target of the dragged data.
  4062. // In this case, it is a Record in the GridPanel's Store.
  4063. // We can use the data set up by the DragZone's getDragData method to read
  4064. // any data we decided to attach in the DragZone's getDragData method.
  4065. onNodeDrop : function(target, dd, e, data){
  4066. var rowIndex = myGridPanel.getView().findRowIndex(target);
  4067. var r = myGridPanel.getStore().getAt(rowIndex);
  4068. Ext.Msg.alert('Drop gesture', 'Dropped Record id ' + data.draggedRecord.id +
  4069. ' on Record id ' + r.id);
  4070. return true;
  4071. }
  4072. });
  4073. }
  4074. </code></pre>
  4075. * See the {@link Ext.dd.DragZone DragZone} documentation for details about building a DragZone which
  4076. * cooperates with this DropZone.
  4077. * @constructor
  4078. * @param {Mixed} el The container element
  4079. * @param {Object} config
  4080. */
  4081. Ext.dd.DropZone = function(el, config){
  4082. Ext.dd.DropZone.superclass.constructor.call(this, el, config);
  4083. };
  4084. Ext.extend(Ext.dd.DropZone, Ext.dd.DropTarget, {
  4085. /**
  4086. * Returns a custom data object associated with the DOM node that is the target of the event. By default
  4087. * this looks up the event target in the {@link Ext.dd.Registry}, although you can override this method to
  4088. * provide your own custom lookup.
  4089. * @param {Event} e The event
  4090. * @return {Object} data The custom data
  4091. */
  4092. getTargetFromEvent : function(e){
  4093. return Ext.dd.Registry.getTargetFromEvent(e);
  4094. },
  4095. /**
  4096. * Called when the DropZone determines that a {@link Ext.dd.DragSource} has entered a drop node
  4097. * that has either been registered or detected by a configured implementation of {@link #getTargetFromEvent}.
  4098. * This method has no default implementation and should be overridden to provide
  4099. * node-specific processing if necessary.
  4100. * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
  4101. * {@link #getTargetFromEvent} for this node)
  4102. * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
  4103. * @param {Event} e The event
  4104. * @param {Object} data An object containing arbitrary data supplied by the drag source
  4105. */
  4106. onNodeEnter : function(n, dd, e, data){
  4107. },
  4108. /**
  4109. * Called while the DropZone determines that a {@link Ext.dd.DragSource} is over a drop node
  4110. * that has either been registered or detected by a configured implementation of {@link #getTargetFromEvent}.
  4111. * The default implementation returns this.dropNotAllowed, so it should be
  4112. * overridden to provide the proper feedback.
  4113. * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
  4114. * {@link #getTargetFromEvent} for this node)
  4115. * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
  4116. * @param {Event} e The event
  4117. * @param {Object} data An object containing arbitrary data supplied by the drag source
  4118. * @return {String} status The CSS class that communicates the drop status back to the source so that the
  4119. * underlying {@link Ext.dd.StatusProxy} can be updated
  4120. */
  4121. onNodeOver : function(n, dd, e, data){
  4122. return this.dropAllowed;
  4123. },
  4124. /**
  4125. * Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dragged out of
  4126. * the drop node without dropping. This method has no default implementation and should be overridden to provide
  4127. * node-specific processing if necessary.
  4128. * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
  4129. * {@link #getTargetFromEvent} for this node)
  4130. * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
  4131. * @param {Event} e The event
  4132. * @param {Object} data An object containing arbitrary data supplied by the drag source
  4133. */
  4134. onNodeOut : function(n, dd, e, data){
  4135. },
  4136. /**
  4137. * Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dropped onto
  4138. * the drop node. The default implementation returns false, so it should be overridden to provide the
  4139. * appropriate processing of the drop event and return true so that the drag source's repair action does not run.
  4140. * @param {Object} nodeData The custom data associated with the drop node (this is the same value returned from
  4141. * {@link #getTargetFromEvent} for this node)
  4142. * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
  4143. * @param {Event} e The event
  4144. * @param {Object} data An object containing arbitrary data supplied by the drag source
  4145. * @return {Boolean} True if the drop was valid, else false
  4146. */
  4147. onNodeDrop : function(n, dd, e, data){
  4148. return false;
  4149. },
  4150. /**
  4151. * Called while the DropZone determines that a {@link Ext.dd.DragSource} is being dragged over it,
  4152. * but not over any of its registered drop nodes. The default implementation returns this.dropNotAllowed, so
  4153. * it should be overridden to provide the proper feedback if necessary.
  4154. * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
  4155. * @param {Event} e The event
  4156. * @param {Object} data An object containing arbitrary data supplied by the drag source
  4157. * @return {String} status The CSS class that communicates the drop status back to the source so that the
  4158. * underlying {@link Ext.dd.StatusProxy} can be updated
  4159. */
  4160. onContainerOver : function(dd, e, data){
  4161. return this.dropNotAllowed;
  4162. },
  4163. /**
  4164. * Called when the DropZone determines that a {@link Ext.dd.DragSource} has been dropped on it,
  4165. * but not on any of its registered drop nodes. The default implementation returns false, so it should be
  4166. * overridden to provide the appropriate processing of the drop event if you need the drop zone itself to
  4167. * be able to accept drops. It should return true when valid so that the drag source's repair action does not run.
  4168. * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
  4169. * @param {Event} e The event
  4170. * @param {Object} data An object containing arbitrary data supplied by the drag source
  4171. * @return {Boolean} True if the drop was valid, else false
  4172. */
  4173. onContainerDrop : function(dd, e, data){
  4174. return false;
  4175. },
  4176. /**
  4177. * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the source is now over
  4178. * the zone. The default implementation returns this.dropNotAllowed and expects that only registered drop
  4179. * nodes can process drag drop operations, so if you need the drop zone itself to be able to process drops
  4180. * you should override this method and provide a custom implementation.
  4181. * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
  4182. * @param {Event} e The event
  4183. * @param {Object} data An object containing arbitrary data supplied by the drag source
  4184. * @return {String} status The CSS class that communicates the drop status back to the source so that the
  4185. * underlying {@link Ext.dd.StatusProxy} can be updated
  4186. */
  4187. notifyEnter : function(dd, e, data){
  4188. return this.dropNotAllowed;
  4189. },
  4190. /**
  4191. * The function a {@link Ext.dd.DragSource} calls continuously while it is being dragged over the drop zone.
  4192. * This method will be called on every mouse movement while the drag source is over the drop zone.
  4193. * It will call {@link #onNodeOver} while the drag source is over a registered node, and will also automatically
  4194. * delegate to the appropriate node-specific methods as necessary when the drag source enters and exits
  4195. * registered nodes ({@link #onNodeEnter}, {@link #onNodeOut}). If the drag source is not currently over a
  4196. * registered node, it will call {@link #onContainerOver}.
  4197. * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
  4198. * @param {Event} e The event
  4199. * @param {Object} data An object containing arbitrary data supplied by the drag source
  4200. * @return {String} status The CSS class that communicates the drop status back to the source so that the
  4201. * underlying {@link Ext.dd.StatusProxy} can be updated
  4202. */
  4203. notifyOver : function(dd, e, data){
  4204. var n = this.getTargetFromEvent(e);
  4205. if(!n){ // not over valid drop target
  4206. if(this.lastOverNode){
  4207. this.onNodeOut(this.lastOverNode, dd, e, data);
  4208. this.lastOverNode = null;
  4209. }
  4210. return this.onContainerOver(dd, e, data);
  4211. }
  4212. if(this.lastOverNode != n){
  4213. if(this.lastOverNode){
  4214. this.onNodeOut(this.lastOverNode, dd, e, data);
  4215. }
  4216. this.onNodeEnter(n, dd, e, data);
  4217. this.lastOverNode = n;
  4218. }
  4219. return this.onNodeOver(n, dd, e, data);
  4220. },
  4221. /**
  4222. * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the source has been dragged
  4223. * out of the zone without dropping. If the drag source is currently over a registered node, the notification
  4224. * will be delegated to {@link #onNodeOut} for node-specific handling, otherwise it will be ignored.
  4225. * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop target
  4226. * @param {Event} e The event
  4227. * @param {Object} data An object containing arbitrary data supplied by the drag zone
  4228. */
  4229. notifyOut : function(dd, e, data){
  4230. if(this.lastOverNode){
  4231. this.onNodeOut(this.lastOverNode, dd, e, data);
  4232. this.lastOverNode = null;
  4233. }
  4234. },
  4235. /**
  4236. * The function a {@link Ext.dd.DragSource} calls once to notify this drop zone that the dragged item has
  4237. * been dropped on it. The drag zone will look up the target node based on the event passed in, and if there
  4238. * is a node registered for that event, it will delegate to {@link #onNodeDrop} for node-specific handling,
  4239. * otherwise it will call {@link #onContainerDrop}.
  4240. * @param {Ext.dd.DragSource} source The drag source that was dragged over this drop zone
  4241. * @param {Event} e The event
  4242. * @param {Object} data An object containing arbitrary data supplied by the drag source
  4243. * @return {Boolean} True if the drop was valid, else false
  4244. */
  4245. notifyDrop : function(dd, e, data){
  4246. if(this.lastOverNode){
  4247. this.onNodeOut(this.lastOverNode, dd, e, data);
  4248. this.lastOverNode = null;
  4249. }
  4250. var n = this.getTargetFromEvent(e);
  4251. return n ?
  4252. this.onNodeDrop(n, dd, e, data) :
  4253. this.onContainerDrop(dd, e, data);
  4254. },
  4255. // private
  4256. triggerCacheRefresh : function(){
  4257. Ext.dd.DDM.refreshCache(this.groups);
  4258. }
  4259. });/**
  4260. * @class Ext.Element
  4261. */
  4262. Ext.Element.addMethods({
  4263. /**
  4264. * Initializes a {@link Ext.dd.DD} drag drop object for this element.
  4265. * @param {String} group The group the DD object is member of
  4266. * @param {Object} config The DD config object
  4267. * @param {Object} overrides An object containing methods to override/implement on the DD object
  4268. * @return {Ext.dd.DD} The DD object
  4269. */
  4270. initDD : function(group, config, overrides){
  4271. var dd = new Ext.dd.DD(Ext.id(this.dom), group, config);
  4272. return Ext.apply(dd, overrides);
  4273. },
  4274. /**
  4275. * Initializes a {@link Ext.dd.DDProxy} object for this element.
  4276. * @param {String} group The group the DDProxy object is member of
  4277. * @param {Object} config The DDProxy config object
  4278. * @param {Object} overrides An object containing methods to override/implement on the DDProxy object
  4279. * @return {Ext.dd.DDProxy} The DDProxy object
  4280. */
  4281. initDDProxy : function(group, config, overrides){
  4282. var dd = new Ext.dd.DDProxy(Ext.id(this.dom), group, config);
  4283. return Ext.apply(dd, overrides);
  4284. },
  4285. /**
  4286. * Initializes a {@link Ext.dd.DDTarget} object for this element.
  4287. * @param {String} group The group the DDTarget object is member of
  4288. * @param {Object} config The DDTarget config object
  4289. * @param {Object} overrides An object containing methods to override/implement on the DDTarget object
  4290. * @return {Ext.dd.DDTarget} The DDTarget object
  4291. */
  4292. initDDTarget : function(group, config, overrides){
  4293. var dd = new Ext.dd.DDTarget(Ext.id(this.dom), group, config);
  4294. return Ext.apply(dd, overrides);
  4295. }
  4296. });