@@ -11,102 +11,119 @@ var app = app || {};
11
11
12
12
global . WindowView = {
13
13
14
+ internelMethods : [ 'destroy' , 'minimize' , 'maximize' , 'highlight' ] ,
15
+
14
16
/***
15
17
* Generic initialization method
16
18
*/
17
19
init : function ( options ) {
18
- this . template = options . template || app . templates . windowTemplate ;
19
- this . id = options . id ;
20
- this . type = options . type || 'normalized' ; //minimized or maximized
20
+ this . template = options . template || app . templates . windowTemplate ;
21
+ this . id = options . id ;
22
+ this . type = options . type || 'normalized' ; //minimized or maximized
23
+
24
+ this . bindInternalMethods ( ) ;
21
25
22
26
this . render ( ) ;
23
27
24
28
app . events . notify ( 'app:window:created' , { id : this . id } ) ;
25
-
26
29
// app.events.listen('window:' + this.id + ':render', this.render.bind(this));
27
30
} ,
28
31
32
+ bindInternalMethods : function ( ) {
33
+ var view = this ;
34
+
35
+ this . internelMethods . forEach ( function ( methodName ) {
36
+ view [ methodName ] = view [ methodName ] . bind ( view ) ;
37
+ } ) ;
38
+ } ,
39
+
29
40
/***
30
41
* Window render
31
42
*/
32
43
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 ) ;
44
+ this . wrapper = document . createElement ( 'section' ) ;
45
+ this . wrapper . className = 'window' ;
46
+ this . wrapper . innerHTML = this . template . join ( '' ) ;
47
+ app . ContentView . el . appendChild ( this . wrapper ) ;
37
48
38
- this . closeIcon = this . wrapper . querySelector ( this . selectors . closeIcon ) ;
39
- this . minimizeIcon = this . wrapper . querySelector ( this . selectors . minimizeIcon ) ;
40
- this . maximizeIcon = this . wrapper . querySelector ( this . selectors . maximizeIcon ) ;
49
+ this . closeIcon = this . wrapper . querySelector ( this . selectors . closeIcon ) ;
50
+ this . minimizeIcon = this . wrapper . querySelector ( this . selectors . minimizeIcon ) ;
51
+ this . maximizeIcon = this . wrapper . querySelector ( this . selectors . maximizeIcon ) ;
41
52
42
53
43
- this . events . on . call ( this ) ;
54
+ this . events . on . call ( this ) ;
44
55
} ,
45
56
46
57
/***
47
58
* Window destroy
48
59
*/
49
60
destroy : function ( ) {
61
+ this . events . off . call ( this ) ;
50
62
this . wrapper . parentNode . removeChild ( this . wrapper ) ;
51
63
console . log ( 'destroy' , this . template ) ;
52
64
53
65
app . events . notify ( 'app:window:destroy' , { id : this . id } ) ;
54
66
} ,
55
67
56
68
minimize : function ( ) {
57
- // this.wrapper.remove('fadeInUp');
58
- // this.wrapper.remove('animated');
69
+ this . resetView ( ) ;
59
70
60
- this . wrapper . classList . add ( 'fadeOutDown' ) ;
61
- this . wrapper . classList . add ( 'animated' ) ;
71
+ this . wrapper . classList . add ( 'fadeOutDown' ) ;
72
+ this . wrapper . classList . add ( 'animated' ) ;
62
73
63
- app . events . notify ( 'app:window:minimized' ) ;
74
+ app . events . notify ( 'app:window:minimized' ) ;
75
+ } ,
76
+
77
+ resetView : function ( ) {
78
+ var view = this ;
79
+ this . wrapper . classList . forEach ( function ( className ) {
80
+ if ( className !== 'window' ) {
81
+ view . wrapper . classList . remove ( className ) ;
82
+ }
83
+ } ) ;
64
84
} ,
65
85
66
86
popup : function ( ) {
67
- // this.wrapper.remove('fadeOutDown');
68
- // this.wrapper.remove('animated');
87
+ this . resetView ( ) ;
69
88
70
- this . wrapper . classList . add ( 'fadeInUp' ) ;
71
- this . wrapper . classList . add ( 'animated' ) ;
89
+ this . wrapper . classList . add ( 'fadeInUp' ) ;
90
+ this . wrapper . classList . add ( 'animated' ) ;
72
91
73
- app . events . notify ( 'app:window:popup' ) ;
92
+ // app.events.notify('app:window:popup');
74
93
} ,
75
94
76
95
maximize : function ( ) {
77
- if ( this . type === "maximized" ) {
78
- this . wrapper . removeAttribute ( "style" ) ;
79
- this . type = "normalized" ;
80
- app . events . notify ( 'app:window:normalized' ) ;
81
- }
82
- else {
83
- this . wrapper . style . maxWidth = "100%" ;
84
- this . wrapper . style . height = global . innerHeight - 70 + "px" ;
85
- this . type = "maximized" ;
86
- app . events . notify ( 'app:window:maximized' ) ;
87
- }
96
+ if ( this . type === "maximized" ) {
97
+ this . wrapper . removeAttribute ( "style" ) ;
98
+ this . type = "normalized" ;
99
+ app . events . notify ( 'app:window:normalized' ) ;
100
+ }
101
+ else {
102
+ this . wrapper . style . maxWidth = "100%" ;
103
+ this . wrapper . style . height = global . innerHeight - 70 + "px" ;
104
+ this . type = "maximized" ;
105
+ app . events . notify ( 'app:window:maximized' ) ;
106
+ }
88
107
} ,
89
108
90
109
highlight : function ( evnt ) {
91
- for ( var i = app . windowInstances . length - 1 ; i >= 0 ; i -- ) {
92
- if ( app . windowInstances [ i ] . id === evnt . detail . id ) {
93
- app . windowInstances [ i ] . wrapper . classList . add ( 'windowhighlight' ) ;
94
- this . popup ( ) ;
95
- }
96
- }
110
+ this . wrapper . classList . add ( 'windowhighlight' ) ;
97
111
} ,
98
112
99
113
events : {
100
114
101
115
on : function ( ) {
102
- Events . subscribe ( this . closeIcon , 'click' , this . destroy . bind ( this ) ) ;
103
- Events . subscribe ( this . minimizeIcon , 'click' , this . minimize . bind ( this ) ) ;
104
- Events . subscribe ( this . maximizeIcon , 'click' , this . maximize . bind ( this ) ) ;
105
- app . events . listen ( 'app:footericon:highlighted' , this . highlight . bind ( this ) ) ;
116
+ Events . subscribe ( this . closeIcon , 'click' , this . destroy ) ;
117
+ Events . subscribe ( this . minimizeIcon , 'click' , this . minimize ) ;
118
+ Events . subscribe ( this . maximizeIcon , 'click' , this . maximize ) ;
119
+ app . events . listen ( 'app:footericon:highlighted:' + this . id , this . highlight ) ;
106
120
} ,
107
121
108
122
off : function ( ) {
109
-
123
+ Events . unsubscribe ( this . closeIcon , 'click' , this . destroy ) ;
124
+ Events . unsubscribe ( this . minimizeIcon , 'click' , this . minimize ) ;
125
+ Events . unsubscribe ( this . maximizeIcon , 'click' , this . maximize ) ;
126
+ app . events . remove ( 'app:footericon:highlighted:' + this . id , this . highlight ) ;
110
127
}
111
128
} ,
112
129
0 commit comments