Skip to content

Commit a4e65fc

Browse files
committed
First commit
1 parent 3c963d2 commit a4e65fc

File tree

8 files changed

+88
-21
lines changed

8 files changed

+88
-21
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ var Events = {
2020
* @param {Dom Object} el
2121
* @param {String} eventName
2222
* @param {Function} handler
23+
* @param {Object} params
2324
* returns void
2425
*/
25-
subscribe: function (el,eventName,handler) {
26+
subscribe: function (el,eventName,handler,params) {
2627

2728
el.addEventListener(eventName,handler,false);
2829
},
@@ -31,9 +32,10 @@ var Events = {
3132
* Publishes an event to the listneres
3233
* @param {Dom Object} el
3334
* @param {String} eventName
35+
* @param {Object} params
3436
* returns void
3537
*/
36-
publish: function (el,eventName) {
38+
publish: function (el,eventName,params) {
3739

3840
var event = this.create(eventName);
3941
el.dispatchEvent(event);
@@ -50,4 +52,4 @@ var Events = {
5052
unsubscribe: function (el,eventName,handler) {
5153
el.removeEventListener(eventName,handler,false);
5254
}
53-
};
55+
};

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ var app = app || {};
4747

4848
/***
4949
* Internal application events
50+
* @param {Object} params
5051
*/
5152
app.events = {
5253

@@ -55,7 +56,7 @@ var app = app || {};
5556
Events.subscribe(elements.el, eventName, handler);
5657
},
5758

58-
notify: function (eventName) {
59+
notify: function (eventName,params) {
5960

6061
Events.publish(elements.el, eventName);
6162
}
@@ -114,4 +115,4 @@ var app = app || {};
114115
elements.el = doc.querySelector(config.el);
115116
}
116117

117-
})(window, document);
118+
})(window, document);

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ var app = app || {};
99

1010
layout: {
1111
Content: '<div id="template-Content"></div>',
12-
Footer: '<nav class="menu" id="template-Footer"><ul><li class="start"><a href="javascript:;" class="icon-smile"></a></li><li class="window-tab"><a href="#" class="icon-browser"></a></li></ul></nav>'
12+
Footer: '<nav class="menu" id="template-Footer"><ul><li class="start"><a href="javascript:;" class="icon-smile"></a></li></ul></nav>'
1313
},
1414

15-
windowTemplate: ['<section class="window" id="test">',
15+
windowTemplate: [
1616
'<header class="header">',
1717
'<div class="window-actions">',
1818
'<span class="action icon-dash"></span>',
@@ -31,7 +31,8 @@ var app = app || {};
3131
'</div>',
3232
'<footer class="footer">',
3333
'<strong> Status bar :) </strong>',
34-
'</footer>',
35-
'</section>']
34+
'</footer>'],
35+
36+
footerTemplate:'<a href="#" class="icon-browser"></a>'
3637
};
37-
})();
38+
})();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
this.el = document.getElementById('template-' + this.name);
2929

3030
if(this.selectors) {
31-
31+
// in contentView selectors is undefined; in footer view we have createNewWindow and destroyWindow as selectors
3232
for(var selector in this.selectors) {
3333
this.elements[selector] = document.querySelector(this.selectors[selector]);
3434
}
@@ -58,4 +58,4 @@
5858
}
5959
};
6060

61-
})(window);
61+
})(window);

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

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,30 @@ var app = app || {};
2727
/***
2828
* TO DO Homework: create UNIQUE ID
2929
*/
30-
id: app.windowInstances.length
30+
31+
/**
32+
* Creates a string that can be used for dynamic id attributes
33+
* Example: "id-wm68fu1uk63cjtt9"
34+
* @returns {string}
35+
*/
36+
// var uniqueId =
37+
38+
id: 'id-' + Math.random().toString(36).substr(2, 16)
39+
40+
// id: 'id' + (new Date()).getTime()
41+
// app.windowInstances.length
3142
}));
3243
};
3344

45+
// app.ContentView.selectors={
46+
// destroyWindow: '.icon-delete-circle'
47+
// }
48+
49+
app.ContentView.destroyWindow = function () {
50+
console.log(0);
51+
// this.parentElement.removeChild(this[i]);
52+
app.windowInstances.pop();
53+
};
54+
3455

35-
})(window, app);
56+
})(window, app);

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

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@ var app = app || {};
1616
app.FooterView.events = {
1717
on: function () {
1818

19-
Events.subscribe(this.elements.createNewWindow, 'click', this.createNewWindow);
19+
Events.subscribe(this.elements.createNewWindow, 'click', this.createNewWindow.bind(this));
20+
app.events.listen('app:window:destroy', this.destroyWindow.bind(this));
21+
},
22+
23+
off: function () {
24+
2025
}
2126
};
2227

@@ -27,9 +32,29 @@ var app = app || {};
2732
/***
2833
* TO DO HOMEWORK: add icon for each new window
2934
*/
35+
36+
this.createNewIcon();
37+
// app.FooterView.el.firstChild.innerHTML += app.templates.footerTemplate;
3038
app.events.notify('app:window:create');
39+
3140
};
3241

42+
app.FooterView.createNewIcon = function(){
43+
var wrapper=document.createElement('li');
44+
wrapper.className='window-tab';
45+
wrapper.innerHTML=app.templates.footerTemplate;
46+
this.el.firstChild.appendChild(wrapper);
47+
};
48+
49+
app.FooterView.destroyWindow = function () {
50+
/***
51+
* Need to add code to remove icon
52+
*/
53+
54+
55+
};
56+
57+
3358
/***
3459
* Store cached elements
3560
*/
@@ -40,6 +65,7 @@ var app = app || {};
4065
* Elements selectors
4166
*/
4267
app.FooterView.selectors = {
43-
createNewWindow: '.icon-smile'
68+
createNewWindow: '.icon-smile',
69+
destroyWindow: '.icon-delete-circle'
4470
};
45-
})(window,app);
71+
})(window,app);

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,32 @@ var app = app || {};
1717
this.type = options.type || 'maximized'; //minimized or maximized
1818

1919
this.render();
20+
21+
this.closeIcon=this.wrapper.querySelector('.icon-delete-circle');
22+
Events.subscribe(this.closeIcon, 'click', this.destroy.bind(this));
23+
2024
// app.events.listen('window:' + this.id + ':render', this.render.bind(this));
2125
};
2226

2327
windowView.prototype.render = function() {
24-
app.ContentView.el.innerHTML += this.template.join('');
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);
32+
33+
34+
35+
// .el.innerHTML += this.template;
2536
};
2637

2738
windowView.prototype.destroy = function() {
39+
this.wrapper.parentNode.removeChild(this.wrapper);
2840
console.log('destroy', this.template);
41+
42+
app.events.notify('app:window:destroy',{id: this.id});
2943
};
3044

45+
46+
3147
window.windowView = windowView;
32-
})();
48+
})();

EXERCISE/Exercise 4/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<body>
1313

1414
<div class="wrapper">
15-
<div id="placeholder-header">
15+
<div id="placeholder-Header">
1616

1717
</div>
1818
<div id="placeholder-Content"></div>
@@ -28,4 +28,4 @@
2828
<script type="text/javascript" src="app/controllers/controller.js"></script>
2929

3030
</body>
31-
</html>
31+
</html>

0 commit comments

Comments
 (0)