@@ -10,9 +10,15 @@ var app = app || {};
10
10
*/
11
11
app . FooterView = Object . create ( global . BaseView ) ;
12
12
13
+ /***
14
+ * FooterView render
15
+ * @returns void
16
+ */
13
17
app . FooterView . render = function ( ) {
18
+
14
19
this . placeholder . innerHTML = this . template ;
15
20
this . el = document . getElementById ( 'template-' + this . name ) ;
21
+ this . state = 'highlightedIcon' ; // highlightedIcon, unhighlightedIcon
16
22
17
23
if ( this . selectors ) {
18
24
// in contentView selectors is undefined; in footer view we have createNewWindow and windowIcon as selectors
@@ -23,7 +29,6 @@ var app = app || {};
23
29
24
30
this . iconList = this . el . firstChild ;
25
31
26
-
27
32
this . events . on . call ( this ) ;
28
33
29
34
} ;
@@ -32,13 +37,13 @@ var app = app || {};
32
37
* Bind event listeners to view elements
33
38
*/
34
39
app . FooterView . events = {
40
+
35
41
on : function ( ) {
36
42
37
43
Events . subscribe ( this . elements . createNewWindow , 'click' , this . createNewWindow . bind ( this ) ) ;
38
44
app . events . listen ( 'app:window:destroy' , this . destroyWindow . bind ( this ) ) ;
39
45
app . events . listen ( 'app:window:created' , this . createNewIcon . bind ( this ) ) ;
40
-
41
- // Events.subscribe(this.iconToHighlight,'click', this.iconHighlight.bind(this));
46
+ app . events . listen ( 'app:window:minimized' , this . windowMinimized ) ;
42
47
} ,
43
48
44
49
off : function ( ) {
@@ -47,13 +52,13 @@ var app = app || {};
47
52
} ;
48
53
49
54
/***
50
- * Create new Windown object
55
+ * Create new Window Object
56
+ * @returns void
51
57
*/
52
58
app . FooterView . createNewWindow = function ( ) {
53
- // app.FooterView.el.firstChild.innerHTML += app.templates.footerTemplate;
54
59
60
+ this . state = 'highlightedIcon' ;
55
61
app . events . notify ( 'app:window:create' ) ;
56
-
57
62
} ;
58
63
59
64
/***
@@ -62,56 +67,108 @@ var app = app || {};
62
67
* @return void
63
68
*/
64
69
app . FooterView . createNewIcon = function ( evnt ) {
70
+
65
71
var wrapper = document . createElement ( 'li' ) ;
66
72
wrapper . className = 'window-tab' ;
67
73
wrapper . id = evnt . detail . id ;
68
74
wrapper . innerHTML = app . templates . footerTemplate ;
69
75
var iconcolor = 'rgb(' + ( Math . floor ( Math . random ( ) * 256 ) ) + ',' + ( Math . floor ( Math . random ( ) * 256 ) ) + ',' + ( Math . floor ( Math . random ( ) * 256 ) ) + ')' ;
70
- // function GetRandomColor() {
71
- // var letters = '0123456789ABCDEF'.split('');
72
- // var color = '#';
73
- // for (var i = 0; i < 6; i++ ) {
74
- // color += letters[Math.floor(Math.random() * 16)];
75
- // }
76
- // return color;
77
- // }
78
- // wrapper.firstChild.style.color = GetRandomColor();
76
+
79
77
wrapper . firstChild . style . color = iconcolor ;
80
78
this . iconList . appendChild ( wrapper ) ;
79
+ app . FooterView . footerInstances . push ( { id : wrapper . id } ) ;
81
80
81
+ this . resetFooter ( ) ;
82
82
83
+ wrapper . classList . add ( "iconhighlight" ) ;
83
84
Events . subscribe ( wrapper , 'click' , this . iconHighlight ) ;
84
85
} ;
85
86
87
+ /***
88
+ * Highlights the current icon in footer
89
+ * @param {Object } elm
90
+ * @return void
91
+ */
92
+ app . FooterView . iconHighlight = function ( evnt ) {
93
+
94
+ var elm = evnt . target . parentNode ;
95
+ if ( elm . classList . contains ( 'iconhighlight' ) ) {
96
+ elm . classList . remove ( 'iconhighlight' ) ;
97
+ app . events . notify ( 'app:footericon:unhighlighted:' + elm . id ) ;
98
+ }
99
+ else {
100
+ app . FooterView . resetFooter ( ) ;
101
+ elm . classList . add ( 'iconhighlight' ) ;
102
+ app . events . notify ( 'app:footericon:highlighted:' + elm . id ) ;
103
+ }
104
+ } ;
105
+
106
+ /***
107
+ * What happens when window gets minimized
108
+ * @return void
109
+ */
110
+ app . FooterView . windowMinimized = function ( evnt ) {
111
+
112
+ if ( evnt . detail . id ) {
113
+ var currentElement = document . getElementById ( evnt . detail . id ) ;
114
+ currentElement . classList . remove ( 'iconhighlight' ) ;
115
+ }
116
+ } ,
117
+ /***
118
+ * Creates a new icon in footer
119
+ * @return void
120
+ */
121
+ app . FooterView . resetFooter = function ( ) {
122
+
123
+ for ( var i = app . FooterView . footerInstances . length - 1 ; i >= 0 ; i -- ) {
124
+ var currentElement = document . getElementById ( app . FooterView . footerInstances [ i ] . id ) ;
125
+
126
+ currentElement . classList . forEach ( function ( className ) {
127
+ if ( className !== 'window-tab' ) {
128
+ app . events . notify ( 'app:footericon:unhighlighted:' + app . FooterView . footerInstances [ i ] . id ) ;
129
+ currentElement . classList . remove ( className ) ;
130
+ }
131
+ } ) ;
132
+ }
133
+ } ;
134
+
135
+ /***
136
+ * Destroys the footer icon of destroyed window
137
+ * @param {EventObject } evnt
138
+ * @return void
139
+ */
86
140
app . FooterView . destroyWindow = function ( evnt ) {
87
141
142
+ for ( var i = app . FooterView . footerInstances . length - 1 ; i >= 0 ; i -- ) {
143
+ if ( app . FooterView . footerInstances [ i ] . id === evnt . detail . id ) {
144
+ app . FooterView . footerInstances . splice ( i , 1 ) ;
145
+ }
146
+ }
88
147
/***
89
148
* Need to add code to remove icon
90
149
*/
91
150
var iconToRemove = this . iconList . querySelector ( '#' + evnt . detail . id ) ;
92
151
Events . unsubscribe ( iconToRemove , 'click' , this . iconHighlight ) ;
93
152
iconToRemove . parentNode . removeChild ( iconToRemove ) ;
94
-
95
-
96
-
97
153
} ;
98
154
99
- app . FooterView . iconHighlight = function ( ) {
100
- this . classList . add ( 'iconhighlight' ) ;
101
-
102
- app . events . notify ( 'app:footericon:highlighted:' + this . id ) ;
103
- } ;
155
+ // app.FooterView.checkState = function (elm){
104
156
157
+ // };
105
158
106
159
/***
107
160
* Store cached elements
108
161
*/
109
162
app . FooterView . elements = {
110
163
} ;
164
+
165
+ app . FooterView . footerInstances = [ ] ;
166
+
111
167
/***
112
168
* Elements selectors
113
169
*/
114
170
app . FooterView . selectors = {
171
+
115
172
createNewWindow : '.icon-smile' ,
116
173
windowIcon : '.window-tab'
117
174
} ;
0 commit comments