Blame view

public/js/product/detail/intro.js 1.39 KB
htoooth authored
1
var $ = require('yoho-jquery');
htoooth authored
2
var videoPlayerTpl = require('hbs/product/video-player.hbs');
htoooth authored
3
htoooth authored
4 5 6 7 8 9 10 11 12 13 14 15 16 17
// 图片换成懒加载方式
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;
htoooth authored
18
htoooth authored
19 20 21
    // 详情配图
    $.each(replacePairs, function(key, value) {
        intro = intro.replace(new RegExp(key, 'gm'), value);
htoooth authored
22
    });
htoooth authored
23 24 25 26

    // 视频链接处理
    $intro = $(intro);
htoooth authored
27
    $intro.find('.video-placeholder').each(function(idx, ele) {
htoooth authored
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
        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);
htoooth authored
44
};