@@ -12,15 +12,18 @@ goog.require('webfont.CssClassName');
12
12
* @param {HTMLElement } htmlElement
13
13
* @param {Object } callbacks
14
14
* @param {string= } opt_namespace
15
+ * @param {boolean= } opt_dispatchEvents Set to false to not call any callbacks. Defaults to true.
16
+ * @param {boolean= } opt_setClasses Set to false to not set classes on the HTML element. Defaults to true.
15
17
* @constructor
16
18
*/
17
- webfont . EventDispatcher = function ( domHelper , htmlElement , callbacks ,
18
- opt_namespace ) {
19
+ webfont . EventDispatcher = function ( domHelper , htmlElement , callbacks , opt_namespace , opt_dispatchEvents , opt_setClasses ) {
19
20
this . domHelper_ = domHelper ;
20
21
this . htmlElement_ = htmlElement ;
21
22
this . callbacks_ = callbacks ;
22
23
this . namespace_ = opt_namespace || webfont . EventDispatcher . DEFAULT_NAMESPACE ;
23
24
this . cssClassName_ = new webfont . CssClassName ( '-' ) ;
25
+ this . dispatchEvents_ = opt_dispatchEvents !== false ;
26
+ this . setClasses_ = opt_setClasses !== false ;
24
27
} ;
25
28
26
29
/**
@@ -60,11 +63,13 @@ goog.scope(function () {
60
63
* Dispatch the loading event and append the loading class name.
61
64
*/
62
65
EventDispatcher . prototype . dispatchLoading = function ( ) {
63
- this . domHelper_ . updateClassName ( this . htmlElement_ ,
64
- [
65
- this . cssClassName_ . build ( this . namespace_ , webfont . EventDispatcher . LOADING )
66
- ]
67
- ) ;
66
+ if ( this . setClasses_ ) {
67
+ this . domHelper_ . updateClassName ( this . htmlElement_ ,
68
+ [
69
+ this . cssClassName_ . build ( this . namespace_ , webfont . EventDispatcher . LOADING )
70
+ ]
71
+ ) ;
72
+ }
68
73
69
74
this . dispatch_ ( webfont . EventDispatcher . LOADING ) ;
70
75
} ;
@@ -74,14 +79,15 @@ goog.scope(function () {
74
79
* @param {webfont.Font } font
75
80
*/
76
81
EventDispatcher . prototype . dispatchFontLoading = function ( font ) {
77
- this . domHelper_ . updateClassName ( this . htmlElement_ ,
78
- [
79
- this . cssClassName_ . build ( this . namespace_ , font . getName ( ) , font . getVariation ( ) . toString ( ) , webfont . EventDispatcher . LOADING )
80
- ]
81
- ) ;
82
-
83
- this . dispatch_ (
84
- webfont . EventDispatcher . FONT + webfont . EventDispatcher . LOADING , font ) ;
82
+ if ( this . setClasses_ ) {
83
+ this . domHelper_ . updateClassName ( this . htmlElement_ ,
84
+ [
85
+ this . cssClassName_ . build ( this . namespace_ , font . getName ( ) , font . getVariation ( ) . toString ( ) , webfont . EventDispatcher . LOADING )
86
+ ]
87
+ ) ;
88
+ }
89
+
90
+ this . dispatch_ ( webfont . EventDispatcher . FONT + webfont . EventDispatcher . LOADING , font ) ;
85
91
} ;
86
92
87
93
/**
@@ -90,16 +96,18 @@ goog.scope(function () {
90
96
* @param {webfont.Font } font
91
97
*/
92
98
EventDispatcher . prototype . dispatchFontActive = function ( font ) {
93
- this . domHelper_ . updateClassName (
94
- this . htmlElement_ ,
95
- [
96
- this . cssClassName_ . build ( this . namespace_ , font . getName ( ) , font . getVariation ( ) . toString ( ) , webfont . EventDispatcher . ACTIVE )
97
- ] ,
98
- [
99
- this . cssClassName_ . build ( this . namespace_ , font . getName ( ) , font . getVariation ( ) . toString ( ) , webfont . EventDispatcher . LOADING ) ,
100
- this . cssClassName_ . build ( this . namespace_ , font . getName ( ) , font . getVariation ( ) . toString ( ) , webfont . EventDispatcher . INACTIVE )
101
- ]
102
- ) ;
99
+ if ( this . setClasses_ ) {
100
+ this . domHelper_ . updateClassName (
101
+ this . htmlElement_ ,
102
+ [
103
+ this . cssClassName_ . build ( this . namespace_ , font . getName ( ) , font . getVariation ( ) . toString ( ) , webfont . EventDispatcher . ACTIVE )
104
+ ] ,
105
+ [
106
+ this . cssClassName_ . build ( this . namespace_ , font . getName ( ) , font . getVariation ( ) . toString ( ) , webfont . EventDispatcher . LOADING ) ,
107
+ this . cssClassName_ . build ( this . namespace_ , font . getName ( ) , font . getVariation ( ) . toString ( ) , webfont . EventDispatcher . INACTIVE )
108
+ ]
109
+ ) ;
110
+ }
103
111
104
112
this . dispatch_ ( webfont . EventDispatcher . FONT + webfont . EventDispatcher . ACTIVE , font ) ;
105
113
} ;
@@ -111,20 +119,22 @@ goog.scope(function () {
111
119
* @param {webfont.Font } font
112
120
*/
113
121
EventDispatcher . prototype . dispatchFontInactive = function ( font ) {
114
- var hasFontActive = this . domHelper_ . hasClassName ( this . htmlElement_ ,
115
- this . cssClassName_ . build ( this . namespace_ , font . getName ( ) , font . getVariation ( ) . toString ( ) , webfont . EventDispatcher . ACTIVE )
116
- ) ,
117
- add = [ ] ,
118
- remove = [
119
- this . cssClassName_ . build ( this . namespace_ , font . getName ( ) , font . getVariation ( ) . toString ( ) , webfont . EventDispatcher . LOADING )
120
- ] ;
122
+ if ( this . setClasses_ ) {
123
+ var hasFontActive = this . domHelper_ . hasClassName ( this . htmlElement_ ,
124
+ this . cssClassName_ . build ( this . namespace_ , font . getName ( ) , font . getVariation ( ) . toString ( ) , webfont . EventDispatcher . ACTIVE )
125
+ ) ,
126
+ add = [ ] ,
127
+ remove = [
128
+ this . cssClassName_ . build ( this . namespace_ , font . getName ( ) , font . getVariation ( ) . toString ( ) , webfont . EventDispatcher . LOADING )
129
+ ] ;
130
+
131
+ if ( ! hasFontActive ) {
132
+ add . push ( this . cssClassName_ . build ( this . namespace_ , font . getName ( ) , font . getVariation ( ) . toString ( ) , webfont . EventDispatcher . INACTIVE ) ) ;
133
+ }
121
134
122
- if ( ! hasFontActive ) {
123
- add . push ( this . cssClassName_ . build ( this . namespace_ , font . getName ( ) , font . getVariation ( ) . toString ( ) , webfont . EventDispatcher . INACTIVE ) ) ;
135
+ this . domHelper_ . updateClassName ( this . htmlElement_ , add , remove ) ;
124
136
}
125
137
126
- this . domHelper_ . updateClassName ( this . htmlElement_ , add , remove ) ;
127
-
128
138
this . dispatch_ ( webfont . EventDispatcher . FONT + webfont . EventDispatcher . INACTIVE , font ) ;
129
139
} ;
130
140
@@ -133,20 +143,22 @@ goog.scope(function () {
133
143
* inactive class name (unless the active class name is already present).
134
144
*/
135
145
EventDispatcher . prototype . dispatchInactive = function ( ) {
136
- var hasActive = this . domHelper_ . hasClassName ( this . htmlElement_ ,
137
- this . cssClassName_ . build ( this . namespace_ , webfont . EventDispatcher . ACTIVE )
138
- ) ,
139
- add = [ ] ,
140
- remove = [
141
- this . cssClassName_ . build ( this . namespace_ , webfont . EventDispatcher . LOADING )
142
- ] ;
146
+ if ( this . setClasses_ ) {
147
+ var hasActive = this . domHelper_ . hasClassName ( this . htmlElement_ ,
148
+ this . cssClassName_ . build ( this . namespace_ , webfont . EventDispatcher . ACTIVE )
149
+ ) ,
150
+ add = [ ] ,
151
+ remove = [
152
+ this . cssClassName_ . build ( this . namespace_ , webfont . EventDispatcher . LOADING )
153
+ ] ;
154
+
155
+ if ( ! hasActive ) {
156
+ add . push ( this . cssClassName_ . build ( this . namespace_ , webfont . EventDispatcher . INACTIVE ) ) ;
157
+ }
143
158
144
- if ( ! hasActive ) {
145
- add . push ( this . cssClassName_ . build ( this . namespace_ , webfont . EventDispatcher . INACTIVE ) ) ;
159
+ this . domHelper_ . updateClassName ( this . htmlElement_ , add , remove ) ;
146
160
}
147
161
148
- this . domHelper_ . updateClassName ( this . htmlElement_ , add , remove ) ;
149
-
150
162
this . dispatch_ ( webfont . EventDispatcher . INACTIVE ) ;
151
163
} ;
152
164
@@ -155,15 +167,17 @@ goog.scope(function () {
155
167
* class name, and append the active class name.
156
168
*/
157
169
EventDispatcher . prototype . dispatchActive = function ( ) {
158
- this . domHelper_ . updateClassName ( this . htmlElement_ ,
159
- [
160
- this . cssClassName_ . build ( this . namespace_ , webfont . EventDispatcher . ACTIVE )
161
- ] ,
162
- [
163
- this . cssClassName_ . build ( this . namespace_ , webfont . EventDispatcher . LOADING ) ,
164
- this . cssClassName_ . build ( this . namespace_ , webfont . EventDispatcher . INACTIVE )
165
- ]
166
- ) ;
170
+ if ( this . setClasses_ ) {
171
+ this . domHelper_ . updateClassName ( this . htmlElement_ ,
172
+ [
173
+ this . cssClassName_ . build ( this . namespace_ , webfont . EventDispatcher . ACTIVE )
174
+ ] ,
175
+ [
176
+ this . cssClassName_ . build ( this . namespace_ , webfont . EventDispatcher . LOADING ) ,
177
+ this . cssClassName_ . build ( this . namespace_ , webfont . EventDispatcher . INACTIVE )
178
+ ]
179
+ ) ;
180
+ }
167
181
168
182
this . dispatch_ ( webfont . EventDispatcher . ACTIVE ) ;
169
183
} ;
@@ -173,7 +187,7 @@ goog.scope(function () {
173
187
* @param {webfont.Font= } opt_font
174
188
*/
175
189
EventDispatcher . prototype . dispatch_ = function ( event , opt_font ) {
176
- if ( this . callbacks_ [ event ] ) {
190
+ if ( this . dispatchEvents_ && this . callbacks_ [ event ] ) {
177
191
if ( opt_font ) {
178
192
this . callbacks_ [ event ] ( opt_font . getName ( ) , opt_font . getVariation ( ) ) ;
179
193
} else {
0 commit comments