@@ -48,10 +48,9 @@ goog.require('wgxpath.nsResolver');
48
48
/**
49
49
* Enum for XPathResult types.
50
50
*
51
- * @private
52
51
* @enum {number}
53
52
*/
54
- wgxpath . XPathResultType_ = {
53
+ wgxpath . XPathResultType = {
55
54
ANY_TYPE : 0 ,
56
55
NUMBER_TYPE : 1 ,
57
56
STRING_TYPE : 2 ,
@@ -115,44 +114,44 @@ wgxpath.XPathExpression_ = function(expr, nsResolver) {
115
114
* @private
116
115
*/
117
116
wgxpath . XPathResult_ = function ( value , type ) {
118
- if ( type == wgxpath . XPathResultType_ . ANY_TYPE ) {
117
+ if ( type == wgxpath . XPathResultType . ANY_TYPE ) {
119
118
if ( value instanceof wgxpath . NodeSet ) {
120
- type = wgxpath . XPathResultType_ . UNORDERED_NODE_ITERATOR_TYPE ;
119
+ type = wgxpath . XPathResultType . UNORDERED_NODE_ITERATOR_TYPE ;
121
120
} else if ( typeof value == 'string' ) {
122
- type = wgxpath . XPathResultType_ . STRING_TYPE ;
121
+ type = wgxpath . XPathResultType . STRING_TYPE ;
123
122
} else if ( typeof value == 'number' ) {
124
- type = wgxpath . XPathResultType_ . NUMBER_TYPE ;
123
+ type = wgxpath . XPathResultType . NUMBER_TYPE ;
125
124
} else if ( typeof value == 'boolean' ) {
126
- type = wgxpath . XPathResultType_ . BOOLEAN_TYPE ;
125
+ type = wgxpath . XPathResultType . BOOLEAN_TYPE ;
127
126
} else {
128
127
throw Error ( 'Unexpected evaluation result.' ) ;
129
128
}
130
129
}
131
- if ( type != wgxpath . XPathResultType_ . STRING_TYPE &&
132
- type != wgxpath . XPathResultType_ . NUMBER_TYPE &&
133
- type != wgxpath . XPathResultType_ . BOOLEAN_TYPE &&
130
+ if ( type != wgxpath . XPathResultType . STRING_TYPE &&
131
+ type != wgxpath . XPathResultType . NUMBER_TYPE &&
132
+ type != wgxpath . XPathResultType . BOOLEAN_TYPE &&
134
133
! ( value instanceof wgxpath . NodeSet ) ) {
135
134
throw Error ( 'value could not be converted to the specified type' ) ;
136
135
}
137
136
this [ 'resultType' ] = type ;
138
137
var nodes ;
139
138
switch ( type ) {
140
- case wgxpath . XPathResultType_ . STRING_TYPE :
139
+ case wgxpath . XPathResultType . STRING_TYPE :
141
140
this [ 'stringValue' ] = ( value instanceof wgxpath . NodeSet ) ?
142
141
value . string ( ) : '' + value ;
143
142
break ;
144
- case wgxpath . XPathResultType_ . NUMBER_TYPE :
143
+ case wgxpath . XPathResultType . NUMBER_TYPE :
145
144
this [ 'numberValue' ] = ( value instanceof wgxpath . NodeSet ) ?
146
145
value . number ( ) : + value ;
147
146
break ;
148
- case wgxpath . XPathResultType_ . BOOLEAN_TYPE :
147
+ case wgxpath . XPathResultType . BOOLEAN_TYPE :
149
148
this [ 'booleanValue' ] = ( value instanceof wgxpath . NodeSet ) ?
150
149
value . getLength ( ) > 0 : ! ! value ;
151
150
break ;
152
- case wgxpath . XPathResultType_ . UNORDERED_NODE_ITERATOR_TYPE :
153
- case wgxpath . XPathResultType_ . ORDERED_NODE_ITERATOR_TYPE :
154
- case wgxpath . XPathResultType_ . UNORDERED_NODE_SNAPSHOT_TYPE :
155
- case wgxpath . XPathResultType_ . ORDERED_NODE_SNAPSHOT_TYPE :
151
+ case wgxpath . XPathResultType . UNORDERED_NODE_ITERATOR_TYPE :
152
+ case wgxpath . XPathResultType . ORDERED_NODE_ITERATOR_TYPE :
153
+ case wgxpath . XPathResultType . UNORDERED_NODE_SNAPSHOT_TYPE :
154
+ case wgxpath . XPathResultType . ORDERED_NODE_SNAPSHOT_TYPE :
156
155
var iter = value . iterator ( ) ;
157
156
nodes = [ ] ;
158
157
for ( var node = iter . next ( ) ; node ; node = iter . next ( ) ) {
@@ -162,8 +161,8 @@ wgxpath.XPathResult_ = function(value, type) {
162
161
this [ 'snapshotLength' ] = value . getLength ( ) ;
163
162
this [ 'invalidIteratorState' ] = false ;
164
163
break ;
165
- case wgxpath . XPathResultType_ . ANY_UNORDERED_NODE_TYPE :
166
- case wgxpath . XPathResultType_ . FIRST_ORDERED_NODE_TYPE :
164
+ case wgxpath . XPathResultType . ANY_UNORDERED_NODE_TYPE :
165
+ case wgxpath . XPathResultType . FIRST_ORDERED_NODE_TYPE :
167
166
var firstNode = value . getFirst ( ) ;
168
167
this [ 'singleNodeValue' ] =
169
168
firstNode instanceof wgxpath . IEAttrWrapper ?
@@ -174,36 +173,36 @@ wgxpath.XPathResult_ = function(value, type) {
174
173
}
175
174
var index = 0 ;
176
175
this [ 'iterateNext' ] = function ( ) {
177
- if ( type != wgxpath . XPathResultType_ . UNORDERED_NODE_ITERATOR_TYPE &&
178
- type != wgxpath . XPathResultType_ . ORDERED_NODE_ITERATOR_TYPE ) {
176
+ if ( type != wgxpath . XPathResultType . UNORDERED_NODE_ITERATOR_TYPE &&
177
+ type != wgxpath . XPathResultType . ORDERED_NODE_ITERATOR_TYPE ) {
179
178
throw Error ( 'iterateNext called with wrong result type' ) ;
180
179
}
181
180
return ( index >= nodes . length ) ? null : nodes [ index ++ ] ;
182
181
} ;
183
182
this [ 'snapshotItem' ] = function ( i ) {
184
- if ( type != wgxpath . XPathResultType_ . UNORDERED_NODE_SNAPSHOT_TYPE &&
185
- type != wgxpath . XPathResultType_ . ORDERED_NODE_SNAPSHOT_TYPE ) {
183
+ if ( type != wgxpath . XPathResultType . UNORDERED_NODE_SNAPSHOT_TYPE &&
184
+ type != wgxpath . XPathResultType . ORDERED_NODE_SNAPSHOT_TYPE ) {
186
185
throw Error ( 'snapshotItem called with wrong result type' ) ;
187
186
}
188
187
return ( i >= nodes . length || i < 0 ) ? null : nodes [ i ] ;
189
188
} ;
190
189
} ;
191
- wgxpath . XPathResult_ [ 'ANY_TYPE' ] = wgxpath . XPathResultType_ . ANY_TYPE ;
192
- wgxpath . XPathResult_ [ 'NUMBER_TYPE' ] = wgxpath . XPathResultType_ . NUMBER_TYPE ;
193
- wgxpath . XPathResult_ [ 'STRING_TYPE' ] = wgxpath . XPathResultType_ . STRING_TYPE ;
194
- wgxpath . XPathResult_ [ 'BOOLEAN_TYPE' ] = wgxpath . XPathResultType_ . BOOLEAN_TYPE ;
190
+ wgxpath . XPathResult_ [ 'ANY_TYPE' ] = wgxpath . XPathResultType . ANY_TYPE ;
191
+ wgxpath . XPathResult_ [ 'NUMBER_TYPE' ] = wgxpath . XPathResultType . NUMBER_TYPE ;
192
+ wgxpath . XPathResult_ [ 'STRING_TYPE' ] = wgxpath . XPathResultType . STRING_TYPE ;
193
+ wgxpath . XPathResult_ [ 'BOOLEAN_TYPE' ] = wgxpath . XPathResultType . BOOLEAN_TYPE ;
195
194
wgxpath . XPathResult_ [ 'UNORDERED_NODE_ITERATOR_TYPE' ] =
196
- wgxpath . XPathResultType_ . UNORDERED_NODE_ITERATOR_TYPE ;
195
+ wgxpath . XPathResultType . UNORDERED_NODE_ITERATOR_TYPE ;
197
196
wgxpath . XPathResult_ [ 'ORDERED_NODE_ITERATOR_TYPE' ] =
198
- wgxpath . XPathResultType_ . ORDERED_NODE_ITERATOR_TYPE ;
197
+ wgxpath . XPathResultType . ORDERED_NODE_ITERATOR_TYPE ;
199
198
wgxpath . XPathResult_ [ 'UNORDERED_NODE_SNAPSHOT_TYPE' ] =
200
- wgxpath . XPathResultType_ . UNORDERED_NODE_SNAPSHOT_TYPE ;
199
+ wgxpath . XPathResultType . UNORDERED_NODE_SNAPSHOT_TYPE ;
201
200
wgxpath . XPathResult_ [ 'ORDERED_NODE_SNAPSHOT_TYPE' ] =
202
- wgxpath . XPathResultType_ . ORDERED_NODE_SNAPSHOT_TYPE ;
201
+ wgxpath . XPathResultType . ORDERED_NODE_SNAPSHOT_TYPE ;
203
202
wgxpath . XPathResult_ [ 'ANY_UNORDERED_NODE_TYPE' ] =
204
- wgxpath . XPathResultType_ . ANY_UNORDERED_NODE_TYPE ;
203
+ wgxpath . XPathResultType . ANY_UNORDERED_NODE_TYPE ;
205
204
wgxpath . XPathResult_ [ 'FIRST_ORDERED_NODE_TYPE' ] =
206
- wgxpath . XPathResultType_ . FIRST_ORDERED_NODE_TYPE ;
205
+ wgxpath . XPathResultType . FIRST_ORDERED_NODE_TYPE ;
207
206
208
207
209
208
@@ -230,7 +229,7 @@ wgxpath.XPathNSResolver_ = function(node) {
230
229
*/
231
230
wgxpath . install = function ( opt_win , opt_force ) {
232
231
var win = opt_win || goog . global ;
233
- var doc = win . document ;
232
+ var doc = ( win . Document && win . Document . prototype ) || win . document ;
234
233
235
234
// Unless opt_force is true, installation is a noop if native XPath is
236
235
// available.
0 commit comments