Changeset 3919:f0be8a8c7715
- Timestamp:
- 11/06/18 13:29:04 (7 years ago)
- Branch:
- default
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
admin/_charte.php
r3915 r3919 34 34 // Set some JSON data 35 35 echo dcUtils::jsJson('dotclear_init', $js); 36 echo dcPage::jsUtil();37 36 ?> 38 37 <script type="text/javascript" src="js/jquery/jquery.js"></script> -
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 */ -
inc/admin/lib.dc.page.php
r3915 r3919 172 172 ' <meta name="viewport" content="width=device-width, initial-scale=1.0" />' . "\n" . 173 173 ' <title>' . $title . ' - ' . html::escapeHTML($core->blog->name) . ' - ' . html::escapeHTML(DC_VENDOR_NAME) . ' - ' . DC_VERSION . '</title>' . "\n"; 174 175 echo self::jsUtil();176 174 177 175 if ($core->auth->user_prefs->interface->darkmode) { … … 449 447 ' <meta name="GOOGLEBOT" content="NOSNIPPET" />' . "\n"; 450 448 451 echo self::jsUtil();452 453 449 if ($core->auth->user_prefs->interface->darkmode) { 454 450 $js['darkMode'] = 1; … … 724 720 725 721 return $ret; 726 }727 728 public static function jsUtil()729 {730 $core = self::getCore();731 return self::jsLoad($core->blog->getPF('util.js'));732 722 } 733 723 -
inc/core/class.dc.utils.php
r3913 r3919 137 137 public static function jsJson($id, $vars) 138 138 { 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 141 140 $ret = '<script type="application/json" id="' . html::escapeHTML($id) . '-data">' . "\n" . 142 141 json_encode($vars, JSON_HEX_TAG | JSON_UNESCAPED_SLASHES) . "\n" . '</script>';
Note: See TracChangeset
for help on using the changeset viewer.