From 4c5feeaf06e2f160bd75bf1919cb9920835efc87 Mon Sep 17 00:00:00 2001
From: Ugnich Anton
Date: Sat, 15 Feb 2014 16:35:10 +0700
Subject: JS cleanup
---
web/scripts3.js | 376 +-------------------------------------------------------
1 file changed, 5 insertions(+), 371 deletions(-)
diff --git a/web/scripts3.js b/web/scripts3.js
index 8445ee19..2b12bfbd 100644
--- a/web/scripts3.js
+++ b/web/scripts3.js
@@ -1,18 +1,5 @@
+/*
var ws=null;
-var currentPMUser="";
-var currentMID=0;
-
-/******************************************************************************/
-
-function initPage() {
- var url=window.location.hash.substring(1);
- if(url.substr(0,5)==="chat/") {
- var uname=url.substr(5);
- showPM(uname);
- }
-}
-
-/******************************************************************************/
function initWS() {
ws = new WebSocket("wss://ws.juick.com/?hash="+hash);
@@ -31,11 +18,11 @@ function initWS() {
try {
var jsonMsg=$.parseJSON(msg.data);
if(jsonMsg.rid>0) {
- incomingComment(jsonMsg);
+ //incomingComment(jsonMsg);
} else if(jsonMsg.mid>0) {
- incomingPost(jsonMsg);
+ //incomingPost(jsonMsg);
} else {
- incomingPM(jsonMsg);
+ //incomingPM(jsonMsg);
}
} catch(err) {
console.log(err);
@@ -50,353 +37,7 @@ function wsSendKeepAlive() {
ws.send(' ');
}
}
-
-/******************************************************************************/
-
-function initPMUList() {
- var ul=$('#pmulist');
- ul.empty();
- $.each(lastConversations,function(i,item) {
- var img=$("").attr("src","https://i.juick.com/as/"+item.uid+".png");
- var a=$("").attr("href","#chat/"+item.uname);
- a.append(img).append(item.uname);
- if(item.MessagesCount) {
- a.append($("
").attr("class","unreadcnt").text(item.MessagesCount));
- }
- var li=$("").append(a);
- ul.append(li);
- });
-}
-
-/******************************************************************************/
-
-function incomingPost(msg) {
- console.log(msg);
- if(groups[0].MessagesCount>0) {
- groups[0].MessagesCount++;
- } else {
- groups[0].MessagesCount=1;
- }
- initGroupsList();
-}
-
-function incomingComment(msg) {
- console.log(msg);
-}
-
-function showGroup(gid) {
- currentPMUser="";
- currentMID=0;
- groups[0].MessagesCount=0;
- initGroupsList();
-
- $.getJSON('https://api.juick.com/home?hash='+hash+'&callback=?').done(function(data) {
- var ul=$('');
- ul.attr("id","msglist");
- $.each(data,function(i,item) {
- var tags="";
- if(item.tags) {
- $.each(item.tags,function(t,tag) {
- tags+=" *"+tag;
- });
- }
- var photo="";
- if(item.photo) {
- photo="";
- }
- var replies="";
- if(item.replies>0) {
- replies="";
- }
- var li=$("").attr("class","msg").html(
- ""+
- ""+item.body+"
"+
- photo+
- ""+
- replies
- );
- ul.append(li);
- });
- $('#toppanel').css("display","none");
- $('#bottompanel').css("display","none");
- var content=$('#content');
- content.attr("class","");
- content.empty();
- content.append(ul);
- $(window).scrollTop(0);
- });
- return false;
-}
-
-function showMessages(param) {
- currentPMUser="";
- currentMID=0;
- $.getJSON('https://api.juick.com/messages?hash='+hash+'&'+param+'&callback=?').done(function(data) {
- var ul=$('');
- ul.attr("id","msglist");
- $.each(data,function(i,item) {
- var tags="";
- if(item.tags) {
- $.each(item.tags,function(t,tag) {
- tags+=" *"+tag+"";
- });
- }
- var photo="";
- if(item.photo) {
- photo="";
- }
- var replies="";
- if(item.replies>0) {
- replies="";
- }
- var li=$("").attr("class","msg").html(
- ""+
- ""+item.body+"
"+
- photo+
- ""+
- replies
- );
- ul.append(li);
- });
- $('#toppanel').css("display","none");
- $('#bottompanel').css("display","none");
- var content=$('#content');
- content.attr("class","");
- content.empty();
- content.append(ul);
- $(window).scrollTop(0);
- });
- return false;
-}
-
-/******************************************************************************/
-
-function showUser(uname) {
- showMessages('uname='+uname);
- return false;
-}
-
-/******************************************************************************/
-
-function showMessage(mid) {
- currentPMUser="";
- currentMID=mid;
- $.getJSON('https://api.juick.com/thread?mid='+mid+'&hash='+hash+'&callback=?').done(function(data) {
- var ul=$('');
- ul.attr("id","thread");
-
- var post=data.shift();
- var tags="";
- if(post.tags) {
- $.each(post.tags,function(t,tag) {
- tags+=" *"+tag+"";
- });
- }
- var photo="";
- if(post.photo) {
- photo="";
- }
- var li=$("").attr("class","msg").html(
- ""+
- ""+post.body+"
"+
- photo+
- ""
- );
- ul.append(li);
-
- var content=$('#content');
- var maxmargin=content.width()-li.width()-50;
-
- var start,end;
- start=new Date();
- showThread(ul,data,0,20,maxmargin);
- end=new Date();
- console.log("Execution time: "+(end.getTime()-start.getTime()));
-
- $('#toppanel').css("display","none");
- $('#bottompanel').css("display","none");
- content.attr("class","");
- content.empty();
- content.append($('').attr("id","threadwrap").append(ul));
- $(window).scrollTop(0);
- });
- return false;
-}
-
-function showThread(ul,data,rid,margin,maxmargin) {
- $.each(data,function(i,item) {
- var replyto=item.replyto || 0;
- if(replyto==rid) {
- var photo="";
- if(item.photo) {
- photo="";
- }
- var li=$("").attr("class","msg").css("margin-left",margin).html(
- ""+
- ""+item.body+"
"+
- photo//+
- //""
- );
- ul.append(li);
-
- var newmargin=margin+20;
- if(newmargin>maxmargin) {
- newmargin=maxmargin;
- }
- showThread(ul,data.slice(i),item.rid,newmargin,maxmargin);
- }
- });
-}
-
-/******************************************************************************/
-
-function incomingPM(msg) {
- try {
- if(msg.user.uname===currentPMUser) {
- $('#pmlist').append($("").attr("class","pm-in").text(msg.body));
- $(window).scrollTop($(document).height());
- } else {
- var modified=false;
- $.each(lastConversations,function(i,item) {
- if(item.uname===msg.user.uname) {
- if(item.MessagesCount>0) {
- item.MessagesCount++;
- } else {
- item.MessagesCount=1;
- }
- modified=true;
- }
- });
- if(!modified) {
- lastConversations.unshift({
- uname:msg.user.uname,
- uid:msg.user.uid,
- MessagesCount:"1"
- });
- }
- initPMUList();
- }
- } catch(err) { }
-}
-
-function showPM(uname) {
- currentMID=0;
-
- var modified=false;
- $.each(lastConversations,function(i,item) {
- if(item.uname===uname && item.MessagesCount>0) {
- item.MessagesCount=0;
- modified=true;
- }
- });
- if(modified) {
- initPMUList();
- }
-
- currentPMUser=uname;
-
- var content=$('#content');
- content.empty();
- content.append($(''));
- var sendform=$('');
- content.append(sendform);
- $('#pmreplytext').focus();
-
- $.getJSON('https://api.juick.com/pm?hash='+hash+'&uname='+uname+'&callback=?').done(function(data) {
- var ul=$('#pmlist');
- $.each(data,function(i,item) {
- var li=$("
");
- if(item.user.uid==user_id) {
- li.attr("class","pm-out");
- } else {
- li.attr("class","pm-in");
- }
- li.text(item.body);
- ul.append(li);
- });
- $(window).scrollTop($(document).height());
- });
- return false;
-}
-
-function sendPMformListener(formEl,ev) {
- if(ev.ctrlKey && (ev.keyCode==10 || ev.keyCode==13)) {
- sendPM();
- }
-}
-
-function sendPM() {
- var replypmtext=$('#pmreplytext');
- var replypmbutton=$('#pmreplybutton');
- replypmtext.prop('disabled', true);
- replypmbutton.prop('disabled', true);
-
- var body=replypmtext.val();
-
- $.ajax({
- url:"https://api.juick.com/pm",
- type:"POST",
- data:{
- hash:hash,
- uname:currentPMUser,
- body:body
- },
- success:function(data) {
- replypmtext.val("");
- $('#pmlist').append($("").attr("class","pm-out").text(body));
- $(window).scrollTop($(document).height());
- },
- error:function(jqxhr,status) {
- alert("Error: "+status);
- },
- complete:function() {
- replypmtext.removeAttr("disabled");
- replypmbutton.removeAttr("disabled");
- replypmtext.focus();
- }
- });
- return false;
-}
+*/
/******************************************************************************/
/******************************************************************************/
@@ -819,10 +460,6 @@ jQuery.fn.selectText = function(){
/******************************************************************************/
$(document).ready(function() {
- if(typeof lastConversations != 'undefined') {
- initPMUList();
- }
-
var tareply=$('textarea.reply');
tareply.autoResize({
extraSpace: 0,
@@ -848,7 +485,4 @@ $(document).ready(function() {
unfoldReply();
$(window).bind('hashchange',unfoldReply);
-
- initPage();
- $(window).bind('hashchange',initPage);
});
--
cgit v1.2.3