Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
4d89319b
Commit
4d89319b
authored
Jul 16, 2014
by
Randall Leeds
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1319 from hypothesis/374-sign-in-button-firefox-fix
374 sign in button firefox fix
parents
21898533
49427241
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
117 additions
and
0 deletions
+117
-0
autofill-event.js
h/lib/polyfills/autofill-event.js
+117
-0
No files found.
h/lib/polyfills/autofill-event.js
0 → 100644
View file @
4d89319b
/**
* Autofill event polyfill ##version:1.0.0##
* (c) 2014 Google, Inc.
* License: MIT
*/
(
function
(
window
)
{
var
$
=
window
.
jQuery
||
window
.
angular
.
element
;
var
rootElement
=
window
.
document
.
documentElement
,
$rootElement
=
$
(
rootElement
);
addGlobalEventListener
(
'change'
,
markValue
);
addValueChangeByJsListener
(
markValue
);
$
.
prototype
.
checkAndTriggerAutoFillEvent
=
jqCheckAndTriggerAutoFillEvent
;
// Need to use blur and not change event
// as Chrome does not fire change events in all cases an input is changed
// (e.g. when starting to type and then finish the input by auto filling a username)
addGlobalEventListener
(
'blur'
,
function
(
target
)
{
// setTimeout needed for Chrome as it fills other
// form fields a little later...
window
.
setTimeout
(
function
()
{
findParentForm
(
target
).
find
(
'input'
).
checkAndTriggerAutoFillEvent
();
},
20
);
});
window
.
document
.
addEventListener
(
'DOMContentLoaded'
,
function
()
{
// The timeout is needed for Chrome as it auto fills
// login forms some time after DOMContentLoaded!
window
.
setTimeout
(
function
()
{
$rootElement
.
find
(
'input'
).
checkAndTriggerAutoFillEvent
();
},
200
);
},
false
);
return
;
// ----------
function
jqCheckAndTriggerAutoFillEvent
()
{
var
i
,
el
;
for
(
i
=
0
;
i
<
this
.
length
;
i
++
)
{
el
=
this
[
i
];
if
(
!
valueMarked
(
el
))
{
markValue
(
el
);
triggerChangeEvent
(
el
);
}
}
}
function
valueMarked
(
el
)
{
var
val
=
el
.
value
,
$$currentValue
=
el
.
$$currentValue
;
if
(
!
val
&&
!
$$currentValue
)
{
return
true
;
}
return
val
===
$$currentValue
;
}
function
markValue
(
el
)
{
el
.
$$currentValue
=
el
.
value
;
}
function
addValueChangeByJsListener
(
listener
)
{
var
jq
=
window
.
jQuery
||
window
.
angular
.
element
,
jqProto
=
jq
.
prototype
;
var
_val
=
jqProto
.
val
;
jqProto
.
val
=
function
(
newValue
)
{
var
res
=
_val
.
apply
(
this
,
arguments
);
if
(
arguments
.
length
>
0
)
{
forEach
(
this
,
function
(
el
)
{
listener
(
el
,
newValue
);
});
}
return
res
;
}
}
function
addGlobalEventListener
(
eventName
,
listener
)
{
// Use a capturing event listener so that
// we also get the event when it's stopped!
// Also, the blur event does not bubble.
rootElement
.
addEventListener
(
eventName
,
onEvent
,
true
);
function
onEvent
(
event
)
{
var
target
=
event
.
target
;
listener
(
target
);
}
}
function
findParentForm
(
el
)
{
while
(
el
)
{
if
(
el
.
nodeName
===
'FORM'
)
{
return
$
(
el
);
}
el
=
el
.
parentNode
;
}
return
$
();
}
function
forEach
(
arr
,
listener
)
{
if
(
arr
.
forEach
)
{
return
arr
.
forEach
(
listener
);
}
var
i
;
for
(
i
=
0
;
i
<
arr
.
length
;
i
++
)
{
listener
(
arr
[
i
]);
}
}
function
triggerChangeEvent
(
element
)
{
var
doc
=
window
.
document
;
var
event
=
doc
.
createEvent
(
"HTMLEvents"
);
event
.
initEvent
(
"change"
,
true
,
true
);
element
.
dispatchEvent
(
event
);
}
})(
window
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment