suggest.js 1.37 KB
/**
 * 个人中心--意见反馈
 * @author: chenglong<chenglong.wang@yoho.cn>
 * @date: 2015/11/12
 */


var $ = require('jquery'),
    Hammer = require('yoho.hammer'),
    Handlebars = require('yoho.handlebars');

var $uploadImgList = $('.upload-img-list'),
    headerNavHammer,
    imgTpl,
    template;

require('./jquery.uploadifive');

$('#upload-img').uploadifive({
    auto: true,
    fileType: 'image*/*',
    uploadScript: '/home/suggestimgUpload',
    fileObjName: 'fileData',
    fileSizeLimit: 1024,
    height: '100%',
    width: '100%',
    onAddQueueItem: function (files) {

        //TODO
    },
    onUploadComplete: function (file, data) {
        $uploadImgList.html(template(data));
    }
});


imgTpl = '{{# imgList}}' +
    '<li><img src="{{imgUrl}}" /></li>' +
    '{{/ imgList}}';

template = Handlebars.compile(imgTpl);

headerNavHammer = new Hammer(document.getElementById('yoho-header'));

headerNavHammer.on('tap', function (e) {
    var suggestText = $('#suggest-textarea').val();


    if ($(e.target).hasClass('nav-btn')) {

        $.ajax({
            method: 'post',
            url: '/home/savesuggest',
            data: {
                content: suggestText
            }
        }).then(function (data) {

            //TODO
        }).fail(function () {

            //TODO
        });
    }
});