// JavaScript Document
/* liens spellcheck
http://man.hubwiz.com/docset/HTML.docset/Contents/Resources/Documents/developer.mozilla.org/en-US/docs/Web/HTML/Controlling_spell_checking_in_HTML_forms.html
https://stackoverflow.com/questions/30704264/how-to-access-chrome-spell-check-suggestions-in-javascript
https://www.chrisfinke.com/2011/03/31/announcing-typo-js-client-side-javascript-spellchecking/
théorie
*/
function create_br(div){
var br = document.createElement("br");
div.appendChild(br);
}
function set_textarea(that){//if textarea change
///var change=that.getAttribute("data-change");
if(that.getAttribute("onchange")!==""){
that.setAttribute("data-change",true);
that.setAttribute("onchange","");
}
}
function create_sub_comment(div,step,precedent){
var Class=String(step)+"divc",child = document.createElement("textarea");
div.appendChild(child);
create_br(div);
//var br = document.createElement("br");
//div.appendChild(br);
////step++;
child.style.marginLeft=String(step*30)+"px";
child.setAttribute("spellcheck","true");
child.setAttribute("placeholder","your comment");
child.setAttribute("onclick","set_textarea(this);");
Class=String(step)+"divc";
div.setAttribute("class",Class);
return(child);
}
function create_a_comment(div,step,precedent,onclick,todo){
var a = document.createElement("a");
div.appendChild(a);
a.setAttribute("href","javascript:void(0);");
a.setAttribute("data-auth",precedent);
a.setAttribute("onclick",onclick);
a.innerHTML=todo;////"envoyer";
a.style.marginLeft=String(step*30)+"px";
}
function response_to_comment(that,command,tag){
var texta=null,precedent="",step=0,tparent = that.parentNode;//emptydiv
///alert("ljs:169 "+that.parentNode);
var divs = tparent.getElementsByTagName("div");
var length=divs.length;
if(length>0){
texta=divs[length-1];
var texts = texta.getElementsByTagName("textarea");
//// step=parseInt(texta.getAttribute("class"));
/// precedent=texta.getAttribute("data-auth");
}
else
{
var texts = tparent.getElementsByTagName("textarea");
texta=texts[texts.length-1];
}
precedent=texta.getAttribute("data-auth");
//======
var iarr=precedent.split("|");
step=parseInt(iarr[1]);///tparent.getAttribute("class"));
//======
//$icone='
//'.$codeicone.'';
create_br(tparent);
var a = document.createElement("a");
tparent.appendChild(a);
//iarr[2] destinataire val expéditeur
var val=document.getElementById("eauteur").value;
document.getElementById("eauteur").value=(!val?"anonymous":val);
a.innerHTML="👤 "+document.getElementById("eauteur").value+" "+new Date(Date.now()).toLocaleString();
a.href="javascript:void(0);";
a.onclick="javascript:void(0);";
a.style.marginLeft=((step+1)*30)+"px";
//create_a_comment(div,step,precedent,"","👤 "+iarr[1]+" "+new Date(Date.now()).toLocaleString());
//create_br(div);
//======
var div = document.createElement("div");
tparent.appendChild(div);
step++;
var child = create_sub_comment(div,step,precedent);////+1,precedent);
///step++;
create_a_comment(div,step,precedent,"send_comment(this,'"+command+"','"+tag+"');","envoyer");
///var space = document.createTextNode(' ');
///div.appendChild(space);
///create_a_comment(div,step,precedent,"send_comment(this,'modify');","modifier");
}
function create_comment(tag){
var o=null,tparent = document.getElementById('totaldiv');//emptydiv
/*
o=document.getElementById('storeNum');
///num=(tparent.innerHTML==""?0:1)+parseInt(o.value);
num=parseInt(o.value);
o.value=num;
*/
var child=create_sub_comment(tparent,0,"");
create_a_comment(tparent,0,"","send_comment(this,'putstart','"+tag+"');","envoyer");
create_br(tparent);
}
/*
function comment_is_selected(that){
alert("ljs:288 "+chrrc+that+chrrc+that.getAttribute("data-index")+chrrc+that.getAttribute("data-index"));
document.getElementById('selected').value=parseInt(that.getAttribute("data-index"));
var target=document.getElementById('target').value=that.getAttribute("data-index");
var arr=target.split("|");
document.getElementById('eauteur').value=arr[1];
document.getElementById('email').value=arr[2];
document.getElementById('edate').value=new Date(Date.now()).toLocaleString();
}
*/
function send_comment(that,command,tag){
///if(!step)step=0;
var ores="",content="",order=0;
var tparent=that.parentNode;
//// alert("ljs:117 "+chrrc+textarea.innerHTML+chrrc+that.getAttribute("data-auth"));
var length=tparent.getElementsByTagName("textarea").length;
var textarea=tparent.getElementsByTagName("textarea")[length-1];
content=textarea.value;
contentinnerHTML=textarea.innerHTML;
if(command=="response"){
var iarr=that.getAttribute("data-auth").split("|");/// 1divc|1|tartampion|16/04/2021 18:50:05||0
document.getElementById('selected').value=iarr[0];///document.getElementById('storeNum').value=iarr[1];
order=parseInt(iarr[1])+1;
document.getElementById("dauteur").value=iarr[2];
var val=document.getElementById("eauteur").value;
document.getElementById("eauteur").value=(!val?"anonymous":val);
alert("ljs:117 "+chrrc+textarea.value+chrrc+that.getAttribute("data-auth"));
}
else{
if(command==="modify"||command==="heart"||command==="likes"||command==="hates"){
/// var textarea=tparent.getElementsByTagName("textarea")[length-1];
if(command==="modify"&&(!textarea.getAttribute("data-change")||textarea.getAttribute("data-change")!=="true")){
alert("Votre commentaire n'a pas été modifié !");return(false);
}
alert("ljs:128 "+chrrc+textarea.getAttribute("data-auth"));////return(false);
document.getElementById('selected').value=parseInt(textarea.getAttribute("data-auth"));
}
}
if(content===""){alert("Votre commentaire est vide !");return(false);}
////alert("ljs:134 "+chrrc+CheckText(content,contentinnerHTML));return(false);
var selected=document.getElementById('selected').value;
if(selected===""){alert("Vous n'avez sélectionné aucun commentaire !");return(false);}
var numC=selected;///document.getElementById('selected').value;
ores=document.getElementById('result');if(ores)ores.value="send";
////document.getElementById('edate').value=new Date(Date.now()).toLocaleString();
var action="sendComment";////,time_start;
var xhr=getXMLHttpRequest();
xhr.onreadystatechange=function(){
///if(xhr.responseText==="")return(false);
var arr=checkXMLHttpRequest(xhr);
if(ores)ores.value="échec";
if(arr[0]){
/////alert("ljs:153 likes: "+chrrc+tparent.getElementsByTagName("label")[1].getAttribute("data-what"));
length=tparent.getElementsByTagName("label").length;
for(var i = 0; i < length; i++){
alert("ljs:156 heart: "+chrrc+length+chrrc+tparent.getElementsByTagName("label")[i].getAttribute("data-what")+chrrc+command);
if(tparent.getElementsByTagName("label")[i].getAttribute("data-what")===command){
tparent.getElementsByTagName("label")[i].innerHTML=parseInt(tparent.getElementsByTagName("label")[i].innerHTML)+1;
break;
}
}
alert("ljs:148 xhr.responseText: "+chrrc+xhr.responseText+chrrc+"arr: "+arr+chrrc);
if(ores)ores.value="OK";
}
else{
return("");
}
};
////var formDatas=new FormData(that.form);formComment
///var nameform=tag+"formComment";
alert("ljs:194 nameform: "+chrrc+document.getElementById("filename").value);
var formDatas=new FormData(document.getElementById(tag+"formComment"));
//===
///alert("ljs:323 comment: "+document.getElementById('t.'+document.getElementById('storeNum').value).value+chrrc+"storeNum: "+'t.'+document.getElementById('storeNum').value+chrrc);
formDatas.append('comment',content);
formDatas.append('command',command);
formDatas.append('step',order);
formDatas.append('edate',new Date(Date.now()).toLocaleString());
formDatas.append('filename',document.getElementById("filename").value);
///if(!document.getElementById('bloque').checked)
sendXMLHttpRequest(xhr,"POST",null,"/atelier/commentaires/ajax_input.php",formDatas,action);
// C:\atelier\commentaires\mycommentaires.php
}
/*
function add_comment(){
// crée un nouvel élément div
var newDiv = document.createElement("div");
// et lui donne un peu de contenu
var newContent = document.createTextNode('Hi there and greetings!');
// ajoute le nœud texte au nouveau div créé
newDiv.appendChild(newContent);
// ajoute le nouvel élément créé et son contenu dans le DOM
var currentDiv = document.getElementById('comment.2');
// document.body.insertBefore(newDiv, document.getElementById('comment.2').nextSibling);///currentDiv);
document.getElementById('allcomments').insertBefore(newDiv, newDiv.nextSibling);///currentDiv);
document.getElementById('edate').value=new Date(Date.now()).toLocaleString();
//// document.body.insertBefore(newDiv, newDiv.nextSibling);///currentDiv);
/// document.body.insertAfter(newDiv, currentDiv);
}
*/
function CheckText(text,inner) {
return(false);
// inner contient texte initial et ne change plus , value contient le texte modifie , ctrl+z revient vers inner
alert("ljs:212 "+chrrc+text+chrrc+inner+chrrc+(text===inner));
return(false);
var result = new Array;
if(!ActiveXObject('Wordpad.Application'))return(false);//com.sun.star.text.MailMerge
var app = new ActiveXObject('Wordpad.Application');
var doc = app.Documents.Add();
doc.Content = text;
for (var i = 1; i <= doc.SpellingErrors.Count; i++) {
var spellingError = doc.SpellingErrors.Item(i);
for (var j = 1; j <= spellingError.Words.Count; j++) {
var word = spellingError.Words.Item(j);
var error = {};
error.word = word.Text;
error.start = word.Start;
error.length = word.Text.length;
error.suggestions = new Array;
var suggestions = word.GetSpellingSuggestions();
for (var k = 1; k <= suggestions.Count; k++) {
error.suggestions.push(suggestions.Item(k).Name);
}
result.push(error);
}
}
return result;
}