diff --git a/src/mip-showmore/mip-showmore.js b/src/mip-showmore/mip-showmore.js index dc39d84cd..4a299faa2 100755 --- a/src/mip-showmore/mip-showmore.js +++ b/src/mip-showmore/mip-showmore.js @@ -10,6 +10,18 @@ define(function (require) { var viewport = require('viewport'); var timeoutArray = []; + // 匹配节点是否在按钮中 + function matchOriginTarget (id, node) { + while (node.parentNode) { + var attr = node.getAttribute('on'); + if (attr && attr.indexOf('tap:' + id) === 0) { + return node; + } + node = node.parentNode; + } + return node; + } + /** * define a showmore class based on * @@ -202,7 +214,7 @@ define(function (require) { Showmore.prototype.toggle = function (event) { var me = this; var classList = this.ele.classList; - var clickBtn = event ? event.target : null; + var clickBtn = matchOriginTarget(this.ele.id.trim(), event.target); var opt = {}; opt.aniTime = this.animateTime; if (this.showType === this.heightType[2]) { @@ -279,12 +291,15 @@ define(function (require) { if (!status) { return; } - var openStyle = clickBtn.dataset.closestyle; + var closeclass = clickBtn.dataset.closeclass; if (status === 'showOpen') { // v1.1.0 显示“展开”按钮 if (clickBtn) { - clickBtn.innerText = clickBtn.dataset.opentext; - openStyle && clickBtn.classList.remove(openStyle); + if (closeclass) { + clickBtn.classList.remove(closeclass); + } else { + clickBtn.innerText = clickBtn.dataset.opentext; + } } // v1.0.0 显示“展开”按钮 this._changeBtnText({ @@ -296,12 +311,14 @@ define(function (require) { else { // v1.1.0显示“收起”按钮 if (clickBtn) { - var opentext = clickBtn.innerText; - clickBtn.innerText = clickBtn.dataset.closetext || '收起'; - clickBtn.dataset.opentext = opentext; - openStyle && clickBtn.classList.add(openStyle); + if (closeclass) { + clickBtn.classList.add(closeclass) + } else { + var opentext = clickBtn.innerText; + clickBtn.innerText = clickBtn.dataset.closetext || '收起'; + clickBtn.dataset.opentext = opentext; + } } - // v1.0.0 显示“收起”按钮 this._changeBtnText({ display: 'none' @@ -502,4 +519,4 @@ define(function (require) { return customElement; -}); +}); \ No newline at end of file diff --git a/src/mip-showmore/package.json b/src/mip-showmore/package.json index 0e993f214..24604e726 100755 --- a/src/mip-showmore/package.json +++ b/src/mip-showmore/package.json @@ -1,6 +1,6 @@ { "name": "mip-showmore", - "version": "1.1.5", + "version": "1.1.6", "description": "mip点击显示更多组件:新增加按屏折叠,折叠边界渐变", "contributors": [ {