Browse Source

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

pull/1372/head
贤心 1 year ago
parent
commit
66b36296e2
  1. 41
      docs/icon/index.md

41
docs/icon/index.md

@ -1183,12 +1183,25 @@ 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, {
lay.clipboard.writeText({
text: text,
done: function() {
layer.msg('已复制 '+ html, {
icon: 1, icon: 1,
offset: '5%', offset: '5%',
anim: 'slideDown', anim: 'slideDown',
@ -1196,23 +1209,7 @@ toc: true
}); });
} }
}); });
});
function copy(text){
var textarea = document.createElement('textarea');
textarea.value = text;
textarea.style.position = 'absolute';
textarea.style.opacity = '0';
document.body.appendChild(textarea);
textarea.select();
var copied = false;
try{
copied = document.execCommand('copy');
}catch(err){
console.log('error', err);
}
textarea.remove();
return copied;
}
}); });
</script> </script>
</textarea> </textarea>

Loading…
Cancel
Save