|
18 | 18 | </template> |
19 | 19 |
|
20 | 20 | <script> |
| 21 | + var search; |
21 | 22 | // #ifndef H5 || APP-PLUS-NVUE || MP-360 |
22 | 23 | import trees from './libs/trees'; |
23 | 24 | var cache = {}, |
|
66 | 67 | * @event {Function} imgtap 图片点击事件 |
67 | 68 | * @event {Function} linkpress 链接点击事件 |
68 | 69 | * @author JinYufeng |
69 | | - * @version 20201014 |
| 70 | + * @version 20201029 |
70 | 71 | * @listens MIT |
71 | 72 | */ |
72 | 73 | export default { |
|
173 | 174 | // #ifndef H5 || APP-PLUS-NVUE || MP-360 |
174 | 175 | if (dom) this.document = new dom(this); |
175 | 176 | // #endif |
| 177 | + if (search) this.search = args => search(this, args); |
176 | 178 | // #ifdef APP-PLUS-NVUE |
177 | 179 | this.document = this.$refs.web; |
178 | 180 | setTimeout(() => { |
|
225 | 227 | this.$refs.web.evalJs( |
226 | 228 | 'var t=document.getElementsByTagName("title");t.length&&e({action:"getTitle",title:t[0].innerText});for(var o,n=document.getElementsByTagName("style"),r=1;o=n[r++];)o.innerHTML=o.innerHTML.replace(/body/g,"#parser");for(var a,c=document.getElementsByTagName("img"),s=[],i=0==c.length,d=0,l=0,g=0;a=c[l];l++)parseInt(a.style.width||a.getAttribute("width"))>' + |
227 | 229 | windowWidth + '&&(a.style.height="auto"),a.onload=function(){++d==c.length&&(i=!0)},a.onerror=function(){++d==c.length&&(i=!0),' + (cfg.errorImg ? 'this.src="' + cfg.errorImg + '",' : '') + |
228 | | - 'e({action:"error",source:"img",target:this})},a.hasAttribute("ignore")||"A"==a.parentElement.nodeName||(a.i=g++,s.push(a.getAttribute("original-src")||a.src||a.getAttribute("data-src")),a.onclick=function(){e({action:"preview",img:{i:this.i,src:this.src}})});e({action:"getImgList",imgList:s});for(var u,m=document.getElementsByTagName("a"),f=0;u=m[f];f++)u.onclick=function(){var t,o=this.getAttribute("href");if("#"==o[0]){var n=document.getElementById(o.substr(1));n&&(t=n.offsetTop)}return e({action:"linkpress",href:o,offset:t}),!1};for(var h,y=document.getElementsByTagName("video"),v=0;h=y[v];v++)h.style.maxWidth="100%",h.onerror=function(){e({action:"error",source:"video",target:this})}' + |
| 230 | + 'e({action:"error",source:"img",target:this})},a.hasAttribute("ignore")||"A"==a.parentElement.nodeName||(a.i=g++,s.push(a.getAttribute("original-src")||a.src||a.getAttribute("data-src")),a.onclick=function(t){t.stopPropagation(),e({action:"preview",img:{i:this.i,src:this.src}})});e({action:"getImgList",imgList:s});for(var u,m=document.getElementsByTagName("a"),f=0;u=m[f];f++)u.onclick=function(m){m.stopPropagation();var t,o=this.getAttribute("href");if("#"==o[0]){var n=document.getElementById(o.substr(1));n&&(t=n.offsetTop)}return e({action:"linkpress",href:o,offset:t}),!1};for(var h,y=document.getElementsByTagName("video"),v=0;h=y[v];v++)h.style.maxWidth="100%",h.onerror=function(){e({action:"error",source:"video",target:this})}' + |
229 | 231 | (this.autopause ? ',h.onplay=function(){for(var e,t=0;e=y[t];t++)e!=this&&e.pause()}' : '') + |
230 | 232 | ';for(var _,p=document.getElementsByTagName("audio"),w=0;_=p[w];w++)_.onerror=function(){e({action:"error",source:"audio",target:this})};' + |
231 | 233 | (this.autoscroll ? 'for(var T,E=document.getElementsByTagName("table"),B=0;T=E[B];B++){var N=document.createElement("div");N.style.overflow="scroll",T.parentNode.replaceChild(N,T),N.appendChild(T)}' : '') + |
|
272 | 274 | uni.setNavigationBarTitle({ |
273 | 275 | title: title[0].innerText |
274 | 276 | }) |
| 277 | + // 填充 domain |
| 278 | + var fill = target => { |
| 279 | + var src = target.getAttribute('src'); |
| 280 | + if (this.domain && src) { |
| 281 | + if (src[0] == '/') { |
| 282 | + if (src[1] == '/') |
| 283 | + target.src = (this.domain.includes('://') ? this.domain.split('://')[0] : '') + ':' + src; |
| 284 | + else target.src = this.domain + src; |
| 285 | + } else if (!src.includes('://') && src.indexOf('data:') != 0) target.src = this.domain + '/' + src; |
| 286 | + } |
| 287 | + } |
275 | 288 | // 图片处理 |
276 | 289 | this.imgList.length = 0; |
277 | 290 | var imgs = this.rtf.getElementsByTagName('img'); |
278 | 291 | for (let i = 0, j = 0, img; img = imgs[i]; i++) { |
279 | 292 | if (parseInt(img.style.width || img.getAttribute('width')) > windowWidth) |
280 | 293 | img.style.height = 'auto'; |
281 | | - var src = img.getAttribute('src'); |
282 | | - if (this.domain && src) { |
283 | | - if (src[0] == '/') { |
284 | | - if (src[1] == '/') |
285 | | - img.src = (this.domain.includes('://') ? this.domain.split('://')[0] : '') + ':' + src; |
286 | | - else img.src = this.domain + src; |
287 | | - } else if (!src.includes('://')) img.src = this.domain + '/' + src; |
288 | | - } |
| 294 | + fill(img); |
289 | 295 | if (!img.hasAttribute('ignore') && img.parentElement.nodeName != 'A') { |
290 | 296 | img.i = j++; |
291 | 297 | _ts.imgList.push(img.getAttribute('original-src') || img.src || img.getAttribute('data-src')); |
292 | | - img.onclick = function() { |
| 298 | + img.onclick = function(e) { |
| 299 | + e.stopPropagation(); |
293 | 300 | var preview = true; |
294 | 301 | this.ignore = () => preview = false; |
295 | 302 | _ts.$emit('imgtap', this); |
|
318 | 325 | // 链接处理 |
319 | 326 | var links = this.rtf.getElementsByTagName('a'); |
320 | 327 | for (var link of links) { |
321 | | - link.onclick = function() { |
| 328 | + link.onclick = function(e) { |
| 329 | + e.stopPropagation(); |
322 | 330 | var jump = true, |
323 | 331 | href = this.getAttribute('href'); |
324 | 332 | _ts.$emit('linkpress', { |
|
346 | 354 | var videos = this.rtf.getElementsByTagName('video'); |
347 | 355 | _ts.videoContexts = videos; |
348 | 356 | for (let video, i = 0; video = videos[i++];) { |
| 357 | + fill(video); |
349 | 358 | video.style.maxWidth = '100%'; |
350 | 359 | video.onerror = function() { |
351 | 360 | _ts.$emit('error', { |
|
361 | 370 | } |
362 | 371 | // 音频处理 |
363 | 372 | var audios = this.rtf.getElementsByTagName('audio'); |
364 | | - for (var audio of audios) |
| 373 | + for (var audio of audios) { |
| 374 | + fill(audio); |
365 | 375 | audio.onerror = function() { |
366 | 376 | _ts.$emit('error', { |
367 | 377 | source: 'audio', |
368 | 378 | target: this |
369 | 379 | }); |
370 | 380 | } |
| 381 | + } |
371 | 382 | // 表格处理 |
372 | 383 | if (this.autoscroll) { |
373 | 384 | var tables = this.rtf.getElementsByTagName('table'); |
|
626 | 637 | /* #ifdef MP-WEIXIN */ |
627 | 638 | :host { |
628 | 639 | display: block; |
629 | | - overflow: scroll; |
| 640 | + overflow: auto; |
630 | 641 | -webkit-overflow-scrolling: touch; |
631 | 642 | } |
632 | 643 |
|
|
0 commit comments