Skip to content

Commit 3fb4f88

Browse files
committed
latest changes - OLOO style added
1 parent 3b7e7a9 commit 3fb4f88

File tree

7 files changed

+113
-106
lines changed

7 files changed

+113
-106
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,10 @@ var app = app || {};
9090

9191
for (var templateName in this.templates.layout) {
9292

93-
app.layout[templateName] = new this[templateName + 'View']({
93+
this[templateName + 'View'].init({
9494
template: this.templates.layout[templateName],
9595
name: templateName
9696
});
97-
98-
app.events.notify('view:' + templateName + ':render');
9997
}
10098
};
10199

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

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

1010
layout: {
11-
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>'
11+
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>'
1313
},
1414

1515
windowTemplate: ['<section class="window" id="test">',
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/***
2+
* Base view
3+
* - render
4+
* - destroy
5+
* - bind events
6+
* - unbind events
7+
*/
8+
(function(global){
9+
10+
global.BaseView = {
11+
12+
/***
13+
* Generic initialization method
14+
*/
15+
init: function (options) {
16+
this.template = options.template;
17+
this.name = options.name;
18+
this.placeholder = document.getElementById('placeholder-' + options.name);
19+
20+
this.render();
21+
},
22+
23+
/***
24+
* Generic render
25+
*/
26+
render: function () {
27+
this.placeholder.innerHTML = this.template;
28+
this.el = document.getElementById('template-' + this.name);
29+
30+
if(this.selectors) {
31+
32+
for(var selector in this.selectors) {
33+
this.elements[selector] = document.querySelector(this.selectors[selector]);
34+
}
35+
}
36+
37+
this.events.on.call(this);
38+
},
39+
40+
/***
41+
* Generic destroy
42+
*/
43+
destroy: function () {
44+
console.log('destroy', this.template);
45+
46+
this.events.off();
47+
},
48+
49+
events: {
50+
51+
on: function () {
52+
53+
},
54+
55+
off: function () {
56+
57+
}
58+
}
59+
};
60+
61+
})(window);

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

Lines changed: 18 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,58 +3,33 @@
33
*/
44
var app = app || {};
55

6-
(function (global){
6+
(function (global, app){
77

88
/***
99
* @param {Object} options
1010
* returns void
1111
*/
12-
function contentView (options) {
12+
app.ContentView = Object.create(global.BaseView);
1313

14-
this.template = options.template;
15-
this.name = options.name;
16-
this.placeholder = document.getElementById('placeholder-' + options.name);
17-
18-
19-
/***
20-
* Bind event listeners to view elements
21-
*/
22-
this.bindEvents = function () {
14+
app.ContentView.events = {
15+
on: function () {
2316
app.events.listen('app:window:create', this.createNewWindow);
24-
};
25-
26-
this.unbindEvents = function () {
27-
28-
};
29-
30-
/***
31-
* Create new Windown object
32-
*/
33-
this.createNewWindow = function () {
34-
console.log(2);
35-
app.windowInstances.push(new global.windowView({
36-
/***
37-
* TO DO Homework: create UNIQUE ID
38-
*/
39-
id: app.windowInstances.length
40-
}));
41-
};
17+
},
4218

19+
off: function (argument) {
4320

44-
this.render = function () {
45-
46-
this.placeholder.innerHTML = this.template;
47-
this.el = document.getElementById('template-' + options.name);
48-
49-
this.bindEvents();
50-
};
51-
52-
this.destroy = function () {
53-
console.log('destroy', this.template);
54-
};
21+
}
22+
};
5523

56-
app.events.listen('view:' + this.name + ':render', this.render.bind(this));
24+
app.ContentView.createNewWindow = function () {
25+
console.log(2);
26+
app.windowInstances.push(new global.windowView({
27+
/***
28+
* TO DO Homework: create UNIQUE ID
29+
*/
30+
id: app.windowInstances.length
31+
}));
5732
};
5833

59-
app.contentView = contentView;
60-
})(window);
34+
35+
})(window, app);

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

Lines changed: 27 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -3,71 +3,43 @@
33
*/
44
var app = app || {};
55

6-
(function (global){
7-
6+
(function (global,app){
87
/***
98
* @param {Object} options
109
* returns void
1110
*/
12-
function footerView (options) {
13-
14-
this.template = options.template;
15-
this.name = options.name;
16-
this.placeholder = document.getElementById('placeholder-' + options.name);
17-
18-
/***
19-
* Elements selectors
20-
*/
21-
this.selectors = {
22-
createNewWindow: '.icon-smile'
23-
};
24-
25-
/***
26-
* Store cached elements
27-
*/
28-
this.elements = {
11+
app.FooterView = Object.create(global.BaseView);
2912

30-
};
31-
32-
/***
33-
* Bind event listeners to view elements
34-
*/
35-
this.bindEvents = function () {
13+
/***
14+
* Bind event listeners to view elements
15+
*/
16+
app.FooterView.events = {
17+
on: function () {
3618

3719
Events.subscribe(this.elements.createNewWindow, 'click', this.createNewWindow);
38-
};
39-
40-
this.unbindEvents = function () {
41-
42-
};
20+
}
21+
};
4322

23+
/***
24+
* Create new Windown object
25+
*/
26+
app.FooterView.createNewWindow = function () {
4427
/***
45-
* Create new Windown object
28+
* TO DO HOMEWORK: add icon for each new window
4629
*/
47-
this.createNewWindow = function () {
48-
/***
49-
* TO DO HOMEWORK: add icon for each new window
50-
*/
51-
app.events.notify('app:window:create');
52-
};
53-
54-
55-
this.render = function () {
56-
57-
this.placeholder.innerHTML = this.template;
58-
this.el = document.getElementById('template-' + options.name);
59-
60-
this.elements.createNewWindow = this.el.querySelector(this.selectors.createNewWindow);
61-
62-
this.bindEvents();
63-
};
30+
app.events.notify('app:window:create');
31+
};
6432

65-
this.destroy = function () {
66-
console.log('destroy', this.template);
67-
};
33+
/***
34+
* Store cached elements
35+
*/
36+
app.FooterView.elements = {
6837

69-
app.events.listen('view:' + this.name + ':render', this.render.bind(this));
7038
};
71-
72-
app.footerView = footerView;
73-
})(window);
39+
/***
40+
* Elements selectors
41+
*/
42+
app.FooterView.selectors = {
43+
createNewWindow: '.icon-smile'
44+
};
45+
})(window,app);

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

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

2323
windowView.prototype.render = function() {
24-
app.layout.content.el.innerHTML += this.template.join('');
24+
app.ContentView.el.innerHTML += this.template.join('');
2525
};
2626

2727
windowView.prototype.destroy = function() {

EXERCISE/Exercise 4/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
<div id="placeholder-header">
1616

1717
</div>
18-
<div id="placeholder-content"></div>
19-
<div id="placeholder-footer"></div>
18+
<div id="placeholder-Content"></div>
19+
<div id="placeholder-Footer"></div>
2020
</div>
2121

2222
<script type="text/javascript" src="app/components/events.js"></script>
2323
<script type="text/javascript" src="app/templates/templates.js"></script>
24+
<script type="text/javascript" src="app/views/base-view.js"></script>
2425
<script type="text/javascript" src="app/views/footer-view.js"></script>
2526
<script type="text/javascript" src="app/views/content-view.js"></script>
2627
<script type="text/javascript" src="app/views/window-view.js"></script>

0 commit comments

Comments
 (0)