1

我正在使用SCEditor,我正在尝试根据此页面上指定的表情选项设置我自己的自定义表情。

所以我这样称呼它:

$(document).ready(function() {

    $(".sceditor").sceditor({
        // Other options
        emoticons: $.getJSON('../../images/emoticons/default/emoticons.json'),
        emoticonsRoot: '../../images/emoticons/default/'
    });

})

然后在我的emoticons.json文件中我有这个:

{
    dropdown: {
        ':)': 'emoticons/smile.png',
        ':angel:': 'emoticons/angel.png',
        ':angry:': 'emoticons/angry.png'
    }
}

但是它不起作用。我已经检查了NET浏览器中的面板,并确认它可以正常获取.json文件,但是当我单击在编辑器中打开笑脸窗口时,它是空白的(我看到的只是“更多”链接)。

我在这里做错了吗?

4

3 回答 3

0

json 文件中上面显示的 Json lint 文本无效。

尝试将其放入您的 json 文件中

{
    "dropdown": {
        ":)": "emoticons/smile.png",
        ":angel:": "emoticons/angel.png",
        ":angry:": "emoticons/angry.png"
    }
}

我在php中试过这个

$a = '{
    "dropdown": {
        ":)": "emoticons/smile.png",
        ":angel:": "emoticons/angel.png",
        ":angry:": "emoticons/angry.png"
    }
}' ;
print_r(json_decode($a));

输出

Array
(
    [dropdown] => Array
        (
            [:)] => emoticons/smile.png
            [:angel:] => emoticons/angel.png
            [:angry:] => emoticons/angry.png
        )

)
于 2015-06-11T10:41:30.063 回答
0

我已经通过你的链接试过了。以下是我的代码:

$(function() {
        // Replace all textarea's
        // with SCEditor
        $("textarea").sceditor({
            plugins: "bbcode",
            style: "plugins/SCEditor/development/jquery.sceditor.default.css",
            emoticons: {
                // Emoticons to be included in the dropdown
                dropdown: {
                    ":)": "emoticons/smile.png",
                    ":angel:": "emoticons/angel.png"
                },
                // Emoticons to be included in the more section
                more: {
                    ":alien:": "emoticons/alien.png",
                    ":blink:": "emoticons/blink.png"
                },
                // Emoticons that are not shown in the dropdown but will still
                // be converted. Can be used for things like aliases
                hidden: {
                    ":aliasforalien:": "emoticons/alien.png",
                    ":aliasforblink:": "emoticons/blink.png"
                }
            },
            emoticonsRoot: "plugins/SCEditor/"
        });
    });

在此之上,您可能知道您的代码错误的原因。与jQuery.getJSON 相对,$.getJSON 返回 JQXHR,而不是 Json 对象。因此,无法显示您的表情符号。

于 2015-06-11T10:44:24.940 回答
0

根据 WhiteWater 的回答,它不起作用的原因是因为它返回的是一个JQXHR对象而不是一个JSON对象,所以我必须弄清楚如何让它返回一个JSON对象,同时编辑器加载不依赖于表情符号的存在。

所以我们有下面的解决方案,感谢 jeremysawesome对这个问题的回答

// create a variable to store the results
var emoticons = false;

$.getJSON('../../images/emoticons/default/emoticons.json')
.done(function(result){
    emoticons = result;
})
.always(function(){
    // always initialize the sceditor
    $('.my-selector').sceditor({emoticons: emoticons}); 
});

这将加载表情符号,但将始终加载 sceditor 实例,即使表情符号由于某种原因失败。

于 2015-06-12T06:31:43.810 回答