功能 features

示例 demo

文本框 textarea

代码 code

$("#content").emoji({
    showTab: true,
    animation: 'fade',
    icons: [{
        name: "贴吧表情",
        path: "dist/img/tieba/",
        maxNum: 50,
        file: ".jpg",
        placeholder: ":{alias}:",
        alias: {
            1: "hehe",
            2: "haha",
            3: "tushe",
            4: "a",
            5: "ku",
            6: "lu",
            7: "kaixin",
            8: "han",
            9: "lei",
            10: "heixian",
            11: "bishi",
            12: "bugaoxing",
            13: "zhenbang",
            14: "qian",
            15: "yiwen",
            16: "yinxian",
            17: "tu",
            18: "yi",
            19: "weiqu",
            20: "huaxin",
            21: "hu",
            22: "xiaonian",
            23: "neng",
            24: "taikaixin",
            25: "huaji",
            26: "mianqiang",
            27: "kuanghan",
            28: "guai",
            29: "shuijiao",
            30: "jinku",
            31: "shengqi",
            32: "jinya",
            33: "pen",
            34: "aixin",
            35: "xinsui",
            36: "meigui",
            37: "liwu",
            38: "caihong",
            39: "xxyl",
            40: "taiyang",
            41: "qianbi",
            42: "dnegpao",
            43: "chabei",
            44: "dangao",
            45: "yinyue",
            46: "haha2",
            47: "shenli",
            48: "damuzhi",
            49: "ruo",
            50: "OK"
        },
        title: {
            1: "呵呵",
            2: "哈哈",
            3: "吐舌",
            4: "啊",
            5: "酷",
            6: "怒",
            7: "开心",
            8: "汗",
            9: "泪",
            10: "黑线",
            11: "鄙视",
            12: "不高兴",
            13: "真棒",
            14: "钱",
            15: "疑问",
            16: "阴脸",
            17: "吐",
            18: "咦",
            19: "委屈",
            20: "花心",
            21: "呼~",
            22: "笑脸",
            23: "冷",
            24: "太开心",
            25: "滑稽",
            26: "勉强",
            27: "狂汗",
            28: "乖",
            29: "睡觉",
            30: "惊哭",
            31: "生气",
            32: "惊讶",
            33: "喷",
            34: "爱心",
            35: "心碎",
            36: "玫瑰",
            37: "礼物",
            38: "彩虹",
            39: "星星月亮",
            40: "太阳",
            41: "钱币",
            42: "灯泡",
            43: "茶杯",
            44: "蛋糕",
            45: "音乐",
            46: "haha",
            47: "胜利",
            48: "大拇指",
            49: "弱",
            50: "OK"
        }
    }, {
        path: "dist/img/qq/",
        maxNum: 91,
        excludeNums: [41, 45, 54],
        file: ".gif",
        placeholder: "#qq_{alias}#"
    }]
});

可编辑div editable div

代码 code

$("#editor").emoji({
    button: "#btn",
    showTab: false,
    animation: 'slide',
    icons: [{
        name: "QQ表情",
        path: "dist/img/qq/",
        maxNum: 91,
        excludeNums: [41, 45, 54],
        file: ".gif"
    }]
});

文本转换 text parse

It's a:taiyang:day, :xxx: I had a:chabei:, and feel nice~#qq_14#

代码 code

$("#sourceText").emojiParse({
    icons: [{
        path: "dist/img/tieba/",
        file: ".jpg",
        placeholder: ":{alias}:",
        alias: {
            1: "hehe",
            2: "haha",
            3: "tushe",
            4: "a",
            5: "ku",
            6: "lu",
            7: "kaixin",
            8: "han",
            9: "lei",
            10: "heixian",
            11: "bishi",
            12: "bugaoxing",
            13: "zhenbang",
            14: "qian",
            15: "yiwen",
            16: "yinxian",
            17: "tu",
            18: "yi",
            19: "weiqu",
            20: "huaxin",
            21: "hu",
            22: "xiaonian",
            23: "neng",
            24: "taikaixin",
            25: "huaji",
            26: "mianqiang",
            27: "kuanghan",
            28: "guai",
            29: "shuijiao",
            30: "jinku",
            31: "shengqi",
            32: "jinya",
            33: "pen",
            34: "aixin",
            35: "xinsui",
            36: "meigui",
            37: "liwu",
            38: "caihong",
            39: "xxyl",
            40: "taiyang",
            41: "qianbi",
            42: "dnegpao",
            43: "chabei",
            44: "dangao",
            45: "yinyue",
            46: "haha2",
            47: "shenli",
            48: "damuzhi",
            49: "ruo",
            50: "OK"
        }
    }, {
        path: "dist/img/qq/",
        file: ".gif",
        placeholder: "#qq_{alias}#"
    }]
});

使用 usage

安装 install

$ bower install jquery-emoji

引用 reference

首先在页面上引用css文件和js文件,css文件一般在<head>中添加,js文件一般在</body>之前添加。注意要先引用jquery和jquery.mCustomScrollbar,再引用该js。
Firstly reference the css and js file of this plugin, the best location of the css reference is in <head>, and the js is before </body>, make sure the js follows jQuery and jquery.mCustomScrollbar.

<head>
    ...
    <!--the css for jquery.mCustomScrollbar-->
    <link rel="stylesheet" href="lib/css/jquery.mCustomScrollbar.min.css"/>
    <!--the css for this plugin-->
    <link rel="stylesheet" href="css/jquery.emoji.css"/>
</head>
<body>
...
<!--the js for jquery-->
<script src="https://cdn.bootcss.com/jquery/1.11.3/jquery.js"></script>
<!--(Optional) the js for jquery.mCustomScrollbar's addon-->
<script src="lib/script/jquery.mousewheel-3.0.6.min.js"></script>
<!--the js for jquery.mCustomScrollbar-->
<script src="lib/script/jquery.mCustomScrollbar.min.js"></script>
<!--the js for this plugin-->
<script src="js/jquery.emoji.js"></script>
</body>

调用 invoke

在文本框或可编辑div上初始化emoji
initialize emoji on textarea or editable div

$("#content").emoji(options);

参数 options

名称 name 类型 type 默认值 default 说明 desc
button String 触发表情面板的按钮的选择器,如"#btn1",若指定则将表情选择面板绑定到该按钮,若未指定,则自动创建一个按钮。
button selector, such as "#btn1", if has value, bind it to the emoji panel. If it is empty, then automatically creates a button.
showTab Boolean true 当只有一组表情时,是否仍然显示Tab。
if show tab when only one emoji group.
animation String 'fade' 表情面板动画效果,可能的值:'fade':淡入淡出,'slide':滚动,'none':无动画。
the animation effect for emoji panel, possible values: 'fade':fade-in fade-out, 'slide':slide up & down, 'none':no animation.
icons Array [] 表情组。
icons group.
icons:{ name } String group(n) 该组表情名称。
the name of the icons group.
icons:{ path } String 必填。该组表情路径(表情文件必须是1,2,3...命名)。
required.the path of the icons group(icon file must named as 1 ,2 ,3...).
icons:{ maxNum } Number 必填。该组表情文件名的最大数。
required.the max number of the icons group file name.
icons:{ excludeNums } Array [] 要排除的表情文件集合。
the exclude icon files.
icons:{ file } String '.jpg' 表情文件的后缀名。
the icon file extension.
icons:{ placeholder } String '#em(n)_{alias}#'
该组表情插入文本框后的占位标识,必须包含'{alias}'部分,'{alias}'会被自动替换成每个表情的标识。
the placeholder for the icon group, must contains '{alias}' in it, it will be replaced with the code of each emoji.
icons:{ alias } String 每个表情对应的标识,若未指定,则为表情文件名(1,2,3...),若指定为一个对象,则会根据对象属性名(1,2,3...)查找属性的值作为表情标识。
the flag for each emoji, if undefined, it refers the name of emoji file (1,2,3...), else if specify an object, it will look for the value of the attribute as the emoji flag according to the attribute name (1,2,3...).
icons:{ title } Object 每个表情指上去显示的文字,格式:fileName:title, 如:1:'good'。
the shows title for each emoji, format: fileName:title, such as: 1:'good'.
* n: 分组的次序 index of the group

方法 method

.emoji(options);

初始化表情。
initialize emoji.

$("#editor").emoji({
    icons: [{
        name: "QQ表情",
        path: "img/qq/",
        maxNum: 91,
        excludeNums: [41, 45, 54],
        file: ".gif",
        placeholder: "#qq_{alias}#"
    }]
});

.emoji('show');

显示表情面板。
show emoji panel.

$("#editor").emoji('show');

.emoji('hide');

隐藏表情面板。
hide emoji panel.

$("#editor").emoji('hide');

.emoji('toggle');

切换显示隐藏表情面板。
show or hide emoji panel.

$("#editor").emoji('toggle');