17
17
* specific language governing permissions and limitations
18
18
* under the License.
19
19
*
20
- */
20
+ */
21
21
22
- /* jslint sloppy:true */
23
- /* global Windows:true, setImmediate */
24
- /* eslint standard/no-callback-literal : 0 */
22
+ /* eslint-disable standard/no-callback-literal */
23
+ /* global Windows, setImmediate */
25
24
26
25
var cordova = require ( 'cordova' ) ;
27
26
var urlutil = require ( 'cordova/urlutil' ) ;
@@ -44,21 +43,32 @@ var isWebViewAvailable = cordova.platformId === 'windows';
44
43
function attachNavigationEvents ( element , callback ) {
45
44
if ( isWebViewAvailable ) {
46
45
element . addEventListener ( 'MSWebViewNavigationStarting' , function ( e ) {
47
- callback ( { type : 'loadstart' , url : e . uri } , { keepCallback : true } ) ;
46
+ callback ( { type : 'loadstart' , url : e . uri } , { keepCallback : true } ) ;
48
47
} ) ;
49
48
50
49
element . addEventListener ( 'MSWebViewNavigationCompleted' , function ( e ) {
51
50
if ( e . isSuccess ) {
52
51
callback ( { type : 'loadstop' , url : e . uri } , { keepCallback : true } ) ;
53
52
} else {
54
- callback ( { type : 'loaderror' , url : e . uri , code : e . webErrorStatus , message : 'Navigation failed with error code ' + e . webErrorStatus } , { keepCallback : true } ) ;
53
+ callback (
54
+ {
55
+ type : 'loaderror' ,
56
+ url : e . uri ,
57
+ code : e . webErrorStatus ,
58
+ message : 'Navigation failed with error code ' + e . webErrorStatus
59
+ } ,
60
+ { keepCallback : true }
61
+ ) ;
55
62
}
56
63
} ) ;
57
64
58
65
element . addEventListener ( 'MSWebViewUnviewableContentIdentified' , function ( e ) {
59
66
// WebView found the content to be not HTML.
60
67
// http://msdn.microsoft.com/en-us/library/windows/apps/dn609716.aspx
61
- callback ( { type : 'loaderror' , url : e . uri , code : e . webErrorStatus , message : 'Navigation failed with error code ' + e . webErrorStatus } , { keepCallback : true } ) ;
68
+ callback (
69
+ { type : 'loaderror' , url : e . uri , code : e . webErrorStatus , message : 'Navigation failed with error code ' + e . webErrorStatus } ,
70
+ { keepCallback : true }
71
+ ) ;
62
72
} ) ;
63
73
64
74
element . addEventListener ( 'MSWebViewContentLoading' , function ( e ) {
@@ -78,15 +88,15 @@ function attachNavigationEvents (element, callback) {
78
88
} ) ;
79
89
} else {
80
90
var onError = function ( ) {
81
- callback ( { type : 'loaderror' , url : this . contentWindow . location } , { keepCallback : true } ) ;
91
+ callback ( { type : 'loaderror' , url : this . contentWindow . location } , { keepCallback : true } ) ;
82
92
} ;
83
93
84
94
element . addEventListener ( 'unload' , function ( ) {
85
- callback ( { type : 'loadstart' , url : this . contentWindow . location } , { keepCallback : true } ) ;
95
+ callback ( { type : 'loadstart' , url : this . contentWindow . location } , { keepCallback : true } ) ;
86
96
} ) ;
87
97
88
98
element . addEventListener ( 'load' , function ( ) {
89
- callback ( { type : 'loadstop' , url : this . contentWindow . location } , { keepCallback : true } ) ;
99
+ callback ( { type : 'loadstop' , url : this . contentWindow . location } , { keepCallback : true } ) ;
90
100
} ) ;
91
101
92
102
element . addEventListener ( 'error' , onError ) ;
@@ -175,7 +185,8 @@ var IAB = {
175
185
}
176
186
177
187
popup = document . createElement ( isWebViewAvailable ? 'x-ms-webview' : 'iframe' ) ;
178
- if ( popup instanceof HTMLIFrameElement ) { // eslint-disable-line no-undef
188
+ if ( popup instanceof HTMLIFrameElement ) {
189
+ // eslint-disable-line no-undef
179
190
// For iframe we need to override bacground color of parent element here
180
191
// otherwise pages without background color set will have transparent background
181
192
popup . style . backgroundColor = 'white' ;
@@ -240,14 +251,18 @@ var IAB = {
240
251
backButton . innerText = 'back' ;
241
252
backButton . className = 'app-bar-action action-back' ;
242
253
backButton . addEventListener ( 'click' , function ( e ) {
243
- if ( popup . canGoBack ) { popup . goBack ( ) ; }
254
+ if ( popup . canGoBack ) {
255
+ popup . goBack ( ) ;
256
+ }
244
257
} ) ;
245
258
246
259
forwardButton = document . createElement ( 'div' ) ;
247
260
forwardButton . innerText = 'forward' ;
248
261
forwardButton . className = 'app-bar-action action-forward' ;
249
262
forwardButton . addEventListener ( 'click' , function ( e ) {
250
- if ( popup . canGoForward ) { popup . goForward ( ) ; }
263
+ if ( popup . canGoForward ) {
264
+ popup . goForward ( ) ;
265
+ }
251
266
} ) ;
252
267
253
268
closeButton = document . createElement ( 'div' ) ;
@@ -292,11 +307,11 @@ var IAB = {
292
307
op . oncomplete = function ( e ) {
293
308
if ( hasCallback ) {
294
309
// return null if event target is unavailable by some reason
295
- var result = ( e && e . target ) ? [ e . target . result ] : [ null ] ;
310
+ var result = e && e . target ? [ e . target . result ] : [ null ] ;
296
311
win ( result ) ;
297
312
}
298
313
} ;
299
- op . onerror = function ( ) { } ;
314
+ op . onerror = function ( ) { } ;
300
315
op . start ( ) ;
301
316
}
302
317
} ) ;
@@ -323,7 +338,7 @@ var IAB = {
323
338
win ( result ) ;
324
339
}
325
340
} ;
326
- op . onerror = function ( ) { } ;
341
+ op . onerror = function ( ) { } ;
327
342
op . start ( ) ;
328
343
} ) ;
329
344
} ) ;
@@ -352,13 +367,18 @@ var IAB = {
352
367
if ( isWebViewAvailable && browserWrap && popup ) {
353
368
// CB-12364 getFileFromApplicationUriAsync does not support ms-appx-web
354
369
var uri = new Windows . Foundation . Uri ( filePath . replace ( 'ms-appx-web:' , 'ms-appx:' ) ) ;
355
- Windows . Storage . StorageFile . getFileFromApplicationUriAsync ( uri ) . then ( function ( file ) {
356
- return Windows . Storage . FileIO . readTextAsync ( file ) ;
357
- } ) . done ( function ( code ) {
358
- injectCSS ( popup , code , hasCallback && win ) ;
359
- } , function ( ) {
360
- // no-op, just catch an error
361
- } ) ;
370
+ Windows . Storage . StorageFile . getFileFromApplicationUriAsync ( uri )
371
+ . then ( function ( file ) {
372
+ return Windows . Storage . FileIO . readTextAsync ( file ) ;
373
+ } )
374
+ . done (
375
+ function ( code ) {
376
+ injectCSS ( popup , code , hasCallback && win ) ;
377
+ } ,
378
+ function ( ) {
379
+ // no-op, just catch an error
380
+ }
381
+ ) ;
362
382
}
363
383
} ) ;
364
384
}
@@ -367,16 +387,18 @@ var IAB = {
367
387
function injectCSS ( webView , cssCode , callback ) {
368
388
// This will automatically escape all thing that we need (quotes, slashes, etc.)
369
389
var escapedCode = JSON . stringify ( cssCode ) ;
370
- var evalWrapper = '(function(d){var c=d.createElement(\'style\');c.innerHTML=%s;d.head.appendChild(c);})(document)'
371
- . replace ( '%s' , escapedCode ) ;
390
+ var evalWrapper = "(function(d){var c=d.createElement('style');c.innerHTML=%s;d.head.appendChild(c);})(document)" . replace (
391
+ '%s' ,
392
+ escapedCode
393
+ ) ;
372
394
373
395
var op = webView . invokeScriptAsync ( 'eval' , evalWrapper ) ;
374
396
op . oncomplete = function ( ) {
375
397
if ( callback ) {
376
398
callback ( [ ] ) ;
377
399
}
378
400
} ;
379
- op . onerror = function ( ) { } ;
401
+ op . onerror = function ( ) { } ;
380
402
op . start ( ) ;
381
403
}
382
404
0 commit comments