Advertisement
Guest User

Untitled

a guest
Dec 20th, 2013
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.18 KB | None | 0 0
  1. /*
  2. * Avatar in /chatbox - Fast and Rá!!!
  3. * Version: 1.11.2013 - Kheops
  4. * Copyright (c) 2013 JScript <jscriptbrasil at live dot com>
  5. * This work is free. You can redistribute it and/or modify it
  6. * under the terms of the WTFPL, Version 2
  7. */
  8. $(document).ready(function(){
  9. var sHtml = '<iframe onload="setOptions()" src="/chatbox/index.forum?archives=1" id="frame_chatbox" scrolling="yes" width="100%" height="100%" type="text/html" style="border: 0px;" />';
  10. $('#frame_chatbox').replaceWith(sHtml);
  11. });
  12.  
  13. var old = '',
  14. oChat= null,
  15. connected = 1,
  16. chatbox_updated = 0,
  17. chatbox_last_update = 1,
  18. template_color = '#333333',
  19. chatbox_messages = 'null',
  20. chatbox_messages_old = '',
  21. number_of_refresh = 0,
  22. refresh_interval = 0,
  23. ncheckData = 0;
  24.  
  25. function setOptions() {
  26. oChat = $('#frame_chatbox').contents();
  27. oChat.find('#chatbox_footer form').attr('onsubmit', "parent.submitmsg2('?archives=1');parent.refresh_chatbox2('?archives=1');return false;");
  28. oChat.find('#chatbox_main_options li:eq(0) a').attr('onclick', "parent.ajax_refresh_chatbox2('?archives=1', 1);");
  29. oChat.find('#chatbox_main_options li:eq(3)').attr('onclick', "parent.refresh_chatbox2('?archives=1');");
  30. oChat.find('#chatbox_main_options li:eq(4) a').attr('onclick', "parent.CB_disconnect2();");
  31.  
  32. connected = document.getElementById('frame_chatbox').contentWindow['connected'];
  33. chatbox_updated = document.getElementById('frame_chatbox').contentWindow['chatbox_updated'];
  34. chatbox_last_update = document.getElementById('frame_chatbox').contentWindow['chatbox_last_update'];
  35. number_of_refresh = document.getElementById('frame_chatbox').contentWindow['number_of_refresh'];
  36. //refresh_interval = document.getElementById('frame_chatbox').contentWindow['refresh_interval'];
  37.  
  38. ncheckData = setInterval("checkData()", 10);
  39. }
  40. function checkData() {
  41. if (oChat.find('#chatbox span.user').length) {
  42. clearInterval(ncheckData);
  43. try {
  44. connected = document.getElementById('frame_chatbox').contentWindow['connected'];
  45. document.getElementById('frame_chatbox').contentWindow.clearInterval(document.getElementById('frame_chatbox').contentWindow['refresh_interval']);
  46. chatAvatar();
  47. refresh_interval = setInterval("refresh_chatbox2('?archives=1')", 5000);
  48. oChat[0].getElementById('chatbox').scrollTop = 999999;
  49. } catch (err) {}
  50. }
  51. }
  52. function chatAvatar() {
  53. var target = oChat.find('#chatbox span.user a'), chk = {};
  54. target.each(function(index) {
  55. var oThis = $(this);
  56. var USER_URL = oThis.attr('href');
  57.  
  58. if (!chk[USER_URL]) {
  59. chk[USER_URL] = true;
  60. //if ( !oThis.parent().find('.KheopsUserPhoto.KheopsUserPhoto_icon').length ) {
  61. /* Gets the avatar saved in local storage */
  62. var oStor = sessionStorage.getItem('chat' + USER_URL);
  63.  
  64. if (oStor !== null) {
  65. oChat.find("#chatbox span.user a[href='" + USER_URL + "']").parent().prepend('<img alt="" class="KheopsUserPhoto KheopsUserPhoto_icon" src="' + oStor + '">');
  66. //oThis.parent().prepend('<img alt="" class="KheopsUserPhoto KheopsUserPhoto_icon" src="' + oStor + '">');
  67. } else {
  68. //jQuery.ajaxSetup({async:false});
  69. $.get(USER_URL, function (data) {
  70. var AVATAR = $('#profile-advanced-right img', data).attr('src');
  71. if (!AVATAR) AVATAR = $('#profile_tabs p img', data).attr('src');
  72.  
  73. oChat.find("#chatbox span.user a[href='" + USER_URL + "']").parent().prepend('<img alt="" class="KheopsUserPhoto KheopsUserPhoto_icon" src="' + AVATAR + '">');
  74. /* Saves the member avatar in local storage */
  75. sessionStorage.setItem('chat' + USER_URL, AVATAR);
  76. });
  77. //jQuery.ajaxSetup({async:true});
  78. }
  79. //}
  80. }
  81. });
  82. }
  83. function CB_disconnect2() {
  84. if (connected) {
  85. document.getElementById('frame_chatbox').contentWindow.ajax_connect('?archives=1', 'disconnect');
  86. clearInterval(refresh_interval);
  87. clearInterval(ncheckData);
  88. connected = 0;
  89. } else {
  90. document.getElementById('frame_chatbox').contentWindow.ajax_connect('?archives=1', 'connect');
  91. clearInterval(refresh_interval);
  92. document.getElementById('frame_chatbox').contentWindow.clearInterval(document.getElementById('frame_chatbox').contentWindow['refresh_interval']);
  93. connected = 1;
  94. number_of_refresh = 0;
  95. if (!ncheckData) ncheckData = setInterval("checkData()", 10);
  96. /*try {
  97. chatAvatar();
  98. refresh_interval = setInterval("refresh_chatbox2('?archives=1')", 5000);
  99. } catch (err) {}*/
  100. }
  101. }
  102. function submitmsg2(params) {
  103. oChat[0].post.sent.value = oChat[0].post.message.value;
  104. oChat[0].post.message.value = '';
  105. oChat[0].post.message.focus();
  106. ajax_submit_chatbox2(params);
  107. return false
  108. }
  109. function refresh_chatbox2(params) {
  110. if (params == '' || params == undefined) {
  111. params = '?achives=0'
  112. }
  113. if (oChat[0].getElementById('refresh_auto').checked == true) {
  114. ajax_refresh_chatbox2(params)
  115. }
  116. $.post('/chatbox/chatbox_actions.forum?archives=1', 'mode=send&sent=');
  117. }
  118. function ajax_refresh_chatbox2(params, force) {
  119. if (params == '' || params == undefined) {
  120. params = '?achives=0'
  121. }
  122. if (window.XMLHttpRequest) {
  123. var http_request = new XMLHttpRequest()
  124. } else if (window.ActiveXObject) {
  125. var http_request = new ActiveXObject("Microsoft.XMLHTTP")
  126. }
  127. http_request.onreadystatechange = function () {
  128. if (http_request.readyState == 4 && http_request.status == 200) {
  129. var parsed_text = http_request.responseText;
  130. eval(parsed_text);
  131. if (chatbox_last_update > chatbox_updated || force) {
  132. if (oChat[0].getElementById('chatbox').innerHTML != null) {
  133. if (chatbox_messages_old != chatbox_messages) {
  134. oChat[0].getElementById('chatbox').innerHTML = chatbox_messages;
  135. chatbox_messages_old = chatbox_messages;
  136. chatAvatar()
  137. oChat[0].getElementById('chatbox').scrollTop = oChat[0].getElementById('chatbox').scrollHeight + oChat[0].getElementById('chatbox').offsetHeight;
  138. oChat[0].getElementById('chatbox').scrollTop = 999999;
  139. }
  140. }
  141. if (oChat[0].getElementById('chatbox_members').innerHTML != null) oChat[0].getElementById('chatbox_members').innerHTML = chatbox_memberlist;
  142. chatbox_updated = chatbox_last_update
  143. }
  144. }
  145. };
  146. http_request.open('GET', '/chatbox/chatbox_actions.forum' + params + '&mode=refresh', true);
  147. http_request.send(null)
  148. }
  149. function ajax_submit_chatbox2(params) {
  150. number_of_refresh = 0;
  151. var msg_sent = oChat[0].post.sent.value;
  152. if (params == '' || params == undefined) {
  153. params = '?achives=0'
  154. }
  155. var data = '&mode=send';
  156. data += '&sent=' + encodeURIComponent(msg_sent);
  157. data += '&sbold=' + oChat[0].post.sbold.value;
  158. data += '&sitalic=' + oChat[0].post.sitalic.value;
  159. data += '&sunderline=' + oChat[0].post.sunderline.value;
  160. data += '&sstrike=' + oChat[0].post.sstrike.value;
  161. data += '&scolor=' + oChat[0].post.scolor.value;
  162. if ((msg_sent.indexOf('/away') == 0) || (msg_sent.indexOf('/abs') == 0)) {
  163. oChat[0].getElementById('refresh_auto').checked = false
  164. }
  165. if (oChat[0].post.sent.value == '/banlist') {
  166. window.open('/chatbox/chatbox_banlist.forum' + params, 'banlist', 'toolbar=no,menubar=no,personalbar=no,width=450,height=300,scrollbars=yes,resizable=yes');
  167. return false
  168. }
  169. if (window.XMLHttpRequest) {
  170. var http_request = new XMLHttpRequest()
  171. } else if (window.ActiveXObject) {
  172. var http_request = new ActiveXObject("Microsoft.XMLHTTP")
  173. }
  174. http_request.onreadystatechange = function () {
  175. if (http_request.readyState == 4 && http_request.status == 200) {
  176. var parsed_text = http_request.responseText;
  177. eval(parsed_text);
  178. if (chatbox_last_update > chatbox_updated) {
  179. oChat[0].getElementById('chatbox').innerHTML = chatbox_messages;
  180. oChat[0].getElementById('chatbox_members').innerHTML = chatbox_memberlist;
  181. chatbox_updated = chatbox_last_update;
  182. chatAvatar()
  183. oChat[0].getElementById('chatbox').scrollTop = 999999;
  184. }
  185. }
  186. };
  187. http_request.open('POST', '/chatbox/chatbox_actions.forum' + params, true);
  188. http_request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded;');
  189. http_request.send((data))
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement