soso_smilies.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. [Discuz!] (C)2001-2009 Comsenz Inc.
  3. This is NOT a freeware, use is subject to license terms
  4. $Id: soso_smilies.js 34306 2014-01-17 04:31:33Z nemohou $
  5. */
  6. var sosojs = document.createElement('script');
  7. sosojs.type = 'text/javascript';
  8. sosojs.charset = "utf-8";
  9. sosojs.src = 'http://pic.sogou.com/discuz/sosoexp_platform.js';
  10. var sosolo = document.getElementsByTagName('script')[0];
  11. sosolo.parentNode.insertBefore(sosojs, sosolo);
  12. function bbcode2html_sososmilies(sososmilieid, getsrc) {
  13. var imgsrc = '';
  14. sososmilieid = String(sososmilieid);
  15. if(sososmilieid.indexOf('_') >= 0) {
  16. if (sososmilieid.indexOf('_') == 0) {
  17. sososmilieid = sososmilieid.substr(1);
  18. }
  19. var imgid = 'soso__' + sososmilieid;
  20. var realsmilieid = sososmilieid.substr(0, sososmilieid.length-2);
  21. var serverid = sososmilieid.substr(sososmilieid.length-1);
  22. imgsrc = "http://imgstore0"+serverid+".cdn.sogou.com/app/a/100520032/"+realsmilieid;
  23. } else {
  24. var imgid = 'soso_' + sososmilieid;
  25. imgsrc = "http://imgstore01.cdn.sogou.com/app/a/100520032/"+sososmilieid;
  26. }
  27. if(!isUndefined(getsrc)) {
  28. return imgsrc;
  29. }
  30. return '<img src="'+imgsrc+'" smilieid="'+imgid+'" border="0" alt="" />';
  31. }
  32. function html2bbcode_sososmilies(htmlsmilies) {
  33. if(htmlsmilies) {
  34. htmlsmilies = htmlsmilies.replace(/<img[^>]+smilieid=(["']?)soso_(\w+)(\1)[^>]*>/ig, function($1, $2, $3) { return sososmileycode($3);});
  35. }
  36. return htmlsmilies;
  37. }
  38. function sososmileycode(sososmilieid) {
  39. if(sososmilieid) {
  40. return "{:soso_"+sososmilieid+":}";
  41. }
  42. }
  43. function sososmiliesurl2id(sosourl) {
  44. var sososmilieid = '';
  45. if(sosourl && sosourl.length > 30 && sosourl.indexOf('http://imgstore0') == 0) {
  46. var type = sosourl.substr(sosourl.lastIndexOf('/') + 1, 1);
  47. if (type == 'e') {
  48. sososmilieid = sosourl.substr(sosourl.lastIndexOf('/') + 1);
  49. } else {
  50. var serverid = sosourl.substr(16, 1);
  51. var realsmilieid = sosourl.substr(sosourl.lastIndexOf('/') + 1);
  52. sososmilieid = '_'+realsmilieid+'_'+serverid;
  53. }
  54. return sososmilieid;
  55. }
  56. }
  57. function insertsosoSmiley(sosourl) {
  58. var sososmilieid = sososmiliesurl2id(sosourl);
  59. if(sososmilieid) {
  60. var code = sososmileycode(sososmilieid);
  61. var src = bbcode2html_sososmilies(sososmilieid, true);
  62. checkFocus();
  63. if(wysiwyg && allowsmilies && (!$('smileyoff') || $('smileyoff').checked == false)) {
  64. insertText(bbcode2html_sososmilies(sososmilieid), false);
  65. } else {
  66. code += ' ';
  67. insertText(code, strlen(code), 0);
  68. }
  69. hideMenu();
  70. }
  71. }
  72. function insertfastpostSmiley(sosourl, textareaid) {
  73. var sososmilieid = sososmiliesurl2id(sosourl);
  74. if(sososmilieid) {
  75. var code = sososmileycode(sososmilieid);
  76. seditor_insertunit(textareaid, code);
  77. }
  78. }
  79. var TimeCounter = 0;
  80. function SOSO_EXP_CHECK(textareaid) {
  81. TimeCounter++;
  82. if(typeof editorid!='undefined' && textareaid == 'newthread') {
  83. var eExpBtn = $(editorid + '_sml'),
  84. eEditBox = $(editorid + '_textarea');
  85. eExpBtn.setAttribute('init', 1);
  86. fFillEditBox = function(editbox, url) {
  87. insertsosoSmiley(url);
  88. };
  89. } else if(in_array(textareaid, ['post', 'fastpost', 'pm', 'send', 'reply', 'sightml'])) {
  90. var eExpBtn = $(textareaid+"sml"),
  91. eEditBox = $(textareaid+"message"),
  92. fFillEditBox = function(editbox, url) {
  93. insertfastpostSmiley(url, textareaid);
  94. };
  95. } else {
  96. return false;
  97. }
  98. if(typeof SOSO_EXP != "undefined" && typeof SOSO_EXP.Register == "function" && eExpBtn && eEditBox) {
  99. var pos = 'bottom';
  100. if(in_array(textareaid, ['fastpost', 'pm', 'reply'])) {
  101. pos = 'top';
  102. }
  103. eExpBtn.onclick = function() { return null; };
  104. SOSO_EXP.Register(60001, 'discuz', eExpBtn, pos, eEditBox, fFillEditBox);
  105. if(typeof editdoc != "undefined" && editdoc && editdoc.body) {
  106. editdoc.body.onclick = extrafunc_soso_showmenu;
  107. document.body.onclick = extrafunc_soso_showmenu;
  108. }
  109. return true;
  110. } else if(TimeCounter<15) {
  111. setTimeout(function () { SOSO_EXP_CHECK(textareaid) ; }, 2000);
  112. return false;
  113. } else if(typeof SOSO_EXP == "undefined" || typeof SOSO_EXP.Register != "function") {
  114. return false;
  115. } else {
  116. return false;
  117. }
  118. }
  119. if(typeof EXTRAFUNC['bbcode2html'] != "undefined") {
  120. EXTRAFUNC['bbcode2html']['soso'] = 'extrafunc_soso_bbcode2html';
  121. EXTRAFUNC['html2bbcode']['soso'] = 'extrafunc_soso_html2bbcode';
  122. if(typeof editdoc != "undefined") {
  123. EXTRAFUNC['showmenu']['soso'] = 'extrafunc_soso_showmenu';
  124. }
  125. }
  126. function extrafunc_soso_showmenu() {
  127. SOSO_EXP.Platform.hideBox();
  128. }
  129. function extrafunc_soso_bbcode2html() {
  130. if(!fetchCheckbox('smileyoff') && allowsmilies) {
  131. EXTRASTR = EXTRASTR.replace(/\{\:soso_(\w+)\:\}/ig, function($1, $2) { return bbcode2html_sososmilies($2);});
  132. }
  133. return EXTRASTR;
  134. }
  135. function extrafunc_soso_html2bbcode() {
  136. if((allowhtml && fetchCheckbox('htmlon')) || (!fetchCheckbox('bbcodeoff') && allowbbcode)) {
  137. EXTRASTR = html2bbcode_sososmilies(EXTRASTR);
  138. }
  139. return EXTRASTR;
  140. }