Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F4292642
behavior-copy.js
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
1 KB
Referenced Files
None
Subscribers
None
behavior-copy.js
View Options
/**
* @provides javelin-behavior-phabricator-clipboard-copy
* @requires javelin-behavior
* javelin-dom
* javelin-stratcom
* phabricator-notification
* @javelin
*/
JX
.
behavior
(
'phabricator-clipboard-copy'
,
function
()
{
var
fallback_working
=
document
.
queryCommandSupported
&&
document
.
queryCommandSupported
(
'copy'
);
if
(
!
navigator
.
clipboard
&&
!
fallback_working
)
{
return
;
}
JX
.
DOM
.
alterClass
(
document
.
body
,
'supports-clipboard'
,
true
);
var
copy_fallback
=
function
(
text
)
{
var
attr
=
{
value
:
text
||
''
,
className
:
'clipboard-buffer'
};
var
node
=
JX
.
$N
(
'textarea'
,
attr
);
document
.
body
.
appendChild
(
node
);
node
.
select
();
document
.
execCommand
(
'copy'
);
JX
.
DOM
.
remove
(
node
);
};
var
show_success_message
=
function
(
message
)
{
if
(
!
message
)
{
return
;
}
new
JX
.
Notification
()
.
setContent
(
message
)
.
alterClassName
(
'jx-notification-done'
,
true
)
.
setDuration
(
8000
)
.
show
();
};
var
show_error_message
=
function
(
message
)
{
if
(
!
message
)
{
return
;
}
new
JX
.
Notification
()
.
setContent
(
message
)
.
alterClassName
(
'jx-notification-error'
,
true
)
.
setDuration
(
8000
)
.
show
();
};
JX
.
Stratcom
.
listen
(
'click'
,
'clipboard-copy'
,
function
(
e
)
{
var
data
=
e
.
getNodeData
(
'clipboard-copy'
);
var
text
=
data
.
text
||
''
;
var
copy
=
async
function
(
// jshint ignore:line
text
,
successMessage
,
errorMessage
)
{
try
{
if
(
navigator
.
clipboard
)
{
await
navigator
.
clipboard
.
writeText
(
text
);
}
else
{
copy_fallback
(
text
);
}
show_success_message
(
successMessage
);
}
catch
(
ex
)
{
show_error_message
(
errorMessage
);
}
};
e
.
kill
();
copy
(
text
,
data
.
successMessage
,
data
.
errorMessage
);
});
});
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, May 19, 04:12 (1 d, 16 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1632681
Default Alt Text
behavior-copy.js (1 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment