Dotclear

Changeset 3919:f0be8a8c7715


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

Files:
4 edited

Legend:

Unmodified
Added
Removed
  • admin/_charte.php

    r3915 r3919  
    3434// Set some JSON data 
    3535echo dcUtils::jsJson('dotclear_init', $js); 
    36 echo dcPage::jsUtil(); 
    3736?> 
    3837    <script type="text/javascript" src="js/jquery/jquery.js"></script> 
  • 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 */ 
  • inc/admin/lib.dc.page.php

    r3915 r3919  
    172172        '  <meta name="viewport" content="width=device-width, initial-scale=1.0" />' . "\n" . 
    173173        '  <title>' . $title . ' - ' . html::escapeHTML($core->blog->name) . ' - ' . html::escapeHTML(DC_VENDOR_NAME) . ' - ' . DC_VERSION . '</title>' . "\n"; 
    174  
    175         echo self::jsUtil(); 
    176174 
    177175        if ($core->auth->user_prefs->interface->darkmode) { 
     
    449447        '  <meta name="GOOGLEBOT" content="NOSNIPPET" />' . "\n"; 
    450448 
    451         echo self::jsUtil(); 
    452  
    453449        if ($core->auth->user_prefs->interface->darkmode) { 
    454450            $js['darkMode'] = 1; 
     
    724720 
    725721        return $ret; 
    726     } 
    727  
    728     public static function jsUtil() 
    729     { 
    730         $core = self::getCore(); 
    731         return self::jsLoad($core->blog->getPF('util.js')); 
    732722    } 
    733723 
  • inc/core/class.dc.utils.php

    r3913 r3919  
    137137    public static function jsJson($id, $vars) 
    138138    { 
    139         // Use echo dcUtils::jsLoad($core->blog->getPF('util.js')); to use the JS getData() decoder 
    140         // or echo dcPage::jsUtil(); in admin mode 
     139        // Use echo dcUtils::jsLoad($core->blog->getPF('util.js')); to use the JS getData() decoder in public mode 
    141140        $ret = '<script type="application/json" id="' . html::escapeHTML($id) . '-data">' . "\n" . 
    142141            json_encode($vars, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES) . "\n" . '</script>'; 
Note: See TracChangeset for help on using the changeset viewer.

Sites map