Skip to content

Commit 194572b

Browse files
committed
Added Documentation
1 parent 36a96d3 commit 194572b

File tree

4 files changed

+138
-12
lines changed

4 files changed

+138
-12
lines changed

EXERCISE/Exercise 4/app/views/content-view.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ var app = app || {};
66
(function (global, app){
77

88
/***
9-
* @param {Object} options
10-
* returns void
9+
* Created ContentView
10+
* @returns void
1111
*/
1212
app.ContentView = Object.create(global.BaseView);
1313

@@ -22,6 +22,10 @@ var app = app || {};
2222
}
2323
};
2424

25+
/***
26+
* Creates new Instance of WindowView and adds unique id
27+
* @returns void
28+
*/
2529
app.ContentView.createNewWindow = function () {
2630
console.log(2);
2731
var windowInstance = Object.create(global.WindowView);
@@ -38,6 +42,11 @@ var app = app || {};
3842
// destroyWindow: '.icon-delete-circle'
3943
// }
4044

45+
/***
46+
* Removes the current WindowView instance
47+
* @param {EventObject} evnt
48+
* @returns void
49+
*/
4150
app.ContentView.destroyWindow = function (evnt) {
4251
console.log(0);
4352
// this.parentElement.removeChild(this[i]);

EXERCISE/Exercise 4/app/views/footer-view.js

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,14 @@ var app = app || {};
1010
*/
1111
app.FooterView = Object.create(global.BaseView);
1212

13+
/***
14+
* FooterView render
15+
* @returns void
16+
*/
1317
app.FooterView.render= function () {
1418
this.placeholder.innerHTML = this.template;
1519
this.el = document.getElementById('template-' + this.name);
20+
this.state='highlightedIcon';// highlightedIcon, unhighlightedIcon
1621

1722
if(this.selectors) {
1823
// in contentView selectors is undefined; in footer view we have createNewWindow and windowIcon as selectors
@@ -47,11 +52,12 @@ var app = app || {};
4752
};
4853

4954
/***
50-
* Create new Windown object
55+
* Create new Window Object
56+
* @returns void
5157
*/
5258
app.FooterView.createNewWindow = function () {
5359
// app.FooterView.el.firstChild.innerHTML += app.templates.footerTemplate;
54-
60+
this.state='highlightedIcon';
5561
app.events.notify('app:window:create');
5662

5763
};
@@ -78,28 +84,68 @@ var app = app || {};
7884
// wrapper.firstChild.style.color = GetRandomColor();
7985
wrapper.firstChild.style.color = iconcolor;
8086
this.iconList.appendChild(wrapper);
87+
app.FooterView.footerInstances.push({id: wrapper.id});
8188

89+
this.resetFooter();
8290

83-
Events.subscribe(wrapper, 'click', this.iconHighlight);
91+
wrapper.classList.add("iconHighlight");
92+
Events.subscribe(wrapper, 'click', this.iconHighlight(wrapper));
8493
};
8594

86-
app.FooterView.destroyWindow = function (evnt) {
95+
/***
96+
* Creates a new icon in footer
97+
* @return void
98+
*/
99+
app.FooterView.resetFooter = function(){
100+
// var footerview = this.el;
101+
for (var i = app.FooterView.footerInstances.length - 1; i >= 0; i--) {
102+
var currentElement = document.getElementById(app.FooterView.footerInstances[i].id);
103+
currentElement.classList.forEach(function(className){
104+
if(className !== 'window-tab') {
105+
currentElement.classList.remove(className);
106+
}
107+
});
108+
}
109+
};
87110

111+
/***
112+
* Destroys the footer icon of destroyed window
113+
* @param {EventObject} evnt
114+
* @return void
115+
*/
116+
app.FooterView.destroyWindow = function (evnt) {
117+
for (var i = app.FooterView.footerInstances.length - 1; i >= 0; i--) {
118+
if(app.FooterView.footerInstances[i].id === evnt.detail.id){
119+
app.FooterView.footerInstances.splice(i,1);
120+
}
121+
}
88122
/***
89123
* Need to add code to remove icon
90124
*/
91125
var iconToRemove = this.iconList.querySelector('#'+evnt.detail.id);
92126
Events.unsubscribe(iconToRemove,'click',this.iconHighlight);
93127
iconToRemove.parentNode.removeChild(iconToRemove);
128+
};
94129

95-
96-
130+
/***
131+
* Highlights the current icon in footer
132+
* @param {Object} elm
133+
* @return void
134+
*/
135+
app.FooterView.iconHighlight = function (elm) {
136+
if(elm.classList.contains('iconhighlight')){
137+
elm.classList.remove('iconhighlight');
138+
app.events.notify('app:footericon:unhighlighted:' + elm.id);
139+
}
140+
else{
141+
this.resetFooter();
142+
elm.classList.add('iconhighlight');
143+
app.events.notify('app:footericon:highlighted:' + elm.id);
144+
}
97145
};
98146

99-
app.FooterView.iconHighlight = function () {
100-
this.classList.add('iconhighlight');
147+
app.FooterView.checkState = function (elm){
101148

102-
app.events.notify('app:footericon:highlighted:' + this.id);
103149
};
104150

105151

@@ -108,6 +154,9 @@ var app = app || {};
108154
*/
109155
app.FooterView.elements = {
110156
};
157+
158+
app.FooterView.footerInstances = [];
159+
111160
/***
112161
* Elements selectors
113162
*/

EXERCISE/Exercise 4/app/views/window-view.js

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ var app = app || {};
1414
internelMethods: ['destroy', 'minimize', 'maximize', 'highlight'],
1515

1616
/***
17-
* Generic initialization method
17+
* Window initialization method
18+
* @param {Object} options
19+
* @returns void
1820
*/
1921
init: function (options) {
2022
this.template = options.template || app.templates.windowTemplate;
@@ -29,6 +31,11 @@ var app = app || {};
2931
// app.events.listen('window:' + this.id + ':render', this.render.bind(this));
3032
},
3133

34+
35+
/***
36+
* Binds the events of internal methods
37+
* @returns void
38+
*/
3239
bindInternalMethods: function () {
3340
var view = this;
3441

@@ -39,6 +46,7 @@ var app = app || {};
3946

4047
/***
4148
* Window render
49+
* @returns void
4250
*/
4351
render: function () {
4452
this.wrapper=document.createElement('section');
@@ -56,6 +64,7 @@ var app = app || {};
5664

5765
/***
5866
* Window destroy
67+
* @returns void
5968
*/
6069
destroy: function () {
6170
this.events.off.call(this);
@@ -65,6 +74,10 @@ var app = app || {};
6574
app.events.notify('app:window:destroy',{id: this.id});
6675
},
6776

77+
/***
78+
* Window minimize
79+
* @returns void
80+
*/
6881
minimize: function(){
6982
this.resetView();
7083

@@ -74,6 +87,10 @@ var app = app || {};
7487
app.events.notify('app:window:minimized');
7588
},
7689

90+
/***
91+
* Window reset- removes the extra styles added in code
92+
* @returns void
93+
*/
7794
resetView: function () {
7895
var view = this;
7996
this.wrapper.classList.forEach(function(className){
@@ -83,6 +100,10 @@ var app = app || {};
83100
});
84101
},
85102

103+
/***
104+
* Window popup
105+
* @returns void
106+
*/
86107
popup: function(){
87108
this.resetView();
88109

@@ -92,6 +113,10 @@ var app = app || {};
92113
// app.events.notify('app:window:popup');
93114
},
94115

116+
/***
117+
* Window maximize
118+
* @returns void
119+
*/
95120
maximize: function(){
96121
if(this.type === "maximized"){
97122
this.wrapper.removeAttribute("style");
@@ -106,27 +131,52 @@ var app = app || {};
106131
}
107132
},
108133

134+
/***
135+
* Window highlight
136+
* @param {EventObject} evnt
137+
* @returns void
138+
*/
109139
highlight: function(evnt){
140+
this.resetView();
110141
this.wrapper.classList.add('windowhighlight');
111142
},
112143

144+
/***
145+
* Window unhighlight
146+
* @param {EventObject} evnt
147+
* @returns void
148+
*/
149+
unhighlight: function(evnt){
150+
this.wrapper.classList.remove('windowhighlight');
151+
},
152+
153+
/***
154+
* Bind event listeners to view elements
155+
*/
113156
events: {
114157

115158
on: function () {
116159
Events.subscribe(this.closeIcon, 'click', this.destroy);
117160
Events.subscribe(this.minimizeIcon, 'click', this.minimize);
118161
Events.subscribe(this.maximizeIcon, 'click', this.maximize);
162+
app.events.listen('app:footericon:unhighlighted:' + this.id, this.unhighlight);
119163
app.events.listen('app:footericon:highlighted:' + this.id, this.highlight);
164+
120165
},
121166

122167
off: function () {
123168
Events.unsubscribe(this.closeIcon, 'click', this.destroy);
124169
Events.unsubscribe(this.minimizeIcon, 'click', this.minimize);
125170
Events.unsubscribe(this.maximizeIcon, 'click', this.maximize);
171+
app.events.remove('app:footericon:unhighlighted:' + this.id, this.unhighlight);
126172
app.events.remove('app:footericon:highlighted:' + this.id, this.highlight);
173+
127174
}
128175
},
129176

177+
/***
178+
* Elements selectors
179+
*/
130180
selectors: {
131181
closeIcon:'.icon-delete-circle',
132182
minimizeIcon: '.icon-dash',

EXERCISE/Exercise 4/styles/style.css

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,21 @@ body {
225225
.wrapper .menu li.iconhighlight{
226226
background-color: rgba(5,180,186,0.2);
227227
}
228+
229+
/*
230+
* Hidden Window by initialization
231+
*/
232+
233+
.hidden{
234+
display: none;
235+
}
236+
237+
/*
238+
* Maximized Window
239+
*/
240+
.maxi{
241+
position: absolute;
242+
top: 0;
243+
max-width: 100%;
244+
}
245+

0 commit comments

Comments
 (0)