qrcode.page.js 1.61 KB
var $ = require('yoho-jquery');
var Slide = require('../plugins/yohoui/YH.slide');

var $item = $('li', '.qrctxt');
var len = $item.length, slide;

require('../common');

function slideDo(to) {
    $item.each(function(index) {
        index === to ? $(this).stop().animate({
            opacity: 1,
            zIndex: 1
        }, 400) : $(this).stop().animate({
            opacity: 0,
            zIndex: 0
        }, 400);
        to === 0 ? $('.prev').addClass('gray') : $('.prev').removeClass('gray');
        to === len - 1 ? $('.next').addClass('gray') : $('.next').removeClass('gray');
    });
}

slideDo(0);

slide = new Slide({
    length: len,
    loop: false,
    auto: false,
    timeout: 2,
    index: 0
});
slide.on('change', function(data) {
    slideDo(data.to);
});
$('.prev', '.qrcmain-switch').click(function() {
    slide.prev();
});
$('.next', '.qrcmain-switch').click(function() {
    slide.next();
});
$('.btn-qcode').click(function() {
    var html = ['<ul>'];

    $('.center', '.qrctxt').each(function() {
        var _src, _bianhao, _zuoweihao;

        html.push('<li>');
        _src = $(this).find('img').attr('src');
        html.push('<img src=\'' + _src + '\'/>');
        _bianhao = $(this).find('.bianhao').text();
        html.push('<p>' + _bianhao + '</p>');
        _zuoweihao = $(this).find('.zuoweihao').text();
        if (_zuoweihao) {
            html.push('<p>' + _zuoweihao + '</p>');
        }
        html.push('</li>');
    });
    html.push('</ul>');

    $('.print-content').html(html.join(''));
    document.body.innerHTML = $('#print_wrap').show().html();
    window.print();
    return false;
});