1
+ /**
2
+ * @license
3
+ * Copyright (c) 2016 The Polymer Project Authors. All rights reserved.
4
+ * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
5
+ * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
6
+ * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
7
+ * Code distributed by Google as part of the polymer project is also
8
+ * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
9
+ */
10
+
11
+ ( function ( ) {
12
+ 'use strict' ;
13
+
14
+ // defaultPrevented is broken in IE.
15
+ // https://connect.microsoft.com/IE/feedback/details/790389/event-defaultprevented-returns-false-after-preventdefault-was-called
16
+ var workingDefaultPrevented = ( function ( ) {
17
+ var e = document . createEvent ( 'Event' ) ;
18
+ e . initEvent ( 'foo' , true , true ) ;
19
+ e . preventDefault ( ) ;
20
+ return e . defaultPrevented ;
21
+ } ) ( ) ;
22
+
23
+ if ( ! workingDefaultPrevented ) {
24
+ var origPreventDefault = Event . prototype . preventDefault ;
25
+ Event . prototype . preventDefault = function ( ) {
26
+ if ( ! this . cancelable ) {
27
+ return ;
28
+ }
29
+
30
+ origPreventDefault . call ( this ) ;
31
+
32
+ Object . defineProperty ( this , 'defaultPrevented' , {
33
+ get : function ( ) {
34
+ return true ;
35
+ } ,
36
+ configurable : true
37
+ } ) ;
38
+ } ;
39
+ }
40
+
41
+ var isIE = / T r i d e n t / . test ( navigator . userAgent ) ;
42
+
43
+ // Event constructor shim
44
+ if ( ! window . Event || isIE && ( typeof window . Event !== 'function' ) ) {
45
+ var origEvent = window . Event ;
46
+ /**
47
+ * @param {!string } inType
48
+ * @param {?(EventInit)= } params
49
+ */
50
+ window . Event = function ( inType , params ) {
51
+ params = params || { } ;
52
+ var e = document . createEvent ( 'Event' ) ;
53
+ e . initEvent ( inType , Boolean ( params . bubbles ) , Boolean ( params . cancelable ) ) ;
54
+ return e ;
55
+ } ;
56
+ if ( origEvent ) {
57
+ for ( var i in origEvent ) {
58
+ window . Event [ i ] = origEvent [ i ] ;
59
+ }
60
+ window . Event . prototype = origEvent . prototype ;
61
+ }
62
+ }
63
+
64
+ // CustomEvent constructor shim
65
+ if ( ! window . CustomEvent || isIE && ( typeof window . CustomEvent !== 'function' ) ) {
66
+ /**
67
+ * @template T
68
+ * @param {!string } inType
69
+ * @param {?(CustomEventInit<T>)= } params
70
+ */
71
+ window . CustomEvent = function ( inType , params ) {
72
+ params = params || { } ;
73
+ var e = document . createEvent ( 'CustomEvent' ) ;
74
+ e . initCustomEvent ( inType , Boolean ( params . bubbles ) , Boolean ( params . cancelable ) , params . detail ) ;
75
+ return e ;
76
+ } ;
77
+ window . CustomEvent . prototype = window . Event . prototype ;
78
+ }
79
+
80
+ if ( ! window . MouseEvent || isIE && ( typeof window . MouseEvent !== 'function' ) ) {
81
+ var origMouseEvent = window . MouseEvent ;
82
+ /**
83
+ *
84
+ * @param {!string } inType
85
+ * @param {?(MouseEventInit)= } params
86
+ */
87
+ window . MouseEvent = function ( inType , params ) {
88
+ params = params || { } ;
89
+ var e = document . createEvent ( 'MouseEvent' ) ;
90
+ e . initMouseEvent ( inType ,
91
+ Boolean ( params . bubbles ) , Boolean ( params . cancelable ) ,
92
+ params . view || window , params . detail ,
93
+ params . screenX , params . screenY , params . clientX , params . clientY ,
94
+ params . ctrlKey , params . altKey , params . shiftKey , params . metaKey ,
95
+ params . button , params . relatedTarget ) ;
96
+ return e ;
97
+ } ;
98
+ if ( origMouseEvent ) {
99
+ for ( var i in origMouseEvent ) {
100
+ window . MouseEvent [ i ] = origMouseEvent [ i ] ;
101
+ }
102
+ }
103
+ window . MouseEvent . prototype = origMouseEvent . prototype ;
104
+ }
105
+ } ) ( ) ;
0 commit comments