diff --git a/package.json b/package.json index 4ee0ed6..c511692 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "anot", - "version": "2.1.1", + "version": "2.2.0", "description": "Anot - 迷你mvvm框架", "main": "dist/anot.js", "files": ["dist"], diff --git a/src/00-generate.js b/src/00-generate.js index 23efe00..b6bb266 100644 --- a/src/00-generate.js +++ b/src/00-generate.js @@ -31,6 +31,8 @@ function createMap() { return Object.create(null) } +var encode = encodeURIComponent +var decode = decodeURIComponent var subscribers = '$' + expose var nullObject = {} //作用类似于noop,只用于代码防御,千万不要在它上面添加属性 diff --git a/src/02-core.js b/src/02-core.js index 49da09f..e6fe735 100644 --- a/src/02-core.js +++ b/src/02-core.js @@ -423,7 +423,7 @@ Anot.mix({ if ((this.type(val) == 'string' && val.trim() === '') || val === null) { document.cookie = - encodeURIComponent(key) + + encode(key) + '=; expires=Thu, 01 Jan 1970 00:00:00 GMT; domain=' + opt.domain + '; path=' + @@ -447,9 +447,9 @@ Anot.mix({ } } document.cookie = - encodeURIComponent(key) + + encode(key) + '=' + - encodeURIComponent(val) + + encode(val) + opt.expires + '; domain=' + opt.domain + @@ -463,11 +463,11 @@ Anot.mix({ return document.cookie } return ( - decodeURIComponent( + decode( document.cookie.replace( new RegExp( '(?:(?:^|.*;)\\s*' + - encodeURIComponent(key).replace(/[\-\.\+\*]/g, '\\$&') + + encode(key).replace(/[\-\.\+\*]/g, '\\$&') + '\\s*\\=\\s*([^;]*).*$)|^.*$' ), '$1' @@ -484,7 +484,7 @@ Anot.mix({ if (!key || !uri) { return null } - uri = decodeURIComponent(uri) + uri = decode(uri) uri = uri.slice(1) uri = uri.split('&') @@ -509,22 +509,11 @@ Anot.mix({ }, //复制文本到粘贴板 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 { - DOC.execCommand('copy') + navigator.clipboard.writeText(txt) } catch (err) { log('复制到粘贴板失败', err) } - DOC.body.removeChild(ta) } })