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
b7c95926
Commit
b7c95926
authored
Mar 30, 2016
by
Robert Knight
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3141 from hypothesis/csp-violation-form-onfocus
CSP Violation: form input onfocus
parents
a2f95b67
243e4623
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
81 additions
and
1 deletion
+81
-1
form-select-onfocus-controller.js
h/static/scripts/form-select-onfocus-controller.js
+20
-0
site.js
h/static/scripts/site.js
+16
-1
form-select-onfocus-controller-test.js
h/static/scripts/test/form-select-onfocus-controller-test.js
+45
-0
No files found.
h/static/scripts/form-select-onfocus-controller.js
0 → 100644
View file @
b7c95926
'use strict'
;
function
FormSelectOnFocusController
(
root
)
{
this
.
_elements
=
root
.
querySelectorAll
(
'.js-select-onfocus'
);
for
(
var
i
=
0
;
i
<
this
.
_elements
.
length
;
i
++
)
{
var
element
=
this
.
_elements
[
i
];
// In case the `focus` event has already been fired, select the element
if
(
element
===
document
.
activeElement
)
{
element
.
select
();
}
element
.
addEventListener
(
'focus'
,
function
(
event
)
{
event
.
target
.
select
();
});
}
}
module
.
exports
=
FormSelectOnFocusController
;
h/static/scripts/site.js
View file @
b7c95926
'use strict'
;
// configure error reporting
// configure error reporting
var
settings
=
require
(
'./settings'
)(
document
);
var
settings
=
require
(
'./settings'
)(
document
);
if
(
settings
.
raven
)
{
if
(
settings
.
raven
)
{
...
@@ -9,6 +11,7 @@ var page = require('page');
...
@@ -9,6 +11,7 @@ var page = require('page');
var
CreateGroupFormController
=
require
(
'./create-group-form'
);
var
CreateGroupFormController
=
require
(
'./create-group-form'
);
var
DropdownMenuController
=
require
(
'./dropdown-menu'
);
var
DropdownMenuController
=
require
(
'./dropdown-menu'
);
var
InstallerController
=
require
(
'./installer-controller'
);
var
InstallerController
=
require
(
'./installer-controller'
);
var
FormSelectOnFocusController
=
require
(
'./form-select-onfocus-controller'
);
// setup components
// setup components
new
DropdownMenuController
(
document
);
new
DropdownMenuController
(
document
);
...
@@ -24,6 +27,18 @@ page('/groups/new', function () {
...
@@ -24,6 +27,18 @@ page('/groups/new', function () {
new
CreateGroupFormController
(
document
.
body
);
new
CreateGroupFormController
(
document
.
body
);
});
});
page
(
'/login'
,
function
()
{
new
FormSelectOnFocusController
(
document
.
body
);
});
page
(
'/register'
,
function
()
{
new
FormSelectOnFocusController
(
document
.
body
);
});
page
(
'/forgot_password'
,
function
()
{
new
FormSelectOnFocusController
(
document
.
body
);
});
document
.
addEventListener
(
'DOMContentLoaded'
,
function
()
{
document
.
addEventListener
(
'DOMContentLoaded'
,
function
()
{
page
.
start
();
page
.
start
(
{
click
:
false
}
);
});
});
h/static/scripts/test/form-select-onfocus-controller-test.js
0 → 100644
View file @
b7c95926
'use strict'
;
var
FormSelectOnFocusController
=
require
(
'../form-select-onfocus-controller'
);
// helper to dispatch a native event to an element
function
sendEvent
(
element
,
eventType
)
{
// createEvent() used instead of Event constructor
// for PhantomJS compatibility
var
event
=
document
.
createEvent
(
'Event'
);
event
.
initEvent
(
eventType
,
true
/* bubbles */
,
true
/* cancelable */
);
element
.
dispatchEvent
(
event
);
}
describe
(
'FormSelectOnFocusController'
,
function
()
{
var
root
;
beforeEach
(
function
()
{
root
=
document
.
createElement
(
'div'
);
root
.
innerHTML
=
'<form id="js-users-delete-form">'
+
'<input type="text" class="js-select-onfocus" value="some-test-value">'
;
document
.
body
.
appendChild
(
root
);
});
afterEach
(
function
()
{
root
.
parentNode
.
removeChild
(
root
);
});
it
(
'it selects the element on focus event'
,
function
()
{
new
FormSelectOnFocusController
(
root
);
var
input
=
root
.
querySelector
(
'input'
);
sendEvent
(
input
,
'focus'
);
assert
.
strictEqual
(
input
.
selectionStart
,
0
);
assert
.
strictEqual
(
input
.
selectionEnd
,
input
.
value
.
length
);
});
it
(
'it selects the element without focus event when it is the active element'
,
function
()
{
// Focus element before instantiating the controller
var
input
=
root
.
querySelector
(
'input'
);
input
.
focus
();
new
FormSelectOnFocusController
(
document
.
body
);
assert
.
strictEqual
(
input
.
selectionStart
,
0
);
assert
.
strictEqual
(
input
.
selectionEnd
,
input
.
value
.
length
);
});
});
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