search.js 1.14 KB
/**
 * 我的信息
 * @author: yyqing<yanqing.yang@yoho.cn>
 * @date: 2016/3/23
 */
var $ = require('yoho.jquery'),
    Handlebars = require('yoho.handlebars');

var $searchMain = $('.search-content'),
    $dialog = $('#help-dialog-widget'),
    $dialogBg = $('#help-dialog-bg');

var docW = $(document).width(),
    winH = $(window).height();

var tpl =
    '<div class="dialog-titlebar">' +
        '<span class="dialog-close-btn"></span>' +
    '</div>' +
    '<div class="dialog-content">' +
        '<p class="ask">问:<br>{{ask}}</p>' +
        '<p class="answer">答:<br>{{answer}}</p>' +
    '</div>';

var tplFn = Handlebars.compile(tpl);

$searchMain.on('click', '.faqs', function() {
    var data = $(this).data(),
        top = $(document).scrollTop();

    $dialog.html(tplFn(data)).removeClass('hide');
    $dialogBg.removeClass('hide');

    $dialog.html(tplFn(data)).css({
        top: top + (winH - $dialog.outerHeight()) / 2,
        left: (docW - $dialog.outerWidth()) / 2
    });
});

$dialog.on('click', '.dialog-close-btn', function() {
    $dialog.addClass('hide');
    $dialogBg.addClass('hide');
});