rdsedmundo

CHAT ESTABLE

Jun 23rd, 2012
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  /*
  2.    JSChat v1.0
  3.    Por edi472
  4.    05/07/2012
  5.     (c) 2012
  6. */
  7. start = function (_chat) {
  8.     var att = null;
  9.     var exit = null;
  10.     var lastmsg = null;
  11.     var delay = 800;
  12.     $(function () {
  13.         $(window).bind("error", function (a) {
  14.             chat.dialog("Erro", a.originalEvent["message"])
  15.         });
  16.         function sprintf(a,b){if(a.match(/%s/gi)){return a.replace(/%s/gi,b)}}
  17.         chat = {
  18.             startonwindow: function (a, b) {
  19.                 if (a == true && this.loggedin) {
  20.                     $('[name=chat-actions]').hide();
  21.                     $("[name=chat-tools],[name=chat-box]").show();
  22.                     $("[name=chat]").fadeIn(2100)
  23.                 }
  24.                 else {
  25.           $('[name=chat-welcome-msg]').html("Crie sua conta já e participe também do meu chat! Espero que goste!");
  26.           $("[name=chat]").fadeIn(2100);
  27.                 }
  28.                 b.setInterval(function () {
  29.                     $("button").button();
  30.                     $("input:text").addClass("input");
  31.                     $("input:password").addClass("input")
  32.                 }, 1);
  33.                 return this
  34.             },
  35.             check_nick: function (a) {
  36.                 $.ajax({
  37.                     url: "headers/check_nick.php?n=" + a.value,
  38.                     success: function (a) {
  39.                         if (a == 1) {
  40.                             chat.dialog("Opa", 'Parece que alguém já está usando o nick "<b>' + $("[name=chat-nick]").val() + '</b>"');
  41.                             $("[name=chat-nick]").val("").focus()
  42.                         }
  43.                     }
  44.                 })
  45.             },
  46.             dialog: function (a, b) {
  47.                 $('<div id="' + a + '" title="' + a + '" id="chat-' + Math.floor(Math.random() * Date.now()) + '">' + b + "</div>").dialog({
  48.                     close: function () {
  49.                         $("#id=" + a + "").dialog("destroy").remove()
  50.                     },
  51.                     width: "auto",
  52.                     modal: true
  53.                 })
  54.             },
  55.             auto_complete: function () {
  56.                 if (typeof array_users == "undefined") {
  57.                     $.getScript("headers/auto_complete.php", function () {
  58.                         $("[name=chat-nick-login]").autocomplete({
  59.                             source: array_users
  60.                         });
  61.                         return array_users
  62.                     })
  63.                 }
  64.                 else {
  65.                     $("[name=chat-nick-login]").autocomplete({
  66.                         source: array_users
  67.                     });
  68.                     return array_users
  69.                 }
  70.             },
  71.             logout: function () {
  72.                 $("#1").slideUp(500);
  73.                 $.get("headers/bye.php", {}, function (a) {
  74.                     if (a.match(/NO_/gi)) {
  75.                         location.reload()
  76.                     }
  77.                     else {
  78.                         location.reload();
  79.                         setTimeout(function () {
  80.                             location.reload();
  81.                         }, 2500)
  82.                     }
  83.                 })
  84.             },
  85.             see_error: function (a) {
  86.                 $("[name=chat-msg]").effect("highlight", 1100).val("").attr("placeholder", a).blur();
  87.                 return setTimeout(function () {
  88.                     $("[name=chat-msg]").removeAttr("placeholder").focus()
  89.                 }, delay)
  90.             },
  91.             reg: function () {
  92.                 $.post("headers/member.php?do=register", {
  93.                     psecretp: $("[name=chat-secret-question]").val(),
  94.                     RES: $("[name=chat-secret-aswner]").val(),
  95.                     packer: "++[md5]",
  96.                     captcha: $("[name=chat-captcha]").val(),
  97.                     login: $("[name=chat-nick]").val(),
  98.                     senha: $("[name=chat-pass]").val(),
  99.                     email: $("[name=chat-email]").val()
  100.                 }, function (p) {
  101.                     eval(p)
  102.                 })
  103.             },
  104.             login: function () {
  105.                 $.post("headers/member.php?do=login", {
  106.                     lembrar: $("input:checkbox").val(),
  107.                     login: $("[name=chat-nick-login]").val(),
  108.                     senha: $("[name=chat-pass-login]").val()
  109.                 }, function (p) {
  110.                     eval(p)
  111.                 })
  112.             },
  113.             update: function () {
  114.                 if (c === true) {
  115.                     $.ajax({
  116.                         url: "headers/member.php?do=see",
  117.                         cache: false,
  118.                         error: function () {
  119.                             chat.update()
  120.                         },
  121.                         success: function (a) {
  122.                             $("[name=chat-box]").html('<p align="left">' + a + "</p>").scrollTop($("[name=chat-box]")[0].scrollHeight)
  123.                         }
  124.                     })
  125.                 }
  126.             }
  127.         };
  128.         $("[name=chat-send]").click(function () {
  129.             msg = $("[name=chat-msg]").val();
  130.             /*if (lastmsg === msg) {
  131.                 chat.see_error("Mensagem simultânea.");
  132.                 return false
  133.             }*/
  134.             if (msg.length > 50) {
  135.                 chat.see_error("Mensagem muito grande.");
  136.                 return false
  137.             }
  138.             else if (msg.length < 1) {
  139.                 chat.see_error("Mensagem muito pequena.");
  140.                 return false
  141.             }
  142.             if (msg.match(/\/last/gi)) {
  143.                 var a = msg.match(/\[(.*)\]/gi).toString().split("[")[1].split("]")[0];
  144.                 $.get("headers/last_entry.php?date=" + Date.now(), {
  145.                     nick: a
  146.                 }, function (b) {
  147.                     if (b !== "NO_EXISTS") {
  148.                         chat.dialog("Aviso", "A última visita do usuário <b>" + a + "</b> foi à " + b);
  149.                         $("[name=chat-msg").val("");
  150.                         return false
  151.                     }
  152.                     chat.dialog("Erro", "O usuário de nome <b>" + a + "</b> não existe.<br>Tente novamente.");
  153.                     $("[name=chat-msg").val("");
  154.                     return false
  155.                 })
  156.             } else if(msg.match(/\/bye/gi)||msg.match(/\/logout/gi)) {
  157.             } else if(msg.match(/\/commands/gi)) {
  158.                 if (!admin) chat.dialog("Comandos", "<b>/commands</b> - ver lista de comandos disponíveis<br><b>/pm [nick] [msg]</b> - mandar mensagem privada<br><b>/last [nick]</b> - ver última visita de um usuário");
  159.             else chat.dialog("Comandos", "<b>/commands</b> - ver lista de comandos disponíveis<br><b>/pm [nick] [msg]</b> - mandar mensagem privada<br><b>/last [nick]</b> - ver última visita de um usuário<br><b>/ban [nick] [motivo]</b> - banir usuário</b><br><b>/superban [nick] [motivo]</b> - banir usuário deletando todos seus registros<br><b>/rank [nick] [rank]</b> - trocar rank do usuário (3-ADM, 2-MOD, 1-MEMBRO, 0-CONVIDADO)</b><br><b>/clear</b> - limpar mensagens da BOX<br><b>/nick [nick] [novo_nick]</b> - mudar nick de um usuário<br><b>/pm [nick] [msg]</b> - mandar mensagem privada<br><b>/alert [msg]</b> - mandar mensagem para todos]")
  160.             } else if(msg.match(/\/online/gi)) {
  161.                 $.ajax({
  162.                 url: "headers/online.php?token=" + user_hash,
  163.                 error: function () {
  164.                     chat.dialog("Erro", "Tente novamente mais tarde.");
  165.                 },
  166.                 success: function (a) {
  167.                     $('<div name="wio" title="Usuários Online">' + a + "</div>").dialog({
  168.                         modal: true,
  169.                         resizable: false,
  170.                         close: function () {
  171.                             $("[name=wio]").dialog("destroy").remove()
  172.                         }
  173.                     })
  174.                 }
  175.             })
  176.             }
  177.             $.post("headers/member.php?do=save", {
  178.                 m: msg
  179.             }, function (a) {
  180.                 $("[name=chat-msg]").val("");
  181.                 chat.update()
  182.             });
  183.             return lastmsg = msg
  184.         });
  185.         $("[name=chat-logout]").click(function () {
  186.             clearInterval(qaz);
  187.             chat.logout()
  188.         });
  189.         $("[name=chat-msg]").keydown(function (a) {
  190.             if (a.keyCode == 13) {
  191.                 $("[name=chat-send]").click()
  192.             }
  193.         });
  194.         qaz = _chat.setInterval("chat.update()", 5000);
  195.         return this
  196.     })
  197. }(window)
Advertisement
Add Comment
Please, Sign In to add comment