diff options
author | Valerio Virgillito | 2012-02-06 14:09:29 -0800 |
---|---|---|
committer | Valerio Virgillito | 2012-02-06 14:09:29 -0800 |
commit | 07e5839e0ec6da2eb71056ff18b90226af213eef (patch) | |
tree | bfc93091f03f2c2383ccfe3ec73dd85bf0a0ccf3 /js/components/treeview/ninja-branch.reel/ninja-branch.js | |
parent | 671a27069db6a121507c2b342653aede685cff67 (diff) | |
parent | c83b0d9bf3f37ae8569e8afc51dbcba9ed003929 (diff) | |
download | ninja-07e5839e0ec6da2eb71056ff18b90226af213eef.tar.gz |
Merge pull request #16 from ericguzman/TreeComponents
Tree components
Diffstat (limited to 'js/components/treeview/ninja-branch.reel/ninja-branch.js')
-rw-r--r-- | js/components/treeview/ninja-branch.reel/ninja-branch.js | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/js/components/treeview/ninja-branch.reel/ninja-branch.js b/js/components/treeview/ninja-branch.reel/ninja-branch.js new file mode 100644 index 00000000..6b9ebb10 --- /dev/null +++ b/js/components/treeview/ninja-branch.reel/ninja-branch.js | |||
@@ -0,0 +1,131 @@ | |||
1 | /* <copyright> | ||
2 | This file contains proprietary software owned by Motorola Mobility, Inc.<br/> | ||
3 | No rights, expressed or implied, whatsoever to this software are provided by Motorola Mobility, Inc. hereunder.<br/> | ||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | ||
5 | </copyright> */ | ||
6 | |||
7 | var Montage = require("montage").Montage, | ||
8 | Component = require("montage/ui/component").Component, | ||
9 | TreeNode = require("js/components/treeview/tree-node").TreeNode; | ||
10 | |||
11 | var Branch = exports.Branch = Montage.create(TreeNode, { | ||
12 | hasTemplate:{ | ||
13 | value:true | ||
14 | }, | ||
15 | repetition:{ | ||
16 | value: null | ||
17 | }, | ||
18 | prepareForDraw : { | ||
19 | value: function() { | ||
20 | this.collapser.removeAttribute('id'); | ||
21 | this.label._element.addEventListener('click', this, false); | ||
22 | |||
23 | if(this.hideLabel) { | ||
24 | this.label.element.style.display = "none"; | ||
25 | } | ||
26 | |||
27 | this.treeView.contentController.addBranchController(this.arrayController); | ||
28 | } | ||
29 | }, | ||
30 | handleWebkitTransitionEnd : { | ||
31 | value: function(e) { | ||
32 | e.stopPropagation(); | ||
33 | |||
34 | ///// Remove Transition | ||
35 | this._removeTransition = true; | ||
36 | this.collapser.removeEventListener('webkitTransitionEnd', this, false); | ||
37 | |||
38 | //// If it's an expand transition, restore height to auto | ||
39 | if(this.isExpanded) { | ||
40 | this._switchToAuto = true; | ||
41 | } | ||
42 | |||
43 | this.needsDraw = true; | ||
44 | |||
45 | } | ||
46 | }, | ||
47 | templateDidLoad: { | ||
48 | value: function() { | ||
49 | this.arrayController.delegate = this.treeView.contentController; | ||
50 | } | ||
51 | }, | ||
52 | willDraw : { | ||
53 | value: function() { | ||
54 | if(this._doCollapse && this._step === 0) { | ||
55 | this.branchHeight = window.getComputedStyle(this.collapser).height; | ||
56 | } | ||
57 | } | ||
58 | }, | ||
59 | draw:{ | ||
60 | value: function () { | ||
61 | |||
62 | if (this.sourceObject[this.labelKey]) { | ||
63 | this._labelText = this.sourceObject[this.labelKey]; | ||
64 | } | ||
65 | |||
66 | if(this._doCollapse) { | ||
67 | if (this._step === 0) { | ||
68 | this.collapser.style.height = this.branchHeight; | ||
69 | this.collapser.style.position = "relative"; | ||
70 | this.collapser.style.overflow = 'hidden'; | ||
71 | this.collapser.childNodes[1].style.bottom = '0px'; | ||
72 | this.collapser.childNodes[1].style.position = 'absolute'; | ||
73 | this._step = 1; | ||
74 | this.needsDraw = true; | ||
75 | } else if (this._step === 1) { | ||
76 | this.collapser.classList.add(this.collapseClass); | ||
77 | this._step = 2; | ||
78 | this.needsDraw = true; | ||
79 | } else { | ||
80 | this.collapser.style.height = '0px'; | ||
81 | this._doCollapse = false; | ||
82 | this._step = 0; | ||
83 | } | ||
84 | } else if(this._doExpand) { | ||
85 | this.collapser.style.height = this.branchHeight; | ||
86 | |||
87 | this._doExpand = false; | ||
88 | } | ||
89 | if(this._switchToAuto) { | ||
90 | this.collapser.childNodes[1].style.position = 'static'; | ||
91 | this.collapser.style.height = 'auto'; | ||
92 | this._switchToAuto = false; | ||
93 | } | ||
94 | |||
95 | if(this._removeTransition) { | ||
96 | this.collapser.classList.remove(this.collapseClass); | ||
97 | this._removeTransition = false; | ||
98 | } | ||
99 | |||
100 | } | ||
101 | }, | ||
102 | _step : { | ||
103 | value : 0 | ||
104 | }, | ||
105 | handleClick : { | ||
106 | value: function(e) { | ||
107 | this.toggleExpand(); | ||
108 | } | ||
109 | }, | ||
110 | expand : { | ||
111 | value: function() { | ||
112 | this.collapser.addEventListener('webkitTransitionEnd', this, false); | ||
113 | this.needsDraw = this._doExpand = true; | ||
114 | } | ||
115 | }, | ||
116 | collapse : { | ||
117 | value: function() { | ||
118 | this.needsDraw = this._doCollapse = true; | ||
119 | } | ||
120 | }, | ||
121 | branchHeight: { | ||
122 | value: null, | ||
123 | enumberable: false | ||
124 | }, | ||
125 | collapseClass : { | ||
126 | value: 'nj-collapser', | ||
127 | enumberable: false | ||
128 | } | ||
129 | |||
130 | |||
131 | }); | ||