Changeset 3930:5007b8ff2be4 for admin/js/common.js
- Timestamp:
- 11/13/18 17:14:28 (7 years ago)
- Branch:
- default
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
admin/js/common.js
r3927 r3930 1 /*global $, jQuery */2 /*exported chainHandler , getData*/1 /*global $, jQuery, getData */ 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 contents15 element.innerHTML = '';16 }17 } catch (e) {}18 }19 return data;20 }21 4 22 5 /* Get PreInit JSON data */ … … 570 553 dotclear.data = dotclear_init; 571 554 // Get other DATA 572 Object.assign(dotclear.data, getData('dotclear')); 555 Object.assign(dotclear, getData('dotclear')); 556 Object.assign(dotclear.msg, getData('dotclear_msg')); 573 557 574 558 // remove class no-js from html tag; cf style/default.css for examples
Note: See TracChangeset
for help on using the changeset viewer.