Skip to content

Commit 601dcb3

Browse files
committed
Added different colors for each window , WindowView is not prototype any more, made it OLOO , problems : by destroying windows , can't destroy more than one window and can't remove icons from footer
1 parent a4e65fc commit 601dcb3

File tree

4 files changed

+71
-35
lines changed

4 files changed

+71
-35
lines changed

EXERCISE/Exercise 4/app/components/events.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var Events = {
2323
* @param {Object} params
2424
* returns void
2525
*/
26-
subscribe: function (el,eventName,handler,params) {
26+
subscribe: function (el,eventName,handler) {
2727

2828
el.addEventListener(eventName,handler,false);
2929
},
@@ -35,7 +35,7 @@ var Events = {
3535
* @param {Object} params
3636
* returns void
3737
*/
38-
publish: function (el,eventName,params) {
38+
publish: function (el,eventName) {
3939

4040
var event = this.create(eventName);
4141
el.dispatchEvent(event);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ var app = app || {};
2323

2424
app.ContentView.createNewWindow = function () {
2525
console.log(2);
26-
app.windowInstances.push(new global.windowView({
26+
app.windowInstances.push(global.WindowView.init({
2727
/***
2828
* TO DO Homework: create UNIQUE ID
2929
*/

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,25 @@ var app = app || {};
4343
var wrapper=document.createElement('li');
4444
wrapper.className='window-tab';
4545
wrapper.innerHTML=app.templates.footerTemplate;
46+
var iconcolor = 'rgb(' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ',' + (Math.floor(Math.random() * 256)) + ')';
47+
// function GetRandomColor() {
48+
// var letters = '0123456789ABCDEF'.split('');
49+
// var color = '#';
50+
// for (var i = 0; i < 6; i++ ) {
51+
// color += letters[Math.floor(Math.random() * 16)];
52+
// }
53+
// return color;
54+
// }
55+
// wrapper.firstChild.style.color = GetRandomColor();
56+
wrapper.firstChild.style.color = iconcolor;
4657
this.el.firstChild.appendChild(wrapper);
4758
};
4859

4960
app.FooterView.destroyWindow = function () {
5061
/***
5162
* Need to add code to remove icon
5263
*/
53-
54-
64+
this.wrapper.parentNode.removeChild(this.wrapper);
5565
};
5666

5767

@@ -66,6 +76,16 @@ var app = app || {};
6676
*/
6777
app.FooterView.selectors = {
6878
createNewWindow: '.icon-smile',
69-
destroyWindow: '.icon-delete-circle'
79+
destroyWindow: '.window-tab'
7080
};
81+
82+
// app.FooterView.iconcolor= function() {
83+
// var letters = '0123456789ABCDEF'.split('');
84+
// var color = '#';
85+
// for (var i = 0; i < 6; i++ ) {
86+
// color += letters[Math.floor(Math.random() * 16)];
87+
// }
88+
// return color;
89+
// };
90+
7191
})(window,app);
Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,64 @@
11
/***
22
* Window view
33
*/
4+
/***
5+
* @param {Object} options
6+
* returns void
7+
*/
48
var app = app || {};
59

6-
(function (){
10+
(function(global){
711

8-
/***
9-
* @param {Object} options
10-
* returns void
11-
*/
12-
function windowView (options) {
12+
global.WindowView = {
1313

14-
//Execpional template or default template
15-
this.template = options.template || app.templates.windowTemplate;
16-
this.id = options.id;
17-
this.type = options.type || 'maximized'; //minimized or maximized
14+
/***
15+
* Generic initialization method
16+
*/
17+
init: function (options) {
18+
this.template = options.template || app.templates.windowTemplate;
19+
this.id = options.id;
20+
this.type = options.type || 'maximized'; //minimized or maximized
1821

19-
this.render();
22+
this.render();
2023

21-
this.closeIcon=this.wrapper.querySelector('.icon-delete-circle');
22-
Events.subscribe(this.closeIcon, 'click', this.destroy.bind(this));
24+
this.closeIcon=this.wrapper.querySelector('.icon-delete-circle');
25+
Events.subscribe(this.closeIcon, 'click', this.destroy.bind(this));
26+
// app.events.listen('window:' + this.id + ':render', this.render.bind(this));
27+
},
2328

24-
// app.events.listen('window:' + this.id + ':render', this.render.bind(this));
25-
};
29+
/***
30+
* Window render
31+
*/
32+
render: function () {
33+
this.wrapper=document.createElement('section');
34+
this.wrapper.className='window';
35+
this.wrapper.innerHTML=this.template.join('');
36+
app.ContentView.el.appendChild(this.wrapper);
37+
},
2638

27-
windowView.prototype.render = function() {
28-
this.wrapper=document.createElement('section');
29-
this.wrapper.className='window';
30-
this.wrapper.innerHTML=this.template.join('');
31-
app.ContentView.el.appendChild(this.wrapper);
39+
/***
40+
* Window destroy
41+
*/
42+
destroy: function () {
43+
this.wrapper.parentNode.removeChild(this.wrapper);
44+
console.log('destroy', this.template);
3245

46+
app.events.notify('app:window:destroy',{id: this.id});
47+
},
3348

49+
events: {
3450

35-
// .el.innerHTML += this.template;
36-
};
51+
on: function () {
3752

38-
windowView.prototype.destroy = function() {
39-
this.wrapper.parentNode.removeChild(this.wrapper);
40-
console.log('destroy', this.template);
53+
},
4154

42-
app.events.notify('app:window:destroy',{id: this.id});
43-
};
55+
off: function () {
4456

57+
}
58+
},
4559

60+
selectors: {
4661

47-
window.windowView = windowView;
48-
})();
62+
}
63+
};
64+
})(window);

0 commit comments

Comments
 (0)