Page Menu
Home
GnuPG
Search
Configure Global Search
Log In
Files
F35860121
behavior-form.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Size
1 KB
Subscribers
None
behavior-form.js
View Options
/**
* @requires javelin-behavior javelin-stratcom javelin-dom
* @provides javelin-behavior-aphront-form-disable-on-submit
*/
JX
.
behavior
(
'aphront-form-disable-on-submit'
,
function
(
config
)
{
var
restore
=
[];
var
root
=
null
;
var
new_tab
=
false
;
JX
.
Stratcom
.
listen
(
'click'
,
'tag:button'
,
function
(
e
)
{
var
raw
=
e
.
getRawEvent
();
new_tab
=
(
raw
.
altKey
||
raw
.
ctrlKey
||
raw
.
metaKey
||
raw
.
shiftKey
);
});
JX
.
Stratcom
.
listen
(
'submit'
,
'tag:form'
,
function
(
e
)
{
if
(
e
.
getNode
(
'workflow'
))
{
// Don't activate for forms with workflow, the workflow behavior will
// handle it.
return
;
}
root
=
e
.
getNode
(
'tag:form'
);
// Open the form to a new tab in Firefox explicitly (automatic in Chrome).
// We render some buttons as links so users may be confused that the links
// don't open to new tabs with Ctrl+click as normal links.
root
.
target
=
(
new_tab
?
'_blank'
:
''
);
if
(
new_tab
)
{
return
;
}
if
(
root
.
_disabled
)
{
e
.
kill
();
}
root
.
_disabled
=
true
;
var
buttons
=
JX
.
DOM
.
scry
(
root
,
'button'
);
for
(
var
ii
=
0
;
ii
<
buttons
.
length
;
ii
++
)
{
if
(
!
buttons
[
ii
].
disabled
)
{
buttons
[
ii
].
disabled
=
'disabled'
;
JX
.
DOM
.
alterClass
(
buttons
[
ii
],
'disabled'
,
true
);
restore
.
push
(
buttons
[
ii
]);
}
}
});
JX
.
Stratcom
.
listen
(
'unload'
,
null
,
function
(
e
)
{
// Reenable everything on page unload so we don't bfcache back to a page
// that has disabled forms.
for
(
var
ii
=
0
;
ii
<
restore
.
length
;
ii
++
)
{
restore
[
ii
].
disabled
=
''
;
JX
.
DOM
.
alterClass
(
restore
[
ii
],
'disabled'
,
false
);
root
.
_disabled
=
false
;
}
if
(
root
)
{
delete
root
.
_disabled
;
}
restore
=
[];
root
=
null
;
});
});
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Feb 15, 3:45 PM (14 h, 16 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
3d/08/d97c67807714c07b50580347a4bd
Attached To
rPHAB Phabricator
Event Timeline
Log In to Comment