1
0

demo.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. window.addEvent('domready',function(){
  2. Mif.Tree.Node.implement({
  3. switchSelect: function(state){
  4. this.tree[state ? 'select' : 'unselect'](this);
  5. }
  6. });
  7. tree = new Mif.Tree({
  8. id: 'tree1',
  9. container: $('tree_container'),// tree container
  10. initialize: function(){
  11. this.initCheckbox('simple');
  12. var storage = new Mif.Tree.CookieStorage(this);
  13. var switchStorage = new Mif.Tree.CookieStorage(this, {event: 'switch', action: 'switch'});
  14. var selectStorage = new Mif.Tree.CookieStorage(this, {event: 'selectChange', action: 'switchSelect'});
  15. this.addEvent('load', function(){
  16. storage.restore();
  17. switchStorage.restore();
  18. selectStorage.restore();
  19. }).addEvent('loadChildren', function(){
  20. storage.restore();
  21. switchStorage.restore();
  22. selectStorage.restore();
  23. });
  24. },
  25. types: {// node types
  26. folder: {
  27. openIcon: 'mif-tree-open-icon',//css class open icon
  28. closeIcon: 'mif-tree-close-icon'// css class close icon
  29. }
  30. },
  31. dfltType: 'folder',//default node type
  32. height: 18//node height
  33. });
  34. tree2 = new Mif.Tree({
  35. id: 'tree2',
  36. container: $('tree_container2'),// tree container
  37. initialize: function(){
  38. this.initCheckbox('simple');
  39. var storage = new Mif.Tree.CookieStorage(this);
  40. var switchStorage = new Mif.Tree.CookieStorage(this, {event: 'switch', action: 'switch'});
  41. var selectStorage = new Mif.Tree.CookieStorage(this, {event: 'selectChange', action: 'switchSelect'});
  42. this.addEvent('load', function(){
  43. storage.restore();
  44. switchStorage.restore();
  45. selectStorage.restore();
  46. }).addEvent('loadChildren', function(){
  47. storage.restore();
  48. switchStorage.restore();
  49. selectStorage.restore();
  50. });
  51. },
  52. types: {// node types
  53. folder: {
  54. openIcon: 'mif-tree-open-icon',//css class open icon
  55. closeIcon: 'mif-tree-close-icon'// css class close icon
  56. }
  57. },
  58. dfltType: 'folder',//default node type
  59. height: 18//node height
  60. });
  61. var children = [
  62. {
  63. "property": {
  64. "name": "cnode1",
  65. "id": "cnode1"
  66. }
  67. },
  68. {
  69. "property": {
  70. "name": "cnode2",
  71. "id": "cnode2"
  72. },
  73. "children": [
  74. {
  75. "property":{
  76. "name": "cnodeX",
  77. "id": "cnodeXXXX"
  78. }
  79. },
  80. {
  81. "property":{
  82. "name": "cnodeY",
  83. "id": "cnodeY"
  84. },
  85. "children":[
  86. {
  87. "property":{
  88. "name": "cnodeZ",
  89. "id": "cnodeZ"
  90. }
  91. },
  92. {
  93. "property":{
  94. "name": "cnodeL",
  95. "id": "cnodeL"
  96. }
  97. }
  98. ]
  99. }
  100. ]
  101. },
  102. {
  103. "property":{
  104. "name": "cnode3",
  105. "id": "cnode3"
  106. }
  107. }
  108. ];
  109. var json = [
  110. {
  111. "property": {
  112. "name": "root",
  113. "id": "root"
  114. },
  115. "children": [
  116. {
  117. "property": {
  118. "name": "node1",
  119. "id": "node1"
  120. }
  121. },
  122. {
  123. "property": {
  124. "name": "node2",
  125. "id": "node2"
  126. },
  127. "children":[
  128. {
  129. "property": {
  130. "name": "node2.1",
  131. "id": "node2.1"
  132. }
  133. },
  134. {
  135. "property": {
  136. "name": "node2.2",
  137. "id": "node2.2"
  138. },
  139. "children":[
  140. {
  141. "property": {
  142. "name": "node2.2.1",
  143. "id": "node2.2.1"
  144. }
  145. },
  146. {
  147. "property": {
  148. "name": "node2.2.2",
  149. "id": "node2.2.2"
  150. }
  151. }
  152. ]
  153. }
  154. ]
  155. },
  156. {
  157. "property": {
  158. "name": "node4",
  159. "id": "node4"
  160. },
  161. "children": [
  162. {
  163. "property":{
  164. "name": "nodeX",
  165. "id": "nodeXXXX"
  166. }
  167. },
  168. {
  169. "property":{
  170. "name": "nodeY",
  171. "id": "nodeY"
  172. }
  173. }
  174. ]
  175. },
  176. {
  177. "property": {
  178. "name": "node3 loadable",
  179. "id": "node3",
  180. "loadable": true,
  181. "loadOptions": {"json": children}
  182. }
  183. }
  184. ]
  185. }
  186. ];
  187. var json2 = [
  188. {
  189. "property": {
  190. "name": "root",
  191. "id": "root_2"
  192. },
  193. "children": [
  194. {
  195. "property": {
  196. "name": "node1",
  197. "id": "node1_2"
  198. }
  199. },
  200. {
  201. "property": {
  202. "name": "node2",
  203. "id": "node2_2"
  204. },
  205. "children":[
  206. {
  207. "property": {
  208. "name": "node2.1",
  209. "id": "node2.1_2"
  210. }
  211. },
  212. {
  213. "property": {
  214. "name": "node2.2",
  215. "id": "node2.2_2"
  216. },
  217. "children":[
  218. {
  219. "property": {
  220. "name": "node2.2.1",
  221. "id": "node2.2.1_2"
  222. }
  223. },
  224. {
  225. "property": {
  226. "name": "node2.2.2",
  227. "id": "node2.2.2_2"
  228. }
  229. }
  230. ]
  231. }
  232. ]
  233. },
  234. {
  235. "property": {
  236. "name": "node4",
  237. "id": "node4_2"
  238. },
  239. "children": [
  240. {
  241. "property":{
  242. "name": "nodeX",
  243. "id": "nodeXXXX_2"
  244. }
  245. },
  246. {
  247. "property":{
  248. "name": "nodeY",
  249. "id": "nodeY_2"
  250. }
  251. }
  252. ]
  253. },
  254. {
  255. "property": {
  256. "name": "node3 loadable",
  257. "id": "node3_2"
  258. }
  259. }
  260. ]
  261. }
  262. ];
  263. // load tree from json.
  264. tree.load({
  265. json: json
  266. });
  267. tree2.load({
  268. json: json2
  269. });
  270. });