This repository has been archived on 2023-08-29. You can view files and clone it, but cannot push or open issues/pull-requests.
yutent
/
anot.js
Archived
1
0
Fork 0

剪切板的操作更新为调用navigator的API

master
宇天 2019-09-02 21:01:31 +08:00
parent 9d790d087a
commit fe1fd505ed
3 changed files with 10 additions and 19 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "anot", "name": "anot",
"version": "2.1.1", "version": "2.2.0",
"description": "Anot - 迷你mvvm框架", "description": "Anot - 迷你mvvm框架",
"main": "dist/anot.js", "main": "dist/anot.js",
"files": ["dist"], "files": ["dist"],

View File

@ -31,6 +31,8 @@ function createMap() {
return Object.create(null) return Object.create(null)
} }
var encode = encodeURIComponent
var decode = decodeURIComponent
var subscribers = '$' + expose var subscribers = '$' + expose
var nullObject = {} //作用类似于noop只用于代码防御千万不要在它上面添加属性 var nullObject = {} //作用类似于noop只用于代码防御千万不要在它上面添加属性

View File

@ -423,7 +423,7 @@ Anot.mix({
if ((this.type(val) == 'string' && val.trim() === '') || val === null) { if ((this.type(val) == 'string' && val.trim() === '') || val === null) {
document.cookie = document.cookie =
encodeURIComponent(key) + encode(key) +
'=; expires=Thu, 01 Jan 1970 00:00:00 GMT; domain=' + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT; domain=' +
opt.domain + opt.domain +
'; path=' + '; path=' +
@ -447,9 +447,9 @@ Anot.mix({
} }
} }
document.cookie = document.cookie =
encodeURIComponent(key) + encode(key) +
'=' + '=' +
encodeURIComponent(val) + encode(val) +
opt.expires + opt.expires +
'; domain=' + '; domain=' +
opt.domain + opt.domain +
@ -463,11 +463,11 @@ Anot.mix({
return document.cookie return document.cookie
} }
return ( return (
decodeURIComponent( decode(
document.cookie.replace( document.cookie.replace(
new RegExp( new RegExp(
'(?:(?:^|.*;)\\s*' + '(?:(?:^|.*;)\\s*' +
encodeURIComponent(key).replace(/[\-\.\+\*]/g, '\\$&') + encode(key).replace(/[\-\.\+\*]/g, '\\$&') +
'\\s*\\=\\s*([^;]*).*$)|^.*$' '\\s*\\=\\s*([^;]*).*$)|^.*$'
), ),
'$1' '$1'
@ -484,7 +484,7 @@ Anot.mix({
if (!key || !uri) { if (!key || !uri) {
return null return null
} }
uri = decodeURIComponent(uri) uri = decode(uri)
uri = uri.slice(1) uri = uri.slice(1)
uri = uri.split('&') uri = uri.split('&')
@ -509,22 +509,11 @@ Anot.mix({
}, },
//复制文本到粘贴板 //复制文本到粘贴板
copy: function(txt) { copy: function(txt) {
if (!DOC.queryCommandSupported || !DOC.queryCommandSupported('copy')) {
return log('该浏览器不支持复制到粘贴板')
}
let ta = DOC.createElement('textarea')
ta.textContent = txt
ta.style.position = 'fixed'
ta.style.bottom = '-1000px'
DOC.body.appendChild(ta)
ta.select()
try { try {
DOC.execCommand('copy') navigator.clipboard.writeText(txt)
} catch (err) { } catch (err) {
log('复制到粘贴板失败', err) log('复制到粘贴板失败', err)
} }
DOC.body.removeChild(ta)
} }
}) })