1 /* -*- coding: utf-8 -*- */
2 /** \file one-OPiQuotation.js
6 * JavaScript functions to open/close AJAX sharing panel.
8 * Piece of OPiQuotations.
9 * https://bitbucket.org/OPiMedia/opiquotations
11 * GPLv3 --- Copyright (C) 2014, 2015, 2016 Olivier Pirson
12 * http://www.opimedia.be/
17 * Close this sharing panel.
19 * @param: DOM liCloseItem
21 function sharingClose(liCloseItem) {
24 console.assert(liCloseItem instanceof HTMLElement, liCloseItem);
26 var ul = liCloseItem.parentNode;
28 ul.parentNode.removeChild(ul);
34 * Open the sharing panel for the quotation id
35 * in a <ul> sibling of item.
38 * @param integer id > 0
40 function sharingOpen(item, id) {
43 console.assert(item instanceof HTMLElement, item);
44 console.assert(Number.isInteger(id), id);
45 console.assert(id > 0, id);
47 if (!item || !id || (id <= 0)) {
51 var parent = item.parentNode;
53 // If panel already open, then remove sibling items of item
54 if (parent.children.length > 1) {
55 while (parent.children.length > 1) {
56 parent.removeChild(parent.children[1]);
62 // Create <ul> and fill it in AJAX
63 var ul = document.createElement("ul");
65 ul.setAttribute("aria-haspopup", "true");
67 ul.innerHTML = "<li>Chargement…</li>";
68 parent.appendChild(ul);
70 var xhr = new XMLHttpRequest();
72 xhr.open("GET", "OPiQuotations-sharing.php?id=" + id, true);
73 xhr.setRequestHeader("Content-Type", "text/html;charset=UTF-8");
75 xhr.onreadystatechange = function() { // callback
76 if ((xhr.readyState !== 4) || (xhr.status !== 200 || !xhr.responseText)) {
79 ul.innerHTML = xhr.responseText;