emotion.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. (function(){
  2. var editor = null;
  3. UM.registerWidget('emotion',{
  4. tpl: "<link type=\"text/css\" rel=\"stylesheet\" href=\"<%=emotion_url%>emotion.css\">" +
  5. "<div class=\"edui-emotion-tab-Jpanel edui-emotion-wrapper\">" +
  6. "<ul class=\"edui-emotion-Jtabnav edui-tab-nav\">" +
  7. "<li class=\"edui-tab-item\"><a data-context=\".edui-emotion-Jtab0\" hideFocus=\"true\" class=\"edui-tab-text\"><%=lang_input_choice%></a></li>" +
  8. "<li class=\"edui-tab-item\"><a data-context=\".edui-emotion-Jtab1\" class=\"edui-tab-text\"><%=lang_input_Tuzki%></a></li>" +
  9. "<li class=\"edui-tab-item\"><a data-context=\".edui-emotion-Jtab2\" hideFocus=\"true\" class=\"edui-tab-text\"><%=lang_input_lvdouwa%></a></li>" +
  10. "<li class=\"edui-tab-item\"><a data-context=\".edui-emotion-Jtab3\" hideFocus=\"true\" class=\"edui-tab-text\"><%=lang_input_BOBO%></a></li>" +
  11. "<li class=\"edui-tab-item\"><a data-context=\".edui-emotion-Jtab4\" hideFocus=\"true\" class=\"edui-tab-text\"><%=lang_input_babyCat%></a></li>" +
  12. "<li class=\"edui-tab-item\"><a data-context=\".edui-emotion-Jtab5\" hideFocus=\"true\" class=\"edui-tab-text\"><%=lang_input_bubble%></a></li>" +
  13. "<li class=\"edui-tab-item\"><a data-context=\".edui-emotion-Jtab6\" hideFocus=\"true\" class=\"edui-tab-text\"><%=lang_input_youa%></a></li>" +
  14. "<li class=\"edui-emotion-tabs\"></li>" +
  15. "</ul>" +
  16. "<div class=\"edui-tab-content edui-emotion-JtabBodys\">" +
  17. "<div class=\"edui-emotion-Jtab0 edui-tab-pane\"></div>" +
  18. "<div class=\"edui-emotion-Jtab1 edui-tab-pane\"></div>" +
  19. "<div class=\"edui-emotion-Jtab2 edui-tab-pane\"></div>" +
  20. "<div class=\"edui-emotion-Jtab3 edui-tab-pane\"></div>" +
  21. "<div class=\"edui-emotion-Jtab4 edui-tab-pane\"></div>" +
  22. "<div class=\"edui-emotion-Jtab5 edui-tab-pane\"></div>" +
  23. "<div class=\"edui-emotion-Jtab6 edui-tab-pane\"></div>" +
  24. "</div>" +
  25. "<div class=\"edui-emotion-JtabIconReview edui-emotion-preview-box\">" +
  26. "<img src=\"<%=cover_img%>\" class=\'edui-emotion-JfaceReview edui-emotion-preview-img\'/>" +
  27. "</div>",
  28. sourceData: {
  29. emotion: {
  30. tabNum:7, //切换面板数量
  31. SmilmgName:{ 'edui-emotion-Jtab0':['j_00', 84], 'edui-emotion-Jtab1':['t_00', 40], 'edui-emotion-Jtab2':['w_00', 52], 'edui-emotion-Jtab3':['B_00', 63], 'edui-emotion-Jtab4':['C_00', 20], 'edui-emotion-Jtab5':['i_f', 50], 'edui-emotion-Jtab6':['y_00', 40] }, //图片前缀名
  32. imageFolders:{ 'edui-emotion-Jtab0':'jx2/', 'edui-emotion-Jtab1':'tsj/', 'edui-emotion-Jtab2':'ldw/', 'edui-emotion-Jtab3':'bobo/', 'edui-emotion-Jtab4':'babycat/', 'edui-emotion-Jtab5':'face/', 'edui-emotion-Jtab6':'youa/'}, //图片对应文件夹路径
  33. imageCss:{'edui-emotion-Jtab0':'jd', 'edui-emotion-Jtab1':'tsj', 'edui-emotion-Jtab2':'ldw', 'edui-emotion-Jtab3':'bb', 'edui-emotion-Jtab4':'cat', 'edui-emotion-Jtab5':'pp', 'edui-emotion-Jtab6':'youa'}, //图片css类名
  34. imageCssOffset:{'edui-emotion-Jtab0':35, 'edui-emotion-Jtab1':35, 'edui-emotion-Jtab2':35, 'edui-emotion-Jtab3':35, 'edui-emotion-Jtab4':35, 'edui-emotion-Jtab5':25, 'edui-emotion-Jtab6':35}, //图片偏移
  35. SmileyInfor:{
  36. 'edui-emotion-Jtab0':['Kiss', 'Love', 'Yeah', '啊!', '背扭', '顶', '抖胸', '88', '汗', '瞌睡', '鲁拉', '拍砖', '揉脸', '生日快乐', '大笑', '瀑布汗~', '惊讶', '臭美', '傻笑', '抛媚眼', '发怒', '打酱油', '俯卧撑', '气愤', '?', '吻', '怒', '胜利', 'HI', 'KISS', '不说', '不要', '扯花', '大心', '顶', '大惊', '飞吻', '鬼脸', '害羞', '口水', '狂哭', '来', '发财了', '吃西瓜', '套牢', '害羞', '庆祝', '我来了', '敲打', '晕了', '胜利', '臭美', '被打了', '贪吃', '迎接', '酷', '微笑', '亲吻', '调皮', '惊恐', '耍酷', '发火', '害羞', '汗水', '大哭', '', '加油', '困', '你NB', '晕倒', '开心', '偷笑', '大哭', '滴汗', '叹气', '超赞', '??', '飞吻', '天使', '撒花', '生气', '被砸', '吓傻', '随意吐'],
  37. 'edui-emotion-Jtab1':['Kiss', 'Love', 'Yeah', '啊!', '背扭', '顶', '抖胸', '88', '汗', '瞌睡', '鲁拉', '拍砖', '揉脸', '生日快乐', '摊手', '睡觉', '瘫坐', '无聊', '星星闪', '旋转', '也不行', '郁闷', '正Music', '抓墙', '撞墙至死', '歪头', '戳眼', '飘过', '互相拍砖', '砍死你', '扔桌子', '少林寺', '什么?', '转头', '我爱牛奶', '我踢', '摇晃', '晕厥', '在笼子里', '震荡'],
  38. 'edui-emotion-Jtab2':['大笑', '瀑布汗~', '惊讶', '臭美', '傻笑', '抛媚眼', '发怒', '我错了', 'money', '气愤', '挑逗', '吻', '怒', '胜利', '委屈', '受伤', '说啥呢?', '闭嘴', '不', '逗你玩儿', '飞吻', '眩晕', '魔法', '我来了', '睡了', '我打', '闭嘴', '打', '打晕了', '刷牙', '爆揍', '炸弹', '倒立', '刮胡子', '邪恶的笑', '不要不要', '爱恋中', '放大仔细看', '偷窥', '超高兴', '晕', '松口气', '我跑', '享受', '修养', '哭', '汗', '啊~', '热烈欢迎', '打酱油', '俯卧撑', '?'],
  39. 'edui-emotion-Jtab3':['HI', 'KISS', '不说', '不要', '扯花', '大心', '顶', '大惊', '飞吻', '鬼脸', '害羞', '口水', '狂哭', '来', '泪眼', '流泪', '生气', '吐舌', '喜欢', '旋转', '再见', '抓狂', '汗', '鄙视', '拜', '吐血', '嘘', '打人', '蹦跳', '变脸', '扯肉', '吃To', '吃花', '吹泡泡糖', '大变身', '飞天舞', '回眸', '可怜', '猛抽', '泡泡', '苹果', '亲', '', '骚舞', '烧香', '睡', '套娃娃', '捅捅', '舞倒', '西红柿', '爱慕', '摇', '摇摆', '杂耍', '招财', '被殴', '被球闷', '大惊', '理想', '欧打', '呕吐', '碎', '吐痰'],
  40. 'edui-emotion-Jtab4':['发财了', '吃西瓜', '套牢', '害羞', '庆祝', '我来了', '敲打', '晕了', '胜利', '臭美', '被打了', '贪吃', '迎接', '酷', '顶', '幸运', '爱心', '躲', '送花', '选择'],
  41. 'edui-emotion-Jtab5':['微笑', '亲吻', '调皮', '惊讶', '耍酷', '发火', '害羞', '汗水', '大哭', '得意', '鄙视', '困', '夸奖', '晕倒', '疑问', '媒婆', '狂吐', '青蛙', '发愁', '亲吻', '', '爱心', '心碎', '玫瑰', '礼物', '哭', '奸笑', '可爱', '得意', '呲牙', '暴汗', '楚楚可怜', '困', '哭', '生气', '惊讶', '口水', '彩虹', '夜空', '太阳', '钱钱', '灯泡', '咖啡', '蛋糕', '音乐', '爱', '胜利', '赞', '鄙视', 'OK'],
  42. 'edui-emotion-Jtab6':['男兜', '女兜', '开心', '乖乖', '偷笑', '大笑', '抽泣', '大哭', '无奈', '滴汗', '叹气', '狂晕', '委屈', '超赞', '??', '疑问', '飞吻', '天使', '撒花', '生气', '被砸', '口水', '泪奔', '吓傻', '吐舌头', '点头', '随意吐', '旋转', '困困', '鄙视', '狂顶', '篮球', '再见', '欢迎光临', '恭喜发财', '稍等', '我在线', '恕不议价', '库房有货', '货在路上']
  43. }
  44. }
  45. },
  46. initContent:function( _editor, $widget ){
  47. var me = this,
  48. emotion = me.sourceData.emotion,
  49. lang = _editor.getLang( 'emotion' )['static'],
  50. emotionUrl = UMEDITOR_CONFIG.UMEDITOR_HOME_URL + 'dialogs/emotion/',
  51. options = $.extend( {}, lang, {
  52. emotion_url: emotionUrl
  53. }),
  54. $root = me.root();
  55. if( me.inited ) {
  56. me.preventDefault();
  57. this.switchToFirst();
  58. return;
  59. }
  60. me.inited = true;
  61. editor = _editor;
  62. this.widget = $widget;
  63. emotion.SmileyPath = _editor.options.emotionLocalization === true ? emotionUrl + 'images/' : "http://img.baidu.com/hi/";
  64. emotion.SmileyBox = me.createTabList( emotion.tabNum );
  65. emotion.tabExist = me.createArr( emotion.tabNum );
  66. options['cover_img'] = emotion.SmileyPath + (editor.options.emotionLocalization ? '0.gif' : 'default/0.gif');
  67. $root.html( $.parseTmpl( me.tpl, options ) );
  68. me.tabs = $.eduitab({selector:".edui-emotion-tab-Jpanel"});
  69. //缓存预览对象
  70. me.previewBox = $root.find(".edui-emotion-JtabIconReview");
  71. me.previewImg = $root.find(".edui-emotion-JfaceReview");
  72. me.initImgName();
  73. },
  74. initEvent:function(){
  75. var me = this;
  76. //防止点击过后关闭popup
  77. me.root().on('click', function(e){
  78. return false;
  79. });
  80. //移动预览
  81. me.root().delegate( 'td', 'mouseover mouseout', function( evt ){
  82. var $td = $( this),
  83. url = $td.attr('data-surl') || null;
  84. if( url ) {
  85. me[evt.type]( this, url , $td.attr('data-posflag') );
  86. }
  87. return false;
  88. } );
  89. //点击选中
  90. me.root().delegate( 'td', 'click', function( evt ){
  91. var $td = $( this),
  92. realUrl = $td.attr('data-realurl') || null;
  93. if( realUrl ) {
  94. me.insertSmiley( realUrl.replace( /'/g, "\\'" ), evt );
  95. }
  96. return false;
  97. } );
  98. //更新模板
  99. me.tabs.edui().on("beforeshow", function( evt ){
  100. var contentId = $(evt.target).attr('data-context').replace( /^.*\.(?=[^\s]*$)/, '' );
  101. evt.stopPropagation();
  102. me.updateTab( contentId );
  103. });
  104. this.switchToFirst();
  105. },
  106. initImgName: function() {
  107. var emotion = this.sourceData.emotion;
  108. for ( var pro in emotion.SmilmgName ) {
  109. var tempName = emotion.SmilmgName[pro],
  110. tempBox = emotion.SmileyBox[pro],
  111. tempStr = "";
  112. if ( tempBox.length ) return;
  113. for ( var i = 1; i <= tempName[1]; i++ ) {
  114. tempStr = tempName[0];
  115. if ( i < 10 ) tempStr = tempStr + '0';
  116. tempStr = tempStr + i + '.gif';
  117. tempBox.push( tempStr );
  118. }
  119. }
  120. },
  121. /**
  122. * 切换到第一个tab
  123. */
  124. switchToFirst: function(){
  125. this.root().find(".edui-emotion-Jtabnav .edui-tab-text:first").trigger('click');
  126. },
  127. updateTab: function( contentBoxId ) {
  128. var me = this,
  129. emotion = me.sourceData.emotion;
  130. me.autoHeight( contentBoxId );
  131. if ( !emotion.tabExist[ contentBoxId ] ) {
  132. emotion.tabExist[ contentBoxId ] = true;
  133. me.createTab( contentBoxId );
  134. }
  135. },
  136. autoHeight: function( ) {
  137. this.widget.height(this.root() + 2);
  138. },
  139. createTabList: function( tabNum ) {
  140. var obj = {};
  141. for ( var i = 0; i < tabNum; i++ ) {
  142. obj["edui-emotion-Jtab" + i] = [];
  143. }
  144. return obj;
  145. },
  146. mouseover: function( td, srcPath, posFlag ) {
  147. posFlag -= 0;
  148. $(td).css( 'backgroundColor', '#ACCD3C' );
  149. this.previewImg.css( "backgroundImage", "url(" + srcPath + ")" );
  150. posFlag && this.previewBox.addClass('edui-emotion-preview-left');
  151. this.previewBox.show();
  152. },
  153. mouseout: function( td ) {
  154. $(td).css( 'backgroundColor', 'transparent' );
  155. this.previewBox.removeClass('edui-emotion-preview-left').hide();
  156. },
  157. insertSmiley: function( url, evt ) {
  158. var obj = {
  159. src: url
  160. };
  161. obj._src = obj.src;
  162. editor.execCommand( 'insertimage', obj );
  163. if ( !evt.ctrlKey ) {
  164. //关闭预览
  165. this.previewBox.removeClass('edui-emotion-preview-left').hide();
  166. this.widget.edui().hide();
  167. }
  168. },
  169. createTab: function( contentBoxId ) {
  170. var faceVersion = "?v=1.1", //版本号
  171. me = this,
  172. $contentBox = this.root().find("."+contentBoxId),
  173. emotion = me.sourceData.emotion,
  174. imagePath = emotion.SmileyPath + emotion.imageFolders[ contentBoxId ], //获取显示表情和预览表情的路径
  175. positionLine = 11 / 2, //中间数
  176. iWidth = iHeight = 35, //图片长宽
  177. iColWidth = 3, //表格剩余空间的显示比例
  178. tableCss = emotion.imageCss[ contentBoxId ],
  179. cssOffset = emotion.imageCssOffset[ contentBoxId ],
  180. textHTML = ['<table border="1" class="edui-emotion-smileytable">'],
  181. i = 0, imgNum = emotion.SmileyBox[ contentBoxId ].length, imgColNum = 11, faceImage,
  182. sUrl, realUrl, posflag, offset, infor;
  183. for ( ; i < imgNum; ) {
  184. textHTML.push( '<tr>' );
  185. for ( var j = 0; j < imgColNum; j++, i++ ) {
  186. faceImage = emotion.SmileyBox[ contentBoxId ][i];
  187. if ( faceImage ) {
  188. sUrl = imagePath + faceImage + faceVersion;
  189. realUrl = imagePath + faceImage;
  190. posflag = j < positionLine ? 0 : 1;
  191. offset = cssOffset * i * (-1) - 1;
  192. infor = emotion.SmileyInfor[ contentBoxId ][i];
  193. textHTML.push( '<td class="edui-emotion-' + tableCss + '" data-surl="'+ sUrl +'" data-realurl="'+ realUrl +'" data-posflag="'+ posflag +'" align="center">' );
  194. textHTML.push( '<span>' );
  195. textHTML.push( '<img style="background-position:left ' + offset + 'px;" title="' + infor + '" src="' + emotion.SmileyPath + (editor.options.emotionLocalization ? '0.gif" width="' : 'default/0.gif" width="') + iWidth + '" height="' + iHeight + '"></img>' );
  196. textHTML.push( '</span>' );
  197. } else {
  198. textHTML.push( '<td bgcolor="#FFFFFF">' );
  199. }
  200. textHTML.push( '</td>' );
  201. }
  202. textHTML.push( '</tr>' );
  203. }
  204. textHTML.push( '</table>' );
  205. textHTML = textHTML.join( "" );
  206. $contentBox.html( textHTML );
  207. },
  208. createArr: function( tabNum ) {
  209. var arr = [];
  210. for ( var i = 0; i < tabNum; i++ ) {
  211. arr[i] = 0;
  212. }
  213. return arr;
  214. },
  215. width:603,
  216. height:400
  217. });
  218. })();