trees.js 2.4 KB

12
  1. // 小程序富文本插件 https://github.com/jin-yufeng/Parser
  2. "use strict";function _defineProperty(t,e,r){return e in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}var _extends=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(t[i]=r[i])}return t};Component({data:{canIUse:!!wx.chooseMessageFile},properties:{nodes:Array,lazyLoad:Boolean},methods:{play:function(t){if(this.top.group&&this.top.group.pause(this.top.i),this.top.videoContexts.length>1&&this.top.data.autopause)for(var e=this.top.videoContexts.length;e--;)this.top.videoContexts[e].id!=t.currentTarget.id&&this.top.videoContexts[e].pause()},imgtap:function(t){var e=t.target.dataset.attrs;if(!e.ignore){var r=!0;if(this.top.triggerEvent("imgtap",{id:t.target.id,src:e.src,ignore:function(){return r=!1}}),r){if(this.top.group)return this.top.group.preview(this.top.i,e.i);var i=this.top.imgList,a=i[e.i]?i[e.i]:(i=[e.src],e.src);wx.previewImage({current:a,urls:i})}}},linkpress:function(t){var e=!0,r=t.currentTarget.dataset.attrs;r.ignore=function(){return e=!1},this.top.triggerEvent("linkpress",r),e&&(r["app-id"]?wx.navigateToMiniProgram({appId:r["app-id"],path:r.path}):r.href&&("#"==r.href[0]?this.top.navigateTo({id:r.href.substring(1)}):0==r.href.indexOf("http")||0==r.href.indexOf("//")?wx.setClipboardData({data:r.href,success:function(){return wx.showToast({title:"链接已复制"})}}):wx.navigateTo({url:r.href})))},error:function(t){var e,r="",i=t.target.dataset.source,a=t.target.dataset.i,o=this.data.nodes[a];if("video"==i||"audio"==i){var s=(o.i||0)+1;if(s<o.attrs.source.length)return this.setData(_defineProperty({},"nodes["+a+"].i",s));this.top&&(e=this.top.getVideoContext(t.target.id))}else"img"==i&&(e={setSrc:function(t){return r=t}});if(this.top&&this.top.triggerEvent("error",_extends({source:i,target:t.target,context:e},t.detail)),"img"==i){var n=_defineProperty({},"nodes["+a+"].attrs.src",r);r||(n["nodes["+a+"].err"]=1),this.setData(n)}},loadVideo:function(t){var e,r=t.target.dataset.i;this.setData((e={},_defineProperty(e,"nodes["+r+"].lazyLoad",!1),_defineProperty(e,"nodes["+r+"].attrs.autoplay",!0),e))},loadImg:function(t){var e=t.target.dataset;e.auto&&this.setData(_defineProperty({},"nodes["+e.i+"].attrs.style",this.data.nodes[e.i].attrs.style+";width:"+t.detail.width+"px"))}}});