Skip to content

Commit 4f672f2

Browse files
committed
Merge pull request CodiCamp#3 from An2kataluna/master
22.11.2015
2 parents 4f381aa + 9753906 commit 4f672f2

File tree

7 files changed

+247
-97
lines changed

7 files changed

+247
-97
lines changed

EXERCISE/Exercise 4/app/controllers/controller.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ var app = app || {};
1111
* Base app config
1212
*/
1313
var config = {
14+
1415
el: '.wrapper'
1516
},
1617

EXERCISE/Exercise 4/app/templates/templates.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@ var app = app || {};
88
app.templates = {
99

1010
layout: {
11+
1112
Content: '<div id="template-Content"></div>',
1213
Footer: '<nav class="menu" id="template-Footer"><ul><li class="start"><a href="javascript:;" class="icon-smile"></a></li></ul></nav>'
1314
},
1415

1516
windowTemplate: [
17+
1618
'<header class="header">',
1719
'<div class="window-actions">',
1820
'<span class="action icon-dash"></span>',

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* Generic initialization method
1414
*/
1515
init: function (options) {
16+
1617
this.template = options.template;
1718
this.name = options.name;
1819
this.placeholder = document.getElementById('placeholder-' + options.name);
@@ -24,6 +25,7 @@
2425
* Generic render
2526
*/
2627
render: function () {
28+
2729
this.placeholder.innerHTML = this.template;
2830
this.el = document.getElementById('template-' + this.name);
2931

@@ -41,8 +43,8 @@
4143
* Generic destroy
4244
*/
4345
destroy: function () {
44-
console.log('destroy', this.template);
4546

47+
// console.log('destroy', this.template);
4648
this.events.off();
4749
},
4850

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

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@ 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

1414
app.ContentView.events = {
15+
1516
on: function () {
17+
1618
app.events.listen('app:window:create', this.createNewWindow);
1719
app.events.listen('app:window:destroy', this.destroyWindow);
1820
},
@@ -22,9 +24,15 @@ var app = app || {};
2224
}
2325
};
2426

27+
/***
28+
* Creates new Instance of WindowView and adds unique id
29+
* @returns void
30+
*/
2531
app.ContentView.createNewWindow = function () {
32+
2633
console.log(2);
2734
var windowInstance = Object.create(global.WindowView);
35+
2836
/**
2937
* Creates a string that can be used for dynamic id attributes
3038
* Example: "id-wm68fu1uk63cjtt9"
@@ -38,7 +46,13 @@ var app = app || {};
3846
// destroyWindow: '.icon-delete-circle'
3947
// }
4048

49+
/***
50+
* Removes the current WindowView instance
51+
* @param {EventObject} evnt
52+
* @returns void
53+
*/
4154
app.ContentView.destroyWindow = function (evnt) {
55+
4256
console.log(0);
4357
// this.parentElement.removeChild(this[i]);
4458
for (var i = app.windowInstances.length - 1; i >= 0; i--) {
@@ -49,5 +63,4 @@ var app = app || {};
4963

5064
};
5165

52-
5366
})(window, app);

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

Lines changed: 80 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,15 @@ 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 () {
18+
1419
this.placeholder.innerHTML = this.template;
1520
this.el = document.getElementById('template-' + this.name);
21+
this.state='highlightedIcon';// highlightedIcon, unhighlightedIcon
1622

1723
if(this.selectors) {
1824
// in contentView selectors is undefined; in footer view we have createNewWindow and windowIcon as selectors
@@ -23,7 +29,6 @@ var app = app || {};
2329

2430
this.iconList = this.el.firstChild;
2531

26-
2732
this.events.on.call(this);
2833

2934
};
@@ -32,13 +37,13 @@ var app = app || {};
3237
* Bind event listeners to view elements
3338
*/
3439
app.FooterView.events = {
40+
3541
on: function () {
3642

3743
Events.subscribe(this.elements.createNewWindow, 'click', this.createNewWindow.bind(this));
3844
app.events.listen('app:window:destroy', this.destroyWindow.bind(this));
3945
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);
4247
},
4348

4449
off: function () {
@@ -47,13 +52,13 @@ 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 () {
53-
// app.FooterView.el.firstChild.innerHTML += app.templates.footerTemplate;
5459

60+
this.state='highlightedIcon';
5561
app.events.notify('app:window:create');
56-
5762
};
5863

5964
/***
@@ -62,56 +67,108 @@ var app = app || {};
6267
* @return void
6368
*/
6469
app.FooterView.createNewIcon = function(evnt){
70+
6571
var wrapper=document.createElement('li');
6672
wrapper.className='window-tab';
6773
wrapper.id = evnt.detail.id;
6874
wrapper.innerHTML=app.templates.footerTemplate;
6975
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+
7977
wrapper.firstChild.style.color = iconcolor;
8078
this.iconList.appendChild(wrapper);
79+
app.FooterView.footerInstances.push({id: wrapper.id});
8180

81+
this.resetFooter();
8282

83+
wrapper.classList.add("iconhighlight");
8384
Events.subscribe(wrapper, 'click', this.iconHighlight);
8485
};
8586

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+
*/
86140
app.FooterView.destroyWindow = function (evnt) {
87141

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+
}
88147
/***
89148
* Need to add code to remove icon
90149
*/
91150
var iconToRemove = this.iconList.querySelector('#'+evnt.detail.id);
92151
Events.unsubscribe(iconToRemove,'click',this.iconHighlight);
93152
iconToRemove.parentNode.removeChild(iconToRemove);
94-
95-
96-
97153
};
98154

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){
104156

157+
// };
105158

106159
/***
107160
* Store cached elements
108161
*/
109162
app.FooterView.elements = {
110163
};
164+
165+
app.FooterView.footerInstances = [];
166+
111167
/***
112168
* Elements selectors
113169
*/
114170
app.FooterView.selectors = {
171+
115172
createNewWindow: '.icon-smile',
116173
windowIcon: '.window-tab'
117174
};

0 commit comments

Comments
 (0)