Dotclear


Ignore:
Timestamp:
11/06/18 13:29:04 (7 years ago)
Author:
franck <carnet.franck.paul@…>
Branch:
default
Message:

Switching from inline JS variables to JSON script. Includes a copy of getData() function in common.js

File:
1 edited

Legend:

Unmodified
Added
Removed
  • admin/js/common.js

    r3915 r3919  
    22/*exported chainHandler */ 
    33'use strict'; 
     4 
     5function getData(id, clear = true) { 
     6  let data = {}; 
     7  // Read the JSON-formatted data from the DOM. (from https://mathiasbynens.be/notes/json-dom-csp) 
     8  // To be use with: <script type="application/json" id="myid-data">{"key":value, …}</script> 
     9  const element = document.getElementById(`${id}-data`); 
     10  if (element) { 
     11    try { 
     12      data = JSON.parse(element.textContent); 
     13      if (clear) { 
     14        // Clear the element’s contents 
     15        element.innerHTML = ''; 
     16      } 
     17    } catch (e) {} 
     18  } 
     19  return data; 
     20}; 
    421 
    522/* Get PreInit JSON data */ 
Note: See TracChangeset for help on using the changeset viewer.

Sites map