Dotclear


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

Switching from inline JS variables to JSON script. Common js vars and msg

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 */ 
    33'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 } 
    214 
    225/* Get PreInit JSON data */ 
     
    570553  dotclear.data = dotclear_init; 
    571554  // Get other DATA 
    572   Object.assign(dotclear.data, getData('dotclear')); 
     555  Object.assign(dotclear, getData('dotclear')); 
     556  Object.assign(dotclear.msg, getData('dotclear_msg')); 
    573557 
    574558  // remove class no-js from html tag; cf style/default.css for examples 
Note: See TracChangeset for help on using the changeset viewer.

Sites map