ChatFace.js 3.5 KB
//*
// 聊天表情 和选项卡
// */

import Emiter from "Emiter";
import Loger from "Loger";
import $ from "jquery";


let loger = Loger.getLoger('PC-ChatFace');
let step = 0, count = 4;
let $inner = $("#inner-slide"), $tip = $("#tiplist"), $tipList = $tip.children("li");
class ChatFace extends Emiter {
    constructor() {
        super();
        this.addEvent();
        this.init();
    }

    init() {
        let that = this;
        //布局

        $(".face").on("click", that._showHide.bind(this));
        $(".swiper-slide").on("click", "li", function (e) {

            $("#txt_message").val($("#txt_message").val() + "[img:" + $(this).find("img").attr("data-type") + "]");
            const faceList = document.getElementById("facelist");
            faceList.style.display = "none";
        });
        //UI按钮点击事件
        $tipList.bind("click", function () {
            step = $(this).index();
            $inner.stop().animate({left: -step * 320}, 500);
            that._changeTip();
        });
        //选项卡s
        this._changeTab();
        //文字区域点击后表情消失
       /* $("#txt_message").on("focus",that._hideFace.bind(this));
        $("#panel_message").on("click",that._hideFace.bind(this));
        $(".middle").on("click",that._hideFace.bind(this));
        $(".left").on("click",that._hideFace.bind(this));
        $(".header").on("click",that._hideFace.bind(this));
        $(".videoWindow").on("click",that._hideFace.bind(this));
        $(".userListTitle").on("click",that._hideFace.bind(this));*/

    }

    addEvent() {

    }

    _showHide() {
        let faceList = document.getElementById("facelist");
        this._showHideFace(faceList);
    }

    _showHideFace(obj) {
        if (obj.style.display == "none") {
            obj.style.display = 'block';
        } else {
            obj.style.display = 'none';
        }
    }
    _hideFace(){
        let faceList = document.getElementById("facelist");
        if (faceList.style.display == "block") {
            faceList.style.display = 'none';
        }

    }

    _faceSelected() {
        $("#txt_message").val($("#txt_message").val() + "[img:" + $(this).find("img").attr("data-type") + "]");
        let faceList = document.getElementById("facelist");
        faceList.style.display = "none";
    }


    _changeTip() {
        let that = this;
        let temp = step;
        temp >= count ? temp = 0 : null;
        $tipList.each(function (index, item) {
            index === temp ? $(this).addClass("bg") : $(this).removeClass("bg");
        });
    }

    _changeTab() {
        $(document).ready(function () {
            $(".tabTitle li").click(function () {
                $(".tabTitle li").eq($(this).index()).addClass("select").siblings().removeClass("select");
                $(".tabCon").hide().eq($(this).index()).show();
            });
            $(".userListTitle").click(function () {
                $(".userListTitle").css("borderBottom", "1px solid #3498db");
                $(".discussTitle").css("borderBottom", "1px solid #666");
            });
            $(".discussTitle").click(function () {
                $(".userListTitle").css("borderBottom", "1px solid #666");
                $(".discussTitle").css("borderBottom", "1px solid #3498db");
                $("#panel_message")[0].scrollTop=$("#panel_message")[0].scrollHeight;
            })
        })
    }
}
ChatFace.prototype.CHAT_FACE_CHANGE = ChatFace.CHAT_FACE_CHANGE = "chat_face_change";
export default ChatFace;