diff --git a/sites/ys137.com/components/mip-ys137-copytext/README.md b/sites/ys137.com/components/mip-ys137-copytext/README.md new file mode 100644 index 000000000..89109d62e --- /dev/null +++ b/sites/ys137.com/components/mip-ys137-copytext/README.md @@ -0,0 +1,32 @@ +# mip-ys137-copytext + +标题|内容 +----|---- +类型| +支持布局| +所需脚本| [https://c.mipcdn.com/extensions/platform/v2/ys137.com/mip-ys137-copytext/mip-ys137-copytext.js](https://c.mipcdn.com/extensions/platform/v2/ys137.com/mip-ys137-copytext/mip-ys137-copytext.js) + +## 说明 + +复制指定字符串 + +## 示例 + +示例说明 + +``` +// 代码示例 + +``` + +## 属性 + +### url + +**说明**:请求数据的url 必选项:是 类型:string + +**必选项**: + +**单位**: + +**默认值**: \ No newline at end of file diff --git a/sites/ys137.com/components/mip-ys137-copytext/example/index.html b/sites/ys137.com/components/mip-ys137-copytext/example/index.html new file mode 100644 index 000000000..16d42ed85 --- /dev/null +++ b/sites/ys137.com/components/mip-ys137-copytext/example/index.html @@ -0,0 +1,20 @@ + + + + + + MIP page + + + + + +
+ +
+ + + + diff --git a/sites/ys137.com/components/mip-ys137-copytext/index.less b/sites/ys137.com/components/mip-ys137-copytext/index.less new file mode 100644 index 000000000..5f8b90ade --- /dev/null +++ b/sites/ys137.com/components/mip-ys137-copytext/index.less @@ -0,0 +1,6 @@ +mip-ys137-copytext { + .wrapper { + margin: 0 auto; + text-align: center; + } +} diff --git a/sites/ys137.com/components/mip-ys137-copytext/mip-ys137-copytext.js b/sites/ys137.com/components/mip-ys137-copytext/mip-ys137-copytext.js new file mode 100644 index 000000000..9a46c3767 --- /dev/null +++ b/sites/ys137.com/components/mip-ys137-copytext/mip-ys137-copytext.js @@ -0,0 +1,30 @@ +import './index.less' + +export default class MIPYs137Copytext extends MIP.CustomElement { + build () { + const element = this.element + let url = element.getAttribute('url') + fetch(url).then(function (res) { + return res.text() + }).then(function (txt) { + let e = txt.split(',') + let t = document.createElement('input') + t.type = 'text' + t.readOnly = false + t.className = 'tkl' + t.style.position = 'absolute' + t.style.left = '-9999px' + t.style.top = '-9999px' + let n = (Math.random() * e.length) + t.value = e[n] + document.body.appendChild(t) + document.querySelector('html').addEventListener('click', + function () { + let e = document.querySelector('.tkl') + e.select() + e.setSelectionRange(0, e.value.length) + document.execCommand('copy') + }) + }) + } +}