intro.js
1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
var $ = require('yoho-jquery');
var videoPlayerTpl = require('hbs/product/video-player.hbs');
// 图片换成懒加载方式
var replacePairs = {
'<img src=': '<img class="lazy img-responsive" width="720" height="200" ' +
'src="data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw==" ' +
'data-original=',
'<img border="0" src=': '<img border="0" class="lazy img-responsive" width="720" height="200" ' +
'src="data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw==" ' +
'data-original=',
'.jpg"': '.jpg?imageslim"',
'http://': '//'
};
function _getDetailDataBySizeInfo(intro) {
var $intro;
// 详情配图
$.each(replacePairs, function(key, value) {
intro = intro.replace(new RegExp(key, 'gm'), value);
});
// 视频链接处理
$intro = $(intro);
$intro.find('a[href]').each(function() {
const $el = $(this);
$el.attr('href', 'javascript:;') //eslint-disable-line
.attr('target', '')
.attr('title', '')
.css('cursor', 'initial');
});
$intro.find('.video-placeholder').each(function(idx, ele) {
var $this = $(ele);
var videoSrc = $this.find('source').attr('src');
var $video = $this.find('video');
var width = $video.attr('width');
var height = $video.attr('height');
$this.empty().append(videoPlayerTpl({url: videoSrc, width: width || 750, height: height || 240}));
});
return $intro;
}
exports.getHtml = function() {
var intro = $('#details-intro').html();
return _getDetailDataBySizeInfo(intro);
};