function setNameToStorage(string) { if(typeof(window.localStorage) === "undefined") { return; } window.localStorage.setItem('userName', string); } function getNameFromStorage() { if(typeof(window.localStorage) === "undefined") { return ""; } ret = window.localStorage.getItem('userName'); if(ret == null) { return ""; } return ret; } function postGoodBad(item, threadid, messageid, value) { var url = "/api/goodbad.php"; try { $.ajax({ cache: "false", async: "false", type: "POST", url: url, data: "messageid="+ messageid + "&threadid="+ threadid + "&value="+ value + "&type=json" , // uri encode success: function(data){ //$("#postgb" + threadid + "_" +messageid).css("display","none"); //alert('data.status='+ data.status); if(data.status == "ok") { //$("#spangood"+ threadid + "_" + messageid).html(data.good); //$("#spanbad" + threadid + "_" + messageid).html(data.bad); // 投票ボタンのハンドラをUNBINDする $("#span_good"+messageid).unbind('click'); $("#span_bad"+messageid).unbind('click'); $("#span_good"+messageid).text("good:"+data.good).removeClass("button").addClass("button_disabled"); $("#span_bad"+messageid).text("bad:"+data.bad).removeClass("button").addClass("button_disabled"); //div_postgb = $("#postgb" + threadid + "_" +messageid); //div_postgb.contents().remove(); //div_postgb.append("good:"+data.good+ " bad:"+data.bad); } }, error:function(XMLHttpRequest, textStatus, errorThrown){ // 通常はここでtextStatusやerrorThrownの値を見て処理を切り分けるか、 // 単純に通信に失敗した際の処理を記述します。 //alert( "failed to create thread.\n retry");; // thisは他のコールバック関数同様にAJAX通信時のオプションを示します。 } }); } catch(e) { alert("exception:"+e); } } function createThread() { var url = "/api/createthread.php"; try { if($("#title").val() == "" || $("#message").val()=="") { alert('input title and message.'); return; } setNameToStorage($("#name").val()); $.ajax({ cache: "false", async: "false", type: "POST", url: url, data: "name="+ $("#name").val() + "&title="+ $("#title").val() + "&category="+ $("#category").val() + "&type=json" + // uri encode "&text="+ encodeURIComponent($("#message").val()) , success: function(data){ if(data.status!="ok") { alert( "failed to create thread.\n retry"); return; } //$("#name").val(""); $("#title").val(""); $("#message").val(""); ReadThreadList(); }, error:function(XMLHttpRequest, textStatus, errorThrown){ // 通常はここでtextStatusやerrorThrownの値を見て処理を切り分けるか、 // 単純に通信に失敗した際の処理を記述します。 //alert( "failed to create thread.\n retry");; // thisは他のコールバック関数同様にAJAX通信時のオプションを示します。 if(XMLHttpRequest.readyState == 0 || XMLHttpRequest.status == 0) { return; // it's not really an error } else { alert(XMLHttpRequest.status); alert(textStatus); } } }); } catch(e) { alert("exception:"+e); } } function createThread2() { try { var url = "/api/createthread.php"; $("#loading") .ajaxStart(function(){ $(this).show(); }) .ajaxComplete(function(){ $(this).hide(); }); var name = $("#name").val(); name = name.replace(/(\")/g, function(whole,$1){return """}); setNameToStorage(name); var title = $("#title").val(); title = title.replace(/(\")/g, function(whole,$1){return """}); var message = $("#message").val(); message = message.replace(/(\")/g, function(whole,$1){return """}); $.ajaxFileUpload ( { url:url, secureuri:false, fileElementId:'fileToUpload', dataName: name, dataTitle: title, dataText: message, dataCategory: $("#category").val(), dataThreadid: '', dataType: 'json', dataAntiCsrf: $("#anticsrf").val(), success: function (data, status) { if(data.status != "ok") { alert(data.status); } else { //$("#name").val(""); $("#title").val(""); $("#message").val(""); ReadThreadList(); } }, error: function (data, status, e) { alert(e); } } ) } catch(e) { alert("exception:"+e); } } // スレッド一覧読み込み function ReadThreadList() { var url = "/api/readtopics.php"; try { //alert("ReadThreadList"); $.ajax({ cache: "false", async: "true", type: "GET", url: url, dataType:"json", data: "category="+ $("#category").val() + "&type=json" + "&sort=asc", success: function(data){ //$("#div_thread_inner").html(""); if(data.status == "ok") { var out = ""; var temp; var i; //alert("data.topics.length="+data.length); for(i=0;i" + data.topics[i].title + "(" + data.topics[i].numMessage + ")"+ " "+data.topics[i].createDate+"
"; out += temp; //alert(temp); } $("#div_thread_inner").html(out); } }, error:function(XMLHttpRequest, textStatus, errorThrown){ // ??? alert(textStatus); out="

Server has something wrong.

" $("#div_thread_inner").html(out); } }); } catch(e) { alert(e); } } // メッセージ読み込み function ReadThread() { var url = "/api/readthread.php"; try { $.ajax({ cache: "false", async: "true", type: "GET", url: url, dataType:"json", data: "id="+ $("#threadid").val() + "&type=json&sort=asc", success: function(data){ //$("#div_thread_inner").html(""); if(data.status!="ok") { out = "there is no message or thead is expired." $("#div_messages").html(out); return; } var out = ""; var temp; var i; // タイトル設定 out = "Title: " + data.thread.title + "" + " was created at " + "" + data.thread.date + ""+ " by id: " + data.thread.ipid + ""+ "
" ; $("#div_threadtitle").html(out); out = ""; //alert("data.messages.length="+data.messages.length); for(i=0; i 0) { // 一分後に新着を調べる。 $("#div_updatecheck").everyTime("15s", CheckNewMessage); } }, error:function(XMLHttpRequest, textStatus, errorThrown){ alert("error "+textStatus); } }); } catch(e) { alert(e); } } // メッセージ書き込み function PostMessage() { var url = "/api/postmessage.php"; try { if( $("#message").val()=="") { alert('input message.'); return; } $.ajax({ cache: "false", async: "false", type: "POST", url: url, data: "name="+ $("#name").val() + "&type=json" + // uri encode "&text="+ encodeURIComponent($("#message").val()) + "&id="+ $("#threadid").val(), success: function(data){ if(data.status == "post after a while") { alert( data.status); } else if(data.status!="ok") { alert( "failed to post message.\n retry" + data.status); return; } //$("#name").val(""); $("#message").val(""); GetMessages(); }, error:function(XMLHttpRequest, textStatus, errorThrown){ // 通常はここでtextStatusやerrorThrownの値を見て処理を切り分けるか、 // 単純に通信に失敗した際の処理を記述します。 //alert( "failed to create thread.\n retry");; // thisは他のコールバック関数同様にAJAX通信時のオプションを示します。 if(XMLHttpRequest.readyState == 0 || XMLHttpRequest.status == 0) { return; // it's not really an error } else { alert(XMLHttpRequest.status); alert(textStatus); } } }); } catch(e) { alert(e); } } function PostMessage2() { try { var url = "/api/postmessage.php"; $("#loading") .ajaxStart(function(){ $(this).show(); }) .ajaxComplete(function(){ $(this).hide(); }); var name = $("#name").val(); name = name.replace(/(\")/g, function(whole,$1){return """}); setNameToStorage(name); var message = $("#message").val(); message = message.replace(/(\")/g, function(whole,$1){return """}); $.ajaxFileUpload ( { url:url, secureuri:false, fileElementId:'fileToUpload', dataTitle: 'title', dataName: name, dataThreadid: $("#threadid").val(), dataText: message, dataType: 'json', dataAntiCsrf: $("#anticsrf").val(), success: function (data, status) { if(data.status != "ok") { alert(data.status); } else { //$("#name").val(""); $("#message").val(""); GetMessages(); } }, error: function (data, status, e) { alert(e); } } ) } catch(e) { alert(e); } } ///////////////////////////////////////////////////////////////// var maxMessageNum = -1; function CheckNewMessage() { url = "/api/getmessagedata.php"; try { //alert("CheckNewMessage"); $.ajax({ cache: "false", async: "true", type: "GET", url: url, dataType:"json", data: "id="+ $("#threadid").val() + "&type=json", success: function(data){ //$("#div_thread_inner").html(""); if(data.status=="ok") { if(data.topic.numMessage > maxMessageNum) { $("#div_updatecheck").addClass("updatecheck"); $("#div_updatecheck").html("read new post."); $("#div_updatecheck").bind("click", GetMessages ); } } //$("#div_updatecheck").oneTime("15s", CheckNewMessage); }, error: function(data, status, e) { //$("#div_updatecheck").oneTime("15s", CheckNewMessage); } }); } catch(e) { alert(e); } } /* topicの内容だけ取って設定する */ function GetTopic() { url = "api/getmessagedata.php"; try { $.ajax({ cache: "false", async: "true", type: "GET", url: url, dataType:"json", data: "id="+ $("#threadid").val() + "&type=json" , success: function(data){ //$("#div_thread_inner").html(""); try { if(data.status=="ok") { // タイトル設定 out = "Title: " + data.topic.title + "" + " was created at " + "" + data.topic.createDate + ""+ "
" ; $("#div_threadtitle").html(out); } else { } } catch(e) { alert("1"+e); } }, error: function(data, status, e) { alert("2 "+e); $("#div_updatecheck").unbind('click'); $("#div_updatecheck").one("onclick", GetMessages() ); } }); } catch(e) { alert("3"+e); } } function GetMessages() { url = "api/readmessage.php"; try { $.ajax({ cache: "false", async: "true", type: "GET", url: url, dataType:"json", data: "id="+ $("#threadid").val() + "&type=json&from=" + (maxMessageNum+1) +"&to=999&sort=asc" , success: function(data){ //$("#div_thread_inner").html(""); try { if(data.status=="ok") { out = ""; //alert("data.messages.length="+data.messages.length); for(i=0; i maxMessageNum) { temp = CreateHtmlFromMessage(data.messages[i]); maxMessageNum = data.messages[i].no; //out += temp; $("#div_updatecheck").after(temp); //$("#div_updatecheck").before($("
")); } } //$("#div_updatecheck").before(out); $("#div_updatecheck").unbind('click'); $("#div_updatecheck").removeClass("updatecheck"); $("#div_updatecheck").html(""); //$("#div_updatecheck").oneTime("15s", CheckNewMessage); } else { } } catch(e) { alert("1"+e); } }, error: function(data, status, e) { alert("2"+e); $("#div_updatecheck").unbind('click'); $("#div_updatecheck").one("onclick", GetMessages() ); } }); } catch(e) { alert("3"+e); } } /* 更新チェックを追加するだけ */ function AddCheckNewMessage() { temp = "
"; $("#div_texts").html(temp); $("#div_updatecheck").everyTime("15s", CheckNewMessage); } function CreateHtmlFromMessage(message) { // URLをaタグで囲う text = message.text.replace(/(https?:\/\/\S+\s?)/g, function(whole,$1){return ""}); // 改行コードをbr text = text.replace(/\n/g,"
"); div_message = $("
"); image_wrap = $("
") if(message.image > 0) { image_wrap.html(""); } div_message.append(image_wrap); div_right_message = $("
"); //a_message = $(""); div_right_message.append( "#:" + ""+message.no +""+ " Name:"+ ""+ message.name + "" + " Date:" + message.date + ""+ " Id: "+message.ipid+"
" ); div_right_message.append(""+text + "" ); //div_right_message.append(a_message); div_right_message.append("
"); div_postgb = $("
"); div_good = $("
good:"+ message.good+"
"); div_bad = $("
bad:"+ message.bad+"
"); div_good.bind('click', function( ) { postGoodBad( div_postgb ,message.threadid, message.messageid , 0); }); div_bad.bind('click', function( ) { postGoodBad( div_postgb ,message.threadid, message.messageid , 1); }); div_postgb.append(div_good); div_postgb.append(" "); div_postgb.append(div_bad); div_gbvalues = $("
"); div_gbvalues.append(div_postgb); div_right_message.append(div_gbvalues); //alert("message.messageid="+message.messageid); div_message.append(div_right_message); div_message.append("
"); return div_message; } /* top_b用 */ function ReadTopB() { url = "api/gettopb.php"; try { // top_loadingを、AJAX開始で表示・終了で非表示 $("#top_loading") .ajaxStart(function(){ $(this).show(); }) .ajaxComplete(function(){ $(this).hide(); }); //alert("++**"); $.ajax({ cache: "false", async: "true", type: "GET", url: url, dataType:"json", data: "type=json" , success: function(data){ try { if(data.status=="ok") { out = ""; text = ""; for(i=0; i"+$1+"
"}); // 改行コードをbr text = text.replace(/\n/g,"
"); //div_message = $("
").addClass("message"); image_wrap = $("