copy_id
This commit is contained in:
parent
180cbaeb70
commit
37e0e9cc51
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var copy_index = 0;
|
||||||
|
|
||||||
hexo.extend.tag.register('copy', function(args) {
|
hexo.extend.tag.register('copy', function(args) {
|
||||||
args = hexo.args.map(args, ['width', 'git'], ['text']);
|
args = hexo.args.map(args, ['width', 'git'], ['text']);
|
||||||
if (args == undefined || args.text == undefined) {
|
if (args == undefined || args.text == undefined) {
|
||||||
|
@ -27,9 +29,8 @@ hexo.extend.tag.register('copy', function(args) {
|
||||||
text = 'https://github.com/' + text + '.git';
|
text = 'https://github.com/' + text + '.git';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
function generate_id(text) {
|
|
||||||
return 'copy-' + text.replace(/[^a-z|0-9|.:]/gi, '')
|
const copy_id = 'copy-' + ++copy_index + '-' + text.replace(/[^a-z|0-9|.:]/gi, '');
|
||||||
}
|
|
||||||
|
|
||||||
var el = '';
|
var el = '';
|
||||||
el += '<div class="tag-plugin copy"';
|
el += '<div class="tag-plugin copy"';
|
||||||
|
@ -37,10 +38,9 @@ hexo.extend.tag.register('copy', function(args) {
|
||||||
el += ' width="' + args.width + '"';
|
el += ' width="' + args.width + '"';
|
||||||
}
|
}
|
||||||
el += '>';
|
el += '>';
|
||||||
|
el += '<input class="copy-area" readonly id="' + copy_id + '"';
|
||||||
el += '<input class="copy-area" readonly id="' + generate_id(text) + '"';
|
|
||||||
el += ' value="' + text + '">';
|
el += ' value="' + text + '">';
|
||||||
el += '<button class="copy-btn" onclick="util.copy("' + generate_id(text) + '","Copied!")">';
|
el += '<button class="copy-btn" onclick="util.copy("' + copy_id + '","Copied!")">';
|
||||||
el += '<svg class="icon copy-btn" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M5.75 1a.75.75 0 00-.75.75v3c0 .414.336.75.75.75h4.5a.75.75 0 00.75-.75v-3a.75.75 0 00-.75-.75h-4.5zm.75 3V2.5h3V4h-3zm-2.874-.467a.75.75 0 00-.752-1.298A1.75 1.75 0 002 3.75v9.5c0 .966.784 1.75 1.75 1.75h8.5A1.75 1.75 0 0014 13.25v-9.5a1.75 1.75 0 00-.874-1.515.75.75 0 10-.752 1.298.25.25 0 01.126.217v9.5a.25.25 0 01-.25.25h-8.5a.25.25 0 01-.25-.25v-9.5a.25.25 0 01.126-.217z"></path></svg>';
|
el += '<svg class="icon copy-btn" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M5.75 1a.75.75 0 00-.75.75v3c0 .414.336.75.75.75h4.5a.75.75 0 00.75-.75v-3a.75.75 0 00-.75-.75h-4.5zm.75 3V2.5h3V4h-3zm-2.874-.467a.75.75 0 00-.752-1.298A1.75 1.75 0 002 3.75v9.5c0 .966.784 1.75 1.75 1.75h8.5A1.75 1.75 0 0014 13.25v-9.5a1.75 1.75 0 00-.874-1.515.75.75 0 10-.752 1.298.25.25 0 01.126.217v9.5a.25.25 0 01-.25.25h-8.5a.25.25 0 01-.25-.25v-9.5a.25.25 0 01.126-.217z"></path></svg>';
|
||||||
el += '</button>';
|
el += '</button>';
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue