优化 icon 文档中复制功能细节

pull/1372/head
贤心 1 year ago
parent 86454a3acc
commit 66b36296e2

@ -1183,36 +1183,33 @@ toc: true
layui.use(function(){ layui.use(function(){
var $ = layui.jquery; var $ = layui.jquery;
var layer = layui.layer; var layer = layui.layer;
var lay = layui.lay;
var util = layui.util;
// click
$('.ws-docs-icon > div').on('click', function(e){
var elem = $(this);
var unicodeElem = elem.children('.docs-icon-code')
var classnameElem = elem.children('.docs-icon-fontclass')
var text = classnameElem.text();
var html = text;
$('.ws-docs-icon > div').on('click', function(){ if ($(e.target).is(unicodeElem)) {
var iconclass = $(this).find('.docs-icon-fontclass').text(); text = unicodeElem.text();
var copied = copy(iconclass); html = unicodeElem.html();
if(copied){
layer.msg('已复制 '+ iconclass, {
icon: 1,
offset: '5%',
anim: 'slideDown',
isOutAnim: false
});
} }
});
function copy(text){ lay.clipboard.writeText({
var textarea = document.createElement('textarea'); text: text,
textarea.value = text; done: function() {
textarea.style.position = 'absolute'; layer.msg('已复制 '+ html, {
textarea.style.opacity = '0'; icon: 1,
document.body.appendChild(textarea); offset: '5%',
textarea.select(); anim: 'slideDown',
var copied = false; isOutAnim: false
try{ });
copied = document.execCommand('copy'); }
}catch(err){ });
console.log('error', err); });
}
textarea.remove();
return copied;
}
}); });
</script> </script>
</textarea> </textarea>

Loading…
Cancel
Save