From fe1fd505ed98ca03cd47f24b6e314a836fe02721 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Mon, 2 Sep 2019 21:01:31 +0800 Subject: [PATCH] =?UTF-8?q?=E5=89=AA=E5=88=87=E6=9D=BF=E7=9A=84=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E6=9B=B4=E6=96=B0=E4=B8=BA=E8=B0=83=E7=94=A8navigator?= =?UTF-8?q?=E7=9A=84API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 2 +- src/00-generate.js | 2 ++ src/02-core.js | 25 +++++++------------------ 3 files changed, 10 insertions(+), 19 deletions(-) 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) } })