博客回复改版的事件、研究了新浪的web.api成功调用的新浪表情组件
优采云 发布时间: 2021-08-15 22:09博客回复改版的事件、研究了新浪的web.api成功调用的新浪表情组件
最近在准备博客响应事件改版,研究了新浪的web.api调用成功的新浪表情组件
来和大家分享一个很实用的东西,希望对大家有帮助
我们先来看看操作的结果。
是不是很刺眼?让我们来看看如何实现它。
JS自定义hashtable代码如下
//自定义hashtable
function Hashtable() {
this._hash = new Object();
this.put = function(key, value) {
if (typeof (key) != "undefined") {
if (this.containsKey(key) == false) {
this._hash[key] = typeof (value) == "undefined" ? null : value;
return true;
} else {
return false;
}
} else {
return false;
}
}
this.remove = function(key) { delete this._hash[key]; }
this.size =
function() { var i = 0; for (var k in this._hash) { i ; } return i; }
this.get = function(key) { return this._hash[key]; }
this.containsKey =
function(key) { return typeof (this._hash[key]) != "undefined"; }
this.clear =
function() { for (var k in this._hash) { delete this._hash[k]; } }
}
初始化缓存并只加载一次页面。
$(function() {
$.ajax( {
dataType : ´json´,
url : ´json/jquery.sinaEmotion.json´,
success : function(response) {
var data = response.data;
for ( var i in data) {
if (data[i].category == ´´) {
data[i].category = ´默认´;
}
if (emotions[data[i].category] == undefined) {
emotions[data[i].category] = new Array();
categorys.push(data[i].category);
}
emotions[data[i].category].push( {
name : data[i].phrase,
icon : data[i].icon
});
uSinaEmotionsHt.put(data[i].phrase, data[i].icon);
}
}
});
});
替换
function AnalyticEmotion(s) {
if(typeof (s) != "undefined") {
var sArr = s.match(/[.*?]/g);
for(var i = 0; i < sArr.length; i ){
if(uSinaEmotionsHt.containsKey(sArr[i])) {
var reStr = "";
s = s.replace(sArr[i], reStr);
}
}
}
return s;
}
显示类别
function showCategorys(){
var page = arguments[0]?arguments[0]:0;
if(page < 0 || page >= categorys.length / 5){
return;
}
$(´#emotions .categorys´).html(´´);
cat_page = page;
for(var i = page * 5; i < (page 1) * 5 && i < categorys.length; i){
$(´#emotions .categorys´)
.append($(´´
categorys[i] ´´));
}
$(´#emotions .categorys a´).click(function(){
showEmotions($(this).text());
});
$(´#emotions .categorys a´).each(function(){
if($(this).text() == cat_current){
$(this).addClass(´current´);
}
});
}
显示表情
function showEmotions(){
var category = arguments[0]?arguments[0]:´默认´;
var page = arguments[1]?arguments[1] - 1:0;
$(´#emotions .containersina´).html(´´);
$(´#emotions .page´).html(´´);
cat_current = category;
for(var i = page * 72; i < (page 1) * 72 && i < emotions[category].length; i){
$(´#emotions .containersina´)
.append($(´´
emotions[category][i].icon ´´));
}
$(´#emotions .containersina a´).click(function(){
target.insertText($(this).attr(´title´));
$(´#emotions´).remove();
});
for(var i = 1; i < emotions[category].length / 72 1; i){
$(´#emotions .page´).append($(´´ i ´´));
}
$(´#emotions .page a´).click(function(){
showEmotions(category, $(this).text());
});
$(´#emotions .categorys a.current´).removeClass(´current´);
$(´#emotions .categorys a´).each(function(){
if($(this).text() == category){
$(this).addClass(´current´);
}
});
}
HTML代码如下
JQuery新浪1630个表情插件(带解析方法)
完美兼容IE6 所有浏览器
<br />
<br />
当然要在整个代码实现之前引入对应的JS和CSS文件,对应的文件在源码中
最后给大家一个源码下载链接:密码:6xe9
也有本地版本:密码:6s3r
如果资源对你有帮助,浏览后收获很多,不妨,你的鼓励是我继续写博客的最大动力