Changeset 3919:f0be8a8c7715 for admin/js/common.js
- Timestamp:
- 11/06/18 13:29:04 (7 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
admin/js/common.js
r3915 r3919 2 2 /*exported chainHandler */ 3 3 'use strict'; 4 5 function 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 }; 4 21 5 22 /* Get PreInit JSON data */
Note: See TracChangeset
for help on using the changeset viewer.