ui.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. function getAllData(){
  2. $( "#data" ).empty();
  3. var url_string = window.location.href
  4. var url = new URL(url_string);
  5. if(!url.searchParams.has("display")){
  6. var urlarray = ["aktivieren","aktivierenPrio","stornieren","moveTop","moveX","move","move2","edit"]
  7. }else{
  8. var urlparams = url.searchParams.get("display").replace("/","");
  9. var urlarray = urlparams.split(",");
  10. }
  11. if(url.searchParams.has("menu")){
  12. console.log("MENU");
  13. menuentries = url.searchParams.get("menu").split(",")
  14. $( "#data" ).append("<a class='ontop'href='" + menuentries[1] + "' target='_blank'>" + menuentries[0] +"</a>" );
  15. }
  16. $.ajax({
  17. type: "GET",
  18. url: 'data.db',
  19. async: false,
  20. success: function(ret) {
  21. if(!$(ret.data).length == 0){
  22. container = document.getElementById("data");
  23. entry = document.createElement("div");
  24. tablehead = "<table><tbody id='tablecontent'><tr>";
  25. urlarray.forEach(function(element) { tablehead += "<th></th>" });
  26. var joinkey = urlarray.length;
  27. if(ret.data[0].hasOwnProperty('pkvalue')){
  28. tablehead += "<th class='primarykey'>Primary Key</th>";
  29. }
  30. else{
  31. --joinkey
  32. }
  33. for (var i = 0; i < Object.keys(JSON.parse(ret.data[0].alldata)).length; i++) {
  34. tablehead += "<th class='editable'>" + Object.keys(JSON.parse(ret.data[0].alldata))[i]
  35. if(url.searchParams.has("showfilter")){
  36. tablehead += '<br><input styl="width: 100%;" type="text" id="searchtable' + ++joinkey +'" onkeyup="searchtable(' + joinkey + ')" placeholder="Search for ' + Object.keys(JSON.parse(ret.data[0].alldata))[i] + '" name="' +Object.keys(JSON.parse(ret.data[0].alldata))[i] + '">'
  37. }
  38. tablehead += '</th>'
  39. }
  40. tablehead += "</tr></tbody></table>";
  41. $(entry).html(tablehead);
  42. $(container).append(entry);
  43. container = document.getElementById("tablecontent");
  44. entry = document.createElement("tr");
  45. $(entry).attr("id","AddEntry");
  46. $(entry).attr("class","tableentryAdd");
  47. tableedit = "<td class='addEntry'><a onclick='addEntry()' href='#'>Add</a></td>"
  48. urlarray.forEach(function(element) { });
  49. for (var i = 1; i < urlarray.length; i++) { //start at 1 as add is already set
  50. tableedit += "<td></td>"
  51. }
  52. if(ret.data[0].hasOwnProperty('pkvalue')){
  53. tableedit += "<td class='editableprimarykey'>Primary Key</td>";
  54. }
  55. tableedit += "<td class='editable'>" + Object.keys(JSON.parse(ret.data[0].alldata)).join("</td><td class='editable'>") + "</td>"
  56. $(entry).append(tableedit);
  57. $("#tablecontent").append(entry);
  58. $.each(ret.data, function(i, item) {
  59. setSingleData(item, urlarray, i, url);
  60. });
  61. }
  62. }
  63. });
  64. if(url.searchParams.has("searchkey")){
  65. var searchkey = url.searchParams.get("searchkey").replace("/","");
  66. $('[name="' + searchkey +'"]').val(url.searchParams.get("searchterm").replace("/",""));
  67. $('[name="' + searchkey +'"]').keyup();
  68. }
  69. if(url.searchParams.has("sendListBack")){
  70. $('body').append('<a onclick="collectdata2sendBack()" href="#">Sende Liste</a>');
  71. }
  72. /*
  73. //Single move
  74. if(urlarray.includes("move")){
  75. $( "#data" ).prepend('<a id="storesortedtablebutton" onclick="storesortedtable()" hidden href="#">Store Table</a>');
  76. $( "#tablecontent" ).sortable({
  77. handle: '.handle',
  78. change: function (event, ui) {
  79. $( "#storesortedtablebutton" ).show();
  80. }
  81. });
  82. }*/
  83. if(urlarray.includes("move") || urlarray.includes("move")){
  84. $( "#data" ).prepend('<a id="storesortedtablebutton" onclick="storesortedtable()" hidden href="#">Store Table</a>');
  85. }
  86. //move single or multiple items (buttonpress)
  87. if(urlarray.includes("move")){
  88. new Sortable(tablecontent, {
  89. handle: '.handle',
  90. multiDrag: true, // Enable multi-drag
  91. selectedClass: 'sortable-selected', // The class applied to the selected items
  92. fallbackTolerance: 3, // So that we can select items on mobile
  93. animation: 150,
  94. avoidImplicitDeselect: false,
  95. onSelect: function(/**Event*/evt) {
  96. $( 'tr[ grouping="' + $(evt.item).attr("grouping") + '"]' ).each(function( index ) {
  97. console.log( index + ":select " + $( this ).text() );
  98. Sortable.utils.select($(this)[0]);
  99. });
  100. },
  101. onDeselect: function(/**Event*/evt) {
  102. $( 'tr[ grouping="' + $(evt.item).attr("grouping") + '"]' ).each(function( index ) {
  103. console.log( index + ":deselect " + $( this ).text() );
  104. Sortable.utils.deselect($(this)[0]);
  105. });
  106. },
  107. onEnd: function (/**Event*/evt) { //deselect all on end
  108. $( 'tr' ).each(function( index ) {
  109. console.log( index + ": " + $( this ).text() );
  110. Sortable.utils.deselect($(this)[0]);
  111. });
  112. },
  113. onSort: function (/**Event*/evt) { //on any change show store table button
  114. $( "#storesortedtablebutton" ).show();
  115. }
  116. });
  117. }
  118. if(urlarray.includes("move2")){
  119. new Sortable(tablecontent, {
  120. handle: '.handle2',
  121. multiDrag: true, // Enable multi-drag
  122. selectedClass: 'sortable-selected', // The class applied to the selected items
  123. fallbackTolerance: 3, // So that we can select items on mobile
  124. animation: 150,
  125. avoidImplicitDeselect: false,
  126. onSelect: function(/**Event*/evt) {
  127. $( 'tr[ grouping2="' + $(evt.item).attr("grouping2") + '"]' ).each(function( index ) {
  128. console.log( index + ": " + $( this ).text() );
  129. Sortable.utils.select($(this)[0]);
  130. });
  131. },
  132. onDeselect: function(/**Event*/evt) {
  133. $( 'tr[ grouping2="' + $(evt.item).attr("grouping2") + '"]' ).each(function( index ) {
  134. console.log( index + ": " + $( this ).text() );
  135. Sortable.utils.deselect($(this)[0]);
  136. });
  137. },
  138. onEnd: function (/**Event*/evt) { //deselect all on end
  139. $( 'tr' ).each(function( index ) {
  140. console.log( index + ": " + $( this ).text() );
  141. Sortable.utils.deselect($(this)[0]);
  142. });
  143. },
  144. onSort: function (/**Event*/evt) { //on any change show store table button
  145. $( "#storesortedtablebutton" ).show();
  146. }
  147. });
  148. }
  149. /*
  150. $( "#tablecontent" ).sortable({
  151. multiDrag: true, // Enable the plugin
  152. selectedClass: "sortable-selected", // Class name for selected item
  153. multiDragKey: null, // Key that must be down for items to be selected
  154. avoidImplicitDeselect: true, // true - if you don't want to deselect items on outside click
  155. // Called when an item is selected
  156. onSelect: function(/**Event*/ /*evt) {
  157. evt.item // The selected item
  158. console.log(evt.item);
  159. },
  160. // Called when an item is deselected
  161. onDeselect: function(/**Event*/ /*evt) {
  162. evt.item // The deselected item
  163. }
  164. });
  165. }
  166. */
  167. //$( "#tablecontent" ).on( "sortstart", function( event, ui ) {console.log("start" + ui.item.html())} );
  168. }
  169. function collectdata2sendBack(){
  170. console.log("sending");
  171. var sendback = [];
  172. $('[name="pkvalues"]:visible').each(function(){
  173. sendback.push($(this).html());
  174. });
  175. sendDataElementBack(sendback)
  176. }
  177. function searchtable(key) {
  178. // Declare variables
  179. var input, filter, table, tr, td, i, txtValue;
  180. input = document.getElementById("searchtable" +key);
  181. filter = input.value.toUpperCase();
  182. table = document.getElementById("tablecontent");
  183. tr = table.getElementsByTagName("tr");
  184. // Loop through all table rows, and hide those who don't match the search query
  185. for (i = 0; i < tr.length; i++) {
  186. td = tr[i].getElementsByTagName("td")[key];
  187. if (td) {
  188. txtValue = td.textContent || td.innerText;
  189. if (txtValue.toUpperCase().indexOf(filter) > -1) {
  190. tr[i].style.display = "";
  191. } else {
  192. tr[i].style.display = "none";
  193. }
  194. }
  195. }
  196. }
  197. function sortTable(n) {
  198. var table, rows, switching, i, x, y, shouldSwitch, dir, switchcount = 0;
  199. table = document.getElementById("tablecontent");
  200. switching = true;
  201. // Set the sorting direction to ascending:
  202. dir = "asc";
  203. /* Make a loop that will continue until
  204. no switching has been done: */
  205. while (switching) {
  206. // Start by saying: no switching is done:
  207. switching = false;
  208. rows = table.rows;
  209. /* Loop through all table rows (except the
  210. first, which contains table headers): */
  211. for (i = 1; i < (rows.length - 1); i++) {
  212. // Start by saying there should be no switching:
  213. shouldSwitch = false;
  214. /* Get the two elements you want to compare,
  215. one from current row and one from the next: */
  216. x = rows[i].getElementsByTagName("TD")[n];
  217. y = rows[i + 1].getElementsByTagName("TD")[n];
  218. /* Check if the two rows should switch place,
  219. based on the direction, asc or desc: */
  220. if (dir == "asc") {
  221. if (x.innerHTML.toLowerCase() > y.innerHTML.toLowerCase()) {
  222. // If so, mark as a switch and break the loop:
  223. shouldSwitch = true;
  224. break;
  225. }
  226. } else if (dir == "desc") {
  227. if (x.innerHTML.toLowerCase() < y.innerHTML.toLowerCase()) {
  228. // If so, mark as a switch and break the loop:
  229. shouldSwitch = true;
  230. break;
  231. }
  232. }
  233. }
  234. if (shouldSwitch) {
  235. /* If a switch has been marked, make the switch
  236. and mark that a switch has been done: */
  237. rows[i].parentNode.insertBefore(rows[i + 1], rows[i]);
  238. switching = true;
  239. // Each time a switch is done, increase this count by 1:
  240. switchcount ++;
  241. } else {
  242. /* If no switching has been done AND the direction is "asc",
  243. set the direction to "desc" and run the while loop again. */
  244. if (switchcount == 0 && dir == "asc") {
  245. dir = "desc";
  246. switching = true;
  247. }
  248. }
  249. }
  250. }
  251. function deleteDataElement(dataelement){
  252. console.log("Löschen")
  253. console.log(dataelement)
  254. $.ajax({
  255. type: "DELETE",
  256. url: location.protocol + '//' + location.host + location.pathname,
  257. contentType: "application/json",
  258. headers: {"content-id": "deleteByID"},
  259. data: JSON.stringify(dataelement),
  260. success: function(ret) {
  261. getAllData();
  262. }
  263. });
  264. }
  265. //if used in frames send row to frames
  266. function sendDataElementBack(dataelement, type){
  267. parent.sendJson(window.name,{ type: type, dataelement: dataelement })
  268. //deleteDataElement(dataelement.__orderID__)
  269. }
  270. //retrieves ID´s in current order and sends back 2 server
  271. //security, in case an id got removed it is not retrieved, in case an id got added it will still be added
  272. //server does the following: looks for ID and sets the order to the current order we sent,
  273. //in case the id is not found nothing happens (entry was removed during sorting by someone else)
  274. //in case another ID is in the db that was added while we sort, the id will remain (maybe at different position)
  275. function storesortedtable(){
  276. var alldata = [];
  277. alldata.entry = entry;
  278. $( ".tableentry" ).each(function( index ) {
  279. alldata.push($( this ).attr("id"));
  280. });
  281. $.LoadingOverlay("show");
  282. $.ajax({
  283. type: "PUT",
  284. url: location.protocol + '//' + location.host + location.pathname,
  285. headers: {"content-id": "storesortedtable"},
  286. contentType: "application/json",
  287. data: JSON.stringify(alldata),
  288. success: function(ret) {
  289. $.LoadingOverlay("hide");
  290. getAllData();
  291. }
  292. });
  293. }
  294. function move(from, to){
  295. $.ajax({
  296. type: "PUT",
  297. url: location.protocol + '//' + location.host + location.pathname,
  298. headers: {"content-id": "move"},
  299. contentType: "application/json",
  300. data: JSON.stringify({"From": from, "To": to}),
  301. success: function(ret) {
  302. getAllData();
  303. }
  304. });
  305. }
  306. function setSingleData(singleData, urlarray, i = -1, url = ""){
  307. container = document.getElementById("tablecontent");
  308. entry = document.createElement("tr");
  309. $(entry).attr("id",singleData.__orderID__);
  310. $(entry).attr("class","tableentry");
  311. if(urlarray.includes("move")){
  312. if(url.searchParams.has("group1column")){
  313. $(entry).attr("grouping","Grp1" + JSON.parse(singleData.alldata)[url.searchParams.get("group1column").replace("/","")]);
  314. }
  315. }
  316. if(urlarray.includes("move2")){
  317. if(url.searchParams.has("group2column1") & url.searchParams.has("group2column2")){
  318. $(entry).attr("grouping2","Grp2" + JSON.parse(singleData.alldata)[url.searchParams.get("group2column1").replace("/","")]+ "_" + JSON.parse(singleData.alldata)[url.searchParams.get("group2column2").replace("/","")]);
  319. }
  320. }
  321. /*
  322. if(urlarray.includes("move")){
  323. $(entry).attr("draggable","true");
  324. $(entry).attr("ondragstart","start()");
  325. $(entry).attr("ondragover","dragover()");
  326. }
  327. */
  328. if(url.searchParams.has("colorize")){
  329. if(i == 0){
  330. var tableheader = url.searchParams.has("colorize") ? url.searchParams.get("colorize").replace("/","") : "";
  331. var colorizestart = url.searchParams.has("colorize2") ? url.searchParams.get("colorizestart").replace("/","") : "";
  332. var colorizecol = url.searchParams.has("colorize2") ? url.searchParams.get("colorizecol").replace("/","") : "";
  333. var table2header = url.searchParams.has("colorize2") ? url.searchParams.get("colorize2").replace("/","") : "";
  334. var colorize2start = url.searchParams.has("colorize2start") ? url.searchParams.get("colorize2start").replace("/","") : "";
  335. var colorize2col = url.searchParams.has("colorize2col") ? url.searchParams.get("colorize2col").replace("/","") : "";
  336. if(JSON.parse(singleData.alldata).hasOwnProperty(tableheader)){
  337. if(JSON.parse(singleData.alldata)[tableheader].startsWith(colorizestart)){
  338. $(entry).attr("style","background-color: #" + colorizecol);
  339. }
  340. }
  341. if(JSON.parse(singleData.alldata).hasOwnProperty(table2header)){
  342. if(JSON.parse(singleData.alldata)[table2header].startsWith(colorize2start)){
  343. $(entry).attr("style","background-color: #" + colorize2col);
  344. }
  345. }
  346. }
  347. }
  348. tableentry = "";
  349. if(urlarray.includes("aktivieren")){
  350. tableentry += "<td><a onclick='sendDataElementBack(" + JSON.stringify(singleData) +", \"normal\")' href='#'>Aktivieren</a></td>"
  351. }
  352. if(urlarray.includes("aktivierenPrio")){
  353. tableentry += "<td><a onclick='sendDataElementBack(" + JSON.stringify(singleData) +", \"prio\")' href='#'>Aktivieren Prio</a></td>"
  354. }
  355. if(urlarray.includes("stornieren")){
  356. tableentry += "<td><a onclick='deleteDataElement(" + singleData.__orderID__ +")' href='#'>Stornieren</a></td>"
  357. }
  358. if(urlarray.includes("moveTop")){
  359. tableentry += "<td><a onclick='move(" + singleData.__orderID__ +",0)' href='#'>MoveTop</a></td>"
  360. }
  361. if(urlarray.includes("moveX")){
  362. tableentry += "<td><a onclick='move(" + singleData.__orderID__ +",7)' href='#'>MovetoX</a></td>"
  363. }
  364. if(urlarray.includes("move")){
  365. var name = "⇅";
  366. if(url.searchParams.has("group1name")){
  367. name = url.searchParams.get("group1name").replace("/","")
  368. }
  369. tableentry += '<td class="handle"><a href="#">' + name +'</a></td>'
  370. }
  371. if(urlarray.includes("move2")){
  372. var name = "⇅";
  373. if(url.searchParams.has("group2name")){
  374. name = url.searchParams.get("group2name").replace("/","")
  375. }
  376. tableentry += '<td class="handle2"><a href="#">' + name + '</a></td>'
  377. }
  378. url.searchParams.get("menu")
  379. if(urlarray.includes("edit")){
  380. tableentry += "<td class='edit'><a onclick='edit(" + singleData.__orderID__ +")' href='#'>Edit</a></td>"
  381. }
  382. if(singleData.hasOwnProperty('pkvalue')){
  383. tableentry += "<td name='pkvalues'>" + singleData.pkvalue + "</td>";
  384. }
  385. tableentry += "<td class='editable'>" + Object.values(JSON.parse(singleData.alldata)).join("</td><td class='editable'>") + "</td>"
  386. $(entry).html(tableentry);
  387. //$(entry).hide().fadeIn(2000);
  388. $("#tablecontent tr:last").before(entry);
  389. }
  390. function getUpdateData(id){
  391. //Json aufbauen
  392. var i = 0;
  393. var obj = {};
  394. $("#tablecontent th[class='editable'").each(function( index ) {
  395. curname = $( this ).html();
  396. curvalue = $("#" + id + " .editable:eq(" + i + ") input").val();
  397. if(isNaN(curvalue)){
  398. obj[curname] = curvalue;
  399. }else{
  400. obj[curname] = parseInt(curvalue, 10);
  401. }
  402. ++i;
  403. });
  404. console.log("TEST" + JSON.stringify(obj));
  405. update(id, obj)
  406. }
  407. function update(id, obj){
  408. $.ajax({
  409. type: "PUT",
  410. url: location.protocol + '//' + location.host + location.pathname,
  411. headers: {"content-id": "update"},
  412. contentType: "application/json",
  413. data: JSON.stringify({"ID": id, "alldata": obj}),
  414. success: function(ret) {
  415. getAllData();
  416. }
  417. });
  418. }
  419. function edit(id){
  420. console.log("#" + id + " .editable");
  421. $("#" + id + " .edit").each(function( index ) {
  422. $( this ).html("<a onclick='getUpdateData(" + id +")' href='#'>Update</a>");
  423. });
  424. $("#" + id + " .editable").each(function( index ) {
  425. if(isNaN($( this ).text())){
  426. $( this ).html("<input type='text' value='" + $( this ).text() +"'>");
  427. }else{
  428. $( this ).html("<input type='number' value='" + $( this ).text() +"'>");
  429. }
  430. });
  431. }
  432. function addEntry() {
  433. $("#AddEntry .addEntry").each(function( index ) {
  434. $( this ).html("<a onclick='getNewData(\"AddEntry\")' href='#'>Add</a>");
  435. });
  436. $("#AddEntry .editableprimarykey").each(function( index ) {
  437. $( this ).html("<input type='text' value='" + $( this ).text() +"'>");
  438. });
  439. $("#AddEntry .editable").each(function( index ) {
  440. $( this ).html("<input type='text' value='" + $( this ).text() +"'>");
  441. });
  442. }
  443. function getNewData(id){
  444. //Json aufbauen
  445. var i = 0;
  446. var obj = {};
  447. $("#tablecontent th[class='editable'").each(function( index ) {
  448. curname = $( this ).html();
  449. curvalue = $("#" + id + " .editable:eq(" + i + ") input").val();
  450. if(isNaN(curvalue)){
  451. obj[curname] = curvalue;
  452. }else{
  453. obj[curname] = parseInt(curvalue, 10);
  454. }
  455. ++i;
  456. });
  457. pk = $("#" + id + " .editableprimarykey input").val()
  458. obj = {alldata: obj, pkvalue: pk}
  459. addNewData(id, obj)
  460. }
  461. function addNewData(id, obj){
  462. $.ajax({
  463. type: "POST",
  464. url: location.protocol + '//' + location.host + location.pathname,
  465. headers: {"content-id": "directADD"},
  466. contentType: "application/json",
  467. data: JSON.stringify(obj),
  468. success: function(ret) {
  469. getAllData();
  470. }
  471. });
  472. }
  473. function openlink(menuitem){
  474. var menu = { name: menuitem };
  475. $.ajax({
  476. type: "PUT",
  477. url: window.name,
  478. contentType: "application/json",
  479. data: JSON.stringify(menu),
  480. success: function (data) {
  481. }
  482. });
  483. }
  484. function showDocument() {
  485. $.ajax({
  486. type: "GET",
  487. url: location.protocol + '//' + location.host + location.pathname + 'style.url',
  488. success: function(ret) {
  489. $('head link.custom').attr('href',ret);
  490. }
  491. });
  492. /*
  493. $.ajax({
  494. type: "GET",
  495. url: 'info.json',
  496. success: function(ret) {
  497. makeGrid(ret.x_amount, ret.y_amount);
  498. //set name
  499. document.title = ret.document_name;
  500. $.ajax({
  501. type: "GET",
  502. url: 'frames.json',
  503. success: function(ret2) {
  504. for (i of ret2.data) {
  505. makeFrame(i.lx,i.ly,i.rx,i.ry, i.url, i.callback, i.default, i.showbutton, i.style);
  506. }
  507. }
  508. });
  509. },
  510. error: function() {
  511. reason = '';
  512. clearDocument();
  513. }
  514. });*/
  515. }
  516. function clearDocument() {
  517. console.log('rrrr');
  518. $('#languages').addClass('hidden');
  519. $('#nope').removeClass('hidden');
  520. $('#control .added').remove();
  521. $('#content .added').remove();
  522. $('#reason').text(reason);
  523. }
  524. function init() {
  525. es = new EventSource('sse/');
  526. es.onopen = function() {
  527. getAllData();
  528. // load
  529. };
  530. es.onmessage = function(e) {
  531. console.log("Got SSE");
  532. if (e.data == 'new') {
  533. reason = '';
  534. getAllData();
  535. }
  536. if (e.data == 'reset') {
  537. reason = '';
  538. getAllData();
  539. }
  540. else{
  541. if(e.data == "update"){
  542. alert("update")
  543. }
  544. if(e.data != "keepalive" && e.data != "started"){
  545. try {
  546. var prdata = JSON.parse(e.data)
  547. //alert("LastIf" + prdata.seriennummer)
  548. setSingleData(prdata);
  549. }
  550. catch (e) {
  551. }
  552. }
  553. }
  554. };
  555. es.onerror = function() {
  556. es.close();
  557. reason = 'Server down.';
  558. clearDocument();
  559. setTimeout(init, 10000);
  560. };
  561. }
  562. $(document).ready(function() {
  563. init();
  564. });