1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
| // Example ObjetSmartLink en json
var SmartlinkJson = {"id_source":"7315f47dba65515fca60c851d7065bc6","url_source":"http:\/\/news.yahoo.com\//s\/afp/news/s\/afp/news/s\/afp/news/s\/afp/news","title_source":"Jail-theme teahouse","smartlinks_infos":[{"id_dest":"1735c9d7c2f5b9a51aeaa7aadd3e8df3","score":"268","deleted":"0","date":"1164279208","zone_cible":"151","manually_added":"0","url_dest":"http:\/\/news.yahoo.com\/s\/csm\/ojilleleven","title_dest":"Hostage: The Jill Carroll Story - Epilogue * Family reunion "},{"id_dest":"2fb28d5e3fadd63c9c44736c119b7418","score":"585","deleted":"0","date":"1164279208","zone_cible":"151","manually_added":"0","url_dest":"http:\/\/news.yahoo.com\/s\/csm\/ojilltwo","title_dest":"Hostage: The Jill Carroll Story - Part 2 "},{"id_dest":"380cd804c08c0d64de89ec0d1fa59b8b","score":"335","deleted":"0","date":"1164279208","zone_cible":"151","manually_added":"0","url_dest":"http:\/\/news.yahoo.com\/s\/csm\/ojillthree","title_dest":"Hostage: The Jill Carroll Story - Part 3: The first video "},{"id_dest":"54fe13d026b97bd6e7ce98eab3bb4d23","score":"280","deleted":"0","date":"1164279208","zone_cible":"151","manually_added":"0","url_dest":"http:\/\/news.yahoo.com\/s\/csm\/ojillnine","title_dest":"Hostage: The Jill Carroll Story - Part 9 * The Muj brothers"},{"id_dest":"f9b24f20bc6917a5deb5537e4f5be4cc","score":"352","deleted":"0","date":"1164279208","zone_cible":"151","manually_added":"0","url_dest":"http:\/\/news.yahoo.com\/s\/csm\/ojillone","title_dest":"The Jill Carroll Story - Part 1: The kidnapping"}]};
//var SmartlinkJson = <?= $jsonstring ?>
//construction de SmartLink Objet JS
var SmartLink = eval(SmartlinkJson);
//inserer des espaces dans les urls afin de ls afficher correctement dans le tableau
function insertionspace (string,chr,nth) {
var output = '';
for (var i=0; i<string.length; i++)
{
if (i>0 && i%20 == 0)
output += chr;
output += string.charAt(i);
}
return output;
}
//Modifie les timestamp en date object javascript
function dateTransform (smartlinkdate)
{
var ladate = new Date(smartlinkdate*1000);
var lejour = ladate.getDay();
var lemois = ladate.getMonth();
var lannee = ladate.getFullYear();
return (lejour + "-" + lemois + "-" + lannee);
}
//suppression et retablissement d'un lien cible
function suppRetabLienCible()
{
if (document.getElementById("btn" + sli).value == 'Supp')
{
document.getElementById('btn" + sli + "').value = 'Retablir';
document.getElementById("displayTitleDest").style.textDecoration = 'line-through';
return true;
}
else
{
document.getElementById('btn" + sli + "').value = 'Supp';
document.getElementById("displayTitleDest").style.textDecoration = 'none';
return true;
}
}
function DisplaySmartLinks () {
// récupère une référence vers l'élément body
var zone_affichage = document.getElementById('SmartLink');
// création des éléments <table> et <tbody>
var smartlinksTable = document.createElement("table");
//appliquer la classe CSS SmartLink au tableau d'affichage
smartlinksTable.id = 'SmartLink';
var smartlinksTbody = document.createElement("tbody");
//inserer des espaces dans les urls afin de ls afficher correctement dans le tableau
//var BrokenUrl = SmartLink.url_source.split('/').join(' /');
var BrokenUrl = insertionspace(SmartLink.url_source, ' ', 20)
// var BriceUrl = SmartLink.url_source.group(20,'' , ignoreWhiteSpace);
// alert(BriceUrl);
// création des cellules
//for(var j = 0; j < 2; j++) {
// création d'un élément <tr>
var smartlinksLine = document.createElement("tr");
//Insertion d'une checkbox dans la ligne SmartLink
var smartLinkCheckBox = smartlinksLine.insertCell(0);
smartLinkCheckBox.id = 'AffichageCheckBox';
//smartLinkCheckBox.setAttribute('type', 'checkbox');
//smartLinkCheckBox.setAttribute('name','smartlink_choix');
smartLinkCheckBox .innerHTML = '<input type="checkbox" name="sl_json_selected_"+SmartLink.id_source>';
// création du premier élément <td> de la ligne SmartLinks
var smartlinksCell1 = document.createElement("td");
// Remplissage de la cellule relative au lien source du SmartLink
smartlinksCell1.innerHTML += '<span id="TitreSource">' + SmartLink.title_source + '</span>';
smartlinksCell1.innerHTML += '<br />';
smartlinksCell1.innerHTML += (BrokenUrl);
smartlinksCell1.style.width = '250px';
// ajoute la premiere cellule <td> à la ligne <tr>
smartlinksLine.appendChild(smartlinksCell1);
// creation du second élément <td> de la ligne smartlinks
var smartlinksCell2 = document.createElement("td");
//smartlinksCell2.style.width = '500px';
smartlinksCell2.id= "TableauSuppr";
//creation d'un tableau d'affichage spécifique à aux liens cibles
cell2DisplayTable = document.createElement("table");
cell2DisplayTable.id= "TableauSuppr";
cell2DisplayTbody = document.createElement("tbody");
// var smartlinksCell2pt1 = document.createElement("div");
// Remplissage de la cellule relative aux liens cible du SmartLink
for (sli=0; sli<SmartLink.smartlinks_infos.length; sli++)
{
//une ligne du tableau de liens cibles
var cell2DisplayLine = document.createElement("tr");
// Insertion d'une colonne contenant le Boutton de Suppression
var celluleButton = document.createElement("td");
celluleButton.id = 'celluleButton' + sli;
//celluleButton.innerHTML = '<input type="button" id='btn" + sli + "' value="Supp" onclick="suppRetabLienCible()">';
celluleButton.innerHTML = "<input type='button' id='btn" + sli + "' value='Supp' onclick='suppRetabLienCible()'>";
cell2DisplayLine.appendChild(celluleButton);
//1ere colonne de la ligne du tableau
var cell2DisplayCell1 = document.createElement("td");
cell2DisplayCell1.id = "displayTitleDest";
//remplissage de la 1ere colonne de la ligne
cell2DisplayCell1.innerHTML += (SmartLink.smartlinks_infos[sli].title_dest);
cell2DisplayCell1.innerHTML += ' ';
//cell2DisplayCell1.style.paddingLeft = "50px";
//on attache la colonne a sa ligne
cell2DisplayLine.appendChild(cell2DisplayCell1);
//2eme colonne de la ligne de la ligne du tableau
var cell2DisplayCell2 = document.createElement("td");
//remplissage de la 2eme colonne de la ligne
dateConvertie = dateTransform (SmartLink.smartlinks_infos[sli].date);
cell2DisplayCell2.innerHTML += (dateConvertie);
//on attache la colonne a sa ligne
cell2DisplayLine.appendChild(cell2DisplayCell2);
//smartlinksCell2.innerHTML += (SmartLink.smartlinks_infos[sli].date);
//smartlinksCell2.innerHTML += '<br />';
//on attache la ligne au tableau des liens cibles
cell2DisplayTbody.appendChild(cell2DisplayLine);
}
//On attache le tableau des liens cibles à la cellule 2
cell2DisplayTable.appendChild(cell2DisplayTbody)
smartlinksCell2.appendChild(cell2DisplayTable)
//On attache la cellule2 à la ligne d'affichage d'un SmartLinks
smartlinksLine.appendChild(smartlinksCell2);
// ajoute la ligne <tr> à l'élément <tbody>
smartlinksTbody.appendChild(smartlinksLine);
// ajoute <tbody> à l'élément <table>
smartlinksTable.appendChild(smartlinksTbody);
// ajoute <table> à l'élément <body>
zone_affichage.appendChild(smartlinksTable);
// définit l'attribut border de mytable à 2
// alert(insertionspace(SmartLink.url_source, ' ', 20));
// alert(dateTransform(1164279208));
//alert(BrokenUrl);
//brokenurl2 = insertWhiteSpace(SmartLink.url_source);
}
</script> |